]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
rec: Separate the actual code checking if a cut exists for refactoring
authorRemi Gacogne <remi.gacogne@powerdns.com>
Tue, 12 Sep 2017 12:34:09 +0000 (14:34 +0200)
committerRemi Gacogne <remi.gacogne@powerdns.com>
Tue, 19 Sep 2017 14:38:26 +0000 (16:38 +0200)
pdns/syncres.cc
pdns/syncres.hh

index f6a959e93986a70cdeedcbbff51b6a74c78b197b..05ecb7dc3fdb92a12a67cea67518bee9b9fa883d 100644 (file)
@@ -1431,6 +1431,40 @@ vState SyncRes::getValidationStatus(const DNSName& subdomain)
   return result;
 }
 
+bool SyncRes::lookForCut(const DNSName& qname, unsigned int depth, const vState existingState, vState& newState)
+{
+  bool foundCut = false;
+  std::set<GetBestNSAnswer> beenthere;
+  std::vector<DNSRecord> nsrecords;
+
+  int rcode = doResolve(qname, QType(QType::NS), nsrecords, depth, beenthere, newState);
+
+  if (rcode == RCode::NoError && !nsrecords.empty()) {
+    for (const auto& record : nsrecords) {
+      if(record.d_type != QType::NS || record.d_name != qname)
+        continue;
+      foundCut = true;
+      break;
+    }
+
+    if (foundCut) {
+      dsmap_t ds;
+      vState dsState = getDSRecords(qname, ds, newState == Bogus || existingState == Insecure || existingState == Bogus, depth);
+      if (dsState != Indeterminate) {
+        newState = dsState;
+      }
+      if (newState == TA) {
+        newState = Secure;
+      }
+      else if (newState == NTA) {
+        newState = Insecure;
+      }
+    }
+  }
+
+  return foundCut;
+}
+
 void SyncRes::computeZoneCuts(const DNSName& begin, const DNSName& end, unsigned int depth)
 {
   if(!begin.isPartOf(end)) {
@@ -1466,7 +1500,6 @@ void SyncRes::computeZoneCuts(const DNSName& begin, const DNSName& end, unsigned
   d_requireAuthData = false;
 
   while(qname != begin) {
-    bool foundCut = false;
     if (labelsToAdd.empty())
       break;
 
@@ -1482,45 +1515,20 @@ void SyncRes::computeZoneCuts(const DNSName& begin, const DNSName& end, unsigned
       }
     }
 
-    std::set<GetBestNSAnswer> beenthere;
-    std::vector<DNSRecord> nsrecords;
-
-    vState state = Indeterminate;
+    vState newState = Indeterminate;
     /* temporarily mark as Indeterminate, so that we won't enter an endless loop
        trying to determine that zone cut again. */
-    d_cutStates[qname] = state;
-    int rcode = doResolve(qname, QType(QType::NS), nsrecords, depth + 1, beenthere, state);
-
-    if (rcode == RCode::NoError && !nsrecords.empty()) {
-      for (const auto& record : nsrecords) {
-        if(record.d_type != QType::NS || record.d_name != qname)
-          continue;
-        foundCut = true;
-        break;
-      }
-      if (foundCut) {
-        LOG(d_prefix<<": - Found cut at "<<qname<<endl);
-        /* if we get a Bogus state while retrieving the NS,
-           the cut state is Bogus (we'll look for a (N)TA below though). */
-        if (state == Bogus) {
-          cutState = Bogus;
-        }
-        dsmap_t ds;
-        vState newState = getDSRecords(qname, ds, cutState == Insecure || cutState == Bogus, depth);
-        if (newState != Indeterminate) {
-          cutState = newState;
-        }
-        LOG(d_prefix<<": New state for "<<qname<<" is "<<vStates[cutState]<<endl);
-        if (cutState == TA) {
-          cutState = Secure;
-        }
-        else if (cutState == NTA) {
-          cutState = Insecure;
-        }
-        d_cutStates[qname] = cutState;
+    d_cutStates[qname] = newState;
+    bool foundCut = lookForCut(qname, depth + 1, cutState, newState);
+    if (foundCut) {
+      LOG(d_prefix<<": - Found cut at "<<qname<<endl);
+      if (newState != Indeterminate) {
+        cutState = newState;
       }
+      LOG(d_prefix<<": New state for "<<qname<<" is "<<vStates[cutState]<<endl);
+      d_cutStates[qname] = cutState;
     }
-    if (!foundCut) {
+    else {
       /* remove the temporary cut */
       LOG(d_prefix<<qname<<": removing cut state for "<<qname<<", was "<<vStates[d_cutStates[qname]]<<endl);
       d_cutStates.erase(qname);
index 980650f6d31d306b49ebb27da6392523564a8e63..9b41c7bf14cef9b29b6be1b38c7f25603cb37952 100644 (file)
@@ -760,6 +760,7 @@ private:
   bool haveExactValidationStatus(const DNSName& domain);
   vState getValidationStatus(const DNSName& subdomain);
 
+  bool lookForCut(const DNSName& qname, unsigned int depth, const vState existingState, vState& newState);
   void computeZoneCuts(const DNSName& begin, const DNSName& end, unsigned int depth);
 
   void setUpdatingRootNS()