]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
More use of domainid_t instead of int.
authorMiod Vallat <miod.vallat@powerdns.com>
Mon, 5 May 2025 06:24:52 +0000 (08:24 +0200)
committerMiod Vallat <miod.vallat@powerdns.com>
Mon, 26 May 2025 11:49:12 +0000 (13:49 +0200)
modules/bindbackend/bindbackend2.hh
pdns/auth-querycache.cc
pdns/auth-querycache.hh
pdns/auth-zonecache.cc
pdns/auth-zonecache.hh
pdns/dnsbackend.cc
pdns/lua-record.cc
pdns/ueberbackend.cc
pdns/ueberbackend.hh

index 6fe202ef9c6c532042248e19c8ef19c30f2fa86a..cc6658235dfed5babea00cfd420da6c14722330f 100644 (file)
@@ -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<BB2DomainInfo,
-                                indexed_by<ordered_unique<member<BB2DomainInfo, unsigned int, &BB2DomainInfo::d_id>>,
+                                indexed_by<ordered_unique<member<BB2DomainInfo, domainid_t, &BB2DomainInfo::d_id>>,
                                            ordered_unique<tag<NameTag>, member<BB2DomainInfo, ZoneName, &BB2DomainInfo::d_name>>>>
     state_t;
   static SharedLockGuarded<state_t> s_state;
index b397c1e830454aae92ee33792885d248afdcb41e..844a5dc4b5732875bd5bf8f78bfb8876e7f690f2 100644 (file)
@@ -52,7 +52,7 @@ void AuthQueryCache::MapCombo::reserve(size_t numberOfEntries)
 }
 
 // called from ueberbackend
-bool AuthQueryCache::getEntry(const DNSName &qname, const QType& qtype, vector<DNSZoneRecord>& value, int zoneID)
+bool AuthQueryCache::getEntry(const DNSName &qname, const QType& qtype, vector<DNSZoneRecord>& value, domainid_t zoneID)
 {
   cleanupIfNeeded();
 
@@ -70,7 +70,7 @@ bool AuthQueryCache::getEntry(const DNSName &qname, const QType& qtype, vector<D
   }
 }
 
-void AuthQueryCache::insert(const DNSName &qname, const QType& qtype, vector<DNSZoneRecord>&& value, uint32_t ttl, int zoneID)
+void AuthQueryCache::insert(const DNSName &qname, const QType& qtype, vector<DNSZoneRecord>&& value, uint32_t ttl, domainid_t zoneID)
 {
   cleanupIfNeeded();
 
@@ -115,7 +115,7 @@ void AuthQueryCache::insert(const DNSName &qname, const QType& qtype, vector<DNS
   }
 }
 
-bool AuthQueryCache::getEntryLocked(const cmap_t& map, const DNSName &qname, uint16_t qtype, vector<DNSZoneRecord>& value, int zoneID, time_t now)
+bool AuthQueryCache::getEntryLocked(const cmap_t& map, const DNSName &qname, uint16_t qtype, vector<DNSZoneRecord>& value, domainid_t zoneID, time_t now)
 {
   auto& idx = boost::multi_index::get<HashTag>(map);
   auto iter = idx.find(std::tie(qname, qtype, zoneID));
index b144b366700d42fa6caa0ccdf440e25ee1ac2bc7..712cde113db9c9219094f254ebabd8daf0283fa7 100644 (file)
@@ -42,9 +42,9 @@ class AuthQueryCache : public boost::noncopyable
 public:
   AuthQueryCache(size_t mapsCount=1024);
 
-  void insert(const DNSName &qname, const QType& qtype, vector<DNSZoneRecord>&& content, uint32_t ttl, int zoneID);
+  void insert(const DNSName &qname, const QType& qtype, vector<DNSZoneRecord>&& value, uint32_t ttl, domainid_t zoneID);
 
-  bool getEntry(const DNSName &qname, const QType& qtype, vector<DNSZoneRecord>& entry, int zoneID);
+  bool getEntry(const DNSName &qname, const QType& qtype, vector<DNSZoneRecord>& 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<DNSZoneRecord> 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<DNSZoneRecord>& entry, int zoneID, time_t now);
+  bool getEntryLocked(const cmap_t& map, const DNSName &qname, uint16_t qtype, vector<DNSZoneRecord>& value, domainid_t zoneID, time_t now);
   void cleanupIfNeeded();
 
   AtomicCounter d_ops{0};
index ff4c0948d96e632e76fe947b4b22b1dcbd1dd00e..904c75abd4b49bbfe7dd1d6bf9d3a93df135066a 100644 (file)
@@ -134,7 +134,7 @@ void AuthZoneCache::clear()
   }
 }
 
