]> granicus.if.org Git - pdns/commitdiff
use IPv6 addresses from dnspcap infrastructure for question/answer tracking in analysis
authorbert hubert <bert.hubert@netherlabs.nl>
Thu, 11 Jul 2013 15:05:00 +0000 (17:05 +0200)
committerbert hubert <bert.hubert@netherlabs.nl>
Thu, 11 Jul 2013 15:05:00 +0000 (17:05 +0200)
pdns/anadns.hh

index 4c53effbbab10a4264c58cb77be9f8f91e476ec5..84c1e00b474883f4ed820148c296252616e0259d 100644 (file)
@@ -6,7 +6,7 @@
 #include <netinet/ip.h>
 #include <netinet/udp.h>
 #include "dnsparser.hh"
-
+#include "iputils.hh"
 #include "namespaces.hh"
 #include "namespaces.hh"
 
@@ -18,33 +18,39 @@ struct QuestionIdentifier
   bool operator<(const QuestionIdentifier& rhs) const
   {
     return 
-      tie(d_sourceip, d_destip, d_sourceport, d_destport, d_qname, d_qtype, d_id) < 
-      tie(rhs.d_sourceip, rhs.d_destip, rhs.d_sourceport, rhs.d_destport, rhs.d_qname, rhs.d_qtype, rhs.d_id);
+      tie(d_source, d_dest, d_qname, d_qtype, d_id) < 
+      tie(rhs.d_source, rhs.d_dest, rhs.d_qname, rhs.d_qtype, rhs.d_id);
   }
 
   // the canonical direction is that of the question
   static QuestionIdentifier create(const struct ip* ip, const struct udphdr* udp, const MOADNSParser& mdp)
   {
     QuestionIdentifier ret;
+    struct ip6_hdr* ip6 = (struct ip6_hdr*)ip;
     if(mdp.d_header.qr) {
-      memcpy(&ret.d_sourceip, &ip->ip_dst, sizeof(ret.d_sourceip));
-      ret.d_sourceip=htonl(ret.d_sourceip);
-
-      memcpy(&ret.d_destip, &ip->ip_src, sizeof(ret.d_destip));
-      ret.d_destip=htonl(ret.d_destip);
-
-      ret.d_sourceport=htons(udp->uh_dport);
-      ret.d_destport=htons(udp->uh_sport);
+      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;
     }
     else {
-      memcpy(&ret.d_sourceip, &ip->ip_src, sizeof(ret.d_sourceip));
-      ret.d_sourceip=htonl(ret.d_sourceip);
+      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;
 
-      memcpy(&ret.d_destip, &ip->ip_dst, sizeof(ret.d_destip));
-      ret.d_destip=htonl(ret.d_destip);
-
-      ret.d_sourceport=htons(udp->uh_sport);
-      ret.d_destport=htons(udp->uh_dport);
     }
     ret.d_qname=mdp.d_qname;
     ret.d_qtype=mdp.d_qtype;
@@ -52,10 +58,7 @@ struct QuestionIdentifier
     return ret;
   }
 
-  uint32_t d_sourceip;
-  uint32_t d_destip;
-  uint16_t d_sourceport;
-  uint16_t d_destport;
+  ComboAddress d_source, d_dest;
 
   string d_qname;
   uint16_t d_qtype;
@@ -64,22 +67,10 @@ struct QuestionIdentifier
 
 inline ostream& operator<<(ostream &s, const QuestionIdentifier& qi) 
 {
-  s<< "'"<<qi.d_qname<<"|"<<DNSRecordContent::NumberToType(qi.d_qtype)<<"', with id " << qi.d_id <<" from ";
-  uint32_t rint=qi.d_sourceip;
-
-  s<< (rint>>24 & 0xff)<<".";
-  s<< (rint>>16 & 0xff)<<".";
-  s<< (rint>>8  & 0xff)<<".";
-  s<< (rint     & 0xff);
-  s<<":"<<qi.d_sourceport;
+  s<< "'"<<qi.d_qname<<"|"<<DNSRecordContent::NumberToType(qi.d_qtype)<<"', with id " << qi.d_id <<" from "<<qi.d_source.toStringWithPort();
   
-  s<<" to ";
-  rint=qi.d_destip;
-  s<< (rint>>24 & 0xff)<<".";
-  s<< (rint>>16 & 0xff)<<".";
-  s<< (rint>>8  & 0xff)<<".";
-  s<< (rint     & 0xff);
-  return s<<":"<<qi.d_destport;
+  s<<" to " << qi.d_dest.toStringWithPort();
+  return s;
 }