From c0587d0407046b7ff6454e14c8688fbae9d5ab97 Mon Sep 17 00:00:00 2001 From: MurphyZhao Date: Mon, 28 May 2018 17:13:41 +0800 Subject: [PATCH] [components/net] add dns server ip address config, may custom in menuconfig Signed-off-by: MurphyZhao --- components/net/Kconfig | 10 ++++++++++ components/net/lwip_dhcpd/dhcp_server.c | 23 +++++++++++++++++++---- 2 files changed, 29 insertions(+), 4 deletions(-) diff --git a/components/net/Kconfig b/components/net/Kconfig index 2fa1dccf6e..192fc2684f 100644 --- a/components/net/Kconfig +++ b/components/net/Kconfig @@ -217,7 +217,17 @@ config LWIP_USING_DHCPD config DHCPD_USING_ROUTER bool "alloc gateway ip for router" default y + + config LWIP_USING_CUSTOMER_DNS_SERVER + bool "Enable customer DNS server config" + default n + if LWIP_USING_CUSTOMER_DNS_SERVER + config DHCP_DNS_SERVER_IP + string "Custom DNS server IP address" + default 1.1.1.1 + endif endif + endif diff --git a/components/net/lwip_dhcpd/dhcp_server.c b/components/net/lwip_dhcpd/dhcp_server.c index 0a3cca6d3e..1ee4075632 100644 --- a/components/net/lwip_dhcpd/dhcp_server.c +++ b/components/net/lwip_dhcpd/dhcp_server.c @@ -434,10 +434,25 @@ static void dhcpd_thread_entry(void *parameter) // DHCP_OPTION_DNS_SERVER, use the default DNS server address in lwIP *dhcp_opt++ = DHCP_OPTION_DNS_SERVER; *dhcp_opt++ = 4; - *dhcp_opt++ = 208; - *dhcp_opt++ = 67; - *dhcp_opt++ = 222; - *dhcp_opt++ = 222; + +#ifndef DHCP_DNS_SERVER_IP + *dhcp_opt++ = DHCPD_SERVER_IPADDR0; + *dhcp_opt++ = DHCPD_SERVER_IPADDR1; + *dhcp_opt++ = DHCPD_SERVER_IPADDR2; + *dhcp_opt++ = 1; +#else + struct ip_addr dns_addr; + ip4addr_aton(DHCP_DNS_SERVER_IP, &dns_addr); + DNS_SERVER_IPADDR0 = (ntohl(dns_addr.addr) >> 24) & 0xFF; + DNS_SERVER_IPADDR1 = (ntohl(dns_addr.addr) >> 16) & 0xFF; + DNS_SERVER_IPADDR2 = (ntohl(dns_addr.addr) >> 8) & 0xFF; + DNS_SERVER_IPADDR3 = (ntohl(dns_addr.addr) >> 0) & 0xFF; + + *dhcp_opt++ = DNS_SERVER_IPADDR0; + *dhcp_opt++ = DNS_SERVER_IPADDR1; + *dhcp_opt++ = DNS_SERVER_IPADDR2; + *dhcp_opt++ = DNS_SERVER_IPADDR3; +#endif // DHCP_OPTION_LEASE_TIME *dhcp_opt++ = DHCP_OPTION_LEASE_TIME;