diff options
| author | Philippe Guibert <philippe.guibert@6wind.com> | 2023-02-28 14:17:17 +0100 | 
|---|---|---|
| committer | Philippe Guibert <philippe.guibert@6wind.com> | 2023-03-22 12:06:29 +0100 | 
| commit | 4a3243116be562b5eb083b3effd62b72f29ed87a (patch) | |
| tree | 520e98937a6e1c44467a24b0c211a45de45cf0c8 /bgpd/bgp_labelpool.c | |
| parent | bb3b811305ffc3c0998438b48a003c815c859293 (diff) | |
bgpd: add the bgp_label_per_nexthop_cache struct and apis
This commit introduces the necessary structs and apis to
create the cache entries that store the label information
associated to a given nexthop.
A hash table is created in each BGP instance for all the
AFIs: IPv4 and IPv6. That hash table is initialised.
An API to look and/or create an entry based on a given
nexthop.
Signed-off-by: Philippe Guibert <philippe.guibert@6wind.com>
Diffstat (limited to 'bgpd/bgp_labelpool.c')
| -rw-r--r-- | bgpd/bgp_labelpool.c | 55 | 
1 files changed, 55 insertions, 0 deletions
diff --git a/bgpd/bgp_labelpool.c b/bgpd/bgp_labelpool.c index 3e43a41daf..4d70199938 100644 --- a/bgpd/bgp_labelpool.c +++ b/bgpd/bgp_labelpool.c @@ -23,6 +23,7 @@  #include "bgpd/bgp_debug.h"  #include "bgpd/bgp_errors.h"  #include "bgpd/bgp_route.h" +#include "bgpd/bgp_zebra.h"  #define BGP_LABELPOOL_ENABLE_TESTS 0 @@ -1558,3 +1559,57 @@ void bgp_lp_vty_init(void)  	install_element(ENABLE_NODE, &clear_labelpool_perf_test_cmd);  #endif /* BGP_LABELPOOL_ENABLE_TESTS */  } + +DEFINE_MTYPE_STATIC(BGPD, LABEL_PER_NEXTHOP_CACHE, +		    "BGP Label Per Nexthop entry"); + +/* The nexthops values are compared to + * find in the tree the appropriate cache entry + */ +int bgp_label_per_nexthop_cache_cmp(const struct bgp_label_per_nexthop_cache *a, +				    const struct bgp_label_per_nexthop_cache *b) +{ +	return prefix_cmp(&a->nexthop, &b->nexthop); +} + +struct bgp_label_per_nexthop_cache * +bgp_label_per_nexthop_new(struct bgp_label_per_nexthop_cache_head *tree, +			  struct prefix *nexthop) +{ +	struct bgp_label_per_nexthop_cache *blnc; + +	blnc = XCALLOC(MTYPE_LABEL_PER_NEXTHOP_CACHE, +		       sizeof(struct bgp_label_per_nexthop_cache)); +	blnc->tree = tree; +	blnc->label = MPLS_INVALID_LABEL; +	prefix_copy(&blnc->nexthop, nexthop); +	LIST_INIT(&(blnc->paths)); +	bgp_label_per_nexthop_cache_add(tree, blnc); + +	return blnc; +} + +struct bgp_label_per_nexthop_cache * +bgp_label_per_nexthop_find(struct bgp_label_per_nexthop_cache_head *tree, +			   struct prefix *nexthop) +{ +	struct bgp_label_per_nexthop_cache blnc = {}; + +	if (!tree) +		return NULL; + +	memcpy(&blnc.nexthop, nexthop, sizeof(struct prefix)); +	return bgp_label_per_nexthop_cache_find(tree, &blnc); +} + +void bgp_label_per_nexthop_free(struct bgp_label_per_nexthop_cache *blnc) +{ +	if (blnc->label != MPLS_INVALID_LABEL) { +		bgp_zebra_send_nexthop_label(ZEBRA_MPLS_LABELS_DELETE, +					     blnc->label, ZEBRA_LSP_BGP, +					     &blnc->nexthop); +		bgp_lp_release(LP_TYPE_NEXTHOP, blnc, blnc->label); +	} +	bgp_label_per_nexthop_cache_del(blnc->tree, blnc); +	XFREE(MTYPE_LABEL_PER_NEXTHOP_CACHE, blnc); +}  | 
