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
This commit is contained in:
David Cermak 2019-10-08 19:53:56 +02:00 committed by bot
parent 1007473a3b
commit 98450e80e5

View 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);
}
}