From f97a1d9802e82f05d8e860c74e3d5c20c5d8598f Mon Sep 17 00:00:00 2001 From: Miod Vallat Date: Mon, 5 May 2025 08:24:52 +0200 Subject: [PATCH] More use of domainid_t instead of int. --- modules/bindbackend/bindbackend2.hh | 4 ++-- pdns/auth-querycache.cc | 6 +++--- pdns/auth-querycache.hh | 8 ++++---- pdns/auth-zonecache.cc | 10 +++++----- pdns/auth-zonecache.hh | 8 ++++---- pdns/dnsbackend.cc | 2 +- pdns/lua-record.cc | 4 ++-- pdns/ueberbackend.cc | 8 ++++---- pdns/ueberbackend.hh | 8 ++++---- 9 files changed, 29 insertions(+), 29 deletions(-) diff --git a/modules/bindbackend/bindbackend2.hh b/modules/bindbackend/bindbackend2.hh index 6fe202ef9c..cc6658235d 100644 --- a/modules/bindbackend/bindbackend2.hh +++ b/modules/bindbackend/bindbackend2.hh @@ -157,7 +157,7 @@ public: time_t d_ctime{0}; //!< last known ctime of the file on disk time_t d_lastcheck{0}; //!< last time domain was checked for freshness uint32_t d_lastnotified{0}; //!< Last serial number we notified our secondaries of - unsigned int d_id{0}; //!< internal id of the domain + domainid_t d_id{0}; //!< internal id of the domain mutable bool d_checknow; //!< if this domain has been flagged for a check bool d_loaded{false}; //!< if a domain is loaded bool d_wasRejectedLastReload{false}; //!< if the domain was rejected during Bind2Backend::queueReloadAndStore @@ -224,7 +224,7 @@ public: // end of DNSSEC typedef multi_index_container>, + indexed_by>, ordered_unique, member>>> state_t; static SharedLockGuarded s_state; diff --git a/pdns/auth-querycache.cc b/pdns/auth-querycache.cc index b397c1e830..844a5dc4b5 100644 --- a/pdns/auth-querycache.cc +++ b/pdns/auth-querycache.cc @@ -52,7 +52,7 @@ void AuthQueryCache::MapCombo::reserve(size_t numberOfEntries) } // called from ueberbackend -bool AuthQueryCache::getEntry(const DNSName &qname, const QType& qtype, vector& value, int zoneID) +bool AuthQueryCache::getEntry(const DNSName &qname, const QType& qtype, vector& value, domainid_t zoneID) { cleanupIfNeeded(); @@ -70,7 +70,7 @@ bool AuthQueryCache::getEntry(const DNSName &qname, const QType& qtype, vector&& value, uint32_t ttl, int zoneID) +void AuthQueryCache::insert(const DNSName &qname, const QType& qtype, vector&& value, uint32_t ttl, domainid_t zoneID) { cleanupIfNeeded(); @@ -115,7 +115,7 @@ void AuthQueryCache::insert(const DNSName &qname, const QType& qtype, vector& value, int zoneID, time_t now) +bool AuthQueryCache::getEntryLocked(const cmap_t& map, const DNSName &qname, uint16_t qtype, vector& value, domainid_t zoneID, time_t now) { auto& idx = boost::multi_index::get(map); auto iter = idx.find(std::tie(qname, qtype, zoneID)); diff --git a/pdns/auth-querycache.hh b/pdns/auth-querycache.hh index b144b36670..712cde113d 100644 --- a/pdns/auth-querycache.hh +++ b/pdns/auth-querycache.hh @@ -42,9 +42,9 @@ class AuthQueryCache : public boost::noncopyable public: AuthQueryCache(size_t mapsCount=1024); - void insert(const DNSName &qname, const QType& qtype, vector&& content, uint32_t ttl, int zoneID); + void insert(const DNSName &qname, const QType& qtype, vector&& value, uint32_t ttl, domainid_t zoneID); - bool getEntry(const DNSName &qname, const QType& qtype, vector& entry, int zoneID); + bool getEntry(const DNSName &qname, const QType& qtype, vector& value, domainid_t zoneID); size_t size() { return *d_statnumentries; } //!< number of entries in the cache void cleanup(); //!< force the cache to preen itself from expired queries @@ -69,7 +69,7 @@ private: mutable vector drs; mutable time_t ttd{0}; uint16_t qtype{0}; - int zoneID{-1}; + domainid_t zoneID{UnknownDomainID}; }; struct HashTag{}; @@ -108,7 +108,7 @@ private: return d_maps[qname.hash() % d_maps.size()]; } - bool getEntryLocked(const cmap_t& map, const DNSName &content, uint16_t qtype, vector& entry, int zoneID, time_t now); + bool getEntryLocked(const cmap_t& map, const DNSName &qname, uint16_t qtype, vector& value, domainid_t zoneID, time_t now); void cleanupIfNeeded(); AtomicCounter d_ops{0}; diff --git a/pdns/auth-zonecache.cc b/pdns/auth-zonecache.cc index ff4c0948d9..904c75abd4 100644 --- a/pdns/auth-zonecache.cc +++ b/pdns/auth-zonecache.cc @@ -134,7 +134,7 @@ void AuthZoneCache::clear() } } -void AuthZoneCache::replace(const vector>& zone_indices) +void AuthZoneCache::replace(const vector>& zone_indices) { if (!d_refreshinterval) return; @@ -205,7 +205,7 @@ void AuthZoneCache::replace(ViewsMap viewsmap) views->swap(viewsmap); } -void AuthZoneCache::add(const ZoneName& zone, const int zoneId) +void AuthZoneCache::add(const ZoneName& zone, const domainid_t zoneId) { if (!d_refreshinterval) return; @@ -220,7 +220,7 @@ void AuthZoneCache::add(const ZoneName& zone, const int zoneId) CacheValue val; val.zoneId = zoneId; - int mapIndex = getMapIndex(zone); + auto mapIndex = getMapIndex(zone); { auto& mc = d_maps[mapIndex]; auto map = mc.d_map.write_lock(); @@ -243,11 +243,11 @@ void AuthZoneCache::remove(const ZoneName& zone) { auto pending = d_pending.lock(); if (pending->d_replacePending) { - pending->d_pendingUpdates.emplace_back(zone, -1, false); + pending->d_pendingUpdates.emplace_back(zone, UnknownDomainID, false); } } - int mapIndex = getMapIndex(zone); + auto mapIndex = getMapIndex(zone); { auto& mc = d_maps[mapIndex]; auto map = mc.d_map.write_lock(); diff --git a/pdns/auth-zonecache.hh b/pdns/auth-zonecache.hh index 29c530cb34..ae511d1e56 100644 --- a/pdns/auth-zonecache.hh +++ b/pdns/auth-zonecache.hh @@ -37,10 +37,10 @@ public: using ViewsMap = std::map>; // Zone maintainance - void replace(const vector>& zone); + void replace(const vector>& zone); void replace(NetmaskTree nettree); void replace(ViewsMap viewsmap); - void add(const ZoneName& zone, const int zoneId); + void add(const ZoneName& zone, const domainid_t zoneId); void remove(const ZoneName& zone); void setReplacePending(); //!< call this when data collection for the subsequent replace() call starts. @@ -84,7 +84,7 @@ private: struct CacheValue { - int zoneId{-1}; + domainid_t zoneId{UnknownDomainID}; }; typedef std::unordered_map> cmap_t; @@ -117,7 +117,7 @@ private: struct PendingData { - std::vector> d_pendingUpdates; + std::vector> d_pendingUpdates; bool d_replacePending{false}; }; LockGuarded d_pending; diff --git a/pdns/dnsbackend.cc b/pdns/dnsbackend.cc index 1c0791361b..5ae71c45df 100644 --- a/pdns/dnsbackend.cc +++ b/pdns/dnsbackend.cc @@ -260,7 +260,7 @@ bool DNSBackend::getSOA(const ZoneName& domain, domainid_t zoneId, SOAData& soaD } zoneId = domaininfo.id; } - // Safe for zoneId to be -1 here - it won't be the case for variants, see above + // Safe for zoneId to be UnknownDomainID here - it won't be the case for variants, see above this->lookup(QType(QType::SOA), domain.operator const DNSName&(), zoneId); S.inc("backend-queries"); diff --git a/pdns/lua-record.cc b/pdns/lua-record.cc index 8f3d48c322..edfca3068f 100644 --- a/pdns/lua-record.cc +++ b/pdns/lua-record.cc @@ -613,7 +613,7 @@ static ComboAddress pickclosest(const ComboAddress& bestwho, const vectorsecond[dns_random(ranked.begin()->second.size())]; } -static std::vector lookup(const DNSName& name, uint16_t qtype, int zoneid) +static std::vector lookup(const DNSName& name, uint16_t qtype, domainid_t zoneid) { static LockGuarded s_ub; @@ -823,7 +823,7 @@ static void cleanZoneHashes() } } -static std::vector> getCHashedEntries(const int zoneId, const std::string& queryName, const std::vector>& items) +static std::vector> getCHashedEntries(const domainid_t zoneId, const std::string& queryName, const std::vector>& items) { std::vector> result{}; std::map> newEntries{}; diff --git a/pdns/ueberbackend.cc b/pdns/ueberbackend.cc index c42a874a2e..dbcdef8934 100644 --- a/pdns/ueberbackend.cc +++ b/pdns/ueberbackend.cc @@ -406,7 +406,7 @@ bool UeberBackend::inTransaction() return false; } -bool UeberBackend::fillSOAFromZoneRecord(ZoneName& shorter, const int zoneId, SOAData* const soaData) +bool UeberBackend::fillSOAFromZoneRecord(ZoneName& shorter, const domainid_t zoneId, SOAData* const soaData) { // Zone exists in zone cache, directly look up SOA. lookup(QType(QType::SOA), shorter.operator const DNSName&(), zoneId, nullptr); @@ -551,7 +551,7 @@ bool UeberBackend::getAuth(const ZoneName& target, const QType& qtype, SOAData* while (first || shorter.chopOff()) { first = false; - int zoneId{-1}; + domainid_t zoneId{UnknownDomainID}; if (cachedOk && g_zoneCache.isEnabled()) { std::string variant = g_zoneCache.getVariantFromView(shorter, view); @@ -643,7 +643,7 @@ bool UeberBackend::getSOAUncached(const ZoneName& domain, SOAData& soaData) { d_question.qtype = QType::SOA; d_question.qname = domain.operator const DNSName&(); - d_question.zoneId = -1; + d_question.zoneId = UnknownDomainID; for (auto& backend : backends) { // Do not risk passing variant zones to variant-unaware backends. @@ -806,7 +806,7 @@ UeberBackend::~UeberBackend() } // this handle is more magic than most -void UeberBackend::lookup(const QType& qtype, const DNSName& qname, int zoneId, DNSPacket* pkt_p) +void UeberBackend::lookup(const QType& qtype, const DNSName& qname, domainid_t zoneId, DNSPacket* pkt_p) { if (d_stale) { g_log << Logger::Error << "Stale ueberbackend received question, signalling that we want to be recycled" << endl; diff --git a/pdns/ueberbackend.hh b/pdns/ueberbackend.hh index f727e8d7cc..ea172f2a71 100644 --- a/pdns/ueberbackend.hh +++ b/pdns/ueberbackend.hh @@ -87,13 +87,13 @@ public: //! Index of the current backend within the backends vector unsigned int i{0}; QType qtype; - int zoneId{-1}; + domainid_t zoneId{UnknownDomainID}; private: static AtomicCounter instances; }; - void lookup(const QType& qtype, const DNSName& qname, int zoneId, DNSPacket* pkt_p = nullptr); + void lookup(const QType& qtype, const DNSName& qname, domainid_t zoneId, DNSPacket* pkt_p = nullptr); /** Read a single record from a lookup(...) result. */ bool get(DNSZoneRecord& resourceRecord); /** Close state created by lookup(...). */ @@ -164,7 +164,7 @@ private: struct Question { DNSName qname; - int zoneId; + domainid_t zoneId; QType qtype; } d_question; @@ -189,6 +189,6 @@ private: void addNegCache(const Question& question) const; void addCache(const Question& question, vector&& rrs) const; - bool fillSOAFromZoneRecord(ZoneName& shorter, int zoneId, SOAData* soaData); + bool fillSOAFromZoneRecord(ZoneName& shorter, domainid_t zoneId, SOAData* soaData); CacheResult fillSOAFromCache(SOAData* soaData, ZoneName& shorter); }; -- 2.47.2