mirror of
https://git.proxmox.com/git/mirror_frr
synced 2025-08-16 10:38:05 +00:00
lib/zebra: remove code duplication in redist_del_instance()
Change redist_check_instance() to return a pointer instead of returning 1 on success. This way this function can be reused in redist_del_instance() instead of duplicating the same logic there. Also, remove unnecessary call to redist_check_instance() in zebra_redistribute_delete(). While here, remove unnecessary cast from void* in redist_add_instance(). Signed-off-by: Renato Westphal <renato@opensourcerouting.org>
This commit is contained in:
parent
4e1cadf011
commit
43e7c3b421
@ -80,20 +80,20 @@ zclient_free (struct zclient *zclient)
|
||||
XFREE (MTYPE_ZCLIENT, zclient);
|
||||
}
|
||||
|
||||
int
|
||||
u_short *
|
||||
redist_check_instance (struct redist_proto *red, u_short instance)
|
||||
{
|
||||
struct listnode *node;
|
||||
u_short *id;
|
||||
|
||||
if (!red->instances)
|
||||
return 0;
|
||||
return NULL;
|
||||
|
||||
for (ALL_LIST_ELEMENTS_RO (red->instances, node, id))
|
||||
if (*id == instance)
|
||||
return 1;
|
||||
return id;
|
||||
|
||||
return 0;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void
|
||||
@ -106,7 +106,7 @@ redist_add_instance (struct redist_proto *red, u_short instance)
|
||||
if (!red->instances)
|
||||
red->instances = list_new();
|
||||
|
||||
in = (u_short *)calloc(1, sizeof(u_short));
|
||||
in = calloc (1, sizeof(u_short));
|
||||
*in = instance;
|
||||
listnode_add (red->instances, in);
|
||||
}
|
||||
@ -114,25 +114,18 @@ redist_add_instance (struct redist_proto *red, u_short instance)
|
||||
void
|
||||
redist_del_instance (struct redist_proto *red, u_short instance)
|
||||
{
|
||||
struct listnode *node;
|
||||
u_short *id = NULL;
|
||||
u_short *id;
|
||||
|
||||
if (!red->instances)
|
||||
id = redist_check_instance (red, instance);
|
||||
if (! id)
|
||||
return;
|
||||
|
||||
for (ALL_LIST_ELEMENTS_RO (red->instances, node, id))
|
||||
if (*id == instance)
|
||||
break;
|
||||
|
||||
if (id)
|
||||
listnode_delete(red->instances, id);
|
||||
if (!red->instances->count)
|
||||
{
|
||||
listnode_delete(red->instances, id);
|
||||
if (!red->instances->count)
|
||||
{
|
||||
red->enabled = 0;
|
||||
list_free(red->instances);
|
||||
red->instances = NULL;
|
||||
}
|
||||
red->enabled = 0;
|
||||
list_free(red->instances);
|
||||
red->instances = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -169,7 +169,7 @@ extern int zclient_socket_connect (struct zclient *);
|
||||
extern void zclient_serv_path_set (char *path);
|
||||
extern const char *zclient_serv_path_get (void);
|
||||
|
||||
extern int redist_check_instance (struct redist_proto *, u_short);
|
||||
extern u_short *redist_check_instance (struct redist_proto *, u_short);
|
||||
extern void redist_add_instance (struct redist_proto *, u_short);
|
||||
extern void redist_del_instance (struct redist_proto *, u_short);
|
||||
|
||||
|
@ -294,10 +294,7 @@ zebra_redistribute_delete (int command, struct zserv *client, int length,
|
||||
* withdraw them when necessary.
|
||||
*/
|
||||
if (instance)
|
||||
{
|
||||
if (redist_check_instance (&client->mi_redist[afi][type], instance))
|
||||
redist_del_instance (&client->mi_redist[afi][type], instance);
|
||||
}
|
||||
redist_del_instance (&client->mi_redist[afi][type], instance);
|
||||
else
|
||||
vrf_bitmap_unset (client->redist[afi][type], zvrf->vrf_id);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user