Skip to content

Commit

Permalink
Don't claim minimal mdns is initialized until it's advertising on som…
Browse files Browse the repository at this point in the history
…e IPv6 interface. (#25173)

This fixes two things:

1. We now don't consider advertising properly initialized until we are
   advertising on at least one ipv6 interface.

2. Actually check which sorts of addresses interfaces have, instead of
   just assuming that all interfaces have both IPv4 and IPv6 addresses.

Fixes #25013
  • Loading branch information
bzbarsky-apple authored and pull[bot] committed Aug 15, 2023
1 parent a2dec18 commit 1574353
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 8 deletions.
42 changes: 36 additions & 6 deletions src/lib/dnssd/minimal_mdns/AddressPolicy_DefaultImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,23 +69,38 @@ class AllInterfaces : public mdns::Minimal::ListenIterator
#if INET_CONFIG_ENABLE_IPV4
if (mState == State::kIpV4)
{
*id = mIterator.GetInterfaceId();
*type = chip::Inet::IPAddressType::kIPv4;
mState = State::kIpV6;
return true;

if (CurrentInterfaceHasAddressOfType(chip::Inet::IPAddressType::kIPv4))
{
*id = mIterator.GetInterfaceId();
*type = chip::Inet::IPAddressType::kIPv4;
return true;
}
}
#endif

*id = mIterator.GetInterfaceId();
*type = chip::Inet::IPAddressType::kIPv6;
#if INET_CONFIG_ENABLE_IPV4
mState = State::kIpV4;
#endif

bool haveResult = CurrentInterfaceHasAddressOfType(chip::Inet::IPAddressType::kIPv6);
if (haveResult)
{
*id = mIterator.GetInterfaceId();
*type = chip::Inet::IPAddressType::kIPv6;
}

for (mIterator.Next(); SkipCurrentInterface(); mIterator.Next())
{
}
return true;

if (haveResult)
{
return true;
}

return Next(id, type);
}

private:
Expand Down Expand Up @@ -119,6 +134,8 @@ class AllInterfaces : public mdns::Minimal::ListenIterator

return !IsCurrentInterfaceUsable(mIterator);
}

bool CurrentInterfaceHasAddressOfType(chip::Inet::IPAddressType type);
};

class AllAddressesIterator : public mdns::Minimal::IpAddressIterator
Expand Down Expand Up @@ -170,6 +187,19 @@ class AllAddressesIterator : public mdns::Minimal::IpAddressIterator
chip::Inet::InterfaceAddressIterator mIterator;
};

bool AllInterfaces::CurrentInterfaceHasAddressOfType(chip::Inet::IPAddressType type)
{
// mIterator.HasCurrent() must be true here.
AllAddressesIterator addressIter(mIterator.GetInterfaceId(), type);
chip::Inet::IPAddress addr;
if (addressIter.Next(addr))
{
return true;
}

return false;
}

class DefaultAddressPolicy : public AddressPolicy
{
public:
Expand Down
4 changes: 2 additions & 2 deletions src/lib/dnssd/minimal_mdns/Server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -279,8 +279,8 @@ CHIP_ERROR ServerBase::Listen(chip::Inet::EndPointManager<chip::Inet::UDPEndPoin
}
#endif

// If at least one interface is used by the mDNS server, notify the application that DNS-SD is ready.
if (!mIsInitialized)
// If at least one IPv6 interface is used by the mDNS server, notify the application that DNS-SD is ready.
if (!mIsInitialized && addressType == chip::Inet::IPAddressType::kIPv6)
{
#if !CHIP_DEVICE_LAYER_NONE
chip::DeviceLayer::ChipDeviceEvent event{};
Expand Down

0 comments on commit 1574353

Please sign in to comment.