]>
Commit | Line | Data |
---|---|---|
12471842 PL |
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 | */ | |
9a450843 BH |
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" | |
8b422c02 | 30 | #include "iputils.hh" |
61b26744 | 31 | #include "namespaces.hh" |
9a450843 BH |
32 | |
33 | struct QuestionIdentifier | |
34 | { | |
35 | QuestionIdentifier() | |
36 | {} | |
37 | ||
38 | bool operator<(const QuestionIdentifier& rhs) const | |
39 | { | |
40 | return | |
8b422c02 | 41 | tie(d_source, d_dest, d_qname, d_qtype, d_id) < |
42 | tie(rhs.d_source, rhs.d_dest, rhs.d_qname, rhs.d_qtype, rhs.d_id); | |
9a450843 BH |
43 | } |
44 | ||
45 | // the canonical direction is that of the question | |
a5d9353e | 46 | static QuestionIdentifier create(const ComboAddress& src, const ComboAddress& dst, const MOADNSParser& mdp) |
9a450843 BH |
47 | { |
48 | QuestionIdentifier ret; | |
a5d9353e | 49 | |
9a450843 | 50 | if(mdp.d_header.qr) { |
a5d9353e | 51 | ret.d_source = dst; |
52 | ret.d_dest = src; | |
9a450843 BH |
53 | } |
54 | else { | |
a5d9353e | 55 | ret.d_source = src; |
56 | ret.d_dest = dst; | |
9a450843 BH |
57 | } |
58 | ret.d_qname=mdp.d_qname; | |
59 | ret.d_qtype=mdp.d_qtype; | |
60 | ret.d_id=mdp.d_header.id; | |
61 | return ret; | |
62 | } | |
63 | ||
8b422c02 | 64 | ComboAddress d_source, d_dest; |
9a450843 | 65 | |
af6406f5 | 66 | DNSName d_qname; |
9a450843 BH |
67 | uint16_t d_qtype; |
68 | uint16_t d_id; | |
9a450843 BH |
69 | }; |
70 | ||
71 | inline ostream& operator<<(ostream &s, const QuestionIdentifier& qi) | |
72 | { | |
81aa6d25 | 73 | s<< "'"<<qi.d_qname<<"|"<<DNSRecordContent::NumberToType(qi.d_qtype)<<"', with id " << qi.d_id <<" from "<<qi.d_source.toStringWithPort(); |
9a450843 | 74 | |
8b422c02 | 75 | s<<" to " << qi.d_dest.toStringWithPort(); |
76 | return s; | |
9a450843 BH |
77 | } |
78 | ||
79 | ||
80 | #endif |