+/*
+ * This file is part of PowerDNS or dnsdist.
+ * Copyright -- PowerDNS.COM B.V. and its contributors
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of version 2 of the GNU General Public License as
+ * published by the Free Software Foundation.
+ *
+ * In addition, for the avoidance of any doubt, permission is granted to
+ * link this program with OpenSSL and to (re)distribute the binaries
+ * produced as the result of such linking.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
#ifndef PDNS_ANADNS_HH
#define PDNS_ANADNS_HH
#include <boost/tuple/tuple.hpp>
#include <netinet/ip.h>
#include <netinet/udp.h>
#include "dnsparser.hh"
-
-using namespace boost;
-using namespace std;
+#include "iputils.hh"
+#include "namespaces.hh"
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_id, d_qtype, d_source, d_dest, d_qname) <
+ tie(rhs.d_id, rhs.d_qtype, rhs.d_source, rhs.d_dest, rhs.d_qname);
}
+
// 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 struct dnsheader& header, const DNSName& qname, uint16_t qtype)
{
QuestionIdentifier ret;
- 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(header.qr) {
+ ret.d_source = dst;
+ ret.d_dest = src;
}
else {
- memcpy(&ret.d_sourceip, &ip->ip_src, sizeof(ret.d_sourceip));
- ret.d_sourceip=htonl(ret.d_sourceip);
-
- 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_source = src;
+ ret.d_dest = dst;
}
- ret.d_qname=mdp.d_qname;
- ret.d_qtype=mdp.d_qtype;
- ret.d_id=mdp.d_header.id;
+ ret.d_qname=qname;
+ ret.d_qtype=qtype;
+ ret.d_id=ntohs(header.id);
return ret;
}
- uint32_t d_sourceip;
- uint32_t d_destip;
- uint16_t d_sourceport;
- uint16_t d_destport;
+ // the canonical direction is that of the question
+ static QuestionIdentifier create(const ComboAddress& src, const ComboAddress& dst, const MOADNSParser& mdp)
+ {
+ return create(src, dst, mdp.d_header, mdp.d_qname, mdp.d_qtype);
+ }
- string d_qname;
+
+ ComboAddress d_source, d_dest;
+
+ DNSName d_qname;
uint16_t d_qtype;
uint16_t d_id;
};
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;
}