1 /* $NetBSD: tcp_timer.h,v 1.23 2005/12/10 23:36:23 elad Exp $ */ 2 3 /*- 4 * Copyright (c) 2001, 2005 The NetBSD Foundation, Inc. 5 * All rights reserved. 6 * 7 * This code is derived from software contributed to The NetBSD Foundation 8 * by Jason R. Thorpe of Wasabi Systems, Inc. 9 * This code is derived from software contributed to The NetBSD Foundation 10 * by Charles M. Hannum. 11 * 12 * Redistribution and use in source and binary forms, with or without 13 * modification, are permitted provided that the following conditions 14 * are met: 15 * 1. Redistributions of source code must retain the above copyright 16 * notice, this list of conditions and the following disclaimer. 17 * 2. Redistributions in binary form must reproduce the above copyright 18 * notice, this list of conditions and the following disclaimer in the 19 * documentation and/or other materials provided with the distribution. 20 * 3. All advertising materials mentioning features or use of this software 21 * must display the following acknowledgement: 22 * This product includes software developed by the NetBSD 23 * Foundation, Inc. and its contributors. 24 * 4. Neither the name of The NetBSD Foundation nor the names of its 25 * contributors may be used to endorse or promote products derived 26 * from this software without specific prior written permission. 27 * 28 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 29 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 30 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 31 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 32 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 33 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 34 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 35 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 36 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 37 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 38 * POSSIBILITY OF SUCH DAMAGE. 39 */ 40 41 /* 42 * Copyright (c) 1982, 1986, 1993 43 * The Regents of the University of California. All rights reserved. 44 * 45 * Redistribution and use in source and binary forms, with or without 46 * modification, are permitted provided that the following conditions 47 * are met: 48 * 1. Redistributions of source code must retain the above copyright 49 * notice, this list of conditions and the following disclaimer. 50 * 2. Redistributions in binary form must reproduce the above copyright 51 * notice, this list of conditions and the following disclaimer in the 52 * documentation and/or other materials provided with the distribution. 53 * 3. Neither the name of the University nor the names of its contributors 54 * may be used to endorse or promote products derived from this software 55 * without specific prior written permission. 56 * 57 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 58 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 59 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 60 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 61 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 62 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 63 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 64 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 65 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 66 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 67 * SUCH DAMAGE. 68 * 69 * @(#)tcp_timer.h 8.1 (Berkeley) 6/10/93 70 */ 71 72 #ifndef _NETINET_TCP_TIMER_H_ 73 #define _NETINET_TCP_TIMER_H_ 74 75 /* 76 * Definitions of the TCP timers. These timers are counted 77 * down PR_SLOWHZ times a second. 78 */ 79 #define TCPT_NTIMERS 4 80 81 #define TCPT_REXMT 0 /* retransmit */ 82 #define TCPT_PERSIST 1 /* retransmit persistance */ 83 #define TCPT_KEEP 2 /* keep alive */ 84 #define TCPT_2MSL 3 /* 2*msl quiet time timer */ 85 86 /* 87 * The TCPT_REXMT timer is used to force retransmissions. 88 * The TCP has the TCPT_REXMT timer set whenever segments 89 * have been sent for which ACKs are expected but not yet 90 * received. If an ACK is received which advances tp->snd_una, 91 * then the retransmit timer is cleared (if there are no more 92 * outstanding segments) or reset to the base value (if there 93 * are more ACKs expected). Whenever the retransmit timer goes off, 94 * we retransmit one unacknowledged segment, and do a backoff 95 * on the retransmit timer. 96 * 97 * The TCPT_PERSIST timer is used to keep window size information 98 * flowing even if the window goes shut. If all previous transmissions 99 * have been acknowledged (so that there are no retransmissions in progress), 100 * and the window is too small to bother sending anything, then we start 101 * the TCPT_PERSIST timer. When it expires, if the window is nonzero, 102 * we go to transmit state. Otherwise, at intervals send a single byte 103 * into the peer's window to force him to update our window information. 104 * We do this at most as often as TCPT_PERSMIN time intervals, 105 * but no more frequently than the current estimate of round-trip 106 * packet time. The TCPT_PERSIST timer is cleared whenever we receive 107 * a window update from the peer. 108 * 109 * The TCPT_KEEP timer is used to keep connections alive. If an 110 * connection is idle (no segments received) for TCPTV_KEEP_INIT amount of time, 111 * but not yet established, then we drop the connection. Once the connection 112 * is established, if the connection is idle for TCPTV_KEEP_IDLE time 113 * (and keepalives have been enabled on the socket), we begin to probe 114 * the connection. We force the peer to send us a segment by sending: 115 * <SEQ=SND.UNA-1><ACK=RCV.NXT><CTL=ACK> 116 * This segment is (deliberately) outside the window, and should elicit 117 * an ack segment in response from the peer. If, despite the TCPT_KEEP 118 * initiated segments we cannot elicit a response from a peer in TCPT_MAXIDLE 119 * amount of time probing, then we drop the connection. 120 */ 121 122 /* 123 * Time constants. 124 */ 125 #define TCPTV_MSL ( 30*PR_SLOWHZ) /* max seg lifetime (hah!) */ 126 #define TCPTV_SRTTBASE 0 /* base roundtrip time; 127 if 0, no idea yet */ 128 #define TCPTV_SRTTDFLT ( 3*PR_SLOWHZ) /* assumed RTT if no info */ 129 130 #define TCPTV_PERSMIN ( 5*PR_SLOWHZ) /* retransmit persistance */ 131 #define TCPTV_PERSMAX ( 60*PR_SLOWHZ) /* maximum persist interval */ 132 133 #define TCPTV_KEEP_INIT ( 75*PR_SLOWHZ) /* initial connect keep alive */ 134 #define TCPTV_KEEP_IDLE (120*60*PR_SLOWHZ) /* dflt time before probing */ 135 #define TCPTV_KEEPINTVL ( 75*PR_SLOWHZ) /* default probe interval */ 136 #define TCPTV_KEEPCNT 8 /* max probes before drop */ 137 138 #define TCPTV_MIN ( 1*PR_SLOWHZ) /* minimum allowable value */ 139 #define TCPTV_REXMTMAX ( 64*PR_SLOWHZ) /* max allowable REXMT value */ 140 141 #define TCP_LINGERTIME 120 /* linger at most 2 minutes */ 142 143 #define TCP_MAXRXTSHIFT 12 /* maximum retransmits */ 144 145 #define TCP_DELACK_TICKS (hz / PR_FASTHZ) /* time to delay ACK */ 146 147 #ifdef TCPTIMERS 148 const char *tcptimers[] = 149 { "REXMT", "PERSIST", "KEEP", "2MSL" }; 150 #endif 151 152 /* 153 * Init, arm, disarm, and test TCP timers. 154 */ 155 #define TCP_TIMER_INIT(tp, timer) \ 156 callout_setfunc(&(tp)->t_timer[(timer)], \ 157 tcp_timer_funcs[(timer)], (tp)) 158 159 #define TCP_TIMER_ARM(tp, timer, nticks) \ 160 callout_schedule(&(tp)->t_timer[(timer)], \ 161 (nticks) * (hz / PR_SLOWHZ)) 162 163 #define TCP_TIMER_DISARM(tp, timer) \ 164 callout_stop(&(tp)->t_timer[(timer)]) 165 166 #define TCP_TIMER_ISARMED(tp, timer) \ 167 callout_active(&(tp)->t_timer[(timer)]) 168 169 /* 170 * Force a time value to be in a certain range. 171 */ 172 #define TCPT_RANGESET(tv, value, tvmin, tvmax) { \ 173 (tv) = (value); \ 174 if ((tv) < (tvmin)) \ 175 (tv) = (tvmin); \ 176 else if ((tv) > (tvmax)) \ 177 (tv) = (tvmax); \ 178 } 179 180 #ifdef _KERNEL 181 typedef void (*tcp_timer_func_t)(void *); 182 183 extern const tcp_timer_func_t tcp_timer_funcs[TCPT_NTIMERS]; 184 185 extern int tcp_keepidle; /* time before keepalive probes begin */ 186 extern int tcp_keepintvl; /* time between keepalive probes */ 187 extern int tcp_keepcnt; /* number of keepalives, 0=infty */ 188 extern int tcp_maxpersistidle; /* max idle time in persist */ 189 extern int tcp_maxidle; /* time to drop after starting probes */ 190 extern int tcp_ttl; /* time to live for TCP segs */ 191 extern const int tcp_backoff[]; 192 193 void tcp_timer_init(void); 194 #endif 195 196 #endif /* !_NETINET_TCP_TIMER_H_ */ 197