diff options
| author | Russ White <russ@riw.us> | 2023-09-20 23:09:35 -0400 | 
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-09-20 23:09:35 -0400 | 
| commit | 90d19d1489c7237acaad7dfa79af2080301ad60d (patch) | |
| tree | 59d903742e50c7d36edf22cfcd98cff736fbf063 /staticd/static_nb_config.c | |
| parent | 0c9aabe76040dff04c76b127f92087236a623451 (diff) | |
| parent | 9f3ceabd490a4ab90dd8e8b74b4d16117edd8c10 (diff) | |
Merge pull request #14089 from dmytroshytyi-6WIND/srv6_multiple_segs_sids
 bgpd,doc,lib,sharpd,staticd,yang,zebra: SRv6 multiple segs SIDs
Diffstat (limited to 'staticd/static_nb_config.c')
| -rw-r--r-- | staticd/static_nb_config.c | 200 | 
1 files changed, 200 insertions, 0 deletions
diff --git a/staticd/static_nb_config.c b/staticd/static_nb_config.c index 520a3ee2c1..ede2e38754 100644 --- a/staticd/static_nb_config.c +++ b/staticd/static_nb_config.c @@ -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; @@ -643,6 +735,60 @@ int routing_control_plane_protocols_control_plane_protocol_staticd_route_list_pa  /*   * 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   */  int routing_control_plane_protocols_control_plane_protocol_staticd_route_list_path_list_frr_nexthops_nexthop_mpls_label_stack_entry_create( @@ -1021,6 +1167,60 @@ int routing_control_plane_protocols_control_plane_protocol_staticd_route_list_sr  /*   * 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   */  int routing_control_plane_protocols_control_plane_protocol_staticd_route_list_src_list_path_list_frr_nexthops_nexthop_mpls_label_stack_entry_create(  | 
