localzone.h File Reference

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

#include "util/rbtree.h"
#include "util/locks.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...

Enumerations

enum  localzone_type {
  local_zone_deny = 0, local_zone_refuse, local_zone_static, local_zone_transparent,
  local_zone_redirect, local_zone_nodefault
}
 Local zone type This type determines processing for queries that did not match local-data directly. More...

Functions

struct local_zoneslocal_zones_create ()
 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_zonelocal_zones_lookup (struct local_zones *zones, uint8_t *name, size_t len, int labs, uint16_t dclass)
 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 query_info *qinfo, struct edns_data *edns, ldns_buffer *buf, struct regional *temp)
 Answer authoritatively for local zones.
int local_zone_str2type (const char *str, enum localzone_type *t)
 Parse the string into localzone type.
struct local_zonelocal_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_zonelocal_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, ldns_buffer *buf)
 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.


Detailed Description

This file contains functions to enable local zone authority service.


Enumeration Type Documentation

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

Enumerator:
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_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.


Function Documentation

struct local_zones* local_zones_create (  )  [read]

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(), and localzonechecks().

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(), and ub_ctx_delete().

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 fatal_exit(), init_parents(), lz_enter_data(), lz_enter_defaults(), lz_enter_zones(), lz_freeup_cfg(), and lz_setup_implicit().

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

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().

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().

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, and regional_destroy().

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

struct local_zone* local_zones_lookup ( struct local_zones zones,
uint8_t *  name,
size_t  len,
int  labs,
uint16_t  dclass 
) [read]

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.
Returns:
closest local_zone or NULL if no covering zone is found.

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

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

void local_zones_print ( struct local_zones zones  ) 

int local_zones_answer ( struct local_zones zones,
struct query_info qinfo,
struct edns_data edns,
ldns_buffer *  buf,
struct regional temp 
)

Answer authoritatively for local zones.

Takes care of locking.

Parameters:
zones,: the stored zones (shared, read only).
qinfo,: query info (parsed).
edns,: edns info (parsed).
buf,: buffer with query ID and flags, also for reply.
temp,: temporary storage region.
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).

References dname_count_labels(), local_data_answer(), local_zones_lookup(), local_zone::lock, local_zones::lock, lz_zone_answer(), query_info::qclass, query_info::qname, and query_info::qname_len.

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

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_deny, local_zone_redirect, local_zone_refuse, local_zone_static, and local_zone_transparent.

Referenced by do_zone_add(), lz_enter_zone(), and ub_ctx_zone_add().

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

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_t::key, local_zone::name, local_zone::namelabs, local_zone::namelen, local_zone::node, rbtree_search(), and local_zones::ztree.

Referenced by do_zone_add(), do_zone_remove(), local_zones_add_zone(), ub_ctx_zone_add(), and ub_ctx_zone_remove().

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 
) [read]

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_create(), local_zone_delete(), local_zones_find(), local_zone::lock, log_err(), local_zone::node, local_zone::parent, rbtree_insert(), set_kiddo_parents(), and local_zones::ztree.

Referenced by do_zone_add(), local_zones_add_RR(), 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.

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 do_zone_remove(), and ub_ctx_zone_remove().

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

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.
buf,: buffer for scratch.
Returns:
false on failure.

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

Referenced by do_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.

Parameters:
zones,: zones tree.
name,: dname to remove
len,: length of name.
labs,: labelcount of name.
dclass,: class to remove.

References del_empty_term(), local_zones_lookup(), local_zone::lock, local_zones::lock, lz_find_node(), local_zone::name, local_data::name, query_dname_compare(), local_data::rrsets, and local_zone::soa.

Referenced by do_data_remove(), and ub_ctx_data_remove().

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 memdup().

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


Generated on Tue Oct 13 06:46:31 2009 for unbound by  doxygen 1.5.9