Functions
val_kentry.c File Reference

This file contains functions for dealing with validator key entries. More...

#include "config.h"
#include "validator/val_kentry.h"
#include "util/data/packed_rrset.h"
#include "util/data/dname.h"
#include "util/storage/lookup3.h"
#include "util/regional.h"
#include "util/net_help.h"
#include "ldns/rrdef.h"
#include "ldns/keyraw.h"

Functions

size_t key_entry_sizefunc (void *key, void *data)
 function for lruhash operation
 
int key_entry_compfunc (void *k1, void *k2)
 function for lruhash operation
 
void key_entry_delkeyfunc (void *key, void *ATTR_UNUSED(userarg))
 
void key_entry_deldatafunc (void *data, void *ATTR_UNUSED(userarg))
 
void key_entry_hash (struct key_entry_key *kk)
 calculate hash for key entry More...
 
struct key_entry_keykey_entry_copy_toregion (struct key_entry_key *kkey, struct regional *region)
 Copy a key entry, to be region-allocated. More...
 
struct key_entry_keykey_entry_copy (struct key_entry_key *kkey)
 Copy a key entry, malloced. More...
 
int key_entry_isnull (struct key_entry_key *kkey)
 See if this is a null entry. More...
 
int key_entry_isgood (struct key_entry_key *kkey)
 See if this entry is good. More...
 
int key_entry_isbad (struct key_entry_key *kkey)
 See if this entry is bad. More...
 
void key_entry_set_reason (struct key_entry_key *kkey, char *reason)
 Set reason why a key is bad. More...
 
char * key_entry_get_reason (struct key_entry_key *kkey)
 Get reason why a key is bad. More...
 
static int key_entry_setup (struct regional *region, uint8_t *name, size_t namelen, uint16_t dclass, struct key_entry_key **k, struct key_entry_data **d)
 setup key entry in region
 
struct key_entry_keykey_entry_create_null (struct regional *region, uint8_t *name, size_t namelen, uint16_t dclass, time_t ttl, time_t now)
 Create a null entry, in the given region. More...
 
struct key_entry_keykey_entry_create_rrset (struct regional *region, uint8_t *name, size_t namelen, uint16_t dclass, struct ub_packed_rrset_key *rrset, uint8_t *sigalg, time_t now)
 Create a key entry from an rrset, in the given region. More...
 
struct key_entry_keykey_entry_create_bad (struct regional *region, uint8_t *name, size_t namelen, uint16_t dclass, time_t ttl, time_t now)
 Create a bad entry, in the given region. More...
 
struct ub_packed_rrset_keykey_entry_get_rrset (struct key_entry_key *kkey, struct regional *region)
 Obtain rrset from a key entry, allocated in region. More...
 
static size_t dnskey_get_keysize (struct packed_rrset_data *data, size_t idx)
 Get size of key in keyset.
 
static uint16_t kd_get_flags (struct packed_rrset_data *data, size_t idx)
 get dnskey flags from data
 
size_t key_entry_keysize (struct key_entry_key *kkey)
 Get keysize of the keyentry. More...
 

Detailed Description

This file contains functions for dealing with validator key entries.

Function Documentation

void key_entry_hash ( struct key_entry_key kk)

calculate hash for key entry

Parameters
kkkey entry. The lruhash entry.hash value is filled in.

References dname_query_hash(), key_entry_key::entry, lruhash_entry::hash, hashlittle(), key_entry_key::key_class, and key_entry_key::name.

Referenced by key_cache_insert(), key_cache_remove(), and key_cache_search().

struct key_entry_key* key_entry_copy_toregion ( struct key_entry_key kkey,
struct regional region 
)

Copy a key entry, to be region-allocated.

Parameters
kkeythe key entry key (and data pointer) to copy.
regionwhere to allocate it
Returns
newly region-allocated entry or NULL on a failure to allocate.

References key_entry_data::algo, lruhash_entry::data, key_entry_key::entry, lruhash_entry::key, key_entry_key::name, key_entry_key::namelen, packed_rrset_ptr_fixup(), packed_rrset_sizeof(), key_entry_data::reason, regional_alloc_init(), regional_strdup(), and key_entry_data::rrset_data.

Referenced by key_cache_obtain().

struct key_entry_key* key_entry_copy ( struct key_entry_key kkey)

Copy a key entry, malloced.

Parameters
kkeythe key entry key (and data pointer) to copy.
Returns
newly allocated entry or NULL on a failure to allocate memory.

References key_entry_data::algo, lruhash_entry::data, key_entry_key::entry, lruhash_entry::key, lruhash_entry::lock, memdup(), key_entry_key::name, key_entry_key::namelen, packed_rrset_ptr_fixup(), packed_rrset_sizeof(), key_entry_data::reason, and key_entry_data::rrset_data.

Referenced by key_cache_insert().

int key_entry_isnull ( struct key_entry_key kkey)

See if this is a null entry.

Does not do locking.

Parameters
kkeymust have data pointer set correctly
Returns
true if it is a NULL rrset entry.

References lruhash_entry::data, key_entry_key::entry, key_entry_data::isbad, and key_entry_data::rrset_data.

Referenced by iter_indicates_dnssec(), process_prime_response(), processFindKey(), processInit(), processValidate(), and val_dlv_init().

