From: Remi Gacogne Date: Mon, 29 May 2017 16:16:10 +0000 (+0200) Subject: dnsdist: Add labels count to StatNode, only set the name once X-Git-Tag: rec-4.1.0-alpha1~25^2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=431c43598fd7f17cf70b44383c7045c5c091bdf4;p=thirdparty%2Fpdns.git dnsdist: Add labels count to StatNode, only set the name once --- diff --git a/pdns/dnsdist-lua2.cc b/pdns/dnsdist-lua2.cc index 2a98618c5b..738dc686f3 100644 --- a/pdns/dnsdist-lua2.cc +++ b/pdns/dnsdist-lua2.cc @@ -372,6 +372,7 @@ void moreLua(bool client) } ); g_lua.registerMember("fullname", &StatNode::fullname); + g_lua.registerMember("labelsCount", &StatNode::labelsCount); g_lua.registerMember("servfails", &StatNode::Stat::servfails); g_lua.registerMember("nxdomains", &StatNode::Stat::nxdomains); g_lua.registerMember("queries", &StatNode::Stat::queries); diff --git a/pdns/statnode.cc b/pdns/statnode.cc index f33e6f8d90..7a6959dd3a 100644 --- a/pdns/statnode.cc +++ b/pdns/statnode.cc @@ -1,6 +1,6 @@ #include "statnode.hh" -StatNode::Stat StatNode::print(int depth, Stat newstat, bool silent) const +StatNode::Stat StatNode::print(unsigned int depth, Stat newstat, bool silent) const { if(!silent) { cout< @@ -75,7 +75,7 @@ void StatNode::submit(const DNSName& domain, int rcode, const ComboAddress& remo www.powerdns.com. */ -void StatNode::submit(deque& labels, const std::string& domain, int rcode, const ComboAddress& remote) +void StatNode::submit(deque& labels, const std::string& domain, int rcode, const ComboAddress& remote, unsigned int count) { if(labels.empty()) return; @@ -92,7 +92,10 @@ void StatNode::submit(deque& labels, const std::string& domain, int rcod ; // cerr<<"Short name was already set to '"<& labels, const std::string& domain, int rcod s.remotes[remote]++; } else { - fullname=name+"."+domain; + if (fullname.empty()) { + fullname=name+"."+domain; + labelsCount = count; + } // cerr<<"Not yet end, set our fullname to '"<& labels, const std::string& domain, int rcode, const ComboAddress& remote); - std::string name; - std::string fullname; struct Stat { Stat() : queries(0), noerrors(0), nxdomains(0), servfails(0), drops(0){} @@ -50,14 +46,21 @@ public: } return *this; } -typedef std::map remotes_t; + typedef std::map remotes_t; remotes_t remotes; }; Stat s; - Stat print(int depth=0, Stat newstat=Stat(), bool silent=false) const; + std::string name; + std::string fullname; + unsigned int labelsCount{0}; + + void submit(const DNSName& domain, int rcode, const ComboAddress& remote); + void submit(std::deque& labels, const std::string& domain, int rcode, const ComboAddress& remote, unsigned int count); + + Stat print(unsigned int depth=0, Stat newstat=Stat(), bool silent=false) const; typedef boost::function visitor_t; - void visit(visitor_t visitor, Stat& newstat, int depth=0) const; + void visit(visitor_t visitor, Stat& newstat, unsigned int depth=0) const; typedef std::map children_t; children_t children;