diff options
| author | Russ White <russ@riw.us> | 2020-08-10 15:31:35 -0400 | 
|---|---|---|
| committer | GitHub <noreply@github.com> | 2020-08-10 15:31:35 -0400 | 
| commit | 271ac28499e6be25a1c42b9ea138e782548893f6 (patch) | |
| tree | 8ae825feb8b044871d331a803b4e7de596f95ef0 /zebra/zapi_msg.c | |
| parent | 8e3ac40d2cb5f38a2804d1b19eeb77aeebd7c7af (diff) | |
| parent | 31f937fb43f4920d14de6193de440279fbd5d99e (diff) | |
Merge pull request #6783 from opensourcerouting/feature/sr-te
lib, zebra: Add SR-TE policy infrastructure to zebra
Diffstat (limited to 'zebra/zapi_msg.c')
| -rw-r--r-- | zebra/zapi_msg.c | 114 | 
1 files changed, 114 insertions, 0 deletions
diff --git a/zebra/zapi_msg.c b/zebra/zapi_msg.c index 48aa566136..6dd197f010 100644 --- a/zebra/zapi_msg.c +++ b/zebra/zapi_msg.c @@ -60,6 +60,7 @@  #include "zebra/zebra_mlag.h"  #include "zebra/connected.h"  #include "zebra/zebra_opaque.h" +#include "zebra/zebra_srte.h"  /* Encoding helpers -------------------------------------------------------- */ @@ -1651,6 +1652,11 @@ static void zread_route_add(ZAPI_HANDLER_ARGS)  			return;  		} +		if (CHECK_FLAG(api.message, ZAPI_MESSAGE_SRTE)) { +			SET_FLAG(nexthop->flags, NEXTHOP_FLAG_SRTE); +			nexthop->srte_color = api_nh->srte_color; +		} +  		/* MPLS labels for BGP-LU or Segment Routing */  		if (CHECK_FLAG(api_nh->flags, ZAPI_NEXTHOP_FLAG_LABEL)  		    && api_nh->type != NEXTHOP_TYPE_IFINDEX @@ -1730,6 +1736,11 @@ static void zread_route_add(ZAPI_HANDLER_ARGS)  			nexthop->backup_num = 0;  		} +		if (CHECK_FLAG(api.message, ZAPI_MESSAGE_SRTE)) { +			SET_FLAG(nexthop->flags, NEXTHOP_FLAG_SRTE); +			nexthop->srte_color = api_nh->srte_color; +		} +  		/* MPLS labels for BGP-LU or Segment Routing */  		if (CHECK_FLAG(api_nh->flags, ZAPI_NEXTHOP_FLAG_LABEL)  		    && api_nh->type != NEXTHOP_TYPE_IFINDEX @@ -2209,6 +2220,107 @@ static void zread_mpls_labels_replace(ZAPI_HANDLER_ARGS)  	mpls_zapi_labels_process(true, zvrf, &zl);  } +static void zread_sr_policy_set(ZAPI_HANDLER_ARGS) +{ +	struct stream *s; +	struct zapi_sr_policy zp; +	struct zapi_srte_tunnel *zt; +	struct zebra_sr_policy *policy; + +	/* Get input stream.  */ +	s = msg; +	if (zapi_sr_policy_decode(s, &zp) < 0) { +		if (IS_ZEBRA_DEBUG_RECV) +			zlog_debug("%s: Unable to decode zapi_sr_policy sent", +				   __PRETTY_FUNCTION__); +		return; +	} +	zt = &zp.segment_list; +	if (zt->label_num < 1) { +		if (IS_ZEBRA_DEBUG_RECV) +			zlog_debug( +				"%s: SR-TE tunnel must contain at least one label", +				__PRETTY_FUNCTION__); +		return; +	} + +	if (!mpls_enabled) +		return; + +	policy = zebra_sr_policy_find(zp.color, &zp.endpoint); +	if (!policy) +		policy = zebra_sr_policy_add(zp.color, &zp.endpoint, zp.name); +	/* TODO: per-VRF list of SR-TE policies. */ +	policy->zvrf = zvrf; + +	zebra_sr_policy_validate(policy, &zp.segment_list); +} + +static void zread_sr_policy_delete(ZAPI_HANDLER_ARGS) +{ +	struct stream *s; +	struct zapi_sr_policy zp; +	struct zebra_sr_policy *policy; + +	/* Get input stream.  */ +	s = msg; +	if (zapi_sr_policy_decode(s, &zp) < 0) { +		if (IS_ZEBRA_DEBUG_RECV) +			zlog_debug("%s: Unable to decode zapi_sr_policy sent", +				   __PRETTY_FUNCTION__); +		return; +	} + +	if (!mpls_enabled) +		return; + +	policy = zebra_sr_policy_find(zp.color, &zp.endpoint); +	if (!policy) { +		if (IS_ZEBRA_DEBUG_RECV) +			zlog_debug("%s: Unable to find SR-TE policy", +				   __PRETTY_FUNCTION__); +		return; +	} + +	zebra_sr_policy_del(policy); +} + +int zsend_sr_policy_notify_status(uint32_t color, struct ipaddr *endpoint, +				  char *name, int status) +{ +	struct zserv *client; +	struct stream *s; + +	client = zserv_find_client(ZEBRA_ROUTE_SRTE, 0); +	if (!client) { +		if (IS_ZEBRA_DEBUG_PACKET) +			zlog_debug( +				"Not notifying pathd about policy %s" +				" status change to %d", +				name, status); +		return 0; +	} + +	if (IS_ZEBRA_DEBUG_PACKET) +		zlog_debug( +			"Notifying pathd about policy %s status change" +			" to %d", +			name, status); + +	s = stream_new(ZEBRA_MAX_PACKET_SIZ); +	stream_reset(s); + +	zclient_create_header(s, ZEBRA_SR_POLICY_NOTIFY_STATUS, VRF_DEFAULT); +	stream_putl(s, color); +	stream_put_ipaddr(s, endpoint); +	stream_write(s, name, SRTE_POLICY_NAME_MAX_LENGTH); +	stream_putl(s, status); + +	stream_putw_at(s, 0, stream_get_endp(s)); + +	return zserv_send_message(client, s); +} +  /* Send response to a table manager connect request to client */  static void zread_table_manager_connect(struct zserv *client,  					struct stream *msg, vrf_id_t vrf_id) @@ -2908,6 +3020,8 @@ void (*const zserv_handlers[])(ZAPI_HANDLER_ARGS) = {  	[ZEBRA_BFD_CLIENT_REGISTER] = zebra_ptm_bfd_client_register,  	[ZEBRA_INTERFACE_ENABLE_RADV] = zebra_interface_radv_enable,  	[ZEBRA_INTERFACE_DISABLE_RADV] = zebra_interface_radv_disable, +	[ZEBRA_SR_POLICY_SET] = zread_sr_policy_set, +	[ZEBRA_SR_POLICY_DELETE] = zread_sr_policy_delete,  	[ZEBRA_MPLS_LABELS_ADD] = zread_mpls_labels_add,  	[ZEBRA_MPLS_LABELS_DELETE] = zread_mpls_labels_delete,  	[ZEBRA_MPLS_LABELS_REPLACE] = zread_mpls_labels_replace,  | 
