unbound: services/localzone.h File Reference

unbound 0.1

Data Structures | Enumerations | Functions
localzone.h File Reference

This file contains functions to enable local zone authority service. More...

`#include "util/rbtree.h"`
`#include "util/locks.h"`
`#include "util/storage/dnstree.h"`
`#include "util/module.h"`
`#include "services/view.h"`
`#include "sldns/sbuffer.h"`

## Data Structures
struct | local_zones
| Authoritative local zones storage, shared. More...
struct | local_zone
| Local zone. More...
struct | local_data
| Local data. More...
struct | local_rrset
| A local data RRset. More...
struct | local_zone_override
| Local zone override information. More...

## Enumerations
enum | localzone_type { local_zone_unset = 0 , local_zone_deny , local_zone_refuse , local_zone_static , local_zone_transparent , local_zone_typetransparent , local_zone_redirect , local_zone_nodefault , local_zone_inform , local_zone_inform_deny , local_zone_inform_redirect , local_zone_always_transparent , local_zone_always_refuse , local_zone_always_nxdomain , local_zone_always_nodata , local_zone_always_deny , local_zone_always_null , local_zone_noview , local_zone_truncate , local_zone_invalid }
| Local zone type This type determines processing for queries that did not match local-data directly. More...
enum | respip_action { respip_none = local_zone_unset , respip_deny = local_zone_deny , respip_redirect = local_zone_redirect , respip_inform = local_zone_inform , respip_inform_deny = local_zone_inform_deny , respip_inform_redirect = local_zone_inform_redirect , respip_always_transparent = local_zone_always_transparent , respip_always_refuse = local_zone_always_refuse , respip_always_nxdomain = local_zone_always_nxdomain , respip_always_nodata = local_zone_always_nodata , respip_always_deny = local_zone_always_deny , respip_truncate = local_zone_truncate , respip_refuse = local_zone_refuse , respip_static = local_zone_static , respip_transparent = local_zone_transparent , respip_typetransparent = local_zone_typetransparent , respip_invalid = local_zone_invalid }
| Valid response ip actions for the IP-response-driven-action feature; defined here instead of in the respip module to enable sharing of enum values with the localzone_type enum. More...

## Functions
struct local_zones * | local_zones_create (void)
| Create local zones storage.
void | local_zones_delete (struct local_zones *zones)
| Delete local zones storage.
int | local_zones_apply_cfg (struct local_zones *zones, struct config_file *cfg)
| Apply config settings; setup the local authoritative data.
int | local_zone_cmp (const void *z1, const void *z2)
| Compare two local_zone entries in rbtree.
int | local_data_cmp (const void *d1, const void *d2)
| Compare two local_data entries in rbtree.
void | local_zone_delete (struct local_zone *z)
| Delete one zone.
struct local_zone * | local_zones_tags_lookup (struct local_zones *zones, uint8_t *name, size_t len, int labs, uint16_t dclass, uint16_t dtype, uint8_t *taglist, size_t taglen, int ignoretags)
| Lookup zone that contains the given name, class and taglist.
struct local_zone * | local_zones_lookup (struct local_zones *zones, uint8_t *name, size_t len, int labs, uint16_t dclass, uint16_t dtype)
| Lookup zone that contains the given name, class.
void | local_zones_print (struct local_zones *zones)
| Debug helper.
int | local_zones_answer (struct local_zones *zones, struct module_env *env, struct query_info *qinfo, struct edns_data *edns, struct sldns_buffer *buf, struct regional *temp, struct comm_reply *repinfo, uint8_t *taglist, size_t taglen, uint8_t *tagactions, size_t tagactionssize, struct config_strlist **tag_datas, size_t tag_datas_size, char **tagname, int num_tags, struct view *view)
| Answer authoritatively for local zones.
int | local_zones_zone_answer (struct local_zone *z, struct module_env *env, struct query_info *qinfo, struct edns_data *edns, struct comm_reply *repinfo, sldns_buffer *buf, struct regional *temp, struct local_data *ld, enum localzone_type lz_type)
| Answer using the local zone only (not local data used).
int | local_zone_str2type (const char *str, enum localzone_type *t)
| Parse the string into localzone type.
const char * | local_zone_type2str (enum localzone_type t)
| Print localzone type to a string.
struct local_zone * | local_zones_find (struct local_zones *zones, uint8_t *name, size_t len, int labs, uint16_t dclass)
| Find zone that with exactly given name, class.
struct local_zone * | local_zones_find_le (struct local_zones *zones, uint8_t *name, size_t len, int labs, uint16_t dclass, int *exact)
| Find zone that with exactly or smaller name/class User must lock the tree or result zone.
struct local_zone * | local_zones_add_zone (struct local_zones *zones, uint8_t *name, size_t len, int labs, uint16_t dclass, enum localzone_type tp)
| Add a new zone.
void | local_zones_del_zone (struct local_zones *zones, struct local_zone *zone)
| Delete a zone.
int | local_zones_add_RR (struct local_zones *zones, const char *rr)
| Add RR data into the localzone data.
void | local_zones_del_data (struct local_zones *zones, uint8_t *name, size_t len, int labs, uint16_t dclass)
| Remove data from domain name in the tree.
int | parse_dname (const char *str, uint8_t **res, size_t *len, int *labs)
| Form wireformat from text format domain name.
int | local_data_find_tag_datas (const struct query_info *qinfo, struct config_strlist *list, struct ub_packed_rrset_key *r, struct regional *temp)
| Find local data tag string match for the given type (in qinfo) in the list.
enum localzone_type | local_data_find_tag_action (const uint8_t *taglist, size_t taglen, const uint8_t *taglist2, size_t taglen2, const uint8_t *tagactions, size_t tagactionssize, enum localzone_type lzt, int *tag, char *const *tagname, int num_tags)
| See if two sets of tag lists (in the form of bitmap) have the same tag that has an action.
int | local_zone_enter_defaults (struct local_zones *zones, struct config_file *cfg)
| Enter defaults to local zone.
int | rrstr_get_rr_content (const char *str, uint8_t **nm, uint16_t *type, uint16_t *dclass, time_t *ttl, uint8_t *rr, size_t len, uint8_t **rdata, size_t *rdata_len)
| Parses resource record string into wire format, also returning its field values.
int | rrset_insert_rr (struct regional *region, struct packed_rrset_data *pd, uint8_t *rdata, size_t rdata_len, time_t ttl, const char *rrstr)
| Insert specified rdata into the specified resource record.
int | local_rrset_remove_rr (struct packed_rrset_data *pd, size_t index)
| Remove RR from rrset that is created using localzone's rrset_insert_rr.
int | local_data_answer (struct local_zone *z, struct module_env *env, struct query_info *qinfo, struct edns_data *edns, struct comm_reply *repinfo, sldns_buffer *buf, struct regional *temp, int labs, struct local_data **ldp, enum localzone_type lz_type, int tag, struct config_strlist **tag_datas, size_t tag_datas_size, char **tagname, int num_tags)
| Get local data from local zone and encode answer.
int | local_zone_enter_rr (struct local_zone *z, uint8_t *nm, size_t nmlen, int nmlabs, uint16_t rrtype, uint16_t rrclass, time_t ttl, uint8_t *rdata, size_t rdata_len, const char *rrstr)
| Add RR to local zone.
struct local_data * | local_zone_find_data (struct local_zone *z, uint8_t *nm, size_t nmlen, int nmlabs)
| Find a data node by exact name for a local zone.

