From c905f04c7ce7b09189999d4908c379f880b6b179 Mon Sep 17 00:00:00 2001 From: Donald Sharp Date: Tue, 17 May 2022 16:29:29 -0400 Subject: [PATCH] ospf6d: Clean up thread interface a) Remove setting of thread pointer to NULL after thread invocation, this is already done. b) Use thread_is_scheduled() Signed-off-by: Donald Sharp --- ospf6d/ospf6_asbr.c | 4 +-- ospf6d/ospf6_gr.c | 1 - ospf6d/ospf6_gr_helper.c | 3 +-- ospf6d/ospf6_interface.c | 25 +++++++++++------- ospf6d/ospf6_message.c | 6 ----- ospf6d/ospf6_neighbor.c | 57 +++++++++++++++++++++++----------------- ospf6d/ospf6_nssa.c | 2 +- ospf6d/ospf6_spf.c | 6 ++--- ospf6d/ospf6_top.c | 8 +++--- 9 files changed, 59 insertions(+), 53 deletions(-) diff --git a/ospf6d/ospf6_asbr.c b/ospf6d/ospf6_asbr.c index 899c78c9fb..c210b4476c 100644 --- a/ospf6d/ospf6_asbr.c +++ b/ospf6d/ospf6_asbr.c @@ -1121,7 +1121,7 @@ void ospf6_asbr_distribute_list_update(struct ospf6 *ospf6, { SET_FLAG(red->flag, OSPF6_IS_RMAP_CHANGED); - if (ospf6->t_distribute_update) + if (thread_is_scheduled(ospf6->t_distribute_update)) return; if (IS_OSPF6_DEBUG_ASBR) @@ -3360,7 +3360,7 @@ ospf6_start_asbr_summary_delay_timer(struct ospf6 *ospf6, { aggr->action = operation; - if (ospf6->t_external_aggr) { + if (thread_is_scheduled(ospf6->t_external_aggr)) { if (ospf6->aggr_action == OSPF6_ROUTE_AGGR_ADD) { if (IS_OSPF6_DEBUG_AGGR) diff --git a/ospf6d/ospf6_gr.c b/ospf6d/ospf6_gr.c index 87407245b3..d7de66c663 100644 --- a/ospf6d/ospf6_gr.c +++ b/ospf6d/ospf6_gr.c @@ -459,7 +459,6 @@ static void ospf6_gr_grace_period_expired(struct thread *thread) { struct ospf6 *ospf6 = THREAD_ARG(thread); - ospf6->gr_info.t_grace_period = NULL; ospf6_gr_restart_exit(ospf6, "grace period has expired"); } diff --git a/ospf6d/ospf6_gr_helper.c b/ospf6d/ospf6_gr_helper.c index 1db56beaff..33a7a57c0f 100644 --- a/ospf6d/ospf6_gr_helper.c +++ b/ospf6d/ospf6_gr_helper.c @@ -400,8 +400,7 @@ int ospf6_process_grace_lsa(struct ospf6 *ospf6, struct ospf6_lsa *lsa, } if (OSPF6_GR_IS_ACTIVE_HELPER(restarter)) { - if (restarter->gr_helper_info.t_grace_timer) - THREAD_OFF(restarter->gr_helper_info.t_grace_timer); + THREAD_OFF(restarter->gr_helper_info.t_grace_timer); if (ospf6->ospf6_helper_cfg.active_restarter_cnt > 0) ospf6->ospf6_helper_cfg.active_restarter_cnt--; diff --git a/ospf6d/ospf6_interface.c b/ospf6d/ospf6_interface.c index c58bb3a0fb..2a503c6233 100644 --- a/ospf6d/ospf6_interface.c +++ b/ospf6d/ospf6_interface.c @@ -1152,7 +1152,7 @@ static int ospf6_interface_show(struct vty *vty, struct interface *ifp, if (use_json) { timerclear(&res); - if (oi->thread_send_lsupdate) + if (thread_is_scheduled(oi->thread_send_lsupdate)) timersub(&oi->thread_send_lsupdate->u.sands, &now, &res); timerstring(&res, duration, sizeof(duration)); @@ -1162,7 +1162,9 @@ static int ospf6_interface_show(struct vty *vty, struct interface *ifp, duration); json_object_string_add( json_obj, "lsUpdateSendThread", - (oi->thread_send_lsupdate ? "on" : "off")); + (thread_is_scheduled(oi->thread_send_lsupdate) + ? "on" + : "off")); json_arr = json_object_new_array(); for (ALL_LSDB(oi->lsupdate_list, lsa, lsanext)) @@ -1172,7 +1174,7 @@ static int ospf6_interface_show(struct vty *vty, struct interface *ifp, json_arr); timerclear(&res); - if (oi->thread_send_lsack) + if (thread_is_scheduled(oi->thread_send_lsack)) timersub(&oi->thread_send_lsack->u.sands, &now, &res); timerstring(&res, duration, sizeof(duration)); @@ -1180,8 +1182,10 @@ static int ospf6_interface_show(struct vty *vty, struct interface *ifp, oi->lsack_list->count); json_object_string_add(json_obj, "pendingLsaLsAckTime", duration); - json_object_string_add(json_obj, "lsAckSendThread", - (oi->thread_send_lsack ? "on" : "off")); + json_object_string_add( + json_obj, "lsAckSendThread", + (thread_is_scheduled(oi->thread_send_lsack) ? "on" + : "off")); json_arr = json_object_new_array(); for (ALL_LSDB(oi->lsack_list, lsa, lsanext)) @@ -1191,25 +1195,28 @@ static int ospf6_interface_show(struct vty *vty, struct interface *ifp, } else { timerclear(&res); - if (oi->thread_send_lsupdate) + if (thread_is_scheduled(oi->thread_send_lsupdate)) timersub(&oi->thread_send_lsupdate->u.sands, &now, &res); timerstring(&res, duration, sizeof(duration)); vty_out(vty, " %d Pending LSAs for LSUpdate in Time %s [thread %s]\n", oi->lsupdate_list->count, duration, - (oi->thread_send_lsupdate ? "on" : "off")); + (thread_is_scheduled(oi->thread_send_lsupdate) + ? "on" + : "off")); for (ALL_LSDB(oi->lsupdate_list, lsa, lsanext)) vty_out(vty, " %s\n", lsa->name); timerclear(&res); - if (oi->thread_send_lsack) + if (thread_is_scheduled(oi->thread_send_lsack)) timersub(&oi->thread_send_lsack->u.sands, &now, &res); timerstring(&res, duration, sizeof(duration)); vty_out(vty, " %d Pending LSAs for LSAck in Time %s [thread %s]\n", oi->lsack_list->count, duration, - (oi->thread_send_lsack ? "on" : "off")); + (thread_is_scheduled(oi->thread_send_lsack) ? "on" + : "off")); for (ALL_LSDB(oi->lsack_list, lsa, lsanext)) vty_out(vty, " %s\n", lsa->name); } diff --git a/ospf6d/ospf6_message.c b/ospf6d/ospf6_message.c index 1eede57232..ae7f16a9f6 100644 --- a/ospf6d/ospf6_message.c +++ b/ospf6d/ospf6_message.c @@ -2339,7 +2339,6 @@ void ospf6_dbdesc_send(struct thread *thread) struct ospf6_packet *op; on = (struct ospf6_neighbor *)THREAD_ARG(thread); - on->thread_send_dbdesc = (struct thread *)NULL; if (on->state < OSPF6_NEIGHBOR_EXSTART) { if (IS_OSPF6_DEBUG_MESSAGE(OSPF6_MESSAGE_TYPE_DBDESC, SEND)) @@ -2505,7 +2504,6 @@ void ospf6_lsreq_send(struct thread *thread) uint16_t length = OSPF6_HEADER_SIZE; on = (struct ospf6_neighbor *)THREAD_ARG(thread); - on->thread_send_lsreq = (struct thread *)NULL; /* LSReq will be sent only in ExStart or Loading */ if (on->state != OSPF6_NEIGHBOR_EXCHANGE @@ -2685,7 +2683,6 @@ void ospf6_lsupdate_send_neighbor(struct thread *thread) int lsa_cnt = 0; on = (struct ospf6_neighbor *)THREAD_ARG(thread); - on->thread_send_lsupdate = (struct thread *)NULL; if (IS_OSPF6_DEBUG_MESSAGE(OSPF6_MESSAGE_TYPE_LSUPDATE, SEND_HDR)) zlog_debug("LSUpdate to neighbor %s", on->name); @@ -2821,7 +2818,6 @@ void ospf6_lsupdate_send_interface(struct thread *thread) int lsa_cnt = 0; oi = (struct ospf6_interface *)THREAD_ARG(thread); - oi->thread_send_lsupdate = (struct thread *)NULL; if (oi->state <= OSPF6_INTERFACE_WAITING) { if (IS_OSPF6_DEBUG_MESSAGE(OSPF6_MESSAGE_TYPE_LSUPDATE, @@ -2862,7 +2858,6 @@ void ospf6_lsack_send_neighbor(struct thread *thread) uint16_t length = OSPF6_HEADER_SIZE; on = (struct ospf6_neighbor *)THREAD_ARG(thread); - on->thread_send_lsack = (struct thread *)NULL; if (on->state < OSPF6_NEIGHBOR_EXCHANGE) { if (IS_OSPF6_DEBUG_MESSAGE(OSPF6_MESSAGE_TYPE_LSACK, SEND_HDR)) @@ -2939,7 +2934,6 @@ void ospf6_lsack_send_interface(struct thread *thread) uint16_t length = OSPF6_HEADER_SIZE; oi = (struct ospf6_interface *)THREAD_ARG(thread); - oi->thread_send_lsack = (struct thread *)NULL; if (oi->state <= OSPF6_INTERFACE_WAITING) { if (IS_OSPF6_DEBUG_MESSAGE(OSPF6_MESSAGE_TYPE_LSACK, SEND_HDR)) diff --git a/ospf6d/ospf6_neighbor.c b/ospf6d/ospf6_neighbor.c index 8dca0913d3..439b94c9af 100644 --- a/ospf6d/ospf6_neighbor.c +++ b/ospf6d/ospf6_neighbor.c @@ -435,8 +435,7 @@ void ospf6_check_nbr_loading(struct ospf6_neighbor *on) if (on->request_list->count == 0) thread_add_event(master, loading_done, on, 0, NULL); else if (on->last_ls_req == NULL) { - if (on->thread_send_lsreq != NULL) - THREAD_OFF(on->thread_send_lsreq); + THREAD_OFF(on->thread_send_lsreq); thread_add_event(master, ospf6_lsreq_send, on, 0, &on->thread_send_lsreq); } @@ -481,7 +480,6 @@ void adj_ok(struct thread *thread) SET_FLAG(on->dbdesc_bits, OSPF6_DBDESC_IBIT); THREAD_OFF(on->thread_send_dbdesc); - on->thread_send_dbdesc = NULL; thread_add_event(master, ospf6_dbdesc_send, on, 0, &on->thread_send_dbdesc); @@ -527,7 +525,6 @@ void seqnumber_mismatch(struct thread *thread) THREAD_OFF(on->thread_send_dbdesc); on->dbdesc_seqnum++; /* Incr seqnum as per RFC2328, sec 10.3 */ - on->thread_send_dbdesc = NULL; thread_add_event(master, ospf6_dbdesc_send, on, 0, &on->thread_send_dbdesc); } @@ -562,7 +559,6 @@ void bad_lsreq(struct thread *thread) THREAD_OFF(on->thread_send_dbdesc); on->dbdesc_seqnum++; /* Incr seqnum as per RFC2328, sec 10.3 */ - on->thread_send_dbdesc = NULL; thread_add_event(master, ospf6_dbdesc_send, on, 0, &on->thread_send_dbdesc); @@ -850,15 +846,17 @@ static void ospf6_neighbor_show_detail(struct vty *vty, timerclear(&res); - if (on->thread_send_dbdesc) + if (thread_is_scheduled(on->thread_send_dbdesc)) timersub(&on->thread_send_dbdesc->u.sands, &now, &res); timerstring(&res, duration, sizeof(duration)); json_object_int_add(json_neighbor, "pendingLsaDbDescCount", on->dbdesc_list->count); json_object_string_add(json_neighbor, "pendingLsaDbDescTime", duration); - json_object_string_add(json_neighbor, "dbDescSendThread", - (on->thread_send_dbdesc ? "on" : "off")); + json_object_string_add( + json_neighbor, "dbDescSendThread", + (thread_is_scheduled(on->thread_send_dbdesc) ? "on" + : "off")); json_array = json_object_new_array(); for (ALL_LSDB(on->dbdesc_list, lsa, lsanext)) json_object_array_add( @@ -867,15 +865,17 @@ static void ospf6_neighbor_show_detail(struct vty *vty, json_array); timerclear(&res); - if (on->thread_send_lsreq) + if (thread_is_scheduled(on->thread_send_lsreq)) timersub(&on->thread_send_lsreq->u.sands, &now, &res); timerstring(&res, duration, sizeof(duration)); json_object_int_add(json_neighbor, "pendingLsaLsReqCount", on->request_list->count); json_object_string_add(json_neighbor, "pendingLsaLsReqTime", duration); - json_object_string_add(json_neighbor, "lsReqSendThread", - (on->thread_send_lsreq ? "on" : "off")); + json_object_string_add( + json_neighbor, "lsReqSendThread", + (thread_is_scheduled(on->thread_send_lsreq) ? "on" + : "off")); json_array = json_object_new_array(); for (ALL_LSDB(on->request_list, lsa, lsanext)) json_object_array_add( @@ -885,7 +885,7 @@ static void ospf6_neighbor_show_detail(struct vty *vty, timerclear(&res); - if (on->thread_send_lsupdate) + if (thread_is_scheduled(on->thread_send_lsupdate)) timersub(&on->thread_send_lsupdate->u.sands, &now, &res); timerstring(&res, duration, sizeof(duration)); @@ -895,7 +895,9 @@ static void ospf6_neighbor_show_detail(struct vty *vty, duration); json_object_string_add( json_neighbor, "lsUpdateSendThread", - (on->thread_send_lsupdate ? "on" : "off")); + (thread_is_scheduled(on->thread_send_lsupdate) + ? "on" + : "off")); json_array = json_object_new_array(); for (ALL_LSDB(on->lsupdate_list, lsa, lsanext)) json_object_array_add( @@ -904,15 +906,17 @@ static void ospf6_neighbor_show_detail(struct vty *vty, json_array); timerclear(&res); - if (on->thread_send_lsack) + if (thread_is_scheduled(on->thread_send_lsack)) timersub(&on->thread_send_lsack->u.sands, &now, &res); timerstring(&res, duration, sizeof(duration)); json_object_int_add(json_neighbor, "pendingLsaLsAckCount", on->lsack_list->count); json_object_string_add(json_neighbor, "pendingLsaLsAckTime", duration); - json_object_string_add(json_neighbor, "lsAckSendThread", - (on->thread_send_lsack ? "on" : "off")); + json_object_string_add( + json_neighbor, "lsAckSendThread", + (thread_is_scheduled(on->thread_send_lsack) ? "on" + : "off")); json_array = json_object_new_array(); for (ALL_LSDB(on->lsack_list, lsa, lsanext)) json_object_array_add( @@ -1000,47 +1004,52 @@ static void ospf6_neighbor_show_detail(struct vty *vty, vty_out(vty, " %s\n", lsa->name); timerclear(&res); - if (on->thread_send_dbdesc) + if (thread_is_scheduled(on->thread_send_dbdesc)) timersub(&on->thread_send_dbdesc->u.sands, &now, &res); timerstring(&res, duration, sizeof(duration)); vty_out(vty, " %d Pending LSAs for DbDesc in Time %s [thread %s]\n", on->dbdesc_list->count, duration, - (on->thread_send_dbdesc ? "on" : "off")); + (thread_is_scheduled(on->thread_send_dbdesc) ? "on" + : "off")); for (ALL_LSDB(on->dbdesc_list, lsa, lsanext)) vty_out(vty, " %s\n", lsa->name); timerclear(&res); - if (on->thread_send_lsreq) + if (thread_is_scheduled(on->thread_send_lsreq)) timersub(&on->thread_send_lsreq->u.sands, &now, &res); timerstring(&res, duration, sizeof(duration)); vty_out(vty, " %d Pending LSAs for LSReq in Time %s [thread %s]\n", on->request_list->count, duration, - (on->thread_send_lsreq ? "on" : "off")); + (thread_is_scheduled(on->thread_send_lsreq) ? "on" + : "off")); for (ALL_LSDB(on->request_list, lsa, lsanext)) vty_out(vty, " %s\n", lsa->name); timerclear(&res); - if (on->thread_send_lsupdate) + if (thread_is_scheduled(on->thread_send_lsupdate)) timersub(&on->thread_send_lsupdate->u.sands, &now, &res); timerstring(&res, duration, sizeof(duration)); vty_out(vty, " %d Pending LSAs for LSUpdate in Time %s [thread %s]\n", on->lsupdate_list->count, duration, - (on->thread_send_lsupdate ? "on" : "off")); + (thread_is_scheduled(on->thread_send_lsupdate) + ? "on" + : "off")); for (ALL_LSDB(on->lsupdate_list, lsa, lsanext)) vty_out(vty, " %s\n", lsa->name); timerclear(&res); - if (on->thread_send_lsack) + if (thread_is_scheduled(on->thread_send_lsack)) timersub(&on->thread_send_lsack->u.sands, &now, &res); timerstring(&res, duration, sizeof(duration)); vty_out(vty, " %d Pending LSAs for LSAck in Time %s [thread %s]\n", on->lsack_list->count, duration, - (on->thread_send_lsack ? "on" : "off")); + (thread_is_scheduled(on->thread_send_lsack) ? "on" + : "off")); for (ALL_LSDB(on->lsack_list, lsa, lsanext)) vty_out(vty, " %s\n", lsa->name); diff --git a/ospf6d/ospf6_nssa.c b/ospf6d/ospf6_nssa.c index 53b45d6ca3..b1bff69f06 100644 --- a/ospf6d/ospf6_nssa.c +++ b/ospf6d/ospf6_nssa.c @@ -1007,7 +1007,7 @@ static void ospf6_abr_task_timer(struct thread *thread) void ospf6_schedule_abr_task(struct ospf6 *ospf6) { - if (ospf6->t_abr_task) { + if (thread_is_scheduled(ospf6->t_abr_task)) { if (IS_OSPF6_DEBUG_ABR) zlog_debug("ABR task already scheduled"); return; diff --git a/ospf6d/ospf6_spf.c b/ospf6d/ospf6_spf.c index 2e8e9f2cdd..aac371ebbb 100644 --- a/ospf6d/ospf6_spf.c +++ b/ospf6d/ospf6_spf.c @@ -615,7 +615,6 @@ static void ospf6_spf_calculation_thread(struct thread *t) char rbuf[32]; ospf6 = (struct ospf6 *)THREAD_ARG(t); - ospf6->t_spf_calc = NULL; /* execute SPF calculation */ monotime(&start); @@ -703,7 +702,7 @@ void ospf6_spf_schedule(struct ospf6 *ospf6, unsigned int reason) } /* SPF calculation timer is already scheduled. */ - if (ospf6->t_spf_calc) { + if (thread_is_scheduled(ospf6->t_spf_calc)) { if (IS_OSPF6_DEBUG_SPF(PROCESS) || IS_OSPF6_DEBUG_SPF(TIME)) zlog_debug( "SPF: calculation timer is already scheduled: %p", @@ -740,7 +739,7 @@ void ospf6_spf_schedule(struct ospf6 *ospf6, unsigned int reason) if (IS_OSPF6_DEBUG_SPF(PROCESS) || IS_OSPF6_DEBUG_SPF(TIME)) zlog_debug("SPF: Rescheduling in %ld msec", delay); - ospf6->t_spf_calc = NULL; + THREAD_OFF(ospf6->t_spf_calc); thread_add_timer_msec(master, ospf6_spf_calculation_thread, ospf6, delay, &ospf6->t_spf_calc); } @@ -1253,7 +1252,6 @@ static void ospf6_ase_calculate_timer(struct thread *t) uint16_t type; ospf6 = THREAD_ARG(t); - ospf6->t_ase_calc = NULL; /* Calculate external route for each AS-external-LSA */ type = htons(OSPF6_LSTYPE_AS_EXTERNAL); diff --git a/ospf6d/ospf6_top.c b/ospf6d/ospf6_top.c index f85bdb35b8..d48e85cedb 100644 --- a/ospf6d/ospf6_top.c +++ b/ospf6d/ospf6_top.c @@ -1372,9 +1372,7 @@ static void ospf6_show(struct vty *vty, struct ospf6 *o, json_object *json, } else json_object_boolean_false_add(json, "spfHasRun"); - - threadtimer_string(now, o->t_spf_calc, buf, sizeof(buf)); - if (o->t_spf_calc) { + if (thread_is_scheduled(o->t_spf_calc)) { long time_store; json_object_boolean_true_add(json, "spfTimerActive"); @@ -1467,7 +1465,9 @@ static void ospf6_show(struct vty *vty, struct ospf6 *o, json_object *json, threadtimer_string(now, o->t_spf_calc, buf, sizeof(buf)); vty_out(vty, " SPF timer %s%s\n", - (o->t_spf_calc ? "due in " : "is "), buf); + (thread_is_scheduled(o->t_spf_calc) ? "due in " + : "is "), + buf); if (CHECK_FLAG(o->flag, OSPF6_STUB_ROUTER)) vty_out(vty, " Router Is Stub Router\n"); -- 2.39.5