1c398230bSWarner Losh /*- 2df8bae1dSRodney W. Grimes * Copyright (c) 1982, 1986, 1993 3df8bae1dSRodney W. Grimes * The Regents of the University of California. All rights reserved. 4df8bae1dSRodney W. Grimes * 5df8bae1dSRodney W. Grimes * Redistribution and use in source and binary forms, with or without 6df8bae1dSRodney W. Grimes * modification, are permitted provided that the following conditions 7df8bae1dSRodney W. Grimes * are met: 8df8bae1dSRodney W. Grimes * 1. Redistributions of source code must retain the above copyright 9df8bae1dSRodney W. Grimes * notice, this list of conditions and the following disclaimer. 10df8bae1dSRodney W. Grimes * 2. Redistributions in binary form must reproduce the above copyright 11df8bae1dSRodney W. Grimes * notice, this list of conditions and the following disclaimer in the 12df8bae1dSRodney W. Grimes * documentation and/or other materials provided with the distribution. 13df8bae1dSRodney W. Grimes * 4. Neither the name of the University nor the names of its contributors 14df8bae1dSRodney W. Grimes * may be used to endorse or promote products derived from this software 15df8bae1dSRodney W. Grimes * without specific prior written permission. 16df8bae1dSRodney W. Grimes * 17df8bae1dSRodney W. Grimes * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 18df8bae1dSRodney W. Grimes * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19df8bae1dSRodney W. Grimes * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20df8bae1dSRodney W. Grimes * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 21df8bae1dSRodney W. Grimes * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 22df8bae1dSRodney W. Grimes * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 23df8bae1dSRodney W. Grimes * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 24df8bae1dSRodney W. Grimes * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 25df8bae1dSRodney W. Grimes * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 26df8bae1dSRodney W. Grimes * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 27df8bae1dSRodney W. Grimes * SUCH DAMAGE. 28df8bae1dSRodney W. Grimes * 29df8bae1dSRodney W. Grimes * @(#)tcp_timer.h 8.1 (Berkeley) 6/10/93 30c3aac50fSPeter Wemm * $FreeBSD$ 31df8bae1dSRodney W. Grimes */ 32df8bae1dSRodney W. Grimes 33707f139eSPaul Richards #ifndef _NETINET_TCP_TIMER_H_ 34707f139eSPaul Richards #define _NETINET_TCP_TIMER_H_ 35707f139eSPaul Richards 36df8bae1dSRodney W. Grimes /* 37df8bae1dSRodney W. Grimes * The TCPT_REXMT timer is used to force retransmissions. 38df8bae1dSRodney W. Grimes * The TCP has the TCPT_REXMT timer set whenever segments 39df8bae1dSRodney W. Grimes * have been sent for which ACKs are expected but not yet 40df8bae1dSRodney W. Grimes * received. If an ACK is received which advances tp->snd_una, 41df8bae1dSRodney W. Grimes * then the retransmit timer is cleared (if there are no more 42df8bae1dSRodney W. Grimes * outstanding segments) or reset to the base value (if there 43df8bae1dSRodney W. Grimes * are more ACKs expected). Whenever the retransmit timer goes off, 44df8bae1dSRodney W. Grimes * we retransmit one unacknowledged segment, and do a backoff 45df8bae1dSRodney W. Grimes * on the retransmit timer. 46df8bae1dSRodney W. Grimes * 47df8bae1dSRodney W. Grimes * The TCPT_PERSIST timer is used to keep window size information 48df8bae1dSRodney W. Grimes * flowing even if the window goes shut. If all previous transmissions 49df8bae1dSRodney W. Grimes * have been acknowledged (so that there are no retransmissions in progress), 50df8bae1dSRodney W. Grimes * and the window is too small to bother sending anything, then we start 51df8bae1dSRodney W. Grimes * the TCPT_PERSIST timer. When it expires, if the window is nonzero, 52df8bae1dSRodney W. Grimes * we go to transmit state. Otherwise, at intervals send a single byte 53df8bae1dSRodney W. Grimes * into the peer's window to force him to update our window information. 54df8bae1dSRodney W. Grimes * We do this at most as often as TCPT_PERSMIN time intervals, 55df8bae1dSRodney W. Grimes * but no more frequently than the current estimate of round-trip 56df8bae1dSRodney W. Grimes * packet time. The TCPT_PERSIST timer is cleared whenever we receive 57df8bae1dSRodney W. Grimes * a window update from the peer. 58df8bae1dSRodney W. Grimes * 59df8bae1dSRodney W. Grimes * The TCPT_KEEP timer is used to keep connections alive. If an 60df8bae1dSRodney W. Grimes * connection is idle (no segments received) for TCPTV_KEEP_INIT amount of time, 61df8bae1dSRodney W. Grimes * but not yet established, then we drop the connection. Once the connection 62df8bae1dSRodney W. Grimes * is established, if the connection is idle for TCPTV_KEEP_IDLE time 63df8bae1dSRodney W. Grimes * (and keepalives have been enabled on the socket), we begin to probe 64df8bae1dSRodney W. Grimes * the connection. We force the peer to send us a segment by sending: 65df8bae1dSRodney W. Grimes * <SEQ=SND.UNA-1><ACK=RCV.NXT><CTL=ACK> 66df8bae1dSRodney W. Grimes * This segment is (deliberately) outside the window, and should elicit 67df8bae1dSRodney W. Grimes * an ack segment in response from the peer. If, despite the TCPT_KEEP 68df8bae1dSRodney W. Grimes * initiated segments we cannot elicit a response from a peer in TCPT_MAXIDLE 69df8bae1dSRodney W. Grimes * amount of time probing, then we drop the connection. 70df8bae1dSRodney W. Grimes */ 71df8bae1dSRodney W. Grimes 72df8bae1dSRodney W. Grimes /* 73df8bae1dSRodney W. Grimes * Time constants. 74df8bae1dSRodney W. Grimes */ 759b8b58e0SJonathan Lemon #define TCPTV_MSL ( 30*hz) /* max seg lifetime (hah!) */ 76df8bae1dSRodney W. Grimes #define TCPTV_SRTTBASE 0 /* base roundtrip time; 77df8bae1dSRodney W. Grimes if 0, no idea yet */ 789b8b58e0SJonathan Lemon #define TCPTV_RTOBASE ( 3*hz) /* assumed RTO if no info */ 799b8b58e0SJonathan Lemon #define TCPTV_SRTTDFLT ( 3*hz) /* assumed RTT if no info */ 80df8bae1dSRodney W. Grimes 819b8b58e0SJonathan Lemon #define TCPTV_PERSMIN ( 5*hz) /* retransmit persistence */ 829b8b58e0SJonathan Lemon #define TCPTV_PERSMAX ( 60*hz) /* maximum persist interval */ 83df8bae1dSRodney W. Grimes 849b8b58e0SJonathan Lemon #define TCPTV_KEEP_INIT ( 75*hz) /* initial connect keepalive */ 859b8b58e0SJonathan Lemon #define TCPTV_KEEP_IDLE (120*60*hz) /* dflt time before probing */ 869b8b58e0SJonathan Lemon #define TCPTV_KEEPINTVL ( 75*hz) /* default probe interval */ 87df8bae1dSRodney W. Grimes #define TCPTV_KEEPCNT 8 /* max probes before drop */ 88df8bae1dSRodney W. Grimes 8922fd54d4SMatthew Dillon /* 9022fd54d4SMatthew Dillon * Minimum retransmit timer is 3 ticks, for algorithmic stability. 91701bec5aSMatthew Dillon * TCPT_RANGESET() will add another TCPTV_CPU_VAR to deal with 92701bec5aSMatthew Dillon * the expected worst-case processing variances by the kernels 93701bec5aSMatthew Dillon * representing the end points. Such variances do not always show 94701bec5aSMatthew Dillon * up in the srtt because the timestamp is often calculated at 95701bec5aSMatthew Dillon * the interface rather then at the TCP layer. This value is 96701bec5aSMatthew Dillon * typically 50ms. However, it is also possible that delayed 97701bec5aSMatthew Dillon * acks (typically 100ms) could create issues so we set the slop 98701bec5aSMatthew Dillon * to 200ms to try to cover it. Note that, properly speaking, 99701bec5aSMatthew Dillon * delayed-acks should not create a major issue for interactive 100701bec5aSMatthew Dillon * environments which 'P'ush the last segment, at least as 101701bec5aSMatthew Dillon * long as implementations do the required 'at least one ack 102701bec5aSMatthew Dillon * for every two packets' for the non-interactive streaming case. 103701bec5aSMatthew Dillon * (maybe the RTO calculation should use 2*RTT instead of RTT 104701bec5aSMatthew Dillon * to handle the ack-every-other-packet case). 105701bec5aSMatthew Dillon * 106701bec5aSMatthew Dillon * The prior minimum of 1*hz (1 second) badly breaks throughput on any 107701bec5aSMatthew Dillon * networks faster then a modem that has minor (e.g. 1%) packet loss. 10822fd54d4SMatthew Dillon */ 10922fd54d4SMatthew Dillon #define TCPTV_MIN ( 3 ) /* minimum allowable value */ 110701bec5aSMatthew Dillon #define TCPTV_CPU_VAR ( hz/5 ) /* cpu variance allowed (200ms) */ 1119b8b58e0SJonathan Lemon #define TCPTV_REXMTMAX ( 64*hz) /* max allowable REXMT value */ 112df8bae1dSRodney W. Grimes 113eb6ad696SGarrett Wollman #define TCPTV_TWTRUNC 8 /* RTO factor to truncate TW */ 114eb6ad696SGarrett Wollman 115df8bae1dSRodney W. Grimes #define TCP_LINGERTIME 120 /* linger at most 2 minutes */ 116df8bae1dSRodney W. Grimes 117df8bae1dSRodney W. Grimes #define TCP_MAXRXTSHIFT 12 /* maximum retransmits */ 118df8bae1dSRodney W. Grimes 119c0a929b4SJonathan Lemon #define TCPTV_DELACK (hz / PR_FASTHZ / 2) /* 100ms timeout */ 1209b8b58e0SJonathan Lemon 121df8bae1dSRodney W. Grimes #ifdef TCPTIMERS 122e88894d3SAlfred Perlstein static const char *tcptimers[] = 123df8bae1dSRodney W. Grimes { "REXMT", "PERSIST", "KEEP", "2MSL" }; 124df8bae1dSRodney W. Grimes #endif 125df8bae1dSRodney W. Grimes 126df8bae1dSRodney W. Grimes /* 127df8bae1dSRodney W. Grimes * Force a time value to be in a certain range. 128df8bae1dSRodney W. Grimes */ 1299b8b58e0SJonathan Lemon #define TCPT_RANGESET(tv, value, tvmin, tvmax) do { \ 130701bec5aSMatthew Dillon (tv) = (value) + tcp_rexmit_slop; \ 13126f9a767SRodney W. Grimes if ((u_long)(tv) < (u_long)(tvmin)) \ 132df8bae1dSRodney W. Grimes (tv) = (tvmin); \ 13326f9a767SRodney W. Grimes else if ((u_long)(tv) > (u_long)(tvmax)) \ 134df8bae1dSRodney W. Grimes (tv) = (tvmax); \ 1359b8b58e0SJonathan Lemon } while(0) 1369b8b58e0SJonathan Lemon 137664a31e4SPeter Wemm #ifdef _KERNEL 1387b40aa32SPaul Traina extern int tcp_keepinit; /* time to establish connection */ 139df8bae1dSRodney W. Grimes extern int tcp_keepidle; /* time before keepalive probes begin */ 1409b8b58e0SJonathan Lemon extern int tcp_keepintvl; /* time between keepalive probes */ 141df8bae1dSRodney W. Grimes extern int tcp_maxidle; /* time to drop after starting probes */ 1429b8b58e0SJonathan Lemon extern int tcp_delacktime; /* time before sending a delayed ACK */ 1439b8b58e0SJonathan Lemon extern int tcp_maxpersistidle; 144701bec5aSMatthew Dillon extern int tcp_rexmit_min; 145701bec5aSMatthew Dillon extern int tcp_rexmit_slop; 1469b8b58e0SJonathan Lemon extern int tcp_msl; 147df8bae1dSRodney W. Grimes extern int tcp_ttl; /* time to live for TCP segs */ 148df8bae1dSRodney W. Grimes extern int tcp_backoff[]; 149707f139eSPaul Richards 150607b0b0cSJonathan Lemon struct tcptw; 151607b0b0cSJonathan Lemon 152607b0b0cSJonathan Lemon void tcp_timer_init(void); 1534d77a549SAlfred Perlstein void tcp_timer_2msl(void *xtp); 154607b0b0cSJonathan Lemon struct tcptw * 155607b0b0cSJonathan Lemon tcp_timer_2msl_tw(int _reuse); /* XXX temporary */ 156607b0b0cSJonathan Lemon void tcp_timer_2msl_reset(struct tcptw *_tw, int _timeo); 157607b0b0cSJonathan Lemon void tcp_timer_2msl_stop(struct tcptw *_tw); 1584d77a549SAlfred Perlstein void tcp_timer_keep(void *xtp); 1594d77a549SAlfred Perlstein void tcp_timer_persist(void *xtp); 1604d77a549SAlfred Perlstein void tcp_timer_rexmt(void *xtp); 1614d77a549SAlfred Perlstein void tcp_timer_delack(void *xtp); 1629b8b58e0SJonathan Lemon 163664a31e4SPeter Wemm #endif /* _KERNEL */ 1649b8b58e0SJonathan Lemon 1659b8b58e0SJonathan Lemon #endif /* !_NETINET_TCP_TIMER_H_ */ 166