rrset.h File Reference

This file contains the rrset cache. More...

Data Structures

struct  rrset_cache
 The rrset cache Thin wrapper around hashtable, like a typedef. More...
 

Functions

struct rrset_cacherrset_cache_create (struct config_file *cfg, struct alloc_cache *alloc)
 Create rrset cache. More...
 
void rrset_cache_delete (struct rrset_cache *r)
 Delete rrset cache. More...
 
struct rrset_cacherrset_cache_adjust (struct rrset_cache *r, struct config_file *cfg, struct alloc_cache *alloc)
 Adjust settings of the cache to settings from the config file. More...
 
void rrset_cache_touch (struct rrset_cache *r, struct ub_packed_rrset_key *key, hashvalue_type hash, rrset_id_type id)
 Touch rrset, with given pointer and id. More...
 
int rrset_cache_update (struct rrset_cache *r, struct rrset_ref *ref, struct alloc_cache *alloc, time_t timenow)
 Update an rrset in the rrset cache. More...
 
void rrset_cache_update_wildcard (struct rrset_cache *rrset_cache, struct ub_packed_rrset_key *rrset, uint8_t *ce, size_t ce_len, struct alloc_cache *alloc, time_t timenow)
 Update or add an rrset in the rrset cache using a wildcard dname. More...
 
struct ub_packed_rrset_keyrrset_cache_lookup (struct rrset_cache *r, uint8_t *qname, size_t qnamelen, uint16_t qtype, uint16_t qclass, uint32_t flags, time_t timenow, int wr)
 Lookup rrset. More...
 
int rrset_array_lock (struct rrset_ref *ref, size_t count, time_t timenow)
 Obtain readlock on a (sorted) list of rrset references. More...
 
void rrset_array_unlock (struct rrset_ref *ref, size_t count)
 Unlock array (sorted) of rrset references. More...
 
void rrset_array_unlock_touch (struct rrset_cache *r, struct regional *scratch, struct rrset_ref *ref, size_t count)
 Unlock array (sorted) of rrset references and at the same time touch LRU on the rrsets. More...
 
void rrset_update_sec_status (struct rrset_cache *r, struct ub_packed_rrset_key *rrset, time_t now)
 Update security status of an rrset. More...
 
void rrset_check_sec_status (struct rrset_cache *r, struct ub_packed_rrset_key *rrset, time_t now)
 Looks up security status of an rrset. More...
 
void rrset_cache_remove_above (struct rrset_cache *r, uint8_t **qname, size_t *qnamelen, uint16_t searchtype, uint16_t qclass, time_t now, uint8_t *qnametop, size_t qnametoplen)
 Removes rrsets above the qname, returns upper qname. More...
 
int rrset_cache_expired_above (struct rrset_cache *r, uint8_t **qname, size_t *qnamelen, uint16_t searchtype, uint16_t qclass, time_t now, uint8_t *qnametop, size_t qnametoplen)
 Sees if an rrset is expired above the qname, returns upper qname. More...
 
void rrset_cache_remove (struct rrset_cache *r, uint8_t *nm, size_t nmlen, uint16_t type, uint16_t dclass, uint32_t flags)
 Remove an rrset from the cache, by name and type and flags. More...
 
void rrset_markdel (void *key)
 mark rrset to be deleted, set id=0
 

Detailed Description

This file contains the rrset cache.

Function Documentation

◆ rrset_cache_create()

struct rrset_cache* rrset_cache_create ( struct config_file cfg,
struct alloc_cache alloc 
)

Create rrset cache.

Parameters
cfgconfig settings or NULL for defaults.
allocinitial default rrset key allocation.
Returns
: NULL on error.

References HASH_DEFAULT_MAXMEM, HASH_DEFAULT_SLABS, HASH_DEFAULT_STARTARRAY, config_file::rrset_cache_size, config_file::rrset_cache_slabs, rrset_data_delete(), rrset_markdel(), slabhash_create(), slabhash_setmarkdel(), rrset_cache::table, ub_rrset_compare(), ub_rrset_key_delete(), and ub_rrset_sizefunc().

Referenced by rrset_cache_adjust().

◆ rrset_cache_delete()

void rrset_cache_delete ( struct rrset_cache r)

Delete rrset cache.

Parameters
rrrset cache to delete.

References slabhash_delete(), and rrset_cache::table.

Referenced by daemon_delete(), and rrset_cache_adjust().

