From 4195d7c2eec2d93781d5f88fd71f5c7e1ee1ff20 Mon Sep 17 00:00:00 2001 From: Michael Balzer Date: Tue, 17 Dec 2019 21:16:36 +0100 Subject: [PATCH] LWIP DHCP server: fix disabling DNS offer MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Applying tcpip_adapter_dhcps_option(TCPIP_ADAPTER_OP_SET, TCPIP_ADAPTER_DOMAIN_NAME_SERVER, …) with option value 0 now disables the DNS offer. It previously would only switch the DNS offer to sending the interface IP address instead of the DNS set. If enabled now with an unset DNS IP (0.0.0.0) it will fallback to the interface IP. --- components/lwip/apps/dhcpserver/dhcpserver.c | 30 +++++++++++--------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/components/lwip/apps/dhcpserver/dhcpserver.c b/components/lwip/apps/dhcpserver/dhcpserver.c index 5e0c1a678..7997eb419 100644 --- a/components/lwip/apps/dhcpserver/dhcpserver.c +++ b/components/lwip/apps/dhcpserver/dhcpserver.c @@ -341,18 +341,20 @@ static u8_t *add_offer_options(u8_t *optptr) } } - *optptr++ = DHCP_OPTION_DNS_SERVER; - *optptr++ = 4; if (dhcps_dns_enabled(dhcps_dns)) { - *optptr++ = ip4_addr1(&dns_server); - *optptr++ = ip4_addr2(&dns_server); - *optptr++ = ip4_addr3(&dns_server); - *optptr++ = ip4_addr4(&dns_server); - }else { - *optptr++ = ip4_addr1(&ipadd); - *optptr++ = ip4_addr2(&ipadd); - *optptr++ = ip4_addr3(&ipadd); - *optptr++ = ip4_addr4(&ipadd); + *optptr++ = DHCP_OPTION_DNS_SERVER; + *optptr++ = 4; + if (dns_server.addr != IPADDR_ANY) { + *optptr++ = ip4_addr1(&dns_server); + *optptr++ = ip4_addr2(&dns_server); + *optptr++ = ip4_addr3(&dns_server); + *optptr++ = ip4_addr4(&dns_server); + } else { + *optptr++ = ip4_addr1(&ipadd); + *optptr++ = ip4_addr2(&ipadd); + *optptr++ = ip4_addr3(&ipadd); + *optptr++ = ip4_addr4(&ipadd); + } } #ifdef CLASS_B_NET @@ -1110,7 +1112,7 @@ static void dhcps_poll_set(u32_t ip) /****************************************************************************** * FunctionName : dhcps_set_new_lease_cb - * Description : set callback for dhcp server when it assign an IP + * Description : set callback for dhcp server when it assign an IP * to the connected dhcp client * Parameters : cb -- callback for dhcp server * Returns : none @@ -1306,7 +1308,7 @@ dhcps_dns_setserver(const ip_addr_t *dnsserver) dns_server = *(ip_2_ip4(dnsserver)); } else { dns_server = *(ip_2_ip4(IP_ADDR_ANY)); - } + } } /****************************************************************************** @@ -1315,7 +1317,7 @@ dhcps_dns_setserver(const ip_addr_t *dnsserver) * Parameters : none * Returns : ip4_addr_t *******************************************************************************/ -ip4_addr_t +ip4_addr_t dhcps_dns_getserver() { return dns_server;