From: Kees Monshouwer Date: Tue, 5 Jun 2018 00:16:26 +0000 (+0200) Subject: rec: add cached bogus answers to the statistics X-Git-Tag: dnsdist-1.3.1~25^2~2 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=88694a6a80b81bb8a0115d48057d930509284902;p=thirdparty%2Fpdns.git rec: add cached bogus answers to the statistics --- diff --git a/pdns/pdns_recursor.cc b/pdns/pdns_recursor.cc index 09cbd181d5..6a7a870311 100644 --- a/pdns/pdns_recursor.cc +++ b/pdns/pdns_recursor.cc @@ -1357,6 +1357,7 @@ static void startDoResolve(void *p) g_now.tv_sec, pw.getHeader()->rcode == RCode::ServFail ? SyncRes::s_packetcacheservfailttl : min(minTTL,SyncRes::s_packetcachettl), + dq.validationState, pbMessage); } // else cerr<<"Not putting in packet cache: "<getResponsePacket(ctag, question, qname, qtype, qclass, g_now.tv_sec, &response, &age, &qhash, pbMessage ? &(*pbMessage) : nullptr)); + cacheHit = (!SyncRes::s_nopacketcache && t_packetCache->getResponsePacket(ctag, source, question, qname, qtype, qclass, g_now.tv_sec, &response, &age, &qhash, pbMessage ? &(*pbMessage) : nullptr)); } else { - cacheHit = (!SyncRes::s_nopacketcache && t_packetCache->getResponsePacket(ctag, question, g_now.tv_sec, &response, &age, &qhash, pbMessage ? &(*pbMessage) : nullptr)); + cacheHit = (!SyncRes::s_nopacketcache && t_packetCache->getResponsePacket(ctag, source, question, g_now.tv_sec, &response, &age, &qhash, pbMessage ? &(*pbMessage) : nullptr)); } if (cacheHit) { diff --git a/pdns/recpacketcache.cc b/pdns/recpacketcache.cc index fc27b26d43..4067f4bbb1 100644 --- a/pdns/recpacketcache.cc +++ b/pdns/recpacketcache.cc @@ -8,6 +8,7 @@ #include "cachecleaner.hh" #include "dns.hh" #include "namespaces.hh" +#include "syncres.hh" RecursorPacketCache::RecursorPacketCache() { @@ -45,7 +46,7 @@ static bool qrMatch(const DNSName& qname, uint16_t qtype, uint16_t qclass, const return qname==rname && rtype == qtype && rclass == qclass; } -bool RecursorPacketCache::checkResponseMatches(std::pair::type::iterator, packetCache_t::index::type::iterator> range, const std::string& queryPacket, const DNSName& qname, uint16_t qtype, uint16_t qclass, time_t now, std::string* responsePacket, uint32_t* age, RecProtoBufMessage* protobufMessage) +bool RecursorPacketCache::checkResponseMatches(std::pair::type::iterator, packetCache_t::index::type::iterator> range, const ComboAddress& source, const std::string& queryPacket, const DNSName& qname, uint16_t qtype, uint16_t qclass, time_t now, std::string* responsePacket, uint32_t* age, RecProtoBufMessage* protobufMessage) { for(auto iter = range.first ; iter != range.second ; ++ iter) { // the possibility is VERY real that we get hits that are not right - birthday paradox @@ -66,6 +67,12 @@ bool RecursorPacketCache::checkResponseMatches(std::paird_vstate == Bogus) { + if(t_bogusremotes) + t_bogusremotes->push_back(source); + if(t_bogusqueryring) + t_bogusqueryring->push_back(make_pair(qname, qtype)); + } d_hits++; moveCacheItemToBack(d_packetCache, iter); #ifdef HAVE_PROTOBUF @@ -94,16 +101,18 @@ bool RecursorPacketCache::checkResponseMatches(std::pair pb(boost::none); - insertResponsePacket(tag, qhash, qname, qtype, qclass, responsePacket, now, ttl, pb); + insertResponsePacket(tag, qhash, qname, qtype, qclass, responsePacket, now, ttl, valState, pb); } -void RecursorPacketCache::insertResponsePacket(unsigned int tag, uint32_t qhash, const DNSName& qname, uint16_t qtype, uint16_t qclass, const std::string& responsePacket, time_t now, uint32_t ttl, const boost::optional& protobufMessage) +void RecursorPacketCache::insertResponsePacket(unsigned int tag, uint32_t qhash, const DNSName& qname, uint16_t qtype, uint16_t qclass, const std::string& responsePacket, time_t now, uint32_t ttl, const vState& valState, const boost::optional& protobufMessage) { auto& idx = d_packetCache.get(); auto range = idx.equal_range(tie(tag,qhash)); @@ -174,6 +182,7 @@ void RecursorPacketCache::insertResponsePacket(unsigned int tag, uint32_t qhash, e.d_ttd = now+ttl; e.d_creation = now; e.d_tag = tag; + e.d_vstate = valState; #ifdef HAVE_PROTOBUF if (protobufMessage) { e.d_protobufMessage = *protobufMessage; diff --git a/pdns/recpacketcache.hh b/pdns/recpacketcache.hh index 2ceda67a06..0fa182c71b 100644 --- a/pdns/recpacketcache.hh +++ b/pdns/recpacketcache.hh @@ -33,6 +33,7 @@ #include #include "packetcache.hh" +#include "validate.hh" #ifdef HAVE_CONFIG_H #include "config.h" @@ -51,12 +52,13 @@ class RecursorPacketCache: public PacketCache { public: RecursorPacketCache(); + bool getResponsePacket(unsigned int tag, const std::string& queryPacket, time_t now, std::string* responsePacket, uint32_t* age, uint32_t* qhash); - bool getResponsePacket(unsigned int tag, const std::string& queryPacket, time_t now, std::string* responsePacket, uint32_t* age, uint32_t* qhash, RecProtoBufMessage* protobufMessage); bool getResponsePacket(unsigned int tag, const std::string& queryPacket, const DNSName& qname, uint16_t qtype, uint16_t qclass, time_t now, std::string* responsePacket, uint32_t* age, uint32_t* qhash); - bool getResponsePacket(unsigned int tag, const std::string& queryPacket, const DNSName& qname, uint16_t qtype, uint16_t qclass, time_t now, std::string* responsePacket, uint32_t* age, uint32_t* qhash, RecProtoBufMessage* protobufMessage); + bool getResponsePacket(unsigned int tag, const ComboAddress& source, const std::string& queryPacket, time_t now, std::string* responsePacket, uint32_t* age, uint32_t* qhash, RecProtoBufMessage* protobufMessage); + bool getResponsePacket(unsigned int tag, const ComboAddress& source, const std::string& queryPacket, const DNSName& qname, uint16_t qtype, uint16_t qclass, time_t now, std::string* responsePacket, uint32_t* age, uint32_t* qhash, RecProtoBufMessage* protobufMessage); void insertResponsePacket(unsigned int tag, uint32_t qhash, const DNSName& qname, uint16_t qtype, uint16_t qclass, const std::string& responsePacket, time_t now, uint32_t ttl); - void insertResponsePacket(unsigned int tag, uint32_t qhash, const DNSName& qname, uint16_t qtype, uint16_t qclass, const std::string& responsePacket, time_t now, uint32_t ttl, const boost::optional& protobufMessage); + void insertResponsePacket(unsigned int tag, uint32_t qhash, const DNSName& qname, uint16_t qtype, uint16_t qclass, const std::string& responsePacket, time_t now, uint32_t ttl, const vState& valState, const boost::optional& protobufMessage); void doPruneTo(unsigned int maxSize=250000); uint64_t doDump(int fd); int doWipePacketCache(const DNSName& name, uint16_t qtype=0xffff, bool subtree=false); @@ -86,6 +88,7 @@ private: #endif uint32_t d_qhash; uint32_t d_tag; + vState d_vstate; inline bool operator<(const struct Entry& rhs) const; time_t getTTD() const @@ -105,7 +108,7 @@ private: packetCache_t d_packetCache; - bool checkResponseMatches(std::pair::type::iterator, packetCache_t::index::type::iterator> range, const std::string& queryPacket, const DNSName& qname, uint16_t qtype, uint16_t qclass, time_t now, std::string* responsePacket, uint32_t* age, RecProtoBufMessage* protobufMessage); + bool checkResponseMatches(std::pair::type::iterator, packetCache_t::index::type::iterator> range, const ComboAddress& source, const std::string& queryPacket, const DNSName& qname, uint16_t qtype, uint16_t qclass, time_t now, std::string* responsePacket, uint32_t* age, RecProtoBufMessage* protobufMessage); public: void preRemoval(const Entry& entry) diff --git a/pdns/test-recpacketcache_cc.cc b/pdns/test-recpacketcache_cc.cc index 5b1c084633..b8e1e490f3 100644 --- a/pdns/test-recpacketcache_cc.cc +++ b/pdns/test-recpacketcache_cc.cc @@ -10,8 +10,11 @@ #include "dns_random.hh" #include "iputils.hh" #include "recpacketcache.hh" +#include "syncres.hh" #include +thread_local std::unique_ptr t_bogusremotes; +thread_local std::unique_ptr > > t_bogusqueryring; BOOST_AUTO_TEST_SUITE(recpacketcache_cc)