]> git.proxmox.com Git - mirror_frr.git/commitdiff
lib: test vrfs in nexthop_same_firsthop()
authorMark Stapp <mjs@voltanet.io>
Tue, 26 May 2020 15:08:42 +0000 (11:08 -0400)
committerMark Stapp <mjs@voltanet.io>
Tue, 7 Jul 2020 17:14:01 +0000 (13:14 -0400)
Test the two nexthops' vrfs, and convert api to 'bool' return.

Signed-off-by: Mark Stapp <mjs@voltanet.io>
lib/nexthop.c
lib/nexthop.h

index 0d239e091b5ea71a2d7a0ea2f62d3ba91e604358..3496081d47d409b1c0ed2ea190b7ab38c3852d7c 100644 (file)
@@ -187,35 +187,41 @@ int nexthop_cmp(const struct nexthop *next1, const struct nexthop *next2)
        return ret;
 }
 
-int nexthop_same_firsthop(struct nexthop *next1, struct nexthop *next2)
+bool nexthop_same_firsthop(const struct nexthop *next1,
+                          const struct nexthop *next2)
 {
+       /* Map the TYPE_IPx types to TYPE_IPx_IFINDEX */
        int type1 = NEXTHOP_FIRSTHOPTYPE(next1->type);
        int type2 = NEXTHOP_FIRSTHOPTYPE(next2->type);
 
        if (type1 != type2)
-               return 0;
+               return false;
+
+       if (next1->vrf_id != next2->vrf_id)
+               return false;
+
        switch (type1) {
        case NEXTHOP_TYPE_IPV4_IFINDEX:
                if (!IPV4_ADDR_SAME(&next1->gate.ipv4, &next2->gate.ipv4))
-                       return 0;
+                       return false;
                if (next1->ifindex != next2->ifindex)
-                       return 0;
+                       return false;
                break;
        case NEXTHOP_TYPE_IFINDEX:
                if (next1->ifindex != next2->ifindex)
-                       return 0;
+                       return false;
                break;
        case NEXTHOP_TYPE_IPV6_IFINDEX:
                if (!IPV6_ADDR_SAME(&next1->gate.ipv6, &next2->gate.ipv6))
-                       return 0;
+                       return false;
                if (next1->ifindex != next2->ifindex)
-                       return 0;
+                       return false;
                break;
        default:
                /* do nothing */
                break;
        }
-       return 1;
+       return true;
 }
 
 /*
index 9b71262589534bc45dc5ccc68f7aabbef6c143e1..eda88efc08dc78682fd5c33b099c1bed27583402 100644 (file)
@@ -208,7 +208,8 @@ extern int nexthop_g_addr_cmp(enum nexthop_types_t type,
 extern const char *nexthop_type_to_str(enum nexthop_types_t nh_type);
 extern bool nexthop_labels_match(const struct nexthop *nh1,
                                 const struct nexthop *nh2);
-extern int nexthop_same_firsthop(struct nexthop *next1, struct nexthop *next2);
+extern bool nexthop_same_firsthop(const struct nexthop *next1,
+                                 const struct nexthop *next2);
 
 extern const char *nexthop2str(const struct nexthop *nexthop,
                               char *str, int size);