diff options
author | tuexen <tuexen@FreeBSD.org> | 2010-12-30 16:56:20 +0000 |
---|---|---|
committer | tuexen <tuexen@FreeBSD.org> | 2010-12-30 16:56:20 +0000 |
commit | 839236cbc1d5d457989fd137b9f17d9eaf1648dd (patch) | |
tree | 0f7ed0ea1f0fee5fba05900c6e204bf17571f2e8 /sys/netinet/sctputil.c | |
parent | e71b6473c68e46ca3d024d8bd06702b8b854aa25 (diff) | |
download | FreeBSD-src-839236cbc1d5d457989fd137b9f17d9eaf1648dd.zip FreeBSD-src-839236cbc1d5d457989fd137b9f17d9eaf1648dd.tar.gz |
Code cleanup: Use LIST_FOREACH, LIST_FOREACH_SAFE, TAILQ_FOREACH,
TAILQ_FOREACH_SAFE where appropriate.
No functional change.
MFC after: 3 months.
Diffstat (limited to 'sys/netinet/sctputil.c')
-rw-r--r-- | sys/netinet/sctputil.c | 136 |
1 files changed, 55 insertions, 81 deletions
diff --git a/sys/netinet/sctputil.c b/sys/netinet/sctputil.c index 975acb8..72e5269 100644 --- a/sys/netinet/sctputil.c +++ b/sys/netinet/sctputil.c @@ -1417,13 +1417,13 @@ no_stcb: void sctp_iterator_worker(void) { - struct sctp_iterator *it = NULL; + struct sctp_iterator *it, *nit; /* This function is called with the WQ lock in place */ sctp_it_ctl.iterator_running = 1; - sctp_it_ctl.cur_it = it = TAILQ_FIRST(&sctp_it_ctl.iteratorhead); - while (it) { + TAILQ_FOREACH_SAFE(it, &sctp_it_ctl.iteratorhead, sctp_nxt_itr, nit) { + sctp_it_ctl.cur_it = it; /* now lets work on this one */ TAILQ_REMOVE(&sctp_it_ctl.iteratorhead, it, sctp_nxt_itr); SCTP_IPI_ITERATOR_WQ_UNLOCK(); @@ -1437,7 +1437,6 @@ sctp_iterator_worker(void) break; } /* sa_ignore FREED_MEMORY */ - sctp_it_ctl.cur_it = it = TAILQ_FIRST(&sctp_it_ctl.iteratorhead); } sctp_it_ctl.iterator_running = 0; return; @@ -1448,7 +1447,7 @@ static void sctp_handle_addr_wq(void) { /* deal with the ADDR wq from the rtsock calls */ - struct sctp_laddr *wi; + struct sctp_laddr *wi, *nwi; struct sctp_asconf_iterator *asc; SCTP_MALLOC(asc, struct sctp_asconf_iterator *, @@ -1465,12 +1464,10 @@ sctp_handle_addr_wq(void) asc->cnt = 0; SCTP_WQ_ADDR_LOCK(); - wi = LIST_FIRST(&SCTP_BASE_INFO(addr_wq)); - while (wi != NULL) { + LIST_FOREACH_SAFE(wi, &SCTP_BASE_INFO(addr_wq), sctp_nxt_addr, nwi) { LIST_REMOVE(wi, sctp_nxt_addr); LIST_INSERT_HEAD(&asc->list_of_work, wi, sctp_nxt_addr); asc->cnt++; - wi = LIST_FIRST(&SCTP_BASE_INFO(addr_wq)); } SCTP_WQ_ADDR_UNLOCK(); @@ -1664,8 +1661,7 @@ sctp_timeout_handler(void *t) #endif sctp_chunk_output(inp, stcb, SCTP_OUTPUT_FROM_T3, SCTP_SO_NOT_LOCKED); if ((stcb->asoc.num_send_timers_up == 0) && - (stcb->asoc.sent_queue_cnt > 0) - ) { + (stcb->asoc.sent_queue_cnt > 0)) { struct sctp_tmit_chunk *chk; /* @@ -3693,22 +3689,21 @@ sctp_report_all_outbound(struct sctp_tcb *stcb, int holds_lock, int so_locked { struct sctp_association *asoc; struct sctp_stream_out *outs; - struct sctp_tmit_chunk *chk; - struct sctp_stream_queue_pending *sp; + struct sctp_tmit_chunk *chk, *nchk; + struct sctp_stream_queue_pending *sp, *nsp; int i; - asoc = &stcb->asoc; - if (stcb == NULL) { return; } - if (stcb->asoc.state & SCTP_STATE_ABOUT_TO_BE_FREED) { + asoc = &stcb->asoc; + if (asoc->state & SCTP_STATE_ABOUT_TO_BE_FREED) { /* already being freed */ return; } if ((stcb->sctp_ep->sctp_flags & SCTP_PCB_FLAGS_SOCKET_GONE) || (stcb->sctp_ep->sctp_flags & SCTP_PCB_FLAGS_SOCKET_ALLGONE) || - (stcb->asoc.state & SCTP_STATE_CLOSED_SOCKET)) { + (asoc->state & SCTP_STATE_CLOSED_SOCKET)) { return; } /* now through all the gunk freeing chunks */ @@ -3716,53 +3711,44 @@ sctp_report_all_outbound(struct sctp_tcb *stcb, int holds_lock, int so_locked SCTP_TCB_SEND_LOCK(stcb); } /* sent queue SHOULD be empty */ - if (!TAILQ_EMPTY(&asoc->sent_queue)) { - chk = TAILQ_FIRST(&asoc->sent_queue); - while (chk) { - TAILQ_REMOVE(&asoc->sent_queue, chk, sctp_next); - asoc->sent_queue_cnt--; - if (chk->data != NULL) { - sctp_free_bufspace(stcb, asoc, chk, 1); - sctp_ulp_notify(SCTP_NOTIFY_DG_FAIL, stcb, - SCTP_NOTIFY_DATAGRAM_SENT, chk, so_locked); - if (chk->data) { - sctp_m_freem(chk->data); - chk->data = NULL; - } + TAILQ_FOREACH_SAFE(chk, &asoc->sent_queue, sctp_next, nchk) { + TAILQ_REMOVE(&asoc->sent_queue, chk, sctp_next); + asoc->sent_queue_cnt--; + if (chk->data != NULL) { + sctp_free_bufspace(stcb, asoc, chk, 1); + sctp_ulp_notify(SCTP_NOTIFY_DG_FAIL, stcb, + SCTP_NOTIFY_DATAGRAM_SENT, chk, so_locked); + if (chk->data) { + sctp_m_freem(chk->data); + chk->data = NULL; } - sctp_free_a_chunk(stcb, chk); - /* sa_ignore FREED_MEMORY */ - chk = TAILQ_FIRST(&asoc->sent_queue); } + sctp_free_a_chunk(stcb, chk); + /* sa_ignore FREED_MEMORY */ } /* pending send queue SHOULD be empty */ - if (!TAILQ_EMPTY(&asoc->send_queue)) { - chk = TAILQ_FIRST(&asoc->send_queue); - while (chk) { - TAILQ_REMOVE(&asoc->send_queue, chk, sctp_next); - asoc->send_queue_cnt--; - if (chk->data != NULL) { - sctp_free_bufspace(stcb, asoc, chk, 1); - sctp_ulp_notify(SCTP_NOTIFY_DG_FAIL, stcb, - SCTP_NOTIFY_DATAGRAM_UNSENT, chk, so_locked); - if (chk->data) { - sctp_m_freem(chk->data); - chk->data = NULL; - } + TAILQ_FOREACH_SAFE(chk, &asoc->send_queue, sctp_next, nchk) { + TAILQ_REMOVE(&asoc->send_queue, chk, sctp_next); + asoc->send_queue_cnt--; + if (chk->data != NULL) { + sctp_free_bufspace(stcb, asoc, chk, 1); + sctp_ulp_notify(SCTP_NOTIFY_DG_FAIL, stcb, + SCTP_NOTIFY_DATAGRAM_UNSENT, chk, so_locked); + if (chk->data) { + sctp_m_freem(chk->data); + chk->data = NULL; } - sctp_free_a_chunk(stcb, chk); - /* sa_ignore FREED_MEMORY */ - chk = TAILQ_FIRST(&asoc->send_queue); } + sctp_free_a_chunk(stcb, chk); + /* sa_ignore FREED_MEMORY */ } - for (i = 0; i < stcb->asoc.streamoutcnt; i++) { + for (i = 0; i < asoc->streamoutcnt; i++) { /* For each stream */ - outs = &stcb->asoc.strmout[i]; + outs = &asoc->strmout[i]; /* clean up any sends there */ - stcb->asoc.locked_on_sending = NULL; - sp = TAILQ_FIRST(&outs->outqueue); - while (sp) { - stcb->asoc.stream_queue_cnt--; + asoc->locked_on_sending = NULL; + TAILQ_FOREACH_SAFE(sp, &outs->outqueue, next, nsp) { + asoc->stream_queue_cnt--; TAILQ_REMOVE(&outs->outqueue, sp, next); sctp_free_spbufspace(stcb, asoc, sp); if (sp->data) { @@ -3780,7 +3766,6 @@ sctp_report_all_outbound(struct sctp_tcb *stcb, int holds_lock, int so_locked /* Free the chunk */ sctp_free_a_strmoq(stcb, sp); /* sa_ignore FREED_MEMORY */ - sp = TAILQ_FIRST(&outs->outqueue); } } @@ -4311,10 +4296,8 @@ sctp_pull_off_control_to_new_inp(struct sctp_inpcb *old_inp, } /* lock the socket buffers */ SCTP_INP_READ_LOCK(old_inp); - control = TAILQ_FIRST(&old_inp->read_queue); - /* Pull off all for out target stcb */ - while (control) { - nctl = TAILQ_NEXT(control, next); + TAILQ_FOREACH_SAFE(control, &old_inp->read_queue, next, nctl) { + /* Pull off all for out target stcb */ if (control->stcb == stcb) { /* remove it we want it */ TAILQ_REMOVE(&old_inp->read_queue, control, next); @@ -4331,17 +4314,14 @@ sctp_pull_off_control_to_new_inp(struct sctp_inpcb *old_inp, m = SCTP_BUF_NEXT(m); } } - control = nctl; } SCTP_INP_READ_UNLOCK(old_inp); /* Remove the sb-lock on the old socket */ sbunlock(&old_so->so_rcv); /* Now we move them over to the new socket buffer */ - control = TAILQ_FIRST(&tmp_queue); SCTP_INP_READ_LOCK(new_inp); - while (control) { - nctl = TAILQ_NEXT(control, next); + TAILQ_FOREACH_SAFE(control, &tmp_queue, next, nctl) { TAILQ_INSERT_TAIL(&new_inp->read_queue, control, next); m = control->data; while (m) { @@ -4354,7 +4334,6 @@ sctp_pull_off_control_to_new_inp(struct sctp_inpcb *old_inp, } m = SCTP_BUF_NEXT(m); } - control = nctl; } SCTP_INP_READ_UNLOCK(new_inp); } @@ -4700,7 +4679,7 @@ sctp_release_pr_sctp_chunk(struct sctp_tcb *stcb, struct sctp_tmit_chunk *tp1, ) { struct sctp_stream_out *strq; - struct sctp_tmit_chunk *chk = NULL; + struct sctp_tmit_chunk *chk = NULL, *tp2; struct sctp_stream_queue_pending *sp; uint16_t stream = 0, seq = 0; uint8_t foundeom = 0; @@ -4754,15 +4733,11 @@ sctp_release_pr_sctp_chunk(struct sctp_tcb *stcb, struct sctp_tmit_chunk *tp1, * The multi-part message was scattered across the send and * sent queue. */ -next_on_sent: - tp1 = TAILQ_FIRST(&stcb->asoc.send_queue); - /* - * recurse throught the send_queue too, starting at the - * beginning. - */ - if ((tp1) && - (tp1->rec.data.stream_number == stream) && - (tp1->rec.data.stream_seq == seq)) { + TAILQ_FOREACH_SAFE(tp1, &stcb->asoc.send_queue, sctp_next, tp2) { + if ((tp1->rec.data.stream_number != stream) || + (tp1->rec.data.stream_seq != seq)) { + break; + } /* * save to chk in case we have some on stream out * queue. If so and we have an un-transmitted one we @@ -4792,7 +4767,6 @@ next_on_sent: sctp_next); stcb->asoc.send_queue_cnt--; stcb->asoc.sent_queue_cnt++; - goto next_on_sent; } } if (foundeom == 0) { @@ -4802,8 +4776,11 @@ next_on_sent: */ strq = &stcb->asoc.strmout[stream]; SCTP_TCB_SEND_LOCK(stcb); - sp = TAILQ_FIRST(&strq->outqueue); - while (sp->strseq <= seq) { + TAILQ_FOREACH(sp, &strq->outqueue, next) { + /* FIXME: Shouldn't this be a serial number check? */ + if (sp->strseq > seq) { + break; + } /* Check if its our SEQ */ if (sp->strseq == seq) { sp->discard_rest = 1; @@ -4866,11 +4843,8 @@ next_on_sent: sp->tail_mbuf = NULL; } break; - } else { - /* Next one please */ - sp = TAILQ_NEXT(sp, next); } - } /* End while */ + } /* End tailq_foreach */ SCTP_TCB_SEND_UNLOCK(stcb); } if (do_wakeup_routine) { |