ripngd: move "ripng_offset_list_master" to the ripng structure

Signed-off-by: Renato Westphal <renato@opensourcerouting.org>
This commit is contained in:
Renato Westphal 2019-01-04 19:08:10 -02:00
parent 56bf1cb2c3
commit 26c6be9314
3 changed files with 16 additions and 29 deletions

View File

@ -33,8 +33,6 @@
#include "ripngd/ripngd.h" #include "ripngd/ripngd.h"
static struct list *ripng_offset_list_master;
#define OFFSET_LIST_IN_NAME(O) ((O)->direct[RIPNG_OFFSET_LIST_IN].alist_name) #define OFFSET_LIST_IN_NAME(O) ((O)->direct[RIPNG_OFFSET_LIST_IN].alist_name)
#define OFFSET_LIST_IN_METRIC(O) ((O)->direct[RIPNG_OFFSET_LIST_IN].metric) #define OFFSET_LIST_IN_METRIC(O) ((O)->direct[RIPNG_OFFSET_LIST_IN].metric)
@ -48,14 +46,14 @@ struct ripng_offset_list *ripng_offset_list_new(const char *ifname)
new = XCALLOC(MTYPE_RIPNG_OFFSET_LIST, new = XCALLOC(MTYPE_RIPNG_OFFSET_LIST,
sizeof(struct ripng_offset_list)); sizeof(struct ripng_offset_list));
new->ifname = strdup(ifname); new->ifname = strdup(ifname);
listnode_add_sort(ripng_offset_list_master, new); listnode_add_sort(ripng->offset_list_master, new);
return new; return new;
} }
void ripng_offset_list_del(struct ripng_offset_list *offset) void ripng_offset_list_del(struct ripng_offset_list *offset)
{ {
listnode_delete(ripng_offset_list_master, offset); listnode_delete(ripng->offset_list_master, offset);
if (OFFSET_LIST_IN_NAME(offset)) if (OFFSET_LIST_IN_NAME(offset))
free(OFFSET_LIST_IN_NAME(offset)); free(OFFSET_LIST_IN_NAME(offset));
if (OFFSET_LIST_OUT_NAME(offset)) if (OFFSET_LIST_OUT_NAME(offset))
@ -69,7 +67,8 @@ struct ripng_offset_list *ripng_offset_list_lookup(const char *ifname)
struct ripng_offset_list *offset; struct ripng_offset_list *offset;
struct listnode *node, *nnode; struct listnode *node, *nnode;
for (ALL_LIST_ELEMENTS(ripng_offset_list_master, node, nnode, offset)) { for (ALL_LIST_ELEMENTS(ripng->offset_list_master, node, nnode,
offset)) {
if (strcmp(offset->ifname, ifname) == 0) if (strcmp(offset->ifname, ifname) == 0)
return offset; return offset;
} }
@ -153,26 +152,7 @@ int ripng_offset_list_apply_out(struct prefix_ipv6 *p, struct interface *ifp,
return 0; return 0;
} }
static int offset_list_cmp(struct ripng_offset_list *o1, int offset_list_cmp(struct ripng_offset_list *o1, struct ripng_offset_list *o2)
struct ripng_offset_list *o2)
{ {
return strcmp(o1->ifname, o2->ifname); return strcmp(o1->ifname, o2->ifname);
} }
void ripng_offset_init(void)
{
ripng_offset_list_master = list_new();
ripng_offset_list_master->cmp =
(int (*)(void *, void *))offset_list_cmp;
ripng_offset_list_master->del = (void (*)(void *))ripng_offset_list_del;
}
void ripng_offset_clean(void)
{
list_delete(&ripng_offset_list_master);
ripng_offset_list_master = list_new();
ripng_offset_list_master->cmp =
(int (*)(void *, void *))offset_list_cmp;
ripng_offset_list_master->del = (void (*)(void *))ripng_offset_list_del;
}

View File

@ -1811,6 +1811,11 @@ int ripng_create(int socket)
ripng->enable_if = vector_init(1); ripng->enable_if = vector_init(1);
ripng->enable_network = agg_table_init(); ripng->enable_network = agg_table_init();
ripng->passive_interface = vector_init(1); ripng->passive_interface = vector_init(1);
ripng->offset_list_master = list_new();
ripng->offset_list_master->cmp =
(int (*)(void *, void *))offset_list_cmp;
ripng->offset_list_master->del =
(void (*)(void *))ripng_offset_list_del;
/* Distribute list install. */ /* Distribute list install. */
ripng->distribute_ctx = distribute_list_ctx_create( ripng->distribute_ctx = distribute_list_ctx_create(
@ -2471,7 +2476,7 @@ void ripng_clean()
vector_free(ripng->enable_if); vector_free(ripng->enable_if);
agg_table_finish(ripng->enable_network); agg_table_finish(ripng->enable_network);
vector_free(ripng->passive_interface); vector_free(ripng->passive_interface);
ripng_offset_clean(); list_delete(&ripng->offset_list_master);
ripng_interface_clean(); ripng_interface_clean();
ripng_redistribute_clean(); ripng_redistribute_clean();
@ -2583,7 +2588,6 @@ void ripng_init()
/* Route-map for interface. */ /* Route-map for interface. */
ripng_route_map_init(); ripng_route_map_init();
ripng_offset_init();
route_map_add_hook(ripng_routemap_update); route_map_add_hook(ripng_routemap_update);
route_map_delete_hook(ripng_routemap_update); route_map_delete_hook(ripng_routemap_update);

View File

@ -120,6 +120,9 @@ struct ripng {
/* Vector to store passive-interface name. */ /* Vector to store passive-interface name. */
vector passive_interface; vector passive_interface;
/* RIPng offset-lists. */
struct list *offset_list_master;
/* RIPng threads. */ /* RIPng threads. */
struct thread *t_read; struct thread *t_read;
struct thread *t_write; struct thread *t_write;
@ -387,8 +390,8 @@ extern int ripng_offset_list_apply_in(struct prefix_ipv6 *, struct interface *,
uint8_t *); uint8_t *);
extern int ripng_offset_list_apply_out(struct prefix_ipv6 *, struct interface *, extern int ripng_offset_list_apply_out(struct prefix_ipv6 *, struct interface *,
uint8_t *); uint8_t *);
extern void ripng_offset_init(void); extern int offset_list_cmp(struct ripng_offset_list *o1,
extern void ripng_offset_clean(void); struct ripng_offset_list *o2);
extern int ripng_route_rte(struct ripng_info *rinfo); extern int ripng_route_rte(struct ripng_info *rinfo);
extern struct ripng_info *ripng_info_new(void); extern struct ripng_info *ripng_info_new(void);