]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
dnsdist: Hopefully slightly reduce the complexity of `processQueryAfterRules`
authorRemi Gacogne <remi.gacogne@powerdns.com>
Thu, 9 Oct 2025 13:02:12 +0000 (15:02 +0200)
committerRemi Gacogne <remi.gacogne@powerdns.com>
Thu, 9 Oct 2025 13:02:12 +0000 (15:02 +0200)
Signed-off-by: Remi Gacogne <remi.gacogne@powerdns.com>
pdns/dnsdistdist/dnsdist.cc

index 0cc8025c311bd6b54aa856f5dc74dd5f01bdd3b1..06d32ae974807ca6c4bc6e5efc31a66009a12372 100644 (file)
@@ -1433,6 +1433,11 @@ static ServerPolicy::SelectedBackend selectBackendForOutgoingQuery(DNSQuestion&
 
 ProcessQueryResult processQueryAfterRules(DNSQuestion& dnsQuestion, std::shared_ptr<DownstreamState>& 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;