]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
Refactor UeberBackend::getAuth: UeberBackend::fillSOAFromCache
authorFred Morcos <fred.morcos@open-xchange.com>
Thu, 26 Oct 2023 12:38:28 +0000 (14:38 +0200)
committerFred Morcos <fred.morcos@open-xchange.com>
Sun, 29 Oct 2023 14:35:49 +0000 (15:35 +0100)
pdns/ueberbackend.cc
pdns/ueberbackend.hh

index 593b1757a3afa7c0e8fc1d43e8a8af143b0bd496..e528dc7d3914800ac3f8bc29606ffa317c142eab 100644 (file)
@@ -373,6 +373,24 @@ bool UeberBackend::fillSOAFromZoneRecord(DNSName& shorter, const int zoneId, SOA
   return true;
 }
 
+UeberBackend::CacheResult UeberBackend::fillSOAFromCache(SOAData* soaData, DNSName& shorter)
+{
+  auto cacheResult = cacheHas(d_question, d_answers);
+
+  if (cacheResult == CacheResult::Hit && !d_answers.empty() && d_cache_ttl != 0U) {
+    DLOG(g_log << Logger::Error << "has pos cache entry: " << shorter << endl);
+    fillSOAData(d_answers[0], *soaData);
+
+    soaData->db = backends.size() == 1 ? *backends.begin() : nullptr;
+    soaData->qname = shorter;
+  }
+  else if (cacheResult == CacheResult::NegativeMatch && d_negcache_ttl != 0U) {
+    DLOG(g_log << Logger::Error << "has neg cache entry: " << shorter << endl);
+  }
+
+  return cacheResult;
+}
+
 bool UeberBackend::getAuth(const DNSName& target, const QType& qtype, SOAData* soaData, bool cachedOk)
 {
   // A backend can respond to our authority request with the 'best' match it
@@ -409,19 +427,10 @@ bool UeberBackend::getAuth(const DNSName& target, const QType& qtype, SOAData* s
 
     // Check cache.
     if (cachedOk && (d_cache_ttl != 0 || d_negcache_ttl != 0)) {
-      auto cacheResult = cacheHas(d_question, d_answers);
-
-      if (cacheResult == CacheResult::Hit && !d_answers.empty() && d_cache_ttl != 0) {
-        DLOG(g_log << Logger::Error << "has pos cache entry: " << shorter << endl);
-        fillSOAData(d_answers[0], *soaData);
-
-        soaData->db = backends.size() == 1 ? *backends.begin() : nullptr;
-        soaData->qname = shorter;
-
+      auto cacheResult = fillSOAFromCache(soaData, shorter);
+      if (cacheResult == CacheResult::Hit) {
         goto found;
-      }
-      else if (cacheResult == CacheResult::NegativeMatch && d_negcache_ttl != 0) {
-        DLOG(g_log << Logger::Error << "has neg cache entry: " << shorter << endl);
+      } else if (cacheResult == CacheResult::NegativeMatch) {
         continue;
       }
     }
index 4fd10f8e4c34d02e639efe400ed489f42b393f05..7aaeb78f6e36c9e0692daa56b586eb19d676b3f3 100644 (file)
@@ -177,4 +177,5 @@ private:
   void addCache(const Question& q, vector<DNSZoneRecord>&& rrs) const;
 
   bool fillSOAFromZoneRecord(DNSName& shorter, int zoneId, SOAData* soaData);
+  CacheResult fillSOAFromCache(SOAData* soaData, DNSName& shorter);
 };