@@ -113,16 +113,6 @@ do {
113
113
action; \
114
114
} while(0)
115
115
116
- //
117
- // Internal types
118
- //
119
- typedef enum esp_netif_action {
120
- ESP_NETIF_UNDEF ,
121
- ESP_NETIF_STARTED ,
122
- ESP_NETIF_STOPPED ,
123
- ESP_NETIF_SET_DEFAULT ,
124
- } esp_netif_action_t ;
125
-
126
116
//
127
117
// Internal variables for this module
128
118
//
@@ -306,6 +296,11 @@ static void esp_netif_set_default_netif_internal(esp_netif_t *esp_netif)
306
296
} else {
307
297
netif_set_default (esp_netif -> lwip_netif );
308
298
}
299
+ #ifdef CONFIG_ESP_NETIF_SET_DNS_PER_DEFAULT_NETIF
300
+ for (int i = 0 ; i < DNS_MAX_SERVERS ; ++ i ) {
301
+ dns_setserver (i , & esp_netif -> dns [i ]);
302
+ }
303
+ #endif
309
304
}
310
305
311
306
/**
@@ -316,7 +311,7 @@ static void esp_netif_set_default_netif_internal(esp_netif_t *esp_netif)
316
311
static esp_err_t esp_netif_update_default_netif_lwip (esp_netif_api_msg_t * msg )
317
312
{
318
313
esp_netif_t * esp_netif = msg -> esp_netif ;
319
- esp_netif_action_t action = (esp_netif_action_t )msg -> data ;
314
+ esp_netif_route_prio_action_t action = (esp_netif_route_prio_action_t )msg -> data ;
320
315
321
316
ESP_LOGD (TAG , "%s %p" , __func__ , esp_netif );
322
317
@@ -336,6 +331,7 @@ static esp_err_t esp_netif_update_default_netif_lwip(esp_netif_api_msg_t *msg)
336
331
esp_netif_set_default_netif_internal (s_last_default_esp_netif );
337
332
break ;
338
333
case ESP_NETIF_STARTED :
334
+ case ESP_NETIF_GOT_IP :
339
335
{
340
336
// check if previously default interface hasn't been destroyed in the meantime
341
337
s_last_default_esp_netif = esp_netif_is_active (s_last_default_esp_netif );
@@ -351,6 +347,7 @@ static esp_err_t esp_netif_update_default_netif_lwip(esp_netif_api_msg_t *msg)
351
347
352
348
default :
353
349
case ESP_NETIF_STOPPED :
350
+ case ESP_NETIF_LOST_IP :
354
351
{
355
352
s_last_default_esp_netif = NULL ;
356
353
esp_netif_t * netif = esp_netif_next_unsafe (NULL );
@@ -382,7 +379,7 @@ static esp_err_t esp_netif_update_default_netif_lwip(esp_netif_api_msg_t *msg)
382
379
* @param esp_netif current interface which just updated state
383
380
* @param action updating action (on-off)
384
381
*/
385
- static esp_err_t esp_netif_update_default_netif (esp_netif_t * esp_netif , esp_netif_action_t action )
382
+ esp_err_t esp_netif_update_default_netif (esp_netif_t * esp_netif , esp_netif_route_prio_action_t action )
386
383
{
387
384
return esp_netif_lwip_ipc_call (esp_netif_update_default_netif_lwip , esp_netif , (void * )action );
388
385
}
@@ -503,6 +500,24 @@ void* esp_netif_get_netif_impl(esp_netif_t *esp_netif)
503
500
return NULL ;
504
501
}
505
502
503
+ #if CONFIG_ESP_NETIF_SET_DNS_PER_DEFAULT_NETIF
504
+ static void store_dnsserver_info (struct netif * netif , u8_t numdns , const ip_addr_t * dnsserver )
505
+ {
506
+ if (netif == NULL ) {
507
+ return ;
508
+ }
509
+ esp_netif_t * esp_netif = lwip_get_esp_netif (netif );
510
+ if (esp_netif == NULL || !esp_netif_is_netif_listed (esp_netif )) {
511
+ return ;
512
+ }
513
+ if (!ip_addr_isany (dnsserver )) {
514
+ ip_addr_copy (esp_netif -> dns [numdns ], * dnsserver );
515
+ } else {
516
+ ip_addr_copy (esp_netif -> dns [numdns ], * IP_ADDR_ANY );
517
+ }
518
+ }
519
+ #endif
520
+
506
521
static void tcpip_init_done (void * arg )
507
522
{
508
523
sys_sem_t * init_sem = arg ;
@@ -546,6 +561,12 @@ esp_err_t esp_netif_init(void)
546
561
sys_sem_wait (& init_sem );
547
562
sys_sem_free (& init_sem );
548
563
ESP_LOGD (TAG , "LwIP stack has been initialized" );
564
+ #if CONFIG_ESP_NETIF_SET_DNS_PER_DEFAULT_NETIF
565
+ if (dns_setserver_callback (store_dnsserver_info ) != ERR_OK ) {
566
+ ESP_LOGE (TAG , "Feiled to configure DNS set server callback" );
567
+ return ESP_FAIL ;
568
+ }
569
+ #endif
549
570
}
550
571
551
572
#if !LWIP_TCPIP_CORE_LOCKING
@@ -1072,11 +1093,7 @@ static esp_err_t esp_netif_start_api(esp_netif_api_msg_t *msg)
1072
1093
ESP_LOGD (TAG , "%s %p" , __func__ , esp_netif );
1073
1094
if (ESP_NETIF_IS_POINT2POINT_TYPE (esp_netif , PPP_LWIP_NETIF )) {
1074
1095
#if CONFIG_PPP_SUPPORT
1075
- esp_err_t ret = esp_netif_start_ppp (esp_netif );
1076
- if (ret == ESP_OK ) {
1077
- esp_netif_update_default_netif (esp_netif , ESP_NETIF_STARTED );
1078
- }
1079
- return ret ;
1096
+ return esp_netif_start_ppp (esp_netif );
1080
1097
#endif
1081
1098
}
1082
1099
@@ -1153,8 +1170,10 @@ static esp_err_t esp_netif_start_api(esp_netif_api_msg_t *msg)
1153
1170
LOG_NETIF_DISABLED_AND_DO ("IPv4's DHCP Client" , return ESP_ERR_NOT_SUPPORTED );
1154
1171
#endif
1155
1172
}
1156
-
1157
- esp_netif_update_default_netif (esp_netif , ESP_NETIF_STARTED );
1173
+ // For netifs with (active) DHCP client: we update the default netif after getting a valid IP
1174
+ if (!((esp_netif -> flags & ESP_NETIF_DHCP_CLIENT ) && esp_netif -> dhcpc_status != ESP_NETIF_DHCP_STOPPED )) {
1175
+ esp_netif_update_default_netif (esp_netif , ESP_NETIF_STARTED );
1176
+ }
1158
1177
1159
1178
return ESP_OK ;
1160
1179
}
@@ -1303,7 +1322,7 @@ static void esp_netif_internal_dhcpc_cb(struct netif *netif)
1303
1322
if (memcmp (ip_info , ip_info_old , sizeof (esp_netif_ip_info_t ))) {
1304
1323
evt .ip_changed = true;
1305
1324
}
1306
-
1325
+ esp_netif_update_default_netif ( esp_netif , ESP_NETIF_GOT_IP );
1307
1326
memcpy (& evt .ip_info , ip_info , sizeof (esp_netif_ip_info_t ));
1308
1327
memcpy (ip_info_old , ip_info , sizeof (esp_netif_ip_info_t ));
1309
1328
ESP_LOGD (TAG , "if%p ip changed=%d" , esp_netif , evt .ip_changed );
@@ -1344,7 +1363,7 @@ static void esp_netif_ip_lost_timer(void *arg)
1344
1363
.esp_netif = esp_netif ,
1345
1364
};
1346
1365
int ret ;
1347
-
1366
+ esp_netif_update_default_netif ( esp_netif , ESP_NETIF_LOST_IP );
1348
1367
ESP_LOGD (TAG , "if%p ip lost tmr: raise ip lost event" , esp_netif );
1349
1368
memset (esp_netif -> ip_info_old , 0 , sizeof (esp_netif_ip_info_t ));
1350
1369
if (esp_netif -> lost_ip_event ) {
@@ -1663,7 +1682,10 @@ static esp_err_t esp_netif_up_api(esp_netif_api_msg_t *msg)
1663
1682
netif_set_up (lwip_netif );
1664
1683
netif_set_link_up (lwip_netif );
1665
1684
1666
- esp_netif_update_default_netif (esp_netif , ESP_NETIF_STARTED );
1685
+ // For netifs with (active) DHCP client: we update the default netif after getting a valid IP
1686
+ if (!((esp_netif -> flags & ESP_NETIF_DHCP_CLIENT ) && esp_netif -> dhcpc_status != ESP_NETIF_DHCP_STOPPED )) {
1687
+ esp_netif_update_default_netif (esp_netif , ESP_NETIF_STARTED );
1688
+ }
1667
1689
1668
1690
return ESP_OK ;
1669
1691
}
@@ -1842,7 +1864,7 @@ static esp_err_t esp_netif_set_ip_info_api(esp_netif_api_msg_t *msg)
1842
1864
if (memcmp (ip_info , esp_netif -> ip_info_old , sizeof (esp_netif_ip_info_t ))) {
1843
1865
evt .ip_changed = true;
1844
1866
}
1845
-
1867
+ esp_netif_update_default_netif ( esp_netif , ESP_NETIF_GOT_IP );
1846
1868
memcpy (& evt .ip_info , ip_info , sizeof (esp_netif_ip_info_t ));
1847
1869
memcpy (esp_netif -> ip_info_old , ip_info , sizeof (esp_netif_ip_info_t ));
1848
1870
ret = esp_event_post (IP_EVENT , evt_id , & evt , sizeof (evt ), 0 );
@@ -1903,7 +1925,7 @@ static esp_err_t esp_netif_set_dns_info_api(esp_netif_api_msg_t *msg)
1903
1925
1904
1926
ip_addr_t lwip_ip = {};
1905
1927
ESPIP_TO_IP (& dns -> ip , & lwip_ip );
1906
- if (esp_netif -> flags & ESP_NETIF_DHCP_SERVER ) {
1928
+ if (esp_netif && esp_netif -> flags & ESP_NETIF_DHCP_SERVER ) {
1907
1929
#if ESP_DHCPS
1908
1930
// if DHCP server configured to set DNS in dhcps API
1909
1931
if (type != ESP_NETIF_DNS_MAIN ) {
@@ -1916,17 +1938,29 @@ static esp_err_t esp_netif_set_dns_info_api(esp_netif_api_msg_t *msg)
1916
1938
LOG_NETIF_DISABLED_AND_DO ("DHCP Server" , return ESP_ERR_NOT_SUPPORTED );
1917
1939
#endif
1918
1940
} else {
1941
+ #ifdef CONFIG_ESP_NETIF_SET_DNS_PER_DEFAULT_NETIF
1942
+ if (esp_netif ) {
1943
+ store_dnsserver_info (esp_netif -> lwip_netif , type , & lwip_ip );
1944
+ }
1945
+ if (esp_netif == s_last_default_esp_netif || // if this is the default one -> need to update global DNS servers
1946
+ esp_netif == NULL ) { // if the netif ptr is set to NULL -> we explicitly require the update
1947
+ dns_setserver (type , & lwip_ip );
1948
+ }
1949
+ #else
1919
1950
dns_setserver (type , & lwip_ip );
1951
+ #endif
1920
1952
}
1921
1953
1922
1954
return ESP_OK ;
1923
1955
}
1924
1956
1925
1957
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 )
1926
1958
{
1959
+ #ifndef CONFIG_ESP_NETIF_SET_DNS_PER_DEFAULT_NETIF
1927
1960
if (esp_netif == NULL ) {
1928
1961
return ESP_ERR_ESP_NETIF_INVALID_PARAMS ;
1929
1962
}
1963
+ #endif
1930
1964
1931
1965
if (dns == NULL ) {
1932
1966
ESP_LOGD (TAG , "set dns null dns" );
@@ -1954,7 +1988,7 @@ static esp_err_t esp_netif_get_dns_info_api(esp_netif_api_msg_t *msg)
1954
1988
1955
1989
ESP_LOGD (TAG , "esp_netif_get_dns_info: esp_netif=%p type=%d" , esp_netif , type );
1956
1990
1957
- if (esp_netif -> flags & ESP_NETIF_DHCP_SERVER ) {
1991
+ if (esp_netif && esp_netif -> flags & ESP_NETIF_DHCP_SERVER ) {
1958
1992
#if ESP_DHCPS
1959
1993
ip4_addr_t dns_ip ;
1960
1994
dhcps_dns_getserver (esp_netif -> dhcps , & dns_ip );
@@ -1965,7 +1999,15 @@ static esp_err_t esp_netif_get_dns_info_api(esp_netif_api_msg_t *msg)
1965
1999
#endif
1966
2000
} else {
1967
2001
const ip_addr_t * dns_ip = NULL ;
2002
+ #ifdef CONFIG_ESP_NETIF_SET_DNS_PER_DEFAULT_NETIF
2003
+ if (esp_netif == NULL ) { // by setting esp_netif to NULL we require the global DNS server entry
2004
+ dns_ip = dns_getserver (type );
2005
+ } else {
2006
+ dns_ip = & esp_netif -> dns [type ];
2007
+ }
2008
+ #else
1968
2009
dns_ip = dns_getserver (type );
2010
+ #endif
1969
2011
if (dns_ip != NULL ) {
1970
2012
IP_TO_ESPIP (dns_ip , & dns -> ip );
1971
2013
}
@@ -1976,9 +2018,11 @@ static esp_err_t esp_netif_get_dns_info_api(esp_netif_api_msg_t *msg)
1976
2018
1977
2019
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 )
1978
2020
{
2021
+ #ifndef CONFIG_ESP_NETIF_SET_DNS_PER_DEFAULT_NETIF
1979
2022
if (esp_netif == NULL ) {
1980
2023
return ESP_ERR_ESP_NETIF_INVALID_PARAMS ;
1981
2024
}
2025
+ #endif
1982
2026
1983
2027
if (dns == NULL ) {
1984
2028
ESP_LOGE (TAG , "%s: dns_info cannot be NULL" , __func__ );
@@ -2074,7 +2118,7 @@ static void esp_netif_internal_nd6_cb(struct netif *netif, uint8_t ip_index)
2074
2118
ESP_LOGW (TAG ,"CONFIG_LWIP_ESP_MLDV6_REPORT not enabled, but esp-netif configured with ESP_NETIF_FLAG_MLDV6_REPORT" );
2075
2119
#endif
2076
2120
}
2077
-
2121
+ esp_netif_update_default_netif ( esp_netif , ESP_NETIF_GOT_IP );
2078
2122
memcpy (& evt .ip6_info , & ip6_info , sizeof (esp_netif_ip6_info_t ));
2079
2123
int ret = esp_event_post (IP_EVENT , IP_EVENT_GOT_IP6 , & evt , sizeof (evt ), 0 );
2080
2124
if (ESP_OK != ret ) {
@@ -2516,15 +2560,6 @@ esp_err_t esp_netif_ppp_set_auth(esp_netif_t *esp_netif, esp_netif_auth_type_t a
2516
2560
{
2517
2561
set_auth_msg_t msg = { .authtype = authtype , .user = user , .passwd = passwd };
2518
2562
return esp_netif_lwip_ipc_call (esp_netif_ppp_set_auth_api , esp_netif , & msg );
2519
- #if PPP_AUTH_SUPPORT
2520
- lwip_peer2peer_ctx_t * ppp_ctx = (lwip_peer2peer_ctx_t * )netif -> related_data ;
2521
- assert (ppp_ctx -> base .netif_type == PPP_LWIP_NETIF );
2522
- pppapi_set_auth (ppp_ctx -> ppp , authtype , user , passwd );
2523
- return ESP_OK ;
2524
- #else
2525
- ESP_LOGE (TAG , "%s failed: No authorisation enabled in menuconfig" , __func__ );
2526
- return ESP_ERR_ESP_NETIF_IF_NOT_READY ;
2527
- #endif
2528
2563
}
2529
2564
2530
2565
esp_err_t esp_netif_napt_disable (esp_netif_t * esp_netif )
@@ -2613,7 +2648,7 @@ static esp_err_t esp_netif_add_ip6_address_api(esp_netif_api_msg_t *msg)
2613
2648
err_t err = netif_add_ip6_address (msg -> esp_netif -> lwip_netif , & ip6addr , & index );
2614
2649
ESP_RETURN_ON_FALSE (err == ERR_OK && index >= 0 , ESP_ERR_ESP_NETIF_IP6_ADDR_FAILED , TAG ,
2615
2650
"Failed to add ip6 address" );
2616
-
2651
+ esp_netif_update_default_netif ( msg -> esp_netif , ESP_NETIF_GOT_IP );
2617
2652
netif_ip6_addr_set_state (msg -> esp_netif -> lwip_netif , index ,
2618
2653
addr -> preferred ? IP6_ADDR_PREFERRED : IP6_ADDR_DEPRECATED );
2619
2654
ip_event_got_ip6_t evt = {.esp_netif = msg -> esp_netif , .ip_index = index };
0 commit comments