]> granicus.if.org Git - esp-idf/commitdiff
mdns: fixed crashes on network changes
authorDavid Cermak <cermak@espressif.com>
Mon, 22 Oct 2018 14:45:42 +0000 (16:45 +0200)
committerDavid Cermak <cermak@espressif.com>
Wed, 24 Oct 2018 10:03:41 +0000 (12:03 +0200)
1) two events AP_STOP, AP_START shortly after each other may cause IGMP config on already stopped netif
2) not properly locked sending packets to queue from timer task

closes #2580

components/mdns/mdns.c
components/mdns/mdns_networking.c
components/tcpip_adapter/include/tcpip_adapter.h
components/tcpip_adapter/tcpip_adapter_lwip.c

index 38d678268af0e7144211a3027d32388ed8c8378d..443b39846a66aea15fc6a5e9e08c4995832ca21e 100644 (file)
@@ -3794,13 +3794,14 @@ static esp_err_t _mdns_send_search_action(mdns_action_type_t type, mdns_search_o
  */
 static void _mdns_scheduler_run()
 {
+    MDNS_SERVICE_LOCK();
     mdns_tx_packet_t * p = _mdns_server->tx_queue_head;
     mdns_action_t * action = NULL;
 
     if (!p) {
+        MDNS_SERVICE_UNLOCK();
         return;
     }
-    MDNS_SERVICE_LOCK();
     if ((int32_t)(p->send_at - (xTaskGetTickCount() * portTICK_PERIOD_MS)) < 0) {
         action = (mdns_action_t *)malloc(sizeof(mdns_action_t));
         if (action) {
index 4e64e36cf61f81600fa7349e9dbfdcdb971a3e6e..9aac3ec8991a93fff8eac83a8be0b8fc57057507 100644 (file)
@@ -62,6 +62,12 @@ static esp_err_t _udp_join_group(tcpip_adapter_if_t tcpip_if, mdns_ip_protocol_t
 {
     struct netif * netif = NULL;
     void * nif = NULL;
+
+    if (!tcpip_adapter_is_netif_up(tcpip_if)) {
+        // Network interface went down before event propagated, skipping IGMP config
+        return ESP_ERR_INVALID_STATE;
+    }
+
     esp_err_t err = tcpip_adapter_get_netif(tcpip_if, &nif);
     if (err) {
         return ESP_ERR_INVALID_ARG;
index 205c05fab6b364d958896c3c57f73b30d4e682b2..7d9e4ad8cd1cf873fba29672775ec1d1da55f1ba 100644 (file)
@@ -618,6 +618,16 @@ esp_err_t tcpip_adapter_get_hostname(tcpip_adapter_if_t tcpip_if, const char **h
  */
 esp_err_t tcpip_adapter_get_netif(tcpip_adapter_if_t tcpip_if, void ** netif);
 
+/**
+ * @brief  Test if supplied interface is up or down
+ *
+ * @param[in]   tcpip_if: the interface which we will get the hostname
+ *
+ * @return  true:  tcpip_if is UP
+ *          false: tcpip_if id DOWN
+ */
+bool tcpip_adapter_is_netif_up(tcpip_adapter_if_t tcpip_if);
+
 #ifdef __cplusplus
 }
 #endif
index 85a76da815ab574fa937890fe1b0cdf4c33967f6..f1c32b0e5e7224dce49965dea75664516a8bd67d 100644 (file)
@@ -1222,4 +1222,13 @@ esp_err_t tcpip_adapter_get_netif(tcpip_adapter_if_t tcpip_if, void ** netif)
     return ESP_OK;
 }
 
+bool tcpip_adapter_is_netif_up(tcpip_adapter_if_t tcpip_if)
+{
+    if (esp_netif[tcpip_if] != NULL && netif_is_up(esp_netif[tcpip_if])) {
+        return true;
+    } else {
+        return false;
+    }
+}
+
 #endif /* CONFIG_TCPIP_LWIP */