]> git.proxmox.com Git - mirror_frr.git/commitdiff
sharp: Modify route install to take nexthop groups
authorDonald Sharp <sharpd@cumulusnetworks.com>
Mon, 31 Dec 2018 22:28:13 +0000 (17:28 -0500)
committerDonald Sharp <sharpd@cumulusnetworks.com>
Wed, 2 Jan 2019 14:46:33 +0000 (09:46 -0500)
Modify the route_add function to take nexthop groups.  Future commits
will allow sharpd to use nexthop groups as the install mechanism
for routes.

Signed-off-by: Donald Sharp <sharpd@cumulusnetworks.com>
sharpd/sharp_main.c
sharpd/sharp_vty.c
sharpd/sharp_zebra.c
sharpd/sharp_zebra.h

index 20cdd21e7d23498af780700ddf7535b4fe65b7a7..34b84f6062e91c174432638ea4de1b302b98031f 100644 (file)
@@ -42,6 +42,7 @@
 #include "distribute.h"
 #include "libfrr.h"
 #include "routemap.h"
+#include "nexthop_group.h"
 
 #include "sharp_zebra.h"
 #include "sharp_vty.h"
index 797e336c2d2de814d91a6a5e3437d34e9146a9a0..700b5a911c43c0d78f0ee266b1fad4b0667e6b4f 100644 (file)
@@ -28,6 +28,7 @@
 #include "log.h"
 #include "vrf.h"
 #include "zclient.h"
+#include "nexthop_group.h"
 
 #include "sharpd/sharp_zebra.h"
 #include "sharpd/sharp_vty.h"
@@ -96,6 +97,7 @@ DEFPY (install_routes,
        int i;
        struct prefix p;
        struct nexthop nhop;
+       struct nexthop_group nhg;
        uint32_t temp;
 
        total_routes = routes;
@@ -103,6 +105,7 @@ DEFPY (install_routes,
 
        memset(&p, 0, sizeof(p));
        memset(&nhop, 0, sizeof(nhop));
+       memset(&nhg, 0, sizeof(nhg));
 
        p.family = AF_INET;
        p.prefixlen = 32;
@@ -116,11 +119,12 @@ DEFPY (install_routes,
                nhop.type = NEXTHOP_TYPE_IPV6;
        }
 
+       nhg.nexthop = &nhop;
        zlog_debug("Inserting %ld routes", routes);
 
        temp = ntohl(p.u.prefix4.s_addr);
        for (i = 0; i < routes; i++) {
-               route_add(&p, (uint8_t)instance, &nhop);
+               route_add(&p, (uint8_t)instance, &nhg);
                p.u.prefix4.s_addr = htonl(++temp);
        }
 
index f752009eb8fc61312e35b08e0d13bbe44e26aabf..4a88b6c8ee13e984f03c90ca2b1fe15210153d59 100644 (file)
@@ -34,6 +34,7 @@
 #include "plist.h"
 #include "log.h"
 #include "nexthop.h"
+#include "nexthop_group.h"
 
 #include "sharp_zebra.h"
 
@@ -176,10 +177,12 @@ void vrf_label_add(vrf_id_t vrf_id, afi_t afi, mpls_label_t label)
        zclient_send_vrf_label(zclient, vrf_id, afi, label, ZEBRA_LSP_SHARP);
 }
 
-void route_add(struct prefix *p, uint8_t instance, struct nexthop *nh)
+void route_add(struct prefix *p, uint8_t instance, struct nexthop_group *nhg)
 {
        struct zapi_route api;
        struct zapi_nexthop *api_nh;
+       struct nexthop *nh;
+       int i = 0;
 
        memset(&api, 0, sizeof(api));
        api.vrf_id = VRF_DEFAULT;
@@ -191,12 +194,35 @@ void route_add(struct prefix *p, uint8_t instance, struct nexthop *nh)
        SET_FLAG(api.flags, ZEBRA_FLAG_ALLOW_RECURSION);
        SET_FLAG(api.message, ZAPI_MESSAGE_NEXTHOP);
 
-       api_nh = &api.nexthops[0];
-       api_nh->vrf_id = VRF_DEFAULT;
-       api_nh->gate = nh->gate;
-       api_nh->type = nh->type;
-       api_nh->ifindex = nh->ifindex;
-       api.nexthop_num = 1;
+       for (ALL_NEXTHOPS_PTR(nhg, nh)) {
+               api_nh = &api.nexthops[i];
+               api_nh->vrf_id = VRF_DEFAULT;
+               api_nh->type = nh->type;
+               switch (nh->type) {
+               case NEXTHOP_TYPE_IPV4:
+                       api_nh->gate = nh->gate;
+                       break;
+               case NEXTHOP_TYPE_IPV4_IFINDEX:
+                       api_nh->gate = nh->gate;
+                       api_nh->ifindex = nh->ifindex;
+                       break;
+               case NEXTHOP_TYPE_IFINDEX:
+                       api_nh->ifindex = nh->ifindex;
+                       break;
+               case NEXTHOP_TYPE_IPV6:
+                       memcpy(&api_nh->gate.ipv6, &nh->gate.ipv6, 16);
+                       break;
+               case NEXTHOP_TYPE_IPV6_IFINDEX:
+                       api_nh->ifindex = nh->ifindex;
+                       memcpy(&api_nh->gate.ipv6, &nh->gate.ipv6, 16);
+                       break;
+               case NEXTHOP_TYPE_BLACKHOLE:
+                       api_nh->bh_type = nh->bh_type;
+                       break;
+               }
+               i++;
+       }
+       api.nexthop_num = i;
 
        zclient_route_send(ZEBRA_ROUTE_ADD, zclient, &api);
 }
index 58438ed01d821b2f9b8c1f9eda64062e493254e5..ffe21df9b807af57ee0c19e426619b1f040c06e7 100644 (file)
@@ -25,7 +25,8 @@
 extern void sharp_zebra_init(void);
 
 extern void vrf_label_add(vrf_id_t vrf_id, afi_t afi, mpls_label_t label);
-extern void route_add(struct prefix *p, uint8_t instance, struct nexthop *nh);
+extern void route_add(struct prefix *p, uint8_t instance,
+                     struct nexthop_group *nhg);
 extern void route_delete(struct prefix *p, uint8_t instance);
 extern void sharp_zebra_nexthop_watch(struct prefix *p, bool watch);
 #endif