Disconnect hostapd from building in base
[dragonfly.git] / contrib / ldns / rr.c
CommitLineData
825eb42b
JL
1/* rr.c
2 *
3 * access functions for ldns_rr -
4 * a Net::DNS like library for C
5 * LibDNS Team @ NLnet Labs
6 *
7 * (c) NLnet Labs, 2004-2006
8 * See the file LICENSE for the license
9 */
10#include <ldns/config.h>
11
12#include <ldns/ldns.h>
13
14#include <strings.h>
15#include <limits.h>
16
17#include <errno.h>
18
19#define LDNS_SYNTAX_DATALEN 16
20#define LDNS_TTL_DATALEN 21
21#define LDNS_RRLIST_INIT 8
22
23ldns_rr *
24ldns_rr_new(void)
25{
26 ldns_rr *rr;
27 rr = LDNS_MALLOC(ldns_rr);
28 if (!rr) {
29 return NULL;
30 }
31
32 ldns_rr_set_owner(rr, NULL);
33 ldns_rr_set_question(rr, false);
34 ldns_rr_set_rd_count(rr, 0);
35 rr->_rdata_fields = NULL;
36 ldns_rr_set_class(rr, LDNS_RR_CLASS_IN);
37 ldns_rr_set_ttl(rr, LDNS_DEFAULT_TTL);
38 return rr;
39}
40
41ldns_rr *
42ldns_rr_new_frm_type(ldns_rr_type t)
43{
44 ldns_rr *rr;
45 const ldns_rr_descriptor *desc;
46 size_t i;
47
48 rr = LDNS_MALLOC(ldns_rr);
49 if (!rr) {
50 return NULL;
51 }
52
53 desc = ldns_rr_descript(t);
54
55 rr->_rdata_fields = LDNS_XMALLOC(ldns_rdf *, ldns_rr_descriptor_minimum(desc));
fd185f4d
JL
56 if(!rr->_rdata_fields) {
57 LDNS_FREE(rr);
58 return NULL;
59 }
825eb42b
JL
60 for (i = 0; i < ldns_rr_descriptor_minimum(desc); i++) {
61 rr->_rdata_fields[i] = NULL;
62 }
63
64 ldns_rr_set_owner(rr, NULL);
65 ldns_rr_set_question(rr, false);
66 /* set the count to minimum */
67 ldns_rr_set_rd_count(rr, ldns_rr_descriptor_minimum(desc));
68 ldns_rr_set_class(rr, LDNS_RR_CLASS_IN);
69 ldns_rr_set_ttl(rr, LDNS_DEFAULT_TTL);
70 ldns_rr_set_type(rr, t);
71 return rr;
72}
73
74void
75ldns_rr_free(ldns_rr *rr)
76{
77 size_t i;
78 if (rr) {
79 if (ldns_rr_owner(rr)) {
80 ldns_rdf_deep_free(ldns_rr_owner(rr));
81 }
82 for (i = 0; i < ldns_rr_rd_count(rr); i++) {
83 ldns_rdf_deep_free(ldns_rr_rdf(rr, i));
84 }
85 LDNS_FREE(rr->_rdata_fields);
86 LDNS_FREE(rr);
87 }
88}
89
90/*
91 * trailing spaces are allowed
92 * leading spaces are not allowed
93 * allow ttl to be optional
94 * class is optional too
95 * if ttl is missing, and default_ttl is 0, use DEF_TTL
96 * allow ttl to be written as 1d3h
97 * So the RR should look like. e.g.
98 * miek.nl. 3600 IN MX 10 elektron.atoom.net
99 * or
100 * miek.nl. 1h IN MX 10 elektron.atoom.net
101 * or
102 * miek.nl. IN MX 10 elektron.atoom.net
103 */
104static ldns_status
105ldns_rr_new_frm_str_internal(ldns_rr **newrr, const char *str,
106 uint32_t default_ttl, ldns_rdf *origin,
107 ldns_rdf **prev, bool question)
108{
109 ldns_rr *new;
110 const ldns_rr_descriptor *desc;
111 ldns_rr_type rr_type;
fd185f4d
JL
112 ldns_buffer *rr_buf = NULL;
113 ldns_buffer *rd_buf = NULL;
825eb42b 114 uint32_t ttl_val;
fd185f4d
JL
115 char *owner = NULL;
116 char *ttl = NULL;
825eb42b 117 ldns_rr_class clas_val;
fd185f4d 118 char *clas = NULL;
825eb42b 119 char *type = NULL;
fd185f4d
JL
120 char *rdata = NULL;
121 char *rd = NULL;
d1b2b5ca 122 char * b64 = NULL;
825eb42b
JL
123 size_t rd_strlen;
124 const char *delimiters;
125 ssize_t c;
126 ldns_rdf *owner_dname;
ac996e71
JL
127 const char* endptr;
128 int was_unknown_rr_format = 0;
fd185f4d 129 ldns_status status = LDNS_STATUS_OK;
825eb42b
JL
130
131 /* used for types with unknown number of rdatas */
132 bool done;
133 bool quoted;
134
135 ldns_rdf *r = NULL;
136 uint16_t r_cnt;
137 uint16_t r_min;
138 uint16_t r_max;
ac996e71 139 size_t pre_data_pos;
825eb42b
JL
140
141 new = ldns_rr_new();
142
143 owner = LDNS_XMALLOC(char, LDNS_MAX_DOMAINLEN + 1);
144 ttl = LDNS_XMALLOC(char, LDNS_TTL_DATALEN);
145 clas = LDNS_XMALLOC(char, LDNS_SYNTAX_DATALEN);
146 rdata = LDNS_XMALLOC(char, LDNS_MAX_PACKETLEN + 1);
147 rr_buf = LDNS_MALLOC(ldns_buffer);
148 rd_buf = LDNS_MALLOC(ldns_buffer);
149 rd = LDNS_XMALLOC(char, LDNS_MAX_RDFLEN);
150 b64 = LDNS_XMALLOC(char, LDNS_MAX_RDFLEN);
151 if (!new || !owner || !ttl || !clas || !rdata || !rr_buf || !rd_buf || !rd || !b64 ) {
fd185f4d
JL
152 status = LDNS_STATUS_MEM_ERR;
153 LDNS_FREE(rr_buf);
154 goto ldnserror;
825eb42b 155 }
825eb42b
JL
156
157 ldns_buffer_new_frm_data(rr_buf, (char*)str, strlen(str));
158
159 /* split the rr in its parts -1 signals trouble */
160 if (ldns_bget_token(rr_buf, owner, "\t\n ", LDNS_MAX_DOMAINLEN) == -1) {
fd185f4d 161 status = LDNS_STATUS_SYNTAX_ERR;
825eb42b 162 ldns_buffer_free(rr_buf);
fd185f4d 163 goto ldnserror;
825eb42b
JL
164 }
165
166 if (ldns_bget_token(rr_buf, ttl, "\t\n ", LDNS_TTL_DATALEN) == -1) {
fd185f4d 167 status = LDNS_STATUS_SYNTAX_TTL_ERR;
825eb42b 168 ldns_buffer_free(rr_buf);
fd185f4d 169 goto ldnserror;
825eb42b
JL
170 }
171 ttl_val = (uint32_t) ldns_str2period(ttl, &endptr);
172
173 if (strlen(ttl) > 0 && !isdigit((int) ttl[0])) {
174 /* ah, it's not there or something */
175 if (default_ttl == 0) {
176 ttl_val = LDNS_DEFAULT_TTL;
177 } else {
178 ttl_val = default_ttl;
179 }
180 /* we not ASSUMING the TTL is missing and that
181 * the rest of the RR is still there. That is
182 * CLASS TYPE RDATA
183 * so ttl value we read is actually the class
184 */
185 clas_val = ldns_get_rr_class_by_name(ttl);
186 /* class can be left out too, assume IN, current
187 * token must be type
188 */
189 if (clas_val == 0) {
190 clas_val = LDNS_RR_CLASS_IN;
191 type = LDNS_XMALLOC(char, strlen(ttl) + 1);
fd185f4d
JL
192 if(!type) {
193 status = LDNS_STATUS_MEM_ERR;
194 ldns_buffer_free(rr_buf);
195 goto ldnserror;
196 }
825eb42b
JL
197 strncpy(type, ttl, strlen(ttl) + 1);
198 }
199 } else {
200 if (ldns_bget_token(rr_buf, clas, "\t\n ", LDNS_SYNTAX_DATALEN) == -1) {
fd185f4d 201 status = LDNS_STATUS_SYNTAX_CLASS_ERR;
825eb42b 202 ldns_buffer_free(rr_buf);
fd185f4d 203 goto ldnserror;
825eb42b
JL
204 }
205 clas_val = ldns_get_rr_class_by_name(clas);
206 /* class can be left out too, assume IN, current
207 * token must be type
208 */
209 if (clas_val == 0) {
210 clas_val = LDNS_RR_CLASS_IN;
211 type = LDNS_XMALLOC(char, strlen(clas) + 1);
fd185f4d
JL
212 if(!type) {
213 status = LDNS_STATUS_MEM_ERR;
214 ldns_buffer_free(rr_buf);
215 goto ldnserror;
216 }
825eb42b
JL
217 strncpy(type, clas, strlen(clas) + 1);
218 }
219 }
220 /* the rest should still be waiting for us */
221
222 if (!type) {
223 type = LDNS_XMALLOC(char, LDNS_SYNTAX_DATALEN);
fd185f4d
JL
224 if(!type) {
225 status = LDNS_STATUS_MEM_ERR;
226 ldns_buffer_free(rr_buf);
227 goto ldnserror;
228 }
825eb42b 229 if (ldns_bget_token(rr_buf, type, "\t\n ", LDNS_SYNTAX_DATALEN) == -1) {
fd185f4d 230 status = LDNS_STATUS_SYNTAX_TYPE_ERR;
825eb42b 231 ldns_buffer_free(rr_buf);
fd185f4d 232 goto ldnserror;
825eb42b
JL
233 }
234 }
235
236 if (ldns_bget_token(rr_buf, rdata, "\0", LDNS_MAX_PACKETLEN) == -1) {
237 /* apparently we are done, and it's only a question RR
fd185f4d 238 * so do not set status and go to ldnserror here
825eb42b
JL
239 */
240 }
241
242 ldns_buffer_new_frm_data(rd_buf, rdata, strlen(rdata));
243
244 if (strlen(owner) <= 1 && strncmp(owner, "@", 1) == 0) {
245 if (origin) {
246 ldns_rr_set_owner(new, ldns_rdf_clone(origin));
247 } else if (prev && *prev) {
248 ldns_rr_set_owner(new, ldns_rdf_clone(*prev));
249 } else {
250 /* default to root */
251 ldns_rr_set_owner(new, ldns_dname_new_frm_str("."));
252 }
253
254 /* @ also overrides prev */
255 if (prev) {
256 ldns_rdf_deep_free(*prev);
257 *prev = ldns_rdf_clone(ldns_rr_owner(new));
fd185f4d
JL
258 if (!*prev) {
259 status = LDNS_STATUS_MEM_ERR;
260 ldns_buffer_free(rr_buf);
261 goto ldnserror;
262 }
825eb42b
JL
263 }
264 } else {
265 if (strlen(owner) == 0) {
266 /* no ownername was given, try prev, if that fails
267 * origin, else default to root */
268 if (prev && *prev) {
269 ldns_rr_set_owner(new, ldns_rdf_clone(*prev));
270 } else if (origin) {
271 ldns_rr_set_owner(new, ldns_rdf_clone(origin));
272 } else {
273 ldns_rr_set_owner(new, ldns_dname_new_frm_str("."));
274 }
fd185f4d
JL
275 if(!ldns_rr_owner(new)) {
276 status = LDNS_STATUS_MEM_ERR;
277 ldns_buffer_free(rr_buf);
278 goto ldnserror;
279 }
825eb42b
JL
280 } else {
281 owner_dname = ldns_dname_new_frm_str(owner);
282 if (!owner_dname) {
fd185f4d
JL
283 status = LDNS_STATUS_SYNTAX_ERR;
284 ldns_buffer_free(rr_buf);
285 goto ldnserror;
825eb42b
JL
286 }
287
288 ldns_rr_set_owner(new, owner_dname);
289 if (!ldns_dname_str_absolute(owner) && origin) {
290 if(ldns_dname_cat(ldns_rr_owner(new),
291 origin) != LDNS_STATUS_OK) {
fd185f4d 292 status = LDNS_STATUS_SYNTAX_ERR;
825eb42b 293 ldns_buffer_free(rr_buf);
fd185f4d 294 goto ldnserror;
825eb42b
JL
295 }
296 }
297 if (prev) {
298 ldns_rdf_deep_free(*prev);
299 *prev = ldns_rdf_clone(ldns_rr_owner(new));
fd185f4d
JL
300 if(!*prev) {
301 status = LDNS_STATUS_MEM_ERR;
302 ldns_buffer_free(rr_buf);
303 goto ldnserror;
304 }
825eb42b
JL
305 }
306 }
307 }
308 LDNS_FREE(owner);
fd185f4d 309 owner = NULL;
825eb42b
JL
310
311 ldns_rr_set_question(new, question);
312
313 ldns_rr_set_ttl(new, ttl_val);
314 LDNS_FREE(ttl);
fd185f4d 315 ttl = NULL;
825eb42b
JL
316
317 ldns_rr_set_class(new, clas_val);
318 LDNS_FREE(clas);
fd185f4d 319 clas = NULL;
825eb42b
JL
320
321 rr_type = ldns_get_rr_type_by_name(type);
322 LDNS_FREE(type);
fd185f4d 323 type = NULL;
825eb42b
JL
324
325 desc = ldns_rr_descript((uint16_t)rr_type);
326 ldns_rr_set_type(new, rr_type);
327 if (desc) {
328 /* only the rdata remains */
329 r_max = ldns_rr_descriptor_maximum(desc);
330 r_min = ldns_rr_descriptor_minimum(desc);
331 } else {
332 r_min = 0;
333 r_max = 1;
334 }
335
336 /* depending on the rr_type we need to extract
337 * the rdata differently, e.g. NSEC/NSEC3 */
338 switch(rr_type) {
339 default:
340 done = false;
341
342 for (r_cnt = 0; !done && r_cnt < r_max; r_cnt++) {
343 quoted = false;
344 /* if type = B64, the field may contain spaces */
345 if (ldns_rr_descriptor_field_type(desc,
346 r_cnt) == LDNS_RDF_TYPE_B64 ||
347 ldns_rr_descriptor_field_type(desc,
348 r_cnt) == LDNS_RDF_TYPE_HEX ||
349 ldns_rr_descriptor_field_type(desc,
350 r_cnt) == LDNS_RDF_TYPE_LOC ||
351 ldns_rr_descriptor_field_type(desc,
352 r_cnt) == LDNS_RDF_TYPE_WKS ||
353 ldns_rr_descriptor_field_type(desc,
354 r_cnt) == LDNS_RDF_TYPE_IPSECKEY ||
355 ldns_rr_descriptor_field_type(desc,
356 r_cnt) == LDNS_RDF_TYPE_NSEC) {
357 delimiters = "\n\t";
358 } else {
359 delimiters = "\n\t ";
360 }
361
362 if (ldns_rr_descriptor_field_type(desc,
363 r_cnt) == LDNS_RDF_TYPE_STR &&
364 ldns_buffer_remaining(rd_buf) > 0) {
365 /* skip spaces */
366 while (*(ldns_buffer_current(rd_buf)) == ' ') {
367 ldns_buffer_skip(rd_buf, 1);
368 }
369
370 if (*(ldns_buffer_current(rd_buf)) == '\"') {
371 delimiters = "\"\0";
372 ldns_buffer_skip(rd_buf, 1);
373 quoted = true;
374 }
375 }
376
377 /* because number of fields can be variable, we can't
378 rely on _maximum() only */
379 /* skip spaces */
380 while (ldns_buffer_position(rd_buf) < ldns_buffer_limit(rd_buf) &&
fd185f4d 381 *(ldns_buffer_current(rd_buf)) == ' ' && !quoted
825eb42b
JL
382 ) {
383 ldns_buffer_skip(rd_buf, 1);
384 }
385
ac996e71 386 pre_data_pos = ldns_buffer_position(rd_buf);
825eb42b
JL
387 if ((c = ldns_bget_token(rd_buf, rd, delimiters,
388 LDNS_MAX_RDFLEN)) != -1) {
389 /* hmmz, rfc3597 specifies that any type can be represented with
390 * \# method, which can contain spaces...
391 * it does specify size though...
392 */
393 rd_strlen = strlen(rd);
394
395 /* unknown RR data */
ac996e71
JL
396 if (strncmp(rd, "\\#", 2) == 0 && !quoted && (rd_strlen == 2 || rd[2]==' ')) {
397 uint16_t hex_data_size;
398 char *hex_data_str;
399 uint16_t cur_hex_data_size;
400
401 was_unknown_rr_format = 1;
402 /* go back to before \# and skip it while setting delimiters better */
403 ldns_buffer_set_position(rd_buf, pre_data_pos);
404 delimiters = "\n\t ";
405 (void)ldns_bget_token(rd_buf, rd, delimiters, LDNS_MAX_RDFLEN);
406 /* read rdata octet length */
825eb42b
JL
407 c = ldns_bget_token(rd_buf, rd, delimiters, LDNS_MAX_RDFLEN);
408 if (c == -1) {
409 /* something goes very wrong here */
fd185f4d
JL
410 LDNS_FREE(rd);
411 LDNS_FREE(b64);
412 ldns_buffer_free(rd_buf);
413 ldns_buffer_free(rr_buf);
414 LDNS_FREE(rdata);
415 ldns_rr_free(new);
825eb42b
JL
416 return LDNS_STATUS_SYNTAX_RDATA_ERR;
417 }
418 hex_data_size = (uint16_t) atoi(rd);
419 /* copy the hex chars into hex str (which is 2 chars per byte) */
420 hex_data_str = LDNS_XMALLOC(char, 2 * hex_data_size + 1);
421 if (!hex_data_str) {
422 /* malloc error */
fd185f4d
JL
423 LDNS_FREE(rd);
424 LDNS_FREE(b64);
425 ldns_buffer_free(rd_buf);
426 ldns_buffer_free(rr_buf);
427 LDNS_FREE(rdata);
428 ldns_rr_free(new);
825eb42b
JL
429 return LDNS_STATUS_SYNTAX_RDATA_ERR;
430 }
431 cur_hex_data_size = 0;
432 while(cur_hex_data_size < 2 * hex_data_size) {
433 c = ldns_bget_token(rd_buf, rd, delimiters, LDNS_MAX_RDFLEN);
b5dedcca
JL
434 if (c != -1) {
435 rd_strlen = strlen(rd);
436 }
437 if (c == -1 || (size_t)cur_hex_data_size + rd_strlen > 2 * (size_t)hex_data_size) {
438 LDNS_FREE(hex_data_str);
439 LDNS_FREE(rd);
440 LDNS_FREE(b64);
441 ldns_buffer_free(rd_buf);
442 ldns_buffer_free(rr_buf);
443 LDNS_FREE(rdata);
444 ldns_rr_free(new);
445 return LDNS_STATUS_SYNTAX_RDATA_ERR;
446 }
825eb42b
JL
447 strncpy(hex_data_str + cur_hex_data_size, rd, rd_strlen);
448 cur_hex_data_size += rd_strlen;
449 }
450 hex_data_str[cur_hex_data_size] = '\0';
451
452 /* correct the rdf type */
453 /* if *we* know the type, interpret it as wireformat */
454 if (desc) {
ac996e71
JL
455 size_t hex_pos = 0;
456 uint8_t *hex_data = LDNS_XMALLOC(uint8_t, hex_data_size + 2);
fd185f4d
JL
457 ldns_status s;
458 if(!hex_data) {
459 LDNS_FREE(hex_data_str);
460 LDNS_FREE(rd);
461 LDNS_FREE(b64);
462 ldns_buffer_free(rd_buf);
463 ldns_buffer_free(rr_buf);
464 LDNS_FREE(rdata);
465 ldns_rr_free(new);
466 return LDNS_STATUS_MEM_ERR;
467 }
825eb42b
JL
468 ldns_write_uint16(hex_data, hex_data_size);
469 ldns_hexstring_to_data(hex_data + 2, hex_data_str);
fd185f4d 470 s = ldns_wire2rdf(new, hex_data,
825eb42b 471 hex_data_size+2, &hex_pos);
fd185f4d
JL
472 if(s != LDNS_STATUS_OK) {
473 LDNS_FREE(hex_data_str);
474 LDNS_FREE(rd);
475 LDNS_FREE(b64);
476 ldns_buffer_free(rd_buf);
477 ldns_buffer_free(rr_buf);
478 LDNS_FREE(rdata);
479 ldns_rr_free(new);
d1b2b5ca 480 LDNS_FREE(hex_data);
fd185f4d
JL
481 return s;
482 }
825eb42b
JL
483 LDNS_FREE(hex_data);
484 } else {
485 r = ldns_rdf_new_frm_str(LDNS_RDF_TYPE_HEX, hex_data_str);
fd185f4d
JL
486 if(!r) {
487 LDNS_FREE(hex_data_str);
488 LDNS_FREE(rd);
489 LDNS_FREE(b64);
490 ldns_buffer_free(rd_buf);
491 ldns_buffer_free(rr_buf);
492 LDNS_FREE(rdata);
493 ldns_rr_free(new);
494 return LDNS_STATUS_MEM_ERR;
495 }
825eb42b 496 ldns_rdf_set_type(r, LDNS_RDF_TYPE_UNKNOWN);
fd185f4d
JL
497 if(!ldns_rr_push_rdf(new, r)) {
498 LDNS_FREE(hex_data_str);
499 LDNS_FREE(rd);
500 LDNS_FREE(b64);
501 ldns_buffer_free(rd_buf);
502 ldns_buffer_free(rr_buf);
503 LDNS_FREE(rdata);
504 ldns_rr_free(new);
505 return LDNS_STATUS_MEM_ERR;
506 }
825eb42b
JL
507 }
508 LDNS_FREE(hex_data_str);
509 } else {
510 /* Normal RR */
511 switch(ldns_rr_descriptor_field_type(desc, r_cnt)) {
512 case LDNS_RDF_TYPE_HEX:
513 case LDNS_RDF_TYPE_B64:
514 /* can have spaces, and will always be the last
515 * record of the rrdata. Read in the rest */
516 if ((c = ldns_bget_token(rd_buf,
517 b64,
518 "\n",
519 LDNS_MAX_RDFLEN))
520 != -1) {
521 rd = strncat(rd,
522 b64,
523 LDNS_MAX_RDFLEN
524 - strlen(rd) - 1);
525 }
526 r = ldns_rdf_new_frm_str(
527 ldns_rr_descriptor_field_type(desc, r_cnt),
528 rd);
529 break;
530 case LDNS_RDF_TYPE_DNAME:
531 r = ldns_rdf_new_frm_str(
532 ldns_rr_descriptor_field_type(desc, r_cnt),
533 rd);
534
535 /* check if the origin should be used or concatenated */
536 if (r && ldns_rdf_size(r) > 1 && ldns_rdf_data(r)[0] == 1
537 && ldns_rdf_data(r)[1] == '@') {
538 ldns_rdf_deep_free(r);
539 if (origin) {
540 r = ldns_rdf_clone(origin);
541 } else {
542 /* if this is the SOA, use its own owner name */
543 if (rr_type == LDNS_RR_TYPE_SOA) {
544 r = ldns_rdf_clone(ldns_rr_owner(new));
545 } else {
546 r = ldns_rdf_new_frm_str(LDNS_RDF_TYPE_DNAME, ".");
547 }
548 }
549 } else if (r && rd_strlen >= 1 && !ldns_dname_str_absolute(rd) && origin) {
550 if (ldns_dname_cat(r, origin) != LDNS_STATUS_OK) {
fd185f4d
JL
551 LDNS_FREE(rd);
552 LDNS_FREE(b64);
553 ldns_buffer_free(rd_buf);
554 ldns_buffer_free(rr_buf);
555 LDNS_FREE(rdata);
556 ldns_rr_free(new);
825eb42b
JL
557 return LDNS_STATUS_ERR;
558 }
559 }
560 break;
561 default:
562 r = ldns_rdf_new_frm_str(
563 ldns_rr_descriptor_field_type(desc, r_cnt),
564 rd);
565 break;
566 }
567 if (r) {
568 ldns_rr_push_rdf(new, r);
569 } else {
570 LDNS_FREE(rd);
571 LDNS_FREE(b64);
572 ldns_buffer_free(rd_buf);
573 ldns_buffer_free(rr_buf);
574 LDNS_FREE(rdata);
575 ldns_rr_free(new);
576 return LDNS_STATUS_SYNTAX_RDATA_ERR;
577 }
578 }
579 if (quoted) {
580 if (ldns_buffer_available(rd_buf, 1)) {
581 ldns_buffer_skip(rd_buf, 1);
582 } else {
583 done = true;
584 }
585 }
586 } else {
587 done = true;
588 }
589 }
590 }
591 LDNS_FREE(rd);
592 LDNS_FREE(b64);
593 ldns_buffer_free(rd_buf);
594 ldns_buffer_free(rr_buf);
595 LDNS_FREE(rdata);
596
ac996e71 597 if (!question && desc && !was_unknown_rr_format && ldns_rr_rd_count(new) < r_min) {
825eb42b
JL
598 ldns_rr_free(new);
599 return LDNS_STATUS_SYNTAX_MISSING_VALUE_ERR;
600 }
601
602 if (newrr) {
603 *newrr = new;
d1b2b5ca
JM
604 } else {
605 /* Maybe the caller just wanted to see if it would parse? */
606 ldns_rr_free(new);
825eb42b
JL
607 }
608 return LDNS_STATUS_OK;
fd185f4d
JL
609
610ldnserror:
611 LDNS_FREE(type);
612 LDNS_FREE(owner);
613 LDNS_FREE(ttl);
614 LDNS_FREE(clas);
615 LDNS_FREE(rdata);
616 LDNS_FREE(rd);
617 LDNS_FREE(rd_buf);
618 LDNS_FREE(b64);
619 ldns_rr_free(new);
620 return status;
825eb42b
JL
621}
622
623ldns_status
624ldns_rr_new_frm_str(ldns_rr **newrr, const char *str,
625 uint32_t default_ttl, ldns_rdf *origin,
626 ldns_rdf **prev)
627{
628 return ldns_rr_new_frm_str_internal(newrr,
629 str,
630 default_ttl,
631 origin,
632 prev,
633 false);
634}
635
636ldns_status
637ldns_rr_new_question_frm_str(ldns_rr **newrr, const char *str,
638 ldns_rdf *origin, ldns_rdf **prev)
639{
640 return ldns_rr_new_frm_str_internal(newrr,
641 str,
642 0,
643 origin,
644 prev,
645 true);
646}
647
648ldns_status
649ldns_rr_new_frm_fp(ldns_rr **newrr, FILE *fp, uint32_t *ttl, ldns_rdf **origin, ldns_rdf **prev)
650{
651 return ldns_rr_new_frm_fp_l(newrr, fp, ttl, origin, prev, NULL);
652}
653
654ldns_status
655ldns_rr_new_frm_fp_l(ldns_rr **newrr, FILE *fp, uint32_t *default_ttl, ldns_rdf **origin, ldns_rdf **prev, int *line_nr)
656{
657 char *line;
658 const char *endptr; /* unused */
659 ldns_rr *rr;
825eb42b
JL
660 uint32_t ttl;
661 ldns_rdf *tmp;
662 ldns_status s;
663 ssize_t size;
ac996e71 664 int offset = 0;
825eb42b 665
825eb42b
JL
666 if (default_ttl) {
667 ttl = *default_ttl;
668 } else {
669 ttl = 0;
670 }
671
672 line = LDNS_XMALLOC(char, LDNS_MAX_LINELEN + 1);
673 if (!line) {
674 return LDNS_STATUS_MEM_ERR;
675 }
676
677 /* read an entire line in from the file */
678 if ((size = ldns_fget_token_l(fp, line, LDNS_PARSE_SKIP_SPACE, LDNS_MAX_LINELEN, line_nr)) == -1) {
679 LDNS_FREE(line);
680 /* if last line was empty, we are now at feof, which is not
681 * always a parse error (happens when for instance last line
682 * was a comment)
683 */
684 return LDNS_STATUS_SYNTAX_ERR;
685 }
686
687 /* we can have the situation, where we've read ok, but still got
688 * no bytes to play with, in this case size is 0
689 */
690 if (size == 0) {
691 LDNS_FREE(line);
692 return LDNS_STATUS_SYNTAX_EMPTY;
693 }
694
ac996e71 695 if (strncmp(line, "$ORIGIN", 7) == 0 && isspace(line[7])) {
825eb42b
JL
696 if (*origin) {
697 ldns_rdf_deep_free(*origin);
698 *origin = NULL;
699 }
ac996e71
JL
700 offset = 8;
701 while (isspace(line[offset])) {
702 offset++;
703 }
704 tmp = ldns_rdf_new_frm_str(LDNS_RDF_TYPE_DNAME, line + offset);
825eb42b
JL
705 if (!tmp) {
706 /* could not parse what next to $ORIGIN */
707 LDNS_FREE(line);
708 return LDNS_STATUS_SYNTAX_DNAME_ERR;
709 }
710 *origin = tmp;
711 s = LDNS_STATUS_SYNTAX_ORIGIN;
ac996e71
JL
712 } else if (strncmp(line, "$TTL", 4) == 0 && isspace(line[4])) {
713 offset = 5;
714 while (isspace(line[offset])) {
715 offset++;
716 }
825eb42b 717 if (default_ttl) {
ac996e71 718 *default_ttl = ldns_str2period(line + offset, &endptr);
825eb42b
JL
719 }
720 s = LDNS_STATUS_SYNTAX_TTL;
ac996e71
JL
721 } else if (strncmp(line, "$INCLUDE", 8) == 0) {
722 s = LDNS_STATUS_SYNTAX_INCLUDE;
825eb42b
JL
723 } else {
724 if (origin && *origin) {
725 s = ldns_rr_new_frm_str(&rr, (const char*) line, ttl, *origin, prev);
726 } else {
727 s = ldns_rr_new_frm_str(&rr, (const char*) line, ttl, NULL, prev);
728 }
729 }
730 LDNS_FREE(line);
d1b2b5ca
JM
731 if (s == LDNS_STATUS_OK) {
732 if (newrr) {
733 *newrr = rr;
734 } else {
735 /* Just testing if it would parse? */
736 ldns_rr_free(rr);
737 }
825eb42b
JL
738 }
739 return s;
740}
741
742void
743ldns_rr_set_owner(ldns_rr *rr, ldns_rdf *owner)
744{
745 rr->_owner = owner;
746}
747
748void
749ldns_rr_set_question(ldns_rr *rr, bool question)
750{
751 rr->_rr_question = question;
752}
753
754void
755ldns_rr_set_ttl(ldns_rr *rr, uint32_t ttl)
756{
757 rr->_ttl = ttl;
758}
759
760void
761ldns_rr_set_rd_count(ldns_rr *rr, size_t count)
762{
763 rr->_rd_count = count;
764}
765
766void
767ldns_rr_set_type(ldns_rr *rr, ldns_rr_type rr_type)
768{
769 rr->_rr_type = rr_type;
770}
771
772void
773ldns_rr_set_class(ldns_rr *rr, ldns_rr_class rr_class)
774{
775 rr->_rr_class = rr_class;
776}
777
778ldns_rdf *
779ldns_rr_set_rdf(ldns_rr *rr, const ldns_rdf *f, size_t position)
780{
781 size_t rd_count;
782 ldns_rdf *pop;
825eb42b
JL
783
784 rd_count = ldns_rr_rd_count(rr);
785 if (position < rd_count) {
825eb42b
JL
786 /* dicard the old one */
787 pop = rr->_rdata_fields[position];
788 rr->_rdata_fields[position] = (ldns_rdf*)f;
789 return pop;
790 } else {
791 return NULL;
792 }
793}
794
795bool
796ldns_rr_push_rdf(ldns_rr *rr, const ldns_rdf *f)
797{
798 size_t rd_count;
799 ldns_rdf **rdata_fields;
800
801 rd_count = ldns_rr_rd_count(rr);
802
803 /* grow the array */
804 rdata_fields = LDNS_XREALLOC(
805 rr->_rdata_fields, ldns_rdf *, rd_count + 1);
806 if (!rdata_fields) {
807 return false;
808 }
809
810 /* add the new member */
811 rr->_rdata_fields = rdata_fields;
812 rr->_rdata_fields[rd_count] = (ldns_rdf*)f;
813
814 ldns_rr_set_rd_count(rr, rd_count + 1);
815 return true;
816}
817
818ldns_rdf *
819ldns_rr_pop_rdf(ldns_rr *rr)
820{
821 size_t rd_count;
822 ldns_rdf *pop;
ac996e71 823 ldns_rdf** newrd;
825eb42b
JL
824
825 rd_count = ldns_rr_rd_count(rr);
826
827 if (rd_count == 0) {
828 return NULL;
829 }
830
831 pop = rr->_rdata_fields[rd_count - 1];
832
ac996e71
JL
833 /* try to shrink the array */
834 if(rd_count > 1) {
835 newrd = LDNS_XREALLOC(
836 rr->_rdata_fields, ldns_rdf *, rd_count - 1);
837 if(newrd)
838 rr->_rdata_fields = newrd;
839 } else {
840 LDNS_FREE(rr->_rdata_fields);
841 }
825eb42b
JL
842
843 ldns_rr_set_rd_count(rr, rd_count - 1);
844 return pop;
845}
846
847ldns_rdf *
848ldns_rr_rdf(const ldns_rr *rr, size_t nr)
849{
b5dedcca 850 if (rr && nr < ldns_rr_rd_count(rr)) {
825eb42b
JL
851 return rr->_rdata_fields[nr];
852 } else {
853 return NULL;
854 }
855}
856
857ldns_rdf *
858ldns_rr_owner(const ldns_rr *rr)
859{
860 return rr->_owner;
861}
862
863bool
864ldns_rr_is_question(const ldns_rr *rr)
865{
866 return rr->_rr_question;
867}
868
869uint32_t
870ldns_rr_ttl(const ldns_rr *rr)
871{
872 return rr->_ttl;
873}
874
875size_t
876ldns_rr_rd_count(const ldns_rr *rr)
877{
878 return rr->_rd_count;
879}
880
881ldns_rr_type
882ldns_rr_get_type(const ldns_rr *rr)
883{
884 return rr->_rr_type;
885}
886
887ldns_rr_class
888ldns_rr_get_class(const ldns_rr *rr)
889{
890 return rr->_rr_class;
891}
892
893/* rr_lists */
894
895size_t
896ldns_rr_list_rr_count(const ldns_rr_list *rr_list)
897{
898 if (rr_list) {
899 return rr_list->_rr_count;
900 } else {
901 return 0;
902 }
903}
904
905ldns_rr *
906ldns_rr_list_set_rr(ldns_rr_list *rr_list, const ldns_rr *r, size_t count)
907{
908 ldns_rr *old;
909
910 if (count > ldns_rr_list_rr_count(rr_list)) {
911 return NULL;
912 }
913
914 old = ldns_rr_list_rr(rr_list, count);
915
916 /* overwrite old's pointer */
917 rr_list->_rrs[count] = (ldns_rr*)r;
918 return old;
919}
920
921void
922ldns_rr_list_set_rr_count(ldns_rr_list *rr_list, size_t count)
923{
924 assert(count <= rr_list->_rr_capacity);
925 rr_list->_rr_count = count;
926}
927
928ldns_rr *
929ldns_rr_list_rr(const ldns_rr_list *rr_list, size_t nr)
930{
931 if (nr < ldns_rr_list_rr_count(rr_list)) {
932 return rr_list->_rrs[nr];
933 } else {
934 return NULL;
935 }
936}
937
938ldns_rr_list *
939ldns_rr_list_new()
940{
941 ldns_rr_list *rr_list = LDNS_MALLOC(ldns_rr_list);
fd185f4d 942 if(!rr_list) return NULL;
825eb42b
JL
943 rr_list->_rr_count = 0;
944 rr_list->_rr_capacity = 0;
945 rr_list->_rrs = NULL;
946 return rr_list;
947}
948
949void
950ldns_rr_list_free(ldns_rr_list *rr_list)
951{
952 if (rr_list) {
953 LDNS_FREE(rr_list->_rrs);
954 LDNS_FREE(rr_list);
955 }
956}
957
958void
959ldns_rr_list_deep_free(ldns_rr_list *rr_list)
960{
961 size_t i;
962
963 if (rr_list) {
964 for (i=0; i < ldns_rr_list_rr_count(rr_list); i++) {
965 ldns_rr_free(ldns_rr_list_rr(rr_list, i));
966 }
967 LDNS_FREE(rr_list->_rrs);
968 LDNS_FREE(rr_list);
969 }
970}
971
972
973/* add right to left. So we modify *left! */
974bool
975ldns_rr_list_cat(ldns_rr_list *left, ldns_rr_list *right)
976{
977 size_t r_rr_count;
825eb42b
JL
978 size_t i;
979
ac996e71 980 if (!left) {
825eb42b
JL
981 return false;
982 }
983
984 if (right) {
985 r_rr_count = ldns_rr_list_rr_count(right);
986 } else {
987 r_rr_count = 0;
988 }
989
990 /* push right to left */
991 for(i = 0; i < r_rr_count; i++) {
992 ldns_rr_list_push_rr(left, ldns_rr_list_rr(right, i));
993 }
994 return true;
995}
996
997ldns_rr_list *
998ldns_rr_list_cat_clone(ldns_rr_list *left, ldns_rr_list *right)
999{
1000 size_t l_rr_count;
1001 size_t r_rr_count;
1002 size_t i;
1003 ldns_rr_list *cat;
1004
825eb42b
JL
1005 if (left) {
1006 l_rr_count = ldns_rr_list_rr_count(left);
1007 } else {
1008 return ldns_rr_list_clone(right);
1009 }
1010
1011 if (right) {
1012 r_rr_count = ldns_rr_list_rr_count(right);
1013 } else {
1014 r_rr_count = 0;
1015 }
1016
1017 cat = ldns_rr_list_new();
1018
1019 if (!cat) {
1020 return NULL;
1021 }
1022
1023 /* left */
1024 for(i = 0; i < l_rr_count; i++) {
1025 ldns_rr_list_push_rr(cat,
1026 ldns_rr_clone(ldns_rr_list_rr(left, i)));
1027 }
1028 /* right */
1029 for(i = 0; i < r_rr_count; i++) {
1030 ldns_rr_list_push_rr(cat,
1031 ldns_rr_clone(ldns_rr_list_rr(right, i)));
1032 }
1033 return cat;
1034}
1035
1036ldns_rr_list *
1037ldns_rr_list_subtype_by_rdf(ldns_rr_list *l, ldns_rdf *r, size_t pos)
1038{
1039 size_t i;
1040 ldns_rr_list *subtyped;
1041 ldns_rdf *list_rdf;
1042
1043 subtyped = ldns_rr_list_new();
1044
1045 for(i = 0; i < ldns_rr_list_rr_count(l); i++) {
1046 list_rdf = ldns_rr_rdf(
1047 ldns_rr_list_rr(l, i),
1048 pos);
1049 if (!list_rdf) {
1050 /* pos is too large or any other error */
1051 ldns_rr_list_deep_free(subtyped);
1052 return NULL;
1053 }
1054
1055 if (ldns_rdf_compare(list_rdf, r) == 0) {
1056 /* a match */
1057 ldns_rr_list_push_rr(subtyped,
1058 ldns_rr_clone(ldns_rr_list_rr(l, i)));
1059 }
1060 }
1061
1062 if (ldns_rr_list_rr_count(subtyped) > 0) {
1063 return subtyped;
1064 } else {
1065 ldns_rr_list_free(subtyped);
1066 return NULL;
1067 }
1068}
1069
1070bool
1071ldns_rr_list_push_rr(ldns_rr_list *rr_list, const ldns_rr *rr)
1072{
1073 size_t rr_count;
1074 size_t cap;
1075
1076 rr_count = ldns_rr_list_rr_count(rr_list);
1077 cap = rr_list->_rr_capacity;
1078
1079 /* grow the array */
1080 if(rr_count+1 > cap) {
1081 ldns_rr **rrs;
1082
1083 if(cap == 0)
1084 cap = LDNS_RRLIST_INIT; /* initial list size */
1085 else cap *= 2;
1086 rrs = LDNS_XREALLOC(rr_list->_rrs, ldns_rr *, cap);
1087 if (!rrs) {
1088 return false;
1089 }
1090 rr_list->_rrs = rrs;
1091 rr_list->_rr_capacity = cap;
1092 }
1093
1094 /* add the new member */
1095 rr_list->_rrs[rr_count] = (ldns_rr*)rr;
1096
1097 ldns_rr_list_set_rr_count(rr_list, rr_count + 1);
1098 return true;
1099}
1100
1101bool
1102ldns_rr_list_push_rr_list(ldns_rr_list *rr_list, const ldns_rr_list *push_list)
1103{
1104 size_t i;
1105
1106 for(i = 0; i < ldns_rr_list_rr_count(push_list); i++) {
1107 if (!ldns_rr_list_push_rr(rr_list,
1108 ldns_rr_list_rr(push_list, i))) {
1109 return false;
1110 }
1111 }
1112 return true;
1113}
1114
1115ldns_rr *
1116ldns_rr_list_pop_rr(ldns_rr_list *rr_list)
1117{
1118 size_t rr_count;
1119 size_t cap;
1120 ldns_rr *pop;
1121
1122 rr_count = ldns_rr_list_rr_count(rr_list);
1123
1124 if (rr_count == 0) {
1125 return NULL;
1126 }
1127
1128 cap = rr_list->_rr_capacity;
1129 pop = ldns_rr_list_rr(rr_list, rr_count - 1);
1130
1131 /* shrink the array */
1132 if(cap > LDNS_RRLIST_INIT && rr_count-1 <= cap/2) {
fd185f4d 1133 ldns_rr** a;
825eb42b 1134 cap /= 2;
fd185f4d
JL
1135 a = LDNS_XREALLOC(rr_list->_rrs, ldns_rr *, cap);
1136 if(a) {
1137 rr_list->_rrs = a;
1138 rr_list->_rr_capacity = cap;
1139 }
825eb42b
JL
1140 }
1141
1142 ldns_rr_list_set_rr_count(rr_list, rr_count - 1);
1143
1144 return pop;
1145}
1146
1147ldns_rr_list *
1148ldns_rr_list_pop_rr_list(ldns_rr_list *rr_list, size_t howmany)
1149{
1150 /* pop a number of rr's and put them in a rr_list */
1151 ldns_rr_list *popped;
1152 ldns_rr *p;
1153 size_t i = howmany;
1154
1155 popped = ldns_rr_list_new();
1156
1157 if (!popped) {
1158 return NULL;
1159 }
1160
1161
1162 while(i > 0 &&
1163 (p = ldns_rr_list_pop_rr(rr_list)) != NULL) {
1164 ldns_rr_list_push_rr(popped, p);
1165 i--;
1166 }
1167
d1b2b5ca
JM
1168 if (i == howmany) { /* so i <= 0 */
1169 ldns_rr_list_free(popped);
825eb42b
JL
1170 return NULL;
1171 } else {
1172 return popped;
1173 }
1174}
1175
1176
1177bool
1178ldns_rr_list_contains_rr(const ldns_rr_list *rr_list, ldns_rr *rr)
1179{
1180 size_t i;
1181
1182 if (!rr_list || !rr || ldns_rr_list_rr_count(rr_list) == 0) {
1183 return false;
1184 }
1185
1186 for (i = 0; i < ldns_rr_list_rr_count(rr_list); i++) {
1187 if (rr == ldns_rr_list_rr(rr_list, i)) {
1188 return true;
1189 } else if (ldns_rr_compare(rr, ldns_rr_list_rr(rr_list, i)) == 0) {
1190 return true;
1191 }
1192 }
1193 return false;
1194}
1195
1196bool
1197ldns_is_rrset(ldns_rr_list *rr_list)
1198{
1199 ldns_rr_type t;
1200 ldns_rr_class c;
1201 ldns_rdf *o;
1202 ldns_rr *tmp;
1203 size_t i;
1204
1205 if (!rr_list || ldns_rr_list_rr_count(rr_list) == 0) {
1206 return false;
1207 }
1208
1209 tmp = ldns_rr_list_rr(rr_list, 0);
1210
1211 t = ldns_rr_get_type(tmp);
1212 c = ldns_rr_get_class(tmp);
1213 o = ldns_rr_owner(tmp);
1214
1215 /* compare these with the rest of the rr_list, start with 1 */
1216 for (i = 1; i < ldns_rr_list_rr_count(rr_list); i++) {
1217 tmp = ldns_rr_list_rr(rr_list, i);
1218 if (t != ldns_rr_get_type(tmp)) {
1219 return false;
1220 }
1221 if (c != ldns_rr_get_class(tmp)) {
1222 return false;
1223 }
1224 if (ldns_rdf_compare(o, ldns_rr_owner(tmp)) != 0) {
1225 return false;
1226 }
1227 }
1228 return true;
1229}
1230
1231bool
1232ldns_rr_set_push_rr(ldns_rr_list *rr_list, ldns_rr *rr)
1233{
1234 size_t rr_count;
1235 size_t i;
1236 ldns_rr *last;
1237
1238 assert(rr != NULL);
1239
1240 rr_count = ldns_rr_list_rr_count(rr_list);
1241
1242 if (rr_count == 0) {
1243 /* nothing there, so checking it is
1244 * not needed */
1245 return ldns_rr_list_push_rr(rr_list, rr);
1246 } else {
1247 /* check with the final rr in the rr_list */
1248 last = ldns_rr_list_rr(rr_list, rr_count - 1);
1249
1250 if (ldns_rr_get_class(last) != ldns_rr_get_class(rr)) {
1251 return false;
1252 }
1253 if (ldns_rr_get_type(last) != ldns_rr_get_type(rr)) {
1254 return false;
1255 }
1256 /* only check if not equal to RRSIG */
1257 if (ldns_rr_get_type(rr) != LDNS_RR_TYPE_RRSIG) {
1258 if (ldns_rr_ttl(last) != ldns_rr_ttl(rr)) {
1259 return false;
1260 }
1261 }
1262 if (ldns_rdf_compare(ldns_rr_owner(last),
1263 ldns_rr_owner(rr)) != 0) {
1264 return false;
1265 }
1266 /* ok, still alive - check if the rr already
1267 * exists - if so, dont' add it */
1268 for(i = 0; i < rr_count; i++) {
1269 if(ldns_rr_compare(
1270 ldns_rr_list_rr(rr_list, i), rr) == 0) {
1271 return false;
1272 }
1273 }
1274 /* it's safe, push it */
1275 return ldns_rr_list_push_rr(rr_list, rr);
1276 }
1277}
1278
1279ldns_rr *
1280ldns_rr_set_pop_rr(ldns_rr_list *rr_list)
1281{
1282 return ldns_rr_list_pop_rr(rr_list);
1283}
1284
1285ldns_rr_list *
1286ldns_rr_list_pop_rrset(ldns_rr_list *rr_list)
1287{
1288 ldns_rr_list *rrset;
1289 ldns_rr *last_rr = NULL;
1290 ldns_rr *next_rr;
1291
1292 if (!rr_list) {
1293 return NULL;
1294 }
1295
1296 rrset = ldns_rr_list_new();
1297 if (!last_rr) {
1298 last_rr = ldns_rr_list_pop_rr(rr_list);
1299 if (!last_rr) {
1300 ldns_rr_list_free(rrset);
1301 return NULL;
1302 } else {
1303 ldns_rr_list_push_rr(rrset, last_rr);
1304 }
1305 }
1306
1307 if (ldns_rr_list_rr_count(rr_list) > 0) {
1308 next_rr = ldns_rr_list_rr(rr_list, ldns_rr_list_rr_count(rr_list) - 1);
1309 } else {
1310 next_rr = NULL;
1311 }
1312
1313 while (next_rr) {
1314 if (
1315 ldns_rdf_compare(ldns_rr_owner(next_rr),
1316 ldns_rr_owner(last_rr)) == 0
1317 &&
1318 ldns_rr_get_type(next_rr) == ldns_rr_get_type(last_rr)
1319 &&
1320 ldns_rr_get_class(next_rr) == ldns_rr_get_class(last_rr)
1321 ) {
1322 ldns_rr_list_push_rr(rrset, ldns_rr_list_pop_rr(rr_list));
1323 if (ldns_rr_list_rr_count(rr_list) > 0) {
1324 last_rr = next_rr;
1325 next_rr = ldns_rr_list_rr(rr_list, ldns_rr_list_rr_count(rr_list) - 1);
1326 } else {
1327 next_rr = NULL;
1328 }
1329 } else {
1330 next_rr = NULL;
1331 }
1332 }
1333
1334 return rrset;
1335}
1336
1337ldns_rr *
1338ldns_rr_clone(const ldns_rr *rr)
1339{
1340 size_t i;
1341 ldns_rr *new_rr;
1342
1343 if (!rr) {
1344 return NULL;
1345 }
1346
1347 new_rr = ldns_rr_new();
1348 if (!new_rr) {
1349 return NULL;
1350 }
1351 if (ldns_rr_owner(rr)) {
1352 ldns_rr_set_owner(new_rr, ldns_rdf_clone(ldns_rr_owner(rr)));
1353 }
1354 ldns_rr_set_ttl(new_rr, ldns_rr_ttl(rr));
1355 ldns_rr_set_type(new_rr, ldns_rr_get_type(rr));
1356 ldns_rr_set_class(new_rr, ldns_rr_get_class(rr));
ac996e71 1357 ldns_rr_set_question(new_rr, ldns_rr_is_question(rr));
825eb42b
JL
1358
1359 for (i = 0; i < ldns_rr_rd_count(rr); i++) {
1360 if (ldns_rr_rdf(rr,i)) {
1361 ldns_rr_push_rdf(new_rr, ldns_rdf_clone(ldns_rr_rdf(rr, i)));
1362 }
1363 }
1364
1365 return new_rr;
1366}
1367
1368ldns_rr_list *
1369ldns_rr_list_clone(const ldns_rr_list *rrlist)
1370{
1371 size_t i;
1372 ldns_rr_list *new_list;
1373 ldns_rr *r;
1374
1375 if (!rrlist) {
1376 return NULL;
1377 }
1378
1379 new_list = ldns_rr_list_new();
1380 if (!new_list) {
1381 return NULL;
1382 }
1383 for (i = 0; i < ldns_rr_list_rr_count(rrlist); i++) {
1384 r = ldns_rr_clone(
1385 ldns_rr_list_rr(rrlist, i)
1386 );
1387 if (!r) {
1388 /* huh, failure in cloning */
1389 ldns_rr_list_deep_free(new_list);
1390 return NULL;
1391 }
1392 ldns_rr_list_push_rr(new_list, r);
1393 }
1394 return new_list;
1395}
1396
1397
1398int
1399qsort_rr_compare(const void *a, const void *b)
1400{
1401 const ldns_rr *rr1 = * (const ldns_rr **) a;
1402 const ldns_rr *rr2 = * (const ldns_rr **) b;
1403
1404 if (rr1 == NULL && rr2 == NULL) {
1405 return 0;
1406 }
1407 if (rr1 == NULL) {
1408 return -1;
1409 }
1410 if (rr2 == NULL) {
1411 return 1;
1412 }
1413 return ldns_rr_compare(rr1, rr2);
1414}
1415
1416int
1417qsort_schwartz_rr_compare(const void *a, const void *b)
1418{
1419 int result = 0;
1420 ldns_rr *rr1, *rr2;
1421 ldns_buffer *rr1_buf, *rr2_buf;
1422 struct ldns_schwartzian_compare_struct *sa = *(struct ldns_schwartzian_compare_struct **) a;
1423 struct ldns_schwartzian_compare_struct *sb = *(struct ldns_schwartzian_compare_struct **) b;
1424 /* if we are doing 2wire, we need to do lowercasing on the dname (and maybe on the rdata)
1425 * this must be done for comparison only, so we need to have a temp var for both buffers,
1426 * which is only used when the transformed object value isn't there yet
1427 */
1428 ldns_rr *canonical_a, *canonical_b;
1429
1430 rr1 = (ldns_rr *) sa->original_object;
1431 rr2 = (ldns_rr *) sb->original_object;
1432
1433 result = ldns_rr_compare_no_rdata(rr1, rr2);
1434
1435 if (result == 0) {
1436 if (!sa->transformed_object) {
1437 canonical_a = ldns_rr_clone(sa->original_object);
1438 ldns_rr2canonical(canonical_a);
1439 sa->transformed_object = ldns_buffer_new(ldns_rr_uncompressed_size(canonical_a));
1440 if (ldns_rr2buffer_wire(sa->transformed_object, canonical_a, LDNS_SECTION_ANY) != LDNS_STATUS_OK) {
fd185f4d
JL
1441 ldns_buffer_free((ldns_buffer *)sa->transformed_object);
1442 sa->transformed_object = NULL;
825eb42b
JL
1443 ldns_rr_free(canonical_a);
1444 return 0;
1445 }
1446 ldns_rr_free(canonical_a);
1447 }
1448 if (!sb->transformed_object) {
1449 canonical_b = ldns_rr_clone(sb->original_object);
1450 ldns_rr2canonical(canonical_b);
1451 sb->transformed_object = ldns_buffer_new(ldns_rr_uncompressed_size(canonical_b));
1452 if (ldns_rr2buffer_wire(sb->transformed_object, canonical_b, LDNS_SECTION_ANY) != LDNS_STATUS_OK) {
fd185f4d
JL
1453 ldns_buffer_free((ldns_buffer *)sa->transformed_object);
1454 ldns_buffer_free((ldns_buffer *)sb->transformed_object);
1455 sa->transformed_object = NULL;
1456 sb->transformed_object = NULL;
825eb42b
JL
1457 ldns_rr_free(canonical_b);
1458 return 0;
1459 }
1460 ldns_rr_free(canonical_b);
1461 }
1462 rr1_buf = (ldns_buffer *) sa->transformed_object;
1463 rr2_buf = (ldns_buffer *) sb->transformed_object;
1464
1465 result = ldns_rr_compare_wire(rr1_buf, rr2_buf);
1466 }
1467
1468 return result;
1469}
1470
1471void
1472ldns_rr_list_sort(ldns_rr_list *unsorted)
1473{
1474 struct ldns_schwartzian_compare_struct **sortables;
1475 size_t item_count;
1476 size_t i;
1477
1478 if (unsorted) {
1479 item_count = ldns_rr_list_rr_count(unsorted);
1480
1481 sortables = LDNS_XMALLOC(struct ldns_schwartzian_compare_struct *,
1482 item_count);
fd185f4d 1483 if(!sortables) return; /* no way to return error */
825eb42b
JL
1484 for (i = 0; i < item_count; i++) {
1485 sortables[i] = LDNS_XMALLOC(struct ldns_schwartzian_compare_struct, 1);
fd185f4d
JL
1486 if(!sortables[i]) {
1487 /* free the allocated parts */
1488 while(i>0) {
1489 i--;
1490 LDNS_FREE(sortables[i]);
1491 }
1492 /* no way to return error */
d1b2b5ca 1493 LDNS_FREE(sortables);
fd185f4d
JL
1494 return;
1495 }
825eb42b
JL
1496 sortables[i]->original_object = ldns_rr_list_rr(unsorted, i);
1497 sortables[i]->transformed_object = NULL;
1498 }
1499 qsort(sortables,
1500 item_count,
1501 sizeof(struct ldns_schwartzian_compare_struct *),
1502 qsort_schwartz_rr_compare);
1503 for (i = 0; i < item_count; i++) {
1504 unsorted->_rrs[i] = sortables[i]->original_object;
1505 if (sortables[i]->transformed_object) {
1506 ldns_buffer_free(sortables[i]->transformed_object);
1507 }
1508 LDNS_FREE(sortables[i]);
1509 }
1510 LDNS_FREE(sortables);
1511 }
1512}
1513
1514int
1515ldns_rr_compare_no_rdata(const ldns_rr *rr1, const ldns_rr *rr2)
1516{
1517 size_t rr1_len;
1518 size_t rr2_len;
1519 size_t offset;
1520
1521 assert(rr1 != NULL);
1522 assert(rr2 != NULL);
1523
1524 rr1_len = ldns_rr_uncompressed_size(rr1);
1525 rr2_len = ldns_rr_uncompressed_size(rr2);
1526
1527 if (ldns_dname_compare(ldns_rr_owner(rr1), ldns_rr_owner(rr2)) < 0) {
1528 return -1;
1529 } else if (ldns_dname_compare(ldns_rr_owner(rr1), ldns_rr_owner(rr2)) > 0) {
1530 return 1;
1531 }
1532
1533 /* should return -1 if rr1 comes before rr2, so need to do rr1 - rr2, not rr2 - rr1 */
1534 if (ldns_rr_get_class(rr1) != ldns_rr_get_class(rr2)) {
1535 return ldns_rr_get_class(rr1) - ldns_rr_get_class(rr2);
1536 }
1537
1538 /* should return -1 if rr1 comes before rr2, so need to do rr1 - rr2, not rr2 - rr1 */
1539 if (ldns_rr_get_type(rr1) != ldns_rr_get_type(rr2)) {
1540 return ldns_rr_get_type(rr1) - ldns_rr_get_type(rr2);
1541 }
1542
1543 /* offset is the owername length + ttl + type + class + rdlen == start of wire format rdata */
1544 offset = ldns_rdf_size(ldns_rr_owner(rr1)) + 4 + 2 + 2 + 2;
1545 /* if either record doesn't have any RDATA... */
1546 if (offset > rr1_len || offset > rr2_len) {
1547 if (rr1_len == rr2_len) {
1548 return 0;
1549 }
1550 return ((int) rr2_len - (int) rr1_len);
1551 }
1552
1553 return 0;
1554}
1555
1556int ldns_rr_compare_wire(ldns_buffer *rr1_buf, ldns_buffer *rr2_buf)
1557{
1558 size_t rr1_len, rr2_len, min_len, i, offset;
1559
1560 rr1_len = ldns_buffer_capacity(rr1_buf);
1561 rr2_len = ldns_buffer_capacity(rr2_buf);
1562
1563 /* jump past dname (checked in earlier part)
1564 * and especially past TTL */
1565 offset = 0;
1566 while (offset < rr1_len && *ldns_buffer_at(rr1_buf, offset) != 0) {
1567 offset += *ldns_buffer_at(rr1_buf, offset) + 1;
1568 }
1569 /* jump to rdata section (PAST the rdata length field, otherwise
1570 rrs with different lengths might be sorted erroneously */
1571 offset += 11;
1572 min_len = (rr1_len < rr2_len) ? rr1_len : rr2_len;
1573 /* Compare RRs RDATA byte for byte. */
1574 for(i = offset; i < min_len; i++) {
1575 if (*ldns_buffer_at(rr1_buf,i) < *ldns_buffer_at(rr2_buf,i)) {
1576 return -1;
1577 } else if (*ldns_buffer_at(rr1_buf,i) > *ldns_buffer_at(rr2_buf,i)) {
1578 return +1;
1579 }
1580 }
1581
1582 /* If both RDATAs are the same up to min_len, then the shorter one sorts first. */
1583 if (rr1_len < rr2_len) {
1584 return -1;
1585 } else if (rr1_len > rr2_len) {
1586 return +1;
1587 }
1588 /* The RDATAs are equal. */
1589 return 0;
1590
1591}
1592
1593int
1594ldns_rr_compare(const ldns_rr *rr1, const ldns_rr *rr2)
1595{
1596 int result;
1597 size_t rr1_len, rr2_len;
1598
1599 ldns_buffer *rr1_buf;
1600 ldns_buffer *rr2_buf;
1601
1602 result = ldns_rr_compare_no_rdata(rr1, rr2);
1603 if (result == 0) {
1604 rr1_len = ldns_rr_uncompressed_size(rr1);
1605 rr2_len = ldns_rr_uncompressed_size(rr2);
1606
1607 rr1_buf = ldns_buffer_new(rr1_len);
1608 rr2_buf = ldns_buffer_new(rr2_len);
1609
1610 if (ldns_rr2buffer_wire_canonical(rr1_buf,
1611 rr1,
1612 LDNS_SECTION_ANY)
1613 != LDNS_STATUS_OK) {
1614 ldns_buffer_free(rr1_buf);
1615 ldns_buffer_free(rr2_buf);
1616 return 0;
1617 }
1618 if (ldns_rr2buffer_wire_canonical(rr2_buf,
1619 rr2,
1620 LDNS_SECTION_ANY)
1621 != LDNS_STATUS_OK) {
1622 ldns_buffer_free(rr1_buf);
1623 ldns_buffer_free(rr2_buf);
1624 return 0;
1625 }
1626
1627 result = ldns_rr_compare_wire(rr1_buf, rr2_buf);
1628
1629 ldns_buffer_free(rr1_buf);
1630 ldns_buffer_free(rr2_buf);
1631 }
1632
1633 return result;
1634}
1635
1636/* convert dnskey to a ds with the given algorithm,
1637 * then compare the result with the given ds */
1638static int
1639ldns_rr_compare_ds_dnskey(ldns_rr *ds,
1640 ldns_rr *dnskey)
1641{
1642 ldns_rr *ds_gen;
1643 bool result = false;
1644 ldns_hash algo;
1645
1646 if (!dnskey || !ds ||
1647 ldns_rr_get_type(ds) != LDNS_RR_TYPE_DS ||
1648 ldns_rr_get_type(dnskey) != LDNS_RR_TYPE_DNSKEY) {
1649 return false;
1650 }
1651
b5dedcca
JL
1652 if (ldns_rr_rdf(ds, 2) == NULL) {
1653 return false;
1654 }
1655 algo = ldns_rdf2native_int8(ldns_rr_rdf(ds, 2));
825eb42b
JL
1656
1657 ds_gen = ldns_key_rr2ds(dnskey, algo);
1658 if (ds_gen) {
1659 result = ldns_rr_compare(ds, ds_gen) == 0;
1660 ldns_rr_free(ds_gen);
1661 }
1662 return result;
1663}
1664
1665bool
1666ldns_rr_compare_ds(const ldns_rr *orr1, const ldns_rr *orr2)
1667{
1668 bool result;
1669 ldns_rr *rr1 = ldns_rr_clone(orr1);
1670 ldns_rr *rr2 = ldns_rr_clone(orr2);
1671
1672 /* set ttls to zero */
1673 ldns_rr_set_ttl(rr1, 0);
1674 ldns_rr_set_ttl(rr2, 0);
1675
1676 if (ldns_rr_get_type(rr1) == LDNS_RR_TYPE_DS &&
1677 ldns_rr_get_type(rr2) == LDNS_RR_TYPE_DNSKEY) {
1678 result = ldns_rr_compare_ds_dnskey(rr1, rr2);
1679 } else if (ldns_rr_get_type(rr1) == LDNS_RR_TYPE_DNSKEY &&
1680 ldns_rr_get_type(rr2) == LDNS_RR_TYPE_DS) {
1681 result = ldns_rr_compare_ds_dnskey(rr2, rr1);
1682 } else {
1683 result = (ldns_rr_compare(rr1, rr2) == 0);
1684 }
1685
1686 ldns_rr_free(rr1);
1687 ldns_rr_free(rr2);
1688
1689 return result;
1690}
1691
1692int
1693ldns_rr_list_compare(const ldns_rr_list *rrl1, const ldns_rr_list *rrl2)
1694{
1695 size_t i = 0;
1696 int rr_cmp;
1697
1698 assert(rrl1 != NULL);
1699 assert(rrl2 != NULL);
1700
1701 for (i = 0; i < ldns_rr_list_rr_count(rrl1) && i < ldns_rr_list_rr_count(rrl2); i++) {
1702 rr_cmp = ldns_rr_compare(ldns_rr_list_rr(rrl1, i), ldns_rr_list_rr(rrl2, i));
1703 if (rr_cmp != 0) {
1704 return rr_cmp;
1705 }
1706 }
1707
1708 if (i == ldns_rr_list_rr_count(rrl1) &&
1709 i != ldns_rr_list_rr_count(rrl2)) {
1710 return 1;
1711 } else if (i == ldns_rr_list_rr_count(rrl2) &&
1712 i != ldns_rr_list_rr_count(rrl1)) {
1713 return -1;
1714 } else {
1715 return 0;
1716 }
1717}
1718
1719size_t
1720ldns_rr_uncompressed_size(const ldns_rr *r)
1721{
1722 size_t rrsize;
1723 size_t i;
1724
1725 rrsize = 0;
1726 /* add all the rdf sizes */
1727 for(i = 0; i < ldns_rr_rd_count(r); i++) {
1728 rrsize += ldns_rdf_size(ldns_rr_rdf(r, i));
1729 }
1730 /* ownername */
1731 rrsize += ldns_rdf_size(ldns_rr_owner(r));
1732 rrsize += LDNS_RR_OVERHEAD;
1733 return rrsize;
1734}
1735
1736void
1737ldns_rr2canonical(ldns_rr *rr)
1738{
1739 uint16_t i;
1740
1741 if (!rr) {
1742 return;
1743 }
1744
1745 ldns_dname2canonical(ldns_rr_owner(rr));
1746
1747 /*
1748 * lowercase the rdata dnames if the rr type is one
1749 * of the list in chapter 7 of RFC3597
d1b2b5ca
JM
1750 * Also added RRSIG, because a "Signer's Name" should be canonicalized
1751 * too. See dnssec-bis-updates-16. We can add it to this list because
1752 * the "Signer's Name" is the only dname type rdata field in a RRSIG.
825eb42b
JL
1753 */
1754 switch(ldns_rr_get_type(rr)) {
1755 case LDNS_RR_TYPE_NS:
1756 case LDNS_RR_TYPE_MD:
1757 case LDNS_RR_TYPE_MF:
1758 case LDNS_RR_TYPE_CNAME:
1759 case LDNS_RR_TYPE_SOA:
1760 case LDNS_RR_TYPE_MB:
1761 case LDNS_RR_TYPE_MG:
1762 case LDNS_RR_TYPE_MR:
1763 case LDNS_RR_TYPE_PTR:
825eb42b
JL
1764 case LDNS_RR_TYPE_MINFO:
1765 case LDNS_RR_TYPE_MX:
1766 case LDNS_RR_TYPE_RP:
1767 case LDNS_RR_TYPE_AFSDB:
1768 case LDNS_RR_TYPE_RT:
1769 case LDNS_RR_TYPE_SIG:
1770 case LDNS_RR_TYPE_PX:
1771 case LDNS_RR_TYPE_NXT:
1772 case LDNS_RR_TYPE_NAPTR:
1773 case LDNS_RR_TYPE_KX:
1774 case LDNS_RR_TYPE_SRV:
1775 case LDNS_RR_TYPE_DNAME:
1776 case LDNS_RR_TYPE_A6:
d1b2b5ca 1777 case LDNS_RR_TYPE_RRSIG:
825eb42b
JL
1778 for (i = 0; i < ldns_rr_rd_count(rr); i++) {
1779 ldns_dname2canonical(ldns_rr_rdf(rr, i));
1780 }
1781 return;
1782 default:
1783 /* do nothing */
1784 return;
1785 }
1786}
1787
1788void
1789ldns_rr_list2canonical(ldns_rr_list *rr_list)
1790{
1791 size_t i;
1792 for (i = 0; i < ldns_rr_list_rr_count(rr_list); i++) {
1793 ldns_rr2canonical(ldns_rr_list_rr(rr_list, i));
1794 }
1795}
1796
1797uint8_t
1798ldns_rr_label_count(ldns_rr *rr)
1799{
1800 if (!rr) {
1801 return 0;
1802 }
1803 return ldns_dname_label_count(
1804 ldns_rr_owner(rr));
1805}
1806
1807/** \cond */
1808static const ldns_rdf_type type_0_wireformat[] = { LDNS_RDF_TYPE_UNKNOWN };
1809static const ldns_rdf_type type_a_wireformat[] = { LDNS_RDF_TYPE_A };
1810static const ldns_rdf_type type_ns_wireformat[] = { LDNS_RDF_TYPE_DNAME };
1811static const ldns_rdf_type type_md_wireformat[] = { LDNS_RDF_TYPE_DNAME };
1812static const ldns_rdf_type type_mf_wireformat[] = { LDNS_RDF_TYPE_DNAME };
1813static const ldns_rdf_type type_cname_wireformat[] = { LDNS_RDF_TYPE_DNAME };
1814static const ldns_rdf_type type_soa_wireformat[] = {
1815 LDNS_RDF_TYPE_DNAME, LDNS_RDF_TYPE_DNAME, LDNS_RDF_TYPE_INT32,
1816 LDNS_RDF_TYPE_PERIOD, LDNS_RDF_TYPE_PERIOD, LDNS_RDF_TYPE_PERIOD,
1817 LDNS_RDF_TYPE_PERIOD
1818};
1819static const ldns_rdf_type type_mb_wireformat[] = { LDNS_RDF_TYPE_DNAME };
1820static const ldns_rdf_type type_mg_wireformat[] = { LDNS_RDF_TYPE_DNAME };
1821static const ldns_rdf_type type_mr_wireformat[] = { LDNS_RDF_TYPE_DNAME };
1822static const ldns_rdf_type type_wks_wireformat[] = {
1823 LDNS_RDF_TYPE_A, LDNS_RDF_TYPE_WKS
1824};
1825static const ldns_rdf_type type_ptr_wireformat[] = { LDNS_RDF_TYPE_DNAME };
1826static const ldns_rdf_type type_hinfo_wireformat[] = {
1827 LDNS_RDF_TYPE_STR, LDNS_RDF_TYPE_STR
1828};
1829static const ldns_rdf_type type_minfo_wireformat[] = {
1830 LDNS_RDF_TYPE_DNAME, LDNS_RDF_TYPE_DNAME
1831};
1832static const ldns_rdf_type type_mx_wireformat[] = {
1833 LDNS_RDF_TYPE_INT16, LDNS_RDF_TYPE_DNAME
1834};
1835static const ldns_rdf_type type_rp_wireformat[] = {
1836 LDNS_RDF_TYPE_DNAME, LDNS_RDF_TYPE_DNAME
1837};
1838static const ldns_rdf_type type_afsdb_wireformat[] = {
1839 LDNS_RDF_TYPE_INT16, LDNS_RDF_TYPE_DNAME
1840};
1841static const ldns_rdf_type type_x25_wireformat[] = { LDNS_RDF_TYPE_STR };
1842static const ldns_rdf_type type_isdn_wireformat[] = {
1843 LDNS_RDF_TYPE_STR, LDNS_RDF_TYPE_STR
1844};
1845static const ldns_rdf_type type_rt_wireformat[] = {
1846 LDNS_RDF_TYPE_INT16, LDNS_RDF_TYPE_DNAME
1847};
1848static const ldns_rdf_type type_nsap_wireformat[] = {
1849 LDNS_RDF_TYPE_NSAP
1850};
1851static const ldns_rdf_type type_nsap_ptr_wireformat[] = {
1852 LDNS_RDF_TYPE_STR
1853};
1854static const ldns_rdf_type type_sig_wireformat[] = {
1855 LDNS_RDF_TYPE_TYPE, LDNS_RDF_TYPE_ALG, LDNS_RDF_TYPE_INT8, LDNS_RDF_TYPE_INT32,
1856 LDNS_RDF_TYPE_TIME, LDNS_RDF_TYPE_TIME, LDNS_RDF_TYPE_INT16,
1857 LDNS_RDF_TYPE_DNAME, LDNS_RDF_TYPE_B64
1858};
1859static const ldns_rdf_type type_key_wireformat[] = {
1860 LDNS_RDF_TYPE_INT16, LDNS_RDF_TYPE_INT8, LDNS_RDF_TYPE_INT8, LDNS_RDF_TYPE_B64
1861};
1862static const ldns_rdf_type type_px_wireformat[] = {
1863 LDNS_RDF_TYPE_INT16, LDNS_RDF_TYPE_DNAME, LDNS_RDF_TYPE_DNAME
1864};
1865static const ldns_rdf_type type_gpos_wireformat[] = {
1866 LDNS_RDF_TYPE_STR,
1867 LDNS_RDF_TYPE_STR,
1868 LDNS_RDF_TYPE_STR
1869};
1870static const ldns_rdf_type type_aaaa_wireformat[] = { LDNS_RDF_TYPE_AAAA };
1871static const ldns_rdf_type type_loc_wireformat[] = { LDNS_RDF_TYPE_LOC };
1872static const ldns_rdf_type type_nxt_wireformat[] = {
1873 LDNS_RDF_TYPE_DNAME, LDNS_RDF_TYPE_UNKNOWN
1874};
1875static const ldns_rdf_type type_eid_wireformat[] = {
1876 LDNS_RDF_TYPE_HEX
1877};
1878static const ldns_rdf_type type_nimloc_wireformat[] = {
1879 LDNS_RDF_TYPE_HEX
1880};
1881static const ldns_rdf_type type_srv_wireformat[] = {
1882 LDNS_RDF_TYPE_INT16, LDNS_RDF_TYPE_INT16, LDNS_RDF_TYPE_INT16, LDNS_RDF_TYPE_DNAME
1883};
1884static const ldns_rdf_type type_atma_wireformat[] = {
1885 LDNS_RDF_TYPE_ATMA
1886};
1887static const ldns_rdf_type type_naptr_wireformat[] = {
1888 LDNS_RDF_TYPE_INT16, LDNS_RDF_TYPE_INT16, LDNS_RDF_TYPE_STR, LDNS_RDF_TYPE_STR, LDNS_RDF_TYPE_STR, LDNS_RDF_TYPE_DNAME
1889};
1890static const ldns_rdf_type type_kx_wireformat[] = {
1891 LDNS_RDF_TYPE_INT16, LDNS_RDF_TYPE_DNAME
1892};
1893static const ldns_rdf_type type_cert_wireformat[] = {
1894 LDNS_RDF_TYPE_CERT_ALG, LDNS_RDF_TYPE_INT16, LDNS_RDF_TYPE_ALG, LDNS_RDF_TYPE_B64
1895};
1896static const ldns_rdf_type type_a6_wireformat[] = { LDNS_RDF_TYPE_UNKNOWN };
1897static const ldns_rdf_type type_dname_wireformat[] = { LDNS_RDF_TYPE_DNAME };
1898static const ldns_rdf_type type_sink_wireformat[] = { LDNS_RDF_TYPE_INT8,
1899 LDNS_RDF_TYPE_INT8, LDNS_RDF_TYPE_INT8, LDNS_RDF_TYPE_B64
1900};
1901static const ldns_rdf_type type_apl_wireformat[] = {
1902 LDNS_RDF_TYPE_APL
1903};
1904static const ldns_rdf_type type_ds_wireformat[] = {
1905 LDNS_RDF_TYPE_INT16, LDNS_RDF_TYPE_ALG, LDNS_RDF_TYPE_INT8, LDNS_RDF_TYPE_HEX
1906};
1907static const ldns_rdf_type type_sshfp_wireformat[] = {
1908 LDNS_RDF_TYPE_INT8, LDNS_RDF_TYPE_INT8, LDNS_RDF_TYPE_HEX
1909};
1910static const ldns_rdf_type type_ipseckey_wireformat[] = {
1911 LDNS_RDF_TYPE_IPSECKEY
1912};
1913static const ldns_rdf_type type_rrsig_wireformat[] = {
1914 LDNS_RDF_TYPE_TYPE, LDNS_RDF_TYPE_ALG, LDNS_RDF_TYPE_INT8, LDNS_RDF_TYPE_INT32,
1915 LDNS_RDF_TYPE_TIME, LDNS_RDF_TYPE_TIME, LDNS_RDF_TYPE_INT16, LDNS_RDF_TYPE_DNAME, LDNS_RDF_TYPE_B64
1916};
1917static const ldns_rdf_type type_nsec_wireformat[] = {
1918 LDNS_RDF_TYPE_DNAME, LDNS_RDF_TYPE_NSEC
1919};
1920static const ldns_rdf_type type_dhcid_wireformat[] = {
1921 LDNS_RDF_TYPE_B64
1922};
ac996e71
JL
1923static const ldns_rdf_type type_talink_wireformat[] = {
1924 LDNS_RDF_TYPE_DNAME, LDNS_RDF_TYPE_DNAME
1925};
825eb42b
JL
1926/* nsec3 is some vars, followed by same type of data of nsec */
1927static const ldns_rdf_type type_nsec3_wireformat[] = {
1928/* LDNS_RDF_TYPE_NSEC3_VARS, LDNS_RDF_TYPE_NSEC3_NEXT_OWNER, LDNS_RDF_TYPE_NSEC*/
1929 LDNS_RDF_TYPE_INT8, LDNS_RDF_TYPE_INT8, LDNS_RDF_TYPE_INT16, LDNS_RDF_TYPE_NSEC3_SALT, LDNS_RDF_TYPE_NSEC3_NEXT_OWNER, LDNS_RDF_TYPE_NSEC
1930};
1931
b5dedcca 1932static const ldns_rdf_type type_nsec3param_wireformat[] = {
825eb42b
JL
1933/* LDNS_RDF_TYPE_NSEC3_PARAMS_VARS*/
1934 LDNS_RDF_TYPE_INT8,
1935 LDNS_RDF_TYPE_INT8,
1936 LDNS_RDF_TYPE_INT16,
1937 LDNS_RDF_TYPE_NSEC3_SALT
1938};
1939
1940static const ldns_rdf_type type_dnskey_wireformat[] = {
1941 LDNS_RDF_TYPE_INT16,
1942 LDNS_RDF_TYPE_INT8,
1943 LDNS_RDF_TYPE_ALG,
1944 LDNS_RDF_TYPE_B64
1945};
1946static const ldns_rdf_type type_tsig_wireformat[] = {
1947 LDNS_RDF_TYPE_DNAME,
1948 LDNS_RDF_TYPE_TSIGTIME,
1949 LDNS_RDF_TYPE_INT16,
1950 LDNS_RDF_TYPE_INT16_DATA,
1951 LDNS_RDF_TYPE_INT16,
1952 LDNS_RDF_TYPE_INT16,
1953 LDNS_RDF_TYPE_INT16_DATA
1954};
d1b2b5ca
JM
1955static const ldns_rdf_type type_tlsa_wireformat[] = {
1956 LDNS_RDF_TYPE_INT8,
1957 LDNS_RDF_TYPE_INT8,
1958 LDNS_RDF_TYPE_INT8,
1959 LDNS_RDF_TYPE_HEX
1960};
825eb42b
JL
1961/** \endcond */
1962
1963/** \cond */
1964/* All RR's defined in 1035 are well known and can thus
1965 * be compressed. See RFC3597. These RR's are:
1966 * CNAME HINFO MB MD MF MG MINFO MR MX NULL NS PTR SOA TXT
1967 */
1968static ldns_rr_descriptor rdata_field_descriptors[] = {
1969 /* 0 */
1970 { 0, NULL, 0, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
1971 /* 1 */
1972 {LDNS_RR_TYPE_A, "A", 1, 1, type_a_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
1973 /* 2 */
1974 {LDNS_RR_TYPE_NS, "NS", 1, 1, type_ns_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_COMPRESS, 1 },
1975 /* 3 */
1976 {LDNS_RR_TYPE_MD, "MD", 1, 1, type_md_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_COMPRESS, 1 },
1977 /* 4 */
1978 {LDNS_RR_TYPE_MF, "MF", 1, 1, type_mf_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_COMPRESS, 1 },
1979 /* 5 */
1980 {LDNS_RR_TYPE_CNAME, "CNAME", 1, 1, type_cname_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_COMPRESS, 1 },
1981 /* 6 */
1982 {LDNS_RR_TYPE_SOA, "SOA", 7, 7, type_soa_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_COMPRESS, 2 },
1983 /* 7 */
1984 {LDNS_RR_TYPE_MB, "MB", 1, 1, type_mb_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_COMPRESS, 1 },
1985 /* 8 */
1986 {LDNS_RR_TYPE_MG, "MG", 1, 1, type_mg_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_COMPRESS, 1 },
1987 /* 9 */
1988 {LDNS_RR_TYPE_MR, "MR", 1, 1, type_mr_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_COMPRESS, 1 },
1989 /* 10 */
1990 {LDNS_RR_TYPE_NULL, "NULL", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
1991 /* 11 */
1992 {LDNS_RR_TYPE_WKS, "WKS", 2, 2, type_wks_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
1993 /* 12 */
1994 {LDNS_RR_TYPE_PTR, "PTR", 1, 1, type_ptr_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_COMPRESS, 1 },
1995 /* 13 */
1996 {LDNS_RR_TYPE_HINFO, "HINFO", 2, 2, type_hinfo_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
1997 /* 14 */
1998 {LDNS_RR_TYPE_MINFO, "MINFO", 2, 2, type_minfo_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_COMPRESS, 2 },
1999 /* 15 */
2000 {LDNS_RR_TYPE_MX, "MX", 2, 2, type_mx_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_COMPRESS, 1 },
2001 /* 16 */
2002 {LDNS_RR_TYPE_TXT, "TXT", 1, 0, NULL, LDNS_RDF_TYPE_STR, LDNS_RR_NO_COMPRESS, 0 },
2003 /* 17 */
2004 {LDNS_RR_TYPE_RP, "RP", 2, 2, type_rp_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 2 },
2005 /* 18 */
2006 {LDNS_RR_TYPE_AFSDB, "AFSDB", 2, 2, type_afsdb_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 1 },
2007 /* 19 */
2008 {LDNS_RR_TYPE_X25, "X25", 1, 1, type_x25_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
2009 /* 20 */
2010 {LDNS_RR_TYPE_ISDN, "ISDN", 1, 2, type_isdn_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
2011 /* 21 */
2012 {LDNS_RR_TYPE_RT, "RT", 2, 2, type_rt_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 1 },
2013 /* 22 */
2014 {LDNS_RR_TYPE_NSAP, "NSAP", 1, 1, type_nsap_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
2015 /* 23 */
2016 {LDNS_RR_TYPE_NSAP_PTR, "NSAP-PTR", 1, 1, type_nsap_ptr_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
2017 /* 24 */
2018 {LDNS_RR_TYPE_SIG, "SIG", 9, 9, type_sig_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 1 },
2019 /* 25 */
2020 {LDNS_RR_TYPE_KEY, "KEY", 4, 4, type_key_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
2021 /* 26 */
2022 {LDNS_RR_TYPE_PX, "PX", 3, 3, type_px_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 2 },
2023 /* 27 */
2024 {LDNS_RR_TYPE_GPOS, "GPOS", 1, 1, type_gpos_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
2025 /* 28 */
2026 {LDNS_RR_TYPE_AAAA, "AAAA", 1, 1, type_aaaa_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
2027 /* 29 */
2028 {LDNS_RR_TYPE_LOC, "LOC", 1, 1, type_loc_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
2029 /* 30 */
2030 {LDNS_RR_TYPE_NXT, "NXT", 2, 2, type_nxt_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 1 },
2031 /* 31 */
2032 {LDNS_RR_TYPE_EID, "EID", 1, 1, type_eid_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
2033 /* 32 */
2034 {LDNS_RR_TYPE_NIMLOC, "NIMLOC", 1, 1, type_nimloc_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
2035 /* 33 */
2036 {LDNS_RR_TYPE_SRV, "SRV", 4, 4, type_srv_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 1 },
2037 /* 34 */
2038 {LDNS_RR_TYPE_ATMA, "ATMA", 1, 1, type_atma_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
2039 /* 35 */
2040 {LDNS_RR_TYPE_NAPTR, "NAPTR", 6, 6, type_naptr_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 1 },
2041 /* 36 */
2042 {LDNS_RR_TYPE_KX, "KX", 2, 2, type_kx_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 1 },
2043 /* 37 */
2044 {LDNS_RR_TYPE_CERT, "CERT", 4, 4, type_cert_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
2045 /* 38 */
2046 {LDNS_RR_TYPE_A6, "A6", 1, 1, type_a6_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
2047 /* 39 */
2048 {LDNS_RR_TYPE_DNAME, "DNAME", 1, 1, type_dname_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 1 },
2049 /* 40 */
2050 {LDNS_RR_TYPE_SINK, "SINK", 1, 1, type_sink_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
2051 /* 41 */
2052 {LDNS_RR_TYPE_OPT, "OPT", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
2053 /* 42 */
2054 {LDNS_RR_TYPE_APL, "APL", 0, 0, type_apl_wireformat, LDNS_RDF_TYPE_APL, LDNS_RR_NO_COMPRESS, 0 },
2055 /* 43 */
2056 {LDNS_RR_TYPE_DS, "DS", 4, 4, type_ds_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
2057 /* 44 */
2058 {LDNS_RR_TYPE_SSHFP, "SSHFP", 3, 3, type_sshfp_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
2059 /* 45 */
2060 {LDNS_RR_TYPE_IPSECKEY, "IPSECKEY", 1, 1, type_ipseckey_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
2061 /* 46 */
2062 {LDNS_RR_TYPE_RRSIG, "RRSIG", 9, 9, type_rrsig_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 1 },
2063 /* 47 */
2064 {LDNS_RR_TYPE_NSEC, "NSEC", 1, 2, type_nsec_wireformat, LDNS_RDF_TYPE_NSEC, LDNS_RR_NO_COMPRESS, 1 },
2065 /* 48 */
2066 {LDNS_RR_TYPE_DNSKEY, "DNSKEY", 4, 4, type_dnskey_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
2067 /* 49 */
d1b2b5ca 2068 {LDNS_RR_TYPE_DHCID, "DHCID", 1, 1, type_dhcid_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
825eb42b
JL
2069 /* 50 */
2070 {LDNS_RR_TYPE_NSEC3, "NSEC3", 5, 6, type_nsec3_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
2071 /* 51 */
d1b2b5ca 2072 {LDNS_RR_TYPE_NSEC3PARAM, "NSEC3PARAM", 4, 4, type_nsec3param_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
825eb42b 2073 /* 52 */
d1b2b5ca
JM
2074 {LDNS_RR_TYPE_TLSA, "TLSA", 4, 4, type_tlsa_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
2075
825eb42b
JL
2076{LDNS_RR_TYPE_NULL, "TYPE53", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
2077{LDNS_RR_TYPE_NULL, "TYPE54", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
2078{LDNS_RR_TYPE_NULL, "TYPE55", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
2079{LDNS_RR_TYPE_NULL, "TYPE56", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
2080{LDNS_RR_TYPE_NULL, "TYPE57", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
d1b2b5ca 2081 /* 58 */
ac996e71 2082{LDNS_RR_TYPE_TALINK, "TALINK", 2, 2, type_talink_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 2 },
825eb42b
JL
2083{LDNS_RR_TYPE_NULL, "TYPE59", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
2084{LDNS_RR_TYPE_NULL, "TYPE60", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
2085{LDNS_RR_TYPE_NULL, "TYPE61", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
2086{LDNS_RR_TYPE_NULL, "TYPE62", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
2087{LDNS_RR_TYPE_NULL, "TYPE63", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
2088{LDNS_RR_TYPE_NULL, "TYPE64", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
2089{LDNS_RR_TYPE_NULL, "TYPE65", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
2090{LDNS_RR_TYPE_NULL, "TYPE66", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
2091{LDNS_RR_TYPE_NULL, "TYPE67", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
2092{LDNS_RR_TYPE_NULL, "TYPE68", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
2093{LDNS_RR_TYPE_NULL, "TYPE69", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
2094{LDNS_RR_TYPE_NULL, "TYPE70", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
2095{LDNS_RR_TYPE_NULL, "TYPE71", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
2096{LDNS_RR_TYPE_NULL, "TYPE72", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
2097{LDNS_RR_TYPE_NULL, "TYPE73", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
2098{LDNS_RR_TYPE_NULL, "TYPE74", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
2099{LDNS_RR_TYPE_NULL, "TYPE75", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
2100{LDNS_RR_TYPE_NULL, "TYPE76", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
2101{LDNS_RR_TYPE_NULL, "TYPE77", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
2102{LDNS_RR_TYPE_NULL, "TYPE78", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
2103{LDNS_RR_TYPE_NULL, "TYPE79", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
2104{LDNS_RR_TYPE_NULL, "TYPE80", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
2105{LDNS_RR_TYPE_NULL, "TYPE81", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
2106{LDNS_RR_TYPE_NULL, "TYPE82", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
2107{LDNS_RR_TYPE_NULL, "TYPE83", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
2108{LDNS_RR_TYPE_NULL, "TYPE84", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
2109{LDNS_RR_TYPE_NULL, "TYPE85", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
2110{LDNS_RR_TYPE_NULL, "TYPE86", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
2111{LDNS_RR_TYPE_NULL, "TYPE87", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
2112{LDNS_RR_TYPE_NULL, "TYPE88", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
2113{LDNS_RR_TYPE_NULL, "TYPE89", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
2114{LDNS_RR_TYPE_NULL, "TYPE90", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
2115{LDNS_RR_TYPE_NULL, "TYPE91", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
2116{LDNS_RR_TYPE_NULL, "TYPE92", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
2117{LDNS_RR_TYPE_NULL, "TYPE93", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
2118{LDNS_RR_TYPE_NULL, "TYPE94", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
2119{LDNS_RR_TYPE_NULL, "TYPE95", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
2120{LDNS_RR_TYPE_NULL, "TYPE96", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
2121{LDNS_RR_TYPE_NULL, "TYPE97", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
2122{LDNS_RR_TYPE_NULL, "TYPE98", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
2123{LDNS_RR_TYPE_SPF, "SPF", 1, 0, NULL, LDNS_RDF_TYPE_STR, LDNS_RR_NO_COMPRESS, 0 },
2124{LDNS_RR_TYPE_NULL, "TYPE100", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
2125{LDNS_RR_TYPE_NULL, "TYPE101", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
2126{LDNS_RR_TYPE_NULL, "TYPE102", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
2127{LDNS_RR_TYPE_NULL, "TYPE103", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
2128{LDNS_RR_TYPE_NULL, "TYPE104", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
2129{LDNS_RR_TYPE_NULL, "TYPE105", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
2130{LDNS_RR_TYPE_NULL, "TYPE106", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
2131{LDNS_RR_TYPE_NULL, "TYPE107", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
2132{LDNS_RR_TYPE_NULL, "TYPE108", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
2133{LDNS_RR_TYPE_NULL, "TYPE109", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
2134{LDNS_RR_TYPE_NULL, "TYPE110", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
2135{LDNS_RR_TYPE_NULL, "TYPE111", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
2136{LDNS_RR_TYPE_NULL, "TYPE112", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
2137{LDNS_RR_TYPE_NULL, "TYPE113", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
2138{LDNS_RR_TYPE_NULL, "TYPE114", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
2139{LDNS_RR_TYPE_NULL, "TYPE115", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
2140{LDNS_RR_TYPE_NULL, "TYPE116", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
2141{LDNS_RR_TYPE_NULL, "TYPE117", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
2142{LDNS_RR_TYPE_NULL, "TYPE118", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
2143{LDNS_RR_TYPE_NULL, "TYPE119", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
2144{LDNS_RR_TYPE_NULL, "TYPE120", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
2145{LDNS_RR_TYPE_NULL, "TYPE121", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
2146{LDNS_RR_TYPE_NULL, "TYPE122", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
2147{LDNS_RR_TYPE_NULL, "TYPE123", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
2148{LDNS_RR_TYPE_NULL, "TYPE124", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
2149{LDNS_RR_TYPE_NULL, "TYPE125", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
2150{LDNS_RR_TYPE_NULL, "TYPE126", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
2151{LDNS_RR_TYPE_NULL, "TYPE127", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
2152{LDNS_RR_TYPE_NULL, "TYPE128", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
2153{LDNS_RR_TYPE_NULL, "TYPE129", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
2154{LDNS_RR_TYPE_NULL, "TYPE130", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
2155{LDNS_RR_TYPE_NULL, "TYPE131", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
2156{LDNS_RR_TYPE_NULL, "TYPE132", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
2157{LDNS_RR_TYPE_NULL, "TYPE133", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
2158{LDNS_RR_TYPE_NULL, "TYPE134", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
2159{LDNS_RR_TYPE_NULL, "TYPE135", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
2160{LDNS_RR_TYPE_NULL, "TYPE136", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
2161{LDNS_RR_TYPE_NULL, "TYPE137", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
2162{LDNS_RR_TYPE_NULL, "TYPE138", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
2163{LDNS_RR_TYPE_NULL, "TYPE139", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
2164{LDNS_RR_TYPE_NULL, "TYPE140", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
2165{LDNS_RR_TYPE_NULL, "TYPE141", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
2166{LDNS_RR_TYPE_NULL, "TYPE142", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
2167{LDNS_RR_TYPE_NULL, "TYPE143", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
2168{LDNS_RR_TYPE_NULL, "TYPE144", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
2169{LDNS_RR_TYPE_NULL, "TYPE145", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
2170{LDNS_RR_TYPE_NULL, "TYPE146", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
2171{LDNS_RR_TYPE_NULL, "TYPE147", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
2172{LDNS_RR_TYPE_NULL, "TYPE148", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
2173{LDNS_RR_TYPE_NULL, "TYPE149", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
2174{LDNS_RR_TYPE_NULL, "TYPE150", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
2175{LDNS_RR_TYPE_NULL, "TYPE151", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
2176{LDNS_RR_TYPE_NULL, "TYPE152", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
2177{LDNS_RR_TYPE_NULL, "TYPE153", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
2178{LDNS_RR_TYPE_NULL, "TYPE154", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
2179{LDNS_RR_TYPE_NULL, "TYPE155", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
2180{LDNS_RR_TYPE_NULL, "TYPE156", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
2181{LDNS_RR_TYPE_NULL, "TYPE157", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
2182{LDNS_RR_TYPE_NULL, "TYPE158", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
2183{LDNS_RR_TYPE_NULL, "TYPE159", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
2184{LDNS_RR_TYPE_NULL, "TYPE160", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
2185{LDNS_RR_TYPE_NULL, "TYPE161", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
2186{LDNS_RR_TYPE_NULL, "TYPE162", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
2187{LDNS_RR_TYPE_NULL, "TYPE163", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
2188{LDNS_RR_TYPE_NULL, "TYPE164", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
2189{LDNS_RR_TYPE_NULL, "TYPE165", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
2190{LDNS_RR_TYPE_NULL, "TYPE166", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
2191{LDNS_RR_TYPE_NULL, "TYPE167", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
2192{LDNS_RR_TYPE_NULL, "TYPE168", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
2193{LDNS_RR_TYPE_NULL, "TYPE169", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
2194{LDNS_RR_TYPE_NULL, "TYPE170", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
2195{LDNS_RR_TYPE_NULL, "TYPE171", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
2196{LDNS_RR_TYPE_NULL, "TYPE172", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
2197{LDNS_RR_TYPE_NULL, "TYPE173", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
2198{LDNS_RR_TYPE_NULL, "TYPE174", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
2199{LDNS_RR_TYPE_NULL, "TYPE175", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
2200{LDNS_RR_TYPE_NULL, "TYPE176", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
2201{LDNS_RR_TYPE_NULL, "TYPE177", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
2202{LDNS_RR_TYPE_NULL, "TYPE178", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
2203{LDNS_RR_TYPE_NULL, "TYPE179", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
2204{LDNS_RR_TYPE_NULL, "TYPE180", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
2205{LDNS_RR_TYPE_NULL, "TYPE181", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
2206{LDNS_RR_TYPE_NULL, "TYPE182", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
2207{LDNS_RR_TYPE_NULL, "TYPE183", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
2208{LDNS_RR_TYPE_NULL, "TYPE184", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
2209{LDNS_RR_TYPE_NULL, "TYPE185", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
2210{LDNS_RR_TYPE_NULL, "TYPE186", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
2211{LDNS_RR_TYPE_NULL, "TYPE187", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
2212{LDNS_RR_TYPE_NULL, "TYPE188", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
2213{LDNS_RR_TYPE_NULL, "TYPE189", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
2214{LDNS_RR_TYPE_NULL, "TYPE190", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
2215{LDNS_RR_TYPE_NULL, "TYPE191", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
2216{LDNS_RR_TYPE_NULL, "TYPE192", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
2217{LDNS_RR_TYPE_NULL, "TYPE193", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
2218{LDNS_RR_TYPE_NULL, "TYPE194", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
2219{LDNS_RR_TYPE_NULL, "TYPE195", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
2220{LDNS_RR_TYPE_NULL, "TYPE196", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
2221{LDNS_RR_TYPE_NULL, "TYPE197", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
2222{LDNS_RR_TYPE_NULL, "TYPE198", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
2223{LDNS_RR_TYPE_NULL, "TYPE199", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
2224{LDNS_RR_TYPE_NULL, "TYPE200", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
2225{LDNS_RR_TYPE_NULL, "TYPE201", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
2226{LDNS_RR_TYPE_NULL, "TYPE202", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
2227{LDNS_RR_TYPE_NULL, "TYPE203", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
2228{LDNS_RR_TYPE_NULL, "TYPE204", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
2229{LDNS_RR_TYPE_NULL, "TYPE205", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
2230{LDNS_RR_TYPE_NULL, "TYPE206", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
2231{LDNS_RR_TYPE_NULL, "TYPE207", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
2232{LDNS_RR_TYPE_NULL, "TYPE208", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
2233{LDNS_RR_TYPE_NULL, "TYPE209", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
2234{LDNS_RR_TYPE_NULL, "TYPE210", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
2235{LDNS_RR_TYPE_NULL, "TYPE211", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
2236{LDNS_RR_TYPE_NULL, "TYPE212", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
2237{LDNS_RR_TYPE_NULL, "TYPE213", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
2238{LDNS_RR_TYPE_NULL, "TYPE214", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
2239{LDNS_RR_TYPE_NULL, "TYPE215", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
2240{LDNS_RR_TYPE_NULL, "TYPE216", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
2241{LDNS_RR_TYPE_NULL, "TYPE217", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
2242{LDNS_RR_TYPE_NULL, "TYPE218", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
2243{LDNS_RR_TYPE_NULL, "TYPE219", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
2244{LDNS_RR_TYPE_NULL, "TYPE220", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
2245{LDNS_RR_TYPE_NULL, "TYPE221", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
2246{LDNS_RR_TYPE_NULL, "TYPE222", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
2247{LDNS_RR_TYPE_NULL, "TYPE223", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
2248{LDNS_RR_TYPE_NULL, "TYPE224", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
2249{LDNS_RR_TYPE_NULL, "TYPE225", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
2250{LDNS_RR_TYPE_NULL, "TYPE226", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
2251{LDNS_RR_TYPE_NULL, "TYPE227", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
2252{LDNS_RR_TYPE_NULL, "TYPE228", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
2253{LDNS_RR_TYPE_NULL, "TYPE229", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
2254{LDNS_RR_TYPE_NULL, "TYPE230", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
2255{LDNS_RR_TYPE_NULL, "TYPE231", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
2256{LDNS_RR_TYPE_NULL, "TYPE232", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
2257{LDNS_RR_TYPE_NULL, "TYPE233", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
2258{LDNS_RR_TYPE_NULL, "TYPE234", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
2259{LDNS_RR_TYPE_NULL, "TYPE235", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
2260{LDNS_RR_TYPE_NULL, "TYPE236", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
2261{LDNS_RR_TYPE_NULL, "TYPE237", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
2262{LDNS_RR_TYPE_NULL, "TYPE238", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
2263{LDNS_RR_TYPE_NULL, "TYPE239", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
2264{LDNS_RR_TYPE_NULL, "TYPE240", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
2265{LDNS_RR_TYPE_NULL, "TYPE241", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
2266{LDNS_RR_TYPE_NULL, "TYPE242", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
2267{LDNS_RR_TYPE_NULL, "TYPE243", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
2268{LDNS_RR_TYPE_NULL, "TYPE244", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
2269{LDNS_RR_TYPE_NULL, "TYPE245", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
2270{LDNS_RR_TYPE_NULL, "TYPE246", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
2271{LDNS_RR_TYPE_NULL, "TYPE247", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
2272{LDNS_RR_TYPE_NULL, "TYPE248", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
2273{LDNS_RR_TYPE_NULL, "TYPE249", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
b5dedcca
JL
2274/* LDNS_RDF_TYPE_INT16_DATA essentially takes two fields (length and data) and
2275 * makes them into one. So, while in rfc 2845 is specified that a TSIG may have
2276 * 8 or 9 rdata fields, by this implementation, the min/max are 7 each.
2277 */
2278{LDNS_RR_TYPE_TSIG, "TSIG", 7, 7, type_tsig_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 },
825eb42b
JL
2279/* split in array, no longer contiguous */
2280{LDNS_RR_TYPE_DLV, "DLV", 4, 4, type_ds_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 }
2281};
2282/** \endcond */
2283
2284/**
2285 * \def LDNS_RDATA_FIELD_DESCRIPTORS_COUNT
2286 * computes the number of rdata fields
2287 */
2288#define LDNS_RDATA_FIELD_DESCRIPTORS_COUNT \
2289 (sizeof(rdata_field_descriptors)/sizeof(rdata_field_descriptors[0]))
2290
2291const ldns_rr_descriptor *
2292ldns_rr_descript(uint16_t type)
2293{
2294 size_t i;
2295 if (type <= LDNS_RDATA_FIELD_DESCRIPTORS_COMMON) {
2296 return &rdata_field_descriptors[type];
2297 } else {
2298 /* because not all array index equals type code */
2299 for (i = LDNS_RDATA_FIELD_DESCRIPTORS_COMMON;
2300 i < LDNS_RDATA_FIELD_DESCRIPTORS_COUNT;
2301 i++) {
2302 if (rdata_field_descriptors[i]._type == type) {
2303 return &rdata_field_descriptors[i];
2304 }
2305 }
2306 return &rdata_field_descriptors[0];
2307 }
2308}
2309
2310size_t
2311ldns_rr_descriptor_minimum(const ldns_rr_descriptor *descriptor)
2312{
2313 if (descriptor) {
2314 return descriptor->_minimum;
2315 } else {
2316 return 0;
2317 }
2318}
2319
2320size_t
2321ldns_rr_descriptor_maximum(const ldns_rr_descriptor *descriptor)
2322{
2323 if (descriptor) {
2324 if (descriptor->_variable != LDNS_RDF_TYPE_NONE) {
2325 /* Should really be SIZE_MAX... bad FreeBSD. */
2326 return UINT_MAX;
2327 } else {
2328 return descriptor->_maximum;
2329 }
2330 } else {
2331 return 0;
2332 }
2333}
2334
2335ldns_rdf_type
2336ldns_rr_descriptor_field_type(const ldns_rr_descriptor *descriptor,
2337 size_t index)
2338{
2339 assert(descriptor != NULL);
2340 assert(index < descriptor->_maximum
2341 || descriptor->_variable != LDNS_RDF_TYPE_NONE);
2342 if (index < descriptor->_maximum) {
2343 return descriptor->_wireformat[index];
2344 } else {
2345 return descriptor->_variable;
2346 }
2347}
2348
2349ldns_rr_type
2350ldns_get_rr_type_by_name(const char *name)
2351{
2352 unsigned int i;
2353 const char *desc_name;
2354 const ldns_rr_descriptor *desc;
2355
2356 /* TYPEXX representation */
2357 if (strlen(name) > 4 && strncasecmp(name, "TYPE", 4) == 0) {
2358 return atoi(name + 4);
2359 }
2360
2361 /* Normal types */
2362 for (i = 0; i < (unsigned int) LDNS_RDATA_FIELD_DESCRIPTORS_COUNT; i++) {
2363 desc = &rdata_field_descriptors[i];
2364 desc_name = desc->_name;
2365 if(desc_name &&
2366 strlen(name) == strlen(desc_name) &&
2367 strncasecmp(name, desc_name, strlen(desc_name)) == 0) {
2368 /* because not all array index equals type code */
2369 return desc->_type;
2370 }
2371 }
2372
2373 /* special cases for query types */
2374 if (strlen(name) == 4 && strncasecmp(name, "IXFR", 4) == 0) {
2375 return 251;
2376 } else if (strlen(name) == 4 && strncasecmp(name, "AXFR", 4) == 0) {
2377 return 252;
2378 } else if (strlen(name) == 5 && strncasecmp(name, "MAILB", 5) == 0) {
2379 return 253;
2380 } else if (strlen(name) == 5 && strncasecmp(name, "MAILA", 5) == 0) {
2381 return 254;
2382 } else if (strlen(name) == 3 && strncasecmp(name, "ANY", 3) == 0) {
2383 return 255;
2384 }
2385
2386 return 0;
2387}
2388
2389ldns_rr_class
2390ldns_get_rr_class_by_name(const char *name)
2391{
2392 ldns_lookup_table *lt;
2393
2394 /* CLASSXX representation */
2395 if (strlen(name) > 5 && strncasecmp(name, "CLASS", 5) == 0) {
2396 return atoi(name + 5);
2397 }
2398
2399 /* Normal types */
2400 lt = ldns_lookup_by_name(ldns_rr_classes, name);
2401
2402 if (lt) {
2403 return lt->id;
2404 }
2405 return 0;
2406}
2407
2408
2409ldns_rr_type
2410ldns_rdf2rr_type(const ldns_rdf *rd)
2411{
2412 ldns_rr_type r;
2413
2414 if (!rd) {
2415 return 0;
2416 }
2417
2418 if (ldns_rdf_get_type(rd) != LDNS_RDF_TYPE_TYPE) {
2419 return 0;
2420 }
2421
2422 r = (ldns_rr_type) ldns_rdf2native_int16(rd);
2423 return r;
2424}
2425
2426ldns_rr_type
2427ldns_rr_list_type(const ldns_rr_list *rr_list)
2428{
2429 if (rr_list && ldns_rr_list_rr_count(rr_list) > 0) {
2430 return ldns_rr_get_type(ldns_rr_list_rr(rr_list, 0));
2431 } else {
2432 return 0;
2433 }
2434}
2435
2436ldns_rdf *
2437ldns_rr_list_owner(const ldns_rr_list *rr_list)
2438{
2439 if (rr_list && ldns_rr_list_rr_count(rr_list) > 0) {
2440 return ldns_rr_owner(ldns_rr_list_rr(rr_list, 0));
2441 } else {
2442 return NULL;
2443 }
2444}