infra.c File Reference

This file contains the infrastructure cache. More...

#include "config.h"
#include "services/cache/infra.h"
#include "util/storage/slabhash.h"
#include "util/storage/lookup3.h"
#include "util/data/dname.h"
#include "util/log.h"
#include "util/net_help.h"
#include "util/config_file.h"

Functions

size_t infra_host_sizefunc (void *k, void *d)
 calculate size for the hashtable, does not count size of lameness, so the hashtable is a fixed number of items
int infra_host_compfunc (void *key1, void *key2)
 compare two addresses, returns -1, 0, or +1
void infra_host_delkeyfunc (void *k, void *arg)
 delete key, and destroy the lock
void infra_host_deldatafunc (void *d, void *arg)
 delete data and destroy the lameness hashtable
struct infra_cacheinfra_create (struct config_file *cfg)
 Create infra cache.
void infra_delete (struct infra_cache *infra)
 Delete infra cache.
struct infra_cacheinfra_adjust (struct infra_cache *infra, struct config_file *cfg)
 Adjust infra cache to use updated configuration settings.
static hashvalue_t hash_addr (struct sockaddr_storage *addr, socklen_t addrlen)
 calculate the hash value for a host key
static struct lruhash_entryinfra_lookup_host_nottl (struct infra_cache *infra, struct sockaddr_storage *addr, socklen_t addrlen, int wr)
 lookup version that does not check host ttl (you check it)
struct infra_host_datainfra_lookup_host (struct infra_cache *infra, struct sockaddr_storage *addr, socklen_t addrlen, int wr, uint32_t timenow, struct infra_host_key **key)
 Lookup host data.
static struct lruhash_entrynew_host_entry (struct infra_cache *infra, struct sockaddr_storage *addr, socklen_t addrlen, uint32_t tm)
 Create and init a new entry for a host.
int infra_host (struct infra_cache *infra, struct sockaddr_storage *addr, socklen_t addrlen, uint32_t timenow, int *edns_vs, uint8_t *edns_lame_known, int *to)
 Find host information to send a packet.
static hashvalue_t hash_lameness (uint8_t *name)
 hash lameness key
int infra_lookup_lame (struct infra_host_data *host, uint8_t *name, size_t namelen, uint32_t timenow, int *dlame, int *rlame, int *alame, int *olame)
 Check for lameness of this server for a particular zone.
size_t infra_lame_sizefunc (void *k, void *d)
 calculate size, which is fixed, zonename does not count so that a fixed number of items is stored
int infra_lame_compfunc (void *key1, void *key2)
 compare zone names, returns -1, 0, +1
void infra_lame_delkeyfunc (void *k, void *arg)
 free key, lock and zonename
void infra_lame_deldatafunc (void *d, void *arg)
 free the lameness data
int infra_set_lame (struct infra_cache *infra, struct sockaddr_storage *addr, socklen_t addrlen, uint8_t *name, size_t namelen, uint32_t timenow, int dnsseclame, int reclame, uint16_t qtype)
 Set a host to be lame for the given zone.
void infra_update_tcp_works (struct infra_cache *infra, struct sockaddr_storage *addr, socklen_t addrlen)
 Update information for the host, store that a TCP transaction works.
int infra_rtt_update (struct infra_cache *infra, struct sockaddr_storage *addr, socklen_t addrlen, int roundtrip, int orig_rtt, uint32_t timenow)
 Update rtt information for the host.
int infra_edns_update (struct infra_cache *infra, struct sockaddr_storage *addr, socklen_t addrlen, int edns_version, uint32_t timenow)
 Update edns information for the host.
int infra_get_lame_rtt (struct infra_cache *infra, struct sockaddr_storage *addr, socklen_t addrlen, uint8_t *name, size_t namelen, uint16_t qtype, int *lame, int *dnsseclame, int *reclame, int *rtt, uint32_t timenow)
 Get Lameness information and average RTT if host is in the cache.
static size_t count_host_lame (struct lruhash_entry *e)
 helper memory count for a host lame cache
size_t infra_get_mem (struct infra_cache *infra)
 Get memory used by the infra cache.


Detailed Description

This file contains the infrastructure cache.


Function Documentation

struct infra_cache* infra_create ( struct config_file cfg  )  [read]

void infra_delete ( struct infra_cache infra  ) 

Delete infra cache.

Parameters:
infra,: infrastructure cache to delete.

References infra_cache::hosts, and slabhash_delete().

Referenced by daemon_delete(), infra_adjust(), infra_test(), and ub_ctx_delete().

struct infra_cache* infra_adjust ( struct infra_cache infra,
struct config_file cfg 
) [read]

Adjust infra cache to use updated configuration settings.

This may clean the cache. Operates a bit like realloc. There may be no threading or use by other threads.

Parameters:
infra,: existing cache. If NULL a new infra cache is returned.
cfg,: config options.
Returns:
the new infra cache pointer or NULL on error.

