[posix] update dns Resolver to attempt all servers before reporting failure (#11495)

This commit addresses a defect in the Resolver::Query function where
it would error out if the attempt to send a DNS query to any single
configured server failed. This could lead to query failures even if
other DNS servers were available and operational.
This commit is contained in:
Yang Song
2025-05-14 07:54:54 -07:00
committed by GitHub
parent 718a27e8f2
commit 078c6f1dc5
+17 -13
View File
@@ -248,6 +248,8 @@ otError Resolver::SendQueryToServer(Transaction *aTxn,
error = OT_ERROR_NO_ROUTE);
}
LogInfo("Forwarded DNS query %p to %s", static_cast<void *>(aTxn), Ip6AddressString(&aServerAddress).AsCString());
exit:
return error;
}
@@ -255,9 +257,10 @@ exit:
void Resolver::Query(otPlatDnsUpstreamQuery *aTxn, const otMessage *aQuery)
{
char packet[kMaxDnsMessageSize];
otError error = OT_ERROR_NONE;
uint16_t length = otMessageGetLength(aQuery);
Transaction *txn = nullptr;
otError error = OT_ERROR_NONE;
uint16_t length = otMessageGetLength(aQuery);
uint32_t serverCount = 0;
Transaction *txn = nullptr;
VerifyOrExit(length <= kMaxDnsMessageSize, error = OT_ERROR_NO_BUFS);
VerifyOrExit(otMessageRead(aQuery, 0, &packet, sizeof(packet)) == length, error = OT_ERROR_NO_BUFS);
@@ -268,22 +271,23 @@ void Resolver::Query(otPlatDnsUpstreamQuery *aTxn, const otMessage *aQuery)
for (uint32_t i = 0; i < mRecursiveDnsServerCount; i++)
{
SuccessOrExit(error = SendQueryToServer(txn, mRecursiveDnsServerList[i], packet, length));
LogInfo("Forwarded DNS query %p to %s", static_cast<void *>(aTxn),
Ip6AddressString(&mRecursiveDnsServerList[i]).AsCString());
if (SendQueryToServer(txn, mRecursiveDnsServerList[i], packet, length) == OT_ERROR_NONE)
{
serverCount++;
}
}
for (uint32_t i = 0; i < mUpstreamDnsServerCount; i++)
{
SuccessOrExit(error = SendQueryToServer(txn, mUpstreamDnsServerList[i], packet, length));
LogInfo("Forwarded DNS query %p to %s", static_cast<void *>(aTxn),
Ip6AddressString(&mUpstreamDnsServerList[i]).AsCString());
if (SendQueryToServer(txn, mUpstreamDnsServerList[i], packet, length) == OT_ERROR_NONE)
{
serverCount++;
}
}
LogInfo("Forwarded DNS query %p to %d server(s).", static_cast<void *>(aTxn),
mRecursiveDnsServerCount + mUpstreamDnsServerCount);
VerifyOrExit(serverCount > 0, error = OT_ERROR_NO_ROUTE);
LogInfo("Forwarded DNS query %p to %u server(s).", static_cast<void *>(aTxn), serverCount);
exit:
if (error != OT_ERROR_NONE)