]> git.proxmox.com Git - mirror_frr.git/blobdiff - ospfd/ospfd.c
*: Convert `struct event_master` to `struct event_loop`
[mirror_frr.git] / ospfd / ospfd.c
index e0c36d86fea0b9d497566c9952140cd7dd4514b4..2cdad9368cf65038f45a9b31325c5fd1e31c6c87 100644 (file)
@@ -1,26 +1,11 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
 /* OSPF version 2 daemon program.
  * Copyright (C) 1999, 2000 Toshiaki Takada
- *
- * This file is part of GNU Zebra.
- *
- * GNU Zebra is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License as published by the
- * Free Software Foundation; either version 2, or (at your option) any
- * later version.
- *
- * GNU Zebra is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License along
- * with this program; see the file COPYING; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
  */
 
 #include <zebra.h>
 
-#include "thread.h"
+#include "event.h"
 #include "vty.h"
 #include "command.h"
 #include "linklist.h"
@@ -89,6 +74,25 @@ static int ospf_network_match_iface(const struct connected *,
                                    const struct prefix *);
 static void ospf_finish_final(struct ospf *);
 
+/* API to clean refresh queues and LSAs */
+static void ospf_free_refresh_queue(struct ospf *ospf)
+{
+       for (int i = 0; i < OSPF_LSA_REFRESHER_SLOTS; i++) {
+               struct list *list = ospf->lsa_refresh_queue.qs[i];
+               struct listnode *node, *nnode;
+               struct ospf_lsa *lsa;
+
+               if (list) {
+                       for (ALL_LIST_ELEMENTS(list, node, nnode, lsa)) {
+                               listnode_delete(list, lsa);
+                               lsa->refresh_list = -1;
+                               ospf_lsa_unlock(&lsa);
+                       }
+                       list_delete(&list);
+                       ospf->lsa_refresh_queue.qs[i] = NULL;
+               }
+       }
+}
 #define OSPF_EXTERNAL_LSA_ORIGINATE_DELAY 1
 
 int p_spaces_compare_func(const struct p_space *a, const struct p_space *b)
@@ -381,8 +385,8 @@ struct ospf *ospf_new_alloc(unsigned short instance, const char *name)
        new->maxage_delay = OSPF_LSA_MAXAGE_REMOVE_DELAY_DEFAULT;
        new->maxage_lsa = route_table_init();
        new->t_maxage_walker = NULL;
-       thread_add_timer(master, ospf_lsa_maxage_walker, new,
-                        OSPF_LSA_MAXAGE_CHECK_INTERVAL, &new->t_maxage_walker);
+       event_add_timer(master, ospf_lsa_maxage_walker, new,
+                       OSPF_LSA_MAXAGE_CHECK_INTERVAL, &new->t_maxage_walker);
 
        /* Max paths initialization */
        new->max_multipath = MULTIPATH_NUM;
@@ -394,8 +398,8 @@ struct ospf *ospf_new_alloc(unsigned short instance, const char *name)
        new->lsa_refresh_interval = OSPF_LSA_REFRESH_INTERVAL_DEFAULT;
        new->lsa_refresh_timer = OSPF_LS_REFRESH_TIME;
        new->t_lsa_refresher = NULL;
-       thread_add_timer(master, ospf_lsa_refresh_walker, new,
-                        new->lsa_refresh_interval, &new->t_lsa_refresher);
+       event_add_timer(master, ospf_lsa_refresh_walker, new,
+                       new->lsa_refresh_interval, &new->t_lsa_refresher);
        new->lsa_refresher_started = monotime(NULL);
 
        new->ibuf = stream_new(OSPF_MAX_PACKET_SIZE + 1);
@@ -437,7 +441,7 @@ static struct ospf *ospf_new(unsigned short instance, const char *name)
                return new;
        }
 
-       thread_add_read(master, ospf_read, new, new->fd, &new->t_read);
+       event_add_read(master, ospf_read, new, new->fd, &new->t_read);
 
        new->oi_running = 1;
        ospf_router_id_update(new);
@@ -448,6 +452,8 @@ static struct ospf *ospf_new(unsigned short instance, const char *name)
         */
        ospf_gr_nvm_read(new);
 
+       new->fr_configured = false;
+
        return new;
 }
 
@@ -573,7 +579,7 @@ static struct ospf *ospf_lookup_by_name(const char *vrf_name)
 static void ospf_deferred_shutdown_finish(struct ospf *ospf)
 {
        ospf->stub_router_shutdown_time = OSPF_STUB_ROUTER_UNCONFIGURED;
-       THREAD_OFF(ospf->t_deferred_shutdown);
+       EVENT_OFF(ospf->t_deferred_shutdown);
 
        ospf_finish_final(ospf);
 
@@ -590,9 +596,9 @@ static void ospf_deferred_shutdown_finish(struct ospf *ospf)
 }
 
 /* Timer thread for G-R */
