ripd: move "rip_distance_table" 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 c08a21077f
commit 2826309c11
3 changed files with 15 additions and 25 deletions

View file

@ -173,7 +173,7 @@ static int ripd_instance_distance_source_create(enum nb_event event,
apply_mask_ipv4(&prefix); apply_mask_ipv4(&prefix);
/* Get RIP distance node. */ /* Get RIP distance node. */
rn = route_node_get(rip_distance_table, (struct prefix *)&prefix); rn = route_node_get(rip->distance_table, (struct prefix *)&prefix);
rn->info = rip_distance_new(); rn->info = rip_distance_new();
yang_dnode_set_entry(dnode, rn); yang_dnode_set_entry(dnode, rn);
@ -191,10 +191,7 @@ static int ripd_instance_distance_source_delete(enum nb_event event,
rn = yang_dnode_get_entry(dnode, true); rn = yang_dnode_get_entry(dnode, true);
rdistance = rn->info; rdistance = rn->info;
if (rdistance->access_list)
free(rdistance->access_list);
rip_distance_free(rdistance); rip_distance_free(rdistance);
rn->info = NULL; rn->info = NULL;
route_unlock_node(rn); route_unlock_node(rn);

View file

@ -58,6 +58,8 @@ static void rip_output_process(struct connected *, struct sockaddr_in *, int,
uint8_t); uint8_t);
static int rip_triggered_update(struct thread *); static int rip_triggered_update(struct thread *);
static int rip_update_jitter(unsigned long); static int rip_update_jitter(unsigned long);
static void rip_distance_table_node_cleanup(struct route_table *table,
struct route_node *node);
static void rip_distribute_update(struct distribute_ctx *ctx, static void rip_distribute_update(struct distribute_ctx *ctx,
struct distribute *dist); struct distribute *dist);
@ -2607,6 +2609,8 @@ int rip_create(int socket)
rip->neighbor = route_table_init(); rip->neighbor = route_table_init();
rip->peer_list = list_new(); rip->peer_list = list_new();
rip->peer_list->cmp = (int (*)(void *, void *))rip_peer_list_cmp; rip->peer_list->cmp = (int (*)(void *, void *))rip_peer_list_cmp;
rip->distance_table = route_table_init();
rip->distance_table->cleanup = rip_distance_table_node_cleanup;
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);
@ -2744,9 +2748,6 @@ rip_update_default_metric (void)
} }
#endif #endif
struct route_table *rip_distance_table;
struct rip_distance *rip_distance_new(void) struct rip_distance *rip_distance_new(void)
{ {
return XCALLOC(MTYPE_RIP_DISTANCE, sizeof(struct rip_distance)); return XCALLOC(MTYPE_RIP_DISTANCE, sizeof(struct rip_distance));
@ -2754,22 +2755,19 @@ struct rip_distance *rip_distance_new(void)
void rip_distance_free(struct rip_distance *rdistance) void rip_distance_free(struct rip_distance *rdistance)
{ {
if (rdistance->access_list)
free(rdistance->access_list);
XFREE(MTYPE_RIP_DISTANCE, rdistance); XFREE(MTYPE_RIP_DISTANCE, rdistance);
} }
static void rip_distance_reset(void) static void rip_distance_table_node_cleanup(struct route_table *table,
struct route_node *node)
{ {
struct route_node *rn;
struct rip_distance *rdistance; struct rip_distance *rdistance;
for (rn = route_top(rip_distance_table); rn; rn = route_next(rn)) rdistance = node->info;
if ((rdistance = rn->info) != NULL) { if (rdistance)
if (rdistance->access_list) rip_distance_free(rdistance);
free(rdistance->access_list);
rip_distance_free(rdistance);
rn->info = NULL;
route_unlock_node(rn);
}
} }
/* Apply RIP information to distance method. */ /* Apply RIP information to distance method. */
@ -2789,7 +2787,7 @@ uint8_t rip_distance_apply(struct rip_info *rinfo)
p.prefixlen = IPV4_MAX_BITLEN; p.prefixlen = IPV4_MAX_BITLEN;
/* Check source address. */ /* Check source address. */
rn = route_node_match(rip_distance_table, (struct prefix *)&p); rn = route_node_match(rip->distance_table, (struct prefix *)&p);
if (rn) { if (rn) {
rdistance = rn->info; rdistance = rn->info;
route_unlock_node(rn); route_unlock_node(rn);
@ -2824,7 +2822,7 @@ static void rip_distance_show(struct vty *vty)
vty_out(vty, " Distance: (default is %u)\n", vty_out(vty, " Distance: (default is %u)\n",
rip->distance ? rip->distance : ZEBRA_RIP_DISTANCE_DEFAULT); rip->distance ? rip->distance : ZEBRA_RIP_DISTANCE_DEFAULT);
for (rn = route_top(rip_distance_table); rn; rn = route_next(rn)) for (rn = route_top(rip->distance_table); rn; rn = route_next(rn))
if ((rdistance = rn->info) != NULL) { if ((rdistance = rn->info) != NULL) {
if (header) { if (header) {
vty_out(vty, vty_out(vty,
@ -3299,7 +3297,7 @@ void rip_clean(void)
vector_free(rip->passive_nondefault); vector_free(rip->passive_nondefault);
list_delete(&rip->offset_list_master); list_delete(&rip->offset_list_master);
rip_interfaces_clean(); rip_interfaces_clean();
rip_distance_reset(); route_table_finish(rip->distance_table);
rip_redistribute_clean(); rip_redistribute_clean();
XFREE(MTYPE_RIP, rip); XFREE(MTYPE_RIP, rip);
@ -3407,7 +3405,4 @@ void rip_init(void)
if_rmap_init(RIP_NODE); if_rmap_init(RIP_NODE);
if_rmap_hook_add(rip_if_rmap_update); if_rmap_hook_add(rip_if_rmap_update);
if_rmap_hook_delete(rip_if_rmap_update); if_rmap_hook_delete(rip_if_rmap_update);
/* Distance control. */
rip_distance_table = route_table_init();
} }

View file

@ -486,8 +486,6 @@ extern struct thread_master *master;
DECLARE_HOOK(rip_ifaddr_add, (struct connected * ifc), (ifc)) DECLARE_HOOK(rip_ifaddr_add, (struct connected * ifc), (ifc))
DECLARE_HOOK(rip_ifaddr_del, (struct connected * ifc), (ifc)) DECLARE_HOOK(rip_ifaddr_del, (struct connected * ifc), (ifc))
extern struct route_table *rip_distance_table;
/* Northbound. */ /* Northbound. */
extern void rip_cli_init(void); extern void rip_cli_init(void);
extern const struct frr_yang_module_info frr_ripd_info; extern const struct frr_yang_module_info frr_ripd_info;