summaryrefslogtreecommitdiff
path: root/lib/table.c
diff options
context:
space:
mode:
authorLou Berger <lberger@labn.net>2019-05-02 06:54:59 -0400
committerGitHub <noreply@github.com>2019-05-02 06:54:59 -0400
commite8b9ad5cdda832ea5ff8dbe21f6078fe15badd33 (patch)
tree8b5978d6155cbb1cb9d2877e165bf9b60f261303 /lib/table.c
parenteefbfd1d276d3c31ac87256785f463b840c55797 (diff)
Revert "Zebra diet"
Diffstat (limited to 'lib/table.c')
-rw-r--r--lib/table.c31
1 files changed, 17 insertions, 14 deletions
diff --git a/lib/table.c b/lib/table.c
index 2d42e2d55c..edba7f1932 100644
--- a/lib/table.c
+++ b/lib/table.c
@@ -33,14 +33,12 @@ DEFINE_MTYPE(LIB, ROUTE_NODE, "Route node")
static void route_table_free(struct route_table *);
-static int route_table_hash_cmp(const void *a, const void *b)
+static bool route_table_hash_cmp(const void *a, const void *b)
{
const struct prefix *pa = a, *pb = b;
- return prefix_cmp(pa, pb);
+ return prefix_cmp(pa, pb) == 0;
}
-DECLARE_HASH(rn_hash_node, struct route_node, nodehash, route_table_hash_cmp,
- prefix_hash_key)
/*
* route_table_init_with_delegate
*/
@@ -51,7 +49,8 @@ route_table_init_with_delegate(route_table_delegate_t *delegate)
rt = XCALLOC(MTYPE_ROUTE_TABLE, sizeof(struct route_table));
rt->delegate = delegate;
- rn_hash_node_init(&rt->hash);
+ rt->hash = hash_create(prefix_hash_key, route_table_hash_cmp,
+ "route table hash");
return rt;
}
@@ -70,14 +69,15 @@ static struct route_node *route_node_new(struct route_table *table)
static struct route_node *route_node_set(struct route_table *table,
const struct prefix *prefix)
{
- struct route_node *node;
+ struct route_node *node, *inserted;
node = route_node_new(table);
prefix_copy(&node->p, prefix);
node->table = table;
- rn_hash_node_add(&node->table->hash, node);
+ inserted = hash_get(node->table->hash, node, hash_alloc_intern);
+ assert(inserted == node);
return node;
}
@@ -99,6 +99,9 @@ static void route_table_free(struct route_table *rt)
if (rt == NULL)
return;
+ hash_clean(rt->hash, NULL);
+ hash_free(rt->hash);
+
node = rt->top;
/* Bulk deletion of nodes remaining in this table. This function is not
@@ -120,7 +123,6 @@ static void route_table_free(struct route_table *rt)
tmp_node->table->count--;
tmp_node->lock = 0; /* to cause assert if unlocked after this */
- rn_hash_node_del(&rt->hash, tmp_node);
route_node_free(rt, tmp_node);
if (node != NULL) {
@@ -135,7 +137,6 @@ static void route_table_free(struct route_table *rt)
assert(rt->count == 0);
- rn_hash_node_fini(&rt->hash);
XFREE(MTYPE_ROUTE_TABLE, rt);
return;
}
@@ -256,7 +257,7 @@ struct route_node *route_node_lookup(const struct route_table *table,
prefix_copy(&p, pu.p);
apply_mask(&p);
- node = rn_hash_node_find(&table->hash, (void *)&p);
+ node = hash_get(table->hash, (void *)&p, NULL);
return (node && node->info) ? route_lock_node(node) : NULL;
}
@@ -269,7 +270,7 @@ struct route_node *route_node_lookup_maynull(const struct route_table *table,
prefix_copy(&p, pu.p);
apply_mask(&p);
- node = rn_hash_node_find(&table->hash, (void *)&p);
+ node = hash_get(table->hash, (void *)&p, NULL);
return node ? route_lock_node(node) : NULL;
}
@@ -281,11 +282,12 @@ struct route_node *route_node_get(struct route_table *const table,
struct route_node *new;
struct route_node *node;
struct route_node *match;
+ struct route_node *inserted;
uint16_t prefixlen = p->prefixlen;
const uint8_t *prefix = &p->u.prefix;
apply_mask((struct prefix *)p);
- node = rn_hash_node_find(&table->hash, (void *)p);
+ node = hash_get(table->hash, (void *)p, NULL);
if (node && node->info)
return route_lock_node(node);
@@ -312,7 +314,8 @@ struct route_node *route_node_get(struct route_table *const table,
new->p.family = p->family;
new->table = table;
set_link(new, node);
- rn_hash_node_add(&table->hash, new);
+ inserted = hash_get(node->table->hash, new, hash_alloc_intern);
+ assert(inserted == new);
if (match)
set_link(match, new);
@@ -364,7 +367,7 @@ void route_node_delete(struct route_node *node)
node->table->count--;
- rn_hash_node_del(&node->table->hash, node);
+ hash_release(node->table->hash, node);
/* WARNING: FRAGILE CODE!
* route_node_free may have the side effect of free'ing the entire