## Detailed Description

This file contains functions to enable local zone authority service.

## Enumeration Type Documentation

## ◆ localzone_type

enum localzone_type

Local zone type This type determines processing for queries that did not match local-data directly.

Enumerator
local_zone_unset | unset type, used for unset tag_action elements
local_zone_deny | drop query
local_zone_refuse | answer with error
local_zone_static | answer nxdomain or nodata
local_zone_transparent | resolve normally
local_zone_typetransparent | do not block types at localdata names
local_zone_redirect | answer with data at zone apex
local_zone_nodefault | remove default AS112 blocking contents for zone nodefault is used in config not during service.
local_zone_inform | log client address, but no block (transparent)
local_zone_inform_deny | log client address, and block (drop)
local_zone_inform_redirect | log client address, and direct
local_zone_always_transparent | resolve normally, even when there is local data
local_zone_always_refuse | answer with error, even when there is local data
local_zone_always_nxdomain | answer with nxdomain, even when there is local data
local_zone_always_nodata | answer with noerror/nodata, even when there is local data
local_zone_always_deny | drop query, even when there is local data
local_zone_always_null | answer with 0.0.0.0 or ::0 or noerror/nodata, even when there is local data
local_zone_noview | answer not from the view, but global or no-answer
local_zone_truncate | truncate the response; client should retry via tcp
local_zone_invalid | Invalid type, cannot be used to generate answer.

## ◆ respip_action

enum respip_action

Valid response ip actions for the IP-response-driven-action feature; defined here instead of in the respip module to enable sharing of enum values with the localzone_type enum.

Note that these values except 'none' are the same as localzone types of the 'same semantics'. It's intentional as we use these values via access-control-tags, which can be shared for both response ip actions and local zones.

Enumerator
respip_none | no respip action
respip_deny | don't answer
respip_redirect | redirect as per provided data
respip_inform | log query source and answer query
respip_inform_deny | log query source and don't answer query
respip_inform_redirect | log query source and redirect
respip_always_transparent | resolve normally, even when there is response-ip data
respip_always_refuse | answer with 'refused' response
respip_always_nxdomain | answer with 'no such domain' response
respip_always_nodata | answer with nodata response
respip_always_deny | answer with nodata response
respip_truncate | RPZ: truncate answer in order to force switch to tcp.
respip_refuse | serves response data (if any), else, drops queries.
respip_static | serves response data, else, nodata answer.
respip_transparent | gives response data (if any), else nodata answer.
respip_typetransparent | gives response data (if any), else nodata answer.
respip_invalid | type invalid

