From 9806de304e2ea0925e014a9048bb7e1884242b1b Mon Sep 17 00:00:00 2001 From: me-no-dev Date: Mon, 6 Jan 2025 10:42:53 +0200 Subject: [PATCH 1/2] fix(udp): Add missing LwIP locks to init multicast --- libraries/AsyncUDP/src/AsyncUDP.cpp | 32 ++++++++++++++++++----------- 1 file changed, 20 insertions(+), 12 deletions(-) diff --git a/libraries/AsyncUDP/src/AsyncUDP.cpp b/libraries/AsyncUDP/src/AsyncUDP.cpp index 48714bce5c5..e2c63f76a12 100644 --- a/libraries/AsyncUDP/src/AsyncUDP.cpp +++ b/libraries/AsyncUDP/src/AsyncUDP.cpp @@ -601,76 +601,84 @@ static esp_err_t joinMulticastGroup(const ip_addr_t *addr, bool join, tcpip_adap return ESP_ERR_INVALID_ARG; } netif = (struct netif *)nif; + UDP_MUTEX_LOCK(); #if CONFIG_LWIP_IPV6 if (addr->type == IPADDR_TYPE_V4) { if (join) { if (igmp_joingroup_netif(netif, (const ip4_addr *)&(addr->u_addr.ip4))) { - return ESP_ERR_INVALID_STATE; + goto igmp_fail; } } else { if (igmp_leavegroup_netif(netif, (const ip4_addr *)&(addr->u_addr.ip4))) { - return ESP_ERR_INVALID_STATE; + goto igmp_fail; } } } else { if (join) { if (mld6_joingroup_netif(netif, &(addr->u_addr.ip6))) { - return ESP_ERR_INVALID_STATE; + goto igmp_fail; } } else { if (mld6_leavegroup_netif(netif, &(addr->u_addr.ip6))) { - return ESP_ERR_INVALID_STATE; + goto igmp_fail; } } } #else if (join) { if (igmp_joingroup_netif(netif, (const ip4_addr *)(addr))) { - return ESP_ERR_INVALID_STATE; + goto igmp_fail; } } else { if (igmp_leavegroup_netif(netif, (const ip4_addr *)(addr))) { - return ESP_ERR_INVALID_STATE; + goto igmp_fail; } } #endif + UDP_MUTEX_UNLOCK(); } else { + UDP_MUTEX_LOCK(); #if CONFIG_LWIP_IPV6 if (addr->type == IPADDR_TYPE_V4) { if (join) { if (igmp_joingroup((const ip4_addr *)IP4_ADDR_ANY, (const ip4_addr *)&(addr->u_addr.ip4))) { - return ESP_ERR_INVALID_STATE; + goto igmp_fail; } } else { if (igmp_leavegroup((const ip4_addr *)IP4_ADDR_ANY, (const ip4_addr *)&(addr->u_addr.ip4))) { - return ESP_ERR_INVALID_STATE; + goto igmp_fail; } } } else { if (join) { if (mld6_joingroup((const ip6_addr *)IP6_ADDR_ANY, &(addr->u_addr.ip6))) { - return ESP_ERR_INVALID_STATE; + goto igmp_fail; } } else { if (mld6_leavegroup((const ip6_addr *)IP6_ADDR_ANY, &(addr->u_addr.ip6))) { - return ESP_ERR_INVALID_STATE; + goto igmp_fail; } } } #else if (join) { if (igmp_joingroup((const ip4_addr *)IP4_ADDR_ANY, (const ip4_addr *)(addr))) { - return ESP_ERR_INVALID_STATE; + goto igmp_fail; } } else { if (igmp_leavegroup((const ip4_addr *)IP4_ADDR_ANY, (const ip4_addr *)(addr))) { - return ESP_ERR_INVALID_STATE; + goto igmp_fail; } } #endif + UDP_MUTEX_UNLOCK(); } return ESP_OK; + +igmp_fail: + UDP_MUTEX_UNLOCK(); + return ESP_ERR_INVALID_STATE; } bool AsyncUDP::listenMulticast(const ip_addr_t *addr, uint16_t port, uint8_t ttl, tcpip_adapter_if_t tcpip_if) { From a8584138fcb6975de8b1a2c3b37904ea25443706 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci-lite[bot]" <117423508+pre-commit-ci-lite[bot]@users.noreply.github.com> Date: Tue, 7 Jan 2025 09:47:32 +0000 Subject: [PATCH 2/2] ci(pre-commit): Apply automatic fixes --- libraries/AsyncUDP/src/AsyncUDP.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libraries/AsyncUDP/src/AsyncUDP.cpp b/libraries/AsyncUDP/src/AsyncUDP.cpp index e2c63f76a12..f44cc839c97 100644 --- a/libraries/AsyncUDP/src/AsyncUDP.cpp +++ b/libraries/AsyncUDP/src/AsyncUDP.cpp @@ -675,7 +675,7 @@ static esp_err_t joinMulticastGroup(const ip_addr_t *addr, bool join, tcpip_adap UDP_MUTEX_UNLOCK(); } return ESP_OK; - + igmp_fail: UDP_MUTEX_UNLOCK(); return ESP_ERR_INVALID_STATE;