summaryrefslogtreecommitdiff
path: root/components
diff options
context:
space:
mode:
authorMurphyZhao <[email protected]>2018-05-28 17:13:41 +0800
committerMurphyZhao <[email protected]>2018-05-28 17:37:30 +0800
commitc0587d0407046b7ff6454e14c8688fbae9d5ab97 (patch)
tree85b20728584b981c13fc291777bd7608302d85cf /components
parentf29cc0dba460ff861682b20e7288732676a6c34b (diff)
[components/net] add dns server ip address config, may custom in menuconfig
Signed-off-by: MurphyZhao <[email protected]>
Diffstat (limited to 'components')
-rw-r--r--components/net/Kconfig10
-rw-r--r--components/net/lwip_dhcpd/dhcp_server.c23
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;