References config_file::host_ttl, infra_cache::host_ttl, infra_cache::hosts, config_file::infra_cache_lame_size, config_file::infra_cache_numhosts, config_file::infra_cache_slabs, infra_create(), infra_delete(), config_file::lame_ttl, infra_cache::lame_ttl, infra_cache::max_lame_size, slabhash::size, and slabhash_get_size().

Referenced by context_finalize(), and daemon_apply_cfg().

struct infra_host_data* infra_lookup_host ( struct infra_cache infra,
struct sockaddr_storage *  addr,
socklen_t  addrlen,
int  wr,
uint32_t  timenow,
struct infra_host_key **  key 
) [read]

Lookup host data.

Parameters:
infra,: infrastructure cache.
addr,: host address.
addrlen,: length of addr.
wr,: set to true to get a writelock on the entry.
timenow,: what time it is now.
key,: the key for the host, returned so caller can unlock when done.
Returns:
: host data or NULL if not found or expired.

References lruhash_entry::data, infra_lookup_host_nottl(), lruhash_entry::key, lruhash_entry::lock, and infra_host_data::ttl.

Referenced by infra_test().

static struct lruhash_entry* new_host_entry ( struct infra_cache infra,
struct sockaddr_storage *  addr,
socklen_t  addrlen,
uint32_t  tm 
) [static, read]

Create and init a new entry for a host.

Parameters:
infra,: infra structure with config parameters.
addr,: host address.
addrlen,: length of addr.
tm,: time now.
Returns:
: the new entry or NULL on malloc failure.

References infra_host_key::addr, infra_host_key::addrlen, lruhash_entry::data, infra_host_data::edns_lame_known, infra_host_data::edns_version, infra_host_key::entry, lruhash_entry::hash, hash_addr(), infra_cache::host_ttl, lruhash_entry::key, infra_host_data::lameness, lruhash_entry::lock, infra_host_data::rtt, rtt_init(), and infra_host_data::ttl.

Referenced by infra_edns_update(), infra_host(), infra_rtt_update(), and infra_set_lame().

int infra_host ( struct infra_cache infra,
struct sockaddr_storage *  addr,
socklen_t  addrlen,
uint32_t  timenow,
int *  edns_vs,
uint8_t *  edns_lame_known,
int *  to 
)

Find host information to send a packet.

Creates new entry if not found. Lameness is empty. EDNS is 0 (try with first), and rtt is returned for the first message to it.

Parameters:
infra,: infrastructure cache.
addr,: host address.
addrlen,: length of addr.
timenow,: what time it is now.
edns_vs,: edns version it supports, is returned.
edns_lame_known,: if EDNS lame (EDNS is dropped in transit) has already been probed, is returned.
to,: timeout to use, is returned.
Returns:
: 0 on error.

References lruhash_entry::data, infra_host_data::edns_lame_known, infra_host_data::edns_version, lruhash_entry::hash, infra_cache::host_ttl, infra_cache::hosts, infra_lookup_host_nottl(), lruhash_entry::lock, new_host_entry(), infra_host_data::rtt, rtt_init(), rtt_timeout(), slabhash_insert(), and infra_host_data::ttl.

Referenced by infra_test(), and serviced_udp_send().

int infra_lookup_lame ( struct infra_host_data host,
uint8_t *  name,
size_t  namelen,
uint32_t  timenow,
int *  dlame,
int *  rlame,
int *  alame,
int *  olame 
)

Check for lameness of this server for a particular zone.

You must have a lock on the host structure.

Parameters:
host,: infrastructure cache data for the host. Caller holds lock.
name,: domain name of zone apex.
namelen,: length of domain name.
timenow,: what time it is now.
dlame,: if the function returns true, is set true if dnssec lame.
rlame,: if the function returns true, is set true if recursion lame.
alame,: if the function returns true, is set true if qtype A lame.
olame,: if the function returns true, is set true if qtype other lame.
Returns:
: 0 if not lame or unknown or timed out, 1 if lame

References lruhash_entry::data, infra_lame_key::entry, lruhash_entry::hash, hash_lameness(), infra_lame_data::isdnsseclame, lruhash_entry::key, infra_lame_data::lame_other, infra_lame_data::lame_type_A, infra_host_data::lameness, lruhash_entry::lock, lruhash_lookup(), infra_lame_key::namelen, infra_lame_data::rec_lame, infra_lame_data::ttl, and infra_lame_key::zonename.

Referenced by infra_get_lame_rtt(), infra_set_lame(), and infra_test().

int infra_set_lame ( struct infra_cache infra,
struct sockaddr_storage *  addr,
socklen_t  addrlen,
uint8_t *  name,
size_t  namelen,
uint32_t  timenow,
int  dnsseclame,
int  reclame,
uint16_t  qtype 
)

Set a host to be lame for the given zone.

Parameters:
infra,: infrastructure cache.
addr,: host address.
addrlen,: length of addr.
name,: domain name of zone apex.
namelen,: length of domain name.
timenow,: what time it is now.
dnsseclame,: if true the host is set dnssec lame. if false, the host is marked lame (not serving the zone).
reclame,: if true host is a recursor not AA server. if false, dnsseclame or marked lame.
qtype,: the query type for which it is lame.
Returns:
: 0 on error.

