]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
Use lookupEnd() to exit lookup loops faster when possible.
authorMiod Vallat <miod.vallat@powerdns.com>
Fri, 18 Apr 2025 08:38:48 +0000 (10:38 +0200)
committerMiod Vallat <miod.vallat@powerdns.com>
Mon, 4 Aug 2025 13:17:39 +0000 (15:17 +0200)
pdns/packethandler.cc
pdns/pdnsutil.cc

index 76ee3ed8d8bcf9ee459b55b3af1a24aed7ab4a01..44463e56360c9308fc7d60fd34920282deefd4f0 100644 (file)
@@ -416,7 +416,9 @@ bool PacketHandler::getBestWildcard(DNSPacket& p, const DNSName &target, DNSName
     }
     while(B.get(rr)) {
       if (haveCNAME) {
-        continue;
+        // No need to look any further
+        B.lookupEnd();
+        break;
       }
 #ifdef HAVE_LUA_RECORDS
       if (rr.dr.d_type == QType::LUA && !isPresigned()) {
@@ -932,9 +934,13 @@ void PacketHandler::addNSEC3(DNSPacket& p, std::unique_ptr<DNSPacket>& r, const
       DNSZoneRecord rr;
       while( closest.chopOff() && (closest != d_sd.qname()))  { // stop at SOA
         B.lookup(QType(QType::ANY), closest, d_sd.domain_id, &p);
-        while(B.get(rr))
-          if (rr.auth)
+        while (B.get(rr)) {
+          if (rr.auth) {
+            B.lookupEnd();
             doBreak = true;
+            break;
+          }
+        }
         if(doBreak)
           break;
       }
index 3f4f9c552da5f040ccfaa0f29410ebc28cb3298a..35975383190d163953a4a20046e90eb74fb3e251 100644 (file)
@@ -781,8 +781,7 @@ static void dbBench(const std::string& fname)
     }
     // Safe to pass UnknownDomainID here
     B.lookup(QType(QType::A), DNSName(std::to_string(dns_random_uint32()))+domain, UnknownDomainID);
-    while(B.get(rr)) {
-    }
+    B.lookupEnd();
     misses++;
 
   }
@@ -906,8 +905,13 @@ static int checkZone(DNSSECKeeper &dk, UeberBackend &B, const ZoneName& zone, co
       bool ns=false;
       DNSZoneRecord zr;
       B.lookup(QType(QType::ANY), zone.operator const DNSName&(), sd_p.domain_id);
-      while(B.get(zr))
-        ns |= (zr.dr.d_type == QType::NS);
+      while(B.get(zr)) {
+        if (zr.dr.d_type == QType::NS) {
+          ns = true;
+          B.lookupEnd();
+          break;
+        }
+      }
       if (!ns) {
         cout<<"[Error] No delegation for zone '"<<zone<<"' in parent '"<<parent<<"'"<<endl;
         numerrors++;
@@ -2327,6 +2331,8 @@ static int addOrReplaceRecord(bool isAdd, const vector<string>& cmds) {
         }
       }
       reject = true;
+      di.backend->lookupEnd();
+      break;
     }
     if (reject) {
       cerr<<"Attempting to add CNAME to "<<rr.qname<<" which already has existing records"<<endl;
@@ -2335,12 +2341,10 @@ static int addOrReplaceRecord(bool isAdd, const vector<string>& cmds) {
   }
   else {
     di.backend->lookup(QType(QType::CNAME), rr.qname, static_cast<int>(di.id));
-    // TODO: It would be nice to have a way to complete a lookup and release its
-    // resources without having to exhaust its results - here one successful
-    // get() is all we need to decide to reject the operation. I'm looking at
-    // you, lmdb backend.
     while (di.backend->get(oldrr)) {
       reject = true;
+      di.backend->lookupEnd();
+      break;
     }
     if (reject) {
       cerr<<"Attempting to add record to "<<rr.qname<<" which already has a CNAME record"<<endl;