From e8a0aa00acf1bf6f6122fbdd8c913ac5bf6c023a Mon Sep 17 00:00:00 2001 From: Otto Moerbeek Date: Tue, 19 Nov 2019 10:49:49 +0000 Subject: [PATCH] Fix merge errors --- pdns/rec_channel_rec.cc | 3 +++ pdns/syncres.cc | 21 +++++++++++++++++++++ pdns/syncres.hh | 17 +++++++++++------ 3 files changed, 35 insertions(+), 6 deletions(-) diff --git a/pdns/rec_channel_rec.cc b/pdns/rec_channel_rec.cc index 2e1e7aa14e..ca6180f14e 100644 --- a/pdns/rec_channel_rec.cc +++ b/pdns/rec_channel_rec.cc @@ -1433,6 +1433,9 @@ string RecursorControlParser::getAnswer(const string& question, RecursorControlP if(cmd=="dump-failedservers") return doDumpFailedServers(begin, end); + if(cmd=="dump-throttlemap") + return doDumpThrottleMap(begin, end); + if(cmd=="dump-rpz") { return doDumpRPZ(begin, end); } diff --git a/pdns/syncres.cc b/pdns/syncres.cc index 402b9db812..c62099ba45 100644 --- a/pdns/syncres.cc +++ b/pdns/syncres.cc @@ -397,6 +397,27 @@ uint64_t SyncRes::doDumpNSSpeeds(int fd) return count; } +uint64_t SyncRes::doDumpThrottleMap(int fd) +{ + auto fp = std::unique_ptr(fdopen(dup(fd), "w"), fclose); + if(!fp) + return 0; + fprintf(fp.get(), "; throttle map dump follows\n"); + fprintf(fp.get(), "; remote IP\tqname\tqtype\tcount\tttd\n"); + uint64_t count=0; + + const auto& throttleMap = t_sstorage.throttle.getThrottleMap(); + for(const auto& i : throttleMap) + { + count++; + char tmp[26]; + // remote IP, dns name, qtype, count, ttd + fprintf(fp.get(), "%s\t%s\t%d\t%u\t%s", i.first.get<0>().toString().c_str(), i.first.get<1>().toLogString().c_str(), i.first.get<2>(), i.second.count, ctime_r(&i.second.ttd, tmp)); + } + + return count; +} + uint64_t SyncRes::doDumpFailedServers(int fd) { auto fp = std::unique_ptr(fdopen(dup(fd), "w"), fclose); diff --git a/pdns/syncres.hh b/pdns/syncres.hh index 6fd3d67da0..29eed21913 100644 --- a/pdns/syncres.hh +++ b/pdns/syncres.hh @@ -73,6 +73,12 @@ typedef map< template class Throttle : public boost::noncopyable { public: + struct entry + { + time_t ttd; + unsigned int count; + }; + typedef map cont_t; Throttle() { d_limit=3; @@ -121,6 +127,11 @@ public: return (unsigned int)d_cont.size(); } + const cont_t& getThrottleMap() const + { + return d_cont; + } + void clear() { d_cont.clear(); @@ -129,12 +140,6 @@ private: unsigned int d_limit; time_t d_ttl; time_t d_last_clean; - struct entry - { - time_t ttd; - unsigned int count; - }; - typedef map cont_t; cont_t d_cont; }; -- 2.47.2