diff options
author | Stephen Worley <sworley@cumulusnetworks.com> | 2019-09-03 22:59:57 +0200 |
---|---|---|
committer | Stephen Worley <sworley@cumulusnetworks.com> | 2019-10-25 17:13:43 +0200 |
commit | f17f2c5d6c4321ecac68f55aeba5fbb2d04c27bb (patch) | |
tree | 723fbaf60169b390da8246ab5d51ab760280e358 /lib | |
parent | lib: Add NULL check in nexthop_group_equal*() iter (diff) | |
download | frr-f17f2c5d6c4321ecac68f55aeba5fbb2d04c27bb.tar.xz frr-f17f2c5d6c4321ecac68f55aeba5fbb2d04c27bb.zip |
lib: Add common handler for nexthop_group_equal*()
Add a common handler function for the different nexthop_group_equal*()
comparison functions.
Signed-off-by: Stephen Worley <sworley@cumulusnetworks.com>
Diffstat (limited to 'lib')
-rw-r--r-- | lib/nexthop_group.c | 40 |
1 files changed, 22 insertions, 18 deletions
diff --git a/lib/nexthop_group.c b/lib/nexthop_group.c index 35599488b..7d8bcd116 100644 --- a/lib/nexthop_group.c +++ b/lib/nexthop_group.c @@ -132,13 +132,12 @@ struct nexthop *nexthop_exists(const struct nexthop_group *nhg, return NULL; } -/* This assumes ordered */ -bool nexthop_group_equal_no_recurse(const struct nexthop_group *nhg1, - const struct nexthop_group *nhg2) +static bool +nexthop_group_equal_common(const struct nexthop_group *nhg1, + const struct nexthop_group *nhg2, + uint8_t (*nexthop_group_nexthop_num_func)( + const struct nexthop_group *nhg)) { - struct nexthop *nh1 = NULL; - struct nexthop *nh2 = NULL; - if (nhg1 && !nhg2) return false; @@ -148,8 +147,22 @@ bool nexthop_group_equal_no_recurse(const struct nexthop_group *nhg1, if (nhg1 == nhg2) return true; - if (nexthop_group_nexthop_num_no_recurse(nhg1) - != nexthop_group_nexthop_num_no_recurse(nhg2)) + if (nexthop_group_nexthop_num_func(nhg1) + != nexthop_group_nexthop_num_func(nhg2)) + return false; + + return true; +} + +/* This assumes ordered */ +bool nexthop_group_equal_no_recurse(const struct nexthop_group *nhg1, + const struct nexthop_group *nhg2) +{ + struct nexthop *nh1 = NULL; + struct nexthop *nh2 = NULL; + + if (!nexthop_group_equal_common(nhg1, nhg2, + &nexthop_group_nexthop_num_no_recurse)) return false; for (nh1 = nhg1->nexthop, nh2 = nhg2->nexthop; nh1 || nh2; @@ -172,16 +185,7 @@ bool nexthop_group_equal(const struct nexthop_group *nhg1, struct nexthop *nh1 = NULL; struct nexthop *nh2 = NULL; - if (nhg1 && !nhg2) - return false; - - if (!nhg1 && nhg2) - return false; - - if (nhg1 == nhg2) - return true; - - if (nexthop_group_nexthop_num(nhg1) != nexthop_group_nexthop_num(nhg2)) + if (!nexthop_group_equal_common(nhg1, nhg2, &nexthop_group_nexthop_num)) return false; for (nh1 = nhg1->nexthop, nh2 = nhg2->nexthop; nh1 || nh2; |