◆ rrset_cache_adjust()

struct rrset_cache* rrset_cache_adjust ( struct rrset_cache r,
struct config_file cfg,
struct alloc_cache alloc 
)

Adjust settings of the cache to settings from the config file.

May purge the cache. May recreate the cache. There may be no threading or use by other threads.

Parameters
rrrset cache to adjust (like realloc).
cfgconfig settings or NULL for defaults.
allocinitial default rrset key allocation.
Returns
0 on error, or new rrset cache pointer on success.

References rrset_cache_create(), rrset_cache_delete(), config_file::rrset_cache_size, config_file::rrset_cache_slabs, slabhash_is_size(), and rrset_cache::table.

Referenced by context_finalize().

◆ rrset_cache_touch()

void rrset_cache_touch ( struct rrset_cache r,
struct ub_packed_rrset_key key,
hashvalue_type  hash,
rrset_id_type  id 
)

Touch rrset, with given pointer and id.

Caller may not hold a lock on ANY rrset, this could give deadlock.

This routine is faster than a hashtable lookup: o no bin_lock is acquired. o no walk through the bin-overflow-list. o no comparison of the entry key to find it.

Parameters
rrrset cache.
keyrrset key. Marked recently used (if it was not deleted before the lock is acquired, in that case nothing happens).
hashhash value of the item. Please read it from the key when you have it locked. Used to find slab from slabhash.
idused to check that the item is unchanged and not deleted.

References ub_packed_rrset_key::entry, lruhash_entry::hash, ub_packed_rrset_key::id, lruhash::lock, lruhash_entry::lock, lru_touch(), slabhash_gettable(), and rrset_cache::table.

Referenced by rrset_array_unlock_touch().

◆ rrset_cache_update()

int rrset_cache_update ( struct rrset_cache r,
struct rrset_ref ref,
struct alloc_cache alloc,
time_t  timenow 
)

Update an rrset in the rrset cache.

Stores the information for later use. Will lookup if the rrset is in the cache and perform an update if necessary. If the item was present, and superior, references are returned to that. The passed item is then deallocated with rrset_parsedelete.

A superior rrset is: o rrset with better trust value. o same trust value, different rdata, newly passed rrset is inserted. If rdata is the same, TTL in the cache is updated.

Parameters
rthe rrset cache.
refreference (ptr and id) to the rrset. Pass reference setup for the new rrset. The reference may be changed if the cached rrset is superior. Before calling the rrset is presumed newly allocated and changeable. After calling you do not hold a lock, and the rrset is inserted in the hashtable so you need a lock to change it.
allochow to allocate (and deallocate) the special rrset key.
timenowcurrent time (to see if ttl in cache is expired).
Returns
: true if the passed reference is updated, false if it is unchanged. 0: reference unchanged, inserted in cache. 1: reference updated, item is inserted in cache. 2: reference updated, item in cache is considered superior. also the rdata is equal (but other parameters in cache are superior).

References lruhash_entry::data, packed_rrset_key::dname, ub_packed_rrset_key::entry, lruhash_entry::hash, rrset_ref::id, ub_packed_rrset_key::id, rrset_ref::key, lruhash_entry::key, LDNS_RR_TYPE_NS, lruhash_entry::lock, log_assert, need_to_update_rrset(), ub_packed_rrset_key::rk, rrsetdata_equal(), slabhash_insert(), slabhash_lookup(), rrset_cache::table, packed_rrset_key::type, and ub_packed_rrset_parsedelete().

Referenced by dns_cache_store(), iter_store_parentside_rrset(), move_into_cache(), rrset_cache_update_wildcard(), store_rrset(), and store_rrsets().

◆ rrset_cache_update_wildcard()

void rrset_cache_update_wildcard ( struct rrset_cache rrset_cache,
struct ub_packed_rrset_key rrset,
uint8_t *  ce,
size_t  ce_len,
struct alloc_cache alloc,
time_t  timenow 
)

Update or add an rrset in the rrset cache using a wildcard dname.

Generates wildcard dname by prepending the wildcard label to the closest encloser. Will lookup if the rrset is in the cache and perform an update if necessary.

Parameters
rrset_cachethe rrset cache.
rrsetwhich rrset to cache as wildcard. This rrset is left untouched.
cethe closest encloser, will be uses to generate the wildcard dname.
ce_lenthe closest encloser length.
allochow to allocate (and deallocate) the special rrset key.
timenowcurrent time (to see if ttl in cache is expired).