-void AuthZoneCache::replace(const vector<std::tuple<ZoneName, int>>& zone_indices)
+void AuthZoneCache::replace(const vector<std::tuple<ZoneName, domainid_t>>& 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();
index 29c530cb34391ec533a9ef6207471daba153e4b6..ae511d1e569e8e9d5d11ebf42e42d183a67ad79d 100644 (file)
@@ -37,10 +37,10 @@ public:
   using ViewsMap = std::map<std::string, std::map<DNSName, std::string>>;
 
   // Zone maintainance
-  void replace(const vector<std::tuple<ZoneName, int>>& zone);
+  void replace(const vector<std::tuple<ZoneName, domainid_t>>& zone);
   void replace(NetmaskTree<string> 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<ZoneName, CacheValue, std::hash<ZoneName>> cmap_t;
@@ -117,7 +117,7 @@ private:
 
   struct PendingData
   {
-    std::vector<std::tuple<ZoneName, int, bool>> d_pendingUpdates;
+    std::vector<std::tuple<ZoneName, domainid_t, bool>> d_pendingUpdates;
     bool d_replacePending{false};
   };
   LockGuarded<PendingData> d_pending;
index 1c0791361baf3899507b7405ec71c31845f012a5..5ae71c45df7cc07bea9c3fca97d4171790a88712 100644 (file)
@@ -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");
 
index 8f3d48c3226bf676bbf9eab25d4b599008bb5b3e..edfca3068f72cae3db546dc1fcb82b28f7010791 100644 (file)
@@ -613,7 +613,7 @@ static ComboAddress pickclosest(const ComboAddress& bestwho, const vector<ComboA
   return ranked.begin()->second[dns_random(ranked.begin()->second.size())];
 }
 
-static std::vector<DNSZoneRecord> lookup(const DNSName& name, uint16_t qtype, int zoneid)
+static std::vector<DNSZoneRecord> lookup(const DNSName& name, uint16_t qtype, domainid_t zoneid)
 {
   static LockGuarded<UeberBackend> s_ub;
 
@@ -823,7 +823,7 @@ static void cleanZoneHashes()
   }
 }
 
-static std::vector<std::shared_ptr<EntryHashesHolder>> getCHashedEntries(const int zoneId, const std::string& queryName, const std::vector<std::pair<int, std::string>>& items)
+static std::vector<std::shared_ptr<EntryHashesHolder>> getCHashedEntries(const domainid_t zoneId, const std::string& queryName, const std::vector<std::pair<int, std::string>>& items)
 {
   std::vector<std::shared_ptr<EntryHashesHolder>> result{};
   std::map<zone_hashes_key_t, std::shared_ptr<EntryHashesHolder>> newEntries{};
index c42a874a2ed4168b18192066795ed218a939a796..dbcdef89340e477e7c1901471220baecddd37275 100644 (file)
@@ -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;
index f727e8d7cc82bf2b435e86888dfef12d344ef361..ea172f2a711906e7616f4d33ed6a8d49a71f5e87 100644 (file)
@@ -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<DNSZoneRecord>&& 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);
 };