Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 1016efc

Browse files
committedJul 16, 2024·
patch(lwip): Add main component changes
1 parent 7d59e98 commit 1016efc

File tree

4 files changed

+530
-3
lines changed

4 files changed

+530
-3
lines changed
 

‎configs/defconfig.common

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ CONFIG_LWIP_HOOK_ND6_GET_GW_DEFAULT=y
7575
CONFIG_LWIP_HOOK_IP6_SELECT_SRC_ADDR_DEFAULT=y
7676
CONFIG_LWIP_HOOK_NETCONN_EXT_RESOLVE_DEFAULT=y
7777
CONFIG_LWIP_HOOK_IP6_INPUT_DEFAULT=y
78+
CONFIG_LWIP_DNS_SETSERVER_WITH_NETIF=y
7879
CONFIG_MBEDTLS_PSK_MODES=y
7980
CONFIG_MBEDTLS_KEY_EXCHANGE_PSK=y
8081
CONFIG_MBEDTLS_CAMELLIA_C=y

‎patches/lwip_dns_per_netif.diff

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ diff --git a/components/lwip/lwip/src/include/lwip/opt.h b/components/lwip/lwip/
123123
index 2c58c53229d0df1d5e60dab8fd65c48562a76bed..91aa3513fde2a285543649c8bbf7795b6d1471d4 100644
124124
--- a/components/lwip/lwip/src/include/lwip/opt.h
125125
+++ b/components/lwip/lwip/src/include/lwip/opt.h
126-
@@ -1161,6 +1161,22 @@
126+
@@ -1161,6 +1161,20 @@
127127
#define DNS_LOCAL_HOSTLIST 0
128128
#endif /* DNS_LOCAL_HOSTLIST */
129129

