]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
Use correct logic for isEntryUsable() 12347/head
authorOtto Moerbeek <otto.moerbeek@open-xchange.com>
Tue, 20 Dec 2022 11:30:54 +0000 (12:30 +0100)
committerOtto Moerbeek <otto.moerbeek@open-xchange.com>
Tue, 20 Dec 2022 11:30:54 +0000 (12:30 +0100)
Existing code was correct but used the wrong name for the method:
isEntryUsable() actually tested for isUnusable, but the caller
compensated for it. Reverse logic to make it more clear.

pdns/recursordist/recursor_cache.cc
pdns/recursordist/recursor_cache.hh

index c2ef9ce34b1c9a2eda5fb0f4848ddf9231f44d3d..8f9e440f4dadd9f7c802b4bc430a2ca9d746f23f 100644 (file)
@@ -418,7 +418,7 @@ time_t MemRecursorCache::get(time_t now, const DNSName& qname, const QType qt, F
         firstIndexIterator = map->d_map.project<OrderedTag>(i);
 
         // When serving stale, we consider expired records
-        if (i->isEntryUsable(now, serveStale)) {
+        if (!i->isEntryUsable(now, serveStale)) {
           moveCacheItemToFront<SequencedTag>(map->d_map, firstIndexIterator);
           continue;
         }
@@ -459,7 +459,7 @@ time_t MemRecursorCache::get(time_t now, const DNSName& qname, const QType qt, F
       firstIndexIterator = map->d_map.project<OrderedTag>(i);
 
       // When serving stale, we consider expired records
-      if (i->isEntryUsable(now, serveStale)) {
+      if (!i->isEntryUsable(now, serveStale)) {
         moveCacheItemToFront<SequencedTag>(map->d_map, firstIndexIterator);
         continue;
       }
index d191d1ac329c50ec5fd5bb2ab7f08817609f044e..bd3b0eb859e788bb00f19f59bae611dbbb5d4541 100644 (file)
@@ -104,7 +104,7 @@ private:
     bool isEntryUsable(time_t now, bool serveStale) const
     {
       // When serving stale, we consider expired records
-      return d_ttd <= now && !serveStale && d_servedStale == 0;
+      return d_ttd > now || serveStale || d_servedStale != 0;
     }
 
     bool shouldReplace(time_t now, bool auth, vState state, bool refresh);