]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
rec: Add a hashed index to the negative cache
authorRemi Gacogne <remi.gacogne@powerdns.com>
Thu, 5 Apr 2018 09:43:52 +0000 (11:43 +0200)
committerRemi Gacogne <remi.gacogne@powerdns.com>
Fri, 13 Apr 2018 14:14:15 +0000 (16:14 +0200)
pdns/recursordist/negcache.cc
pdns/recursordist/negcache.hh

index 7b9d33645ab8f6d68af59f0e9b62b9ad0c43b5a9..13fbf619fe6026bc32b2aae50359633e63c38a7f 100644 (file)
@@ -71,21 +71,24 @@ bool NegCache::getRootNXTrust(const DNSName& qname, const struct timeval& now, N
  * \return         true if ne was filled out, false otherwise
  */
 bool NegCache::get(const DNSName& qname, const QType& qtype, const struct timeval& now, NegCacheEntry& ne, bool typeMustMatch) {
-  auto range = d_negcache.equal_range(tie(qname));
-  negcache_t::iterator ni = range.first;
+  const auto& idx = d_negcache.get<2>();
+  auto range = idx.equal_range(qname);
+  auto ni = range.first;
 
   while (ni != range.second) {
     // We have an entry
     if ((!typeMustMatch && ni->d_qtype.getCode() == 0) || ni->d_qtype == qtype) {
       // We match the QType or the whole name is denied
+      auto firstIndexIterator = d_negcache.project<0>(ni);
+
       if((uint32_t) now.tv_sec < ni->d_ttd) {
         // Not expired
         ne = *ni;
-        moveCacheItemToBack(d_negcache, ni);
+        moveCacheItemToBack(d_negcache, firstIndexIterator);
         return true;
       }
       // expired
-      moveCacheItemToFront(d_negcache, ni);
+      moveCacheItemToFront(d_negcache, firstIndexIterator);
     }
     ++ni;
   }
index d1a742da3e06d8ef83ab7abff6a40e4a2a982309..2bc41da620796d3ec2f0d8a924a91cd4146eb178 100644 (file)
@@ -22,6 +22,7 @@
 #pragma once
 
 #include <boost/multi_index_container.hpp>
+#include <boost/multi_index/hashed_index.hpp>
 #include "dnsparser.hh"
 #include "dnsname.hh"
 #include "dns.hh"
@@ -90,7 +91,10 @@ class NegCache : public boost::noncopyable {
             CanonDNSNameCompare, std::less<QType>
           >
         >,
-        sequenced<>
+        sequenced<>,
+        hashed_non_unique <
+          member<NegCacheEntry, DNSName, &NegCacheEntry::d_name>
+        >
       >
     > negcache_t;