References alloc_special_release(), packed_rrset_key::dname, packed_rrset_key::dname_len, ub_packed_rrset_key::entry, lruhash_entry::hash, rrset_ref::id, ub_packed_rrset_key::id, rrset_ref::key, LDNS_MAX_DOMAINLEN, log_err(), memdup(), packed_rrset_copy_alloc(), ub_packed_rrset_key::rk, rrset_cache_update(), and rrset_key_hash().

◆ rrset_cache_lookup()

struct ub_packed_rrset_key* rrset_cache_lookup ( struct rrset_cache r,
uint8_t *  qname,
size_t  qnamelen,
uint16_t  qtype,
uint16_t  qclass,
uint32_t  flags,
time_t  timenow,
int  wr 
)

Lookup rrset.

You obtain read/write lock. You must unlock before lookup anything of else.

Parameters
rthe rrset cache.
qnamename of rrset to lookup.
qnamelenlength of name of rrset to lookup.
qtypetype of rrset to lookup (host order).
qclassclass of rrset to lookup (host order).
flagsrrset flags, or 0.
timenowused to compare with TTL.
wrset true to get writelock.
Returns
packed rrset key pointer. Remember to unlock the key.entry.lock. or NULL if could not be found or it was timed out.

References lruhash_entry::data, packed_rrset_key::dname, packed_rrset_key::dname_len, ub_packed_rrset_key::entry, packed_rrset_key::flags, lruhash_entry::hash, lruhash_entry::key, lruhash_entry::lock, ub_packed_rrset_key::rk, packed_rrset_key::rrset_class, rrset_key_hash(), slabhash_lookup(), rrset_cache::table, packed_rrset_data::ttl, and packed_rrset_key::type.

Referenced by add_soa(), dns_cache_lookup(), find_add_addrs(), find_add_ds(), find_closest_of_type(), grab_nsec(), iter_lookup_parent_NS_from_cache(), load_ref(), rrset_cache_expired_above(), rrset_cache_remove_above(), and val_find_DS().

◆ rrset_array_lock()

int rrset_array_lock ( struct rrset_ref ref,
size_t  count,
time_t  timenow 
)

Obtain readlock on a (sorted) list of rrset references.

Checks TTLs and IDs of the rrsets and rollbacks locking if not Ok.

Parameters
refarray of rrset references (key pointer and ID value). duplicate references are allowed and handled.
countsize of array.
timenowused to compare with TTL.
Returns
true on success, false on a failure, which can be that some RRsets have timed out, or that they do not exist any more, the RRsets have been purged from the cache. If true, you hold readlocks on all the ref items.

References packed_rrset_data::count, lruhash_entry::data, ub_packed_rrset_key::entry, rrset_ref::id, rrset_ref::key, and rrset_array_unlock().

Referenced by answer_from_cache(), dump_msg(), invalidateQueryInCache(), and tomsg().

◆ rrset_array_unlock()

void rrset_array_unlock ( struct rrset_ref ref,
size_t  count 
)

Unlock array (sorted) of rrset references.

Parameters
refarray of rrset references (key pointer and ID value). duplicate references are allowed and handled.
countsize of array.

References packed_rrset_data::count.

Referenced by dump_msg(), invalidateQueryInCache(), rrset_array_lock(), and tomsg().

◆ rrset_array_unlock_touch()

void rrset_array_unlock_touch ( struct rrset_cache r,
struct regional scratch,
struct rrset_ref ref,
size_t  count 
)

Unlock array (sorted) of rrset references and at the same time touch LRU on the rrsets.

It needs the scratch region for temporary storage as it uses the initial locks to obtain hash values.

Parameters
rthe rrset cache. In this cache LRU is updated.
scratchregion for temporary storage of hash values. if memory allocation fails, the lru touch fails silently, but locks are released. memory errors are logged.
refarray of rrset references (key pointer and ID value). duplicate references are allowed and handled.
countsize of array.

References packed_rrset_data::count, log_warn(), regional_alloc(), RR_COUNT_MAX, and rrset_cache_touch().

Referenced by tomsg().

◆ rrset_update_sec_status()

void rrset_update_sec_status ( struct rrset_cache r,
struct ub_packed_rrset_key rrset,
time_t  now 
)

Update security status of an rrset.

Looks up the rrset. If found, checks if rdata is equal. If so, it will update the security, trust and rrset-ttl values. The values are only updated if security is increased (towards secure).

