From 2f00094498ebd5dc65c66c1219e4553e36ec35f6 Mon Sep 17 00:00:00 2001 From: Stephen Worley Date: Tue, 2 Jul 2019 01:34:57 -0400 Subject: [PATCH] lib: Hash on resolved nexthops by default Include resolved nexthops when hashing a nexthop group but provide an API that allows you to non-recursively hash as well. Signed-off-by: Stephen Worley --- lib/nexthop_group.c | 13 ++++++++++++- lib/nexthop_group.h | 1 + 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/lib/nexthop_group.c b/lib/nexthop_group.c index c9a8f1af51..a79b2741c5 100644 --- a/lib/nexthop_group.c +++ b/lib/nexthop_group.c @@ -273,7 +273,7 @@ void copy_nexthops(struct nexthop **tnh, const struct nexthop *nh, } } -uint32_t nexthop_group_hash(const struct nexthop_group *nhg) +uint32_t nexthop_group_hash_no_recurse(const struct nexthop_group *nhg) { struct nexthop *nh; uint32_t key = 0; @@ -288,6 +288,17 @@ uint32_t nexthop_group_hash(const struct nexthop_group *nhg) return key; } +uint32_t nexthop_group_hash(const struct nexthop_group *nhg) +{ + struct nexthop *nh; + uint32_t key = 0; + + for (ALL_NEXTHOPS_PTR(nhg, nh)) + key = jhash_1word(nexthop_hash(nh), key); + + return key; +} + static void nhgc_delete_nexthops(struct nexthop_group_cmd *nhgc) { struct nexthop *nexthop; diff --git a/lib/nexthop_group.h b/lib/nexthop_group.h index 57a5a97599..a765b4b76b 100644 --- a/lib/nexthop_group.h +++ b/lib/nexthop_group.h @@ -48,6 +48,7 @@ void nexthop_group_copy(struct nexthop_group *to, void copy_nexthops(struct nexthop **tnh, const struct nexthop *nh, struct nexthop *rparent); +uint32_t nexthop_group_hash_no_recurse(const struct nexthop_group *nhg); uint32_t nexthop_group_hash(const struct nexthop_group *nhg); /* The following for loop allows to iterate over the nexthop