From: Fred Morcos Date: Sun, 29 Oct 2023 14:09:36 +0000 (+0100) Subject: Various UeberBackend cleanups X-Git-Tag: rec-5.0.0-beta1~16^2~15 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=01f43baebdf578b57ca127284aa32a052686e03d;p=thirdparty%2Fpdns.git Various UeberBackend cleanups --- diff --git a/pdns/ueberbackend.cc b/pdns/ueberbackend.cc index 7bcb49bd09..6543968631 100644 --- a/pdns/ueberbackend.cc +++ b/pdns/ueberbackend.cc @@ -284,9 +284,9 @@ void UeberBackend::updateZoneCache() vector> zone_indices; g_zoneCache.setReplacePending(); - for (vector::iterator i = backends.begin(); i != backends.end(); ++i) { + for (auto& backend : backends) { vector zones; - (*i)->getAllDomains(&zones, false, true); + backend->getAllDomains(&zones, false, true); for (auto& di : zones) { zone_indices.emplace_back(std::move(di.zone), (int)di.id); // this cast should not be necessary } @@ -296,11 +296,12 @@ void UeberBackend::updateZoneCache() void UeberBackend::rediscover(string* status) { - for (vector::iterator i = backends.begin(); i != backends.end(); ++i) { + for (auto i = backends.begin(); i != backends.end(); ++i) { string tmpstr; (*i)->rediscover(&tmpstr); - if (status) + if (status != nullptr) { *status += tmpstr + (i != backends.begin() ? "\n" : ""); + } } updateZoneCache(); @@ -387,10 +388,10 @@ bool UeberBackend::getAuth(const DNSName& target, const QType& qtype, SOAData* s d_question.zoneId = zoneId; // Check cache - if (cachedOk && (d_cache_ttl || d_negcache_ttl)) { + if (cachedOk && (d_cache_ttl != 0 || d_negcache_ttl != 0)) { cstat = cacheHas(d_question, d_answers); - if (cstat == 1 && !d_answers.empty() && d_cache_ttl) { + if (cstat == 1 && !d_answers.empty() && d_cache_ttl != 0) { DLOG(g_log << Logger::Error << "has pos cache entry: " << shorter << endl); fillSOAData(d_answers[0], *sd); @@ -403,7 +404,7 @@ bool UeberBackend::getAuth(const DNSName& target, const QType& qtype, SOAData* s sd->qname = shorter; goto found; } - else if (cstat == 0 && d_negcache_ttl) { + else if (cstat == 0 && d_negcache_ttl != 0) { DLOG(g_log << Logger::Error << "has neg cache entry: " << shorter << endl); continue; } @@ -411,8 +412,8 @@ bool UeberBackend::getAuth(const DNSName& target, const QType& qtype, SOAData* s // Check backends { - vector::const_iterator i = backends.begin(); - vector>::iterator j = bestmatch.begin(); + auto i = backends.begin(); + auto j = bestmatch.begin(); for (; i != backends.end() && j != bestmatch.end(); ++i, ++j) { DLOG(g_log << Logger::Error << "backend: " << i - backends.begin() << ", qname: " << shorter << endl); @@ -454,7 +455,8 @@ bool UeberBackend::getAuth(const DNSName& target, const QType& qtype, SOAData* s } continue; } - else if (d_cache_ttl) { + + if (d_cache_ttl != 0) { DLOG(g_log << Logger::Error << "add pos cache entry: " << sd->qname << endl); d_question.qtype = QType::SOA; d_question.qname = sd->qname; @@ -806,18 +808,22 @@ bool UeberBackend::deleteTSIGKey(const DNSName& name) bool UeberBackend::searchRecords(const string& pattern, int maxResults, vector& result) { bool rc = false; - for (vector::iterator i = backends.begin(); result.size() < static_cast::size_type>(maxResults) && i != backends.end(); ++i) - if ((*i)->searchRecords(pattern, maxResults - result.size(), result)) + for (auto i = backends.begin(); result.size() < static_cast::size_type>(maxResults) && i != backends.end(); ++i) { + if ((*i)->searchRecords(pattern, maxResults - result.size(), result)) { rc = true; + } + } return rc; } bool UeberBackend::searchComments(const string& pattern, int maxResults, vector& result) { bool rc = false; - for (vector::iterator i = backends.begin(); result.size() < static_cast::size_type>(maxResults) && i != backends.end(); ++i) - if ((*i)->searchComments(pattern, maxResults - result.size(), result)) + for (auto i = backends.begin(); result.size() < static_cast::size_type>(maxResults) && i != backends.end(); ++i) { + if ((*i)->searchComments(pattern, maxResults - result.size(), result)) { rc = true; + } + } return rc; } @@ -852,8 +858,9 @@ bool UeberBackend::handle::get(DNSZoneRecord& r) d_hinterBackend->lookup(qtype, qname, zoneId, pkt_p); ++(*s_backendQueries); } - else + else { break; + } DLOG(g_log << "Now asking backend #" << i << endl); } diff --git a/pdns/ueberbackend.hh b/pdns/ueberbackend.hh index 04785d1adb..ff15a5b74d 100644 --- a/pdns/ueberbackend.hh +++ b/pdns/ueberbackend.hh @@ -95,7 +95,7 @@ public: static AtomicCounter instances; }; - void lookup(const QType&, const DNSName& qdomain, int zoneId, DNSPacket* pkt_p = nullptr); + void lookup(const QType& qtype, const DNSName& qname, int zoneId, DNSPacket* pkt_p = nullptr); /** Determines if we are authoritative for a zone, and at what level */ bool getAuth(const DNSName& target, const QType& qtype, SOAData* sd, bool cachedOk = true); @@ -106,8 +106,8 @@ public: void getUnfreshSlaveInfos(vector* domains); void getUpdatedMasters(vector& domains, std::unordered_set& catalogs, CatalogHashMap& catalogHashes); - bool createDomain(const DNSName& domain, const DomainInfo::DomainKind kind, const vector& masters, const string& account); bool getDomainInfo(const DNSName& domain, DomainInfo& domainInfo, bool getSerial = true); + bool createDomain(const DNSName& domain, DomainInfo::DomainKind kind, const vector& masters, const string& account); bool doesDNSSEC(); bool addDomainKey(const DNSName& name, const DNSBackend::KeyData& key, int64_t& id);