]> git.ipfire.org Git - thirdparty/pdns.git/blob - pdns/dnsrecords.hh
Use a bitset for NSEC(3) records with lots of types
[thirdparty/pdns.git] / pdns / dnsrecords.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_DNSRECORDS_HH
23 #define PDNS_DNSRECORDS_HH
24
25 #ifdef HAVE_CONFIG_H
26 #include "config.h"
27 #endif
28
29 #include "dnsparser.hh"
30 #include "dnswriter.hh"
31 #include "rcpgenerator.hh"
32 #include <set>
33 #include <bitset>
34 #include "namespaces.hh"
35 #include "iputils.hh"
36
37 #define includeboilerplate(RNAME) RNAME##RecordContent(const DNSRecord& dr, PacketReader& pr); \
38 RNAME##RecordContent(const string& zoneData); \
39 static void report(void); \
40 static void unreport(void); \
41 static std::shared_ptr<DNSRecordContent> make(const DNSRecord &dr, PacketReader& pr); \
42 static std::shared_ptr<DNSRecordContent> make(const string& zonedata); \
43 string getZoneRepresentation(bool noDot=false) const override; \
44 void toPacket(DNSPacketWriter& pw) override; \
45 uint16_t getType() const override { return QType::RNAME; } \
46 template<class Convertor> void xfrPacket(Convertor& conv, bool noDot=false);
47
48 class NAPTRRecordContent : public DNSRecordContent
49 {
50 public:
51 NAPTRRecordContent(uint16_t order, uint16_t preference, string flags, string services, string regexp, DNSName replacement);
52
53 includeboilerplate(NAPTR)
54 template<class Convertor> void xfrRecordContent(Convertor& conv);
55 private:
56 uint16_t d_order, d_preference;
57 string d_flags, d_services, d_regexp;
58 DNSName d_replacement;
59 };
60
61
62 class ARecordContent : public DNSRecordContent
63 {
64 public:
65 explicit ARecordContent(const ComboAddress& ca);
66 explicit ARecordContent(uint32_t ip);
67 includeboilerplate(A)
68 void doRecordCheck(const DNSRecord& dr);
69 ComboAddress getCA(int port=0) const;
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 }
76 private:
77 uint32_t d_ip;
78 };
79
80 class AAAARecordContent : public DNSRecordContent
81 {
82 public:
83 AAAARecordContent(std::string &val);
84 explicit AAAARecordContent(const ComboAddress& ca);
85 includeboilerplate(AAAA)
86 ComboAddress getCA(int port=0) const;
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 }
93 private:
94 string d_ip6; // why??
95 };
96
97 class MXRecordContent : public DNSRecordContent
98 {
99 public:
100 MXRecordContent(uint16_t preference, const DNSName& mxname);
101
102 includeboilerplate(MX)
103
104 uint16_t d_preference;
105 DNSName d_mxname;
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
115 };
116
117 class KXRecordContent : public DNSRecordContent
118 {
119 public:
120 KXRecordContent(uint16_t preference, const DNSName& exchanger);
121
122 includeboilerplate(KX)
123
124 private:
125 uint16_t d_preference;
126 DNSName d_exchanger;
127 };
128
129 class IPSECKEYRecordContent : public DNSRecordContent
130 {
131 public:
132 IPSECKEYRecordContent(uint16_t preference, uint8_t gatewaytype, uint8_t algo, const DNSName& gateway, const string& publickey);
133
134 includeboilerplate(IPSECKEY)
135
136 private:
137 uint32_t d_ip4;
138 DNSName d_gateway;
139 string d_publickey;
140 string d_ip6;
141 uint8_t d_preference, d_gatewaytype, d_algorithm;
142 };
143
144 class DHCIDRecordContent : public DNSRecordContent
145 {
146 public:
147 includeboilerplate(DHCID)
148
149 private:
150 string d_content;
151 };
152
153
154 class SRVRecordContent : public DNSRecordContent
155 {
156 public:
157 SRVRecordContent(uint16_t preference, uint16_t weight, uint16_t port, const DNSName& target);
158
159 includeboilerplate(SRV)
160
161 uint16_t d_weight, d_port;
162 DNSName d_target;
163 uint16_t d_preference;
164 };
165
166 class TSIGRecordContent : public DNSRecordContent
167 {
168 public:
169 includeboilerplate(TSIG)
170 TSIGRecordContent() {}
171
172 uint16_t d_origID{0};
173 uint16_t d_fudge{0};
174
175 DNSName d_algoName;
176 string d_mac;
177 string d_otherData;
178 uint64_t d_time{0};
179 // uint16_t d_macSize;
180 uint16_t d_eRcode{0};
181 // uint16_t d_otherLen
182 };
183
184
185 class TXTRecordContent : public DNSRecordContent
186 {
187 public:
188 includeboilerplate(TXT)
189
190 string d_text;
191 };
192
193 #ifdef HAVE_LUA_RECORDS
194 class LUARecordContent : public DNSRecordContent
195 {
196 public:
197 includeboilerplate(LUA)
198 string getCode() const;
199 uint16_t d_type;
200 string d_code;
201 };
202 #endif
203
204 class ENTRecordContent : public DNSRecordContent
205 {
206 public:
207 includeboilerplate(ENT)
208 };
209
210 class SPFRecordContent : public DNSRecordContent
211 {
212 public:
213 includeboilerplate(SPF)
214 const std::string& getText() const
215 {
216 return d_text;
217 }
218
219 private:
220 string d_text;
221 };
222
223
224 class NSRecordContent : public DNSRecordContent
225 {
226 public:
227 includeboilerplate(NS)
228 explicit NSRecordContent(const DNSName& content) : d_content(content){}
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
238 private:
239 DNSName d_content;
240 };
241
242 class PTRRecordContent : public DNSRecordContent
243 {
244 public:
245 includeboilerplate(PTR)
246 explicit PTRRecordContent(const DNSName& content) : d_content(content){}
247 const DNSName& getContent() const { return d_content; }
248 private:
249 DNSName d_content;
250 };
251
252 class CNAMERecordContent : public DNSRecordContent
253 {
254 public:
255 includeboilerplate(CNAME)
256 CNAMERecordContent(const DNSName& content) : d_content(content){}
257 DNSName getTarget() const { return d_content; }
258 private:
259 DNSName d_content;
260 };
261
262 class ALIASRecordContent : public DNSRecordContent
263 {
264 public:
265 includeboilerplate(ALIAS)
266
267 DNSName d_content;
268 };
269
270
271 class DNAMERecordContent : public DNSRecordContent
272 {
273 public:
274 includeboilerplate(DNAME)
275 DNSName d_content;
276 };
277
278
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
297 class MRRecordContent : public DNSRecordContent
298 {
299 public:
300 includeboilerplate(MR)
301
302 private:
303 DNSName d_alias;
304 };
305
306 class MINFORecordContent : public DNSRecordContent
307 {
308 public:
309 includeboilerplate(MINFO)
310
311 private:
312 DNSName d_rmailbx;
313 DNSName d_emailbx;
314 };
315
316 class OPTRecordContent : public DNSRecordContent
317 {
318 public:
319 OPTRecordContent(){}
320 includeboilerplate(OPT)
321 void getData(vector<pair<uint16_t, string> > &opts);
322 private:
323 string d_data;
324 };
325
326
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:
342 DNSName d_mbox, d_info;
343 };
344
345
346 class DNSKEYRecordContent : public DNSRecordContent
347 {
348 public:
349 DNSKEYRecordContent();
350 includeboilerplate(DNSKEY)
351 uint16_t getTag() const;
352 uint16_t getTag();
353
354 uint16_t d_flags{0};
355 uint8_t d_protocol{0};
356 uint8_t d_algorithm{0};
357 string d_key;
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 }
363 };
364
365 class CDNSKEYRecordContent : public DNSRecordContent
366 {
367 public:
368 CDNSKEYRecordContent();
369 includeboilerplate(CDNSKEY)
370 uint16_t getTag();
371
372 uint16_t d_flags{0};
373 uint8_t d_protocol{0};
374 uint8_t d_algorithm{0};
375 string d_key;
376 };
377
378 class DSRecordContent : public DNSRecordContent
379 {
380 public:
381 DSRecordContent();
382 bool operator==(const DNSRecordContent& rhs) const override
383 {
384 if(typeid(*this) != typeid(rhs))
385 return false;
386 auto rrhs =dynamic_cast<const decltype(this)>(&rhs);
387 return tie(d_tag, d_algorithm, d_digesttype, d_digest) ==
388 tie(rrhs->d_tag, rrhs->d_algorithm, rrhs->d_digesttype, rrhs->d_digest);
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
396 includeboilerplate(DS)
397
398 uint16_t d_tag{0};
399 uint8_t d_algorithm{0}, d_digesttype{0};
400 string d_digest;
401 };
402
403 class CDSRecordContent : public DNSRecordContent
404 {
405 public:
406 CDSRecordContent();
407 includeboilerplate(CDS)
408
409 uint16_t d_tag{0};
410 uint8_t d_algorithm{0}, d_digesttype{0};
411 string d_digest;
412 };
413
414 class DLVRecordContent : public DNSRecordContent
415 {
416 public:
417 DLVRecordContent();
418 includeboilerplate(DLV)
419
420 uint16_t d_tag{0};
421 uint8_t d_algorithm{0}, d_digesttype{0};
422 string d_digest;
423 };
424
425
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 };
435
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
447 class AFSDBRecordContent : public DNSRecordContent
448 {
449 public:
450 includeboilerplate(AFSDB)
451
452 private:
453 uint16_t d_subtype;
454 DNSName d_hostname;
455 };
456
457
458 class CERTRecordContent : public DNSRecordContent
459 {
460 public:
461 includeboilerplate(CERT)
462
463 private:
464 uint16_t d_type, d_tag;
465 string d_certificate;
466 uint8_t d_algorithm;
467 };
468
469 class TLSARecordContent : public DNSRecordContent
470 {
471 public:
472 includeboilerplate(TLSA)
473
474 private:
475 uint8_t d_certusage, d_selector, d_matchtype;
476 string d_cert;
477 };
478
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
489 class OPENPGPKEYRecordContent : public DNSRecordContent
490 {
491 public:
492 includeboilerplate(OPENPGPKEY)
493
494 private:
495 string d_keyring;
496 };
497
498
499 class RRSIGRecordContent : public DNSRecordContent
500 {
501 public:
502 RRSIGRecordContent();
503 includeboilerplate(RRSIG)
504
505 uint16_t d_type{0};
506 uint16_t d_tag{0};
507 DNSName d_signer;
508 string d_signature;
509 uint32_t d_originalttl{0}, d_sigexpire{0}, d_siginception{0};
510 uint8_t d_algorithm{0}, d_labels{0};
511 };
512
513 //namespace {
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 };
522 //}
523
524 class RKEYRecordContent : public DNSRecordContent
525 {
526 public:
527 RKEYRecordContent();
528 includeboilerplate(RKEY)
529 uint16_t d_flags{0};
530 uint8_t d_protocol{0}, d_algorithm{0};
531 string d_key;
532 };
533
534 class SOARecordContent : public DNSRecordContent
535 {
536 public:
537 includeboilerplate(SOA)
538 SOARecordContent(const DNSName& mname, const DNSName& rname, const struct soatimes& st);
539
540 DNSName d_mname;
541 DNSName d_rname;
542 struct soatimes d_st;
543 };
544
545 class NSECBitmap
546 {
547 public:
548 bool isSet(uint16_t type) const
549 {
550 if (d_bitset) {
551 return d_bitset->test(type);
552 }
553 return d_set.count(type);
554 }
555 void set(uint16_t type)
556 {
557 if (!d_bitset) {
558 if (d_set.size() >= 200) {
559 migrateToBitSet();
560 }
561 }
562 if (d_bitset) {
563 d_bitset->set(type);
564 }
565 else {
566 d_set.insert(type);
567 }
568 }
569 size_t count() const
570 {
571 if (d_bitset) {
572 return d_bitset->count();
573 }
574 else {
575 return d_set.size();
576 }
577 }
578
579 void fromPacket(PacketReader& pr);
580 void toPacket(DNSPacketWriter& pw);
581 std::string getZoneRepresentation() const;
582
583 private:
584 void migrateToBitSet()
585 {
586 d_bitset = std::unique_ptr<std::bitset<65536>>(new std::bitset<65536>());
587 for (const auto& type : d_set) {
588 d_bitset->set(type);
589 }
590 d_set.clear();
591 }
592 /* using a dynamic set is very efficient for a small number of
593 types covered (~200), but uses a lot of memory (up to 3MB)
594 when there are a lot of them.
595 So we start with the set, but allocate and switch to a bitset
596 if the number of covered types increases a lot */
597 std::unique_ptr<std::bitset<65536>> d_bitset;
598 std::set<uint16_t> d_set;
599 };
600
601 class NSECRecordContent : public DNSRecordContent
602 {
603 public:
604 static void report(void);
605 NSECRecordContent()
606 {}
607 NSECRecordContent(const string& content, const string& zone=""); //FIXME400: DNSName& zone?
608
609 static std::shared_ptr<DNSRecordContent> make(const DNSRecord &dr, PacketReader& pr);
610 static std::shared_ptr<DNSRecordContent> make(const string& content);
611 string getZoneRepresentation(bool noDot=false) const override;
612 void toPacket(DNSPacketWriter& pw) override;
613 uint16_t getType() const override
614 {
615 return QType::NSEC;
616 }
617 bool isSet(uint16_t type) const
618 {
619 return d_bitmap.isSet(type);
620 }
621 void set(uint16_t type)
622 {
623 d_bitmap.set(type);
624 }
625 size_t numberOfTypesSet() const
626 {
627 return d_bitmap.count();
628 }
629
630 DNSName d_next;
631 private:
632 NSECBitmap d_bitmap;
633 };
634
635 class NSEC3RecordContent : public DNSRecordContent
636 {
637 public:
638 static void report(void);
639 NSEC3RecordContent()
640 {}
641 NSEC3RecordContent(const string& content, const string& zone=""); //FIXME400: DNSName& zone?
642
643 static std::shared_ptr<DNSRecordContent> make(const DNSRecord &dr, PacketReader& pr);
644 static std::shared_ptr<DNSRecordContent> make(const string& content);
645 string getZoneRepresentation(bool noDot=false) const override;
646 void toPacket(DNSPacketWriter& pw) override;
647
648 uint8_t d_algorithm{0}, d_flags{0};
649 uint16_t d_iterations{0};
650 string d_salt;
651 string d_nexthash;
652
653 uint16_t getType() const override
654 {
655 return QType::NSEC3;
656 }
657 bool isSet(uint16_t type) const
658 {
659 return d_bitmap.isSet(type);
660 }
661 void set(uint16_t type)
662 {
663 d_bitmap.set(type);
664 }
665 size_t numberOfTypesSet() const
666 {
667 return d_bitmap.count();
668 }
669
670 private:
671 NSECBitmap d_bitmap;
672 };
673
674
675 class NSEC3PARAMRecordContent : public DNSRecordContent
676 {
677 public:
678 static void report(void);
679 NSEC3PARAMRecordContent()
680 {}
681 NSEC3PARAMRecordContent(const string& content, const string& zone=""); // FIXME400: DNSName& zone?
682
683 static std::shared_ptr<DNSRecordContent> make(const DNSRecord &dr, PacketReader& pr);
684 static std::shared_ptr<DNSRecordContent> make(const string& content);
685 string getZoneRepresentation(bool noDot=false) const override;
686 void toPacket(DNSPacketWriter& pw) override;
687
688 uint16_t getType() const override
689 {
690 return QType::NSEC3PARAM;
691 }
692
693
694 uint8_t d_algorithm{0}, d_flags{0};
695 uint16_t d_iterations{0};
696 string d_salt;
697 };
698
699
700 class LOCRecordContent : public DNSRecordContent
701 {
702 public:
703 static void report(void);
704 LOCRecordContent()
705 {}
706 LOCRecordContent(const string& content, const string& zone="");
707
708 static std::shared_ptr<DNSRecordContent> make(const DNSRecord &dr, PacketReader& pr);
709 static std::shared_ptr<DNSRecordContent> make(const string& content);
710 string getZoneRepresentation(bool noDot=false) const override;
711 void toPacket(DNSPacketWriter& pw) override;
712
713 uint8_t d_version{0}, d_size{0}, d_horizpre{0}, d_vertpre{0};
714 uint32_t d_latitude{0}, d_longitude{0}, d_altitude{0};
715 uint16_t getType() const override
716 {
717 return QType::LOC;
718 }
719
720 private:
721 };
722
723
724 class WKSRecordContent : public DNSRecordContent
725 {
726 public:
727 static void report(void);
728 WKSRecordContent()
729 {}
730 WKSRecordContent(const string& content, const string& zone=""); // FIXME400: DNSName& zone?
731
732 static std::shared_ptr<DNSRecordContent> make(const DNSRecord &dr, PacketReader& pr);
733 static std::shared_ptr<DNSRecordContent> make(const string& content);
734 string getZoneRepresentation(bool noDot=false) const override;
735 void toPacket(DNSPacketWriter& pw) override;
736
737 uint32_t d_ip{0};
738 std::bitset<65535> d_services;
739 private:
740 };
741
742 class EUI48RecordContent : public DNSRecordContent
743 {
744 public:
745 EUI48RecordContent() {};
746 static void report(void);
747 static std::shared_ptr<DNSRecordContent> make(const DNSRecord &dr, PacketReader& pr);
748 static std::shared_ptr<DNSRecordContent> make(const string& zone); // FIXME400: DNSName& zone?
749 string getZoneRepresentation(bool noDot=false) const override;
750 void toPacket(DNSPacketWriter& pw) override;
751 uint16_t getType() const override { return QType::EUI48; }
752 private:
753 // storage for the bytes
754 uint8_t d_eui48[6];
755 };
756
757 class EUI64RecordContent : public DNSRecordContent
758 {
759 public:
760 EUI64RecordContent() {};
761 static void report(void);
762 static std::shared_ptr<DNSRecordContent> make(const DNSRecord &dr, PacketReader& pr);
763 static std::shared_ptr<DNSRecordContent> make(const string& zone); // FIXME400: DNSName& zone?
764 string getZoneRepresentation(bool noDot=false) const override;
765 void toPacket(DNSPacketWriter& pw) override;
766 uint16_t getType() const override { return QType::EUI64; }
767 private:
768 // storage for the bytes
769 uint8_t d_eui64[8];
770 };
771
772 class TKEYRecordContent : public DNSRecordContent
773 {
774 public:
775 TKEYRecordContent();
776 includeboilerplate(TKEY)
777
778 // storage for the bytes
779 uint16_t d_othersize{0};
780 uint16_t d_mode{0};
781 uint32_t d_inception{0};
782 uint32_t d_expiration{0};
783
784 DNSName d_algo;
785 string d_key;
786 string d_other;
787
788 uint16_t d_error{0};
789 uint16_t d_keysize{0};
790 private:
791 };
792
793 class URIRecordContent : public DNSRecordContent {
794 public:
795 includeboilerplate(URI)
796 private:
797 uint16_t d_priority, d_weight;
798 string d_target;
799 };
800
801 class CAARecordContent : public DNSRecordContent {
802 public:
803 includeboilerplate(CAA)
804 private:
805 uint8_t d_flags;
806 string d_tag, d_value;
807 };
808
809 #define boilerplate(RNAME, RTYPE) \
810 std::shared_ptr<RNAME##RecordContent::DNSRecordContent> RNAME##RecordContent::make(const DNSRecord& dr, PacketReader& pr) \
811 { \
812 return std::make_shared<RNAME##RecordContent>(dr, pr); \
813 } \
814 \
815 RNAME##RecordContent::RNAME##RecordContent(const DNSRecord& dr, PacketReader& pr) \
816 { \
817 doRecordCheck(dr); \
818 xfrPacket(pr); \
819 } \
820 \
821 std::shared_ptr<RNAME##RecordContent::DNSRecordContent> RNAME##RecordContent::make(const string& zonedata) \
822 { \
823 return std::make_shared<RNAME##RecordContent>(zonedata); \
824 } \
825 \
826 void RNAME##RecordContent::toPacket(DNSPacketWriter& pw) \
827 { \
828 this->xfrPacket(pw); \
829 } \
830 \
831 void RNAME##RecordContent::report(void) \
832 { \
833 regist(1, RTYPE, &RNAME##RecordContent::make, &RNAME##RecordContent::make, #RNAME); \
834 regist(254, RTYPE, &RNAME##RecordContent::make, &RNAME##RecordContent::make, #RNAME); \
835 } \
836 void RNAME##RecordContent::unreport(void) \
837 { \
838 unregist(1, RTYPE); \
839 unregist(254, RTYPE); \
840 } \
841 \
842 RNAME##RecordContent::RNAME##RecordContent(const string& zoneData) \
843 { \
844 try { \
845 RecordTextReader rtr(zoneData); \
846 xfrPacket(rtr); \
847 } \
848 catch(RecordTextException& rte) { \
849 throw MOADNSException("Parsing record content (try 'pdnsutil check-zone'): "+string(rte.what())); \
850 } \
851 } \
852 \
853 string RNAME##RecordContent::getZoneRepresentation(bool noDot) const \
854 { \
855 string ret; \
856 RecordTextWriter rtw(ret, noDot); \
857 const_cast<RNAME##RecordContent*>(this)->xfrPacket(rtw); \
858 return ret; \
859 }
860
861
862 #define boilerplate_conv(RNAME, TYPE, CONV) \
863 boilerplate(RNAME, TYPE) \
864 template<class Convertor> \
865 void RNAME##RecordContent::xfrPacket(Convertor& conv, bool noDot) \
866 { \
867 CONV; \
868 if (conv.eof() == false) throw MOADNSException("When parsing " #RNAME " trailing data was not parsed: '" + conv.getRemaining() + "'"); \
869 } \
870
871 struct EDNSOpts
872 {
873 enum zFlags { DNSSECOK=32768 };
874 vector<pair<uint16_t, string> > d_options;
875 uint16_t d_packetsize{0};
876 uint16_t d_extFlags{0};
877 uint8_t d_extRCode, d_version;
878 };
879 //! Convenience function that fills out EDNS0 options, and returns true if there are any
880
881 class MOADNSParser;
882 bool getEDNSOpts(const MOADNSParser& mdp, EDNSOpts* eo);
883 DNSRecord makeOpt(const uint16_t udpsize, const uint16_t extRCode, const uint16_t extFlags);
884 void reportBasicTypes();
885 void reportOtherTypes();
886 void reportAllTypes();
887 ComboAddress getAddr(const DNSRecord& dr, uint16_t defport=0);
888 void checkHostnameCorrectness(const DNSResourceRecord& rr);
889 #endif