From: Pieter Lexis Date: Wed, 22 Oct 2025 16:08:56 +0000 (+0200) Subject: chore(dnsdist): move restoreFlags to dnsdist::PacketMangling X-Git-Url: http://git.ipfire.org/gitweb/index.cgi?a=commitdiff_plain;h=468ea543a6989c86b6fcbe303e4da0fca5c8a3a4;p=thirdparty%2Fpdns.git chore(dnsdist): move restoreFlags to dnsdist::PacketMangling --- diff --git a/pdns/dnsdistdist/dnsdist-dnsparser.cc b/pdns/dnsdistdist/dnsdist-dnsparser.cc index 4fe07e3642..bafbda570c 100644 --- a/pdns/dnsdistdist/dnsdist-dnsparser.cc +++ b/pdns/dnsdistdist/dnsdist-dnsparser.cc @@ -248,6 +248,19 @@ namespace PacketMangling editDNSPacketTTL(reinterpret_cast(packet.data()), packet.size(), visitor); } + void restoreFlags(struct dnsheader* dnsHeader, uint16_t origFlags) + { + static const uint16_t rdMask = 1 << FLAGS_RD_OFFSET; + static const uint16_t cdMask = 1 << FLAGS_CD_OFFSET; + static const uint16_t restoreFlagsMask = UINT16_MAX & ~(rdMask | cdMask); + uint16_t* flags = getFlagsFromDNSHeader(dnsHeader); + /* clear the flags we are about to restore */ + *flags &= restoreFlagsMask; + /* only keep the flags we want to restore */ + origFlags &= ~restoreFlagsMask; + /* set the saved flags as they were */ + *flags |= origFlags; + } } namespace RecordParsers diff --git a/pdns/dnsdistdist/dnsdist-dnsparser.hh b/pdns/dnsdistdist/dnsdist-dnsparser.hh index 88a93b47e9..943bba0ce3 100644 --- a/pdns/dnsdistdist/dnsdist-dnsparser.hh +++ b/pdns/dnsdistdist/dnsdist-dnsparser.hh @@ -61,6 +61,7 @@ namespace PacketMangling bool editDNSHeaderFromPacket(PacketBuffer& packet, const std::function& editFunction); bool editDNSHeaderFromRawPacket(void* packet, const std::function& editFunction); void restrictDNSPacketTTLs(PacketBuffer& packet, uint32_t minimumValue, uint32_t maximumValue = std::numeric_limits::max(), const std::unordered_set& types = {}); + void restoreFlags(struct dnsheader* dnsHeader, uint16_t origFlags); } namespace RecordParsers diff --git a/pdns/dnsdistdist/dnsdist.cc b/pdns/dnsdistdist/dnsdist.cc index 16eaba147c..c84a51574e 100644 --- a/pdns/dnsdistdist/dnsdist.cc +++ b/pdns/dnsdistdist/dnsdist.cc @@ -252,24 +252,10 @@ bool responseContentMatches(const PacketBuffer& response, const DNSName& qname, } } -static void restoreFlags(struct dnsheader* dnsHeader, uint16_t origFlags) -{ - static const uint16_t rdMask = 1 << FLAGS_RD_OFFSET; - static const uint16_t cdMask = 1 << FLAGS_CD_OFFSET; - static const uint16_t restoreFlagsMask = UINT16_MAX & ~(rdMask | cdMask); - uint16_t* flags = getFlagsFromDNSHeader(dnsHeader); - /* clear the flags we are about to restore */ - *flags &= restoreFlagsMask; - /* only keep the flags we want to restore */ - origFlags &= ~restoreFlagsMask; - /* set the saved flags as they were */ - *flags |= origFlags; -} - static bool fixUpQueryTurnedResponse(DNSQuestion& dnsQuestion, const uint16_t origFlags) { dnsdist::PacketMangling::editDNSHeaderFromPacket(dnsQuestion.getMutableData(), [origFlags](dnsheader& header) { - restoreFlags(&header, origFlags); + dnsdist::PacketMangling::restoreFlags(&header, origFlags); return true; }); @@ -286,7 +272,7 @@ static bool fixUpResponse(PacketBuffer& response, const DNSName& qname, uint16_t } dnsdist::PacketMangling::editDNSHeaderFromPacket(response, [origFlags](dnsheader& header) { - restoreFlags(&header, origFlags); + dnsdist::PacketMangling::restoreFlags(&header, origFlags); return true; }); @@ -1531,7 +1517,7 @@ ProcessQueryResult processQueryAfterRules(DNSQuestion& dnsQuestion, std::shared_ if (serverPool.packetCache->get(dnsQuestion, dnsQuestion.getHeader()->id, dnsQuestion.ids.protocol == dnsdist::Protocol::DoH ? &dnsQuestion.ids.cacheKeyTCP : &dnsQuestion.ids.cacheKey, dnsQuestion.ids.subnet, *dnsQuestion.ids.dnssecOK, dnsQuestion.ids.protocol != dnsdist::Protocol::DoH && willBeForwardedOverUDP, allowExpired, false, true, dnsQuestion.ids.protocol != dnsdist::Protocol::DoH || !willBeForwardedOverUDP)) { dnsdist::PacketMangling::editDNSHeaderFromPacket(dnsQuestion.getMutableData(), [flags = dnsQuestion.ids.origFlags](dnsheader& header) { - restoreFlags(&header, flags); + dnsdist::PacketMangling::restoreFlags(&header, flags); return true; }); @@ -1638,7 +1624,7 @@ bool handleTimeoutResponseRules(const std::vector