Skip to content

Commit

Permalink
Adds bugfix for lwip multicast group commands (#20136)
Browse files Browse the repository at this point in the history
* Adds fix for IPV6 multicast

* Revert LwIP options

* Adds fix for warning on ESP32 toolchain

* Adds changes to incorporate InterfaceId:Null() for LWIP

* Add IPv4 support for non-interface join/leave group

* Fix some typos - compile tested with esp32

* Reformat code for readability and consistency

Co-authored-by: Andrei Litvin <[email protected]>
  • Loading branch information
rosahay-silabs and andy31415 authored Jul 8, 2022
1 parent 8ebd7f0 commit fb98787
Showing 1 changed file with 30 additions and 11 deletions.
41 changes: 30 additions & 11 deletions src/inet/UDPEndPointImplLwIP.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -410,13 +410,24 @@ 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);

lStatus = join ? igmp_joingroup_netif(lNetif, &lIPv4Address) //
: igmp_leavegroup_netif(lNetif, &lIPv4Address);
}
else
{
lStatus = join ? igmp_joingroup(IP4_ADDR_ANY4, &lIPv4Address) //
: igmp_leavegroup(IP4_ADDR_ANY4, &lIPv4Address);
}

const ip4_addr_t lIPv4Address = aAddress.ToIPv4();
const err_t lStatus = method(lNetif, &lIPv4Address);
if (lStatus == ERR_MEM)
{
return CHIP_ERROR_NO_MEMORY;
Expand All @@ -431,13 +442,21 @@ 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);
lStatus = join ? mld6_joingroup_netif(lNetif, &lIPv6Address) //
: mld6_leavegroup_netif(lNetif, &lIPv6Address);
}
else
{
lStatus = join ? mld6_joingroup(IP6_ADDR_ANY6, &lIPv6Address) //
: mld6_leavegroup(IP6_ADDR_ANY6, &lIPv6Address);
}

if (lStatus == ERR_MEM)
{
return CHIP_ERROR_NO_MEMORY;
Expand Down

0 comments on commit fb98787

Please sign in to comment.