## Function Documentation

## ◆ local_zones_create()

struct local_zones * local_zones_create | ( | void |  | ) |

Create local zones storage.

Returns
  new struct or NULL on error.

References local_zone_cmp(), local_zones::lock, rbtree_init(), and local_zones::ztree.

Referenced by context_finalize(), daemon_fork(), do_view_data_add(), do_view_datas_add(), do_view_zone_add(), localzonechecks(), rpz_clear(), rpz_create(), and views_apply_cfg().

## ◆ local_zones_delete()

void local_zones_delete | ( | struct local_zones * | zones | ) |

Delete local zones storage.

Parameters

  zones | to delete.

References local_zones::lock, lzdel(), traverse_postorder(), and local_zones::ztree.

Referenced by daemon_cleanup(), localzonechecks(), rpz_clear(), rpz_create(), rpz_delete(), ub_ctx_delete(), and view_delete().

## ◆ local_zones_apply_cfg()

int local_zones_apply_cfg | ( | struct local_zones * | zones,
|  | struct config_file * | cfg
| ) |  |

Apply config settings; setup the local authoritative data.

Takes care of locking.

Parameters

  zones | is set up.
  cfg | config data.

Returns
  false on error.

References init_parents(), local_zone_enter_defaults(), lz_enter_data(), lz_enter_overrides(), lz_enter_zone_tags(), lz_enter_zones(), lz_freeup_cfg(), and lz_setup_implicit().

Referenced by context_finalize(), daemon_fork(), localzonechecks(), and views_apply_cfg().

## ◆ local_zone_cmp()

int local_zone_cmp | ( | const void * | z1,
|  | const void * | z2
| ) |  |

Compare two local_zone entries in rbtree.

Sort hierarchical but not canonical

Parameters

  z1 | zone 1
  z2 | zone 2

Returns
  : -1, 0, +1 comparison value.

References local_zone::dclass, dname_lab_cmp(), local_zone::name, and local_zone::namelabs.

Referenced by fptr_whitelist_rbtree_cmp(), and local_zones_create().

## ◆ local_data_cmp()

int local_data_cmp | ( | const void * | d1,
|  | const void * | d2
| ) |  |

Compare two local_data entries in rbtree.

Sort canonical.

Parameters

  d1 | data 1
  d2 | data 2

Returns
  : -1, 0, +1 comparison value.

References dname_canon_lab_cmp(), local_data::name, and local_data::namelabs.

Referenced by fptr_whitelist_rbtree_cmp(), and local_zone_create().

## ◆ local_zone_delete()

void local_zone_delete | ( | struct local_zone * | z | ) |

Delete one zone.

Parameters

  z | to delete.

References local_zone::lock, local_zone::name, local_zone::region, regional_destroy(), and local_zone::taglist.

Referenced by local_zones_add_zone(), local_zones_del_zone(), lz_enter_zone_dname(), and lzdel().

## ◆ local_zones_tags_lookup()

struct local_zone * local_zones_tags_lookup | ( | struct local_zones * | zones,
|  | uint8_t * | name,
|  | size_t | len,
|  | int | labs,
|  | uint16_t | dclass,
|  | uint16_t | dtype,
|  | uint8_t * | taglist,
|  | size_t | taglen,
|  | int | ignoretags
| ) |  |

Lookup zone that contains the given name, class and taglist.

User must lock the tree or result zone.

Parameters

  zones | the zones tree
  name | dname to lookup
  len | length of name.
  labs | labelcount of name.
  dclass | class to lookup.
  dtype | type to lookup, if type DS a zone higher is used for zonecuts.
  taglist | taglist to lookup.
  taglen | length of taglist.
  ignoretags | lookup zone by name and class, regardless the local-zone's tags.

Returns
  closest local_zone or NULL if no covering zone is found.

References local_zone::dclass, dname_is_root(), dname_lab_cmp(), dname_remove_label(), rbnode_type::key, LDNS_RR_TYPE_DS, local_zone::name, local_zone::namelabs, local_zone::namelen, local_zone::node, local_zone::parent, rbtree_find_less_equal(), local_zone::taglen, local_zone::taglist, taglist_intersect(), and local_zones::ztree.

Referenced by local_zones_answer(), and local_zones_lookup().

## ◆ local_zones_lookup()

struct local_zone * local_zones_lookup | ( | struct local_zones * | zones,
|  | uint8_t * | name,
|  | size_t | len,
|  | int | labs,
|  | uint16_t | dclass,
|  | uint16_t | dtype
| ) |  |

Lookup zone that contains the given name, class.

User must lock the tree or result zone.

