]> granicus.if.org Git - pdns/commitdiff
improve statistics with names of rcodes & don't measure rcodes of questions!
authorbert hubert <bert.hubert@netherlabs.nl>
Tue, 18 Mar 2014 11:46:27 +0000 (12:46 +0100)
committerbert hubert <bert.hubert@netherlabs.nl>
Tue, 18 Mar 2014 11:46:27 +0000 (12:46 +0100)
pdns/Makefile.am
pdns/dnsscope.cc

index 92a79c9c98229137ef4b32370c758093a9387d20..7db34f728c4cb11f82fa37e35de3b42ac7da1206 100644 (file)
@@ -253,7 +253,7 @@ notify_LDADD= $(BOOST_PROGRAM_OPTIONS_LIBS)
 dnsscope_SOURCES=dnsscope.cc misc.cc unix_utility.cc qtype.cc \
        logger.cc statbag.cc  dnspcap.cc dnspcap.hh dnsparser.cc dnsrecords.cc \
        base64.cc base64.hh dnswriter.cc dnslabeltext.cc dnswriter.hh rcpgenerator.cc rcpgenerator.hh \
-       utility.hh dnsparser.hh sillyrecords.cc nsecrecords.cc base32.cc
+       utility.hh dnsparser.hh sillyrecords.cc nsecrecords.cc base32.cc dns.cc arguments.cc
 
 dnsscope_LDFLAGS= @DYNLINKFLAGS@ @THREADFLAGS@ $(BOOST_PROGRAM_OPTIONS_LDFLAGS) 
 dnsscope_LDADD = $(BOOST_PROGRAM_OPTIONS_LIBS) 
index 8680cf8b62198eb0a361398da59403ad112e12ea..d3389e430c40c71fa1c991cced536f6f1ea6b790 100644 (file)
 #include <boost/program_options.hpp>
 #include <boost/foreach.hpp>
 #include <boost/logic/tribool.hpp>
+#include "arguments.hh"
 #include "namespaces.hh"
 
 namespace po = boost::program_options;
 po::variables_map g_vm;
 
+ArgvMap& arg()
+{      
+  static ArgvMap theArg;
+  return theArg;
+}
 StatBag S;
 
 struct QuestionData
@@ -68,6 +74,14 @@ struct LiveCounts
   }
 };
 