References lruhash_entry::data, infra_lame_key::entry, lruhash_entry::hash, hash_lameness(), infra_cache::hosts, infra_lame_compfunc(), infra_lame_deldatafunc(), infra_lame_delkeyfunc(), infra_lame_sizefunc(), INFRA_LAME_STARTSIZE, infra_lookup_host_nottl(), infra_lookup_lame(), infra_lame_data::isdnsseclame, lruhash_entry::key, infra_lame_data::lame_other, infra_cache::lame_ttl, infra_lame_data::lame_type_A, infra_host_data::lameness, lruhash_entry::lock, log_err(), lruhash_create(), lruhash_insert(), infra_cache::max_lame_size, memdup(), infra_lame_key::namelen, new_host_entry(), infra_lame_data::rec_lame, slabhash_insert(), infra_lame_data::ttl, and infra_lame_key::zonename.

Referenced by infra_test(), and processQueryResponse().

void infra_update_tcp_works ( struct infra_cache infra,
struct sockaddr_storage *  addr,
socklen_t  addrlen 
)

Update information for the host, store that a TCP transaction works.

Parameters:
infra,: infrastructure cache.
addr,: host address.
addrlen,: length of addr.

References lruhash_entry::data, infra_lookup_host_nottl(), lruhash_entry::lock, rtt_info::rto, infra_host_data::rtt, and RTT_MAX_TIMEOUT.

Referenced by serviced_tcp_callback().

int infra_rtt_update ( struct infra_cache infra,
struct sockaddr_storage *  addr,
socklen_t  addrlen,
int  roundtrip,
int  orig_rtt,
uint32_t  timenow 
)

Update rtt information for the host.

Parameters:
infra,: infrastructure cache.
addr,: host address.
addrlen,: length of addr.
roundtrip,: estimate of roundtrip time in milliseconds or -1 for timeout.
orig_rtt,: original rtt for the query that timed out (roundtrip==-1). ignored if roundtrip != -1.
timenow,: what time it is now.
Returns:
: 0 on error. new rto otherwise.

References lruhash_entry::data, lruhash_entry::hash, infra_cache::host_ttl, infra_cache::hosts, infra_lookup_host_nottl(), lruhash_entry::lock, new_host_entry(), rtt_info::rto, infra_host_data::rtt, rtt_lost(), rtt_update(), slabhash_insert(), and infra_host_data::ttl.

Referenced by infra_test(), and serviced_udp_callback().

int infra_edns_update ( struct infra_cache infra,
struct sockaddr_storage *  addr,
socklen_t  addrlen,
int  edns_version,
uint32_t  timenow 
)

Update edns information for the host.

Parameters:
infra,: infrastructure cache.
addr,: host address.
addrlen,: length of addr.
edns_version,: the version that it publishes.
timenow,: what time it is now.
Returns:
: 0 on error.

References lruhash_entry::data, infra_host_data::edns_lame_known, infra_host_data::edns_version, lruhash_entry::hash, infra_cache::host_ttl, infra_cache::hosts, infra_lookup_host_nottl(), lruhash_entry::lock, new_host_entry(), slabhash_insert(), and infra_host_data::ttl.

Referenced by infra_test(), serviced_tcp_callback(), and serviced_udp_callback().

int infra_get_lame_rtt ( struct infra_cache infra,
struct sockaddr_storage *  addr,
socklen_t  addrlen,
uint8_t *  name,
size_t  namelen,
uint16_t  qtype,
int *  lame,
int *  dnsseclame,
int *  reclame,
int *  rtt,
uint32_t  timenow 
)

Get Lameness information and average RTT if host is in the cache.

Parameters:
infra,: infrastructure cache.
addr,: host address.
addrlen,: length of addr.
name,: zone name.
namelen,: zone name length.
qtype,: the query to be made.
lame,: if function returns true, this returns lameness of the zone.
dnsseclame,: if function returns true, this returns if the zone is dnssec-lame.
reclame,: if function returns true, this is if it is recursion lame.
rtt,: if function returns true, this returns avg rtt of the server. The rtt value is unclamped and reflects recent timeouts.
timenow,: what time it is now.
Returns:
if found in cache, or false if not (or TTL bad).

References lruhash_entry::data, infra_lookup_host_nottl(), infra_lookup_lame(), lruhash_entry::lock, infra_host_data::rtt, rtt_unclamped(), and infra_host_data::ttl.

Referenced by iter_filter_unsuitable().

size_t infra_get_mem ( struct infra_cache infra  ) 

Get memory used by the infra cache.

Parameters:
infra,: infrastructure cache.
Returns:
memory in use in bytes.

References lruhash::array, slabhash::array, count_host_lame(), infra_cache::hosts, lruhash_entry::lock, lruhash::lock, lruhash_entry::overflow_next, lruhash::size, slabhash::size, and slabhash_get_mem().

Referenced by worker_mem_report().


Generated on Tue Oct 13 06:45:50 2009 for unbound by  doxygen 1.5.9