Parameters

  zones | the zones tree
  name | dname to lookup
  len | length of name.
  labs | labelcount of name.
  dclass | class to lookup.
  dtype | type of the record, if type DS then a zone higher up is found pass 0 to just plain find a zone for a name.

Returns
  closest local_zone or NULL if no covering zone is found.

References local_zone::dclass, local_zones_tags_lookup(), and local_zone::name.

Referenced by local_zones_add_RR(), local_zones_answer(), local_zones_del_data(), lz_enter_rr_str(), and lz_setup_implicit().

## ◆ local_zones_print()

void local_zones_print | ( | struct local_zones * | zones | ) |

Debug helper.

Print all zones Takes care of locking.

Parameters

  zones | the zones tree

References rbtree_type::count, local_zones::lock, log_info(), RBTREE_FOR, and local_zones::ztree.

Referenced by ub_ctx_print_local_zones().

## ◆ local_zones_answer()

int local_zones_answer | ( | struct local_zones * | zones,
|  | struct module_env * | env,
|  | struct query_info * | qinfo,
|  | struct edns_data * | edns,
|  | struct sldns_buffer * | buf,
|  | struct regional * | temp,
|  | struct comm_reply * | repinfo,
|  | uint8_t * | taglist,
|  | size_t | taglen,
|  | uint8_t * | tagactions,
|  | size_t | tagactionssize,
|  | struct config_strlist ** | tag_datas,
|  | size_t | tag_datas_size,
|  | char ** | tagname,
|  | int | num_tags,
|  | struct view * | view
| ) |  |

Answer authoritatively for local zones.

Takes care of locking.

Parameters

  zones | the stored zones (shared, read only).
  env | the module environment.
  qinfo | query info (parsed).
  edns | edns info (parsed).
  buf | buffer with query ID and flags, also for reply.
  temp | temporary storage region.
  repinfo | source address for checks. may be NULL.
  taglist | taglist for checks. May be NULL.
  taglen | length of the taglist.
  tagactions | local zone actions for tags. May be NULL.
  tagactionssize | length of the tagactions.
  tag_datas | array per tag of strlist with rdata strings. or NULL.
  tag_datas_size | size of tag_datas array.
  tagname | array of tag name strings (for debug output).
  num_tags | number of items in tagname array.
  view | answer using this view. May be NULL.

Returns
  true if answer is in buffer. false if query is not answered by authority data. If the reply should be dropped altogether, the return value is true, but the buffer is cleared (empty). It can also return true if a non-exact alias answer is found. In this case qinfo->local_alias points to the corresponding alias RRset but the answer is NOT encoded in buffer. It's the caller's responsibility to complete the alias chain (if needed) and encode the final set of answer. Data pointed to by qinfo->local_alias is allocated in 'temp' or refers to configuration data. So the caller will need to make a deep copy of it if it needs to keep it beyond the lifetime of 'temp' or a dynamic update to local zone data.

References module_env::cfg, comm_reply::client_addr, comm_reply::client_addrlen, dname_count_labels(), dname_str(), view::isfirst, query_info::local_alias, local_data_answer(), local_zone_always_deny, local_zone_always_nodata, local_zone_always_nxdomain, local_zone_always_refuse, local_zone_always_transparent, local_zone_does_not_cover(), local_zone_inform, local_zone_inform_deny, local_zone_inform_redirect, local_zone_noview, local_zone_transparent, local_zone_type2str(), local_zone_typetransparent, view::local_zones, local_zones_lookup(), local_zones_tags_lookup(), local_zones_zone_answer(), local_zones::lock, local_zone::lock, view::lock, config_file::log_local_actions, lz_inform_print(), local_zone::name, view::name, local_zone::override_tree, query_info::qclass, query_info::qname, query_info::qname_len, query_info::qtype, local_zone::taglen, local_zone::taglist, local_zone::type, VERB_ALGO, verbose(), and verbosity.

Referenced by handle_newq(), libworker_attach_mesh(), libworker_fg(), and worker_handle_request().

## ◆ local_zones_zone_answer()

int local_zones_zone_answer | ( | struct local_zone * | z,
|  | struct module_env * | env,
|  | struct query_info * | qinfo,
|  | struct edns_data * | edns,
|  | struct comm_reply * | repinfo,
|  | sldns_buffer * | buf,
|  | struct regional * | temp,
|  | struct local_data * | ld,
|  | enum localzone_type | lz_type
| ) |  |

Answer using the local zone only (not local data used).

Parameters

  z | zone for query.
  env | module environment.
  qinfo | query.
  edns | edns from query.
  repinfo | source address for checks. may be NULL.
  buf | buffer for answer.
  temp | temp region for encoding.
  ld | local data, if NULL, no such name exists in localdata.
  lz_type | type of the local zone.

Returns
  1 if a reply is to be sent, 0 if not.

no reply at all, signal caller by clearing buffer.

