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: stable/11/sys/netinet/tcp_timer.h 330303 2018-03-03 00:54:12Z jhb $ 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 */ 791541Srgrimes 80294840Shiren#define TCPTV_PERSMIN ( 5*hz) /* minimum persist interval */ 8150673Sjlemon#define TCPTV_PERSMAX ( 60*hz) /* maximum persist interval */ 821541Srgrimes 8350673Sjlemon#define TCPTV_KEEP_INIT ( 75*hz) /* initial connect keepalive */ 8450673Sjlemon#define TCPTV_KEEP_IDLE (120*60*hz) /* dflt time before probing */ 8550673Sjlemon#define TCPTV_KEEPINTVL ( 75*hz) /* default probe interval */ 861541Srgrimes#define TCPTV_KEEPCNT 8 /* max probes before drop */ 871541Srgrimes 88167036Smohans#define TCPTV_FINWAIT2_TIMEOUT (60*hz) /* FIN_WAIT_2 timeout if no receiver */ 89167036Smohans 90100270Sdillon/* 91100270Sdillon * Minimum retransmit timer is 3 ticks, for algorithmic stability. 92100335Sdillon * TCPT_RANGESET() will add another TCPTV_CPU_VAR to deal with 93100335Sdillon * the expected worst-case processing variances by the kernels 94100335Sdillon * representing the end points. Such variances do not always show 95100335Sdillon * up in the srtt because the timestamp is often calculated at 96100335Sdillon * the interface rather then at the TCP layer. This value is 97100335Sdillon * typically 50ms. However, it is also possible that delayed 98100335Sdillon * acks (typically 100ms) could create issues so we set the slop 99100335Sdillon * to 200ms to try to cover it. Note that, properly speaking, 100100335Sdillon * delayed-acks should not create a major issue for interactive 101133874Srwatson * environments which 'P'ush the last segment, at least as 102100335Sdillon * long as implementations do the required 'at least one ack 103100335Sdillon * for every two packets' for the non-interactive streaming case. 104100335Sdillon * (maybe the RTO calculation should use 2*RTT instead of RTT 105100335Sdillon * to handle the ack-every-other-packet case). 106100335Sdillon * 107100335Sdillon * The prior minimum of 1*hz (1 second) badly breaks throughput on any 108100335Sdillon * networks faster then a modem that has minor (e.g. 1%) packet loss. 109100270Sdillon */ 110171677Speter#define TCPTV_MIN ( hz/33 ) /* minimum allowable value */ 111100335Sdillon#define TCPTV_CPU_VAR ( hz/5 ) /* cpu variance allowed (200ms) */ 11250673Sjlemon#define TCPTV_REXMTMAX ( 64*hz) /* max allowable REXMT value */ 1131541Srgrimes 1146247Swollman#define TCPTV_TWTRUNC 8 /* RTO factor to truncate TW */ 1156247Swollman 1161541Srgrimes#define TCP_LINGERTIME 120 /* linger at most 2 minutes */ 1171541Srgrimes 1181541Srgrimes#define TCP_MAXRXTSHIFT 12 /* maximum retransmits */ 1191541Srgrimes 120242308Sandre#define TCPTV_DELACK ( hz/10 ) /* 100ms timeout */ 12150673Sjlemon 1221541Srgrimes#ifdef TCPTIMERS 123101975Salfredstatic const char *tcptimers[] = 124243621Sandre { "REXMT", "PERSIST", "KEEP", "2MSL", "DELACK" }; 1251541Srgrimes#endif 1261541Srgrimes 127168621Sru/* 128168621Sru * Force a time value to be in a certain range. 129168621Sru */ 130168621Sru#define TCPT_RANGESET(tv, value, tvmin, tvmax) do { \ 131168621Sru (tv) = (value) + tcp_rexmit_slop; \ 132168621Sru if ((u_long)(tv) < (u_long)(tvmin)) \ 133168621Sru (tv) = (tvmin); \ 134168621Sru if ((u_long)(tv) > (u_long)(tvmax)) \ 135168621Sru (tv) = (tvmax); \ 136168621Sru} while(0) 137168621Sru 138168621Sru#ifdef _KERNEL 139168621Sru 140197244Ssilbystruct xtcp_timer; 141197244Ssilby 142172309Ssilbystruct tcp_timer { 143172309Ssilby struct callout tt_rexmt; /* retransmit timer */ 144172309Ssilby struct callout tt_persist; /* retransmit persistence */ 145172309Ssilby struct callout tt_keep; /* keepalive */ 146172309Ssilby struct callout tt_2msl; /* 2*msl TIME_WAIT timer */ 147172309Ssilby struct callout tt_delack; /* delayed ACK timer */ 148281599Sjch uint32_t tt_flags; /* Timers flags */ 149298743Srrs uint32_t tt_draincnt; /* Count being drained */ 150172309Ssilby}; 151168615Sandre 152281599Sjch/* 153281599Sjch * Flags for the tt_flags field. 154281599Sjch */ 155281599Sjch#define TT_DELACK 0x0001 156281599Sjch#define TT_REXMT 0x0002 157281599Sjch#define TT_PERSIST 0x0004 158281599Sjch#define TT_KEEP 0x0008 159281599Sjch#define TT_2MSL 0x0010 160281599Sjch#define TT_MASK (TT_DELACK|TT_REXMT|TT_PERSIST|TT_KEEP|TT_2MSL) 161281599Sjch 162287304Sjch#define TT_DELACK_RST 0x0100 163287304Sjch#define TT_REXMT_RST 0x0200 164287304Sjch#define TT_PERSIST_RST 0x0400 165287304Sjch#define TT_KEEP_RST 0x0800 166287304Sjch#define TT_2MSL_RST 0x1000 167287304Sjch 168281599Sjch#define TT_STOPPED 0x00010000 169281599Sjch 170231025Sglebius#define TP_KEEPINIT(tp) ((tp)->t_keepinit ? (tp)->t_keepinit : tcp_keepinit) 171231025Sglebius#define TP_KEEPIDLE(tp) ((tp)->t_keepidle ? (tp)->t_keepidle : tcp_keepidle) 172231025Sglebius#define TP_KEEPINTVL(tp) ((tp)->t_keepintvl ? (tp)->t_keepintvl : tcp_keepintvl) 173231025Sglebius#define TP_KEEPCNT(tp) ((tp)->t_keepcnt ? (tp)->t_keepcnt : tcp_keepcnt) 174231025Sglebius#define TP_MAXIDLE(tp) (TP_KEEPCNT(tp) * TP_KEEPINTVL(tp)) 175231025Sglebius 176294840Shirenextern int tcp_persmin; /* minimum persist interval */ 177294840Shirenextern int tcp_persmax; /* maximum persist interval */ 17818280Spstextern int tcp_keepinit; /* time to establish connection */ 1791541Srgrimesextern int tcp_keepidle; /* time before keepalive probes begin */ 18050673Sjlemonextern int tcp_keepintvl; /* time between keepalive probes */ 181231025Sglebiusextern int tcp_keepcnt; /* number of keepalives */ 18250673Sjlemonextern int tcp_delacktime; /* time before sending a delayed ACK */ 18350673Sjlemonextern int tcp_maxpersistidle; 184100335Sdillonextern int tcp_rexmit_min; 185100335Sdillonextern int tcp_rexmit_slop; 18650673Sjlemonextern int tcp_msl; 1871541Srgrimesextern int tcp_ttl; /* time to live for TCP segs */ 1881541Srgrimesextern int tcp_backoff[]; 189242261Sandreextern int tcp_syn_backoff[]; 1902169Spaul 191330303Sjhbextern int tcp_always_keepalive; 192167036Smohansextern int tcp_finwait2_timeout; 193167036Smohansextern int tcp_fast_finwait2_recycle; 194167036Smohans 195112009Sjlemonvoid tcp_timer_init(void); 196172074Srwatsonvoid tcp_timer_2msl(void *xtp); 197298743Srrsvoid tcp_timer_discard(void *); 198169608Sandrestruct tcptw * 199273850Sjch tcp_tw_2msl_scan(int reuse); /* XXX temporary? */ 200172074Srwatsonvoid tcp_timer_keep(void *xtp); 201172074Srwatsonvoid tcp_timer_persist(void *xtp); 202172074Srwatsonvoid tcp_timer_rexmt(void *xtp); 203172074Srwatsonvoid tcp_timer_delack(void *xtp); 204197244Ssilbyvoid tcp_timer_to_xtimer(struct tcpcb *tp, struct tcp_timer *timer, 205197244Ssilby struct xtcp_timer *xtimer); 20650673Sjlemon 20755205Speter#endif /* _KERNEL */ 20850673Sjlemon 20950673Sjlemon#endif /* !_NETINET_TCP_TIMER_H_ */ 210