unbound: validator/val_kcache.c File Reference

unbound 0.1

Functions
val_kcache.c File Reference

This file contains functions for dealing with the validator key cache. More...

`#include "config.h"`
`#include "validator/val_kcache.h"`
`#include "validator/val_kentry.h"`
`#include "util/log.h"`
`#include "util/config_file.h"`
`#include "util/data/dname.h"`
`#include "util/module.h"`

## Functions
struct key_cache * | key_cache_create (struct config_file *cfg)
| Create the key cache.
void | key_cache_delete (struct key_cache *kcache)
| Delete the key cache.
void | key_cache_insert (struct key_cache *kcache, struct key_entry_key *kkey, int copy_reason)
| Insert or update a key cache entry.
static struct key_entry_key * | key_cache_search (struct key_cache *kcache, uint8_t *name, size_t namelen, uint16_t key_class, int wr)
| Lookup exactly in the key cache.
struct key_entry_key * | key_cache_obtain (struct key_cache *kcache, uint8_t *name, size_t namelen, uint16_t key_class, struct regional *region, time_t now)
| Lookup key entry in the cache.
size_t | key_cache_get_mem (struct key_cache *kcache)
| Get memory in use by the key cache.
void | key_cache_remove (struct key_cache *kcache, uint8_t *name, size_t namelen, uint16_t key_class)
| Remove an entry from the key cache.

## Detailed Description

This file contains functions for dealing with the validator key cache.

## Function Documentation

## ◆ key_cache_create()

struct key_cache * key_cache_create | ( | struct config_file * | cfg | ) |

Create the key cache.

Parameters

  cfg | config settings for the key cache.

Returns
  new key cache or NULL on malloc failure.

References HASH_DEFAULT_STARTARRAY, config_file::key_cache_size, config_file::key_cache_slabs, key_entry_compfunc(), key_entry_sizefunc(), log_err(), key_cache::slab, and slabhash_create().

Referenced by val_apply_cfg().

## ◆ key_cache_delete()

void key_cache_delete | ( | struct key_cache * | kcache | ) |

Delete the key cache.

Parameters

  kcache | to delete

References key_cache::slab, and slabhash_delete().

Referenced by val_deinit().

## ◆ key_cache_insert()

void key_cache_insert | ( | struct key_cache * | kcache,
|  | struct key_entry_key * | kkey,
|  | int | copy_reason )

Insert or update a key cache entry.

Note that the insert may silently fail if there is not enough memory.

Parameters

  kcache | the key cache.
  kkey | key entry key, assumed malloced in a region, is copied to perform update or insertion. Its data pointer is also copied.
  copy_reason | if the reason string needs to be copied (allocated).

References lruhash_entry::data, key_entry_key::entry, lruhash_entry::hash, key_entry_copy(), key_entry_hash(), key_cache::slab, and slabhash_insert().

Referenced by process_dnskey_response(), process_prime_response(), and processValidate().

## ◆ key_cache_search()

static struct key_entry_key * key_cache_search | ( | struct key_cache * | kcache,
|  | uint8_t * | name,
|  | size_t | namelen,
|  | uint16_t | key_class,
|  | int | wr )
| static

Lookup exactly in the key cache.

Returns pointer to locked entry. Caller must unlock it after use.

Parameters

  kcache | the key cache.
  name | for what name to look; uncompressed wireformat
  namelen | length of the name.
  key_class | class of the key.
  wr | set true to get a writelock.

Returns
  key entry, locked, or NULL if not found. No TTL checking is performed.

References key_entry_key::entry, lruhash_entry::hash, lruhash_entry::key, key_entry_key::key_class, key_entry_hash(), key_entry_key::name, key_entry_key::namelen, key_cache::slab, and slabhash_lookup().

Referenced by key_cache_obtain().

## ◆ key_cache_obtain()

struct key_entry_key * key_cache_obtain | ( | struct key_cache * | kcache,
|  | uint8_t * | name,
|  | size_t | namelen,
|  | uint16_t | key_class,
|  | struct regional * | region,
|  | time_t | now )

Lookup key entry in the cache.

Looks up the closest key entry above the given name.

Parameters

  kcache | the key cache.
  name | for what name to look; uncompressed wireformat
  namelen | length of the name.
  key_class | class of the key.
  region | a copy of the key_entry is allocated in this region.
  now | current time.

Returns
  pointer to a newly allocated key_entry copy in the region, if a key entry could be found, and allocation succeeded and TTL was OK. Otherwise, NULL is returned.

References lruhash_entry::data, dname_is_root(), dname_remove_label(), key_entry_key::entry, key_cache_search(), key_entry_key::key_class, key_entry_copy_toregion(), lruhash_entry::lock, key_entry_key::name, key_entry_key::namelen, and key_entry_data::ttl.

Referenced by iter_indicates_dnssec(), and processInit().

## ◆ key_cache_get_mem()

size_t key_cache_get_mem | ( | struct key_cache * | kcache | ) |

Get memory in use by the key cache.

Parameters

  kcache | the key cache.

Returns
  memory in use in bytes.

References key_cache::slab, and slabhash_get_mem().

Referenced by val_get_mem().

## ◆ key_cache_remove()

void key_cache_remove | ( | struct key_cache * | kcache,
|  | uint8_t * | name,
|  | size_t | namelen,
|  | uint16_t | key_class )

Remove an entry from the key cache.

Parameters

  kcache | the key cache.
  name | for what name to look; uncompressed wireformat
  namelen | length of the name.
  key_class | class of the key.

References key_entry_key::entry, lruhash_entry::hash, lruhash_entry::key, key_entry_key::key_class, key_entry_hash(), key_entry_key::name, key_entry_key::namelen, key_cache::slab, and slabhash_remove().

Referenced by probe_anchor().