1 /* 2 * services/localzone.h - local zones authority service. 3 * 4 * Copyright (c) 2007, NLnet Labs. All rights reserved. 5 * 6 * This software is open source. 7 * 8 * Redistribution and use in source and binary forms, with or without 9 * modification, are permitted provided that the following conditions 10 * are met: 11 * 12 * Redistributions of source code must retain the above copyright notice, 13 * this list of conditions and the following disclaimer. 14 * 15 * Redistributions in binary form must reproduce the above copyright notice, 16 * this list of conditions and the following disclaimer in the documentation 17 * and/or other materials provided with the distribution. 18 * 19 * Neither the name of the NLNET LABS nor the names of its contributors may 20 * be used to endorse or promote products derived from this software without 21 * specific prior written permission. 22 * 23 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 24 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 25 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 26 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 27 * HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 28 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED 29 * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 30 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 31 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 32 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 33 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 34 */ 35 36 /** 37 * \file 38 * 39 * This file contains functions to enable local zone authority service. 40 */ 41 42 #ifndef SERVICES_LOCALZONE_H 43 #define SERVICES_LOCALZONE_H 44 #include "util/rbtree.h" 45 #include "util/locks.h" 46 #include "util/storage/dnstree.h" 47 #include "util/module.h" 48 #include "services/view.h" 49 #include "sldns/sbuffer.h" 50 struct packed_rrset_data; 51 struct ub_packed_rrset_key; 52 struct regional; 53 struct config_file; 54 struct edns_data; 55 struct query_info; 56 struct sldns_buffer; 57 struct comm_reply; 58 struct config_strlist; 59 60 extern const char** local_zones_default_special; 61 extern const char** local_zones_default_reverse; 62 63 /** 64 * Local zone type 65 * This type determines processing for queries that did not match 66 * local-data directly. 67 */ 68 enum localzone_type { 69 /** unset type, used for unset tag_action elements */ 70 local_zone_unset = 0, 71 /** drop query */ 72 local_zone_deny, 73 /** answer with error */ 74 local_zone_refuse, 75 /** answer nxdomain or nodata */ 76 local_zone_static, 77 /** resolve normally */ 78 local_zone_transparent, 79 /** do not block types at localdata names */ 80 local_zone_typetransparent, 81 /** answer with data at zone apex */ 82 local_zone_redirect, 83 /** remove default AS112 blocking contents for zone 84 * nodefault is used in config not during service. */ 85 local_zone_nodefault, 86 /** log client address, but no block (transparent) */ 87 local_zone_inform, 88 /** log client address, and block (drop) */ 89 local_zone_inform_deny, 90 /** log client address, and direct */ 91 local_zone_inform_redirect, 92 /** resolve normally, even when there is local data */ 93 local_zone_always_transparent, 94 /** resolve normally, even when there is local data but return NODATA for A queries */ 95 local_zone_block_a, 96 /** resolve normally, even when there is local data, but return NODATA for AAAA queries */ 97 local_zone_block_aaaa, 98 /** resolve normally, use local data, else return NODATA for A queries */ 99 local_zone_block_a_wdata, 100 /** resolve normally, use local data, else return NODATA for AAAA queries */ 101 local_zone_block_aaaa_wdata, 102 /** answer with error, even when there is local data */ 103 local_zone_always_refuse, 104 /** answer with nxdomain, even when there is local data */ 105 local_zone_always_nxdomain, 106 /** answer with noerror/nodata, even when there is local data */ 107 local_zone_always_nodata, 108 /** drop query, even when there is local data */ 109 local_zone_always_deny, 110 /** answer with 0.0.0.0 or ::0 or noerror/nodata, even when there is 111 * local data */ 112 local_zone_always_null, 113 /** answer not from the view, but global or no-answer */ 114 local_zone_noview, 115 /** truncate the response; client should retry via tcp */ 116 local_zone_truncate, 117 /** Invalid type, cannot be used to generate answer */ 118 local_zone_invalid 119 }; 120 121 /** 122 * Authoritative local zones storage, shared. 123 */ 124 struct local_zones { 125 /** lock on the localzone tree */ 126 lock_rw_type lock; 127 /** rbtree of struct local_zone */ 128 rbtree_type ztree; 129 }; 130 131 /** 132 * Local zone. A locally served authoritative zone. 133 */ 134 struct local_zone { 135 /** rbtree node, key is name and class */ 136 rbnode_type node; 137 /** parent zone, if any. */ 138 struct local_zone* parent; 139 140 /** zone name, in uncompressed wireformat */ 141 uint8_t* name; 142 /** length of zone name */ 143 size_t namelen; 144 /** number of labels in zone name */ 145 int namelabs; 146 /** the class of this zone. 147 * uses 'dclass' to not conflict with c++ keyword class. */ 148 uint16_t dclass; 149 150 /** lock on the data in the structure 151 * For the node, parent, name, namelen, namelabs, dclass, you 152 * need to also hold the zones_tree lock to change them (or to 153 * delete this zone) */ 154 lock_rw_type lock; 155 156 /** how to process zone */ 157 enum localzone_type type; 158 /** tag bitlist */ 159 uint8_t* taglist; 160 /** length of the taglist (in bytes) */ 161 size_t taglen; 162 /** netblock addr_tree with struct local_zone_override information 163 * or NULL if there are no override elements */ 164 struct rbtree_type* override_tree; 165 166 /** in this region the zone's data is allocated. 167 * the struct local_zone itself is malloced. */ 168 struct regional* region; 169 /** local data for this zone 170 * rbtree of struct local_data */ 171 rbtree_type data; 172 /** if data contains zone apex SOA data, this is a ptr to it. */ 173 struct ub_packed_rrset_key* soa; 174 /** if data contains zone apex SOA data, this is a ptr to an 175 * artificial negative SOA rrset (TTL is the minimum of the TTL and the 176 * SOA.MINIMUM). */ 177 struct ub_packed_rrset_key* soa_negative; 178 }; 179 180 /** 181 * Local data. One domain name, and the RRs to go with it. 182 */ 183 struct local_data { 184 /** rbtree node, key is name only */ 185 rbnode_type node; 186 /** domain name */ 187 uint8_t* name; 188 /** length of name */ 189 size_t namelen; 190 /** number of labels in name */ 191 int namelabs; 192 /** the data rrsets, with different types, linked list. 193 * If this list is NULL, the node is an empty non-terminal. */ 194 struct local_rrset* rrsets; 195 }; 196 197 /** 198 * A local data RRset 199 */ 200 struct local_rrset { 201 /** next in list */ 202 struct local_rrset* next; 203 /** RRset data item */ 204 struct ub_packed_rrset_key* rrset; 205 }; 206 207 /** 208 * Local zone override information 209 */ 210 struct local_zone_override { 211 /** node in addrtree */ 212 struct addr_tree_node node; 213 /** override for local zone type */ 214 enum localzone_type type; 215 }; 216 217 /** 218 * Create local zones storage 219 * @return new struct or NULL on error. 220 */ 221 struct local_zones* local_zones_create(void); 222 223 /** 224 * Delete local zones storage 225 * @param zones: to delete. 226 */ 227 void local_zones_delete(struct local_zones* zones); 228 229 /** 230 * Apply config settings; setup the local authoritative data. 231 * Takes care of locking. 232 * @param zones: is set up. 233 * @param cfg: config data. 234 * @return false on error. 235 */ 236 int local_zones_apply_cfg(struct local_zones* zones, struct config_file* cfg); 237 238 /** 239 * Compare two local_zone entries in rbtree. Sort hierarchical but not 240 * canonical 241 * @param z1: zone 1 242 * @param z2: zone 2 243 * @return: -1, 0, +1 comparison value. 244 */ 245 int local_zone_cmp(const void* z1, const void* z2); 246 247 /** 248 * Compare two local_data entries in rbtree. Sort canonical. 249 * @param d1: data 1 250 * @param d2: data 2 251 * @return: -1, 0, +1 comparison value. 252 */ 253 int local_data_cmp(const void* d1, const void* d2); 254 255 /** 256 * Delete one zone 257 * @param z: to delete. 258 */ 259 void local_zone_delete(struct local_zone* z); 260 261 /** 262 * Lookup zone that contains the given name, class and taglist. 263 * User must lock the tree or result zone. 264 * @param zones: the zones tree 265 * @param name: dname to lookup 266 * @param len: length of name. 267 * @param labs: labelcount of name. 268 * @param dclass: class to lookup. 269 * @param dtype: type to lookup, if type DS a zone higher is used for zonecuts. 270 * @param taglist: taglist to lookup. 271 * @param taglen: length of taglist. 272 * @param ignoretags: lookup zone by name and class, regardless the 273 * local-zone's tags. 274 * @param foradd: if the lookup is for addition or removal of the type. 275 * Used for type DS. The lookup for answers turns this off. 276 * @return closest local_zone or NULL if no covering zone is found. 277 */ 278 struct local_zone* local_zones_tags_lookup(struct local_zones* zones, 279 uint8_t* name, size_t len, int labs, uint16_t dclass, uint16_t dtype, 280 uint8_t* taglist, size_t taglen, int ignoretags, int foradd); 281 282 /** 283 * Lookup zone that contains the given name, class. 284 * User must lock the tree or result zone. 285 * @param zones: the zones tree 286 * @param name: dname to lookup 287 * @param len: length of name. 288 * @param labs: labelcount of name. 289 * @param dclass: class to lookup. 290 * @param dtype: type of the record, if type DS then a zone higher up is found 291 * pass 0 to just plain find a zone for a name. 292 * @param foradd: if the lookup is for addition or removal of the type. 293 * Used for type DS. The lookup for answers turns this off. 294 * @return closest local_zone or NULL if no covering zone is found. 295 */ 296 struct local_zone* local_zones_lookup(struct local_zones* zones, 297 uint8_t* name, size_t len, int labs, uint16_t dclass, uint16_t dtype, 298 int foradd); 299 300 /** 301 * Debug helper. Print all zones 302 * Takes care of locking. 303 * @param zones: the zones tree 304 */ 305 void local_zones_print(struct local_zones* zones); 306 307 /** 308 * Answer authoritatively for local zones. 309 * Takes care of locking. 310 * @param zones: the stored zones (shared, read only). 311 * @param env: the module environment. 312 * @param qinfo: query info (parsed). 313 * @param edns: edns info (parsed). 314 * @param buf: buffer with query ID and flags, also for reply. 315 * @param temp: temporary storage region. 316 * @param repinfo: source address for checks. may be NULL. 317 * @param taglist: taglist for checks. May be NULL. 318 * @param taglen: length of the taglist. 319 * @param tagactions: local zone actions for tags. May be NULL. 320 * @param tagactionssize: length of the tagactions. 321 * @param tag_datas: array per tag of strlist with rdata strings. or NULL. 322 * @param tag_datas_size: size of tag_datas array. 323 * @param tagname: array of tag name strings (for debug output). 324 * @param num_tags: number of items in tagname array. 325 * @param view: answer using this view. May be NULL. 326 * @return true if answer is in buffer. false if query is not answered 327 * by authority data. If the reply should be dropped altogether, the return 328 * value is true, but the buffer is cleared (empty). 329 * It can also return true if a non-exact alias answer is found. In this 330 * case qinfo->local_alias points to the corresponding alias RRset but the 331 * answer is NOT encoded in buffer. It's the caller's responsibility to 332 * complete the alias chain (if needed) and encode the final set of answer. 333 * Data pointed to by qinfo->local_alias is allocated in 'temp' or refers to 334 * configuration data. So the caller will need to make a deep copy of it 335 * if it needs to keep it beyond the lifetime of 'temp' or a dynamic update 336 * to local zone data. 337 */ 338 int local_zones_answer(struct local_zones* zones, struct module_env* env, 339 struct query_info* qinfo, struct edns_data* edns, struct sldns_buffer* buf, 340 struct regional* temp, struct comm_reply* repinfo, uint8_t* taglist, 341 size_t taglen, uint8_t* tagactions, size_t tagactionssize, 342 struct config_strlist** tag_datas, size_t tag_datas_size, 343 char** tagname, int num_tags, struct view* view); 344 345 /** 346 * Answer using the local zone only (not local data used). 347 * @param z: zone for query. 348 * @param env: module environment. 349 * @param qinfo: query. 350 * @param edns: edns from query. 351 * @param repinfo: source address for checks. may be NULL. 352 * @param buf: buffer for answer. 353 * @param temp: temp region for encoding. 354 * @param ld: local data, if NULL, no such name exists in localdata. 355 * @param lz_type: type of the local zone. 356 * @return 1 if a reply is to be sent, 0 if not. 357 */ 358 int 359 local_zones_zone_answer(struct local_zone* z, struct module_env* env, 360 struct query_info* qinfo, struct edns_data* edns, 361 struct comm_reply* repinfo, sldns_buffer* buf, struct regional* temp, 362 struct local_data* ld, enum localzone_type lz_type); 363 364 /** 365 * Parse the string into localzone type. 366 * 367 * @param str: string to parse 368 * @param t: local zone type returned here. 369 * @return 0 on parse error. 370 */ 371 int local_zone_str2type(const char* str, enum localzone_type* t); 372 373 /** 374 * Print localzone type to a string. Pointer to a constant string. 375 * 376 * @param t: local zone type. 377 * @return constant string that describes type. 378 */ 379 const char* local_zone_type2str(enum localzone_type t); 380 381 /** 382 * Find zone that with exactly given name, class. 383 * User must lock the tree or result zone. 384 * @param zones: the zones tree 385 * @param name: dname to lookup 386 * @param len: length of name. 387 * @param labs: labelcount of name. 388 * @param dclass: class to lookup. 389 * @return the exact local_zone or NULL. 390 */ 391 struct local_zone* local_zones_find(struct local_zones* zones, 392 uint8_t* name, size_t len, int labs, uint16_t dclass); 393 394 /** 395 * Find zone that with exactly or smaller name/class 396 * User must lock the tree or result zone. 397 * @param zones: the zones tree 398 * @param name: dname to lookup 399 * @param len: length of name. 400 * @param labs: labelcount of name. 401 * @param dclass: class to lookup. 402 * @param exact: 1 on return is this is an exact match. 403 * @return the exact or smaller local_zone or NULL. 404 */ 405 struct local_zone* 406 local_zones_find_le(struct local_zones* zones, 407 uint8_t* name, size_t len, int labs, uint16_t dclass, 408 int* exact); 409 410 /** 411 * Add a new zone. Caller must hold the zones lock. 412 * Adjusts the other zones as well (parent pointers) after insertion. 413 * The zone must NOT exist (returns NULL and logs error). 414 * @param zones: the zones tree 415 * @param name: dname to add 416 * @param len: length of name. 417 * @param labs: labelcount of name. 418 * @param dclass: class to add. 419 * @param tp: type. 420 * @return local_zone or NULL on error, caller must printout memory error. 421 */ 422 struct local_zone* local_zones_add_zone(struct local_zones* zones, 423 uint8_t* name, size_t len, int labs, uint16_t dclass, 424 enum localzone_type tp); 425 426 /** 427 * Delete a zone. Caller must hold the zones lock. 428 * Adjusts the other zones as well (parent pointers) after insertion. 429 * @param zones: the zones tree 430 * @param zone: the zone to delete from tree. Also deletes zone from memory. 431 */ 432 void local_zones_del_zone(struct local_zones* zones, struct local_zone* zone); 433 434 /** 435 * Add RR data into the localzone data. 436 * Looks up the zone, if no covering zone, a transparent zone with the 437 * name of the RR is created. 438 * @param zones: the zones tree. Not locked by caller. 439 * @param rr: string with on RR. 440 * @return false on failure. 441 */ 442 int local_zones_add_RR(struct local_zones* zones, const char* rr); 443 444 /** 445 * Remove data from domain name in the tree. 446 * All types are removed. No effect if zone or name does not exist. 447 * @param zones: zones tree. 448 * @param name: dname to remove 449 * @param len: length of name. 450 * @param labs: labelcount of name. 451 * @param dclass: class to remove. 452 */ 453 void local_zones_del_data(struct local_zones* zones, 454 uint8_t* name, size_t len, int labs, uint16_t dclass); 455 456 457 /** 458 * Form wireformat from text format domain name. 459 * @param str: the domain name in text "www.example.com" 460 * @param res: resulting wireformat is stored here with malloc. 461 * @param len: length of resulting wireformat. 462 * @param labs: number of labels in resulting wireformat. 463 * @return false on error, syntax or memory. Also logged. 464 */ 465 int parse_dname(const char* str, uint8_t** res, size_t* len, int* labs); 466 467 /** 468 * Find local data tag string match for the given type (in qinfo) in the list. 469 * If found, 'r' will be filled with corresponding rrset information. 470 * @param qinfo: contains name, type, and class for the data 471 * @param list: stores local tag data to be searched 472 * @param r: rrset key to be filled for matched data 473 * @param temp: region to allocate rrset in 'r' 474 * @return 1 if a match is found and rrset is built; otherwise 0 including 475 * errors. 476 */ 477 int local_data_find_tag_datas(const struct query_info* qinfo, 478 struct config_strlist* list, struct ub_packed_rrset_key* r, 479 struct regional* temp); 480 481 /** 482 * See if two sets of tag lists (in the form of bitmap) have the same tag that 483 * has an action. If so, '*tag' will be set to the found tag index, and the 484 * corresponding action will be returned in the form of local zone type. 485 * Otherwise the passed type (lzt) will be returned as the default action. 486 * Pointers except tagactions must not be NULL. 487 * @param taglist: 1st list of tags 488 * @param taglen: size of taglist in bytes 489 * @param taglist2: 2nd list of tags 490 * @param taglen2: size of taglist2 in bytes 491 * @param tagactions: local data actions for tags. May be NULL. 492 * @param tagactionssize: length of the tagactions. 493 * @param lzt: default action (local zone type) if no tag action is found. 494 * @param tag: see above. 495 * @param tagname: array of tag name strings (for debug output). 496 * @param num_tags: number of items in tagname array. 497 * @return found tag action or the default action. 498 */ 499 enum localzone_type local_data_find_tag_action(const uint8_t* taglist, 500 size_t taglen, const uint8_t* taglist2, size_t taglen2, 501 const uint8_t* tagactions, size_t tagactionssize, 502 enum localzone_type lzt, int* tag, char* const* tagname, int num_tags); 503 504 /** 505 * Enter defaults to local zone. 506 * @param zones: to add defaults to 507 * @param cfg: containing list of zones to exclude from default set. 508 * @return 1 on success; 0 otherwise. 509 */ 510 int local_zone_enter_defaults(struct local_zones* zones, 511 struct config_file* cfg); 512 513 /** 514 * Parses resource record string into wire format, also returning its field values. 515 * @param str: input resource record 516 * @param nm: domain name field 517 * @param type: record type field 518 * @param dclass: record class field 519 * @param ttl: ttl field 520 * @param rr: buffer for the parsed rr in wire format 521 * @param len: buffer length 522 * @param rdata: rdata field 523 * @param rdata_len: rdata field length 524 * @return 1 on success; 0 otherwise. 525 */ 526 int rrstr_get_rr_content(const char* str, uint8_t** nm, uint16_t* type, 527 uint16_t* dclass, time_t* ttl, uint8_t* rr, size_t len, 528 uint8_t** rdata, size_t* rdata_len); 529 530 /** 531 * Insert specified rdata into the specified resource record. 532 * @param region: allocator 533 * @param pd: data portion of the destination resource record 534 * @param rdata: source rdata 535 * @param rdata_len: source rdata length 536 * @param ttl: time to live 537 * @param rrstr: resource record in text form (for logging) 538 * @return 1 on success; 0 otherwise. 539 */ 540 int rrset_insert_rr(struct regional* region, struct packed_rrset_data* pd, 541 uint8_t* rdata, size_t rdata_len, time_t ttl, const char* rrstr); 542 543 /** 544 * Remove RR from rrset that is created using localzone's rrset_insert_rr. 545 * @param pd: the RRset containing the RR to remove 546 * @param index: index of RR to remove 547 * @return: 1 on success; 0 otherwise. 548 */ 549 int 550 local_rrset_remove_rr(struct packed_rrset_data* pd, size_t index); 551 552 /** 553 * Valid response ip actions for the IP-response-driven-action feature; 554 * defined here instead of in the respip module to enable sharing of enum 555 * values with the localzone_type enum. 556 * Note that these values except 'none' are the same as localzone types of 557 * the 'same semantics'. It's intentional as we use these values via 558 * access-control-tags, which can be shared for both response ip actions and 559 * local zones. 560 */ 561 enum respip_action { 562 /** no respip action */ 563 respip_none = local_zone_unset, 564 /** don't answer */ 565 respip_deny = local_zone_deny, 566 /** redirect as per provided data */ 567 respip_redirect = local_zone_redirect, 568 /** log query source and answer query */ 569 respip_inform = local_zone_inform, 570 /** log query source and don't answer query */ 571 respip_inform_deny = local_zone_inform_deny, 572 /** log query source and redirect */ 573 respip_inform_redirect = local_zone_inform_redirect, 574 /** resolve normally, even when there is response-ip data */ 575 respip_always_transparent = local_zone_always_transparent, 576 /** answer with 'refused' response */ 577 respip_always_refuse = local_zone_always_refuse, 578 /** answer with 'no such domain' response */ 579 respip_always_nxdomain = local_zone_always_nxdomain, 580 /** answer with nodata response */ 581 respip_always_nodata = local_zone_always_nodata, 582 /** drop query */ 583 respip_always_deny = local_zone_always_deny, 584 /** RPZ: truncate answer in order to force switch to tcp */ 585 respip_truncate = local_zone_truncate, 586 587 /* The rest of the values are only possible as 588 * access-control-tag-action */ 589 590 /** serves response data (if any), else, drops queries. */ 591 respip_refuse = local_zone_refuse, 592 /** serves response data, else, nodata answer. */ 593 respip_static = local_zone_static, 594 /** gives response data (if any), else nodata answer. */ 595 respip_transparent = local_zone_transparent, 596 /** gives response data (if any), else nodata answer. */ 597 respip_typetransparent = local_zone_typetransparent, 598 /** type invalid */ 599 respip_invalid = local_zone_invalid, 600 }; 601 602 /** 603 * Get local data from local zone and encode answer. 604 * @param z: local zone to use 605 * @param env: module env 606 * @param qinfo: qinfo 607 * @param edns: edns data, for message encoding 608 * @param repinfo: reply info, for message encoding 609 * @param buf: commpoint buffer 610 * @param temp: scratchpad region 611 * @param labs: number of labels in qname 612 * @param ldp: where to store local data 613 * @param lz_type: type of local zone 614 * @param tag: matching tag index 615 * @param tag_datas: alc specific tag data list 616 * @param tag_datas_size: size of tag_datas 617 * @param tagname: list of names of tags, for logging purpose 618 * @param num_tags: number of tags 619 * @return 1 on success 620 */ 621 int 622 local_data_answer(struct local_zone* z, struct module_env* env, 623 struct query_info* qinfo, struct edns_data* edns, 624 struct comm_reply* repinfo, sldns_buffer* buf, 625 struct regional* temp, int labs, struct local_data** ldp, 626 enum localzone_type lz_type, int tag, struct config_strlist** tag_datas, 627 size_t tag_datas_size, char** tagname, int num_tags); 628 629 /** 630 * Add RR to local zone. 631 * @param z: local zone to add RR to 632 * @param nm: dname of RR 633 * @param nmlen: length of nm 634 * @param nmlabs: number of labels of nm 635 * @param rrtype: RR type 636 * @param rrclass: RR class 637 * @param ttl: TTL of RR to add 638 * @param rdata: RDATA of RR to add 639 * @param rdata_len: length of rdata 640 * @param rrstr: RR in string format, for logging 641 * @return: 1 on success 642 */ 643 int 644 local_zone_enter_rr(struct local_zone* z, uint8_t* nm, size_t nmlen, 645 int nmlabs, uint16_t rrtype, uint16_t rrclass, time_t ttl, 646 uint8_t* rdata, size_t rdata_len, const char* rrstr); 647 648 /** 649 * Find a data node by exact name for a local zone 650 * @param z: local_zone containing data tree 651 * @param nm: name of local-data element to find 652 * @param nmlen: length of nm 653 * @param nmlabs: labs of nm 654 * @return local_data on exact match, NULL otherwise. 655 */ 656 struct local_data* 657 local_zone_find_data(struct local_zone* z, uint8_t* nm, size_t nmlen, int nmlabs); 658 659 /** Get memory usage for local_zones tree. The routine locks and unlocks 660 * the tree for reading. */ 661 size_t local_zones_get_mem(struct local_zones* zones); 662 663 /** 664 * Swap internal tree with preallocated entries. Caller should manage 665 * the locks. 666 * @param zones: the local zones structure. 667 * @param data: the data structure used to take elements from. This contains 668 * the old elements on return. 669 */ 670 void local_zones_swap_tree(struct local_zones* zones, 671 struct local_zones* data); 672 673 /** Enter a new zone; returns with WRlock 674 * Made public for unit testing 675 * @param zones: the local zones tree 676 * @param name: name of the zone 677 * @param type: type of the zone 678 * @param dclass: class of the zone 679 * @return local_zone (or duplicate), NULL on parse and malloc failures 680 */ 681 struct local_zone* 682 lz_enter_zone(struct local_zones* zones, const char* name, const char* type, 683 uint16_t dclass); 684 685 /** Setup parent pointers, so that a lookup can be done for closest match 686 * Made public for unit testing 687 * @param zones: the local zones tree 688 */ 689 void 690 lz_init_parents(struct local_zones* zones); 691 #endif /* SERVICES_LOCALZONE_H */ 692