]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
Call the right wipe function for negcache
authorOtto Moerbeek <otto.moerbeek@open-xchange.com>
Wed, 1 Mar 2023 08:16:52 +0000 (09:16 +0100)
committerOtto Moerbeek <otto.moerbeek@open-xchange.com>
Wed, 1 Mar 2023 08:16:52 +0000 (09:16 +0100)
pdns/recursordist/negcache.cc
pdns/recursordist/negcache.hh
pdns/recursordist/test-negcache_cc.cc
pdns/syncres.cc

index 7153c6ce172816fdd1a0e308de8aacf5f2183516..50b01abe95af8e148680ff26c2eaace89387b80e 100644 (file)
@@ -242,7 +242,7 @@ size_t NegCache::wipe(const DNSName& name, bool subtree)
   return ret;
 }
 
-size_t NegCache::wipe(const DNSName& qname, QType qtype)
+size_t NegCache::wipeTyped(const DNSName& qname, QType qtype)
 {
   size_t ret = 0;
   auto& map = getMap(qname);
index 97e9be32a93c3057859f9a7d764626096d38c7af..2e989aadef30c33d32067987d1946d9aecfbef06 100644 (file)
@@ -96,7 +96,7 @@ public:
   void clear();
   size_t doDump(int fd, size_t maxCacheEntries);
   size_t wipe(const DNSName& name, bool subtree = false);
-  size_t wipe(const DNSName& name, QType qtype);
+  size_t wipeTyped(const DNSName& name, QType qtype);
   size_t size() const;
 
 private:
index 3306df1da87cacc591b30d64d20a984d36db88df..e050097ec1da85f912d7e69f6f2d9e8bf3302d14 100644 (file)
@@ -438,6 +438,44 @@ BOOST_AUTO_TEST_CASE(test_wipe_subtree)
   BOOST_CHECK_EQUAL(cache.size(), 400U);
 }
 
+BOOST_AUTO_TEST_CASE(test_wipe_typed)
+{
+  string qname(".powerdns.com");
+  DNSName auth("powerdns.com");
+
+  struct timeval now;
+  Utility::gettimeofday(&now, 0);
+
+  NegCache cache;
+  NegCache::NegCacheEntry ne;
+  ne = genNegCacheEntry(auth, auth, now, QType::A);
+  cache.add(ne);
+
+  for (int i = 0; i < 400; i++) {
+    ne = genNegCacheEntry(DNSName(std::to_string(i) + qname), auth, now, QType::A);
+    cache.add(ne);
+  }
+
+  BOOST_CHECK_EQUAL(cache.size(), 401U);
+
+  // Should only wipe the powerdns.com entry
+  cache.wipeTyped(auth, QType::A);
+  BOOST_CHECK_EQUAL(cache.size(), 400U);
+
+  NegCache::NegCacheEntry ne2;
+  bool ret = cache.get(auth, QType(1), now, ne2);
+
+  BOOST_CHECK_EQUAL(ret, false);
+
+  cache.wipeTyped(DNSName("1.powerdns.com"), QType::A);
+  BOOST_CHECK_EQUAL(cache.size(), 399U);
+
+  NegCache::NegCacheEntry ne3;
+  ret = cache.get(auth, QType(1), now, ne3);
+
+  BOOST_CHECK_EQUAL(ret, false);
+}
+
 BOOST_AUTO_TEST_CASE(test_clear)
 {
   string qname(".powerdns.com");
index c01a6ff1c9ae9bd24384e3ae940eeb6586c9a114..ad976bf51b631614c9732cfc9f8296f214792252 100644 (file)
@@ -4601,7 +4601,7 @@ RCode::rcodes_ SyncRes::updateCacheFromRecords(unsigned int depth, LWResult& lwr
         // Delete potential negcache entry. When a record recovers with serve-stale the negcache entry can cause the wrong entry to
         // be served, as negcache entries are checked before record cache entries
         if (NegCache::s_maxServedStaleExtensions > 0) {
-          g_negCache->wipe(i->first.name, i->first.type);
+          g_negCache->wipeTyped(i->first.name, i->first.type);
         }
 
         if (g_aggressiveNSECCache && needWildcardProof && recordState == vState::Secure && i->first.place == DNSResourceRecord::ANSWER && i->first.name == qname && !i->second.signatures.empty() && !d_routingTag && !ednsmask) {