unbound: iterator/iter_hints.h File Reference

unbound 0.1

Data Structures | Functions
iter_hints.h File Reference

This file contains functions to assist the iterator module. More...

`#include "util/storage/dnstree.h"`
`#include "util/locks.h"`

## Data Structures
struct | iter_hints
| Iterator hints structure. More...
struct | iter_hints_stub
| Iterator hints for a particular stub. More...

## Functions
struct iter_hints * | hints_create (void)
| Create hints.
void | hints_delete (struct iter_hints *hints)
| Delete hints.
int | hints_apply_cfg (struct iter_hints *hints, struct config_file *cfg)
| Process hints config.
struct delegpt * | hints_find (struct iter_hints *hints, uint8_t *qname, uint16_t qclass, int nolock)
| Find hints for the given class.
struct delegpt * | hints_find_root (struct iter_hints *hints, uint16_t qclass, int nolock)
| Same as hints_lookup, but for the root only.
int | hints_next_root (struct iter_hints *hints, uint16_t *qclass, int nolock)
| Find next root hints (to cycle through all root hints).
struct iter_hints_stub * | hints_lookup_stub (struct iter_hints *hints, uint8_t *qname, uint16_t qclass, struct delegpt *dp, int nolock)
| Given a qname/qclass combination, and the delegation point from the cache for this qname/qclass, determine if this combination indicates that a stub hint exists and must be primed.
size_t | hints_get_mem (struct iter_hints *hints)
| Get memory in use by hints Locks and unlocks the structure.
int | hints_add_stub (struct iter_hints *hints, uint16_t c, struct delegpt *dp, int noprime, int nolock)
| Add stub to hints structure.
void | hints_delete_stub (struct iter_hints *hints, uint16_t c, uint8_t *nm, int nolock)
| Remove stub from hints structure.
void | hints_swap_tree (struct iter_hints *hints, struct iter_hints *data)
| Swap internal tree with preallocated entries.

## Detailed Description

This file contains functions to assist the iterator module.

Keep track of stub and root hints, and read those from config.

## Function Documentation

## ◆ hints_create()

struct iter_hints * hints_create | ( | void |  | ) |

Create hints.

Returns
  new hints or NULL on error.

References iter_hints::lock, and iter_hints::tree.

Referenced by check_hints(), context_finalize(), daemon_fork(), and fr_construct_from_config().

## ◆ hints_delete()

void hints_delete | ( | struct iter_hints * | hints | ) |

Delete hints.

Parameters

  hints | to delete.

References iter_hints::lock.

Referenced by check_hints(), daemon_cleanup(), fr_construct_clear(), and ub_ctx_delete().

## ◆ hints_apply_cfg()

int hints_apply_cfg | ( | struct iter_hints * | hints,
|  | struct config_file * | cfg )

Process hints config.

Sets default values for root hints if no config.

Parameters

  hints | where to store.
  cfg | config options.

Returns
  0 on error.

References compile_time_root_prime(), config_file::do_ip4, config_file::do_ip6, hints_find_root(), hints_insert(), LDNS_RR_CLASS_IN, iter_hints::lock, name_tree_init(), name_tree_init_parents(), read_root_hints_list(), read_stubs(), iter_hints::tree, VERB_ALGO, and verbose().

Referenced by check_hints(), context_finalize(), daemon_fork(), and fr_construct_from_config().

## ◆ hints_find()

struct delegpt * hints_find | ( | struct iter_hints * | hints,
|  | uint8_t * | qname,
|  | uint16_t | qclass,
|  | int | nolock )

Find hints for the given class.

The return value is contents of the hints structure. Caller should lock and unlock a readlock on the hints structure if nolock is set. Otherwise caller should unlock the readlock on the hints structure if a value was returned.

Parameters

  hints | hint storage.
  qname | the qname that generated the delegation point.
  qclass | class for which root hints are requested. host order.
  nolock | Skip locking, locking is handled by the caller.

Returns
  : NULL if no hints, or a ptr to stored hints.

References dname_count_size_labels(), iter_hints_stub::dp, iter_hints::lock, name_tree_find(), and iter_hints::tree.

Referenced by can_have_last_resort(), and hints_find_root().

## ◆ hints_find_root()

struct delegpt * hints_find_root | ( | struct iter_hints * | hints,
|  | uint16_t | qclass,
|  | int | nolock )

Same as hints_lookup, but for the root only.

Parameters

  hints | hint storage.
  qclass | class for which root hints are requested. host order.
  nolock | Skip locking, locking is handled by the caller.

Returns
  : NULL if no hints, or a ptr to stored hints.

References hints_find().

