ripd: move "rip_offset_list_master" to the rip 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 29e897ad33
commit 3f21c8c4cb
3 changed files with 13 additions and 27 deletions

View file

@ -29,8 +29,6 @@
#include "ripd/ripd.h" #include "ripd/ripd.h"
static struct list *rip_offset_list_master;
#define OFFSET_LIST_IN_NAME(O) ((O)->direct[RIP_OFFSET_LIST_IN].alist_name) #define OFFSET_LIST_IN_NAME(O) ((O)->direct[RIP_OFFSET_LIST_IN].alist_name)
#define OFFSET_LIST_IN_METRIC(O) ((O)->direct[RIP_OFFSET_LIST_IN].metric) #define OFFSET_LIST_IN_METRIC(O) ((O)->direct[RIP_OFFSET_LIST_IN].metric)
@ -43,14 +41,14 @@ struct rip_offset_list *rip_offset_list_new(const char *ifname)
offset = XCALLOC(MTYPE_RIP_OFFSET_LIST, sizeof(struct rip_offset_list)); offset = XCALLOC(MTYPE_RIP_OFFSET_LIST, sizeof(struct rip_offset_list));
offset->ifname = strdup(ifname); offset->ifname = strdup(ifname);
listnode_add_sort(rip_offset_list_master, offset); listnode_add_sort(rip->offset_list_master, offset);
return offset; return offset;
} }
void offset_list_del(struct rip_offset_list *offset) void offset_list_del(struct rip_offset_list *offset)
{ {
listnode_delete(rip_offset_list_master, offset); listnode_delete(rip->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))
@ -64,7 +62,7 @@ struct rip_offset_list *rip_offset_list_lookup(const char *ifname)
struct rip_offset_list *offset; struct rip_offset_list *offset;
struct listnode *node, *nnode; struct listnode *node, *nnode;
for (ALL_LIST_ELEMENTS(rip_offset_list_master, node, nnode, offset)) { for (ALL_LIST_ELEMENTS(rip->offset_list_master, node, nnode, offset)) {
if (strcmp(offset->ifname, ifname) == 0) if (strcmp(offset->ifname, ifname) == 0)
return offset; return offset;
} }
@ -146,24 +144,7 @@ int rip_offset_list_apply_out(struct prefix_ipv4 *p, struct interface *ifp,
return 0; return 0;
} }
static int offset_list_cmp(struct rip_offset_list *o1, int offset_list_cmp(struct rip_offset_list *o1, struct rip_offset_list *o2)
struct rip_offset_list *o2)
{ {
return strcmp(o1->ifname, o2->ifname); return strcmp(o1->ifname, o2->ifname);
} }
void rip_offset_init()
{
rip_offset_list_master = list_new();
rip_offset_list_master->cmp = (int (*)(void *, void *))offset_list_cmp;
rip_offset_list_master->del = (void (*)(void *))offset_list_del;
}
void rip_offset_clean()
{
list_delete(&rip_offset_list_master);
rip_offset_list_master = list_new();
rip_offset_list_master->cmp = (int (*)(void *, void *))offset_list_cmp;
rip_offset_list_master->del = (void (*)(void *))offset_list_del;
}

View file

@ -2697,6 +2697,9 @@ int rip_create(int socket)
rip->enable_interface = vector_init(1); rip->enable_interface = vector_init(1);
rip->enable_network = route_table_init(); rip->enable_network = route_table_init();
rip->passive_nondefault = vector_init(1); rip->passive_nondefault = vector_init(1);
rip->offset_list_master = list_new();
rip->offset_list_master->cmp = (int (*)(void *, void *))offset_list_cmp;
rip->offset_list_master->del = (void (*)(void *))offset_list_del;
/* Distribute list install. */ /* Distribute list install. */
rip->distribute_ctx = rip->distribute_ctx =
@ -3381,7 +3384,7 @@ void rip_clean(void)
vector_free(rip->enable_interface); vector_free(rip->enable_interface);
route_table_finish(rip->enable_network); route_table_finish(rip->enable_network);
vector_free(rip->passive_nondefault); vector_free(rip->passive_nondefault);
rip_offset_clean(); list_delete(&rip->offset_list_master);
rip_interfaces_clean(); rip_interfaces_clean();
rip_distance_reset(); rip_distance_reset();
rip_redistribute_clean(); rip_redistribute_clean();
@ -3484,7 +3487,6 @@ void rip_init(void)
/* Route-map */ /* Route-map */
rip_route_map_init(); rip_route_map_init();
rip_offset_init();
route_map_add_hook(rip_routemap_update); route_map_add_hook(rip_routemap_update);
route_map_delete_hook(rip_routemap_update); route_map_delete_hook(rip_routemap_update);

View file

@ -156,6 +156,9 @@ struct rip {
/* Vector to store passive-interface name. */ /* Vector to store passive-interface name. */
vector passive_nondefault; vector passive_nondefault;
/* RIP offset-lists. */
struct list *offset_list_master;
/* For redistribute route map. */ /* For redistribute route map. */
struct { struct {
char *name; char *name;
@ -462,8 +465,8 @@ extern int rip_offset_list_apply_in(struct prefix_ipv4 *, struct interface *,
uint32_t *); uint32_t *);
extern int rip_offset_list_apply_out(struct prefix_ipv4 *, struct interface *, extern int rip_offset_list_apply_out(struct prefix_ipv4 *, struct interface *,
uint32_t *); uint32_t *);
extern void rip_offset_init(void); extern int offset_list_cmp(struct rip_offset_list *o1,
extern void rip_offset_clean(void); struct rip_offset_list *o2);
/* YANG notifications */ /* YANG notifications */
extern void ripd_notif_send_auth_type_failure(const char *ifname); extern void ripd_notif_send_auth_type_failure(const char *ifname);