Skip to content

Commit 1031784

Browse files
bzbarsky-applepull[bot]
authored andcommitted
Don't claim minimal mdns is initialized until it's advertising on some 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
1 parent 6de3ef3 commit 1031784

File tree

2 files changed

+38
-8
lines changed

2 files changed

+38
-8
lines changed

src/lib/dnssd/minimal_mdns/AddressPolicy_DefaultImpl.cpp

+36-6
Original file line numberDiff line numberDiff line change
@@ -69,23 +69,38 @@ class AllInterfaces : public mdns::Minimal::ListenIterator
6969
#if INET_CONFIG_ENABLE_IPV4
7070
if (mState == State::kIpV4)
7171
{
72-
*id = mIterator.GetInterfaceId();
73-
*type = chip::Inet::IPAddressType::kIPv4;
7472
mState = State::kIpV6;
75-
return true;
73+
74+
if (CurrentInterfaceHasAddressOfType(chip::Inet::IPAddressType::kIPv4))
75+
{
76+
*id = mIterator.GetInterfaceId();
77+
*type = chip::Inet::IPAddressType::kIPv4;
78+
return true;
79+
}
7680
}
7781
#endif
7882

79-
*id = mIterator.GetInterfaceId();
80-
*type = chip::Inet::IPAddressType::kIPv6;
8183
#if INET_CONFIG_ENABLE_IPV4
8284
mState = State::kIpV4;
8385
#endif
8486

87+
bool haveResult = CurrentInterfaceHasAddressOfType(chip::Inet::IPAddressType::kIPv6);
88+
if (haveResult)
89+
{
90+
*id = mIterator.GetInterfaceId();
91+
*type = chip::Inet::IPAddressType::kIPv6;
92+
}
93+
8594
for (mIterator.Next(); SkipCurrentInterface(); mIterator.Next())
8695
{
8796
}
88-
return true;
97+
98+
if (haveResult)
99+
{
100+
return true;
101+
}
102+
103+
return Next(id, type);
89104
}
90105

91106
private:
@@ -119,6 +134,8 @@ class AllInterfaces : public mdns::Minimal::ListenIterator
119134

120135
return !IsCurrentInterfaceUsable(mIterator);
121136
}
137+
138+
bool CurrentInterfaceHasAddressOfType(chip::Inet::IPAddressType type);
122139
};
123140

124141
class AllAddressesIterator : public mdns::Minimal::IpAddressIterator
@@ -170,6 +187,19 @@ class AllAddressesIterator : public mdns::Minimal::IpAddressIterator
170187
chip::Inet::InterfaceAddressIterator mIterator;
171188
};
172189

190+
bool AllInterfaces::CurrentInterfaceHasAddressOfType(chip::Inet::IPAddressType type)
191+
{
192+
// mIterator.HasCurrent() must be true here.
193+
AllAddressesIterator addressIter(mIterator.GetInterfaceId(), type);
194+
chip::Inet::IPAddress addr;
195+
if (addressIter.Next(addr))
196+
{
197+
return true;
198+
}
199+
200+
return false;
201+
}
202+
173203
class DefaultAddressPolicy : public AddressPolicy
174204
{
175205
public:

src/lib/dnssd/minimal_mdns/Server.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -279,8 +279,8 @@ CHIP_ERROR ServerBase::Listen(chip::Inet::EndPointManager<chip::Inet::UDPEndPoin
279279
}
280280
#endif
281281

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

0 commit comments

Comments
 (0)