]> git.puffer.fish Git - matthieu/frr.git/commitdiff
lib: Separate nexthop_group_equal() into recursive
authorStephen Worley <sworley@cumulusnetworks.com>
Wed, 7 Aug 2019 18:04:19 +0000 (14:04 -0400)
committerStephen Worley <sworley@cumulusnetworks.com>
Fri, 25 Oct 2019 15:13:42 +0000 (11:13 -0400)
Separate nexthop_group_equal() into two versions. One
that compares verses recurisvely resolved nexthops and
one that doesn't.

Signed-off-by: Stephen Worley <sworley@cumulusnetworks.com>
lib/nexthop_group.c
lib/nexthop_group.h

index 8bb6fc9593c8bea8cd04c2c82720ce7f9b37fb06..86c885012c838309c9bb7808b0d95da2fec87b6e 100644 (file)
@@ -133,8 +133,8 @@ struct nexthop *nexthop_exists(const struct nexthop_group *nhg,
 }
 
 /* This assumes ordered */
-bool nexthop_group_equal(const struct nexthop_group *nhg1,
-                        const struct nexthop_group *nhg2)
+bool nexthop_group_equal_no_recurse(const struct nexthop_group *nhg1,
+                                   const struct nexthop_group *nhg2)
 {
        struct nexthop *nh1 = NULL;
        struct nexthop *nh2 = NULL;
@@ -149,7 +149,7 @@ bool nexthop_group_equal(const struct nexthop_group *nhg1,
            != nexthop_group_nexthop_num_no_recurse(nhg2))
                return false;
 
-       for (nh1 = nhg1->nexthop, nh2 = nhg2->nexthop; nh1 && nh2;
+       for (nh1 = nhg1->nexthop, nh2 = nhg2->nexthop; nh1 || nh2;
             nh1 = nh1->next, nh2 = nh2->next) {
                if (!nexthop_same(nh1, nh2))
                        return false;
@@ -158,6 +158,30 @@ bool nexthop_group_equal(const struct nexthop_group *nhg1,
        return true;
 }
 
+/* This assumes ordered */
+bool nexthop_group_equal(const struct nexthop_group *nhg1,
+                        const struct nexthop_group *nhg2)
+{
+       struct nexthop *nh1 = NULL;
+       struct nexthop *nh2 = 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 (nh1 = nhg1->nexthop, nh2 = nhg2->nexthop; nh1 || nh2;
+            nh1 = nexthop_next(nh1), nh2 = nexthop_next(nh2)) {
+               if (!nexthop_same(nh1, nh2))
+                       return false;
+       }
+
+       return true;
+}
 struct nexthop_group *nexthop_group_new(void)
 {
        return XCALLOC(MTYPE_NEXTHOP_GROUP, sizeof(struct nexthop_group));
index 291a259f935490822c593106888a514653684cf4..378b0ce6bb717160300709c38f076cf12457ca82 100644 (file)
@@ -115,6 +115,11 @@ void nexthop_group_interface_state_change(struct interface *ifp,
 
 extern struct nexthop *nexthop_exists(const struct nexthop_group *nhg,
                                      const struct nexthop *nh);
+/* This assumes ordered */
+extern bool nexthop_group_equal_no_recurse(const struct nexthop_group *nhg1,
+                                          const struct nexthop_group *nhg2);
+
+/* This assumes ordered */
 extern bool nexthop_group_equal(const struct nexthop_group *nhg1,
                                const struct nexthop_group *nhg2);