esp32 AP DNS server sets a default route, it shouldn't, this breaks my phone

BrucePerens
Posts: 5
Joined: Mon Mar 05, 2018 4:33 am

esp32 AP DNS server sets a default route, it shouldn't, this breaks my phone

Postby BrucePerens » Mon Mar 05, 2018 4:59 am

Hi,

Using the latest esp-idf for development, the ESP32 access point's DNS server sends DNS option 3, "router" set to its own IP address, and this sets a gateway route on the client. But the ESP32 doesn't perform any routing. So, this makes my phone stop routing to the global internet through its cellular radio when it's connected to the ESP32. If the ESP32 did not send the router option, the phone would have a route for the ESP32's IP and netmask only, and it would use the normal cellular gateway route for everything else.

Thanks

Bruce Perens K6BP

WiFive
Posts: 3529
Joined: Tue Dec 01, 2015 7:35 am

Re: esp32 AP DNS server sets a default route, it shouldn't, this breaks my phone

Postby WiFive » Tue Mar 06, 2018 12:08 am

Have you tried clearing the softap gateway address after tcpip_adapter_init?

BrucePerens
Posts: 5
Joined: Mon Mar 05, 2018 4:33 am

Re: esp32 AP DNS server sets a default route, it shouldn't, this breaks my phone

Postby BrucePerens » Wed Mar 07, 2018 2:36 am

From the source code for components/lwip/apps/dhcpserver.c clearing the interface's gateway field looks like it would work, the result is that it sends 0.0.0.0 as the router in the BOOTP response. I'm not sure when the interface is initialized, so I set it (and the netmask) both in my initialization code and in the event handler for SYSTEM_EVENT_AP_START until I have time to sniff more packets. Now the esp32 only sends its own network, and all but addresses 0-15 masked out.

This allows a phone to continue to use its cellular internet connection.

If you look at the source for components/lwip/apps/dhcpserver.c you will see that dhcps_set_option_info() only knows how to set
REQUESTED_IP_ADDRESS - actually the address range handed out by the DHCP server.
IP_ADDRESS_LEASE_TIME - duration of DHCP leases
ROUTER_SOLICITATION_ADDRESS - not an address at all, but a boolean that says whether to send an address of a host or perhaps a broadcast address to which the client will send router _solicitations_. This is not the router's address.
DOMAIN_NAME_SERVER - not the address of the domain name server, but a boolean that says whether the esp32 should say via DHCP/BOOTP that it is the DNS server.

By the way, for the people having trouble with AP+STA, it should say somewhere that you have to scan first and make sure the AP you connect to and the AP within the esp32 are both using the same channel.

kevinevans
Posts: 7
Joined: Thu Aug 25, 2022 10:34 pm

Re: esp32 AP DNS server sets a default route, it shouldn't, this breaks my phone

Postby kevinevans » Thu Oct 06, 2022 5:55 pm

Sorry to bump an old thread, but I'm having trouble with this exact problem. I'm currently basing this off of the softAP example in the espidf repo.

In my `wifi_event_handler`, I think I'm correctly unsetting the gateway and DNS,

Code: Select all

    if (event_id == WIFI_EVENT_AP_START) {
      ESP_LOGI(TAG, "WIFI_EVENT_AP_START, setting gateway");
      esp_netif_dns_info_t dns_info = {0};
      esp_netif_ip_info_t info;
      
      esp_netif_dhcps_stop(netif);
      esp_netif_get_ip_info(netif, &info);

      IP4_ADDR(&info.gw, 0, 0, 0, 0);
      IP4_ADDR(&info.netmask, 255, 255, 255, 0);
      
      IP_ADDR4(&dns_info.ip, 0, 0, 0, 0);

      esp_netif_set_ip_info(netif, &info);

      dhcps_offer_t opt_val = OFFER_DNS;
      esp_netif_dhcps_option(netif, TCPIP_ADAPTER_OP_SET, TCPIP_ADAPTER_DOMAIN_NAME_SERVER, &opt_val, 1);
      esp_netif_dhcps_start(netif);
    }
On my phone's network settings, I'm seeing:

Image

Is there anything else that needs to be done here?

Who is online

Users browsing this forum: Google [Bot] and 293 guests