]> git.proxmox.com Git - mirror_frr.git/blobdiff - sharpd/sharp_zebra.c
lib,sharpd: support labelled nexthop-groups in sharpd
[mirror_frr.git] / sharpd / sharp_zebra.c
index 14220830c2394be0c4b14b6f579fa185246419f9..797398c79134a32a8112db52997bbb3b35a7d166 100644 (file)
@@ -73,7 +73,7 @@ static int interface_address_delete(ZAPI_CALLBACK_ARGS)
        if (!c)
                return 0;
 
-       connected_free(c);
+       connected_free(&c);
        return 0;
 }
 
@@ -205,6 +205,15 @@ static int route_notify_owner(ZAPI_CALLBACK_ARGS)
 static void zebra_connected(struct zclient *zclient)
 {
        zclient_send_reg_requests(zclient, VRF_DEFAULT);
+
+       /*
+        * Do not actually turn this on yet
+        * This is just the start of the infrastructure needed here
+        * This can be fixed at a later time.
+        *
+        *      zebra_redistribute_send(ZEBRA_REDISTRIBUTE_ADD, zclient, AFI_IP,
+        *                      ZEBRA_ROUTE_ALL, 0, VRF_DEFAULT);
+        */
 }
 
 void vrf_label_add(vrf_id_t vrf_id, afi_t afi, mpls_label_t label)
@@ -256,6 +265,17 @@ void route_add(struct prefix *p, vrf_id_t vrf_id,
                        api_nh->bh_type = nh->bh_type;
                        break;
                }
+
+               if (nh->nh_label && nh->nh_label->num_labels > 0) {
+                       int j;
+
+                       SET_FLAG(api_nh->flags, ZAPI_NEXTHOP_FLAG_LABEL);
+
+                       api_nh->label_num = nh->nh_label->num_labels;
+                       for (j = 0; j < nh->nh_label->num_labels; j++)
+                               api_nh->labels[j] = nh->nh_label->label[j];
+               }
+
                i++;
        }
        api.nexthop_num = i;
@@ -300,28 +320,13 @@ void sharp_zebra_nexthop_watch(struct prefix *p, vrf_id_t vrf_id, bool import,
                          __PRETTY_FUNCTION__);
 }
 
-static int sharp_nexthop_update(ZAPI_CALLBACK_ARGS)
+static int sharp_debug_nexthops(struct zapi_route *api)
 {
-       struct sharp_nh_tracker *nht;
-       struct zapi_route nhr;
-       char buf[PREFIX_STRLEN];
        int i;
+       char buf[PREFIX_STRLEN];
 
-       if (!zapi_nexthop_update_decode(zclient->ibuf, &nhr)) {
-               zlog_warn("%s: Decode of update failed", __PRETTY_FUNCTION__);
-
-               return 0;
-       }
-
-       zlog_debug("Received update for %s",
-                  prefix2str(&nhr.prefix, buf, sizeof(buf)));
-
-       nht = sharp_nh_tracker_get(&nhr.prefix);
-       nht->nhop_num = nhr.nexthop_num;
-       nht->updates++;
-
-       for (i = 0; i < nhr.nexthop_num; i++) {
-               struct zapi_nexthop *znh = &nhr.nexthops[i];
+       for (i = 0; i < api->nexthop_num; i++) {
+               struct zapi_nexthop *znh = &api->nexthops[i];
 
                switch (znh->type) {
                case NEXTHOP_TYPE_IPV4_IFINDEX:
@@ -351,6 +356,45 @@ static int sharp_nexthop_update(ZAPI_CALLBACK_ARGS)
                        break;
                }
        }
+
+       return i;
+}
+static int sharp_nexthop_update(ZAPI_CALLBACK_ARGS)
+{
+       struct sharp_nh_tracker *nht;
+       struct zapi_route nhr;
+
+       if (!zapi_nexthop_update_decode(zclient->ibuf, &nhr)) {
+               zlog_warn("%s: Decode of update failed", __PRETTY_FUNCTION__);
+
+               return 0;
+       }
+
+       zlog_debug("Received update for %pFX", &nhr.prefix);
+
+       nht = sharp_nh_tracker_get(&nhr.prefix);
+       nht->nhop_num = nhr.nexthop_num;
+       nht->updates++;
+
+       sharp_debug_nexthops(&nhr);
+
+       return 0;
+}
+
+static int sharp_redistribute_route(ZAPI_CALLBACK_ARGS)
+{
+       struct zapi_route api;
+
+       if (zapi_route_decode(zclient->ibuf, &api) < 0)
+               zlog_warn("%s: Decode of redistribute failed: %d",
+                         __PRETTY_FUNCTION__,
+                         ZEBRA_REDISTRIBUTE_ROUTE_ADD);
+
+       zlog_debug("%s: %pFX (%s)", zserv_command_string(cmd),
+                  &api.prefix, zebra_route_string(api.type));
+
+       sharp_debug_nexthops(&api);
+
        return 0;
 }
 
@@ -372,4 +416,7 @@ void sharp_zebra_init(void)
        zclient->route_notify_owner = route_notify_owner;
        zclient->nexthop_update = sharp_nexthop_update;
        zclient->import_check_update = sharp_nexthop_update;
+
+       zclient->redistribute_route_add = sharp_redistribute_route;
+       zclient->redistribute_route_del = sharp_redistribute_route;
 }