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: 3092
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.

Who is online

Users browsing this forum: No registered users and 47 guests