]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
dnsdist: Add labels count to StatNode, only set the name once 5353/head
authorRemi Gacogne <remi.gacogne@powerdns.com>
Mon, 29 May 2017 16:16:10 +0000 (18:16 +0200)
committerRemi Gacogne <remi.gacogne@powerdns.com>
Mon, 29 May 2017 16:16:10 +0000 (18:16 +0200)
pdns/dnsdist-lua2.cc
pdns/statnode.cc
pdns/statnode.hh

index 2a98618c5b2ba8200f7d5eff00e8a63929f12e4d..738dc686f376d7fb516b63c1cf360f35b082b310 100644 (file)
@@ -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);
index f33e6f8d9077b2840bd94d9be73eb543dfa3f154..7a6959dd3a2b70a1916a232664a484dc49a2de6a 100644 (file)
@@ -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<<string(depth, ' ');
@@ -31,7 +31,7 @@ StatNode::Stat StatNode::print(int depth, Stat newstat, bool silent) const
 }
 
 
-void  StatNode::visit(visitor_t visitor, Stat &newstat, int depth) const
+void  StatNode::visit(visitor_t visitor, Stat &newstat, unsigned int depth) const
 {
   Stat childstat;
   childstat.queries += s.queries;
@@ -65,7 +65,7 @@ void StatNode::submit(const DNSName& domain, int rcode, const ComboAddress& remo
   for(auto const i : tmp) {
     parts.push_back(i);
   }
-  children[parts.back()].submit(parts, "", rcode, remote);
+  children[parts.back()].submit(parts, "", rcode, remote, 1);
 }
 
 /* www.powerdns.com. -> 
@@ -75,7 +75,7 @@ void StatNode::submit(const DNSName& domain, int rcode, const ComboAddress& remo
    www.powerdns.com. 
 */
 
-void StatNode::submit(deque<string>& labels, const std::string& domain, int rcode, const ComboAddress& remote)
+void StatNode::submit(deque<string>& 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<string>& labels, const std::string& domain, int rcod
     ; //    cerr<<"Short name was already set to '"<<name<<"'"<<endl;
 
   if(labels.size()==1) {
-    fullname=name+"."+domain;
+    if (fullname.empty()) {
+      fullname=name+"."+domain;
+      labelsCount = count;
+    }
     //    cerr<<"Hit the end, set our fullname to '"<<fullname<<"'"<<endl<<endl;
     s.queries++;
     if(rcode<0)
@@ -106,10 +109,13 @@ void StatNode::submit(deque<string>& 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 '"<<fullname<<"', recursing"<<endl;
     labels.pop_back();
-    children[labels.back()].submit(labels, fullname, rcode, remote);
+    children[labels.back()].submit(labels, fullname, rcode, remote, count+1);
   }
 }
 
index 108a9d00d7004cb654c8e86bc509158d1729a912..26759fd2ce0ceee650b189897850c3049ab13f26 100644 (file)
 class StatNode
 {
 public:
-  void submit(const DNSName& domain, int rcode, const ComboAddress& remote);
-  void submit(std::deque<std::string>& 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<ComboAddress,int,ComboAddress::addressOnlyLessThan> remotes_t;
+    typedef std::map<ComboAddress,int,ComboAddress::addressOnlyLessThan> 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<std::string>& 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<void(const StatNode*, const Stat& selfstat, const Stat& childstat)> 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<std::string,StatNode, CIStringCompare> children_t;
   children_t children;