]>
Commit | Line | Data |
---|---|---|
12c86877 | 1 | /* |
6edbf68a PL |
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 | */ | |
288f4aa9 | 22 | #include "dns.hh" |
12c86877 BH |
23 | #include <iostream> |
24 | #include <string> | |
25 | #include <vector> | |
26 | #include <utility> | |
27 | #include <sstream> | |
28 | #include "qtype.hh" | |
29 | #include "misc.hh" | |
30 | ||
792402a9 PL |
31 | static_assert(sizeof(QType) == 2, "QType is not 2 bytes in size, something is wrong!"); |
32 | ||
22165a18 | 33 | const map<const string, uint16_t> QType::names = { |
f4e0e6ff OM |
34 | {"A", 1}, |
35 | {"NS", 2}, | |
36 | {"CNAME", 5}, | |
37 | {"SOA", 6}, | |
38 | {"MB", 7}, | |
39 | {"MG", 8}, | |
40 | {"MR", 9}, | |
41 | {"PTR", 12}, | |
42 | {"HINFO", 13}, | |
43 | {"MINFO", 14}, | |
44 | {"MX", 15}, | |
45 | {"TXT", 16}, | |
46 | {"RP", 17}, | |
47 | {"AFSDB", 18}, | |
48 | {"SIG", 24}, | |
49 | {"KEY", 25}, | |
50 | {"AAAA", 28}, | |
51 | {"LOC", 29}, | |
52 | {"SRV", 33}, | |
53 | {"NAPTR", 35}, | |
54 | {"KX", 36}, | |
55 | {"CERT", 37}, | |
56 | {"A6", 38}, | |
57 | {"DNAME", 39}, | |
58 | {"OPT", 41}, | |
59 | {"APL", 42}, | |
60 | {"DS", 43}, | |
61 | {"SSHFP", 44}, | |
62 | {"IPSECKEY", 45}, | |
63 | {"RRSIG", 46}, | |
64 | {"NSEC", 47}, | |
65 | {"DNSKEY", 48}, | |
66 | {"DHCID", 49}, | |
67 | {"NSEC3", 50}, | |
68 | {"NSEC3PARAM", 51}, | |
69 | {"TLSA", 52}, | |
70 | {"SMIMEA", 53}, | |
71 | {"RKEY", 57}, | |
72 | {"CDS", 59}, | |
73 | {"CDNSKEY", 60}, | |
74 | {"OPENPGPKEY", 61}, | |
40b67e4b | 75 | {"CSYNC", 62}, |
f01f7fa4 | 76 | {"ZONEMD", 63}, |
f4e0e6ff OM |
77 | {"SVCB", 64}, |
78 | {"HTTPS", 65}, | |
79 | {"SPF", 99}, | |
786ed0ff PL |
80 | {"NID", 104}, |
81 | {"L32", 105}, | |
82 | {"L64", 106}, | |
83 | {"LP", 107}, | |
f4e0e6ff OM |
84 | {"EUI48", 108}, |
85 | {"EUI64", 109}, | |
86 | {"TKEY", 249}, | |
f38196e3 | 87 | {"TSIG", 250}, |
f4e0e6ff OM |
88 | {"IXFR", 251}, |
89 | {"AXFR", 252}, | |
90 | {"MAILB", 253}, | |
91 | {"MAILA", 254}, | |
92 | {"ANY", 255}, | |
93 | {"URI", 256}, | |
94 | {"CAA", 257}, | |
95 | {"DLV", 32769}, | |
96 | {"ADDR", 65400}, | |
0abfc310 | 97 | #if !defined(RECURSOR) |
f4e0e6ff OM |
98 | {"ALIAS", 65401}, |
99 | {"LUA", 65402}, | |
0abfc310 | 100 | #endif |
f4e0e6ff OM |
101 | }; |
102 | ||
22165a18 OM |
103 | static map<uint16_t, const string> swapElements(const map<const string, uint16_t>& names) { |
104 | map<uint16_t, const string> ret; | |
105 | ||
106 | for (const auto& n : names) { | |
e32a8d46 | 107 | ret.emplace(n.second, n.first); |
22165a18 OM |
108 | } |
109 | return ret; | |
110 | } | |
111 | ||
112 | const map<uint16_t, const string> QType::numbers = swapElements(names); | |
113 | ||
114 | ||
f4e0e6ff | 115 | bool QType::isSupportedType() const |
12c86877 | 116 | { |
22165a18 | 117 | return numbers.count(code) == 1; |
e2b22865 RA |
118 | } |
119 | ||
f4e0e6ff OM |
120 | bool QType::isMetadataType() const |
121 | { | |
2e63e431 RG |
122 | // rfc6895 section 3.1, note ANY is 255 and falls outside the range |
123 | if (code == QType::OPT || (code >= rfc6895MetaLowerBound && code <= rfc6895MetaUpperBound)) { | |
e2b22865 | 124 | return true; |
2e63e431 | 125 | } |
e2b22865 RA |
126 | return false; |
127 | } | |
128 | ||
d5fcd583 | 129 | const string QType::toString() const |
a9e2e5ef | 130 | { |
22165a18 OM |
131 | const auto& name = numbers.find(code); |
132 | if (name != numbers.cend()) { | |
133 | return name->second; | |
f4e0e6ff | 134 | } |
564db8c5 | 135 | return "TYPE" + std::to_string(code); |
12c86877 BH |
136 | } |
137 | ||
f4e0e6ff | 138 | uint16_t QType::chartocode(const char *p) |
12c86877 | 139 | { |
8ce0dc75 | 140 | string P = toUpper(p); |
8ce0dc75 | 141 | |
22165a18 OM |
142 | const auto& num = names.find(P); |
143 | if (num != names.cend()) { | |
144 | return num->second; | |
f4e0e6ff OM |
145 | } |
146 | if (*p == '#') { | |
22165a18 | 147 | return static_cast<uint16_t>(atoi(p + 1)); |
e1de312a | 148 | } |
12c86877 | 149 | |
f4e0e6ff | 150 | if (boost::starts_with(P, "TYPE")) { |
22165a18 | 151 | return static_cast<uint16_t>(atoi(p + 4)); |
f4e0e6ff | 152 | } |
8ce0dc75 | 153 | |
12c86877 BH |
154 | return 0; |
155 | } | |
156 | ||
157 | QType &QType::operator=(const char *p) | |
158 | { | |
f4e0e6ff | 159 | code = chartocode(p); |
12c86877 BH |
160 | return *this; |
161 | } | |
162 | ||
12c86877 BH |
163 | QType &QType::operator=(const string &s) |
164 | { | |
f4e0e6ff | 165 | code = chartocode(s.c_str()); |
12c86877 BH |
166 | return *this; |
167 | } | |
5153bf35 O |
168 | |
169 | const std::string QClass::toString() const | |
170 | { | |
171 | switch (qclass) { | |
172 | case IN: | |
173 | return "IN"; | |
174 | case CHAOS: | |
175 | return "CHAOS"; | |
176 | case NONE: | |
177 | return "NONE"; | |
178 | case ANY: | |
179 | return "ANY"; | |
180 | default : | |
181 | return "CLASS" + std::to_string(qclass); | |
182 | } | |
183 | } |