From: Otto Moerbeek Date: Wed, 21 Dec 2022 09:12:46 +0000 (+0100) Subject: Change the logic a bit, as negcache->get() can be called with qtype = QType:::ENT, X-Git-Tag: rec-4.8.2~4^2 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=refs%2Fpull%2F12455%2Fhead;p=thirdparty%2Fpdns.git Change the logic a bit, as negcache->get() can be called with qtype = QType:::ENT, but we do not want to push a task with QType::ENT Also change a few QType& to QType, it's a small int, no need to pass by reference. (cherry picked from commit 2541e0f53c6abba298b4a86032bdbc7dfff3ee03) --- diff --git a/pdns/recursordist/negcache.cc b/pdns/recursordist/negcache.cc index 95a5f6c757..542e99acba 100644 --- a/pdns/recursordist/negcache.cc +++ b/pdns/recursordist/negcache.cc @@ -70,7 +70,7 @@ bool NegCache::getRootNXTrust(const DNSName& qname, const struct timeval& now, N 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(QType::A)); + updateStaleEntry(now.tv_sec, ni, QType::A); } // We have something if (now.tv_sec < ni->d_ttd) { @@ -86,7 +86,7 @@ bool NegCache::getRootNXTrust(const DNSName& qname, const struct timeval& now, N return false; } -void NegCache::updateStaleEntry(time_t now, negcache_t::iterator& entry, const QType& qtype) +void NegCache::updateStaleEntry(time_t now, negcache_t::iterator& entry, QType qtype) { // We need to take care a infrequently access stale item cannot be extended past // s_maxServedStaleExtension * s_serveStaleExtensionPeriod @@ -96,7 +96,11 @@ void NegCache::updateStaleEntry(time_t now, negcache_t::iterator& entry, const Q entry->d_servedStale = std::min(entry->d_servedStale + 1 + howlong / extension, static_cast(s_maxServedStaleExtensions)); entry->d_ttd = now + std::min(entry->d_orig_ttl, s_serveStaleExtensionPeriod); - pushAlmostExpiredTask(entry->d_name, entry->d_qtype == 0 ? qtype : entry->d_qtype, entry->d_ttd, Netmask()); + if (qtype == QType::ENT) { + qtype = QType::A; + } + + pushAlmostExpiredTask(entry->d_name, qtype, entry->d_ttd, Netmask()); } /*! @@ -108,7 +112,7 @@ void NegCache::updateStaleEntry(time_t now, negcache_t::iterator& entry, const Q * \param ne A NegCacheEntry that is filled when there is a cache entry * \return true if ne was filled out, false otherwise */ -bool NegCache::get(const DNSName& qname, const QType& qtype, const struct timeval& now, NegCacheEntry& ne, bool typeMustMatch, bool serveStale, bool refresh) +bool NegCache::get(const DNSName& qname, QType qtype, const struct timeval& now, NegCacheEntry& ne, bool typeMustMatch, bool serveStale, bool refresh) { auto& map = getMap(qname); auto content = map.lock(); @@ -119,7 +123,7 @@ bool NegCache::get(const DNSName& qname, const QType& qtype, const struct timeva while (ni != range.second) { // We have an entry - if ((!typeMustMatch && ni->d_qtype.getCode() == 0) || ni->d_qtype == qtype) { + if ((!typeMustMatch && ni->d_qtype == QType::ENT) || ni->d_qtype == qtype) { // We match the QType or the whole name is denied auto firstIndexIterator = content->d_map.project(ni); @@ -163,7 +167,7 @@ void NegCache::add(const NegCacheEntry& ne) * \param qtype The type of the entry to replace * \param newState The new validation state */ -void NegCache::updateValidationStatus(const DNSName& qname, const QType& qtype, const vState newState, boost::optional capTTD) +void NegCache::updateValidationStatus(const DNSName& qname, const QType qtype, const vState newState, boost::optional capTTD) { auto& mc = getMap(qname); auto map = mc.lock(); diff --git a/pdns/recursordist/negcache.hh b/pdns/recursordist/negcache.hh index d4b9c629d5..4e4648aa48 100644 --- a/pdns/recursordist/negcache.hh +++ b/pdns/recursordist/negcache.hh @@ -87,11 +87,11 @@ public: }; void add(const NegCacheEntry& ne); - void updateValidationStatus(const DNSName& qname, const QType& qtype, const vState newState, boost::optional capTTD); - bool get(const DNSName& qname, const QType& qtype, const struct timeval& now, NegCacheEntry& ne, bool typeMustMatch = false, bool serverStale = false, bool refresh = false); + 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); size_t count(const DNSName& qname); - size_t count(const DNSName& qname, const QType qtype); + size_t count(const DNSName& qname, QType qtype); void prune(size_t maxEntries); void clear(); size_t doDump(int fd, size_t maxCacheEntries); @@ -120,7 +120,7 @@ private: member>>> negcache_t; - void updateStaleEntry(time_t now, negcache_t::iterator& entry, const QType& qtype); + void updateStaleEntry(time_t now, negcache_t::iterator& entry, QType qtype); struct MapCombo {