]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
chore(dnsdist): Move some limits to a new dnsdist-udp header
authorPieter Lexis <pieter.lexis@powerdns.com>
Wed, 22 Oct 2025 14:38:27 +0000 (16:38 +0200)
committerPieter Lexis <pieter.lexis@powerdns.com>
Mon, 1 Jun 2026 10:52:27 +0000 (12:52 +0200)
pdns/dnsdistdist/dnsdist-udp.hh
pdns/dnsdistdist/dnsdist.cc

index f2a2ff0445c7efefa5f9178a4541873cbed19089..ff7556d4329502583be868dd1f8763af6ac9ae8c 100644 (file)
 #pragma once
 
 #include <cstdint>
+#include <cstddef>
+#include <cstdint>
+#include <limits>
+
+#include "noinitvector.hh"
+#include "iputils.hh"
+#include "dnscrypt.hh"
 
 #include "dnsdist-logging.hh"
 
@@ -34,4 +41,11 @@ enum class Context : uint8_t
 };
 
 void setUDPSocketBufferSizes(int socketDesc, const Logr::Logger& logger, Context context, const ComboAddress& addr);
-}
+
+// we are not willing to receive a bigger UDP response than that, no matter what
+static constexpr size_t s_maxUDPResponsePacketSize{4096U};
+static size_t const s_initialUDPPacketBufferSize = s_maxUDPResponsePacketSize + DNSCRYPT_MAX_RESPONSE_PADDING_AND_MAC_SIZE;
+static_assert(s_initialUDPPacketBufferSize <= std::numeric_limits<uint16_t>::max(), "Packet size should fit in a uint16_t");
+
+void sendfromto(int sock, const PacketBuffer& buffer, const ComboAddress& from, const ComboAddress& dest);
+} // namespace dnsdist::udp
index 5119d69a54504944100539b035f13f7a7f3381b8..d5a3db301f5f6ddc6989fc95106988ac58a360b1 100644 (file)
@@ -80,6 +80,7 @@
 #include "dnsdist-udp.hh"
 #include "dnsdist-web.hh"
 #include "dnsdist-xsk.hh"
+#include "dnsdist-udp.hh"
 
 #include "base64.hh"
 #include "capabilities.hh"
@@ -130,10 +131,6 @@ shared_ptr<BPFFilter> g_defaultBPFFilter{nullptr};
 
 Rings g_rings;
 
-// we are not willing to receive a bigger UDP response than that, no matter what
-static constexpr size_t s_maxUDPResponsePacketSize{4096U};
-static size_t const s_initialUDPPacketBufferSize = s_maxUDPResponsePacketSize + DNSCRYPT_MAX_RESPONSE_PADDING_AND_MAC_SIZE;
-static_assert(s_initialUDPPacketBufferSize <= UINT16_MAX, "Packet size should fit in a uint16_t");
 
 static void sendfromto(int sock, const PacketBuffer& buffer, const ComboAddress& from, const ComboAddress& dest)
 {
@@ -521,7 +518,7 @@ bool processResponseAfterRules(PacketBuffer& response, DNSResponse& dnsResponse,
     return false;
   }
 
-  if (dnsResponse.ids.packetCache && !dnsResponse.ids.selfGenerated && !dnsResponse.ids.skipCache && (!dnsResponse.ids.forwardedOverUDP || response.size() <= s_maxUDPResponsePacketSize)) {
+  if (dnsResponse.ids.packetCache && !dnsResponse.ids.selfGenerated && !dnsResponse.ids.skipCache && (!dnsResponse.ids.forwardedOverUDP || response.size() <= dnsdist::udp::s_maxUDPResponsePacketSize)) {
     if (!dnsResponse.ids.useZeroScope) {
       /* if the query was not suitable for zero-scope, for
          example because it had an existing ECS entry so the hash is
@@ -600,14 +597,14 @@ bool processResponse(PacketBuffer& response, DNSResponse& dnsResponse, bool mute
 
 static size_t getInitialUDPPacketBufferSize(bool expectProxyProtocol)
 {
-  static_assert(dnsdist::configuration::s_udpIncomingBufferSize <= s_initialUDPPacketBufferSize, "The incoming buffer size should not be larger than s_initialUDPPacketBufferSize");
+  static_assert(dnsdist::configuration::s_udpIncomingBufferSize <= dnsdist::udp::s_initialUDPPacketBufferSize, "The incoming buffer size should not be larger than s_initialUDPPacketBufferSize");
 
   const auto& runtimeConfig = dnsdist::configuration::getCurrentRuntimeConfiguration();
   if (!expectProxyProtocol || runtimeConfig.d_proxyProtocolACL.empty()) {
-    return s_initialUDPPacketBufferSize;
+    return dnsdist::udp::s_initialUDPPacketBufferSize;
   }
 
-  return s_initialUDPPacketBufferSize + runtimeConfig.d_proxyProtocolMaximumSize;
+  return dnsdist::udp::s_initialUDPPacketBufferSize + runtimeConfig.d_proxyProtocolMaximumSize;
 }
 
 static size_t getMaximumIncomingPacketSize(const ClientState& clientState)