]> git.proxmox.com Git - mirror_frr.git/blobdiff - sharpd/sharp_zebra.c
isisd: fix redistribute CLI
[mirror_frr.git] / sharpd / sharp_zebra.c
index 0095aed547b517e939e12894ec608dea7cecdaa2..2575475dd22ade0b1345801ad4534d55a0f91bff 100644 (file)
@@ -30,6 +30,7 @@
 #include "zclient.h"
 #include "nexthop.h"
 #include "nexthop_group.h"
+#include "link_state.h"
 
 #include "sharp_globals.h"
 #include "sharp_nht.h"
@@ -229,6 +230,7 @@ struct buffer_delay {
        vrf_id_t vrf_id;
        uint8_t instance;
        uint32_t nhgid;
+       uint32_t flags;
        const struct nexthop_group *nhg;
        const struct nexthop_group *backup_nhg;
        enum where_to_restart restart;
@@ -243,7 +245,8 @@ struct buffer_delay {
  */
 static bool route_add(const struct prefix *p, vrf_id_t vrf_id, uint8_t instance,
                      uint32_t nhgid, const struct nexthop_group *nhg,
-                     const struct nexthop_group *backup_nhg, char *opaque)
+                     const struct nexthop_group *backup_nhg, uint32_t flags,
+                     char *opaque)
 {
        struct zapi_route api;
        struct zapi_nexthop *api_nh;
@@ -257,6 +260,7 @@ static bool route_add(const struct prefix *p, vrf_id_t vrf_id, uint8_t instance,
        api.safi = SAFI_UNICAST;
        memcpy(&api.prefix, p, sizeof(*p));
 
+       api.flags = flags;
        SET_FLAG(api.flags, ZEBRA_FLAG_ALLOW_RECURSION);
        SET_FLAG(api.message, ZAPI_MESSAGE_NEXTHOP);
 
@@ -334,7 +338,8 @@ static void sharp_install_routes_restart(struct prefix *p, uint32_t count,
                                         uint32_t nhgid,
                                         const struct nexthop_group *nhg,
                                         const struct nexthop_group *backup_nhg,
-                                        uint32_t routes, char *opaque)
+                                        uint32_t routes, uint32_t flags,
+                                        char *opaque)
 {
        uint32_t temp, i;
        bool v4 = false;
@@ -347,7 +352,7 @@ static void sharp_install_routes_restart(struct prefix *p, uint32_t count,
 
        for (i = count; i < routes; i++) {
                bool buffered = route_add(p, vrf_id, (uint8_t)instance, nhgid,
-                                         nhg, backup_nhg, opaque);
+                                         nhg, backup_nhg, flags, opaque);
                if (v4)
                        p->u.prefix4.s_addr = htonl(++temp);
                else
@@ -361,6 +366,7 @@ static void sharp_install_routes_restart(struct prefix *p, uint32_t count,
                        wb.instance = instance;
                        wb.nhgid = nhgid;
                        wb.nhg = nhg;
+                       wb.flags = flags;
                        wb.backup_nhg = backup_nhg;
                        wb.opaque = opaque;
                        wb.restart = SHARP_INSTALL_ROUTES_RESTART;
@@ -374,7 +380,7 @@ void sharp_install_routes_helper(struct prefix *p, vrf_id_t vrf_id,
                                 uint8_t instance, uint32_t nhgid,
                                 const struct nexthop_group *nhg,
                                 const struct nexthop_group *backup_nhg,
-                                uint32_t routes, char *opaque)
+                                uint32_t routes, uint32_t flags, char *opaque)
 {
        zlog_debug("Inserting %u routes", routes);
 
@@ -384,7 +390,7 @@ void sharp_install_routes_helper(struct prefix *p, vrf_id_t vrf_id,
 
        monotime(&sg.r.t_start);
        sharp_install_routes_restart(p, 0, vrf_id, instance, nhgid, nhg,
-                                    backup_nhg, routes, opaque);
+                                    backup_nhg, routes, flags, opaque);
 }
 
 static void sharp_remove_routes_restart(struct prefix *p, uint32_t count,
@@ -450,7 +456,8 @@ static void handle_repeated(bool installed)
                sharp_install_routes_helper(&p, sg.r.vrf_id, sg.r.inst,
                                            sg.r.nhgid, &sg.r.nhop_group,
                                            &sg.r.backup_nhop_group,
-                                           sg.r.total_routes, sg.r.opaque);
+                                           sg.r.total_routes, sg.r.flags,
+                                           sg.r.opaque);
        }
 }
 
@@ -460,7 +467,8 @@ static void sharp_zclient_buffer_ready(void)
        case SHARP_INSTALL_ROUTES_RESTART:
                sharp_install_routes_restart(
                        &wb.p, wb.count, wb.vrf_id, wb.instance, wb.nhgid,
-                       wb.nhg, wb.backup_nhg, wb.routes, wb.opaque);
+                       wb.nhg, wb.backup_nhg, wb.routes, wb.flags,
+                       wb.opaque);
                return;
        case SHARP_DELETE_ROUTES_RESTART:
                sharp_remove_routes_restart(&wb.p, wb.count, wb.vrf_id,
@@ -685,7 +693,8 @@ static int sharp_nexthop_update(ZAPI_CALLBACK_ARGS)
                return 0;
        }
 
-       zlog_debug("Received update for %pFX", &nhr.prefix);
+       zlog_debug("Received update for %pFX metric: %u", &nhr.prefix,
+                  nhr.metric);
 
        nht = sharp_nh_tracker_get(&nhr.prefix);
        nht->nhop_num = nhr.nexthop_num;
@@ -712,6 +721,12 @@ static int sharp_redistribute_route(ZAPI_CALLBACK_ARGS)
        return 0;
 }
 
