From: Remi Gacogne Date: Thu, 9 Oct 2025 13:02:12 +0000 (+0200) Subject: dnsdist: Hopefully slightly reduce the complexity of `processQueryAfterRules` X-Git-Tag: rec-5.4.0-alpha1~191^2~5 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=dc143997ee303971af10e7d8a98e8136e55fb347;p=thirdparty%2Fpdns.git dnsdist: Hopefully slightly reduce the complexity of `processQueryAfterRules` Signed-off-by: Remi Gacogne --- diff --git a/pdns/dnsdistdist/dnsdist.cc b/pdns/dnsdistdist/dnsdist.cc index 0cc8025c31..06d32ae974 100644 --- a/pdns/dnsdistdist/dnsdist.cc +++ b/pdns/dnsdistdist/dnsdist.cc @@ -1433,6 +1433,11 @@ static ServerPolicy::SelectedBackend selectBackendForOutgoingQuery(DNSQuestion& ProcessQueryResult processQueryAfterRules(DNSQuestion& dnsQuestion, std::shared_ptr& outgoingBackend) { + const auto sendAnswer = [](DNSQuestion& dnsQ) -> ProcessQueryResult{ + ++dnsdist::metrics::g_stats.responses; + ++dnsQ.ids.cs->responses; + return ProcessQueryResult::SendAnswer; + }; const uint16_t queryId = ntohs(dnsQuestion.getHeader()->id); try { @@ -1481,9 +1486,7 @@ ProcessQueryResult processQueryAfterRules(DNSQuestion& dnsQuestion, std::shared_ return ProcessQueryResult::Drop; } - ++dnsdist::metrics::g_stats.responses; - ++dnsQuestion.ids.cs->responses; - return ProcessQueryResult::SendAnswer; + return sendAnswer(dnsQuestion); } if (!dnsQuestion.ids.subnet) { @@ -1516,9 +1519,7 @@ ProcessQueryResult processQueryAfterRules(DNSQuestion& dnsQuestion, std::shared_ return ProcessQueryResult::Drop; } - ++dnsdist::metrics::g_stats.responses; - ++dnsQuestion.ids.cs->responses; - return ProcessQueryResult::SendAnswer; + return sendAnswer(dnsQuestion); } if (dnsQuestion.ids.protocol == dnsdist::Protocol::DoH && willBeForwardedOverUDP) { /* do a second-lookup for responses received over UDP, but we do not want TC=1 answers */ @@ -1528,9 +1529,7 @@ ProcessQueryResult processQueryAfterRules(DNSQuestion& dnsQuestion, std::shared_ return ProcessQueryResult::Drop; } - ++dnsdist::metrics::g_stats.responses; - ++dnsQuestion.ids.cs->responses; - return ProcessQueryResult::SendAnswer; + return sendAnswer(dnsQuestion); } } @@ -1579,10 +1578,7 @@ ProcessQueryResult processQueryAfterRules(DNSQuestion& dnsQuestion, std::shared_ if (!prepareOutgoingResponse(*dnsQuestion.ids.cs, dnsQuestion, false)) { return ProcessQueryResult::Drop; } - ++dnsdist::metrics::g_stats.responses; - ++dnsQuestion.ids.cs->responses; - // no response-only statistics counter to update. - return ProcessQueryResult::SendAnswer; + return sendAnswer(dnsQuestion); } return ProcessQueryResult::Drop;