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