diff options
author | Pat Ruddy <pat@voltanet.io> | 2020-12-17 11:41:07 +0100 |
---|---|---|
committer | Pat Ruddy <pat@voltanet.io> | 2021-01-04 15:29:44 +0100 |
commit | 992dd67ec76de375b967b408c26f9c9f9e0608c5 (patch) | |
tree | beb593cd4aea8b15d6fbbab0cf0fcd76ca20ee09 /bgpd/bgp_labelpool.c | |
parent | zebra: labelmanager could return reserved labels (diff) | |
download | frr-992dd67ec76de375b967b408c26f9c9f9e0608c5.tar.xz frr-992dd67ec76de375b967b408c26f9c9f9e0608c5.zip |
bgpd: refactor label allocation code
To prepare for fixing an issue where labels do not get released back
to the labelpool when the route is deleted some refactoring is
necessary. There are 2 parts to this.
1. restructure the code to remove the circular nature of label
allocations via the labelpool and decouple the label type decision
from the notification fo the FEC.
The code to notify the FEC association to zebra has been split out
into a separate function so that it can be called from the synchronous
path (for registration of index-based labels and de-registration of all
labels), and from the asynchronous path where we need to wait for a
callback from the labelpool code with a label allocation.
The decision about whether we are using an index-based label or an
allocated label is reflected in the state of the BGP_NODE_LABEL_REQUESTED
flag so the checks on the path_info in the labelpool callback code are
no longer required.
2. change the owned of a labelpool allocated label from the path info
structure to the bgp_dest structure. This allows labels to be released
(in a subsequent commit) when the owner (bgp_dest) goes away.
Signed-off-by: Pat Ruddy <pat@voltanet.io>
Diffstat (limited to 'bgpd/bgp_labelpool.c')
-rw-r--r-- | bgpd/bgp_labelpool.c | 49 |
1 files changed, 25 insertions, 24 deletions
diff --git a/bgpd/bgp_labelpool.c b/bgpd/bgp_labelpool.c index 4386ef69c..c5d8bbec3 100644 --- a/bgpd/bgp_labelpool.c +++ b/bgpd/bgp_labelpool.c @@ -182,18 +182,18 @@ void bgp_lp_init(struct thread_master *master, struct labelpool *pool) lp->callback_q->spec.max_retries = 0; } -/* check if a label callback was for a BGP LU path, and if so, unlock it */ +/* check if a label callback was for a BGP LU node, and if so, unlock it */ static void check_bgp_lu_cb_unlock(struct lp_lcb *lcb) { if (lcb->type == LP_TYPE_BGP_LU) - bgp_path_info_unlock(lcb->labelid); + bgp_dest_unlock_node(lcb->labelid); } -/* check if a label callback was for a BGP LU path, and if so, lock it */ +/* check if a label callback was for a BGP LU node, and if so, lock it */ static void check_bgp_lu_cb_lock(struct lp_lcb *lcb) { if (lcb->type == LP_TYPE_BGP_LU) - bgp_path_info_lock(lcb->labelid); + bgp_dest_lock_node(lcb->labelid); } void bgp_lp_finish(void) @@ -356,7 +356,7 @@ void bgp_lp_get( q->labelid = lcb->labelid; q->allocated = true; - /* if this is a LU request, lock path info before queueing */ + /* if this is a LU request, lock node before queueing */ check_bgp_lu_cb_lock(lcb); work_queue_add(lp->callback_q, q); @@ -384,7 +384,7 @@ void bgp_lp_get( sizeof(struct lp_fifo)); lf->lcb = *lcb; - /* if this is a LU request, lock path info before queueing */ + /* if this is a LU request, lock node before queueing */ check_bgp_lu_cb_lock(lcb); lp_fifo_add_tail(&lp->requests, lf); @@ -461,7 +461,7 @@ void bgp_lp_event_chunk(uint8_t keep, uint32_t first, uint32_t last) zlog_debug("%s: labelid %p: request no longer in effect", __func__, labelid); } - /* if this was a BGP_LU request, unlock path info node + /* if this was a BGP_LU request, unlock node */ check_bgp_lu_cb_unlock(lcb); goto finishedrequest; @@ -475,7 +475,7 @@ void bgp_lp_event_chunk(uint8_t keep, uint32_t first, uint32_t last) __func__, labelid, lcb->label, lcb->label, lcb); } - /* if this was a BGP_LU request, unlock path info node + /* if this was a BGP_LU request, unlock node */ check_bgp_lu_cb_unlock(lcb); @@ -667,7 +667,7 @@ DEFUN(show_bgp_labelpool_ledger, show_bgp_labelpool_ledger_cmd, bool uj = use_json(argc, argv); json_object *json = NULL, *json_elem = NULL; struct lp_lcb *lcb = NULL; - struct bgp_path_info *pi; + struct bgp_dest *dest; void *cursor = NULL; const struct prefix *p; int rc, count; @@ -692,9 +692,9 @@ DEFUN(show_bgp_labelpool_ledger, show_bgp_labelpool_ledger_cmd, vty_out(vty, "---------------------------\n"); } - for (rc = skiplist_next(lp->ledger, (void **)&pi, (void **)&lcb, + for (rc = skiplist_next(lp->ledger, (void **)&dest, (void **)&lcb, &cursor); - !rc; rc = skiplist_next(lp->ledger, (void **)&pi, (void **)&lcb, + !rc; rc = skiplist_next(lp->ledger, (void **)&dest, (void **)&lcb, &cursor)) { if (uj) { json_elem = json_object_new_object(); @@ -702,7 +702,7 @@ DEFUN(show_bgp_labelpool_ledger, show_bgp_labelpool_ledger_cmd, } switch (lcb->type) { case LP_TYPE_BGP_LU: - if (!CHECK_FLAG(pi->flags, BGP_PATH_VALID)) + if (!CHECK_FLAG(dest->flags, BGP_NODE_LABEL_REQUESTED)) if (uj) { json_object_string_add( json_elem, "prefix", "INVALID"); @@ -713,7 +713,7 @@ DEFUN(show_bgp_labelpool_ledger, show_bgp_labelpool_ledger_cmd, "INVALID", lcb->label); else { char buf[PREFIX2STR_BUFFER]; - p = bgp_dest_get_prefix(pi->net); + p = bgp_dest_get_prefix(dest); prefix2str(p, buf, sizeof(buf)); if (uj) { json_object_string_add(json_elem, @@ -755,7 +755,7 @@ DEFUN(show_bgp_labelpool_inuse, show_bgp_labelpool_inuse_cmd, { bool uj = use_json(argc, argv); json_object *json = NULL, *json_elem = NULL; - struct bgp_path_info *pi; + struct bgp_dest *dest; mpls_label_t label; struct lp_lcb *lcb; void *cursor = NULL; @@ -785,11 +785,11 @@ DEFUN(show_bgp_labelpool_inuse, show_bgp_labelpool_inuse_cmd, vty_out(vty, "Prefix Label\n"); vty_out(vty, "---------------------------\n"); } - for (rc = skiplist_next(lp->inuse, (void **)&label, (void **)&pi, + for (rc = skiplist_next(lp->inuse, (void **)&label, (void **)&dest, &cursor); - !rc; rc = skiplist_next(lp->ledger, (void **)&label, (void **)&pi, - &cursor)) { - if (skiplist_search(lp->ledger, pi, (void **)&lcb)) + !rc; rc = skiplist_next(lp->ledger, (void **)&label, + (void **)&dest, &cursor)) { + if (skiplist_search(lp->ledger, dest, (void **)&lcb)) continue; if (uj) { @@ -799,7 +799,7 @@ DEFUN(show_bgp_labelpool_inuse, show_bgp_labelpool_inuse_cmd, switch (lcb->type) { case LP_TYPE_BGP_LU: - if (!CHECK_FLAG(pi->flags, BGP_PATH_VALID)) + if (!CHECK_FLAG(dest->flags, BGP_NODE_LABEL_REQUESTED)) if (uj) { json_object_string_add( json_elem, "prefix", "INVALID"); @@ -810,7 +810,7 @@ DEFUN(show_bgp_labelpool_inuse, show_bgp_labelpool_inuse_cmd, label); else { char buf[PREFIX2STR_BUFFER]; - p = bgp_dest_get_prefix(pi->net); + p = bgp_dest_get_prefix(dest); prefix2str(p, buf, sizeof(buf)); if (uj) { json_object_string_add(json_elem, @@ -850,7 +850,7 @@ DEFUN(show_bgp_labelpool_requests, show_bgp_labelpool_requests_cmd, { bool uj = use_json(argc, argv); json_object *json = NULL, *json_elem = NULL; - struct bgp_path_info *pi; + struct bgp_dest *dest; const struct prefix *p; char buf[PREFIX2STR_BUFFER]; struct lp_fifo *item, *next; @@ -878,21 +878,22 @@ DEFUN(show_bgp_labelpool_requests, show_bgp_labelpool_requests_cmd, for (item = lp_fifo_first(&lp->requests); item; item = next) { next = lp_fifo_next_safe(&lp->requests, item); - pi = item->lcb.labelid; + dest = item->lcb.labelid; if (uj) { json_elem = json_object_new_object(); json_object_array_add(json, json_elem); } switch (item->lcb.type) { case LP_TYPE_BGP_LU: - if (!CHECK_FLAG(pi->flags, BGP_PATH_VALID)) { + if (!CHECK_FLAG(dest->flags, + BGP_NODE_LABEL_REQUESTED)) { if (uj) json_object_string_add( json_elem, "prefix", "INVALID"); else vty_out(vty, "INVALID\n"); } else { - p = bgp_dest_get_prefix(pi->net); + p = bgp_dest_get_prefix(dest); prefix2str(p, buf, sizeof(buf)); if (uj) json_object_string_add(json_elem, |