zebra, test: mark mpls label chunks as dynamic or static

The zebra label manager stores the mpls label chunks,
but does not record if the label request was for a
dynamic or a static chunk.

For all label requests accepted, mark the label chunk
if the 'base' parameter is set to MPLS_LABEL_BASE_ANY,
unmark it otherwise.

Signed-off-by: Philippe Guibert <philippe.guibert@6wind.com>
This commit is contained in:
Philippe Guibert 2023-10-04 14:57:27 +02:00
parent b5808ecc89
commit 9d32589b58
3 changed files with 15 additions and 9 deletions

View file

@ -48,7 +48,7 @@ static int lm_get_chunk_pi(struct label_manager_chunk **lmc,
uint32_t base, vrf_id_t vrf_id)
{
if (base == 0)
*lmc = create_label_chunk(10, 55, 0, 1, 50, 50 + size);
*lmc = create_label_chunk(10, 55, 0, 1, 50, 50 + size, true);
else
*lmc = assign_label_chunk(10, 55, 0, 1, size, base);

View file

@ -184,7 +184,7 @@ void label_manager_init(void)
/* alloc and fill a label chunk */
struct label_manager_chunk *
create_label_chunk(uint8_t proto, unsigned short instance, uint32_t session_id,
uint8_t keep, uint32_t start, uint32_t end)
uint8_t keep, uint32_t start, uint32_t end, bool is_dynamic)
{
/* alloc chunk, fill it and return it */
struct label_manager_chunk *lmc =
@ -196,6 +196,7 @@ create_label_chunk(uint8_t proto, unsigned short instance, uint32_t session_id,
lmc->instance = instance;
lmc->session_id = session_id;
lmc->keep = keep;
lmc->is_dynamic = is_dynamic;
return lmc;
}
@ -254,7 +255,7 @@ assign_specific_label_chunk(uint8_t proto, unsigned short instance,
/* insert chunk between existing chunks */
if (insert_node) {
lmc = create_label_chunk(proto, instance, session_id, keep,
base, end);
base, end, false);
listnode_add_before(lbl_mgr.lc_list, insert_node, lmc);
return lmc;
}
@ -277,7 +278,7 @@ assign_specific_label_chunk(uint8_t proto, unsigned short instance,
}
lmc = create_label_chunk(proto, instance, session_id, keep,
base, end);
base, end, false);
if (last_node)
listnode_add_before(lbl_mgr.lc_list, last_node, lmc);
else
@ -288,7 +289,7 @@ assign_specific_label_chunk(uint8_t proto, unsigned short instance,
/* create a new chunk past all the existing ones and link at
* tail */
lmc = create_label_chunk(proto, instance, session_id, keep,
base, end);
base, end, false);
listnode_add(lbl_mgr.lc_list, lmc);
return lmc;
}
@ -315,7 +316,10 @@ assign_label_chunk(uint8_t proto, unsigned short instance, uint32_t session_id,
struct listnode *node;
uint32_t prev_end = MPLS_LABEL_UNRESERVED_MIN;
/* handle chunks request with a specific base label */
/* handle chunks request with a specific base label
* - static label requests: BGP hardset value, Pathd
* - segment routing label requests
*/
if (base != MPLS_LABEL_BASE_ANY)
return assign_specific_label_chunk(proto, instance, session_id,
keep, size, base);
@ -331,6 +335,7 @@ assign_label_chunk(uint8_t proto, unsigned short instance, uint32_t session_id,
lmc->instance = instance;
lmc->session_id = session_id;
lmc->keep = keep;
lmc->is_dynamic = true;
return lmc;
}
/* check if we hadve a "hole" behind us that we can squeeze into
@ -338,7 +343,7 @@ assign_label_chunk(uint8_t proto, unsigned short instance, uint32_t session_id,
if ((lmc->start > prev_end) && (lmc->start - prev_end > size)) {
lmc = create_label_chunk(proto, instance, session_id,
keep, prev_end + 1,
prev_end + size);
prev_end + size, true);
listnode_add_before(lbl_mgr.lc_list, node, lmc);
return lmc;
}
@ -364,7 +369,7 @@ assign_label_chunk(uint8_t proto, unsigned short instance, uint32_t session_id,
/* create chunk and link at tail */
lmc = create_label_chunk(proto, instance, session_id, keep, start_free,
start_free + size - 1);
start_free + size - 1, true);
listnode_add(lbl_mgr.lc_list, lmc);
return lmc;
}

View file

@ -42,6 +42,7 @@ struct label_manager_chunk {
unsigned short instance;
uint32_t session_id;
uint8_t keep;
uint8_t is_dynamic; /* Tell if chunk is dynamic or static */
uint32_t start; /* First label of the chunk */
uint32_t end; /* Last label of the chunk */
};
@ -82,7 +83,7 @@ int lm_client_connect_response(uint8_t proto, uint16_t instance,
/* convenience function to allocate an lmc to be consumed by the above API */
struct label_manager_chunk *
create_label_chunk(uint8_t proto, unsigned short instance, uint32_t session_id,
uint8_t keep, uint32_t start, uint32_t end);
uint8_t keep, uint32_t start, uint32_t end, bool is_dynamic);
void delete_label_chunk(void *val);
/* register/unregister callbacks for hooks */