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 <fredi@voltanet.io>
This commit is contained in:
Fredi Raspall 2021-05-29 03:22:04 +02:00 committed by Emanuele Di Pascale
parent 4e10b4dfba
commit 37a331f8c2

View File

@ -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;
}