val_neg.h File Reference

This file contains helper functions for the validator module. More...

#include "util/locks.h"
#include "util/rbtree.h"

Data Structures

struct  val_neg_cache
 The negative cache. More...
 
struct  val_neg_zone
 Per Zone aggressive negative caching data. More...
 
struct  val_neg_data
 Data element for aggressive negative caching. More...
 

Functions

struct val_neg_cacheval_neg_create (struct config_file *cfg, size_t maxiter)
 Create negative cache. More...
 
size_t val_neg_get_mem (struct val_neg_cache *neg)
 see how much memory is in use by the negative cache. More...
 
void neg_cache_delete (struct val_neg_cache *neg)
 Destroy negative cache. More...
 
int val_neg_data_compare (const void *a, const void *b)
 Comparison function for rbtree val neg data elements.
 
int val_neg_zone_compare (const void *a, const void *b)
 Comparison function for rbtree val neg zone elements.
 
void val_neg_addreply (struct val_neg_cache *neg, struct reply_info *rep)
 Insert NSECs from this message into the negative cache for reference. More...
 
void val_neg_addreferral (struct val_neg_cache *neg, struct reply_info *rep, uint8_t *zone)
 Insert NSECs from this referral into the negative cache for reference. More...
 
struct dns_msgval_neg_getmsg (struct val_neg_cache *neg, struct query_info *qinfo, struct regional *region, struct rrset_cache *rrset_cache, struct sldns_buffer *buf, time_t now, int addsoa, uint8_t *topname, struct config_file *cfg)
 For the given query, try to get a reply out of the negative cache. More...
 
void neg_insert_data (struct val_neg_cache *neg, struct val_neg_zone *zone, struct ub_packed_rrset_key *nsec)
 Insert data into the data tree of a zone Does not do locking. More...
 
void neg_delete_data (struct val_neg_cache *neg, struct val_neg_data *el)
 Delete a data element from the negative cache. More...
 
struct val_neg_zoneneg_find_zone (struct val_neg_cache *neg, uint8_t *nm, size_t len, uint16_t dclass)
 Find the given zone, from the SOA owner name and class Does not do locking. More...
 
struct val_neg_zoneneg_create_zone (struct val_neg_cache *neg, uint8_t *nm, size_t nm_len, uint16_t dclass)
 Create a new zone. More...
 
void val_neg_zone_take_inuse (struct val_neg_zone *zone)
 take a zone into use. More...
 

Detailed Description

This file contains helper functions for the validator module.

The functions help with aggressive negative caching. This creates new denials of existence, and proofs for absence of types from cached NSEC records.

Function Documentation

◆ val_neg_create()

struct val_neg_cache* val_neg_create ( struct config_file cfg,
size_t  maxiter 
)

Create negative cache.

Parameters
cfgconfig options.
maxitermax nsec3 iterations allowed.
Returns
neg cache, empty or NULL on failure.

References val_neg_cache::lock, log_err(), val_neg_cache::max, config_file::neg_cache_size, val_neg_cache::nsec3_max_iter, rbtree_init(), val_neg_cache::tree, and val_neg_zone_compare().

Referenced by neg_test(), and val_apply_cfg().

◆ val_neg_get_mem()

size_t val_neg_get_mem ( struct val_neg_cache neg)

see how much memory is in use by the negative cache.

Parameters
negnegative cache
Returns
number of bytes in use.

References val_neg_cache::lock, and val_neg_cache::use.

◆ neg_cache_delete()

void neg_cache_delete ( struct val_neg_cache neg)

Destroy negative cache.

There must no longer be any other threads.

Parameters
negnegative cache.

References val_neg_cache::lock, neg_clear_zones(), traverse_postorder(), and val_neg_cache::tree.

Referenced by neg_test(), and val_deinit().

◆ val_neg_addreply()

◆ val_neg_addreferral()

void val_neg_addreferral ( struct val_neg_cache neg,
struct reply_info rep,
uint8_t *  zone 
)

Insert NSECs from this referral into the negative cache for reference.

Parameters
negnegative cache
repreferral reply with NS, NSECs.
zonebailiwick for the referral. Errors are ignored, means that storage is omitted.

