]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
Add the ability to purge an entire view from the packetcache.
authorMiod Vallat <miod.vallat@powerdns.com>
Wed, 28 May 2025 12:50:31 +0000 (14:50 +0200)
committerMiod Vallat <miod.vallat@powerdns.com>
Wed, 11 Jun 2025 05:27:20 +0000 (07:27 +0200)
pdns/auth-packetcache.cc
pdns/auth-packetcache.hh
pdns/test-packetcache_cc.cc

index 16275dd008d5f129a78e8e5fe075e10301718d5a..2be70171685ddebdc6852bf6dd416b974d2816aa 100644 (file)
@@ -282,6 +282,24 @@ uint64_t AuthPacketCache::purgeExact(const std::string& view, const DNSName& qna
   return delcount;
 }
 
+uint64_t AuthPacketCache::purgeView(const std::string& view)
+{
+  uint64_t delcount = 0;
+
+  {
+    auto cache = d_cache.write_lock();
+    if (auto iter = cache->find(view); iter != cache->end()) {
+      auto* map = iter->second.get();
+      delcount += purgeLockedCollectionsVector(*map);
+      cache->erase(iter);
+    }
+  }
+
+  *d_statnumentries -= delcount;
+
+  return delcount;
+}
+
 /* purges entries from the packetcache. If match ends on a $, it is treated as a suffix */
 uint64_t AuthPacketCache::purge(const string &match)
 {
index f5cf00043ad3f50f2ca2c09a35aaf4d410ecdf0a..b10a6b210e05af89c98073a47262d7662fcc9a10 100644 (file)
@@ -66,6 +66,7 @@ public:
   uint64_t purge(const std::string& match); // could be $ terminated. Is not a dnsname!
   uint64_t purgeExact(const DNSName& qname); // no wildcard matching here
   uint64_t purgeExact(const std::string& view, const DNSName& qname); // same as above, but in the given view
+  uint64_t purgeView(const std::string& view);
 
   uint64_t size() const { return *d_statnumentries; };
 
index 021479e68aa25ff3b69bb465a76d8ca0223cc2f6..037860130bbadc6c21cf5c879fccde6764360967 100644 (file)
@@ -708,6 +708,19 @@ BOOST_AUTO_TEST_CASE(test_AuthViews)
 
   // Check that requesting from view2 causes a cache miss
   BOOST_CHECK_EQUAL(queryPacketCache2(PC, ZC, ComboAddress("192.0.2.1"), qname, innerMask, view2, "2.2.2.2"), false);
+
+  // Cache answers for view1 and view2 again
+  feedPacketCache2(PC, view1, 0x01010101, qname);
+  feedPacketCache2(PC, view2, 0x02020202, qname);
+  BOOST_CHECK_EQUAL(PC.size(), 2);
+
+  // Purge view1
+  BOOST_CHECK_EQUAL(PC.purgeView(view1), 1);
+  BOOST_CHECK_EQUAL(PC.size(), 1);
+
+  // Purge view2
+  BOOST_CHECK_EQUAL(PC.purgeView(view2), 1);
+  BOOST_CHECK_EQUAL(PC.size(), 0);
 }
 #endif // ] PDNS_AUTH