Skip to content

Commit

Permalink
Better IPv6 handling of AddrAny (which maps to IPv4 if enabled in lwi…
Browse files Browse the repository at this point in the history
…p) (#10564)

* Better IPv6 handling of any: support both LWIP conversion if IPv6 is disabled and enabled

* Remove previous settype code

* Fix typo
  • Loading branch information
andy31415 authored Oct 18, 2021
1 parent 9b0afc4 commit 5987dab
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
4 changes: 4 additions & 0 deletions src/inet/IPAddress.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,11 @@ ip_addr_t IPAddress::ToLwIPAddr(void) const
break;

default:
#if INET_CONFIG_ENABLE_IPV4
ret = *IP_ADDR_ANY;
#else
ret = *IP6_ADDR_ANY;
#endif
break;
}

Expand Down
17 changes: 13 additions & 4 deletions src/inet/UDPEndPoint.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -134,10 +134,19 @@ CHIP_ERROR UDPEndPoint::BindImpl(IPAddressType addrType, const IPAddress & addr,
{
#if LWIP_VERSION_MAJOR > 1 || LWIP_VERSION_MINOR >= 5
ip_addr_t ipAddr = addr.ToLwIPAddr();
#if INET_CONFIG_ENABLE_IPV4
lwip_ip_addr_type lType = IPAddress::ToLwIPAddrType(addrType);
IP_SET_TYPE_VAL(ipAddr, lType);
#endif // INET_CONFIG_ENABLE_IPV4

// TODO: IPAddress ANY has only one constant state, however addrType
// has separate IPV4 and IPV6 'any' settings. This tries to correct
// for this as LWIP default if IPv4 is compiled in is to consider
// 'any == any_v4'
//
// We may want to consider having separate AnyV4 and AnyV6 constants
// inside CHIP to resolve this ambiguity
if ((addr.Type() == kIPAddressType_Any) && (addrType == kIPAddressType_IPv6))
{
ipAddr = *IP6_ADDR_ANY;
}

res = chip::System::MapErrorLwIP(udp_bind(mUDP, &ipAddr, port));
#else // LWIP_VERSION_MAJOR <= 1 && LWIP_VERSION_MINOR < 5
if (addrType == kIPAddressType_IPv6)
Expand Down

0 comments on commit 5987dab

Please sign in to comment.