1 /* $KAME: sctp_timer.c,v 1.28 2004/08/17 04:06:20 itojun Exp $ */
2 /* $DragonFly: src/sys/netinet/sctp_timer.c,v 1.3 2005/07/15 15:15:27 eirikn Exp $ */
5 * Copyright (C) 2002, 2003, 2004 Cisco Systems Inc,
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
16 * 3. Neither the name of the project nor the names of its contributors
17 * may be used to endorse or promote products derived from this software
18 * without specific prior written permission.
20 * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND
21 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23 * ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE
24 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32 #if !(defined(__OpenBSD__) || defined(__APPLE__))
33 #include "opt_ipsec.h"
35 #if defined(__FreeBSD__) || defined(__DragonFly__)
36 #include "opt_compat.h"
37 #include "opt_inet6.h"
40 #if defined(__NetBSD__)
45 #elif !defined(__OpenBSD__)
49 #include <sys/param.h>
50 #include <sys/systm.h>
51 #include <sys/malloc.h>
54 #include <sys/domain.h>
56 #include <sys/protosw.h>
57 #include <sys/socket.h>
58 #include <sys/socketvar.h>
60 #include <sys/kernel.h>
61 #include <sys/sysctl.h>
63 #include <sys/domain.h>
66 #if (defined(__FreeBSD__) && __FreeBSD_version >= 500000)
67 #include <sys/limits.h>
69 #include <machine/limits.h>
73 #include <net/if_types.h>
74 #include <net/route.h>
75 #include <netinet/in.h>
76 #include <netinet/in_systm.h>
78 #include <netinet/ip.h>
79 #include <netinet/in_pcb.h>
80 #include <netinet/in_var.h>
81 #include <netinet/ip_var.h>
84 #include <netinet/ip6.h>
85 #include <netinet6/ip6_var.h>
88 #include <netinet/sctp_pcb.h>
92 #include <netinet6/ipsec.h>
93 #include <netkey/key.h>
99 #include <netinet6/sctp6_var.h>
101 #include <netinet/sctp_var.h>
102 #include <netinet/sctp_timer.h>
103 #include <netinet/sctputil.h>
104 #include <netinet/sctp_output.h>
105 #include <netinet/sctp_hashdriver.h>
106 #include <netinet/sctp_header.h>
107 #include <netinet/sctp_indata.h>
108 #include <netinet/sctp_asconf.h>
110 #include <netinet/sctp.h>
111 #include <netinet/sctp_uio.h>
113 #include <net/net_osdep.h>
116 extern u_int32_t sctp_debug_on;
117 #endif /* SCTP_DEBUG */
120 sctp_audit_retranmission_queue(struct sctp_association *asoc)
122 struct sctp_tmit_chunk *chk;
125 if (sctp_debug_on & SCTP_DEBUG_TIMER4) {
126 printf("Audit invoked on send queue cnt:%d onqueue:%d\n",
127 asoc->sent_queue_retran_cnt,
128 asoc->sent_queue_cnt);
130 #endif /* SCTP_DEBUG */
131 asoc->sent_queue_retran_cnt = 0;
132 asoc->sent_queue_cnt = 0;
133 TAILQ_FOREACH(chk, &asoc->sent_queue, sctp_next) {
134 if (chk->sent == SCTP_DATAGRAM_RESEND) {
135 asoc->sent_queue_retran_cnt++;
137 asoc->sent_queue_cnt++;
139 TAILQ_FOREACH(chk, &asoc->control_send_queue, sctp_next) {
140 if (chk->sent == SCTP_DATAGRAM_RESEND) {
141 asoc->sent_queue_retran_cnt++;
145 if (sctp_debug_on & SCTP_DEBUG_TIMER4) {
146 printf("Audit completes retran:%d onqueue:%d\n",
147 asoc->sent_queue_retran_cnt,
148 asoc->sent_queue_cnt);
150 #endif /* SCTP_DEBUG */
154 sctp_threshold_management(struct sctp_inpcb *inp, struct sctp_tcb *stcb,
155 struct sctp_nets *net, uint16_t threshold)
160 if (sctp_debug_on & SCTP_DEBUG_TIMER4) {
161 printf("Error count for %p now %d thresh:%d\n",
162 net, net->error_count,
163 net->failure_threshold);
165 #endif /* SCTP_DEBUG */
166 if (net->error_count >= net->failure_threshold) {
167 /* We had a threshold failure */
168 if (net->dest_state & SCTP_ADDR_REACHABLE) {
169 net->dest_state &= ~SCTP_ADDR_REACHABLE;
170 net->dest_state |= SCTP_ADDR_NOT_REACHABLE;
171 if (net == stcb->asoc.primary_destination) {
172 net->dest_state |= SCTP_ADDR_WAS_PRIMARY;
174 sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_DOWN,
176 SCTP_FAILED_THRESHOLD,
180 /*********HOLD THIS COMMENT FOR PATCH OF ALTERNATE
181 *********ROUTING CODE
183 /*********HOLD THIS COMMENT FOR END OF PATCH OF ALTERNATE
184 *********ROUTING CODE
191 if ((net->dest_state & SCTP_ADDR_UNCONFIRMED) == 0) {
192 stcb->asoc.overall_error_count++;
195 stcb->asoc.overall_error_count++;
198 if (sctp_debug_on & SCTP_DEBUG_TIMER4) {
199 printf("Overall error count for %p now %d thresh:%u state:%x\n",
201 stcb->asoc.overall_error_count,
203 ((net == NULL) ? (u_int)0 : (u_int)net->dest_state));
205 #endif /* SCTP_DEBUG */
206 /* We specifically do not do >= to give the assoc one more
207 * change before we fail it.
209 if (stcb->asoc.overall_error_count > threshold) {
210 /* Abort notification sends a ULP notify */
212 MGET(oper, MB_DONTWAIT, MT_DATA);
214 struct sctp_paramhdr *ph;
217 oper->m_len = sizeof(struct sctp_paramhdr) +
219 ph = mtod(oper, struct sctp_paramhdr *);
220 ph->param_type = htons(SCTP_CAUSE_PROTOCOL_VIOLATION);
221 ph->param_length = htons(oper->m_len);
222 ippp = (u_int32_t *)(ph + 1);
223 *ippp = htonl(0x40000001);
225 sctp_abort_an_association(inp, stcb, SCTP_FAILED_THRESHOLD, oper);
232 sctp_find_alternate_net(struct sctp_tcb *stcb,
233 struct sctp_nets *net)
235 /* Find and return an alternate network if possible */
236 struct sctp_nets *alt, *mnet;
239 if (stcb->asoc.numnets == 1) {
240 /* No others but net */
241 return (TAILQ_FIRST(&stcb->asoc.nets));
247 mnet = TAILQ_FIRST(&stcb->asoc.nets);
250 alt = TAILQ_NEXT(mnet, sctp_next);
256 alt = TAILQ_FIRST(&stcb->asoc.nets);
258 if (alt->ro.ro_rt == NULL) {
259 #ifndef SCOPEDROUTING
260 struct sockaddr_in6 *sin6;
261 sin6 = (struct sockaddr_in6 *)&alt->ro._l_addr;
262 if (sin6->sin6_family == AF_INET6) {
263 #if defined(SCTP_BASE_FREEBSD) || defined(__APPLE__) || defined(__DragonFly__)
264 (void)in6_embedscope(&sin6->sin6_addr, sin6,
267 (void)in6_embedscope(&sin6->sin6_addr, sin6);
271 #if defined(__FreeBSD__) || defined(__APPLE__) || defined(__DragonFly__)
272 rtalloc_ign((struct route*)&alt->ro, 0UL);
274 rtalloc((struct route*)&alt->ro);
276 #ifndef SCOPEDROUTING
277 if (sin6->sin6_family == AF_INET6) {
278 (void)in6_recoverscope(sin6, &sin6->sin6_addr,
282 alt->src_addr_selected = 0;
285 ((alt->dest_state & SCTP_ADDR_REACHABLE) == SCTP_ADDR_REACHABLE) &&
286 (alt->ro.ro_rt != NULL) &&
287 (!(alt->dest_state & SCTP_ADDR_UNCONFIRMED))
289 /* Found a reachable address */
293 } while (alt != NULL);
296 /* Case where NO insv network exists (dormant state) */
297 /* we rotate destinations */
301 alt = TAILQ_NEXT(mnet, sctp_next);
307 alt = TAILQ_FIRST(&stcb->asoc.nets);
309 if ((!(alt->dest_state & SCTP_ADDR_UNCONFIRMED)) &&
311 /* Found an alternate address */
315 } while (alt != NULL);
324 sctp_backoff_on_timeout(struct sctp_tcb *stcb,
325 struct sctp_nets *net,
333 #endif /* SCTP_DEBUG */
336 if (sctp_debug_on & SCTP_DEBUG_TIMER2) {
337 printf("Timer doubles from %d ms -to-> %d ms\n",
340 #endif /* SCTP_DEBUG */
342 if (net->RTO > stcb->asoc.maxrto) {
343 net->RTO = stcb->asoc.maxrto;
345 if (sctp_debug_on & SCTP_DEBUG_TIMER2) {
346 printf("Growth capped by maxrto %d\n",
349 #endif /* SCTP_DEBUG */
353 if ((win_probe == 0) && num_marked) {
354 /* We don't apply penalty to window probe scenarios */
355 #ifdef SCTP_CWND_LOGGING
356 int old_cwnd=net->cwnd;
358 net->ssthresh = net->cwnd >> 1;
359 if (net->ssthresh < (net->mtu << 1)) {
360 net->ssthresh = (net->mtu << 1);
362 net->cwnd = net->mtu;
364 if (net->cwnd < net->mtu)
365 net->cwnd = net->mtu;
366 #ifdef SCTP_CWND_LOGGING
367 sctp_log_cwnd(net, net->cwnd-old_cwnd, SCTP_CWND_LOG_FROM_RTX);
370 net->partial_bytes_acked = 0;
372 if (sctp_debug_on & SCTP_DEBUG_TIMER1) {
373 printf("collapse cwnd to 1MTU ssthresh to %d\n",
383 sctp_mark_all_for_resend(struct sctp_tcb *stcb,
384 struct sctp_nets *net,
385 struct sctp_nets *alt,
390 * Mark all chunks (well not all) that were sent to *net for retransmission.
391 * Move them to alt for there destination as well... We only
392 * mark chunks that have been outstanding long enough to have
393 * received feed-back.
395 struct sctp_tmit_chunk *chk, *tp2;
396 struct sctp_nets *lnets;
397 struct timeval now, min_wait, tv;
399 int win_probes, non_win_probes, orig_rwnd, audit_tf, num_mk, fir;
401 u_int32_t orig_flight;
402 u_int32_t tsnlast, tsnfirst;
404 /* none in flight now */
407 /* figure out how long a data chunk must be pending
408 * before we can mark it ..
410 SCTP_GETTIME_TIMEVAL(&now);
411 /* get cur rto in micro-seconds */
412 cur_rto = (((net->lastsa >> 2) + net->lastsv) >> 1);
413 #ifdef SCTP_FR_LOGGING
414 sctp_log_fr(cur_rto, 0, 0, SCTP_FR_T3_MARK_TIME);
417 #ifdef SCTP_FR_LOGGING
418 sctp_log_fr(cur_rto, 0, 0, SCTP_FR_T3_MARK_TIME);
420 tv.tv_sec = cur_rto / 1000000;
421 tv.tv_usec = cur_rto % 1000000;
423 timersub(&now, &tv, &min_wait);
426 timevalsub(&min_wait, &tv);
428 if (min_wait.tv_sec < 0 || min_wait.tv_usec < 0) {
430 * if we hit here, we don't
431 * have enough seconds on the clock to account
432 * for the RTO. We just let the lower seconds
433 * be the bounds and don't worry about it. This
434 * may mean we will mark a lot more than we should.
436 min_wait.tv_sec = min_wait.tv_usec = 0;
438 #ifdef SCTP_FR_LOGGING
439 sctp_log_fr(cur_rto, now.tv_sec, now.tv_usec, SCTP_FR_T3_MARK_TIME);
440 sctp_log_fr(0, min_wait.tv_sec, min_wait.tv_usec, SCTP_FR_T3_MARK_TIME);
442 stcb->asoc.total_flight -= net->flight_size;
443 if (stcb->asoc.total_flight < 0) {
445 stcb->asoc.total_flight = 0;
447 /* Our rwnd will be incorrect here since we are not adding
448 * back the cnt * mbuf but we will fix that down below.
450 orig_rwnd = stcb->asoc.peers_rwnd;
451 orig_flight = net->flight_size;
452 stcb->asoc.peers_rwnd += net->flight_size;
453 net->flight_size = 0;
454 net->rto_pending = 0;
455 net->fast_retran_ip= 0;
456 win_probes = non_win_probes = 0;
458 if (sctp_debug_on & SCTP_DEBUG_TIMER2) {
459 printf("Marking ALL un-acked for retransmission at t3-timeout\n");
461 #endif /* SCTP_DEBUG */
462 /* Now on to each chunk */
464 tsnfirst = tsnlast = 0;
465 chk = TAILQ_FIRST(&stcb->asoc.sent_queue);
466 for (;chk != NULL; chk = tp2) {
467 tp2 = TAILQ_NEXT(chk, sctp_next);
468 if ((compare_with_wrap(stcb->asoc.last_acked_seq,
469 chk->rec.data.TSN_seq,
471 (stcb->asoc.last_acked_seq == chk->rec.data.TSN_seq)) {
472 /* Strange case our list got out of order? */
473 printf("Our list is out of order?\n");
474 TAILQ_REMOVE(&stcb->asoc.sent_queue, chk, sctp_next);
476 sctp_release_pr_sctp_chunk(stcb, chk, 0xffff,
477 &stcb->asoc.sent_queue);
478 if (chk->flags & SCTP_PR_SCTP_BUFFER) {
479 stcb->asoc.sent_queue_cnt_removeable--;
482 stcb->asoc.sent_queue_cnt--;
483 sctp_free_remote_addr(chk->whoTo);
484 sctppcbinfo.ipi_count_chunk--;
485 if ((int)sctppcbinfo.ipi_count_chunk < 0) {
486 panic("Chunk count is going negative");
488 SCTP_ZONE_FREE(sctppcbinfo.ipi_zone_chunk, chk);
489 sctppcbinfo.ipi_gencnt_chunk++;
492 if ((chk->whoTo == net) && (chk->sent < SCTP_DATAGRAM_ACKED)) {
493 /* found one to mark:
494 * If it is less than DATAGRAM_ACKED it MUST
495 * not be a skipped or marked TSN but instead
496 * one that is either already set for retransmission OR
497 * one that needs retransmission.
500 /* validate its been outstanding long enough */
501 #ifdef SCTP_FR_LOGGING
502 sctp_log_fr(chk->rec.data.TSN_seq,
503 chk->sent_rcv_time.tv_sec,
504 chk->sent_rcv_time.tv_usec,
505 SCTP_FR_T3_MARK_TIME);
507 if (chk->sent_rcv_time.tv_sec > min_wait.tv_sec) {
508 /* we have reached a chunk that was sent some
509 * seconds past our min.. forget it we will
510 * find no more to send.
512 #ifdef SCTP_FR_LOGGING
514 chk->sent_rcv_time.tv_sec,
515 chk->sent_rcv_time.tv_usec,
519 } else if (chk->sent_rcv_time.tv_sec == min_wait.tv_sec) {
520 /* we must look at the micro seconds to know.
522 if (chk->sent_rcv_time.tv_usec >= min_wait.tv_usec) {
523 /* ok it was sent after our boundary time. */
524 #ifdef SCTP_FR_LOGGING
526 chk->sent_rcv_time.tv_sec,
527 chk->sent_rcv_time.tv_usec,
533 stcb->asoc.total_flight_count--;
534 if (stcb->asoc.total_flight_count < 0) {
535 stcb->asoc.total_flight_count = 0;
537 if ((chk->flags & (SCTP_PR_SCTP_ENABLED|SCTP_PR_SCTP_BUFFER)) == SCTP_PR_SCTP_ENABLED) {
539 if ((now.tv_sec > chk->rec.data.timetodrop.tv_sec) ||
540 ((chk->rec.data.timetodrop.tv_sec == now.tv_sec) &&
541 (now.tv_usec > chk->rec.data.timetodrop.tv_usec))) {
544 sctp_release_pr_sctp_chunk(stcb,
546 (SCTP_RESPONSE_TO_USER_REQ|SCTP_NOTIFY_DATAGRAM_SENT),
547 &stcb->asoc.sent_queue);
552 if (chk->sent != SCTP_DATAGRAM_RESEND) {
553 stcb->asoc.sent_queue_retran_cnt++;
558 if (sctp_debug_on & SCTP_DEBUG_TIMER1) {
559 printf("First TSN marked was %x\n",
560 chk->rec.data.TSN_seq);
563 tsnfirst = chk->rec.data.TSN_seq;
565 tsnlast = chk->rec.data.TSN_seq;
566 #ifdef SCTP_FR_LOGGING
567 sctp_log_fr(chk->rec.data.TSN_seq, chk->snd_count,
568 0, SCTP_FR_T3_MARKED);
572 chk->sent = SCTP_DATAGRAM_RESEND;
573 /* reset the TSN for striking and other FR stuff */
574 chk->rec.data.doing_fast_retransmit = 0;
576 if (sctp_debug_on & SCTP_DEBUG_TIMER3) {
577 printf("mark TSN:%x for retransmission\n", chk->rec.data.TSN_seq);
579 #endif /* SCTP_DEBUG */
580 /* Clear any time so NO RTT is being done */
582 /* Bump up the count */
583 if (compare_with_wrap(chk->rec.data.TSN_seq,
584 stcb->asoc.t3timeout_highest_marked,
586 /* TSN_seq > than t3timeout so update */
587 stcb->asoc.t3timeout_highest_marked = chk->rec.data.TSN_seq;
590 sctp_free_remote_addr(chk->whoTo);
594 if ((chk->rec.data.state_flags & SCTP_WINDOW_PROBE) !=
598 chk->rec.data.state_flags &= ~SCTP_WINDOW_PROBE;
602 if (chk->sent == SCTP_DATAGRAM_RESEND) {
607 #ifdef SCTP_FR_LOGGING
608 sctp_log_fr(tsnfirst, tsnlast, num_mk, SCTP_FR_T3_TIMEOUT);
610 /* compensate for the number we marked */
611 stcb->asoc.peers_rwnd += (num_mk /* * sizeof(struct mbuf)*/);
614 if (sctp_debug_on & SCTP_DEBUG_TIMER1) {
616 printf("LAST TSN marked was %x\n", tsnlast);
617 printf("Num marked for retransmission was %d peer-rwd:%ld\n",
618 num_mk, (u_long)stcb->asoc.peers_rwnd);
619 printf("LAST TSN marked was %x\n", tsnlast);
620 printf("Num marked for retransmission was %d peer-rwd:%d\n",
622 (int)stcb->asoc.peers_rwnd
627 *num_marked = num_mk;
628 if (stcb->asoc.sent_queue_retran_cnt != cnt_mk) {
629 printf("Local Audit says there are %d for retran asoc cnt:%d\n",
630 cnt_mk, stcb->asoc.sent_queue_retran_cnt);
631 #ifndef SCTP_AUDITING_ENABLED
632 stcb->asoc.sent_queue_retran_cnt = cnt_mk;
636 if (sctp_debug_on & SCTP_DEBUG_TIMER3) {
637 printf("**************************\n");
639 #endif /* SCTP_DEBUG */
641 /* Now check for a ECN Echo that may be stranded */
642 TAILQ_FOREACH(chk, &stcb->asoc.control_send_queue, sctp_next) {
643 if ((chk->whoTo == net) &&
644 (chk->rec.chunk_id == SCTP_ECN_ECHO)) {
645 sctp_free_remote_addr(chk->whoTo);
647 if (chk->sent != SCTP_DATAGRAM_RESEND) {
648 chk->sent = SCTP_DATAGRAM_RESEND;
649 stcb->asoc.sent_queue_retran_cnt++;
654 if ((orig_rwnd == 0) && (stcb->asoc.total_flight == 0) &&
655 (orig_flight <= net->mtu)) {
657 * If the LAST packet sent was not acked and our rwnd is 0
658 * then we are in a win-probe state.
663 if (sctp_debug_on & SCTP_DEBUG_TIMER1) {
664 printf("WIN_PROBE set via o_rwnd=0 tf=0 and all:%d fit in mtu:%d\n",
665 orig_flight, net->mtu);
672 if (sctp_debug_on & SCTP_DEBUG_TIMER4) {
673 printf("Audit total flight due to negative value net:%p\n",
676 #endif /* SCTP_DEBUG */
677 stcb->asoc.total_flight = 0;
678 stcb->asoc.total_flight_count = 0;
679 /* Clear all networks flight size */
680 TAILQ_FOREACH(lnets, &stcb->asoc.nets, sctp_next) {
681 lnets->flight_size = 0;
683 if (sctp_debug_on & SCTP_DEBUG_TIMER4) {
684 printf("Net:%p c-f cwnd:%d ssthresh:%d\n",
685 lnets, lnets->cwnd, lnets->ssthresh);
687 #endif /* SCTP_DEBUG */
689 TAILQ_FOREACH(chk, &stcb->asoc.sent_queue, sctp_next) {
690 if (chk->sent < SCTP_DATAGRAM_RESEND) {
691 stcb->asoc.total_flight += chk->book_size;
692 chk->whoTo->flight_size += chk->book_size;
693 stcb->asoc.total_flight_count++;
697 /* Setup the ecn nonce re-sync point. We
698 * do this since retranmissions are NOT
699 * setup for ECN. This means that do to
700 * Karn's rule, we don't know the total
701 * of the peers ecn bits.
703 chk = TAILQ_FIRST(&stcb->asoc.send_queue);
705 stcb->asoc.nonce_resync_tsn = stcb->asoc.sending_seq;
707 stcb->asoc.nonce_resync_tsn = chk->rec.data.TSN_seq;
709 stcb->asoc.nonce_wait_for_ecne = 0;
710 stcb->asoc.nonce_sum_check = 0;
711 /* We return 1 if we only have a window probe outstanding */
712 if (win_probes && (non_win_probes == 0)) {
719 sctp_move_all_chunks_to_alt(struct sctp_tcb *stcb,
720 struct sctp_nets *net,
721 struct sctp_nets *alt)
723 struct sctp_association *asoc;
724 struct sctp_stream_out *outs;
725 struct sctp_tmit_chunk *chk;
734 * now through all the streams checking for chunks sent to our
737 TAILQ_FOREACH(outs, &asoc->out_wheel, next_spoke) {
738 /* now clean up any chunks here */
739 TAILQ_FOREACH(chk, &outs->outqueue, sctp_next) {
740 if (chk->whoTo == net) {
741 sctp_free_remote_addr(chk->whoTo);
747 /* Now check the pending queue */
748 TAILQ_FOREACH(chk, &asoc->send_queue, sctp_next) {
749 if (chk->whoTo == net) {
750 sctp_free_remote_addr(chk->whoTo);
759 sctp_t3rxt_timer(struct sctp_inpcb *inp,
760 struct sctp_tcb *stcb,
761 struct sctp_nets *net)
763 struct sctp_nets *alt;
764 int win_probe, num_mk;
767 #ifdef SCTP_FR_LOGGING
768 sctp_log_fr(0, 0, 0, SCTP_FR_T3_TIMEOUT);
770 /* Find an alternate and mark those for retransmission */
771 alt = sctp_find_alternate_net(stcb, net);
772 win_probe = sctp_mark_all_for_resend(stcb, net, alt, &num_mk);
774 /* FR Loss recovery just ended with the T3. */
775 stcb->asoc.fast_retran_loss_recovery = 0;
777 /* setup the sat loss recovery that prevents
778 * satellite cwnd advance.
780 stcb->asoc.sat_t3_loss_recovery = 1;
781 stcb->asoc.sat_t3_recovery_tsn = stcb->asoc.sending_seq;
783 /* Backoff the timer and cwnd */
784 sctp_backoff_on_timeout(stcb, net, win_probe, num_mk);
785 if (win_probe == 0) {
786 /* We don't do normal threshold management on window probes */
787 if (sctp_threshold_management(inp, stcb, net,
788 stcb->asoc.max_send_times)) {
789 /* Association was destroyed */
792 if (net != stcb->asoc.primary_destination) {
793 /* send a immediate HB if our RTO is stale */
795 unsigned int ms_goneby;
796 SCTP_GETTIME_TIMEVAL(&now);
797 if (net->last_sent_time.tv_sec) {
798 ms_goneby = (now.tv_sec - net->last_sent_time.tv_sec) * 1000;
802 if ((ms_goneby > net->RTO) || (net->RTO == 0)) {
803 /* no recent feed back in an RTO or more, request a RTT update */
804 sctp_send_hb(stcb, 1, net);
810 * For a window probe we don't penalize the net's but only
811 * the association. This may fail it if SACKs are not coming
812 * back. If sack's are coming with rwnd locked at 0, we will
813 * continue to hold things waiting for rwnd to raise
815 if (sctp_threshold_management(inp, stcb, NULL,
816 stcb->asoc.max_send_times)) {
817 /* Association was destroyed */
821 if (net->dest_state & SCTP_ADDR_NOT_REACHABLE) {
822 /* Move all pending over too */
823 sctp_move_all_chunks_to_alt(stcb, net, alt);
824 /* Was it our primary? */
825 if ((stcb->asoc.primary_destination == net) && (alt != net)) {
827 * Yes, note it as such and find an alternate
828 * note: this means HB code must use this to resent
829 * the primary if it goes active AND if someone does
830 * a change-primary then this flag must be cleared
831 * from any net structures.
833 if (sctp_set_primary_addr(stcb,
834 (struct sockaddr *)NULL,
836 net->dest_state |= SCTP_ADDR_WAS_PRIMARY;
837 net->src_addr_selected = 0;
842 * Special case for cookie-echo'ed case, we don't do output
843 * but must await the COOKIE-ACK before retransmission
845 if (SCTP_GET_STATE(&stcb->asoc) == SCTP_STATE_COOKIE_ECHOED) {
847 * Here we just reset the timer and start again since we
848 * have not established the asoc
851 if (sctp_debug_on & SCTP_DEBUG_TIMER1) {
852 printf("Special cookie case return\n");
854 #endif /* SCTP_DEBUG */
855 sctp_timer_start(SCTP_TIMER_TYPE_SEND, inp, stcb, net);
858 if (stcb->asoc.peer_supports_prsctp) {
859 struct sctp_tmit_chunk *lchk;
860 lchk = sctp_try_advance_peer_ack_point(stcb, &stcb->asoc);
861 /* C3. See if we need to send a Fwd-TSN */
862 if (compare_with_wrap(stcb->asoc.advanced_peer_ack_point,
863 stcb->asoc.last_acked_seq, MAX_TSN)) {
865 * ISSUE with ECN, see FWD-TSN processing for notes
866 * on issues that will occur when the ECN NONCE stuff
867 * is put into SCTP for cross checking.
870 if (sctp_debug_on & SCTP_DEBUG_TIMER1) {
871 printf("Forward TSN time\n");
873 #endif /* SCTP_DEBUG */
874 send_forward_tsn(stcb, &stcb->asoc);
876 /* Assure a timer is up */
877 sctp_timer_start(SCTP_TIMER_TYPE_SEND, stcb->sctp_ep, stcb, lchk->whoTo);
885 sctp_t1init_timer(struct sctp_inpcb *inp,
886 struct sctp_tcb *stcb,
887 struct sctp_nets *net)
889 /* bump the thresholds */
890 if (stcb->asoc.delayed_connection) {
891 /* special hook for delayed connection. The
892 * library did NOT complete the rest of its
895 stcb->asoc.delayed_connection = 0;
896 sctp_send_initiate(inp, stcb);
899 if (sctp_threshold_management(inp, stcb, net,
900 stcb->asoc.max_init_times)) {
901 /* Association was destroyed */
904 stcb->asoc.dropped_special_cnt = 0;
905 sctp_backoff_on_timeout(stcb, stcb->asoc.primary_destination, 1, 0);
906 if (stcb->asoc.initial_init_rto_max < net->RTO) {
907 net->RTO = stcb->asoc.initial_init_rto_max;
909 if (stcb->asoc.numnets > 1) {
910 /* If we have more than one addr use it */
911 struct sctp_nets *alt;
912 alt = sctp_find_alternate_net(stcb, stcb->asoc.primary_destination);
913 if ((alt != NULL) && (alt != stcb->asoc.primary_destination)) {
914 sctp_move_all_chunks_to_alt(stcb, stcb->asoc.primary_destination, alt);
915 stcb->asoc.primary_destination = alt;
918 /* Send out a new init */
919 sctp_send_initiate(inp, stcb);
924 * For cookie and asconf we actually need to find and mark for resend,
925 * then increment the resend counter (after all the threshold management
928 int sctp_cookie_timer(struct sctp_inpcb *inp,
929 struct sctp_tcb *stcb,
930 struct sctp_nets *net)
932 struct sctp_nets *alt;
933 struct sctp_tmit_chunk *cookie;
934 /* first before all else we must find the cookie */
935 TAILQ_FOREACH(cookie, &stcb->asoc.control_send_queue, sctp_next) {
936 if (cookie->rec.chunk_id == SCTP_COOKIE_ECHO) {
940 if (cookie == NULL) {
941 if (SCTP_GET_STATE(&stcb->asoc) == SCTP_STATE_COOKIE_ECHOED) {
944 MGET(oper, MB_DONTWAIT, MT_DATA);
946 struct sctp_paramhdr *ph;
949 oper->m_len = sizeof(struct sctp_paramhdr) +
951 ph = mtod(oper, struct sctp_paramhdr *);
952 ph->param_type = htons(SCTP_CAUSE_PROTOCOL_VIOLATION);
953 ph->param_length = htons(oper->m_len);
954 ippp = (u_int32_t *)(ph + 1);
955 *ippp = htonl(0x40000002);
957 sctp_abort_an_association(inp, stcb, SCTP_INTERNAL_ERROR,
962 /* Ok we found the cookie, threshold management next */
963 if (sctp_threshold_management(inp, stcb, cookie->whoTo,
964 stcb->asoc.max_init_times)) {
969 * cleared theshold management now lets backoff the address &
970 * select an alternate
972 stcb->asoc.dropped_special_cnt = 0;
973 sctp_backoff_on_timeout(stcb, cookie->whoTo, 1, 0);
974 alt = sctp_find_alternate_net(stcb, cookie->whoTo);
975 if (alt != cookie->whoTo) {
976 sctp_free_remote_addr(cookie->whoTo);
980 /* Now mark the retran info */
981 if (cookie->sent != SCTP_DATAGRAM_RESEND) {
982 stcb->asoc.sent_queue_retran_cnt++;
984 cookie->sent = SCTP_DATAGRAM_RESEND;
986 * Now call the output routine to kick out the cookie again, Note we
987 * don't mark any chunks for retran so that FR will need to kick in
988 * to move these (or a send timer).
993 int sctp_strreset_timer(struct sctp_inpcb *inp, struct sctp_tcb *stcb,
994 struct sctp_nets *net)
996 struct sctp_nets *alt;
997 struct sctp_tmit_chunk *strrst, *chk;
998 struct sctp_stream_reset_req *strreq;
999 /* find the existing STRRESET */
1000 TAILQ_FOREACH(strrst, &stcb->asoc.control_send_queue,
1002 if (strrst->rec.chunk_id == SCTP_STREAM_RESET) {
1003 /* is it what we want */
1004 strreq = mtod(strrst->data, struct sctp_stream_reset_req *);
1005 if (strreq->sr_req.ph.param_type == ntohs(SCTP_STR_RESET_REQUEST)) {
1010 if (strrst == NULL) {
1012 if (sctp_debug_on & SCTP_DEBUG_TIMER1) {
1013 printf("Strange, strreset timer fires, but I can't find an str-reset?\n");
1015 #endif /* SCTP_DEBUG */
1018 /* do threshold management */
1019 if (sctp_threshold_management(inp, stcb, strrst->whoTo,
1020 stcb->asoc.max_send_times)) {
1026 * cleared theshold management
1027 * now lets backoff the address & select an alternate
1029 sctp_backoff_on_timeout(stcb, strrst->whoTo, 1, 0);
1030 alt = sctp_find_alternate_net(stcb, strrst->whoTo);
1031 sctp_free_remote_addr(strrst->whoTo);
1032 strrst->whoTo = alt;
1035 /* See if a ECN Echo is also stranded */
1036 TAILQ_FOREACH(chk, &stcb->asoc.control_send_queue, sctp_next) {
1037 if ((chk->whoTo == net) &&
1038 (chk->rec.chunk_id == SCTP_ECN_ECHO)) {
1039 sctp_free_remote_addr(chk->whoTo);
1040 if (chk->sent != SCTP_DATAGRAM_RESEND) {
1041 chk->sent = SCTP_DATAGRAM_RESEND;
1042 stcb->asoc.sent_queue_retran_cnt++;
1048 if (net->dest_state & SCTP_ADDR_NOT_REACHABLE) {
1050 * If the address went un-reachable, we need to move
1051 * to alternates for ALL chk's in queue
1053 sctp_move_all_chunks_to_alt(stcb, net, alt);
1055 /* mark the retran info */
1056 if (strrst->sent != SCTP_DATAGRAM_RESEND)
1057 stcb->asoc.sent_queue_retran_cnt++;
1058 strrst->sent = SCTP_DATAGRAM_RESEND;
1060 /* restart the timer */
1061 sctp_timer_start(SCTP_TIMER_TYPE_STRRESET, inp, stcb, strrst->whoTo);
1065 int sctp_asconf_timer(struct sctp_inpcb *inp, struct sctp_tcb *stcb,
1066 struct sctp_nets *net)
1068 struct sctp_nets *alt;
1069 struct sctp_tmit_chunk *asconf, *chk;
1071 /* is this the first send, or a retransmission? */
1072 if (stcb->asoc.asconf_sent == 0) {
1073 /* compose a new ASCONF chunk and send it */
1074 sctp_send_asconf(stcb, net);
1076 /* Retransmission of the existing ASCONF needed... */
1078 /* find the existing ASCONF */
1079 TAILQ_FOREACH(asconf, &stcb->asoc.control_send_queue,
1081 if (asconf->rec.chunk_id == SCTP_ASCONF) {
1085 if (asconf == NULL) {
1087 if (sctp_debug_on & SCTP_DEBUG_TIMER1) {
1088 printf("Strange, asconf timer fires, but I can't find an asconf?\n");
1090 #endif /* SCTP_DEBUG */
1093 /* do threshold management */
1094 if (sctp_threshold_management(inp, stcb, asconf->whoTo,
1095 stcb->asoc.max_send_times)) {
1100 /* PETER? FIX? How will the following code ever run? If
1101 * the max_send_times is hit, threshold managment will
1102 * blow away the association?
1104 if (asconf->snd_count > stcb->asoc.max_send_times) {
1106 * Something is rotten, peer is not responding to
1107 * ASCONFs but maybe is to data etc. e.g. it is not
1108 * properly handling the chunk type upper bits
1109 * Mark this peer as ASCONF incapable and cleanup
1112 if (sctp_debug_on & SCTP_DEBUG_TIMER1) {
1113 printf("asconf_timer: Peer has not responded to our repeated ASCONFs\n");
1115 #endif /* SCTP_DEBUG */
1116 sctp_asconf_cleanup(stcb, net);
1120 * cleared theshold management
1121 * now lets backoff the address & select an alternate
1123 sctp_backoff_on_timeout(stcb, asconf->whoTo, 1, 0);
1124 alt = sctp_find_alternate_net(stcb, asconf->whoTo);
1125 sctp_free_remote_addr(asconf->whoTo);
1126 asconf->whoTo = alt;
1129 /* See if a ECN Echo is also stranded */
1130 TAILQ_FOREACH(chk, &stcb->asoc.control_send_queue, sctp_next) {
1131 if ((chk->whoTo == net) &&
1132 (chk->rec.chunk_id == SCTP_ECN_ECHO)) {
1133 sctp_free_remote_addr(chk->whoTo);
1135 if (chk->sent != SCTP_DATAGRAM_RESEND) {
1136 chk->sent = SCTP_DATAGRAM_RESEND;
1137 stcb->asoc.sent_queue_retran_cnt++;
1143 if (net->dest_state & SCTP_ADDR_NOT_REACHABLE) {
1145 * If the address went un-reachable, we need to move
1146 * to alternates for ALL chk's in queue
1148 sctp_move_all_chunks_to_alt(stcb, net, alt);
1150 /* mark the retran info */
1151 if (asconf->sent != SCTP_DATAGRAM_RESEND)
1152 stcb->asoc.sent_queue_retran_cnt++;
1153 asconf->sent = SCTP_DATAGRAM_RESEND;
1159 * For the shutdown and shutdown-ack, we do not keep one around on the
1160 * control queue. This means we must generate a new one and call the general
1161 * chunk output routine, AFTER having done threshold
1165 sctp_shutdown_timer(struct sctp_inpcb *inp, struct sctp_tcb *stcb,
1166 struct sctp_nets *net)
1168 struct sctp_nets *alt;
1169 /* first threshold managment */
1170 if (sctp_threshold_management(inp, stcb, net, stcb->asoc.max_send_times)) {
1174 /* second select an alternative */
1175 alt = sctp_find_alternate_net(stcb, net);
1177 /* third generate a shutdown into the queue for out net */
1179 if (sctp_debug_on & SCTP_DEBUG_OUTPUT4) {
1180 printf("%s:%d sends a shutdown\n",
1187 sctp_send_shutdown(stcb, alt);
1189 /* if alt is NULL, there is no dest
1194 /* fourth restart timer */
1195 sctp_timer_start(SCTP_TIMER_TYPE_SHUTDOWN, inp, stcb, alt);
1199 int sctp_shutdownack_timer(struct sctp_inpcb *inp, struct sctp_tcb *stcb,
1200 struct sctp_nets *net)
1202 struct sctp_nets *alt;
1203 /* first threshold managment */
1204 if (sctp_threshold_management(inp, stcb, net, stcb->asoc.max_send_times)) {
1208 /* second select an alternative */
1209 alt = sctp_find_alternate_net(stcb, net);
1211 /* third generate a shutdown into the queue for out net */
1212 sctp_send_shutdown_ack(stcb, alt);
1214 /* fourth restart timer */
1215 sctp_timer_start(SCTP_TIMER_TYPE_SHUTDOWNACK, inp, stcb, alt);
1220 sctp_audit_stream_queues_for_size(struct sctp_inpcb *inp,
1221 struct sctp_tcb *stcb)
1223 struct sctp_stream_out *outs;
1224 struct sctp_tmit_chunk *chk;
1225 unsigned int chks_in_queue=0;
1227 if ((stcb == NULL) || (inp == NULL))
1229 if (TAILQ_EMPTY(&stcb->asoc.out_wheel)) {
1230 printf("Strange, out_wheel empty nothing on sent/send and tot=%lu?\n",
1231 (u_long)stcb->asoc.total_output_queue_size);
1232 stcb->asoc.total_output_queue_size = 0;
1235 if (stcb->asoc.sent_queue_retran_cnt) {
1236 printf("Hmm, sent_queue_retran_cnt is non-zero %d\n",
1237 stcb->asoc.sent_queue_retran_cnt);
1238 stcb->asoc.sent_queue_retran_cnt = 0;
1240 /* Check to see if some data queued, if so report it */
1241 TAILQ_FOREACH(outs, &stcb->asoc.out_wheel, next_spoke) {
1242 if (!TAILQ_EMPTY(&outs->outqueue)) {
1243 TAILQ_FOREACH(chk, &outs->outqueue, sctp_next) {
1248 if (chks_in_queue != stcb->asoc.stream_queue_cnt) {
1249 printf("Hmm, stream queue cnt at %d I counted %d in stream out wheel\n",
1250 stcb->asoc.stream_queue_cnt, chks_in_queue);
1252 if (chks_in_queue) {
1253 /* call the output queue function */
1254 sctp_chunk_output(inp, stcb, 1);
1255 if ((TAILQ_EMPTY(&stcb->asoc.send_queue)) &&
1256 (TAILQ_EMPTY(&stcb->asoc.sent_queue))) {
1257 /* Probably should go in and make it go back through and add fragments allowed */
1258 printf("Still nothing moved %d chunks are stuck\n", chks_in_queue);
1261 printf("Found no chunks on any queue tot:%lu\n",
1262 (u_long)stcb->asoc.total_output_queue_size);
1263 stcb->asoc.total_output_queue_size = 0;
1268 sctp_heartbeat_timer(struct sctp_inpcb *inp, struct sctp_tcb *stcb,
1269 struct sctp_nets *net)
1271 int cnt_of_unconf=0;
1274 if (net->hb_responded == 0) {
1275 sctp_backoff_on_timeout(stcb, net, 1, 0);
1277 /* Zero PBA, if it needs it */
1278 if (net->partial_bytes_acked) {
1279 net->partial_bytes_acked = 0;
1282 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
1283 if ((net->dest_state & SCTP_ADDR_UNCONFIRMED) &&
1284 (net->dest_state & SCTP_ADDR_REACHABLE)) {
1288 if ((stcb->asoc.total_output_queue_size > 0) &&
1289 (TAILQ_EMPTY(&stcb->asoc.send_queue)) &&
1290 (TAILQ_EMPTY(&stcb->asoc.sent_queue))) {
1291 sctp_audit_stream_queues_for_size(inp, stcb);
1293 /* Send a new HB, this will do threshold managment, pick a new dest */
1294 if (sctp_send_hb(stcb, 0, NULL) < 0) {
1297 if (cnt_of_unconf > 1) {
1299 * this will send out extra hb's up to maxburst if
1300 * there are any unconfirmed addresses.
1303 while ((cnt_sent < stcb->asoc.max_burst) && (cnt_of_unconf > 1)) {
1304 if (sctp_send_hb(stcb, 0, NULL) == 0)
1313 #define SCTP_NUMBER_OF_MTU_SIZES 18
1314 static u_int32_t mtu_sizes[]={
1337 sctp_getnext_mtu(struct sctp_inpcb *inp, u_int32_t cur_mtu)
1339 /* select another MTU that is just bigger than this one */
1342 for (i = 0; i < SCTP_NUMBER_OF_MTU_SIZES; i++) {
1343 if (cur_mtu < mtu_sizes[i]) {
1344 /* no max_mtu is bigger than this one */
1345 return (mtu_sizes[i]);
1348 /* here return the highest allowable */
1353 void sctp_pathmtu_timer(struct sctp_inpcb *inp,
1354 struct sctp_tcb *stcb,
1355 struct sctp_nets *net)
1359 /* restart the timer in any case */
1360 next_mtu = sctp_getnext_mtu(inp, net->mtu);
1361 if (next_mtu <= net->mtu) {
1365 if (net->ro.ro_rt != NULL) {
1366 /* only if we have a route and interface do we
1367 * set anything. Note we always restart
1368 * the timer though just in case it is updated
1369 * (i.e. the ifp) or route/ifp is populated.
1371 if (net->ro.ro_rt->rt_ifp != NULL) {
1372 if (net->ro.ro_rt->rt_ifp->if_mtu > next_mtu) {
1373 /* ok it will fit out the door */
1374 net->mtu = next_mtu;
1378 /* restart the timer */
1379 sctp_timer_start(SCTP_TIMER_TYPE_PATHMTURAISE, inp, stcb, net);
1382 void sctp_autoclose_timer(struct sctp_inpcb *inp,
1383 struct sctp_tcb *stcb,
1384 struct sctp_nets *net)
1386 struct timeval tn, *tim_touse;
1387 struct sctp_association *asoc;
1390 SCTP_GETTIME_TIMEVAL(&tn);
1391 if (stcb->asoc.sctp_autoclose_ticks &&
1392 (inp->sctp_flags & SCTP_PCB_FLAGS_AUTOCLOSE)) {
1393 /* Auto close is on */
1395 /* pick the time to use */
1396 if (asoc->time_last_rcvd.tv_sec >
1397 asoc->time_last_sent.tv_sec) {
1398 tim_touse = &asoc->time_last_rcvd;
1400 tim_touse = &asoc->time_last_sent;
1402 /* Now has long enough transpired to autoclose? */
1403 ticks_gone_by = ((tn.tv_sec - tim_touse->tv_sec) * hz);
1404 if ((ticks_gone_by > 0) &&
1405 (ticks_gone_by >= (int)asoc->sctp_autoclose_ticks)) {
1407 * autoclose time has hit, call the output routine,
1408 * which should do nothing just to be SURE we don't
1409 * have hanging data. We can then safely check the
1410 * queues and know that we are clear to send shutdown
1412 sctp_chunk_output(inp, stcb, 9);
1414 if (TAILQ_EMPTY(&asoc->send_queue) &&
1415 TAILQ_EMPTY(&asoc->sent_queue)) {
1417 * there is nothing queued to send,
1420 if (SCTP_GET_STATE(asoc) !=
1421 SCTP_STATE_SHUTDOWN_SENT) {
1422 /* only send SHUTDOWN 1st time thru */
1424 if (sctp_debug_on & SCTP_DEBUG_OUTPUT4) {
1425 printf("%s:%d sends a shutdown\n",
1431 sctp_send_shutdown(stcb, stcb->asoc.primary_destination);
1432 asoc->state = SCTP_STATE_SHUTDOWN_SENT;
1433 sctp_timer_start(SCTP_TIMER_TYPE_SHUTDOWN,
1434 stcb->sctp_ep, stcb,
1435 asoc->primary_destination);
1436 sctp_timer_start(SCTP_TIMER_TYPE_SHUTDOWNGUARD,
1437 stcb->sctp_ep, stcb,
1438 asoc->primary_destination);
1443 * No auto close at this time, reset t-o to
1447 /* fool the timer startup to use the time left */
1448 tmp = asoc->sctp_autoclose_ticks;
1449 asoc->sctp_autoclose_ticks -= ticks_gone_by;
1450 sctp_timer_start(SCTP_TIMER_TYPE_AUTOCLOSE, inp, stcb,
1452 /* restore the real tick value */
1453 asoc->sctp_autoclose_ticks = tmp;
1459 sctp_iterator_timer(struct sctp_iterator *it)
1462 /* only one iterator can run at a
1463 * time. This is the only way we
1464 * can cleanly pull ep's from underneath
1465 * all the running interators when a
1468 SCTP_ITERATOR_LOCK();
1469 if (it->inp == NULL) {
1470 /* iterator is complete */
1472 SCTP_ITERATOR_UNLOCK();
1473 SCTP_INP_INFO_WLOCK();
1474 LIST_REMOVE(it, sctp_nxt_itr);
1475 /* stopping the callout is not needed, in theory,
1476 * but I am paranoid.
1478 SCTP_INP_INFO_WUNLOCK();
1479 callout_stop(&it->tmr.timer);
1480 if (it->function_atend != NULL) {
1481 (*it->function_atend)(it->pointer, it->val);
1487 SCTP_INP_WLOCK(it->inp);
1488 while ((it->pcb_flags) && ((it->inp->sctp_flags & it->pcb_flags) != it->pcb_flags)) {
1489 /* we do not like this ep */
1490 if (it->iterator_flags & SCTP_ITERATOR_DO_SINGLE_INP) {
1491 SCTP_INP_WUNLOCK(it->inp);
1492 goto done_with_iterator;
1494 SCTP_INP_WUNLOCK(it->inp);
1495 it->inp = LIST_NEXT(it->inp, sctp_list);
1496 if (it->inp == NULL) {
1497 goto done_with_iterator;
1499 SCTP_INP_WLOCK(it->inp);
1501 if ((it->inp->inp_starting_point_for_iterator != NULL) &&
1502 (it->inp->inp_starting_point_for_iterator != it)) {
1503 printf("Iterator collision, we must wait for other iterator at %x\n",
1505 SCTP_INP_WUNLOCK(it->inp);
1506 goto start_timer_return;
1508 /* now we do the actual write to this guy */
1509 it->inp->inp_starting_point_for_iterator = it;
1510 SCTP_INP_WUNLOCK(it->inp);
1511 SCTP_INP_RLOCK(it->inp);
1512 /* if we reach here we found a inp acceptable, now through each
1513 * one that has the association in the right state
1515 if (it->stcb == NULL) {
1516 it->stcb = LIST_FIRST(&it->inp->sctp_asoc_list);
1518 if (it->stcb->asoc.stcb_starting_point_for_iterator == it) {
1519 it->stcb->asoc.stcb_starting_point_for_iterator = NULL;
1522 SCTP_TCB_LOCK(it->stcb);
1523 if (it->asoc_state && ((it->stcb->asoc.state & it->asoc_state) != it->asoc_state)) {
1524 SCTP_TCB_UNLOCK(it->stcb);
1525 it->stcb = LIST_NEXT(it->stcb, sctp_tcblist);
1529 /* run function on this one */
1530 SCTP_INP_RUNLOCK(it->inp);
1531 (*it->function_toapply)(it->inp, it->stcb, it->pointer, it->val);
1532 sctp_chunk_output(it->inp, it->stcb, 1);
1533 SCTP_TCB_UNLOCK(it->stcb);
1534 /* see if we have limited out */
1535 if (cnt > SCTP_MAX_ITERATOR_AT_ONCE) {
1536 it->stcb->asoc.stcb_starting_point_for_iterator = it;
1538 SCTP_ITERATOR_UNLOCK();
1539 sctp_timer_start(SCTP_TIMER_TYPE_ITERATOR, (struct sctp_inpcb *)it, NULL, NULL);
1542 SCTP_INP_RLOCK(it->inp);
1543 it->stcb = LIST_NEXT(it->stcb, sctp_tcblist);
1545 /* if we reach here, we ran out of stcb's in the inp we are looking at */
1546 SCTP_INP_RUNLOCK(it->inp);
1547 SCTP_INP_WLOCK(it->inp);
1548 it->inp->inp_starting_point_for_iterator = NULL;
1549 SCTP_INP_WUNLOCK(it->inp);
1550 if (it->iterator_flags & SCTP_ITERATOR_DO_SINGLE_INP) {
1553 SCTP_INP_INFO_RLOCK();
1554 it->inp = LIST_NEXT(it->inp, sctp_list);
1555 SCTP_INP_INFO_RUNLOCK();
1557 if (it->inp == NULL) {
1558 goto done_with_iterator;
1560 goto select_a_new_ep;