From: Otto Moerbeek Date: Fri, 3 Mar 2023 08:14:55 +0000 (+0100) Subject: rec: Backport 12347 to rec-4.x.8: Use correct logic for isEntryUsable() X-Git-Tag: rec-4.8.3~4^2 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=refs%2Fpull%2F12607%2Fhead;p=thirdparty%2Fpdns.git rec: Backport 12347 to rec-4.x.8: Use correct logic for isEntryUsable() Backport of #12347 --- diff --git a/pdns/recursor_cache.cc b/pdns/recursor_cache.cc index b4f08cab5f..2bf5d556e9 100644 --- a/pdns/recursor_cache.cc +++ b/pdns/recursor_cache.cc @@ -418,7 +418,7 @@ time_t MemRecursorCache::get(time_t now, const DNSName& qname, const QType qt, F firstIndexIterator = map->d_map.project(i); // When serving stale, we consider expired records - if (i->isEntryUsable(now, serveStale)) { + if (!i->isEntryUsable(now, serveStale)) { moveCacheItemToFront(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(i); // When serving stale, we consider expired records - if (i->isEntryUsable(now, serveStale)) { + if (!i->isEntryUsable(now, serveStale)) { moveCacheItemToFront(map->d_map, firstIndexIterator); continue; } diff --git a/pdns/recursor_cache.hh b/pdns/recursor_cache.hh index 8d9e2e3a53..91102d99ae 100644 --- a/pdns/recursor_cache.hh +++ b/pdns/recursor_cache.hh @@ -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);