]> git.puffer.fish Git - matthieu/frr.git/commitdiff
ripd: move "rip_distance_table" to the rip structure
authorRenato Westphal <renato@opensourcerouting.org>
Fri, 4 Jan 2019 21:08:10 +0000 (19:08 -0200)
committerRenato Westphal <renato@opensourcerouting.org>
Fri, 18 Jan 2019 18:15:41 +0000 (16:15 -0200)
Signed-off-by: Renato Westphal <renato@opensourcerouting.org>
ripd/rip_northbound.c
ripd/ripd.c
ripd/ripd.h

index 17ba672614f8582e7a1521f82ce0b5a4d48d259d..b0f2b62a5d583c009e2c07bef4fa23c3856dce54 100644 (file)
@@ -173,7 +173,7 @@ static int ripd_instance_distance_source_create(enum nb_event event,
        apply_mask_ipv4(&prefix);
 
        /* 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();
        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);
        rdistance = rn->info;
-       if (rdistance->access_list)
-               free(rdistance->access_list);
        rip_distance_free(rdistance);
-
        rn->info = NULL;
        route_unlock_node(rn);
 
index 1e92fedb632e2d7607fe73180635c18d31036798..49787db2bbc26c19f36f0d74b0b23681b9528952 100644 (file)
@@ -58,6 +58,8 @@ static void rip_output_process(struct connected *, struct sockaddr_in *, int,
                               uint8_t);
 static int rip_triggered_update(struct thread *);
 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,
                                  struct distribute *dist);
@@ -2607,6 +2609,8 @@ int rip_create(int socket)
        rip->neighbor = route_table_init();
        rip->peer_list = list_new();
        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_network = route_table_init();
        rip->passive_nondefault = vector_init(1);
@@ -2744,9 +2748,6 @@ rip_update_default_metric (void)
 }
 #endif
 
-
-struct route_table *rip_distance_table;
-
 struct rip_distance *rip_distance_new(void)
 {
        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)
 {
+       if (rdistance->access_list)
+               free(rdistance->access_list);
        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;
 
-       for (rn = route_top(rip_distance_table); rn; rn = route_next(rn))
-               if ((rdistance = rn->info) != NULL) {
-                       if (rdistance->access_list)
-                               free(rdistance->access_list);
-                       rip_distance_free(rdistance);
-                       rn->info = NULL;
-                       route_unlock_node(rn);
-               }
+       rdistance = node->info;
+       if (rdistance)
+               rip_distance_free(rdistance);
 }
 
 /* Apply RIP information to distance method. */
@@ -2789,7 +2787,7 @@ uint8_t rip_distance_apply(struct rip_info *rinfo)
        p.prefixlen = IPV4_MAX_BITLEN;
 
        /* 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) {
                rdistance = rn->info;
                route_unlock_node(rn);
@@ -2824,7 +2822,7 @@ static void rip_distance_show(struct vty *vty)
        vty_out(vty, "  Distance: (default is %u)\n",
                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 (header) {
                                vty_out(vty,
@@ -3299,7 +3297,7 @@ void rip_clean(void)
        vector_free(rip->passive_nondefault);
        list_delete(&rip->offset_list_master);
        rip_interfaces_clean();
-       rip_distance_reset();
+       route_table_finish(rip->distance_table);
        rip_redistribute_clean();
 
        XFREE(MTYPE_RIP, rip);
@@ -3407,7 +3405,4 @@ void rip_init(void)
        if_rmap_init(RIP_NODE);
        if_rmap_hook_add(rip_if_rmap_update);
        if_rmap_hook_delete(rip_if_rmap_update);
-
-       /* Distance control. */
-       rip_distance_table = route_table_init();
 }
index a75e43d5dff8977521fb3233b1df5761714df0de..6936ad12378696b394d412a2bdd19ee9f5b2c646 100644 (file)
@@ -486,8 +486,6 @@ extern struct thread_master *master;
 DECLARE_HOOK(rip_ifaddr_add, (struct connected * ifc), (ifc))
 DECLARE_HOOK(rip_ifaddr_del, (struct connected * ifc), (ifc))
 
-extern struct route_table *rip_distance_table;
-
 /* Northbound. */
 extern void rip_cli_init(void);
 extern const struct frr_yang_module_info frr_ripd_info;