From 34d0bb974d2c37dfc95c42331c3b1b53696de54f Mon Sep 17 00:00:00 2001 From: Carmine Scarpitta Date: Thu, 20 Feb 2025 11:25:54 +0100 Subject: [PATCH] staticd: Add nb callbacks for SRv6 encap behavior This commit adds the northbound callbacks to handle the SRv6 encapsulation behavior associated with an SRv6 route. Signed-off-by: Carmine Scarpitta --- staticd/static_nb.c | 7 +++ staticd/static_nb.h | 6 +++ staticd/static_nb_config.c | 92 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 105 insertions(+) diff --git a/staticd/static_nb.c b/staticd/static_nb.c index 60dc3dc788..0fe97b3588 100644 --- a/staticd/static_nb.c +++ b/staticd/static_nb.c @@ -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 = { diff --git a/staticd/static_nb.h b/staticd/static_nb.h index 6106f90018..313cb02aa4 100644 --- a/staticd/static_nb.h +++ b/staticd/static_nb.h @@ -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 \ diff --git a/staticd/static_nb_config.c b/staticd/static_nb_config.c index 0a1d05ad80..5648b37e97 100644 --- a/staticd/static_nb_config.c +++ b/staticd/static_nb_config.c @@ -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 -- 2.39.5