References reply_info::an_numrrsets, calc_data_need(), calc_zone_need(), val_neg_zone::dclass, dname_subdomain_c(), LDNS_RR_TYPE_NS, val_neg_cache::lock, log_err(), log_nametypeclass(), neg_create_zone(), neg_find_zone(), neg_make_space(), reply_info::ns_numrrsets, reply_nsec_signer(), ub_packed_rrset_key::rk, reply_info::rrsets, packed_rrset_key::type, val_neg_zone_take_inuse(), and VERB_ALGO.

◆ val_neg_getmsg()

struct dns_msg* val_neg_getmsg ( struct val_neg_cache neg,
struct query_info qinfo,
struct regional region,
struct rrset_cache rrset_cache,
struct sldns_buffer buf,
time_t  now,
int  addsoa,
uint8_t *  topname,
struct config_file cfg 
)

For the given query, try to get a reply out of the negative cache.

The reply still needs to be validated.

Parameters
negnegative cache.
qinfoquery
regionwhere to allocate reply.
rrset_cacherrset cache.
buftemporary buffer.
nowto check TTLs against.
addsoaif true, produce result for external consumption. if false, do not add SOA - for unbound-internal consumption.
topnamedo not look higher than this name, so that the result cannot be taken from a zone above the current trust anchor. Which could happen with multiple islands of trust. if NULL, then no trust anchor is used, but also the algorithm becomes more conservative, especially for opt-out zones, since the receiver may have a trust-anchor below the optout and thus the optout cannot be used to create a proof from the negative cache.
cfgconfig options.
Returns
a reply message if something was found. This reply may still need validation. NULL if nothing found (or out of memory).

References LDNS_MAX_DOMAINLEN.

Referenced by val_find_DS().

◆ neg_insert_data()

◆ neg_delete_data()

void neg_delete_data ( struct val_neg_cache neg,
struct val_neg_data el 
)

Delete a data element from the negative cache.

May delete other data elements to keep tree coherent, or only mark the element as 'not in use'. Does not do locking.

Parameters
negnegative cache.
eldata element to delete.

References rbtree_type::count, val_neg_data::count, val_neg_cache::first, val_neg_data::in_use, val_neg_cache::last, val_neg_data::len, log_assert, val_neg_data::name, neg_delete_zone(), neg_lru_remove(), val_neg_data::node, val_neg_data::parent, rbtree_delete(), val_neg_zone::tree, val_neg_cache::use, and val_neg_data::zone.

Referenced by neg_make_space(), and remove_item().

◆ neg_find_zone()

struct val_neg_zone* neg_find_zone ( struct val_neg_cache neg,
uint8_t *  nm,
size_t  len,
uint16_t  dclass 
)

Find the given zone, from the SOA owner name and class Does not do locking.

Parameters
negnegative cache
nmwhat to look for.
lenlength of nm
dclassclass to look for.
Returns
zone or NULL if not found.

References val_neg_zone::dclass, dname_count_labels(), rbnode_type::key, val_neg_zone::labs, val_neg_zone::len, val_neg_zone::name, val_neg_zone::node, rbtree_search(), and val_neg_cache::tree.

Referenced by add_item(), val_neg_addreferral(), and val_neg_addreply().

◆ neg_create_zone()

struct val_neg_zone* neg_create_zone ( struct val_neg_cache neg,
uint8_t *  nm,
size_t  nm_len,
uint16_t  dclass 
)

Create a new zone.

Does not do locking.

Parameters
negnegative cache
nmwhat to look for.
nm_lenlength of name.
dclassclass of zone, host order.
Returns
zone or NULL if out of memory.

References val_neg_zone::count, val_neg_zone::dclass, dname_count_labels(), val_neg_zone::labs, val_neg_zone::len, log_assert, val_neg_zone::name, neg_closest_zone_parent(), neg_zone_chain(), val_neg_zone::node, val_neg_zone::parent, query_dname_compare(), rbtree_insert(), val_neg_cache::tree, and val_neg_cache::use.

Referenced by add_item(), val_neg_addreferral(), and val_neg_addreply().

◆ val_neg_zone_take_inuse()

void val_neg_zone_take_inuse ( struct val_neg_zone zone)

take a zone into use.

increases counts of parents. Does not do locking.

Parameters
zonezone to take into use.

References val_neg_zone::count, val_neg_zone::in_use, and val_neg_zone::parent.

Referenced by add_item(), val_neg_addreferral(), and val_neg_addreply().