References BIT_AA, BIT_TC, packed_rrset_data::count, lruhash_entry::data, packed_rrset_key::dname, packed_rrset_key::dname_len, ub_packed_rrset_key::entry, LDNS_RR_TYPE_A, LDNS_RR_TYPE_AAAA, local_encode(), local_error_encode(), local_zone_always_deny, local_zone_always_nodata, local_zone_always_null, local_zone_always_nxdomain, local_zone_always_refuse, local_zone_always_transparent, local_zone_deny, local_zone_inform_deny, local_zone_inform_redirect, local_zone_redirect, local_zone_refuse, local_zone_static, local_zone_truncate, local_zone_typetransparent, query_info::qclass, query_info::qname, query_info::qname_len, query_info::qtype, ub_packed_rrset_key::rk, packed_rrset_data::rr_data, packed_rrset_data::rr_len, packed_rrset_data::rr_ttl, packed_rrset_key::rrset_class, local_data::rrsets, sldns_buffer_clear(), sldns_buffer_flip(), local_zone::soa, local_zone::soa_negative, packed_rrset_data::ttl, and packed_rrset_key::type.

Referenced by local_zones_answer().

## ◆ local_zone_str2type()

int local_zone_str2type | ( | const char * | str,
|  | enum localzone_type * | t
| ) |  |

Parse the string into localzone type.

Parameters

  str | string to parse
  t | local zone type returned here.

Returns
  0 on parse error.

References local_zone_always_deny, local_zone_always_nodata, local_zone_always_null, local_zone_always_nxdomain, local_zone_always_refuse, local_zone_always_transparent, local_zone_deny, local_zone_inform, local_zone_inform_deny, local_zone_inform_redirect, local_zone_nodefault, local_zone_noview, local_zone_redirect, local_zone_refuse, local_zone_static, local_zone_transparent, local_zone_truncate, local_zone_typetransparent, and local_zone::type.

Referenced by acl_list_tag_action_cfg(), acl_view_tag_checks(), lz_enter_override(), lz_enter_zone(), perform_zone_add(), and ub_ctx_zone_add().

## ◆ local_zone_type2str()

const char * local_zone_type2str | ( | enum localzone_type | t | ) |

Print localzone type to a string.

Pointer to a constant string.

Parameters

  t | local zone type.

Returns
  constant string that describes type.

References local_zone_always_deny, local_zone_always_nodata, local_zone_always_null, local_zone_always_nxdomain, local_zone_always_refuse, local_zone_always_transparent, local_zone_deny, local_zone_inform, local_zone_inform_deny, local_zone_inform_redirect, local_zone_invalid, local_zone_nodefault, local_zone_noview, local_zone_redirect, local_zone_refuse, local_zone_static, local_zone_transparent, local_zone_truncate, local_zone_typetransparent, and local_zone_unset.

Referenced by do_list_local_zones(), local_data_find_tag_action(), local_zones_answer(), and lz_inform_print().

## ◆ local_zones_find()

struct local_zone * local_zones_find | ( | struct local_zones * | zones,
|  | uint8_t * | name,
|  | size_t | len,
|  | int | labs,
|  | uint16_t | dclass
| ) |  |

Find zone that with exactly given name, class.

User must lock the tree or result zone.

Parameters

  zones | the zones tree
  name | dname to lookup
  len | length of name.
  labs | labelcount of name.
  dclass | class to lookup.

Returns
  the exact local_zone or NULL.

References local_zone::dclass, rbnode_type::key, local_zone::name, local_zone::namelabs, local_zone::namelen, local_zone::node, rbtree_search(), and local_zones::ztree.

Referenced by local_zones_add_zone(), lz_enter_override(), lz_enter_zone_dname(), lz_enter_zone_tag(), perform_zone_add(), perform_zone_remove(), ub_ctx_zone_add(), and ub_ctx_zone_remove().

## ◆ local_zones_find_le()

struct local_zone * local_zones_find_le | ( | struct local_zones * | zones,
|  | uint8_t * | name,
|  | size_t | len,
|  | int | labs,
|  | uint16_t | dclass,
|  | int * | exact
| ) |  |

Find zone that with exactly or smaller name/class User must lock the tree or result zone.

Parameters

  zones | the zones tree
  name | dname to lookup
  len | length of name.
  labs | labelcount of name.
  dclass | class to lookup.
  exact | 1 on return is this is an exact match.

Returns
  the exact or smaller local_zone or NULL.

References local_zone::dclass, rbnode_type::key, local_zone::name, local_zone::namelabs, local_zone::namelen, local_zone::node, rbtree_find_less_equal(), and local_zones::ztree.

Referenced by rpz_find_zone().

## ◆ local_zones_add_zone()

struct local_zone * local_zones_add_zone | ( | struct local_zones * | zones,
|  | uint8_t * | name,
|  | size_t | len,
|  | int | labs,
|  | uint16_t | dclass,
|  | enum localzone_type | tp
| ) |  |

Add a new zone.

