]> granicus.if.org Git - pdns/commitdiff
teach recursor packet cache to dump itself too for dump-cache
authorbert hubert <bert.hubert@netherlabs.nl>
Wed, 2 Mar 2016 12:01:30 +0000 (13:01 +0100)
committerbert hubert <bert.hubert@netherlabs.nl>
Wed, 2 Mar 2016 12:01:30 +0000 (13:01 +0100)
pdns/recpacketcache.cc
pdns/recpacketcache.hh

index 9478af2c64c803a5dc274017b90bf951af39043c..68a4f3640dc4ea2085f429550b6140d1563f1197 100644 (file)
@@ -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;
+
+}
index 0d6c1fb34b491b36e38d05b8f55a2d2f26c420c3..8cf7dd2d2518ca6f6a470ef1d10bb3aa60b3a7ae 100644 (file)
@@ -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();