int key_entry_isgood ( struct key_entry_key kkey)
int key_entry_isbad ( struct key_entry_key kkey)

See if this entry is bad.

Does not do locking.

Parameters
kkeymust have data pointer set correctly
Returns
true if it is bad.

References lruhash_entry::data, key_entry_key::entry, and key_entry_data::isbad.

Referenced by iter_indicates_dnssec(), key_cache_insert(), process_dnskey_response(), process_ds_response(), process_prime_response(), processFindKey(), processInit(), and processValidate().

void key_entry_set_reason ( struct key_entry_key kkey,
char *  reason 
)

Set reason why a key is bad.

Parameters
kkeybad key.
reasonstring to attach, you must allocate it. Not safe to call twice unless you deallocate it yourself.

References lruhash_entry::data, key_entry_key::entry, and key_entry_data::reason.

Referenced by key_cache_insert().

char* key_entry_get_reason ( struct key_entry_key kkey)

Get reason why a key is bad.

Parameters
kkeybad key
Returns
pointer to string. String is part of key entry and is deleted with it.

References lruhash_entry::data, key_entry_key::entry, and key_entry_data::reason.

Referenced by processInit().

struct key_entry_key* key_entry_create_null ( struct regional region,
uint8_t *  name,
size_t  namelen,
uint16_t  dclass,
time_t  ttl,
time_t  now 
)

Create a null entry, in the given region.

Parameters
regionwhere to allocate
namethe key name
namelenlength of name
dclassclass of key entry. (host order);
ttlwhat ttl should the key have. relative.
nowcurrent time (added to ttl).
Returns
new key entry or NULL on alloc failure

References key_entry_data::algo, key_entry_data::isbad, key_entry_setup(), key_entry_data::reason, key_entry_data::rrset_data, key_entry_data::rrset_type, and key_entry_data::ttl.

Referenced by ds_response_to_ke(), primeResponseToKE(), processDLVLookup(), val_verify_new_DNSKEYs(), and val_verify_new_DNSKEYs_with_ta().

struct key_entry_key* key_entry_create_rrset ( struct regional region,
uint8_t *  name,
size_t  namelen,
uint16_t  dclass,
struct ub_packed_rrset_key rrset,
uint8_t *  sigalg,
time_t  now 
)

Create a key entry from an rrset, in the given region.

Parameters
regionwhere to allocate.
namethe key name
namelenlength of name
dclassclass of key entry. (host order);
rrsetdata for key entry. This is copied to the region.
sigalgsignalled algorithm list (or NULL).
nowcurrent time (added to ttl of rrset)
Returns
new key entry or NULL on alloc failure

References key_entry_data::algo, lruhash_entry::data, ub_packed_rrset_key::entry, key_entry_data::isbad, key_entry_setup(), packed_rrset_ptr_fixup(), packed_rrset_sizeof(), key_entry_data::reason, regional_alloc_init(), regional_strdup(), ub_packed_rrset_key::rk, key_entry_data::rrset_data, key_entry_data::rrset_type, key_entry_data::ttl, packed_rrset_data::ttl, and packed_rrset_key::type.

Referenced by ds_response_to_ke(), val_verify_new_DNSKEYs(), and val_verify_new_DNSKEYs_with_ta().

struct key_entry_key* key_entry_create_bad ( struct regional region,
uint8_t *  name,
size_t  namelen,
uint16_t  dclass,
time_t  ttl,
time_t  now 
)

Create a bad entry, in the given region.

Parameters
regionwhere to allocate
namethe key name
namelenlength of name
dclassclass of key entry. (host order);
ttlwhat ttl should the key have. relative.
nowcurrent time (added to ttl).
Returns
new key entry or NULL on alloc failure

References key_entry_data::algo, key_entry_data::isbad, key_entry_setup(), key_entry_data::reason, key_entry_data::rrset_data, key_entry_data::rrset_type, and key_entry_data::ttl.

Referenced by ds_response_to_ke(), primeResponseToKE(), process_dnskey_response(), val_verify_new_DNSKEYs(), and val_verify_new_DNSKEYs_with_ta().

struct ub_packed_rrset_key* key_entry_get_rrset ( struct key_entry_key kkey,
struct regional region 
)

Obtain rrset from a key entry, allocated in region.

Parameters
kkeykey entry to convert to a rrset.
regionwhere to allocate rrset
Returns
rrset copy; if no rrset or alloc error returns NULL.

References lruhash_entry::data, key_entry_key::entry, key_entry_key::key_class, key_entry_key::name, key_entry_key::namelen, packed_rrset_ptr_fixup(), packed_rrset_sizeof(), regional_alloc(), regional_alloc_init(), key_entry_data::rrset_data, and key_entry_data::rrset_type.

Referenced by process_ds_response().

size_t key_entry_keysize ( struct key_entry_key kkey)

Get keysize of the keyentry.

Parameters
kkeykey, must be a good key, with contents.
Returns
size in bits of the key.

References packed_rrset_data::count, lruhash_entry::data, DNSKEY_BIT_ZSK, dnskey_get_keysize(), key_entry_key::entry, kd_get_flags(), and key_entry_isgood().

Referenced by nsec3_iteration_count_high().