-static void ospf_deferred_shutdown_timer(struct thread *t)
+static void ospf_deferred_shutdown_timer(struct event *t)
 {
-       struct ospf *ospf = THREAD_ARG(t);
+       struct ospf *ospf = EVENT_ARG(t);
 
        ospf_deferred_shutdown_finish(ospf);
 }
@@ -755,7 +761,7 @@ static void ospf_finish_final(struct ospf *ospf)
        /* Clear static neighbors */
        for (rn = route_top(ospf->nbr_nbma); rn; rn = route_next(rn))
                if ((nbr_nbma = rn->info)) {
-                       THREAD_OFF(nbr_nbma->t_poll);
+                       EVENT_OFF(nbr_nbma->t_poll);
 
                        if (nbr_nbma->nbr) {
                                nbr_nbma->nbr->nbr_nbma = NULL;
@@ -791,22 +797,23 @@ static void ospf_finish_final(struct ospf *ospf)
        }
 
        /* Cancel all timers. */
-       THREAD_OFF(ospf->t_read);
-       THREAD_OFF(ospf->t_write);
-       THREAD_OFF(ospf->t_spf_calc);
-       THREAD_OFF(ospf->t_ase_calc);
-       THREAD_OFF(ospf->t_maxage);
-       THREAD_OFF(ospf->t_maxage_walker);
-       THREAD_OFF(ospf->t_abr_task);
-       THREAD_OFF(ospf->t_asbr_check);
-       THREAD_OFF(ospf->t_asbr_nssa_redist_update);
-       THREAD_OFF(ospf->t_distribute_update);
-       THREAD_OFF(ospf->t_lsa_refresher);
-       THREAD_OFF(ospf->t_opaque_lsa_self);
-       THREAD_OFF(ospf->t_sr_update);
-       THREAD_OFF(ospf->t_default_routemap_timer);
-       THREAD_OFF(ospf->t_external_aggr);
-       THREAD_OFF(ospf->gr_info.t_grace_period);
+       EVENT_OFF(ospf->t_read);
+       EVENT_OFF(ospf->t_write);
+       EVENT_OFF(ospf->t_spf_calc);
+       EVENT_OFF(ospf->t_ase_calc);
+       EVENT_OFF(ospf->t_maxage);
+       EVENT_OFF(ospf->t_maxage_walker);
+       EVENT_OFF(ospf->t_abr_task);
+       EVENT_OFF(ospf->t_abr_fr);
+       EVENT_OFF(ospf->t_asbr_check);
+       EVENT_OFF(ospf->t_asbr_nssa_redist_update);
+       EVENT_OFF(ospf->t_distribute_update);
+       EVENT_OFF(ospf->t_lsa_refresher);
+       EVENT_OFF(ospf->t_opaque_lsa_self);
+       EVENT_OFF(ospf->t_sr_update);
+       EVENT_OFF(ospf->t_default_routemap_timer);
+       EVENT_OFF(ospf->t_external_aggr);
+       EVENT_OFF(ospf->gr_info.t_grace_period);
 
        LSDB_LOOP (OPAQUE_AS_LSDB(ospf), rn, lsa)
                ospf_discard_from_db(ospf, ospf->lsdb, lsa);
@@ -832,6 +839,10 @@ static void ospf_finish_final(struct ospf *ospf)
                        ospf_route_delete(ospf, ospf->new_table);
                ospf_route_table_free(ospf->new_table);
        }
+       if (ospf->oall_rtrs)
+               ospf_rtrs_free(ospf->oall_rtrs);
+       if (ospf->all_rtrs)
+               ospf_rtrs_free(ospf->all_rtrs);
        if (ospf->old_rtrs)
                ospf_rtrs_free(ospf->old_rtrs);
        if (ospf->new_rtrs)
@@ -894,6 +905,8 @@ static void ospf_finish_final(struct ospf *ospf)
        route_table_finish(ospf->rt_aggr_tbl);
 
 
+       ospf_free_refresh_queue(ospf);
+
        list_delete(&ospf->areas);
        list_delete(&ospf->oi_write_q);
 
@@ -937,6 +950,15 @@ struct ospf_area *ospf_area_new(struct ospf *ospf, struct in_addr area_id)
        /* Self-originated LSAs initialize. */
        new->router_lsa_self = NULL;
 
+       /* Initialize FR field */
+       new->fr_info.enabled = false;
+       new->fr_info.configured = false;
+       new->fr_info.state_changed = false;
+       new->fr_info.router_lsas_recv_dc_bit = 0;
+       new->fr_info.indication_lsa_self = NULL;
+       new->fr_info.area_ind_lsa_recvd = false;
+       new->fr_info.area_dc_clear = false;
+
        ospf_opaque_type10_lsa_init(new);
 
        new->oiflist = list_new();
@@ -993,8 +1015,8 @@ static void ospf_area_free(struct ospf_area *area)
                free(IMPORT_NAME(area));
 
        /* Cancel timer. */
