1*a9643ea8Slogwang /*- 2*a9643ea8Slogwang * Copyright (c) 1982, 1986, 1993 3*a9643ea8Slogwang * The Regents of the University of California. All rights reserved. 4*a9643ea8Slogwang * 5*a9643ea8Slogwang * Redistribution and use in source and binary forms, with or without 6*a9643ea8Slogwang * modification, are permitted provided that the following conditions 7*a9643ea8Slogwang * are met: 8*a9643ea8Slogwang * 1. Redistributions of source code must retain the above copyright 9*a9643ea8Slogwang * notice, this list of conditions and the following disclaimer. 10*a9643ea8Slogwang * 2. Redistributions in binary form must reproduce the above copyright 11*a9643ea8Slogwang * notice, this list of conditions and the following disclaimer in the 12*a9643ea8Slogwang * documentation and/or other materials provided with the distribution. 13*a9643ea8Slogwang * 4. Neither the name of the University nor the names of its contributors 14*a9643ea8Slogwang * may be used to endorse or promote products derived from this software 15*a9643ea8Slogwang * without specific prior written permission. 16*a9643ea8Slogwang * 17*a9643ea8Slogwang * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 18*a9643ea8Slogwang * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19*a9643ea8Slogwang * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20*a9643ea8Slogwang * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 21*a9643ea8Slogwang * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 22*a9643ea8Slogwang * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 23*a9643ea8Slogwang * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 24*a9643ea8Slogwang * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 25*a9643ea8Slogwang * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 26*a9643ea8Slogwang * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 27*a9643ea8Slogwang * SUCH DAMAGE. 28*a9643ea8Slogwang * 29*a9643ea8Slogwang * @(#)tcp_timer.h 8.1 (Berkeley) 6/10/93 30*a9643ea8Slogwang * $FreeBSD$ 31*a9643ea8Slogwang */ 32*a9643ea8Slogwang 33*a9643ea8Slogwang #ifndef _NETINET_TCP_TIMER_H_ 34*a9643ea8Slogwang #define _NETINET_TCP_TIMER_H_ 35*a9643ea8Slogwang 36*a9643ea8Slogwang /* 37*a9643ea8Slogwang * The TCPT_REXMT timer is used to force retransmissions. 38*a9643ea8Slogwang * The TCP has the TCPT_REXMT timer set whenever segments 39*a9643ea8Slogwang * have been sent for which ACKs are expected but not yet 40*a9643ea8Slogwang * received. If an ACK is received which advances tp->snd_una, 41*a9643ea8Slogwang * then the retransmit timer is cleared (if there are no more 42*a9643ea8Slogwang * outstanding segments) or reset to the base value (if there 43*a9643ea8Slogwang * are more ACKs expected). Whenever the retransmit timer goes off, 44*a9643ea8Slogwang * we retransmit one unacknowledged segment, and do a backoff 45*a9643ea8Slogwang * on the retransmit timer. 46*a9643ea8Slogwang * 47*a9643ea8Slogwang * The TCPT_PERSIST timer is used to keep window size information 48*a9643ea8Slogwang * flowing even if the window goes shut. If all previous transmissions 49*a9643ea8Slogwang * have been acknowledged (so that there are no retransmissions in progress), 50*a9643ea8Slogwang * and the window is too small to bother sending anything, then we start 51*a9643ea8Slogwang * the TCPT_PERSIST timer. When it expires, if the window is nonzero, 52*a9643ea8Slogwang * we go to transmit state. Otherwise, at intervals send a single byte 53*a9643ea8Slogwang * into the peer's window to force him to update our window information. 54*a9643ea8Slogwang * We do this at most as often as TCPT_PERSMIN time intervals, 55*a9643ea8Slogwang * but no more frequently than the current estimate of round-trip 56*a9643ea8Slogwang * packet time. The TCPT_PERSIST timer is cleared whenever we receive 57*a9643ea8Slogwang * a window update from the peer. 58*a9643ea8Slogwang * 59*a9643ea8Slogwang * The TCPT_KEEP timer is used to keep connections alive. If an 60*a9643ea8Slogwang * connection is idle (no segments received) for TCPTV_KEEP_INIT amount of time, 61*a9643ea8Slogwang * but not yet established, then we drop the connection. Once the connection 62*a9643ea8Slogwang * is established, if the connection is idle for TCPTV_KEEP_IDLE time 63*a9643ea8Slogwang * (and keepalives have been enabled on the socket), we begin to probe 64*a9643ea8Slogwang * the connection. We force the peer to send us a segment by sending: 65*a9643ea8Slogwang * <SEQ=SND.UNA-1><ACK=RCV.NXT><CTL=ACK> 66*a9643ea8Slogwang * This segment is (deliberately) outside the window, and should elicit 67*a9643ea8Slogwang * an ack segment in response from the peer. If, despite the TCPT_KEEP 68*a9643ea8Slogwang * initiated segments we cannot elicit a response from a peer in TCPT_MAXIDLE 69*a9643ea8Slogwang * amount of time probing, then we drop the connection. 70*a9643ea8Slogwang */ 71*a9643ea8Slogwang 72*a9643ea8Slogwang /* 73*a9643ea8Slogwang * Time constants. 74*a9643ea8Slogwang */ 75*a9643ea8Slogwang #define TCPTV_MSL ( 30*hz) /* max seg lifetime (hah!) */ 76*a9643ea8Slogwang #define TCPTV_SRTTBASE 0 /* base roundtrip time; 77*a9643ea8Slogwang if 0, no idea yet */ 78*a9643ea8Slogwang #define TCPTV_RTOBASE ( 3*hz) /* assumed RTO if no info */ 79*a9643ea8Slogwang 80*a9643ea8Slogwang #define TCPTV_PERSMIN ( 5*hz) /* minimum persist interval */ 81*a9643ea8Slogwang #define TCPTV_PERSMAX ( 60*hz) /* maximum persist interval */ 82*a9643ea8Slogwang 83*a9643ea8Slogwang #define TCPTV_KEEP_INIT ( 75*hz) /* initial connect keepalive */ 84*a9643ea8Slogwang #define TCPTV_KEEP_IDLE (120*60*hz) /* dflt time before probing */ 85*a9643ea8Slogwang #define TCPTV_KEEPINTVL ( 75*hz) /* default probe interval */ 86*a9643ea8Slogwang #define TCPTV_KEEPCNT 8 /* max probes before drop */ 87*a9643ea8Slogwang 88*a9643ea8Slogwang #define TCPTV_FINWAIT2_TIMEOUT (60*hz) /* FIN_WAIT_2 timeout if no receiver */ 89*a9643ea8Slogwang 90*a9643ea8Slogwang /* 91*a9643ea8Slogwang * Minimum retransmit timer is 3 ticks, for algorithmic stability. 92*a9643ea8Slogwang * TCPT_RANGESET() will add another TCPTV_CPU_VAR to deal with 93*a9643ea8Slogwang * the expected worst-case processing variances by the kernels 94*a9643ea8Slogwang * representing the end points. Such variances do not always show 95*a9643ea8Slogwang * up in the srtt because the timestamp is often calculated at 96*a9643ea8Slogwang * the interface rather then at the TCP layer. This value is 97*a9643ea8Slogwang * typically 50ms. However, it is also possible that delayed 98*a9643ea8Slogwang * acks (typically 100ms) could create issues so we set the slop 99*a9643ea8Slogwang * to 200ms to try to cover it. Note that, properly speaking, 100*a9643ea8Slogwang * delayed-acks should not create a major issue for interactive 101*a9643ea8Slogwang * environments which 'P'ush the last segment, at least as 102*a9643ea8Slogwang * long as implementations do the required 'at least one ack 103*a9643ea8Slogwang * for every two packets' for the non-interactive streaming case. 104*a9643ea8Slogwang * (maybe the RTO calculation should use 2*RTT instead of RTT 105*a9643ea8Slogwang * to handle the ack-every-other-packet case). 106*a9643ea8Slogwang * 107*a9643ea8Slogwang * The prior minimum of 1*hz (1 second) badly breaks throughput on any 108*a9643ea8Slogwang * networks faster then a modem that has minor (e.g. 1%) packet loss. 109*a9643ea8Slogwang */ 110*a9643ea8Slogwang #define TCPTV_MIN ( hz/33 ) /* minimum allowable value */ 111*a9643ea8Slogwang #define TCPTV_CPU_VAR ( hz/5 ) /* cpu variance allowed (200ms) */ 112*a9643ea8Slogwang #define TCPTV_REXMTMAX ( 64*hz) /* max allowable REXMT value */ 113*a9643ea8Slogwang 114*a9643ea8Slogwang #define TCPTV_TWTRUNC 8 /* RTO factor to truncate TW */ 115*a9643ea8Slogwang 116*a9643ea8Slogwang #define TCP_LINGERTIME 120 /* linger at most 2 minutes */ 117*a9643ea8Slogwang 118*a9643ea8Slogwang #define TCP_MAXRXTSHIFT 12 /* maximum retransmits */ 119*a9643ea8Slogwang 120*a9643ea8Slogwang #define TCPTV_DELACK ( hz/10 ) /* 100ms timeout */ 121*a9643ea8Slogwang 122*a9643ea8Slogwang #ifdef TCPTIMERS 123*a9643ea8Slogwang static const char *tcptimers[] = 124*a9643ea8Slogwang { "REXMT", "PERSIST", "KEEP", "2MSL", "DELACK" }; 125*a9643ea8Slogwang #endif 126*a9643ea8Slogwang 127*a9643ea8Slogwang /* 128*a9643ea8Slogwang * Force a time value to be in a certain range. 129*a9643ea8Slogwang */ 130*a9643ea8Slogwang #define TCPT_RANGESET(tv, value, tvmin, tvmax) do { \ 131*a9643ea8Slogwang (tv) = (value) + tcp_rexmit_slop; \ 132*a9643ea8Slogwang if ((u_long)(tv) < (u_long)(tvmin)) \ 133*a9643ea8Slogwang (tv) = (tvmin); \ 134*a9643ea8Slogwang if ((u_long)(tv) > (u_long)(tvmax)) \ 135*a9643ea8Slogwang (tv) = (tvmax); \ 136*a9643ea8Slogwang } while(0) 137*a9643ea8Slogwang 138*a9643ea8Slogwang #ifdef _KERNEL 139*a9643ea8Slogwang 140*a9643ea8Slogwang struct xtcp_timer; 141*a9643ea8Slogwang 142*a9643ea8Slogwang struct tcp_timer { 143*a9643ea8Slogwang struct callout tt_rexmt; /* retransmit timer */ 144*a9643ea8Slogwang struct callout tt_persist; /* retransmit persistence */ 145*a9643ea8Slogwang struct callout tt_keep; /* keepalive */ 146*a9643ea8Slogwang struct callout tt_2msl; /* 2*msl TIME_WAIT timer */ 147*a9643ea8Slogwang struct callout tt_delack; /* delayed ACK timer */ 148*a9643ea8Slogwang uint32_t tt_flags; /* Timers flags */ 149*a9643ea8Slogwang uint32_t tt_draincnt; /* Count being drained */ 150*a9643ea8Slogwang }; 151*a9643ea8Slogwang 152*a9643ea8Slogwang /* 153*a9643ea8Slogwang * Flags for the tt_flags field. 154*a9643ea8Slogwang */ 155*a9643ea8Slogwang #define TT_DELACK 0x0001 156*a9643ea8Slogwang #define TT_REXMT 0x0002 157*a9643ea8Slogwang #define TT_PERSIST 0x0004 158*a9643ea8Slogwang #define TT_KEEP 0x0008 159*a9643ea8Slogwang #define TT_2MSL 0x0010 160*a9643ea8Slogwang #define TT_MASK (TT_DELACK|TT_REXMT|TT_PERSIST|TT_KEEP|TT_2MSL) 161*a9643ea8Slogwang 162*a9643ea8Slogwang #define TT_DELACK_RST 0x0100 163*a9643ea8Slogwang #define TT_REXMT_RST 0x0200 164*a9643ea8Slogwang #define TT_PERSIST_RST 0x0400 165*a9643ea8Slogwang #define TT_KEEP_RST 0x0800 166*a9643ea8Slogwang #define TT_2MSL_RST 0x1000 167*a9643ea8Slogwang 168*a9643ea8Slogwang #define TT_STOPPED 0x00010000 169*a9643ea8Slogwang 170*a9643ea8Slogwang #define TP_KEEPINIT(tp) ((tp)->t_keepinit ? (tp)->t_keepinit : tcp_keepinit) 171*a9643ea8Slogwang #define TP_KEEPIDLE(tp) ((tp)->t_keepidle ? (tp)->t_keepidle : tcp_keepidle) 172*a9643ea8Slogwang #define TP_KEEPINTVL(tp) ((tp)->t_keepintvl ? (tp)->t_keepintvl : tcp_keepintvl) 173*a9643ea8Slogwang #define TP_KEEPCNT(tp) ((tp)->t_keepcnt ? (tp)->t_keepcnt : tcp_keepcnt) 174*a9643ea8Slogwang #define TP_MAXIDLE(tp) (TP_KEEPCNT(tp) * TP_KEEPINTVL(tp)) 175*a9643ea8Slogwang 176*a9643ea8Slogwang extern int tcp_persmin; /* minimum persist interval */ 177*a9643ea8Slogwang extern int tcp_persmax; /* maximum persist interval */ 178*a9643ea8Slogwang extern int tcp_keepinit; /* time to establish connection */ 179*a9643ea8Slogwang extern int tcp_keepidle; /* time before keepalive probes begin */ 180*a9643ea8Slogwang extern int tcp_keepintvl; /* time between keepalive probes */ 181*a9643ea8Slogwang extern int tcp_keepcnt; /* number of keepalives */ 182*a9643ea8Slogwang extern int tcp_delacktime; /* time before sending a delayed ACK */ 183*a9643ea8Slogwang extern int tcp_maxpersistidle; 184*a9643ea8Slogwang extern int tcp_rexmit_min; 185*a9643ea8Slogwang extern int tcp_rexmit_slop; 186*a9643ea8Slogwang extern int tcp_msl; 187*a9643ea8Slogwang extern int tcp_ttl; /* time to live for TCP segs */ 188*a9643ea8Slogwang extern int tcp_backoff[]; 189*a9643ea8Slogwang extern int tcp_syn_backoff[]; 190*a9643ea8Slogwang 191*a9643ea8Slogwang extern int tcp_finwait2_timeout; 192*a9643ea8Slogwang extern int tcp_fast_finwait2_recycle; 193*a9643ea8Slogwang 194*a9643ea8Slogwang void tcp_timer_init(void); 195*a9643ea8Slogwang void tcp_timer_2msl(void *xtp); 196*a9643ea8Slogwang void tcp_timer_discard(void *); 197*a9643ea8Slogwang struct tcptw * 198*a9643ea8Slogwang tcp_tw_2msl_scan(int reuse); /* XXX temporary? */ 199*a9643ea8Slogwang void tcp_timer_keep(void *xtp); 200*a9643ea8Slogwang void tcp_timer_persist(void *xtp); 201*a9643ea8Slogwang void tcp_timer_rexmt(void *xtp); 202*a9643ea8Slogwang void tcp_timer_delack(void *xtp); 203*a9643ea8Slogwang void tcp_timer_to_xtimer(struct tcpcb *tp, struct tcp_timer *timer, 204*a9643ea8Slogwang struct xtcp_timer *xtimer); 205*a9643ea8Slogwang 206*a9643ea8Slogwang #endif /* _KERNEL */ 207*a9643ea8Slogwang 208*a9643ea8Slogwang #endif /* !_NETINET_TCP_TIMER_H_ */ 209