1139823Simp/*- 21541Srgrimes * Copyright (c) 1982, 1986, 1993 31541Srgrimes * The Regents of the University of California. All rights reserved. 41541Srgrimes * 51541Srgrimes * Redistribution and use in source and binary forms, with or without 61541Srgrimes * modification, are permitted provided that the following conditions 71541Srgrimes * are met: 81541Srgrimes * 1. Redistributions of source code must retain the above copyright 91541Srgrimes * notice, this list of conditions and the following disclaimer. 101541Srgrimes * 2. Redistributions in binary form must reproduce the above copyright 111541Srgrimes * notice, this list of conditions and the following disclaimer in the 121541Srgrimes * documentation and/or other materials provided with the distribution. 131541Srgrimes * 4. Neither the name of the University nor the names of its contributors 141541Srgrimes * may be used to endorse or promote products derived from this software 151541Srgrimes * without specific prior written permission. 161541Srgrimes * 171541Srgrimes * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 181541Srgrimes * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 191541Srgrimes * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 201541Srgrimes * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 211541Srgrimes * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 221541Srgrimes * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 231541Srgrimes * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 241541Srgrimes * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 251541Srgrimes * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 261541Srgrimes * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 271541Srgrimes * SUCH DAMAGE. 281541Srgrimes * 291541Srgrimes * @(#)tcp_timer.h 8.1 (Berkeley) 6/10/93 3050477Speter * $FreeBSD$ 311541Srgrimes */ 321541Srgrimes 332169Spaul#ifndef _NETINET_TCP_TIMER_H_ 342169Spaul#define _NETINET_TCP_TIMER_H_ 352169Spaul 361541Srgrimes/* 371541Srgrimes * The TCPT_REXMT timer is used to force retransmissions. 381541Srgrimes * The TCP has the TCPT_REXMT timer set whenever segments 391541Srgrimes * have been sent for which ACKs are expected but not yet 401541Srgrimes * received. If an ACK is received which advances tp->snd_una, 411541Srgrimes * then the retransmit timer is cleared (if there are no more 421541Srgrimes * outstanding segments) or reset to the base value (if there 431541Srgrimes * are more ACKs expected). Whenever the retransmit timer goes off, 441541Srgrimes * we retransmit one unacknowledged segment, and do a backoff 451541Srgrimes * on the retransmit timer. 461541Srgrimes * 471541Srgrimes * The TCPT_PERSIST timer is used to keep window size information 481541Srgrimes * flowing even if the window goes shut. If all previous transmissions 491541Srgrimes * have been acknowledged (so that there are no retransmissions in progress), 501541Srgrimes * and the window is too small to bother sending anything, then we start 511541Srgrimes * the TCPT_PERSIST timer. When it expires, if the window is nonzero, 521541Srgrimes * we go to transmit state. Otherwise, at intervals send a single byte 531541Srgrimes * into the peer's window to force him to update our window information. 541541Srgrimes * We do this at most as often as TCPT_PERSMIN time intervals, 551541Srgrimes * but no more frequently than the current estimate of round-trip 561541Srgrimes * packet time. The TCPT_PERSIST timer is cleared whenever we receive 571541Srgrimes * a window update from the peer. 581541Srgrimes * 591541Srgrimes * The TCPT_KEEP timer is used to keep connections alive. If an 601541Srgrimes * connection is idle (no segments received) for TCPTV_KEEP_INIT amount of time, 611541Srgrimes * but not yet established, then we drop the connection. Once the connection 621541Srgrimes * is established, if the connection is idle for TCPTV_KEEP_IDLE time 631541Srgrimes * (and keepalives have been enabled on the socket), we begin to probe 641541Srgrimes * the connection. We force the peer to send us a segment by sending: 651541Srgrimes * <SEQ=SND.UNA-1><ACK=RCV.NXT><CTL=ACK> 661541Srgrimes * This segment is (deliberately) outside the window, and should elicit 671541Srgrimes * an ack segment in response from the peer. If, despite the TCPT_KEEP 681541Srgrimes * initiated segments we cannot elicit a response from a peer in TCPT_MAXIDLE 691541Srgrimes * amount of time probing, then we drop the connection. 701541Srgrimes */ 711541Srgrimes 721541Srgrimes/* 731541Srgrimes * Time constants. 741541Srgrimes */ 7550673Sjlemon#define TCPTV_MSL ( 30*hz) /* max seg lifetime (hah!) */ 761541Srgrimes#define TCPTV_SRTTBASE 0 /* base roundtrip time; 771541Srgrimes if 0, no idea yet */ 7850673Sjlemon#define TCPTV_RTOBASE ( 3*hz) /* assumed RTO if no info */ 7950673Sjlemon#define TCPTV_SRTTDFLT ( 3*hz) /* assumed RTT if no info */ 801541Srgrimes 8150673Sjlemon#define TCPTV_PERSMIN ( 5*hz) /* retransmit persistence */ 8250673Sjlemon#define TCPTV_PERSMAX ( 60*hz) /* maximum persist interval */ 831541Srgrimes 8450673Sjlemon#define TCPTV_KEEP_INIT ( 75*hz) /* initial connect keepalive */ 8550673Sjlemon#define TCPTV_KEEP_IDLE (120*60*hz) /* dflt time before probing */ 8650673Sjlemon#define TCPTV_KEEPINTVL ( 75*hz) /* default probe interval */ 871541Srgrimes#define TCPTV_KEEPCNT 8 /* max probes before drop */ 881541Srgrimes 89167036Smohans#define TCPTV_FINWAIT2_TIMEOUT (60*hz) /* FIN_WAIT_2 timeout if no receiver */ 90167036Smohans 91100270Sdillon/* 92100270Sdillon * Minimum retransmit timer is 3 ticks, for algorithmic stability. 93100335Sdillon * TCPT_RANGESET() will add another TCPTV_CPU_VAR to deal with 94100335Sdillon * the expected worst-case processing variances by the kernels 95100335Sdillon * representing the end points. Such variances do not always show 96100335Sdillon * up in the srtt because the timestamp is often calculated at 97100335Sdillon * the interface rather then at the TCP layer. This value is 98100335Sdillon * typically 50ms. However, it is also possible that delayed 99100335Sdillon * acks (typically 100ms) could create issues so we set the slop 100100335Sdillon * to 200ms to try to cover it. Note that, properly speaking, 101100335Sdillon * delayed-acks should not create a major issue for interactive 102133874Srwatson * environments which 'P'ush the last segment, at least as 103100335Sdillon * long as implementations do the required 'at least one ack 104100335Sdillon * for every two packets' for the non-interactive streaming case. 105100335Sdillon * (maybe the RTO calculation should use 2*RTT instead of RTT 106100335Sdillon * to handle the ack-every-other-packet case). 107100335Sdillon * 108100335Sdillon * The prior minimum of 1*hz (1 second) badly breaks throughput on any 109100335Sdillon * networks faster then a modem that has minor (e.g. 1%) packet loss. 110100270Sdillon */ 111171677Speter#define TCPTV_MIN ( hz/33 ) /* minimum allowable value */ 112100335Sdillon#define TCPTV_CPU_VAR ( hz/5 ) /* cpu variance allowed (200ms) */ 11350673Sjlemon#define TCPTV_REXMTMAX ( 64*hz) /* max allowable REXMT value */ 1141541Srgrimes 1156247Swollman#define TCPTV_TWTRUNC 8 /* RTO factor to truncate TW */ 1166247Swollman 1171541Srgrimes#define TCP_LINGERTIME 120 /* linger at most 2 minutes */ 1181541Srgrimes 1191541Srgrimes#define TCP_MAXRXTSHIFT 12 /* maximum retransmits */ 1201541Srgrimes 121242308Sandre#define TCPTV_DELACK ( hz/10 ) /* 100ms timeout */ 12250673Sjlemon 1231541Srgrimes#ifdef TCPTIMERS 124101975Salfredstatic const char *tcptimers[] = 125243621Sandre { "REXMT", "PERSIST", "KEEP", "2MSL", "DELACK" }; 1261541Srgrimes#endif 1271541Srgrimes 128168621Sru/* 129168621Sru * Force a time value to be in a certain range. 130168621Sru */ 131168621Sru#define TCPT_RANGESET(tv, value, tvmin, tvmax) do { \ 132168621Sru (tv) = (value) + tcp_rexmit_slop; \ 133168621Sru if ((u_long)(tv) < (u_long)(tvmin)) \ 134168621Sru (tv) = (tvmin); \ 135168621Sru if ((u_long)(tv) > (u_long)(tvmax)) \ 136168621Sru (tv) = (tvmax); \ 137168621Sru} while(0) 138168621Sru 139168621Sru#ifdef _KERNEL 140168621Sru 141197244Ssilbystruct xtcp_timer; 142197244Ssilby 143172309Ssilbystruct tcp_timer { 144172309Ssilby struct callout tt_rexmt; /* retransmit timer */ 145172309Ssilby struct callout tt_persist; /* retransmit persistence */ 146172309Ssilby struct callout tt_keep; /* keepalive */ 147172309Ssilby struct callout tt_2msl; /* 2*msl TIME_WAIT timer */ 148172309Ssilby struct callout tt_delack; /* delayed ACK timer */ 149172309Ssilby}; 150168615Sandre#define TT_DELACK 0x01 151168615Sandre#define TT_REXMT 0x02 152168615Sandre#define TT_PERSIST 0x04 153168615Sandre#define TT_KEEP 0x08 154168615Sandre#define TT_2MSL 0x10 155168615Sandre 156231025Sglebius#define TP_KEEPINIT(tp) ((tp)->t_keepinit ? (tp)->t_keepinit : tcp_keepinit) 157231025Sglebius#define TP_KEEPIDLE(tp) ((tp)->t_keepidle ? (tp)->t_keepidle : tcp_keepidle) 158231025Sglebius#define TP_KEEPINTVL(tp) ((tp)->t_keepintvl ? (tp)->t_keepintvl : tcp_keepintvl) 159231025Sglebius#define TP_KEEPCNT(tp) ((tp)->t_keepcnt ? (tp)->t_keepcnt : tcp_keepcnt) 160231025Sglebius#define TP_MAXIDLE(tp) (TP_KEEPCNT(tp) * TP_KEEPINTVL(tp)) 161231025Sglebius 16218280Spstextern int tcp_keepinit; /* time to establish connection */ 1631541Srgrimesextern int tcp_keepidle; /* time before keepalive probes begin */ 16450673Sjlemonextern int tcp_keepintvl; /* time between keepalive probes */ 165231025Sglebiusextern int tcp_keepcnt; /* number of keepalives */ 16650673Sjlemonextern int tcp_delacktime; /* time before sending a delayed ACK */ 16750673Sjlemonextern int tcp_maxpersistidle; 168100335Sdillonextern int tcp_rexmit_min; 169100335Sdillonextern int tcp_rexmit_slop; 17050673Sjlemonextern int tcp_msl; 1711541Srgrimesextern int tcp_ttl; /* time to live for TCP segs */ 1721541Srgrimesextern int tcp_backoff[]; 173242261Sandreextern int tcp_syn_backoff[]; 1742169Spaul 175167036Smohansextern int tcp_finwait2_timeout; 176167036Smohansextern int tcp_fast_finwait2_recycle; 177167036Smohans 178112009Sjlemonvoid tcp_timer_init(void); 179172074Srwatsonvoid tcp_timer_2msl(void *xtp); 180169608Sandrestruct tcptw * 181169608Sandre tcp_tw_2msl_scan(int _reuse); /* XXX temporary */ 182172074Srwatsonvoid tcp_timer_keep(void *xtp); 183172074Srwatsonvoid tcp_timer_persist(void *xtp); 184172074Srwatsonvoid tcp_timer_rexmt(void *xtp); 185172074Srwatsonvoid tcp_timer_delack(void *xtp); 186197244Ssilbyvoid tcp_timer_to_xtimer(struct tcpcb *tp, struct tcp_timer *timer, 187197244Ssilby struct xtcp_timer *xtimer); 18850673Sjlemon 18955205Speter#endif /* _KERNEL */ 19050673Sjlemon 19150673Sjlemon#endif /* !_NETINET_TCP_TIMER_H_ */ 192