Data Structures | Functions
rrset.h File Reference

This file contains the rrset cache. More...

#include "util/storage/lruhash.h"
#include "util/storage/slabhash.h"
#include "util/data/packed_rrset.h"

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_t hash, rrset_id_t 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...
 
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 (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

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

Create rrset cache.

Parameters
cfg,:config settings or NULL for defaults.
alloc,:initial 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().

void rrset_cache_delete ( struct rrset_cache r)

Delete rrset cache.

Parameters
r,:rrset cache to delete.

References slabhash_delete(), and rrset_cache::table.

Referenced by daemon_delete(), rrset_cache_adjust(), and ub_ctx_delete().

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

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
r,:rrset cache to adjust (like realloc).
cfg,:config settings or NULL for defaults.
alloc,:initial 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::size, slabhash_get_size(), and rrset_cache::table.

Referenced by context_finalize(), and daemon_apply_cfg().

void rrset_cache_touch ( struct rrset_cache r,
struct ub_packed_rrset_key key,
hashvalue_t  hash,
rrset_id_t  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
r,:rrset cache.
key,:rrset key. Marked recently used (if it was not deleted before the lock is acquired, in that case nothing happens).
hash,:hash value of the item. Please read it from the key when you have it locked. Used to find slab from slabhash.
id,:used 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().

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
r,:the rrset cache.
ref,:reference (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. Afer calling you do not hold a lock, and the rrset is inserted in the hashtable so you need a lock to change it.
alloc,:how to allocate (and deallocate) the special rrset key.
timenow,:current 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, 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_DNAME, LDNS_RR_TYPE_NS, lruhash_entry::lock, log_assert, need_to_update_rrset(), ub_packed_rrset_key::rk, rrset_update_id(), 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(), store_rrset(), and store_rrsets().

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

Lookup rrset.

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

Parameters
r,:the rrset cache.
qname,:name of rrset to lookup.
qnamelen,:length of name of rrset to lookup.
qtype,:type of rrset to lookup (host order).
qclass,:class of rrset to lookup (host order).
flags,:rrset flags, or 0.
timenow,:used to compare with TTL.
wr,:set 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(), cache_fill_missing(), dns_cache_lookup(), find_add_addrs(), find_add_ds(), find_closest_of_type(), grab_nsec(), iter_lookup_parent_glue_from_cache(), iter_lookup_parent_NS_from_cache(), load_ref(), val_find_DS(), and val_neg_dlvlookup().

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
ref,:array of rrset references (key pointer and ID value). duplicate references are allowed and handled.
count,:size of array.
timenow,:used 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().

void rrset_array_unlock ( struct rrset_ref ref,
size_t  count 
)

Unlock array (sorted) of rrset references.

Parameters
ref,:array of rrset references (key pointer and ID value). duplicate references are allowed and handled.
count,:size of array.

References packed_rrset_data::count.

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

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
r,:the rrset cache. In this cache LRU is updated.
scratch,:region for temporary storage of hash values. if memory allocation fails, the lru touch fails silently, but locks are released. memory errors are logged.
ref,:array of rrset references (key pointer and ID value). duplicate references are allowed and handled.
count,:size of array.

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

Referenced by answer_from_cache(), and tomsg().

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
r,:the rrset cache.
rrset,:which rrset to attempt to update. This rrset is left untouched. The rrset in the cache is updated in-place.
now,:current 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 list_is_secure(), nsec_verify_rrset(), val_mark_indeterminate(), val_mark_insecure(), and val_verify_rrset().

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
r,:the rrset cache.
rrset,:This rrset may change security status due to the cache. But its status will only improve, towards secure.
now,:current 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 list_is_secure(), nsec_verify_rrset(), and val_verify_rrset().

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
r,:rrset cache
nm,:name of rrset
nmlen,:length of name
type,:type of rrset
dclass,:class of rrset, host order
flags,:flags 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 probe_anchor().