From 37a331f8c2ba2ba72bed447fb80ee91a72dae8ec Mon Sep 17 00:00:00 2001 From: Fredi Raspall Date: Sat, 29 May 2021 03:22:04 +0200 Subject: [PATCH] ospfd: fix condition to get label from SRLB The prior condition was wrong since it ended up allowing for labels past the end of the SRLB. Variable 'current' should be in range [0, size-1] for labels not to exceed the SRLB upper boundary. In addition, emit a warning log when all labels in the SRLB have been used. Signed-off-by: Fredi Raspall --- ospfd/ospf_sr.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/ospfd/ospf_sr.c b/ospfd/ospf_sr.c index e19dbc7d3b..60485a770f 100644 --- a/ospfd/ospf_sr.c +++ b/ospfd/ospf_sr.c @@ -385,9 +385,10 @@ mpls_label_t ospf_sr_local_block_request_label(void) mpls_label_t label; uint32_t index; uint32_t pos; + uint32_t size = srlb->end - srlb->start + 1; /* Check if we ran out of available labels */ - if (srlb->current >= srlb->end) + if (srlb->current >= size) return MPLS_INVALID_LABEL; /* Get first available label and mark it used */ @@ -399,7 +400,7 @@ mpls_label_t ospf_sr_local_block_request_label(void) /* Jump to the next free position */ srlb->current++; pos = srlb->current % SRLB_BLOCK_SIZE; - while (srlb->current < srlb->end) { + while (srlb->current < size) { if (pos == 0) index++; if (!((1ULL << pos) & srlb->used_mark[index])) @@ -410,6 +411,10 @@ mpls_label_t ospf_sr_local_block_request_label(void) } } + if (srlb->current == size) + zlog_warn( + "SR: Warning, SRLB is depleted and next label request will fail"); + return label; }