From: bert hubert Date: Thu, 11 Jul 2013 15:05:00 +0000 (+0200) Subject: use IPv6 addresses from dnspcap infrastructure for question/answer tracking in analysis X-Git-Tag: rec-3.6.0-rc1~576 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=8b422c02a5cb07c9ea3a2cdc658ec4d85f4f0a1d;p=thirdparty%2Fpdns.git use IPv6 addresses from dnspcap infrastructure for question/answer tracking in analysis --- diff --git a/pdns/anadns.hh b/pdns/anadns.hh index 4c53effbba..84c1e00b47 100644 --- a/pdns/anadns.hh +++ b/pdns/anadns.hh @@ -6,7 +6,7 @@ #include #include #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<< "'"<>24 & 0xff)<<"."; - s<< (rint>>16 & 0xff)<<"."; - s<< (rint>>8 & 0xff)<<"."; - s<< (rint & 0xff); - s<<":"<>24 & 0xff)<<"."; - s<< (rint>>16 & 0xff)<<"."; - s<< (rint>>8 & 0xff)<<"."; - s<< (rint & 0xff); - return s<<":"<