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 <sharpd@nvidia.com>
This commit is contained in:
Donald Sharp 2022-05-17 16:29:29 -04:00
parent 23b11ab185
commit c905f04c7c
9 changed files with 59 additions and 53 deletions

View File

@ -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)

View File

@ -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");
}

View File

@ -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--;

View File

@ -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);
}

View File

@ -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))

View File

@ -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);

View File

@ -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;

View File

@ -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);

View File

@ -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");