]> granicus.if.org Git - pdns/commitdiff
teach dnspcap to provide ComboAddresses for src/dst of IPv4 and IPv6 packets, move...
authorbert hubert <bert.hubert@netherlabs.nl>
Thu, 11 Jul 2013 20:05:50 +0000 (22:05 +0200)
committerbert hubert <bert.hubert@netherlabs.nl>
Thu, 11 Jul 2013 20:05:50 +0000 (22:05 +0200)
I don't think dnsreplay is really IPv6 ready though. Might even crash on it right now.

pdns/anadns.hh
pdns/dnspcap.cc
pdns/dnspcap.hh
pdns/dnsreplay.cc
pdns/dnsscope.cc

index 84c1e00b474883f4ed820148c296252616e0259d..a64897345a93a5726ccfd1c803e954e7e6e37026 100644 (file)
@@ -23,34 +23,17 @@ struct QuestionIdentifier
   }
 
   // the canonical direction is that of the question
-  static QuestionIdentifier create(const struct ip* ip, const struct udphdr* udp, const MOADNSParser& mdp)
+  static QuestionIdentifier create(const ComboAddress& src, const ComboAddress& dst, const MOADNSParser& mdp)
   {
     QuestionIdentifier ret;
-    struct ip6_hdr* ip6 = (struct ip6_hdr*)ip;
+
     if(mdp.d_header.qr) {
-      if(ip->ip_v!=6) {
-       ret.d_source.sin4.sin_addr  = ip->ip_dst;
-       ret.d_dest.sin4.sin_addr = ip->ip_src;
-      }
-      else {
-       ret.d_source.sin6.sin6_addr = ip6->ip6_dst;
-       ret.d_dest.sin6.sin6_addr = ip6->ip6_src;
-      }
-      ret.d_dest.sin4.sin_port = udp->uh_sport;
-      ret.d_source.sin4.sin_port = udp->uh_dport;
+      ret.d_source = dst;
+      ret.d_dest = src;
     }
     else {
-      if(ip->ip_v != 6) {
-       ret.d_source.sin4.sin_addr  = ip->ip_src;
-       ret.d_dest.sin4.sin_addr = ip->ip_dst;
-      }
-      else {
-       ret.d_source.sin6.sin6_addr = ip6->ip6_src;
-       ret.d_dest.sin6.sin6_addr = ip6->ip6_dst;
-      }
-      ret.d_source.sin4.sin_port = udp->uh_sport;
-      ret.d_dest.sin4.sin_port = udp->uh_dport;
-
+      ret.d_source = src;
+      ret.d_dest = dst;
     }
     ret.d_qname=mdp.d_qname;
     ret.d_qtype=mdp.d_qtype;
index dde33327a418dabafb5e3bbb6fff13e56d55d8e2..c5effcc53838f09a173261980d7ff6d3a3be9429 100644 (file)
@@ -102,6 +102,36 @@ catch(EofException) {
   return false;
 }
 
+ComboAddress PcapPacketReader::getSource() const
+{
+  ComboAddress ret;
+  if(d_ip->ip_v == 4) {
+    ret.sin4.sin_family = AF_INET;
+    ret.sin4.sin_addr = d_ip->ip_src;
+    ret.sin4.sin_port = d_udp->uh_sport; // should deal with TCP too!
+  } else {
+    ret.sin6.sin6_family = AF_INET6;
+    ret.sin6.sin6_addr = d_ip6->ip6_src;
+    ret.sin6.sin6_port = d_udp->uh_sport; // should deal with TCP too!
+  }
+  return ret;
+}
+
+ComboAddress PcapPacketReader::getDest() const
+{
+  ComboAddress ret;
+  if(d_ip->ip_v == 4) {
+    ret.sin4.sin_family = AF_INET;
+    ret.sin4.sin_addr = d_ip->ip_dst;
+    ret.sin4.sin_port = d_udp->uh_dport; // should deal with TCP too!
+  } else {
+    ret.sin6.sin6_family = AF_INET6;
+    ret.sin6.sin6_addr = d_ip6->ip6_dst;
+    ret.sin6.sin6_port = d_udp->uh_dport; // should deal with TCP too!
+  }
+  return ret;
+}
+
 
 PcapPacketWriter::PcapPacketWriter(const string& fname, PcapPacketReader& ppr) : d_fname(fname), d_ppr(ppr)
 {
index b1813276196430bf441ff2762f0f35b81bef57c4..1abc40c5a8c9247529bd27d05d600b9b927d182a 100644 (file)
@@ -3,6 +3,7 @@
 
 #include <cstdio>
 #include <stdexcept>
+#include "iputils.hh"
 #include <string>
 #include "misc.hh"
 #include <iostream>
@@ -82,6 +83,10 @@ public:
 
   bool getUDPPacket();
 
+
+  ComboAddress getSource() const;
+  ComboAddress getDest() const;
+
   struct pdns_lcc_header* d_lcc;
   struct ether_header* d_ether;
   struct ip *d_ip;
index a77a7a0ff838711c1c1b2d81758fa731c6978de0..805ca1ae9f43ec2dce7db8b88b502da7cb73631e 100644 (file)
@@ -495,7 +495,7 @@ bool sendPacketFromPR(PcapPacketReader& pr, const ComboAddress& remote)
       dh->id=tmp;
     }
     MOADNSParser mdp((const char*)pr.d_payload, pr.d_len);
-    QuestionIdentifier qi=QuestionIdentifier::create(pr.d_ip, pr.d_udp, mdp);
+    QuestionIdentifier qi=QuestionIdentifier::create(pr.getSource(), pr.getDest(), mdp);
     
     if(!mdp.d_header.qr) {
       s_questions++;
index a687462de8556b25d0de471591519c936ea3ae78..6e6176915a767c9f2091990dc3429e6608fb35fd 100644 (file)
@@ -49,19 +49,24 @@ try
   typedef map<uint32_t,uint32_t> cumul_t;
   cumul_t cumul;
   unsigned int untracked=0, errorresult=0, reallylate=0, nonRDQueries=0, queries=0;
+  unsigned int ipv4Packets=0, ipv6Packets=0;
 
   typedef map<uint16_t,uint32_t> rcodes_t;
   rcodes_t rcodes;
 
   time_t lowestTime=2000000000, highestTime=0;
 
-
   while(pr.getUDPPacket()) {
     if((ntohs(pr.d_udp->uh_dport)==5300 || ntohs(pr.d_udp->uh_sport)==5300 ||
         ntohs(pr.d_udp->uh_dport)==53   || ntohs(pr.d_udp->uh_sport)==53) &&
         pr.d_len > 12) {
       try {
         MOADNSParser mdp((const char*)pr.d_payload, pr.d_len);
+       if(pr.d_ip->ip_v == 4) 
+         ++ipv4Packets;
+       else
+         ++ipv6Packets;
+       
        if(!mdp.d_header.qr) {
          if(!mdp.d_header.rd)
            nonRDQueries++;
@@ -73,7 +78,7 @@ try
 
         string name=mdp.d_qname+"|"+DNSRecordContent::NumberToType(mdp.d_qtype);
         
-        QuestionIdentifier qi=QuestionIdentifier::create(pr.d_ip, pr.d_udp, mdp);
+        QuestionIdentifier qi=QuestionIdentifier::create(pr.getSource(), pr.getDest(), mdp);
 
         if(!mdp.d_header.qr) {
           //     cout<<"Question for '"<< name <<"'\n";
@@ -127,11 +132,11 @@ try
       }
     }
   }
-  cerr<<"Timespan: "<<(highestTime-lowestTime)/3600.0<<" hours"<<endl;
+  cout<<"Timespan: "<<(highestTime-lowestTime)/3600.0<<" hours"<<endl;
 
-  cerr<<"Saw "<<pr.d_correctpackets<<" correct packets, "<<pr.d_runts<<" runts, "<< pr.d_oversized<<" oversize, "<<
+  cout<<"Saw "<<pr.d_correctpackets<<" correct packets, "<<pr.d_runts<<" runts, "<< pr.d_oversized<<" oversize, "<<
     pr.d_nonetheripudp<<" unknown encaps, "<<dnserrors<<" dns decoding errors, "<<bogus<<" bogus packets"<<endl;
-
+  cout<<"IPv4: "<<ipv4Packets<<" packets, IPv6: "<<ipv6Packets<<" packets"<<endl;
   unsigned int unanswered=0;
   for(statmap_t::const_iterator i=statmap.begin(); i!=statmap.end(); ++i) {
     if(!i->second.d_answercount) {
@@ -140,11 +145,11 @@ try
     }
   }
 
-  cerr<< boost::format("%d (%.02f%% of all) queries did not request recursion") % nonRDQueries % ((nonRDQueries*100.0)/queries) << endl;
-  cerr<<statmap.size()<<" packets went unanswered, of which "<< statmap.size()-unanswered<<" were answered on exact retransmit"<<endl;
-  cerr<<untracked<<" answers could not be matched to questions"<<endl;
-  cerr<<dnserrors<<" answers were unsatisfactory (indefinite, or SERVFAIL)"<<endl;
-  cerr<<reallylate<<" answers (would be) discarded because older than 2 seconds"<<endl;
+  cout<< boost::format("%d (%.02f%% of all) queries did not request recursion") % nonRDQueries % ((nonRDQueries*100.0)/queries) << 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. */
@@ -154,9 +159,9 @@ try
         ns_r_refused = 5,       /* Operation refused. */
 #endif
 
-  cerr<<"Rcode\tCount\n";
+  cout<<"Rcode\tCount\n";
   for(rcodes_t::const_iterator i=rcodes.begin(); i!=rcodes.end(); ++i)
-    cerr<<i->first<<"\t"<<i->second<<endl;
+    cout<<i->first<<"\t"<<i->second<<endl;
 
   uint32_t sum=0;
   ofstream stats("stats");
@@ -214,10 +219,9 @@ try
         lastperc=sum*100.0/totpackets;
       }
   }
-
   
   if(totpackets)
-    cerr<<"Average response time: "<<tottime/totpackets<<" usec"<<endl;
+    cout<<"Average response time: "<<tottime/totpackets<<" usec"<<endl;
 }
 catch(std::exception& e)
 {