xref: /freebsd-src/sys/netinet/tcp_timer.c (revision cce83ffb5a508b414d0b2d5f23d2b2cf13d51e0f)
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$
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 
66 static int
67 sysctl_msec_to_ticks(SYSCTL_HANDLER_ARGS)
68 {
69 	int error, s, tt;
70 
71 	tt = *(int *)oidp->oid_arg1;
72 	s = (int)((int64_t)tt * 1000 / hz);
73 
74 	error = sysctl_handle_int(oidp, &s, 0, req);
75 	if (error || !req->newptr)
76 		return (error);
77 
78 	tt = (int)((int64_t)s * hz / 1000);
79 	if (tt < 1)
80 		return (EINVAL);
81 
82 	*(int *)oidp->oid_arg1 = tt;
83 	return (0);
84 }
85 
86 int	tcp_keepinit;
87 SYSCTL_PROC(_net_inet_tcp, TCPCTL_KEEPINIT, keepinit, CTLTYPE_INT|CTLFLAG_RW,
88     &tcp_keepinit, 0, sysctl_msec_to_ticks, "I", "");
89 
90 int	tcp_keepidle;
91 SYSCTL_PROC(_net_inet_tcp, TCPCTL_KEEPIDLE, keepidle, CTLTYPE_INT|CTLFLAG_RW,
92     &tcp_keepidle, 0, sysctl_msec_to_ticks, "I", "");
93 
94 int	tcp_keepintvl;
95 SYSCTL_PROC(_net_inet_tcp, TCPCTL_KEEPINTVL, keepintvl, CTLTYPE_INT|CTLFLAG_RW,
96     &tcp_keepintvl, 0, sysctl_msec_to_ticks, "I", "");
97 
98 int	tcp_delacktime;
99 SYSCTL_PROC(_net_inet_tcp, TCPCTL_DELACKTIME, delacktime,
100     CTLTYPE_INT|CTLFLAG_RW, &tcp_delacktime, 0, sysctl_msec_to_ticks, "I",
101     "Time before a delayed ACK is sent");
102 
103 int	tcp_msl;
104 SYSCTL_PROC(_net_inet_tcp, OID_AUTO, msl, CTLTYPE_INT|CTLFLAG_RW,
105     &tcp_msl, 0, sysctl_msec_to_ticks, "I", "Maximum segment lifetime");
106 
107 int	tcp_rexmit_min;
108 SYSCTL_PROC(_net_inet_tcp, OID_AUTO, rexmit_min, CTLTYPE_INT|CTLFLAG_RW,
109     &tcp_rexmit_min, 0, sysctl_msec_to_ticks, "I", "Minimum Retransmission Timeout");
110 
111 int	tcp_rexmit_slop;
112 SYSCTL_PROC(_net_inet_tcp, OID_AUTO, rexmit_slop, CTLTYPE_INT|CTLFLAG_RW,
113     &tcp_rexmit_slop, 0, sysctl_msec_to_ticks, "I", "Retransmission Timer Slop");
114 
115 static int	always_keepalive = 1;
116 SYSCTL_INT(_net_inet_tcp, OID_AUTO, always_keepalive, CTLFLAG_RW,
117     &always_keepalive , 0, "Assume SO_KEEPALIVE on all TCP connections");
118 
119 static int	tcp_keepcnt = TCPTV_KEEPCNT;
120 	/* max idle probes */
121 int	tcp_maxpersistidle;
122 	/* max idle time in persist */
123 int	tcp_maxidle;
124 
125 /*
126  * Tcp protocol timeout routine called every 500 ms.
127  * Updates timestamps used for TCP
128  * causes finite state machine actions if timers expire.
129  */
130 void
131 tcp_slowtimo()
132 {
133 
134 	/*
135 	 * XXXRW: Note that there is a minor race issue associated with rapid
136 	 * modification of the two components of tcp_maxidle.  This could be
137 	 * corrected by introducing sysctl handlers for those two fields,
138 	 * sliding this update of tcp_maxidle under the tcbinfo lock, and
139 	 * acquiring that lock in the handlers.
140 	 */
141 	tcp_maxidle = tcp_keepcnt * tcp_keepintvl;
142 	INP_INFO_WLOCK(&tcbinfo);
143 	(void) tcp_timer_2msl_tw(0);
144 	INP_INFO_WUNLOCK(&tcbinfo);
145 }
146 
147 /*
148  * Cancel all timers for TCP tp.
149  *
150  * XXXRW: This appears to be unused.
151  */
152 void
153 tcp_canceltimers(tp)
154 	struct tcpcb *tp;
155 {
156 	callout_stop(tp->tt_2msl);
157 	callout_stop(tp->tt_persist);
158 	callout_stop(tp->tt_keep);
159 	callout_stop(tp->tt_rexmt);
160 }
161 
162 int	tcp_syn_backoff[TCP_MAXRXTSHIFT + 1] =
163     { 1, 1, 1, 1, 1, 2, 4, 8, 16, 32, 64, 64, 64 };
164 
165 int	tcp_backoff[TCP_MAXRXTSHIFT + 1] =
166     { 1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 512, 512, 512 };
167 
168 static int tcp_totbackoff = 2559;	/* sum of tcp_backoff[] */
169 
170 /*
171  * TCP timer processing.
172  */
173 
174 void
175 tcp_timer_delack(xtp)
176 	void *xtp;
177 {
178 	struct tcpcb *tp = xtp;
179 	struct inpcb *inp;
180 
181 	INP_INFO_RLOCK(&tcbinfo);
182 	inp = tp->t_inpcb;
183 	if (inp == NULL) {
184 		INP_INFO_RUNLOCK(&tcbinfo);
185 		return;
186 	}
187 	INP_LOCK(inp);
188 	INP_INFO_RUNLOCK(&tcbinfo);
189 	if (callout_pending(tp->tt_delack) || !callout_active(tp->tt_delack)) {
190 		INP_UNLOCK(inp);
191 		return;
192 	}
193 	callout_deactivate(tp->tt_delack);
194 
195 	tp->t_flags |= TF_ACKNOW;
196 	tcpstat.tcps_delack++;
197 	(void) tcp_output(tp);
198 	INP_UNLOCK(inp);
199 }
200 
201 void
202 tcp_timer_2msl(xtp)
203 	void *xtp;
204 {
205 	struct tcpcb *tp = xtp;
206 	struct inpcb *inp;
207 #ifdef TCPDEBUG
208 	int ostate;
209 
210 	ostate = tp->t_state;
211 #endif
212 	INP_INFO_WLOCK(&tcbinfo);
213 	inp = tp->t_inpcb;
214 	if (inp == NULL) {
215 		INP_INFO_WUNLOCK(&tcbinfo);
216 		return;
217 	}
218 	INP_LOCK(inp);
219 	tcp_free_sackholes(tp);
220 	if (callout_pending(tp->tt_2msl) || !callout_active(tp->tt_2msl)) {
221 		INP_UNLOCK(tp->t_inpcb);
222 		INP_INFO_WUNLOCK(&tcbinfo);
223 		return;
224 	}
225 	callout_deactivate(tp->tt_2msl);
226 	/*
227 	 * 2 MSL timeout in shutdown went off.  If we're closed but
228 	 * still waiting for peer to close and connection has been idle
229 	 * too long, or if 2MSL time is up from TIME_WAIT, delete connection
230 	 * control block.  Otherwise, check again in a bit.
231 	 */
232 	if (tp->t_state != TCPS_TIME_WAIT &&
233 	    (ticks - tp->t_rcvtime) <= tcp_maxidle)
234 		callout_reset(tp->tt_2msl, tcp_keepintvl,
235 			      tcp_timer_2msl, tp);
236 	else
237 		tp = tcp_close(tp);
238 
239 #ifdef TCPDEBUG
240 	if (tp && (tp->t_inpcb->inp_socket->so_options & SO_DEBUG))
241 		tcp_trace(TA_USER, ostate, tp, (void *)0, (struct tcphdr *)0,
242 			  PRU_SLOWTIMO);
243 #endif
244 	if (tp)
245 		INP_UNLOCK(inp);
246 	INP_INFO_WUNLOCK(&tcbinfo);
247 }
248 
249 /*
250  * The timed wait lists contain references to each of the TCP sessions
251  * currently TIME_WAIT state.  The list pointers, including the list pointers
252  * in each tcptw structure, are protected using the global tcbinfo lock,
253  * which must be held over list iteration and modification.
254  */
255 struct twlist {
256 	LIST_HEAD(, tcptw)	tw_list;
257 	struct tcptw	tw_tail;
258 };
259 #define TWLIST_NLISTS	2
260 static struct twlist twl_2msl[TWLIST_NLISTS];
261 static struct twlist *tw_2msl_list[] = { &twl_2msl[0], &twl_2msl[1], NULL };
262 
263 void
264 tcp_timer_init(void)
265 {
266 	int i;
267 	struct twlist *twl;
268 
269 	for (i = 0; i < TWLIST_NLISTS; i++) {
270 		twl = &twl_2msl[i];
271 		LIST_INIT(&twl->tw_list);
272 		LIST_INSERT_HEAD(&twl->tw_list, &twl->tw_tail, tw_2msl);
273 	}
274 }
275 
276 void
277 tcp_timer_2msl_reset(struct tcptw *tw, int timeo)
278 {
279 	int i;
280 	struct tcptw *tw_tail;
281 
282 	INP_INFO_WLOCK_ASSERT(&tcbinfo);
283 	if (tw->tw_time != 0)
284 		LIST_REMOVE(tw, tw_2msl);
285 	tw->tw_time = timeo + ticks;
286 	i = timeo > tcp_msl ? 1 : 0;
287 	tw_tail = &twl_2msl[i].tw_tail;
288 	LIST_INSERT_BEFORE(tw_tail, tw, tw_2msl);
289 }
290 
291 void
292 tcp_timer_2msl_stop(struct tcptw *tw)
293 {
294 
295 	INP_INFO_WLOCK_ASSERT(&tcbinfo);
296 	if (tw->tw_time != 0)
297 		LIST_REMOVE(tw, tw_2msl);
298 }
299 
300 struct tcptw *
301 tcp_timer_2msl_tw(int reuse)
302 {
303 	struct tcptw *tw, *tw_tail;
304 	struct twlist *twl;
305 	int i;
306 
307 	INP_INFO_WLOCK_ASSERT(&tcbinfo);
308 	for (i = 0; i < 2; i++) {
309 		twl = tw_2msl_list[i];
310 		tw_tail = &twl->tw_tail;
311 		for (;;) {
312 			tw = LIST_FIRST(&twl->tw_list);
313 			if (tw == tw_tail || (!reuse && tw->tw_time > ticks))
314 				break;
315 			INP_LOCK(tw->tw_inpcb);
316 			if (tcp_twclose(tw, reuse) != NULL)
317 				return (tw);
318 		}
319 	}
320 	return (NULL);
321 }
322 
323 void
324 tcp_timer_keep(xtp)
325 	void *xtp;
326 {
327 	struct tcpcb *tp = xtp;
328 	struct tcptemp *t_template;
329 	int s;
330 	struct inpcb *inp;
331 #ifdef TCPDEBUG
332 	int ostate;
333 
334 	ostate = tp->t_state;
335 #endif
336 	s = splnet();
337 	INP_INFO_WLOCK(&tcbinfo);
338 	inp = tp->t_inpcb;
339 	if (!inp) {
340 		INP_INFO_WUNLOCK(&tcbinfo);
341 		splx(s);
342 		return;
343 	}
344 	INP_LOCK(inp);
345 	if (callout_pending(tp->tt_keep) || !callout_active(tp->tt_keep)) {
346 		INP_UNLOCK(inp);
347 		INP_INFO_WUNLOCK(&tcbinfo);
348 		splx(s);
349 		return;
350 	}
351 	callout_deactivate(tp->tt_keep);
352 	/*
353 	 * Keep-alive timer went off; send something
354 	 * or drop connection if idle for too long.
355 	 */
356 	tcpstat.tcps_keeptimeo++;
357 	if (tp->t_state < TCPS_ESTABLISHED)
358 		goto dropit;
359 	if ((always_keepalive || inp->inp_socket->so_options & SO_KEEPALIVE) &&
360 	    tp->t_state <= TCPS_CLOSING) {
361 		if ((ticks - tp->t_rcvtime) >= tcp_keepidle + tcp_maxidle)
362 			goto dropit;
363 		/*
364 		 * Send a packet designed to force a response
365 		 * if the peer is up and reachable:
366 		 * either an ACK if the connection is still alive,
367 		 * or an RST if the peer has closed the connection
368 		 * due to timeout or reboot.
369 		 * Using sequence number tp->snd_una-1
370 		 * causes the transmitted zero-length segment
371 		 * to lie outside the receive window;
372 		 * by the protocol spec, this requires the
373 		 * correspondent TCP to respond.
374 		 */
375 		tcpstat.tcps_keepprobe++;
376 		t_template = tcpip_maketemplate(inp);
377 		if (t_template) {
378 			tcp_respond(tp, t_template->tt_ipgen,
379 				    &t_template->tt_t, (struct mbuf *)NULL,
380 				    tp->rcv_nxt, tp->snd_una - 1, 0);
381 			(void) m_free(dtom(t_template));
382 		}
383 		callout_reset(tp->tt_keep, tcp_keepintvl, tcp_timer_keep, tp);
384 	} else
385 		callout_reset(tp->tt_keep, tcp_keepidle, tcp_timer_keep, tp);
386 
387 #ifdef TCPDEBUG
388 	if (inp->inp_socket->so_options & SO_DEBUG)
389 		tcp_trace(TA_USER, ostate, tp, (void *)0, (struct tcphdr *)0,
390 			  PRU_SLOWTIMO);
391 #endif
392 	INP_UNLOCK(inp);
393 	INP_INFO_WUNLOCK(&tcbinfo);
394 	splx(s);
395 	return;
396 
397 dropit:
398 	tcpstat.tcps_keepdrops++;
399 	tp = tcp_drop(tp, ETIMEDOUT);
400 
401 #ifdef TCPDEBUG
402 	if (tp && (tp->t_inpcb->inp_socket->so_options & SO_DEBUG))
403 		tcp_trace(TA_USER, ostate, tp, (void *)0, (struct tcphdr *)0,
404 			  PRU_SLOWTIMO);
405 #endif
406 	if (tp)
407 		INP_UNLOCK(tp->t_inpcb);
408 	INP_INFO_WUNLOCK(&tcbinfo);
409 	splx(s);
410 }
411 
412 void
413 tcp_timer_persist(xtp)
414 	void *xtp;
415 {
416 	struct tcpcb *tp = xtp;
417 	int s;
418 	struct inpcb *inp;
419 #ifdef TCPDEBUG
420 	int ostate;
421 
422 	ostate = tp->t_state;
423 #endif
424 	s = splnet();
425 	INP_INFO_WLOCK(&tcbinfo);
426 	inp = tp->t_inpcb;
427 	if (!inp) {
428 		INP_INFO_WUNLOCK(&tcbinfo);
429 		splx(s);
430 		return;
431 	}
432 	INP_LOCK(inp);
433 	if (callout_pending(tp->tt_persist) || !callout_active(tp->tt_persist)){
434 		INP_UNLOCK(inp);
435 		INP_INFO_WUNLOCK(&tcbinfo);
436 		splx(s);
437 		return;
438 	}
439 	callout_deactivate(tp->tt_persist);
440 	/*
441 	 * Persistance timer into zero window.
442 	 * Force a byte to be output, if possible.
443 	 */
444 	tcpstat.tcps_persisttimeo++;
445 	/*
446 	 * Hack: if the peer is dead/unreachable, we do not
447 	 * time out if the window is closed.  After a full
448 	 * backoff, drop the connection if the idle time
449 	 * (no responses to probes) reaches the maximum
450 	 * backoff that we would use if retransmitting.
451 	 */
452 	if (tp->t_rxtshift == TCP_MAXRXTSHIFT &&
453 	    ((ticks - tp->t_rcvtime) >= tcp_maxpersistidle ||
454 	     (ticks - tp->t_rcvtime) >= TCP_REXMTVAL(tp) * tcp_totbackoff)) {
455 		tcpstat.tcps_persistdrop++;
456 		tp = tcp_drop(tp, ETIMEDOUT);
457 		goto out;
458 	}
459 	tcp_setpersist(tp);
460 	tp->t_force = 1;
461 	(void) tcp_output(tp);
462 	tp->t_force = 0;
463 
464 out:
465 #ifdef TCPDEBUG
466 	if (tp && tp->t_inpcb->inp_socket->so_options & SO_DEBUG)
467 		tcp_trace(TA_USER, ostate, tp, (void *)0, (struct tcphdr *)0,
468 			  PRU_SLOWTIMO);
469 #endif
470 	if (tp)
471 		INP_UNLOCK(inp);
472 	INP_INFO_WUNLOCK(&tcbinfo);
473 	splx(s);
474 }
475 
476 void
477 tcp_timer_rexmt(xtp)
478 	void *xtp;
479 {
480 	struct tcpcb *tp = xtp;
481 	int s;
482 	int rexmt;
483 	int headlocked;
484 	struct inpcb *inp;
485 #ifdef TCPDEBUG
486 	int ostate;
487 
488 	ostate = tp->t_state;
489 #endif
490 	s = splnet();
491 	INP_INFO_WLOCK(&tcbinfo);
492 	headlocked = 1;
493 	inp = tp->t_inpcb;
494 	if (!inp) {
495 		INP_INFO_WUNLOCK(&tcbinfo);
496 		splx(s);
497 		return;
498 	}
499 	INP_LOCK(inp);
500 	if (callout_pending(tp->tt_rexmt) || !callout_active(tp->tt_rexmt)) {
501 		INP_UNLOCK(inp);
502 		INP_INFO_WUNLOCK(&tcbinfo);
503 		splx(s);
504 		return;
505 	}
506 	callout_deactivate(tp->tt_rexmt);
507 	tcp_free_sackholes(tp);
508 	/*
509 	 * Retransmission timer went off.  Message has not
510 	 * been acked within retransmit interval.  Back off
511 	 * to a longer retransmit interval and retransmit one segment.
512 	 */
513 	if (++tp->t_rxtshift > TCP_MAXRXTSHIFT) {
514 		tp->t_rxtshift = TCP_MAXRXTSHIFT;
515 		tcpstat.tcps_timeoutdrop++;
516 		tp = tcp_drop(tp, tp->t_softerror ?
517 			      tp->t_softerror : ETIMEDOUT);
518 		goto out;
519 	}
520 	INP_INFO_WUNLOCK(&tcbinfo);
521 	headlocked = 0;
522 	if (tp->t_rxtshift == 1) {
523 		/*
524 		 * first retransmit; record ssthresh and cwnd so they can
525 		 * be recovered if this turns out to be a "bad" retransmit.
526 		 * A retransmit is considered "bad" if an ACK for this
527 		 * segment is received within RTT/2 interval; the assumption
528 		 * here is that the ACK was already in flight.  See
529 		 * "On Estimating End-to-End Network Path Properties" by
530 		 * Allman and Paxson for more details.
531 		 */
532 		tp->snd_cwnd_prev = tp->snd_cwnd;
533 		tp->snd_ssthresh_prev = tp->snd_ssthresh;
534 		tp->snd_recover_prev = tp->snd_recover;
535 		if (IN_FASTRECOVERY(tp))
536 		  tp->t_flags |= TF_WASFRECOVERY;
537 		else
538 		  tp->t_flags &= ~TF_WASFRECOVERY;
539 		tp->t_badrxtwin = ticks + (tp->t_srtt >> (TCP_RTT_SHIFT + 1));
540 	}
541 	tcpstat.tcps_rexmttimeo++;
542 	if (tp->t_state == TCPS_SYN_SENT)
543 		rexmt = TCP_REXMTVAL(tp) * tcp_syn_backoff[tp->t_rxtshift];
544 	else
545 		rexmt = TCP_REXMTVAL(tp) * tcp_backoff[tp->t_rxtshift];
546 	TCPT_RANGESET(tp->t_rxtcur, rexmt,
547 		      tp->t_rttmin, TCPTV_REXMTMAX);
548 	/*
549 	 * Disable rfc1323 if we havn't got any response to
550 	 * our third SYN to work-around some broken terminal servers
551 	 * (most of which have hopefully been retired) that have bad VJ
552 	 * header compression code which trashes TCP segments containing
553 	 * unknown-to-them TCP options.
554 	 */
555 	if ((tp->t_state == TCPS_SYN_SENT) && (tp->t_rxtshift == 3))
556 		tp->t_flags &= ~(TF_REQ_SCALE|TF_REQ_TSTMP);
557 	/*
558 	 * If we backed off this far, our srtt estimate is probably bogus.
559 	 * Clobber it so we'll take the next rtt measurement as our srtt;
560 	 * move the current srtt into rttvar to keep the current
561 	 * retransmit times until then.
562 	 */
563 	if (tp->t_rxtshift > TCP_MAXRXTSHIFT / 4) {
564 #ifdef INET6
565 		if ((tp->t_inpcb->inp_vflag & INP_IPV6) != 0)
566 			in6_losing(tp->t_inpcb);
567 		else
568 #endif
569 		tp->t_rttvar += (tp->t_srtt >> TCP_RTT_SHIFT);
570 		tp->t_srtt = 0;
571 	}
572 	tp->snd_nxt = tp->snd_una;
573 	tp->snd_recover = tp->snd_max;
574 	/*
575 	 * Force a segment to be sent.
576 	 */
577 	tp->t_flags |= TF_ACKNOW;
578 	/*
579 	 * If timing a segment in this window, stop the timer.
580 	 */
581 	tp->t_rtttime = 0;
582 	/*
583 	 * Close the congestion window down to one segment
584 	 * (we'll open it by one segment for each ack we get).
585 	 * Since we probably have a window's worth of unacked
586 	 * data accumulated, this "slow start" keeps us from
587 	 * dumping all that data as back-to-back packets (which
588 	 * might overwhelm an intermediate gateway).
589 	 *
590 	 * There are two phases to the opening: Initially we
591 	 * open by one mss on each ack.  This makes the window
592 	 * size increase exponentially with time.  If the
593 	 * window is larger than the path can handle, this
594 	 * exponential growth results in dropped packet(s)
595 	 * almost immediately.  To get more time between
596 	 * drops but still "push" the network to take advantage
597 	 * of improving conditions, we switch from exponential
598 	 * to linear window opening at some threshhold size.
599 	 * For a threshhold, we use half the current window
600 	 * size, truncated to a multiple of the mss.
601 	 *
602 	 * (the minimum cwnd that will give us exponential
603 	 * growth is 2 mss.  We don't allow the threshhold
604 	 * to go below this.)
605 	 */
606 	{
607 		u_int win = min(tp->snd_wnd, tp->snd_cwnd) / 2 / tp->t_maxseg;
608 		if (win < 2)
609 			win = 2;
610 		tp->snd_cwnd = tp->t_maxseg;
611 		tp->snd_ssthresh = win * tp->t_maxseg;
612 		tp->t_dupacks = 0;
613 	}
614 	EXIT_FASTRECOVERY(tp);
615 	(void) tcp_output(tp);
616 
617 out:
618 #ifdef TCPDEBUG
619 	if (tp && (tp->t_inpcb->inp_socket->so_options & SO_DEBUG))
620 		tcp_trace(TA_USER, ostate, tp, (void *)0, (struct tcphdr *)0,
621 			  PRU_SLOWTIMO);
622 #endif
623 	if (tp)
624 		INP_UNLOCK(inp);
625 	if (headlocked)
626 		INP_INFO_WUNLOCK(&tcbinfo);
627 	splx(s);
628 }
629