Parameters
rthe rrset cache.
rrsetwhich rrset to attempt to update. This rrset is left untouched. The rrset in the cache is updated in-place.
nowcurrent time.

References lruhash_entry::data, ub_packed_rrset_key::entry, lruhash_entry::hash, LDNS_RR_TYPE_NS, ub_packed_rrset_key::rk, packed_rrset_data::rr_ttl, rrset_key_hash(), rrsetdata_equal(), sec_status_bogus, packed_rrset_data::security, slabhash_lookup(), rrset_cache::table, packed_rrset_data::trust, packed_rrset_data::ttl, and packed_rrset_key::type.

Referenced by val_mark_indeterminate(), and val_mark_insecure().

◆ rrset_check_sec_status()

void rrset_check_sec_status ( struct rrset_cache r,
struct ub_packed_rrset_key rrset,
time_t  now 
)

Looks up security status of an rrset.

Looks up the rrset. If found, checks if rdata is equal, and entry did not expire. If so, it will update the security, trust and rrset-ttl values.

Parameters
rthe rrset cache.
rrsetThis rrset may change security status due to the cache. But its status will only improve, towards secure.
nowcurrent time.

References lruhash_entry::data, ub_packed_rrset_key::entry, lruhash_entry::hash, ub_packed_rrset_key::rk, packed_rrset_data::rr_ttl, rrset_key_hash(), rrsetdata_equal(), sec_status_bogus, packed_rrset_data::security, slabhash_lookup(), rrset_cache::table, packed_rrset_data::trust, and packed_rrset_data::ttl.

Referenced by nsec_verify_rrset().

◆ rrset_cache_remove_above()

void rrset_cache_remove_above ( struct rrset_cache r,
uint8_t **  qname,
size_t *  qnamelen,
uint16_t  searchtype,
uint16_t  qclass,
time_t  now,
uint8_t *  qnametop,
size_t  qnametoplen 
)

Removes rrsets above the qname, returns upper qname.

Parameters
rthe rrset cache.
qnamethe start qname, also used as the output.
qnamelenlength of qname, updated when it returns.
searchtypeqtype to search for.
qclassqclass to search for.
nowcurrent time.
qnametopthe top qname to stop removal (it is not removed).
qnametoplenlength of qnametop.

References lruhash_entry::data, ub_packed_rrset_key::entry, lruhash_entry::lock, log_nametypeclass(), query_dname_compare(), rrset_cache_lookup(), rrset_cache_remove(), packed_rrset_data::ttl, VERB_ALGO, and verbosity.

◆ rrset_cache_expired_above()

int rrset_cache_expired_above ( struct rrset_cache r,
uint8_t **  qname,
size_t *  qnamelen,
uint16_t  searchtype,
uint16_t  qclass,
time_t  now,
uint8_t *  qnametop,
size_t  qnametoplen 
)

Sees if an rrset is expired above the qname, returns upper qname.

Parameters
rthe rrset cache.
qnamethe start qname, also used as the output.
qnamelenlength of qname, updated when it returns.
searchtypeqtype to search for.
qclassqclass to search for.
nowcurrent time.
qnametopthe top qname, don't look farther than that.
qnametoplenlength of qnametop.
Returns
true if there is an expired rrset above, false otherwise.

References lruhash_entry::data, ub_packed_rrset_key::entry, lruhash_entry::lock, log_nametypeclass(), query_dname_compare(), rrset_cache_lookup(), packed_rrset_data::ttl, and VERB_ALGO.

Referenced by find_closest_of_type().

◆ rrset_cache_remove()

void rrset_cache_remove ( struct rrset_cache r,
uint8_t *  nm,
size_t  nmlen,
uint16_t  type,
uint16_t  dclass,
uint32_t  flags 
)

Remove an rrset from the cache, by name and type and flags.

Parameters
rrrset cache
nmname of rrset
nmlenlength of name
typetype of rrset
dclassclass of rrset, host order
flagsflags of rrset, host order

References packed_rrset_key::dname, packed_rrset_key::dname_len, ub_packed_rrset_key::entry, packed_rrset_key::flags, lruhash_entry::hash, lruhash_entry::key, ub_packed_rrset_key::rk, packed_rrset_key::rrset_class, rrset_key_hash(), slabhash_remove(), rrset_cache::table, and packed_rrset_key::type.

Referenced by do_cache_remove(), and rrset_cache_remove_above().