Skip to content

Commit

Permalink
[dnssd-server] send response if ResolveByUpstream() fails (openthre…
Browse files Browse the repository at this point in the history
…ad#9331)

When `ResolveByUpstream()` returns an error, we ensure that the error
is cleared so that the transmission of the DNS response (with
`kResponseServerFailure` rcode) is not skipped at the `exit` label.
  • Loading branch information
abtink committed Aug 1, 2023
1 parent 7d6740c commit 992be27
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions src/core/net/dnssd_server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -169,13 +169,20 @@ void Server::ProcessQuery(const Header &aRequestHeader, Message &aRequestMessage
if (mEnableUpstreamQuery && ShouldForwardToUpstream(aRequestHeader, aRequestMessage))
{
error = ResolveByUpstream(aRequestMessage, aMessageInfo);

if (error == kErrorNone)
{
shouldSendResponse = false;
ExitNow();
}
response = Header::kResponseServerFailure;

LogWarn("Failed to forward DNS query to upstream: %s", ErrorToString(error));

error = kErrorNone;
response = Header::kResponseServerFailure;

// Continue to allocate and prepare the response message
// to send the `kResponseServerFailure` response code.
}
#endif

Expand All @@ -195,8 +202,11 @@ void Server::ProcessQuery(const Header &aRequestHeader, Message &aRequestMessage
responseHeader.SetRecursionDesiredFlag();
}

// We may met errors when forwarding the query to the upstream
#if OPENTHREAD_CONFIG_DNS_UPSTREAM_QUERY_ENABLE
// Forwarding the query to the upstream may have already set the
// response error code.
VerifyOrExit(response == Header::kResponseSuccess);
#endif

// Validate the query
VerifyOrExit(aRequestHeader.GetQueryType() == Header::kQueryTypeStandard,
Expand Down Expand Up @@ -231,7 +241,7 @@ void Server::ProcessQuery(const Header &aRequestHeader, Message &aRequestMessage
#endif

exit:
if (error == kErrorNone && shouldSendResponse)
if ((error == kErrorNone) && shouldSendResponse)
{
SendResponse(responseHeader, response, *responseMessage, aMessageInfo, mSocket);
}
Expand Down

0 comments on commit 992be27

Please sign in to comment.