]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
Refactor UeberBackend::getAuth: UeberBackend::fillSOAFromZoneRecord
authorFred Morcos <fred.morcos@open-xchange.com>
Thu, 26 Oct 2023 12:09:33 +0000 (14:09 +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 e03c9016c378b7268735c0788fb88fc57cca7c2e..da29c062a8748aed99f389fb0b82726b0a5d864b 100644 (file)
@@ -332,6 +332,47 @@ bool UeberBackend::inTransaction()
   return false;
 }
 
+bool UeberBackend::fillSOAFromZoneRecord(DNSName& shorter, const int zoneId, SOAData* const soaData)
+{
+  // Zone exists in zone cache, directly look up SOA.
+  lookup(QType(QType::SOA), shorter, zoneId, nullptr);
+
+  DNSZoneRecord zoneRecord;
+  if (!get(zoneRecord)) {
+    DLOG(g_log << Logger::Info << "Backend returned no SOA for zone '" << shorter.toLogString() << "', which it reported as existing " << endl);
+    return false;
+  }
+
+  if (zoneRecord.dr.d_name != shorter) {
+    throw PDNSException("getAuth() returned an SOA for the wrong zone. Zone '" + zoneRecord.dr.d_name.toLogString() + "' is not equal to looked up zone '" + shorter.toLogString() + "'");
+  }
+
+  // Fill soaData.
+  soaData->qname = zoneRecord.dr.d_name;
+
+  try {
+    fillSOAData(zoneRecord, *soaData);
+  }
+  catch (...) {
+    g_log << Logger::Warning << "Backend returned a broken SOA for zone '" << shorter.toLogString() << "'" << endl;
+
+    while (get(zoneRecord)) {
+      ;
+    }
+
+    return false;
+  }
+
+  soaData->db = backends.size() == 1 ? *backends.begin() : nullptr;
+
+  // Leave database handle in a consistent state.
+  while (get(zoneRecord)) {
+    ;
+  }
+
+  return true;
+}
+
 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
@@ -351,39 +392,12 @@ bool UeberBackend::getAuth(const DNSName& target, const QType& qtype, SOAData* s
 
     if (cachedOk && g_zoneCache.isEnabled()) {
       if (g_zoneCache.getEntry(shorter, zoneId)) {
-        // Zone exists in zone cache, directly look up SOA.
-        DNSZoneRecord zoneRecord;
-        lookup(QType(QType::SOA), shorter, zoneId, nullptr);
-        if (!get(zoneRecord)) {
-          DLOG(g_log << Logger::Info << "Backend returned no SOA for zone '" << shorter.toLogString() << "', which it reported as existing " << endl);
-          continue;
-        }
-        if (zoneRecord.dr.d_name != shorter) {
-          throw PDNSException("getAuth() returned an SOA for the wrong zone. Zone '" + zoneRecord.dr.d_name.toLogString() + "' is not equal to looked up zone '" + shorter.toLogString() + "'");
-        }
-        // fill soaData
-        soaData->qname = zoneRecord.dr.d_name;
-        try {
-          fillSOAData(zoneRecord, *soaData);
-        }
-        catch (...) {
-          g_log << Logger::Warning << "Backend returned a broken SOA for zone '" << shorter.toLogString() << "'" << endl;
-          while (get(zoneRecord)) {
-            ;
-          }
-          continue;
-        }
-        if (backends.size() == 1) {
-          soaData->db = *backends.begin();
+        if (fillSOAFromZoneRecord(shorter, zoneId, soaData)) {
+          goto found;
         }
         else {
-          soaData->db = nullptr;
-        }
-        // leave database handle in a consistent state
-        while (get(zoneRecord)) {
-          ;
+          continue;
         }
-        goto found;
       }
 
       // Zone does not exist, try again with a shorter name.
index 241751c91d4e7902e447a98c3475e37b6dbaa0a4..be54670357f9f76b017e6ed0d59f28122c8e4341 100644 (file)
@@ -168,4 +168,6 @@ private:
   int cacheHas(const Question& q, vector<DNSZoneRecord>& rrs) const;
   void addNegCache(const Question& q) const;
   void addCache(const Question& q, vector<DNSZoneRecord>&& rrs) const;
+
+  bool fillSOAFromZoneRecord(DNSName& shorter, int zoneId, SOAData* soaData);
 };