4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
23 * Copyright (c) 2004, 2010, Oracle and/or its affiliates. All rights reserved.
26 #include <sys/types.h>
27 #include <sys/systm.h>
28 #include <sys/stream.h>
29 #include <sys/cmn_err.h>
30 #include <sys/strsubr.h>
31 #include <sys/strsun.h>
33 #include <netinet/in.h>
34 #include <netinet/ip6.h>
36 #include <inet/common.h>
38 #include <inet/mib2.h>
39 #include <inet/ipclassifier.h>
40 #include "sctp_impl.h"
41 #include "sctp_asconf.h"
43 /* Timer block states. */
47 /* Could not stop/free before mblk got queued */
48 SCTP_TB_RESCHED
, /* sctp_tb_time_left contains tick count */
53 typedef struct sctp_tb_s
{
54 timer_block_state sctp_tb_state
;
55 timeout_id_t sctp_tb_tid
;
57 clock_t sctp_tb_time_left
;
61 * Early abort threshold when the system is under pressure, sctps_reclaim
64 * sctp_pa_early_abort: number of strikes per association before abort
65 * sctp_pp_early_abort: number of strikes per peer address before abort
67 uint32_t sctp_pa_early_abort
= 5;
68 uint32_t sctp_pp_early_abort
= 3;
70 static void sctp_timer_fire(sctp_tb_t
*);
73 * sctp_timer mechanism.
75 * Each timer is represented by a timer mblk. When the
76 * timer fires, and the sctp_t is busy, the timer mblk will be put on
77 * the associated sctp_t timer queue so that it can be executed when
78 * the thread holding the lock on the sctp_t is done with its job.
80 * Note that there is no lock to protect the timer mblk state. The reason
81 * is that the timer state can only be changed by a thread holding the
84 * The interface consists of 4 entry points:
85 * sctp_timer_alloc - create a timer mblk
86 * sctp_timer_free - free a timer mblk
87 * sctp_timer - start, restart, stop the timer
88 * sctp_timer_valid - called by sctp_process_recvq to verify that
89 * the timer did indeed fire.
94 * Start, restart, stop the timer.
95 * If "tim" is -1 the timer is stopped.
96 * Otherwise, the timer is stopped if it is already running, and
97 * set to fire tim clock ticks from now.
100 sctp_timer(sctp_t
*sctp
, mblk_t
*mp
, clock_t tim
)
105 ASSERT(sctp
!= NULL
&& mp
!= NULL
);
106 ASSERT((mp
->b_rptr
- mp
->b_datap
->db_base
) == sizeof (sctp_tb_t
));
107 ASSERT(mp
->b_datap
->db_type
== M_PCSIG
);
109 sctp_tb
= (sctp_tb_t
*)mp
->b_datap
->db_base
;
111 state
= sctp_tb
->sctp_tb_state
;
112 sctp_tb
->sctp_tb_time_left
= tim
;
113 if (state
== SCTP_TB_RUNNING
) {
114 if (untimeout(sctp_tb
->sctp_tb_tid
) < 0) {
115 sctp_tb
->sctp_tb_state
= SCTP_TB_RESCHED
;
116 /* sctp_timer_valid will start timer */
119 } else if (state
!= SCTP_TB_IDLE
) {
120 ASSERT(state
!= SCTP_TB_TO_BE_FREED
);
121 if (state
== SCTP_TB_CANCELLED
) {
122 sctp_tb
->sctp_tb_state
= SCTP_TB_RESCHED
;
123 /* sctp_timer_valid will start timer */
126 if (state
== SCTP_TB_RESCHED
) {
127 /* sctp_timer_valid will start timer */
133 sctp_tb
->sctp_tb_state
= SCTP_TB_RUNNING
;
134 sctp_tb
->sctp_tb_tid
=
135 timeout((pfv_t
)sctp_timer_fire
, sctp_tb
, tim
);
149 * sctp_timer_alloc is called by sctp_init to allocate and initialize a
152 * Allocate an M_PCSIG timer message. The space between db_base and
153 * b_rptr is used by the sctp_timer mechanism, and after b_rptr there is
157 sctp_timer_alloc(sctp_t
*sctp
, pfv_t func
, int sleep
)
162 sctp_stack_t
*sctps
= sctp
->sctp_sctps
;
164 if (sleep
== KM_SLEEP
) {
165 mp
= allocb_wait(sizeof (sctp_t
) + sizeof (sctp_tb_t
), BPRI_HI
,
168 mp
= allocb(sizeof (sctp_t
) + sizeof (sctp_tb_t
), BPRI_HI
);
171 mp
->b_datap
->db_type
= M_PCSIG
;
172 sctp_tb
= (sctp_tb_t
*)mp
->b_datap
->db_base
;
173 mp
->b_rptr
= (uchar_t
*)&sctp_tb
[1];
174 mp
->b_wptr
= mp
->b_rptr
+ sizeof (sctpt_t
);
175 sctp_tb
->sctp_tb_state
= SCTP_TB_IDLE
;
176 sctp_tb
->sctp_tb_mp
= mp
;
178 sctpt
= (sctpt_t
*)mp
->b_rptr
;
179 sctpt
->sctpt_sctp
= sctp
;
180 sctpt
->sctpt_faddr
= NULL
; /* set when starting timer */
181 sctpt
->sctpt_pfv
= func
;
184 SCTP_KSTAT(sctps
, sctp_add_timer
);
189 * timeout() callback function.
190 * Put the message on the process control block's queue.
191 * If the timer is stopped or freed after
192 * it has fired then sctp_timer() and sctp_timer_valid() will clean
196 sctp_timer_fire(sctp_tb_t
*sctp_tb
)
202 mp
= sctp_tb
->sctp_tb_mp
;
203 ASSERT(sctp_tb
== (sctp_tb_t
*)mp
->b_datap
->db_base
);
204 ASSERT(mp
->b_datap
->db_type
== M_PCSIG
);
206 sctpt
= (sctpt_t
*)mp
->b_rptr
;
207 sctp
= sctpt
->sctpt_sctp
;
208 ASSERT(sctp
!= NULL
);
210 mutex_enter(&sctp
->sctp_lock
);
211 if (sctp
->sctp_running
) {
213 * Put the timer mblk to the special sctp_timer_mp list.
214 * This timer will be handled when the thread using this
215 * SCTP is done with its job.
217 if (sctp
->sctp_timer_mp
== NULL
) {
219 sctp
->sctp_timer_mp
= mp
;
221 linkb(sctp
->sctp_timer_mp
, mp
);
224 mutex_exit(&sctp
->sctp_lock
);
226 sctp
->sctp_running
= B_TRUE
;
227 mutex_exit(&sctp
->sctp_lock
);
229 sctp_timer_call(sctp
, mp
);
236 * Logically free a timer mblk (that might have a pending timeout().)
237 * If the timer has fired and the mblk has been put on the queue then
238 * sctp_timer_valid will free the mblk.
241 sctp_timer_free(mblk_t
*mp
)
248 ASSERT((mp
->b_rptr
- mp
->b_datap
->db_base
) == sizeof (sctp_tb_t
));
249 ASSERT(mp
->b_datap
->db_type
== M_PCSIG
);
251 sctp_tb
= (sctp_tb_t
*)mp
->b_datap
->db_base
;
252 state
= sctp_tb
->sctp_tb_state
;
254 dprint(5, ("sctp_timer_free %p state %d\n", (void *)mp
, state
));
256 if (state
== SCTP_TB_RUNNING
) {
257 if (untimeout(sctp_tb
->sctp_tb_tid
) < 0) {
258 sctp_tb
->sctp_tb_state
= SCTP_TB_TO_BE_FREED
;
259 /* sctp_timer_valid will free the mblk */
262 sctpt
= (sctpt_t
*)mp
->b_rptr
;
263 SCTP_REFRELE(sctpt
->sctpt_sctp
);
264 } else if (state
!= SCTP_TB_IDLE
) {
265 ASSERT(state
!= SCTP_TB_TO_BE_FREED
);
266 sctp_tb
->sctp_tb_state
= SCTP_TB_TO_BE_FREED
;
267 /* sctp_timer_valid will free the mblk */
274 * Called from sctp_timer(,,-1)
277 sctp_timer_stop(mblk_t
*mp
)
284 ASSERT(mp
->b_datap
->db_type
== M_PCSIG
);
286 sctp_tb
= (sctp_tb_t
*)mp
->b_datap
->db_base
;
287 state
= sctp_tb
->sctp_tb_state
;
289 dprint(5, ("sctp_timer_stop %p %d\n", (void *)mp
, state
));
291 if (state
== SCTP_TB_RUNNING
) {
292 if (untimeout(sctp_tb
->sctp_tb_tid
) < 0) {
293 sctp_tb
->sctp_tb_state
= SCTP_TB_CANCELLED
;
295 sctp_tb
->sctp_tb_state
= SCTP_TB_IDLE
;
296 sctpt
= (sctpt_t
*)mp
->b_rptr
;
297 SCTP_REFRELE(sctpt
->sctpt_sctp
);
299 } else if (state
== SCTP_TB_RESCHED
) {
300 sctp_tb
->sctp_tb_state
= SCTP_TB_CANCELLED
;
305 * The user of the sctp_timer mechanism is required to call
306 * sctp_timer_valid() for each M_PCSIG message processed in the
307 * service procedures.
308 * sctp_timer_valid will return "true" if the timer actually did fire.
312 sctp_timer_valid(mblk_t
*mp
)
319 ASSERT(mp
->b_datap
->db_type
== M_PCSIG
);
321 sctp_tb
= (sctp_tb_t
*)DB_BASE(mp
);
322 sctpt
= (sctpt_t
*)mp
->b_rptr
;
323 state
= sctp_tb
->sctp_tb_state
;
324 if (state
!= SCTP_TB_RUNNING
) {
325 ASSERT(state
!= SCTP_TB_IDLE
);
326 if (state
== SCTP_TB_TO_BE_FREED
) {
328 * sctp_timer_free was called after the message
334 if (state
== SCTP_TB_CANCELLED
) {
335 /* The timer was stopped after the mblk was putq'ed */
336 sctp_tb
->sctp_tb_state
= SCTP_TB_IDLE
;
339 if (state
== SCTP_TB_RESCHED
) {
341 * The timer was stopped and then restarted after
342 * the mblk was putq'ed.
343 * sctp_tb_time_left contains the number of ticks that
344 * the timer was restarted with.
345 * The sctp will not be disapper between the time
346 * the sctpt_t is marked SCTP_TB_RESCHED and when
347 * we get here as sctp_add_recvq() does a refhold.
349 sctp_tb
->sctp_tb_state
= SCTP_TB_RUNNING
;
350 sctp_tb
->sctp_tb_tid
= timeout((pfv_t
)sctp_timer_fire
,
351 sctp_tb
, sctp_tb
->sctp_tb_time_left
);
352 SCTP_REFHOLD(sctpt
->sctpt_sctp
);
356 sctp_tb
->sctp_tb_state
= SCTP_TB_IDLE
;
361 * The SCTP timer call. Calls sctp_timer_valid() to verify whether
362 * timer was cancelled or not.
365 sctp_timer_call(sctp_t
*sctp
, mblk_t
*mp
)
367 sctpt_t
*sctpt
= (sctpt_t
*)mp
->b_rptr
;
369 if (sctp_timer_valid(mp
)) {
370 (*sctpt
->sctpt_pfv
)(sctp
, sctpt
->sctpt_faddr
);
378 sctp_ack_timer(sctp_t
*sctp
)
380 sctp_stack_t
*sctps
= sctp
->sctp_sctps
;
382 sctp
->sctp_ack_timer_running
= 0;
383 sctp
->sctp_sack_toggle
= sctps
->sctps_deferred_acks_max
;
384 SCTPS_BUMP_MIB(sctps
, sctpOutAckDelayed
);
385 (void) sctp_sack(sctp
, NULL
);
389 * Peer address heartbeat timer handler
392 sctp_heartbeat_timer(sctp_t
*sctp
)
396 int64_t earliest_expiry
;
398 sctp_stack_t
*sctps
= sctp
->sctp_sctps
;
401 if (sctp
->sctp_strikes
>= sctp
->sctp_pa_max_rxt
) {
403 * If there is a peer address with no strikes, don't give up
404 * yet unless we are under memory pressure. If enough other
405 * peer address are down, we could otherwise fail the
406 * association prematurely. This is a byproduct of our
407 * aggressive probe approach when a heartbeat fails to
408 * connect. We may wish to revisit this...
410 if (sctps
->sctps_reclaim
|| !sctp_is_a_faddr_clean(sctp
)) {
411 /* time to give up */
412 SCTPS_BUMP_MIB(sctps
, sctpAborted
);
413 SCTPS_BUMP_MIB(sctps
, sctpTimHeartBeatDrop
);
414 sctp_assoc_event(sctp
, SCTP_COMM_LOST
, 0, NULL
);
415 sctp_clean_death(sctp
, sctp
->sctp_client_errno
?
416 sctp
->sctp_client_errno
: ETIMEDOUT
);
421 /* Only send heartbeats in the established state */
422 if (sctp
->sctp_state
!= SCTPS_ESTABLISHED
) {
423 dprint(5, ("sctp_heartbeat_timer: not in ESTABLISHED\n"));
427 now
= ddi_get_lbolt64();
429 cnt
= sctps
->sctps_maxburst
;
432 * Walk through all faddrs. Since the timer should run infrequently
433 * and the number of peer addresses should not be big, this should
436 for (fp
= sctp
->sctp_faddrs
; fp
!= NULL
; fp
= fp
->sf_next
) {
437 if (sctps
->sctps_reclaim
)
438 pp_max_retr
= MIN(sctp_pp_early_abort
, fp
->sf_max_retr
);
440 pp_max_retr
= fp
->sf_max_retr
;
443 * If the peer is unreachable because there is no available
444 * source address, call sctp_get_dest() to see if it is
445 * reachable now. If it is OK, the state will become
446 * unconfirmed. And the following code to handle unconfirmed
447 * address will be executed. If it is still not OK,
448 * re-schedule. If heartbeat is enabled, only try this
449 * up to the normal heartbeat max times. But if heartbeat
450 * is disable, this retry may go on forever.
452 if (fp
->sf_state
== SCTP_FADDRS_UNREACH
) {
453 sctp_get_dest(sctp
, fp
);
454 if (fp
->sf_state
== SCTP_FADDRS_UNREACH
) {
455 if (fp
->sf_hb_enabled
&&
456 ++fp
->sf_strikes
> pp_max_retr
&&
457 sctp_faddr_dead(sctp
, fp
,
458 SCTP_FADDRS_DOWN
) == -1) {
462 fp
->sf_hb_expiry
= now
+ SET_HB_INTVL(fp
);
465 /* Send a heartbeat immediately. */
466 fp
->sf_hb_expiry
= now
;
470 * Don't send heartbeat to this address if it is not
471 * hb_enabled and the address has been confirmed.
473 if (!fp
->sf_hb_enabled
&& fp
->sf_state
!=
474 SCTP_FADDRS_UNCONFIRMED
) {
479 * The heartbeat timer is expired. If the address is dead,
480 * we still send heartbeat to it in case it becomes alive
481 * again. But we will only send once in a while, calculated
484 * If the address is alive and there is a hearbeat pending,
485 * resend the heartbeat and start exponential backoff on the
486 * heartbeat timeout value. If there is no heartbeat pending,
489 if (now
>= fp
->sf_hb_expiry
) {
490 if (fp
->sf_hb_pending
) {
492 * If an address is not confirmed, no need
493 * to bump the overall counter as it doesn't
494 * matter as we will not use it to send data
495 * and it should not affect the association.
497 switch (fp
->sf_state
) {
498 case SCTP_FADDRS_ALIVE
:
499 sctp
->sctp_strikes
++;
501 case SCTP_FADDRS_UNCONFIRMED
:
503 * Retransmission implies that RTO
504 * is probably not correct.
506 fp
->sf_rtt_updates
= 0;
508 if (fp
->sf_strikes
> pp_max_retr
) {
509 if (sctp_faddr_dead(sctp
, fp
,
510 SCTP_FADDRS_DOWN
) == -1) {
515 * Addr is down; keep initial
519 sctp
->sctp_rto_initial
;
522 SCTP_CALC_RXT(sctp
, fp
,
524 fp
->sf_hb_expiry
= now
+
528 case SCTP_FADDRS_DOWN
:
530 fp
->sf_hb_expiry
= now
+
538 * If there is unack'ed data, no need to
541 if (fp
->sf_suna
> 0) {
542 fp
->sf_hb_expiry
= now
+
546 fp
->sf_hb_expiry
= now
+ fp
->sf_rto
;
550 * Note that the total number of heartbeat we can send
551 * out simultaneously is limited by sctp_maxburst. If
552 * the limit is exceeded, we need to wait for the next
553 * timeout to send them. This should only happen if
554 * there is unconfirmed address. Note that hb_pending
555 * is set in sctp_send_heartbeat(). So if a heartbeat
556 * is not sent, it will not affect the state of the
559 if (fp
->sf_state
!= SCTP_FADDRS_UNCONFIRMED
||
561 sctp_send_heartbeat(sctp
, fp
);
564 if (fp
->sf_hb_expiry
< earliest_expiry
|| earliest_expiry
== 0)
565 earliest_expiry
= fp
->sf_hb_expiry
;
567 if (sctp
->sctp_autoclose
!= 0) {
570 expire
= sctp
->sctp_active
+ sctp
->sctp_autoclose
;
573 dprint(3, ("sctp_heartbeat_timer: autoclosing\n"));
574 sctp_send_shutdown(sctp
, 0);
577 if (expire
< earliest_expiry
|| earliest_expiry
== 0)
578 earliest_expiry
= expire
;
581 earliest_expiry
-= now
;
582 if (earliest_expiry
< 0)
584 sctp_timer(sctp
, sctp
->sctp_heartbeat_mp
, earliest_expiry
);
588 sctp_rexmit_timer(sctp_t
*sctp
, sctp_faddr_t
*fp
)
591 uint32_t rto_max
= sctp
->sctp_rto_max
;
592 sctp_stack_t
*sctps
= sctp
->sctp_sctps
;
593 int pp_max_retr
, pa_max_retr
;
597 dprint(3, ("sctp_timer: faddr=%x:%x:%x:%x\n",
598 SCTP_PRINTADDR(fp
->sf_faddr
)));
600 fp
->sf_timer_running
= 0;
602 if (!sctps
->sctps_reclaim
) {
603 pp_max_retr
= fp
->sf_max_retr
;
604 pa_max_retr
= sctp
->sctp_pa_max_rxt
;
606 /* App may have set a very aggressive retransmission limit. */
607 pp_max_retr
= MIN(sctp_pp_early_abort
, fp
->sf_max_retr
);
608 pa_max_retr
= MIN(sctp_pa_early_abort
, sctp
->sctp_pa_max_rxt
);
611 /* Check is we've reached the max for retries */
612 if (sctp
->sctp_state
< SCTPS_ESTABLISHED
) {
613 if (fp
->sf_strikes
>= sctp
->sctp_max_init_rxt
) {
614 /* time to give up */
615 SCTPS_BUMP_MIB(sctps
, sctpAborted
);
616 SCTPS_BUMP_MIB(sctps
, sctpTimRetransDrop
);
617 sctp_assoc_event(sctp
, SCTP_CANT_STR_ASSOC
, 0, NULL
);
618 sctp_clean_death(sctp
, sctp
->sctp_client_errno
?
619 sctp
->sctp_client_errno
: ETIMEDOUT
);
622 } else if (sctp
->sctp_state
>= SCTPS_ESTABLISHED
) {
623 if (sctp
->sctp_strikes
>= pa_max_retr
) {
624 /* time to give up */
625 SCTPS_BUMP_MIB(sctps
, sctpAborted
);
626 SCTPS_BUMP_MIB(sctps
, sctpTimRetransDrop
);
627 sctp_assoc_event(sctp
, SCTP_COMM_LOST
, 0, NULL
);
628 sctp_clean_death(sctp
, sctp
->sctp_client_errno
?
629 sctp
->sctp_client_errno
: ETIMEDOUT
);
634 if (fp
->sf_strikes
>= pp_max_retr
) {
635 if (sctp_faddr_dead(sctp
, fp
, SCTP_FADDRS_DOWN
) == -1) {
640 switch (sctp
->sctp_state
) {
641 case SCTPS_SHUTDOWN_RECEIVED
:
642 (void) sctp_shutdown_received(sctp
, NULL
, B_FALSE
, B_TRUE
,
646 case SCTPS_ESTABLISHED
:
647 case SCTPS_SHUTDOWN_PENDING
:
648 if (sctp
->sctp_xmit_head
== NULL
&&
649 sctp
->sctp_xmit_unsent
== NULL
) {
650 /* Nothing to retransmit */
651 if (sctp
->sctp_state
== SCTPS_SHUTDOWN_PENDING
) {
652 sctp_send_shutdown(sctp
, 1);
657 SCTPS_BUMP_MIB(sctps
, sctpTimRetrans
);
659 sctp_rexmit(sctp
, fp
);
661 * sctp_rexmit() will increase the strikes and restart the
662 * timer, so return here.
665 case SCTPS_COOKIE_WAIT
:
666 BUMP_LOCAL(sctp
->sctp_T1expire
);
668 /* retransmit init */
670 * We don't take the conn hash lock here since the source
671 * address list won't be modified (it would have been done
672 * the first time around).
674 mp
= sctp_init_mp(sctp
, fp
);
676 SCTPS_BUMP_MIB(sctps
, sctpTimRetrans
);
677 (void) conn_ip_output(mp
, fp
->sf_ixa
);
678 BUMP_LOCAL(sctp
->sctp_opkts
);
680 rto_max
= sctp
->sctp_rto_max_init
;
682 case SCTPS_COOKIE_ECHOED
:
683 BUMP_LOCAL(sctp
->sctp_T1expire
);
684 if (sctp
->sctp_cookie_mp
== NULL
) {
685 sctp
->sctp_state
= SCTPS_COOKIE_WAIT
;
688 mp
= dupmsg(sctp
->sctp_cookie_mp
);
691 (void) conn_ip_output(mp
, fp
->sf_ixa
);
692 BUMP_LOCAL(sctp
->sctp_opkts
);
693 SCTPS_BUMP_MIB(sctps
, sctpTimRetrans
);
694 rto_max
= sctp
->sctp_rto_max_init
;
696 case SCTPS_SHUTDOWN_SENT
:
697 BUMP_LOCAL(sctp
->sctp_T2expire
);
698 sctp_send_shutdown(sctp
, 1);
699 SCTPS_BUMP_MIB(sctps
, sctpTimRetrans
);
701 case SCTPS_SHUTDOWN_ACK_SENT
:
702 /* We shouldn't have any more outstanding data */
703 ASSERT(sctp
->sctp_xmit_head
== NULL
);
704 ASSERT(sctp
->sctp_xmit_unsent
== NULL
);
706 BUMP_LOCAL(sctp
->sctp_T2expire
);
707 (void) sctp_shutdown_received(sctp
, NULL
, B_FALSE
, B_TRUE
,
709 SCTPS_BUMP_MIB(sctps
, sctpTimRetrans
);
717 sctp
->sctp_strikes
++;
718 SCTP_CALC_RXT(sctp
, fp
, rto_max
);
720 SCTP_FADDR_TIMER_RESTART(sctp
, fp
, fp
->sf_rto
);
724 * RTO calculation. timesent and now are both in ms.
727 sctp_update_rtt(sctp_t
*sctp
, sctp_faddr_t
*fp
, clock_t delta
)
731 /* Calculate the RTT in ms */
733 rtt
= rtt
> 0 ? rtt
: 1;
735 dprint(5, ("sctp_update_rtt: fp = %p, rtt = %d\n", (void *)fp
, rtt
));
737 /* Is this the first RTT measurement? */
738 if (fp
->sf_srtt
== -1) {
740 fp
->sf_rttvar
= rtt
/ 2;
741 fp
->sf_rto
= 3 * rtt
; /* == rtt + 4 * rttvar ( == rtt / 2) */
745 * Versions of the RTO equations that use fixed-point math.
746 * alpha and beta are NOT tunable in this implementation,
747 * and so are hard-coded in. alpha = 1/8, beta = 1/4.
749 abs
= fp
->sf_srtt
- rtt
;
750 abs
= abs
>= 0 ? abs
: -abs
;
751 fp
->sf_rttvar
= (3 * fp
->sf_rttvar
+ abs
) >> 2;
752 fp
->sf_rttvar
= fp
->sf_rttvar
!= 0 ? fp
->sf_rttvar
: 1;
754 fp
->sf_srtt
= (7 * fp
->sf_srtt
+ rtt
) >> 3;
755 fp
->sf_rto
= fp
->sf_srtt
+ 4 * fp
->sf_rttvar
;
758 dprint(5, ("sctp_update_rtt: srtt = %d, rttvar = %d, rto = %d\n",
759 fp
->sf_srtt
, fp
->sf_rttvar
, fp
->sf_rto
));
761 /* Bound the RTO by configured min and max values */
762 if (fp
->sf_rto
< sctp
->sctp_rto_min
) {
763 fp
->sf_rto
= sctp
->sctp_rto_min
;
765 if (fp
->sf_rto
> sctp
->sctp_rto_max
) {
766 fp
->sf_rto
= sctp
->sctp_rto_max
;
769 SCTP_MAX_RTO(sctp
, fp
);
770 fp
->sf_rtt_updates
++;
774 sctp_free_faddr_timers(sctp_t
*sctp
)
778 for (fp
= sctp
->sctp_faddrs
; fp
!= NULL
; fp
= fp
->sf_next
) {
779 if (fp
->sf_timer_mp
!= NULL
) {
780 sctp_timer_free(fp
->sf_timer_mp
);
781 fp
->sf_timer_mp
= NULL
;
782 fp
->sf_timer_running
= 0;
784 if (fp
->sf_rc_timer_mp
!= NULL
) {
785 sctp_timer_free(fp
->sf_rc_timer_mp
);
786 fp
->sf_rc_timer_mp
= NULL
;
787 fp
->sf_rc_timer_running
= 0;
793 sctp_stop_faddr_timers(sctp_t
*sctp
)
797 for (fp
= sctp
->sctp_faddrs
; fp
!= NULL
; fp
= fp
->sf_next
) {
798 SCTP_FADDR_TIMER_STOP(fp
);
799 SCTP_FADDR_RC_TIMER_STOP(fp
);
804 sctp_process_timer(sctp_t
*sctp
)
808 ASSERT(sctp
->sctp_running
);
809 ASSERT(MUTEX_HELD(&sctp
->sctp_lock
));
810 while ((mp
= sctp
->sctp_timer_mp
) != NULL
) {
811 ASSERT(DB_TYPE(mp
) == M_PCSIG
);
813 * Since the timer mblk can be freed in sctp_timer_call(),
814 * we need to grab the b_cont before that.
816 sctp
->sctp_timer_mp
= mp
->b_cont
;
819 * We have a reference on the sctp, the lock must be
820 * dropped to avoid deadlocks with functions potentially
821 * called in this context which in turn call untimeout().
823 mutex_exit(&sctp
->sctp_lock
);
824 sctp_timer_call(sctp
, mp
);
825 mutex_enter(&sctp
->sctp_lock
);