From ce9309b78fc13dba9fc14162182d91450c81a031 Mon Sep 17 00:00:00 2001 From: bert hubert Date: Tue, 18 Mar 2014 12:46:27 +0100 Subject: [PATCH] improve statistics with names of rcodes & don't measure rcodes of questions! --- pdns/Makefile.am | 2 +- pdns/dnsscope.cc | 73 +++++++++++++++++++++++++++++++++++++----------- 2 files changed, 58 insertions(+), 17 deletions(-) diff --git a/pdns/Makefile.am b/pdns/Makefile.am index 92a79c9c9..7db34f728 100644 --- a/pdns/Makefile.am +++ b/pdns/Makefile.am @@ -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) diff --git a/pdns/dnsscope.cc b/pdns/dnsscope.cc index 8680cf8b6..d3389e430 100644 --- a/pdns/dnsscope.cc +++ b/pdns/dnsscope.cc @@ -12,11 +12,17 @@ #include #include #include +#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 requestors, recipients, rdnonra; typedef vector > 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, "<first<<"\t"<second<first) % i->second % (i->second*100.0/answers))< diff; + set_difference(requestors.begin(), requestors.end(), recipients.begin(), recipients.end(), back_inserter(diff), comboCompare()); + cout<<"Saw "<