@@ -139,8 +139,6 @@ index 2c58c53229d0df1d5e60dab8fd65c48562a76bed..91aa3513fde2a285543649c8bbf7795b
139139
+ * */
140140
+#if !defined LWIP_DNS_SETSERVER_WITH_NETIF && defined __DOXYGEN__
141141
+#define LWIP_DNS_SETSERVER_WITH_NETIF 0
142-
+#elif !defined LWIP_DNS_SETSERVER_WITH_NETIF
143-
+#define LWIP_DNS_SETSERVER_WITH_NETIF 1
144142
+#endif /* LWIP_DNS_SETSERVER_WITH_NETIF */
145143
+
146144
/** If this is turned on, the local host-list can be dynamically changed

‎patches/lwip_dns_per_netif_2.diff

Lines changed: 527 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,527 @@
1+
diff --git a/components/esp_netif/Kconfig b/components/esp_netif/Kconfig
2+
index 4511bbeaafbacc7774f11e6cfa0a2734b64867f3..7704a2959a255142c06eb489977916e93ac74305 100644
3+
--- a/components/esp_netif/Kconfig
4+
+++ b/components/esp_netif/Kconfig
5+
@@ -84,4 +84,15 @@ menu "ESP NETIF Adapter"
6+
help
7+
Enable LwIP IEEE 802.1D bridge support in ESP-NETIF. Note that "Number of clients store data in netif"
8+
(LWIP_NUM_NETIF_CLIENT_DATA) option needs to be properly configured to be LwIP bridge available!
9+
+
10+
+ config ESP_NETIF_SET_DNS_PER_DEFAULT_NETIF
11+
+ bool "Enable DNS server per interface"
12+
+ default n
13+
+ select LWIP_DNS_SETSERVER_WITH_NETIF
14+
+ help
15+
+ Enable this option to use the DNS server which belongs to the selected default network interface.
16+
+ This feature collects DNS server and netif information from LWIP core modules.
17+
+ Whenever a new default netif is selected, global DNS servers in LWIP are updated with the netif
18+
+ related servers.
19+
+
20+
endmenu
21+
diff --git a/components/esp_netif/include/esp_netif.h b/components/esp_netif/include/esp_netif.h
22+
index d8d9918ce4e5375d20cc28228aab6e8356456cbf..f5df24632b0451e1b4737d2616a44241b46173f4 100644
23+
--- a/components/esp_netif/include/esp_netif.h
24+
+++ b/components/esp_netif/include/esp_netif.h
25+
@@ -769,6 +769,11 @@ esp_err_t esp_netif_dhcps_get_clients_by_mac(esp_netif_t *esp_netif, int num, es
26+
* and is designed to be set via this API.
27+
* If DHCP client is disabled, all DNS server types can be set via this API only.
28+
*
29+
+ * Note that LWIP stores DNS server information globally, not per interface, so the first parameter is unused
30+
+ * in the default LWIP configuration.
31+
+ * If CONFIG_ESP_NETIF_SET_DNS_PER_DEFAULT_NETIF=1 this API sets internal DNS server information per
32+
+ * netif. It's also possible to set the global DNS server info by supplying esp_netif=NULL
33+
+ *
34+
* If DHCP server is enabled, the Main DNS Server setting is used by the DHCP server to provide a DNS Server option
35+
* to DHCP clients (Wi-Fi stations).
36+
* - The default Main DNS server is typically the IP of the DHCP server itself.
37+
@@ -794,6 +799,11 @@ esp_err_t esp_netif_set_dns_info(esp_netif_t *esp_netif, esp_netif_dns_type_t ty
38+
* This may be result of a previous call to esp_netif_set_dns_info(). If the interface's DHCP client is enabled,
39+
* the Main or Backup DNS Server may be set by the current DHCP lease.
40+
*
41+
+ * Note that LWIP stores DNS server information globally, not per interface, so the first parameter is unused
42+
+ * in the default LWIP configuration.
43+
+ * If CONFIG_ESP_NETIF_SET_DNS_PER_DEFAULT_NETIF=1 this API returns internally saved DNS server information per
44+
+ * netif. It's also possible to ask for the global DNS server info by supplying esp_netif=NULL
45+
+ *
46+
* @param[in] esp_netif Handle to esp-netif instance
47+
* @param[in] type Type of DNS Server to get: ESP_NETIF_DNS_MAIN, ESP_NETIF_DNS_BACKUP, ESP_NETIF_DNS_FALLBACK
48+
* @param[out] dns DNS Server result is written here on success
49+
diff --git a/components/esp_netif/lwip/esp_netif_lwip.c b/components/esp_netif/lwip/esp_netif_lwip.c
50+
index e0cd05c6f0f952ee6c31b86400ad8a4128a60c69..62edeb69eaef74be81a9b0c9c6fe13b09b56180f 100644
51+
--- a/components/esp_netif/lwip/esp_netif_lwip.c
52+
+++ b/components/esp_netif/lwip/esp_netif_lwip.c
53+
@@ -114,16 +114,6 @@ do {
54+
action; \
55+
} while(0)
56+
57+
-//
58+
-// Internal types
59+
-//
60+
-typedef enum esp_netif_action {
61+
- ESP_NETIF_UNDEF,
62+
- ESP_NETIF_STARTED,
63+
- ESP_NETIF_STOPPED,
64+
- ESP_NETIF_SET_DEFAULT,
65+
-} esp_netif_action_t;
66+
-
67+
//
68+
// Internal variables for this module
69+
//
70+
@@ -307,6 +297,11 @@ static void esp_netif_set_default_netif_internal(esp_netif_t *esp_netif)
71+
} else {
72+
netif_set_default(esp_netif->lwip_netif);
73+
}
74+
+#ifdef CONFIG_ESP_NETIF_SET_DNS_PER_DEFAULT_NETIF
75+
+ for (int i = 0; i < DNS_MAX_SERVERS; ++i) {
76+
+ dns_setserver(i, &esp_netif->dns[i]);
77+
+ }
78+
+#endif
79+
}
80+
81+
/**
82+
@@ -317,7 +312,7 @@ static void esp_netif_set_default_netif_internal(esp_netif_t *esp_netif)
83+
static esp_err_t esp_netif_update_default_netif_lwip(esp_netif_api_msg_t *msg)
84+
{
85+
esp_netif_t *esp_netif = msg->esp_netif;
86+
- esp_netif_action_t action = (esp_netif_action_t)msg->data;
87+
+ esp_netif_route_prio_action_t action = (esp_netif_route_prio_action_t)msg->data;
88+
89+
ESP_LOGD(TAG, "%s %p", __func__, esp_netif);
90+
91+
@@ -337,6 +332,7 @@ static esp_err_t esp_netif_update_default_netif_lwip(esp_netif_api_msg_t *msg)
92+
esp_netif_set_default_netif_internal(s_last_default_esp_netif);
93+
break;
94+
case ESP_NETIF_STARTED:
95+
+ case ESP_NETIF_GOT_IP:
96+
{
97+
// check if previously default interface hasn't been destroyed in the meantime
98+
s_last_default_esp_netif = esp_netif_is_active(s_last_default_esp_netif);
99+
@@ -352,6 +348,7 @@ static esp_err_t esp_netif_update_default_netif_lwip(esp_netif_api_msg_t *msg)
100+
101+
default:
102+
case ESP_NETIF_STOPPED:
103+
+ case ESP_NETIF_LOST_IP:
104+
{
105+
s_last_default_esp_netif = NULL;
106+
esp_netif_t *netif = esp_netif_next_unsafe(NULL);
107+
@@ -383,7 +380,7 @@ static esp_err_t esp_netif_update_default_netif_lwip(esp_netif_api_msg_t *msg)
108+
* @param esp_netif current interface which just updated state
109+
* @param action updating action (on-off)
110+
*/
111+
-static esp_err_t esp_netif_update_default_netif(esp_netif_t *esp_netif, esp_netif_action_t action)
112+
+esp_err_t esp_netif_update_default_netif(esp_netif_t *esp_netif, esp_netif_route_prio_action_t action)
113+
{
114+
return esp_netif_lwip_ipc_call(esp_netif_update_default_netif_lwip, esp_netif, (void*)action);
115+
}
116+
@@ -503,6 +500,24 @@ void* esp_netif_get_netif_impl(esp_netif_t *esp_netif)
117+
return NULL;
118+
}
119+
120+
+#if CONFIG_ESP_NETIF_SET_DNS_PER_DEFAULT_NETIF
121+
+static void store_dnsserver_info(struct netif* netif, u8_t numdns, const ip_addr_t *dnsserver)
122+
+{
123+
+ if (netif == NULL) {
124+
+ return;
125+
+ }
126+
+ esp_netif_t *esp_netif = lwip_get_esp_netif(netif);
127+
+ if (esp_netif == NULL || !esp_netif_is_netif_listed(esp_netif)) {
128+
+ return;
129+
+ }
130+
+ if (!ip_addr_isany(dnsserver)) {
131+
+ ip_addr_copy(esp_netif->dns[numdns], *dnsserver);
132+
+ } else {
133+
+ ip_addr_copy(esp_netif->dns[numdns], *IP_ADDR_ANY);
134+
+ }
135+
+}
136+
+#endif
137+
+
138+
static void tcpip_init_done(void *arg)
139+
{
140+
sys_sem_t *init_sem = arg;
141+
@@ -546,6 +561,12 @@ esp_err_t esp_netif_init(void)
142+
sys_sem_wait(&init_sem);
143+
sys_sem_free(&init_sem);
144+
ESP_LOGD(TAG, "LwIP stack has been initialized");
145+
+#if CONFIG_ESP_NETIF_SET_DNS_PER_DEFAULT_NETIF
146+
+ if (dns_setserver_callback(store_dnsserver_info) != ERR_OK) {
147+
+ ESP_LOGE(TAG, "Feiled to configure DNS set server callback");
148+
+ return ESP_FAIL;
149+
+ }
150+
+#endif
151+
}
152+
153+
#if !LWIP_TCPIP_CORE_LOCKING
154+
@@ -1075,11 +1096,7 @@ static esp_err_t esp_netif_start_api(esp_netif_api_msg_t *msg)
155+
ESP_LOGD(TAG, "%s %p", __func__, esp_netif);
156+
if (ESP_NETIF_IS_POINT2POINT_TYPE(esp_netif, PPP_LWIP_NETIF)) {
157+
#if CONFIG_PPP_SUPPORT
158+
- esp_err_t ret = esp_netif_start_ppp(esp_netif);
159+
- if (ret == ESP_OK) {
160+
- esp_netif_update_default_netif(esp_netif, ESP_NETIF_STARTED);
161+
- }
162+
- return ret;
163+
+ return esp_netif_start_ppp(esp_netif);
164+
#endif
165+
}
166+
167+
@@ -1156,8 +1173,10 @@ static esp_err_t esp_netif_start_api(esp_netif_api_msg_t *msg)
168+
LOG_NETIF_DISABLED_AND_DO("IPv4's DHCP Client", return ESP_ERR_NOT_SUPPORTED);
169+
#endif
170+
}
171+
-
172+
- esp_netif_update_default_netif(esp_netif, ESP_NETIF_STARTED);
173+
+ // For netifs with (active) DHCP client: we update the default netif after getting a valid IP
174+
+ if (!((esp_netif->flags & ESP_NETIF_DHCP_CLIENT) && esp_netif->dhcpc_status != ESP_NETIF_DHCP_STOPPED)) {
175+
+ esp_netif_update_default_netif(esp_netif, ESP_NETIF_STARTED);
176+
+ }
177+
178+
return ESP_OK;
179+
}
180+
@@ -1371,7 +1390,7 @@ static void esp_netif_internal_dhcpc_cb(struct netif *netif)
181+
if (memcmp(ip_info, ip_info_old, sizeof(esp_netif_ip_info_t))) {
182+
evt.ip_changed = true;
183+
}
184+
-
185+
+ esp_netif_update_default_netif(esp_netif, ESP_NETIF_GOT_IP);
186+
memcpy(&evt.ip_info, ip_info, sizeof(esp_netif_ip_info_t));
187+
memcpy(ip_info_old, ip_info, sizeof(esp_netif_ip_info_t));
188+
ESP_LOGD(TAG, "if%p ip changed=%d", esp_netif, evt.ip_changed);
189+
@@ -1412,7 +1431,7 @@ static void esp_netif_ip_lost_timer(void *arg)
190+
.esp_netif = esp_netif,
191+
};
192+
int ret;
193+
-
194+
+ esp_netif_update_default_netif(esp_netif, ESP_NETIF_LOST_IP);
195+
ESP_LOGD(TAG, "if%p ip lost tmr: raise ip lost event", esp_netif);
196+
memset(esp_netif->ip_info_old, 0, sizeof(esp_netif_ip_info_t));
197+
if (esp_netif->lost_ip_event) {
198+
@@ -1731,7 +1750,10 @@ static esp_err_t esp_netif_up_api(esp_netif_api_msg_t *msg)
199+
netif_set_up(lwip_netif);
200+
netif_set_link_up(lwip_netif);
201+
202+
- esp_netif_update_default_netif(esp_netif, ESP_NETIF_STARTED);
203+
+ // For netifs with (active) DHCP client: we update the default netif after getting a valid IP
204+
+ if (!((esp_netif->flags & ESP_NETIF_DHCP_CLIENT) && esp_netif->dhcpc_status != ESP_NETIF_DHCP_STOPPED)) {
205+
+ esp_netif_update_default_netif(esp_netif, ESP_NETIF_STARTED);
206+
+ }
207+
208+
return ESP_OK;
209+
}
210+
@@ -1910,7 +1932,7 @@ static esp_err_t esp_netif_set_ip_info_api(esp_netif_api_msg_t *msg)
211+
if (memcmp(ip_info, esp_netif->ip_info_old, sizeof(esp_netif_ip_info_t))) {
212+
evt.ip_changed = true;
213+
}
214+
-
215+
+ esp_netif_update_default_netif(esp_netif, ESP_NETIF_GOT_IP);
216+
memcpy(&evt.ip_info, ip_info, sizeof(esp_netif_ip_info_t));
217+
memcpy(esp_netif->ip_info_old, ip_info, sizeof(esp_netif_ip_info_t));
218+
ret = esp_event_post(IP_EVENT, evt_id, &evt, sizeof(evt), 0);
219+
@@ -1971,7 +1993,7 @@ static esp_err_t esp_netif_set_dns_info_api(esp_netif_api_msg_t *msg)
220+
221+
ip_addr_t lwip_ip = {};
222+
ESPIP_TO_IP(&dns->ip, &lwip_ip);
223+
- if (esp_netif->flags & ESP_NETIF_DHCP_SERVER) {
224+
+ if (esp_netif && esp_netif->flags & ESP_NETIF_DHCP_SERVER) {
225+
#if ESP_DHCPS
226+
// if DHCP server configured to set DNS in dhcps API
227+
if (type != ESP_NETIF_DNS_MAIN) {
228+
@@ -1984,7 +2006,17 @@ static esp_err_t esp_netif_set_dns_info_api(esp_netif_api_msg_t *msg)
229+
LOG_NETIF_DISABLED_AND_DO("DHCP Server", return ESP_ERR_NOT_SUPPORTED);
230+
#endif
231+
} else {
232+
+#ifdef CONFIG_ESP_NETIF_SET_DNS_PER_DEFAULT_NETIF
233+
+ if (esp_netif) {
234+
+ store_dnsserver_info(esp_netif->lwip_netif, type, &lwip_ip);
235+
+ }
236+
+ if (esp_netif == s_last_default_esp_netif || // if this is the default one -> need to update global DNS servers
237+
+ esp_netif == NULL) { // if the netif ptr is set to NULL -> we explicitly require the update
238+
+ dns_setserver(type, &lwip_ip);
239+
+ }
240+
+#else
241+
dns_setserver(type, &lwip_ip);
242+
+#endif
243+
}
244+
245+
return ESP_OK;
246+
@@ -1992,9 +2024,11 @@ static esp_err_t esp_netif_set_dns_info_api(esp_netif_api_msg_t *msg)
247+
248+
esp_err_t esp_netif_set_dns_info(esp_netif_t *esp_netif, esp_netif_dns_type_t type, esp_netif_dns_info_t *dns)
249+
{
250+
+#ifndef CONFIG_ESP_NETIF_SET_DNS_PER_DEFAULT_NETIF
251+
if (esp_netif == NULL) {
252+
return ESP_ERR_ESP_NETIF_INVALID_PARAMS;
253+
}
254+
+#endif
255+
256+
if (dns == NULL) {
257+
ESP_LOGD(TAG, "set dns null dns");
258+
@@ -2022,7 +2056,7 @@ static esp_err_t esp_netif_get_dns_info_api(esp_netif_api_msg_t *msg)
259+
260+
ESP_LOGD(TAG, "esp_netif_get_dns_info: esp_netif=%p type=%d", esp_netif, type);
261+
262+
- if (esp_netif->flags & ESP_NETIF_DHCP_SERVER) {
263+
+ if (esp_netif && esp_netif->flags & ESP_NETIF_DHCP_SERVER) {
264+
#if ESP_DHCPS
265+
ip4_addr_t dns_ip;
266+
dhcps_dns_getserver(esp_netif->dhcps, &dns_ip);
267+
@@ -2033,7 +2067,15 @@ static esp_err_t esp_netif_get_dns_info_api(esp_netif_api_msg_t *msg)
268+
#endif
269+
} else {
270+
const ip_addr_t* dns_ip = NULL;
271+
+#ifdef CONFIG_ESP_NETIF_SET_DNS_PER_DEFAULT_NETIF
272+
+ if (esp_netif == NULL) { // by setting esp_netif to NULL we require the global DNS server entry
273+
+ dns_ip = dns_getserver(type);
274+
+ } else {
275+
+ dns_ip = &esp_netif->dns[type];
276+
+ }
277+
+#else
278+
dns_ip = dns_getserver(type);
279+
+#endif
280+
if(dns_ip != NULL) {
281+
IP_TO_ESPIP(dns_ip, &dns->ip);
282+
}
283+
@@ -2044,9 +2086,11 @@ static esp_err_t esp_netif_get_dns_info_api(esp_netif_api_msg_t *msg)
284+
285+
esp_err_t esp_netif_get_dns_info(esp_netif_t *esp_netif, esp_netif_dns_type_t type, esp_netif_dns_info_t *dns)
286+
{
287+
+#ifndef CONFIG_ESP_NETIF_SET_DNS_PER_DEFAULT_NETIF
288+
if (esp_netif == NULL) {
289+
return ESP_ERR_ESP_NETIF_INVALID_PARAMS;
290+
}
291+
+#endif
292+
293+
if (dns == NULL) {
294+
ESP_LOGE(TAG, "%s: dns_info cannot be NULL", __func__);
295+
@@ -2142,7 +2186,7 @@ static void esp_netif_internal_nd6_cb(struct netif *netif, uint8_t ip_index)
296+
ESP_LOGW(TAG,"CONFIG_LWIP_ESP_MLDV6_REPORT not enabled, but esp-netif configured with ESP_NETIF_FLAG_MLDV6_REPORT");
297+
#endif
298+
}
299+
-
300+
+ esp_netif_update_default_netif(esp_netif, ESP_NETIF_GOT_IP);
301+
memcpy(&evt.ip6_info, &ip6_info, sizeof(esp_netif_ip6_info_t));
302+
int ret = esp_event_post(IP_EVENT, IP_EVENT_GOT_IP6, &evt, sizeof(evt), 0);
303+
if (ESP_OK != ret) {
304+
@@ -2685,7 +2729,7 @@ static esp_err_t esp_netif_add_ip6_address_api(esp_netif_api_msg_t *msg)
305+
err_t err = netif_add_ip6_address(msg->esp_netif->lwip_netif, &ip6addr, &index);
306+
ESP_RETURN_ON_FALSE(err == ERR_OK && index >= 0, ESP_ERR_ESP_NETIF_IP6_ADDR_FAILED, TAG,
307+
"Failed to add ip6 address");
308+
-
309+
+ esp_netif_update_default_netif(msg->esp_netif, ESP_NETIF_GOT_IP);
310+
netif_ip6_addr_set_state(msg->esp_netif->lwip_netif, index,
311+
addr->preferred ? IP6_ADDR_PREFERRED : IP6_ADDR_DEPRECATED);
312+
ip_event_got_ip6_t evt = {.esp_netif = msg->esp_netif, .ip_index = index};
313+
diff --git a/components/esp_netif/lwip/esp_netif_lwip_internal.h b/components/esp_netif/lwip/esp_netif_lwip_internal.h
314+
index 955dd19f9d7b4c58393b83c4308cff36d3a617f1..7881348ff26c3d918690507c30d5abbe6d380999 100644
315+
--- a/components/esp_netif/lwip/esp_netif_lwip_internal.h
316+
+++ b/components/esp_netif/lwip/esp_netif_lwip_internal.h
317+
@@ -1,5 +1,5 @@
318+
/*
319+
- * SPDX-FileCopyrightText: 2015-2023 Espressif Systems (Shanghai) CO LTD
320+
+ * SPDX-FileCopyrightText: 2015-2024 Espressif Systems (Shanghai) CO LTD
321+
*
322+
* SPDX-License-Identifier: Apache-2.0
323+
*/
324+
@@ -117,4 +117,19 @@ struct esp_netif_obj {
325+
#endif // CONFIG_ESP_NETIF_BRIDGE_EN
326+
// mldv6 timer
327+
bool mldv6_report_timer_started;
328+
+
329+
+#ifdef CONFIG_ESP_NETIF_SET_DNS_PER_DEFAULT_NETIF
330+
+ ip_addr_t dns[DNS_MAX_SERVERS];
331+
+#endif
332+
};
333+
+
334+
+typedef enum esp_netif_set_default_state {
335+
+ ESP_NETIF_UNDEF,
336+
+ ESP_NETIF_STARTED,
337+
+ ESP_NETIF_GOT_IP,
338+
+ ESP_NETIF_STOPPED,
339+
+ ESP_NETIF_LOST_IP,
340+
+ ESP_NETIF_SET_DEFAULT,
341+
+} esp_netif_route_prio_action_t;
342+
+
343+
+esp_err_t esp_netif_update_default_netif(esp_netif_t *esp_netif, esp_netif_route_prio_action_t action);
344+
diff --git a/components/esp_netif/lwip/esp_netif_lwip_ppp.c b/components/esp_netif/lwip/esp_netif_lwip_ppp.c
345+
index 1c5e91d3f6e172984bbc2418c08836703b79c66c..d3f37c7fb54e4431c823e3938ee819247361efd8 100644
346+
--- a/components/esp_netif/lwip/esp_netif_lwip_ppp.c
347+
+++ b/components/esp_netif/lwip/esp_netif_lwip_ppp.c
348+
@@ -75,6 +75,7 @@ static void on_ppp_status_changed(ppp_pcb *pcb, int err_code, void *ctx)
349+
break;
350+
case PPPERR_CONNECT: /* Connection lost */
351+
ESP_LOGI(TAG, "Connection lost");
352+
+ esp_netif_update_default_netif(netif, ESP_NETIF_LOST_IP);
353+
err = esp_event_post(IP_EVENT, netif->lost_ip_event, &evt, sizeof(evt), 0);
354+
355+
if (ESP_OK != err) {
356+
diff --git a/components/esp_netif/test_apps/test_app_esp_netif/main/esp_netif_test.c b/components/esp_netif/test_apps/test_app_esp_netif/main/esp_netif_test.c
357+
index 84705bc784e3551151dd92c32ba4f0ee81434b2e..080f565ec52bde549dcadd8f9d594c283e04820d 100644
358+
--- a/components/esp_netif/test_apps/test_app_esp_netif/main/esp_netif_test.c
359+
+++ b/components/esp_netif/test_apps/test_app_esp_netif/main/esp_netif_test.c
360+
@@ -502,6 +502,81 @@ TEST(esp_netif, route_priority)
361+
}
362+
}
363+
364+
+// to probe DNS server info directly in LWIP
365+
+const ip_addr_t * dns_getserver(u8_t numdns);
366+
+
367+
+TEST(esp_netif, set_get_dnsserver)
368+
+{
369+
+ // create a couple of netifs
370+
+ test_case_uses_tcpip();
371+
+ const char *if_keys[] = {"if0", "if1", "if2", "if3", "if4", "if5", "if6", "if7", "if8", "if9"};
372+
+ const int nr_of_netifs = sizeof(if_keys) / sizeof(char *);
373+
+ esp_netif_t *netifs[nr_of_netifs];
374+
+ esp_netif_driver_ifconfig_t driver_config = { .handle = (void*)1, .transmit = dummy_transmit };
375+
+ // create 10 netifs with different route prio
376+
+ for (int i = 0; i < nr_of_netifs; ++i) {
377+
+ esp_netif_inherent_config_t base_netif_config = { .if_key = if_keys[i], .route_prio = i };
378+
+ esp_netif_config_t cfg = { .base = &base_netif_config,
379+
+ .stack = ESP_NETIF_NETSTACK_DEFAULT_WIFI_STA,
380+
+ .driver = &driver_config };
381+
+ netifs[i] = esp_netif_new(&cfg);
382+
+ TEST_ASSERT_NOT_NULL(netifs[i]);
383+
+ // set the interface up and connected -- to enable the default netif based on route_prio
384+
+ esp_netif_action_start(netifs[i], 0, 0, 0);
385+
+ esp_netif_action_connected(netifs[i], 0, 0, 0);
386+
+ }
387+
+
388+
+ esp_netif_dns_info_t dns[2];
389+
+ esp_netif_dns_info_t get_dns;
390+
+ TEST_ASSERT_EQUAL(ESP_OK, esp_netif_str_to_ip4("1.2.3.4", &dns[0].ip.u_addr.ip4));
391+
+ TEST_ASSERT_EQUAL(ESP_OK, esp_netif_str_to_ip4("5.6.7.8", &dns[1].ip.u_addr.ip4));
392+
+
393+
+ // set DNS info to one netif
394+
+ TEST_ASSERT_EQUAL(ESP_OK, esp_netif_set_dns_info(netifs[3], ESP_NETIF_DNS_MAIN, &dns[0]));
395+
+ TEST_ASSERT_EQUAL(ESP_OK, esp_netif_set_dns_info(netifs[3], ESP_NETIF_DNS_BACKUP, &dns[1]));
396+
+#ifndef CONFIG_ESP_NETIF_SET_DNS_PER_DEFAULT_NETIF
397+
+ // check that calling setters/getters with 'esp_netif==NULL' is invalid
398+
+ TEST_ASSERT_NOT_EQUAL(ESP_OK, esp_netif_set_dns_info(NULL, ESP_NETIF_DNS_BACKUP, &dns[1]));
399+
+ TEST_ASSERT_NOT_EQUAL(ESP_OK, esp_netif_get_dns_info(NULL, ESP_NETIF_DNS_BACKUP, &get_dns));
400+
+
401+
+ // check that the global DNS is configured the same way
402+
+ const ip_addr_t *ip = dns_getserver(0);
403+
+ TEST_ASSERT_EQUAL(ip->u_addr.ip4.addr, dns[0].ip.u_addr.ip4.addr);
404+
+ ip = dns_getserver(1);
405+
+ TEST_ASSERT_EQUAL(ip->u_addr.ip4.addr, dns[1].ip.u_addr.ip4.addr);
406+
+
407+
+ // check that we get the same DNS information for all netifs
408+
+ for (int i=0; i < nr_of_netifs; ++i) {
409+
+ TEST_ASSERT_EQUAL(ESP_OK, esp_netif_get_dns_info(netifs[i], ESP_NETIF_DNS_MAIN, &get_dns));
410+
+ TEST_ASSERT_EQUAL(get_dns.ip.u_addr.ip4.addr, dns[0].ip.u_addr.ip4.addr);
411+
+ TEST_ASSERT_EQUAL(ESP_OK, esp_netif_get_dns_info(netifs[i], ESP_NETIF_DNS_BACKUP, &get_dns));
412+
+ TEST_ASSERT_EQUAL(get_dns.ip.u_addr.ip4.addr, dns[1].ip.u_addr.ip4.addr);
413+
+ }
414+
+#else
415+
+ // check that calling setters/getters with 'esp_netif==NULL' is valid, they set/get global DNS servers
416+
+ TEST_ASSERT_EQUAL(ESP_OK, esp_netif_set_dns_info(NULL, ESP_NETIF_DNS_MAIN, &dns[0]));
417+
+ TEST_ASSERT_EQUAL(ESP_OK, esp_netif_get_dns_info(NULL, ESP_NETIF_DNS_BACKUP, &get_dns));
418+
+ const ip_addr_t *ip = dns_getserver(0);
419+
+ TEST_ASSERT_EQUAL(ip->u_addr.ip4.addr, dns[0].ip.u_addr.ip4.addr);
420+
+ ip = dns_getserver(1);
421+
+ TEST_ASSERT_EQUAL(ip->u_addr.ip4.addr, get_dns.ip.u_addr.ip4.addr); // same as what we got at the esp-netif layer
422+
+ TEST_ASSERT_NOT_EQUAL(ip->u_addr.ip4.addr, dns[1].ip.u_addr.ip4.addr); // but different from what we set earlier per netif
423+
+
424+
+ // now we set the netif[3] as default one and check again
425+
+ esp_netif_set_default_netif(netifs[3]);
426+
+ ip = dns_getserver(1);
427+
+ TEST_ASSERT_EQUAL(ip->u_addr.ip4.addr, dns[1].ip.u_addr.ip4.addr); // now the ESP_NETIF_DNS_BACKUP[3[ should be set globally
428+
+
429+
+ // check that we get a different DNS server with another netif
430+
+ TEST_ASSERT_EQUAL(ESP_OK, esp_netif_get_dns_info(netifs[5], ESP_NETIF_DNS_MAIN, &get_dns));
431+
+ TEST_ASSERT_NOT_EQUAL(dns[0].ip.u_addr.ip4.addr, get_dns.ip.u_addr.ip4.addr);
432+
+#endif
433+
+
434+
+ for (int i=0; i < nr_of_netifs; ++i) {
435+
+ esp_netif_destroy(netifs[i]);
436+
+ TEST_ASSERT_FALSE(esp_netif_is_netif_listed(netifs[i]));
437+
+ }
438+
+}
439+
440+
TEST_GROUP_RUNNER(esp_netif)
441+
{
442+
@@ -531,6 +606,7 @@ TEST_GROUP_RUNNER(esp_netif)
443+
RUN_TEST_CASE(esp_netif, dhcp_server_state_transitions_mesh)
444+
#endif
445+
RUN_TEST_CASE(esp_netif, route_priority)
446+
+ RUN_TEST_CASE(esp_netif, set_get_dnsserver)
447+
}
448+
449+
void app_main(void)
450+
diff --git a/components/esp_netif/test_apps/test_app_esp_netif/pytest_esp_netif.py b/components/esp_netif/test_apps/test_app_esp_netif/pytest_esp_netif.py
451+
index 841d8253608c3fd83da0d7e52801f8270be5f8a0..43c01256372ff4219b516883def12ae3ba380a8d 100644
452+
--- a/components/esp_netif/test_apps/test_app_esp_netif/pytest_esp_netif.py
453+
+++ b/components/esp_netif/test_apps/test_app_esp_netif/pytest_esp_netif.py
454+
@@ -1,6 +1,5 @@
455+
-# SPDX-FileCopyrightText: 2022 Espressif Systems (Shanghai) CO LTD
456+
+# SPDX-FileCopyrightText: 2022-2024 Espressif Systems (Shanghai) CO LTD
457+
# SPDX-License-Identifier: CC0-1.0
458+
-
459+
import pytest
460+
from pytest_embedded import Dut
461+
462+
@@ -8,5 +7,9 @@ from pytest_embedded import Dut
463+
@pytest.mark.esp32s2
464+
@pytest.mark.esp32c3
465+
@pytest.mark.generic
466+
+@pytest.mark.parametrize('config', [
467+
+ 'global_dns',
468+
+ 'dns_per_netif',
469+
+], indirect=True)
470+
def test_esp_netif(dut: Dut) -> None:
471+
dut.expect_unity_test_output()
472+
diff --git a/components/esp_netif/test_apps/test_app_esp_netif/sdkconfig.ci.dns_per_netif b/components/esp_netif/test_apps/test_app_esp_netif/sdkconfig.ci.dns_per_netif
473+
new file mode 100644
474+
index 0000000000000000000000000000000000000000..3abbf3a3bcfdd6715d8e05462ea4ddb809e39729
475+
--- /dev/null
476+
+++ b/components/esp_netif/test_apps/test_app_esp_netif/sdkconfig.ci.dns_per_netif
477+
@@ -0,0 +1 @@
478+
+CONFIG_ESP_NETIF_SET_DNS_PER_DEFAULT_NETIF=y
479+
diff --git a/components/esp_netif/test_apps/test_app_esp_netif/sdkconfig.ci.global_dns b/components/esp_netif/test_apps/test_app_esp_netif/sdkconfig.ci.global_dns
480+
new file mode 100644
481+
index 0000000000000000000000000000000000000000..ba627cbf81dba8d3dced317d56729b45d020917b
482+
--- /dev/null
483+
+++ b/components/esp_netif/test_apps/test_app_esp_netif/sdkconfig.ci.global_dns
484+
@@ -0,0 +1 @@
485+
+CONFIG_ESP_NETIF_SET_DNS_PER_DEFAULT_NETIF=n
486+
diff --git a/components/lwip/Kconfig b/components/lwip/Kconfig
487+
index 5d80561043eb3c9f07c0e95d7d4284c314da6b59..c3588ef1f4ce1e3f04b3febd03d9fe92e509b694 100644
488+
--- a/components/lwip/Kconfig
489+
+++ b/components/lwip/Kconfig
490+
@@ -1130,6 +1130,15 @@ menu "LWIP"
491+
help
492+
This option allows you to config dns fallback server address.
493+
494+
+ config LWIP_DNS_SETSERVER_WITH_NETIF
495+
+ bool "Enable DNS server settings with netif"
496+
+ default n
497+
+ help
498+
+ This option allows collecting DNS server settings per netif using
499+
+ configurable callback function.
500+
+ It's typically used with CONFIG_ESP_NETIF_SET_DNS_PER_DEFAULT_NETIF
501+
+ which configures a callback to collect the DNS info on esp_netif layer.
502+
+
503+
endmenu # DNS
504+
505+
config LWIP_BRIDGEIF_MAX_PORTS
506+
diff --git a/components/lwip/port/include/lwipopts.h b/components/lwip/port/include/lwipopts.h
507+
index 48feeb16c38e25c6fc0117d804c76f45eb8af75d..b20b07479bdcace5b5c475376f606945ce0f23ca 100644
508+
--- a/components/lwip/port/include/lwipopts.h
509+
+++ b/components/lwip/port/include/lwipopts.h
510+
@@ -503,6 +503,17 @@ static inline uint32_t timeout_from_offered(uint32_t lease, uint32_t min)
511+
#define LWIP_DNS_SUPPORT_MDNS_QUERIES 0
512+
#endif
513+
514+
+/**
515+
+ * LWIP_DNS_SETSERVER_WITH_NETIF: If this is turned on, the dns_setserver_with_netif() is enabled and called
516+
+ * from all internal modules (instead of dns_setserver()) allowing to setup a user callback to collect DNS server
517+
+ * information acquired by the related network interface.
518+
+ */
519+
+#ifdef CONFIG_LWIP_DNS_SETSERVER_WITH_NETIF
520+
+#define LWIP_DNS_SETSERVER_WITH_NETIF 1
521+
+#else
522+
+#define LWIP_DNS_SETSERVER_WITH_NETIF 0
523+
+#endif
524+
+
525+
/*
526+
---------------------------------
527+
---------- UDP options ----------

‎tools/install-esp-idf.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ if [ ! -x $idf_was_installed ] || [ ! -x $commit_predefined ]; then
4141
patch -p1 -N -i ../patches/mmu_map.diff
4242
patch -p1 -N -i ../patches/lwip_max_tcp_pcb.diff
4343
patch -p1 -N -i ../patches/lwip_dns_per_netif.diff
44+
patch -p1 -N -i ../patches/lwip_dns_per_netif_2.diff
4445
cd -
4546
fi
4647

0 commit comments

Comments
 (0)
Please sign in to comment.