From: Otto Moerbeek Date: Mon, 23 Oct 2023 07:17:16 +0000 (+0200) Subject: rec: handle serve stale logic in getRootNXTrust() X-Git-Tag: rec-5.0.0-beta1~26^2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=e2bfa1460d5b9e4e470c2f8829ef6c10bc583c73;p=thirdparty%2Fpdns.git rec: handle serve stale logic in getRootNXTrust() Superseded #13383 by calling the general get() function that has all the special cases covered. --- diff --git a/pdns/recursordist/negcache.cc b/pdns/recursordist/negcache.cc index af6cd1fa6a..7668a7de41 100644 --- a/pdns/recursordist/negcache.cc +++ b/pdns/recursordist/negcache.cc @@ -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(content->d_map, ni); - return true; - } - if (ni->d_servedStale == 0 && !serveStale) { - moveCacheItemToFront(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; } diff --git a/pdns/recursordist/negcache.hh b/pdns/recursordist/negcache.hh index 86c3b562f4..8ef17360fe 100644 --- a/pdns/recursordist/negcache.hh +++ b/pdns/recursordist/negcache.hh @@ -95,7 +95,7 @@ public: void add(const NegCacheEntry& ne); void updateValidationStatus(const DNSName& qname, QType qtype, vState newState, boost::optional 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);