]> git.puffer.fish Git - matthieu/frr.git/commitdiff
staticd: northbound srv6 hooks for segs stack yang model
authorDmytro Shytyi <dmytro.shytyi@6wind.com>
Wed, 26 Jul 2023 16:01:20 +0000 (18:01 +0200)
committerDmytro Shytyi <dmytro.shytyi@6wind.com>
Wed, 20 Sep 2023 13:07:15 +0000 (15:07 +0200)
Provive hooks for srv6 segs SIDs stack yang model.

Signed-off-by: Dmytro Shytyi <dmytro.shytyi@6wind.com>
staticd/static_nb.c
staticd/static_nb.h
staticd/static_nb_config.c

index d8b5b167cf226b3cf47efbbd6b55f41f3413aa66..1c69a58035b9b499e466dee178758d4b09b764cc 100644 (file)
@@ -74,6 +74,21 @@ const struct frr_yang_module_info frr_staticd_info = {
                                .destroy = routing_control_plane_protocols_control_plane_protocol_staticd_route_list_path_list_frr_nexthops_nexthop_color_destroy,
                        }
                },
+               {
+                       .xpath = "/frr-routing:routing/control-plane-protocols/control-plane-protocol/frr-staticd:staticd/route-list/path-list/frr-nexthops/nexthop/srv6-segs-stack/entry",
+                       .cbs = {
+                               .create = routing_control_plane_protocols_control_plane_protocol_staticd_route_list_path_list_frr_nexthops_nexthop_srv6_segs_stack_entry_create,
+                               .destroy = routing_control_plane_protocols_control_plane_protocol_staticd_route_list_path_list_frr_nexthops_nexthop_srv6_segs_stack_entry_destroy,
+
+                       }
+               },
+               {
+                       .xpath = "/frr-routing:routing/control-plane-protocols/control-plane-protocol/frr-staticd:staticd/route-list/path-list/frr-nexthops/nexthop/srv6-segs-stack/entry/seg",
+                       .cbs = {
+                               .modify = routing_control_plane_protocols_control_plane_protocol_staticd_route_list_path_list_frr_nexthops_nexthop_srv6_segs_stack_entry_seg_modify,
+                               .destroy = routing_control_plane_protocols_control_plane_protocol_staticd_route_list_path_list_frr_nexthops_nexthop_srv6_segs_stack_entry_seg_destroy,
+                       }
+               },
                {
                        .xpath = "/frr-routing:routing/control-plane-protocols/control-plane-protocol/frr-staticd:staticd/route-list/path-list/frr-nexthops/nexthop/mpls-label-stack/entry",
                        .cbs = {
@@ -182,6 +197,20 @@ const struct frr_yang_module_info frr_staticd_info = {
                                .destroy = routing_control_plane_protocols_control_plane_protocol_staticd_route_list_src_list_path_list_frr_nexthops_nexthop_color_destroy,
                        }
                },
+               {
+                       .xpath = "/frr-routing:routing/control-plane-protocols/control-plane-protocol/frr-staticd:staticd/route-list/src-list/path-list/frr-nexthops/nexthop/srv6-segs-stack/entry",
+                       .cbs = {
+                               .create = routing_control_plane_protocols_control_plane_protocol_staticd_route_list_src_list_path_list_frr_nexthops_nexthop_srv6_segs_stack_entry_create,
+                               .destroy = routing_control_plane_protocols_control_plane_protocol_staticd_route_list_src_list_path_list_frr_nexthops_nexthop_srv6_segs_stack_entry_destroy,
+                       }
+               },
+               {
+                       .xpath = "/frr-routing:routing/control-plane-protocols/control-plane-protocol/frr-staticd:staticd/route-list/src-list/path-list/frr-nexthops/nexthop/srv6-segs-stack/entry/seg",
+                       .cbs = {
+                               .modify = routing_control_plane_protocols_control_plane_protocol_staticd_route_list_src_list_path_list_frr_nexthops_nexthop_srv6_segs_stack_entry_seg_modify,
+                               .destroy = routing_control_plane_protocols_control_plane_protocol_staticd_route_list_src_list_path_list_frr_nexthops_nexthop_srv6_segs_stack_entry_seg_destroy,
+                       }
+               },
                {
                        .xpath = "/frr-routing:routing/control-plane-protocols/control-plane-protocol/frr-staticd:staticd/route-list/src-list/path-list/frr-nexthops/nexthop/mpls-label-stack/entry",
                        .cbs = {
index ce3644076c01f8fdedcb5de832873b2b31216e7f..9f80653b762d93bcccd1240d5d2a5885d31e216c 100644 (file)
@@ -35,6 +35,14 @@ int routing_control_plane_protocols_control_plane_protocol_staticd_route_list_pa
        struct nb_cb_modify_args *args);
 int routing_control_plane_protocols_control_plane_protocol_staticd_route_list_path_list_frr_nexthops_nexthop_color_destroy(
        struct nb_cb_destroy_args *args);
+int routing_control_plane_protocols_control_plane_protocol_staticd_route_list_path_list_frr_nexthops_nexthop_srv6_segs_stack_entry_create(
+       struct nb_cb_create_args *args);
+int routing_control_plane_protocols_control_plane_protocol_staticd_route_list_path_list_frr_nexthops_nexthop_srv6_segs_stack_entry_destroy(
+       struct nb_cb_destroy_args *args);
+int routing_control_plane_protocols_control_plane_protocol_staticd_route_list_path_list_frr_nexthops_nexthop_srv6_segs_stack_entry_seg_modify(
+       struct nb_cb_modify_args *args);
+int routing_control_plane_protocols_control_plane_protocol_staticd_route_list_path_list_frr_nexthops_nexthop_srv6_segs_stack_entry_seg_destroy(
+       struct nb_cb_destroy_args *args);
 int routing_control_plane_protocols_control_plane_protocol_staticd_route_list_path_list_frr_nexthops_nexthop_mpls_label_stack_entry_create(
        struct nb_cb_create_args *args);
 int routing_control_plane_protocols_control_plane_protocol_staticd_route_list_path_list_frr_nexthops_nexthop_mpls_label_stack_entry_destroy(
@@ -80,6 +88,14 @@ int routing_control_plane_protocols_control_plane_protocol_staticd_route_list_sr
        struct nb_cb_modify_args *args);
 int routing_control_plane_protocols_control_plane_protocol_staticd_route_list_src_list_path_list_frr_nexthops_nexthop_color_destroy(
        struct nb_cb_destroy_args *args);
+int routing_control_plane_protocols_control_plane_protocol_staticd_route_list_src_list_path_list_frr_nexthops_nexthop_srv6_segs_stack_entry_create(
+       struct nb_cb_create_args *args);
+int routing_control_plane_protocols_control_plane_protocol_staticd_route_list_src_list_path_list_frr_nexthops_nexthop_srv6_segs_stack_entry_destroy(
+       struct nb_cb_destroy_args *args);
+int routing_control_plane_protocols_control_plane_protocol_staticd_route_list_src_list_path_list_frr_nexthops_nexthop_srv6_segs_stack_entry_seg_modify(
+       struct nb_cb_modify_args *args);
+int routing_control_plane_protocols_control_plane_protocol_staticd_route_list_src_list_path_list_frr_nexthops_nexthop_srv6_segs_stack_entry_seg_destroy(
+       struct nb_cb_destroy_args *args);
 int routing_control_plane_protocols_control_plane_protocol_staticd_route_list_src_list_path_list_frr_nexthops_nexthop_mpls_label_stack_entry_create(
        struct nb_cb_create_args *args);
 int routing_control_plane_protocols_control_plane_protocol_staticd_route_list_src_list_path_list_frr_nexthops_nexthop_mpls_label_stack_entry_destroy(
@@ -147,6 +163,10 @@ int routing_control_plane_protocols_name_validate(
 
 #define FRR_STATIC_ROUTE_NHLB_KEY_XPATH "/entry[id='%u']/label"
 
+#define FRR_STATIC_ROUTE_NH_SRV6_SEGS_XPATH "/srv6-segs-stack"
+
+#define FRR_STATIC_ROUTE_NH_SRV6_KEY_SEG_XPATH "/entry[id='%u']/seg"
+
 /* route-list/srclist */
 #define FRR_S_ROUTE_SRC_INFO_KEY_XPATH                                         \
        "/frr-routing:routing/control-plane-protocols/"                        \
index 6673cce108b34cd30d8eefb233aa460bc476e088..5f5f7a1976d5d00da63d3a3640a3318dd1b591a6 100644 (file)
@@ -209,6 +209,98 @@ static bool static_nexthop_destroy(struct nb_cb_destroy_args *args)
        return NB_OK;
 }
 
+static int nexthop_srv6_segs_stack_entry_create(struct nb_cb_create_args *args)
+{
+       struct static_nexthop *nh;
+       uint32_t pos;
+       uint8_t index;
+
+       switch (args->event) {
+       case NB_EV_VALIDATE:
+       case NB_EV_PREPARE:
+       case NB_EV_ABORT:
+               break;
+       case NB_EV_APPLY:
+               nh = nb_running_get_entry(args->dnode, NULL, true);
+               pos = yang_get_list_pos(args->dnode);
+               if (!pos) {
+                       flog_warn(EC_LIB_NB_CB_CONFIG_APPLY,
+                                 "libyang returns invalid seg position");
+                       return NB_ERR;
+               }
+               /* Mapping to array = list-index -1 */
+               index = pos - 1;
+               memset(&nh->snh_seg.seg[index], 0, sizeof(struct in6_addr));
+               nh->snh_seg.num_segs++;
+               break;
+       }
+
+       return NB_OK;
+}
+
+static int nexthop_srv6_segs_stack_entry_destroy(struct nb_cb_destroy_args *args)
+{
+       struct static_nexthop *nh;
+       uint32_t pos;
+       uint8_t index;
+       int old_num_segs;
+
+       switch (args->event) {
+       case NB_EV_VALIDATE:
+       case NB_EV_PREPARE:
+       case NB_EV_ABORT:
+               break;
+       case NB_EV_APPLY:
+               nh = nb_running_get_entry(args->dnode, NULL, true);
+               pos = yang_get_list_pos(args->dnode);
+               if (!pos) {
+                       flog_warn(EC_LIB_NB_CB_CONFIG_APPLY,
+                                 "libyang returns invalid seg position");
+                       return NB_ERR;
+               }
+               index = pos - 1;
+               old_num_segs = nh->snh_seg.num_segs;
+               memset(&nh->snh_seg.seg[index], 0, sizeof(struct in6_addr));
+               nh->snh_seg.num_segs--;
+
+               if (old_num_segs != nh->snh_seg.num_segs)
+                       nh->state = STATIC_START;
+               break;
+       }
+
+       return NB_OK;
+}
+
+static int static_nexthop_srv6_segs_modify(struct nb_cb_modify_args *args)
+{
+       struct static_nexthop *nh;
+       uint32_t pos;
+       uint8_t index;
+       struct in6_addr old_seg;
+       struct in6_addr cli_seg;
+
+       nh = nb_running_get_entry(args->dnode, NULL, true);
+       pos = yang_get_list_pos(lyd_parent(args->dnode));
+       if (!pos) {
+               flog_warn(EC_LIB_NB_CB_CONFIG_APPLY,
+                         "libyang returns invalid seg position");
+               return NB_ERR;
+       }
+       /* Mapping to array = list-index -1 */
+       index = pos - 1;
+
+       old_seg = nh->snh_seg.seg[index];
+       yang_dnode_get_ipv6(&cli_seg, args->dnode, NULL);
+
+       memcpy(&nh->snh_seg.seg[index], &cli_seg, sizeof(struct in6_addr));
+
+       if (memcmp(&old_seg, &nh->snh_seg.seg[index],
+                  sizeof(struct in6_addr)) != 0)
+               nh->state = STATIC_START;
+
+       return NB_OK;
+}
+
 static int nexthop_mpls_label_stack_entry_create(struct nb_cb_create_args *args)
 {
        struct static_nexthop *nh;
@@ -634,6 +726,60 @@ int routing_control_plane_protocols_control_plane_protocol_staticd_route_list_pa
        return NB_OK;
 }
 
+/*
+ * XPath:
+ * /frr-routing:routing/control-plane-protocols/control-plane-protocol/frr-staticd:staticd/route-list/path-list/frr-nexthops/nexthop/srv6-segs-stack/entry
+ */
+int routing_control_plane_protocols_control_plane_protocol_staticd_route_list_path_list_frr_nexthops_nexthop_srv6_segs_stack_entry_create(
+       struct nb_cb_create_args *args)
+{
+       return nexthop_srv6_segs_stack_entry_create(args);
+}
+
+int routing_control_plane_protocols_control_plane_protocol_staticd_route_list_path_list_frr_nexthops_nexthop_srv6_segs_stack_entry_destroy(
+       struct nb_cb_destroy_args *args)
+{
+       return nexthop_srv6_segs_stack_entry_destroy(args);
+}
+
+/*
+ * XPath:
+ * /frr-routing:routing/control-plane-protocols/control-plane-protocol/frr-staticd:staticd/route-list/path-list/frr-nexthops/nexthop/srv6-segs-stack/entry/seg
+ */
+int routing_control_plane_protocols_control_plane_protocol_staticd_route_list_path_list_frr_nexthops_nexthop_srv6_segs_stack_entry_seg_modify(
+       struct nb_cb_modify_args *args)
+{
+       switch (args->event) {
+       case NB_EV_VALIDATE:
+       case NB_EV_PREPARE:
+       case NB_EV_ABORT:
+               break;
+       case NB_EV_APPLY:
+               if (static_nexthop_srv6_segs_modify(args) != NB_OK)
+                       return NB_ERR;
+               break;
+       }
+       return NB_OK;
+}
+
+int routing_control_plane_protocols_control_plane_protocol_staticd_route_list_path_list_frr_nexthops_nexthop_srv6_segs_stack_entry_seg_destroy(
+       struct nb_cb_destroy_args *args)
+{
+       /*
+        * No operation is required in this call back.
+        * nexthop_srv6_segs_stack_entry_destroy() will take care
+        * to reset the seg vaue.
+        */
+       switch (args->event) {
+       case NB_EV_VALIDATE:
+       case NB_EV_PREPARE:
+       case NB_EV_ABORT:
+       case NB_EV_APPLY:
+               break;
+       }
+       return NB_OK;
+}
+
 /*
  * XPath:
  * /frr-routing:routing/control-plane-protocols/control-plane-protocol/frr-staticd:staticd/route-list/path-list/frr-nexthops/nexthop/mpls-label-stack/entry
@@ -1012,6 +1158,60 @@ int routing_control_plane_protocols_control_plane_protocol_staticd_route_list_sr
        return NB_OK;
 }
 
+/*
+ * XPath:
+ * /frr-routing:routing/control-plane-protocols/control-plane-protocol/frr-staticd:staticd/route-list/src-list/path-list/frr-nexthops/nexthop/srv6-segs-stack/entry
+ */
+int routing_control_plane_protocols_control_plane_protocol_staticd_route_list_src_list_path_list_frr_nexthops_nexthop_srv6_segs_stack_entry_create(
+       struct nb_cb_create_args *args)
+{
+       return nexthop_srv6_segs_stack_entry_create(args);
+}
+
+int routing_control_plane_protocols_control_plane_protocol_staticd_route_list_src_list_path_list_frr_nexthops_nexthop_srv6_segs_stack_entry_destroy(
+       struct nb_cb_destroy_args *args)
+{
+       return nexthop_srv6_segs_stack_entry_destroy(args);
+}
+
+/*
+ * XPath:
+ * /frr-routing:routing/control-plane-protocols/control-plane-protocol/frr-staticd:staticd/route-list/src-list/path-list/frr-nexthops/nexthop/srv6-segs-stack/entry/seg
+ */
+int routing_control_plane_protocols_control_plane_protocol_staticd_route_list_src_list_path_list_frr_nexthops_nexthop_srv6_segs_stack_entry_seg_modify(
+       struct nb_cb_modify_args *args)
+{
+       switch (args->event) {
+       case NB_EV_VALIDATE:
+       case NB_EV_PREPARE:
+       case NB_EV_ABORT:
+               break;
+       case NB_EV_APPLY:
+               if (static_nexthop_srv6_segs_modify(args) != NB_OK)
+                       return NB_ERR;
+               break;
+       }
+       return NB_OK;
+}
+
+int routing_control_plane_protocols_control_plane_protocol_staticd_route_list_src_list_path_list_frr_nexthops_nexthop_srv6_segs_stack_entry_seg_destroy(
+       struct nb_cb_destroy_args *args)
+{
+       /*
+        * No operation is required in this call back.
+        * nexthop_mpls_seg_stack_entry_destroy() will take care
+        * to reset the seg vaue.
+        */
+       switch (args->event) {
+       case NB_EV_VALIDATE:
+       case NB_EV_PREPARE:
+       case NB_EV_ABORT:
+       case NB_EV_APPLY:
+               break;
+       }
+       return NB_OK;
+}
+
 /*
  * XPath:
  * /frr-routing:routing/control-plane-protocols/control-plane-protocol/frr-staticd:staticd/route-list/src-list/path-list/frr-nexthops/nexthop/mpls-label-stack/entry