[dnssd] echo all questions in the response on NameError (#11510)

This commit updates the DNSSD server/resolver to ensure it includes
the questions in the response message when the returned RCODE is
`NameError` (NXDOMAIN). It also clears the question count and any
partially appended content if there is a failure to append all
questions (when `kResponseServerFailure` (SERVFAIL) is returned).

It also adds a test case in `test_dns_client` to resolve a
non-existent name and validate the included questions.
This commit is contained in:
Abtin Keshavarzian
2025-05-19 12:09:12 -07:00
committed by GitHub
parent 55d657187b
commit ca3df1f057
2 changed files with 27 additions and 8 deletions
+14 -6
View File
@@ -366,11 +366,6 @@ Server::ResponseCode Server::Response::AddQuestionsFrom(const Request &aRequest)
SuccessOrExit(Name(*aRequest.mMessage, kQueryNameOffset).AppendTo(*mMessage));
// Check the name to include the correct domain name and determine
// the domain name offset (for DNS name compression).
VerifyOrExit(ParseQueryName() == kErrorNone, rcode = Header::kResponseNameError);
mHeader.SetQuestionCount(aRequest.mHeader.GetQuestionCount());
offset = sizeof(Header);
@@ -394,9 +389,22 @@ Server::ResponseCode Server::Response::AddQuestionsFrom(const Request &aRequest)
SuccessOrExit(mMessage->Append(question));
}
rcode = Header::kResponseSuccess;
// Check the name to include the correct domain name and determine
// the domain name offset (for DNS name compression).
rcode = (ParseQueryName() == kErrorNone) ? Header::kResponseSuccess : Header::kResponseNameError;
exit:
if (rcode == Header::kResponseServerFailure)
{
// If we fail to add questions to the response message
// (no buffer), we clear the question count in the header and
// just include the header in the message.
mHeader.SetQuestionCount(0);
IgnoreError(mMessage->SetLength(sizeof(Header)));
}
return rcode;
}
+13 -2
View File
@@ -238,8 +238,9 @@ void FinalizeTest(void)
//---------------------------------------------------------------------------------------------------------------------
static const char kHostName[] = "elden";
static const char kHostFullName[] = "elden.default.service.arpa.";
static const char kHostName[] = "elden";
static const char kHostFullName[] = "elden.default.service.arpa.";
static const char kNonExistingName[] = "noname.nodomain.";
static const char kService1Name[] = "_srv._udp";
static const char kService1FullName[] = "_srv._udp.default.service.arpa.";
@@ -804,6 +805,16 @@ void TestDnsClient(void)
VerifyOrQuit(addresses.Contains(sAddressInfo.mHostAddresses[index]));
}
//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
// Validate DNS Client `ResolveAddress()` for an invalid (non-existing) name
sAddressInfo.Reset();
Log("ResolveAddress(%s)", kNonExistingName);
SuccessOrQuit(dnsClient->ResolveAddress(kNonExistingName, AddressCallback, sInstance));
AdvanceTime(100);
VerifyOrQuit(sAddressInfo.mCallbackCount == 1);
VerifyOrQuit(sAddressInfo.mError == kErrorNotFound);
//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
// Validate DNS Client `ResolveIp4Address()`