-       THREAD_OFF(area->t_stub_router);
-       THREAD_OFF(area->t_opaque_lsa_self);
+       EVENT_OFF(area->t_stub_router);
+       EVENT_OFF(area->t_opaque_lsa_self);
 
        if (OSPF_IS_AREA_BACKBONE(area))
                area->ospf->backbone = NULL;
@@ -1429,7 +1451,7 @@ void ospf_ls_upd_queue_empty(struct ospf_interface *oi)
                }
 
        /* remove update event */
-       THREAD_OFF(oi->t_ls_upd_event);
+       EVENT_OFF(oi->t_ls_upd_event);
 }
 
 void ospf_if_update(struct ospf *ospf, struct interface *ifp)
@@ -1837,9 +1859,9 @@ int ospf_timers_refresh_set(struct ospf *ospf, int interval)
                    - (monotime(NULL) - ospf->lsa_refresher_started);
 
        if (time_left > interval) {
-               THREAD_OFF(ospf->t_lsa_refresher);
-               thread_add_timer(master, ospf_lsa_refresh_walker, ospf,
-                                interval, &ospf->t_lsa_refresher);
+               EVENT_OFF(ospf->t_lsa_refresher);
+               event_add_timer(master, ospf_lsa_refresh_walker, ospf, interval,
+                               &ospf->t_lsa_refresher);
        }
        ospf->lsa_refresh_interval = interval;
 
@@ -1854,11 +1876,11 @@ int ospf_timers_refresh_unset(struct ospf *ospf)
                    - (monotime(NULL) - ospf->lsa_refresher_started);
 
        if (time_left > OSPF_LSA_REFRESH_INTERVAL_DEFAULT) {
-               THREAD_OFF(ospf->t_lsa_refresher);
+               EVENT_OFF(ospf->t_lsa_refresher);
                ospf->t_lsa_refresher = NULL;
-               thread_add_timer(master, ospf_lsa_refresh_walker, ospf,
-                                OSPF_LSA_REFRESH_INTERVAL_DEFAULT,
-                                &ospf->t_lsa_refresher);
+               event_add_timer(master, ospf_lsa_refresh_walker, ospf,
+                               OSPF_LSA_REFRESH_INTERVAL_DEFAULT,
+                               &ospf->t_lsa_refresher);
        }
 
        ospf->lsa_refresh_interval = OSPF_LSA_REFRESH_INTERVAL_DEFAULT;
@@ -1906,7 +1928,7 @@ static void ospf_nbr_nbma_delete(struct ospf *ospf,
 
 static void ospf_nbr_nbma_down(struct ospf_nbr_nbma *nbr_nbma)
 {
-       THREAD_OFF(nbr_nbma->t_poll);
+       EVENT_OFF(nbr_nbma->t_poll);
 
        if (nbr_nbma->nbr) {
                nbr_nbma->nbr->nbr_nbma = NULL;
@@ -2095,7 +2117,7 @@ int ospf_nbr_nbma_poll_interval_set(struct ospf *ospf, struct in_addr nbr_addr,
        if (nbr_nbma->v_poll != interval) {
                nbr_nbma->v_poll = interval;
                if (nbr_nbma->oi && ospf_if_is_up(nbr_nbma->oi)) {
-                       THREAD_OFF(nbr_nbma->t_poll);
+                       EVENT_OFF(nbr_nbma->t_poll);
                        OSPF_POLL_TIMER_ON(nbr_nbma->t_poll, ospf_poll_timer,
                                           nbr_nbma->v_poll);
                }
@@ -2118,7 +2140,7 @@ int ospf_nbr_nbma_poll_interval_unset(struct ospf *ospf, struct in_addr addr)
        return 1;
 }
 
-void ospf_master_init(struct thread_master *master)
+void ospf_master_init(struct event_loop *master)
 {
        memset(&ospf_master, 0, sizeof(ospf_master));
 
@@ -2225,8 +2247,8 @@ static int ospf_vrf_enable(struct vrf *vrf)
                        ret = ospf_sock_init(ospf);
                        if (ret < 0 || ospf->fd <= 0)
                                return 0;
-                       thread_add_read(master, ospf_read, ospf, ospf->fd,
-                                       &ospf->t_read);
+                       event_add_read(master, ospf_read, ospf, ospf->fd,
+                                      &ospf->t_read);
                        ospf->oi_running = 1;
                        ospf_router_id_update(ospf);
                }
@@ -2264,7 +2286,7 @@ static int ospf_vrf_disable(struct vrf *vrf)
                if (IS_DEBUG_OSPF_EVENT)
                        zlog_debug("%s: ospf old_vrf_id %d unlinked", __func__,
                                   old_vrf_id);
-               THREAD_OFF(ospf->t_read);
+               EVENT_OFF(ospf->t_read);
                close(ospf->fd);
                ospf->fd = -1;
        }