diff options
| -rw-r--r-- | isisd/isis_te.c | 2 | ||||
| -rw-r--r-- | isisd/isis_tlvs.c | 17 | ||||
| -rw-r--r-- | isisd/isis_tlvs.h | 11 | ||||
| -rw-r--r-- | lib/link_state.h | 5 | ||||
| -rw-r--r-- | lib/segment_routing.c | 30 | ||||
| -rw-r--r-- | lib/segment_routing.h | 42 | ||||
| -rw-r--r-- | lib/subdir.am | 2 | 
7 files changed, 86 insertions, 23 deletions
diff --git a/isisd/isis_te.c b/isisd/isis_te.c index 4e180ead61..70b0633fa5 100644 --- a/isisd/isis_te.c +++ b/isisd/isis_te.c @@ -611,7 +611,7 @@ static struct ls_vertex *lsp_to_vertex(struct ls_ted *ted, struct isis_lsp *lsp)  				lnode.srgb.flag = cap->srgb.flags;  				lnode.srgb.lower_bound = cap->srgb.lower_bound;  				lnode.srgb.range_size = cap->srgb.range_size; -				for (int i = 0; i < SR_ALGORITHM_COUNT; i++) +				for (int i = 0; i < LIB_LS_SR_ALGO_COUNT; i++)  					lnode.algo[i] = cap->algo[i];  			} diff --git a/isisd/isis_tlvs.c b/isisd/isis_tlvs.c index 3b6db0ee17..15f927969d 100644 --- a/isisd/isis_tlvs.c +++ b/isisd/isis_tlvs.c @@ -3552,9 +3552,8 @@ static void format_tlv_router_cap(const struct isis_router_cap *router_cap,  		for (int i = 0; i < SR_ALGORITHM_COUNT; i++)  			if (router_cap->algo[i] != SR_ALGORITHM_UNSET)  				sbuf_push(buf, indent, "    %u: %s\n", i, -					  router_cap->algo[i] == 0 -						  ? "SPF" -						  : "Strict SPF"); +					  sr_algorithm_string( +						  router_cap->algo[i]));  	}  	/* Segment Routing Node MSD as per RFC8491 section #2 */ @@ -3573,7 +3572,7 @@ static int pack_tlv_router_cap(const struct isis_router_cap *router_cap,  {  	size_t tlv_len = ISIS_ROUTER_CAP_SIZE;  	size_t len_pos; -	uint8_t nb_algo; +	uint16_t nb_algo;  	if (!router_cap)  		return 0; @@ -3757,13 +3756,9 @@ static int unpack_tlv_router_cap(enum isis_tlv_context context,  			if (length == 0)  				break;  			/* Only 2 algorithms are supported: SPF & Strict SPF */ -			stream_get(&rcap->algo, s, -				   length > SR_ALGORITHM_COUNT -					   ? SR_ALGORITHM_COUNT -					   : length); -			if (length > SR_ALGORITHM_COUNT) -				stream_forward_getp( -					s, length - SR_ALGORITHM_COUNT); +			stream_get(&rcap->algo, s, length > 2 ? 2 : length); +			if (length > 2) +				stream_forward_getp(s, length - 2);  			break;  		case ISIS_SUBTLV_SRLB:  			/* Check that SRLB is correctly formated */ diff --git a/isisd/isis_tlvs.h b/isisd/isis_tlvs.h index 51058f1af1..454288c45e 100644 --- a/isisd/isis_tlvs.h +++ b/isisd/isis_tlvs.h @@ -9,6 +9,7 @@  #ifndef ISIS_TLVS_H  #define ISIS_TLVS_H +#include "segment_routing.h"  #include "openbsd-tree.h"  #include "prefix.h" @@ -177,16 +178,6 @@ struct isis_lan_adj_sid {  #define ISIS_ROUTER_CAP_FLAG_D	0x02  #define ISIS_ROUTER_CAP_SIZE	5 -/* Number of supported algorithm for Segment Routing. - * Right now only 2 have been standardized: - *  - 0: SPF - *  - 1: Strict SPF - */ -#define SR_ALGORITHM_COUNT	2 -#define SR_ALGORITHM_SPF	0 -#define SR_ALGORITHM_STRICT_SPF	1 -#define SR_ALGORITHM_UNSET	255 -  #define MSD_TYPE_BASE_MPLS_IMPOSITION  0x01  #define MSD_TLV_SIZE            2 diff --git a/lib/link_state.h b/lib/link_state.h index b75f035431..3d2ed7a872 100644 --- a/lib/link_state.h +++ b/lib/link_state.h @@ -92,6 +92,9 @@ struct ls_node_id {   */  extern int ls_node_id_same(struct ls_node_id i1, struct ls_node_id i2); +/* Supported number of algorithm by the link-state library */ +#define LIB_LS_SR_ALGO_COUNT 2 +  /* Link State flags to indicate which Node parameters are valid */  #define LS_NODE_UNSET		0x0000  #define LS_NODE_NAME		0x0001 @@ -123,7 +126,7 @@ struct ls_node {  		uint32_t lower_bound;		/* MPLS label lower bound */  		uint32_t range_size;		/* MPLS label range size */  	} srlb; -	uint8_t algo[2];		/* Segment Routing Algorithms */ +	uint8_t algo[LIB_LS_SR_ALGO_COUNT]; /* Segment Routing Algorithms */  	uint8_t msd;			/* Maximum Stack Depth */  }; diff --git a/lib/segment_routing.c b/lib/segment_routing.c new file mode 100644 index 0000000000..f45a64d29a --- /dev/null +++ b/lib/segment_routing.c @@ -0,0 +1,30 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/********************************************************************* + * Copyright 2022 Hiroki Shirokura, LINE Corporation + * Copyright 2022 Masakazu Asama + * Copyright 2022 6WIND S.A. + * + * segment_routing.c: Segment-Routing Library + * + * Authors + * ------- + * Hiroki Shirokura + * Masakazu Asama + * Louis Scalbert + */ + +#include "segment_routing.h" + +const char *sr_algorithm_string(uint8_t algo) +{ +	switch (algo) { +	case SR_ALGORITHM_SPF: +		return "SPF"; +	case SR_ALGORITHM_STRICT_SPF: +		return "Strict SPF"; +	case SR_ALGORITHM_UNSET: +		return "Unset"; +	default: +		return algo >= SR_ALGORITHM_FLEX_MIN ? "Flex-Algo" : "Unknown"; +	} +} diff --git a/lib/segment_routing.h b/lib/segment_routing.h new file mode 100644 index 0000000000..5e71466bf1 --- /dev/null +++ b/lib/segment_routing.h @@ -0,0 +1,42 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/********************************************************************* + * Copyright 2022 Hiroki Shirokura, LINE Corporation + * Copyright 2022 Masakazu Asama + * Copyright 2022 6WIND S.A. + * + * segment_routing.h: Segment-Routing Library + * + * Authors + * ------- + * Hiroki Shirokura + * Masakazu Asama + * Louis Scalbert + */ + +#ifndef _FRR_SR_H +#define _FRR_SR_H + +#include <zebra.h> + +#ifdef __cplusplus +extern "C" { +#endif + +/* + * IGP Algorithm Types + * https://www.iana.org/assignments/igp-parameters/igp-parameters.xhtml + */ +#define SR_ALGORITHM_SPF 0	/* RFC8665 */ +#define SR_ALGORITHM_STRICT_SPF 1 /* RFC8665 */ +#define SR_ALGORITHM_UNSET 127    /* FRRouting defined */ +#define SR_ALGORITHM_FLEX_MIN 128 /* RFC9350 Flex-Algorithm */ +#define SR_ALGORITHM_FLEX_MAX 255 /* RFC9350 Flex-Algorithm */ +#define SR_ALGORITHM_COUNT 256 + +const char *sr_algorithm_string(uint8_t algo); + +#ifdef __cplusplus +} +#endif + +#endif /* _FRR_SR_H */ diff --git a/lib/subdir.am b/lib/subdir.am index dcc58b31ae..318c09663e 100644 --- a/lib/subdir.am +++ b/lib/subdir.am @@ -99,6 +99,7 @@ lib_libfrr_la_SOURCES = \  	lib/sockopt.c \  	lib/sockunion.c \  	lib/spf_backoff.c \ +	lib/segment_routing.c \  	lib/srcdest_table.c \  	lib/stream.c \  	lib/strformat.c \ @@ -282,6 +283,7 @@ pkginclude_HEADERS += \  	lib/sockopt.h \  	lib/sockunion.h \  	lib/spf_backoff.h \ +	lib/segment_routing.h \  	lib/srcdest_table.h \  	lib/srte.h \  	lib/stream.h \  | 
