mirror of
https://git.proxmox.com/git/mirror_frr
synced 2025-07-27 10:04:18 +00:00
lib: abstract instance redistribution management
Use the linked list `del` callback to free memory instead of manually calling. Signed-off-by: Rafael Zalamena <rzalamena@opensourcerouting.org>
This commit is contained in:
parent
44c6bbeadb
commit
dfdc12e164
@ -104,6 +104,11 @@ void zclient_free(struct zclient *zclient)
|
|||||||
XFREE(MTYPE_ZCLIENT, zclient);
|
XFREE(MTYPE_ZCLIENT, zclient);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void redist_free_instance(void *data)
|
||||||
|
{
|
||||||
|
XFREE(MTYPE_REDIST_INST, data);
|
||||||
|
}
|
||||||
|
|
||||||
unsigned short *redist_check_instance(struct redist_proto *red,
|
unsigned short *redist_check_instance(struct redist_proto *red,
|
||||||
unsigned short instance)
|
unsigned short instance)
|
||||||
{
|
{
|
||||||
@ -126,8 +131,10 @@ void redist_add_instance(struct redist_proto *red, unsigned short instance)
|
|||||||
|
|
||||||
red->enabled = 1;
|
red->enabled = 1;
|
||||||
|
|
||||||
if (!red->instances)
|
if (!red->instances) {
|
||||||
red->instances = list_new();
|
red->instances = list_new();
|
||||||
|
red->instances->del = redist_free_instance;
|
||||||
|
}
|
||||||
|
|
||||||
in = XMALLOC(MTYPE_REDIST_INST, sizeof(unsigned short));
|
in = XMALLOC(MTYPE_REDIST_INST, sizeof(unsigned short));
|
||||||
*in = instance;
|
*in = instance;
|
||||||
@ -143,7 +150,7 @@ void redist_del_instance(struct redist_proto *red, unsigned short instance)
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
listnode_delete(red->instances, id);
|
listnode_delete(red->instances, id);
|
||||||
XFREE(MTYPE_REDIST_INST, id);
|
red->instances->del(id);
|
||||||
if (!red->instances->count) {
|
if (!red->instances->count) {
|
||||||
red->enabled = 0;
|
red->enabled = 0;
|
||||||
list_delete(&red->instances);
|
list_delete(&red->instances);
|
||||||
@ -152,14 +159,10 @@ void redist_del_instance(struct redist_proto *red, unsigned short instance)
|
|||||||
|
|
||||||
void redist_del_all_instances(struct redist_proto *red)
|
void redist_del_all_instances(struct redist_proto *red)
|
||||||
{
|
{
|
||||||
struct listnode *ln, *nn;
|
|
||||||
unsigned short *id;
|
|
||||||
|
|
||||||
if (!red->instances)
|
if (!red->instances)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
for (ALL_LIST_ELEMENTS(red->instances, ln, nn, id))
|
list_delete(&red->instances);
|
||||||
redist_del_instance(red, *id);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Stop zebra client services. */
|
/* Stop zebra client services. */
|
||||||
|
Loading…
Reference in New Issue
Block a user