]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
tests(dnsdist): Add initial RCodeAction benchmark
authorPieter Lexis <pieter.lexis@powerdns.com>
Wed, 22 Oct 2025 12:56:42 +0000 (14:56 +0200)
committerPieter Lexis <pieter.lexis@powerdns.com>
Wed, 7 Jan 2026 12:16:20 +0000 (13:16 +0100)
pdns/dnsdistdist/bench-dnsdist-action-rcode.cc [new file with mode: 0644]
pdns/dnsdistdist/benchmarkrunner.cc
pdns/dnsdistdist/meson.build

diff --git a/pdns/dnsdistdist/bench-dnsdist-action-rcode.cc b/pdns/dnsdistdist/bench-dnsdist-action-rcode.cc
new file mode 100644 (file)
index 0000000..239e27b
--- /dev/null
@@ -0,0 +1,52 @@
+/*
+ * This file is part of PowerDNS or dnsdist.
+ * Copyright -- PowerDNS.COM B.V. and its contributors
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of version 2 of the GNU General Public License as
+ * published by the Free Software Foundation.
+ *
+ * In addition, for the avoidance of any doubt, permission is granted to
+ * link this program with OpenSSL and to (re)distribute the binaries
+ * produced as the result of such linking.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+#include "dnsname.hh"
+#define CATCH_CONFIG_NO_MAIN
+#include <catch2/catch_test_macros.hpp>
+#include <catch2/benchmark/catch_benchmark.hpp>
+
+#include "dnsdist.hh"
+#include "dnsdist-idstate.hh"
+#include "dnsdist-dnsparser.hh"
+#include "dnsdist-actions-factory.hh"
+
+TEST_CASE("Actions/RCodeAction", "[actions]") {
+  InternalQueryState ids;
+  PacketBuffer data;
+  GenericDNSPacketWriter<PacketBuffer> pwQ(data, DNSName("dnsdist.test.powerdns.com"), QType::A, QClass::IN, 0);
+  pwQ.getHeader()->rd = 1;
+
+  dnsdist::ResponseConfig rconfig;
+  auto action = dnsdist::actions::getRCodeAction(RCode::NXDomain, rconfig);
+
+  DNSQuestion dq(ids, data); // NOLINT
+  std::string ruleresult;
+  BENCHMARK("set-nxd") {
+    return (*action)(&dq, &ruleresult);
+  };
+
+  rconfig.setAA = true;
+  action = dnsdist::actions::getRCodeAction(RCode::NXDomain, rconfig);
+  BENCHMARK("set-nxd-and-AA") {
+    return (*action)(&dq, &ruleresult);
+  };
+}
index 6d1bc34a201885a21c0d793e3ae783be7dd6faf1..9add9fc7ff31eb0147cfd9269dae63aca0783e3c 100644 (file)
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  */
 #define CATCH_CONFIG_MAIN
+#include <memory>
 #include <catch2/catch_config.hpp>
