unbound 0.1
|
This file contains the DNS cache. More...
#include "config.h"
#include "iterator/iter_delegpt.h"
#include "validator/val_nsec.h"
#include "services/cache/dns.h"
#include "services/cache/rrset.h"
#include "util/data/msgreply.h"
#include "util/data/packed_rrset.h"
#include "util/data/dname.h"
#include "util/module.h"
#include "util/net_help.h"
#include "util/regional.h"
#include "util/config_file.h"
Functions | |
static void | store_rrsets (struct module_env *env, struct reply_info *rep, uint32_t now) |
store rrsets in the rrset cache. | |
void | dns_cache_store_msg (struct module_env *env, struct query_info *qinfo, hashvalue_t hash, struct reply_info *rep, uint32_t leeway) |
Store message in the cache. | |
static struct ub_packed_rrset_key * | find_closest_of_type (struct module_env *env, uint8_t *qname, size_t qnamelen, uint16_t qclass, uint32_t now, uint16_t searchtype, int stripfront) |
find closest NS or DNAME and returns the rrset (locked) | |
static void | addr_to_additional (struct ub_packed_rrset_key *rrset, struct regional *region, struct dns_msg *msg, uint32_t now) |
add addr to additional section | |
static struct msgreply_entry * | msg_cache_lookup (struct module_env *env, uint8_t *qname, size_t qnamelen, uint16_t qtype, uint16_t qclass, uint32_t now, int wr) |
lookup message in message cache | |
static int | find_add_addrs (struct module_env *env, uint16_t qclass, struct regional *region, struct delegpt *dp, uint32_t now, struct dns_msg **msg) |
find and add A and AAAA records for nameservers in delegpt | |
int | cache_fill_missing (struct module_env *env, uint16_t qclass, struct regional *region, struct delegpt *dp) |
find and add A and AAAA records for missing nameservers in delegpt | |
static void | find_add_ds (struct module_env *env, struct regional *region, struct dns_msg *msg, struct delegpt *dp, uint32_t now) |
find and add DS or NSEC to delegation msg | |
struct dns_msg * | dns_msg_create (uint8_t *qname, size_t qnamelen, uint16_t qtype, uint16_t qclass, struct regional *region, size_t capacity) |
Utility, create new, unpacked data structure for cache response. | |
int | dns_msg_authadd (struct dns_msg *msg, struct regional *region, struct ub_packed_rrset_key *rrset, uint32_t now) |
Add rrset to authority section in unpacked dns_msg message. | |
struct delegpt * | dns_cache_find_delegation (struct module_env *env, uint8_t *qname, size_t qnamelen, uint16_t qtype, uint16_t qclass, struct regional *region, struct dns_msg **msg, uint32_t now) |
Find a delegation from the cache. | |
static struct dns_msg * | gen_dns_msg (struct regional *region, struct query_info *q, size_t num) |
allocate dns_msg from query_info and reply_info | |
static struct dns_msg * | tomsg (struct module_env *env, struct query_info *q, struct reply_info *r, struct regional *region, uint32_t now, struct regional *scratch) |
generate dns_msg from cached message | |
static struct dns_msg * | rrset_msg (struct ub_packed_rrset_key *rrset, struct regional *region, uint32_t now, struct query_info *q) |
synthesize RRset-only response from cached RRset item | |
static struct dns_msg * | synth_dname_msg (struct ub_packed_rrset_key *rrset, struct regional *region, uint32_t now, struct query_info *q) |
synthesize DNAME+CNAME response from cached DNAME item | |
struct dns_msg * | dns_cache_lookup (struct module_env *env, uint8_t *qname, size_t qnamelen, uint16_t qtype, uint16_t qclass, struct regional *region, struct regional *scratch) |
Find cached message. | |
int | dns_cache_store (struct module_env *env, struct query_info *msgqinf, struct reply_info *msgrep, int is_referral, uint32_t leeway) |
Allocate a dns_msg with malloc/alloc structure and store in dns cache. |
This file contains the DNS cache.
static void store_rrsets | ( | struct module_env * | env, |
struct reply_info * | rep, | ||
uint32_t | now | ||
) | [static] |
store rrsets in the rrset cache.
env,: | module environment with caches. |
rep,: | contains list of rrsets to store. |
now,: | current time. |
References module_env::alloc, ub_packed_rrset_key::id, rrset_ref::id, rrset_ref::key, reply_info::ref, module_env::rrset_cache, rrset_cache_update(), reply_info::rrset_count, and reply_info::rrsets.
Referenced by dns_cache_store_msg().
void dns_cache_store_msg | ( | struct module_env * | env, |
struct query_info * | qinfo, | ||
hashvalue_t | hash, | ||
struct reply_info * | rep, | ||
uint32_t | leeway | ||
) |
Store message in the cache.
Stores in message cache and rrset cache. Both qinfo and rep should be malloced and are put in the cache. They should not be used after this call, as they are then in shared cache. Does not return errors, they are logged and only lead to less cache.
env,: | module environment with the DNS cache. |
qinfo,: | query info |
hash,: | hash over qinfo. |
rep,: | reply info, together with qinfo makes up the message. Adjusts the reply info TTLs to absolute time. |
leeway,: | TTL value, if not 0, other rrsets are considered expired that many seconds before actual TTL expiry. |
References module_env::alloc, msgreply_entry::entry, ub_packed_rrset_key::id, rrset_ref::id, rrset_ref::key, log_err(), module_env::msg_cache, module_env::now, query_info_entrysetup(), reply_info::ref, reply_info_set_ttls(), reply_info_sortref(), reply_info::rrset_count, reply_info::rrsets, slabhash_insert(), store_rrsets(), reply_info::ttl, VERB_ALGO, and verbose().
Referenced by dns_cache_store().
int cache_fill_missing | ( | struct module_env * | env, |
uint16_t | qclass, | ||
struct regional * | region, | ||
struct delegpt * | dp | ||
) |
find and add A and AAAA records for missing nameservers in delegpt
env,: | module environment with rrset cache |
qclass,: | which class to look in. |
region,: | where to store new dp info. |
dp,: | delegation point to fill missing entries. |
References delegpt_add_neg_msg(), delegpt_add_rrset_A(), delegpt_add_rrset_AAAA(), msgreply_entry::entry, ub_packed_rrset_key::entry, delegpt_ns::lame, lruhash_entry::lock, log_nametypeclass(), msg_cache_lookup(), delegpt_ns::name, delegpt_ns::namelen, delegpt_ns::next, module_env::now, delegpt::nslist, module_env::rrset_cache, rrset_cache_lookup(), and VERB_ALGO.
Referenced by error_supers(), processLastResort(), and processQueryResponse().
struct dns_msg* dns_msg_create | ( | uint8_t * | qname, |
size_t | qnamelen, | ||
uint16_t | qtype, | ||
uint16_t | qclass, | ||
struct regional * | region, | ||
size_t | capacity | ||
) | [read] |
Utility, create new, unpacked data structure for cache response.
QR bit set, no AA. Query set as indicated. Space for number of rrsets.
qname,: | query section name |
qnamelen,: | len of qname |
qtype,: | query section type |
qclass,: | query section class |
region,: | where to alloc. |
capacity,: | number of rrsets space to create in the array. |
References BIT_QR, reply_info::flags, query_info::qclass, reply_info::qdcount, dns_msg::qinfo, query_info::qname, query_info::qname_len, query_info::qtype, regional_alloc(), regional_alloc_init(), regional_alloc_zero(), dns_msg::rep, and reply_info::rrsets.
Referenced by dns_cache_find_delegation(), neg_nsec3_proof_ds(), val_find_DS(), and val_neg_getmsg().
int dns_msg_authadd | ( | struct dns_msg * | msg, |
struct regional * | region, | ||
struct ub_packed_rrset_key * | rrset, | ||
uint32_t | now | ||
) |
Add rrset to authority section in unpacked dns_msg message.
Must have enough space left, does not grow the array.
msg,: | msg to put it in. |
region,: | region to alloc in |
rrset,: | to add in authority section |
now,: | now. |
References reply_info::ns_numrrsets, packed_rrset_copy_region(), dns_msg::rep, reply_info::rrset_count, and reply_info::rrsets.
Referenced by add_soa(), dns_cache_find_delegation(), neg_nsec3_proof_ds(), and val_neg_getmsg().
struct delegpt* dns_cache_find_delegation | ( | struct module_env * | env, |
uint8_t * | qname, | ||
size_t | qnamelen, | ||
uint16_t | qtype, | ||
uint16_t | qclass, | ||
struct regional * | region, | ||
struct dns_msg ** | msg, | ||
uint32_t | timenow | ||
) | [read] |
Find a delegation from the cache.
env,: | module environment with the DNS cache. |
qname,: | query name. |
qnamelen,: | length of qname. |
qtype,: | query type. |
qclass,: | query class. |
region,: | where to allocate result delegation. |
msg,: | if not NULL, delegation message is returned here, synthesized from the cache. |
timenow,: | the time now, for checking if TTL on cache entries is OK. |
References packed_rrset_data::count, lruhash_entry::data, delegpt_create(), delegpt_rrset_add_ns(), delegpt_set_name(), packed_rrset_key::dname, dns_msg_authadd(), dns_msg_create(), ub_packed_rrset_key::entry, find_add_addrs(), find_add_ds(), find_closest_of_type(), lruhash_entry::lock, log_err(), and ub_packed_rrset_key::rk.
Referenced by answer_norec_from_cache(), generate_parentside_target_query(), print_deleg_lookup(), and processInitRequest().
struct dns_msg* dns_cache_lookup | ( | struct module_env * | env, |
uint8_t * | qname, | ||
size_t | qnamelen, | ||
uint16_t | qtype, | ||
uint16_t | qclass, | ||
struct regional * | region, | ||
struct regional * | scratch | ||
) | [read] |
Find cached message.
env,: | module environment with the DNS cache. |
qname,: | query name. |
qnamelen,: | length of qname. |
qtype,: | query type. |
qclass,: | query class. |
region,: | where to allocate result. |
scratch,: | where to allocate temporary data. |
References module_env::cfg, lruhash_entry::data, dname_is_root(), dname_remove_label(), ub_packed_rrset_key::entry, find_closest_of_type(), reply_info::flags, FLAGS_GET_RCODE, config_file::harden_below_nxdomain, lruhash_entry::key, msgreply_entry::key, lruhash_entry::lock, module_env::msg_cache, module_env::now, query_info::qclass, query_info::qname, query_info::qname_len, query_info::qtype, query_info_hash(), module_env::rrset_cache, rrset_cache_lookup(), rrset_msg(), rrset_trust_add_AA, rrset_trust_add_noAA, rrset_trust_auth_AA, rrset_trust_auth_noAA, sec_status_bogus, sec_status_unchecked, reply_info::security, slabhash_lookup(), synth_dname_msg(), tomsg(), and packed_rrset_data::trust.
Referenced by processInitRequest().
int dns_cache_store | ( | struct module_env * | env, |
struct query_info * | qinf, | ||
struct reply_info * | rep, | ||
int | is_referral, | ||
uint32_t | leeway | ||
) |
Allocate a dns_msg with malloc/alloc structure and store in dns cache.
env,: | environment, with alloc structure and dns cache. |
qinf,: | query info, the query for which answer is stored. this is allocated in a region, and will be copied to malloc area before insertion. |
rep,: | reply in dns_msg from dns_alloc_msg for example. this is allocated in a region, and will be copied to malloc area before insertion. |
is_referral,: | If true, then the given message to be stored is a referral. The cache implementation may use this as a hint. It will store only the RRsets, not the message. |
leeway,: | TTL value, if not 0, other rrsets are considered expired that many seconds before actual TTL expiry. |
References module_env::alloc, BIT_AA, BIT_CD, BIT_QR, BIT_RA, lruhash_entry::data, dns_cache_store_msg(), ub_packed_rrset_key::entry, reply_info::flags, ub_packed_rrset_key::id, rrset_ref::id, rrset_ref::key, memdup(), module_env::now, packed_rrset_ttl_add(), query_info::qname, query_info::qname_len, query_info_hash(), reply_info_copy(), reply_info_parsedelete(), module_env::rrset_cache, rrset_cache_update(), reply_info::rrset_count, and reply_info::rrsets.
Referenced by iter_dns_store(), load_msg(), processFinished(), and storeQueryInCache().