]> git.puffer.fish Git - matthieu/frr.git/commitdiff
ripngd: simplify cleaning up of routing instance
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)
* Call ripng_clean() only when RIPng is configured, this way we can
  remove one indentation level from this function.
* ripng_redistribute_clean() is only called on shutdown, so there's
  no need to call ripng_redistribute_withdraw() there since the RIPng
  table is already cleaned up elsewhere.
* Deallocate the ripng structure only at the end of the function. This
  prepares the ground for the next commits where all global variables
  will be moved to the ripng structure.

Signed-off-by: Renato Westphal <renato@opensourcerouting.org>
ripngd/ripng_main.c
ripngd/ripng_zebra.c
ripngd/ripngd.c

index 10e19efe77f6962fc39cea79f2378adcb0a52f1c..b7e5739ed2e683785ccec1a5e757993c6b71ece4 100644 (file)
@@ -82,7 +82,8 @@ static void sigint(void)
 {
        zlog_notice("Terminating on signal");
 
-       ripng_clean();
+       if (ripng)
+               ripng_clean();
 
        ripng_zebra_stop();
        frr_fini();
index e3f42edf51266ddf6cafb1a401ca06482349fbdc..7b74561973376628e8debb5dbdfb067119d03458 100644 (file)
@@ -173,9 +173,6 @@ void ripng_redistribute_clean()
                                                VRF_DEFAULT);
 
                vrf_bitmap_unset(zclient->redist[AFI_IP6][i], VRF_DEFAULT);
-
-               /* Remove the routes from RIP table. */
-               ripng_redistribute_withdraw(i);
        }
 }
 
index 03383bc26db0b251d52b914a9fad53a049e9a613..13e3606946514b169ceb78c0be7ca7eabe2f2d78 100644 (file)
@@ -1026,9 +1026,6 @@ void ripng_redistribute_withdraw(int type)
        struct ripng_info *rinfo = NULL;
        struct list *list = NULL;
 
-       if (!ripng)
-               return;
-
        for (rp = agg_route_top(ripng->table); rp; rp = agg_route_next(rp))
                if ((list = rp->info) != NULL) {
                        rinfo = listgetdata(listhead(list));
@@ -2403,77 +2400,72 @@ static void ripng_distribute_update_all_wrapper(struct access_list *notused)
 /* delete all the added ripng routes. */
 void ripng_clean()
 {
-       int i;
        struct agg_node *rp;
-       struct ripng_info *rinfo;
-       struct ripng_aggregate *aggregate;
-       struct list *list = NULL;
-       struct listnode *listnode = NULL;
 
-       if (ripng) {
-               /* Clear RIPng routes */
-               for (rp = agg_route_top(ripng->table); rp;
-                    rp = agg_route_next(rp)) {
-                       if ((list = rp->info) != NULL) {
-                               rinfo = listgetdata(listhead(list));
-                               if (ripng_route_rte(rinfo))
-                                       ripng_zebra_ipv6_delete(rp);
+       /* Clear RIPng routes */
+       for (rp = agg_route_top(ripng->table); rp; rp = agg_route_next(rp)) {
+               struct ripng_aggregate *aggregate;
+               struct list *list;
 
-                               for (ALL_LIST_ELEMENTS_RO(list, listnode,
-                                                         rinfo)) {
-                                       RIPNG_TIMER_OFF(rinfo->t_timeout);
-                                       RIPNG_TIMER_OFF(
-                                               rinfo->t_garbage_collect);
-                                       ripng_info_free(rinfo);
-                               }
-                               list_delete(&list);
-                               rp->info = NULL;
-                               agg_unlock_node(rp);
-                       }
+               if ((list = rp->info) != NULL) {
+                       struct ripng_info *rinfo;
+                       struct listnode *listnode;
 
-                       if ((aggregate = rp->aggregate) != NULL) {
-                               ripng_aggregate_free(aggregate);
-                               rp->aggregate = NULL;
-                               agg_unlock_node(rp);
+                       rinfo = listgetdata(listhead(list));
+                       if (ripng_route_rte(rinfo))
+                               ripng_zebra_ipv6_delete(rp);
+
+                       for (ALL_LIST_ELEMENTS_RO(list, listnode, rinfo)) {
+                               RIPNG_TIMER_OFF(rinfo->t_timeout);
+                               RIPNG_TIMER_OFF(rinfo->t_garbage_collect);
+                               ripng_info_free(rinfo);
                        }
+                       list_delete(&list);
+                       rp->info = NULL;
+                       agg_unlock_node(rp);
                }
 
-               /* Cancel the RIPng timers */
-               RIPNG_TIMER_OFF(ripng->t_update);
-               RIPNG_TIMER_OFF(ripng->t_triggered_update);
-               RIPNG_TIMER_OFF(ripng->t_triggered_interval);
-
-               /* Cancel the read thread */
-               if (ripng->t_read) {
-                       thread_cancel(ripng->t_read);
-                       ripng->t_read = NULL;
+               if ((aggregate = rp->aggregate) != NULL) {
+                       ripng_aggregate_free(aggregate);
+                       rp->aggregate = NULL;
+                       agg_unlock_node(rp);
                }
+       }
 
-               /* Close the RIPng socket */
-               if (ripng->sock >= 0) {
-                       close(ripng->sock);
-                       ripng->sock = -1;
-               }
+       /* Cancel the RIPng timers */
+       RIPNG_TIMER_OFF(ripng->t_update);
+       RIPNG_TIMER_OFF(ripng->t_triggered_update);
+       RIPNG_TIMER_OFF(ripng->t_triggered_interval);
 
-               for (i = 0; i < ZEBRA_ROUTE_MAX; i++)
-                       if (ripng->route_map[i].name)
-                               free(ripng->route_map[i].name);
+       /* Cancel the read thread */
+       if (ripng->t_read) {
+               thread_cancel(ripng->t_read);
+               ripng->t_read = NULL;
+       }
+
+       /* Close the RIPng socket */
+       if (ripng->sock >= 0) {
+               close(ripng->sock);
+               ripng->sock = -1;
+       }
 
-               agg_table_finish(ripng->table);
+       for (int i = 0; i < ZEBRA_ROUTE_MAX; i++)
+               if (ripng->route_map[i].name)
+                       free(ripng->route_map[i].name);
 
-               stream_free(ripng->ibuf);
-               stream_free(ripng->obuf);
+       agg_table_finish(ripng->table);
+       distribute_list_delete(&ripng->distribute_ctx);
 
-               distribute_list_delete(&ripng->distribute_ctx);
-               XFREE(MTYPE_RIPNG, ripng);
-               ripng = NULL;
-       } /* if (ripng) */
+       stream_free(ripng->ibuf);
+       stream_free(ripng->obuf);
 
        ripng_clean_network();
        ripng_passive_interface_clean();
        ripng_offset_clean();
        ripng_interface_clean();
        ripng_redistribute_clean();
+
+       XFREE(MTYPE_RIPNG, ripng);
 }
 
 static void ripng_if_rmap_update(struct if_rmap *if_rmap)