summaryrefslogtreecommitdiff
path: root/lib/nexthop.c
diff options
context:
space:
mode:
authorQuentin Young <qlyoung@cumulusnetworks.com>2018-03-19 09:01:52 -0400
committerDonald Sharp <sharpd@cumulusnetworks.com>2018-04-06 13:22:43 -0400
commitd36d0d57711ec79bb7ff4360b62d80b1a9809f6f (patch)
tree7e9f9c3fc7865e2bb9129a546389d857fff6d641 /lib/nexthop.c
parent6568993b1b624637db7999b7f00cc62b7501bd4f (diff)
lib: Add hash and use const a bit more intelligently
This commit adds code to notify the compiler that we will not be changing the arguments to nexthop2str and we expect thre return to be treated the same. Additionally we add some code to allow nexthops to be hashed to be used in a hash. Signed-off-by: Quentin Young <qlyoung@cumulusnetworks.com>
Diffstat (limited to 'lib/nexthop.c')
-rw-r--r--lib/nexthop.c15
1 files changed, 14 insertions, 1 deletions
diff --git a/lib/nexthop.c b/lib/nexthop.c
index b1e9582b20..3603050f06 100644
--- a/lib/nexthop.c
+++ b/lib/nexthop.c
@@ -31,6 +31,7 @@
#include "prefix.h"
#include "nexthop.h"
#include "mpls.h"
+#include "jhash.h"
DEFINE_MTYPE_STATIC(LIB, NEXTHOP, "Nexthop")
DEFINE_MTYPE_STATIC(LIB, NH_LABEL, "Nexthop label")
@@ -240,7 +241,7 @@ void nexthop_del_labels(struct nexthop *nexthop)
}
}
-const char *nexthop2str(struct nexthop *nexthop, char *str, int size)
+const char *nexthop2str(const struct nexthop *nexthop, char *str, int size)
{
switch (nexthop->type) {
case NEXTHOP_TYPE_IFINDEX:
@@ -310,3 +311,15 @@ unsigned int nexthop_level(struct nexthop *nexthop)
return rv;
}
+
+uint32_t nexthop_hash(struct nexthop *nexthop)
+{
+ uint32_t key;
+
+ key = jhash_1word(nexthop->vrf_id, 0x45afe398);
+ key = jhash_1word(nexthop->ifindex, key);
+ key = jhash_1word(nexthop->type, key);
+ key = jhash(&nexthop->gate, sizeof(union g_addr), key);
+
+ return key;
+}