]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
rec: handle serve stale logic in getRootNXTrust() 13409/head
authorOtto Moerbeek <otto.moerbeek@open-xchange.com>
Mon, 23 Oct 2023 07:17:16 +0000 (09:17 +0200)
committerOtto Moerbeek <otto.moerbeek@open-xchange.com>
Mon, 23 Oct 2023 07:17:16 +0000 (09:17 +0200)
Superseded #13383 by calling the general get() function that has
all the special cases covered.

pdns/recursordist/negcache.cc
pdns/recursordist/negcache.hh

index af6cd1fa6aa9b858993e448dc5648be250a390a1..7668a7de411c69f88af51fb2feb1fc068872b3f4 100644 (file)
@@ -53,35 +53,20 @@ size_t NegCache::size() const
  * \param ne       A NegCacheEntry that is filled when there is a cache entry
  * \return         true if ne was filled out, false otherwise
  */
-bool NegCache::getRootNXTrust(const DNSName& qname, const struct timeval& now, NegCacheEntry& ne, bool serveStale, bool refresh)
+bool NegCache::getRootNXTrust(const DNSName& qname, const struct timeval& now, NegCacheEntry& negEntry, bool serveStale, bool refresh)
 {
   // Never deny the root.
-  if (qname.isRoot())
+  if (qname.isRoot()) {
     return false;
+  }
 
-  // An 'ENT' QType entry, used as "whole name" in the neg-cache context.
-  static const QType qtnull(0);
   DNSName lastLabel = qname.getLastLabel();
-
-  auto& map = getMap(lastLabel);
-  auto content = map.lock();
-
-  negcache_t::const_iterator ni = content->d_map.find(std::tie(lastLabel, qtnull));
-
-  while (ni != content->d_map.end() && ni->d_name == lastLabel && ni->d_auth.isRoot() && ni->d_qtype == qtnull) {
-    if (!refresh && (serveStale || ni->d_servedStale > 0) && ni->d_ttd <= now.tv_sec && ni->d_servedStale < s_maxServedStaleExtensions) {
-      updateStaleEntry(now.tv_sec, ni, QType::A);
-    }
-    // We have something
-    if (now.tv_sec < ni->d_ttd) {
-      ne = *ni;
-      moveCacheItemToBack<SequenceTag>(content->d_map, ni);
-      return true;
-    }
-    if (ni->d_servedStale == 0 && !serveStale) {
-      moveCacheItemToFront<SequenceTag>(content->d_map, ni);
-    }
-    ++ni;
+  NegCacheEntry found;
+  // An 'ENT' QType entry, used as "whole name" in the neg-cache context.
+  auto exists = get(lastLabel, QType::ENT, now, found, true, serveStale, refresh);
+  if (exists && found.d_auth.isRoot()) {
+    negEntry = found;
+    return true;
   }
   return false;
 }
index 86c3b562f428e3e1b636cb1c33f5bcfd3bc9c554..8ef17360fec01ced4f2d3769ff473f65783af8a2 100644 (file)
@@ -95,7 +95,7 @@ public:
   void add(const NegCacheEntry& ne);
   void updateValidationStatus(const DNSName& qname, QType qtype, vState newState, boost::optional<time_t> capTTD);
   bool get(const DNSName& qname, QType qtype, const struct timeval& now, NegCacheEntry& ne, bool typeMustMatch = false, bool serverStale = false, bool refresh = false);
-  bool getRootNXTrust(const DNSName& qname, const struct timeval& now, NegCacheEntry& ne, bool serveStale, bool refresh);
+  bool getRootNXTrust(const DNSName& qname, const struct timeval& now, NegCacheEntry& negEntry, bool serveStale, bool refresh);
   size_t count(const DNSName& qname);
   size_t count(const DNSName& qname, QType qtype);
   void prune(time_t now, size_t maxEntries);