]>
Commit | Line | Data |
---|---|---|
4192ca66 | 1 | /* |
12471842 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 | */ | |
a0a276c2 BH |
22 | #ifndef PDNS_DNSRECORDS_HH |
23 | #define PDNS_DNSRECORDS_HH | |
24 | ||
8900e2e3 CHB |
25 | #ifdef HAVE_CONFIG_H |
26 | #include "config.h" | |
27 | #endif | |
28 | ||
a0a276c2 BH |
29 | #include "dnsparser.hh" |
30 | #include "dnswriter.hh" | |
cbf0e7f3 | 31 | #include "rcpgenerator.hh" |
8c1c9170 | 32 | #include <set> |
51083cab | 33 | #include <bitset> |
61b26744 | 34 | #include "namespaces.hh" |
f4352636 | 35 | #include "iputils.hh" |
a0a276c2 | 36 | |
2770fad0 BH |
37 | #define includeboilerplate(RNAME) RNAME##RecordContent(const DNSRecord& dr, PacketReader& pr); \ |
38 | RNAME##RecordContent(const string& zoneData); \ | |
39 | static void report(void); \ | |
ee1ada80 | 40 | static void unreport(void); \ |
32122aab RG |
41 | static std::shared_ptr<DNSRecordContent> make(const DNSRecord &dr, PacketReader& pr); \ |
42 | static std::shared_ptr<DNSRecordContent> make(const string& zonedata); \ | |
f21fc0aa | 43 | string getZoneRepresentation(bool noDot=false) const override; \ |
2cca142e | 44 | void toPacket(DNSPacketWriter& pw) override; \ |
5a1f298f | 45 | uint16_t getType() const override { return QType::RNAME; } \ |
f21fc0aa | 46 | template<class Convertor> void xfrPacket(Convertor& conv, bool noDot=false); |
a0a276c2 BH |
47 | |
48 | class NAPTRRecordContent : public DNSRecordContent | |
49 | { | |
50 | public: | |
4a51ff72 | 51 | NAPTRRecordContent(uint16_t order, uint16_t preference, string flags, string services, string regexp, DNSName replacement); |
a0a276c2 | 52 | |
1d1d688a | 53 | includeboilerplate(NAPTR) |
cbf0e7f3 | 54 | template<class Convertor> void xfrRecordContent(Convertor& conv); |
a0a276c2 BH |
55 | private: |
56 | uint16_t d_order, d_preference; | |
4a51ff72 PD |
57 | string d_flags, d_services, d_regexp; |
58 | DNSName d_replacement; | |
a0a276c2 BH |
59 | }; |
60 | ||
2770fad0 | 61 | |
a0a276c2 BH |
62 | class ARecordContent : public DNSRecordContent |
63 | { | |
64 | public: | |
447e0cff | 65 | explicit ARecordContent(const ComboAddress& ca); |
efb265e3 | 66 | explicit ARecordContent(uint32_t ip); |
1d1d688a | 67 | includeboilerplate(A) |
2770fad0 | 68 | void doRecordCheck(const DNSRecord& dr); |
447e0cff | 69 | ComboAddress getCA(int port=0) const; |
f18e430f | 70 | bool operator==(const DNSRecordContent& rhs) const override |
71 | { | |
72 | if(typeid(*this) != typeid(rhs)) | |
73 | return false; | |
74 | return d_ip == dynamic_cast<const ARecordContent&>(rhs).d_ip; | |
75 | } | |
2770fad0 BH |
76 | private: |
77 | uint32_t d_ip; | |
78 | }; | |
a0a276c2 | 79 | |
fc465b41 AT |
80 | class AAAARecordContent : public DNSRecordContent |
81 | { | |
82 | public: | |
83 | AAAARecordContent(std::string &val); | |
447e0cff | 84 | explicit AAAARecordContent(const ComboAddress& ca); |
1d1d688a | 85 | includeboilerplate(AAAA) |
447e0cff | 86 | ComboAddress getCA(int port=0) const; |
f18e430f | 87 | bool operator==(const DNSRecordContent& rhs) const override |
88 | { | |
89 | if(typeid(*this) != typeid(rhs)) | |
90 | return false; | |
91 | return d_ip6 == dynamic_cast<const decltype(this)>(&rhs)->d_ip6; | |
92 | } | |
fc465b41 | 93 | private: |
447e0cff | 94 | string d_ip6; // why?? |
fc465b41 AT |
95 | }; |
96 | ||
2770fad0 BH |
97 | class MXRecordContent : public DNSRecordContent |
98 | { | |
99 | public: | |
89735451 | 100 | MXRecordContent(uint16_t preference, const DNSName& mxname); |
a0a276c2 | 101 | |
2770fad0 | 102 | includeboilerplate(MX) |
a0a276c2 | 103 | |
2770fad0 | 104 | uint16_t d_preference; |
89735451 | 105 | DNSName d_mxname; |
f18e430f | 106 | |
107 | bool operator==(const DNSRecordContent& rhs) const override | |
108 | { | |
109 | if(typeid(*this) != typeid(rhs)) | |
110 | return false; | |
111 | auto rrhs =dynamic_cast<const decltype(this)>(&rhs); | |
112 | return std::tie(d_preference, d_mxname) == std::tie(rrhs->d_preference, rrhs->d_mxname); | |
113 | } | |
114 | ||
2770fad0 BH |
115 | }; |
116 | ||
9fd71f2e BH |
117 | class KXRecordContent : public DNSRecordContent |
118 | { | |
119 | public: | |
89735451 | 120 | KXRecordContent(uint16_t preference, const DNSName& exchanger); |
9fd71f2e BH |
121 | |
122 | includeboilerplate(KX) | |
123 | ||
124 | private: | |
125 | uint16_t d_preference; | |
89735451 | 126 | DNSName d_exchanger; |
9fd71f2e BH |
127 | }; |
128 | ||
129 | class IPSECKEYRecordContent : public DNSRecordContent | |
130 | { | |
131 | public: | |
c2f3be9d | 132 | IPSECKEYRecordContent(uint16_t preference, uint8_t gatewaytype, uint8_t algo, const DNSName& gateway, const string& publickey); |
9fd71f2e BH |
133 | |
134 | includeboilerplate(IPSECKEY) | |
135 | ||
136 | private: | |
d0793109 | 137 | uint32_t d_ip4; |
c2f3be9d PD |
138 | DNSName d_gateway; |
139 | string d_publickey; | |
1cafb958 | 140 | string d_ip6; |
adc18742 | 141 | uint8_t d_preference, d_gatewaytype, d_algorithm; |
9fd71f2e BH |
142 | }; |
143 | ||
144 | class DHCIDRecordContent : public DNSRecordContent | |
145 | { | |
146 | public: | |
147 | includeboilerplate(DHCID) | |
148 | ||
149 | private: | |
150 | string d_content; | |
151 | }; | |
152 | ||
153 | ||
2770fad0 BH |
154 | class SRVRecordContent : public DNSRecordContent |
155 | { | |
156 | public: | |
89735451 | 157 | SRVRecordContent(uint16_t preference, uint16_t weight, uint16_t port, const DNSName& target); |
2770fad0 BH |
158 | |
159 | includeboilerplate(SRV) | |
160 | ||
a2d7c36a | 161 | uint16_t d_weight, d_port; |
89735451 | 162 | DNSName d_target; |
a2d7c36a | 163 | uint16_t d_preference; |
2770fad0 BH |
164 | }; |
165 | ||
06ffdc52 BH |
166 | class TSIGRecordContent : public DNSRecordContent |
167 | { | |
168 | public: | |
169 | includeboilerplate(TSIG) | |
5a1f298f | 170 | TSIGRecordContent() {} |
06ffdc52 | 171 | |
34c513f9 RG |
172 | uint16_t d_origID{0}; |
173 | uint16_t d_fudge{0}; | |
c3a81a30 | 174 | |
0b6fa0eb | 175 | DNSName d_algoName; |
483d2f10 PL |
176 | string d_mac; |
177 | string d_otherData; | |
34c513f9 | 178 | uint64_t d_time{0}; |
06ffdc52 | 179 | // uint16_t d_macSize; |
34c513f9 | 180 | uint16_t d_eRcode{0}; |
06ffdc52 | 181 | // uint16_t d_otherLen |
06ffdc52 BH |
182 | }; |
183 | ||
2770fad0 BH |
184 | |
185 | class TXTRecordContent : public DNSRecordContent | |
186 | { | |
187 | public: | |
188 | includeboilerplate(TXT) | |
189 | ||
2770fad0 | 190 | string d_text; |
a0a276c2 BH |
191 | }; |
192 | ||
8900e2e3 | 193 | #ifdef HAVE_LUA_RECORDS |
6b547a53 | 194 | class LUARecordContent : public DNSRecordContent |
195 | { | |
196 | public: | |
197 | includeboilerplate(LUA) | |
98fa3598 | 198 | string getCode() const; |
5dbd408c | 199 | uint16_t d_type; |
6b547a53 | 200 | string d_code; |
201 | }; | |
8900e2e3 | 202 | #endif |
6b547a53 | 203 | |
acedb99e | 204 | class ENTRecordContent : public DNSRecordContent |
205 | { | |
206 | public: | |
207 | includeboilerplate(ENT) | |
208 | }; | |
209 | ||
8c1c9170 BH |
210 | class SPFRecordContent : public DNSRecordContent |
211 | { | |
212 | public: | |
213 | includeboilerplate(SPF) | |
0bd2e252 RG |
214 | const std::string& getText() const |
215 | { | |
216 | return d_text; | |
217 | } | |
8c1c9170 BH |
218 | |
219 | private: | |
220 | string d_text; | |
221 | }; | |
222 | ||
223 | ||
cbf0e7f3 BH |
224 | class NSRecordContent : public DNSRecordContent |
225 | { | |
226 | public: | |
227 | includeboilerplate(NS) | |
5a1f298f | 228 | explicit NSRecordContent(const DNSName& content) : d_content(content){} |
f18e430f | 229 | const DNSName& getNS() const { return d_content; } |
230 | bool operator==(const DNSRecordContent& rhs) const override | |
231 | { | |
232 | if(typeid(*this) != typeid(rhs)) | |
233 | return false; | |
234 | auto rrhs =dynamic_cast<const decltype(this)>(&rhs); | |
235 | return d_content == rrhs->d_content; | |
236 | } | |
237 | ||
cbf0e7f3 | 238 | private: |
89735451 | 239 | DNSName d_content; |
cbf0e7f3 BH |
240 | }; |
241 | ||
242 | class PTRRecordContent : public DNSRecordContent | |
243 | { | |
244 | public: | |
245 | includeboilerplate(PTR) | |
98cda0a9 | 246 | explicit PTRRecordContent(const DNSName& content) : d_content(content){} |
0bd2e252 | 247 | const DNSName& getContent() const { return d_content; } |
cbf0e7f3 | 248 | private: |
89735451 | 249 | DNSName d_content; |
cbf0e7f3 BH |
250 | }; |
251 | ||
252 | class CNAMERecordContent : public DNSRecordContent | |
253 | { | |
254 | public: | |
255 | includeboilerplate(CNAME) | |
90ba52e0 | 256 | CNAMERecordContent(const DNSName& content) : d_content(content){} |
447e0cff | 257 | DNSName getTarget() const { return d_content; } |
cbf0e7f3 | 258 | private: |
89735451 | 259 | DNSName d_content; |
cbf0e7f3 BH |
260 | }; |
261 | ||
d59b894d | 262 | class ALIASRecordContent : public DNSRecordContent |
263 | { | |
264 | public: | |
265 | includeboilerplate(ALIAS) | |
266 | ||
89735451 | 267 | DNSName d_content; |
d59b894d | 268 | }; |
269 | ||
270 | ||
8dee0750 | 271 | class DNAMERecordContent : public DNSRecordContent |
272 | { | |
273 | public: | |
274 | includeboilerplate(DNAME) | |
89735451 | 275 | DNSName d_content; |
8dee0750 | 276 | }; |
277 | ||
278 | ||
fa552262 CHB |
279 | class MBRecordContent : public DNSRecordContent |
280 | { | |
281 | public: | |
282 | includeboilerplate(MB) | |
283 | ||
284 | private: | |
285 | DNSName d_madname; | |
286 | }; | |
287 | ||
288 | class MGRecordContent : public DNSRecordContent | |
289 | { | |
290 | public: | |
291 | includeboilerplate(MG) | |
292 | ||
293 | private: | |
294 | DNSName d_mgmname; | |
295 | }; | |
296 | ||
4e0805a6 BH |
297 | class MRRecordContent : public DNSRecordContent |
298 | { | |
299 | public: | |
300 | includeboilerplate(MR) | |
301 | ||
302 | private: | |
89735451 | 303 | DNSName d_alias; |
4e0805a6 BH |
304 | }; |
305 | ||
7c0b8593 | 306 | class MINFORecordContent : public DNSRecordContent |
307 | { | |
308 | public: | |
309 | includeboilerplate(MINFO) | |
310 | ||
311 | private: | |
89735451 PD |
312 | DNSName d_rmailbx; |
313 | DNSName d_emailbx; | |
7c0b8593 | 314 | }; |
cbf0e7f3 | 315 | |
878435ce BH |
316 | class OPTRecordContent : public DNSRecordContent |
317 | { | |
318 | public: | |
c541004c | 319 | OPTRecordContent(){} |
878435ce | 320 | includeboilerplate(OPT) |
7f7b8d55 | 321 | void getData(vector<pair<uint16_t, string> > &opts); |
878435ce BH |
322 | private: |
323 | string d_data; | |
324 | }; | |
325 | ||
326 | ||
cbf0e7f3 BH |
327 | class HINFORecordContent : public DNSRecordContent |
328 | { | |
329 | public: | |
330 | includeboilerplate(HINFO) | |
331 | ||
332 | private: | |
333 | string d_cpu, d_host; | |
334 | }; | |
335 | ||
336 | class RPRecordContent : public DNSRecordContent | |
337 | { | |
338 | public: | |
339 | includeboilerplate(RP) | |
340 | ||
341 | private: | |
89735451 | 342 | DNSName d_mbox, d_info; |
cbf0e7f3 BH |
343 | }; |
344 | ||
345 | ||
8c1c9170 BH |
346 | class DNSKEYRecordContent : public DNSRecordContent |
347 | { | |
348 | public: | |
1c4d88c5 | 349 | DNSKEYRecordContent(); |
8c1c9170 | 350 | includeboilerplate(DNSKEY) |
523c312b | 351 | uint16_t getTag() const; |
354ccf4e | 352 | uint16_t getTag(); |
8c1c9170 | 353 | |
34c513f9 RG |
354 | uint16_t d_flags{0}; |
355 | uint8_t d_protocol{0}; | |
356 | uint8_t d_algorithm{0}; | |
8c1c9170 | 357 | string d_key; |
523c312b | 358 | bool operator<(const DNSKEYRecordContent& rhs) const |
359 | { | |
360 | return tie(d_flags, d_protocol, d_algorithm, d_key) < | |
361 | tie(rhs.d_flags, rhs.d_protocol, rhs.d_algorithm, rhs.d_key); | |
362 | } | |
8c1c9170 BH |
363 | }; |
364 | ||
882de365 PL |
365 | class CDNSKEYRecordContent : public DNSRecordContent |
366 | { | |
367 | public: | |
368 | CDNSKEYRecordContent(); | |
369 | includeboilerplate(CDNSKEY) | |
370 | uint16_t getTag(); | |
371 | ||
34c513f9 RG |
372 | uint16_t d_flags{0}; |
373 | uint8_t d_protocol{0}; | |
374 | uint8_t d_algorithm{0}; | |
882de365 PL |
375 | string d_key; |
376 | }; | |
377 | ||
8c1c9170 BH |
378 | class DSRecordContent : public DNSRecordContent |
379 | { | |
380 | public: | |
1c4d88c5 | 381 | DSRecordContent(); |
0b062478 | 382 | bool operator==(const DNSRecordContent& rhs) const override |
a820bc34 | 383 | { |
0b062478 RG |
384 | if(typeid(*this) != typeid(rhs)) |
385 | return false; | |
386 | auto rrhs =dynamic_cast<const decltype(this)>(&rhs); | |
a820bc34 | 387 | return tie(d_tag, d_algorithm, d_digesttype, d_digest) == |
0b062478 | 388 | tie(rrhs->d_tag, rrhs->d_algorithm, rrhs->d_digesttype, rrhs->d_digest); |
a820bc34 | 389 | } |
390 | bool operator<(const DSRecordContent& rhs) const | |
391 | { | |
392 | return tie(d_tag, d_algorithm, d_digesttype, d_digest) < | |
393 | tie(rhs.d_tag, rhs.d_algorithm, rhs.d_digesttype, rhs.d_digest); | |
394 | } | |
395 | ||
8c1c9170 BH |
396 | includeboilerplate(DS) |
397 | ||
34c513f9 RG |
398 | uint16_t d_tag{0}; |
399 | uint8_t d_algorithm{0}, d_digesttype{0}; | |
8c1c9170 BH |
400 | string d_digest; |
401 | }; | |
402 | ||
882de365 PL |
403 | class CDSRecordContent : public DNSRecordContent |
404 | { | |
405 | public: | |
406 | CDSRecordContent(); | |
407 | includeboilerplate(CDS) | |
408 | ||
34c513f9 RG |
409 | uint16_t d_tag{0}; |
410 | uint8_t d_algorithm{0}, d_digesttype{0}; | |
882de365 PL |
411 | string d_digest; |
412 | }; | |
413 | ||
0b55f2f5 BH |
414 | class DLVRecordContent : public DNSRecordContent |
415 | { | |
416 | public: | |
417 | DLVRecordContent(); | |
418 | includeboilerplate(DLV) | |
419 | ||
34c513f9 RG |
420 | uint16_t d_tag{0}; |
421 | uint8_t d_algorithm{0}, d_digesttype{0}; | |
0b55f2f5 BH |
422 | string d_digest; |
423 | }; | |
424 | ||
425 | ||
a40a693b BH |
426 | class SSHFPRecordContent : public DNSRecordContent |
427 | { | |
428 | public: | |
429 | includeboilerplate(SSHFP) | |
430 | ||
431 | private: | |
432 | uint8_t d_algorithm, d_fptype; | |
433 | string d_fingerprint; | |
434 | }; | |
8c1c9170 | 435 | |
4b5762f1 BH |
436 | class KEYRecordContent : public DNSRecordContent |
437 | { | |
438 | public: | |
439 | includeboilerplate(KEY) | |
440 | ||
441 | private: | |
442 | uint16_t d_flags; | |
443 | uint8_t d_protocol, d_algorithm; | |
444 | string d_certificate; | |
445 | }; | |
446 | ||
37f47031 BH |
447 | class AFSDBRecordContent : public DNSRecordContent |
448 | { | |
449 | public: | |
450 | includeboilerplate(AFSDB) | |
451 | ||
452 | private: | |
453 | uint16_t d_subtype; | |
89735451 | 454 | DNSName d_hostname; |
37f47031 BH |
455 | }; |
456 | ||
457 | ||
2475a4fc BH |
458 | class CERTRecordContent : public DNSRecordContent |
459 | { | |
460 | public: | |
461 | includeboilerplate(CERT) | |
462 | ||
463 | private: | |
464 | uint16_t d_type, d_tag; | |
2475a4fc | 465 | string d_certificate; |
1e56bb82 | 466 | uint8_t d_algorithm; |
2475a4fc BH |
467 | }; |
468 | ||
07dbe87e BH |
469 | class TLSARecordContent : public DNSRecordContent |
470 | { | |
471 | public: | |
472 | includeboilerplate(TLSA) | |
473 | ||
474 | private: | |
f5a09796 | 475 | uint8_t d_certusage, d_selector, d_matchtype; |
07dbe87e BH |
476 | string d_cert; |
477 | }; | |
478 | ||
291935bb PL |
479 | class SMIMEARecordContent : public DNSRecordContent |
480 | { | |
481 | public: | |
482 | includeboilerplate(SMIMEA) | |
483 | ||
484 | private: | |
485 | uint8_t d_certusage, d_selector, d_matchtype; | |
486 | string d_cert; | |
487 | }; | |
488 | ||
68066337 JC |
489 | class OPENPGPKEYRecordContent : public DNSRecordContent |
490 | { | |
491 | public: | |
492 | includeboilerplate(OPENPGPKEY) | |
493 | ||
494 | private: | |
3fd06ce5 | 495 | string d_keyring; |
68066337 JC |
496 | }; |
497 | ||
07dbe87e | 498 | |
8c1c9170 BH |
499 | class RRSIGRecordContent : public DNSRecordContent |
500 | { | |
501 | public: | |
1c4d88c5 | 502 | RRSIGRecordContent(); |
8c1c9170 BH |
503 | includeboilerplate(RRSIG) |
504 | ||
34c513f9 RG |
505 | uint16_t d_type{0}; |
506 | uint16_t d_tag{0}; | |
89735451 PD |
507 | DNSName d_signer; |
508 | string d_signature; | |
34c513f9 RG |
509 | uint32_t d_originalttl{0}, d_sigexpire{0}, d_siginception{0}; |
510 | uint8_t d_algorithm{0}, d_labels{0}; | |
8c1c9170 BH |
511 | }; |
512 | ||
5ac6a3a3 | 513 | //namespace { |
2770fad0 BH |
514 | struct soatimes |
515 | { | |
516 | uint32_t serial; | |
517 | uint32_t refresh; | |
518 | uint32_t retry; | |
519 | uint32_t expire; | |
520 | uint32_t minimum; | |
521 | }; | |
5ac6a3a3 | 522 | //} |
2770fad0 | 523 | |
3150a49c | 524 | class RKEYRecordContent : public DNSRecordContent |
525 | { | |
526 | public: | |
527 | RKEYRecordContent(); | |
528 | includeboilerplate(RKEY) | |
34c513f9 RG |
529 | uint16_t d_flags{0}; |
530 | uint8_t d_protocol{0}, d_algorithm{0}; | |
3150a49c | 531 | string d_key; |
532 | }; | |
2770fad0 BH |
533 | |
534 | class SOARecordContent : public DNSRecordContent | |
535 | { | |
536 | public: | |
537 | includeboilerplate(SOA) | |
89735451 | 538 | SOARecordContent(const DNSName& mname, const DNSName& rname, const struct soatimes& st); |
2770fad0 | 539 | |
89735451 PD |
540 | DNSName d_mname; |
541 | DNSName d_rname; | |
1c21ab45 | 542 | struct soatimes d_st; |
2770fad0 | 543 | }; |
a0a276c2 | 544 | |
20133c59 BH |
545 | class NSECRecordContent : public DNSRecordContent |
546 | { | |
547 | public: | |
548 | static void report(void); | |
5a1f298f | 549 | NSECRecordContent() |
20133c59 | 550 | {} |
3343ad1f | 551 | NSECRecordContent(const string& content, const string& zone=""); //FIXME400: DNSName& zone? |
20133c59 | 552 | |
32122aab RG |
553 | static std::shared_ptr<DNSRecordContent> make(const DNSRecord &dr, PacketReader& pr); |
554 | static std::shared_ptr<DNSRecordContent> make(const string& content); | |
f21fc0aa | 555 | string getZoneRepresentation(bool noDot=false) const override; |
2cca142e | 556 | void toPacket(DNSPacketWriter& pw) override; |
5a1f298f | 557 | uint16_t getType() const override |
558 | { | |
559 | return QType::NSEC; | |
560 | } | |
89735451 | 561 | DNSName d_next; |
20133c59 BH |
562 | std::set<uint16_t> d_set; |
563 | private: | |
20133c59 BH |
564 | }; |
565 | ||
1c4d88c5 BH |
566 | class NSEC3RecordContent : public DNSRecordContent |
567 | { | |
568 | public: | |
569 | static void report(void); | |
2cca142e | 570 | NSEC3RecordContent() |
1c4d88c5 | 571 | {} |
3343ad1f | 572 | NSEC3RecordContent(const string& content, const string& zone=""); //FIXME400: DNSName& zone? |
1c4d88c5 | 573 | |
32122aab RG |
574 | static std::shared_ptr<DNSRecordContent> make(const DNSRecord &dr, PacketReader& pr); |
575 | static std::shared_ptr<DNSRecordContent> make(const string& content); | |
f21fc0aa | 576 | string getZoneRepresentation(bool noDot=false) const override; |
2cca142e | 577 | void toPacket(DNSPacketWriter& pw) override; |
1c4d88c5 | 578 | |
34c513f9 RG |
579 | uint8_t d_algorithm{0}, d_flags{0}; |
580 | uint16_t d_iterations{0}; | |
1c4d88c5 | 581 | string d_salt; |
1c4d88c5 BH |
582 | string d_nexthash; |
583 | std::set<uint16_t> d_set; | |
584 | ||
5a1f298f | 585 | uint16_t getType() const override |
586 | { | |
587 | return QType::NSEC3; | |
588 | } | |
589 | ||
590 | ||
1c4d88c5 BH |
591 | private: |
592 | }; | |
593 | ||
594 | ||
595 | class NSEC3PARAMRecordContent : public DNSRecordContent | |
596 | { | |
597 | public: | |
827634f0 | 598 | static void report(void); |
5a1f298f | 599 | NSEC3PARAMRecordContent() |
827634f0 | 600 | {} |
3343ad1f | 601 | NSEC3PARAMRecordContent(const string& content, const string& zone=""); // FIXME400: DNSName& zone? |
827634f0 | 602 | |
32122aab RG |
603 | static std::shared_ptr<DNSRecordContent> make(const DNSRecord &dr, PacketReader& pr); |
604 | static std::shared_ptr<DNSRecordContent> make(const string& content); | |
f21fc0aa | 605 | string getZoneRepresentation(bool noDot=false) const override; |
2cca142e | 606 | void toPacket(DNSPacketWriter& pw) override; |
827634f0 | 607 | |
5a1f298f | 608 | uint16_t getType() const override |
609 | { | |
610 | return QType::NSEC3PARAM; | |
611 | } | |
612 | ||
1c4d88c5 | 613 | |
34c513f9 RG |
614 | uint8_t d_algorithm{0}, d_flags{0}; |
615 | uint16_t d_iterations{0}; | |
1c4d88c5 BH |
616 | string d_salt; |
617 | }; | |
618 | ||
619 | ||
c6a60874 BH |
620 | class LOCRecordContent : public DNSRecordContent |
621 | { | |
622 | public: | |
623 | static void report(void); | |
2cca142e | 624 | LOCRecordContent() |
c6a60874 BH |
625 | {} |
626 | LOCRecordContent(const string& content, const string& zone=""); | |
20133c59 | 627 | |
32122aab RG |
628 | static std::shared_ptr<DNSRecordContent> make(const DNSRecord &dr, PacketReader& pr); |
629 | static std::shared_ptr<DNSRecordContent> make(const string& content); | |
f21fc0aa | 630 | string getZoneRepresentation(bool noDot=false) const override; |
2cca142e | 631 | void toPacket(DNSPacketWriter& pw) override; |
c6a60874 | 632 | |
34c513f9 RG |
633 | uint8_t d_version{0}, d_size{0}, d_horizpre{0}, d_vertpre{0}; |
634 | uint32_t d_latitude{0}, d_longitude{0}, d_altitude{0}; | |
5a1f298f | 635 | uint16_t getType() const override |
636 | { | |
637 | return QType::LOC; | |
638 | } | |
639 | ||
c6a60874 BH |
640 | private: |
641 | }; | |
8c1c9170 | 642 | |
51083cab BH |
643 | |
644 | class WKSRecordContent : public DNSRecordContent | |
645 | { | |
646 | public: | |
647 | static void report(void); | |
5a1f298f | 648 | WKSRecordContent() |
51083cab | 649 | {} |
3343ad1f | 650 | WKSRecordContent(const string& content, const string& zone=""); // FIXME400: DNSName& zone? |
51083cab | 651 | |
32122aab RG |
652 | static std::shared_ptr<DNSRecordContent> make(const DNSRecord &dr, PacketReader& pr); |
653 | static std::shared_ptr<DNSRecordContent> make(const string& content); | |
f21fc0aa | 654 | string getZoneRepresentation(bool noDot=false) const override; |
2cca142e | 655 | void toPacket(DNSPacketWriter& pw) override; |
51083cab | 656 | |
34c513f9 | 657 | uint32_t d_ip{0}; |
51083cab BH |
658 | std::bitset<65535> d_services; |
659 | private: | |
660 | }; | |
661 | ||
66a07c55 AT |
662 | class EUI48RecordContent : public DNSRecordContent |
663 | { | |
664 | public: | |
5a1f298f | 665 | EUI48RecordContent() {}; |
66a07c55 | 666 | static void report(void); |
32122aab RG |
667 | static std::shared_ptr<DNSRecordContent> make(const DNSRecord &dr, PacketReader& pr); |
668 | static std::shared_ptr<DNSRecordContent> make(const string& zone); // FIXME400: DNSName& zone? | |
f21fc0aa | 669 | string getZoneRepresentation(bool noDot=false) const override; |
2cca142e | 670 | void toPacket(DNSPacketWriter& pw) override; |
5a1f298f | 671 | uint16_t getType() const override { return QType::EUI48; } |
66a07c55 AT |
672 | private: |
673 | // storage for the bytes | |
674 | uint8_t d_eui48[6]; | |
675 | }; | |
676 | ||
677 | class EUI64RecordContent : public DNSRecordContent | |
678 | { | |
679 | public: | |
5a1f298f | 680 | EUI64RecordContent() {}; |
66a07c55 | 681 | static void report(void); |
32122aab RG |
682 | static std::shared_ptr<DNSRecordContent> make(const DNSRecord &dr, PacketReader& pr); |
683 | static std::shared_ptr<DNSRecordContent> make(const string& zone); // FIXME400: DNSName& zone? | |
f21fc0aa | 684 | string getZoneRepresentation(bool noDot=false) const override; |
2cca142e | 685 | void toPacket(DNSPacketWriter& pw) override; |
5a1f298f | 686 | uint16_t getType() const override { return QType::EUI64; } |
66a07c55 AT |
687 | private: |
688 | // storage for the bytes | |
689 | uint8_t d_eui64[8]; | |
690 | }; | |
d34d3e01 | 691 | |
b3ac6324 AT |
692 | class TKEYRecordContent : public DNSRecordContent |
693 | { | |
694 | public: | |
695 | TKEYRecordContent(); | |
696 | includeboilerplate(TKEY) | |
697 | ||
698 | // storage for the bytes | |
34c513f9 RG |
699 | uint16_t d_othersize{0}; |
700 | uint16_t d_mode{0}; | |
701 | uint32_t d_inception{0}; | |
702 | uint32_t d_expiration{0}; | |
adc18742 | 703 | |
0b6fa0eb | 704 | DNSName d_algo; |
b3ac6324 | 705 | string d_key; |
b3ac6324 | 706 | string d_other; |
adc18742 | 707 | |
34c513f9 RG |
708 | uint16_t d_error{0}; |
709 | uint16_t d_keysize{0}; | |
b3ac6324 AT |
710 | private: |
711 | }; | |
712 | ||
20966479 PL |
713 | class URIRecordContent : public DNSRecordContent { |
714 | public: | |
715 | includeboilerplate(URI) | |
716 | private: | |
fa38400f | 717 | uint16_t d_priority, d_weight; |
20966479 PL |
718 | string d_target; |
719 | }; | |
720 | ||
f75f6821 PL |
721 | class CAARecordContent : public DNSRecordContent { |
722 | public: | |
723 | includeboilerplate(CAA) | |
724 | private: | |
725 | uint8_t d_flags; | |
726 | string d_tag, d_value; | |
727 | }; | |
728 | ||
8c1c9170 | 729 | #define boilerplate(RNAME, RTYPE) \ |
32122aab | 730 | std::shared_ptr<RNAME##RecordContent::DNSRecordContent> RNAME##RecordContent::make(const DNSRecord& dr, PacketReader& pr) \ |
8c1c9170 | 731 | { \ |
32122aab | 732 | return std::make_shared<RNAME##RecordContent>(dr, pr); \ |
8c1c9170 BH |
733 | } \ |
734 | \ | |
5a1f298f | 735 | RNAME##RecordContent::RNAME##RecordContent(const DNSRecord& dr, PacketReader& pr) \ |
8c1c9170 BH |
736 | { \ |
737 | doRecordCheck(dr); \ | |
738 | xfrPacket(pr); \ | |
739 | } \ | |
740 | \ | |
32122aab | 741 | std::shared_ptr<RNAME##RecordContent::DNSRecordContent> RNAME##RecordContent::make(const string& zonedata) \ |
8c1c9170 | 742 | { \ |
32122aab | 743 | return std::make_shared<RNAME##RecordContent>(zonedata); \ |
8c1c9170 BH |
744 | } \ |
745 | \ | |
746 | void RNAME##RecordContent::toPacket(DNSPacketWriter& pw) \ | |
747 | { \ | |
748 | this->xfrPacket(pw); \ | |
749 | } \ | |
750 | \ | |
751 | void RNAME##RecordContent::report(void) \ | |
752 | { \ | |
250d1fd8 | 753 | regist(1, RTYPE, &RNAME##RecordContent::make, &RNAME##RecordContent::make, #RNAME); \ |
d6f3feee | 754 | regist(254, RTYPE, &RNAME##RecordContent::make, &RNAME##RecordContent::make, #RNAME); \ |
ee1ada80 BH |
755 | } \ |
756 | void RNAME##RecordContent::unreport(void) \ | |
757 | { \ | |
758 | unregist(1, RTYPE); \ | |
d6f3feee | 759 | unregist(254, RTYPE); \ |
8c1c9170 BH |
760 | } \ |
761 | \ | |
5a1f298f | 762 | RNAME##RecordContent::RNAME##RecordContent(const string& zoneData) \ |
8c1c9170 | 763 | { \ |
aab4adb0 BH |
764 | try { \ |
765 | RecordTextReader rtr(zoneData); \ | |
766 | xfrPacket(rtr); \ | |
767 | } \ | |
81bb680e JS |
768 | catch(RecordTextException& rte) { \ |
769 | throw MOADNSException("Parsing record content (try 'pdnsutil check-zone'): "+string(rte.what())); \ | |
1649b6ef | 770 | } \ |
8c1c9170 BH |
771 | } \ |
772 | \ | |
f21fc0aa | 773 | string RNAME##RecordContent::getZoneRepresentation(bool noDot) const \ |
8c1c9170 BH |
774 | { \ |
775 | string ret; \ | |
f21fc0aa | 776 | RecordTextWriter rtw(ret, noDot); \ |
8c1c9170 BH |
777 | const_cast<RNAME##RecordContent*>(this)->xfrPacket(rtw); \ |
778 | return ret; \ | |
779 | } | |
780 | ||
781 | ||
782 | #define boilerplate_conv(RNAME, TYPE, CONV) \ | |
783 | boilerplate(RNAME, TYPE) \ | |
784 | template<class Convertor> \ | |
f21fc0aa | 785 | void RNAME##RecordContent::xfrPacket(Convertor& conv, bool noDot) \ |
8c1c9170 BH |
786 | { \ |
787 | CONV; \ | |
ddb79bca | 788 | if (conv.eof() == false) throw MOADNSException("When parsing " #RNAME " trailing data was not parsed: '" + conv.getRemaining() + "'"); \ |
8c1c9170 BH |
789 | } \ |
790 | ||
7f7b8d55 BH |
791 | struct EDNSOpts |
792 | { | |
5ca95d47 PL |
793 | enum zFlags { DNSSECOK=32768 }; |
794 | vector<pair<uint16_t, string> > d_options; | |
447e0cff | 795 | uint16_t d_packetsize{0}; |
d6c335ab | 796 | uint16_t d_extFlags{0}; |
5ca95d47 | 797 | uint8_t d_extRCode, d_version; |
7f7b8d55 BH |
798 | }; |
799 | //! Convenience function that fills out EDNS0 options, and returns true if there are any | |
800 | ||
801 | class MOADNSParser; | |
802 | bool getEDNSOpts(const MOADNSParser& mdp, EDNSOpts* eo); | |
d6c335ab | 803 | DNSRecord makeOpt(const uint16_t udpsize, const uint16_t extRCode, const uint16_t extFlags); |
ea634573 BH |
804 | void reportBasicTypes(); |
805 | void reportOtherTypes(); | |
806 | void reportAllTypes(); | |
f1ae49f7 | 807 | ComboAddress getAddr(const DNSRecord& dr, uint16_t defport=0); |
97c8ea81 | 808 | void checkHostnameCorrectness(const DNSResourceRecord& rr); |
a0a276c2 | 809 | #endif |