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