From 7f410a0bcbafa85dba05807c53c3c38999506509 Mon Sep 17 00:00:00 2001 From: David Cermak Date: Tue, 8 Oct 2019 19:53:56 +0200 Subject: [PATCH] mdns: fix possible race condition when checking DHCP status on WIFI_EVENT_STA_CONNECTED event. 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 | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/components/mdns/mdns.c b/components/mdns/mdns.c index b34452ba0f..d4a68963c4 100644 --- a/components/mdns/mdns.c +++ b/components/mdns/mdns.c @@ -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); } } -- 2.40.0