]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
Change the logic a bit, as negcache->get() can be called with qtype = QType:::ENT, 12455/head
authorOtto Moerbeek <otto.moerbeek@open-xchange.com>
Wed, 21 Dec 2022 09:12:46 +0000 (10:12 +0100)
committerOtto Moerbeek <otto.moerbeek@open-xchange.com>
Mon, 23 Jan 2023 15:39:01 +0000 (16:39 +0100)
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)

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

index 95a5f6c75795590c1cf2375caaab4688a0500247..542e99acba52ee24c83e3254a98ee0cf50a1a9a4 100644 (file)
@@ -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<time_t>(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<CompositeKey>(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<time_t> capTTD)
+void NegCache::updateValidationStatus(const DNSName& qname, const QType qtype, const vState newState, boost::optional<time_t> capTTD)
 {
   auto& mc = getMap(qname);
   auto map = mc.lock();
index d4b9c629d5a885930d48a9408981cbb650c64700..4e4648aa48890bc2dcf7c2bca9176041d2472ab9 100644 (file)
@@ -87,11 +87,11 @@ public:
   };
 
   void add(const NegCacheEntry& ne);
-  void updateValidationStatus(const DNSName& qname, const QType& qtype, const vState newState, boost::optional<time_t> 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<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);
   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<NegCacheEntry, DNSName, &NegCacheEntry::d_name>>>>
     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
   {