]>
Commit | Line | Data |
---|---|---|
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 | ||
9 | This program is distributed in the hope that it will be useful, | |
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
12 | GNU General Public License for more details. | |
13 | ||
14 | You should have received a copy of the GNU General Public License | |
15 | along with this program; if not, write to the Free Software | |
06bd9ccf | 16 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
4192ca66 BH |
17 | */ |
18 | ||
a0a276c2 BH |
19 | #ifndef PDNS_DNSRECORDS_HH |
20 | #define PDNS_DNSRECORDS_HH | |
21 | ||
22 | #include "dnsparser.hh" | |
23 | #include "dnswriter.hh" | |
cbf0e7f3 | 24 | #include "rcpgenerator.hh" |
a0a276c2 | 25 | #include <boost/lexical_cast.hpp> |
8c1c9170 BH |
26 | #include <set> |
27 | ||
a0a276c2 | 28 | using namespace std; |
61b26744 | 29 | #include "namespaces.hh" |
a0a276c2 | 30 | |
2770fad0 BH |
31 | #define includeboilerplate(RNAME) RNAME##RecordContent(const DNSRecord& dr, PacketReader& pr); \ |
32 | RNAME##RecordContent(const string& zoneData); \ | |
33 | static void report(void); \ | |
ee1ada80 | 34 | static void unreport(void); \ |
2770fad0 BH |
35 | static DNSRecordContent* make(const DNSRecord &dr, PacketReader& pr); \ |
36 | static DNSRecordContent* make(const string& zonedata); \ | |
37 | string getZoneRepresentation() const; \ | |
38 | void toPacket(DNSPacketWriter& pw); \ | |
39 | template<class Convertor> void xfrPacket(Convertor& conv); | |
a0a276c2 BH |
40 | |
41 | class NAPTRRecordContent : public DNSRecordContent | |
42 | { | |
43 | public: | |
44 | NAPTRRecordContent(uint16_t order, uint16_t preference, string flags, string services, string regexp, string replacement); | |
a0a276c2 | 45 | |
2770fad0 | 46 | includeboilerplate(NAPTR); |
cbf0e7f3 | 47 | template<class Convertor> void xfrRecordContent(Convertor& conv); |
a0a276c2 BH |
48 | private: |
49 | uint16_t d_order, d_preference; | |
50 | string d_flags, d_services, d_regexp, d_replacement; | |
51 | }; | |
52 | ||
2770fad0 | 53 | |
a0a276c2 BH |
54 | class ARecordContent : public DNSRecordContent |
55 | { | |
56 | public: | |
efb265e3 | 57 | explicit ARecordContent(uint32_t ip); |
2770fad0 BH |
58 | includeboilerplate(A); |
59 | void doRecordCheck(const DNSRecord& dr); | |
60 | uint32_t getIP() const; | |
a0a276c2 | 61 | |
2770fad0 BH |
62 | private: |
63 | uint32_t d_ip; | |
64 | }; | |
a0a276c2 | 65 | |
2770fad0 BH |
66 | class MXRecordContent : public DNSRecordContent |
67 | { | |
68 | public: | |
69 | MXRecordContent(uint16_t preference, const string& mxname); | |
a0a276c2 | 70 | |
2770fad0 | 71 | includeboilerplate(MX) |
a0a276c2 BH |
72 | |
73 | private: | |
2770fad0 BH |
74 | uint16_t d_preference; |
75 | string d_mxname; | |
76 | }; | |
77 | ||
9fd71f2e BH |
78 | class KXRecordContent : public DNSRecordContent |
79 | { | |
80 | public: | |
81 | KXRecordContent(uint16_t preference, const string& exchanger); | |
82 | ||
83 | includeboilerplate(KX) | |
84 | ||
85 | private: | |
86 | uint16_t d_preference; | |
87 | string d_exchanger; | |
88 | }; | |
89 | ||
90 | class IPSECKEYRecordContent : public DNSRecordContent | |
91 | { | |
92 | public: | |
93 | IPSECKEYRecordContent(uint16_t preference, uint8_t gatewaytype, uint8_t algo, const std::string& gateway, const std::string &publickey); | |
94 | ||
95 | includeboilerplate(IPSECKEY) | |
96 | ||
97 | private: | |
98 | uint8_t d_preference, d_gatewaytype, d_algorithm; | |
99 | string d_gateway, d_publickey; | |
100 | }; | |
101 | ||
102 | class DHCIDRecordContent : public DNSRecordContent | |
103 | { | |
104 | public: | |
105 | includeboilerplate(DHCID) | |
106 | ||
107 | private: | |
108 | string d_content; | |
109 | }; | |
110 | ||
111 | ||
2770fad0 BH |
112 | class SRVRecordContent : public DNSRecordContent |
113 | { | |
114 | public: | |
115 | SRVRecordContent(uint16_t preference, uint16_t weight, uint16_t port, const string& target); | |
116 | ||
117 | includeboilerplate(SRV) | |
118 | ||
119 | private: | |
120 | uint16_t d_preference, d_weight, d_port; | |
121 | string d_target; | |
122 | }; | |
123 | ||
06ffdc52 BH |
124 | class TSIGRecordContent : public DNSRecordContent |
125 | { | |
126 | public: | |
127 | includeboilerplate(TSIG) | |
0407751c | 128 | TSIGRecordContent() : DNSRecordContent(QType::TSIG) {} |
06ffdc52 BH |
129 | |
130 | string d_algoName; | |
131 | uint64_t d_time; // 48 bits | |
132 | uint16_t d_fudge; | |
133 | // uint16_t d_macSize; | |
134 | string d_mac; | |
135 | uint16_t d_origID; | |
136 | uint16_t d_eRcode; | |
137 | // uint16_t d_otherLen | |
138 | string d_otherData; | |
139 | }; | |
140 | ||
2770fad0 BH |
141 | |
142 | class TXTRecordContent : public DNSRecordContent | |
143 | { | |
144 | public: | |
145 | includeboilerplate(TXT) | |
146 | ||
147 | private: | |
148 | string d_text; | |
a0a276c2 BH |
149 | }; |
150 | ||
8c1c9170 BH |
151 | class SPFRecordContent : public DNSRecordContent |
152 | { | |
153 | public: | |
154 | includeboilerplate(SPF) | |
155 | ||
156 | private: | |
157 | string d_text; | |
158 | }; | |
159 | ||
160 | ||
cbf0e7f3 BH |
161 | class NSRecordContent : public DNSRecordContent |
162 | { | |
163 | public: | |
164 | includeboilerplate(NS) | |
165 | ||
166 | private: | |
167 | string d_content; | |
168 | }; | |
169 | ||
170 | class PTRRecordContent : public DNSRecordContent | |
171 | { | |
172 | public: | |
173 | includeboilerplate(PTR) | |
174 | ||
175 | private: | |
176 | string d_content; | |
177 | }; | |
178 | ||
179 | class CNAMERecordContent : public DNSRecordContent | |
180 | { | |
181 | public: | |
182 | includeboilerplate(CNAME) | |
183 | ||
184 | private: | |
185 | string d_content; | |
186 | }; | |
187 | ||
4e0805a6 BH |
188 | class MRRecordContent : public DNSRecordContent |
189 | { | |
190 | public: | |
191 | includeboilerplate(MR) | |
192 | ||
193 | private: | |
194 | string d_alias; | |
195 | }; | |
196 | ||
cbf0e7f3 | 197 | |
878435ce BH |
198 | class OPTRecordContent : public DNSRecordContent |
199 | { | |
200 | public: | |
201 | includeboilerplate(OPT) | |
7f7b8d55 | 202 | void getData(vector<pair<uint16_t, string> > &opts); |
878435ce BH |
203 | private: |
204 | string d_data; | |
205 | }; | |
206 | ||
207 | ||
cbf0e7f3 BH |
208 | class HINFORecordContent : public DNSRecordContent |
209 | { | |
210 | public: | |
211 | includeboilerplate(HINFO) | |
212 | ||
213 | private: | |
214 | string d_cpu, d_host; | |
215 | }; | |
216 | ||
217 | class RPRecordContent : public DNSRecordContent | |
218 | { | |
219 | public: | |
220 | includeboilerplate(RP) | |
221 | ||
222 | private: | |
223 | string d_mbox, d_info; | |
224 | }; | |
225 | ||
226 | ||
8c1c9170 BH |
227 | class DNSKEYRecordContent : public DNSRecordContent |
228 | { | |
229 | public: | |
1c4d88c5 | 230 | DNSKEYRecordContent(); |
8c1c9170 | 231 | includeboilerplate(DNSKEY) |
1c4d88c5 BH |
232 | uint16_t getTag(); |
233 | string getExponent() const; | |
234 | string getModulus() const; | |
8c1c9170 | 235 | |
8c1c9170 BH |
236 | uint16_t d_flags; |
237 | uint8_t d_protocol; | |
238 | uint8_t d_algorithm; | |
239 | string d_key; | |
1c4d88c5 BH |
240 | private: |
241 | void getExpLen(uint16_t& startPos, uint16_t& expLen) const; | |
8c1c9170 BH |
242 | }; |
243 | ||
244 | class DSRecordContent : public DNSRecordContent | |
245 | { | |
246 | public: | |
1c4d88c5 | 247 | DSRecordContent(); |
8c1c9170 BH |
248 | includeboilerplate(DS) |
249 | ||
8c1c9170 BH |
250 | uint16_t d_tag; |
251 | uint8_t d_algorithm, d_digesttype; | |
252 | string d_digest; | |
253 | }; | |
254 | ||
a40a693b BH |
255 | class SSHFPRecordContent : public DNSRecordContent |
256 | { | |
257 | public: | |
258 | includeboilerplate(SSHFP) | |
259 | ||
260 | private: | |
261 | uint8_t d_algorithm, d_fptype; | |
262 | string d_fingerprint; | |
263 | }; | |
8c1c9170 | 264 | |
4b5762f1 BH |
265 | class KEYRecordContent : public DNSRecordContent |
266 | { | |
267 | public: | |
268 | includeboilerplate(KEY) | |
269 | ||
270 | private: | |
271 | uint16_t d_flags; | |
272 | uint8_t d_protocol, d_algorithm; | |
273 | string d_certificate; | |
274 | }; | |
275 | ||
37f47031 BH |
276 | class AFSDBRecordContent : public DNSRecordContent |
277 | { | |
278 | public: | |
279 | includeboilerplate(AFSDB) | |
280 | ||
281 | private: | |
282 | uint16_t d_subtype; | |
283 | string d_hostname; | |
284 | }; | |
285 | ||
286 | ||
2475a4fc BH |
287 | class CERTRecordContent : public DNSRecordContent |
288 | { | |
289 | public: | |
290 | includeboilerplate(CERT) | |
291 | ||
292 | private: | |
293 | uint16_t d_type, d_tag; | |
294 | uint8_t d_algorithm; | |
295 | string d_certificate; | |
296 | }; | |
297 | ||
8c1c9170 BH |
298 | class RRSIGRecordContent : public DNSRecordContent |
299 | { | |
300 | public: | |
1c4d88c5 | 301 | RRSIGRecordContent(); |
8c1c9170 BH |
302 | includeboilerplate(RRSIG) |
303 | ||
8c1c9170 BH |
304 | uint16_t d_type; |
305 | uint8_t d_algorithm, d_labels; | |
306 | uint32_t d_originalttl, d_sigexpire, d_siginception; | |
307 | uint16_t d_tag; | |
308 | string d_signer, d_signature; | |
309 | }; | |
310 | ||
311 | ||
312 | ||
5ac6a3a3 | 313 | //namespace { |
2770fad0 BH |
314 | struct soatimes |
315 | { | |
316 | uint32_t serial; | |
317 | uint32_t refresh; | |
318 | uint32_t retry; | |
319 | uint32_t expire; | |
320 | uint32_t minimum; | |
321 | }; | |
5ac6a3a3 | 322 | //} |
2770fad0 BH |
323 | |
324 | ||
325 | class SOARecordContent : public DNSRecordContent | |
326 | { | |
327 | public: | |
328 | includeboilerplate(SOA) | |
329 | SOARecordContent(const string& mname, const string& rname, const struct soatimes& st); | |
330 | ||
2770fad0 BH |
331 | string d_mname; |
332 | string d_rname; | |
333 | struct soatimes d_st; | |
334 | }; | |
a0a276c2 | 335 | |
20133c59 BH |
336 | class NSECRecordContent : public DNSRecordContent |
337 | { | |
338 | public: | |
339 | static void report(void); | |
ea634573 | 340 | NSECRecordContent() : DNSRecordContent(47) |
20133c59 | 341 | {} |
20133c59 BH |
342 | NSECRecordContent(const string& content, const string& zone=""); |
343 | ||
344 | static DNSRecordContent* make(const DNSRecord &dr, PacketReader& pr); | |
250d1fd8 | 345 | static DNSRecordContent* make(const string& content); |
20133c59 BH |
346 | string getZoneRepresentation() const; |
347 | void toPacket(DNSPacketWriter& pw); | |
348 | string d_next; | |
349 | std::set<uint16_t> d_set; | |
350 | private: | |
20133c59 BH |
351 | }; |
352 | ||
1c4d88c5 BH |
353 | class NSEC3RecordContent : public DNSRecordContent |
354 | { | |
355 | public: | |
356 | static void report(void); | |
357 | NSEC3RecordContent() : DNSRecordContent(50) | |
358 | {} | |
359 | NSEC3RecordContent(const string& content, const string& zone=""); | |
360 | ||
361 | static DNSRecordContent* make(const DNSRecord &dr, PacketReader& pr); | |
362 | static DNSRecordContent* make(const string& content); | |
363 | string getZoneRepresentation() const; | |
364 | void toPacket(DNSPacketWriter& pw); | |
365 | ||
366 | uint8_t d_algorithm, d_flags; | |
367 | uint16_t d_iterations; | |
368 | uint8_t d_saltlength; | |
369 | string d_salt; | |
370 | uint8_t d_nexthashlength; | |
371 | string d_nexthash; | |
372 | std::set<uint16_t> d_set; | |
373 | ||
374 | private: | |
375 | }; | |
376 | ||
377 | ||
378 | class NSEC3PARAMRecordContent : public DNSRecordContent | |
379 | { | |
380 | public: | |
827634f0 BH |
381 | static void report(void); |
382 | NSEC3PARAMRecordContent() : DNSRecordContent(51) | |
383 | {} | |
384 | NSEC3PARAMRecordContent(const string& content, const string& zone=""); | |
385 | ||
386 | static DNSRecordContent* make(const DNSRecord &dr, PacketReader& pr); | |
387 | static DNSRecordContent* make(const string& content); | |
388 | string getZoneRepresentation() const; | |
389 | void toPacket(DNSPacketWriter& pw); | |
390 | ||
1c4d88c5 BH |
391 | |
392 | uint8_t d_algorithm, d_flags; | |
393 | uint16_t d_iterations; | |
394 | uint8_t d_saltlength; | |
395 | string d_salt; | |
396 | }; | |
397 | ||
398 | ||
c6a60874 BH |
399 | class LOCRecordContent : public DNSRecordContent |
400 | { | |
401 | public: | |
402 | static void report(void); | |
403 | LOCRecordContent() : DNSRecordContent(ns_t_loc) | |
404 | {} | |
405 | LOCRecordContent(const string& content, const string& zone=""); | |
20133c59 | 406 | |
c6a60874 BH |
407 | static DNSRecordContent* make(const DNSRecord &dr, PacketReader& pr); |
408 | static DNSRecordContent* make(const string& content); | |
409 | string getZoneRepresentation() const; | |
410 | void toPacket(DNSPacketWriter& pw); | |
411 | ||
412 | uint8_t d_version, d_size, d_horizpre, d_vertpre; | |
413 | uint32_t d_latitude, d_longitude, d_altitude; | |
414 | ||
415 | private: | |
416 | }; | |
8c1c9170 | 417 | |
afbb76cd BH |
418 | class URLRecordContent : public DNSRecordContent // Fake, 'fancy record' with type 256 |
419 | { | |
420 | public: | |
421 | includeboilerplate(URL) | |
422 | private: | |
423 | string d_url; | |
424 | }; | |
425 | ||
d34d3e01 BH |
426 | class MBOXFWRecordContent : public DNSRecordContent // Fake, 'fancy record' with type 256 |
427 | { | |
428 | public: | |
429 | includeboilerplate(MBOXFW) | |
430 | private: | |
431 | string d_mboxfw; | |
432 | }; | |
433 | ||
434 | ||
8c1c9170 BH |
435 | #define boilerplate(RNAME, RTYPE) \ |
436 | RNAME##RecordContent::DNSRecordContent* RNAME##RecordContent::make(const DNSRecord& dr, PacketReader& pr) \ | |
437 | { \ | |
438 | return new RNAME##RecordContent(dr, pr); \ | |
439 | } \ | |
440 | \ | |
ea634573 | 441 | RNAME##RecordContent::RNAME##RecordContent(const DNSRecord& dr, PacketReader& pr) : DNSRecordContent(RTYPE) \ |
8c1c9170 BH |
442 | { \ |
443 | doRecordCheck(dr); \ | |
444 | xfrPacket(pr); \ | |
445 | } \ | |
446 | \ | |
447 | RNAME##RecordContent::DNSRecordContent* RNAME##RecordContent::make(const string& zonedata) \ | |
448 | { \ | |
449 | return new RNAME##RecordContent(zonedata); \ | |
450 | } \ | |
451 | \ | |
452 | void RNAME##RecordContent::toPacket(DNSPacketWriter& pw) \ | |
453 | { \ | |
454 | this->xfrPacket(pw); \ | |
455 | } \ | |
456 | \ | |
457 | void RNAME##RecordContent::report(void) \ | |
458 | { \ | |
250d1fd8 | 459 | regist(1, RTYPE, &RNAME##RecordContent::make, &RNAME##RecordContent::make, #RNAME); \ |
ee1ada80 BH |
460 | } \ |
461 | void RNAME##RecordContent::unreport(void) \ | |
462 | { \ | |
463 | unregist(1, RTYPE); \ | |
8c1c9170 BH |
464 | } \ |
465 | \ | |
ea634573 | 466 | RNAME##RecordContent::RNAME##RecordContent(const string& zoneData) : DNSRecordContent(RTYPE) \ |
8c1c9170 | 467 | { \ |
aab4adb0 BH |
468 | try { \ |
469 | RecordTextReader rtr(zoneData); \ | |
470 | xfrPacket(rtr); \ | |
471 | } \ | |
472 | catch(RecordTextException& rtr) { \ | |
7b1469bb | 473 | throw MOADNSException("Parsing record content: "+string(rtr.what())); \ |
4957a608 | 474 | } \ |
8c1c9170 BH |
475 | } \ |
476 | \ | |
477 | string RNAME##RecordContent::getZoneRepresentation() const \ | |
478 | { \ | |
479 | string ret; \ | |
480 | RecordTextWriter rtw(ret); \ | |
481 | const_cast<RNAME##RecordContent*>(this)->xfrPacket(rtw); \ | |
482 | return ret; \ | |
483 | } | |
484 | ||
485 | ||
486 | #define boilerplate_conv(RNAME, TYPE, CONV) \ | |
487 | boilerplate(RNAME, TYPE) \ | |
488 | template<class Convertor> \ | |
489 | void RNAME##RecordContent::xfrPacket(Convertor& conv) \ | |
490 | { \ | |
491 | CONV; \ | |
492 | } \ | |
493 | ||
7f7b8d55 BH |
494 | struct EDNSOpts |
495 | { | |
496 | uint16_t d_packetsize; | |
497 | uint8_t d_extRCode, d_version; | |
498 | uint16_t d_Z; | |
499 | vector<pair<uint16_t, string> > d_options; | |
12b33ac2 | 500 | enum zFlags { DNSSECOK=32768 }; |
7f7b8d55 BH |
501 | }; |
502 | //! Convenience function that fills out EDNS0 options, and returns true if there are any | |
503 | ||
504 | class MOADNSParser; | |
505 | bool getEDNSOpts(const MOADNSParser& mdp, EDNSOpts* eo); | |
506 | ||
ea634573 BH |
507 | void reportBasicTypes(); |
508 | void reportOtherTypes(); | |
509 | void reportAllTypes(); | |
afbb76cd | 510 | void reportFancyTypes(); |
ea634573 | 511 | |
a0a276c2 | 512 | #endif |