From 2a57642874c2ebb04144e30859b9e19863f4c903 Mon Sep 17 00:00:00 2001 From: dongheng Date: Tue, 28 May 2019 14:57:04 +0800 Subject: [PATCH] feat(lwip): add reserved DNS server to avoid DHCP changing all DNS server address --- components/lwip/Kconfig | 12 ++++++++++-- components/lwip/lwip/src/core/ipv4/dhcp.c | 6 ++++++ components/lwip/port/esp8266/include/lwipopts.h | 7 +++++++ 3 files changed, 23 insertions(+), 2 deletions(-) diff --git a/components/lwip/Kconfig b/components/lwip/Kconfig index af62dc5f..a215839e 100644 --- a/components/lwip/Kconfig +++ b/components/lwip/Kconfig @@ -275,10 +275,18 @@ config LWIP_IGMP bool "Enable IGMP module" default y +config ESP_DNS + bool "Enable espressif advansed DNS" + default y + help + Enable this option, espressif advansed DNS functions will be enable. User can set the + reserved DNS server(its index is DNS_FALLBACK_SERVER_INDEX) which will not be changed by DHCP. + config DNS_MAX_SERVERS int "The maximum of DNS servers" - range 1 5 - default 2 + range 2 5 + default 3 if ESP_DNS + default 2 if !ESP_DNS menuconfig LWIP_NETIF_LOOPBACK bool "Enable per-interface loopback" diff --git a/components/lwip/lwip/src/core/ipv4/dhcp.c b/components/lwip/lwip/src/core/ipv4/dhcp.c index 0cf97b03..fe373b1f 100644 --- a/components/lwip/lwip/src/core/ipv4/dhcp.c +++ b/components/lwip/lwip/src/core/ipv4/dhcp.c @@ -657,6 +657,12 @@ dhcp_handle_ack(struct netif *netif) #if LWIP_DHCP_PROVIDE_DNS_SERVERS /* DNS servers */ for (n = 0; (n < LWIP_DHCP_PROVIDE_DNS_SERVERS) && dhcp_option_given(dhcp, DHCP_OPTION_IDX_DNS_SERVER + n); n++) { +#if ESP_DNS + if (n == DNS_FALLBACK_SERVER_INDEX) { + continue; + } +#endif + ip_addr_t dns_addr; ip_addr_set_ip4_u32(&dns_addr, lwip_htonl(dhcp_get_option_value(dhcp, DHCP_OPTION_IDX_DNS_SERVER + n))); dns_setserver(n, &dns_addr); diff --git a/components/lwip/port/esp8266/include/lwipopts.h b/components/lwip/port/esp8266/include/lwipopts.h index c2f9e233..13778982 100644 --- a/components/lwip/port/esp8266/include/lwipopts.h +++ b/components/lwip/port/esp8266/include/lwipopts.h @@ -54,6 +54,12 @@ #define ESP_LWIP 1 +#ifdef CONFIG_ESP_DNS +#define ESP_DNS 1 +#else +#define ESP_DNS 0 +#endif + #ifdef CONFIG_LWIP_IPV6_MLD_SOCK #define ESP_LWIP_IPV6_MLD 1 #else @@ -831,6 +837,7 @@ size_t memp_malloc_get_size(size_t type); * DNS_SERVER_ADDRESS(ipaddr), where 'ipaddr' is an 'ip_addr_t*' */ #define DNS_MAX_SERVERS CONFIG_DNS_MAX_SERVERS +#define DNS_FALLBACK_SERVER_INDEX (DNS_MAX_SERVERS - 1) /** DNS do a name checking between the query and the response. */ #define DNS_DOES_NAME_CHECK 1