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_cache * | rrset_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_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. 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_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. 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 | |
This file contains the rrset cache.
struct rrset_cache* rrset_cache_create | ( | struct config_file * | cfg, |
struct alloc_cache * | alloc | ||
) |
Create rrset cache.
cfg | config settings or NULL for defaults. |
alloc | initial default rrset key allocation. |
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.
r | rrset cache to delete. |
References slabhash_delete(), and rrset_cache::table.
Referenced by daemon_delete(), and 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.
r | rrset cache to adjust (like realloc). |
cfg | config settings or NULL for defaults. |
alloc | initial default rrset key allocation. |
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().
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.
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.
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. After 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). |
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().
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.
rrset_cache | the rrset cache. |
rrset | which rrset to cache as wildcard. This rrset is left untouched. |
ce | the closest encloser, will be uses to generate the wildcard dname. |
ce_len | the closest encloser length. |
alloc | how to allocate (and deallocate) the special rrset key. |
timenow | current 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().
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.
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. |
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().
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.
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. |
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.
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.
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(), RR_COUNT_MAX, and rrset_cache_touch().
Referenced by 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).
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 val_mark_indeterminate(), and val_mark_insecure().
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.
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 nsec_verify_rrset().
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.
r | the rrset cache. |
qname | the start qname, also used as the output. |
qnamelen | length of qname, updated when it returns. |
searchtype | qtype to search for. |
qclass | qclass to search for. |
now | current time. |
qnametop | the top qname to stop removal (it is not removed). |
qnametoplen | length 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.
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.
r | the rrset cache. |
qname | the start qname, also used as the output. |
qnamelen | length of qname, updated when it returns. |
searchtype | qtype to search for. |
qclass | qclass to search for. |
now | current time. |
qnametop | the top qname, don't look farther than that. |
qnametoplen | length of qnametop. |
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().
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.
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 rrset_cache_remove_above().