1df8bae1dSRodney W. Grimes /* 2e79adb8eSGarrett Wollman * Copyright (c) 1982, 1986, 1988, 1990, 1993, 1995 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 * 3. All advertising materials mentioning features or use of this software 14df8bae1dSRodney W. Grimes * must display the following acknowledgement: 15df8bae1dSRodney W. Grimes * This product includes software developed by the University of 16df8bae1dSRodney W. Grimes * California, Berkeley and its contributors. 17df8bae1dSRodney W. Grimes * 4. Neither the name of the University nor the names of its contributors 18df8bae1dSRodney W. Grimes * may be used to endorse or promote products derived from this software 19df8bae1dSRodney W. Grimes * without specific prior written permission. 20df8bae1dSRodney W. Grimes * 21df8bae1dSRodney W. Grimes * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 22df8bae1dSRodney W. Grimes * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 23df8bae1dSRodney W. Grimes * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 24df8bae1dSRodney W. Grimes * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 25df8bae1dSRodney W. Grimes * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 26df8bae1dSRodney W. Grimes * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 27df8bae1dSRodney W. Grimes * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 28df8bae1dSRodney W. Grimes * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 29df8bae1dSRodney W. Grimes * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 30df8bae1dSRodney W. Grimes * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 31df8bae1dSRodney W. Grimes * SUCH DAMAGE. 32df8bae1dSRodney W. Grimes * 33e79adb8eSGarrett Wollman * @(#)tcp_timer.c 8.2 (Berkeley) 5/24/95 347b40aa32SPaul Traina * $Id: tcp_timer.c,v 1.19 1996/07/12 17:28:46 davidg Exp $ 35df8bae1dSRodney W. Grimes */ 36df8bae1dSRodney W. Grimes 37df8bae1dSRodney W. Grimes #ifndef TUBA_INCLUDE 38df8bae1dSRodney W. Grimes #include <sys/param.h> 392ee45d7dSDavid Greenman #include <sys/queue.h> 40df8bae1dSRodney W. Grimes #include <sys/systm.h> 4198163b98SPoul-Henning Kamp #include <sys/kernel.h> 4298163b98SPoul-Henning Kamp #include <sys/sysctl.h> 43df8bae1dSRodney W. Grimes #include <sys/malloc.h> 44df8bae1dSRodney W. Grimes #include <sys/mbuf.h> 45df8bae1dSRodney W. Grimes #include <sys/socket.h> 46df8bae1dSRodney W. Grimes #include <sys/socketvar.h> 47df8bae1dSRodney W. Grimes #include <sys/protosw.h> 48df8bae1dSRodney W. Grimes #include <sys/errno.h> 49df8bae1dSRodney W. Grimes 50e79adb8eSGarrett Wollman #include <machine/cpu.h> /* before tcp_seq.h, for tcp_random18() */ 51e79adb8eSGarrett Wollman 52df8bae1dSRodney W. Grimes #include <net/if.h> 53df8bae1dSRodney W. Grimes #include <net/route.h> 54df8bae1dSRodney W. Grimes 55df8bae1dSRodney W. Grimes #include <netinet/in.h> 56df8bae1dSRodney W. Grimes #include <netinet/in_systm.h> 57df8bae1dSRodney W. Grimes #include <netinet/ip.h> 58df8bae1dSRodney W. Grimes #include <netinet/in_pcb.h> 59df8bae1dSRodney W. Grimes #include <netinet/ip_var.h> 60df8bae1dSRodney W. Grimes #include <netinet/tcp.h> 61df8bae1dSRodney W. Grimes #include <netinet/tcp_fsm.h> 62df8bae1dSRodney W. Grimes #include <netinet/tcp_seq.h> 63df8bae1dSRodney W. Grimes #include <netinet/tcp_timer.h> 64df8bae1dSRodney W. Grimes #include <netinet/tcp_var.h> 65df8bae1dSRodney W. Grimes #include <netinet/tcpip.h> 66af7a2999SDavid Greenman #ifdef TCPDEBUG 67af7a2999SDavid Greenman #include <netinet/tcp_debug.h> 68af7a2999SDavid Greenman #endif 69df8bae1dSRodney W. Grimes 707b40aa32SPaul Traina int tcp_keepinit = TCPTV_KEEP_INIT; 717b40aa32SPaul Traina SYSCTL_INT(_net_inet_tcp, TCPCTL_KEEPINIT, keepinit, 727b40aa32SPaul Traina CTLFLAG_RW, &tcp_keepinit , 0, ""); 737b40aa32SPaul Traina 74df8bae1dSRodney W. Grimes int tcp_keepidle = TCPTV_KEEP_IDLE; 7598163b98SPoul-Henning Kamp SYSCTL_INT(_net_inet_tcp, TCPCTL_KEEPIDLE, keepidle, 7698163b98SPoul-Henning Kamp CTLFLAG_RW, &tcp_keepidle , 0, ""); 7798163b98SPoul-Henning Kamp 780312fbe9SPoul-Henning Kamp static int tcp_keepintvl = TCPTV_KEEPINTVL; 7998163b98SPoul-Henning Kamp SYSCTL_INT(_net_inet_tcp, TCPCTL_KEEPINTVL, keepintvl, 8098163b98SPoul-Henning Kamp CTLFLAG_RW, &tcp_keepintvl , 0, ""); 8198163b98SPoul-Henning Kamp 8234be9bf3SPoul-Henning Kamp static int always_keepalive = 0; 8334be9bf3SPoul-Henning Kamp SYSCTL_INT(_net_inet_tcp, OID_AUTO, always_keepalive, 8434be9bf3SPoul-Henning Kamp CTLFLAG_RW, &always_keepalive , 0, ""); 8534be9bf3SPoul-Henning Kamp 860312fbe9SPoul-Henning Kamp static int tcp_keepcnt = TCPTV_KEEPCNT; 870312fbe9SPoul-Henning Kamp /* max idle probes */ 880312fbe9SPoul-Henning Kamp static int tcp_maxpersistidle = TCPTV_KEEP_IDLE; 890312fbe9SPoul-Henning Kamp /* max idle time in persist */ 90df8bae1dSRodney W. Grimes int tcp_maxidle; 91e79adb8eSGarrett Wollman #else /* TUBA_INCLUDE */ 92e79adb8eSGarrett Wollman 930312fbe9SPoul-Henning Kamp static int tcp_maxpersistidle; 94df8bae1dSRodney W. Grimes #endif /* TUBA_INCLUDE */ 95e79adb8eSGarrett Wollman 96df8bae1dSRodney W. Grimes /* 97df8bae1dSRodney W. Grimes * Fast timeout routine for processing delayed acks 98df8bae1dSRodney W. Grimes */ 99df8bae1dSRodney W. Grimes void 100df8bae1dSRodney W. Grimes tcp_fasttimo() 101df8bae1dSRodney W. Grimes { 102df8bae1dSRodney W. Grimes register struct inpcb *inp; 103df8bae1dSRodney W. Grimes register struct tcpcb *tp; 10415bd2b43SDavid Greenman int s; 105df8bae1dSRodney W. Grimes 10615bd2b43SDavid Greenman s = splnet(); 10715bd2b43SDavid Greenman 10815bd2b43SDavid Greenman for (inp = tcb.lh_first; inp != NULL; inp = inp->inp_list.le_next) { 109df8bae1dSRodney W. Grimes if ((tp = (struct tcpcb *)inp->inp_ppcb) && 110df8bae1dSRodney W. Grimes (tp->t_flags & TF_DELACK)) { 111df8bae1dSRodney W. Grimes tp->t_flags &= ~TF_DELACK; 112df8bae1dSRodney W. Grimes tp->t_flags |= TF_ACKNOW; 113df8bae1dSRodney W. Grimes tcpstat.tcps_delack++; 114df8bae1dSRodney W. Grimes (void) tcp_output(tp); 115df8bae1dSRodney W. Grimes } 11615bd2b43SDavid Greenman } 117df8bae1dSRodney W. Grimes splx(s); 118df8bae1dSRodney W. Grimes } 119df8bae1dSRodney W. Grimes 120df8bae1dSRodney W. Grimes /* 121df8bae1dSRodney W. Grimes * Tcp protocol timeout routine called every 500 ms. 122df8bae1dSRodney W. Grimes * Updates the timers in all active tcb's and 123df8bae1dSRodney W. Grimes * causes finite state machine actions if timers expire. 124df8bae1dSRodney W. Grimes */ 125df8bae1dSRodney W. Grimes void 126df8bae1dSRodney W. Grimes tcp_slowtimo() 127df8bae1dSRodney W. Grimes { 128df8bae1dSRodney W. Grimes register struct inpcb *ip, *ipnxt; 129df8bae1dSRodney W. Grimes register struct tcpcb *tp; 130df8bae1dSRodney W. Grimes register int i; 13115bd2b43SDavid Greenman int s; 1322c37256eSGarrett Wollman #ifdef TCPDEBUG 1332c37256eSGarrett Wollman int ostate; 1342c37256eSGarrett Wollman #endif 13515bd2b43SDavid Greenman 13615bd2b43SDavid Greenman s = splnet(); 137df8bae1dSRodney W. Grimes 138e79adb8eSGarrett Wollman tcp_maxidle = tcp_keepcnt * tcp_keepintvl; 13915bd2b43SDavid Greenman 14015bd2b43SDavid Greenman ip = tcb.lh_first; 14115bd2b43SDavid Greenman if (ip == NULL) { 142df8bae1dSRodney W. Grimes splx(s); 143df8bae1dSRodney W. Grimes return; 144df8bae1dSRodney W. Grimes } 14515bd2b43SDavid Greenman /* 14615bd2b43SDavid Greenman * Search through tcb's and update active timers. 14715bd2b43SDavid Greenman */ 14815bd2b43SDavid Greenman for (; ip != NULL; ip = ipnxt) { 14915bd2b43SDavid Greenman ipnxt = ip->inp_list.le_next; 150df8bae1dSRodney W. Grimes tp = intotcpcb(ip); 151e79adb8eSGarrett Wollman if (tp == 0 || tp->t_state == TCPS_LISTEN) 152df8bae1dSRodney W. Grimes continue; 153df8bae1dSRodney W. Grimes for (i = 0; i < TCPT_NTIMERS; i++) { 154df8bae1dSRodney W. Grimes if (tp->t_timer[i] && --tp->t_timer[i] == 0) { 1552c37256eSGarrett Wollman #ifdef TCPDEBUG 1562c37256eSGarrett Wollman ostate = tp->t_state; 1572c37256eSGarrett Wollman #endif 1582c37256eSGarrett Wollman tp = tcp_timers(tp, i); 1592c37256eSGarrett Wollman if (tp == NULL) 160df8bae1dSRodney W. Grimes goto tpgone; 1612c37256eSGarrett Wollman #ifdef TCPDEBUG 1622c37256eSGarrett Wollman if (tp->t_inpcb->inp_socket->so_options 1632c37256eSGarrett Wollman & SO_DEBUG) 1642c37256eSGarrett Wollman tcp_trace(TA_USER, ostate, tp, 1652c37256eSGarrett Wollman (struct tcpiphdr *)0, 1662c37256eSGarrett Wollman PRU_SLOWTIMO); 1672c37256eSGarrett Wollman #endif 168df8bae1dSRodney W. Grimes } 169df8bae1dSRodney W. Grimes } 170df8bae1dSRodney W. Grimes tp->t_idle++; 171a0292f23SGarrett Wollman tp->t_duration++; 172df8bae1dSRodney W. Grimes if (tp->t_rtt) 173df8bae1dSRodney W. Grimes tp->t_rtt++; 174df8bae1dSRodney W. Grimes tpgone: 175df8bae1dSRodney W. Grimes ; 176df8bae1dSRodney W. Grimes } 177df8bae1dSRodney W. Grimes tcp_iss += TCP_ISSINCR/PR_SLOWHZ; /* increment iss */ 178df8bae1dSRodney W. Grimes #ifdef TCP_COMPAT_42 179df8bae1dSRodney W. Grimes if ((int)tcp_iss < 0) 180e79adb8eSGarrett Wollman tcp_iss = TCP_ISSINCR; /* XXX */ 181df8bae1dSRodney W. Grimes #endif 182df8bae1dSRodney W. Grimes tcp_now++; /* for timestamps */ 183df8bae1dSRodney W. Grimes splx(s); 184df8bae1dSRodney W. Grimes } 185df8bae1dSRodney W. Grimes #ifndef TUBA_INCLUDE 186df8bae1dSRodney W. Grimes 187df8bae1dSRodney W. Grimes /* 188df8bae1dSRodney W. Grimes * Cancel all timers for TCP tp. 189df8bae1dSRodney W. Grimes */ 190df8bae1dSRodney W. Grimes void 191df8bae1dSRodney W. Grimes tcp_canceltimers(tp) 192df8bae1dSRodney W. Grimes struct tcpcb *tp; 193df8bae1dSRodney W. Grimes { 194df8bae1dSRodney W. Grimes register int i; 195df8bae1dSRodney W. Grimes 196df8bae1dSRodney W. Grimes for (i = 0; i < TCPT_NTIMERS; i++) 197df8bae1dSRodney W. Grimes tp->t_timer[i] = 0; 198df8bae1dSRodney W. Grimes } 199df8bae1dSRodney W. Grimes 200df8bae1dSRodney W. Grimes int tcp_backoff[TCP_MAXRXTSHIFT + 1] = 201df8bae1dSRodney W. Grimes { 1, 2, 4, 8, 16, 32, 64, 64, 64, 64, 64, 64, 64 }; 202df8bae1dSRodney W. Grimes 2030312fbe9SPoul-Henning Kamp static int tcp_totbackoff = 511; /* sum of tcp_backoff[] */ 204e79adb8eSGarrett Wollman 205df8bae1dSRodney W. Grimes /* 206df8bae1dSRodney W. Grimes * TCP timer processing. 207df8bae1dSRodney W. Grimes */ 208df8bae1dSRodney W. Grimes struct tcpcb * 209df8bae1dSRodney W. Grimes tcp_timers(tp, timer) 210df8bae1dSRodney W. Grimes register struct tcpcb *tp; 211df8bae1dSRodney W. Grimes int timer; 212df8bae1dSRodney W. Grimes { 213df8bae1dSRodney W. Grimes register int rexmt; 214df8bae1dSRodney W. Grimes 215df8bae1dSRodney W. Grimes switch (timer) { 216df8bae1dSRodney W. Grimes 217df8bae1dSRodney W. Grimes /* 218df8bae1dSRodney W. Grimes * 2 MSL timeout in shutdown went off. If we're closed but 219df8bae1dSRodney W. Grimes * still waiting for peer to close and connection has been idle 220df8bae1dSRodney W. Grimes * too long, or if 2MSL time is up from TIME_WAIT, delete connection 221df8bae1dSRodney W. Grimes * control block. Otherwise, check again in a bit. 222df8bae1dSRodney W. Grimes */ 223df8bae1dSRodney W. Grimes case TCPT_2MSL: 224df8bae1dSRodney W. Grimes if (tp->t_state != TCPS_TIME_WAIT && 225df8bae1dSRodney W. Grimes tp->t_idle <= tcp_maxidle) 226df8bae1dSRodney W. Grimes tp->t_timer[TCPT_2MSL] = tcp_keepintvl; 227df8bae1dSRodney W. Grimes else 228df8bae1dSRodney W. Grimes tp = tcp_close(tp); 229df8bae1dSRodney W. Grimes break; 230df8bae1dSRodney W. Grimes 231df8bae1dSRodney W. Grimes /* 232df8bae1dSRodney W. Grimes * Retransmission timer went off. Message has not 233df8bae1dSRodney W. Grimes * been acked within retransmit interval. Back off 234df8bae1dSRodney W. Grimes * to a longer retransmit interval and retransmit one segment. 235df8bae1dSRodney W. Grimes */ 236df8bae1dSRodney W. Grimes case TCPT_REXMT: 237df8bae1dSRodney W. Grimes if (++tp->t_rxtshift > TCP_MAXRXTSHIFT) { 238df8bae1dSRodney W. Grimes tp->t_rxtshift = TCP_MAXRXTSHIFT; 239df8bae1dSRodney W. Grimes tcpstat.tcps_timeoutdrop++; 240df8bae1dSRodney W. Grimes tp = tcp_drop(tp, tp->t_softerror ? 241df8bae1dSRodney W. Grimes tp->t_softerror : ETIMEDOUT); 242df8bae1dSRodney W. Grimes break; 243df8bae1dSRodney W. Grimes } 244df8bae1dSRodney W. Grimes tcpstat.tcps_rexmttimeo++; 245df8bae1dSRodney W. Grimes rexmt = TCP_REXMTVAL(tp) * tcp_backoff[tp->t_rxtshift]; 246df8bae1dSRodney W. Grimes TCPT_RANGESET(tp->t_rxtcur, rexmt, 247df8bae1dSRodney W. Grimes tp->t_rttmin, TCPTV_REXMTMAX); 248df8bae1dSRodney W. Grimes tp->t_timer[TCPT_REXMT] = tp->t_rxtcur; 249df8bae1dSRodney W. Grimes /* 250df8bae1dSRodney W. Grimes * If losing, let the lower level know and try for 251df8bae1dSRodney W. Grimes * a better route. Also, if we backed off this far, 252df8bae1dSRodney W. Grimes * our srtt estimate is probably bogus. Clobber it 253df8bae1dSRodney W. Grimes * so we'll take the next rtt measurement as our srtt; 254df8bae1dSRodney W. Grimes * move the current srtt into rttvar to keep the current 255df8bae1dSRodney W. Grimes * retransmit times until then. 256df8bae1dSRodney W. Grimes */ 257df8bae1dSRodney W. Grimes if (tp->t_rxtshift > TCP_MAXRXTSHIFT / 4) { 258df8bae1dSRodney W. Grimes in_losing(tp->t_inpcb); 259df8bae1dSRodney W. Grimes tp->t_rttvar += (tp->t_srtt >> TCP_RTT_SHIFT); 260df8bae1dSRodney W. Grimes tp->t_srtt = 0; 261df8bae1dSRodney W. Grimes } 262df8bae1dSRodney W. Grimes tp->snd_nxt = tp->snd_una; 263a0292f23SGarrett Wollman /* 26474b48c1dSAndras Olah * Force a segment to be sent. 26574b48c1dSAndras Olah */ 26674b48c1dSAndras Olah tp->t_flags |= TF_ACKNOW; 26774b48c1dSAndras Olah /* 268df8bae1dSRodney W. Grimes * If timing a segment in this window, stop the timer. 269df8bae1dSRodney W. Grimes */ 270df8bae1dSRodney W. Grimes tp->t_rtt = 0; 271df8bae1dSRodney W. Grimes /* 272df8bae1dSRodney W. Grimes * Close the congestion window down to one segment 273df8bae1dSRodney W. Grimes * (we'll open it by one segment for each ack we get). 274df8bae1dSRodney W. Grimes * Since we probably have a window's worth of unacked 275df8bae1dSRodney W. Grimes * data accumulated, this "slow start" keeps us from 276df8bae1dSRodney W. Grimes * dumping all that data as back-to-back packets (which 277df8bae1dSRodney W. Grimes * might overwhelm an intermediate gateway). 278df8bae1dSRodney W. Grimes * 279df8bae1dSRodney W. Grimes * There are two phases to the opening: Initially we 280df8bae1dSRodney W. Grimes * open by one mss on each ack. This makes the window 281df8bae1dSRodney W. Grimes * size increase exponentially with time. If the 282df8bae1dSRodney W. Grimes * window is larger than the path can handle, this 283df8bae1dSRodney W. Grimes * exponential growth results in dropped packet(s) 284df8bae1dSRodney W. Grimes * almost immediately. To get more time between 285df8bae1dSRodney W. Grimes * drops but still "push" the network to take advantage 286df8bae1dSRodney W. Grimes * of improving conditions, we switch from exponential 287df8bae1dSRodney W. Grimes * to linear window opening at some threshhold size. 288df8bae1dSRodney W. Grimes * For a threshhold, we use half the current window 289df8bae1dSRodney W. Grimes * size, truncated to a multiple of the mss. 290df8bae1dSRodney W. Grimes * 291df8bae1dSRodney W. Grimes * (the minimum cwnd that will give us exponential 292df8bae1dSRodney W. Grimes * growth is 2 mss. We don't allow the threshhold 293df8bae1dSRodney W. Grimes * to go below this.) 294df8bae1dSRodney W. Grimes */ 295df8bae1dSRodney W. Grimes { 296df8bae1dSRodney W. Grimes u_int win = min(tp->snd_wnd, tp->snd_cwnd) / 2 / tp->t_maxseg; 297df8bae1dSRodney W. Grimes if (win < 2) 298df8bae1dSRodney W. Grimes win = 2; 299df8bae1dSRodney W. Grimes tp->snd_cwnd = tp->t_maxseg; 300df8bae1dSRodney W. Grimes tp->snd_ssthresh = win * tp->t_maxseg; 301df8bae1dSRodney W. Grimes tp->t_dupacks = 0; 302df8bae1dSRodney W. Grimes } 303df8bae1dSRodney W. Grimes (void) tcp_output(tp); 304df8bae1dSRodney W. Grimes break; 305df8bae1dSRodney W. Grimes 306df8bae1dSRodney W. Grimes /* 307df8bae1dSRodney W. Grimes * Persistance timer into zero window. 308df8bae1dSRodney W. Grimes * Force a byte to be output, if possible. 309df8bae1dSRodney W. Grimes */ 310df8bae1dSRodney W. Grimes case TCPT_PERSIST: 311df8bae1dSRodney W. Grimes tcpstat.tcps_persisttimeo++; 312cc0964fbSDavid Greenman /* 313cc0964fbSDavid Greenman * Hack: if the peer is dead/unreachable, we do not 314cc0964fbSDavid Greenman * time out if the window is closed. After a full 315cc0964fbSDavid Greenman * backoff, drop the connection if the idle time 316cc0964fbSDavid Greenman * (no responses to probes) reaches the maximum 317cc0964fbSDavid Greenman * backoff that we would use if retransmitting. 318cc0964fbSDavid Greenman */ 319588c9225SJohn Polstra if (tp->t_rxtshift == TCP_MAXRXTSHIFT) { 320588c9225SJohn Polstra u_long maxidle = TCP_REXMTVAL(tp); 321588c9225SJohn Polstra if (maxidle < tp->t_rttmin) 322588c9225SJohn Polstra maxidle = tp->t_rttmin; 323588c9225SJohn Polstra maxidle *= tcp_totbackoff; 324588c9225SJohn Polstra if (tp->t_idle >= tcp_maxpersistidle || 325588c9225SJohn Polstra tp->t_idle >= maxidle) { 326cc0964fbSDavid Greenman tcpstat.tcps_persistdrop++; 327cc0964fbSDavid Greenman tp = tcp_drop(tp, ETIMEDOUT); 328cc0964fbSDavid Greenman break; 329cc0964fbSDavid Greenman } 330588c9225SJohn Polstra } 331df8bae1dSRodney W. Grimes tcp_setpersist(tp); 332df8bae1dSRodney W. Grimes tp->t_force = 1; 333df8bae1dSRodney W. Grimes (void) tcp_output(tp); 334df8bae1dSRodney W. Grimes tp->t_force = 0; 335df8bae1dSRodney W. Grimes break; 336df8bae1dSRodney W. Grimes 337df8bae1dSRodney W. Grimes /* 338df8bae1dSRodney W. Grimes * Keep-alive timer went off; send something 339df8bae1dSRodney W. Grimes * or drop connection if idle for too long. 340df8bae1dSRodney W. Grimes */ 341df8bae1dSRodney W. Grimes case TCPT_KEEP: 342df8bae1dSRodney W. Grimes tcpstat.tcps_keeptimeo++; 343df8bae1dSRodney W. Grimes if (tp->t_state < TCPS_ESTABLISHED) 344df8bae1dSRodney W. Grimes goto dropit; 34534be9bf3SPoul-Henning Kamp if ((always_keepalive || 34634be9bf3SPoul-Henning Kamp tp->t_inpcb->inp_socket->so_options & SO_KEEPALIVE) && 3472d8266afSDavid Greenman tp->t_state <= TCPS_CLOSING) { 348df8bae1dSRodney W. Grimes if (tp->t_idle >= tcp_keepidle + tcp_maxidle) 349df8bae1dSRodney W. Grimes goto dropit; 350df8bae1dSRodney W. Grimes /* 351df8bae1dSRodney W. Grimes * Send a packet designed to force a response 352df8bae1dSRodney W. Grimes * if the peer is up and reachable: 353df8bae1dSRodney W. Grimes * either an ACK if the connection is still alive, 354df8bae1dSRodney W. Grimes * or an RST if the peer has closed the connection 355df8bae1dSRodney W. Grimes * due to timeout or reboot. 356df8bae1dSRodney W. Grimes * Using sequence number tp->snd_una-1 357df8bae1dSRodney W. Grimes * causes the transmitted zero-length segment 358df8bae1dSRodney W. Grimes * to lie outside the receive window; 359df8bae1dSRodney W. Grimes * by the protocol spec, this requires the 360df8bae1dSRodney W. Grimes * correspondent TCP to respond. 361df8bae1dSRodney W. Grimes */ 362df8bae1dSRodney W. Grimes tcpstat.tcps_keepprobe++; 363df8bae1dSRodney W. Grimes #ifdef TCP_COMPAT_42 364df8bae1dSRodney W. Grimes /* 365df8bae1dSRodney W. Grimes * The keepalive packet must have nonzero length 366df8bae1dSRodney W. Grimes * to get a 4.2 host to respond. 367df8bae1dSRodney W. Grimes */ 368df8bae1dSRodney W. Grimes tcp_respond(tp, tp->t_template, (struct mbuf *)NULL, 369df8bae1dSRodney W. Grimes tp->rcv_nxt - 1, tp->snd_una - 1, 0); 370df8bae1dSRodney W. Grimes #else 371df8bae1dSRodney W. Grimes tcp_respond(tp, tp->t_template, (struct mbuf *)NULL, 372df8bae1dSRodney W. Grimes tp->rcv_nxt, tp->snd_una - 1, 0); 373df8bae1dSRodney W. Grimes #endif 374df8bae1dSRodney W. Grimes tp->t_timer[TCPT_KEEP] = tcp_keepintvl; 375df8bae1dSRodney W. Grimes } else 376df8bae1dSRodney W. Grimes tp->t_timer[TCPT_KEEP] = tcp_keepidle; 377df8bae1dSRodney W. Grimes break; 378df8bae1dSRodney W. Grimes dropit: 379df8bae1dSRodney W. Grimes tcpstat.tcps_keepdrops++; 380df8bae1dSRodney W. Grimes tp = tcp_drop(tp, ETIMEDOUT); 381df8bae1dSRodney W. Grimes break; 382df8bae1dSRodney W. Grimes } 383df8bae1dSRodney W. Grimes return (tp); 384df8bae1dSRodney W. Grimes } 385df8bae1dSRodney W. Grimes #endif /* TUBA_INCLUDE */ 386