]> git.puffer.fish Git - mirror/frr.git/commitdiff
lib: Add equals function for nexthop groups
authorStephen Worley <sworley@cumulusnetworks.com>
Thu, 11 Apr 2019 17:36:41 +0000 (13:36 -0400)
committerStephen Worley <sworley@cumulusnetworks.com>
Fri, 25 Oct 2019 15:13:39 +0000 (11:13 -0400)
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>
lib/nexthop_group.c
lib/nexthop_group.h

index 527039ac63e3d045169794e2d8792fe18904abea..463ab0b881c9c06f456e80c2e9b1fe2c2f9c6581 100644 (file)
@@ -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));
index 5193c943c4f68fa179c2a3a7ab6cfb8525430609..be6f50d8a0d34f4a5358962cf10e036beffecbf3 100644 (file)
@@ -111,8 +111,10 @@ void nexthop_group_disable_vrf(struct vrf *vrf);
 void nexthop_group_interface_state_change(struct interface *ifp,
                                          ifindex_t oldifindex);
 
-extern struct nexthop *nexthop_exists(struct nexthop_group *nhg,
-                                     struct nexthop *nh);
+extern struct nexthop *nexthop_exists(const struct nexthop_group *nhg,
+                                     const struct nexthop *nh);
+extern bool nexthop_group_equal(const struct nexthop_group *nhg1,
+                               const struct nexthop_group *nhg2);
 
 extern struct nexthop_group_cmd *nhgc_find(const char *name);