Skip to content

Commit

Permalink
MinMDNS skip interfaces without IPv4 addresses
Browse files Browse the repository at this point in the history
IPv4 multicast require an IPv4 address to be present on a particular
interface. Skip interfaces without IPv4 addresses in the default
address policy. This avoids errors when trying to join the multicast
group later on:
MDNS failed to join multicast group on veth3cdf62f for address type IPv4: src/inet/UDPEndPointImplSockets.cpp:777: Inet Error 0x00000110: Address not found
  • Loading branch information
agners committed Feb 28, 2024
1 parent 6f621f2 commit 5977bf2
Showing 1 changed file with 38 additions and 4 deletions.
42 changes: 38 additions & 4 deletions src/lib/dnssd/minimal_mdns/AddressPolicy_LibNlImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ class AllListenIterator : public mdns::Minimal::ListenIterator

nl_sock * mNlSocket = nullptr;
nl_cache * mNlCache = nullptr;
nl_cache * mNlAddrCache = nullptr;
nl_object * mCurrentLink = nullptr;
IPAddressType mCurrentLinkType = IPAddressType::kUnknown;

Expand Down Expand Up @@ -94,6 +95,12 @@ AllListenIterator::~AllListenIterator()
mNlCache = nullptr;
}

if (mNlAddrCache != nullptr)
{
nl_cache_free(mNlAddrCache);
mNlAddrCache = nullptr;
}

if (mNlSocket != nullptr)
{
nl_socket_free(mNlSocket);
Expand Down Expand Up @@ -151,7 +158,6 @@ bool AllListenIterator::Next(InterfaceId * id, IPAddressType * type)
while (true)
{
#if INET_CONFIG_ENABLE_IPV4
// FOR IPv4, report all interfaces as 'try IPv4 here as well'
if (mCurrentLinkType == IPAddressType::kIPv6)
{
mCurrentLinkType = IPAddressType::kIPv4;
Expand All @@ -176,14 +182,42 @@ bool AllListenIterator::Next(InterfaceId * id, IPAddressType * type)
continue;
}

int idx = rtnl_link_get_ifindex(CurrentLink());
if (idx == 0)
int ifindex = rtnl_link_get_ifindex(CurrentLink());
if (ifindex == 0)
{
// Invalid index, move to the next interface
continue;
}

*id = InterfaceId(idx);
// For IPv4, report only interfaces which have an IPv4 address
if (mCurrentLinkType == IPAddressType::kIPv4)
{
if (mNlAddrCache == nullptr)
{
int result = rtnl_addr_alloc_cache(mNlSocket, &mNlAddrCache);
if (result != 0)
{
ChipLogError(Inet, "Failed to cache addresses");
return false;
}
}

// Find IPv4 address for this interface
struct rtnl_addr *filter = rtnl_addr_alloc();
rtnl_addr_set_family(filter, AF_INET);
rtnl_addr_set_ifindex(filter, ifindex);

struct nl_object *addr = nl_cache_find(mNlAddrCache, OBJ_CAST(filter));
nl_object_put(OBJ_CAST(filter));

// No IPv4 address, skip this interface for IPv4.
if (addr == nullptr)
continue;

nl_object_put(addr);
}

*id = InterfaceId(ifindex);
*type = mCurrentLinkType; // advancing should have set this
return true;
}
Expand Down

0 comments on commit 5977bf2

Please sign in to comment.