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