summaryrefslogtreecommitdiff
path: root/ospfd/ospf_sr.c
diff options
context:
space:
mode:
authorFredi Raspall <fredi@voltanet.io>2021-05-28 19:22:40 +0200
committerEmanuele Di Pascale <emanuele@voltanet.io>2021-09-28 10:40:32 +0200
commitdaaebd394c6844da354f9897c91144f816392244 (patch)
treeaea06cd9aab725c4bb74607b4a45cc3424f48939 /ospfd/ospf_sr.c
parentc181efbe14cfa71efb3c263f8021c87a5fbfe7e1 (diff)
ospfd: homogenize reservation of SRGB & SRLB
Homogenize the code dealing with SRGBs and SRLBs by defining the same set of utility functions for their reservation. Unify also the logs and don't display function names since the operations are only performed from the same functions. Signed-off-by: Fredi Raspall <fredi@voltanet.io>
Diffstat (limited to 'ospfd/ospf_sr.c')
-rw-r--r--ospfd/ospf_sr.c61
1 files changed, 39 insertions, 22 deletions
diff --git a/ospfd/ospf_sr.c b/ospfd/ospf_sr.c
index cf95b8b778..9faf9708cf 100644
--- a/ospfd/ospf_sr.c
+++ b/ospfd/ospf_sr.c
@@ -278,16 +278,20 @@ static int sr_local_block_init(uint32_t lower_bound, uint32_t upper_bound)
* an error to disable SR until a new SRLB is successfully allocated.
*/
size = upper_bound - lower_bound + 1;
- if (ospf_zebra_request_label_range(lower_bound, size))
+ if (ospf_zebra_request_label_range(lower_bound, size)) {
+ zlog_err("SR: Error reserving SRLB [%u/%u] %u labels",
+ lower_bound, upper_bound, size);
return -1;
+ }
- osr_debug("SR (%s): Got new SRLB [%u/%u]", __func__, lower_bound,
- upper_bound);
+ osr_debug("SR: Got new SRLB [%u/%u], %u labels", lower_bound,
+ upper_bound, size);
/* Initialize the SRLB */
srlb->start = lower_bound;
srlb->end = upper_bound;
srlb->current = 0;
+
/* Compute the needed Used Mark number and allocate them */
srlb->max_block = size / SRLB_BLOCK_SIZE;
if ((size % SRLB_BLOCK_SIZE) != 0)
@@ -299,6 +303,31 @@ static int sr_local_block_init(uint32_t lower_bound, uint32_t upper_bound)
return 0;
}
+static int sr_global_block_init(uint32_t start, uint32_t size)
+{
+ struct sr_global_block *srgb = &OspfSR.srgb;
+
+ /* Check if already configured */
+ if (srgb->reserved)
+ return 0;
+
+ /* request chunk */
+ uint32_t end = start + size - 1;
+ if (ospf_zebra_request_label_range(start, size) < 0) {
+ zlog_err("SR: Error reserving SRGB [%u/%u], %u labels", start,
+ end, size);
+ return -1;
+ }
+
+ osr_debug("SR: Got new SRGB [%u/%u], %u labels", start, end, size);
+
+ /* success */
+ srgb->start = start;
+ srgb->size = size;
+ srgb->reserved = true;
+ return 0;
+}
+
/**
* Remove Segment Routing Local Block.
*
@@ -488,16 +517,11 @@ static int ospf_sr_start(struct ospf *ospf)
* If the allocation fails, return an error to disable SR until a new
* SRLB and/or SRGB are successfully allocated.
*/
- sr_local_block_init(OspfSR.srlb.start, OspfSR.srlb.end);
- if (!OspfSR.srgb.reserved) {
- if (ospf_zebra_request_label_range(OspfSR.srgb.start,
- OspfSR.srgb.size)
- < 0) {
- OspfSR.srgb.reserved = false;
- return -1;
- } else
- OspfSR.srgb.reserved = true;
- }
+ if (sr_local_block_init(OspfSR.srlb.start, OspfSR.srlb.end) < 0)
+ return -1;
+
+ if (sr_global_block_init(OspfSR.srgb.start, OspfSR.srgb.size) < 0)
+ return -1;
/* SR is UP and ready to flood LSA */
OspfSR.status = SR_UP;
@@ -2187,18 +2211,11 @@ static int update_sr_blocks(uint32_t gb_lower, uint32_t gb_upper,
* allocated.
*/
if (gb_changed) {
- if (ospf_zebra_request_label_range(OspfSR.srgb.start,
- OspfSR.srgb.size)
+ if (sr_global_block_init(OspfSR.srgb.start, OspfSR.srgb.size)
< 0) {
- OspfSR.srgb.reserved = false;
ospf_sr_stop();
return -1;
- } else
- OspfSR.srgb.reserved = true;
-
- osr_debug("SR(%s): Got new SRGB [%u/%u]", __func__,
- OspfSR.srgb.start,
- OspfSR.srgb.start + OspfSR.srgb.size - 1);
+ }
}
/* Update Self SR-Node */