mdns: fix preset of esp_netif ptr for local interfaces
mdns module store local copy of esp_netif for common interfaces,
but it was correctly initialized only when interface started.
If the event were missed (e.g. mdns_init after interface start)
the local copy wouldn't be initialized. Fixed by restoring the local
copy.
Closes
@@ -56,6 +56,18 @@ static esp_netif_t * s_esp_netifs[MDNS_IF_MAX] = {};
esp_netif_t *_mdns_get_esp_netif(mdns_if_t tcpip_if)
{
if (tcpip_if < MDNS_IF_MAX) {
+ if (s_esp_netifs[tcpip_if] == NULL) {
+ // if local netif copy is NULL, try to search for the default interface key
+ if (tcpip_if == MDNS_IF_STA) {
+ s_esp_netifs[MDNS_IF_STA] = esp_netif_get_handle_from_ifkey("WIFI_STA_DEF");
+ } else if (tcpip_if == MDNS_IF_AP) {
+ s_esp_netifs[MDNS_IF_AP] = esp_netif_get_handle_from_ifkey("WIFI_AP_DEF");
+#if CONFIG_ETH_ENABLED
+ } else if (tcpip_if == MDNS_IF_ETH) {
+ s_esp_netifs[MDNS_IF_ETH] = esp_netif_get_handle_from_ifkey("ETH_DEF");
+#endif
+ }
+ }
return s_esp_netifs[tcpip_if];
}
return NULL;
@@ -3106,17 +3118,6 @@ static void _mdns_handle_system_event(esp_event_base_t event_base,
return;
}
- // Initialize handles to esp-netif if appropriate mdns supported interface started
- if (event_base == WIFI_EVENT && event_id == WIFI_EVENT_STA_START) {
- s_esp_netifs[MDNS_IF_STA] = esp_netif_get_handle_from_ifkey("WIFI_STA_DEF");
- } else if (event_base == WIFI_EVENT && event_id == WIFI_EVENT_AP_START) {
- s_esp_netifs[MDNS_IF_AP] = esp_netif_get_handle_from_ifkey("WIFI_AP_DEF");
-#if CONFIG_ETH_ENABLED
- } else if (event_base == ETH_EVENT && event_id == ETHERNET_EVENT_START) {
- s_esp_netifs[MDNS_IF_ETH] = esp_netif_get_handle_from_ifkey("ETH_DEF");
-#endif
- }
-
esp_netif_dhcp_status_t dcst;
if (event_base == WIFI_EVENT) {
switch(event_id) {
@@ -4231,6 +4232,8 @@ esp_err_t mdns_init(void)
return ESP_ERR_NO_MEM;
}
memset((uint8_t*)_mdns_server, 0, sizeof(mdns_server_t));
+ // zero-out local copy of netifs to initiate a fresh search by interface key whenever a netif ptr is needed
+ memset(s_esp_netifs, 0, sizeof(s_esp_netifs));
_mdns_server->lock = xSemaphoreCreateMutex();
if (!_mdns_server->lock) {
