aboutsummaryrefslogtreecommitdiff
path: root/external/unbound/util/storage
diff options
context:
space:
mode:
Diffstat (limited to 'external/unbound/util/storage')
-rw-r--r--external/unbound/util/storage/dnstree.c39
-rw-r--r--external/unbound/util/storage/dnstree.h39
-rw-r--r--external/unbound/util/storage/lookup3.c10
-rw-r--r--external/unbound/util/storage/lruhash.c103
-rw-r--r--external/unbound/util/storage/lruhash.h80
-rw-r--r--external/unbound/util/storage/slabhash.c18
-rw-r--r--external/unbound/util/storage/slabhash.h16
7 files changed, 224 insertions, 81 deletions
diff --git a/external/unbound/util/storage/dnstree.c b/external/unbound/util/storage/dnstree.c
index 0df490ee5..190369d85 100644
--- a/external/unbound/util/storage/dnstree.c
+++ b/external/unbound/util/storage/dnstree.c
@@ -71,17 +71,17 @@ int addr_tree_compare(const void* k1, const void* k2)
return 0;
}
-void name_tree_init(rbtree_t* tree)
+void name_tree_init(rbtree_type* tree)
{
rbtree_init(tree, &name_tree_compare);
}
-void addr_tree_init(rbtree_t* tree)
+void addr_tree_init(rbtree_type* tree)
{
rbtree_init(tree, &addr_tree_compare);
}
-int name_tree_insert(rbtree_t* tree, struct name_tree_node* node,
+int name_tree_insert(rbtree_type* tree, struct name_tree_node* node,
uint8_t* name, size_t len, int labs, uint16_t dclass)
{
node->node.key = node;
@@ -93,7 +93,7 @@ int name_tree_insert(rbtree_t* tree, struct name_tree_node* node,
return rbtree_insert(tree, &node->node) != NULL;
}
-int addr_tree_insert(rbtree_t* tree, struct addr_tree_node* node,
+int addr_tree_insert(rbtree_type* tree, struct addr_tree_node* node,
struct sockaddr_storage* addr, socklen_t addrlen, int net)
{
node->node.key = node;
@@ -104,7 +104,7 @@ int addr_tree_insert(rbtree_t* tree, struct addr_tree_node* node,
return rbtree_insert(tree, &node->node) != NULL;
}
-void addr_tree_init_parents(rbtree_t* tree)
+void addr_tree_init_parents(rbtree_type* tree)
{
struct addr_tree_node* node, *prev = NULL, *p;
int m;
@@ -130,7 +130,7 @@ void addr_tree_init_parents(rbtree_t* tree)
}
}
-void name_tree_init_parents(rbtree_t* tree)
+void name_tree_init_parents(rbtree_type* tree)
{
struct name_tree_node* node, *prev = NULL, *p;
int m;
@@ -156,7 +156,7 @@ void name_tree_init_parents(rbtree_t* tree)
}
}
-struct name_tree_node* name_tree_find(rbtree_t* tree, uint8_t* name,
+struct name_tree_node* name_tree_find(rbtree_type* tree, uint8_t* name,
size_t len, int labs, uint16_t dclass)
{
struct name_tree_node key;
@@ -168,10 +168,10 @@ struct name_tree_node* name_tree_find(rbtree_t* tree, uint8_t* name,
return (struct name_tree_node*)rbtree_search(tree, &key);
}
-struct name_tree_node* name_tree_lookup(rbtree_t* tree, uint8_t* name,
+struct name_tree_node* name_tree_lookup(rbtree_type* tree, uint8_t* name,
size_t len, int labs, uint16_t dclass)
{
- rbnode_t* res = NULL;
+ rbnode_type* res = NULL;
struct name_tree_node *result;
struct name_tree_node key;
key.node.key = &key;
@@ -200,10 +200,10 @@ struct name_tree_node* name_tree_lookup(rbtree_t* tree, uint8_t* name,
return result;
}
-struct addr_tree_node* addr_tree_lookup(rbtree_t* tree,
+struct addr_tree_node* addr_tree_lookup(rbtree_type* tree,
struct sockaddr_storage* addr, socklen_t addrlen)
{
- rbnode_t* res = NULL;
+ rbnode_type* res = NULL;
struct addr_tree_node* result;
struct addr_tree_node key;
key.node.key = &key;
@@ -231,11 +231,24 @@ struct addr_tree_node* addr_tree_lookup(rbtree_t* tree,
return result;
}
+struct addr_tree_node* addr_tree_find(rbtree_type* tree,
+ struct sockaddr_storage* addr, socklen_t addrlen, int net)
+{
+ rbnode_type* res = NULL;
+ struct addr_tree_node key;
+ key.node.key = &key;
+ memcpy(&key.addr, addr, addrlen);
+ key.addrlen = addrlen;
+ key.net = net;
+ res = rbtree_search(tree, &key);
+ return (struct addr_tree_node*)res;
+}
+
int
-name_tree_next_root(rbtree_t* tree, uint16_t* dclass)
+name_tree_next_root(rbtree_type* tree, uint16_t* dclass)
{
struct name_tree_node key;
- rbnode_t* n;
+ rbnode_type* n;
struct name_tree_node* p;
if(*dclass == 0) {
/* first root item is first item in tree */
diff --git a/external/unbound/util/storage/dnstree.h b/external/unbound/util/storage/dnstree.h
index ec8189100..782644b63 100644
--- a/external/unbound/util/storage/dnstree.h
+++ b/external/unbound/util/storage/dnstree.h
@@ -49,12 +49,12 @@
* This is not sorted canonically, but fast.
* This can be looked up to obtain a closest encloser parent name.
*
- * The tree itself is a rbtree_t.
+ * The tree itself is a rbtree_type.
* This is the element node put as first entry in the client structure.
*/
struct name_tree_node {
/** rbtree node, key is this struct : dclass and name */
- rbnode_t node;
+ rbnode_type node;
/** parent in tree */
struct name_tree_node* parent;
/** name in uncompressed wireformat */
@@ -71,12 +71,12 @@ struct name_tree_node {
* Tree of IP addresses. Sorted first by protocol, then by bits.
* This can be looked up to obtain the enclosing subnet.
*
- * The tree itself is a rbtree_t.
+ * The tree itself is a rbtree_type.
* This is the element node put as first entry in the client structure.
*/
struct addr_tree_node {
/** rbtree node, key is this struct : proto and subnet */
- rbnode_t node;
+ rbnode_type node;
/** parent in tree */
struct addr_tree_node* parent;
/** address */
@@ -91,7 +91,7 @@ struct addr_tree_node {
* Init a name tree to be empty
* @param tree: to init.
*/
-void name_tree_init(rbtree_t* tree);
+void name_tree_init(rbtree_type* tree);
/**
* insert element into name tree.
@@ -105,7 +105,7 @@ void name_tree_init(rbtree_t* tree);
* @param dclass: class of name
* @return false on error (duplicate element).
*/
-int name_tree_insert(rbtree_t* tree, struct name_tree_node* node,
+int name_tree_insert(rbtree_type* tree, struct name_tree_node* node,
uint8_t* name, size_t len, int labs, uint16_t dclass);
/**
@@ -113,7 +113,7 @@ int name_tree_insert(rbtree_t* tree, struct name_tree_node* node,
* Should be performed after insertions are done, before lookups
* @param tree: name tree
*/
-void name_tree_init_parents(rbtree_t* tree);
+void name_tree_init_parents(rbtree_type* tree);
/**
* Lookup exact match in name tree
@@ -124,7 +124,7 @@ void name_tree_init_parents(rbtree_t* tree);
* @param dclass: class of name
* @return node or NULL if not found.
*/
-struct name_tree_node* name_tree_find(rbtree_t* tree, uint8_t* name,
+struct name_tree_node* name_tree_find(rbtree_type* tree, uint8_t* name,
size_t len, int labs, uint16_t dclass);
/**
@@ -136,7 +136,7 @@ struct name_tree_node* name_tree_find(rbtree_t* tree, uint8_t* name,
* @param dclass: class of name
* @return closest enclosing node (could be equal) or NULL if not found.
*/
-struct name_tree_node* name_tree_lookup(rbtree_t* tree, uint8_t* name,
+struct name_tree_node* name_tree_lookup(rbtree_type* tree, uint8_t* name,
size_t len, int labs, uint16_t dclass);
/**
@@ -145,13 +145,13 @@ struct name_tree_node* name_tree_lookup(rbtree_t* tree, uint8_t* name,
* @param dclass: the class to look for next (or higher).
* @return false if no classes found, true means class put into c.
*/
-int name_tree_next_root(rbtree_t* tree, uint16_t* dclass);
+int name_tree_next_root(rbtree_type* tree, uint16_t* dclass);
/**
* Init addr tree to be empty.
* @param tree: to init.
*/
-void addr_tree_init(rbtree_t* tree);
+void addr_tree_init(rbtree_type* tree);
/**
* insert element into addr tree.
@@ -163,7 +163,7 @@ void addr_tree_init(rbtree_t* tree);
* @param net: size of subnet.
* @return false on error (duplicate element).
*/
-int addr_tree_insert(rbtree_t* tree, struct addr_tree_node* node,
+int addr_tree_insert(rbtree_type* tree, struct addr_tree_node* node,
struct sockaddr_storage* addr, socklen_t addrlen, int net);
/**
@@ -171,7 +171,7 @@ int addr_tree_insert(rbtree_t* tree, struct addr_tree_node* node,
* Should be performed after insertions are done, before lookups
* @param tree: addr tree
*/
-void addr_tree_init_parents(rbtree_t* tree);
+void addr_tree_init_parents(rbtree_type* tree);
/**
* Lookup closest encloser in addr tree.
@@ -180,9 +180,20 @@ void addr_tree_init_parents(rbtree_t* tree);
* @param addrlen: length of addr
* @return closest enclosing node (could be equal) or NULL if not found.
*/
-struct addr_tree_node* addr_tree_lookup(rbtree_t* tree,
+struct addr_tree_node* addr_tree_lookup(rbtree_type* tree,
struct sockaddr_storage* addr, socklen_t addrlen);
+/**
+ * Find element in addr tree. (search a netblock, not a match for an address)
+ * @param tree: addr tree
+ * @param addr: netblock to lookup.
+ * @param addrlen: length of addr
+ * @param net: size of subnet
+ * @return addr tree element, or NULL if not found.
+ */
+struct addr_tree_node* addr_tree_find(rbtree_type* tree,
+ struct sockaddr_storage* addr, socklen_t addrlen, int net);
+
/** compare name tree nodes */
int name_tree_compare(const void* k1, const void* k2);
diff --git a/external/unbound/util/storage/lookup3.c b/external/unbound/util/storage/lookup3.c
index ddcb56e74..e9b05af37 100644
--- a/external/unbound/util/storage/lookup3.c
+++ b/external/unbound/util/storage/lookup3.c
@@ -820,7 +820,7 @@ uint32_t hashbig( const void *key, size_t length, uint32_t initval)
#ifdef SELF_TEST
/* used for timings */
-void driver1()
+void driver1(void)
{
uint8_t buf[256];
uint32_t i;
@@ -842,7 +842,7 @@ void driver1()
#define HASHLEN 1
#define MAXPAIR 60
#define MAXLEN 70
-void driver2()
+void driver2(void)
{
uint8_t qa[MAXLEN+1], qb[MAXLEN+2], *a = &qa[0], *b = &qb[1];
uint32_t c[HASHSTATE], d[HASHSTATE], i=0, j=0, k, l, m=0, z;
@@ -912,7 +912,7 @@ void driver2()
}
/* Check for reading beyond the end of the buffer and alignment problems */
-void driver3()
+void driver3(void)
{
uint8_t buf[MAXLEN+20], *b;
uint32_t len;
@@ -1003,7 +1003,7 @@ void driver3()
}
/* check for problems with nulls */
- void driver4()
+ void driver4(void)
{
uint8_t buf[1];
uint32_t h,i,state[HASHSTATE];
@@ -1020,7 +1020,7 @@ void driver3()
}
-int main()
+int main(void)
{
driver1(); /* test that the key is hashed: used for timings */
driver2(); /* test that whole key is hashed thoroughly */
diff --git a/external/unbound/util/storage/lruhash.c b/external/unbound/util/storage/lruhash.c
index 2c987a2e5..0003ff491 100644
--- a/external/unbound/util/storage/lruhash.c
+++ b/external/unbound/util/storage/lruhash.c
@@ -59,9 +59,10 @@ bin_init(struct lruhash_bin* array, size_t size)
}
struct lruhash*
-lruhash_create(size_t start_size, size_t maxmem, lruhash_sizefunc_t sizefunc,
- lruhash_compfunc_t compfunc, lruhash_delkeyfunc_t delkeyfunc,
- lruhash_deldatafunc_t deldatafunc, void* arg)
+lruhash_create(size_t start_size, size_t maxmem,
+ lruhash_sizefunc_type sizefunc, lruhash_compfunc_type compfunc,
+ lruhash_delkeyfunc_type delkeyfunc,
+ lruhash_deldatafunc_type deldatafunc, void* arg)
{
struct lruhash* table = (struct lruhash*)calloc(1,
sizeof(struct lruhash));
@@ -215,7 +216,7 @@ reclaim_space(struct lruhash* table, struct lruhash_entry** list)
struct lruhash_entry*
bin_find_entry(struct lruhash* table,
- struct lruhash_bin* bin, hashvalue_t hash, void* key)
+ struct lruhash_bin* bin, hashvalue_type hash, void* key)
{
struct lruhash_entry* p = bin->overflow_list;
while(p) {
@@ -296,7 +297,7 @@ lru_touch(struct lruhash* table, struct lruhash_entry* entry)
}
void
-lruhash_insert(struct lruhash* table, hashvalue_t hash,
+lruhash_insert(struct lruhash* table, hashvalue_type hash,
struct lruhash_entry* entry, void* data, void* cb_arg)
{
struct lruhash_bin* bin;
@@ -352,7 +353,7 @@ lruhash_insert(struct lruhash* table, hashvalue_t hash,
}
struct lruhash_entry*
-lruhash_lookup(struct lruhash* table, hashvalue_t hash, void* key, int wr)
+lruhash_lookup(struct lruhash* table, hashvalue_type hash, void* key, int wr)
{
struct lruhash_entry* entry;
struct lruhash_bin* bin;
@@ -374,7 +375,7 @@ lruhash_lookup(struct lruhash* table, hashvalue_t hash, void* key, int wr)
}
void
-lruhash_remove(struct lruhash* table, hashvalue_t hash, void* key)
+lruhash_remove(struct lruhash* table, hashvalue_type hash, void* key)
{
struct lruhash_entry* entry;
struct lruhash_bin* bin;
@@ -512,7 +513,7 @@ lruhash_get_mem(struct lruhash* table)
}
void
-lruhash_setmarkdel(struct lruhash* table, lruhash_markdelfunc_t md)
+lruhash_setmarkdel(struct lruhash* table, lruhash_markdelfunc_type md)
{
lock_quick_lock(&table->lock);
table->markdelfunc = md;
@@ -542,3 +543,89 @@ lruhash_traverse(struct lruhash* h, int wr,
}
lock_quick_unlock(&h->lock);
}
+
+/*
+ * Demote: the opposite of touch, move an entry to the bottom
+ * of the LRU pile.
+ */
+
+void
+lru_demote(struct lruhash* table, struct lruhash_entry* entry)
+{
+ log_assert(table && entry);
+ if (entry == table->lru_end)
+ return; /* nothing to do */
+ /* remove from current lru position */
+ lru_remove(table, entry);
+ /* add at end */
+ entry->lru_next = NULL;
+ entry->lru_prev = table->lru_end;
+
+ if (table->lru_end == NULL)
+ {
+ table->lru_start = entry;
+ }
+ else
+ {
+ table->lru_end->lru_next = entry;
+ }
+ table->lru_end = entry;
+}
+
+struct lruhash_entry*
+lruhash_insert_or_retrieve(struct lruhash* table, hashvalue_type hash,
+ struct lruhash_entry* entry, void* data, void* cb_arg)
+{
+ struct lruhash_bin* bin;
+ struct lruhash_entry* found, *reclaimlist = NULL;
+ size_t need_size;
+ fptr_ok(fptr_whitelist_hash_sizefunc(table->sizefunc));
+ fptr_ok(fptr_whitelist_hash_delkeyfunc(table->delkeyfunc));
+ fptr_ok(fptr_whitelist_hash_deldatafunc(table->deldatafunc));
+ fptr_ok(fptr_whitelist_hash_compfunc(table->compfunc));
+ fptr_ok(fptr_whitelist_hash_markdelfunc(table->markdelfunc));
+ need_size = table->sizefunc(entry->key, data);
+ if (cb_arg == NULL) cb_arg = table->cb_arg;
+
+ /* find bin */
+ lock_quick_lock(&table->lock);
+ bin = &table->array[hash & table->size_mask];
+ lock_quick_lock(&bin->lock);
+
+ /* see if entry exists already */
+ if ((found = bin_find_entry(table, bin, hash, entry->key)) != NULL) {
+ /* if so: keep the existing data - acquire a writelock */
+ lock_rw_wrlock(&found->lock);
+ }
+ else
+ {
+ /* if not: add to bin */
+ entry->overflow_next = bin->overflow_list;
+ bin->overflow_list = entry;
+ lru_front(table, entry);
+ table->num++;
+ table->space_used += need_size;
+ /* return the entry that was presented, and lock it */
+ found = entry;
+ lock_rw_wrlock(&found->lock);
+ }
+ lock_quick_unlock(&bin->lock);
+ if (table->space_used > table->space_max)
+ reclaim_space(table, &reclaimlist);
+ if (table->num >= table->size)
+ table_grow(table);
+ lock_quick_unlock(&table->lock);
+
+ /* finish reclaim if any (outside of critical region) */
+ while (reclaimlist) {
+ struct lruhash_entry* n = reclaimlist->overflow_next;
+ void* d = reclaimlist->data;
+ (*table->delkeyfunc)(reclaimlist->key, cb_arg);
+ (*table->deldatafunc)(d, cb_arg);
+ reclaimlist = n;
+ }
+
+ /* return the entry that was selected */
+ return found;
+}
+
diff --git a/external/unbound/util/storage/lruhash.h b/external/unbound/util/storage/lruhash.h
index 30377d8e7..4759b5001 100644
--- a/external/unbound/util/storage/lruhash.h
+++ b/external/unbound/util/storage/lruhash.h
@@ -116,7 +116,7 @@ struct lruhash_entry;
#define HASH_DEFAULT_MAXMEM 4*1024*1024 /* bytes */
/** the type of a hash value */
-typedef uint32_t hashvalue_t;
+typedef uint32_t hashvalue_type;
/**
* Type of function that calculates the size of an entry.
@@ -124,39 +124,39 @@ typedef uint32_t hashvalue_t;
* Keys that are identical must also calculate to the same size.
* size = func(key, data).
*/
-typedef size_t (*lruhash_sizefunc_t)(void*, void*);
+typedef size_t (*lruhash_sizefunc_type)(void*, void*);
/** type of function that compares two keys. return 0 if equal. */
-typedef int (*lruhash_compfunc_t)(void*, void*);
+typedef int (*lruhash_compfunc_type)(void*, void*);
/** old keys are deleted.
* The RRset type has to revoke its ID number, markdel() is used first.
* This function is called: func(key, userarg) */
-typedef void (*lruhash_delkeyfunc_t)(void*, void*);
+typedef void (*lruhash_delkeyfunc_type)(void*, void*);
/** old data is deleted. This function is called: func(data, userarg). */
-typedef void (*lruhash_deldatafunc_t)(void*, void*);
+typedef void (*lruhash_deldatafunc_type)(void*, void*);
/** mark a key as pending to be deleted (and not to be used by anyone).
* called: func(key) */
-typedef void (*lruhash_markdelfunc_t)(void*);
+typedef void (*lruhash_markdelfunc_type)(void*);
/**
* Hash table that keeps LRU list of entries.
*/
struct lruhash {
/** lock for exclusive access, to the lookup array */
- lock_quick_t lock;
+ lock_quick_type lock;
/** the size function for entries in this table */
- lruhash_sizefunc_t sizefunc;
+ lruhash_sizefunc_type sizefunc;
/** the compare function for entries in this table. */
- lruhash_compfunc_t compfunc;
+ lruhash_compfunc_type compfunc;
/** how to delete keys. */
- lruhash_delkeyfunc_t delkeyfunc;
+ lruhash_delkeyfunc_type delkeyfunc;
/** how to delete data. */
- lruhash_deldatafunc_t deldatafunc;
+ lruhash_deldatafunc_type deldatafunc;
/** how to mark a key pending deletion */
- lruhash_markdelfunc_t markdelfunc;
+ lruhash_markdelfunc_type markdelfunc;
/** user argument for user functions */
void* cb_arg;
@@ -188,7 +188,7 @@ struct lruhash_bin {
* Lock for exclusive access to the linked list
* This lock makes deletion of items safe in this overflow list.
*/
- lock_quick_t lock;
+ lock_quick_type lock;
/** linked list of overflow entries */
struct lruhash_entry* overflow_list;
};
@@ -207,7 +207,7 @@ struct lruhash_entry {
* Even with a writelock, you cannot change hash and key.
* You need to delete it to change hash or key.
*/
- lock_rw_t lock;
+ lock_rw_type lock;
/** next entry in overflow chain. Covered by hashlock and binlock. */
struct lruhash_entry* overflow_next;
/** next entry in lru chain. covered by hashlock. */
@@ -215,7 +215,7 @@ struct lruhash_entry {
/** prev entry in lru chain. covered by hashlock. */
struct lruhash_entry* lru_prev;
/** hash value of the key. It may not change, until entry deleted. */
- hashvalue_t hash;
+ hashvalue_type hash;
/** key */
void* key;
/** data */
@@ -236,9 +236,9 @@ struct lruhash_entry {
* @return: new hash table or NULL on malloc failure.
*/
struct lruhash* lruhash_create(size_t start_size, size_t maxmem,
- lruhash_sizefunc_t sizefunc, lruhash_compfunc_t compfunc,
- lruhash_delkeyfunc_t delkeyfunc, lruhash_deldatafunc_t deldatafunc,
- void* arg);
+ lruhash_sizefunc_type sizefunc, lruhash_compfunc_type compfunc,
+ lruhash_delkeyfunc_type delkeyfunc,
+ lruhash_deldatafunc_type deldatafunc, void* arg);
/**
* Delete hash table. Entries are all deleted.
@@ -269,7 +269,7 @@ void lruhash_clear(struct lruhash* table);
* @param data: the data.
* @param cb_override: if not null overrides the cb_arg for the deletefunc.
*/
-void lruhash_insert(struct lruhash* table, hashvalue_t hash,
+void lruhash_insert(struct lruhash* table, hashvalue_type hash,
struct lruhash_entry* entry, void* data, void* cb_override);
/**
@@ -285,8 +285,8 @@ void lruhash_insert(struct lruhash* table, hashvalue_t hash,
* @return: pointer to the entry or NULL. The entry is locked.
* The user must unlock the entry when done.
*/
-struct lruhash_entry* lruhash_lookup(struct lruhash* table, hashvalue_t hash,
- void* key, int wr);
+struct lruhash_entry* lruhash_lookup(struct lruhash* table,
+ hashvalue_type hash, void* key, int wr);
/**
* Touch entry, so it becomes the most recently used in the LRU list.
@@ -299,7 +299,39 @@ void lru_touch(struct lruhash* table, struct lruhash_entry* entry);
/**
* Set the markdelfunction (or NULL)
*/
-void lruhash_setmarkdel(struct lruhash* table, lruhash_markdelfunc_t md);
+void lruhash_setmarkdel(struct lruhash* table, lruhash_markdelfunc_type md);
+
+/************************* getdns functions ************************/
+/*** these are used by getdns only and not by unbound. ***/
+
+/**
+ * Demote entry, so it becomes the least recently used in the LRU list.
+ * Caller must hold hash table lock. The entry must be inserted already.
+ * @param table: hash table.
+ * @param entry: entry to make last in LRU.
+ */
+void lru_demote(struct lruhash* table, struct lruhash_entry* entry);
+
+/**
+ * Insert a new element into the hashtable, or retrieve the corresponding
+ * element of it exits.
+ *
+ * If key is already present data pointer in that entry is kept.
+ * If it is not present, a new entry is created. In that case,
+ * the space calculation function is called with the key, data.
+ * If necessary the least recently used entries are deleted to make space.
+ * If necessary the hash array is grown up.
+ *
+ * @param table: hash table.
+ * @param hash: hash value. User calculates the hash.
+ * @param entry: identifies the entry.
+ * @param data: the data.
+ * @param cb_arg: if not null overrides the cb_arg for the deletefunc.
+ * @return: pointer to the existing entry if the key was already present,
+ * or to the entry argument if it was not.
+ */
+struct lruhash_entry* lruhash_insert_or_retrieve(struct lruhash* table, hashvalue_type hash,
+ struct lruhash_entry* entry, void* data, void* cb_arg);
/************************* Internal functions ************************/
/*** these are only exposed for unit tests. ***/
@@ -311,7 +343,7 @@ void lruhash_setmarkdel(struct lruhash* table, lruhash_markdelfunc_t md);
* @param hash: hash of key.
* @param key: what to look for.
*/
-void lruhash_remove(struct lruhash* table, hashvalue_t hash, void* key);
+void lruhash_remove(struct lruhash* table, hashvalue_type hash, void* key);
/** init the hash bins for the table */
void bin_init(struct lruhash_bin* array, size_t size);
@@ -328,7 +360,7 @@ void bin_delete(struct lruhash* table, struct lruhash_bin* bin);
* @return: the entry or NULL if not found.
*/
struct lruhash_entry* bin_find_entry(struct lruhash* table,
- struct lruhash_bin* bin, hashvalue_t hash, void* key);
+ struct lruhash_bin* bin, hashvalue_type hash, void* key);
/**
* Remove entry from bin overflow chain.
diff --git a/external/unbound/util/storage/slabhash.c b/external/unbound/util/storage/slabhash.c
index 0618b4c72..ae63b9772 100644
--- a/external/unbound/util/storage/slabhash.c
+++ b/external/unbound/util/storage/slabhash.c
@@ -46,9 +46,9 @@
#include "util/storage/slabhash.h"
struct slabhash* slabhash_create(size_t numtables, size_t start_size,
- size_t maxmem, lruhash_sizefunc_t sizefunc,
- lruhash_compfunc_t compfunc, lruhash_delkeyfunc_t delkeyfunc,
- lruhash_deldatafunc_t deldatafunc, void* arg)
+ size_t maxmem, lruhash_sizefunc_type sizefunc,
+ lruhash_compfunc_type compfunc, lruhash_delkeyfunc_type delkeyfunc,
+ lruhash_deldatafunc_type deldatafunc, void* arg)
{
size_t i;
struct slabhash* sl = (struct slabhash*)calloc(1,
@@ -108,24 +108,24 @@ void slabhash_clear(struct slabhash* sl)
/** helper routine to calculate the slabhash index */
static unsigned int
-slab_idx(struct slabhash* sl, hashvalue_t hash)
+slab_idx(struct slabhash* sl, hashvalue_type hash)
{
return ((hash & sl->mask) >> sl->shift);
}
-void slabhash_insert(struct slabhash* sl, hashvalue_t hash,
+void slabhash_insert(struct slabhash* sl, hashvalue_type hash,
struct lruhash_entry* entry, void* data, void* arg)
{
lruhash_insert(sl->array[slab_idx(sl, hash)], hash, entry, data, arg);
}
struct lruhash_entry* slabhash_lookup(struct slabhash* sl,
- hashvalue_t hash, void* key, int wr)
+ hashvalue_type hash, void* key, int wr)
{
return lruhash_lookup(sl->array[slab_idx(sl, hash)], hash, key, wr);
}
-void slabhash_remove(struct slabhash* sl, hashvalue_t hash, void* key)
+void slabhash_remove(struct slabhash* sl, hashvalue_type hash, void* key)
{
lruhash_remove(sl->array[slab_idx(sl, hash)], hash, key);
}
@@ -163,7 +163,7 @@ size_t slabhash_get_mem(struct slabhash* sl)
return total;
}
-struct lruhash* slabhash_gettable(struct slabhash* sl, hashvalue_t hash)
+struct lruhash* slabhash_gettable(struct slabhash* sl, hashvalue_type hash)
{
return sl->array[slab_idx(sl, hash)];
}
@@ -202,7 +202,7 @@ void test_slabhash_deldata(void* data, void* ATTR_UNUSED(arg))
deldata((struct slabhash_testdata*)data);
}
-void slabhash_setmarkdel(struct slabhash* sl, lruhash_markdelfunc_t md)
+void slabhash_setmarkdel(struct slabhash* sl, lruhash_markdelfunc_type md)
{
size_t i;
for(i=0; i<sl->size; i++) {
diff --git a/external/unbound/util/storage/slabhash.h b/external/unbound/util/storage/slabhash.h
index 031a9da0f..d00983fc1 100644
--- a/external/unbound/util/storage/slabhash.h
+++ b/external/unbound/util/storage/slabhash.h
@@ -80,9 +80,9 @@ struct slabhash {
* @return: new hash table or NULL on malloc failure.
*/
struct slabhash* slabhash_create(size_t numtables, size_t start_size,
- size_t maxmem, lruhash_sizefunc_t sizefunc,
- lruhash_compfunc_t compfunc, lruhash_delkeyfunc_t delkeyfunc,
- lruhash_deldatafunc_t deldatafunc, void* arg);
+ size_t maxmem, lruhash_sizefunc_type sizefunc,
+ lruhash_compfunc_type compfunc, lruhash_delkeyfunc_type delkeyfunc,
+ lruhash_deldatafunc_type deldatafunc, void* arg);
/**
* Delete hash table. Entries are all deleted.
@@ -109,7 +109,7 @@ void slabhash_clear(struct slabhash* table);
* @param data: the data.
* @param cb_override: if not NULL overrides the cb_arg for deletfunc.
*/
-void slabhash_insert(struct slabhash* table, hashvalue_t hash,
+void slabhash_insert(struct slabhash* table, hashvalue_type hash,
struct lruhash_entry* entry, void* data, void* cb_override);
/**
@@ -126,7 +126,7 @@ void slabhash_insert(struct slabhash* table, hashvalue_t hash,
* The user must unlock the entry when done.
*/
struct lruhash_entry* slabhash_lookup(struct slabhash* table,
- hashvalue_t hash, void* key, int wr);
+ hashvalue_type hash, void* key, int wr);
/**
* Remove entry from hashtable. Does nothing if not found in hashtable.
@@ -135,7 +135,7 @@ struct lruhash_entry* slabhash_lookup(struct slabhash* table,
* @param hash: hash of key.
* @param key: what to look for.
*/
-void slabhash_remove(struct slabhash* table, hashvalue_t hash, void* key);
+void slabhash_remove(struct slabhash* table, hashvalue_type hash, void* key);
/**
* Output debug info to the log as to state of the hash table.
@@ -165,14 +165,14 @@ size_t slabhash_get_mem(struct slabhash* table);
* @param hash: hash value.
* @return the lru hash table.
*/
-struct lruhash* slabhash_gettable(struct slabhash* table, hashvalue_t hash);
+struct lruhash* slabhash_gettable(struct slabhash* table, hashvalue_type hash);
/**
* Set markdel function
* @param table: slabbed hash table.
* @param md: markdel function ptr.
*/
-void slabhash_setmarkdel(struct slabhash* table, lruhash_markdelfunc_t md);
+void slabhash_setmarkdel(struct slabhash* table, lruhash_markdelfunc_type md);
/**
* Traverse a slabhash.