From ea7d324dce27c53debfaad116ffdf3aa9fe274a3 Mon Sep 17 00:00:00 2001 From: Katerina Kubecova Date: Fri, 9 May 2025 14:29:10 +0200 Subject: [PATCH] ospf: move ospf to its own loop --- proto/ospf/config.Y | 1 + proto/ospf/dbdes.c | 6 +++--- proto/ospf/iface.c | 19 ++++++++++--------- proto/ospf/lsupd.c | 13 +++++++++---- proto/ospf/neighbor.c | 10 +++++----- proto/ospf/ospf.c | 4 ++-- proto/ospf/rt.c | 2 +- 7 files changed, 31 insertions(+), 24 deletions(-) diff --git a/proto/ospf/config.Y b/proto/ospf/config.Y index 7184d7dd9..026e261b7 100644 --- a/proto/ospf/config.Y +++ b/proto/ospf/config.Y @@ -461,6 +461,7 @@ nbma_item: ipa nbma_eligible ';' ospf_iface_start: { + this_proto->loop_order = DOMAIN_ORDER(proto); this_ipatt = cfg_allocz(sizeof(struct ospf_iface_patt)); add_tail(&this_area->patt_list, NODE this_ipatt); init_list(&this_ipatt->ipn_list); diff --git a/proto/ospf/dbdes.c b/proto/ospf/dbdes.c index 6d33bf8e0..f0ba0d6cb 100644 --- a/proto/ospf/dbdes.c +++ b/proto/ospf/dbdes.c @@ -300,7 +300,7 @@ ospf_process_dbdes(struct ospf_proto *p, struct ospf_packet *pkt, struct ospf_ne req->lsa_body = LSA_BODY_DUMMY; if (!tm_active(n->lsrq_timer)) - tm_start(n->lsrq_timer, 0); + tm_start_in(n->lsrq_timer, 0, p->p.loop); } } @@ -453,7 +453,7 @@ ospf_receive_dbdes(struct ospf_packet *pkt, struct ospf_iface *ifa, } ospf_send_dbdes(p, n); - tm_start(n->dbdes_timer, n->ifa->rxmtint S); + tm_start_in(n->dbdes_timer, n->ifa->rxmtint S, p->p.loop); } else { @@ -473,7 +473,7 @@ ospf_receive_dbdes(struct ospf_packet *pkt, struct ospf_iface *ifa, if (!(n->myimms & DBDES_M) && !(n->imms & DBDES_M)) { /* Use dbdes timer to postpone freeing of Last DBDES packet buffer */ - tm_start(n->dbdes_timer, n->ifa->deadint S); + tm_start_in(n->dbdes_timer, n->ifa->deadint S, p->p.loop); ospf_neigh_sm(n, INM_EXDONE); } } diff --git a/proto/ospf/iface.c b/proto/ospf/iface.c index edfbcda43..b11509556 100644 --- a/proto/ospf/iface.c +++ b/proto/ospf/iface.c @@ -386,6 +386,7 @@ ospf_iface_sm(struct ospf_iface *ifa, int event) case ISM_UP: if (ifa->state <= OSPF_IS_LOOP) { + struct ospf_proto *p = ifa->oa->po; /* Now, nothing should be adjacent */ if ((ifa->type == OSPF_IT_PTP) || (ifa->type == OSPF_IT_PTMP) || @@ -401,15 +402,15 @@ ospf_iface_sm(struct ospf_iface *ifa, int event) { ospf_iface_chstate(ifa, OSPF_IS_WAITING); if (ifa->wait_timer) - tm_start(ifa->wait_timer, ifa->waitint S); + tm_start_in(ifa->wait_timer, ifa->waitint S, p->p.loop); } } if (ifa->hello_timer) - tm_start(ifa->hello_timer, ifa->helloint S); + tm_start_in(ifa->hello_timer, ifa->helloint S, p->p.loop); if (ifa->poll_timer) - tm_start(ifa->poll_timer, ifa->pollint S); + tm_start_in(ifa->poll_timer, ifa->pollint S, p->p.loop); ospf_send_hello(ifa, OHS_HELLO, NULL); } @@ -672,7 +673,7 @@ ospf_iface_new(struct ospf_area *oa, struct ifa *addr, struct ospf_iface_patt *i .hook = ospf_iface_add, .data = ifa, }; - lock->target = &global_event_list; + lock->target = proto_event_list(&p->p); olock_acquire(lock); } @@ -734,7 +735,7 @@ ospf_iface_new_vlink(struct ospf_proto *p, struct ospf_iface_patt *ip) } static void -ospf_iface_change_timer(timer *tm, uint val) +ospf_iface_change_timer(timer *tm, uint val, struct birdloop *loop) { if (!tm) return; @@ -742,7 +743,7 @@ ospf_iface_change_timer(timer *tm, uint val) tm->recurrent = val S; if (tm_active(tm)) - tm_start(tm, val S); + tm_start_in(tm, val S, loop); } static inline void @@ -803,7 +804,7 @@ ospf_iface_reconfigure(struct ospf_iface *ifa, struct ospf_iface_patt *new) ifname, ifa->helloint, new->helloint); ifa->helloint = new->helloint; - ospf_iface_change_timer(ifa->hello_timer, ifa->helloint); + ospf_iface_change_timer(ifa->hello_timer, ifa->helloint, p->p.loop); } /* RXMT TIMER */ @@ -823,7 +824,7 @@ ospf_iface_reconfigure(struct ospf_iface *ifa, struct ospf_iface_patt *new) ifname, ifa->pollint, new->pollint); ifa->pollint = new->pollint; - ospf_iface_change_timer(ifa->poll_timer, ifa->pollint); + ospf_iface_change_timer(ifa->poll_timer, ifa->pollint, p->p.loop); } /* WAIT TIMER */ @@ -834,7 +835,7 @@ ospf_iface_reconfigure(struct ospf_iface *ifa, struct ospf_iface_patt *new) ifa->waitint = new->waitint; if (ifa->wait_timer && tm_active(ifa->wait_timer)) - tm_start(ifa->wait_timer, ifa->waitint S); + tm_start_in(ifa->wait_timer, ifa->waitint S, p->p.loop); } /* DEAD TIMER */ diff --git a/proto/ospf/lsupd.c b/proto/ospf/lsupd.c index 12c9cfaaf..60964bedb 100644 --- a/proto/ospf/lsupd.c +++ b/proto/ospf/lsupd.c @@ -137,7 +137,10 @@ ospf_lsa_lsrt_up(struct top_hash_entry *en, struct ospf_neighbor *n) ret->lsa_body = LSA_BODY_DUMMY; if (!tm_active(n->lsrt_timer)) - tm_start(n->lsrt_timer, n->ifa->rxmtint S); + { + struct ospf_proto *p = n->ifa->oa->po; + tm_start_in(n->lsrt_timer, n->ifa->rxmtint S, p->p.loop); + } } void @@ -177,7 +180,7 @@ ospf_add_flushed_to_lsrt(struct ospf_proto *p, struct ospf_neighbor *n) /* If we found any flushed LSA, we send them ASAP */ if (tm_active(n->lsrt_timer)) - tm_start(n->lsrt_timer, 0); + tm_start_in(n->lsrt_timer, 0, p->p.loop); } static int ospf_flood_lsupd(struct ospf_proto *p, struct top_hash_entry **lsa_list, uint lsa_count, uint lsa_min_count, struct ospf_iface *ifa); @@ -185,6 +188,8 @@ static int ospf_flood_lsupd(struct ospf_proto *p, struct top_hash_entry **lsa_li static void ospf_enqueue_lsa(struct ospf_proto *p, struct top_hash_entry *en, struct ospf_iface *ifa) { + ASSERT_DIE(birdloop_inside(p->p.loop)); + /* Exception for local Grace-LSA, they are flooded synchronously */ if ((en->lsa_type == LSA_T_GR) && (en->lsa.rt == p->router_id)) { @@ -211,7 +216,7 @@ ospf_enqueue_lsa(struct ospf_proto *p, struct top_hash_entry *en, struct ospf_if ifa->flood_queue_used++; if (!ev_active(p->flood_event)) - ev_schedule(p->flood_event); + ev_send(proto_event_list(&p->p), p->flood_event); } void @@ -709,7 +714,7 @@ ospf_receive_lsupd(struct ospf_packet *pkt, struct ospf_iface *ifa, if (!EMPTY_SLIST(n->lsrql) && (n->lsrqi == SHEAD(n->lsrql))) { ospf_send_lsreq(p, n); - tm_start(n->lsrq_timer, n->ifa->rxmtint S); + tm_start_in(n->lsrq_timer, n->ifa->rxmtint S, p->p.loop); } return; diff --git a/proto/ospf/neighbor.c b/proto/ospf/neighbor.c index acc0acfb2..792c1a2e0 100644 --- a/proto/ospf/neighbor.c +++ b/proto/ospf/neighbor.c @@ -189,8 +189,8 @@ ospf_neigh_chstate(struct ospf_neighbor *n, u8 state) n->myimms = DBDES_IMMS; n->got_my_rt_lsa = 0; - tm_start(n->dbdes_timer, 0); - tm_start(n->ackd_timer, ifa->rxmtint S / 2); + tm_start_in(n->dbdes_timer, 0, p->p.loop); + tm_start_in(n->ackd_timer, ifa->rxmtint S / 2, p->p.loop); } if (state > NEIGHBOR_EXSTART) @@ -235,7 +235,7 @@ ospf_neigh_sm(struct ospf_neighbor *n, int event) ospf_neigh_chstate(n, NEIGHBOR_INIT); /* Restart inactivity timer */ - tm_start(n->inactim, n->ifa->deadint S); + tm_start_in(n->inactim, n->ifa->deadint S, p->p.loop); break; case INM_2WAYREC: @@ -385,7 +385,7 @@ ospf_neigh_start_graceful_restart(struct ospf_neighbor *n, uint gr_time) p->gr_count++; n->gr_timer = tm_new_init(n->pool, graceful_restart_timeout, n, 0, 0); - tm_start(n->gr_timer, gr_time S); + tm_start_in(n->gr_timer, gr_time S, p->p.loop); } static void @@ -496,7 +496,7 @@ ospf_neigh_notify_grace_lsa(struct ospf_neighbor *n, struct top_hash_entry *en) /* Exception for updating grace period */ if (n->gr_active) { - tm_start(n->gr_timer, (period S) - (en->lsa.age S)); + tm_start_in(n->gr_timer, (period S) - (en->lsa.age S), p->p.loop); return; } diff --git a/proto/ospf/ospf.c b/proto/ospf/ospf.c index bde7d8051..0a5595473 100644 --- a/proto/ospf/ospf.c +++ b/proto/ospf/ospf.c @@ -296,7 +296,7 @@ ospf_start(struct proto *P) p->gr_time = c->gr_time; p->tick = c->tick; p->disp_timer = tm_new_init(P->pool_up, ospf_disp, p, p->tick S, 0); - tm_start(p->disp_timer, 100 MS); + tm_start_in(p->disp_timer, 100 MS, P->loop); p->lsab_size = 256; p->lsab_used = 0; p->lsab = mb_alloc(P->pool, p->lsab_size); @@ -711,7 +711,7 @@ ospf_reconfigure(struct proto *P, struct proto_config *CF) p->gr_time = new->gr_time; p->tick = new->tick; p->disp_timer->recurrent = p->tick S; - tm_start(p->disp_timer, 10 MS); + tm_start_in(p->disp_timer, 10 MS, P->loop); /* Mark all areas and ifaces */ WALK_LIST(oa, p->area_list) diff --git a/proto/ospf/rt.c b/proto/ospf/rt.c index b9b992a5b..939aad732 100644 --- a/proto/ospf/rt.c +++ b/proto/ospf/rt.c @@ -1350,7 +1350,7 @@ ospf_rt_abr2(struct ospf_proto *p) oa->translator_timer = tm_new_init(p->p.pool, translator_timer_hook, oa, 0, 0); /* Schedule the end of translation */ - tm_start(oa->translator_timer, oa->ac->transint S); + tm_start_in(oa->translator_timer, oa->ac->transint S, p->p.loop); oa->translate = TRANS_WAIT; } } -- 2.47.2