]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
Make serve stale more robust by making the view of the record cache
authorOtto Moerbeek <otto.moerbeek@open-xchange.com>
Fri, 1 Jul 2022 11:03:29 +0000 (13:03 +0200)
committerOtto Moerbeek <otto.moerbeek@open-xchange.com>
Fri, 9 Sep 2022 07:45:15 +0000 (09:45 +0200)
and SyncRes consistent: remove the > 5 for the ttl test in SyncRes
glue access code.

Plus fix a few record cache get flags

pdns/syncres.cc

index b06851ceeda72404d4814f501f92069a57fc5bb5..bebb713bd931e8263f01d4b3eaeb5ddddf3d41b2 100644 (file)
@@ -1806,8 +1806,9 @@ int SyncRes::doResolveNoQNameMinimization(const DNSName &qname, const QType qtyp
   const int iterations = !d_refresh && MemRecursorCache::s_maxServedStaleExtensions > 0 ? 2 : 1;
   for (int loop = 0; loop < iterations; loop++) {
 
-    // First try a regular resolve
-    d_serveStale = loop == 1;
+    if (loop == 1) {
+      d_serveStale = true;
+    }
 
     // When we're not on the last iteration, a timeout is not fatal
     const bool exceptionOnTimeout = loop == iterations - 1;
@@ -2017,6 +2018,9 @@ int SyncRes::doResolveNoQNameMinimization(const DNSName &qname, const QType qtyp
       }
 
       LOG(prefix<<qname<<": failed (res="<<res<<")"<<endl);
+      if (res >= 0) {
+        break;
+      }
     }
     catch (const ImmediateServFailException&) {
       if (exceptionOnTimeout) {
@@ -2067,6 +2071,9 @@ vector<ComboAddress> SyncRes::getAddrs(const DNSName &qname, unsigned int depth,
   if (d_serveStale) {
     flags |= MemRecursorCache::ServeStale;
   }
+  if (d_refresh) {
+    flags |= MemRecursorCache::Refresh;
+  }
   try {
     // First look for both A and AAAA in the cache
     res_t cset;
@@ -2214,6 +2221,9 @@ void SyncRes::getBestNSFromCache(const DNSName &qname, const QType qtype, vector
   if (d_serveStale) {
     flags |= MemRecursorCache::ServeStale;
   }
+  if (d_refresh) {
+    flags |= MemRecursorCache::Refresh;
+  }
   do {
     if (cutOffDomain && (subdomain == *cutOffDomain || !subdomain.isPartOf(*cutOffDomain))) {
       break;
@@ -2862,12 +2872,12 @@ bool SyncRes::doCacheCheck(const DNSName &qname, const DNSName& authname, bool w
   if (!wasForwardRecurse && d_requireAuthData) {
     flags |= MemRecursorCache::RequireAuth;
   }
-  if (d_refresh) {
-    flags |= MemRecursorCache::Refresh;
-  }
   if (d_serveStale) {
     flags |= MemRecursorCache::ServeStale;
   }
+  if (d_refresh) {
+    flags |= MemRecursorCache::Refresh;
+  }
   if(g_recCache->get(d_now.tv_sec, sqname, sqt, flags, &cset, d_cacheRemote, d_routingTag, d_doDNSSEC ? &signatures : nullptr, d_doDNSSEC ? &authorityRecs : nullptr, &d_wasVariable, &cachedState, &wasCachedAuth, nullptr, &d_fromAuthIP) > 0) {
 
     LOG(prefix<<sqname<<": Found cache hit for "<<sqt.toString()<<": ");