]> git.ipfire.org Git - thirdparty/pdns.git/blame - pdns/dnsrecords.hh
Merge pull request #1717 from mind04/bind
[thirdparty/pdns.git] / pdns / dnsrecords.hh
CommitLineData
4192ca66
BH
1/*
2 PowerDNS Versatile Database Driven Nameserver
9c92ad4b 3 Copyright (C) 2005 - 2010 PowerDNS.COM BV
4192ca66
BH
4
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License version 2 as
7 published by the Free Software Foundation
8
f782fe38
MH
9 Additionally, the license of this program contains a special
10 exception which allows to distribute the program in binary form when
11 it is linked against OpenSSL.
12
4192ca66
BH
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
06bd9ccf 20 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
4192ca66
BH
21*/
22
a0a276c2
BH
23#ifndef PDNS_DNSRECORDS_HH
24#define PDNS_DNSRECORDS_HH
25
26#include "dnsparser.hh"
27#include "dnswriter.hh"
cbf0e7f3 28#include "rcpgenerator.hh"
a0a276c2 29#include <boost/lexical_cast.hpp>
8c1c9170 30#include <set>
51083cab 31#include <bitset>
8c1c9170 32
10f4eea8 33#include "namespaces.hh"
61b26744 34#include "namespaces.hh"
a0a276c2 35
2770fad0
BH
36#define includeboilerplate(RNAME) RNAME##RecordContent(const DNSRecord& dr, PacketReader& pr); \
37 RNAME##RecordContent(const string& zoneData); \
38 static void report(void); \
ee1ada80 39 static void unreport(void); \
2770fad0
BH
40 static DNSRecordContent* make(const DNSRecord &dr, PacketReader& pr); \
41 static DNSRecordContent* make(const string& zonedata); \
42 string getZoneRepresentation() const; \
43 void toPacket(DNSPacketWriter& pw); \
44 template<class Convertor> void xfrPacket(Convertor& conv);
a0a276c2
BH
45
46class NAPTRRecordContent : public DNSRecordContent
47{
48public:
49 NAPTRRecordContent(uint16_t order, uint16_t preference, string flags, string services, string regexp, string replacement);
a0a276c2 50
2770fad0 51 includeboilerplate(NAPTR);
cbf0e7f3 52 template<class Convertor> void xfrRecordContent(Convertor& conv);
a0a276c2
BH
53private:
54 uint16_t d_order, d_preference;
55 string d_flags, d_services, d_regexp, d_replacement;
56};
57
2770fad0 58
a0a276c2
BH
59class ARecordContent : public DNSRecordContent
60{
61public:
efb265e3 62 explicit ARecordContent(uint32_t ip);
2770fad0
BH
63 includeboilerplate(A);
64 void doRecordCheck(const DNSRecord& dr);
65 uint32_t getIP() const;
a0a276c2 66
2770fad0
BH
67private:
68 uint32_t d_ip;
69};
a0a276c2 70
fc465b41
AT
71class AAAARecordContent : public DNSRecordContent
72{
73public:
74 AAAARecordContent(std::string &val);
75 includeboilerplate(AAAA);
76private:
77 std::string d_ip6;
78};
79
2770fad0
BH
80class MXRecordContent : public DNSRecordContent
81{
82public:
83 MXRecordContent(uint16_t preference, const string& mxname);
a0a276c2 84
2770fad0 85 includeboilerplate(MX)
a0a276c2
BH
86
87private:
2770fad0
BH
88 uint16_t d_preference;
89 string d_mxname;
90};
91
9fd71f2e
BH
92class KXRecordContent : public DNSRecordContent
93{
94public:
95 KXRecordContent(uint16_t preference, const string& exchanger);
96
97 includeboilerplate(KX)
98
99private:
100 uint16_t d_preference;
101 string d_exchanger;
102};
103
104class IPSECKEYRecordContent : public DNSRecordContent
105{
106public:
107 IPSECKEYRecordContent(uint16_t preference, uint8_t gatewaytype, uint8_t algo, const std::string& gateway, const std::string &publickey);
108
109 includeboilerplate(IPSECKEY)
110
111private:
112 uint8_t d_preference, d_gatewaytype, d_algorithm;
113 string d_gateway, d_publickey;
1cafb958
AT
114 uint32_t d_ip4;
115 string d_ip6;
9fd71f2e
BH
116};
117
118class DHCIDRecordContent : public DNSRecordContent
119{
120public:
121 includeboilerplate(DHCID)
122
123private:
124 string d_content;
125};
126
127
2770fad0
BH
128class SRVRecordContent : public DNSRecordContent
129{
130public:
131 SRVRecordContent(uint16_t preference, uint16_t weight, uint16_t port, const string& target);
132
133 includeboilerplate(SRV)
134
135private:
136 uint16_t d_preference, d_weight, d_port;
137 string d_target;
138};
139
06ffdc52
BH
140class TSIGRecordContent : public DNSRecordContent
141{
142public:
143 includeboilerplate(TSIG)
0407751c 144 TSIGRecordContent() : DNSRecordContent(QType::TSIG) {}
06ffdc52
BH
145
146 string d_algoName;
147 uint64_t d_time; // 48 bits
148 uint16_t d_fudge;
149 // uint16_t d_macSize;
150 string d_mac;
151 uint16_t d_origID;
152 uint16_t d_eRcode;
153 // uint16_t d_otherLen
154 string d_otherData;
155};
156
2770fad0
BH
157
158class TXTRecordContent : public DNSRecordContent
159{
160public:
161 includeboilerplate(TXT)
162
163private:
164 string d_text;
a0a276c2
BH
165};
166
8c1c9170
BH
167class SPFRecordContent : public DNSRecordContent
168{
169public:
170 includeboilerplate(SPF)
171
172private:
173 string d_text;
174};
175
176
cbf0e7f3
BH
177class NSRecordContent : public DNSRecordContent
178{
179public:
180 includeboilerplate(NS)
181
182private:
183 string d_content;
184};
185
186class PTRRecordContent : public DNSRecordContent
187{
188public:
189 includeboilerplate(PTR)
190
191private:
192 string d_content;
193};
194
195class CNAMERecordContent : public DNSRecordContent
196{
197public:
198 includeboilerplate(CNAME)
199
200private:
201 string d_content;
202};
203
8dee0750 204class DNAMERecordContent : public DNSRecordContent
205{
206public:
207 includeboilerplate(DNAME)
208
209private:
210 string d_content;
211};
212
213
4e0805a6
BH
214class MRRecordContent : public DNSRecordContent
215{
216public:
217 includeboilerplate(MR)
218
219private:
220 string d_alias;
221};
222
7c0b8593 223class MINFORecordContent : public DNSRecordContent
224{
225public:
226 includeboilerplate(MINFO)
227
228private:
229 string d_rmailbx;
230 string d_emailbx;
231};
cbf0e7f3 232
878435ce
BH
233class OPTRecordContent : public DNSRecordContent
234{
235public:
236 includeboilerplate(OPT)
7f7b8d55 237 void getData(vector<pair<uint16_t, string> > &opts);
878435ce
BH
238private:
239 string d_data;
240};
241
242
cbf0e7f3
BH
243class HINFORecordContent : public DNSRecordContent
244{
245public:
246 includeboilerplate(HINFO)
247
248private:
249 string d_cpu, d_host;
250};
251
252class RPRecordContent : public DNSRecordContent
253{
254public:
255 includeboilerplate(RP)
256
257private:
258 string d_mbox, d_info;
259};
260
261
8c1c9170
BH
262class DNSKEYRecordContent : public DNSRecordContent
263{
264public:
1c4d88c5 265 DNSKEYRecordContent();
8c1c9170 266 includeboilerplate(DNSKEY)
1c4d88c5 267 uint16_t getTag();
8c1c9170 268
8c1c9170
BH
269 uint16_t d_flags;
270 uint8_t d_protocol;
271 uint8_t d_algorithm;
272 string d_key;
273};
274
275class DSRecordContent : public DNSRecordContent
276{
277public:
1c4d88c5 278 DSRecordContent();
8c1c9170
BH
279 includeboilerplate(DS)
280
8c1c9170
BH
281 uint16_t d_tag;
282 uint8_t d_algorithm, d_digesttype;
283 string d_digest;
284};
285
0b55f2f5
BH
286class DLVRecordContent : public DNSRecordContent
287{
288public:
289 DLVRecordContent();
290 includeboilerplate(DLV)
291
292 uint16_t d_tag;
293 uint8_t d_algorithm, d_digesttype;
294 string d_digest;
295};
296
297
a40a693b
BH
298class SSHFPRecordContent : public DNSRecordContent
299{
300public:
301 includeboilerplate(SSHFP)
302
303private:
304 uint8_t d_algorithm, d_fptype;
305 string d_fingerprint;
306};
8c1c9170 307
4b5762f1
BH
308class KEYRecordContent : public DNSRecordContent
309{
310public:
311 includeboilerplate(KEY)
312
313private:
314 uint16_t d_flags;
315 uint8_t d_protocol, d_algorithm;
316 string d_certificate;
317};
318
37f47031
BH
319class AFSDBRecordContent : public DNSRecordContent
320{
321public:
322 includeboilerplate(AFSDB)
323
324private:
325 uint16_t d_subtype;
326 string d_hostname;
327};
328
329
2475a4fc
BH
330class CERTRecordContent : public DNSRecordContent
331{
332public:
333 includeboilerplate(CERT)
334
335private:
336 uint16_t d_type, d_tag;
337 uint8_t d_algorithm;
338 string d_certificate;
339};
340
07dbe87e
BH
341class TLSARecordContent : public DNSRecordContent
342{
343public:
344 includeboilerplate(TLSA)
345
346private:
f5a09796 347 uint8_t d_certusage, d_selector, d_matchtype;
07dbe87e
BH
348 string d_cert;
349};
350
351
8c1c9170
BH
352class RRSIGRecordContent : public DNSRecordContent
353{
354public:
1c4d88c5 355 RRSIGRecordContent();
8c1c9170
BH
356 includeboilerplate(RRSIG)
357
8c1c9170
BH
358 uint16_t d_type;
359 uint8_t d_algorithm, d_labels;
360 uint32_t d_originalttl, d_sigexpire, d_siginception;
361 uint16_t d_tag;
362 string d_signer, d_signature;
363};
364
365
366
5ac6a3a3 367//namespace {
2770fad0
BH
368 struct soatimes
369 {
370 uint32_t serial;
371 uint32_t refresh;
372 uint32_t retry;
373 uint32_t expire;
374 uint32_t minimum;
375 };
5ac6a3a3 376//}
2770fad0 377
3150a49c 378class RKEYRecordContent : public DNSRecordContent
379{
380public:
381 RKEYRecordContent();
382 includeboilerplate(RKEY)
383 uint16_t d_flags;
384 uint8_t d_protocol, d_algorithm;
385 string d_key;
386};
2770fad0
BH
387
388class SOARecordContent : public DNSRecordContent
389{
390public:
391 includeboilerplate(SOA)
392 SOARecordContent(const string& mname, const string& rname, const struct soatimes& st);
393
2770fad0
BH
394 string d_mname;
395 string d_rname;
396 struct soatimes d_st;
397};
a0a276c2 398
20133c59
BH
399class NSECRecordContent : public DNSRecordContent
400{
401public:
402 static void report(void);
ea634573 403 NSECRecordContent() : DNSRecordContent(47)
20133c59 404 {}
20133c59
BH
405 NSECRecordContent(const string& content, const string& zone="");
406
407 static DNSRecordContent* make(const DNSRecord &dr, PacketReader& pr);
250d1fd8 408 static DNSRecordContent* make(const string& content);
20133c59
BH
409 string getZoneRepresentation() const;
410 void toPacket(DNSPacketWriter& pw);
411 string d_next;
412 std::set<uint16_t> d_set;
413private:
20133c59
BH
414};
415
1c4d88c5
BH
416class NSEC3RecordContent : public DNSRecordContent
417{
418public:
419 static void report(void);
420 NSEC3RecordContent() : DNSRecordContent(50)
421 {}
422 NSEC3RecordContent(const string& content, const string& zone="");
423
424 static DNSRecordContent* make(const DNSRecord &dr, PacketReader& pr);
425 static DNSRecordContent* make(const string& content);
426 string getZoneRepresentation() const;
427 void toPacket(DNSPacketWriter& pw);
428
429 uint8_t d_algorithm, d_flags;
430 uint16_t d_iterations;
431 uint8_t d_saltlength;
432 string d_salt;
433 uint8_t d_nexthashlength;
434 string d_nexthash;
435 std::set<uint16_t> d_set;
436
437private:
438};
439
440
441class NSEC3PARAMRecordContent : public DNSRecordContent
442{
443public:
827634f0
BH
444 static void report(void);
445 NSEC3PARAMRecordContent() : DNSRecordContent(51)
446 {}
447 NSEC3PARAMRecordContent(const string& content, const string& zone="");
448
449 static DNSRecordContent* make(const DNSRecord &dr, PacketReader& pr);
450 static DNSRecordContent* make(const string& content);
451 string getZoneRepresentation() const;
452 void toPacket(DNSPacketWriter& pw);
453
1c4d88c5
BH
454
455 uint8_t d_algorithm, d_flags;
456 uint16_t d_iterations;
457 uint8_t d_saltlength;
458 string d_salt;
459};
460
461
c6a60874
BH
462class LOCRecordContent : public DNSRecordContent
463{
464public:
465 static void report(void);
466 LOCRecordContent() : DNSRecordContent(ns_t_loc)
467 {}
468 LOCRecordContent(const string& content, const string& zone="");
20133c59 469
c6a60874
BH
470 static DNSRecordContent* make(const DNSRecord &dr, PacketReader& pr);
471 static DNSRecordContent* make(const string& content);
472 string getZoneRepresentation() const;
473 void toPacket(DNSPacketWriter& pw);
474
475 uint8_t d_version, d_size, d_horizpre, d_vertpre;
476 uint32_t d_latitude, d_longitude, d_altitude;
477
478private:
479};
8c1c9170 480
51083cab
BH
481
482class WKSRecordContent : public DNSRecordContent
483{
484public:
485 static void report(void);
486 WKSRecordContent() : DNSRecordContent(ns_t_wks)
487 {}
488 WKSRecordContent(const string& content, const string& zone="");
489
490 static DNSRecordContent* make(const DNSRecord &dr, PacketReader& pr);
491 static DNSRecordContent* make(const string& content);
492 string getZoneRepresentation() const;
493 void toPacket(DNSPacketWriter& pw);
494
495 uint32_t d_ip;
496 std::bitset<65535> d_services;
497private:
498};
499
500
afbb76cd
BH
501class URLRecordContent : public DNSRecordContent // Fake, 'fancy record' with type 256
502{
503public:
504 includeboilerplate(URL)
505private:
506 string d_url;
507};
508
d34d3e01
BH
509class MBOXFWRecordContent : public DNSRecordContent // Fake, 'fancy record' with type 256
510{
511public:
512 includeboilerplate(MBOXFW)
513private:
514 string d_mboxfw;
515};
516
66a07c55
AT
517class EUI48RecordContent : public DNSRecordContent
518{
519public:
520 EUI48RecordContent() : DNSRecordContent(ns_t_eui48) {};
521 static void report(void);
522 static DNSRecordContent* make(const DNSRecord &dr, PacketReader& pr);
523 static DNSRecordContent* make(const string& zone);
524 void toPacket(DNSPacketWriter& pw);
525 string getZoneRepresentation() const;
526private:
527 // storage for the bytes
528 uint8_t d_eui48[6];
529};
530
531class EUI64RecordContent : public DNSRecordContent
532{
533public:
534 EUI64RecordContent() : DNSRecordContent(ns_t_eui64) {};
535 static void report(void);
536 static DNSRecordContent* make(const DNSRecord &dr, PacketReader& pr);
537 static DNSRecordContent* make(const string& zone);
538 void toPacket(DNSPacketWriter& pw);
539 string getZoneRepresentation() const;
540private:
541 // storage for the bytes
542 uint8_t d_eui64[8];
543};
d34d3e01 544
8c1c9170
BH
545#define boilerplate(RNAME, RTYPE) \
546RNAME##RecordContent::DNSRecordContent* RNAME##RecordContent::make(const DNSRecord& dr, PacketReader& pr) \
547{ \
548 return new RNAME##RecordContent(dr, pr); \
549} \
550 \
ea634573 551RNAME##RecordContent::RNAME##RecordContent(const DNSRecord& dr, PacketReader& pr) : DNSRecordContent(RTYPE) \
8c1c9170
BH
552{ \
553 doRecordCheck(dr); \
554 xfrPacket(pr); \
555} \
556 \
557RNAME##RecordContent::DNSRecordContent* RNAME##RecordContent::make(const string& zonedata) \
558{ \
559 return new RNAME##RecordContent(zonedata); \
560} \
561 \
562void RNAME##RecordContent::toPacket(DNSPacketWriter& pw) \
563{ \
564 this->xfrPacket(pw); \
565} \
566 \
567void RNAME##RecordContent::report(void) \
568{ \
250d1fd8 569 regist(1, RTYPE, &RNAME##RecordContent::make, &RNAME##RecordContent::make, #RNAME); \
d6f3feee 570 regist(254, RTYPE, &RNAME##RecordContent::make, &RNAME##RecordContent::make, #RNAME); \
ee1ada80
BH
571} \
572void RNAME##RecordContent::unreport(void) \
573{ \
574 unregist(1, RTYPE); \
d6f3feee 575 unregist(254, RTYPE); \
8c1c9170
BH
576} \
577 \
ea634573 578RNAME##RecordContent::RNAME##RecordContent(const string& zoneData) : DNSRecordContent(RTYPE) \
8c1c9170 579{ \
aab4adb0
BH
580 try { \
581 RecordTextReader rtr(zoneData); \
582 xfrPacket(rtr); \
583 } \
584 catch(RecordTextException& rtr) { \
7b1469bb 585 throw MOADNSException("Parsing record content: "+string(rtr.what())); \
4957a608 586 } \
8c1c9170
BH
587} \
588 \
589string RNAME##RecordContent::getZoneRepresentation() const \
590{ \
591 string ret; \
592 RecordTextWriter rtw(ret); \
593 const_cast<RNAME##RecordContent*>(this)->xfrPacket(rtw); \
594 return ret; \
595}
596
597
598#define boilerplate_conv(RNAME, TYPE, CONV) \
599boilerplate(RNAME, TYPE) \
600template<class Convertor> \
601void RNAME##RecordContent::xfrPacket(Convertor& conv) \
602{ \
603 CONV; \
d476d7fb 604 if (conv.eof() == false) throw MOADNSException("All data was not consumed"); \
8c1c9170
BH
605} \
606
7f7b8d55
BH
607struct EDNSOpts
608{
609 uint16_t d_packetsize;
610 uint8_t d_extRCode, d_version;
611 uint16_t d_Z;
612 vector<pair<uint16_t, string> > d_options;
12b33ac2 613 enum zFlags { DNSSECOK=32768 };
7f7b8d55
BH
614};
615//! Convenience function that fills out EDNS0 options, and returns true if there are any
616
617class MOADNSParser;
618bool getEDNSOpts(const MOADNSParser& mdp, EDNSOpts* eo);
619
ea634573
BH
620void reportBasicTypes();
621void reportOtherTypes();
622void reportAllTypes();
afbb76cd 623void reportFancyTypes();
ea634573 624
a0a276c2 625#endif