]> git.puffer.fish Git - mirror/frr.git/commitdiff
staticd: Add nb callbacks for SRv6 encap behavior
authorCarmine Scarpitta <cscarpit@cisco.com>
Thu, 20 Feb 2025 10:25:54 +0000 (11:25 +0100)
committerCarmine Scarpitta <cscarpit@cisco.com>
Wed, 30 Apr 2025 16:54:43 +0000 (16:54 +0000)
This commit adds the northbound callbacks to handle the SRv6
encapsulation behavior associated with an SRv6 route.

Signed-off-by: Carmine Scarpitta <cscarpit@cisco.com>
staticd/static_nb.c
staticd/static_nb.h
staticd/static_nb_config.c

index 60dc3dc788c7775888dbc702de6672dcbed6c2b7..0fe97b358864732024bd43d9f73869408f67972a 100644 (file)
@@ -78,6 +78,13 @@ 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_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/srv6-segs-stack/encap-behavior",
+                       .cbs = {
+                               .modify = routing_control_plane_protocols_control_plane_protocol_staticd_route_list_path_list_frr_nexthops_nexthop_srv6_segs_stack_encap_behavior_modify,
+                               .destroy = routing_control_plane_protocols_control_plane_protocol_staticd_route_list_path_list_frr_nexthops_nexthop_srv6_segs_stack_encap_behavior_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 = {
index 6106f90018d3a62c536edf9f85bcda84ddab21d1..313cb02aa4a355b85c2de0053bde7a3a972d1ef0 100644 (file)
@@ -49,6 +49,10 @@ 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_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_srv6_segs_stack_encap_behavior_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_encap_behavior_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(
@@ -167,6 +171,8 @@ int routing_control_plane_protocols_name_validate(
 
 #define FRR_STATIC_ROUTE_NH_SRV6_KEY_SEG_XPATH "/entry[id='%u']/seg"
 
+#define FRR_STATIC_ROUTE_NH_SRV6_ENCAP_BEHAVIOR_XPATH "/encap-behavior"
+
 /* route-list/frr-nexthops */
 #define FRR_DEL_S_ROUTE_NH_KEY_XPATH                                           \
        FRR_STATIC_ROUTE_INFO_KEY_XPATH                                        \
index 0a1d05ad809143198a817f32acb0fbf940522b58..5648b37e97a2a34a4a77a5256a7a42ca93f59173 100644 (file)
@@ -307,6 +307,62 @@ static int static_nexthop_srv6_segs_modify(struct nb_cb_modify_args *args)
        return NB_OK;
 }
 
+static int static_nexthop_srv6_encap_behavior_modify(struct nb_cb_modify_args *args)
+{
+       struct static_nexthop *nh;
+       enum srv6_headend_behavior old_encap_behavior;
+       const char *encap_behavior_str;
+
+       switch (args->event) {
+       case NB_EV_VALIDATE:
+               encap_behavior_str = yang_dnode_get_string(args->dnode, NULL);
+               if (!strmatch(encap_behavior_str, "ietf-srv6-types:H.Encaps") &&
+                   !strmatch(encap_behavior_str, "ietf-srv6-types:H.Encaps.Red")) {
+                       snprintf(args->errmsg, args->errmsg_len,
+                                "%% Unsupported encap behavior: %s", encap_behavior_str);
+                       return NB_ERR_VALIDATION;
+               }
+               break;
+       case NB_EV_PREPARE:
+       case NB_EV_ABORT:
+               break;
+       case NB_EV_APPLY:
+               nh = nb_running_get_entry(args->dnode, NULL, true);
+               old_encap_behavior = nh->snh_seg.encap_behavior;
+               encap_behavior_str = yang_dnode_get_string(args->dnode, NULL);
+               if (strmatch(encap_behavior_str, "ietf-srv6-types:H.Encaps"))
+                       nh->snh_seg.encap_behavior = SRV6_HEADEND_BEHAVIOR_H_ENCAPS;
+               else if (strmatch(encap_behavior_str, "ietf-srv6-types:H.Encaps.Red"))
+                       nh->snh_seg.encap_behavior = SRV6_HEADEND_BEHAVIOR_H_ENCAPS_RED;
+               else {
+                       snprintf(args->errmsg, args->errmsg_len,
+                                "%% Unsupported encap behavior: %s", encap_behavior_str);
+                       return NB_ERR;
+               }
+
+               if (old_encap_behavior != nh->snh_seg.encap_behavior)
+                       nh->state = STATIC_START;
+               break;
+       }
+
+       return NB_OK;
+}
+
+static int static_nexthop_srv6_encap_behavior_destroy(struct nb_cb_destroy_args *args)
+{
+       struct static_nexthop *nh;
+       enum srv6_headend_behavior old_encap_behavior;
+
+       nh = nb_running_get_entry(args->dnode, NULL, true);
+       old_encap_behavior = nh->snh_seg.encap_behavior;
+       nh->snh_seg.encap_behavior = SRV6_HEADEND_BEHAVIOR_H_ENCAPS;
+
+       if (old_encap_behavior != nh->snh_seg.encap_behavior)
+               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;
@@ -812,6 +868,42 @@ 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/encap-behavior
+ */
+int routing_control_plane_protocols_control_plane_protocol_staticd_route_list_path_list_frr_nexthops_nexthop_srv6_segs_stack_encap_behavior_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_encap_behavior_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_encap_behavior_destroy(
+       struct nb_cb_destroy_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_encap_behavior_destroy(args) != NB_OK)
+                       return NB_ERR;
+               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