From c5f3eb08e708b6d9a84926bd4b49b2918c778abe Mon Sep 17 00:00:00 2001 From: rosahay-silabs Date: Thu, 30 Jun 2022 03:48:10 +0530 Subject: [PATCH 1/7] Adds fix for IPV6 multicast --- src/inet/UDPEndPointImplLwIP.cpp | 2 +- src/lwip/efr32/lwipopts-rs911x.h | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/src/inet/UDPEndPointImplLwIP.cpp b/src/inet/UDPEndPointImplLwIP.cpp index b3ce8a24705eb1..62a2a5549e18ef 100644 --- a/src/inet/UDPEndPointImplLwIP.cpp +++ b/src/inet/UDPEndPointImplLwIP.cpp @@ -133,7 +133,7 @@ CHIP_ERROR UDPEndPointImplLwIP::LwIPBindInterface(struct udp_pcb * aUDP, Interfa InterfaceId UDPEndPointImplLwIP::GetBoundInterface() const { #if HAVE_LWIP_UDP_BIND_NETIF - return InterfaceId(netif_get_by_index(mUDP->netif_idx)); + return InterfaceId(netif_get_by_index(mUDP->netif_idx + 1)); #else return InterfaceId(mUDP->intf_filter); #endif diff --git a/src/lwip/efr32/lwipopts-rs911x.h b/src/lwip/efr32/lwipopts-rs911x.h index 5f84181387a69f..c866909e8d5a71 100644 --- a/src/lwip/efr32/lwipopts-rs911x.h +++ b/src/lwip/efr32/lwipopts-rs911x.h @@ -101,6 +101,7 @@ #define LWIP_IPV6_AUTOCONFIG (1) #define LWIP_IPV6_ROUTER_SUPPORT 1 #define LWIP_ND6_LISTEN_RA 1 +#define LWIP_IPV6_MLD 1 #define LWIP_ND6_NUM_NEIGHBORS (2) #define LWIP_ND6_NUM_DESTINATIONS (3) @@ -150,9 +151,7 @@ #define LWIP_IPV6_NUM_ADDRESSES 5 -#ifndef LWIP_IPV6_ND #define LWIP_IPV6_ND 1 -#endif #define LWIP_ND6_QUEUEING 1 #define LWIP_NUM_ND6_QUEUE 3 From 841e563927280447effab2fb420b974f59d27b32 Mon Sep 17 00:00:00 2001 From: rosahay-silabs Date: Thu, 30 Jun 2022 19:44:09 +0530 Subject: [PATCH 2/7] Revert LwIP options --- src/lwip/efr32/lwipopts-rs911x.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/lwip/efr32/lwipopts-rs911x.h b/src/lwip/efr32/lwipopts-rs911x.h index c866909e8d5a71..5f84181387a69f 100644 --- a/src/lwip/efr32/lwipopts-rs911x.h +++ b/src/lwip/efr32/lwipopts-rs911x.h @@ -101,7 +101,6 @@ #define LWIP_IPV6_AUTOCONFIG (1) #define LWIP_IPV6_ROUTER_SUPPORT 1 #define LWIP_ND6_LISTEN_RA 1 -#define LWIP_IPV6_MLD 1 #define LWIP_ND6_NUM_NEIGHBORS (2) #define LWIP_ND6_NUM_DESTINATIONS (3) @@ -151,7 +150,9 @@ #define LWIP_IPV6_NUM_ADDRESSES 5 +#ifndef LWIP_IPV6_ND #define LWIP_IPV6_ND 1 +#endif #define LWIP_ND6_QUEUEING 1 #define LWIP_NUM_ND6_QUEUE 3 From b71053814e7bbfe6ef5249dd5c95bb06f13538e0 Mon Sep 17 00:00:00 2001 From: rosahay-silabs Date: Thu, 30 Jun 2022 19:45:37 +0530 Subject: [PATCH 3/7] Adds fix for warning on ESP32 toolchain --- src/inet/UDPEndPointImplLwIP.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/inet/UDPEndPointImplLwIP.cpp b/src/inet/UDPEndPointImplLwIP.cpp index 62a2a5549e18ef..a81b3922492ce2 100644 --- a/src/inet/UDPEndPointImplLwIP.cpp +++ b/src/inet/UDPEndPointImplLwIP.cpp @@ -133,7 +133,7 @@ CHIP_ERROR UDPEndPointImplLwIP::LwIPBindInterface(struct udp_pcb * aUDP, Interfa InterfaceId UDPEndPointImplLwIP::GetBoundInterface() const { #if HAVE_LWIP_UDP_BIND_NETIF - return InterfaceId(netif_get_by_index(mUDP->netif_idx + 1)); + return InterfaceId(netif_get_by_index(++(mUDP->netif_idx))); #else return InterfaceId(mUDP->intf_filter); #endif From 087af03263b38057a7657c7e8626a1d5a6ddcdc7 Mon Sep 17 00:00:00 2001 From: rosahay-silabs Date: Wed, 6 Jul 2022 21:48:42 +0530 Subject: [PATCH 4/7] Adds changes to incorporate InterfaceId:Null() for LWIP --- src/inet/UDPEndPointImplLwIP.cpp | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/src/inet/UDPEndPointImplLwIP.cpp b/src/inet/UDPEndPointImplLwIP.cpp index a81b3922492ce2..c16716f9aa6424 100644 --- a/src/inet/UDPEndPointImplLwIP.cpp +++ b/src/inet/UDPEndPointImplLwIP.cpp @@ -133,7 +133,7 @@ CHIP_ERROR UDPEndPointImplLwIP::LwIPBindInterface(struct udp_pcb * aUDP, Interfa InterfaceId UDPEndPointImplLwIP::GetBoundInterface() const { #if HAVE_LWIP_UDP_BIND_NETIF - return InterfaceId(netif_get_by_index(++(mUDP->netif_idx))); + return InterfaceId(netif_get_by_index(mUDP->netif_idx)); #else return InterfaceId(mUDP->intf_filter); #endif @@ -431,13 +431,20 @@ CHIP_ERROR UDPEndPointImplLwIP::IPv4JoinLeaveMulticastGroupImpl(InterfaceId aInt CHIP_ERROR UDPEndPointImplLwIP::IPv6JoinLeaveMulticastGroupImpl(InterfaceId aInterfaceId, const IPAddress & aAddress, bool join) { #ifdef HAVE_IPV6_MULTICAST - const auto method = join ? mld6_joingroup_netif : mld6_leavegroup_netif; - - struct netif * const lNetif = FindNetifFromInterfaceId(aInterfaceId); - VerifyOrReturnError(lNetif != nullptr, INET_ERROR_UNKNOWN_INTERFACE); - const ip6_addr_t lIPv6Address = aAddress.ToIPv6(); - const err_t lStatus = method(lNetif, &lIPv6Address); + err_t lStatus; + if (aInterfaceId.IsPresent()) + { + struct netif * const lNetif = FindNetifFromInterfaceId(aInterfaceId); + VerifyOrReturnError(lNetif != nullptr, INET_ERROR_UNKNOWN_INTERFACE); + const auto method = join ? mld6_joingroup_netif : mld6_leavegroup_netif; + lStatus = method(lNetif, &lIPv6Address); + } + else + { + const auto method = join ? mld6_joingroup : mld6_leavegroup; + lStatus = method(IP6_ADDR_ANY6, &lIPv6Address); + } if (lStatus == ERR_MEM) { return CHIP_ERROR_NO_MEMORY; From 2fa93f8fe3ecb139624e59a2273c14b58f9be821 Mon Sep 17 00:00:00 2001 From: Andrei Litvin Date: Thu, 7 Jul 2022 15:42:43 -0400 Subject: [PATCH 5/7] Add IPv4 support for non-interface join/leave group --- src/inet/UDPEndPointImplLwIP.cpp | 33 +++++++++++++++++++++++++++----- 1 file changed, 28 insertions(+), 5 deletions(-) diff --git a/src/inet/UDPEndPointImplLwIP.cpp b/src/inet/UDPEndPointImplLwIP.cpp index c16716f9aa6424..661a52d043d75c 100644 --- a/src/inet/UDPEndPointImplLwIP.cpp +++ b/src/inet/UDPEndPointImplLwIP.cpp @@ -410,13 +410,36 @@ CHIP_ERROR UDPEndPointImplLwIP::SetMulticastLoopback(IPVersion aIPVersion, bool CHIP_ERROR UDPEndPointImplLwIP::IPv4JoinLeaveMulticastGroupImpl(InterfaceId aInterfaceId, const IPAddress & aAddress, bool join) { #if LWIP_IPV4 && LWIP_IGMP - const auto method = join ? igmp_joingroup_netif : igmp_leavegroup_netif; + const ip4_addr_t lIPv4Address = aAddress.ToIPv4(); + err_t lStatus; - struct netif * const lNetif = FindNetifFromInterfaceId(aInterfaceId); - VerifyOrReturnError(lNetif != nullptr, INET_ERROR_UNKNOWN_INTERFACE); + if (aInterfaceId.IsPresent()) + { + + struct netif * const lNetif = FindNetifFromInterfaceId(aInterfaceId); + VerifyOrReturnError(lNetif != nullptr, INET_ERROR_UNKNOWN_INTERFACE); + + if (join) + { + lStatus = igmp_joingroup_netif(lNetif, &lIPv4Address); + } + else + { + lStatus = igmp_leavegroup(lNetif, &lIPv4Address); + } + } + else + { + if (join) + { + lStatus = igmp_joingroup(IP_ADDR_ANY, &lIPv4Address); + } + else + { + lStatus = igmp_leavegroup(IP_ADDR_ANY, &lIPv4Address); + } + } - const ip4_addr_t lIPv4Address = aAddress.ToIPv4(); - const err_t lStatus = method(lNetif, &lIPv4Address); if (lStatus == ERR_MEM) { return CHIP_ERROR_NO_MEMORY; From 09f1fd480c81272e11550fc2a039a0c9b8bcec7a Mon Sep 17 00:00:00 2001 From: Andrei Litvin Date: Thu, 7 Jul 2022 15:48:31 -0400 Subject: [PATCH 6/7] Fix some typos - compile tested with esp32 --- src/inet/UDPEndPointImplLwIP.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/inet/UDPEndPointImplLwIP.cpp b/src/inet/UDPEndPointImplLwIP.cpp index 661a52d043d75c..628b0d4b71c234 100644 --- a/src/inet/UDPEndPointImplLwIP.cpp +++ b/src/inet/UDPEndPointImplLwIP.cpp @@ -425,18 +425,19 @@ CHIP_ERROR UDPEndPointImplLwIP::IPv4JoinLeaveMulticastGroupImpl(InterfaceId aInt } else { - lStatus = igmp_leavegroup(lNetif, &lIPv4Address); + lStatus = igmp_leavegroup_netif(lNetif, &lIPv4Address); } } else { + if (join) { - lStatus = igmp_joingroup(IP_ADDR_ANY, &lIPv4Address); + lStatus = igmp_joingroup(IP4_ADDR_ANY4, &lIPv4Address); } else { - lStatus = igmp_leavegroup(IP_ADDR_ANY, &lIPv4Address); + lStatus = igmp_leavegroup(IP4_ADDR_ANY4, &lIPv4Address); } } From 997d14894a5f2078fd8b9779d7afd90ebf3e762f Mon Sep 17 00:00:00 2001 From: Andrei Litvin Date: Thu, 7 Jul 2022 16:14:01 -0400 Subject: [PATCH 7/7] Reformat code for readability and consistency --- src/inet/UDPEndPointImplLwIP.cpp | 30 +++++++++--------------------- 1 file changed, 9 insertions(+), 21 deletions(-) diff --git a/src/inet/UDPEndPointImplLwIP.cpp b/src/inet/UDPEndPointImplLwIP.cpp index 628b0d4b71c234..d5e90568f7af84 100644 --- a/src/inet/UDPEndPointImplLwIP.cpp +++ b/src/inet/UDPEndPointImplLwIP.cpp @@ -419,26 +419,13 @@ CHIP_ERROR UDPEndPointImplLwIP::IPv4JoinLeaveMulticastGroupImpl(InterfaceId aInt struct netif * const lNetif = FindNetifFromInterfaceId(aInterfaceId); VerifyOrReturnError(lNetif != nullptr, INET_ERROR_UNKNOWN_INTERFACE); - if (join) - { - lStatus = igmp_joingroup_netif(lNetif, &lIPv4Address); - } - else - { - lStatus = igmp_leavegroup_netif(lNetif, &lIPv4Address); - } + lStatus = join ? igmp_joingroup_netif(lNetif, &lIPv4Address) // + : igmp_leavegroup_netif(lNetif, &lIPv4Address); } else { - - if (join) - { - lStatus = igmp_joingroup(IP4_ADDR_ANY4, &lIPv4Address); - } - else - { - lStatus = igmp_leavegroup(IP4_ADDR_ANY4, &lIPv4Address); - } + lStatus = join ? igmp_joingroup(IP4_ADDR_ANY4, &lIPv4Address) // + : igmp_leavegroup(IP4_ADDR_ANY4, &lIPv4Address); } if (lStatus == ERR_MEM) @@ -461,14 +448,15 @@ CHIP_ERROR UDPEndPointImplLwIP::IPv6JoinLeaveMulticastGroupImpl(InterfaceId aInt { struct netif * const lNetif = FindNetifFromInterfaceId(aInterfaceId); VerifyOrReturnError(lNetif != nullptr, INET_ERROR_UNKNOWN_INTERFACE); - const auto method = join ? mld6_joingroup_netif : mld6_leavegroup_netif; - lStatus = method(lNetif, &lIPv6Address); + lStatus = join ? mld6_joingroup_netif(lNetif, &lIPv6Address) // + : mld6_leavegroup_netif(lNetif, &lIPv6Address); } else { - const auto method = join ? mld6_joingroup : mld6_leavegroup; - lStatus = method(IP6_ADDR_ANY6, &lIPv6Address); + lStatus = join ? mld6_joingroup(IP6_ADDR_ANY6, &lIPv6Address) // + : mld6_leavegroup(IP6_ADDR_ANY6, &lIPv6Address); } + if (lStatus == ERR_MEM) { return CHIP_ERROR_NO_MEMORY;