]> git.ipfire.org Git - thirdparty/pdns.git/blob - pdns/anadns.hh
auth: switch circleci mssql image
[thirdparty/pdns.git] / pdns / anadns.hh
1 /*
2 * This file is part of PowerDNS or dnsdist.
3 * Copyright -- PowerDNS.COM B.V. and its contributors
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of version 2 of the GNU General Public License as
7 * published by the Free Software Foundation.
8 *
9 * In addition, for the avoidance of any doubt, permission is granted to
10 * link this program with OpenSSL and to (re)distribute the binaries
11 * produced as the result of such linking.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21 */
22 #ifndef PDNS_ANADNS_HH
23 #define PDNS_ANADNS_HH
24 #include <boost/tuple/tuple.hpp>
25 #include <boost/tuple/tuple_comparison.hpp>
26 #include <string>
27 #include <netinet/ip.h>
28 #include <netinet/udp.h>
29 #include "dnsparser.hh"
30 #include "iputils.hh"
31 #include "namespaces.hh"
32
33 struct QuestionIdentifier
34 {
35 QuestionIdentifier()
36 {}
37
38 bool operator<(const QuestionIdentifier& rhs) const
39 {
40 return
41 tie(d_id, d_qtype, d_source, d_dest, d_qname) <
42 tie(rhs.d_id, rhs.d_qtype, rhs.d_source, rhs.d_dest, rhs.d_qname);
43 }
44
45
46 // the canonical direction is that of the question
47 static QuestionIdentifier create(const ComboAddress& src, const ComboAddress& dst, const struct dnsheader& header, const DNSName& qname, uint16_t qtype)
48 {
49 QuestionIdentifier ret;
50
51 if(header.qr) {
52 ret.d_source = dst;
53 ret.d_dest = src;
54 }
55 else {
56 ret.d_source = src;
57 ret.d_dest = dst;
58 }
59 ret.d_qname=qname;
60 ret.d_qtype=qtype;
61 ret.d_id=ntohs(header.id);
62 return ret;
63 }
64
65 // the canonical direction is that of the question
66 static QuestionIdentifier create(const ComboAddress& src, const ComboAddress& dst, const MOADNSParser& mdp)
67 {
68 return create(src, dst, mdp.d_header, mdp.d_qname, mdp.d_qtype);
69 }
70
71
72 ComboAddress d_source, d_dest;
73
74 DNSName d_qname;
75 uint16_t d_qtype;
76 uint16_t d_id;
77 };
78
79 inline ostream& operator<<(ostream &s, const QuestionIdentifier& qi)
80 {
81 s<< "'"<<qi.d_qname<<"|"<<DNSRecordContent::NumberToType(qi.d_qtype)<<"', with id " << qi.d_id <<" from "<<qi.d_source.toStringWithPort();
82
83 s<<" to " << qi.d_dest.toStringWithPort();
84 return s;
85 }
86
87
88 #endif