From 8b8861401a3cc4db5854c1225c133ef5c2fc77b8 Mon Sep 17 00:00:00 2001 From: Louis Scalbert Date: Thu, 27 Apr 2023 15:05:42 +0200 Subject: lib: clarify flex-algo mtype Clarify flex-algo MTYPE by creating a specific MTYPE definition to the database of flex-algo information. Signed-off-by: Louis Scalbert --- lib/flex_algo.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'lib/flex_algo.c') diff --git a/lib/flex_algo.c b/lib/flex_algo.c index bafbf8b77..4ad4c233a 100644 --- a/lib/flex_algo.c +++ b/lib/flex_algo.c @@ -17,14 +17,15 @@ #include "flex_algo.h" -DEFINE_MTYPE_STATIC(LIB, FLEX_ALGO, "Flex-Algo Definition"); +DEFINE_MTYPE_STATIC(LIB, FLEX_ALGO_DATABASE, "Flex-Algo database"); +DEFINE_MTYPE_STATIC(LIB, FLEX_ALGO, "Flex-Algo algorithm information"); struct flex_algos *flex_algos_alloc(flex_algo_allocator_t allocator, flex_algo_releaser_t releaser) { struct flex_algos *flex_algos; - flex_algos = XCALLOC(MTYPE_FLEX_ALGO, sizeof(*flex_algos)); + flex_algos = XCALLOC(MTYPE_FLEX_ALGO_DATABASE, sizeof(*flex_algos)); flex_algos->flex_algos = list_new(); flex_algos->allocator = allocator; flex_algos->releaser = releaser; -- cgit v1.2.3 From 8766fceefca9b6763a3a0e276959af86c50a9827 Mon Sep 17 00:00:00 2001 From: Louis Scalbert Date: Thu, 27 Apr 2023 15:11:42 +0200 Subject: lib: move flex_algo_delete() just after flex_algo_alloc() Move flex_algo_delete() just after flex_algo_alloc(). No change on code. Signed-off-by: Louis Scalbert --- lib/flex_algo.c | 38 +++++++++++++++++++------------------- 1 file changed, 19 insertions(+), 19 deletions(-) (limited to 'lib/flex_algo.c') diff --git a/lib/flex_algo.c b/lib/flex_algo.c index 4ad4c233a..612bfbc8c 100644 --- a/lib/flex_algo.c +++ b/lib/flex_algo.c @@ -48,6 +48,25 @@ struct flex_algo *flex_algo_alloc(struct flex_algos *flex_algos, return fa; } +void flex_algo_delete(struct flex_algos *flex_algos, uint8_t algorithm) +{ + struct listnode *node, *nnode; + struct flex_algo *fa; + + for (ALL_LIST_ELEMENTS(flex_algos->flex_algos, node, nnode, fa)) { + if (fa->algorithm != algorithm) + continue; + if (flex_algos->releaser) + flex_algos->releaser(fa->data); + admin_group_term(&fa->admin_group_exclude_any); + admin_group_term(&fa->admin_group_include_any); + admin_group_term(&fa->admin_group_include_all); + listnode_delete(flex_algos->flex_algos, fa); + XFREE(MTYPE_FLEX_ALGO, fa); + return; + } +} + /** * @brief Look up the local flex-algo object by its algorithm number. * @param algorithm flex-algo algorithm number @@ -94,25 +113,6 @@ bool flex_algo_definition_cmp(struct flex_algo *fa1, struct flex_algo *fa2) return true; } -void flex_algo_delete(struct flex_algos *flex_algos, uint8_t algorithm) -{ - struct listnode *node, *nnode; - struct flex_algo *fa; - - for (ALL_LIST_ELEMENTS(flex_algos->flex_algos, node, nnode, fa)) { - if (fa->algorithm != algorithm) - continue; - if (flex_algos->releaser) - flex_algos->releaser(fa->data); - admin_group_term(&fa->admin_group_exclude_any); - admin_group_term(&fa->admin_group_include_any); - admin_group_term(&fa->admin_group_include_all); - listnode_delete(flex_algos->flex_algos, fa); - XFREE(MTYPE_FLEX_ALGO, fa); - return; - } -} - /** * Check SR Algorithm is Flex-Algo * according to RFC9350 section 4 -- cgit v1.2.3 From 5b3e0735cce0f2de964070954a6a0d680a93ceb0 Mon Sep 17 00:00:00 2001 From: Louis Scalbert Date: Thu, 27 Apr 2023 15:16:28 +0200 Subject: lib: dispatch flex_algo_delete() Dispatch flex_algo_delete() to prepare the next commit. Cosmetic change. Signed-off-by: Louis Scalbert --- lib/flex_algo.c | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) (limited to 'lib/flex_algo.c') diff --git a/lib/flex_algo.c b/lib/flex_algo.c index 612bfbc8c..b363b5f27 100644 --- a/lib/flex_algo.c +++ b/lib/flex_algo.c @@ -48,6 +48,19 @@ struct flex_algo *flex_algo_alloc(struct flex_algos *flex_algos, return fa; } +static void _flex_algo_delete(struct flex_algos *flex_algos, + struct flex_algo *fa) +{ + if (flex_algos->releaser) + flex_algos->releaser(fa->data); + admin_group_term(&fa->admin_group_exclude_any); + admin_group_term(&fa->admin_group_include_any); + admin_group_term(&fa->admin_group_include_all); + listnode_delete(flex_algos->flex_algos, fa); + XFREE(MTYPE_FLEX_ALGO, fa); +} + + void flex_algo_delete(struct flex_algos *flex_algos, uint8_t algorithm) { struct listnode *node, *nnode; @@ -56,14 +69,7 @@ void flex_algo_delete(struct flex_algos *flex_algos, uint8_t algorithm) for (ALL_LIST_ELEMENTS(flex_algos->flex_algos, node, nnode, fa)) { if (fa->algorithm != algorithm) continue; - if (flex_algos->releaser) - flex_algos->releaser(fa->data); - admin_group_term(&fa->admin_group_exclude_any); - admin_group_term(&fa->admin_group_include_any); - admin_group_term(&fa->admin_group_include_all); - listnode_delete(flex_algos->flex_algos, fa); - XFREE(MTYPE_FLEX_ALGO, fa); - return; + _flex_algo_delete(flex_algos, fa); } } -- cgit v1.2.3 From 87acad869813e8248bdde876b96a67b31a565fbb Mon Sep 17 00:00:00 2001 From: Louis Scalbert Date: Mon, 24 Apr 2023 18:19:03 +0200 Subject: isisd, lib: fix flex-algo database memory leak at area destruction Free flex-algorithm database memory when an IS-IS area is destroyed. Fixes: 735fb37db1 ("lib: add library for igp flexible-algorithm") Fixes: 7f198e063c ("isisd: add isis flex-algo base interface") Signed-off-by: Louis Scalbert --- isisd/isisd.c | 4 ++++ lib/flex_algo.c | 14 ++++++++++++++ lib/flex_algo.h | 1 + 3 files changed, 19 insertions(+) (limited to 'lib/flex_algo.c') diff --git a/isisd/isisd.c b/isisd/isisd.c index 4b01a18ec..ea304ba5e 100644 --- a/isisd/isisd.c +++ b/isisd/isisd.c @@ -520,6 +520,10 @@ void isis_area_destroy(struct isis_area *area) isis_area_invalidate_routes(area, area->is_type); isis_area_verify_routes(area); +#ifndef FABRICD + flex_algos_free(area->flex_algos); +#endif /* ifndef FABRICD */ + isis_sr_area_term(area); isis_mpls_te_term(area); diff --git a/lib/flex_algo.c b/lib/flex_algo.c index b363b5f27..72cefc551 100644 --- a/lib/flex_algo.c +++ b/lib/flex_algo.c @@ -20,6 +20,9 @@ DEFINE_MTYPE_STATIC(LIB, FLEX_ALGO_DATABASE, "Flex-Algo database"); DEFINE_MTYPE_STATIC(LIB, FLEX_ALGO, "Flex-Algo algorithm information"); +static void _flex_algo_delete(struct flex_algos *flex_algos, + struct flex_algo *fa); + struct flex_algos *flex_algos_alloc(flex_algo_allocator_t allocator, flex_algo_releaser_t releaser) { @@ -32,6 +35,17 @@ struct flex_algos *flex_algos_alloc(flex_algo_allocator_t allocator, return flex_algos; } +void flex_algos_free(struct flex_algos *flex_algos) +{ + struct listnode *node, *nnode; + struct flex_algo *fa; + + for (ALL_LIST_ELEMENTS(flex_algos->flex_algos, node, nnode, fa)) + _flex_algo_delete(flex_algos, fa); + list_delete(&flex_algos->flex_algos); + XFREE(MTYPE_FLEX_ALGO_DATABASE, flex_algos); +} + struct flex_algo *flex_algo_alloc(struct flex_algos *flex_algos, uint8_t algorithm, void *arg) { diff --git a/lib/flex_algo.h b/lib/flex_algo.h index e012f4686..9fc285160 100644 --- a/lib/flex_algo.h +++ b/lib/flex_algo.h @@ -107,6 +107,7 @@ struct flex_algos { */ struct flex_algos *flex_algos_alloc(flex_algo_allocator_t allocator, flex_algo_releaser_t releaser); +void flex_algos_free(struct flex_algos *flex_algos); struct flex_algo *flex_algo_alloc(struct flex_algos *flex_algos, uint8_t algorithm, void *arg); struct flex_algo *flex_algo_lookup(struct flex_algos *flex_algos, -- cgit v1.2.3 From 5c284625963812bc4241e10fe415429c81fce9a3 Mon Sep 17 00:00:00 2001 From: Louis Scalbert Date: Thu, 27 Apr 2023 11:52:03 +0200 Subject: isisd, lib: clarify sizeof on flex-algo memory allocation Use the struct instead of the pointer for flex-algo memory allocation. Signed-off-by: Louis Scalbert --- isisd/isis_flex_algo.c | 2 +- lib/flex_algo.c | 5 +++-- 2 files changed, 4 insertions(+), 3 deletions(-) (limited to 'lib/flex_algo.c') diff --git a/isisd/isis_flex_algo.c b/isisd/isis_flex_algo.c index db6fc348e..ef30987b8 100644 --- a/isisd/isis_flex_algo.c +++ b/isisd/isis_flex_algo.c @@ -45,7 +45,7 @@ void *isis_flex_algo_data_alloc(void *voidarg) struct isis_flex_algo_alloc_arg *arg = voidarg; struct isis_flex_algo_data *data; - data = XCALLOC(MTYPE_FLEX_ALGO, sizeof(*data)); + data = XCALLOC(MTYPE_FLEX_ALGO, sizeof(struct isis_flex_algo_data)); for (int tree = SPFTREE_IPV4; tree < SPFTREE_COUNT; tree++) { for (int level = ISIS_LEVEL1; level <= ISIS_LEVEL2; level++) { diff --git a/lib/flex_algo.c b/lib/flex_algo.c index 72cefc551..b4ae86369 100644 --- a/lib/flex_algo.c +++ b/lib/flex_algo.c @@ -28,7 +28,8 @@ struct flex_algos *flex_algos_alloc(flex_algo_allocator_t allocator, { struct flex_algos *flex_algos; - flex_algos = XCALLOC(MTYPE_FLEX_ALGO_DATABASE, sizeof(*flex_algos)); + flex_algos = + XCALLOC(MTYPE_FLEX_ALGO_DATABASE, sizeof(struct flex_algos)); flex_algos->flex_algos = list_new(); flex_algos->allocator = allocator; flex_algos->releaser = releaser; @@ -51,7 +52,7 @@ struct flex_algo *flex_algo_alloc(struct flex_algos *flex_algos, { struct flex_algo *fa; - fa = XCALLOC(MTYPE_FLEX_ALGO, sizeof(*fa)); + fa = XCALLOC(MTYPE_FLEX_ALGO, sizeof(struct flex_algo)); fa->algorithm = algorithm; if (flex_algos->allocator) fa->data = flex_algos->allocator(arg); -- cgit v1.2.3