From: bert hubert Date: Sun, 4 Sep 2016 19:03:16 +0000 (+0200) Subject: packetcache hashed X-Git-Tag: dnsdist-1.1.0-beta2~123^2~27 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=9b1c52553f86f601d9bf0d3e66a2a1dce7d8e180;p=thirdparty%2Fpdns.git packetcache hashed --- diff --git a/pdns/packetcache.cc b/pdns/packetcache.cc index 35212fc417..cfc3915931 100644 --- a/pdns/packetcache.cc +++ b/pdns/packetcache.cc @@ -315,16 +315,26 @@ bool PacketCache::getEntryLocked(const DNSName &qname, const QType& qtype, Cache uint16_t qt = qtype.getCode(); //cerr<<"Lookup for maxReplyLen: "<(mc.d_map); + auto range=idx.equal_range(tie(qname, qt, cet, zoneID)); + + if(range.first == range.second) + return false; time_t now=time(0); - bool ret=(i!=mc.d_map.end() && i->ttd > now); - if(ret) { - if (age) - *age = now - i->created; - value = i->value; + for(auto iter = range.first ; iter != range.second; ++iter) { + if(meritsRecursion == iter->meritsRecursion && maxReplyLen == iter->maxReplyLen && dnssecOK == iter->dnssecOk && hasEDNS == iter->hasEDNS ) { + if(iter->ttd > now) { + if (age) + *age = now - iter->created; + value = iter->value; + return true; + } + } } - return ret; + return false; } bool PacketCache::getEntryLocked(const DNSName &qname, const QType& qtype, CacheEntryType cet, vector& value, int zoneID) @@ -332,13 +342,17 @@ bool PacketCache::getEntryLocked(const DNSName &qname, const QType& qtype, Cache uint16_t qt = qtype.getCode(); //cerr<<"Lookup for maxReplyLen: "<(mc.d_map); + auto i=idx.find(tie(qname, qt, cet, zoneID)); + if(i==idx.end()) + return false; + time_t now=time(0); - bool ret=(i!=mc.d_map.end() && i->ttd > now); - if(ret) { + if(i->ttd > now) { value = i->drs; + return true; } - return ret; + return false; } diff --git a/pdns/packetcache.hh b/pdns/packetcache.hh index 47c3445371..172524ab3b 100644 --- a/pdns/packetcache.hh +++ b/pdns/packetcache.hh @@ -32,6 +32,7 @@ using namespace ::boost::multi_index; #include "namespaces.hh" +#include #include "dnspacket.hh" #include "lock.hh" #include "statbag.hh" @@ -111,6 +112,7 @@ private: void getTTLS(); + struct UnorderedNameTag{}; typedef multi_index_container< CacheEntry, indexed_by < @@ -128,8 +130,13 @@ private: >, composite_key_compare, std::less, std::less, std::less, std::less, std::less, std::less > - >, - sequenced<> + >, + hashed_non_unique, composite_key, + member, + member, + member > > , + sequenced<> > > cmap_t;