From: Otto Moerbeek Date: Tue, 8 Dec 2020 10:29:39 +0000 (+0100) Subject: Also convert te recursor cache, adding the needed hash function for boost X-Git-Tag: dnsdist-1.6.0-alpha2~46^2 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=refs%2Fpull%2F9819%2Fhead;p=thirdparty%2Fpdns.git Also convert te recursor cache, adding the needed hash function for boost --- diff --git a/pdns/qtype.hh b/pdns/qtype.hh index 510563b61a..74695d94db 100644 --- a/pdns/qtype.hh +++ b/pdns/qtype.hh @@ -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 }; diff --git a/pdns/recursor_cache.cc b/pdns/recursor_cache.cc index 37c0b2a372..28e3832f5b 100644 --- a/pdns/recursor_cache.cc +++ b/pdns/recursor_cache.cc @@ -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* res, const ComboAddress& who, bool refresh, const OptTag& routingTag, vector>* signatures, std::vector>* 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* res, const ComboAddress& who, bool refresh, const OptTag& routingTag, vector>* signatures, std::vector>* authorityRecs, bool* variable, vState* state, bool* wasAuth, DNSName* fromAuthZone) { boost::optional 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& content, const vector>& signatures, const std::vector>& authorityRecs, bool auth, const DNSName& authZone, boost::optional ednsmask, const OptTag& routingTag, vState state, boost::optional from) +void MemRecursorCache::replace(time_t now, const DNSName &qname, const QType qt, const vector& content, const vector>& signatures, const std::vector>& authorityRecs, bool auth, const DNSName& authZone, boost::optional ednsmask, const OptTag& routingTag, vState state, boost::optional 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 "< 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 capTTD) { uint16_t qtype = qt.getCode(); if (qtype == QType::ANY) { diff --git a/pdns/recursor_cache.hh b/pdns/recursor_cache.hh index c2446f4c5e..469d43df0a 100644 --- a/pdns/recursor_cache.hh +++ b/pdns/recursor_cache.hh @@ -57,16 +57,16 @@ public: typedef boost::optional OptTag; -time_t get(time_t, const DNSName &qname, const QType& qt, bool requireAuth, vector* res, const ComboAddress& who, bool refresh = false, const OptTag& routingTag = boost::none, vector>* signatures=nullptr, std::vector>* 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* res, const ComboAddress& who, bool refresh = false, const OptTag& routingTag = boost::none, vector>* signatures=nullptr, std::vector>* 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& content, const vector>& signatures, const std::vector>& authorityRecs, bool auth, const DNSName& authZone, boost::optional ednsmask=boost::none, const OptTag& routingTag = boost::none, vState state=vState::Indeterminate, boost::optional from=boost::none); + void replace(time_t, const DNSName &qname, const QType qt, const vector& content, const vector>& signatures, const std::vector>& authorityRecs, bool auth, const DNSName& authZone, boost::optional ednsmask=boost::none, const OptTag& routingTag = boost::none, vState state=vState::Indeterminate, boost::optional 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 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 capTTD); std::atomic cacheHits{0}, cacheMisses{0}; @@ -74,7 +74,7 @@ private: struct CacheEntry { - CacheEntry(const boost::tuple& key, bool auth): + CacheEntry(const boost::tuple& 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 d_nmt; DNSName d_qname; - uint16_t d_qtype; + QType d_qtype; }; struct HashedTag {}; @@ -160,11 +160,11 @@ private: composite_key< CacheEntry, member, - member, + member, member, member >, - composite_key_compare, std::less, std::less > + composite_key_compare, std::less, std::less > >, sequenced >, hashed_non_unique, @@ -187,16 +187,16 @@ private: composite_key< ECSIndexEntry, member, - member + member > >, ordered_unique, composite_key< ECSIndexEntry, member, - member + member >, - composite_key_compare > + composite_key_compare > > > > 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* res, vector>* signatures, std::vector>* authorityRecs, bool* variable, boost::optional& state, bool* wasAuth, DNSName* authZone);