]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
clean negcache&& clean cname cache
authorzhaojingshi <zhaojingshi@bytedance.com>
Fri, 6 Jan 2023 16:21:45 +0000 (00:21 +0800)
committerOtto Moerbeek <otto.moerbeek@open-xchange.com>
Mon, 9 Jan 2023 12:24:29 +0000 (13:24 +0100)
pdns/recursordist/negcache.cc
pdns/recursordist/negcache.hh
pdns/recursordist/recursor_cache.cc
pdns/recursordist/recursor_cache.hh
pdns/recursordist/syncres.cc

index b52690951723648854644a10ab84247f33069236..af33d7dc3fe58c4518015467e26790d81f8c5a5d 100644 (file)
@@ -44,6 +44,25 @@ size_t NegCache::size() const
   return count;
 }
 
+void NegCache::purge(const DNSName& qname, QType qtype)
+{
+  auto& mc = getMap(qname);
+  auto content = mc.lock();
+  auto& idx = content->d_map.get<NegCacheEntry>();
+
+  auto range = idx.equal_range(qname);
+  auto ni = range.first;
+
+  while (ni != range.second) {
+    // We have an entry
+    if ((ni->d_qtype == QType::ENT) || ni->d_qtype == qtype) {
+        ni = idx.erase(ni);
+    }
+    else
+        ++ni;
+  }
+}
+
 /*!
  * Set ne to the NegCacheEntry for the last label in qname and return true if there
  * was one.
index 4e4648aa48890bc2dcf7c2bca9176041d2472ab9..d3d61f7cbf423e9af01d633bcbe90f0f25125404 100644 (file)
@@ -97,6 +97,8 @@ public:
   size_t doDump(int fd, size_t maxCacheEntries);
   size_t wipe(const DNSName& name, bool subtree = false);
   size_t size() const;
+  void purge(const DNSName& qname, QType qtype);
+
 
 private:
   struct CompositeKey
index 2bf5d556e999149ac8419db312aece30ccae5d42..984cc81a0d244ca628e8769666eb051a11fa6d25 100644 (file)
@@ -316,6 +316,20 @@ bool MemRecursorCache::entryMatches(MemRecursorCache::OrderedTagIterator_t& entr
   return match;
 }
 
+void MemRecursorCache::purge(const DNSName& qname, QType qt)
+{
+   if(qt == QType::CNAME)
+   {
+        auto& mc = getMap(qname);
+        auto map = mc.lock();
+        auto key = std::make_tuple(qname, qt, boost::none, Netmask());
+        auto entry = map->d_map.find(key);
+        if (entry != map->d_map.end()) {
+            map->d_map.erase(entry);
+        }
+   }  
+}
+
 // Fake a cache miss if more than refreshTTLPerc of the original TTL has passed
 time_t MemRecursorCache::fakeTTD(MemRecursorCache::OrderedTagIterator_t& entry, const DNSName& qname, QType qtype, time_t ret, time_t now, uint32_t origTTL, bool refresh)
 {
index 91102d99ae2e8fe66f57ab72043f542545d51b2f..ae9981f53c91f14bfa500905320a12935057f8b1 100644 (file)
@@ -72,6 +72,7 @@ public:
   void replace(time_t, const DNSName& qname, const QType qt, const vector<DNSRecord>& content, const vector<shared_ptr<RRSIGRecordContent>>& signatures, const std::vector<std::shared_ptr<DNSRecord>>& authorityRecs, bool auth, const DNSName& authZone, boost::optional<Netmask> ednsmask = boost::none, const OptTag& routingTag = boost::none, vState state = vState::Indeterminate, boost::optional<ComboAddress> from = boost::none, bool refresh = false);
 
   void doPrune(size_t keep);
+  void purge(const DNSName& qname, QType qt);
   uint64_t doDump(int fd, size_t maxCacheEntries);
 
   size_t doWipeCache(const DNSName& name, bool sub, QType qtype = 0xffff);
index e4f2aa3ce24f02eedd63d5f06324576f17c37936..5e23111624af8d039162e071ec2092692b54e534 100644 (file)
@@ -4637,7 +4637,9 @@ RCode::rcodes_ SyncRes::updateCacheFromRecords(unsigned int depth, LWResult& lwr
           rememberParentSetIfNeeded(i->first.name, i->second.records, depth);
         }
         g_recCache->replace(d_now.tv_sec, i->first.name, i->first.type, i->second.records, i->second.signatures, authorityRecs, i->first.type == QType::DS ? true : isAA, auth, i->first.place == DNSResourceRecord::ANSWER ? ednsmask : boost::none, d_routingTag, recordState, remoteIP, d_refresh);
-
+        // delete negcache
+        g_negCache->purge(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) {
           /* we have an answer synthesized from a wildcard and aggressive NSEC is enabled, we need to store the
              wildcard in its non-expanded form in the cache to be able to synthesize wildcard answers later */
@@ -4803,6 +4805,9 @@ bool SyncRes::processRecords(const std::string& prefix, const DNSName& qname, co
       */
       if (newtarget.empty() && putInNegCache) {
         g_negCache->add(ne);
+        if(qtype == QType::CNAME){
+            g_recCache->purge(qname, qtype);
+        }
         if (s_rootNXTrust && ne.d_auth.isRoot() && auth.isRoot() && lwr.d_aabit) {
           ne.d_name = ne.d_name.getLastLabel();
           g_negCache->add(ne);