[dns-client] track limited query (one question) servers (#10403)

This commit updates `Dns::Client` to remember servers/resolvers that
are known to have trouble with multiple-question queries. This
information is learned from earlier interactions with the server.

When `ResolveService()` is requested, if the user explicitly
requests "optimize" service mode, the request is honored. Otherwise,
if "optimize" service mode is chosen from the default configuration
and the DNS server is known to have trouble with multiple-question
queries, "separate" service mode is used instead.

This commit also updates the `test_dns_client.cpp` unit test to
validate the newly added behavior.
This commit is contained in:
Abtin Keshavarzian
2024-08-14 12:41:18 -07:00
committed by GitHub
parent 1645880b8e
commit 9fd6596e7b
4 changed files with 154 additions and 10 deletions
+62 -9
View File
@@ -497,15 +497,17 @@ void TestDnsClient(void)
Dns::Client::QueryConfig::kServiceModeSrvTxtOptimize,
};
Array<Ip6::Address, kNumAddresses> addresses;
Srp::Server *srpServer;
Srp::Client *srpClient;
Srp::Client::Service service1;
Srp::Client::Service service2;
Dns::Client *dnsClient;
Dns::Client::QueryConfig queryConfig;
Dns::ServiceDiscovery::Server *dnsServer;
uint16_t heapAllocations;
Array<Ip6::Address, kNumAddresses> addresses;
Srp::Server *srpServer;
Srp::Client *srpClient;
Srp::Client::Service service1;
Srp::Client::Service service2;
Dns::Client *dnsClient;
Dns::Client::QueryConfig queryConfig;
Dns::ServiceDiscovery::Server *dnsServer;
Dns::ServiceDiscovery::Server::Counters oldServerCounters;
Dns::ServiceDiscovery::Server::Counters newServerCounters;
uint16_t heapAllocations;
Log("--------------------------------------------------------------------------------------------");
Log("TestDnsClient");
@@ -882,6 +884,8 @@ void TestDnsClient(void)
queryConfig.Clear();
queryConfig.mServiceMode = static_cast<otDnsServiceMode>(Dns::Client::QueryConfig::kServiceModeSrvTxtOptimize);
oldServerCounters = dnsServer->GetCounters();
sResolveServiceInfo.Reset();
SuccessOrQuit(dnsClient->ResolveServiceAndHostAddress(kInstance1Label, kService1FullName, ServiceCallback,
sInstance, &queryConfig));
@@ -907,6 +911,55 @@ void TestDnsClient(void)
VerifyOrQuit(addresses.Contains(sResolveServiceInfo.mHostAddresses[index]));
}
newServerCounters = dnsServer->GetCounters();
Log("Validate (using server counter) that client first tried to query SRV/TXT together and failed");
Log("and then send separate queries (for SRV, TXT and AAAA)");
Log(" Total : %2u -> %2u", oldServerCounters.GetTotalQueries(), newServerCounters.GetTotalQueries());
Log(" Failed: %2u -> %2u", oldServerCounters.GetTotalFailedQueries(), newServerCounters.GetTotalFailedQueries());
VerifyOrQuit(newServerCounters.GetTotalFailedQueries() == 1 + oldServerCounters.GetTotalFailedQueries());
VerifyOrQuit(newServerCounters.GetTotalQueries() == 4 + oldServerCounters.GetTotalQueries());
Log("- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - ");
Log("Resolve service again now using `kServiceModeSrvTxtOptimize` as default config");
Log("Client should already know that server is not capable of handling multi-question query");
queryConfig.Clear();
queryConfig.mServiceMode = static_cast<otDnsServiceMode>(Dns::Client::QueryConfig::kServiceModeSrvTxtOptimize);
dnsClient->SetDefaultConfig(queryConfig);
Log("ResolveService(%s,%s)", kInstance1Label, kService1FullName);
oldServerCounters = dnsServer->GetCounters();
sResolveServiceInfo.Reset();
SuccessOrQuit(dnsClient->ResolveService(kInstance1Label, kService1FullName, ServiceCallback, sInstance, nullptr));
AdvanceTime(100);
VerifyOrQuit(sResolveServiceInfo.mCallbackCount == 1);
SuccessOrQuit(sResolveServiceInfo.mError);
VerifyOrQuit(sResolveServiceInfo.mInfo.mTtl != 0);
VerifyOrQuit(sResolveServiceInfo.mInfo.mPort == service1.mPort);
VerifyOrQuit(sResolveServiceInfo.mInfo.mWeight == service1.mWeight);
VerifyOrQuit(strcmp(sResolveServiceInfo.mInfo.mHostNameBuffer, kHostFullName) == 0);
VerifyOrQuit(sResolveServiceInfo.mInfo.mTxtDataTtl != 0);
VerifyOrQuit(sResolveServiceInfo.mInfo.mTxtDataSize != 0);
newServerCounters = dnsServer->GetCounters();
Log("Client should already know that server is not capable of handling multi-question query");
Log("Check server counters to validate that client did send separate queries for TXT and SRV");
Log(" Total : %2u -> %2u", oldServerCounters.GetTotalQueries(), newServerCounters.GetTotalQueries());
Log(" Failed: %2u -> %2u", oldServerCounters.GetTotalFailedQueries(), newServerCounters.GetTotalFailedQueries());
VerifyOrQuit(newServerCounters.GetTotalFailedQueries() == oldServerCounters.GetTotalFailedQueries());
VerifyOrQuit(newServerCounters.GetTotalQueries() == 2 + oldServerCounters.GetTotalQueries());
dnsServer->SetTestMode(Dns::ServiceDiscovery::Server::kTestModeDisabled);
Log("- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - ");