From: Otto Moerbeek Date: Tue, 20 Dec 2022 11:30:54 +0000 (+0100) Subject: Use correct logic for isEntryUsable() X-Git-Tag: dnsdist-1.8.0-rc1~148^2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=24f2f86f94f685bba01a8a10b2a1f3185ba3cff1;p=thirdparty%2Fpdns.git Use correct logic for isEntryUsable() 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. --- diff --git a/pdns/recursordist/recursor_cache.cc b/pdns/recursordist/recursor_cache.cc index c2ef9ce34b..8f9e440f4d 100644 --- a/pdns/recursordist/recursor_cache.cc +++ b/pdns/recursordist/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/recursordist/recursor_cache.hh b/pdns/recursordist/recursor_cache.hh index d191d1ac32..bd3b0eb859 100644 --- a/pdns/recursordist/recursor_cache.hh +++ b/pdns/recursordist/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);