mirror of
https://git.proxmox.com/git/mirror_frr
synced 2025-08-07 09:15:34 +00:00
lib/table: remove odd casts
Working with a proper struct route_node gets us around a bunch of weird casts here and makes the code slightly more robust. Signed-off-by: David Lamparter <equinox@diac24.net>
This commit is contained in:
parent
d0a0e597c8
commit
0734f93b8e
36
lib/table.c
36
lib/table.c
@ -33,10 +33,10 @@ DEFINE_MTYPE(LIB, ROUTE_NODE, "Route node")
|
|||||||
|
|
||||||
static void route_table_free(struct route_table *);
|
static void route_table_free(struct route_table *);
|
||||||
|
|
||||||
static int route_table_hash_cmp(const void *a, const void *b)
|
static int route_table_hash_cmp(const struct route_node *a,
|
||||||
|
const struct route_node *b)
|
||||||
{
|
{
|
||||||
const struct prefix *pa = a, *pb = b;
|
return prefix_cmp(&a->p, &b->p);
|
||||||
return prefix_cmp(pa, pb);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
DECLARE_HASH(rn_hash_node, struct route_node, nodehash, route_table_hash_cmp,
|
DECLARE_HASH(rn_hash_node, struct route_node, nodehash, route_table_hash_cmp,
|
||||||
@ -244,19 +244,18 @@ struct route_node *route_node_match_ipv6(const struct route_table *table,
|
|||||||
p.prefixlen = IPV6_MAX_PREFIXLEN;
|
p.prefixlen = IPV6_MAX_PREFIXLEN;
|
||||||
p.prefix = *addr;
|
p.prefix = *addr;
|
||||||
|
|
||||||
return route_node_match(table, (struct prefix *)&p);
|
return route_node_match(table, &p);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Lookup same prefix node. Return NULL when we can't find route. */
|
/* Lookup same prefix node. Return NULL when we can't find route. */
|
||||||
struct route_node *route_node_lookup(const struct route_table *table,
|
struct route_node *route_node_lookup(const struct route_table *table,
|
||||||
union prefixconstptr pu)
|
union prefixconstptr pu)
|
||||||
{
|
{
|
||||||
struct prefix p;
|
struct route_node rn, *node;
|
||||||
struct route_node *node;
|
prefix_copy(&rn.p, pu.p);
|
||||||
prefix_copy(&p, pu.p);
|
apply_mask(&rn.p);
|
||||||
apply_mask(&p);
|
|
||||||
|
|
||||||
node = rn_hash_node_find(&table->hash, (void *)&p);
|
node = rn_hash_node_find(&table->hash, &rn);
|
||||||
return (node && node->info) ? route_lock_node(node) : NULL;
|
return (node && node->info) ? route_lock_node(node) : NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -264,12 +263,11 @@ struct route_node *route_node_lookup(const struct route_table *table,
|
|||||||
struct route_node *route_node_lookup_maynull(const struct route_table *table,
|
struct route_node *route_node_lookup_maynull(const struct route_table *table,
|
||||||
union prefixconstptr pu)
|
union prefixconstptr pu)
|
||||||
{
|
{
|
||||||
struct prefix p;
|
struct route_node rn, *node;
|
||||||
struct route_node *node;
|
prefix_copy(&rn.p, pu.p);
|
||||||
prefix_copy(&p, pu.p);
|
apply_mask(&rn.p);
|
||||||
apply_mask(&p);
|
|
||||||
|
|
||||||
node = rn_hash_node_find(&table->hash, (void *)&p);
|
node = rn_hash_node_find(&table->hash, &rn);
|
||||||
return node ? route_lock_node(node) : NULL;
|
return node ? route_lock_node(node) : NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -277,15 +275,19 @@ struct route_node *route_node_lookup_maynull(const struct route_table *table,
|
|||||||
struct route_node *route_node_get(struct route_table *const table,
|
struct route_node *route_node_get(struct route_table *const table,
|
||||||
union prefixconstptr pu)
|
union prefixconstptr pu)
|
||||||
{
|
{
|
||||||
const struct prefix *p = pu.p;
|
struct route_node search;
|
||||||
|
struct prefix *p = &search.p;
|
||||||
|
|
||||||
|
prefix_copy(p, pu.p);
|
||||||
|
apply_mask(p);
|
||||||
|
|
||||||
struct route_node *new;
|
struct route_node *new;
|
||||||
struct route_node *node;
|
struct route_node *node;
|
||||||
struct route_node *match;
|
struct route_node *match;
|
||||||
uint16_t prefixlen = p->prefixlen;
|
uint16_t prefixlen = p->prefixlen;
|
||||||
const uint8_t *prefix = &p->u.prefix;
|
const uint8_t *prefix = &p->u.prefix;
|
||||||
|
|
||||||
apply_mask((struct prefix *)p);
|
node = rn_hash_node_find(&table->hash, &search);
|
||||||
node = rn_hash_node_find(&table->hash, (void *)p);
|
|
||||||
if (node && node->info)
|
if (node && node->info)
|
||||||
return route_lock_node(node);
|
return route_lock_node(node);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user