+void sharp_redistribute_vrf(struct vrf *vrf, int type)
+{
+       zebra_redistribute_send(ZEBRA_REDISTRIBUTE_ADD, zclient, AFI_IP, type,
+                               0, vrf->vrf_id);
+}
+
 /* Add a zclient with a specified session id, for testing. */
 int sharp_zclient_create(uint32_t session_id)
 {
@@ -768,11 +783,15 @@ int sharp_zclient_delete(uint32_t session_id)
        return 0;
 }
 
+static const char *const type2txt[] = { "Generic", "Vertex", "Edge", "Subnet" };
+static const char *const status2txt[] = { "Unknown", "New", "Update",
+                                         "Delete", "Sync", "Orphan"};
 /* Handler for opaque messages */
 static int sharp_opaque_handler(ZAPI_CALLBACK_ARGS)
 {
        struct stream *s;
        struct zapi_opaque_msg info;
+       struct ls_element *lse;
 
        s = zclient->ibuf;
 
@@ -782,6 +801,18 @@ static int sharp_opaque_handler(ZAPI_CALLBACK_ARGS)
        zlog_debug("%s: [%u] received opaque type %u", __func__,
                   zclient->session_id, info.type);
 
+       if (info.type == LINK_STATE_UPDATE) {
+               lse = ls_stream2ted(sg.ted, s, false);
+               if (lse)
+                       zlog_debug(" |- Got %s %s from Link State Database",
+                                  status2txt[lse->status],
+                                  type2txt[lse->type]);
+               else
+                       zlog_debug(
+                               "%s: Error to convert Stream into Link State",
+                               __func__);
+       }
+
        return 0;
 }
 
@@ -852,6 +883,16 @@ void sharp_opaque_reg_send(bool is_reg, uint32_t proto, uint32_t instance,
 
 }
 
+/* Link State registration */
+void sharp_zebra_register_te(void)
+{
+       /* First register to received Link State Update messages */
+       zclient_register_opaque(zclient, LINK_STATE_UPDATE);
+
+       /* Then, request initial TED with SYNC message */
+       ls_request_sync(zclient);
+}
+
 void sharp_zebra_send_arp(const struct interface *ifp, const struct prefix *p)
 {
        zclient_send_neigh_discovery_req(zclient, ifp, p);
@@ -884,6 +925,50 @@ static int nhg_notify_owner(ZAPI_CALLBACK_ARGS)
        return 0;
 }
 
+int sharp_zebra_srv6_manager_get_locator_chunk(const char *locator_name)
+{
+       return srv6_manager_get_locator_chunk(zclient, locator_name);
+}
+
+int sharp_zebra_srv6_manager_release_locator_chunk(const char *locator_name)
+{
+       return srv6_manager_release_locator_chunk(zclient, locator_name);
+}
+
+static void sharp_zebra_process_srv6_locator_chunk(ZAPI_CALLBACK_ARGS)
+{
+       struct stream *s = NULL;
+       struct srv6_locator_chunk s6c = {};
+       struct listnode *node, *nnode;
+       struct sharp_srv6_locator *loc;
+
+       s = zclient->ibuf;
+       zapi_srv6_locator_chunk_decode(s, &s6c);
+
+       for (ALL_LIST_ELEMENTS(sg.srv6_locators, node, nnode, loc)) {
+               struct prefix_ipv6 *chunk = NULL;
+               struct listnode *chunk_node;
+               struct prefix_ipv6 *c;
+
+               if (strcmp(loc->name, s6c.locator_name) != 0) {
+                       zlog_err("%s: Locator name unmatch %s:%s", __func__,
+                                loc->name, s6c.locator_name);
+                       continue;
+               }
+
+               for (ALL_LIST_ELEMENTS_RO(loc->chunks, chunk_node, c))
+                       if (!prefix_cmp(c, &s6c.prefix))
+                               return;
+
+               chunk = prefix_ipv6_new();
+               *chunk = s6c.prefix;
+               listnode_add(loc->chunks, chunk);
+               return;
+       }
+
+       zlog_err("%s: can't get locator_chunk!!", __func__);
+}
+
 void sharp_zebra_init(void)
 {
        struct zclient_options opt = {.receive_notify = true};
@@ -905,4 +990,6 @@ void sharp_zebra_init(void)
        zclient->redistribute_route_add = sharp_redistribute_route;
        zclient->redistribute_route_del = sharp_redistribute_route;
        zclient->opaque_msg_handler = sharp_opaque_handler;
+       zclient->process_srv6_locator_chunk =
+               sharp_zebra_process_srv6_locator_chunk;
 }