+#include "dnsdist.hh"
+#include "dnsdist-lua.hh"
+#include "dnsdist-rings.hh"
+#include "dnsdist-xsk.hh"
+#include "dnsdist-tcp.hh"
+
+// NOTE: This file contains waaaaaay too many mocked things to make bench-dnsdist-action-rcode.cc
+// link. In the future, all these functions and declarations should go away and be put into their
+// own hh/cc files.
+
+RecursiveLockGuarded<LuaContext> g_lua{LuaContext()};
+shared_ptr<BPFFilter> g_defaultBPFFilter{nullptr};
+Rings g_rings;
+string g_outputBuffer;
+
+void handleResponseSent([[maybe_unused]] const InternalQueryState& ids, [[maybe_unused]]double udiff, [[maybe_unused]]const ComboAddress& client, [[maybe_unused]]const ComboAddress& backend, [[maybe_unused]]unsigned int size, [[maybe_unused]]const dnsheader& cleartextDH, [[maybe_unused]]dnsdist::Protocol protocol, [[maybe_unused]]bool fromBackend)
+{
+}
+
+void handleResponseSent([[maybe_unused]] const DNSName& qname, [[maybe_unused]]const QType& qtype, [[maybe_unused]]double udiff, [[maybe_unused]]const ComboAddress& client, [[maybe_unused]]const ComboAddress& backend, [[maybe_unused]]unsigned int size, [[maybe_unused]]const dnsheader& cleartextDH, [[maybe_unused]]dnsdist::Protocol outgoingProtocol, [[maybe_unused]]dnsdist::Protocol incomingProtocol, [[maybe_unused]]bool fromBackend)
+{
+}
+
+bool processResponse([[maybe_unused]] PacketBuffer& response, [[maybe_unused]] DNSResponse& dnsResponse, [[maybe_unused]] bool muted)
+{
+  return false;
+}
+
+void doExitNicely(int exitCode);
+void doExitNicely([[maybe_unused]] int exitCode){
+};
+
+ProcessQueryResult processQuery([[maybe_unused]] DNSQuestion& dnsQuestion, [[maybe_unused]]std::shared_ptr<DownstreamState>& selectedBackend)
+{
+  return ProcessQueryResult::Drop;
+};
+
+bool processRulesResult([[maybe_unused]] const DNSAction::Action& action, [[maybe_unused]]DNSQuestion& dnsQuestion, [[maybe_unused]]std::string& ruleresult, [[maybe_unused]]bool& drop)
+{
+  return false;
+}
+
+ProcessQueryResult processQueryAfterRules([[maybe_unused]] DNSQuestion& dnsQuestion, [[maybe_unused]]std::shared_ptr<DownstreamState>& outgoingBackend)
+{
+  return ProcessQueryResult::Drop;
+}
+
+bool processResponseAfterRules([[maybe_unused]] PacketBuffer& response, [[maybe_unused]]DNSResponse& dnsResponse, [[maybe_unused]]bool muted)
+{
+  return false;
+}
+
+bool applyRulesToResponse([[maybe_unused]] const std::vector<dnsdist::rules::ResponseRuleAction>& respRuleActions, [[maybe_unused]]DNSResponse& dnsResponse)
+{
+  (void)respRuleActions;
+  (void)dnsResponse;
+  return true;
+}
+
+bool handleTimeoutResponseRules([[maybe_unused]] const std::vector<dnsdist::rules::ResponseRuleAction>& rules, [[maybe_unused]]InternalQueryState& ids, [[maybe_unused]]const std::shared_ptr<DownstreamState>& d_ds, [[maybe_unused]]const std::shared_ptr<TCPQuerySender>& sender)
+{
+  return false;
+}
+
+void handleServerStateChange([[maybe_unused]] const string& nameWithAddr, [[maybe_unused]]bool newResult)
+{
+}
+
+bool sendUDPResponse([[maybe_unused]] int origFD, [[maybe_unused]]const PacketBuffer& response, [[maybe_unused]]const int delayMsec, [[maybe_unused]]const ComboAddress& origDest, [[maybe_unused]]const ComboAddress& origRemote)
+{
+  return false;
+}
+
+bool assignOutgoingUDPQueryToBackend([[maybe_unused]] std::shared_ptr<DownstreamState>& downstream, [[maybe_unused]]uint16_t queryID, [[maybe_unused]]DNSQuestion& dnsQuestion, [[maybe_unused]]PacketBuffer& query, [[maybe_unused]]bool actuallySend)
+{
+  return true;
+}
+
+#ifdef HAVE_XSK
+namespace dnsdist::xsk
+{
+bool XskProcessQuery([[maybe_unused]] ClientState& clientState, [[maybe_unused]] XskPacket& packet)
+{
+  return false;
+}
+}
+#endif /* HAVE_XSK */
+
+bool processResponderPacket([[maybe_unused]] std::shared_ptr<DownstreamState>& dss, [[maybe_unused]] PacketBuffer& response, [[maybe_unused]] InternalQueryState&& ids)
+{
+  return false;
+}
+
+// NOLINTNEXTLINE(performance-unnecessary-value-param): this is a stub, the real one is not that simple and the performance does not matter
+void responderThread([[maybe_unused]] std::shared_ptr<DownstreamState> dss)
+{
+}
+
+bool checkQueryHeaders([[maybe_unused]] const struct dnsheader& dnsHeader, [[maybe_unused]] ClientState& clientState) {
+  return true;
+}
+
+bool checkDNSCryptQuery([[maybe_unused]] const ClientState& clientState, [[maybe_unused]] PacketBuffer& query, [[maybe_unused]] std::unique_ptr<DNSCryptQuery>& dnsCryptQuery, [[maybe_unused]] time_t now, [[maybe_unused]] bool tcp) {
+  return false;
+}
+
+bool responseContentMatches([[maybe_unused]] const PacketBuffer& response, [[maybe_unused]]const DNSName& qname, [[maybe_unused]]const uint16_t qtype, [[maybe_unused]]const uint16_t qclass, [[maybe_unused]]const std::shared_ptr<DownstreamState>& remote, [[maybe_unused]]bool allowEmptyResponse) {
+  return false;
+}
+
+
+class UDPTCPCrossQuerySender : public TCPQuerySender
+{
+public:
+  UDPTCPCrossQuerySender() = default;
+  UDPTCPCrossQuerySender(const UDPTCPCrossQuerySender&) = delete;
+  UDPTCPCrossQuerySender& operator=(const UDPTCPCrossQuerySender&) = delete;
+  UDPTCPCrossQuerySender(UDPTCPCrossQuerySender&&) = default;
+  UDPTCPCrossQuerySender& operator=(UDPTCPCrossQuerySender&&) = default;
+  ~UDPTCPCrossQuerySender() override = default;
+
+  [[nodiscard]] bool active() const override
+  {
+    return true;
+  }
+
+  void handleResponse([[maybe_unused]] const struct timeval& now, [[maybe_unused]] TCPResponse&& response) override
+  {
+  }
+
+  void handleXFRResponse([[maybe_unused]] const struct timeval& now, [[maybe_unused]] TCPResponse&& response) override
+  {
+  }
+
+  void notifyIOError([[maybe_unused]] const struct timeval& now, [[maybe_unused]] TCPResponse&& response) override
+  {
+  }
+};
+
+
+class UDPCrossProtocolQuery : public CrossProtocolQuery
+{
+public:
+  UDPCrossProtocolQuery() = default;
+  UDPCrossProtocolQuery(PacketBuffer&& buffer_, InternalQueryState&& ids_, std::shared_ptr<DownstreamState> backend) :
+    CrossProtocolQuery(InternalQuery(std::move(buffer_), std::move(ids_)), backend)
+  {
+  }
+  UDPCrossProtocolQuery(const UDPCrossProtocolQuery&) = delete;
+  UDPCrossProtocolQuery& operator=(const UDPCrossProtocolQuery&) = delete;
+  UDPCrossProtocolQuery(UDPCrossProtocolQuery&&) = delete;
+  UDPCrossProtocolQuery& operator=(UDPCrossProtocolQuery&&) = delete;
+  ~UDPCrossProtocolQuery() override = default;
+
+  std::shared_ptr<TCPQuerySender> getTCPQuerySender() override
+  {
+    return s_sender;
+  }
+
+private:
+  static std::shared_ptr<UDPTCPCrossQuerySender> s_sender;
+};
+
+std::shared_ptr<UDPTCPCrossQuerySender> UDPCrossProtocolQuery::s_sender = std::make_shared<UDPTCPCrossQuerySender>();
+
+std::unique_ptr<CrossProtocolQuery> getUDPCrossProtocolQueryFromDQ(DNSQuestion& dnsQuestion);
+std::unique_ptr<CrossProtocolQuery> getUDPCrossProtocolQueryFromDQ([[maybe_unused]] DNSQuestion& dnsQuestion)
+{
+  return std::make_unique<UDPCrossProtocolQuery>();
+}
index 300c7a62a1be3ff86df49bc8fd3e88b02db443a7..8d00f3f9549c737cd17cac363dbe94bcffb2234d 100644 (file)
@@ -594,8 +594,8 @@ if get_option('unit-tests')
   }
 endif
 
-benchmark_sources = []
-benchmark_sources += files(
+benchmark_sources = files(
+  src_dir / 'bench-dnsdist-action-rcode.cc',
   src_dir / 'bench-dnsdist-dnsparser_cc.cc',
   src_dir / 'bench-dnsdist-opentelemetry_cc.cc',
 )
@@ -608,9 +608,18 @@ if get_option('benchmark')
       ],
       'files-extra': [
         benchmark_sources,
+        config_h,
+        mplexer_sources,
+        src_dir / 'dnsdist-lbpolicies.cc',
+        src_dir / 'dnsdist-lua-ffi.cc',
+        src_dir / 'dnstap.cc',
+        src_dir / 'fstrm_logger.cc',
       ],
       'deps-extra': [
         dep_catch2,
+        dep_dnstap,
+        dep_ffi_interface,
+        dep_lua,
         dep_protozero,
       ],
     }