]>
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 | ||
f4e0e6ff OM |
33 | const vector<QType::namenum> QType::names = { |
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}, | |
75 | {"SVCB", 64}, | |
76 | {"HTTPS", 65}, | |
77 | {"SPF", 99}, | |
78 | {"EUI48", 108}, | |
79 | {"EUI64", 109}, | |
80 | {"TKEY", 249}, | |
81 | // {"TSIG", 250}, | |
82 | {"IXFR", 251}, | |
83 | {"AXFR", 252}, | |
84 | {"MAILB", 253}, | |
85 | {"MAILA", 254}, | |
86 | {"ANY", 255}, | |
87 | {"URI", 256}, | |
88 | {"CAA", 257}, | |
89 | {"DLV", 32769}, | |
90 | {"ADDR", 65400}, | |
91 | {"ALIAS", 65401}, | |
92 | {"LUA", 65402}, | |
93 | }; | |
94 | ||
95 | bool QType::isSupportedType() const | |
12c86877 | 96 | { |
f4e0e6ff OM |
97 | for (const auto& pos : names) { |
98 | if (pos.second == code) { | |
e2b22865 | 99 | return true; |
f4e0e6ff OM |
100 | } |
101 | } | |
e2b22865 RA |
102 | return false; |
103 | } | |
104 | ||
f4e0e6ff OM |
105 | bool QType::isMetadataType() const |
106 | { | |
e2b22865 RA |
107 | if (code == QType::AXFR || |
108 | code == QType::MAILA || | |
109 | code == QType::MAILB || | |
110 | code == QType::TSIG || | |
914353ca | 111 | code == QType::IXFR) |
e2b22865 RA |
112 | return true; |
113 | ||
114 | return false; | |
115 | } | |
116 | ||
d6ed1eef | 117 | const string QType::getName() const |
a9e2e5ef | 118 | { |
f4e0e6ff OM |
119 | for (const auto& pos : names) { |
120 | if (pos.second == code) { | |
121 | return pos.first; | |
122 | } | |
123 | } | |
124 | return "TYPE" + itoa(code); | |
12c86877 BH |
125 | } |
126 | ||
f4e0e6ff | 127 | uint16_t QType::chartocode(const char *p) |
12c86877 | 128 | { |
8ce0dc75 | 129 | string P = toUpper(p); |
8ce0dc75 | 130 | |
f4e0e6ff OM |
131 | for(const auto& pos: names) { |
132 | if (pos.first == P) { | |
133 | return pos.second; | |
134 | } | |
135 | } | |
136 | if (*p == '#') { | |
137 | return static_cast<uint16_t>(atoi(p+1)); | |
e1de312a | 138 | } |
12c86877 | 139 | |
f4e0e6ff OM |
140 | if (boost::starts_with(P, "TYPE")) { |
141 | return static_cast<uint16_t>(atoi(p+4)); | |
142 | } | |
8ce0dc75 | 143 | |
12c86877 BH |
144 | return 0; |
145 | } | |
146 | ||
147 | QType &QType::operator=(const char *p) | |
148 | { | |
f4e0e6ff | 149 | code = chartocode(p); |
12c86877 BH |
150 | return *this; |
151 | } | |
152 | ||
12c86877 BH |
153 | QType &QType::operator=(const string &s) |
154 | { | |
f4e0e6ff | 155 | code = chartocode(s.c_str()); |
12c86877 BH |
156 | return *this; |
157 | } |