Caller must hold the zones lock. Adjusts the other zones as well (parent pointers) after insertion. The zone must NOT exist (returns NULL and logs error).

Parameters

  zones | the zones tree
  name | dname to add
  len | length of name.
  labs | labelcount of name.
  dclass | class to add.
  tp | type.

Returns
  local_zone or NULL on error, caller must printout memory error.

References local_zone::dclass, local_zone_create(), local_zone_delete(), local_zones_find(), local_zone::lock, log_err(), local_zone::name, local_zone::node, local_zone::parent, rbtree_insert(), set_kiddo_parents(), and local_zones::ztree.

Referenced by local_zones_add_RR(), perform_zone_add(), and ub_ctx_zone_add().

## ◆ local_zones_del_zone()

void local_zones_del_zone | ( | struct local_zones * | zones,
|  | struct local_zone * | zone
| ) |  |

Delete a zone.

Caller must hold the zones lock. Adjusts the other zones as well (parent pointers) after insertion.

Parameters

  zones | the zones tree
  zone | the zone to delete from tree. Also deletes zone from memory.

References local_zone_delete(), local_zone::lock, local_zone::parent, rbtree_delete(), set_kiddo_parents(), and local_zones::ztree.

Referenced by perform_zone_remove(), rpz_remove_qname_trigger(), and ub_ctx_zone_remove().

## ◆ local_zones_add_RR()

int local_zones_add_RR | ( | struct local_zones * | zones,
|  | const char * | rr
| ) |  |

Add RR data into the localzone data.

Looks up the zone, if no covering zone, a transparent zone with the name of the RR is created.

Parameters

  zones | the zones tree. Not locked by caller.
  rr | string with on RR.

Returns
  false on failure.

References dname_count_size_labels(), get_rr_nameclass(), local_zone_transparent, local_zones_add_zone(), local_zones_lookup(), local_zones::lock, local_zone::lock, and lz_enter_rr_into_zone().

Referenced by perform_data_add(), and ub_ctx_data_add().

## ◆ local_zones_del_data()

void local_zones_del_data | ( | struct local_zones * | zones,
|  | uint8_t * | name,
|  | size_t | len,
|  | int | labs,
|  | uint16_t | dclass
| ) |  |

Remove data from domain name in the tree.

All types are removed. No effect if zone or name does not exist.

Parameters

  zones | zones tree.
  name | dname to remove
  len | length of name.
  labs | labelcount of name.
  dclass | class to remove.

References del_empty_term(), del_local_rrset(), LDNS_RR_TYPE_DS, local_zone_find_data(), local_zones_lookup(), local_zones::lock, local_zone::lock, local_zone::name, local_data::name, query_dname_compare(), local_data::rrsets, local_zone::soa, and local_zone::soa_negative.

Referenced by perform_data_remove(), and ub_ctx_data_remove().

## ◆ parse_dname()

int parse_dname | ( | const char * | str,
|  | uint8_t ** | res,
|  | size_t * | len,
|  | int * | labs
| ) |  |

Form wireformat from text format domain name.

Parameters

  str | the domain name in text "www.example.com"
  res | resulting wireformat is stored here with malloc.
  len | length of resulting wireformat.
  labs | number of labels in resulting wireformat.

Returns
  false on error, syntax or memory. Also logged.

References dname_count_size_labels(), log_err(), and sldns_str2wire_dname().

Referenced by lz_enter_zone(), lz_exists(), ub_ctx_data_remove(), ub_ctx_set_stub(), ub_ctx_zone_add(), and ub_ctx_zone_remove().

## ◆ local_data_find_tag_datas()

int local_data_find_tag_datas | ( | const struct query_info * | qinfo,
|  | struct config_strlist * | list,
|  | struct ub_packed_rrset_key * | r,
|  | struct regional * | temp
| ) |  |

Find local data tag string match for the given type (in qinfo) in the list.

If found, 'r' will be filled with corresponding rrset information.

Parameters

  qinfo | contains name, type, and class for the data
  list | stores local tag data to be searched
  r | rrset key to be filled for matched data
  temp | region to allocate rrset in 'r'

Returns
  1 if a match is found and rrset is built; otherwise 0 including errors.

Find local data tag string match for the given type (in qinfo) in the list.

References packed_rrset_data::count, lruhash_entry::data, packed_rrset_key::dname, packed_rrset_key::dname_len, ub_packed_rrset_key::entry, packed_rrset_key::flags, lruhash_entry::key, LDNS_RR_BUF_SIZE, LDNS_RR_TYPE_CNAME, config_strlist::next, query_info::qclass, query_info::qname, query_info::qname_len, query_info::qtype, regional_alloc_init(), regional_alloc_zero(), ub_packed_rrset_key::rk, packed_rrset_data::rr_data, packed_rrset_data::rr_len, packed_rrset_data::rr_ttl, packed_rrset_key::rrset_class, sldns_str2wire_rr_buf(), sldns_wirerr_get_rdatalen(), sldns_wirerr_get_rdatawl(), sldns_wirerr_get_ttl(), sldns_wirerr_get_type(), config_strlist::str, packed_rrset_data::ttl, and packed_rrset_key::type.

