diff options
author | Stephen Worley <sworley@cumulusnetworks.com> | 2019-04-11 19:36:41 +0200 |
---|---|---|
committer | Stephen Worley <sworley@cumulusnetworks.com> | 2019-10-25 17:13:39 +0200 |
commit | 8f8d9845c6bc283e5a9f7339f9d3f2884774589b (patch) | |
tree | 01b88cc9305eb532d02ca42988e116327479cd1a /lib/nexthop_group.c | |
parent | zebra: Remove uneeded freeing helper function (diff) | |
download | frr-8f8d9845c6bc283e5a9f7339f9d3f2884774589b.tar.xz frr-8f8d9845c6bc283e5a9f7339f9d3f2884774589b.zip |
lib: Add equals function for nexthop groups
Add a function to check whether nexthop groups
are equivalent. It does not care about ordering.
Also, set any functions that it relies on to take
const vars as well.
Signed-off-by: Stephen Worley <sworley@cumulusnetworks.com>
Diffstat (limited to 'lib/nexthop_group.c')
-rw-r--r-- | lib/nexthop_group.c | 25 |
1 files changed, 24 insertions, 1 deletions
diff --git a/lib/nexthop_group.c b/lib/nexthop_group.c index 527039ac6..463ab0b88 100644 --- a/lib/nexthop_group.c +++ b/lib/nexthop_group.c @@ -94,7 +94,8 @@ uint8_t nexthop_group_active_nexthop_num(const struct nexthop_group *nhg) return num; } -struct nexthop *nexthop_exists(struct nexthop_group *nhg, struct nexthop *nh) +struct nexthop *nexthop_exists(const struct nexthop_group *nhg, + const struct nexthop *nh) { struct nexthop *nexthop; @@ -106,6 +107,28 @@ struct nexthop *nexthop_exists(struct nexthop_group *nhg, struct nexthop *nh) return NULL; } +bool nexthop_group_equal(const struct nexthop_group *nhg1, + const struct nexthop_group *nhg2) +{ + struct nexthop *nh = NULL; + + if (nhg1 && !nhg2) + return false; + + if (!nhg1 && !nhg2) + return false; + + if (nexthop_group_nexthop_num(nhg1) != nexthop_group_nexthop_num(nhg2)) + return false; + + for (ALL_NEXTHOPS_PTR(nhg1, nh)) { + if (!nexthop_exists(nhg2, nh)) + return false; + } + + return true; +} + struct nexthop_group *nexthop_group_new(void) { return XCALLOC(MTYPE_NEXTHOP_GROUP, sizeof(struct nexthop_group)); |