]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
dnsdist: Move DNSQuestion's EDNS options to a unique pointer
authorRemi Gacogne <remi.gacogne@powerdns.com>
Thu, 15 Dec 2022 09:24:39 +0000 (10:24 +0100)
committerRemi Gacogne <remi.gacogne@powerdns.com>
Thu, 15 Dec 2022 09:24:39 +0000 (10:24 +0100)
pdns/dnsdist-ecs.cc
pdns/dnsdist-ecs.hh
pdns/dnsdist-idstate.hh
pdns/dnsdist.hh
pdns/dnsdistdist/dnsdist-rules.hh
pdns/test-dnsdist_cc.cc

index af3240a63f28126c533c01d0b8d8970a9826e89d..9ef06814138a6fd04467bcae06b646baf46b5821 100644 (file)
@@ -263,7 +263,7 @@ bool slowRewriteEDNSOptionInQueryWithRecords(const PacketBuffer& initialPacket,
   return true;
 }
 
-static bool slowParseEDNSOptions(const PacketBuffer& packet, std::shared_ptr<std::map<uint16_t, EDNSOptionView> >& options)
+static bool slowParseEDNSOptions(const PacketBuffer& packet, std::map<uint16_t, EDNSOptionView>& options)
 {
   if (packet.size() < sizeof(dnsheader)) {
     return false;
@@ -304,7 +304,7 @@ static bool slowParseEDNSOptions(const PacketBuffer& packet, std::shared_ptr<std
         }
         /* if we survive this call, we can parse it safely */
         dpm.skipRData();
-        return getEDNSOptions(reinterpret_cast<const char*>(&packet.at(offset)), packet.size() - offset, *options) == 0;
+        return getEDNSOptions(reinterpret_cast<const char*>(&packet.at(offset)), packet.size() - offset, options) == 0;
       }
       else {
         dpm.skipRData();
@@ -515,7 +515,7 @@ bool parseEDNSOptions(const DNSQuestion& dq)
     return true;
   }
 
-  dq.ednsOptions = std::make_shared<std::map<uint16_t, EDNSOptionView> >();
+  dq.ednsOptions = std::make_unique<std::map<uint16_t, EDNSOptionView> >();
 
   if (ntohs(dh->arcount) == 0) {
     /* nothing in additional so no EDNS */
@@ -523,7 +523,7 @@ bool parseEDNSOptions(const DNSQuestion& dq)
   }
 
   if (ntohs(dh->ancount) != 0 || ntohs(dh->nscount) != 0 || ntohs(dh->arcount) > 1) {
-    return slowParseEDNSOptions(dq.getData(), dq.ednsOptions);
+    return slowParseEDNSOptions(dq.getData(), *dq.ednsOptions);
   }
 
   size_t remaining = 0;
@@ -1051,12 +1051,11 @@ bool queryHasEDNS(const DNSQuestion& dq)
   return false;
 }
 
-bool getEDNS0Record(const DNSQuestion& dq, EDNS0Record& edns0)
+bool getEDNS0Record(const PacketBuffer& packet, EDNS0Record& edns0)
 {
   uint16_t optStart;
   size_t optLen = 0;
   bool last = false;
-  const auto& packet = dq.getData();
   int res = locateEDNSOptRR(packet, &optStart, &optLen, &last);
   if (res != 0) {
     // no EDNS OPT RR
index 043756a3fb0633b55e1aadb52ed858304398cf61..f5dbc56c253ba99c8a2f5448c0736c125629aa18 100644 (file)
@@ -54,6 +54,6 @@ bool parseEDNSOptions(const DNSQuestion& dq);
 
 int getEDNSZ(const DNSQuestion& dq);
 bool queryHasEDNS(const DNSQuestion& dq);
-bool getEDNS0Record(const DNSQuestion& dq, EDNS0Record& edns0);
+bool getEDNS0Record(const PacketBuffer& packet, EDNS0Record& edns0);
 
 bool setEDNSOption(DNSQuestion& dq, uint16_t ednsCode, const std::string& data);
index 944fed5c694724982b2e2bed33d73c935a7971bf..2da6be64726ac7e3ff8b718d86ec7b04bba6420f 100644 (file)
@@ -122,7 +122,7 @@ struct InternalQueryState
   std::shared_ptr<DNSDistPacketCache> packetCache{nullptr}; // 16
   std::unique_ptr<DNSCryptQuery> dnsCryptQuery{nullptr}; // 8
   std::unique_ptr<QTag> qTag{nullptr}; // 8
-  boost::optional<uint32_t> tempFailureTTL; // 8
+  boost::optional<uint32_t> tempFailureTTL{boost::none}; // 8
   ClientState* cs{nullptr}; // 8
   std::unique_ptr<DOHUnit, void (*)(DOHUnit*)> du; // 8
   uint32_t cacheKey{0}; // 4
index f7111d131e1a9373e1bc5866e17ff9590f6e860a..f7dbac5e90c530f51d6e0058a37fc0ac1bf41804 100644 (file)
@@ -146,7 +146,7 @@ public:
   InternalQueryState& ids;
   std::unique_ptr<Netmask> ecs{nullptr};
   std::string sni; /* Server Name Indication, if any (DoT or DoH) */
-  mutable std::shared_ptr<std::map<uint16_t, EDNSOptionView> > ednsOptions;
+  mutable std::unique_ptr<std::map<uint16_t, EDNSOptionView> > ednsOptions; /* this needs to be mutable because it is parsed just in time, when DNSQuestion is read-only */
   std::unique_ptr<std::vector<ProxyProtocolValue>> proxyProtocolValues{nullptr};
   uint16_t ecsPrefixLength;
   uint8_t ednsRCode{0};
index fdf9edc01f362b183c144810b16ba8b39cf79e47..13ffe52318ad9f53c47b089e2ed4a56b64b60366 100644 (file)
@@ -924,7 +924,7 @@ public:
     }
 
     EDNS0Record edns0;
-    if (!getEDNS0Record(*dq, edns0)) {
+    if (!getEDNS0Record(dq->getData(), edns0)) {
       return false;
     }
 
@@ -948,7 +948,7 @@ public:
   bool matches(const DNSQuestion* dq) const override
   {
     EDNS0Record edns0;
-    if (!getEDNS0Record(*dq, edns0)) {
+    if (!getEDNS0Record(dq->getData(), edns0)) {
       return false;
     }
 
index be7a43d3e6256d2da71497d8376a13f4965b07a5..71e140b99c25090f74846ff3469eb9325ce57f28 100644 (file)
@@ -2215,7 +2215,7 @@ BOOST_AUTO_TEST_CASE(test_setEDNSOption)
   BOOST_CHECK_EQUAL(mdp.d_answers.at(0).first.d_name, g_rootdnsname);
 
   EDNS0Record edns0;
-  BOOST_REQUIRE(getEDNS0Record(dq, edns0));
+  BOOST_REQUIRE(getEDNS0Record(dq.getData(), edns0));
   BOOST_CHECK_EQUAL(edns0.version, 0U);
   BOOST_CHECK_EQUAL(edns0.extRCode, 0U);
   BOOST_CHECK_EQUAL(edns0.extFlags, EDNS_HEADER_FLAG_DO);