Merge pull request #1475 from zhaojuntao/dns-server-fix

[components/net] add dns server ip address config
This commit is contained in:
Bernard Xiong 2018-05-29 08:33:14 +08:00 committed by GitHub
commit 81a9cc37ad
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 29 additions and 4 deletions

View File

@ -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

View File

@ -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;