This file contains functions to enable local zone authority service. More...
#include "config.h"
#include "services/localzone.h"
#include "sldns/str2wire.h"
#include "util/regional.h"
#include "util/config_file.h"
#include "util/data/dname.h"
#include "util/data/packed_rrset.h"
#include "util/data/msgencode.h"
#include "util/net_help.h"
#include "util/netevent.h"
#include "util/data/msgreply.h"
#include "util/data/msgparse.h"
#include "util/as112.h"
Macros | |
#define | LOCALZONE_RRSET_COUNT_MAX 4096 |
Functions | |
static void | local_zone_out (struct local_zone *z) |
print all RRsets in local zone | |
static void | local_zone_print (struct local_zone *z) |
void | local_zones_print (struct local_zones *zones) |
Debug helper. More... | |
struct local_zones * | local_zones_create (void) |
Create local zones storage. More... | |
static void | lzdel (rbnode_type *n, void *ATTR_UNUSED(arg)) |
helper traverse to delete zones | |
void | local_zones_delete (struct local_zones *zones) |
Delete local zones storage. More... | |
void | local_zone_delete (struct local_zone *z) |
Delete one zone. More... | |
int | local_zone_cmp (const void *z1, const void *z2) |
Compare two local_zone entries in rbtree. More... | |
int | local_data_cmp (const void *d1, const void *d2) |
Compare two local_data entries in rbtree. More... | |
int | parse_dname (const char *str, uint8_t **res, size_t *len, int *labs) |
Form wireformat from text format domain name. More... | |
static struct local_zone * | local_zone_create (uint8_t *nm, size_t len, int labs, enum localzone_type t, uint16_t dclass) |
create a new localzone | |
static struct local_zone * | lz_enter_zone_dname (struct local_zones *zones, uint8_t *nm, size_t len, int labs, enum localzone_type t, uint16_t c) |
enter a new zone with allocated dname returns with WRlock | |
struct local_zone * | lz_enter_zone (struct local_zones *zones, const char *name, const char *type, uint16_t dclass) |
enter a new zone More... | |
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. More... | |
static int | get_rr_nameclass (const char *str, uint8_t **nm, uint16_t *dclass, uint16_t *dtype) |
return name and class of rr; parses string | |
static struct local_rrset * | local_data_find_type (struct local_data *data, uint16_t type, int alias_ok) |
Find an rrset in local data structure. More... | |
static int | rr_is_duplicate (struct packed_rrset_data *pd, uint8_t *rdata, size_t rdata_len) |
check for RR duplicates | |
static struct local_rrset * | new_local_rrset (struct regional *region, struct local_data *node, uint16_t rrtype, uint16_t rrclass) |
new local_rrset | |
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 RR into RRset data structure; Wastes a couple of bytes More... | |
int | local_rrset_remove_rr (struct packed_rrset_data *pd, size_t index) |
Delete RR from local-zone RRset, wastes memory as the deleted RRs cannot be free'd (regionally alloc'd) More... | |
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. More... | |
static int | lz_find_create_node (struct local_zone *z, uint8_t *nm, size_t nmlen, int nmlabs, struct local_data **res) |
find a node, create it if not and all its empty nonterminal parents | |
static int | lz_mark_soa_for_zone (struct local_zone *z, struct ub_packed_rrset_key *soa_rrset, uint8_t *rdata, size_t rdata_len, time_t ttl, const char *rrstr) |
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. More... | |
static int | lz_enter_rr_into_zone (struct local_zone *z, const char *rrstr) |
enter data RR into auth zone | |
static int | lz_enter_rr_str (struct local_zones *zones, const char *rr) |
enter a data RR into auth data; a zone for it must exist | |
static int | lz_enter_zone_tag (struct local_zones *zones, char *zname, uint8_t *list, size_t len, uint16_t rr_class) |
enter tagstring into zone | |
static int | lz_enter_override (struct local_zones *zones, char *zname, char *netblock, char *type, uint16_t rr_class) |
enter override into zone | |
static int | lz_enter_zones (struct local_zones *zones, struct config_file *cfg) |
parse local-zone: statements | |
static int | lz_exists (struct local_zones *zones, const char *name) |
lookup a zone in rbtree; exact match only; SLOW due to parse | |
static int | lz_nodefault (struct config_file *cfg, const char *name) |
lookup a zone in cfg->nodefault list | |
static int | add_empty_default (struct local_zones *zones, struct config_file *cfg, const char *name) |
enter (AS112) empty default zone | |
int | local_zone_enter_defaults (struct local_zones *zones, struct config_file *cfg) |
enter default zones More... | |
static int | lz_enter_overrides (struct local_zones *zones, struct config_file *cfg) |
parse local-zone-override: statements | |
static struct local_zone * | find_closest_parent (struct local_zone *curr, struct local_zone *prev) |
void | lz_init_parents (struct local_zones *zones) |
setup parent pointers, so that a lookup can be done for closest match More... | |
static int | lz_setup_implicit (struct local_zones *zones, struct config_file *cfg) |
enter implicit transparent zone for local-data: without local-zone: | |
static int | lz_enter_zone_tags (struct local_zones *zones, struct config_file *cfg) |
enter local-zone-tag info | |
static int | lz_enter_data (struct local_zones *zones, struct config_file *cfg) |
enter auth data | |
static void | lz_freeup_cfg (struct config_file *cfg) |
free memory from config | |
int | local_zones_apply_cfg (struct local_zones *zones, struct config_file *cfg) |
Apply config settings; setup the local authoritative data. More... | |
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. More... | |
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. More... | |
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. More... | |
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. More... | |
static int | local_encode (struct query_info *qinfo, struct module_env *env, struct edns_data *edns, struct comm_reply *repinfo, sldns_buffer *buf, struct regional *temp, struct ub_packed_rrset_key *rrset, int ansec, int rcode) |
encode answer consisting of 1 rrset | |
static void | local_error_encode (struct query_info *qinfo, struct module_env *env, struct edns_data *edns, struct comm_reply *repinfo, sldns_buffer *buf, struct regional *temp, int rcode, int r, int ede_code, const char *ede_txt) |
encode local error answer | |
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 the list More... | |
static int | find_tag_datas (struct query_info *qinfo, struct config_strlist *list, struct ub_packed_rrset_key *r, struct regional *temp) |
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. More... | |
static int | local_zone_does_not_cover (struct local_zone *z, struct query_info *qinfo, int labs) |
See if the local zone does not cover the name, eg. More... | |
static int | local_zone_is_udp_query (struct comm_reply *repinfo) |
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). More... | |
static void | lz_inform_print (struct local_zone *z, struct query_info *qinfo, struct sockaddr_storage *addr, socklen_t addrlen) |
print log information for an inform zone query | |
static enum localzone_type | lz_type (uint8_t *taglist, size_t taglen, uint8_t *taglist2, size_t taglen2, uint8_t *tagactions, size_t tagactionssize, enum localzone_type lzt, struct comm_reply *repinfo, struct rbtree_type *override_tree, int *tag, char **tagname, int num_tags) |
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. More... | |
int | local_zones_answer (struct local_zones *zones, struct module_env *env, struct query_info *qinfo, struct edns_data *edns, 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. More... | |
const char * | local_zone_type2str (enum localzone_type t) |
Print localzone type to a string. More... | |
int | local_zone_str2type (const char *type, enum localzone_type *t) |
Parse the string into localzone type. More... | |
static void | set_kiddo_parents (struct local_zone *z, struct local_zone *match, struct local_zone *newp) |
iterate over the kiddies of the given name and set their parent ptr | |
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. More... | |
void | local_zones_del_zone (struct local_zones *zones, struct local_zone *z) |
Delete a zone. More... | |
int | local_zones_add_RR (struct local_zones *zones, const char *rr) |
Add RR data into the localzone data. More... | |
static int | is_terminal (struct local_data *d) |
returns true if the node is terminal so no deeper domain names exist | |
static void | del_empty_term (struct local_zone *z, struct local_data *d, uint8_t *name, size_t len, int labs) |
delete empty terminals from tree when final data is deleted | |
static void | del_local_rrset (struct local_data *d, uint16_t dtype) |
find and remove type from list in domain struct | |
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. More... | |
This file contains functions to enable local zone authority service.
void local_zones_print | ( | struct local_zones * | zones | ) |
Debug helper.
Print all zones Takes care of locking.
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().
struct local_zones* local_zones_create | ( | void | ) |
Create local zones storage.
References local_zone_cmp(), local_zones::lock, rbtree_init(), and local_zones::ztree.
Referenced by context_finalize(), do_view_data_add(), do_view_zone_add(), localzonechecks(), rpz_create(), and views_apply_cfg().
void local_zones_delete | ( | struct local_zones * | zones | ) |
Delete local zones storage.
zones | to delete. |
References local_zones::lock, lzdel(), traverse_postorder(), and local_zones::ztree.
Referenced by daemon_cleanup(), rpz_clear(), rpz_delete(), and view_delete().
void local_zone_delete | ( | struct local_zone * | z | ) |
Delete one zone.
z | to delete. |
References local_zone::lock, local_zone::name, local_zone::region, regional_destroy(), and local_zone::taglist.
Referenced by local_zones_del_zone().
int local_zone_cmp | ( | const void * | z1, |
const void * | z2 | ||
) |
Compare two local_zone entries in rbtree.
Sort hierarchical but not canonical
z1 | zone 1 |
z2 | zone 2 |
References local_zone::dclass, dname_lab_cmp(), local_zone::name, and local_zone::namelabs.
Referenced by fptr_whitelist_rbtree_cmp(), and local_zones_create().
int local_data_cmp | ( | const void * | d1, |
const void * | d2 | ||
) |
Compare two local_data entries in rbtree.
Sort canonical.
d1 | data 1 |
d2 | data 2 |
References dname_canon_lab_cmp(), local_data::name, and local_data::namelabs.
Referenced by fptr_whitelist_rbtree_cmp(), and local_zone_create().
int parse_dname | ( | const char * | str, |
uint8_t ** | res, | ||
size_t * | len, | ||
int * | labs | ||
) |
Form wireformat from text format domain name.
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. |
Referenced by lz_enter_zone(), lz_exists(), ub_ctx_data_remove(), ub_ctx_set_stub(), ub_ctx_zone_add(), and ub_ctx_zone_remove().
struct local_zone* lz_enter_zone | ( | struct local_zones * | zones, |
const char * | name, | ||
const char * | type, | ||
uint16_t | dclass | ||
) |
enter a new zone
Enter a new zone; returns with WRlock Made public for unit testing.
References local_zone::dclass, local_zone_str2type(), log_err(), lz_enter_zone_dname(), local_zone::name, parse_dname(), and local_zone::type.
Referenced by local_zone_enter_defaults(), and lz_enter_zones().
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.
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 |
Referenced by lz_enter_rr_into_zone().
|
static |
Find an rrset in local data structure.
data | local data domain name structure. |
type | type to look for (host order). |
alias_ok | 1 if matching a non-exact, alias type such as CNAME is allowed. otherwise 0. |
References LDNS_RR_TYPE_CNAME, local_rrset::next, ub_packed_rrset_key::rk, local_rrset::rrset, local_data::rrsets, and packed_rrset_key::type.
Referenced by local_zone_does_not_cover(), and local_zone_enter_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 RR into RRset data structure; Wastes a couple of bytes
Insert specified rdata into the specified resource record.
References packed_rrset_data::count, packed_rrset_data::rr_data, packed_rrset_data::rr_len, and packed_rrset_data::rr_ttl.
Referenced by mesh_state_add_reply(), and respip_enter_rr().
int local_rrset_remove_rr | ( | struct packed_rrset_data * | pd, |
size_t | index | ||
) |
Delete RR from local-zone RRset, wastes memory as the deleted RRs cannot be free'd (regionally alloc'd)
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(), rpz_remove_clientip_rr(), and rpz_rrset_delete_rr().
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.
z | local_zone containing data tree |
nm | name of local-data element to find |
nmlen | length of nm |
nmlabs | labs of nm |
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().
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.
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 |
References LDNS_RR_TYPE_CNAME, 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, query_dname_compare(), local_zone::region, ub_packed_rrset_key::rk, local_rrset::rrset, local_data::rrsets, local_zone::type, and packed_rrset_key::type.
Referenced by lz_enter_rr_into_zone().
int local_zone_enter_defaults | ( | struct local_zones * | zones, |
struct config_file * | cfg | ||
) |
enter default zones
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().
void lz_init_parents | ( | struct local_zones * | zones | ) |
setup parent pointers, so that a lookup can be done for closest match
Setup parent pointers, so that a lookup can be done for closest match Made public for unit testing.
References local_zones::lock, local_zone::node, rbnode_type::parent, RBTREE_FOR, and local_zones::ztree.
Referenced by local_zones_apply_cfg(), and lz_setup_implicit().
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.
zones | is set up. |
cfg | config data. |
References local_zone_enter_defaults(), lz_enter_data(), lz_enter_overrides(), lz_enter_zone_tags(), lz_enter_zones(), lz_freeup_cfg(), lz_init_parents(), and lz_setup_implicit().
Referenced by context_finalize(), and views_apply_cfg().
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.
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. |
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().
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.
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. |
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().
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.
zones | the zones tree |
name | dname to lookup |
len | length of name. |
labs | labelcount of name. |
dclass | class to lookup. |
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 lz_enter_override(), lz_enter_zone_tag(), perform_zone_add(), perform_zone_remove(), ub_ctx_zone_add(), and ub_ctx_zone_remove().
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.
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. |
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 local_zones_add_zone(), and rpz_find_zone().
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 the list
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().
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.
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 |
|
static |
See if the local zone does not cover the name, eg.
the name is not in the zone and the zone is transparent
References local_zone::data, rbnode_type::key, local_data_find_type(), local_zone_always_transparent, local_zone_block_a, local_zone_inform, local_zone_transparent, local_zone_typetransparent, local_data::name, local_data::namelabs, local_data::namelen, local_data::node, query_info::qname, query_info::qname_len, query_info::qtype, rbtree_search(), and local_zone::type.
Referenced by local_zones_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).
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. |
no reply at all, signal caller by clearing buffer.
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.
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. |
References addr_to_str(), dname_str(), LDNS_MAX_DOMAINLEN, local_zone_type2str(), log_nametypeclass(), local_zone::name, NO_VERBOSE, query_info::qclass, query_info::qname, query_info::qtype, and local_zone::type.
Referenced by respip_rewrite_reply().
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.
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. |
References dname_count_labels(), dname_str(), view::isfirst, local_zone_always_transparent, local_zone_block_a, local_zone_does_not_cover(), local_zone_inform, local_zone_noview, local_zone_transparent, local_zone_type2str(), local_zone_typetransparent, view::local_zones, local_zones_lookup(), local_zones_tags_lookup(), local_zones::lock, local_zone::lock, view::lock, local_zone::name, view::name, 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(), and libworker_fg().
const char* local_zone_type2str | ( | enum localzone_type | t | ) |
Print localzone type to a string.
Pointer to a constant string.
t | local zone 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_block_a, 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(), and local_zones_answer().
int local_zone_str2type | ( | const char * | str, |
enum localzone_type * | t | ||
) |
Parse the string into localzone type.
str | string to parse |
t | local zone type returned here. |
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_block_a, 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 lz_enter_override(), lz_enter_zone(), perform_zone_add(), and ub_ctx_zone_add().
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).
zones | the zones tree |
name | dname to add |
len | length of name. |
labs | labelcount of name. |
dclass | class to add. |
tp | type. |
References local_zone::dclass, local_zone_create(), local_zones_find_le(), local_zone::lock, local_zone::name, and local_zone::parent.
Referenced by local_zones_add_RR(), perform_zone_add(), and ub_ctx_zone_add().
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.
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(), and ub_ctx_zone_remove().
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.
zones | the zones tree. Not locked by caller. |
rr | string with on RR. |
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().
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.
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().