summaryrefslogtreecommitdiffstats
path: root/lib/flex_algo.c
diff options
context:
space:
mode:
Diffstat (limited to 'lib/flex_algo.c')
-rw-r--r--lib/flex_algo.c66
1 files changed, 44 insertions, 22 deletions
diff --git a/lib/flex_algo.c b/lib/flex_algo.c
index efeacb5a0..f48117ff1 100644
--- a/lib/flex_algo.c
+++ b/lib/flex_algo.c
@@ -17,26 +17,42 @@
#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");
+
+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)
{
struct flex_algos *flex_algos;
- flex_algos = XCALLOC(MTYPE_FLEX_ALGO, 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;
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)
{
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);
@@ -47,6 +63,31 @@ 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;
+ struct flex_algo *fa;
+
+ for (ALL_LIST_ELEMENTS(flex_algos->flex_algos, node, nnode, fa)) {
+ if (fa->algorithm != algorithm)
+ continue;
+ _flex_algo_delete(flex_algos, fa);
+ }
+}
+
/**
* @brief Look up the local flex-algo object by its algorithm number.
* @param algorithm flex-algo algorithm number
@@ -99,25 +140,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