From: Miod Vallat Date: Fri, 18 Apr 2025 08:38:48 +0000 (+0200) Subject: Use lookupEnd() to exit lookup loops faster when possible. X-Git-Tag: rec-5.4.0-alpha1~368^2~2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=708c7fa820a58e798243f3d51ee6091dcf820320;p=thirdparty%2Fpdns.git Use lookupEnd() to exit lookup loops faster when possible. --- diff --git a/pdns/packethandler.cc b/pdns/packethandler.cc index 76ee3ed8d8..44463e5636 100644 --- a/pdns/packethandler.cc +++ b/pdns/packethandler.cc @@ -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& 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; } diff --git a/pdns/pdnsutil.cc b/pdns/pdnsutil.cc index 3f4f9c552d..3597538319 100644 --- a/pdns/pdnsutil.cc +++ b/pdns/pdnsutil.cc @@ -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 '"<& cmds) { } } reject = true; + di.backend->lookupEnd(); + break; } if (reject) { cerr<<"Attempting to add CNAME to "<& cmds) { } else { di.backend->lookup(QType(QType::CNAME), rr.qname, static_cast(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 "<