[dnssd] smaller enhancements in Server (#11439)

This commit contains a few smaller enhancements in the DNS-SD server
implementation:
- `ShouldForwardToUpstream()` now checks the `mEnableUpstreamQuery`.
- The `ResolveByUpstream()` method now handles its own error logging.
- Comments are added/updated to improve code readability.
This commit is contained in:
Abtin Keshavarzian
2025-04-24 14:12:41 -07:00
committed by GitHub
parent 3e7528e4e9
commit d9710c6ecb
2 changed files with 14 additions and 10 deletions
+13 -9
View File
@@ -157,17 +157,13 @@ void Server::ProcessQuery(Request &aRequest)
Response response(GetInstance()); Response response(GetInstance());
#if OPENTHREAD_CONFIG_DNS_UPSTREAM_QUERY_ENABLE #if OPENTHREAD_CONFIG_DNS_UPSTREAM_QUERY_ENABLE
if (mEnableUpstreamQuery && ShouldForwardToUpstream(aRequest)) if (ShouldForwardToUpstream(aRequest))
{ {
Error error = ResolveByUpstream(aRequest); if (ResolveByUpstream(aRequest) == kErrorNone)
if (error == kErrorNone)
{ {
ExitNow(); ExitNow();
} }
LogWarnOnError(error, "forwarding to upstream");
rcode = Header::kResponseServerFailure; rcode = Header::kResponseServerFailure;
// Continue to allocate and prepare the response message // Continue to allocate and prepare the response message
@@ -207,6 +203,10 @@ void Server::ProcessQuery(Request &aRequest)
} }
#endif #endif
// `ResolveByProxy` may take ownership of `response.mMessage` and
// setting it to `nullptr`. In such a case, the `response.Send()`
// call will effectively do nothing.
ResolveByProxy(response, *aRequest.mMessageInfo); ResolveByProxy(response, *aRequest.mMessageInfo);
exit: exit:
@@ -386,8 +386,9 @@ exit:
Error Server::Response::ParseQueryName(void) Error Server::Response::ParseQueryName(void)
{ {
// Parses and validates the query name and updates // Parses the query name, determines name compression
// the name compression offsets. // offsets, and validates that the query name is for
// `kDefaultDomainName` ("default.service.arpa.").
Error error = kErrorNone; Error error = kErrorNone;
Name::Buffer name; Name::Buffer name;
@@ -865,12 +866,14 @@ exit:
#endif // OPENTHREAD_CONFIG_SRP_SERVER_ENABLE #endif // OPENTHREAD_CONFIG_SRP_SERVER_ENABLE
#if OPENTHREAD_CONFIG_DNS_UPSTREAM_QUERY_ENABLE #if OPENTHREAD_CONFIG_DNS_UPSTREAM_QUERY_ENABLE
bool Server::ShouldForwardToUpstream(const Request &aRequest) bool Server::ShouldForwardToUpstream(const Request &aRequest) const
{ {
bool shouldForward = false; bool shouldForward = false;
uint16_t readOffset; uint16_t readOffset;
Name::Buffer name; Name::Buffer name;
VerifyOrExit(mEnableUpstreamQuery);
VerifyOrExit(aRequest.mHeader.IsRecursionDesiredFlagSet()); VerifyOrExit(aRequest.mHeader.IsRecursionDesiredFlagSet());
readOffset = sizeof(Header); readOffset = sizeof(Header);
@@ -949,6 +952,7 @@ Error Server::ResolveByUpstream(const Request &aRequest)
mCounters.mUpstreamDnsCounters.mQueries++; mCounters.mUpstreamDnsCounters.mQueries++;
exit: exit:
LogWarnOnError(error, "forward to upstream");
return error; return error;
} }
#endif // OPENTHREAD_CONFIG_DNS_UPSTREAM_QUERY_ENABLE #endif // OPENTHREAD_CONFIG_DNS_UPSTREAM_QUERY_ENABLE
+1 -1
View File
@@ -573,7 +573,7 @@ private:
#endif #endif
#if OPENTHREAD_CONFIG_DNS_UPSTREAM_QUERY_ENABLE #if OPENTHREAD_CONFIG_DNS_UPSTREAM_QUERY_ENABLE
static bool ShouldForwardToUpstream(const Request &aRequest); bool ShouldForwardToUpstream(const Request &aRequest) const;
UpstreamQueryTransaction *AllocateUpstreamQueryTransaction(const Ip6::MessageInfo &aMessageInfo); UpstreamQueryTransaction *AllocateUpstreamQueryTransaction(const Ip6::MessageInfo &aMessageInfo);
void ResetUpstreamQueryTransaction(UpstreamQueryTransaction &aTxn, Error aError); void ResetUpstreamQueryTransaction(UpstreamQueryTransaction &aTxn, Error aError);
Error ResolveByUpstream(const Request &aRequest); Error ResolveByUpstream(const Request &aRequest);