From 09645ebbda4c20937055edd481c8f5394ea2297f Mon Sep 17 00:00:00 2001 From: bert hubert Date: Wed, 2 Mar 2016 13:01:30 +0100 Subject: [PATCH] teach recursor packet cache to dump itself too for dump-cache --- pdns/recpacketcache.cc | 25 +++++++++++++++++++++++++ pdns/recpacketcache.hh | 1 + 2 files changed, 26 insertions(+) diff --git a/pdns/recpacketcache.cc b/pdns/recpacketcache.cc index 9478af2c6..68a4f3640 100644 --- a/pdns/recpacketcache.cc +++ b/pdns/recpacketcache.cc @@ -6,6 +6,7 @@ #include "recpacketcache.hh" #include "cachecleaner.hh" #include "dns.hh" +#include "dnsparser.hh" #include "namespaces.hh" #include "lock.hh" #include "dnswriter.hh" @@ -165,3 +166,27 @@ void RecursorPacketCache::doPruneTo(unsigned int maxCached) pruneCollection(d_packetCache, maxCached); } +uint64_t RecursorPacketCache::doDump(int fd) +{ + FILE* fp=fdopen(dup(fd), "w"); + if(!fp) { // dup probably failed + return 0; + } + fprintf(fp, "; main packet cache dump from thread follows\n;\n"); + const auto& sidx=d_packetCache.get<1>(); + + uint64_t count=0; + time_t now=time(0); + for(auto i=sidx.cbegin(); i != sidx.cend(); ++i) { + count++; + try { + fprintf(fp, "%s %d %s ; tag %d\n", i->d_name.toString().c_str(), (int32_t)(i->d_ttd - now), DNSRecordContent::NumberToType(i->d_type).c_str(), i->d_tag); + } + catch(...) { + fprintf(fp, "; error printing '%s'\n", i->d_name.empty() ? "EMPTY" : i->d_name.toString().c_str()); + } + } + fclose(fp); + return count; + +} diff --git a/pdns/recpacketcache.hh b/pdns/recpacketcache.hh index 0d6c1fb34..8cf7dd2d2 100644 --- a/pdns/recpacketcache.hh +++ b/pdns/recpacketcache.hh @@ -27,6 +27,7 @@ public: bool getResponsePacket(unsigned int tag, const std::string& queryPacket, time_t now, std::string* responsePacket, uint32_t* age); void insertResponsePacket(unsigned int tag, const DNSName& qname, uint16_t qtype, const std::string& queryPacket, const std::string& responsePacket, time_t now, uint32_t ttd); void doPruneTo(unsigned int maxSize=250000); + uint64_t doDump(int fd); int doWipePacketCache(const DNSName& name, uint16_t qtype=0xffff, bool subtree=false); void prune(); -- 2.49.0