]> granicus.if.org Git - pdns/commitdiff
add responsestats infra, not actually reporting yet
authorbert hubert <bert.hubert@netherlabs.nl>
Thu, 8 Aug 2013 09:47:20 +0000 (11:47 +0200)
committerPeter van Dijk <peter.van.dijk@netherlabs.nl>
Thu, 8 Aug 2013 14:36:40 +0000 (16:36 +0200)
pdns/Makefile.am
pdns/nameserver.cc
pdns/responsestats.cc [new file with mode: 0644]
pdns/responsestats.hh [new file with mode: 0644]

index 22204501c7e8c3c4200830154fdd3b32a652bfa0..254b87f34987628c574c76d1f71150a8c45ce739 100644 (file)
@@ -60,7 +60,7 @@ randomhelper.cc namespaces.hh nsecrecords.cc base32.cc dbdnsseckeeper.cc dnsseci
 dnsseckeeper.hh dnssecinfra.hh base32.hh dns.cc dnssecsigner.cc polarrsakeyinfra.cc \
 md5.hh signingpipe.cc signingpipe.hh dnslabeltext.cc lua-pdns.cc lua-auth.cc lua-auth.hh serialtweaker.cc \
 ednssubnet.cc ednssubnet.hh cachecleaner.hh json.cc json.hh \
-version.hh version.cc rfc2136handler.cc
+version.hh version.cc rfc2136handler.cc responsestats.cc responsestats.hh
 
 #
 pdns_server_LDFLAGS=@moduleobjects@ @modulelibs@ @DYNLINKFLAGS@ @LIBDL@ @THREADFLAGS@  $(BOOST_SERIALIZATION_LDFLAGS) -rdynamic
@@ -158,7 +158,10 @@ nsec3dig_LDADD= $(POLARSSL_LIBS)
 toysdig_SOURCES=toysdig.cc sstuff.hh dnsparser.cc dnsparser.hh dnsrecords.cc dnswriter.cc dnslabeltext.cc dnswriter.hh \
        misc.cc misc.hh rcpgenerator.cc rcpgenerator.hh base64.cc base64.hh unix_utility.cc \
        logger.cc statbag.cc qtype.cc sillyrecords.cc nsecrecords.cc base32.cc \
-       ednssubnet.cc ednssubnet.hh
+       ednssubnet.cc ednssubnet.hh aes/aescpp.h \
+       aes/aescrypt.c aes/aes.h aes/aeskey.c aes/aes_modes.c aes/aesopt.h \
+       aes/aestab.c aes/aestab.h aes/brg_endian.h aes/brg_types.h aes/dns_random.cc \
+       randomhelper.cc 
 
 
 #tcptorture_SOURCES=tcptorture.cc sstuff.hh dnsparser.cc dnsparser.hh dnsrecords.cc dnswriter.cc dnslabeltext.cc dnswriter.hh \
index d3268114e723ed1c3d41fc56bc55891e583fd59f..e7d32a27b9a4396770f6b24ad4ab8c75d77a6336 100644 (file)
@@ -23,6 +23,7 @@
 #include <iostream>
 #include <string>
 #include <sys/types.h>
+#include "responsestats.hh"
 #include <boost/shared_ptr.hpp>
 #include "dns.hh"
 #include "dnsbackend.hh"
@@ -235,10 +236,15 @@ UDPNameserver::UDPNameserver()
   if(::arg()["local-address"].empty() && ::arg()["local-ipv6"].empty()) 
     L<<Logger::Critical<<"PDNS is deaf and mute! Not listening on any interfaces"<<endl;    
 }
+
+ResponseStats g_rs;
+
 void UDPNameserver::send(DNSPacket *p)
 {
   const string& buffer=p->getString();
   
+  g_rs.submitResponse(p->qtype.getCode(), buffer.length(), true);
+
   struct msghdr msgh;
   struct cmsghdr *cmsg;
   struct iovec iov;
@@ -313,7 +319,7 @@ void UDPNameserver::send(DNSPacket *p)
   }
   DLOG(L<<Logger::Notice<<"Sending a packet to "<< p->getRemote() <<" ("<< buffer.length()<<" octets)"<<endl);
   if(buffer.length() > p->getMaxReplyLen()) {
-    cerr<<"Weird, trying to send a message that needs truncation, "<< buffer.length()<<" > "<<p->getMaxReplyLen()<<endl;
+    L<<Logger::Error<<"Weird, trying to send a message that needs truncation, "<< buffer.length()<<" > "<<p->getMaxReplyLen()<<endl;
   }
   if(sendmsg(p->getSocket(), &msgh, 0) < 0)
     L<<Logger::Error<<"Error sending reply with sendmsg (socket="<<p->getSocket()<<"): "<<strerror(errno)<<endl;
diff --git a/pdns/responsestats.cc b/pdns/responsestats.cc
new file mode 100644 (file)
index 0000000..a46926e
--- /dev/null
@@ -0,0 +1,44 @@
+#include "responsestats.hh"
+#include <limits>
+#include "namespaces.hh"
+
+ResponseStats::ResponseStats()
+{
+  d_qtypecounters.resize(std::numeric_limits<uint16_t>::max());
+  d_sizecounters.push_back(make_pair(20,0));
+  d_sizecounters.push_back(make_pair(40,0));
+  d_sizecounters.push_back(make_pair(60,0));
+  d_sizecounters.push_back(make_pair(80,0));
+  d_sizecounters.push_back(make_pair(100,0));
+  d_sizecounters.push_back(make_pair(150,0));
+  for(int n=200; n < 65000 ; n+=200)
+    d_sizecounters.push_back(make_pair(n,0));
+  d_sizecounters.push_back(make_pair(std::numeric_limits<uint16_t>::max(),0));
+}
+
+static bool pcomp(const pair<uint16_t, uint64_t>&a , const pair<uint16_t, uint64_t>&b)
+{
+  return a.first < b.first;
+} 
+
+void ResponseStats::submitResponse(uint16_t qtype, uint16_t respsize, bool udpOrTCP) 
+{
+  d_qtypecounters[qtype]++;
+  pair<uint16_t, uint64_t> s(respsize, 0);
+  sizecounters_t::iterator iter = std::upper_bound(d_sizecounters.begin(), d_sizecounters.end(), s, pcomp);
+  if(iter!= d_sizecounters.begin())
+    --iter;
+  iter->second++;
+}
+
+map<uint16_t, uint64_t> ResponseStats::getQTypeResponseCounts()
+{
+  map<uint16_t, uint64_t> ret;
+  uint64_t count;
+  for(int i = 0 ; i < d_qtypecounters.size() ; ++i) {
+    count= d_qtypecounters[i];
+    if(count)
+      ret[i]=count;
+  }
+  return ret;
+}
diff --git a/pdns/responsestats.hh b/pdns/responsestats.hh
new file mode 100644 (file)
index 0000000..e2d768a
--- /dev/null
@@ -0,0 +1,20 @@
+#ifndef PDNS_RESPONSESTATS_HH
+#define PDNS_RESPONSESTATS_HH
+#include "misc.hh"
+
+class ResponseStats
+{
+public:
+  ResponseStats();
+
+  void submitResponse(uint16_t qtype, uint16_t respsize, bool udpOrTCP);
+  map<uint16_t, uint64_t> getQTypeResponseCounts();
+  map<uint16_t, uint64_t> getSizeResponseCounts();
+
+private:
+  vector<AtomicCounter> d_qtypecounters;
+  typedef vector<pair<uint16_t, uint64_t> > sizecounters_t;
+  sizecounters_t d_sizecounters;
+};
+
+#endif