forked from cesanta/esp-idf
-
Notifications
You must be signed in to change notification settings - Fork 4
/
lwip.patch
123 lines (115 loc) · 4.91 KB
/
lwip.patch
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
diff --git a/src/core/ipv4/dhcp.c b/src/core/ipv4/dhcp.c
index 1bb9c3da1..bb2b29e7d 100644
--- a/src/core/ipv4/dhcp.c
+++ b/src/core/ipv4/dhcp.c
@@ -157,7 +157,7 @@ enum dhcp_option_idx {
DHCP_OPTION_IDX_DNS_SERVER,
DHCP_OPTION_IDX_DNS_SERVER_LAST = DHCP_OPTION_IDX_DNS_SERVER + LWIP_DHCP_PROVIDE_DNS_SERVERS - 1,
#endif /* LWIP_DHCP_PROVIDE_DNS_SERVERS */
-#if LWIP_DHCP_GET_NTP_SRV
+#if LWIP_DHCP_GET_NTP_SRV && LWIP_DHCP_MAX_NTP_SERVERS
DHCP_OPTION_IDX_NTP_SERVER,
DHCP_OPTION_IDX_NTP_SERVER_LAST = DHCP_OPTION_IDX_NTP_SERVER + LWIP_DHCP_MAX_NTP_SERVERS - 1,
#endif /* LWIP_DHCP_GET_NTP_SRV */
@@ -364,7 +364,9 @@ dhcp_check(struct netif *netif)
static void
dhcp_handle_offer(struct netif *netif, struct dhcp_msg *msg_in)
{
+#if ESP_DHCP && !ESP_DHCP_DISABLE_VENDOR_CLASS_IDENTIFIER
u8_t n;
+#endif
struct dhcp *dhcp = netif_dhcp_data(netif);
LWIP_DEBUGF(DHCP_DEBUG | LWIP_DBG_TRACE, ("dhcp_handle_offer(netif=%p) %c%c%"U16_F"\n",
@@ -693,7 +695,7 @@ dhcp_handle_ack(struct netif *netif, struct dhcp_msg *msg_in)
#if LWIP_DHCP_PROVIDE_DNS_SERVERS || LWIP_DHCP_GET_NTP_SRV || !ESP_DHCP_DISABLE_VENDOR_CLASS_IDENTIFIER
u8_t n;
#endif /* LWIP_DHCP_PROVIDE_DNS_SERVERS || LWIP_DHCP_GET_NTP_SRV || !ESP_DHCP_DISABLE_VENDOR_CLASS_IDENTIFIER */
-#if LWIP_DHCP_GET_NTP_SRV
+#if LWIP_DHCP_GET_NTP_SRV && LWIP_DHCP_MAX_NTP_SERVERS
ip4_addr_t ntp_server_addrs[LWIP_DHCP_MAX_NTP_SERVERS];
#endif
@@ -766,12 +768,15 @@ dhcp_handle_ack(struct netif *netif, struct dhcp_msg *msg_in)
ip4_addr_set_u32(&dhcp->offered_gw_addr, lwip_htonl(dhcp_get_option_value(dhcp, DHCP_OPTION_IDX_ROUTER)));
}
-#if LWIP_DHCP_GET_NTP_SRV
+#if LWIP_DHCP_GET_NTP_SRV && LWIP_DHCP_MAX_NTP_SERVERS
/* NTP servers */
for (n = 0; (n < LWIP_DHCP_MAX_NTP_SERVERS) && dhcp_option_given(dhcp, DHCP_OPTION_IDX_NTP_SERVER + n); n++) {
ip4_addr_set_u32(&ntp_server_addrs[n], lwip_htonl(dhcp_get_option_value(dhcp, DHCP_OPTION_IDX_NTP_SERVER + n)));
}
- dhcp_set_ntp_servers(n, ntp_server_addrs);
+ ip4_addr_set_zero(&dhcp->offered_ntp_addr);
+ if (dhcp_option_given(dhcp, DHCP_OPTION_IDX_NTP_SERVER)) {
+ ip4_addr_set_u32(&dhcp->offered_ntp_addr, lwip_htonl(dhcp_get_option_value(dhcp, DHCP_OPTION_IDX_NTP_SERVER)));
+ }
#endif /* LWIP_DHCP_GET_NTP_SRV */
#if LWIP_DHCP_PROVIDE_DNS_SERVERS
@@ -787,6 +792,10 @@ dhcp_handle_ack(struct netif *netif, struct dhcp_msg *msg_in)
dns_setserver(n, &dns_addr);
}
#endif /* LWIP_DHCP_PROVIDE_DNS_SERVERS */
+ ip4_addr_set_zero(&dhcp->offered_dns_addr);
+ if (dhcp_option_given(dhcp, DHCP_OPTION_IDX_DNS_SERVER)) {
+ ip4_addr_set_u32(&dhcp->offered_dns_addr, lwip_htonl(dhcp_get_option_value(dhcp, DHCP_OPTION_IDX_DNS_SERVER)));
+ }
}
/**
@@ -1988,7 +1997,7 @@ again:
LWIP_ERROR("len == 4", len == 4, return ERR_VAL;);
decode_idx = DHCP_OPTION_IDX_LEASE_TIME;
break;
-#if LWIP_DHCP_GET_NTP_SRV
+#if LWIP_DHCP_GET_NTP_SRV && LWIP_DHCP_MAX_NTP_SERVERS
case (DHCP_OPTION_NTP):
/* special case: there might be more than one server */
LWIP_ERROR("len %% 4 == 0", len % 4 == 0, return ERR_VAL;);
diff --git a/src/include/lwip/dhcp.h b/src/include/lwip/dhcp.h
index 8a528219d..2d283c8f7 100644
--- a/src/include/lwip/dhcp.h
+++ b/src/include/lwip/dhcp.h
@@ -103,6 +103,8 @@ struct dhcp
ip4_addr_t offered_ip_addr;
ip4_addr_t offered_sn_mask;
ip4_addr_t offered_gw_addr;
+ ip4_addr_t offered_dns_addr;
+ ip4_addr_t offered_ntp_addr;
u32_t offered_t0_lease; /* lease period (in seconds) */
u32_t offered_t1_renew; /* recommended renew time (usually 50% of lease period) */
diff --git a/src/include/lwip/opt.h b/src/include/lwip/opt.h
index b314c59a4..615bb4de8 100644
--- a/src/include/lwip/opt.h
+++ b/src/include/lwip/opt.h
@@ -954,7 +954,7 @@
* void dhcp_set_ntp_servers(u8_t num_ntp_servers, ip_addr_t* ntp_server_addrs);
*/
#if !defined LWIP_DHCP_GET_NTP_SRV || defined __DOXYGEN__
-#define LWIP_DHCP_GET_NTP_SRV 0
+#define LWIP_DHCP_GET_NTP_SRV 1
#endif
/**
diff --git a/src/include/netif/ppp/ppp.h b/src/include/netif/ppp/ppp.h
index 3d73c3657..2f1e1e9e3 100644
--- a/src/include/netif/ppp/ppp.h
+++ b/src/include/netif/ppp/ppp.h
@@ -421,6 +421,8 @@ struct ppp_pcb_s {
ipv6cp_options ipv6cp_allowoptions; /* Options we allow peer to request */
ipv6cp_options ipv6cp_hisoptions; /* Options that we ack'd */
#endif /* PPP_IPV6_SUPPORT */
+
+ u32_t dns_server;
};
/************************
diff --git a/src/netif/ppp/ipcp.c b/src/netif/ppp/ipcp.c
index b7c766eb0..2d33f97c2 100644
--- a/src/netif/ppp/ipcp.c
+++ b/src/netif/ppp/ipcp.c
@@ -1930,7 +1930,9 @@ static void ipcp_up(fsm *f) {
if (go->dnsaddr[1])
script_setenv("DNS2", ip_ntoa(go->dnsaddr[1]), 0);
#endif /* UNUSED */
+ pcb->dns_server = 0;
if (pcb->settings.usepeerdns && (go->dnsaddr[0] || go->dnsaddr[1])) {
+ pcb->dns_server = go->dnsaddr[0];
sdns(pcb, go->dnsaddr[0], go->dnsaddr[1]);
#if 0 /* UNUSED */
script_setenv("USEPEERDNS", "1", 0);