diff options
83 files changed, 406 insertions, 443 deletions
diff --git a/babeld/babeld.c b/babeld/babeld.c index 09955cfbef..895ede7040 100644 --- a/babeld/babeld.c +++ b/babeld/babeld.c @@ -317,13 +317,9 @@ babel_clean_routing_process(void) flush_all_routes(); babel_interface_close_all(); - /* cancel threads */ - if (babel_routing_process->t_read != NULL) { - thread_cancel(babel_routing_process->t_read); - } - if (babel_routing_process->t_update != NULL) { - thread_cancel(babel_routing_process->t_update); - } + /* cancel events */ + thread_cancel(&babel_routing_process->t_read); + thread_cancel(&babel_routing_process->t_update); distribute_list_delete(&babel_routing_process->distribute_ctx); XFREE(MTYPE_BABEL, babel_routing_process); @@ -503,9 +499,7 @@ static void babel_set_timer(struct timeval *timeout) { long msecs = timeout->tv_sec * 1000 + timeout->tv_usec / 1000; - if (babel_routing_process->t_update != NULL) { - thread_cancel(babel_routing_process->t_update); - } + thread_cancel(&(babel_routing_process->t_update)); thread_add_timer_msec(master, babel_main_loop, NULL, msecs, &babel_routing_process->t_update); } diff --git a/bfdd/control.c b/bfdd/control.c index 3b954c64f8..4929bf1998 100644 --- a/bfdd/control.c +++ b/bfdd/control.c @@ -145,10 +145,7 @@ void control_shutdown(void) { struct bfd_control_socket *bcs; - if (bglobal.bg_csockev) { - thread_cancel(bglobal.bg_csockev); - bglobal.bg_csockev = NULL; - } + thread_cancel(&bglobal.bg_csockev); socket_close(&bglobal.bg_csock); @@ -204,15 +201,8 @@ static void control_free(struct bfd_control_socket *bcs) struct bfd_control_queue *bcq; struct bfd_notify_peer *bnp; - if (bcs->bcs_ev) { - thread_cancel(bcs->bcs_ev); - bcs->bcs_ev = NULL; - } - - if (bcs->bcs_outev) { - thread_cancel(bcs->bcs_outev); - bcs->bcs_outev = NULL; - } + thread_cancel(&(bcs->bcs_ev)); + thread_cancel(&(bcs->bcs_outev)); close(bcs->bcs_sd); @@ -318,10 +308,7 @@ static int control_queue_dequeue(struct bfd_control_socket *bcs) return 1; empty_list: - if (bcs->bcs_outev) { - thread_cancel(bcs->bcs_outev); - bcs->bcs_outev = NULL; - } + thread_cancel(&(bcs->bcs_outev)); bcs->bcs_bout = NULL; return 0; } diff --git a/bgpd/bgp_damp.c b/bgpd/bgp_damp.c index 9992168182..94a27ead0e 100644 --- a/bgpd/bgp_damp.c +++ b/bgpd/bgp_damp.c @@ -467,10 +467,8 @@ int bgp_damp_disable(struct bgp *bgp, afi_t afi, safi_t safi) if (!CHECK_FLAG(bgp->af_flags[afi][safi], BGP_CONFIG_DAMPENING)) return 0; - /* Cancel reuse thread. */ - if (bdc->t_reuse) - thread_cancel(bdc->t_reuse); - bdc->t_reuse = NULL; + /* Cancel reuse event. */ + thread_cancel(&(bdc->t_reuse)); /* Clean BGP dampening information. */ bgp_damp_info_clean(afi, safi); diff --git a/bgpd/bgp_dump.c b/bgpd/bgp_dump.c index abd349a188..975bba9314 100644 --- a/bgpd/bgp_dump.c +++ b/bgpd/bgp_dump.c @@ -677,11 +677,8 @@ static int bgp_dump_unset(struct bgp_dump *bgp_dump) bgp_dump->fp = NULL; } - /* Removing interval thread. */ - if (bgp_dump->t_interval) { - thread_cancel(bgp_dump->t_interval); - bgp_dump->t_interval = NULL; - } + /* Removing interval event. */ + thread_cancel(&bgp_dump->t_interval); bgp_dump->interval = 0; diff --git a/bgpd/bgp_evpn_mh.c b/bgpd/bgp_evpn_mh.c index 1a58541a71..8f81278dee 100644 --- a/bgpd/bgp_evpn_mh.c +++ b/bgpd/bgp_evpn_mh.c @@ -2911,7 +2911,7 @@ void bgp_evpn_mh_finish(void) es_next) { bgp_evpn_es_local_info_clear(es); } - thread_cancel(bgp_mh_info->t_cons_check); + thread_cancel(&bgp_mh_info->t_cons_check); list_delete(&bgp_mh_info->local_es_list); list_delete(&bgp_mh_info->pend_es_list); diff --git a/bgpd/bgp_fsm.c b/bgpd/bgp_fsm.c index 61119ced80..4468408415 100644 --- a/bgpd/bgp_fsm.c +++ b/bgpd/bgp_fsm.c @@ -704,8 +704,8 @@ bool bgp_update_delay_configured(struct bgp *bgp) on ending the update delay. */ void bgp_update_delay_end(struct bgp *bgp) { - THREAD_TIMER_OFF(bgp->t_update_delay); - THREAD_TIMER_OFF(bgp->t_establish_wait); + THREAD_OFF(bgp->t_update_delay); + THREAD_OFF(bgp->t_establish_wait); /* Reset update-delay related state */ bgp->update_delay_over = 1; @@ -924,7 +924,7 @@ static int bgp_maxmed_onstartup_timer(struct thread *thread) zlog_info("Max med on startup ended - timer expired."); bgp = THREAD_ARG(thread); - THREAD_TIMER_OFF(bgp->t_maxmed_onstartup); + THREAD_OFF(bgp->t_maxmed_onstartup); bgp->maxmed_onstartup_over = 1; bgp_maxmed_update(bgp); @@ -968,7 +968,7 @@ static int bgp_update_delay_timer(struct thread *thread) zlog_info("Update delay ended - timer expired."); bgp = THREAD_ARG(thread); - THREAD_TIMER_OFF(bgp->t_update_delay); + THREAD_OFF(bgp->t_update_delay); bgp_update_delay_end(bgp); return 0; @@ -982,7 +982,7 @@ static int bgp_establish_wait_timer(struct thread *thread) zlog_info("Establish wait - timer expired."); bgp = THREAD_ARG(thread); - THREAD_TIMER_OFF(bgp->t_establish_wait); + THREAD_OFF(bgp->t_establish_wait); bgp_check_update_delay(bgp); return 0; diff --git a/bgpd/bgp_fsm.h b/bgpd/bgp_fsm.h index aa98515c3f..b9156df617 100644 --- a/bgpd/bgp_fsm.h +++ b/bgpd/bgp_fsm.h @@ -31,7 +31,7 @@ #define BGP_TIMER_OFF(T) \ do { \ - THREAD_TIMER_OFF(T); \ + THREAD_OFF(T); \ } while (0) #define BGP_EVENT_ADD(P, E) \ diff --git a/bgpd/bgp_io.c b/bgpd/bgp_io.c index 412c8e3e5e..b14ac8b782 100644 --- a/bgpd/bgp_io.c +++ b/bgpd/bgp_io.c @@ -31,7 +31,7 @@ #include "network.h" // for ERRNO_IO_RETRY #include "stream.h" // for stream_get_endp, stream_getw_from, str... #include "ringbuf.h" // for ringbuf_remain, ringbuf_peek, ringbuf_... -#include "thread.h" // for THREAD_OFF, THREAD_ARG, thread, thread... +#include "thread.h" // for THREAD_OFF, THREAD_ARG, thread... #include "zassert.h" // for assert #include "bgpd/bgp_io.h" diff --git a/bgpd/bgp_nb_config.c b/bgpd/bgp_nb_config.c index f01325577c..3f0325eac6 100644 --- a/bgpd/bgp_nb_config.c +++ b/bgpd/bgp_nb_config.c @@ -509,7 +509,7 @@ int bgp_global_med_config_max_med_onstart_up_time_destroy( /* Cancel max-med onstartup if its on */ if (bgp->t_maxmed_onstartup) { - THREAD_TIMER_OFF(bgp->t_maxmed_onstartup); + THREAD_OFF(bgp->t_maxmed_onstartup); bgp->maxmed_onstartup_over = 1; } diff --git a/bgpd/bgp_route.c b/bgpd/bgp_route.c index eba355fadd..dd5f8c35b1 100644 --- a/bgpd/bgp_route.c +++ b/bgpd/bgp_route.c @@ -4289,7 +4289,7 @@ void bgp_stop_announce_route_timer(struct peer_af *paf) if (!paf->t_announce_route) return; - THREAD_TIMER_OFF(paf->t_announce_route); + thread_cancel(&paf->t_announce_route); } /* diff --git a/bgpd/bgp_updgrp.c b/bgpd/bgp_updgrp.c index 1685f98181..21eca78abc 100644 --- a/bgpd/bgp_updgrp.c +++ b/bgpd/bgp_updgrp.c @@ -796,13 +796,11 @@ static void update_subgroup_delete(struct update_subgroup *subgrp) UPDGRP_INCR_STAT(subgrp->update_group, subgrps_deleted); THREAD_OFF(subgrp->t_merge_check); - - THREAD_TIMER_OFF(subgrp->t_coalesce); + THREAD_OFF(subgrp->t_coalesce); bpacket_queue_cleanup(SUBGRP_PKTQ(subgrp)); subgroup_clear_table(subgrp); - THREAD_TIMER_OFF(subgrp->t_coalesce); sync_delete(subgrp); if (BGP_DEBUG(update_groups, UPDATE_GROUPS) && subgrp->update_group) @@ -1768,7 +1766,7 @@ int update_group_refresh_default_originate_route_map(struct thread *thread) bgp = THREAD_ARG(thread); update_group_walk(bgp, update_group_default_originate_route_map_walkcb, reason); - THREAD_TIMER_OFF(bgp->t_rmap_def_originate_eval); + thread_cancel(&bgp->t_rmap_def_originate_eval); bgp_unlock(bgp); return 0; diff --git a/bgpd/rfapi/rfapi_import.c b/bgpd/rfapi/rfapi_import.c index 68d4f622ed..e3581addee 100644 --- a/bgpd/rfapi/rfapi_import.c +++ b/bgpd/rfapi/rfapi_import.c @@ -858,9 +858,9 @@ static void rfapiBgpInfoChainFree(struct bgp_path_info *bpi) if (CHECK_FLAG(bpi->flags, BGP_PATH_REMOVED) && bpi->extra->vnc.import.timer) { - struct thread *t = - (struct thread *)bpi->extra->vnc.import.timer; - struct rfapi_withdraw *wcb = t->arg; + struct thread **t = + &(bpi->extra->vnc.import.timer); + struct rfapi_withdraw *wcb = (*t)->arg; XFREE(MTYPE_RFAPI_WITHDRAW, wcb); thread_cancel(t); @@ -3093,10 +3093,9 @@ static void rfapiBgpInfoFilteredImportEncap( if (CHECK_FLAG(bpi->flags, BGP_PATH_REMOVED) && bpi->extra->vnc.import.timer) { - struct thread *t = - (struct thread *)bpi->extra->vnc - .import.timer; - struct rfapi_withdraw *wcb = t->arg; + struct thread **t = + &(bpi->extra->vnc.import.timer); + struct rfapi_withdraw *wcb = (*t)->arg; XFREE(MTYPE_RFAPI_WITHDRAW, wcb); thread_cancel(t); @@ -3186,9 +3185,9 @@ static void rfapiBgpInfoFilteredImportEncap( "%s: removing holddown bpi matching NVE of new route", __func__); if (bpi->extra->vnc.import.timer) { - struct thread *t = - (struct thread *)bpi->extra->vnc.import.timer; - struct rfapi_withdraw *wcb = t->arg; + struct thread **t = + &(bpi->extra->vnc.import.timer); + struct rfapi_withdraw *wcb = (*t)->arg; XFREE(MTYPE_RFAPI_WITHDRAW, wcb); thread_cancel(t); @@ -3549,10 +3548,9 @@ void rfapiBgpInfoFilteredImportVPN( if (CHECK_FLAG(bpi->flags, BGP_PATH_REMOVED) && bpi->extra->vnc.import.timer) { - struct thread *t = - (struct thread *)bpi->extra->vnc - .import.timer; - struct rfapi_withdraw *wcb = t->arg; + struct thread **t = + &(bpi->extra->vnc.import.timer); + struct rfapi_withdraw *wcb = (*t)->arg; XFREE(MTYPE_RFAPI_WITHDRAW, wcb); thread_cancel(t); @@ -3768,9 +3766,9 @@ void rfapiBgpInfoFilteredImportVPN( "%s: removing holddown bpi matching NVE of new route", __func__); if (bpi->extra->vnc.import.timer) { - struct thread *t = - (struct thread *)bpi->extra->vnc.import.timer; - struct rfapi_withdraw *wcb = t->arg; + struct thread **t = + &(bpi->extra->vnc.import.timer); + struct rfapi_withdraw *wcb = (*t)->arg; XFREE(MTYPE_RFAPI_WITHDRAW, wcb); thread_cancel(t); @@ -4498,12 +4496,11 @@ static void rfapiDeleteRemotePrefixesIt( continue; if (bpi->extra->vnc.import.timer) { - struct thread *t = - (struct thread *)bpi - ->extra->vnc - .import.timer; + struct thread **t = + &(bpi->extra->vnc + .import.timer); struct rfapi_withdraw *wcb = - t->arg; + (*t)->arg; wcb->import_table ->holddown_count[afi] -= diff --git a/bgpd/rfapi/rfapi_monitor.c b/bgpd/rfapi/rfapi_monitor.c index a4b0eff03e..ce916c104b 100644 --- a/bgpd/rfapi/rfapi_monitor.c +++ b/bgpd/rfapi/rfapi_monitor.c @@ -620,10 +620,7 @@ void rfapiMonitorDel(struct bgp *bgp, struct rfapi_descriptor *rfd, rfapiMonitorDetachImport(m); } - if (m->timer) { - thread_cancel(m->timer); - m->timer = NULL; - } + thread_cancel(&m->timer); /* * remove from rfd list @@ -660,10 +657,7 @@ int rfapiMonitorDelHd(struct rfapi_descriptor *rfd) rfapiMonitorDetachImport(m); } - if (m->timer) { - thread_cancel(m->timer); - m->timer = NULL; - } + thread_cancel(&m->timer); XFREE(MTYPE_RFAPI_MONITOR, m); rn->info = NULL; @@ -697,10 +691,7 @@ int rfapiMonitorDelHd(struct rfapi_descriptor *rfd) #endif } - if (mon_eth->timer) { - thread_cancel(mon_eth->timer); - mon_eth->timer = NULL; - } + thread_cancel(&mon_eth->timer); /* * remove from rfd list @@ -766,8 +757,7 @@ static void rfapiMonitorTimerRestart(struct rfapi_monitor_vpn *m) if (m->rfd->response_lifetime - remain < 2) return; - thread_cancel(m->timer); - m->timer = NULL; + thread_cancel(&m->timer); } { @@ -1078,8 +1068,7 @@ static void rfapiMonitorEthTimerRestart(struct rfapi_monitor_eth *m) if (m->rfd->response_lifetime - remain < 2) return; - thread_cancel(m->timer); - m->timer = NULL; + thread_cancel(&m->timer); } { @@ -1418,10 +1407,7 @@ void rfapiMonitorEthDel(struct bgp *bgp, struct rfapi_descriptor *rfd, rfapiMonitorEthDetachImport(bgp, val); } - if (val->timer) { - thread_cancel(val->timer); - val->timer = NULL; - } + thread_cancel(&val->timer); /* * remove from rfd list diff --git a/bgpd/rfapi/rfapi_rib.c b/bgpd/rfapi/rfapi_rib.c index 09832b32ac..630a379ec2 100644 --- a/bgpd/rfapi/rfapi_rib.c +++ b/bgpd/rfapi/rfapi_rib.c @@ -269,9 +269,8 @@ static void rfapi_info_free(struct rfapi_info *goner) struct rfapi_rib_tcb *tcb; tcb = goner->timer->arg; - thread_cancel(goner->timer); + thread_cancel(&goner->timer); XFREE(MTYPE_RFAPI_RECENT_DELETE, tcb); - goner->timer = NULL; } XFREE(MTYPE_RFAPI_INFO, goner); } @@ -338,13 +337,11 @@ static void rfapiRibStartTimer(struct rfapi_descriptor *rfd, struct agg_node *rn, /* route node attached to */ int deleted) { - struct thread *t = ri->timer; struct rfapi_rib_tcb *tcb = NULL; - if (t) { - tcb = t->arg; - thread_cancel(t); - ri->timer = NULL; + if (ri->timer) { + tcb = ri->timer->arg; + thread_cancel(&ri->timer); } else { tcb = XCALLOC(MTYPE_RFAPI_RECENT_DELETE, sizeof(struct rfapi_rib_tcb)); @@ -917,10 +914,9 @@ static void process_pending_node(struct bgp *bgp, struct rfapi_descriptor *rfd, if (ri->timer) { struct rfapi_rib_tcb *tcb; - tcb = ((struct thread *)ri->timer)->arg; - thread_cancel(ri->timer); + tcb = ri->timer->arg; + thread_cancel(&ri->timer); XFREE(MTYPE_RFAPI_RECENT_DELETE, tcb); - ri->timer = NULL; } vnc_zlog_debug_verbose( @@ -1003,11 +999,9 @@ static void process_pending_node(struct bgp *bgp, struct rfapi_descriptor *rfd, if (ori->timer) { struct rfapi_rib_tcb *tcb; - tcb = ((struct thread *)ori->timer) - ->arg; - thread_cancel(ori->timer); + tcb = ori->timer->arg; + thread_cancel(&ori->timer); XFREE(MTYPE_RFAPI_RECENT_DELETE, tcb); - ori->timer = NULL; } #if DEBUG_PROCESS_PENDING_NODE @@ -1351,11 +1345,9 @@ callback: if (ri->timer) { struct rfapi_rib_tcb *tcb; - tcb = ((struct thread *)ri->timer)->arg; - thread_cancel( - (struct thread *)ri->timer); + tcb = ri->timer->arg; + thread_cancel(&ri->timer); XFREE(MTYPE_RFAPI_RECENT_DELETE, tcb); - ri->timer = NULL; } RFAPI_RIB_CHECK_COUNTS(0, delete_list->count); diff --git a/bgpd/rfapi/vnc_export_bgp.c b/bgpd/rfapi/vnc_export_bgp.c index b56261669c..11f39b2b82 100644 --- a/bgpd/rfapi/vnc_export_bgp.c +++ b/bgpd/rfapi/vnc_export_bgp.c @@ -1711,14 +1711,11 @@ void vnc_direct_bgp_rh_add_route(struct bgp *bgp, afi_t afi, rfapiGetVncLifetime(attr, &eti->lifetime); eti->lifetime = rfapiGetHolddownFromLifetime(eti->lifetime); - if (eti->timer) { - /* - * export expiration timer is already running on - * this route: cancel it - */ - thread_cancel(eti->timer); - eti->timer = NULL; - } + /* + * export expiration timer is already running on + * this route: cancel it + */ + thread_cancel(&eti->timer); bgp_update(peer, prefix, /* prefix */ 0, /* addpath_id */ @@ -1947,15 +1944,12 @@ void vnc_direct_bgp_rh_vpn_enable(struct bgp *bgp, afi_t afi) rfapiGetVncLifetime(ri->attr, &eti->lifetime); - if (eti->timer) { - /* - * export expiration timer is - * already running on - * this route: cancel it - */ - thread_cancel(eti->timer); - eti->timer = NULL; - } + /* + * export expiration timer is + * already running on + * this route: cancel it + */ + thread_cancel(&eti->timer); vnc_zlog_debug_verbose( "%s: calling bgp_update", @@ -2024,8 +2018,7 @@ void vnc_direct_bgp_rh_vpn_disable(struct bgp *bgp, afi_t afi) ZEBRA_ROUTE_VNC_DIRECT_RH, BGP_ROUTE_REDISTRIBUTE); if (eti) { - if (eti->timer) - thread_cancel(eti->timer); + thread_cancel(&eti->timer); vnc_eti_delete(eti); } diff --git a/eigrpd/eigrp_filter.c b/eigrpd/eigrp_filter.c index 9d5d45ca50..009b57e05f 100644 --- a/eigrpd/eigrp_filter.c +++ b/eigrpd/eigrp_filter.c @@ -159,13 +159,10 @@ void eigrp_distribute_update(struct distribute_ctx *ctx, #endif // TODO: check Graceful restart after 10sec - /* check if there is already GR scheduled */ - if (e->t_distribute != NULL) { - /* if is, cancel schedule */ - thread_cancel(e->t_distribute); - } + /* cancel GR scheduled */ + thread_cancel(&(e->t_distribute)); + /* schedule Graceful restart for whole process in 10sec */ - e->t_distribute = NULL; thread_add_timer(master, eigrp_distribute_timer_process, e, (10), &e->t_distribute); @@ -267,11 +264,8 @@ void eigrp_distribute_update(struct distribute_ctx *ctx, #endif // TODO: check Graceful restart after 10sec - /* check if there is already GR scheduled */ - if (ei->t_distribute != NULL) { - /* if is, cancel schedule */ - thread_cancel(ei->t_distribute); - } + /* Cancel GR scheduled */ + thread_cancel(&(ei->t_distribute)); /* schedule Graceful restart for interface in 10sec */ e->t_distribute = NULL; thread_add_timer(master, eigrp_distribute_timer_interface, ei, 10, diff --git a/eigrpd/eigrp_interface.c b/eigrpd/eigrp_interface.c index 2f3f347423..dd43dd0478 100644 --- a/eigrpd/eigrp_interface.c +++ b/eigrpd/eigrp_interface.c @@ -358,7 +358,7 @@ void eigrp_if_stream_unset(struct eigrp_interface *ei) if (ei->on_write_q) { listnode_delete(eigrp->oi_write_q, ei); if (list_isempty(eigrp->oi_write_q)) - thread_cancel(eigrp->t_write); + thread_cancel(&(eigrp->t_write)); ei->on_write_q = 0; } } @@ -420,7 +420,7 @@ void eigrp_if_free(struct eigrp_interface *ei, int source) struct eigrp *eigrp = ei->eigrp; if (source == INTERFACE_DOWN_BY_VTY) { - THREAD_OFF(ei->t_hello); + thread_cancel(&ei->t_hello); eigrp_hello_send(ei, EIGRP_HELLO_GRACEFUL_SHUTDOWN, NULL); } diff --git a/isisd/fabricd.c b/isisd/fabricd.c index 1a081bbea6..57e9e91c15 100644 --- a/isisd/fabricd.c +++ b/isisd/fabricd.c @@ -239,14 +239,11 @@ struct fabricd *fabricd_new(struct isis_area *area) void fabricd_finish(struct fabricd *f) { - if (f->initial_sync_timeout) - thread_cancel(f->initial_sync_timeout); + thread_cancel(&(f->initial_sync_timeout)); - if (f->tier_calculation_timer) - thread_cancel(f->tier_calculation_timer); + thread_cancel(&(f->tier_calculation_timer)); - if (f->tier_set_timer) - thread_cancel(f->tier_set_timer); + thread_cancel(&(f->tier_set_timer)); isis_spftree_del(f->spftree); neighbor_lists_clear(f); @@ -340,8 +337,7 @@ void fabricd_initial_sync_finish(struct isis_area *area) f->initial_sync_circuit->interface->name); f->initial_sync_state = FABRICD_SYNC_COMPLETE; f->initial_sync_circuit = NULL; - thread_cancel(f->initial_sync_timeout); - f->initial_sync_timeout = NULL; + thread_cancel(&(f->initial_sync_timeout)); } static void fabricd_bump_tier_calculation_timer(struct fabricd *f); @@ -437,22 +433,15 @@ static int fabricd_tier_calculation_cb(struct thread *thread) static void fabricd_bump_tier_calculation_timer(struct fabricd *f) { /* Cancel timer if we already know our tier */ - if (f->tier != ISIS_TIER_UNDEFINED - || f->tier_set_timer) { - if (f->tier_calculation_timer) { - thread_cancel(f->tier_calculation_timer); - f->tier_calculation_timer = NULL; - } + if (f->tier != ISIS_TIER_UNDEFINED || f->tier_set_timer) { + thread_cancel(&(f->tier_calculation_timer)); return; } /* If we need to calculate the tier, wait some * time for the topology to settle before running * the calculation */ - if (f->tier_calculation_timer) { - thread_cancel(f->tier_calculation_timer); - f->tier_calculation_timer = NULL; - } + thread_cancel(&(f->tier_calculation_timer)); thread_add_timer(master, fabricd_tier_calculation_cb, f, 2 * f->area->lsp_gen_interval[ISIS_LEVEL2 - 1], @@ -737,7 +726,7 @@ void fabricd_trigger_csnp(struct isis_area *area, bool circuit_scoped) if (!circuit->t_send_csnp[1]) continue; - thread_cancel(circuit->t_send_csnp[ISIS_LEVEL2 - 1]); + thread_cancel(&(circuit->t_send_csnp[ISIS_LEVEL2 - 1])); thread_add_timer_msec(master, send_l2_csnp, circuit, isis_jitter(f->csnp_delay, CSNP_JITTER), &circuit->t_send_csnp[ISIS_LEVEL2 - 1]); diff --git a/isisd/isis_adjacency.c b/isisd/isis_adjacency.c index 59403b6c23..71d4758163 100644 --- a/isisd/isis_adjacency.c +++ b/isisd/isis_adjacency.c @@ -147,7 +147,7 @@ void isis_delete_adj(void *arg) if (!adj) return; - THREAD_TIMER_OFF(adj->t_expire); + thread_cancel(&adj->t_expire); if (adj->adj_state != ISIS_ADJ_DOWN) adj->adj_state = ISIS_ADJ_DOWN; diff --git a/isisd/isis_circuit.c b/isisd/isis_circuit.c index 3eb3b900a5..730d224cb8 100644 --- a/isisd/isis_circuit.c +++ b/isisd/isis_circuit.c @@ -788,12 +788,12 @@ void isis_circuit_down(struct isis_circuit *circuit) memset(circuit->u.bc.l2_desig_is, 0, ISIS_SYS_ID_LEN + 1); memset(circuit->u.bc.snpa, 0, ETH_ALEN); - THREAD_TIMER_OFF(circuit->u.bc.t_send_lan_hello[0]); - THREAD_TIMER_OFF(circuit->u.bc.t_send_lan_hello[1]); - THREAD_TIMER_OFF(circuit->u.bc.t_run_dr[0]); - THREAD_TIMER_OFF(circuit->u.bc.t_run_dr[1]); - THREAD_TIMER_OFF(circuit->u.bc.t_refresh_pseudo_lsp[0]); - THREAD_TIMER_OFF(circuit->u.bc.t_refresh_pseudo_lsp[1]); + thread_cancel(&circuit->u.bc.t_send_lan_hello[0]); + thread_cancel(&circuit->u.bc.t_send_lan_hello[1]); + thread_cancel(&circuit->u.bc.t_run_dr[0]); + thread_cancel(&circuit->u.bc.t_run_dr[1]); + thread_cancel(&circuit->u.bc.t_refresh_pseudo_lsp[0]); + thread_cancel(&circuit->u.bc.t_refresh_pseudo_lsp[1]); circuit->lsp_regenerate_pending[0] = 0; circuit->lsp_regenerate_pending[1] = 0; @@ -803,15 +803,15 @@ void isis_circuit_down(struct isis_circuit *circuit) } else if (circuit->circ_type == CIRCUIT_T_P2P) { isis_delete_adj(circuit->u.p2p.neighbor); circuit->u.p2p.neighbor = NULL; - THREAD_TIMER_OFF(circuit->u.p2p.t_send_p2p_hello); + thread_cancel(&circuit->u.p2p.t_send_p2p_hello); } /* Cancel all active threads */ - THREAD_TIMER_OFF(circuit->t_send_csnp[0]); - THREAD_TIMER_OFF(circuit->t_send_csnp[1]); - THREAD_TIMER_OFF(circuit->t_send_psnp[0]); - THREAD_TIMER_OFF(circuit->t_send_psnp[1]); - THREAD_OFF(circuit->t_read); + thread_cancel(&circuit->t_send_csnp[0]); + thread_cancel(&circuit->t_send_csnp[1]); + thread_cancel(&circuit->t_send_psnp[0]); + thread_cancel(&circuit->t_send_psnp[1]); + thread_cancel(&circuit->t_read); if (circuit->tx_queue) { isis_tx_queue_free(circuit->tx_queue); diff --git a/isisd/isis_dr.c b/isisd/isis_dr.c index 3324d74e0f..d03f857a0c 100644 --- a/isisd/isis_dr.c +++ b/isisd/isis_dr.c @@ -221,8 +221,8 @@ int isis_dr_resign(struct isis_circuit *circuit, int level) circuit->u.bc.is_dr[level - 1] = 0; circuit->u.bc.run_dr_elect[level - 1] = 0; - THREAD_TIMER_OFF(circuit->u.bc.t_run_dr[level - 1]); - THREAD_TIMER_OFF(circuit->u.bc.t_refresh_pseudo_lsp[level - 1]); + thread_cancel(&circuit->u.bc.t_run_dr[level - 1]); + thread_cancel(&circuit->u.bc.t_refresh_pseudo_lsp[level - 1]); circuit->lsp_regenerate_pending[level - 1] = 0; memcpy(id, circuit->isis->sysid, ISIS_SYS_ID_LEN); @@ -246,7 +246,7 @@ int isis_dr_resign(struct isis_circuit *circuit, int level) &circuit->t_send_psnp[1]); } - THREAD_TIMER_OFF(circuit->t_send_csnp[level - 1]); + thread_cancel(&circuit->t_send_csnp[level - 1]); thread_add_timer(master, isis_run_dr, &circuit->level_arg[level - 1], diff --git a/isisd/isis_events.c b/isisd/isis_events.c index c4c95138c4..0b987fc5cf 100644 --- a/isisd/isis_events.c +++ b/isisd/isis_events.c @@ -109,13 +109,13 @@ static void circuit_resign_level(struct isis_circuit *circuit, int level) circuit->area->area_tag, circuit->circuit_id, circuit->interface->name, level); - THREAD_TIMER_OFF(circuit->t_send_csnp[idx]); - THREAD_TIMER_OFF(circuit->t_send_psnp[idx]); + thread_cancel(&circuit->t_send_csnp[idx]); + thread_cancel(&circuit->t_send_psnp[idx]); if (circuit->circ_type == CIRCUIT_T_BROADCAST) { - THREAD_TIMER_OFF(circuit->u.bc.t_send_lan_hello[idx]); - THREAD_TIMER_OFF(circuit->u.bc.t_run_dr[idx]); - THREAD_TIMER_OFF(circuit->u.bc.t_refresh_pseudo_lsp[idx]); + thread_cancel(&circuit->u.bc.t_send_lan_hello[idx]); + thread_cancel(&circuit->u.bc.t_run_dr[idx]); + thread_cancel(&circuit->u.bc.t_refresh_pseudo_lsp[idx]); circuit->lsp_regenerate_pending[idx] = 0; circuit->u.bc.run_dr_elect[idx] = 0; circuit->u.bc.is_dr[idx] = 0; diff --git a/isisd/isis_ldp_sync.c b/isisd/isis_ldp_sync.c index 8360dfc59e..988af64c48 100644 --- a/isisd/isis_ldp_sync.c +++ b/isisd/isis_ldp_sync.c @@ -135,8 +135,8 @@ int isis_ldp_sync_announce_update(struct ldp_igp_sync_announce announce) } } - THREAD_TIMER_OFF(isis->ldp_sync_cmd.t_hello); - isis->ldp_sync_cmd.t_hello = NULL; + THREAD_OFF(isis->ldp_sync_cmd.t_hello); + isis->ldp_sync_cmd.sequence = 0; isis_ldp_sync_hello_timer_add(); @@ -186,7 +186,7 @@ int isis_ldp_sync_hello_update(struct ldp_igp_sync_hello hello) } } } else { - THREAD_TIMER_OFF(isis->ldp_sync_cmd.t_hello); + THREAD_OFF(isis->ldp_sync_cmd.t_hello); isis_ldp_sync_hello_timer_add(); } isis->ldp_sync_cmd.sequence = hello.sequence; @@ -280,8 +280,9 @@ void isis_ldp_sync_if_complete(struct isis_circuit *circuit) if (ldp_sync_info && ldp_sync_info->enabled == LDP_IGP_SYNC_ENABLED) { if (ldp_sync_info->state == LDP_IGP_SYNC_STATE_REQUIRED_NOT_UP) ldp_sync_info->state = LDP_IGP_SYNC_STATE_REQUIRED_UP; - THREAD_TIMER_OFF(ldp_sync_info->t_holddown); - ldp_sync_info->t_holddown = NULL; + + THREAD_OFF(ldp_sync_info->t_holddown); + isis_ldp_sync_set_if_metric(circuit, true); } } @@ -300,7 +301,7 @@ void isis_ldp_sync_ldp_fail(struct isis_circuit *circuit) if (ldp_sync_info && ldp_sync_info->enabled == LDP_IGP_SYNC_ENABLED && ldp_sync_info->state != LDP_IGP_SYNC_STATE_NOT_REQUIRED) { - THREAD_TIMER_OFF(ldp_sync_info->t_holddown); + THREAD_OFF(ldp_sync_info->t_holddown); ldp_sync_info->state = LDP_IGP_SYNC_STATE_REQUIRED_NOT_UP; isis_ldp_sync_set_if_metric(circuit, true); } @@ -323,7 +324,7 @@ void isis_ldp_sync_if_remove(struct isis_circuit *circuit, bool remove) ils_debug("ldp_sync: remove if %s", circuit->interface ? circuit->interface->name : ""); - THREAD_TIMER_OFF(ldp_sync_info->t_holddown); + THREAD_OFF(ldp_sync_info->t_holddown); ldp_sync_info->state = LDP_IGP_SYNC_STATE_NOT_REQUIRED; isis_ldp_sync_set_if_metric(circuit, true); if (remove) { @@ -662,8 +663,7 @@ void isis_ldp_sync_gbl_exit(bool remove) UNSET_FLAG(isis->ldp_sync_cmd.flags, LDP_SYNC_FLAG_ENABLE); UNSET_FLAG(isis->ldp_sync_cmd.flags, LDP_SYNC_FLAG_HOLDDOWN); isis->ldp_sync_cmd.holddown = LDP_IGP_SYNC_HOLDDOWN_DEFAULT; - THREAD_TIMER_OFF(isis->ldp_sync_cmd.t_hello); - isis->ldp_sync_cmd.t_hello = NULL; + THREAD_OFF(isis->ldp_sync_cmd.t_hello); /* remove LDP-SYNC on all ISIS interfaces */ FOR_ALL_INTERFACES (vrf, ifp) { diff --git a/isisd/isis_lsp.c b/isisd/isis_lsp.c index 2e38663d3f..d8ad4cd510 100644 --- a/isisd/isis_lsp.c +++ b/isisd/isis_lsp.c @@ -1241,7 +1241,7 @@ int lsp_generate(struct isis_area *area, int level) refresh_time = lsp_refresh_time(newlsp, rem_lifetime); - THREAD_TIMER_OFF(area->t_lsp_refresh[level - 1]); + thread_cancel(&area->t_lsp_refresh[level - 1]); area->lsp_regenerate_pending[level - 1] = 0; thread_add_timer(master, lsp_refresh, &area->lsp_refresh_arg[level - 1], refresh_time, @@ -1451,7 +1451,7 @@ int _lsp_regenerate_schedule(struct isis_area *area, int level, "ISIS (%s): Will schedule regen timer. Last run was: %lld, Now is: %lld", area->area_tag, (long long)lsp->last_generated, (long long)now); - THREAD_TIMER_OFF(area->t_lsp_refresh[lvl - 1]); + thread_cancel(&area->t_lsp_refresh[lvl - 1]); diff = now - lsp->last_generated; if (diff < area->lsp_gen_interval[lvl - 1] && !(area->bfd_signalled_down)) { @@ -1628,7 +1628,7 @@ int lsp_generate_pseudo(struct isis_circuit *circuit, int level) lsp_flood(lsp, NULL); refresh_time = lsp_refresh_time(lsp, rem_lifetime); - THREAD_TIMER_OFF(circuit->u.bc.t_refresh_pseudo_lsp[level - 1]); + thread_cancel(&circuit->u.bc.t_refresh_pseudo_lsp[level - 1]); circuit->lsp_regenerate_pending[level - 1] = 0; if (level == IS_LEVEL_1) thread_add_timer( @@ -1819,7 +1819,7 @@ int lsp_regenerate_schedule_pseudo(struct isis_circuit *circuit, int level) "ISIS (%s): Will schedule PSN regen timer. Last run was: %lld, Now is: %lld", area->area_tag, (long long)lsp->last_generated, (long long)now); - THREAD_TIMER_OFF(circuit->u.bc.t_refresh_pseudo_lsp[lvl - 1]); + thread_cancel(&circuit->u.bc.t_refresh_pseudo_lsp[lvl - 1]); diff = now - lsp->last_generated; if (diff < circuit->area->lsp_gen_interval[lvl - 1]) { timeout = diff --git a/isisd/isis_nb_config.c b/isisd/isis_nb_config.c index 1019c638a7..6cb7d32c25 100644 --- a/isisd/isis_nb_config.c +++ b/isisd/isis_nb_config.c @@ -2861,8 +2861,7 @@ int lib_interface_isis_mpls_ldp_sync_modify(struct nb_cb_modify_args *args) SET_FLAG(ldp_sync_info->flags, LDP_SYNC_FLAG_IF_CONFIG); ldp_sync_info->enabled = LDP_IGP_SYNC_DEFAULT; ldp_sync_info->state = LDP_IGP_SYNC_STATE_NOT_REQUIRED; - THREAD_TIMER_OFF(ldp_sync_info->t_holddown); - ldp_sync_info->t_holddown = NULL; + THREAD_OFF(ldp_sync_info->t_holddown); isis_ldp_sync_set_if_metric(circuit, true); } break; diff --git a/isisd/isis_pdu.c b/isisd/isis_pdu.c index d6f2571178..72de5d6543 100644 --- a/isisd/isis_pdu.c +++ b/isisd/isis_pdu.c @@ -205,7 +205,7 @@ static int process_p2p_hello(struct iih_info *iih) adj); /* lets take care of the expiry */ - THREAD_TIMER_OFF(adj->t_expire); + thread_cancel(&adj->t_expire); thread_add_timer(master, isis_adj_expire, adj, (long)adj->hold_time, &adj->t_expire); @@ -497,7 +497,7 @@ static int process_lan_hello(struct iih_info *iih) adj); /* lets take care of the expiry */ - THREAD_TIMER_OFF(adj->t_expire); + thread_cancel(&adj->t_expire); thread_add_timer(master, isis_adj_expire, adj, (long)adj->hold_time, &adj->t_expire); @@ -1987,7 +1987,7 @@ static void _send_hello_sched(struct isis_circuit *circuit, if (thread_timer_remain_msec(*threadp) < (unsigned long)delay) return; - thread_cancel(*threadp); + thread_cancel(threadp); } thread_add_timer_msec(master, send_hello_cb, diff --git a/isisd/isis_sr.c b/isisd/isis_sr.c index 140cf5e66c..89fa2018b9 100644 --- a/isisd/isis_sr.c +++ b/isisd/isis_sr.c @@ -1172,7 +1172,7 @@ void isis_sr_stop(struct isis_area *area) area->area_tag); /* Disable any re-attempt to connect to Label Manager */ - THREAD_TIMER_OFF(srdb->t_start_lm); + thread_cancel(&srdb->t_start_lm); /* Uninstall all local Adjacency-SIDs. */ for (ALL_LIST_ELEMENTS(area->srdb.adj_sids, node, nnode, sra)) diff --git a/isisd/isis_tx_queue.c b/isisd/isis_tx_queue.c index 1424b55bdc..5c87e39157 100644 --- a/isisd/isis_tx_queue.c +++ b/isisd/isis_tx_queue.c @@ -93,8 +93,7 @@ static void tx_queue_element_free(void *element) { struct isis_tx_queue_entry *e = element; - if (e->retry) - thread_cancel(e->retry); + thread_cancel(&(e->retry)); XFREE(MTYPE_TX_QUEUE_ENTRY, e); } @@ -166,8 +165,7 @@ void _isis_tx_queue_add(struct isis_tx_queue *queue, e->type = type; - if (e->retry) - thread_cancel(e->retry); + thread_cancel(&(e->retry)); thread_add_event(master, tx_queue_send_event, e, 0, &e->retry); e->is_retry = false; @@ -190,8 +188,7 @@ void _isis_tx_queue_del(struct isis_tx_queue *queue, struct isis_lsp *lsp, func, file, line); } - if (e->retry) - thread_cancel(e->retry); + thread_cancel(&(e->retry)); hash_release(queue->hash, e); XFREE(MTYPE_TX_QUEUE_ENTRY, e); diff --git a/isisd/isisd.c b/isisd/isisd.c index 57d3e9c7c0..075daaec93 100644 --- a/isisd/isisd.c +++ b/isisd/isisd.c @@ -442,8 +442,8 @@ void isis_area_destroy(struct isis_area *area) spftree_area_del(area); - THREAD_TIMER_OFF(area->spf_timer[0]); - THREAD_TIMER_OFF(area->spf_timer[1]); + thread_cancel(&area->spf_timer[0]); + thread_cancel(&area->spf_timer[1]); spf_backoff_free(area->spf_delay_ietf[0]); spf_backoff_free(area->spf_delay_ietf[1]); @@ -457,9 +457,9 @@ void isis_area_destroy(struct isis_area *area) } area->area_addrs = NULL; - THREAD_TIMER_OFF(area->t_tick); - THREAD_TIMER_OFF(area->t_lsp_refresh[0]); - THREAD_TIMER_OFF(area->t_lsp_refresh[1]); + thread_cancel(&area->t_tick); + thread_cancel(&area->t_lsp_refresh[0]); + thread_cancel(&area->t_lsp_refresh[1]); thread_cancel_event(master, area); @@ -2373,12 +2373,12 @@ static void area_resign_level(struct isis_area *area, int level) } } - THREAD_TIMER_OFF(area->spf_timer[level - 1]); + thread_cancel(&area->spf_timer[level - 1]); sched_debug( "ISIS (%s): Resigned from L%d - canceling LSP regeneration timer.", area->area_tag, level); - THREAD_TIMER_OFF(area->t_lsp_refresh[level - 1]); + thread_cancel(&area->t_lsp_refresh[level - 1]); area->lsp_regenerate_pending[level - 1] = 0; } diff --git a/ldpd/accept.c b/ldpd/accept.c index 323558d7fd..9bba0f5ddd 100644 --- a/ldpd/accept.c +++ b/ldpd/accept.c @@ -74,7 +74,7 @@ accept_del(int fd) LIST_FOREACH(av, &accept_queue.queue, entry) if (av->fd == fd) { log_debug("%s: %d removed from queue", __func__, fd); - THREAD_READ_OFF(av->ev); + thread_cancel(&av->ev); LIST_REMOVE(av, entry); free(av); return; @@ -95,7 +95,7 @@ accept_unpause(void) { if (accept_queue.evt != NULL) { log_debug(__func__); - THREAD_TIMER_OFF(accept_queue.evt); + thread_cancel(&accept_queue.evt); accept_arm(); } } @@ -115,7 +115,7 @@ accept_unarm(void) { struct accept_ev *av; LIST_FOREACH(av, &accept_queue.queue, entry) - THREAD_READ_OFF(av->ev); + thread_cancel(&av->ev); } static int diff --git a/ldpd/adjacency.c b/ldpd/adjacency.c index 3923c169d6..795a41491c 100644 --- a/ldpd/adjacency.c +++ b/ldpd/adjacency.c @@ -198,7 +198,7 @@ adj_itimer(struct thread *thread) void adj_start_itimer(struct adj *adj) { - THREAD_TIMER_OFF(adj->inactivity_timer); + thread_cancel(&adj->inactivity_timer); adj->inactivity_timer = NULL; thread_add_timer(master, adj_itimer, adj, adj->holdtime, &adj->inactivity_timer); @@ -207,7 +207,7 @@ adj_start_itimer(struct adj *adj) void adj_stop_itimer(struct adj *adj) { - THREAD_TIMER_OFF(adj->inactivity_timer); + thread_cancel(&adj->inactivity_timer); } /* targeted neighbors */ @@ -359,7 +359,7 @@ tnbr_hello_timer(struct thread *thread) static void tnbr_start_hello_timer(struct tnbr *tnbr) { - THREAD_TIMER_OFF(tnbr->hello_timer); + thread_cancel(&tnbr->hello_timer); tnbr->hello_timer = NULL; thread_add_timer(master, tnbr_hello_timer, tnbr, tnbr_get_hello_interval(tnbr), &tnbr->hello_timer); @@ -368,7 +368,7 @@ tnbr_start_hello_timer(struct tnbr *tnbr) static void tnbr_stop_hello_timer(struct tnbr *tnbr) { - THREAD_TIMER_OFF(tnbr->hello_timer); + thread_cancel(&tnbr->hello_timer); } struct ctl_adj * diff --git a/ldpd/control.c b/ldpd/control.c index 6554f0a6f1..3b77765952 100644 --- a/ldpd/control.c +++ b/ldpd/control.c @@ -183,8 +183,8 @@ control_close(int fd) msgbuf_clear(&c->iev.ibuf.w); TAILQ_REMOVE(&ctl_conns, c, entry); - THREAD_READ_OFF(c->iev.ev_read); - THREAD_WRITE_OFF(c->iev.ev_write); + thread_cancel(&c->iev.ev_read); + thread_cancel(&c->iev.ev_write); close(c->iev.ibuf.fd); accept_unpause(); free(c); diff --git a/ldpd/interface.c b/ldpd/interface.c index 8b3dd71fd7..3e9f2fa991 100644 --- a/ldpd/interface.c +++ b/ldpd/interface.c @@ -470,7 +470,7 @@ if_hello_timer(struct thread *thread) static void if_start_hello_timer(struct iface_af *ia) { - THREAD_TIMER_OFF(ia->hello_timer); + thread_cancel(&ia->hello_timer); ia->hello_timer = NULL; thread_add_timer(master, if_hello_timer, ia, if_get_hello_interval(ia), &ia->hello_timer); @@ -479,7 +479,7 @@ if_start_hello_timer(struct iface_af *ia) static void if_stop_hello_timer(struct iface_af *ia) { - THREAD_TIMER_OFF(ia->hello_timer); + thread_cancel(&ia->hello_timer); } struct ctl_iface * @@ -753,8 +753,7 @@ static void start_wait_for_ldp_sync_timer(struct iface *iface) if (iface->ldp_sync.wait_for_sync_timer) return; - THREAD_TIMER_OFF(iface->ldp_sync.wait_for_sync_timer); - iface->ldp_sync.wait_for_sync_timer = NULL; + THREAD_OFF(iface->ldp_sync.wait_for_sync_timer); thread_add_timer(master, iface_wait_for_ldp_sync_timer, iface, if_get_wait_for_sync_interval(), &iface->ldp_sync.wait_for_sync_timer); @@ -762,8 +761,7 @@ static void start_wait_for_ldp_sync_timer(struct iface *iface) static void stop_wait_for_ldp_sync_timer(struct iface *iface) { - THREAD_TIMER_OFF(iface->ldp_sync.wait_for_sync_timer); - iface->ldp_sync.wait_for_sync_timer = NULL; + THREAD_OFF(iface->ldp_sync.wait_for_sync_timer); } static int diff --git a/ldpd/lde.c b/ldpd/lde.c index df64f908ea..67b695150e 100644 --- a/ldpd/lde.c +++ b/ldpd/lde.c @@ -415,8 +415,8 @@ lde_dispatch_imsg(struct thread *thread) imsg_event_add(iev); else { /* this pipe is dead, so remove the event handlers and exit */ - THREAD_READ_OFF(iev->ev_read); - THREAD_WRITE_OFF(iev->ev_write); + thread_cancel(&iev->ev_read); + thread_cancel(&iev->ev_write); lde_shutdown(); } @@ -661,8 +661,8 @@ lde_dispatch_parent(struct thread *thread) imsg_event_add(iev); else { /* this pipe is dead, so remove the event handlers and exit */ - THREAD_READ_OFF(iev->ev_read); - THREAD_WRITE_OFF(iev->ev_write); + thread_cancel(&iev->ev_read); + thread_cancel(&iev->ev_write); lde_shutdown(); } diff --git a/ldpd/lde_lib.c b/ldpd/lde_lib.c index bed276c7b1..9db931677d 100644 --- a/ldpd/lde_lib.c +++ b/ldpd/lde_lib.c @@ -1060,7 +1060,7 @@ lde_gc_timer(struct thread *thread) void lde_gc_start_timer(void) { - THREAD_TIMER_OFF(gc_timer); + thread_cancel(&gc_timer); gc_timer = NULL; thread_add_timer(master, lde_gc_timer, NULL, LDE_GC_INTERVAL, &gc_timer); @@ -1069,5 +1069,5 @@ lde_gc_start_timer(void) void lde_gc_stop_timer(void) { - THREAD_TIMER_OFF(gc_timer); + thread_cancel(&gc_timer); } diff --git a/ldpd/ldpd.c b/ldpd/ldpd.c index 940333f83c..d6da45c862 100644 --- a/ldpd/ldpd.c +++ b/ldpd/ldpd.c @@ -604,8 +604,8 @@ main_dispatch_ldpe(struct thread *thread) imsg_event_add(iev); else { /* this pipe is dead, so remove the event handlers and exit */ - THREAD_READ_OFF(iev->ev_read); - THREAD_WRITE_OFF(iev->ev_write); + thread_cancel(&iev->ev_read); + thread_cancel(&iev->ev_write); ldpe_pid = 0; if (lde_pid == 0) ldpd_shutdown(); @@ -702,8 +702,8 @@ main_dispatch_lde(struct thread *thread) imsg_event_add(iev); else { /* this pipe is dead, so remove the event handlers and exit */ - THREAD_READ_OFF(iev->ev_read); - THREAD_WRITE_OFF(iev->ev_write); + thread_cancel(&iev->ev_read); + thread_cancel(&iev->ev_write); lde_pid = 0; if (ldpe_pid == 0) ldpd_shutdown(); @@ -728,8 +728,8 @@ ldp_write_handler(struct thread *thread) fatal("msgbuf_write"); if (n == 0) { /* this pipe is dead, so remove the event handlers */ - THREAD_READ_OFF(iev->ev_read); - THREAD_WRITE_OFF(iev->ev_write); + thread_cancel(&iev->ev_read); + thread_cancel(&iev->ev_write); return (0); } @@ -816,7 +816,7 @@ evbuf_init(struct evbuf *eb, int fd, int (*handler)(struct thread *), void evbuf_clear(struct evbuf *eb) { - THREAD_WRITE_OFF(eb->ev); + thread_cancel(&eb->ev); msgbuf_clear(&eb->wbuf); eb->wbuf.fd = -1; } diff --git a/ldpd/ldpe.c b/ldpd/ldpe.c index d3374a62db..ffc1d17f51 100644 --- a/ldpd/ldpe.c +++ b/ldpd/ldpe.c @@ -208,7 +208,7 @@ ldpe_shutdown(void) #ifdef __OpenBSD__ if (sysdep.no_pfkey == 0) { - THREAD_READ_OFF(pfkey_ev); + thread_cancel(&pfkey_ev); close(global.pfkeysock); } #endif @@ -580,8 +580,8 @@ ldpe_dispatch_main(struct thread *thread) imsg_event_add(iev); else { /* this pipe is dead, so remove the event handlers and exit */ - THREAD_READ_OFF(iev->ev_read); - THREAD_WRITE_OFF(iev->ev_write); + thread_cancel(&iev->ev_read); + thread_cancel(&iev->ev_write); ldpe_shutdown(); } @@ -719,8 +719,8 @@ ldpe_dispatch_lde(struct thread *thread) imsg_event_add(iev); else { /* this pipe is dead, so remove the event handlers and exit */ - THREAD_READ_OFF(iev->ev_read); - THREAD_WRITE_OFF(iev->ev_write); + thread_cancel(&iev->ev_read); + thread_cancel(&iev->ev_write); ldpe_shutdown(); } @@ -778,14 +778,14 @@ ldpe_close_sockets(int af) af_global = ldp_af_global_get(&global, af); /* discovery socket */ - THREAD_READ_OFF(af_global->disc_ev); + thread_cancel(&af_global->disc_ev); if (af_global->ldp_disc_socket != -1) { close(af_global->ldp_disc_socket); af_global->ldp_disc_socket = -1; } /* extended discovery socket */ - THREAD_READ_OFF(af_global->edisc_ev); + thread_cancel(&af_global->edisc_ev); if (af_global->ldp_edisc_socket != -1) { close(af_global->ldp_edisc_socket); af_global->ldp_edisc_socket = -1; diff --git a/ldpd/neighbor.c b/ldpd/neighbor.c index 423410f290..75deaad2c0 100644 --- a/ldpd/neighbor.c +++ b/ldpd/neighbor.c @@ -302,7 +302,7 @@ nbr_del(struct nbr *nbr) nbr->auth.method = AUTH_NONE; if (nbr_pending_connect(nbr)) - THREAD_WRITE_OFF(nbr->ev_connect); + thread_cancel(&nbr->ev_connect); nbr_stop_ktimer(nbr); nbr_stop_ktimeout(nbr); nbr_stop_itimeout(nbr); @@ -416,7 +416,7 @@ nbr_start_ktimer(struct nbr *nbr) /* send three keepalives per period */ secs = nbr->keepalive / KEEPALIVE_PER_PERIOD; - THREAD_TIMER_OFF(nbr->keepalive_timer); + thread_cancel(&nbr->keepalive_timer); nbr->keepalive_timer = NULL; thread_add_timer(master, nbr_ktimer, nbr, secs, &nbr->keepalive_timer); } @@ -424,7 +424,7 @@ nbr_start_ktimer(struct nbr *nbr) void nbr_stop_ktimer(struct nbr *nbr) { - THREAD_TIMER_OFF(nbr->keepalive_timer); + thread_cancel(&nbr->keepalive_timer); } /* Keepalive timeout: if the nbr hasn't sent keepalive */ @@ -446,7 +446,7 @@ nbr_ktimeout(struct thread *thread) static void nbr_start_ktimeout(struct nbr *nbr) { - THREAD_TIMER_OFF(nbr->keepalive_timeout); + thread_cancel(&nbr->keepalive_timeout); nbr->keepalive_timeout = NULL; thread_add_timer(master, nbr_ktimeout, nbr, nbr->keepalive, &nbr->keepalive_timeout); @@ -455,7 +455,7 @@ nbr_start_ktimeout(struct nbr *nbr) void nbr_stop_ktimeout(struct nbr *nbr) { - THREAD_TIMER_OFF(nbr->keepalive_timeout); + thread_cancel(&nbr->keepalive_timeout); } /* Session initialization timeout: if nbr got stuck in the initialization FSM */ @@ -478,7 +478,7 @@ nbr_start_itimeout(struct nbr *nbr) int secs; secs = INIT_FSM_TIMEOUT; - THREAD_TIMER_OFF(nbr->init_timeout); + thread_cancel(&nbr->init_timeout); nbr->init_timeout = NULL; thread_add_timer(master, nbr_itimeout, nbr, secs, &nbr->init_timeout); } @@ -486,7 +486,7 @@ nbr_start_itimeout(struct nbr *nbr) void nbr_stop_itimeout(struct nbr *nbr) { - THREAD_TIMER_OFF(nbr->init_timeout); + thread_cancel(&nbr->init_timeout); } /* Init delay timer: timer to retry to iniziatize session */ @@ -527,7 +527,7 @@ nbr_start_idtimer(struct nbr *nbr) break; } - THREAD_TIMER_OFF(nbr->initdelay_timer); + thread_cancel(&nbr->initdelay_timer); nbr->initdelay_timer = NULL; thread_add_timer(master, nbr_idtimer, nbr, secs, &nbr->initdelay_timer); @@ -536,7 +536,7 @@ nbr_start_idtimer(struct nbr *nbr) void nbr_stop_idtimer(struct nbr *nbr) { - THREAD_TIMER_OFF(nbr->initdelay_timer); + thread_cancel(&nbr->initdelay_timer); } int diff --git a/ldpd/packet.c b/ldpd/packet.c index 06ada5957e..fdcaa79d23 100644 --- a/ldpd/packet.c +++ b/ldpd/packet.c @@ -662,7 +662,7 @@ session_shutdown(struct nbr *nbr, uint32_t status, uint32_t msg_id, switch (nbr->state) { case NBR_STA_PRESENT: if (nbr_pending_connect(nbr)) - THREAD_WRITE_OFF(nbr->ev_connect); + thread_cancel(&nbr->ev_connect); break; case NBR_STA_INITIAL: case NBR_STA_OPENREC: @@ -762,7 +762,7 @@ tcp_close(struct tcp_conn *tcp) evbuf_clear(&tcp->wbuf); if (tcp->nbr) { - THREAD_READ_OFF(tcp->rev); + thread_cancel(&tcp->rev); free(tcp->rbuf); tcp->nbr->tcp = NULL; } @@ -794,7 +794,7 @@ pending_conn_new(int fd, int af, union ldpd_addr *addr) void pending_conn_del(struct pending_conn *pconn) { - THREAD_TIMER_OFF(pconn->ev_timeout); + thread_cancel(&pconn->ev_timeout); TAILQ_REMOVE(&global.pending_conns, pconn, entry); free(pconn); } diff --git a/lib/agentx.c b/lib/agentx.c index 7c4bdcbe27..603d8d6172 100644 --- a/lib/agentx.c +++ b/lib/agentx.c @@ -107,7 +107,7 @@ static void agentx_events_update(void) struct thread *thr; int fd, thr_fd; - THREAD_OFF(timeout_thr); + thread_cancel(&timeout_thr); FD_ZERO(&fds); snmp_select_info(&maxfd, &fds, &timeout, &block); @@ -130,7 +130,7 @@ static void agentx_events_update(void) if (thr_fd == fd) { struct listnode *nextln = listnextnode(ln); if (!FD_ISSET(fd, &fds)) { - thread_cancel(thr); + thread_cancel(&thr); list_delete_node(events, ln); } ln = nextln; @@ -151,7 +151,8 @@ static void agentx_events_update(void) */ while (ln) { struct listnode *nextln = listnextnode(ln); - thread_cancel(listgetdata(ln)); + thr = listgetdata(ln); + thread_cancel(&thr); list_delete_node(events, ln); ln = nextln; } diff --git a/lib/frr_zmq.c b/lib/frr_zmq.c index 565936a410..cc11d76700 100644 --- a/lib/frr_zmq.c +++ b/lib/frr_zmq.c @@ -190,10 +190,8 @@ int funcname_frrzmq_thread_add_read(struct thread_master *master, cb->read.cancelled = false; if (events & ZMQ_POLLIN) { - if (cb->read.thread) { - thread_cancel(cb->read.thread); - cb->read.thread = NULL; - } + thread_cancel(&cb->read.thread); + funcname_thread_add_event(master, frrzmq_read_msg, cbp, fd, &cb->read.thread, funcname, schedfrom, fromln); @@ -298,10 +296,8 @@ int funcname_frrzmq_thread_add_write(struct thread_master *master, cb->write.cancelled = false; if (events & ZMQ_POLLOUT) { - if (cb->write.thread) { - thread_cancel(cb->write.thread); - cb->write.thread = NULL; - } + thread_cancel(&cb->write.thread); + funcname_thread_add_event(master, frrzmq_write_msg, cbp, fd, &cb->write.thread, funcname, schedfrom, fromln); @@ -317,10 +313,8 @@ void frrzmq_thread_cancel(struct frrzmq_cb **cb, struct cb_core *core) if (!cb || !*cb) return; core->cancelled = true; - if (core->thread) { - thread_cancel(core->thread); - core->thread = NULL; - } + thread_cancel(&core->thread); + if ((*cb)->read.cancelled && !(*cb)->read.thread && (*cb)->write.cancelled && (*cb)->write.thread) XFREE(MTYPE_ZEROMQ_CB, *cb); @@ -344,8 +338,8 @@ void frrzmq_check_events(struct frrzmq_cb **cbp, struct cb_core *core, return; if (events & event && core->thread && !core->cancelled) { struct thread_master *tm = core->thread->master; - thread_cancel(core->thread); - core->thread = NULL; + thread_cancel(&core->thread); + thread_add_event(tm, (event == ZMQ_POLLIN ? frrzmq_read_msg : frrzmq_write_msg), cbp, cb->fd, &core->thread); diff --git a/lib/ldp_sync.c b/lib/ldp_sync.c index 9657f0b1df..c9d7eb37cf 100644 --- a/lib/ldp_sync.c +++ b/lib/ldp_sync.c @@ -79,7 +79,7 @@ bool ldp_sync_if_down(struct ldp_sync_info *ldp_sync_info) * update state */ if (ldp_sync_info && ldp_sync_info->enabled == LDP_IGP_SYNC_ENABLED) { - THREAD_TIMER_OFF(ldp_sync_info->t_holddown); + THREAD_OFF(ldp_sync_info->t_holddown); if (ldp_sync_info->state == LDP_IGP_SYNC_STATE_REQUIRED_UP) ldp_sync_info->state = diff --git a/lib/northbound_cli.c b/lib/northbound_cli.c index a7f3a1b305..7048df99fb 100644 --- a/lib/northbound_cli.c +++ b/lib/northbound_cli.c @@ -89,7 +89,7 @@ static int nb_cli_classic_commit(struct vty *vty) static void nb_cli_pending_commit_clear(struct vty *vty) { - THREAD_TIMER_OFF(vty->t_pending_commit); + THREAD_OFF(vty->t_pending_commit); vty->backoff_cmd_count = 0; XFREE(MTYPE_TMP, vty->pending_cmds_buf); vty->pending_cmds_buflen = 0; @@ -154,7 +154,7 @@ static int nb_cli_schedule_command(struct vty *vty) vty->pending_cmds_buflen); /* Schedule the commit operation. */ - THREAD_TIMER_OFF(vty->t_pending_commit); + THREAD_OFF(vty->t_pending_commit); thread_add_timer_msec(master, nb_cli_pending_commit_cb, vty, 100, &vty->t_pending_commit); @@ -312,7 +312,7 @@ int nb_cli_rpc(struct vty *vty, const char *xpath, struct list *input, void nb_cli_confirmed_commit_clean(struct vty *vty) { - THREAD_TIMER_OFF(vty->t_confirmed_commit_timeout); + thread_cancel(&vty->t_confirmed_commit_timeout); nb_config_free(vty->confirmed_commit_rollback); vty->confirmed_commit_rollback = NULL; } @@ -377,7 +377,7 @@ static int nb_cli_commit(struct vty *vty, bool force, "%% Resetting confirmed-commit timeout to %u minute(s)\n\n", confirmed_timeout); - THREAD_TIMER_OFF(vty->t_confirmed_commit_timeout); + thread_cancel(&vty->t_confirmed_commit_timeout); thread_add_timer(master, nb_cli_confirmed_commit_timeout, vty, confirmed_timeout * 60, diff --git a/lib/spf_backoff.c b/lib/spf_backoff.c index acb208e5e7..ac6dd29f06 100644 --- a/lib/spf_backoff.c +++ b/lib/spf_backoff.c @@ -110,8 +110,8 @@ void spf_backoff_free(struct spf_backoff *backoff) if (!backoff) return; - THREAD_TIMER_OFF(backoff->t_holddown); - THREAD_TIMER_OFF(backoff->t_timetolearn); + thread_cancel(&backoff->t_holddown); + thread_cancel(&backoff->t_timetolearn); XFREE(MTYPE_SPF_BACKOFF_NAME, backoff->name); XFREE(MTYPE_SPF_BACKOFF, backoff); @@ -121,7 +121,6 @@ static int spf_backoff_timetolearn_elapsed(struct thread *thread) { struct spf_backoff *backoff = THREAD_ARG(thread); - backoff->t_timetolearn = NULL; backoff->state = SPF_BACKOFF_LONG_WAIT; backoff_debug("SPF Back-off(%s) TIMETOLEARN elapsed, move to state %s", backoff->name, spf_backoff_state2str(backoff->state)); @@ -132,7 +131,7 @@ static int spf_backoff_holddown_elapsed(struct thread *thread) { struct spf_backoff *backoff = THREAD_ARG(thread); - THREAD_TIMER_OFF(backoff->t_timetolearn); + THREAD_OFF(backoff->t_timetolearn); timerclear(&backoff->first_event_time); backoff->state = SPF_BACKOFF_QUIET; backoff_debug("SPF Back-off(%s) HOLDDOWN elapsed, move to state %s", @@ -166,7 +165,7 @@ long spf_backoff_schedule(struct spf_backoff *backoff) break; case SPF_BACKOFF_SHORT_WAIT: case SPF_BACKOFF_LONG_WAIT: - THREAD_TIMER_OFF(backoff->t_holddown); + thread_cancel(&backoff->t_holddown); thread_add_timer_msec(backoff->m, spf_backoff_holddown_elapsed, backoff, backoff->holddown, &backoff->t_holddown); diff --git a/lib/thread.c b/lib/thread.c index db35a3f031..012194a47b 100644 --- a/lib/thread.c +++ b/lib/thread.c @@ -1163,19 +1163,26 @@ void thread_cancel_event(struct thread_master *master, void *arg) * * @param thread task to cancel */ -void thread_cancel(struct thread *thread) +void thread_cancel(struct thread **thread) { - struct thread_master *master = thread->master; + struct thread_master *master; + + if (thread == NULL || *thread == NULL) + return; + + master = (*thread)->master; assert(master->owner == pthread_self()); frr_with_mutex(&master->mtx) { struct cancel_req *cr = XCALLOC(MTYPE_TMP, sizeof(struct cancel_req)); - cr->thread = thread; + cr->thread = *thread; listnode_add(master->cancel_req, cr); do_thread_cancel(master); } + + *thread = NULL; } /** @@ -1227,6 +1234,9 @@ void thread_cancel_async(struct thread_master *master, struct thread **thread, while (!master->canceled) pthread_cond_wait(&master->cancel_cond, &master->mtx); } + + if (thread) + *thread = NULL; } /* ------------------------------------------------------------------------- */ diff --git a/lib/thread.h b/lib/thread.h index c22b2105cd..e2b7763c51 100644 --- a/lib/thread.h +++ b/lib/thread.h @@ -147,18 +147,15 @@ struct cpu_thread_history { #define THREAD_FD(X) ((X)->u.fd) #define THREAD_VAL(X) ((X)->u.val) -#define THREAD_OFF(thread) \ - do { \ - if (thread) { \ - thread_cancel(thread); \ - thread = NULL; \ - } \ +/* + * Please consider this macro deprecated, and do not use it in new code. + */ +#define THREAD_OFF(thread) \ + do { \ + if ((thread)) \ + thread_cancel(&(thread)); \ } while (0) -#define THREAD_READ_OFF(thread) THREAD_OFF(thread) -#define THREAD_WRITE_OFF(thread) THREAD_OFF(thread) -#define THREAD_TIMER_OFF(thread) THREAD_OFF(thread) - #define debugargdef const char *funcname, const char *schedfrom, int fromln #define thread_add_read(m,f,a,v,t) funcname_thread_add_read_write(THREAD_READ,m,f,a,v,t,#f,__FILE__,__LINE__) @@ -207,7 +204,7 @@ extern void funcname_thread_execute(struct thread_master *, debugargdef); #undef debugargdef -extern void thread_cancel(struct thread *); +extern void thread_cancel(struct thread **event); extern void thread_cancel_async(struct thread_master *, struct thread **, void *); extern void thread_cancel_event(struct thread_master *, void *); diff --git a/lib/workqueue.c b/lib/workqueue.c index 54090d0d0f..f8e4677220 100644 --- a/lib/workqueue.c +++ b/lib/workqueue.c @@ -104,7 +104,7 @@ void work_queue_free_and_null(struct work_queue **wqp) struct work_queue *wq = *wqp; if (wq->thread != NULL) - thread_cancel(wq->thread); + thread_cancel(&(wq->thread)); while (!work_queue_empty(wq)) { struct work_queue_item *item = work_queue_last_item(wq); @@ -215,7 +215,7 @@ void workqueue_cmd_init(void) void work_queue_plug(struct work_queue *wq) { if (wq->thread) - thread_cancel(wq->thread); + thread_cancel(&(wq->thread)); wq->thread = NULL; diff --git a/nhrpd/netlink_arp.c b/nhrpd/netlink_arp.c index cf338a0876..309f733526 100644 --- a/nhrpd/netlink_arp.c +++ b/nhrpd/netlink_arp.c @@ -257,7 +257,7 @@ static int netlink_log_recv(struct thread *t) void netlink_set_nflog_group(int nlgroup) { if (netlink_log_fd >= 0) { - THREAD_OFF(netlink_log_thread); + thread_cancel(&netlink_log_thread); close(netlink_log_fd); netlink_log_fd = -1; } diff --git a/nhrpd/nhrp_nhs.c b/nhrpd/nhrp_nhs.c index 8509cedcee..085cab347f 100644 --- a/nhrpd/nhrp_nhs.c +++ b/nhrpd/nhrp_nhs.c @@ -137,7 +137,7 @@ static void nhrp_reg_peer_notify(struct notifier_block *n, unsigned long cmd) debugf(NHRP_DEBUG_COMMON, "NHS: Flush timer for %s", sockunion2str(&r->peer->vc->remote.nbma, buf, sizeof(buf))); - THREAD_TIMER_OFF(r->t_register); + THREAD_OFF(r->t_register); thread_add_timer_msec(master, nhrp_reg_send_req, r, 10, &r->t_register); break; diff --git a/ospfd/ospf_apiserver.c b/ospfd/ospf_apiserver.c index 9d3493e910..c01ecdd1d4 100644 --- a/ospfd/ospf_apiserver.c +++ b/ospfd/ospf_apiserver.c @@ -317,21 +317,12 @@ void ospf_apiserver_free(struct ospf_apiserver *apiserv) struct listnode *node; /* Cancel read and write threads. */ - if (apiserv->t_sync_read) { - thread_cancel(apiserv->t_sync_read); - } + thread_cancel(&apiserv->t_sync_read); #ifdef USE_ASYNC_READ - if (apiserv->t_async_read) { - thread_cancel(apiserv->t_async_read); - } + thread_cancel(&apiserv->t_async_read); #endif /* USE_ASYNC_READ */ - if (apiserv->t_sync_write) { - thread_cancel(apiserv->t_sync_write); - } - - if (apiserv->t_async_write) { - thread_cancel(apiserv->t_async_write); - } + thread_cancel(&apiserv->t_sync_write); + thread_cancel(&apiserv->t_async_write); /* Unregister all opaque types that application registered and flush opaque LSAs if still in LSDB. */ diff --git a/ospfd/ospf_ism.h b/ospfd/ospf_ism.h index 67ea4c4684..c41ba6c843 100644 --- a/ospfd/ospf_ism.h +++ b/ospfd/ospf_ism.h @@ -79,13 +79,7 @@ } while (0) /* Macro for OSPF ISM timer turn off. */ -#define OSPF_ISM_TIMER_OFF(X) \ - do { \ - if (X) { \ - thread_cancel(X); \ - (X) = NULL; \ - } \ - } while (0) +#define OSPF_ISM_TIMER_OFF(X) thread_cancel(&(X)) /* Macro for OSPF schedule event. */ #define OSPF_ISM_EVENT_SCHEDULE(I, E) \ diff --git a/ospfd/ospf_ldp_sync.c b/ospfd/ospf_ldp_sync.c index 96fa04b588..68792ebcc2 100644 --- a/ospfd/ospf_ldp_sync.c +++ b/ospfd/ospf_ldp_sync.c @@ -99,8 +99,7 @@ int ospf_ldp_sync_announce_update(struct ldp_igp_sync_announce announce) FOR_ALL_INTERFACES (vrf, ifp) ospf_ldp_sync_if_start(ifp, true); - THREAD_TIMER_OFF(ospf->ldp_sync_cmd.t_hello); - ospf->ldp_sync_cmd.t_hello = NULL; + THREAD_OFF(ospf->ldp_sync_cmd.t_hello); ospf->ldp_sync_cmd.sequence = 0; ospf_ldp_sync_hello_timer_add(ospf); @@ -140,7 +139,7 @@ int ospf_ldp_sync_hello_update(struct ldp_igp_sync_hello hello) FOR_ALL_INTERFACES (vrf, ifp) ospf_ldp_sync_if_start(ifp, true); } else { - THREAD_TIMER_OFF(ospf->ldp_sync_cmd.t_hello); + THREAD_OFF(ospf->ldp_sync_cmd.t_hello); ospf_ldp_sync_hello_timer_add(ospf); } ospf->ldp_sync_cmd.sequence = hello.sequence; @@ -249,8 +248,7 @@ void ospf_ldp_sync_if_complete(struct interface *ifp) if (ldp_sync_info && ldp_sync_info->enabled == LDP_IGP_SYNC_ENABLED) { if (ldp_sync_info->state == LDP_IGP_SYNC_STATE_REQUIRED_NOT_UP) ldp_sync_info->state = LDP_IGP_SYNC_STATE_REQUIRED_UP; - THREAD_TIMER_OFF(ldp_sync_info->t_holddown); - ldp_sync_info->t_holddown = NULL; + THREAD_OFF(ldp_sync_info->t_holddown); ospf_if_recalculate_output_cost(ifp); } } @@ -274,7 +272,7 @@ void ospf_ldp_sync_ldp_fail(struct interface *ifp) if (ldp_sync_info && ldp_sync_info->enabled == LDP_IGP_SYNC_ENABLED && ldp_sync_info->state != LDP_IGP_SYNC_STATE_NOT_REQUIRED) { - THREAD_TIMER_OFF(ldp_sync_info->t_holddown); + THREAD_OFF(ldp_sync_info->t_holddown); ldp_sync_info->state = LDP_IGP_SYNC_STATE_REQUIRED_NOT_UP; ospf_if_recalculate_output_cost(ifp); } @@ -337,7 +335,9 @@ void ospf_ldp_sync_if_remove(struct interface *ifp, bool remove) * restore cost */ ols_debug("ldp_sync: Removed from if %s", ifp->name); - THREAD_TIMER_OFF(ldp_sync_info->t_holddown); + + THREAD_OFF(ldp_sync_info->t_holddown); + ldp_sync_info->state = LDP_IGP_SYNC_STATE_NOT_REQUIRED; ospf_if_recalculate_output_cost(ifp); if (!CHECK_FLAG(ldp_sync_info->flags, LDP_SYNC_FLAG_IF_CONFIG)) @@ -386,7 +386,6 @@ static int ospf_ldp_sync_holddown_timer(struct thread *thread) ldp_sync_info = params->ldp_sync_info; ldp_sync_info->state = LDP_IGP_SYNC_STATE_REQUIRED_UP; - ldp_sync_info->t_holddown = NULL; ols_debug("ldp_sync: holddown timer expired for %s state: %s", ifp->name, "Sync achieved"); @@ -436,7 +435,6 @@ static int ospf_ldp_sync_hello_timer(struct thread *thread) */ ospf = ospf_lookup_by_vrf_id(VRF_DEFAULT); if (ospf) { - ospf->ldp_sync_cmd.t_hello = NULL; vrf = vrf_lookup_by_id(ospf->vrf_id); FOR_ALL_INTERFACES (vrf, ifp) @@ -486,8 +484,8 @@ void ospf_ldp_sync_gbl_exit(struct ospf *ospf, bool remove) UNSET_FLAG(ospf->ldp_sync_cmd.flags, LDP_SYNC_FLAG_ENABLE); UNSET_FLAG(ospf->ldp_sync_cmd.flags, LDP_SYNC_FLAG_HOLDDOWN); ospf->ldp_sync_cmd.holddown = LDP_IGP_SYNC_HOLDDOWN_DEFAULT; - THREAD_TIMER_OFF(ospf->ldp_sync_cmd.t_hello); - ospf->ldp_sync_cmd.t_hello = NULL; + + THREAD_OFF(ospf->ldp_sync_cmd.t_hello); /* turn off LDP-IGP Sync on all OSPF interfaces */ vrf = vrf_lookup_by_id(ospf->vrf_id); @@ -980,8 +978,7 @@ DEFPY (no_mpls_ldp_sync, SET_FLAG(ldp_sync_info->flags, LDP_SYNC_FLAG_IF_CONFIG); ldp_sync_info->enabled = LDP_IGP_SYNC_DEFAULT; ldp_sync_info->state = LDP_IGP_SYNC_STATE_NOT_REQUIRED; - THREAD_TIMER_OFF(ldp_sync_info->t_holddown); - ldp_sync_info->t_holddown = NULL; + THREAD_OFF(ldp_sync_info->t_holddown); ospf_if_recalculate_output_cost(ifp); return CMD_SUCCESS; diff --git a/ospfd/ospf_nsm.h b/ospfd/ospf_nsm.h index c219ba7386..24cf05009c 100644 --- a/ospfd/ospf_nsm.h +++ b/ospfd/ospf_nsm.h @@ -59,13 +59,7 @@ #define OSPF_NSM_TIMER_ON(T,F,V) thread_add_timer (master, (F), nbr, (V), &(T)) /* Macro for OSPF NSM timer turn off. */ -#define OSPF_NSM_TIMER_OFF(X) \ - do { \ - if (X) { \ - thread_cancel(X); \ - (X) = NULL; \ - } \ - } while (0) +#define OSPF_NSM_TIMER_OFF(X) thread_cancel(&(X)) /* Macro for OSPF NSM schedule event. */ #define OSPF_NSM_EVENT_SCHEDULE(N, E) \ diff --git a/ospfd/ospf_packet.c b/ospfd/ospf_packet.c index 8cb0062ea4..ef39b6c2f6 100644 --- a/ospfd/ospf_packet.c +++ b/ospfd/ospf_packet.c @@ -468,11 +468,7 @@ static int ospf_ls_req_timer(struct thread *thread) void ospf_ls_req_event(struct ospf_neighbor *nbr) { - if (nbr->t_ls_req) { - thread_cancel(nbr->t_ls_req); - nbr->t_ls_req = NULL; - } - nbr->t_ls_req = NULL; + thread_cancel(&nbr->t_ls_req); thread_add_event(master, ospf_ls_req_timer, nbr, 0, &nbr->t_ls_req); } diff --git a/ospfd/ospf_sr.c b/ospfd/ospf_sr.c index 4e32732c86..b0b273fb23 100644 --- a/ospfd/ospf_sr.c +++ b/ospfd/ospf_sr.c @@ -519,7 +519,7 @@ static void ospf_sr_stop(void) osr_debug("SR (%s): Stop Segment Routing", __func__); /* Disable any re-attempt to connect to Label Manager */ - THREAD_TIMER_OFF(OspfSR.t_start_lm); + THREAD_OFF(OspfSR.t_start_lm); /* Release SRGB & SRLB if active. */ if (OspfSR.srgb.reserved) diff --git a/ospfd/ospfd.c b/ospfd/ospfd.c index ce3bc33c1a..3718f82c05 100644 --- a/ospfd/ospfd.c +++ b/ospfd/ospfd.c @@ -1324,10 +1324,7 @@ void ospf_ls_upd_queue_empty(struct ospf_interface *oi) } /* remove update event */ - if (oi->t_ls_upd_event) { - thread_cancel(oi->t_ls_upd_event); - oi->t_ls_upd_event = NULL; - } + thread_cancel(&oi->t_ls_upd_event); } void ospf_if_update(struct ospf *ospf, struct interface *ifp) @@ -2158,7 +2155,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_cancel(ospf->t_read); + thread_cancel(&ospf->t_read); close(ospf->fd); ospf->fd = -1; } diff --git a/ospfd/ospfd.h b/ospfd/ospfd.h index 5009355d48..5535cb40ab 100644 --- a/ospfd/ospfd.h +++ b/ospfd/ospfd.h @@ -535,13 +535,7 @@ struct ospf_nbr_nbma { #define OSPF_AREA_TIMER_ON(T,F,V) thread_add_timer (master, (F), area, (V), &(T)) #define OSPF_POLL_TIMER_ON(T,F,V) thread_add_timer (master, (F), nbr_nbma, (V), &(T)) #define OSPF_POLL_TIMER_OFF(X) OSPF_TIMER_OFF((X)) -#define OSPF_TIMER_OFF(X) \ - do { \ - if (X) { \ - thread_cancel(X); \ - (X) = NULL; \ - } \ - } while (0) +#define OSPF_TIMER_OFF(X) thread_cancel(&(X)) /* Extern variables. */ extern struct ospf_master *om; diff --git a/pimd/pim_msdp.h b/pimd/pim_msdp.h index 6caa3181e7..15a1041e21 100644 --- a/pimd/pim_msdp.h +++ b/pimd/pim_msdp.h @@ -208,8 +208,8 @@ struct pim_msdp { thread_add_write(mp->pim->msdp.master, pim_msdp_write, mp, mp->fd, \ &mp->t_write) -#define PIM_MSDP_PEER_READ_OFF(mp) THREAD_READ_OFF(mp->t_read) -#define PIM_MSDP_PEER_WRITE_OFF(mp) THREAD_WRITE_OFF(mp->t_write) +#define PIM_MSDP_PEER_READ_OFF(mp) thread_cancel(&mp->t_read) +#define PIM_MSDP_PEER_WRITE_OFF(mp) thread_cancel(&mp->t_write) // struct pim_msdp *msdp; struct pim_instance; diff --git a/pimd/pim_neighbor.c b/pimd/pim_neighbor.c index 4d6625bf6f..167aa3c604 100644 --- a/pimd/pim_neighbor.c +++ b/pimd/pim_neighbor.c @@ -294,7 +294,7 @@ static int on_neighbor_jp_timer(struct thread *t) static void pim_neighbor_start_jp_timer(struct pim_neighbor *neigh) { - THREAD_TIMER_OFF(neigh->jp_timer); + THREAD_OFF(neigh->jp_timer); thread_add_timer(router->master, on_neighbor_jp_timer, neigh, router->t_periodic, &neigh->jp_timer); } diff --git a/pimd/pim_upstream.c b/pimd/pim_upstream.c index 6bb25c436a..d95b092d94 100644 --- a/pimd/pim_upstream.c +++ b/pimd/pim_upstream.c @@ -1768,7 +1768,7 @@ void pim_upstream_start_register_stop_timer(struct pim_upstream *up, { uint32_t time; - THREAD_TIMER_OFF(up->t_rs_timer); + THREAD_OFF(up->t_rs_timer); if (!null_register) { uint32_t lower = (0.5 * PIM_REGISTER_SUPPRESSION_PERIOD); diff --git a/ripd/rip_interface.c b/ripd/rip_interface.c index c2cee4d69d..c601ab4047 100644 --- a/ripd/rip_interface.c +++ b/ripd/rip_interface.c @@ -468,10 +468,7 @@ static void rip_interface_clean(struct rip_interface *ri) ri->enable_interface = 0; ri->running = 0; - if (ri->t_wakeup) { - thread_cancel(ri->t_wakeup); - ri->t_wakeup = NULL; - } + thread_cancel(&ri->t_wakeup); } void rip_interfaces_clean(struct rip *rip) diff --git a/ripd/rip_peer.c b/ripd/rip_peer.c index 4c5233c82c..23599f0877 100644 --- a/ripd/rip_peer.c +++ b/ripd/rip_peer.c @@ -86,8 +86,7 @@ static struct rip_peer *rip_peer_get(struct rip *rip, struct in_addr *addr) peer = rip_peer_lookup(rip, addr); if (peer) { - if (peer->t_timeout) - thread_cancel(peer->t_timeout); + thread_cancel(&peer->t_timeout); } else { peer = rip_peer_new(); peer->rip = rip; diff --git a/ripd/ripd.c b/ripd/ripd.c index 07f24b5a99..059a0e2efd 100644 --- a/ripd/ripd.c +++ b/ripd/ripd.c @@ -3596,7 +3596,7 @@ static void rip_instance_disable(struct rip *rip) RIP_TIMER_OFF(rip->t_triggered_interval); /* Cancel read thread. */ - THREAD_READ_OFF(rip->t_read); + thread_cancel(&rip->t_read); /* Close RIP socket. */ close(rip->sock); diff --git a/ripd/ripd.h b/ripd/ripd.h index 417bd5b3b1..99718f7b9e 100644 --- a/ripd/ripd.h +++ b/ripd/ripd.h @@ -405,7 +405,7 @@ enum rip_event { #define RIP_TIMER_ON(T,F,V) thread_add_timer (master, (F), rinfo, (V), &(T)) /* Macro for timer turn off. */ -#define RIP_TIMER_OFF(X) THREAD_TIMER_OFF(X) +#define RIP_TIMER_OFF(X) thread_cancel(&(X)) #define RIP_OFFSET_LIST_IN 0 #define RIP_OFFSET_LIST_OUT 1 diff --git a/ripngd/ripng_interface.c b/ripngd/ripng_interface.c index 16859c2d29..115d7a6b99 100644 --- a/ripngd/ripng_interface.c +++ b/ripngd/ripng_interface.c @@ -321,10 +321,7 @@ void ripng_interface_clean(struct ripng *ripng) ri->enable_interface = 0; ri->running = 0; - if (ri->t_wakeup) { - thread_cancel(ri->t_wakeup); - ri->t_wakeup = NULL; - } + thread_cancel(&ri->t_wakeup); } } diff --git a/ripngd/ripng_peer.c b/ripngd/ripng_peer.c index e6ff58dd0c..0ac489c67e 100644 --- a/ripngd/ripng_peer.c +++ b/ripngd/ripng_peer.c @@ -95,8 +95,7 @@ static struct ripng_peer *ripng_peer_get(struct ripng *ripng, peer = ripng_peer_lookup(ripng, addr); if (peer) { - if (peer->t_timeout) - thread_cancel(peer->t_timeout); + thread_cancel(&peer->t_timeout); } else { peer = ripng_peer_new(); peer->ripng = ripng; @@ -105,7 +104,6 @@ static struct ripng_peer *ripng_peer_get(struct ripng *ripng, } /* Update timeout thread. */ - peer->t_timeout = NULL; thread_add_timer(master, ripng_peer_timeout, peer, RIPNG_PEER_TIMER_DEFAULT, &peer->t_timeout); diff --git a/ripngd/ripngd.c b/ripngd/ripngd.c index 060477010b..8d9249e4ae 100644 --- a/ripngd/ripngd.c +++ b/ripngd/ripngd.c @@ -1463,10 +1463,7 @@ static int ripng_update(struct thread *t) /* Triggered updates may be suppressed if a regular update is due by the time the triggered update would be sent. */ - if (ripng->t_triggered_interval) { - thread_cancel(ripng->t_triggered_interval); - ripng->t_triggered_interval = NULL; - } + thread_cancel(&ripng->t_triggered_interval); ripng->trigger = 0; /* Reset flush event. */ @@ -1500,10 +1497,7 @@ int ripng_triggered_update(struct thread *t) ripng->t_triggered_update = NULL; /* Cancel interval timer. */ - if (ripng->t_triggered_interval) { - thread_cancel(ripng->t_triggered_interval); - ripng->t_triggered_interval = NULL; - } + thread_cancel(&ripng->t_triggered_interval); ripng->trigger = 0; /* Logging triggered update. */ @@ -1952,10 +1946,8 @@ void ripng_event(struct ripng *ripng, enum ripng_event event, int sock) &ripng->t_read); break; case RIPNG_UPDATE_EVENT: - if (ripng->t_update) { - thread_cancel(ripng->t_update); - ripng->t_update = NULL; - } + thread_cancel(&ripng->t_update); + /* Update timer jitter. */ jitter = ripng_update_jitter(ripng->update_time); @@ -2719,10 +2711,7 @@ static void ripng_instance_disable(struct ripng *ripng) RIPNG_TIMER_OFF(ripng->t_triggered_interval); /* Cancel the read thread */ - if (ripng->t_read) { - thread_cancel(ripng->t_read); - ripng->t_read = NULL; - } + thread_cancel(&ripng->t_read); /* Close the RIPng socket */ if (ripng->sock >= 0) { diff --git a/ripngd/ripngd.h b/ripngd/ripngd.h index 70508d5cb0..a42c32ebb7 100644 --- a/ripngd/ripngd.h +++ b/ripngd/ripngd.h @@ -351,13 +351,7 @@ enum ripng_event { /* RIPng timer on/off macro. */ #define RIPNG_TIMER_ON(T,F,V) thread_add_timer (master, (F), rinfo, (V), &(T)) -#define RIPNG_TIMER_OFF(T) \ - do { \ - if (T) { \ - thread_cancel(T); \ - (T) = NULL; \ - } \ - } while (0) +#define RIPNG_TIMER_OFF(T) thread_cancel(&(T)) #define RIPNG_OFFSET_LIST_IN 0 #define RIPNG_OFFSET_LIST_OUT 1 diff --git a/tests/lib/test_timer_correctness.c b/tests/lib/test_timer_correctness.c index cbf9b05546..416ea39772 100644 --- a/tests/lib/test_timer_correctness.c +++ b/tests/lib/test_timer_correctness.c @@ -153,7 +153,7 @@ int main(int argc, char **argv) continue; XFREE(MTYPE_TMP, timers[index]->arg); - thread_cancel(timers[index]); + thread_cancel(&timers[index]); timers[index] = NULL; timers_pending--; } diff --git a/tests/lib/test_timer_performance.c b/tests/lib/test_timer_performance.c index 2960e0d81e..45b29b92b1 100644 --- a/tests/lib/test_timer_performance.c +++ b/tests/lib/test_timer_performance.c @@ -59,7 +59,7 @@ int main(int argc, char **argv) thread_add_timer_msec(master, dummy_func, NULL, 0, &timers[i]); } for (i = 0; i < SCHEDULE_TIMERS; i++) - thread_cancel(timers[i]); + thread_cancel(&timers[i]); monotime(&tv_start); @@ -78,8 +78,7 @@ int main(int argc, char **argv) int index; index = prng_rand(prng) % SCHEDULE_TIMERS; - if (timers[index]) - thread_cancel(timers[index]); + thread_cancel(&timers[index]); timers[index] = NULL; } diff --git a/tools/coccinelle/README.md b/tools/coccinelle/README.md new file mode 100644 index 0000000000..262ccc1da0 --- /dev/null +++ b/tools/coccinelle/README.md @@ -0,0 +1,14 @@ +Coccinelle patches +================== + +This collection of coccinelle patches represents some of the broader, +codebase-wide changes that have been made. If you maintain a fork of +FRR and find that your codebase needs to be updated to align with +these changes, the coccinelle tool should help you make that update. + +The coccinelle tool is documented at: + https://coccinelle.gitlabpages.inria.fr/website/ + +To run a coccinelle patch script: + + spatch --sp-file tools/coccinelle/semicolon.cocci zebra/*.c diff --git a/tools/coccinelle/thread_cancel_api.cocci b/tools/coccinelle/thread_cancel_api.cocci new file mode 100644 index 0000000000..cc34f9389a --- /dev/null +++ b/tools/coccinelle/thread_cancel_api.cocci @@ -0,0 +1,68 @@ +@ptrupdate@ +expression E; +@@ +- thread_cancel(E); ++ thread_cancel(&E); + +@nullcheckremove depends on ptrupdate@ +expression E; +@@ + +thread_cancel(&E); +- E = NULL; + +@cancelguardremove depends on nullcheckremove@ +expression E; +@@ +- if (E) +- { + thread_cancel(&E); +- } + +@cancelguardremove2 depends on nullcheckremove@ +expression E; +@@ +- if (E != NULL) +- { + thread_cancel(&E); +- } + +@cancelguardremove3 depends on nullcheckremove@ +expression E; +@@ +- if (E) + thread_cancel(&E); + +@cancelguardremove4 depends on nullcheckremove@ +expression E; +@@ +- if (E != NULL) + thread_cancel(&E); + +@replacetimeroff@ +expression E; +@@ + +- THREAD_TIMER_OFF(E); ++ thread_cancel(&E); + +@replacewriteoff@ +expression E; +@@ + +- THREAD_WRITE_OFF(E); ++ thread_cancel(&E); + +@replacereadoff@ +expression E; +@@ + +- THREAD_READ_OFF(E); ++ thread_cancel(&E); + +@replacethreadoff@ +expression E; +@@ + +- THREAD_OFF(E); ++ thread_cancel(&E);
\ No newline at end of file diff --git a/watchfrr/watchfrr.c b/watchfrr/watchfrr.c index af243f7ca5..319bd6a771 100644 --- a/watchfrr/watchfrr.c +++ b/watchfrr/watchfrr.c @@ -409,8 +409,8 @@ static void sigchild(void) what = restart->what; restart->pid = 0; gs.numpids--; - thread_cancel(restart->t_kill); - restart->t_kill = NULL; + thread_cancel(&restart->t_kill); + /* Update restart time to reflect the time the command * completed. */ gettimeofday(&restart->time, NULL); @@ -586,6 +586,7 @@ static void restart_done(struct daemon *dmn) return; } THREAD_OFF(dmn->t_wakeup); + if (try_connect(dmn) < 0) SET_WAKEUP_DOWN(dmn); } @@ -678,8 +679,7 @@ static int handle_read(struct thread *t_read) dmn->name, (long)delay.tv_sec, (long)delay.tv_usec); SET_READ_HANDLER(dmn); - if (dmn->t_wakeup) - thread_cancel(dmn->t_wakeup); + thread_cancel(&dmn->t_wakeup); SET_WAKEUP_ECHO(dmn); return 0; @@ -866,9 +866,8 @@ static int phase_hanging(struct thread *t_hanging) static void set_phase(restart_phase_t new_phase) { gs.phase = new_phase; - if (gs.t_phase_hanging) - thread_cancel(gs.t_phase_hanging); - gs.t_phase_hanging = NULL; + thread_cancel(&gs.t_phase_hanging); + thread_add_timer(master, phase_hanging, NULL, PHASE_TIMEOUT, &gs.t_phase_hanging); } diff --git a/zebra/irdp_main.c b/zebra/irdp_main.c index 710a32c452..936206641f 100644 --- a/zebra/irdp_main.c +++ b/zebra/irdp_main.c @@ -263,9 +263,7 @@ void irdp_advert_off(struct interface *ifp) if (!irdp) return; - if (irdp->t_advertise) - thread_cancel(irdp->t_advertise); - irdp->t_advertise = NULL; + thread_cancel(&irdp->t_advertise); if (ifp->connected) for (ALL_LIST_ELEMENTS(ifp->connected, node, nnode, ifc)) { @@ -300,9 +298,7 @@ void process_solicit(struct interface *ifp) return; irdp->flags |= IF_SOLICIT; - if (irdp->t_advertise) - thread_cancel(irdp->t_advertise); - irdp->t_advertise = NULL; + thread_cancel(&irdp->t_advertise); timer = (frr_weak_random() % MAX_RESPONSE_DELAY) + 1; diff --git a/zebra/kernel_netlink.c b/zebra/kernel_netlink.c index c53d28a18c..601e3dfa84 100644 --- a/zebra/kernel_netlink.c +++ b/zebra/kernel_netlink.c @@ -1501,7 +1501,7 @@ void kernel_init(struct zebra_ns *zns) void kernel_terminate(struct zebra_ns *zns, bool complete) { - THREAD_READ_OFF(zns->t_netlink); + thread_cancel(&zns->t_netlink); if (zns->netlink.sock >= 0) { close(zns->netlink.sock); diff --git a/zebra/main.c b/zebra/main.c index 6b6409f845..ced29e1a25 100644 --- a/zebra/main.c +++ b/zebra/main.c @@ -170,12 +170,14 @@ static void sigint(void) zebra_ptm_finish(); - if (retain_mode) + if (retain_mode) { + zebra_nhg_mark_keep(); RB_FOREACH (vrf, vrf_name_head, &vrfs_by_name) { zvrf = vrf->info; if (zvrf) SET_FLAG(zvrf->flags, ZEBRA_VRF_RETAIN); } + } if (zrouter.lsp_process_q) work_queue_free_and_null(&zrouter.lsp_process_q); diff --git a/zebra/zebra_fpm.c b/zebra/zebra_fpm.c index 73996c526f..2bf48c6277 100644 --- a/zebra/zebra_fpm.c +++ b/zebra/zebra_fpm.c @@ -489,7 +489,7 @@ static inline void zfpm_write_on(void) */ static inline void zfpm_read_off(void) { - THREAD_READ_OFF(zfpm_g->t_read); + thread_cancel(&zfpm_g->t_read); } /* @@ -497,12 +497,12 @@ static inline void zfpm_read_off(void) */ static inline void zfpm_write_off(void) { - THREAD_WRITE_OFF(zfpm_g->t_write); + thread_cancel(&zfpm_g->t_write); } static inline void zfpm_connect_off(void) { - THREAD_TIMER_OFF(zfpm_g->t_connect); + thread_cancel(&zfpm_g->t_connect); } /* @@ -1687,7 +1687,7 @@ static void zfpm_stop_stats_timer(void) return; zfpm_debug("Stopping existing stats timer"); - THREAD_TIMER_OFF(zfpm_g->t_stats); + thread_cancel(&zfpm_g->t_stats); } /* diff --git a/zebra/zebra_netns_notify.c b/zebra/zebra_netns_notify.c index 995fa6fb5a..ee2dc7a0ed 100644 --- a/zebra/zebra_netns_notify.c +++ b/zebra/zebra_netns_notify.c @@ -378,7 +378,7 @@ void zebra_ns_notify_close(void) fd = zebra_netns_notify_current->u.fd; if (zebra_netns_notify_current->master != NULL) - thread_cancel(zebra_netns_notify_current); + thread_cancel(&zebra_netns_notify_current); /* auto-removal of notify items */ if (fd > 0) diff --git a/zebra/zebra_nhg.c b/zebra/zebra_nhg.c index f1f6e7e2bf..fa7bab9d2c 100644 --- a/zebra/zebra_nhg.c +++ b/zebra/zebra_nhg.c @@ -2711,6 +2711,30 @@ void zebra_nhg_sweep_table(struct hash *hash) hash_iterate(hash, zebra_nhg_sweep_entry, NULL); } +static void zebra_nhg_mark_keep_entry(struct hash_bucket *bucket, void *arg) +{ + struct nhg_hash_entry *nhe = bucket->data; + + UNSET_FLAG(nhe->flags, NEXTHOP_GROUP_INSTALLED); +} + +/* + * When we are shutting down and we have retain mode enabled + * in zebra the process is to mark each vrf that it's + * routes should not be deleted. The problem with that + * is that shutdown actually free's up memory which + * causes the nexthop group's ref counts to go to zero + * we need a way to subtly tell the system to not remove + * the nexthop groups from the kernel at the same time. + * The easiest just looks like that we should not mark + * the nhg's as installed any more and when the ref count + * goes to zero we'll attempt to delete and do nothing + */ +void zebra_nhg_mark_keep(void) +{ + hash_iterate(zrouter.nhgs_id, zebra_nhg_mark_keep_entry, NULL); +} + /* Global control to disable use of kernel nexthops, if available. We can't * force the kernel to support nexthop ids, of course, but we can disable * zebra's use of them, for testing e.g. By default, if the kernel supports diff --git a/zebra/zebra_nhg.h b/zebra/zebra_nhg.h index 052fa65d06..b2ef88bb61 100644 --- a/zebra/zebra_nhg.h +++ b/zebra/zebra_nhg.h @@ -324,9 +324,16 @@ struct zebra_dplane_ctx; extern void zebra_nhg_dplane_result(struct zebra_dplane_ctx *ctx); -/* Sweet the nhg hash tables for old entries on restart */ +/* Sweep the nhg hash tables for old entries on restart */ extern void zebra_nhg_sweep_table(struct hash *hash); +/* + * We are shutting down but the nexthops should be kept + * as that -r has been specified and we don't want to delete + * the routes unintentionally + */ +extern void zebra_nhg_mark_keep(void); + /* Nexthop resolution processing */ struct route_entry; /* Forward ref to avoid circular includes */ extern int nexthop_active_update(struct route_node *rn, struct route_entry *re); diff --git a/zebra/zebra_ptm.c b/zebra/zebra_ptm.c index 9a3b567b5a..1e7b38086b 100644 --- a/zebra/zebra_ptm.c +++ b/zebra/zebra_ptm.c @@ -156,13 +156,10 @@ void zebra_ptm_finish(void) if (ptm_cb.in_data) free(ptm_cb.in_data); - /* Release threads. */ - if (ptm_cb.t_read) - thread_cancel(ptm_cb.t_read); - if (ptm_cb.t_write) - thread_cancel(ptm_cb.t_write); - if (ptm_cb.t_timer) - thread_cancel(ptm_cb.t_timer); + /* Cancel events. */ + thread_cancel(&ptm_cb.t_read); + thread_cancel(&ptm_cb.t_write); + thread_cancel(&ptm_cb.t_timer); if (ptm_cb.wb) buffer_free(ptm_cb.wb); @@ -218,7 +215,7 @@ static int zebra_ptm_send_message(char *data, int size) ptm_cb.reconnect_time, &ptm_cb.t_timer); return -1; case BUFFER_EMPTY: - THREAD_OFF(ptm_cb.t_write); + thread_cancel(&ptm_cb.t_write); break; case BUFFER_PENDING: thread_add_write(zrouter.master, zebra_ptm_flush_messages, NULL, diff --git a/zebra/zebra_pw.c b/zebra/zebra_pw.c index cdcca1e930..ecae021dba 100644 --- a/zebra/zebra_pw.c +++ b/zebra/zebra_pw.c @@ -102,7 +102,7 @@ void zebra_pw_del(struct zebra_vrf *zvrf, struct zebra_pw *pw) hook_call(pw_uninstall, pw); dplane_pw_uninstall(pw); } else if (pw->install_retry_timer) - THREAD_TIMER_OFF(pw->install_retry_timer); + thread_cancel(&pw->install_retry_timer); /* unlink and release memory */ RB_REMOVE(zebra_pw_head, &zvrf->pseudowires, pw); @@ -219,7 +219,7 @@ void zebra_pw_install_failure(struct zebra_pw *pw, int pwstatus) pw->vrf_id, pw->ifname, PW_INSTALL_RETRY_INTERVAL); /* schedule to retry later */ - THREAD_TIMER_OFF(pw->install_retry_timer); + thread_cancel(&pw->install_retry_timer); thread_add_timer(zrouter.master, zebra_pw_install_retry, pw, PW_INSTALL_RETRY_INTERVAL, &pw->install_retry_timer); diff --git a/zebra/zebra_routemap.c b/zebra/zebra_routemap.c index 8155f9acfe..294f2c17ff 100644 --- a/zebra/zebra_routemap.c +++ b/zebra/zebra_routemap.c @@ -1695,7 +1695,7 @@ static void zebra_route_map_set_delay_timer(uint32_t value) if (!value && zebra_t_rmap_update) { /* Event driven route map updates is being disabled */ /* But there's a pending timer. Fire it off now */ - thread_cancel(zebra_t_rmap_update); + thread_cancel(&zebra_t_rmap_update); zebra_route_map_update_timer(zebra_t_rmap_update); } } @@ -1705,7 +1705,7 @@ void zebra_routemap_finish(void) /* Set zebra_rmap_update_timer to 0 so that it wont schedule again */ zebra_rmap_update_timer = 0; /* Thread off if any scheduled already */ - THREAD_TIMER_OFF(zebra_t_rmap_update); + thread_cancel(&zebra_t_rmap_update); route_map_finish(); } |
