From c4ab9fd927a148b776890705e3206dc1929bd8ba Mon Sep 17 00:00:00 2001 From: Ryoga Saito Date: Tue, 20 Sep 2022 18:19:13 +0900 Subject: [PATCH] bgpd: allocate SID according to Function length Allocate SID according to Function length to eliminate old SID allocation limits (255). Signed-off-by: Ryoga Saito --- bgpd/bgp_mplsvpn.c | 37 ++++++++++++++++++++++++++++++------- bgpd/bgp_mplsvpn.h | 2 ++ 2 files changed, 32 insertions(+), 7 deletions(-) diff --git a/bgpd/bgp_mplsvpn.c b/bgpd/bgp_mplsvpn.c index ed4eaf2e18..b7dd7e48b3 100644 --- a/bgpd/bgp_mplsvpn.c +++ b/bgpd/bgp_mplsvpn.c @@ -527,34 +527,57 @@ static uint32_t alloc_new_sid(struct bgp *bgp, uint32_t index, struct in6_addr *sid_locator, struct in6_addr *sid) { + int debug = BGP_DEBUG(vpn, VPN_LEAK_LABEL); struct listnode *node; struct srv6_locator_chunk *chunk; bool alloced = false; int label = 0; uint8_t offset = 0; - uint8_t len = 0; + uint8_t func_len = 0, shift_len = 0; + uint32_t index_max = 0; if (!bgp || !sid_locator || !sid) return false; for (ALL_LIST_ELEMENTS_RO(bgp->srv6_locator_chunks, node, chunk)) { + if (chunk->function_bits_length > + BGP_PREFIX_SID_SRV6_MAX_FUNCTION_LENGTH) { + if (debug) + zlog_debug( + "%s: invalid SRv6 Locator chunk (%pFX): Function Length must be less or equal to %d", + __func__, &chunk->prefix, + BGP_PREFIX_SID_SRV6_MAX_FUNCTION_LENGTH); + continue; + } + + index_max = (1 << chunk->function_bits_length) - 1; + + if (index > index_max) { + if (debug) + zlog_debug( + "%s: skipped SRv6 Locator chunk (%pFX): Function Length is too short to support specified index (%u)", + __func__, &chunk->prefix, index); + continue; + } + *sid_locator = chunk->prefix.prefix; *sid = chunk->prefix.prefix; offset = chunk->block_bits_length + chunk->node_bits_length; - len = chunk->function_bits_length ?: 16; + func_len = chunk->function_bits_length; + shift_len = BGP_PREFIX_SID_SRV6_MAX_FUNCTION_LENGTH - func_len; if (index != 0) { - label = index << 12; - transpose_sid(sid, label, offset, len); + label = index << shift_len; + transpose_sid(sid, label, offset, func_len); if (sid_exist(bgp, sid)) return false; alloced = true; break; } - for (size_t i = 1; i < 255; i++) { - label = i << 12; - transpose_sid(sid, label, offset, len); + for (uint32_t i = 1; i < index_max; i++) { + label = i << shift_len; + transpose_sid(sid, label, offset, func_len); if (sid_exist(bgp, sid)) continue; alloced = true; diff --git a/bgpd/bgp_mplsvpn.h b/bgpd/bgp_mplsvpn.h index c5cc7d4294..46607a38c4 100644 --- a/bgpd/bgp_mplsvpn.h +++ b/bgpd/bgp_mplsvpn.h @@ -41,6 +41,8 @@ #define V4_HEADER_OVERLAY \ " Network Next Hop EthTag Overlay Index RouterMac\n" +#define BGP_PREFIX_SID_SRV6_MAX_FUNCTION_LENGTH 20 + extern void bgp_mplsvpn_init(void); extern int bgp_nlri_parse_vpn(struct peer *, struct attr *, struct bgp_nlri *); extern uint32_t decode_label(mpls_label_t *);