2 * Copyright (c) 1982, 1986, 1988, 1990, 1993, 1995
3 * The Regents of the University of California. All rights reserved.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 4. Neither the name of the University nor the names of its contributors
14 * may be used to endorse or promote products derived from this software
15 * without specific prior written permission.
17 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
18 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
21 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29 * @(#)tcp_timer.c 8.2 (Berkeley) 5/24/95
32 #include <sys/cdefs.h>
33 __FBSDID("$FreeBSD$");
36 #include "opt_inet6.h"
37 #include "opt_tcpdebug.h"
40 #include <sys/param.h>
41 #include <sys/kernel.h>
44 #include <sys/mutex.h>
45 #include <sys/protosw.h>
47 #include <sys/socket.h>
48 #include <sys/socketvar.h>
49 #include <sys/sysctl.h>
50 #include <sys/systm.h>
53 #include <net/route.h>
55 #include <net/netisr.h>
57 #include <netinet/cc.h>
58 #include <netinet/in.h>
59 #include <netinet/in_pcb.h>
60 #include <netinet/in_rss.h>
61 #include <netinet/in_systm.h>
63 #include <netinet6/in6_pcb.h>
65 #include <netinet/ip_var.h>
66 #include <netinet/tcp_fsm.h>
67 #include <netinet/tcp_timer.h>
68 #include <netinet/tcp_var.h>
69 #include <netinet/tcpip.h>
71 #include <netinet/tcp_debug.h>
75 SYSCTL_PROC(_net_inet_tcp, TCPCTL_KEEPINIT, keepinit, CTLTYPE_INT|CTLFLAG_RW,
76 &tcp_keepinit, 0, sysctl_msec_to_ticks, "I", "time to establish connection");
79 SYSCTL_PROC(_net_inet_tcp, TCPCTL_KEEPIDLE, keepidle, CTLTYPE_INT|CTLFLAG_RW,
80 &tcp_keepidle, 0, sysctl_msec_to_ticks, "I", "time before keepalive probes begin");
83 SYSCTL_PROC(_net_inet_tcp, TCPCTL_KEEPINTVL, keepintvl, CTLTYPE_INT|CTLFLAG_RW,
84 &tcp_keepintvl, 0, sysctl_msec_to_ticks, "I", "time between keepalive probes");
87 SYSCTL_PROC(_net_inet_tcp, TCPCTL_DELACKTIME, delacktime, CTLTYPE_INT|CTLFLAG_RW,
88 &tcp_delacktime, 0, sysctl_msec_to_ticks, "I",
89 "Time before a delayed ACK is sent");
92 SYSCTL_PROC(_net_inet_tcp, OID_AUTO, msl, CTLTYPE_INT|CTLFLAG_RW,
93 &tcp_msl, 0, sysctl_msec_to_ticks, "I", "Maximum segment lifetime");
96 SYSCTL_PROC(_net_inet_tcp, OID_AUTO, rexmit_min, CTLTYPE_INT|CTLFLAG_RW,
97 &tcp_rexmit_min, 0, sysctl_msec_to_ticks, "I",
98 "Minimum Retransmission Timeout");
101 SYSCTL_PROC(_net_inet_tcp, OID_AUTO, rexmit_slop, CTLTYPE_INT|CTLFLAG_RW,
102 &tcp_rexmit_slop, 0, sysctl_msec_to_ticks, "I",
103 "Retransmission Timer Slop");
105 static int always_keepalive = 1;
106 SYSCTL_INT(_net_inet_tcp, OID_AUTO, always_keepalive, CTLFLAG_RW,
107 &always_keepalive , 0, "Assume SO_KEEPALIVE on all TCP connections");
109 int tcp_fast_finwait2_recycle = 0;
110 SYSCTL_INT(_net_inet_tcp, OID_AUTO, fast_finwait2_recycle, CTLFLAG_RW,
111 &tcp_fast_finwait2_recycle, 0,
112 "Recycle closed FIN_WAIT_2 connections faster");
114 int tcp_finwait2_timeout;
115 SYSCTL_PROC(_net_inet_tcp, OID_AUTO, finwait2_timeout, CTLTYPE_INT|CTLFLAG_RW,
116 &tcp_finwait2_timeout, 0, sysctl_msec_to_ticks, "I", "FIN-WAIT2 timeout");
118 int tcp_keepcnt = TCPTV_KEEPCNT;
119 SYSCTL_INT(_net_inet_tcp, OID_AUTO, keepcnt, CTLFLAG_RW, &tcp_keepcnt, 0,
120 "Number of keepalive probes to send");
122 /* max idle probes */
123 int tcp_maxpersistidle;
125 static int tcp_rexmit_drop_options = 0;
126 SYSCTL_INT(_net_inet_tcp, OID_AUTO, rexmit_drop_options, CTLFLAG_RW,
127 &tcp_rexmit_drop_options, 0,
128 "Drop TCP options from 3rd and later retransmitted SYN");
131 static int per_cpu_timers = 1;
133 static int per_cpu_timers = 0;
135 SYSCTL_INT(_net_inet_tcp, OID_AUTO, per_cpu_timers, CTLFLAG_RW,
136 &per_cpu_timers , 0, "run tcp timers on all cpus");
139 #define INP_CPU(inp) (per_cpu_timers ? (!CPU_ABSENT(((inp)->inp_flowid % (mp_maxid+1))) ? \
140 ((inp)->inp_flowid % (mp_maxid+1)) : curcpu) : 0)
144 * Map the given inp to a CPU id.
146 * This queries RSS if it's compiled in, else it defaults to the current
150 inp_to_cpuid(struct inpcb *inp)
155 if (per_cpu_timers) {
156 cpuid = rss_hash2cpuid(inp->inp_flowid, inp->inp_flowtype);
157 if (cpuid == NETISR_CPUID_NONE)
158 return (curcpu); /* XXX */
163 /* Legacy, pre-RSS behaviour */
164 if (per_cpu_timers) {
166 * We don't have a flowid -> cpuid mapping, so cheat and
167 * just map unknown cpuids to curcpu. Not the best, but
168 * apparently better than defaulting to swi 0.
170 cpuid = inp->inp_flowid % (mp_maxid + 1);
171 if (! CPU_ABSENT(cpuid))
176 /* Default for RSS and non-RSS - cpuid 0 */
183 * Tcp protocol timeout routine called every 500 ms.
184 * Updates timestamps used for TCP
185 * causes finite state machine actions if timers expire.
190 VNET_ITERATOR_DECL(vnet_iter);
192 VNET_LIST_RLOCK_NOSLEEP();
193 VNET_FOREACH(vnet_iter) {
194 CURVNET_SET(vnet_iter);
198 VNET_LIST_RUNLOCK_NOSLEEP();
201 int tcp_syn_backoff[TCP_MAXRXTSHIFT + 1] =
202 { 1, 1, 1, 1, 1, 2, 4, 8, 16, 32, 64, 64, 64 };
204 int tcp_backoff[TCP_MAXRXTSHIFT + 1] =
205 { 1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 512, 512, 512 };
207 static int tcp_totbackoff = 2559; /* sum of tcp_backoff[] */
209 static int tcp_timer_race;
210 SYSCTL_INT(_net_inet_tcp, OID_AUTO, timer_race, CTLFLAG_RD, &tcp_timer_race,
211 0, "Count of t_inpcb races on tcp_discardcb");
214 * TCP timer processing.
218 tcp_timer_delack(void *xtp)
220 struct tcpcb *tp = xtp;
222 CURVNET_SET(tp->t_vnet);
226 * XXXRW: While this assert is in fact correct, bugs in the tcpcb
227 * tear-down mean we need it as a work-around for races between
228 * timers and tcp_discardcb().
230 * KASSERT(inp != NULL, ("tcp_timer_delack: inp == NULL"));
238 if (callout_pending(&tp->t_timers->tt_delack) ||
239 !callout_active(&tp->t_timers->tt_delack)) {
244 callout_deactivate(&tp->t_timers->tt_delack);
245 if ((inp->inp_flags & INP_DROPPED) != 0) {
251 tp->t_flags |= TF_ACKNOW;
252 TCPSTAT_INC(tcps_delack);
253 (void) tcp_output(tp);
259 tcp_timer_2msl(void *xtp)
261 struct tcpcb *tp = xtp;
263 CURVNET_SET(tp->t_vnet);
267 ostate = tp->t_state;
270 * XXXRW: Does this actually happen?
272 INP_INFO_WLOCK(&V_tcbinfo);
275 * XXXRW: While this assert is in fact correct, bugs in the tcpcb
276 * tear-down mean we need it as a work-around for races between
277 * timers and tcp_discardcb().
279 * KASSERT(inp != NULL, ("tcp_timer_2msl: inp == NULL"));
283 INP_INFO_WUNLOCK(&V_tcbinfo);
288 tcp_free_sackholes(tp);
289 if (callout_pending(&tp->t_timers->tt_2msl) ||
290 !callout_active(&tp->t_timers->tt_2msl)) {
291 INP_WUNLOCK(tp->t_inpcb);
292 INP_INFO_WUNLOCK(&V_tcbinfo);
296 callout_deactivate(&tp->t_timers->tt_2msl);
297 if ((inp->inp_flags & INP_DROPPED) != 0) {
299 INP_INFO_WUNLOCK(&V_tcbinfo);
304 * 2 MSL timeout in shutdown went off. If we're closed but
305 * still waiting for peer to close and connection has been idle
306 * too long, or if 2MSL time is up from TIME_WAIT, delete connection
307 * control block. Otherwise, check again in a bit.
309 * If fastrecycle of FIN_WAIT_2, in FIN_WAIT_2 and receiver has closed,
310 * there's no point in hanging onto FIN_WAIT_2 socket. Just close it.
311 * Ignore fact that there were recent incoming segments.
313 if (tcp_fast_finwait2_recycle && tp->t_state == TCPS_FIN_WAIT_2 &&
314 tp->t_inpcb && tp->t_inpcb->inp_socket &&
315 (tp->t_inpcb->inp_socket->so_rcv.sb_state & SBS_CANTRCVMORE)) {
316 TCPSTAT_INC(tcps_finwait2_drops);
319 if (tp->t_state != TCPS_TIME_WAIT &&
320 ticks - tp->t_rcvtime <= TP_MAXIDLE(tp))
321 callout_reset_on(&tp->t_timers->tt_2msl,
322 TP_KEEPINTVL(tp), tcp_timer_2msl, tp,
329 if (tp != NULL && (tp->t_inpcb->inp_socket->so_options & SO_DEBUG))
330 tcp_trace(TA_USER, ostate, tp, (void *)0, (struct tcphdr *)0,
335 INP_INFO_WUNLOCK(&V_tcbinfo);
340 tcp_timer_keep(void *xtp)
342 struct tcpcb *tp = xtp;
343 struct tcptemp *t_template;
345 CURVNET_SET(tp->t_vnet);
349 ostate = tp->t_state;
351 INP_INFO_WLOCK(&V_tcbinfo);
354 * XXXRW: While this assert is in fact correct, bugs in the tcpcb
355 * tear-down mean we need it as a work-around for races between
356 * timers and tcp_discardcb().
358 * KASSERT(inp != NULL, ("tcp_timer_keep: inp == NULL"));
362 INP_INFO_WUNLOCK(&V_tcbinfo);
367 if (callout_pending(&tp->t_timers->tt_keep) ||
368 !callout_active(&tp->t_timers->tt_keep)) {
370 INP_INFO_WUNLOCK(&V_tcbinfo);
374 callout_deactivate(&tp->t_timers->tt_keep);
375 if ((inp->inp_flags & INP_DROPPED) != 0) {
377 INP_INFO_WUNLOCK(&V_tcbinfo);
382 * Keep-alive timer went off; send something
383 * or drop connection if idle for too long.
385 TCPSTAT_INC(tcps_keeptimeo);
386 if (tp->t_state < TCPS_ESTABLISHED)
388 if ((always_keepalive || inp->inp_socket->so_options & SO_KEEPALIVE) &&
389 tp->t_state <= TCPS_CLOSING) {
390 if (ticks - tp->t_rcvtime >= TP_KEEPIDLE(tp) + TP_MAXIDLE(tp))
393 * Send a packet designed to force a response
394 * if the peer is up and reachable:
395 * either an ACK if the connection is still alive,
396 * or an RST if the peer has closed the connection
397 * due to timeout or reboot.
398 * Using sequence number tp->snd_una-1
399 * causes the transmitted zero-length segment
400 * to lie outside the receive window;
401 * by the protocol spec, this requires the
402 * correspondent TCP to respond.
404 TCPSTAT_INC(tcps_keepprobe);
405 t_template = tcpip_maketemplate(inp);
407 tcp_respond(tp, t_template->tt_ipgen,
408 &t_template->tt_t, (struct mbuf *)NULL,
409 tp->rcv_nxt, tp->snd_una - 1, 0);
410 free(t_template, M_TEMP);
412 callout_reset_on(&tp->t_timers->tt_keep, TP_KEEPINTVL(tp),
413 tcp_timer_keep, tp, inp_to_cpuid(inp));
415 callout_reset_on(&tp->t_timers->tt_keep, TP_KEEPIDLE(tp),
416 tcp_timer_keep, tp, inp_to_cpuid(inp));
419 if (inp->inp_socket->so_options & SO_DEBUG)
420 tcp_trace(TA_USER, ostate, tp, (void *)0, (struct tcphdr *)0,
424 INP_INFO_WUNLOCK(&V_tcbinfo);
429 TCPSTAT_INC(tcps_keepdrops);
430 tp = tcp_drop(tp, ETIMEDOUT);
433 if (tp != NULL && (tp->t_inpcb->inp_socket->so_options & SO_DEBUG))
434 tcp_trace(TA_USER, ostate, tp, (void *)0, (struct tcphdr *)0,
438 INP_WUNLOCK(tp->t_inpcb);
439 INP_INFO_WUNLOCK(&V_tcbinfo);
444 tcp_timer_persist(void *xtp)
446 struct tcpcb *tp = xtp;
448 CURVNET_SET(tp->t_vnet);
452 ostate = tp->t_state;
454 INP_INFO_WLOCK(&V_tcbinfo);
457 * XXXRW: While this assert is in fact correct, bugs in the tcpcb
458 * tear-down mean we need it as a work-around for races between
459 * timers and tcp_discardcb().
461 * KASSERT(inp != NULL, ("tcp_timer_persist: inp == NULL"));
465 INP_INFO_WUNLOCK(&V_tcbinfo);
470 if (callout_pending(&tp->t_timers->tt_persist) ||
471 !callout_active(&tp->t_timers->tt_persist)) {
473 INP_INFO_WUNLOCK(&V_tcbinfo);
477 callout_deactivate(&tp->t_timers->tt_persist);
478 if ((inp->inp_flags & INP_DROPPED) != 0) {
480 INP_INFO_WUNLOCK(&V_tcbinfo);
485 * Persistance timer into zero window.
486 * Force a byte to be output, if possible.
488 TCPSTAT_INC(tcps_persisttimeo);
490 * Hack: if the peer is dead/unreachable, we do not
491 * time out if the window is closed. After a full
492 * backoff, drop the connection if the idle time
493 * (no responses to probes) reaches the maximum
494 * backoff that we would use if retransmitting.
496 if (tp->t_rxtshift == TCP_MAXRXTSHIFT &&
497 (ticks - tp->t_rcvtime >= tcp_maxpersistidle ||
498 ticks - tp->t_rcvtime >= TCP_REXMTVAL(tp) * tcp_totbackoff)) {
499 TCPSTAT_INC(tcps_persistdrop);
500 tp = tcp_drop(tp, ETIMEDOUT);
504 * If the user has closed the socket then drop a persisting
505 * connection after a much reduced timeout.
507 if (tp->t_state > TCPS_CLOSE_WAIT &&
508 (ticks - tp->t_rcvtime) >= TCPTV_PERSMAX) {
509 TCPSTAT_INC(tcps_persistdrop);
510 tp = tcp_drop(tp, ETIMEDOUT);
514 tp->t_flags |= TF_FORCEDATA;
515 (void) tcp_output(tp);
516 tp->t_flags &= ~TF_FORCEDATA;
520 if (tp != NULL && tp->t_inpcb->inp_socket->so_options & SO_DEBUG)
521 tcp_trace(TA_USER, ostate, tp, NULL, NULL, PRU_SLOWTIMO);
525 INP_INFO_WUNLOCK(&V_tcbinfo);
530 tcp_timer_rexmt(void * xtp)
532 struct tcpcb *tp = xtp;
533 CURVNET_SET(tp->t_vnet);
540 ostate = tp->t_state;
542 INP_INFO_RLOCK(&V_tcbinfo);
545 * XXXRW: While this assert is in fact correct, bugs in the tcpcb
546 * tear-down mean we need it as a work-around for races between
547 * timers and tcp_discardcb().
549 * KASSERT(inp != NULL, ("tcp_timer_rexmt: inp == NULL"));
553 INP_INFO_RUNLOCK(&V_tcbinfo);
558 if (callout_pending(&tp->t_timers->tt_rexmt) ||
559 !callout_active(&tp->t_timers->tt_rexmt)) {
561 INP_INFO_RUNLOCK(&V_tcbinfo);
565 callout_deactivate(&tp->t_timers->tt_rexmt);
566 if ((inp->inp_flags & INP_DROPPED) != 0) {
568 INP_INFO_RUNLOCK(&V_tcbinfo);
572 tcp_free_sackholes(tp);
574 * Retransmission timer went off. Message has not
575 * been acked within retransmit interval. Back off
576 * to a longer retransmit interval and retransmit one segment.
578 if (++tp->t_rxtshift > TCP_MAXRXTSHIFT) {
579 tp->t_rxtshift = TCP_MAXRXTSHIFT;
580 TCPSTAT_INC(tcps_timeoutdrop);
582 INP_INFO_RUNLOCK(&V_tcbinfo);
584 INP_INFO_WLOCK(&V_tcbinfo);
586 if (in_pcbrele_wlocked(inp)) {
587 INP_INFO_WUNLOCK(&V_tcbinfo);
591 if (inp->inp_flags & INP_DROPPED) {
593 INP_INFO_WUNLOCK(&V_tcbinfo);
598 tp = tcp_drop(tp, tp->t_softerror ?
599 tp->t_softerror : ETIMEDOUT);
603 INP_INFO_RUNLOCK(&V_tcbinfo);
605 if (tp->t_state == TCPS_SYN_SENT) {
607 * If the SYN was retransmitted, indicate CWND to be
608 * limited to 1 segment in cc_conn_init().
611 } else if (tp->t_rxtshift == 1) {
613 * first retransmit; record ssthresh and cwnd so they can
614 * be recovered if this turns out to be a "bad" retransmit.
615 * A retransmit is considered "bad" if an ACK for this
616 * segment is received within RTT/2 interval; the assumption
617 * here is that the ACK was already in flight. See
618 * "On Estimating End-to-End Network Path Properties" by
619 * Allman and Paxson for more details.
621 tp->snd_cwnd_prev = tp->snd_cwnd;
622 tp->snd_ssthresh_prev = tp->snd_ssthresh;
623 tp->snd_recover_prev = tp->snd_recover;
624 if (IN_FASTRECOVERY(tp->t_flags))
625 tp->t_flags |= TF_WASFRECOVERY;
627 tp->t_flags &= ~TF_WASFRECOVERY;
628 if (IN_CONGRECOVERY(tp->t_flags))
629 tp->t_flags |= TF_WASCRECOVERY;
631 tp->t_flags &= ~TF_WASCRECOVERY;
632 tp->t_badrxtwin = ticks + (tp->t_srtt >> (TCP_RTT_SHIFT + 1));
633 tp->t_flags |= TF_PREVVALID;
635 tp->t_flags &= ~TF_PREVVALID;
636 TCPSTAT_INC(tcps_rexmttimeo);
637 if (tp->t_state == TCPS_SYN_SENT)
638 rexmt = TCPTV_RTOBASE * tcp_syn_backoff[tp->t_rxtshift];
640 rexmt = TCP_REXMTVAL(tp) * tcp_backoff[tp->t_rxtshift];
641 TCPT_RANGESET(tp->t_rxtcur, rexmt,
642 tp->t_rttmin, TCPTV_REXMTMAX);
644 * Disable RFC1323 and SACK if we haven't got any response to
645 * our third SYN to work-around some broken terminal servers
646 * (most of which have hopefully been retired) that have bad VJ
647 * header compression code which trashes TCP segments containing
648 * unknown-to-them TCP options.
650 if (tcp_rexmit_drop_options && (tp->t_state == TCPS_SYN_SENT) &&
651 (tp->t_rxtshift == 3))
652 tp->t_flags &= ~(TF_REQ_SCALE|TF_REQ_TSTMP|TF_SACK_PERMIT);
654 * If we backed off this far, our srtt estimate is probably bogus.
655 * Clobber it so we'll take the next rtt measurement as our srtt;
656 * move the current srtt into rttvar to keep the current
657 * retransmit times until then.
659 if (tp->t_rxtshift > TCP_MAXRXTSHIFT / 4) {
661 if ((tp->t_inpcb->inp_vflag & INP_IPV6) != 0)
662 in6_losing(tp->t_inpcb);
664 tp->t_rttvar += (tp->t_srtt >> TCP_RTT_SHIFT);
667 tp->snd_nxt = tp->snd_una;
668 tp->snd_recover = tp->snd_max;
670 * Force a segment to be sent.
672 tp->t_flags |= TF_ACKNOW;
674 * If timing a segment in this window, stop the timer.
678 cc_cong_signal(tp, NULL, CC_RTO);
680 (void) tcp_output(tp);
684 if (tp != NULL && (tp->t_inpcb->inp_socket->so_options & SO_DEBUG))
685 tcp_trace(TA_USER, ostate, tp, (void *)0, (struct tcphdr *)0,
691 INP_INFO_WUNLOCK(&V_tcbinfo);
696 tcp_timer_activate(struct tcpcb *tp, int timer_type, u_int delta)
698 struct callout *t_callout;
700 struct inpcb *inp = tp->t_inpcb;
701 int cpu = inp_to_cpuid(inp);
704 if (tp->t_flags & TF_TOE)
708 switch (timer_type) {
710 t_callout = &tp->t_timers->tt_delack;
711 f_callout = tcp_timer_delack;
714 t_callout = &tp->t_timers->tt_rexmt;
715 f_callout = tcp_timer_rexmt;
718 t_callout = &tp->t_timers->tt_persist;
719 f_callout = tcp_timer_persist;
722 t_callout = &tp->t_timers->tt_keep;
723 f_callout = tcp_timer_keep;
726 t_callout = &tp->t_timers->tt_2msl;
727 f_callout = tcp_timer_2msl;
730 panic("bad timer_type");
733 callout_stop(t_callout);
735 callout_reset_on(t_callout, delta, f_callout, tp, cpu);
740 tcp_timer_active(struct tcpcb *tp, int timer_type)
742 struct callout *t_callout;
744 switch (timer_type) {
746 t_callout = &tp->t_timers->tt_delack;
749 t_callout = &tp->t_timers->tt_rexmt;
752 t_callout = &tp->t_timers->tt_persist;
755 t_callout = &tp->t_timers->tt_keep;
758 t_callout = &tp->t_timers->tt_2msl;
761 panic("bad timer_type");
763 return callout_active(t_callout);
766 #define ticks_to_msecs(t) (1000*(t) / hz)
769 tcp_timer_to_xtimer(struct tcpcb *tp, struct tcp_timer *timer,
770 struct xtcp_timer *xtimer)
774 bzero(xtimer, sizeof(*xtimer));
777 now = getsbinuptime();
778 if (callout_active(&timer->tt_delack))
779 xtimer->tt_delack = (timer->tt_delack.c_time - now) / SBT_1MS;
780 if (callout_active(&timer->tt_rexmt))
781 xtimer->tt_rexmt = (timer->tt_rexmt.c_time - now) / SBT_1MS;
782 if (callout_active(&timer->tt_persist))
783 xtimer->tt_persist = (timer->tt_persist.c_time - now) / SBT_1MS;
784 if (callout_active(&timer->tt_keep))
785 xtimer->tt_keep = (timer->tt_keep.c_time - now) / SBT_1MS;
786 if (callout_active(&timer->tt_2msl))
787 xtimer->tt_2msl = (timer->tt_2msl.c_time - now) / SBT_1MS;
788 xtimer->t_rcvtime = ticks_to_msecs(ticks - tp->t_rcvtime);