mirror of
https://github.com/espressif/openthread.git
synced 2026-10-31 11:36:27 +00:00
[dns-client] switch to separate SRV/TXT queries on response timeout (#10444)
This commit updates `Dns::Client` so that when resolving a service using `kServiceModeSrvTxtOptimize`, it switches to single-question query mode and sends separate parallel SRV and TXT queries upon the first response timeout. This is in addition to the existing behavior of switching to separate queries upon receiving a response with an error rcode from the server. The `test_dns_client` unit test is also updated to validate this scenario. New `TestMode` configurations are added to server to control its behavior, allowing it to either reject multi-question queries (by sending a "FormatError" rcode) or ignore them (sending no response).
This commit is contained in:
@@ -671,8 +671,8 @@ void TestDnsClient(void)
|
||||
|
||||
Log("- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - ");
|
||||
|
||||
Log("Set TestMode on server to only accept single question");
|
||||
dnsServer->SetTestMode(Dns::ServiceDiscovery::Server::kTestModeSingleQuestionOnly);
|
||||
Log("Set TestMode on server to reject multi-question queries and send error");
|
||||
dnsServer->SetTestMode(Dns::ServiceDiscovery::Server::kTestModeRejectMultiQuestionQuery);
|
||||
|
||||
Log("ResolveService(%s,%s) with ServiceMode %s", kInstance1Label, kService1FullName,
|
||||
ServiceModeToString(Dns::Client::QueryConfig::kServiceModeSrvTxtOptimize));
|
||||
@@ -706,6 +706,48 @@ void TestDnsClient(void)
|
||||
|
||||
dnsServer->SetTestMode(Dns::ServiceDiscovery::Server::kTestModeDisabled);
|
||||
|
||||
Log("- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - ");
|
||||
|
||||
Log("Set TestMode on server to ignore multi-question queries (send no response)");
|
||||
dnsServer->SetTestMode(Dns::ServiceDiscovery::Server::kTestModeIgnoreMultiQuestionQuery);
|
||||
|
||||
Log("ResolveService(%s,%s) with ServiceMode %s", kInstance1Label, kService1FullName,
|
||||
ServiceModeToString(Dns::Client::QueryConfig::kServiceModeSrvTxtOptimize));
|
||||
|
||||
queryConfig.Clear();
|
||||
queryConfig.mServiceMode = static_cast<otDnsServiceMode>(Dns::Client::QueryConfig::kServiceModeSrvTxtOptimize);
|
||||
|
||||
sResolveServiceInfo.Reset();
|
||||
SuccessOrQuit(
|
||||
dnsClient->ResolveService(kInstance1Label, kService1FullName, ServiceCallback, sInstance, &queryConfig));
|
||||
|
||||
AdvanceTime(10 * 1000); // Wait longer than client response timeout.
|
||||
|
||||
VerifyOrQuit(sResolveServiceInfo.mCallbackCount == 1);
|
||||
SuccessOrQuit(sResolveServiceInfo.mError);
|
||||
|
||||
// Use `kServiceModeSrvTxt` and check that server does ignore two questions.
|
||||
|
||||
Log("ResolveService(%s,%s) with ServiceMode %s", kInstance1Label, kService1FullName,
|
||||
ServiceModeToString(Dns::Client::QueryConfig::kServiceModeSrvTxt));
|
||||
|
||||
queryConfig.Clear();
|
||||
queryConfig.mServiceMode = static_cast<otDnsServiceMode>(Dns::Client::QueryConfig::kServiceModeSrvTxt);
|
||||
|
||||
sResolveServiceInfo.Reset();
|
||||
SuccessOrQuit(
|
||||
dnsClient->ResolveService(kInstance1Label, kService1FullName, ServiceCallback, sInstance, &queryConfig));
|
||||
|
||||
// Wait for the client to time out after exhausting all retry attempts, and
|
||||
// ensure that a `kErrorResponseTimeout` error is reported.
|
||||
|
||||
AdvanceTime(45 * 1000);
|
||||
|
||||
VerifyOrQuit(sResolveServiceInfo.mCallbackCount == 1);
|
||||
VerifyOrQuit(sResolveServiceInfo.mError == kErrorResponseTimeout);
|
||||
|
||||
dnsServer->SetTestMode(Dns::ServiceDiscovery::Server::kTestModeDisabled);
|
||||
|
||||
//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
// Validate DNS Client `ResolveService()` using all service modes
|
||||
// when sever does not provide any RR in the addition data section.
|
||||
@@ -832,7 +874,7 @@ void TestDnsClient(void)
|
||||
Log("- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - ");
|
||||
Log("Set TestMode on server to not include any RR in additional section AND to only accept single question");
|
||||
dnsServer->SetTestMode(Dns::ServiceDiscovery::Server::kTestModeEmptyAdditionalSection +
|
||||
Dns::ServiceDiscovery::Server::kTestModeSingleQuestionOnly);
|
||||
Dns::ServiceDiscovery::Server::kTestModeRejectMultiQuestionQuery);
|
||||
|
||||
Log("ResolveServiceAndHostAddress(%s,%s) with ServiceMode: %s", kInstance1Label, kService1FullName,
|
||||
ServiceModeToString(Dns::Client::QueryConfig::kServiceModeSrvTxtOptimize));
|
||||
|
||||
Reference in New Issue
Block a user