[dnssd-server] determine query type & simplify processing of query name (#9349)

This commit simplifies and enhances the DNSSD Server implementation:

- A new method, `ParseQuestions()`, has been added to process the
  questions in a received `Request` message and determine the
  `QueryType`.

- The processing and appending of the query DNS name has been
  simplified. The query name is now read and copied label by label
  from the `Request` message into the `Response`. When matching the
  name against SRP entries, the names are compared with the query
  name directly as it is encoded in the `Response` message using the
  `Dns::Name::CompareName()` method. This approach is more flexible
  and simpler, and it works for all query types and name formats,
  including service instance names where the first label can itself
  contain a dot (`.`) character. This simplification allows us to
  remove the helper functions that were previously used to parse the
  query name and deal with the ambiguity that arises when service
  instance names are read as strings of dot-separated labels.

- The management of offsets for DNS name compression has also been
  simplified. A new method, `Response::ParseQueryName()`, has been
  added to validate the query name (e.g., that it contains the
  correct domain) and determine all offsets.

- The `ResolveBySrp()` method has also been simplified using query
  type and the newly added flavors of `Append{Ptr/Srv/Txt}Record()`
  methods.

- Finally, this commit adds the `Dns::Name::ExtractLabels()` helper
  method, which extracts label(s) from a full DNS name string by
  first checking that it contains a given suffix name (e.g., the
  suffix name can be a domain name or a service name) and then
  removing it, returning the label(s).
This commit is contained in:
Abtin Keshavarzian
2023-08-15 12:12:02 -07:00
committed by GitHub
parent 3b291108a9
commit 7e32165bee
6 changed files with 750 additions and 850 deletions
+14 -4
View File
@@ -242,9 +242,10 @@ static const char kService1Name[] = "_srv._udp";
static const char kService1FullName[] = "_srv._udp.default.service.arpa.";
static const char kInstance1Label[] = "srv-instance";
static const char kService2Name[] = "_game._udp";
static const char kService2FullName[] = "_game._udp.default.service.arpa.";
static const char kInstance2Label[] = "last-ninja";
static const char kService2Name[] = "_game._udp";
static const char kService2FullName[] = "_game._udp.default.service.arpa.";
static const char kService2SubTypeFullName[] = "_best._sub._game._udp.default.service.arpa.";
static const char kInstance2Label[] = "last-ninja";
void PrepareService1(Srp::Client::Service &aService)
{
@@ -277,7 +278,7 @@ void PrepareService1(Srp::Client::Service &aService)
void PrepareService2(Srp::Client::Service &aService)
{
static const char kSub4[] = "_44444444";
static const char kSub4[] = "_best";
static const char *kSubLabels2[] = {kSub4, nullptr};
memset(&aService, 0, sizeof(aService));
@@ -598,6 +599,15 @@ void TestDnsClient(void)
SuccessOrQuit(sBrowseInfo.mError);
VerifyOrQuit(sBrowseInfo.mNumInstances == 1);
sBrowseInfo.Reset();
Log("Browse(%s)", kService2SubTypeFullName);
SuccessOrQuit(dnsClient->Browse(kService2SubTypeFullName, BrowseCallback, sInstance));
AdvanceTime(100);
VerifyOrQuit(sBrowseInfo.mCallbackCount == 1);
SuccessOrQuit(sBrowseInfo.mError);
VerifyOrQuit(sBrowseInfo.mNumInstances == 1);
sBrowseInfo.Reset();
Log("Browse() for unknown service");
SuccessOrQuit(dnsClient->Browse("_unknown._udp.default.service.arpa.", BrowseCallback, sInstance));