tcp_timer.c revision 157376
1/*-
2 * Copyright (c) 1982, 1986, 1988, 1990, 1993, 1995
3 *	The Regents of the University of California.  All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 *    notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 *    notice, this list of conditions and the following disclaimer in the
12 *    documentation and/or other materials provided with the distribution.
13 * 4. Neither the name of the University nor the names of its contributors
14 *    may be used to endorse or promote products derived from this software
15 *    without specific prior written permission.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
18 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
21 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27 * SUCH DAMAGE.
28 *
29 *	@(#)tcp_timer.c	8.2 (Berkeley) 5/24/95
30 * $FreeBSD: head/sys/netinet/tcp_timer.c 157376 2006-04-01 16:36:36Z rwatson $
31 */
32
33#include "opt_inet6.h"
34#include "opt_tcpdebug.h"
35#include "opt_tcp_sack.h"
36
37#include <sys/param.h>
38#include <sys/kernel.h>
39#include <sys/lock.h>
40#include <sys/mbuf.h>
41#include <sys/mutex.h>
42#include <sys/protosw.h>
43#include <sys/socket.h>
44#include <sys/socketvar.h>
45#include <sys/sysctl.h>
46#include <sys/systm.h>
47
48#include <net/route.h>
49
50#include <netinet/in.h>
51#include <netinet/in_pcb.h>
52#include <netinet/in_systm.h>
53#ifdef INET6
54#include <netinet6/in6_pcb.h>
55#endif
56#include <netinet/ip_var.h>
57#include <netinet/tcp.h>
58#include <netinet/tcp_fsm.h>
59#include <netinet/tcp_timer.h>
60#include <netinet/tcp_var.h>
61#include <netinet/tcpip.h>
62#ifdef TCPDEBUG
63#include <netinet/tcp_debug.h>
64#endif
65
66int	tcp_keepinit;
67SYSCTL_PROC(_net_inet_tcp, TCPCTL_KEEPINIT, keepinit, CTLTYPE_INT|CTLFLAG_RW,
68    &tcp_keepinit, 0, sysctl_msec_to_ticks, "I", "");
69
70int	tcp_keepidle;
71SYSCTL_PROC(_net_inet_tcp, TCPCTL_KEEPIDLE, keepidle, CTLTYPE_INT|CTLFLAG_RW,
72    &tcp_keepidle, 0, sysctl_msec_to_ticks, "I", "");
73
74int	tcp_keepintvl;
75SYSCTL_PROC(_net_inet_tcp, TCPCTL_KEEPINTVL, keepintvl, CTLTYPE_INT|CTLFLAG_RW,
76    &tcp_keepintvl, 0, sysctl_msec_to_ticks, "I", "");
77
78int	tcp_delacktime;
79SYSCTL_PROC(_net_inet_tcp, TCPCTL_DELACKTIME, delacktime,
80    CTLTYPE_INT|CTLFLAG_RW, &tcp_delacktime, 0, sysctl_msec_to_ticks, "I",
81    "Time before a delayed ACK is sent");
82
83int	tcp_msl;
84SYSCTL_PROC(_net_inet_tcp, OID_AUTO, msl, CTLTYPE_INT|CTLFLAG_RW,
85    &tcp_msl, 0, sysctl_msec_to_ticks, "I", "Maximum segment lifetime");
86
87int	tcp_rexmit_min;
88SYSCTL_PROC(_net_inet_tcp, OID_AUTO, rexmit_min, CTLTYPE_INT|CTLFLAG_RW,
89    &tcp_rexmit_min, 0, sysctl_msec_to_ticks, "I", "Minimum Retransmission Timeout");
90
91int	tcp_rexmit_slop;
92SYSCTL_PROC(_net_inet_tcp, OID_AUTO, rexmit_slop, CTLTYPE_INT|CTLFLAG_RW,
93    &tcp_rexmit_slop, 0, sysctl_msec_to_ticks, "I", "Retransmission Timer Slop");
94
95static int	always_keepalive = 1;
96SYSCTL_INT(_net_inet_tcp, OID_AUTO, always_keepalive, CTLFLAG_RW,
97    &always_keepalive , 0, "Assume SO_KEEPALIVE on all TCP connections");
98
99static int	tcp_keepcnt = TCPTV_KEEPCNT;
100	/* max idle probes */
101int	tcp_maxpersistidle;
102	/* max idle time in persist */
103int	tcp_maxidle;
104
105/*
106 * Tcp protocol timeout routine called every 500 ms.
107 * Updates timestamps used for TCP
108 * causes finite state machine actions if timers expire.
109 */
110void
111tcp_slowtimo()
112{
113
114	tcp_maxidle = tcp_keepcnt * tcp_keepintvl;
115	INP_INFO_WLOCK(&tcbinfo);
116	(void) tcp_timer_2msl_tw(0);
117	INP_INFO_WUNLOCK(&tcbinfo);
118}
119
120int	tcp_syn_backoff[TCP_MAXRXTSHIFT + 1] =
121    { 1, 1, 1, 1, 1, 2, 4, 8, 16, 32, 64, 64, 64 };
122
123int	tcp_backoff[TCP_MAXRXTSHIFT + 1] =
124    { 1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 512, 512, 512 };
125
126static int tcp_totbackoff = 2559;	/* sum of tcp_backoff[] */
127
128static int tcp_timer_race;
129SYSCTL_INT(_net_inet_tcp, OID_AUTO, timer_race, CTLFLAG_RD, &tcp_timer_race,
130    0, "Count of t_inpcb races on tcp_discardcb");
131
132/*
133 * TCP timer processing.
134 */
135
136void
137tcp_timer_delack(xtp)
138	void *xtp;
139{
140	struct tcpcb *tp = xtp;
141	struct inpcb *inp;
142
143	INP_INFO_RLOCK(&tcbinfo);
144	inp = tp->t_inpcb;
145	/*
146	 * XXXRW: While this assert is in fact correct, bugs in the tcpcb
147	 * tear-down mean we need it as a work-around for races between
148	 * timers and tcp_discardcb().
149	 *
150	 * KASSERT(inp != NULL, ("tcp_timer_delack: inp == NULL"));
151	 */
152	if (inp == NULL) {
153		tcp_timer_race++;
154		INP_INFO_RUNLOCK(&tcbinfo);
155		return;
156	}
157	INP_LOCK(inp);
158	INP_INFO_RUNLOCK(&tcbinfo);
159	if (callout_pending(tp->tt_delack) || !callout_active(tp->tt_delack)) {
160		INP_UNLOCK(inp);
161		return;
162	}
163	callout_deactivate(tp->tt_delack);
164
165	tp->t_flags |= TF_ACKNOW;
166	tcpstat.tcps_delack++;
167	(void) tcp_output(tp);
168	INP_UNLOCK(inp);
169}
170
171void
172tcp_timer_2msl(xtp)
173	void *xtp;
174{
175	struct tcpcb *tp = xtp;
176	struct inpcb *inp;
177#ifdef TCPDEBUG
178	int ostate;
179
180	ostate = tp->t_state;
181#endif
182	/*
183	 * XXXRW: Does this actually happen?
184	 */
185	INP_INFO_WLOCK(&tcbinfo);
186	inp = tp->t_inpcb;
187	/*
188	 * XXXRW: While this assert is in fact correct, bugs in the tcpcb
189	 * tear-down mean we need it as a work-around for races between
190	 * timers and tcp_discardcb().
191	 *
192	 * KASSERT(inp != NULL, ("tcp_timer_2msl: inp == NULL"));
193	 */
194	if (inp == NULL) {
195		tcp_timer_race++;
196		INP_INFO_RUNLOCK(&tcbinfo);
197		return;
198	}
199	INP_LOCK(inp);
200	tcp_free_sackholes(tp);
201	if (callout_pending(tp->tt_2msl) || !callout_active(tp->tt_2msl)) {
202		INP_UNLOCK(tp->t_inpcb);
203		INP_INFO_WUNLOCK(&tcbinfo);
204		return;
205	}
206	callout_deactivate(tp->tt_2msl);
207	/*
208	 * 2 MSL timeout in shutdown went off.  If we're closed but
209	 * still waiting for peer to close and connection has been idle
210	 * too long, or if 2MSL time is up from TIME_WAIT, delete connection
211	 * control block.  Otherwise, check again in a bit.
212	 */
213	if (tp->t_state != TCPS_TIME_WAIT &&
214	    (ticks - tp->t_rcvtime) <= tcp_maxidle)
215		callout_reset(tp->tt_2msl, tcp_keepintvl,
216			      tcp_timer_2msl, tp);
217	else
218		tp = tcp_close(tp);
219
220#ifdef TCPDEBUG
221	if (tp != NULL && (tp->t_inpcb->inp_socket->so_options & SO_DEBUG))
222		tcp_trace(TA_USER, ostate, tp, (void *)0, (struct tcphdr *)0,
223			  PRU_SLOWTIMO);
224#endif
225	if (tp != NULL)
226		INP_UNLOCK(inp);
227	INP_INFO_WUNLOCK(&tcbinfo);
228}
229
230/*
231 * The timed wait lists contain references to each of the TCP sessions
232 * currently TIME_WAIT state.  The list pointers, including the list pointers
233 * in each tcptw structure, are protected using the global tcbinfo lock,
234 * which must be held over list iteration and modification.
235 */
236struct twlist {
237	LIST_HEAD(, tcptw)	tw_list;
238	struct tcptw	tw_tail;
239};
240#define TWLIST_NLISTS	2
241static struct twlist twl_2msl[TWLIST_NLISTS];
242static struct twlist *tw_2msl_list[] = { &twl_2msl[0], &twl_2msl[1], NULL };
243
244void
245tcp_timer_init(void)
246{
247	int i;
248	struct twlist *twl;
249
250	for (i = 0; i < TWLIST_NLISTS; i++) {
251		twl = &twl_2msl[i];
252		LIST_INIT(&twl->tw_list);
253		LIST_INSERT_HEAD(&twl->tw_list, &twl->tw_tail, tw_2msl);
254	}
255}
256
257void
258tcp_timer_2msl_reset(struct tcptw *tw, int timeo)
259{
260	int i;
261	struct tcptw *tw_tail;
262
263	INP_INFO_WLOCK_ASSERT(&tcbinfo);
264	INP_LOCK_ASSERT(tw->tw_inpcb);
265	if (tw->tw_time != 0)
266		LIST_REMOVE(tw, tw_2msl);
267	tw->tw_time = timeo + ticks;
268	i = timeo > tcp_msl ? 1 : 0;
269	tw_tail = &twl_2msl[i].tw_tail;
270	LIST_INSERT_BEFORE(tw_tail, tw, tw_2msl);
271}
272
273void
274tcp_timer_2msl_stop(struct tcptw *tw)
275{
276
277	INP_INFO_WLOCK_ASSERT(&tcbinfo);
278	if (tw->tw_time != 0)
279		LIST_REMOVE(tw, tw_2msl);
280}
281
282struct tcptw *
283tcp_timer_2msl_tw(int reuse)
284{
285	struct tcptw *tw, *tw_tail;
286	struct twlist *twl;
287	int i;
288
289	INP_INFO_WLOCK_ASSERT(&tcbinfo);
290	for (i = 0; i < 2; i++) {
291		twl = tw_2msl_list[i];
292		tw_tail = &twl->tw_tail;
293		tw = LIST_FIRST(&twl->tw_list);
294		if (tw == tw_tail || (!reuse && tw->tw_time > ticks))
295			continue;
296		INP_LOCK(tw->tw_inpcb);
297		tcp_twclose(tw, reuse);
298		return (tw);
299	}
300	return (NULL);
301}
302
303void
304tcp_timer_keep(xtp)
305	void *xtp;
306{
307	struct tcpcb *tp = xtp;
308	struct tcptemp *t_template;
309	struct inpcb *inp;
310#ifdef TCPDEBUG
311	int ostate;
312
313	ostate = tp->t_state;
314#endif
315	INP_INFO_WLOCK(&tcbinfo);
316	inp = tp->t_inpcb;
317	/*
318	 * XXXRW: While this assert is in fact correct, bugs in the tcpcb
319	 * tear-down mean we need it as a work-around for races between
320	 * timers and tcp_discardcb().
321	 *
322	 * KASSERT(inp != NULL, ("tcp_timer_keep: inp == NULL"));
323	 */
324	if (inp == NULL) {
325		tcp_timer_race++;
326		INP_INFO_RUNLOCK(&tcbinfo);
327		return;
328	}
329	INP_LOCK(inp);
330	if (callout_pending(tp->tt_keep) || !callout_active(tp->tt_keep)) {
331		INP_UNLOCK(inp);
332		INP_INFO_WUNLOCK(&tcbinfo);
333		return;
334	}
335	callout_deactivate(tp->tt_keep);
336	/*
337	 * Keep-alive timer went off; send something
338	 * or drop connection if idle for too long.
339	 */
340	tcpstat.tcps_keeptimeo++;
341	if (tp->t_state < TCPS_ESTABLISHED)
342		goto dropit;
343	if ((always_keepalive || inp->inp_socket->so_options & SO_KEEPALIVE) &&
344	    tp->t_state <= TCPS_CLOSING) {
345		if ((ticks - tp->t_rcvtime) >= tcp_keepidle + tcp_maxidle)
346			goto dropit;
347		/*
348		 * Send a packet designed to force a response
349		 * if the peer is up and reachable:
350		 * either an ACK if the connection is still alive,
351		 * or an RST if the peer has closed the connection
352		 * due to timeout or reboot.
353		 * Using sequence number tp->snd_una-1
354		 * causes the transmitted zero-length segment
355		 * to lie outside the receive window;
356		 * by the protocol spec, this requires the
357		 * correspondent TCP to respond.
358		 */
359		tcpstat.tcps_keepprobe++;
360		t_template = tcpip_maketemplate(inp);
361		if (t_template) {
362			tcp_respond(tp, t_template->tt_ipgen,
363				    &t_template->tt_t, (struct mbuf *)NULL,
364				    tp->rcv_nxt, tp->snd_una - 1, 0);
365			(void) m_free(dtom(t_template));
366		}
367		callout_reset(tp->tt_keep, tcp_keepintvl, tcp_timer_keep, tp);
368	} else
369		callout_reset(tp->tt_keep, tcp_keepidle, tcp_timer_keep, tp);
370
371#ifdef TCPDEBUG
372	if (inp->inp_socket->so_options & SO_DEBUG)
373		tcp_trace(TA_USER, ostate, tp, (void *)0, (struct tcphdr *)0,
374			  PRU_SLOWTIMO);
375#endif
376	INP_UNLOCK(inp);
377	INP_INFO_WUNLOCK(&tcbinfo);
378	return;
379
380dropit:
381	tcpstat.tcps_keepdrops++;
382	tp = tcp_drop(tp, ETIMEDOUT);
383
384#ifdef TCPDEBUG
385	if (tp != NULL && (tp->t_inpcb->inp_socket->so_options & SO_DEBUG))
386		tcp_trace(TA_USER, ostate, tp, (void *)0, (struct tcphdr *)0,
387			  PRU_SLOWTIMO);
388#endif
389	if (tp != NULL)
390		INP_UNLOCK(tp->t_inpcb);
391	INP_INFO_WUNLOCK(&tcbinfo);
392}
393
394void
395tcp_timer_persist(xtp)
396	void *xtp;
397{
398	struct tcpcb *tp = xtp;
399	struct inpcb *inp;
400#ifdef TCPDEBUG
401	int ostate;
402
403	ostate = tp->t_state;
404#endif
405	INP_INFO_WLOCK(&tcbinfo);
406	inp = tp->t_inpcb;
407	/*
408	 * XXXRW: While this assert is in fact correct, bugs in the tcpcb
409	 * tear-down mean we need it as a work-around for races between
410	 * timers and tcp_discardcb().
411	 *
412	 * KASSERT(inp != NULL, ("tcp_timer_persist: inp == NULL"));
413	 */
414	if (inp == NULL) {
415		tcp_timer_race++;
416		INP_INFO_RUNLOCK(&tcbinfo);
417		return;
418	}
419	INP_LOCK(inp);
420	if (callout_pending(tp->tt_persist) || !callout_active(tp->tt_persist)){
421		INP_UNLOCK(inp);
422		INP_INFO_WUNLOCK(&tcbinfo);
423		return;
424	}
425	callout_deactivate(tp->tt_persist);
426	/*
427	 * Persistance timer into zero window.
428	 * Force a byte to be output, if possible.
429	 */
430	tcpstat.tcps_persisttimeo++;
431	/*
432	 * Hack: if the peer is dead/unreachable, we do not
433	 * time out if the window is closed.  After a full
434	 * backoff, drop the connection if the idle time
435	 * (no responses to probes) reaches the maximum
436	 * backoff that we would use if retransmitting.
437	 */
438	if (tp->t_rxtshift == TCP_MAXRXTSHIFT &&
439	    ((ticks - tp->t_rcvtime) >= tcp_maxpersistidle ||
440	     (ticks - tp->t_rcvtime) >= TCP_REXMTVAL(tp) * tcp_totbackoff)) {
441		tcpstat.tcps_persistdrop++;
442		tp = tcp_drop(tp, ETIMEDOUT);
443		goto out;
444	}
445	tcp_setpersist(tp);
446	tp->t_flags |= TF_FORCEDATA;
447	(void) tcp_output(tp);
448	tp->t_flags &= ~TF_FORCEDATA;
449
450out:
451#ifdef TCPDEBUG
452	if (tp->t_inpcb->inp_socket->so_options & SO_DEBUG)
453		tcp_trace(TA_USER, ostate, tp, (void *)0, (struct tcphdr *)0,
454			  PRU_SLOWTIMO);
455#endif
456	if (tp != NULL)
457		INP_UNLOCK(inp);
458	INP_INFO_WUNLOCK(&tcbinfo);
459}
460
461void
462tcp_timer_rexmt(xtp)
463	void *xtp;
464{
465	struct tcpcb *tp = xtp;
466	int rexmt;
467	int headlocked;
468	struct inpcb *inp;
469#ifdef TCPDEBUG
470	int ostate;
471
472	ostate = tp->t_state;
473#endif
474	INP_INFO_WLOCK(&tcbinfo);
475	headlocked = 1;
476	inp = tp->t_inpcb;
477	/*
478	 * XXXRW: While this assert is in fact correct, bugs in the tcpcb
479	 * tear-down mean we need it as a work-around for races between
480	 * timers and tcp_discardcb().
481	 *
482	 * KASSERT(inp != NULL, ("tcp_timer_rexmt: inp == NULL"));
483	 */
484	if (inp == NULL) {
485		tcp_timer_race++;
486		INP_INFO_RUNLOCK(&tcbinfo);
487		return;
488	}
489	INP_LOCK(inp);
490	if (callout_pending(tp->tt_rexmt) || !callout_active(tp->tt_rexmt)) {
491		INP_UNLOCK(inp);
492		INP_INFO_WUNLOCK(&tcbinfo);
493		return;
494	}
495	callout_deactivate(tp->tt_rexmt);
496	tcp_free_sackholes(tp);
497	/*
498	 * Retransmission timer went off.  Message has not
499	 * been acked within retransmit interval.  Back off
500	 * to a longer retransmit interval and retransmit one segment.
501	 */
502	if (++tp->t_rxtshift > TCP_MAXRXTSHIFT) {
503		tp->t_rxtshift = TCP_MAXRXTSHIFT;
504		tcpstat.tcps_timeoutdrop++;
505		tp = tcp_drop(tp, tp->t_softerror ?
506			      tp->t_softerror : ETIMEDOUT);
507		goto out;
508	}
509	INP_INFO_WUNLOCK(&tcbinfo);
510	headlocked = 0;
511	if (tp->t_rxtshift == 1) {
512		/*
513		 * first retransmit; record ssthresh and cwnd so they can
514		 * be recovered if this turns out to be a "bad" retransmit.
515		 * A retransmit is considered "bad" if an ACK for this
516		 * segment is received within RTT/2 interval; the assumption
517		 * here is that the ACK was already in flight.  See
518		 * "On Estimating End-to-End Network Path Properties" by
519		 * Allman and Paxson for more details.
520		 */
521		tp->snd_cwnd_prev = tp->snd_cwnd;
522		tp->snd_ssthresh_prev = tp->snd_ssthresh;
523		tp->snd_recover_prev = tp->snd_recover;
524		if (IN_FASTRECOVERY(tp))
525		  tp->t_flags |= TF_WASFRECOVERY;
526		else
527		  tp->t_flags &= ~TF_WASFRECOVERY;
528		tp->t_badrxtwin = ticks + (tp->t_srtt >> (TCP_RTT_SHIFT + 1));
529	}
530	tcpstat.tcps_rexmttimeo++;
531	if (tp->t_state == TCPS_SYN_SENT)
532		rexmt = TCP_REXMTVAL(tp) * tcp_syn_backoff[tp->t_rxtshift];
533	else
534		rexmt = TCP_REXMTVAL(tp) * tcp_backoff[tp->t_rxtshift];
535	TCPT_RANGESET(tp->t_rxtcur, rexmt,
536		      tp->t_rttmin, TCPTV_REXMTMAX);
537	/*
538	 * Disable rfc1323 if we havn't got any response to
539	 * our third SYN to work-around some broken terminal servers
540	 * (most of which have hopefully been retired) that have bad VJ
541	 * header compression code which trashes TCP segments containing
542	 * unknown-to-them TCP options.
543	 */
544	if ((tp->t_state == TCPS_SYN_SENT) && (tp->t_rxtshift == 3))
545		tp->t_flags &= ~(TF_REQ_SCALE|TF_REQ_TSTMP);
546	/*
547	 * If we backed off this far, our srtt estimate is probably bogus.
548	 * Clobber it so we'll take the next rtt measurement as our srtt;
549	 * move the current srtt into rttvar to keep the current
550	 * retransmit times until then.
551	 */
552	if (tp->t_rxtshift > TCP_MAXRXTSHIFT / 4) {
553#ifdef INET6
554		if ((tp->t_inpcb->inp_vflag & INP_IPV6) != 0)
555			in6_losing(tp->t_inpcb);
556		else
557#endif
558		tp->t_rttvar += (tp->t_srtt >> TCP_RTT_SHIFT);
559		tp->t_srtt = 0;
560	}
561	tp->snd_nxt = tp->snd_una;
562	tp->snd_recover = tp->snd_max;
563	/*
564	 * Force a segment to be sent.
565	 */
566	tp->t_flags |= TF_ACKNOW;
567	/*
568	 * If timing a segment in this window, stop the timer.
569	 */
570	tp->t_rtttime = 0;
571	/*
572	 * Close the congestion window down to one segment
573	 * (we'll open it by one segment for each ack we get).
574	 * Since we probably have a window's worth of unacked
575	 * data accumulated, this "slow start" keeps us from
576	 * dumping all that data as back-to-back packets (which
577	 * might overwhelm an intermediate gateway).
578	 *
579	 * There are two phases to the opening: Initially we
580	 * open by one mss on each ack.  This makes the window
581	 * size increase exponentially with time.  If the
582	 * window is larger than the path can handle, this
583	 * exponential growth results in dropped packet(s)
584	 * almost immediately.  To get more time between
585	 * drops but still "push" the network to take advantage
586	 * of improving conditions, we switch from exponential
587	 * to linear window opening at some threshhold size.
588	 * For a threshhold, we use half the current window
589	 * size, truncated to a multiple of the mss.
590	 *
591	 * (the minimum cwnd that will give us exponential
592	 * growth is 2 mss.  We don't allow the threshhold
593	 * to go below this.)
594	 */
595	{
596		u_int win = min(tp->snd_wnd, tp->snd_cwnd) / 2 / tp->t_maxseg;
597		if (win < 2)
598			win = 2;
599		tp->snd_cwnd = tp->t_maxseg;
600		tp->snd_ssthresh = win * tp->t_maxseg;
601		tp->t_dupacks = 0;
602	}
603	EXIT_FASTRECOVERY(tp);
604	(void) tcp_output(tp);
605
606out:
607#ifdef TCPDEBUG
608	if (tp != NULL && (tp->t_inpcb->inp_socket->so_options & SO_DEBUG))
609		tcp_trace(TA_USER, ostate, tp, (void *)0, (struct tcphdr *)0,
610			  PRU_SLOWTIMO);
611#endif
612	if (tp != NULL)
613		INP_UNLOCK(inp);
614	if (headlocked)
615		INP_INFO_WUNLOCK(&tcbinfo);
616}
617