]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
Also convert te recursor cache, adding the needed hash function for boost 9819/head
authorOtto Moerbeek <otto.moerbeek@open-xchange.com>
Tue, 8 Dec 2020 10:29:39 +0000 (11:29 +0100)
committerOtto <otto.moerbeek@open-xchange.com>
Wed, 10 Feb 2021 12:42:30 +0000 (13:42 +0100)
pdns/qtype.hh
pdns/recursor_cache.cc
pdns/recursor_cache.hh

index 510563b61a0ab7b87e2e19ec5072b22a879fe416..74695d94db141b75dea68454e6f9a407fb33d3ff 100644 (file)
@@ -138,6 +138,11 @@ namespace std {
   };
 }
 
+// Used by e.g. boost multi-index
+inline size_t hash_value(const QType qtype) {
+  return qtype.getCode();
+}
+
 struct QClass
 {
   enum QClassEnum { IN = 1, CHAOS = 3, NONE = 254, ANY = 255 };
index 37c0b2a372e43f20f4cc55d263dd2fb7c401b80a..28e3832f5b369883f5b5d8715fefffde6ae10bb3 100644 (file)
@@ -160,7 +160,7 @@ time_t MemRecursorCache::handleHit(MapCombo& map, MemRecursorCache::OrderedTagIt
   return ttd;
 }
 
-MemRecursorCache::cache_t::const_iterator MemRecursorCache::getEntryUsingECSIndex(MapCombo& map, time_t now, const DNSName &qname, uint16_t qtype, bool requireAuth, const ComboAddress& who)
+MemRecursorCache::cache_t::const_iterator MemRecursorCache::getEntryUsingECSIndex(MapCombo& map, time_t now, const DNSName &qname, const QType qtype, bool requireAuth, const ComboAddress& who)
 {
   // MUTEX SHOULD BE ACQUIRED
   auto ecsIndexKey = tie(qname, qtype);
@@ -222,7 +222,7 @@ MemRecursorCache::cache_t::const_iterator MemRecursorCache::getEntryUsingECSInde
   return map.d_map.end();
 }
 
-MemRecursorCache::Entries MemRecursorCache::getEntries(MapCombo& map, const DNSName &qname, const QType& qt, const OptTag& rtag )
+MemRecursorCache::Entries MemRecursorCache::getEntries(MapCombo& map, const DNSName &qname, const QType qt, const OptTag& rtag )
 {
   // MUTEX SHOULD BE ACQUIRED
   if (!map.d_cachecachevalid || map.d_cachedqname != qname || map.d_cachedrtag != rtag) {
@@ -236,7 +236,7 @@ MemRecursorCache::Entries MemRecursorCache::getEntries(MapCombo& map, const DNSN
 }
 
 
-bool MemRecursorCache::entryMatches(MemRecursorCache::OrderedTagIterator_t& entry, uint16_t qt, bool requireAuth, const ComboAddress& who)
+bool MemRecursorCache::entryMatches(MemRecursorCache::OrderedTagIterator_t& entry, const QType qt, bool requireAuth, const ComboAddress& who)
 {
   // This code assumes that if a routing tag is present, it matches
   // MUTEX SHOULD BE ACQUIRED
@@ -250,7 +250,7 @@ bool MemRecursorCache::entryMatches(MemRecursorCache::OrderedTagIterator_t& entr
 }
 
 // Fake a cache miss if more than refreshTTLPerc of the original TTL has passed
-time_t MemRecursorCache::fakeTTD(MemRecursorCache::OrderedTagIterator_t& entry, const DNSName& qname, uint16_t qtype, time_t ret, time_t now, uint32_t origTTL, bool refresh)
+time_t MemRecursorCache::fakeTTD(MemRecursorCache::OrderedTagIterator_t& entry, const DNSName& qname, QType qtype, time_t ret, time_t now, uint32_t origTTL, bool refresh)
 {
   time_t ttl = ret - now;
   if (ttl > 0 && SyncRes::s_refresh_ttlperc > 0) {
@@ -270,7 +270,7 @@ time_t MemRecursorCache::fakeTTD(MemRecursorCache::OrderedTagIterator_t& entry,
   return ttl;
 }
 // returns -1 for no hits
-time_t MemRecursorCache::get(time_t now, const DNSName &qname, const QType& qt, bool requireAuth, vector<DNSRecord>* res, const ComboAddress& who, bool refresh, const OptTag& routingTag, vector<std::shared_ptr<RRSIGRecordContent>>* signatures, std::vector<std::shared_ptr<DNSRecord>>* authorityRecs, bool* variable, vState* state, bool* wasAuth, DNSName* fromAuthZone)
+time_t MemRecursorCache::get(time_t now, const DNSName &qname, const QType qt, bool requireAuth, vector<DNSRecord>* res, const ComboAddress& who, bool refresh, const OptTag& routingTag, vector<std::shared_ptr<RRSIGRecordContent>>* signatures, std::vector<std::shared_ptr<DNSRecord>>* authorityRecs, bool* variable, vState* state, bool* wasAuth, DNSName* fromAuthZone)
 {
   boost::optional<vState> cachedState{boost::none};
   uint32_t origTTL;
@@ -348,7 +348,7 @@ time_t MemRecursorCache::get(time_t now, const DNSName &qname, const QType& qt,
         found = true;
         ttd = handleHit(map, firstIndexIterator, qname, origTTL, res, signatures, authorityRecs, variable, cachedState, wasAuth, fromAuthZone);
 
-        if (qt.getCode() != QType::ANY && qt.getCode() != QType::ADDR) { // normally if we have a hit, we are done
+        if (qt != QType::ANY && qt != QType::ADDR) { // normally if we have a hit, we are done
           break;
         }
       }
@@ -385,7 +385,7 @@ time_t MemRecursorCache::get(time_t now, const DNSName &qname, const QType& qt,
       found = true;
       ttd = handleHit(map, firstIndexIterator, qname, origTTL, res, signatures, authorityRecs, variable, cachedState, wasAuth, fromAuthZone);
 
-      if (qt.getCode() != QType::ANY && qt.getCode() != QType::ADDR) { // normally if we have a hit, we are done
+      if (qt != QType::ANY && qt != QType::ADDR) { // normally if we have a hit, we are done
         break;
       }
     }
@@ -399,7 +399,7 @@ time_t MemRecursorCache::get(time_t now, const DNSName &qname, const QType& qt,
   return -1;
 }
 
-void MemRecursorCache::replace(time_t now, const DNSName &qname, const QType& qt, const vector<DNSRecord>& content, const vector<shared_ptr<RRSIGRecordContent>>& signatures, const std::vector<std::shared_ptr<DNSRecord>>& authorityRecs, bool auth, const DNSName& authZone, boost::optional<Netmask> ednsmask, const OptTag& routingTag, vState state, boost::optional<ComboAddress> from)
+void MemRecursorCache::replace(time_t now, const DNSName &qname, const QType qt, const vector<DNSRecord>& content, const vector<shared_ptr<RRSIGRecordContent>>& signatures, const std::vector<std::shared_ptr<DNSRecord>>& authorityRecs, bool auth, const DNSName& authZone, boost::optional<Netmask> ednsmask, const OptTag& routingTag, vState state, boost::optional<ComboAddress> from)
 {
   auto& map = getMap(qname);
   const lock l(map);
@@ -464,7 +464,7 @@ void MemRecursorCache::replace(time_t now, const DNSName &qname, const QType& qt
   // for an auth to keep a "ghost" zone alive forever, even after the delegation is gone from
   // the parent
   // BUT make sure that we CAN refresh the root
-  if (ce.d_auth && auth && qt.getCode()==QType::NS && !isNew && !qname.isRoot()) {
+  if (ce.d_auth && auth && qt == QType::NS && !isNew && !qname.isRoot()) {
     //    cerr<<"\tLimiting TTL of auth->auth NS set replace to "<<ce.d_ttd<<endl;
     maxTTD = ce.d_ttd;
   }
@@ -497,7 +497,7 @@ void MemRecursorCache::replace(time_t now, const DNSName &qname, const QType& qt
   map.d_map.replace(stored, ce);
 }
 
-size_t MemRecursorCache::doWipeCache(const DNSName& name, bool sub, uint16_t qtype)
+size_t MemRecursorCache::doWipeCache(const DNSName& name, bool sub, const QType qtype)
 {
   size_t count = 0;
 
@@ -561,7 +561,7 @@ size_t MemRecursorCache::doWipeCache(const DNSName& name, bool sub, uint16_t qty
 }
 
 // Name should be doLimitTime or so
-bool MemRecursorCache::doAgeCache(time_t now, const DNSName& name, uint16_t qtype, uint32_t newTTL)
+bool MemRecursorCache::doAgeCache(time_t now, const DNSName& name, const QType qtype, uint32_t newTTL)
 {
   auto& map = getMap(name);
   const lock l(map);
@@ -589,7 +589,7 @@ bool MemRecursorCache::doAgeCache(time_t now, const DNSName& name, uint16_t qtyp
   return false;
 }
 
-bool MemRecursorCache::updateValidationStatus(time_t now, const DNSName &qname, const QType& qt, const ComboAddress& who, const OptTag& routingTag, bool requireAuth, vState newState, boost::optional<time_t> capTTD)
+bool MemRecursorCache::updateValidationStatus(time_t now, const DNSName &qname, const QType qt, const ComboAddress& who, const OptTag& routingTag, bool requireAuth, vState newState, boost::optional<time_t> capTTD)
 {
   uint16_t qtype = qt.getCode();
   if (qtype == QType::ANY) {
index c2446f4c5ecb3fda6832103bc9dd54b8d0220852..469d43df0a87d8cbe2e949dc931976e16464adbf 100644 (file)
@@ -57,16 +57,16 @@ public:
 
   typedef boost::optional<std::string> OptTag;
 
-time_t get(time_t, const DNSName &qname, const QType& qt, bool requireAuth, vector<DNSRecord>* res, const ComboAddress& who, bool refresh = false, const OptTag& routingTag = boost::none, vector<std::shared_ptr<RRSIGRecordContent>>* signatures=nullptr, std::vector<std::shared_ptr<DNSRecord>>* authorityRecs=nullptr, bool* variable=nullptr, vState* state=nullptr, bool* wasAuth=nullptr, DNSName* fromAuthZone=nullptr);
+  time_t get(time_t, const DNSName &qname, const QType qt, bool requireAuth, vector<DNSRecord>* res, const ComboAddress& who, bool refresh = false, const OptTag& routingTag = boost::none, vector<std::shared_ptr<RRSIGRecordContent>>* signatures=nullptr, std::vector<std::shared_ptr<DNSRecord>>* authorityRecs=nullptr, bool* variable=nullptr, vState* state=nullptr, bool* wasAuth=nullptr, DNSName* fromAuthZone=nullptr);
 
-  void replace(time_t, const DNSName &qname, const QType& qt,  const vector<DNSRecord>& content, const vector<shared_ptr<RRSIGRecordContent>>& signatures, const std::vector<std::shared_ptr<DNSRecord>>& authorityRecs, bool auth, const DNSName& authZone, boost::optional<Netmask> ednsmask=boost::none, const OptTag& routingTag = boost::none, vState state=vState::Indeterminate, boost::optional<ComboAddress> from=boost::none);
+  void replace(time_t, const DNSName &qname, const QType qt,  const vector<DNSRecord>& content, const vector<shared_ptr<RRSIGRecordContent>>& signatures, const std::vector<std::shared_ptr<DNSRecord>>& authorityRecs, bool auth, const DNSName& authZone, boost::optional<Netmask> ednsmask=boost::none, const OptTag& routingTag = boost::none, vState state=vState::Indeterminate, boost::optional<ComboAddress> from=boost::none);
 
   void doPrune(size_t keep);
   uint64_t doDump(int fd);
 
-  size_t doWipeCache(const DNSName& name, bool sub, uint16_t qtype=0xffff);
-  bool doAgeCache(time_t now, const DNSName& name, uint16_t qtype, uint32_t newTTL);
-  bool updateValidationStatus(time_t now, const DNSName &qname, const QType& qt, const ComboAddress& who, const OptTag& routingTag, bool requireAuth, vState newState, boost::optional<time_t> capTTD);
+  size_t doWipeCache(const DNSName& name, bool sub, QType qtype=0xffff);
+  bool doAgeCache(time_t now, const DNSName& name, QType qtype, uint32_t newTTL);
+  bool updateValidationStatus(time_t now, const DNSName &qname, QType qt, const ComboAddress& who, const OptTag& routingTag, bool requireAuth, vState newState, boost::optional<time_t> capTTD);
 
   std::atomic<uint64_t> cacheHits{0}, cacheMisses{0};
 
@@ -74,7 +74,7 @@ private:
 
   struct CacheEntry
   {
-    CacheEntry(const boost::tuple<DNSName, uint16_t, OptTag, Netmask>& key, bool auth):
+    CacheEntry(const boost::tuple<DNSName, QType, OptTag, Netmask>& key, bool auth):
       d_qname(key.get<0>()), d_netmask(key.get<3>().getNormalized()), d_rtag(key.get<2>()), d_state(vState::Indeterminate), d_ttd(0), d_qtype(key.get<1>()), d_auth(auth), d_submitted(false)
     {
     }
@@ -96,7 +96,7 @@ private:
     mutable vState d_state;
     mutable time_t d_ttd;
     uint32_t d_orig_ttl;
-    uint16_t d_qtype;
+    QType d_qtype;
     bool d_auth;
     mutable bool d_submitted;     // whether this entry has been queued for refetch
   };
@@ -114,7 +114,7 @@ private:
   class ECSIndexEntry
   {
   public:
-    ECSIndexEntry(const DNSName& qname, uint16_t qtype): d_nmt(), d_qname(qname), d_qtype(qtype)
+    ECSIndexEntry(const DNSName& qname, QType qtype): d_nmt(), d_qname(qname), d_qtype(qtype)
     {
     }
 
@@ -145,7 +145,7 @@ private:
 
     mutable NetmaskTree<bool> d_nmt;
     DNSName d_qname;
-    uint16_t d_qtype;
+    QType d_qtype;
   };
 
   struct HashedTag {};
@@ -160,11 +160,11 @@ private:
                         composite_key<
                                 CacheEntry,
                                 member<CacheEntry,DNSName,&CacheEntry::d_qname>,
-                                member<CacheEntry,uint16_t,&CacheEntry::d_qtype>,
+                                member<CacheEntry,QType,&CacheEntry::d_qtype>,
                                 member<CacheEntry,OptTag,&CacheEntry::d_rtag>,
                                 member<CacheEntry,Netmask,&CacheEntry::d_netmask>
                           >,
-                               composite_key_compare<CanonDNSNameCompare, std::less<uint16_t>, std::less<OptTag>, std::less<Netmask> >
+                               composite_key_compare<CanonDNSNameCompare, std::less<QType>, std::less<OptTag>, std::less<Netmask> >
                 >,
                 sequenced<tag<SequencedTag> >,
                 hashed_non_unique<tag<NameAndRTagOnlyHashedTag>,
@@ -187,16 +187,16 @@ private:
         composite_key<
           ECSIndexEntry,
           member<ECSIndexEntry,DNSName,&ECSIndexEntry::d_qname>,
-          member<ECSIndexEntry,uint16_t,&ECSIndexEntry::d_qtype>
+          member<ECSIndexEntry,QType,&ECSIndexEntry::d_qtype>
         >
       >,
       ordered_unique<tag<OrderedTag>,
         composite_key<
           ECSIndexEntry,
           member<ECSIndexEntry,DNSName,&ECSIndexEntry::d_qname>,
-          member<ECSIndexEntry,uint16_t,&ECSIndexEntry::d_qtype>
+          member<ECSIndexEntry,QType,&ECSIndexEntry::d_qtype>
         >,
-        composite_key_compare<CanonDNSNameCompare, std::less<uint16_t> >
+        composite_key_compare<CanonDNSNameCompare, std::less<QType> >
       >
     >
   > ecsIndex_t;
@@ -231,11 +231,11 @@ private:
     return d_maps[qname.hash() % d_maps.size()];
   }
 
-  static time_t fakeTTD(OrderedTagIterator_t& entry, const DNSName& qname, uint16_t qtype, time_t ret, time_t now, uint32_t origTTL, bool refresh);
+  static time_t fakeTTD(OrderedTagIterator_t& entry, const DNSName& qname, QType qtype, time_t ret, time_t now, uint32_t origTTL, bool refresh);
 
-  bool entryMatches(OrderedTagIterator_t& entry, uint16_t qt, bool requireAuth, const ComboAddress& who);
-  Entries getEntries(MapCombo& map, const DNSName &qname, const QType& qt, const OptTag& rtag);
-  cache_t::const_iterator getEntryUsingECSIndex(MapCombo& map, time_t now, const DNSName &qname, uint16_t qtype, bool requireAuth, const ComboAddress& who);
+  bool entryMatches(OrderedTagIterator_t& entry, QType qt, bool requireAuth, const ComboAddress& who);
+  Entries getEntries(MapCombo& map, const DNSName &qname, const QType qt, const OptTag& rtag);
+  cache_t::const_iterator getEntryUsingECSIndex(MapCombo& map, time_t now, const DNSName &qname, QType qtype, bool requireAuth, const ComboAddress& who);
 
   time_t handleHit(MapCombo& map, OrderedTagIterator_t& entry, const DNSName& qname, uint32_t& origTTL, vector<DNSRecord>* res, vector<std::shared_ptr<RRSIGRecordContent>>* signatures, std::vector<std::shared_ptr<DNSRecord>>* authorityRecs, bool* variable, boost::optional<vState>& state, bool* wasAuth, DNSName* authZone);