From: Pieter Lexis Date: Thu, 23 Oct 2025 08:22:23 +0000 (+0200) Subject: chore(dnsdist): move handleResponseTC4UDPClient to dnsdist::udp X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=cd669c13c3d449b1590503fe844a7cb9a5de3395;p=thirdparty%2Fpdns.git chore(dnsdist): move handleResponseTC4UDPClient to dnsdist::udp --- diff --git a/pdns/dnsdistdist/dnsdist-udp.cc b/pdns/dnsdistdist/dnsdist-udp.cc index 02dc7d13c8..e119033a96 100644 --- a/pdns/dnsdistdist/dnsdist-udp.cc +++ b/pdns/dnsdistdist/dnsdist-udp.cc @@ -152,4 +152,21 @@ void truncateTC(PacketBuffer& packet, size_t maximumSize, unsigned int qnameWire ++dnsdist::metrics::g_stats.truncFail; } } + +void handleResponseTC4UDPClient(DNSQuestion& dnsQuestion, uint16_t udpPayloadSize, PacketBuffer& response) +{ + if (udpPayloadSize != 0 && response.size() > udpPayloadSize) { + VERBOSESLOG(infolog("Got a response of size %d while the initial UDP payload size was %d, truncating", response.size(), udpPayloadSize), + dnsQuestion.getLogger()->withName("udp-response")->info(Logr::Info, "Got a UDP response larger than the initial UDP payload size, truncating", "dns.response.size", Logging::Loggable(response.size()), "dns.query.udp_payload_size", Logging::Loggable(udpPayloadSize))); + + truncateTC(dnsQuestion.getMutableData(), dnsQuestion.getMaximumSize(), dnsQuestion.ids.qname.wirelength(), dnsdist::configuration::getCurrentRuntimeConfiguration().d_addEDNSToSelfGeneratedResponses); + dnsdist::PacketMangling::editDNSHeaderFromPacket(dnsQuestion.getMutableData(), [](dnsheader& header) { + header.tc = true; + return true; + }); + } + else if (dnsdist::configuration::getCurrentRuntimeConfiguration().d_truncateTC && dnsQuestion.getHeader()->tc) { + truncateTC(response, dnsQuestion.getMaximumSize(), dnsQuestion.ids.qname.wirelength(), dnsdist::configuration::getCurrentRuntimeConfiguration().d_addEDNSToSelfGeneratedResponses); + } +} } // namespace dnsdist::udp diff --git a/pdns/dnsdistdist/dnsdist-udp.hh b/pdns/dnsdistdist/dnsdist-udp.hh index 0c856f83c1..eb108ce927 100644 --- a/pdns/dnsdistdist/dnsdist-udp.hh +++ b/pdns/dnsdistdist/dnsdist-udp.hh @@ -29,6 +29,7 @@ #include "noinitvector.hh" #include "iputils.hh" #include "dnscrypt.hh" +#include "dnsdist.hh" #include "dnsdist-logging.hh" @@ -49,4 +50,5 @@ static_assert(s_initialUDPPacketBufferSize <= std::numeric_limits::max void sendfromto(int sock, const PacketBuffer& buffer, const ComboAddress& from, const ComboAddress& dest); void truncateTC(PacketBuffer& packet, size_t maximumSize, unsigned int qnameWireLength, bool addEDNSToSelfGeneratedResponses); +void handleResponseTC4UDPClient(DNSQuestion& dnsQuestion, uint16_t udpPayloadSize, PacketBuffer& response); } // namespace dnsdist::udp diff --git a/pdns/dnsdistdist/dnsdist.cc b/pdns/dnsdistdist/dnsdist.cc index 8ccf74639c..b628cf21c5 100644 --- a/pdns/dnsdistdist/dnsdist.cc +++ b/pdns/dnsdistdist/dnsdist.cc @@ -551,28 +551,11 @@ void handleResponseSent(DNSName&& qname, const QType& qtype, double latencyUs, c dnsdist::metrics::doLatencyStats(incomingProtocol, latencyUs); } -static void handleResponseTC4UDPClient(DNSQuestion& dnsQuestion, uint16_t udpPayloadSize, PacketBuffer& response) -{ - if (udpPayloadSize != 0 && response.size() > udpPayloadSize) { - VERBOSESLOG(infolog("Got a response of size %d while the initial UDP payload size was %d, truncating", response.size(), udpPayloadSize), - dnsQuestion.getLogger()->withName("udp-response")->info(Logr::Info, "Got a UDP response larger than the initial UDP payload size, truncating", "dns.response.size", Logging::Loggable(response.size()), "dns.query.udp_payload_size", Logging::Loggable(udpPayloadSize))); - - dnsdist::udp::truncateTC(dnsQuestion.getMutableData(), dnsQuestion.getMaximumSize(), dnsQuestion.ids.qname.wirelength(), dnsdist::configuration::getCurrentRuntimeConfiguration().d_addEDNSToSelfGeneratedResponses); - dnsdist::PacketMangling::editDNSHeaderFromPacket(dnsQuestion.getMutableData(), [](dnsheader& header) { - header.tc = true; - return true; - }); - } - else if (dnsdist::configuration::getCurrentRuntimeConfiguration().d_truncateTC && dnsQuestion.getHeader()->tc) { - dnsdist::udp::truncateTC(response, dnsQuestion.getMaximumSize(), dnsQuestion.ids.qname.wirelength(), dnsdist::configuration::getCurrentRuntimeConfiguration().d_addEDNSToSelfGeneratedResponses); - } -} - static void handleResponseForUDPClient(InternalQueryState& ids, PacketBuffer& response, const std::shared_ptr& backend, bool isAsync, bool selfGenerated) { DNSResponse dnsResponse(ids, response, backend); - handleResponseTC4UDPClient(dnsResponse, ids.udpPayloadSize, response); + dnsdist::udp::handleResponseTC4UDPClient(dnsResponse, ids.udpPayloadSize, response); /* when the answer is encrypted in place, we need to get a copy of the original header before encryption to fill the ring buffer */ @@ -1937,7 +1920,7 @@ static void processUDPQuery(ClientState& clientState, const struct msghdr* msgh, const auto dnsHeader = dnsQuestion.getHeader(); if (result == ProcessQueryResult::SendAnswer) { /* ensure payload size is not exceeded */ - handleResponseTC4UDPClient(dnsQuestion, udpPayloadSize, query); + dnsdist::udp::handleResponseTC4UDPClient(dnsQuestion, udpPayloadSize, query); #ifndef DISABLE_RECVMMSG #if defined(HAVE_RECVMMSG) && defined(HAVE_SENDMMSG) && defined(MSG_WAITFORONE) if (dnsQuestion.ids.delayMsec == 0 && responsesVect != nullptr) {