mirror of
https://git.proxmox.com/git/mirror_frr
synced 2025-08-02 18:52:04 +00:00
lib: move prefix hash key to prefix.c to allow global use
Signed-off-by: Christian Franke <chris@opensourcerouting.org>
This commit is contained in:
parent
02cd317ea0
commit
7a7761d21c
13
lib/prefix.c
13
lib/prefix.c
@ -26,6 +26,7 @@
|
||||
#include "sockunion.h"
|
||||
#include "memory.h"
|
||||
#include "log.h"
|
||||
#include "jhash.h"
|
||||
|
||||
DEFINE_MTYPE_STATIC(LIB, PREFIX, "Prefix")
|
||||
|
||||
@ -1335,3 +1336,15 @@ char *prefix_mac2str(const struct ethaddr *mac, char *buf, int size)
|
||||
(uint8_t)mac->octet[4], (uint8_t)mac->octet[5]);
|
||||
return ptr;
|
||||
}
|
||||
|
||||
unsigned prefix_hash_key(void *pp)
|
||||
{
|
||||
struct prefix copy;
|
||||
|
||||
/* make sure *all* unused bits are zero, particularly including
|
||||
* alignment /
|
||||
* padding and unused prefix bytes. */
|
||||
memset(©, 0, sizeof(copy));
|
||||
prefix_copy(©, (struct prefix *)pp);
|
||||
return jhash(©, sizeof(copy), 0x55aa5a5a);
|
||||
}
|
||||
|
@ -323,6 +323,8 @@ extern const char *inet6_ntoa(struct in6_addr);
|
||||
extern int prefix_str2mac(const char *str, struct ethaddr *mac);
|
||||
extern char *prefix_mac2str(const struct ethaddr *mac, char *buf, int size);
|
||||
|
||||
extern unsigned prefix_hash_key(void *pp);
|
||||
|
||||
static inline int ipv6_martian(struct in6_addr *addr)
|
||||
{
|
||||
struct in6_addr localhost_addr;
|
||||
|
15
lib/table.c
15
lib/table.c
@ -27,7 +27,6 @@
|
||||
#include "table.h"
|
||||
#include "memory.h"
|
||||
#include "sockunion.h"
|
||||
#include "jhash.h"
|
||||
|
||||
DEFINE_MTYPE(LIB, ROUTE_TABLE, "Route table")
|
||||
DEFINE_MTYPE(LIB, ROUTE_NODE, "Route node")
|
||||
@ -35,18 +34,6 @@ DEFINE_MTYPE(LIB, ROUTE_NODE, "Route node")
|
||||
static void route_node_delete(struct route_node *);
|
||||
static void route_table_free(struct route_table *);
|
||||
|
||||
static unsigned route_table_hash_key(void *pp)
|
||||
{
|
||||
struct prefix copy;
|
||||
|
||||
/* make sure *all* unused bits are zero, particularly including
|
||||
* alignment /
|
||||
* padding and unused prefix bytes. */
|
||||
memset(©, 0, sizeof(copy));
|
||||
prefix_copy(©, (struct prefix *)pp);
|
||||
return jhash(©, sizeof(copy), 0x55aa5a5a);
|
||||
}
|
||||
|
||||
static int route_table_hash_cmp(const void *a, const void *b)
|
||||
{
|
||||
const struct prefix *pa = a, *pb = b;
|
||||
@ -63,7 +50,7 @@ route_table_init_with_delegate(route_table_delegate_t *delegate)
|
||||
|
||||
rt = XCALLOC(MTYPE_ROUTE_TABLE, sizeof(struct route_table));
|
||||
rt->delegate = delegate;
|
||||
rt->hash = hash_create(route_table_hash_key, route_table_hash_cmp,
|
||||
rt->hash = hash_create(prefix_hash_key, route_table_hash_cmp,
|
||||
"route table hash");
|
||||
return rt;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user