2 * This file is part of PowerDNS or dnsdist.
3 * Copyright -- PowerDNS.COM B.V. and its contributors
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of version 2 of the GNU General Public License as
7 * published by the Free Software Foundation.
9 * In addition, for the avoidance of any doubt, permission is granted to
10 * link this program with OpenSSL and to (re)distribute the binaries
11 * produced as the result of such linking.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
22 #ifndef RECURSOR_CACHE_HH
23 #define RECURSOR_CACHE_HH
31 #include "dnsrecords.hh"
32 #include <boost/utility.hpp>
34 #include <boost/multi_index_container.hpp>
35 #include <boost/multi_index/ordered_index.hpp>
36 #include <boost/tuple/tuple_comparison.hpp>
37 #include <boost/multi_index/key_extractors.hpp>
38 #include <boost/multi_index/sequenced_index.hpp>
39 #include <boost/version.hpp>
44 #include "namespaces.hh"
45 using namespace ::boost::multi_index;
47 class MemRecursorCache : public boost::noncopyable // : public RecursorCache
50 MemRecursorCache() : d_cachecachevalid(false)
52 cacheHits = cacheMisses = 0;
56 int get(time_t, const DNSName &qname, const QType& qt, vector<DNSRecord>* res, const ComboAddress& who, vector<std::shared_ptr<RRSIGRecordContent>>* signatures=0);
58 void replace(time_t, const DNSName &qname, const QType& qt, const vector<DNSRecord>& content, const vector<shared_ptr<RRSIGRecordContent>>& signatures, bool auth, boost::optional<Netmask> ednsmask=boost::optional<Netmask>());
60 void doSlash(int perc);
61 uint64_t doDump(int fd);
62 uint64_t doDumpNSSpeeds(int fd);
64 int doWipeCache(const DNSName& name, bool sub, uint16_t qtype=0xffff);
65 bool doAgeCache(time_t now, const DNSName& name, uint16_t qtype, int32_t newTTL);
66 uint64_t cacheHits, cacheMisses;
72 CacheEntry(const boost::tuple<DNSName, uint16_t, Netmask>& key, const vector<shared_ptr<DNSRecordContent>>& records, bool auth) :
73 d_qname(key.get<0>()), d_qtype(key.get<1>()), d_auth(auth), d_ttd(0), d_records(records), d_netmask(key.get<2>())
76 typedef vector<std::shared_ptr<DNSRecordContent>> records_t;
77 vector<std::shared_ptr<RRSIGRecordContent>> d_signatures;
78 uint32_t getTTD() const
91 typedef multi_index_container<
97 member<CacheEntry,DNSName,&CacheEntry::d_qname>,
98 member<CacheEntry,uint16_t,&CacheEntry::d_qtype>,
99 member<CacheEntry,Netmask,&CacheEntry::d_netmask>
101 composite_key_compare<CanonDNSNameCompare, std::less<uint16_t>, std::less<Netmask> >
108 pair<cache_t::iterator, cache_t::iterator> d_cachecache;
109 DNSName d_cachedqname;
110 bool d_cachecachevalid;
111 bool attemptToRefreshNSTTL(const QType& qt, const vector<DNSRecord>& content, const CacheEntry& stored);