Skip to content

Commit

Permalink
Set the cache-flush bit for "unique" records in minimal mdns. (#23933)
Browse files Browse the repository at this point in the history
* Set the cache-flush bit for "unique" records in minimal mdns.

There should only be one entity around with a given Matter instance name or
Matter hostname, so all records which have those as the QName are part of the
unique set.

Fixes #23918

* Fix build issue.
  • Loading branch information
bzbarsky-apple authored and pull[bot] committed Jul 13, 2023
1 parent 3340a8b commit 1087488
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 8 deletions.
15 changes: 8 additions & 7 deletions src/lib/dnssd/Advertiser_ImplMinimalMdns.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -488,18 +488,19 @@ CHIP_ERROR AdvertiserMinMdns::Advertise(const OperationalAdvertisingParameters &
return CHIP_ERROR_NO_MEMORY;
}

if (!operationalAllocator->AddResponder<SrvResponder>(SrvResourceRecord(instanceName, hostName, params.GetPort()))
.SetReportAdditional(hostName)
.IsValid())
// We are the sole owner of our instanceName, so records keyed on the
// instanceName should have the cache-flush bit set.
SrvResourceRecord srvRecord(instanceName, hostName, params.GetPort());
srvRecord.SetCacheFlush(true);
if (!operationalAllocator->AddResponder<SrvResponder>(srvRecord).SetReportAdditional(hostName).IsValid())
{
ChipLogError(Discovery, "Failed to add SRV record mDNS responder");
return CHIP_ERROR_NO_MEMORY;
}

if (!operationalAllocator
->AddResponder<TxtResponder>(TxtResourceRecord(instanceName, GetOperationalTxtEntries(operationalAllocator, params)))
.SetReportAdditional(hostName)
.IsValid())
TxtResourceRecord txtRecord(instanceName, GetOperationalTxtEntries(operationalAllocator, params));
txtRecord.SetCacheFlush(true);
if (!operationalAllocator->AddResponder<TxtResponder>(txtRecord).SetReportAdditional(hostName).IsValid())
{
ChipLogError(Discovery, "Failed to add TXT record mDNS responder");
return CHIP_ERROR_NO_MEMORY;
Expand Down
6 changes: 6 additions & 0 deletions src/lib/dnssd/minimal_mdns/responders/IP.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ void IPv4Responder::AddAllResponses(const chip::Inet::IPPacketInfo * source, Res
assert(addr.IsIPv4());

IPResourceRecord record(GetQName(), addr);
// We're the only thing around with our hostname, so we should set the
// cache-flush bit.
record.SetCacheFlush(true);
configuration.Adjust(record);
delegate->AddResponse(record);
}
Expand All @@ -59,6 +62,9 @@ void IPv6Responder::AddAllResponses(const chip::Inet::IPPacketInfo * source, Res
assert(addr.IsIPv6());

IPResourceRecord record(GetQName(), addr);
// We're the only thing around with our hostname, so we should set the
// cache-flush bit.
record.SetCacheFlush(true);
configuration.Adjust(record);
delegate->AddResponse(record);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class IPResponseAccumulator : public ResponderDelegate
{

NL_TEST_ASSERT(mSuite, (record.GetType() == QType::A) || (record.GetType() == QType::AAAA));
NL_TEST_ASSERT(mSuite, record.GetClass() == QClass::IN);
NL_TEST_ASSERT(mSuite, record.GetClass() == QClass::IN_FLUSH);
NL_TEST_ASSERT(mSuite, record.GetName() == kNames);
}

Expand Down

0 comments on commit 1087488

Please sign in to comment.