Referenced by respip_data_answer().

## ◆ local_data_find_tag_action()

enum localzone_type local_data_find_tag_action | ( | const uint8_t * | taglist,
|  | size_t | taglen,
|  | const uint8_t * | taglist2,
|  | size_t | taglen2,
|  | const uint8_t * | tagactions,
|  | size_t | tagactionssize,
|  | enum localzone_type | lzt,
|  | int * | tag,
|  | char *const * | tagname,
|  | int | num_tags
| ) |  |

See if two sets of tag lists (in the form of bitmap) have the same tag that has an action.

If so, '*tag' will be set to the found tag index, and the corresponding action will be returned in the form of local zone type. Otherwise the passed type (lzt) will be returned as the default action. Pointers except tagactions must not be NULL.

Parameters

  taglist | 1st list of tags
  taglen | size of taglist in bytes
  taglist2 | 2nd list of tags
  taglen2 | size of taglist2 in bytes
  tagactions | local data actions for tags. May be NULL.
  tagactionssize | length of the tagactions.
  lzt | default action (local zone type) if no tag action is found.
  tag | see above.
  tagname | array of tag name strings (for debug output).
  num_tags | number of items in tagname array.

Returns
  found tag action or the default action.

References local_zone_type2str(), VERB_ALGO, and verbose().

Referenced by respip_rewrite_reply().

## ◆ local_zone_enter_defaults()

int local_zone_enter_defaults | ( | struct local_zones * | zones,
|  | struct config_file * | cfg
| ) |  |

Enter defaults to local zone.

Parameters

  zones | to add defaults to
  cfg | containing list of zones to exclude from default set.

Returns
  1 on success; 0 otherwise.

Enter defaults to local zone.

References add_empty_default(), as112_zones, LDNS_RR_CLASS_IN, config_file::local_zones_disable_default, local_zone::lock, log_err(), lz_enter_rr_into_zone(), lz_enter_zone(), lz_exists(), lz_nodefault(), and config_file::unblock_lan_zones.

Referenced by do_view_zone_add(), and local_zones_apply_cfg().

## ◆ rrstr_get_rr_content()

int rrstr_get_rr_content | ( | const char * | str,
|  | uint8_t ** | nm,
|  | uint16_t * | type,
|  | uint16_t * | dclass,
|  | time_t * | ttl,
|  | uint8_t * | rr,
|  | size_t | len,
|  | uint8_t ** | rdata,
|  | size_t * | rdata_len
| ) |  |

Parses resource record string into wire format, also returning its field values.

Parameters

  str | input resource record
  nm | domain name field
  type | record type field
  dclass | record class field
  ttl | ttl field
  rr | buffer for the parsed rr in wire format
  len | buffer length
  rdata | rdata field
  rdata_len | rdata field length

Returns
  1 on success; 0 otherwise.

References local_zone::dclass, log_err(), memdup(), sldns_get_errorstr_parse(), sldns_str2wire_rr_buf(), sldns_wirerr_get_class(), sldns_wirerr_get_rdatalen(), sldns_wirerr_get_rdatawl(), sldns_wirerr_get_ttl(), sldns_wirerr_get_type(), and local_zone::type.

Referenced by lz_enter_rr_into_zone().

## ◆ rrset_insert_rr()

int rrset_insert_rr | ( | struct regional * | region,
|  | struct packed_rrset_data * | pd,
|  | uint8_t * | rdata,
|  | size_t | rdata_len,
|  | time_t | ttl,
|  | const char * | rrstr
| ) |  |

Insert specified rdata into the specified resource record.

Parameters

  region | allocator
  pd | data portion of the destination resource record
  rdata | source rdata
  rdata_len | source rdata length
  ttl | time to live
  rrstr | resource record in text form (for logging)

Returns
  1 on success; 0 otherwise.

Insert specified rdata into the specified resource record.

References packed_rrset_data::count, log_err(), log_warn(), regional_alloc(), regional_alloc_init(), packed_rrset_data::rr_data, packed_rrset_data::rr_len, packed_rrset_data::rr_ttl, and packed_rrset_data::ttl.

Referenced by local_zone_enter_rr(), mesh_state_add_reply(), and respip_enter_rr().

## ◆ local_rrset_remove_rr()

int local_rrset_remove_rr | ( | struct packed_rrset_data * | pd,
|  | size_t | index
| ) |  |

Remove RR from rrset that is created using localzone's rrset_insert_rr.

Parameters

  pd | the RRset containing the RR to remove
  index | index of RR to remove

Returns
  : 1 on success; 0 otherwise.

Remove RR from rrset that is created using localzone's rrset_insert_rr.

References packed_rrset_data::count, log_assert, log_warn(), packed_rrset_data::rr_data, packed_rrset_data::rr_len, and packed_rrset_data::rr_ttl.