+struct comboCompare
+{
+  bool operator()(const ComboAddress& a, const ComboAddress& b) const
+  {
+    return ntohl(a.sin4.sin_addr.s_addr) < ntohl(b.sin4.sin_addr.s_addr);
+  }
+};
+
 int main(int argc, char** argv)
 try
 {
@@ -134,6 +148,7 @@ try
   time_t lowestTime=2000000000, highestTime=0;
   time_t lastsec=0;
   LiveCounts lastcounts;
+  set<ComboAddress, comboCompare> requestors, recipients, rdnonra;
   typedef vector<pair<time_t, LiveCounts> > pcounts_t;
   pcounts_t pcounts;
   while(pr.getUDPPacket()) {
@@ -186,17 +201,29 @@ try
             nonRDQueries++;
           queries++;
 
+         ComboAddress rem = pr.getSource();
+         rem.sin4.sin_port=0;
+         requestors.insert(rem);         
+
           QuestionData& qd=statmap[qi];
           
           if(!qd.d_firstquestiontime.tv_sec)
             qd.d_firstquestiontime=pr.d_pheader.ts;
           qd.d_qcount++;
         }
-        else  {  // NO ERROR or NXDOMAIN
+        else  {  // answer
+          rcodes[mdp.d_header.rcode]++;
+          answers++;
          if(mdp.d_header.rd && !mdp.d_header.ra) {
            rdNonRAAnswers++;
+            rdnonra.insert(pr.getDest());
+         }
+         
+         if(mdp.d_header.ra) {
+           ComboAddress rem = pr.getDest();
+           rem.sin4.sin_port=0;
+           recipients.insert(rem);       
          }
-         answers++;
 
           QuestionData& qd=statmap[qi];
 
@@ -222,7 +249,7 @@ try
             statmap.erase(qi);
          }
 
-        rcodes[mdp.d_header.rcode]++;
+        
       }
       catch(MOADNSException& mde) {
         if(verbose)
@@ -249,6 +276,7 @@ try
     pr.d_nonetheripudp<<" unknown encaps, "<<dnserrors<<" dns decoding errors, "<<bogus<<" bogus packets"<<endl;
   cout<<"Ignored fragment packets: "<<fragmented<<endl;
   cout<<"DNS IPv4: "<<ipv4Packets<<" packets, IPv6: "<<ipv6Packets<<" packets"<<endl;
+  cout<<"Questions: "<<queries<<", answers: "<<answers<<endl;
   unsigned int unanswered=0;
 
 
@@ -264,20 +292,13 @@ try
   cout<< rdNonRAAnswers << " answers had recursion desired bit set, but recursion available=0"<<endl;
   cout<<statmap.size()<<" queries went unanswered, of which "<< statmap.size()-unanswered<<" were answered on exact retransmit"<<endl;
   cout<<untracked<<" responses could not be matched to questions"<<endl;
-  cout<<dnserrors<<" responses were unsatisfactory (indefinite, or SERVFAIL)"<<endl;
   cout<<reallylate<<" responses (would be) discarded because older than 2 seconds"<<endl;
-#if 0
-        ns_r_noerror = 0,       /* No error occurred. */
-        ns_r_formerr = 1,       /* Format error. */
-        ns_r_servfail = 2,      /* Server failure. */
-        ns_r_nxdomain = 3,      /* Name error. */
-        ns_r_notimpl = 4,       /* Unimplemented. */
-        ns_r_refused = 5,       /* Operation refused. */
-#endif
-
-  cout<<"Rcode\tCount\n";
-  for(rcodes_t::const_iterator i=rcodes.begin(); i!=rcodes.end(); ++i)
-    cout<<i->first<<"\t"<<i->second<<endl;
+
+  if(answers) {
+    cout<<(boost::format("%1% %|25t|%2%") % "Rcode" % "Count\n");
+    for(rcodes_t::const_iterator i=rcodes.begin(); i!=rcodes.end(); ++i)
+      cout<<(boost::format("%s %|25t|%d %|35t|(%.1f%%)") % RCode::to_s(i->first) % i->second % (i->second*100.0/answers))<<endl;
+  }
 
   uint32_t sum=0;
   //  ofstream stats("stats");
@@ -340,6 +361,26 @@ try
       load<<val.first<<'\t'<<val.second.questions<<'\t'<<val.second.answers<<'\t'<<val.second.outstanding<<'\n';  
     }
   }
+
+
+  cout<<"Saw questions from "<<requestors.size()<<" distinct remotes, answers to "<<recipients.size()<<endl;
+  ofstream remotes("remotes");
+  BOOST_FOREACH(const ComboAddress& rem, requestors) {
+    remotes<<rem.toString()<<'\n';
+  }
+
+  vector<ComboAddress> diff;
+  set_difference(requestors.begin(), requestors.end(), recipients.begin(), recipients.end(), back_inserter(diff), comboCompare());
+  cout<<"Saw "<<diff.size()<<" remotes ("<<rdnonra.size()<< " distinct) asking questions, but not getting RA answers"<<endl;
+  
+  ofstream ignored("ignored");
+  BOOST_FOREACH(const ComboAddress& rem, diff) {
+    ignored<<rem.toString()<<'\n';
+  }
+  ofstream rdnonrafs("rdnonra");
+  BOOST_FOREACH(const ComboAddress& rem, rdnonra) {
+    rdnonrafs<<rem.toString()<<'\n';
+  }
   
 }
 catch(std::exception& e)