From effe43d0d074ca7b9aacd31a25a920e92e5fe363 Mon Sep 17 00:00:00 2001 From: Bert Hubert Date: Fri, 9 Nov 2012 20:20:49 +0000 Subject: [PATCH] implement wiping of the packetcache, plus fix rec_control command line parsing. Closes ticket 333, which also contained the relevant (anonymous) code. git-svn-id: svn://svn.powerdns.com/pdns/trunk/pdns@2880 d19b8d6e-7fed-0310-83ef-9ca221ded41b --- pdns/rec_channel_rec.cc | 6 +++--- pdns/rec_control.cc | 2 +- pdns/recpacketcache.cc | 22 ++++++++++++++++++++++ pdns/recpacketcache.hh | 1 + 4 files changed, 27 insertions(+), 4 deletions(-) diff --git a/pdns/rec_channel_rec.cc b/pdns/rec_channel_rec.cc index 12d9cd81c..3970c99e8 100644 --- a/pdns/rec_channel_rec.cc +++ b/pdns/rec_channel_rec.cc @@ -179,7 +179,8 @@ string doDumpEDNSStatus(T begin, T end) uint64_t* pleaseWipeCache(const std::string& canon) { - return new uint64_t(t_RC->doWipeCache(canon)); + // clear packet cache too + return new uint64_t(t_RC->doWipeCache(canon) + t_packetCache->doWipePacketCache(canon)); } @@ -590,8 +591,7 @@ string RecursorControlParser::getAnswer(const string& question, RecursorControlP if(cmd=="dump-ednsstatus" || cmd=="dump-edns") return doDumpEDNSStatus(begin, end); - - if(cmd=="wipe-cache") + if(cmd=="wipe-cache" || cmd=="flushname") return doWipeCache(begin, end); if(cmd=="reload-lua-script") diff --git a/pdns/rec_control.cc b/pdns/rec_control.cc index 003b336c2..6d232c4d2 100644 --- a/pdns/rec_control.cc +++ b/pdns/rec_control.cc @@ -54,13 +54,13 @@ static void initArguments(int argc, char** argv) if(!::arg().preParseFile(configname.c_str(), "socket-dir", LOCALSTATEDIR)) cerr<<"Warning: unable to parse configuration file '"<((*iter).d_packet.c_str()); + if (packet->qdcount > 0) + { + // find out type + const struct dnsrecordheader *header = reinterpret_cast((*iter).d_packet.c_str()+sizeof(struct dnsheader)); + uint16_t type = header->d_type; + std::string domain=questionExpand((*iter).d_packet.c_str(), (*iter).d_packet.size(), type); + if (pdns_iequals(name,domain)) + { + iter = d_packetCache.erase(iter); + count++; + } else iter++; + } + } + return count; +} + bool RecursorPacketCache::getResponsePacket(const std::string& queryPacket, time_t now, std::string* responsePacket, uint32_t* age) { diff --git a/pdns/recpacketcache.hh b/pdns/recpacketcache.hh index 881ff8a28..df33ab850 100644 --- a/pdns/recpacketcache.hh +++ b/pdns/recpacketcache.hh @@ -22,6 +22,7 @@ public: bool getResponsePacket(const std::string& queryPacket, time_t now, std::string* responsePacket, uint32_t* age); void insertResponsePacket(const std::string& responsePacket, time_t now, uint32_t ttd); void doPruneTo(unsigned int maxSize=250000); + int doWipePacketCache(const string& name, uint16_t qtype=0xffff); void prune(); uint64_t d_hits, d_misses; -- 2.40.0