Referenced by rpz_data_delete_rr(), and rpz_rrset_delete_rr().

## ◆ local_data_answer()

int local_data_answer | ( | struct local_zone * | z,
|  | struct module_env * | env,
|  | struct query_info * | qinfo,
|  | struct edns_data * | edns,
|  | struct comm_reply * | repinfo,
|  | sldns_buffer * | buf,
|  | struct regional * | temp,
|  | int | labs,
|  | struct local_data ** | ldp,
|  | enum localzone_type | lz_type,
|  | int | tag,
|  | struct config_strlist ** | tag_datas,
|  | size_t | tag_datas_size,
|  | char ** | tagname,
|  | int | num_tags
| ) |  |

Get local data from local zone and encode answer.

Parameters

  z | local zone to use
  env | module env
  qinfo | qinfo
  edns | edns data, for message encoding
  repinfo | reply info, for message encoding
  buf | commpoint buffer
  temp | scratchpad region
  labs | number of labels in qname
  ldp | where to store local data
  lz_type | type of local zone
  tag | matching tag index
  tag_datas | alc specific tag data list
  tag_datas_size | size of tag_datas
  tagname | list of names of tags, for logging purpose
  num_tags | number of tags

Returns
  1 on success

References BIT_AA, packed_rrset_data::count, local_zone::data, lruhash_entry::data, packed_rrset_key::dname, dname_is_wild(), packed_rrset_key::dname_len, ub_packed_rrset_key::entry, get_cname_target(), lruhash_entry::hash, rbnode_type::key, lruhash_entry::key, LDNS_MAX_DOMAINLEN, LDNS_RR_TYPE_CNAME, query_info::local_alias, local_data_find_type(), local_encode(), local_error_encode(), local_zone_inform_redirect, local_zone_redirect, log_assert, local_zone::name, local_data::name, local_zone::namelabs, local_data::namelabs, local_zone::namelen, local_data::namelen, local_data::node, packed_rrset_ptr_fixup(), query_info::qname, query_info::qname_len, query_info::qtype, rbtree_search(), regional_alloc_init(), regional_alloc_zero(), ub_packed_rrset_key::rk, packed_rrset_data::rr_data, packed_rrset_data::rr_len, packed_rrset_data::rr_ttl, local_rrset::rrset, rrset_key_hash(), rrset_trust_ans_noAA, packed_rrset_data::rrsig_count, packed_rrset_data::trust, packed_rrset_data::ttl, packed_rrset_key::type, VERB_ALGO, and verbose().

Referenced by local_zones_answer().

## ◆ local_zone_enter_rr()

int local_zone_enter_rr | ( | struct local_zone * | z,
|  | uint8_t * | nm,
|  | size_t | nmlen,
|  | int | nmlabs,
|  | uint16_t | rrtype,
|  | uint16_t | rrclass,
|  | time_t | ttl,
|  | uint8_t * | rdata,
|  | size_t | rdata_len,
|  | const char * | rrstr
| ) |  |

Add RR to local zone.

Parameters

  z | local zone to add RR to
  nm | dname of RR
  nmlen | length of nm
  nmlabs | number of labels of nm
  rrtype | RR type
  rrclass | RR class
  ttl | TTL of RR to add
  rdata | RDATA of RR to add
  rdata_len | length of rdata
  rrstr | RR in string format, for logging

Returns
  : 1 on success

References lruhash_entry::data, ub_packed_rrset_key::entry, packed_rrset_key::flags, LDNS_RR_TYPE_CNAME, LDNS_RR_TYPE_SOA, local_data_find_type(), local_zone_inform_redirect, local_zone_redirect, log_assert, log_err(), lz_find_create_node(), local_zone::name, local_data::name, new_local_rrset(), local_data::node, PACKED_RRSET_NSEC_AT_APEX, query_dname_compare(), local_zone::region, ub_packed_rrset_key::rk, rr_is_duplicate(), local_rrset::rrset, rrset_insert_rr(), local_data::rrsets, packed_rrset_data::ttl, local_zone::type, packed_rrset_key::type, VERB_ALGO, and verbose().

Referenced by lz_enter_rr_into_zone().

## ◆ local_zone_find_data()

struct local_data * local_zone_find_data | ( | struct local_zone * | z,
|  | uint8_t * | nm,
|  | size_t | nmlen,
|  | int | nmlabs
| ) |  |

Find a data node by exact name for a local zone.

Parameters

  z | local_zone containing data tree
  nm | name of local-data element to find
  nmlen | length of nm
  nmlabs | labs of nm

Returns
  local_data on exact match, NULL otherwise.

References local_zone::data, rbnode_type::key, local_data::name, local_data::namelabs, local_data::namelen, local_data::node, and rbtree_search().

Referenced by del_empty_term(), local_zones_del_data(), lz_find_create_node(), and rpz_data_delete_rr().