]> git.puffer.fish Git - matthieu/frr.git/commitdiff
lib, zebra: Allow for installation of a weighted nexthop
authorDonald Sharp <sharpd@cumulusnetworks.com>
Fri, 6 Dec 2019 13:58:47 +0000 (08:58 -0500)
committerDonald Sharp <sharpd@cumulusnetworks.com>
Mon, 9 Dec 2019 18:37:37 +0000 (13:37 -0500)
Linux has the idea of allowing a weight to be sent
down as part of a nexthop group to allow the kernel
to weight particular nexthop paths a bit more or less
than others.

See:
http://tldp.org/HOWTO/Adv-Routing-HOWTO/lartc.rpdb.multiple-links.html

Allow for installation into the kernel using the weight attribute
associated with the nexthop.

This code is foundational in that it just sets up the ability
to do this, we do not use it yet.  Further commits will
allow for the pass through of this data from upper level protocols.

Signed-off-by: Donald Sharp <sharpd@cumulusnetworks.com>
lib/nexthop.c
lib/nexthop.h
zebra/rt_netlink.c
zebra/zebra_nhg.c

index ce8034846fbb2c238cf28256a8df046441075c54..4cb9f68e8a983e64622698ed4d685f91ceab9487 100644 (file)
@@ -550,6 +550,7 @@ void nexthop_copy(struct nexthop *copy, const struct nexthop *nexthop,
        copy->ifindex = nexthop->ifindex;
        copy->type = nexthop->type;
        copy->flags = nexthop->flags;
+       copy->weight = nexthop->weight;
        memcpy(&copy->gate, &nexthop->gate, sizeof(nexthop->gate));
        memcpy(&copy->src, &nexthop->src, sizeof(nexthop->src));
        memcpy(&copy->rmap_src, &nexthop->rmap_src, sizeof(nexthop->rmap_src));
index 72a4acedb28a7f50a94f74f561b0dc2b79336e71..040b643a84ac5eae30692aeda14ae7036864bf1a 100644 (file)
@@ -110,6 +110,9 @@ struct nexthop {
 
        /* Label(s) associated with this nexthop. */
        struct mpls_label_stack *nh_label;
+
+       /* Weight of the nexthop ( for unequal cost ECMP ) */
+       uint8_t weight;
 };
 
 struct nexthop *nexthop_new(void);
index f3a255fd2940283f55b46c263ecf885481529783..e77c923230093dadacf2459cae2d90d7e524349c 100644 (file)
@@ -467,6 +467,8 @@ static uint8_t parse_multipath_nexthops_unicast(ns_id_t ns_id,
                        nh = nexthop_from_ifindex(index, nh_vrf_id);
 
                if (nh) {
+                       nh->weight = rtnh->rtnh_hops + 1;
+
                        if (num_labels)
                                nexthop_add_labels(nh, ZEBRA_LSP_STATIC,
                                                   num_labels, labels);
@@ -1419,6 +1421,9 @@ static void _netlink_route_build_multipath(const char *routedesc, int bytelen,
                                "nexthop via if %u",
                                routedesc, nexthop->ifindex);
        }
+
+       if (nexthop->weight)
+               rtnh->rtnh_hops = nexthop->weight - 1;
 }
 
 static inline void _netlink_mpls_build_singlepath(const char *routedesc,
@@ -1921,7 +1926,7 @@ static void _netlink_nexthop_build_group(struct nlmsghdr *n, size_t req_size,
        if (count) {
                for (int i = 0; i < count; i++) {
                        grp[i].id = z_grp[i].id;
-                       grp[i].weight = z_grp[i].weight;
+                       grp[i].weight = z_grp[i].weight - 1;
 
                        if (IS_ZEBRA_DEBUG_KERNEL) {
                                if (i == 0)
@@ -2347,7 +2352,7 @@ static int netlink_nexthop_process_group(struct rtattr **tb,
 
        for (int i = 0; ((i < count) && (i < z_grp_size)); i++) {
                z_grp[i].id = n_grp[i].id;
-               z_grp[i].weight = n_grp[i].weight;
+               z_grp[i].weight = n_grp[i].weight + 1;
        }
        return count;
 }
index 1a702506275862f76f4363554731ab16413a0776..9065a265ad7d32c85c32cb867d26de42cfac8d68 100644 (file)
@@ -1790,7 +1790,7 @@ uint8_t zebra_nhg_nhe2grp(struct nh_grp *grp, struct nhg_hash_entry *nhe,
                if (!duplicate) {
                        grp[i].id = depend->id;
                        /* We aren't using weights for anything right now */
-                       grp[i].weight = 0;
+                       grp[i].weight = depend->nhg->nexthop->weight;
                        i++;
                }