Skip to content

Commit 078c6f1

Browse files
[posix] update dns Resolver to attempt all servers before reporting failure (openthread#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.
1 parent 718a27e commit 078c6f1

1 file changed

Lines changed: 17 additions & 13 deletions

File tree

src/posix/platform/resolver.cpp

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -248,16 +248,19 @@ otError Resolver::SendQueryToServer(Transaction *aTxn,
248248
error = OT_ERROR_NO_ROUTE);
249249
}
250250

251+
LogInfo("Forwarded DNS query %p to %s", static_cast<void *>(aTxn), Ip6AddressString(&aServerAddress).AsCString());
252+
251253
exit:
252254
return error;
253255
}
254256

255257
void Resolver::Query(otPlatDnsUpstreamQuery *aTxn, const otMessage *aQuery)
256258
{
257259
char packet[kMaxDnsMessageSize];
258-
otError error = OT_ERROR_NONE;
259-
uint16_t length = otMessageGetLength(aQuery);
260-
Transaction *txn = nullptr;
260+
otError error = OT_ERROR_NONE;
261+
uint16_t length = otMessageGetLength(aQuery);
262+
uint32_t serverCount = 0;
263+
Transaction *txn = nullptr;
261264

262265
VerifyOrExit(length <= kMaxDnsMessageSize, error = OT_ERROR_NO_BUFS);
263266
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)
268271

269272
for (uint32_t i = 0; i < mRecursiveDnsServerCount; i++)
270273
{
271-
SuccessOrExit(error = SendQueryToServer(txn, mRecursiveDnsServerList[i], packet, length));
272-
273-
LogInfo("Forwarded DNS query %p to %s", static_cast<void *>(aTxn),
274-
Ip6AddressString(&mRecursiveDnsServerList[i]).AsCString());
274+
if (SendQueryToServer(txn, mRecursiveDnsServerList[i], packet, length) == OT_ERROR_NONE)
275+
{
276+
serverCount++;
277+
}
275278
}
276279

277280
for (uint32_t i = 0; i < mUpstreamDnsServerCount; i++)
278281
{
279-
SuccessOrExit(error = SendQueryToServer(txn, mUpstreamDnsServerList[i], packet, length));
280-
281-
LogInfo("Forwarded DNS query %p to %s", static_cast<void *>(aTxn),
282-
Ip6AddressString(&mUpstreamDnsServerList[i]).AsCString());
282+
if (SendQueryToServer(txn, mUpstreamDnsServerList[i], packet, length) == OT_ERROR_NONE)
283+
{
284+
serverCount++;
285+
}
283286
}
284287

285-
LogInfo("Forwarded DNS query %p to %d server(s).", static_cast<void *>(aTxn),
286-
mRecursiveDnsServerCount + mUpstreamDnsServerCount);
288+
VerifyOrExit(serverCount > 0, error = OT_ERROR_NO_ROUTE);
289+
290+
LogInfo("Forwarded DNS query %p to %u server(s).", static_cast<void *>(aTxn), serverCount);
287291

288292
exit:
289293
if (error != OT_ERROR_NONE)

0 commit comments

Comments
 (0)