tcp_timer.h revision 167036
196904Sgrog/*- 296904Sgrog * Copyright (c) 1982, 1986, 1993 396904Sgrog * The Regents of the University of California. All rights reserved. 496904Sgrog * 596904Sgrog * Redistribution and use in source and binary forms, with or without 696904Sgrog * modification, are permitted provided that the following conditions 796904Sgrog * are met: 896904Sgrog * 1. Redistributions of source code must retain the above copyright 996904Sgrog * notice, this list of conditions and the following disclaimer. 1096904Sgrog * 2. Redistributions in binary form must reproduce the above copyright 1196904Sgrog * notice, this list of conditions and the following disclaimer in the 1296904Sgrog * documentation and/or other materials provided with the distribution. 1396904Sgrog * 4. Neither the name of the University nor the names of its contributors 1496904Sgrog * may be used to endorse or promote products derived from this software 1596904Sgrog * without specific prior written permission. 1696904Sgrog * 1796904Sgrog * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 1896904Sgrog * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 1996904Sgrog * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 2096904Sgrog * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 2196904Sgrog * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 2296904Sgrog * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 2396904Sgrog * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 2496904Sgrog * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 2596904Sgrog * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 2696904Sgrog * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 2796904Sgrog * SUCH DAMAGE. 2896904Sgrog * 2996904Sgrog * @(#)tcp_timer.h 8.1 (Berkeley) 6/10/93 3096904Sgrog * $FreeBSD: head/sys/netinet/tcp_timer.h 167036 2007-02-26 22:25:21Z mohans $ 3196904Sgrog */ 3296904Sgrog 3396904Sgrog#ifndef _NETINET_TCP_TIMER_H_ 3496904Sgrog#define _NETINET_TCP_TIMER_H_ 3596904Sgrog 3696895Sgrog/* 3796895Sgrog * The TCPT_REXMT timer is used to force retransmissions. 3896895Sgrog * The TCP has the TCPT_REXMT timer set whenever segments 3996895Sgrog * have been sent for which ACKs are expected but not yet 4096895Sgrog * received. If an ACK is received which advances tp->snd_una, 4196895Sgrog * then the retransmit timer is cleared (if there are no more 4296895Sgrog * outstanding segments) or reset to the base value (if there 4396895Sgrog * are more ACKs expected). Whenever the retransmit timer goes off, 4496895Sgrog * we retransmit one unacknowledged segment, and do a backoff 4596895Sgrog * on the retransmit timer. 4696895Sgrog * 4796895Sgrog * The TCPT_PERSIST timer is used to keep window size information 4896895Sgrog * flowing even if the window goes shut. If all previous transmissions 4996895Sgrog * have been acknowledged (so that there are no retransmissions in progress), 5096895Sgrog * and the window is too small to bother sending anything, then we start 5196895Sgrog * the TCPT_PERSIST timer. When it expires, if the window is nonzero, 5296895Sgrog * we go to transmit state. Otherwise, at intervals send a single byte 5396895Sgrog * into the peer's window to force him to update our window information. 5496895Sgrog * We do this at most as often as TCPT_PERSMIN time intervals, 5596895Sgrog * but no more frequently than the current estimate of round-trip 5696895Sgrog * packet time. The TCPT_PERSIST timer is cleared whenever we receive 5796895Sgrog * a window update from the peer. 5896895Sgrog * 5996895Sgrog * The TCPT_KEEP timer is used to keep connections alive. If an 6096895Sgrog * connection is idle (no segments received) for TCPTV_KEEP_INIT amount of time, 6196895Sgrog * but not yet established, then we drop the connection. Once the connection 6296895Sgrog * is established, if the connection is idle for TCPTV_KEEP_IDLE time 6396895Sgrog * (and keepalives have been enabled on the socket), we begin to probe 6496895Sgrog * the connection. We force the peer to send us a segment by sending: 6596895Sgrog * <SEQ=SND.UNA-1><ACK=RCV.NXT><CTL=ACK> 6696895Sgrog * This segment is (deliberately) outside the window, and should elicit 6796895Sgrog * an ack segment in response from the peer. If, despite the TCPT_KEEP 6896895Sgrog * initiated segments we cannot elicit a response from a peer in TCPT_MAXIDLE 6996895Sgrog * amount of time probing, then we drop the connection. 7096895Sgrog */ 7196895Sgrog 7296895Sgrog/* 7396895Sgrog * Time constants. 7496895Sgrog */ 7596895Sgrog#define TCPTV_MSL ( 30*hz) /* max seg lifetime (hah!) */ 7696895Sgrog#define TCPTV_SRTTBASE 0 /* base roundtrip time; 7796895Sgrog if 0, no idea yet */ 7896895Sgrog#define TCPTV_RTOBASE ( 3*hz) /* assumed RTO if no info */ 7996895Sgrog#define TCPTV_SRTTDFLT ( 3*hz) /* assumed RTT if no info */ 8096895Sgrog 8196895Sgrog#define TCPTV_PERSMIN ( 5*hz) /* retransmit persistence */ 8296895Sgrog#define TCPTV_PERSMAX ( 60*hz) /* maximum persist interval */ 8396895Sgrog 8496895Sgrog#define TCPTV_KEEP_INIT ( 75*hz) /* initial connect keepalive */ 8596895Sgrog#define TCPTV_KEEP_IDLE (120*60*hz) /* dflt time before probing */ 8696895Sgrog#define TCPTV_KEEPINTVL ( 75*hz) /* default probe interval */ 8796895Sgrog#define TCPTV_KEEPCNT 8 /* max probes before drop */ 8896895Sgrog 8996895Sgrog#define TCPTV_INFLIGHT_RTTTHRESH (10*hz/1000) /* below which inflight 9096895Sgrog disengages, in msec */ 9196895Sgrog 9296895Sgrog#define TCPTV_FINWAIT2_TIMEOUT (60*hz) /* FIN_WAIT_2 timeout if no receiver */ 9396895Sgrog 9496895Sgrog/* 9596895Sgrog * Minimum retransmit timer is 3 ticks, for algorithmic stability. 9696895Sgrog * TCPT_RANGESET() will add another TCPTV_CPU_VAR to deal with 9796895Sgrog * the expected worst-case processing variances by the kernels 9896895Sgrog * representing the end points. Such variances do not always show 9996895Sgrog * up in the srtt because the timestamp is often calculated at 10096895Sgrog * the interface rather then at the TCP layer. This value is 10196895Sgrog * typically 50ms. However, it is also possible that delayed 10296895Sgrog * acks (typically 100ms) could create issues so we set the slop 10396895Sgrog * to 200ms to try to cover it. Note that, properly speaking, 10496895Sgrog * delayed-acks should not create a major issue for interactive 10596895Sgrog * environments which 'P'ush the last segment, at least as 10696895Sgrog * long as implementations do the required 'at least one ack 10796895Sgrog * for every two packets' for the non-interactive streaming case. 10896895Sgrog * (maybe the RTO calculation should use 2*RTT instead of RTT 10996895Sgrog * to handle the ack-every-other-packet case). 11096895Sgrog * 11196895Sgrog * The prior minimum of 1*hz (1 second) badly breaks throughput on any 11296895Sgrog * networks faster then a modem that has minor (e.g. 1%) packet loss. 11396895Sgrog */ 11496895Sgrog#define TCPTV_MIN ( 3 ) /* minimum allowable value */ 11596895Sgrog#define TCPTV_CPU_VAR ( hz/5 ) /* cpu variance allowed (200ms) */ 11696895Sgrog#define TCPTV_REXMTMAX ( 64*hz) /* max allowable REXMT value */ 11796895Sgrog 11896895Sgrog#define TCPTV_TWTRUNC 8 /* RTO factor to truncate TW */ 11996895Sgrog 12096895Sgrog#define TCP_LINGERTIME 120 /* linger at most 2 minutes */ 12196895Sgrog 12296895Sgrog#define TCP_MAXRXTSHIFT 12 /* maximum retransmits */ 12396895Sgrog 12496895Sgrog#define TCPTV_DELACK (hz / PR_FASTHZ / 2) /* 100ms timeout */ 12596895Sgrog 12696895Sgrog#ifdef TCPTIMERS 12796895Sgrogstatic const char *tcptimers[] = 12896895Sgrog { "REXMT", "PERSIST", "KEEP", "2MSL" }; 12996895Sgrog#endif 13096895Sgrog 13196895Sgrog/* 13296895Sgrog * Force a time value to be in a certain range. 13396895Sgrog */ 13496895Sgrog#define TCPT_RANGESET(tv, value, tvmin, tvmax) do { \ 13596895Sgrog (tv) = (value) + tcp_rexmit_slop; \ 13696895Sgrog if ((u_long)(tv) < (u_long)(tvmin)) \ 13796895Sgrog (tv) = (tvmin); \ 13896895Sgrog if ((u_long)(tv) > (u_long)(tvmax)) \ 13996895Sgrog (tv) = (tvmax); \ 14096895Sgrog} while(0) 14196895Sgrog 14296895Sgrog#ifdef _KERNEL 14396895Sgrogextern int tcp_keepinit; /* time to establish connection */ 14496895Sgrogextern int tcp_keepidle; /* time before keepalive probes begin */ 14596895Sgrogextern int tcp_keepintvl; /* time between keepalive probes */ 14696895Sgrogextern int tcp_maxidle; /* time to drop after starting probes */ 14796895Sgrogextern int tcp_delacktime; /* time before sending a delayed ACK */ 14896895Sgrogextern int tcp_maxpersistidle; 14996895Sgrogextern int tcp_rexmit_min; 15096895Sgrogextern int tcp_rexmit_slop; 15196895Sgrogextern int tcp_msl; 15296895Sgrogextern int tcp_ttl; /* time to live for TCP segs */ 15396895Sgrogextern int tcp_backoff[]; 15496895Sgrog 15596895Sgrogstruct tcptw; 15696895Sgrog 15796895Sgrogextern int tcp_finwait2_timeout; 15896895Sgrogextern int tcp_fast_finwait2_recycle; 15996895Sgrog 16096895Sgrogvoid tcp_timer_init(void); 16196895Sgrogvoid tcp_timer_2msl(void *xtp); 16296895Sgrogstruct tcptw * 16396895Sgrog tcp_timer_2msl_tw(int _reuse); /* XXX temporary */ 16496895Sgrogvoid tcp_timer_2msl_reset(struct tcptw *_tw, int rearm); 16596895Sgrogvoid tcp_timer_2msl_stop(struct tcptw *_tw); 16696895Sgrogvoid tcp_timer_keep(void *xtp); 16796895Sgrogvoid tcp_timer_persist(void *xtp); 16896895Sgrogvoid tcp_timer_rexmt(void *xtp); 16996895Sgrogvoid tcp_timer_delack(void *xtp); 17096895Sgrog 17196895Sgrog#endif /* _KERNEL */ 17296895Sgrog 17396895Sgrog#endif /* !_NETINET_TCP_TIMER_H_ */ 17496895Sgrog