xref: /freebsd/sys/netinet/tcp_timer.c (revision e79adb8ed627dbdfab233869ef0f9abf22d0d4c1)
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
34e79adb8eSGarrett Wollman  *	$Id: tcp_timer.c,v 1.8 1995/07/29 18:48:43 davidg Exp $
35df8bae1dSRodney W. Grimes  */
36df8bae1dSRodney W. Grimes 
37df8bae1dSRodney W. Grimes #ifndef TUBA_INCLUDE
38df8bae1dSRodney W. Grimes #include <sys/param.h>
39df8bae1dSRodney W. Grimes #include <sys/systm.h>
40df8bae1dSRodney W. Grimes #include <sys/malloc.h>
41df8bae1dSRodney W. Grimes #include <sys/mbuf.h>
42df8bae1dSRodney W. Grimes #include <sys/socket.h>
43df8bae1dSRodney W. Grimes #include <sys/socketvar.h>
44df8bae1dSRodney W. Grimes #include <sys/protosw.h>
45df8bae1dSRodney W. Grimes #include <sys/errno.h>
4615bd2b43SDavid Greenman #include <sys/queue.h>
47df8bae1dSRodney W. Grimes 
48e79adb8eSGarrett Wollman #include <machine/cpu.h>	/* before tcp_seq.h, for tcp_random18() */
49e79adb8eSGarrett Wollman 
50df8bae1dSRodney W. Grimes #include <net/if.h>
51df8bae1dSRodney W. Grimes #include <net/route.h>
52df8bae1dSRodney W. Grimes 
53df8bae1dSRodney W. Grimes #include <netinet/in.h>
54df8bae1dSRodney W. Grimes #include <netinet/in_systm.h>
55df8bae1dSRodney W. Grimes #include <netinet/ip.h>
56df8bae1dSRodney W. Grimes #include <netinet/in_pcb.h>
57df8bae1dSRodney W. Grimes #include <netinet/ip_var.h>
58df8bae1dSRodney W. Grimes #include <netinet/tcp.h>
59df8bae1dSRodney W. Grimes #include <netinet/tcp_fsm.h>
60df8bae1dSRodney W. Grimes #include <netinet/tcp_seq.h>
61df8bae1dSRodney W. Grimes #include <netinet/tcp_timer.h>
62df8bae1dSRodney W. Grimes #include <netinet/tcp_var.h>
63df8bae1dSRodney W. Grimes #include <netinet/tcpip.h>
64df8bae1dSRodney W. Grimes 
65df8bae1dSRodney W. Grimes int	tcp_keepidle = TCPTV_KEEP_IDLE;
66df8bae1dSRodney W. Grimes int	tcp_keepintvl = TCPTV_KEEPINTVL;
67e79adb8eSGarrett Wollman int	tcp_keepcnt = TCPTV_KEEPCNT;		/* max idle probes */
68e79adb8eSGarrett Wollman int	tcp_maxpersistidle = TCPTV_KEEP_IDLE;	/* max idle time in persist */
69df8bae1dSRodney W. Grimes int	tcp_maxidle;
70e79adb8eSGarrett Wollman #else /* TUBA_INCLUDE */
71e79adb8eSGarrett Wollman 
72e79adb8eSGarrett Wollman extern	int tcp_maxpersistidle;
73df8bae1dSRodney W. Grimes #endif /* TUBA_INCLUDE */
74e79adb8eSGarrett Wollman 
75df8bae1dSRodney W. Grimes /*
76df8bae1dSRodney W. Grimes  * Fast timeout routine for processing delayed acks
77df8bae1dSRodney W. Grimes  */
78df8bae1dSRodney W. Grimes void
79df8bae1dSRodney W. Grimes tcp_fasttimo()
80df8bae1dSRodney W. Grimes {
81df8bae1dSRodney W. Grimes 	register struct inpcb *inp;
82df8bae1dSRodney W. Grimes 	register struct tcpcb *tp;
8315bd2b43SDavid Greenman 	int s;
84df8bae1dSRodney W. Grimes 
8515bd2b43SDavid Greenman 	s = splnet();
8615bd2b43SDavid Greenman 
8715bd2b43SDavid Greenman 	for (inp = tcb.lh_first; inp != NULL; inp = inp->inp_list.le_next) {
88df8bae1dSRodney W. Grimes 		if ((tp = (struct tcpcb *)inp->inp_ppcb) &&
89df8bae1dSRodney W. Grimes 		    (tp->t_flags & TF_DELACK)) {
90df8bae1dSRodney W. Grimes 			tp->t_flags &= ~TF_DELACK;
91df8bae1dSRodney W. Grimes 			tp->t_flags |= TF_ACKNOW;
92df8bae1dSRodney W. Grimes 			tcpstat.tcps_delack++;
93df8bae1dSRodney W. Grimes 			(void) tcp_output(tp);
94df8bae1dSRodney W. Grimes 		}
9515bd2b43SDavid Greenman 	}
96df8bae1dSRodney W. Grimes 	splx(s);
97df8bae1dSRodney W. Grimes }
98df8bae1dSRodney W. Grimes 
99df8bae1dSRodney W. Grimes /*
100df8bae1dSRodney W. Grimes  * Tcp protocol timeout routine called every 500 ms.
101df8bae1dSRodney W. Grimes  * Updates the timers in all active tcb's and
102df8bae1dSRodney W. Grimes  * causes finite state machine actions if timers expire.
103df8bae1dSRodney W. Grimes  */
104df8bae1dSRodney W. Grimes void
105df8bae1dSRodney W. Grimes tcp_slowtimo()
106df8bae1dSRodney W. Grimes {
107df8bae1dSRodney W. Grimes 	register struct inpcb *ip, *ipnxt;
108df8bae1dSRodney W. Grimes 	register struct tcpcb *tp;
109df8bae1dSRodney W. Grimes 	register int i;
11015bd2b43SDavid Greenman 	int s;
11115bd2b43SDavid Greenman 
11215bd2b43SDavid Greenman 	s = splnet();
113df8bae1dSRodney W. Grimes 
114e79adb8eSGarrett Wollman 	tcp_maxidle = tcp_keepcnt * tcp_keepintvl;
11515bd2b43SDavid Greenman 
11615bd2b43SDavid Greenman 	ip = tcb.lh_first;
11715bd2b43SDavid Greenman 	if (ip == NULL) {
118df8bae1dSRodney W. Grimes 		splx(s);
119df8bae1dSRodney W. Grimes 		return;
120df8bae1dSRodney W. Grimes 	}
12115bd2b43SDavid Greenman 	/*
12215bd2b43SDavid Greenman 	 * Search through tcb's and update active timers.
12315bd2b43SDavid Greenman 	 */
12415bd2b43SDavid Greenman 	for (; ip != NULL; ip = ipnxt) {
12515bd2b43SDavid Greenman 		ipnxt = ip->inp_list.le_next;
126df8bae1dSRodney W. Grimes 		tp = intotcpcb(ip);
127e79adb8eSGarrett Wollman 		if (tp == 0 || tp->t_state == TCPS_LISTEN)
128df8bae1dSRodney W. Grimes 			continue;
129df8bae1dSRodney W. Grimes 		for (i = 0; i < TCPT_NTIMERS; i++) {
130df8bae1dSRodney W. Grimes 			if (tp->t_timer[i] && --tp->t_timer[i] == 0) {
13123062062SDavid Greenman 				if (tcp_usrreq(tp->t_inpcb->inp_socket,
132df8bae1dSRodney W. Grimes 				    PRU_SLOWTIMO, (struct mbuf *)0,
13323062062SDavid Greenman 				    (struct mbuf *)i, (struct mbuf *)0) == NULL)
134df8bae1dSRodney W. Grimes 					goto tpgone;
135df8bae1dSRodney W. Grimes 			}
136df8bae1dSRodney W. Grimes 		}
137df8bae1dSRodney W. Grimes 		tp->t_idle++;
138a0292f23SGarrett Wollman 		tp->t_duration++;
139df8bae1dSRodney W. Grimes 		if (tp->t_rtt)
140df8bae1dSRodney W. Grimes 			tp->t_rtt++;
141df8bae1dSRodney W. Grimes tpgone:
142df8bae1dSRodney W. Grimes 		;
143df8bae1dSRodney W. Grimes 	}
144df8bae1dSRodney W. Grimes 	tcp_iss += TCP_ISSINCR/PR_SLOWHZ;		/* increment iss */
145df8bae1dSRodney W. Grimes #ifdef TCP_COMPAT_42
146df8bae1dSRodney W. Grimes 	if ((int)tcp_iss < 0)
147e79adb8eSGarrett Wollman 		tcp_iss = TCP_ISSINCR;			/* XXX */
148df8bae1dSRodney W. Grimes #endif
149df8bae1dSRodney W. Grimes 	tcp_now++;					/* for timestamps */
150df8bae1dSRodney W. Grimes 	splx(s);
151df8bae1dSRodney W. Grimes }
152df8bae1dSRodney W. Grimes #ifndef TUBA_INCLUDE
153df8bae1dSRodney W. Grimes 
154df8bae1dSRodney W. Grimes /*
155df8bae1dSRodney W. Grimes  * Cancel all timers for TCP tp.
156df8bae1dSRodney W. Grimes  */
157df8bae1dSRodney W. Grimes void
158df8bae1dSRodney W. Grimes tcp_canceltimers(tp)
159df8bae1dSRodney W. Grimes 	struct tcpcb *tp;
160df8bae1dSRodney W. Grimes {
161df8bae1dSRodney W. Grimes 	register int i;
162df8bae1dSRodney W. Grimes 
163df8bae1dSRodney W. Grimes 	for (i = 0; i < TCPT_NTIMERS; i++)
164df8bae1dSRodney W. Grimes 		tp->t_timer[i] = 0;
165df8bae1dSRodney W. Grimes }
166df8bae1dSRodney W. Grimes 
167df8bae1dSRodney W. Grimes int	tcp_backoff[TCP_MAXRXTSHIFT + 1] =
168df8bae1dSRodney W. Grimes     { 1, 2, 4, 8, 16, 32, 64, 64, 64, 64, 64, 64, 64 };
169df8bae1dSRodney W. Grimes 
170e79adb8eSGarrett Wollman int tcp_totbackoff = 511;	/* sum of tcp_backoff[] */
171e79adb8eSGarrett Wollman 
172df8bae1dSRodney W. Grimes /*
173df8bae1dSRodney W. Grimes  * TCP timer processing.
174df8bae1dSRodney W. Grimes  */
175df8bae1dSRodney W. Grimes struct tcpcb *
176df8bae1dSRodney W. Grimes tcp_timers(tp, timer)
177df8bae1dSRodney W. Grimes 	register struct tcpcb *tp;
178df8bae1dSRodney W. Grimes 	int timer;
179df8bae1dSRodney W. Grimes {
180df8bae1dSRodney W. Grimes 	register int rexmt;
181df8bae1dSRodney W. Grimes 
182df8bae1dSRodney W. Grimes 	switch (timer) {
183df8bae1dSRodney W. Grimes 
184df8bae1dSRodney W. Grimes 	/*
185df8bae1dSRodney W. Grimes 	 * 2 MSL timeout in shutdown went off.  If we're closed but
186df8bae1dSRodney W. Grimes 	 * still waiting for peer to close and connection has been idle
187df8bae1dSRodney W. Grimes 	 * too long, or if 2MSL time is up from TIME_WAIT, delete connection
188df8bae1dSRodney W. Grimes 	 * control block.  Otherwise, check again in a bit.
189df8bae1dSRodney W. Grimes 	 */
190df8bae1dSRodney W. Grimes 	case TCPT_2MSL:
191df8bae1dSRodney W. Grimes 		if (tp->t_state != TCPS_TIME_WAIT &&
192df8bae1dSRodney W. Grimes 		    tp->t_idle <= tcp_maxidle)
193df8bae1dSRodney W. Grimes 			tp->t_timer[TCPT_2MSL] = tcp_keepintvl;
194df8bae1dSRodney W. Grimes 		else
195df8bae1dSRodney W. Grimes 			tp = tcp_close(tp);
196df8bae1dSRodney W. Grimes 		break;
197df8bae1dSRodney W. Grimes 
198df8bae1dSRodney W. Grimes 	/*
199df8bae1dSRodney W. Grimes 	 * Retransmission timer went off.  Message has not
200df8bae1dSRodney W. Grimes 	 * been acked within retransmit interval.  Back off
201df8bae1dSRodney W. Grimes 	 * to a longer retransmit interval and retransmit one segment.
202df8bae1dSRodney W. Grimes 	 */
203df8bae1dSRodney W. Grimes 	case TCPT_REXMT:
204df8bae1dSRodney W. Grimes 		if (++tp->t_rxtshift > TCP_MAXRXTSHIFT) {
205df8bae1dSRodney W. Grimes 			tp->t_rxtshift = TCP_MAXRXTSHIFT;
206df8bae1dSRodney W. Grimes 			tcpstat.tcps_timeoutdrop++;
207df8bae1dSRodney W. Grimes 			tp = tcp_drop(tp, tp->t_softerror ?
208df8bae1dSRodney W. Grimes 			    tp->t_softerror : ETIMEDOUT);
209df8bae1dSRodney W. Grimes 			break;
210df8bae1dSRodney W. Grimes 		}
211df8bae1dSRodney W. Grimes 		tcpstat.tcps_rexmttimeo++;
212df8bae1dSRodney W. Grimes 		rexmt = TCP_REXMTVAL(tp) * tcp_backoff[tp->t_rxtshift];
213df8bae1dSRodney W. Grimes 		TCPT_RANGESET(tp->t_rxtcur, rexmt,
214df8bae1dSRodney W. Grimes 		    tp->t_rttmin, TCPTV_REXMTMAX);
215df8bae1dSRodney W. Grimes 		tp->t_timer[TCPT_REXMT] = tp->t_rxtcur;
216df8bae1dSRodney W. Grimes 		/*
217df8bae1dSRodney W. Grimes 		 * If losing, let the lower level know and try for
218df8bae1dSRodney W. Grimes 		 * a better route.  Also, if we backed off this far,
219df8bae1dSRodney W. Grimes 		 * our srtt estimate is probably bogus.  Clobber it
220df8bae1dSRodney W. Grimes 		 * so we'll take the next rtt measurement as our srtt;
221df8bae1dSRodney W. Grimes 		 * move the current srtt into rttvar to keep the current
222df8bae1dSRodney W. Grimes 		 * retransmit times until then.
223df8bae1dSRodney W. Grimes 		 */
224df8bae1dSRodney W. Grimes 		if (tp->t_rxtshift > TCP_MAXRXTSHIFT / 4) {
225df8bae1dSRodney W. Grimes 			in_losing(tp->t_inpcb);
226df8bae1dSRodney W. Grimes 			tp->t_rttvar += (tp->t_srtt >> TCP_RTT_SHIFT);
227df8bae1dSRodney W. Grimes 			tp->t_srtt = 0;
228df8bae1dSRodney W. Grimes 		}
229df8bae1dSRodney W. Grimes 		tp->snd_nxt = tp->snd_una;
230a0292f23SGarrett Wollman 		/*
231a0292f23SGarrett Wollman 		 * Force a segment to be sent.
232a0292f23SGarrett Wollman 		 */
233a0292f23SGarrett Wollman 		tp->t_flags |= TF_ACKNOW;
234df8bae1dSRodney W. Grimes 		/*
235df8bae1dSRodney W. Grimes 		 * If timing a segment in this window, stop the timer.
236df8bae1dSRodney W. Grimes 		 */
237df8bae1dSRodney W. Grimes 		tp->t_rtt = 0;
238df8bae1dSRodney W. Grimes 		/*
239df8bae1dSRodney W. Grimes 		 * Close the congestion window down to one segment
240df8bae1dSRodney W. Grimes 		 * (we'll open it by one segment for each ack we get).
241df8bae1dSRodney W. Grimes 		 * Since we probably have a window's worth of unacked
242df8bae1dSRodney W. Grimes 		 * data accumulated, this "slow start" keeps us from
243df8bae1dSRodney W. Grimes 		 * dumping all that data as back-to-back packets (which
244df8bae1dSRodney W. Grimes 		 * might overwhelm an intermediate gateway).
245df8bae1dSRodney W. Grimes 		 *
246df8bae1dSRodney W. Grimes 		 * There are two phases to the opening: Initially we
247df8bae1dSRodney W. Grimes 		 * open by one mss on each ack.  This makes the window
248df8bae1dSRodney W. Grimes 		 * size increase exponentially with time.  If the
249df8bae1dSRodney W. Grimes 		 * window is larger than the path can handle, this
250df8bae1dSRodney W. Grimes 		 * exponential growth results in dropped packet(s)
251df8bae1dSRodney W. Grimes 		 * almost immediately.  To get more time between
252df8bae1dSRodney W. Grimes 		 * drops but still "push" the network to take advantage
253df8bae1dSRodney W. Grimes 		 * of improving conditions, we switch from exponential
254df8bae1dSRodney W. Grimes 		 * to linear window opening at some threshhold size.
255df8bae1dSRodney W. Grimes 		 * For a threshhold, we use half the current window
256df8bae1dSRodney W. Grimes 		 * size, truncated to a multiple of the mss.
257df8bae1dSRodney W. Grimes 		 *
258df8bae1dSRodney W. Grimes 		 * (the minimum cwnd that will give us exponential
259df8bae1dSRodney W. Grimes 		 * growth is 2 mss.  We don't allow the threshhold
260df8bae1dSRodney W. Grimes 		 * to go below this.)
261df8bae1dSRodney W. Grimes 		 */
262df8bae1dSRodney W. Grimes 		{
263df8bae1dSRodney W. Grimes 		u_int win = min(tp->snd_wnd, tp->snd_cwnd) / 2 / tp->t_maxseg;
264df8bae1dSRodney W. Grimes 		if (win < 2)
265df8bae1dSRodney W. Grimes 			win = 2;
266df8bae1dSRodney W. Grimes 		tp->snd_cwnd = tp->t_maxseg;
267df8bae1dSRodney W. Grimes 		tp->snd_ssthresh = win * tp->t_maxseg;
268df8bae1dSRodney W. Grimes 		tp->t_dupacks = 0;
269df8bae1dSRodney W. Grimes 		}
270df8bae1dSRodney W. Grimes 		(void) tcp_output(tp);
271df8bae1dSRodney W. Grimes 		break;
272df8bae1dSRodney W. Grimes 
273df8bae1dSRodney W. Grimes 	/*
274df8bae1dSRodney W. Grimes 	 * Persistance timer into zero window.
275df8bae1dSRodney W. Grimes 	 * Force a byte to be output, if possible.
276df8bae1dSRodney W. Grimes 	 */
277df8bae1dSRodney W. Grimes 	case TCPT_PERSIST:
278df8bae1dSRodney W. Grimes 		tcpstat.tcps_persisttimeo++;
279cc0964fbSDavid Greenman 		/*
280cc0964fbSDavid Greenman 		 * Hack: if the peer is dead/unreachable, we do not
281cc0964fbSDavid Greenman 		 * time out if the window is closed.  After a full
282cc0964fbSDavid Greenman 		 * backoff, drop the connection if the idle time
283cc0964fbSDavid Greenman 		 * (no responses to probes) reaches the maximum
284cc0964fbSDavid Greenman 		 * backoff that we would use if retransmitting.
285cc0964fbSDavid Greenman 		 */
286cc0964fbSDavid Greenman 		if (tp->t_rxtshift == TCP_MAXRXTSHIFT &&
287cc0964fbSDavid Greenman 		    (tp->t_idle >= tcp_maxpersistidle ||
288cc0964fbSDavid Greenman 		    tp->t_idle >= TCP_REXMTVAL(tp) * tcp_totbackoff)) {
289cc0964fbSDavid Greenman 		        tcpstat.tcps_persistdrop++;
290cc0964fbSDavid Greenman 		        tp = tcp_drop(tp, ETIMEDOUT);
291cc0964fbSDavid Greenman 		        break;
292cc0964fbSDavid Greenman 		}
293df8bae1dSRodney W. Grimes 		tcp_setpersist(tp);
294df8bae1dSRodney W. Grimes 		tp->t_force = 1;
295df8bae1dSRodney W. Grimes 		(void) tcp_output(tp);
296df8bae1dSRodney W. Grimes 		tp->t_force = 0;
297df8bae1dSRodney W. Grimes 		break;
298df8bae1dSRodney W. Grimes 
299df8bae1dSRodney W. Grimes 	/*
300df8bae1dSRodney W. Grimes 	 * Keep-alive timer went off; send something
301df8bae1dSRodney W. Grimes 	 * or drop connection if idle for too long.
302df8bae1dSRodney W. Grimes 	 */
303df8bae1dSRodney W. Grimes 	case TCPT_KEEP:
304df8bae1dSRodney W. Grimes 		tcpstat.tcps_keeptimeo++;
305df8bae1dSRodney W. Grimes 		if (tp->t_state < TCPS_ESTABLISHED)
306df8bae1dSRodney W. Grimes 			goto dropit;
307df8bae1dSRodney W. Grimes 		if (tp->t_inpcb->inp_socket->so_options & SO_KEEPALIVE &&
308df8bae1dSRodney W. Grimes 		    tp->t_state <= TCPS_CLOSE_WAIT) {
309df8bae1dSRodney W. Grimes 		    	if (tp->t_idle >= tcp_keepidle + tcp_maxidle)
310df8bae1dSRodney W. Grimes 				goto dropit;
311df8bae1dSRodney W. Grimes 			/*
312df8bae1dSRodney W. Grimes 			 * Send a packet designed to force a response
313df8bae1dSRodney W. Grimes 			 * if the peer is up and reachable:
314df8bae1dSRodney W. Grimes 			 * either an ACK if the connection is still alive,
315df8bae1dSRodney W. Grimes 			 * or an RST if the peer has closed the connection
316df8bae1dSRodney W. Grimes 			 * due to timeout or reboot.
317df8bae1dSRodney W. Grimes 			 * Using sequence number tp->snd_una-1
318df8bae1dSRodney W. Grimes 			 * causes the transmitted zero-length segment
319df8bae1dSRodney W. Grimes 			 * to lie outside the receive window;
320df8bae1dSRodney W. Grimes 			 * by the protocol spec, this requires the
321df8bae1dSRodney W. Grimes 			 * correspondent TCP to respond.
322df8bae1dSRodney W. Grimes 			 */
323df8bae1dSRodney W. Grimes 			tcpstat.tcps_keepprobe++;
324df8bae1dSRodney W. Grimes #ifdef TCP_COMPAT_42
325df8bae1dSRodney W. Grimes 			/*
326df8bae1dSRodney W. Grimes 			 * The keepalive packet must have nonzero length
327df8bae1dSRodney W. Grimes 			 * to get a 4.2 host to respond.
328df8bae1dSRodney W. Grimes 			 */
329df8bae1dSRodney W. Grimes 			tcp_respond(tp, tp->t_template, (struct mbuf *)NULL,
330df8bae1dSRodney W. Grimes 			    tp->rcv_nxt - 1, tp->snd_una - 1, 0);
331df8bae1dSRodney W. Grimes #else
332df8bae1dSRodney W. Grimes 			tcp_respond(tp, tp->t_template, (struct mbuf *)NULL,
333df8bae1dSRodney W. Grimes 			    tp->rcv_nxt, tp->snd_una - 1, 0);
334df8bae1dSRodney W. Grimes #endif
335df8bae1dSRodney W. Grimes 			tp->t_timer[TCPT_KEEP] = tcp_keepintvl;
336df8bae1dSRodney W. Grimes 		} else
337df8bae1dSRodney W. Grimes 			tp->t_timer[TCPT_KEEP] = tcp_keepidle;
338df8bae1dSRodney W. Grimes 		break;
339df8bae1dSRodney W. Grimes 	dropit:
340df8bae1dSRodney W. Grimes 		tcpstat.tcps_keepdrops++;
341df8bae1dSRodney W. Grimes 		tp = tcp_drop(tp, ETIMEDOUT);
342df8bae1dSRodney W. Grimes 		break;
343df8bae1dSRodney W. Grimes 	}
344df8bae1dSRodney W. Grimes 	return (tp);
345df8bae1dSRodney W. Grimes }
346df8bae1dSRodney W. Grimes #endif /* TUBA_INCLUDE */
347