]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
Prevent lookups for unsupported qtypes or rcode != 0 to submit refresh tasks
authorOtto Moerbeek <otto.moerbeek@open-xchange.com>
Mon, 18 Sep 2023 09:38:10 +0000 (11:38 +0200)
committerOtto Moerbeek <otto.moerbeek@open-xchange.com>
Mon, 18 Sep 2023 09:38:10 +0000 (11:38 +0200)
pdns/recursordist/rec-taskqueue.cc
pdns/recursordist/rec-taskqueue.hh
pdns/recursordist/recpacketcache.cc
pdns/recursordist/recpacketcache.hh

index 29cc6d75c889effc6b767d76011256dcc37ded89..8526e8d4c9644e233aa05e3cb426652a5459db78 100644 (file)
@@ -336,3 +336,8 @@ uint64_t getResolveTaskExceptions()
 {
   return s_almost_expired_tasks.exceptions;
 }
+
+bool taskQTypeIsSupported(QType qtype)
+{
+  return !SyncRes::isUnsupported(qtype);
+}
index 425cb55ac05f63d79046c2d3b33bb6b078adc6c6..73eedeecede7ced32c4132f39d2634b5fd541fb2 100644 (file)
@@ -23,6 +23,7 @@
 
 #include <cstdint>
 #include <ctime>
+#include <qtype.hh>
 
 class DNSName;
 union ComboAddress;
@@ -54,3 +55,6 @@ uint64_t getResolveTaskExceptions();
 uint64_t getAlmostExpiredTasksPushed();
 uint64_t getAlmostExpiredTasksRun();
 uint64_t getAlmostExpiredTaskExceptions();
+
+bool taskQTypeIsSupported(QType qtype);
+
index 184555ebd8e7b928e6042cce5de98e962163efc8..77dc63e1e12684d334f37ececf1f6e053b44cf07 100644 (file)
@@ -126,12 +126,16 @@ bool RecursorPacketCache::checkResponseMatches(MapCombo::LockedContent& shard, s
       *age = static_cast<uint32_t>(now - iter->d_creation);
       // we know ttl is > 0
       auto ttl = static_cast<uint32_t>(iter->d_ttd - now);
-      if (s_refresh_ttlperc > 0 && !iter->d_submitted) {
-        const uint32_t deadline = iter->getOrigTTL() * s_refresh_ttlperc / 100;
-        const bool almostExpired = ttl <= deadline;
-        if (almostExpired) {
-          iter->d_submitted = true;
-          pushAlmostExpiredTask(qname, qtype, iter->d_ttd, Netmask());
+      if (s_refresh_ttlperc > 0 && !iter->d_submitted && taskQTypeIsSupported(qtype)) {
+        const dnsheader_aligned header(iter->d_packet.data());
+        const auto* headerPtr = header.get();
+        if (headerPtr->rcode == RCode::NoError) {
+          const uint32_t deadline = iter->getOrigTTL() * s_refresh_ttlperc / 100;
+          const bool almostExpired = ttl <= deadline;
+          if (almostExpired) {
+            iter->d_submitted = true;
+            pushAlmostExpiredTask(qname, qtype, iter->d_ttd, Netmask());
+          }
         }
       }
       *responsePacket = iter->d_packet;
@@ -244,7 +248,7 @@ void RecursorPacketCache::insertResponsePacket(unsigned int tag, uint32_t qhash,
     seq_idx.erase(seq_idx.begin());
     map.d_entriesCount--;
   }
-  assert(map.d_entriesCount == shard->d_map.size()); // XXX
+  assert(map.d_entriesCount == shard->d_map.size()); // NOLINT(cppcoreguidelines-pro-bounds-array-to-pointer-decay): clib implementation
 }
 
 void RecursorPacketCache::doPruneTo(size_t maxSize)
index 5ff974fefdcef7820e358a61bbdf1c43d46a2fc2..2e847687a127c0f7e58d9283a8df31e1f85be989 100644 (file)
@@ -208,7 +208,7 @@ private:
   }
 
   static bool qrMatch(const packetCache_t::index<HashTag>::type::iterator& iter, const std::string& queryPacket, const DNSName& qname, uint16_t qtype, uint16_t qclass);
-  bool checkResponseMatches(MapCombo::LockedContent& shard, std::pair<packetCache_t::index<HashTag>::type::iterator, packetCache_t::index<HashTag>::type::iterator> range, const std::string& queryPacket, const DNSName& qname, uint16_t qtype, uint16_t qclass, time_t now, std::string* responsePacket, uint32_t* age, vState* valState, OptPBData* pbdata);
+  static bool checkResponseMatches(MapCombo::LockedContent& shard, std::pair<packetCache_t::index<HashTag>::type::iterator, packetCache_t::index<HashTag>::type::iterator> range, const std::string& queryPacket, const DNSName& qname, uint16_t qtype, uint16_t qclass, time_t now, std::string* responsePacket, uint32_t* age, vState* valState, OptPBData* pbdata);
 
   void setShardSizes(size_t shardSize);