From: Fred Morcos Date: Sun, 29 Oct 2023 14:35:04 +0000 (+0100) Subject: Some final UeberBackend cleanups X-Git-Tag: rec-5.0.0-beta1~16^2~4 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=346d1042de1833c2ee0d684eb4f185077aca6ae6;p=thirdparty%2Fpdns.git Some final UeberBackend cleanups --- diff --git a/pdns/ueberbackend.cc b/pdns/ueberbackend.cc index e1e5a01331..4b7d84c30b 100644 --- a/pdns/ueberbackend.cc +++ b/pdns/ueberbackend.cc @@ -288,8 +288,8 @@ void UeberBackend::updateZoneCache() for (auto& backend : backends) { vector zones; 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 + for (auto& domainInfo : zones) { + zone_indices.emplace_back(std::move(domainInfo.zone), (int)domainInfo.id); // this cast should not be necessary } } g_zoneCache.replace(zone_indices); @@ -297,11 +297,11 @@ void UeberBackend::updateZoneCache() void UeberBackend::rediscover(string* status) { - for (auto i = backends.begin(); i != backends.end(); ++i) { + for (auto backend = backends.begin(); backend != backends.end(); ++backend) { string tmpstr; - (*i)->rediscover(&tmpstr); + (*backend)->rediscover(&tmpstr); if (status != nullptr) { - *status += tmpstr + (i != backends.begin() ? "\n" : ""); + *status += tmpstr + (backend != backends.begin() ? "\n" : ""); } } @@ -607,18 +607,17 @@ bool UeberBackend::autoPrimariesList(std::vector& primaries) return false; } -bool UeberBackend::superMasterBackend(const string& ip, const DNSName& domain, const vector& nsset, string* nameserver, string* account, DNSBackend** db) +bool UeberBackend::superMasterBackend(const string& ip, const DNSName& domain, const vector& nsset, string* nameserver, string* account, DNSBackend** dnsBackend) { for (auto* backend : backends) { - if (backend->superMasterBackend(ip, domain, nsset, nameserver, account, db)) { + if (backend->superMasterBackend(ip, domain, nsset, nameserver, account, dnsBackend)) { return true; } } return false; } -UeberBackend::UeberBackend(const string& pname) : - d_negcached(false), d_cached(false) +UeberBackend::UeberBackend(const string& pname) { { d_instances.lock()->push_back(this); // report to the static list of ourself @@ -626,15 +625,13 @@ UeberBackend::UeberBackend(const string& pname) : d_cache_ttl = ::arg().asNum("query-cache-ttl"); d_negcache_ttl = ::arg().asNum("negquery-cache-ttl"); - d_qtype = 0; - d_stale = false; backends = BackendMakers().all(pname == "key-only"); } -static void del(DNSBackend* d) +static void del(DNSBackend* backend) { - delete d; + delete backend; } void UeberBackend::cleanup() @@ -671,17 +668,17 @@ enum UeberBackend::CacheResult UeberBackend::cacheHas(const Question& question, return CacheResult::Hit; } -void UeberBackend::addNegCache(const Question& q) const +void UeberBackend::addNegCache(const Question& question) const { extern AuthQueryCache QC; if (d_negcache_ttl == 0) { return; } // we should also not be storing negative answers if a pipebackend does scopeMask, but we can't pass a negative scopeMask in an empty set! - QC.insert(q.qname, q.qtype, vector(), d_negcache_ttl, q.zoneId); + QC.insert(question.qname, question.qtype, vector(), d_negcache_ttl, question.zoneId); } -void UeberBackend::addCache(const Question& q, vector&& rrs) const +void UeberBackend::addCache(const Question& question, vector&& rrs) const { extern AuthQueryCache QC; @@ -689,13 +686,13 @@ void UeberBackend::addCache(const Question& q, vector&& rrs) cons return; } - for (const auto& rr : rrs) { - if (rr.scopeMask) { + for (const auto& resourceRecord : rrs) { + if (resourceRecord.scopeMask != 0) { return; } } - QC.insert(q.qname, q.qtype, std::move(rrs), d_cache_ttl, q.zoneId); + QC.insert(question.qname, question.qtype, std::move(rrs), d_cache_ttl, question.zoneId); } void UeberBackend::alsoNotifies(const DNSName& domain, set* ips) @@ -776,7 +773,7 @@ void UeberBackend::getAllDomains(vector* domains, bool getSerial, bo } } -bool UeberBackend::get(DNSZoneRecord& rr) +bool UeberBackend::get(DNSZoneRecord& resourceRecord) { // cout<<"UeberBackend::get(DNSZoneRecord) called"<& result) { - bool rc = false; + bool ret = false; 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; + ret = true; } } - return rc; + return ret; } bool UeberBackend::searchComments(const string& pattern, int maxResults, vector& result) { - bool rc = false; + bool ret = false; 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; + ret = true; } } - return rc; + return ret; } AtomicCounter UeberBackend::handle::instances(0); @@ -891,11 +888,6 @@ UeberBackend::handle::handle() { // g_log<get(r))) { // this backend out of answers + while (d_hinterBackend != nullptr && !(isMore = d_hinterBackend->get(record))) { // this backend out of answers if (i < parent->backends.size()) { DLOG(g_log << "Backend #" << i << " of " << parent->backends.size() << " out of answers, taking next" << endl); diff --git a/pdns/ueberbackend.hh b/pdns/ueberbackend.hh index 7aaeb78f6e..ada36f129b 100644 --- a/pdns/ueberbackend.hh +++ b/pdns/ueberbackend.hh @@ -47,7 +47,7 @@ public: UeberBackend(const string& pname = "default"); ~UeberBackend(); - bool superMasterBackend(const string& ip, const DNSName& domain, const vector& nsset, string* nameserver, string* account, DNSBackend** db); + bool superMasterBackend(const string& ip, const DNSName& domain, const vector& nsset, string* nameserver, string* account, DNSBackend** dnsBackend); bool superMasterAdd(const AutoPrimary& primary); bool autoPrimaryRemove(const struct AutoPrimary& primary); @@ -61,7 +61,7 @@ public: static bool loadmodule(const string& name); static bool loadModules(const vector& modules, const string& path); - static void go(void); + static void go(); /** This contains all registered backends. The DynListener modifies this list for us when new modules are loaded */ @@ -73,23 +73,23 @@ public: class handle { public: - bool get(DNSZoneRecord& dr); + bool get(DNSZoneRecord& record); handle(); ~handle(); //! The UeberBackend class where this handle belongs to - UeberBackend* parent; + UeberBackend* parent{nullptr}; //! The current real backend, which is answering questions - DNSBackend* d_hinterBackend; + DNSBackend* d_hinterBackend{nullptr}; //! DNSPacket who asked this question - DNSPacket* pkt_p; + DNSPacket* pkt_p{nullptr}; DNSName qname; //! Index of the current backend within the backends vector - unsigned int i; + unsigned int i{0}; QType qtype; - int zoneId; + int zoneId{-1}; private: static AtomicCounter instances; @@ -101,7 +101,7 @@ public: bool getAuth(const DNSName& target, const QType& qtype, SOAData* soaData, bool cachedOk = true); /** Load SOA info from backends, ignoring the cache.*/ bool getSOAUncached(const DNSName& domain, SOAData& soaData); - bool get(DNSZoneRecord& r); + bool get(DNSZoneRecord& resourceRecord); void getAllDomains(vector* domains, bool getSerial, bool include_disabled); void getUnfreshSlaveInfos(vector* domains); @@ -110,7 +110,7 @@ public: 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); + bool addDomainKey(const DNSName& name, const DNSBackend::KeyData& key, int64_t& keyID); bool getDomainKeys(const DNSName& name, std::vector& keys); bool getAllDomainMetadata(const DNSName& name, std::map>& meta); bool getDomainMetadata(const DNSName& name, const std::string& kind, std::vector& meta); @@ -118,14 +118,14 @@ public: bool setDomainMetadata(const DNSName& name, const std::string& kind, const std::vector& meta); bool setDomainMetadata(const DNSName& name, const std::string& kind, const std::string& meta); - bool removeDomainKey(const DNSName& name, unsigned int id); - bool activateDomainKey(const DNSName& name, unsigned int id); - bool deactivateDomainKey(const DNSName& name, unsigned int id); - bool publishDomainKey(const DNSName& name, unsigned int id); - bool unpublishDomainKey(const DNSName& name, unsigned int id); + bool removeDomainKey(const DNSName& name, unsigned int keyID); + bool activateDomainKey(const DNSName& name, unsigned int keyID); + bool deactivateDomainKey(const DNSName& name, unsigned int keyID); + bool publishDomainKey(const DNSName& name, unsigned int keyID); + bool unpublishDomainKey(const DNSName& name, unsigned int keyID); void alsoNotifies(const DNSName& domain, set* ips); - void rediscover(string* status = 0); + void rediscover(string* status = nullptr); void reload(); bool setTSIGKey(const DNSName& name, const DNSName& algorithm, const string& content); @@ -156,13 +156,13 @@ private: } d_question; unsigned int d_cache_ttl, d_negcache_ttl; - uint16_t d_qtype; + uint16_t d_qtype{0}; - bool d_negcached; - bool d_cached; + bool d_negcached{false}; + bool d_cached{false}; static AtomicCounter* s_backendQueries; static bool d_go; - bool d_stale; + bool d_stale{false}; static bool s_doANYLookupsOnly; enum CacheResult @@ -173,8 +173,8 @@ private: }; CacheResult cacheHas(const Question& question, vector& resourceRecords) const; - void addNegCache(const Question& q) const; - void addCache(const Question& q, vector&& rrs) const; + void addNegCache(const Question& question) const; + void addCache(const Question& question, vector&& rrs) const; bool fillSOAFromZoneRecord(DNSName& shorter, int zoneId, SOAData* soaData); CacheResult fillSOAFromCache(SOAData* soaData, DNSName& shorter);