]> granicus.if.org Git - esp-idf/commitdiff
mdns: fix possible race condition when checking DHCP status on WIFI_EVENT_STA_CONNECT...
authorDavid Cermak <cermak@espressif.com>
Tue, 8 Oct 2019 17:53:56 +0000 (19:53 +0200)
committerbot <bot@espressif.com>
Tue, 15 Oct 2019 07:07:00 +0000 (07:07 +0000)
tcpip_adapter_dhcpc_get_status() returns the actual internal value of dhcp client without any locking or TCP/IP stack context call, so when CONNECTED event fired with default settings it started DHCP client in TCP/IP stack context and at the same time mdns event handler checking actual DHCP state, which could still be INIT (not STARTED). Purpose of this check is to enable PCB if DHCP was stopped before setting network interface up (typically static IP settings), so the solutin is to check against TCPIP_ADAPTER_DHCP_STOPPED state

components/mdns/mdns.c

index b34452ba0f87a57294ce734c847394ce8a5f73df..d4a68963c4389441292755800ac17374a805c1eb 100644 (file)
@@ -3062,7 +3062,7 @@ static void _mdns_handle_system_event(esp_event_base_t event_base,
         switch(event_id) {
             case WIFI_EVENT_STA_CONNECTED:
                 if (!tcpip_adapter_dhcpc_get_status(TCPIP_ADAPTER_IF_STA, &dcst)) {
-                    if (dcst != TCPIP_ADAPTER_DHCP_STARTED) {
+                    if (dcst == TCPIP_ADAPTER_DHCP_STOPPED) {
                         _mdns_enable_pcb(TCPIP_ADAPTER_IF_STA, MDNS_IP_PROTOCOL_V4);
                     }
                 }
@@ -3085,7 +3085,7 @@ static void _mdns_handle_system_event(esp_event_base_t event_base,
         switch (event_id) {
             case ETHERNET_EVENT_CONNECTED:
                 if (!tcpip_adapter_dhcpc_get_status(TCPIP_ADAPTER_IF_ETH, &dcst)) {
-                    if (dcst != TCPIP_ADAPTER_DHCP_STARTED) {
+                    if (dcst == TCPIP_ADAPTER_DHCP_STOPPED) {
                         _mdns_enable_pcb(TCPIP_ADAPTER_IF_ETH, MDNS_IP_PROTOCOL_V4);
                     }
                 }