From: Christian Franke Date: Thu, 3 Aug 2017 11:37:38 +0000 (+0200) Subject: lib: move prefix hash key to prefix.c to allow global use X-Git-Tag: frr-4.0-dev~459^2~2 X-Git-Url: https://git.puffer.fish/?a=commitdiff_plain;h=7a7761d21c9301bdfffc5f3faa2318819c6a0460;p=mirror%2Ffrr.git lib: move prefix hash key to prefix.c to allow global use Signed-off-by: Christian Franke --- diff --git a/lib/prefix.c b/lib/prefix.c index 0ba0025c68..47e16dbf8b 100644 --- a/lib/prefix.c +++ b/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); +} diff --git a/lib/prefix.h b/lib/prefix.h index ce13dcfa0a..4f1f0b22d7 100644 --- a/lib/prefix.h +++ b/lib/prefix.h @@ -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; diff --git a/lib/table.c b/lib/table.c index 2defa4fb62..e89d7d1c67 100644 --- a/lib/table.c +++ b/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; }