Referenced by hints_apply_cfg(), prime_root(), processInitRequest(), and processLastResort().

## ◆ hints_next_root()

int hints_next_root | ( | struct iter_hints * | hints,
|  | uint16_t * | qclass,
|  | int | nolock )

Find next root hints (to cycle through all root hints).

Handles its own locking unless nolock is set. In that case the caller should lock and unlock a readlock on the hints structure.

Parameters

  hints | hint storage
  qclass | class for which root hints are sought. 0 means give the first available root hints class. x means, give class x or a higher class if any. returns the found class in this variable.
  nolock | Skip locking, locking is handled by the caller.

Returns
  true if a root hint class is found. false if not root hint class is found (qclass may have been changed).

References iter_hints::lock, name_tree_next_root(), and iter_hints::tree.

Referenced by iter_get_next_root().

## ◆ hints_lookup_stub()

struct iter_hints_stub * hints_lookup_stub | ( | struct iter_hints * | hints,
|  | uint8_t * | qname,
|  | uint16_t | qclass,
|  | struct delegpt * | dp,
|  | int | nolock )

Given a qname/qclass combination, and the delegation point from the cache for this qname/qclass, determine if this combination indicates that a stub hint exists and must be primed.

The return value is contents of the hints structure. Caller should lock and unlock a readlock on the hints structure if nolock is set. Otherwise caller should unlock the readlock on the hints structure if a value was returned.

Parameters

  hints | hint storage.
  qname | The qname that generated the delegation point.
  qclass | The qclass that generated the delegation point.
  dp | The cache generated delegation point.
  nolock | Skip locking, locking is handled by the caller.

Returns
  : A priming delegation point if there is a stub hint that must be primed, otherwise null.

References dname_count_size_labels(), dname_strict_subdomain(), iter_hints_stub::dp, iter_hints::lock, delegpt::name, name_tree_lookup(), delegpt::namelabs, iter_hints_stub::noprime, query_dname_compare(), and iter_hints::tree.

Referenced by iter_stub_fwd_no_cache(), prime_stub(), and processInitRequest2().

## ◆ hints_get_mem()

size_t hints_get_mem | ( | struct iter_hints * | hints | ) |

Get memory in use by hints Locks and unlocks the structure.

Parameters

  hints | hint storage.

Returns
  bytes in use

References delegpt_get_mem(), iter_hints_stub::dp, iter_hints::lock, RBTREE_FOR, and iter_hints::tree.

Referenced by fr_printmem(), and worker_mem_report().

## ◆ hints_add_stub()

int hints_add_stub | ( | struct iter_hints * | hints,
|  | uint16_t | c,
|  | struct delegpt * | dp,
|  | int | noprime,
|  | int | nolock )

Add stub to hints structure.

For external use since it recalcs the tree parents. Handles its own locking unless nolock is set. In that case the caller should lock and unlock a writelock on the hints structure.

Parameters

  hints | the hints data structure
  c | class of zone
  dp | delegation point with name and target nameservers for new hints stub. malloced.
  noprime | set noprime option to true or false on new hint stub.
  nolock | Skip locking, locking is handled by the caller.

Returns
  false on failure (out of memory);

References iter_hints_stub::dp, hints_insert(), iter_hints::lock, delegpt::name, name_tree_find(), name_tree_init_parents(), delegpt::namelabs, delegpt::namelen, iter_hints_stub::node, iter_hints_stub::noprime, rbtree_delete(), and iter_hints::tree.

Referenced by do_stub_add().

## ◆ hints_delete_stub()

void hints_delete_stub | ( | struct iter_hints * | hints,
|  | uint16_t | c,
|  | uint8_t * | nm,
|  | int | nolock )

Remove stub from hints structure.

For external use since it recalcs the tree parents. Handles its own locking unless nolock is set. In that case the caller should lock and unlock a writelock on the hints structure.

Parameters

  hints | the hints data structure
  c | class of stub zone
  nm | name of stub zone (in uncompressed wireformat).
  nolock | Skip locking, locking is handled by the caller.

References dname_count_size_labels(), iter_hints::lock, name_tree_find(), name_tree_init_parents(), iter_hints_stub::node, rbtree_delete(), and iter_hints::tree.

Referenced by do_stub_remove().

## ◆ hints_swap_tree()

void hints_swap_tree | ( | struct iter_hints * | hints,
|  | struct iter_hints * | data )

Swap internal tree with preallocated entries.

Caller should manage the locks.

Parameters

  hints | the hints data structure.
  data | the data structure used to take elements from. This contains the old elements on return.

References rbtree_type::count, rbtree_type::root, and iter_hints::tree.

Referenced by fr_reload_config().