tcp_timer.c revision 1.89
1/*	$NetBSD: tcp_timer.c,v 1.89 2015/08/24 22:21:26 pooka Exp $	*/
2
3/*
4 * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 * 1. Redistributions of source code must retain the above copyright
11 *    notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 *    notice, this list of conditions and the following disclaimer in the
14 *    documentation and/or other materials provided with the distribution.
15 * 3. Neither the name of the project nor the names of its contributors
16 *    may be used to endorse or promote products derived from this software
17 *    without specific prior written permission.
18 *
19 * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND
20 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22 * ARE DISCLAIMED.  IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE
23 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29 * SUCH DAMAGE.
30 */
31
32/*-
33 * Copyright (c) 1997, 1998, 2001, 2005 The NetBSD Foundation, Inc.
34 * All rights reserved.
35 *
36 * This code is derived from software contributed to The NetBSD Foundation
37 * by Jason R. Thorpe and Kevin M. Lahey of the Numerical Aerospace Simulation
38 * Facility, NASA Ames Research Center.
39 * This code is derived from software contributed to The NetBSD Foundation
40 * by Charles M. Hannum.
41 *
42 * Redistribution and use in source and binary forms, with or without
43 * modification, are permitted provided that the following conditions
44 * are met:
45 * 1. Redistributions of source code must retain the above copyright
46 *    notice, this list of conditions and the following disclaimer.
47 * 2. Redistributions in binary form must reproduce the above copyright
48 *    notice, this list of conditions and the following disclaimer in the
49 *    documentation and/or other materials provided with the distribution.
50 *
51 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
52 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
53 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
54 * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
55 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
56 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
57 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
58 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
59 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
60 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
61 * POSSIBILITY OF SUCH DAMAGE.
62 */
63
64/*
65 * Copyright (c) 1982, 1986, 1988, 1990, 1993, 1995
66 *	The Regents of the University of California.  All rights reserved.
67 *
68 * Redistribution and use in source and binary forms, with or without
69 * modification, are permitted provided that the following conditions
70 * are met:
71 * 1. Redistributions of source code must retain the above copyright
72 *    notice, this list of conditions and the following disclaimer.
73 * 2. Redistributions in binary form must reproduce the above copyright
74 *    notice, this list of conditions and the following disclaimer in the
75 *    documentation and/or other materials provided with the distribution.
76 * 3. Neither the name of the University nor the names of its contributors
77 *    may be used to endorse or promote products derived from this software
78 *    without specific prior written permission.
79 *
80 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
81 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
82 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
83 * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
84 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
85 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
86 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
87 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
88 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
89 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
90 * SUCH DAMAGE.
91 *
92 *	@(#)tcp_timer.c	8.2 (Berkeley) 5/24/95
93 */
94
95#include <sys/cdefs.h>
96__KERNEL_RCSID(0, "$NetBSD: tcp_timer.c,v 1.89 2015/08/24 22:21:26 pooka Exp $");
97
98#ifdef _KERNEL_OPT
99#include "opt_inet.h"
100#include "opt_tcp_debug.h"
101#endif
102
103#include <sys/param.h>
104#include <sys/systm.h>
105#include <sys/mbuf.h>
106#include <sys/socket.h>
107#include <sys/socketvar.h>
108#include <sys/protosw.h>
109#include <sys/errno.h>
110#include <sys/kernel.h>
111
112#include <net/if.h>
113#include <net/route.h>
114
115#include <netinet/in.h>
116#include <netinet/in_systm.h>
117#include <netinet/ip.h>
118#include <netinet/in_pcb.h>
119#include <netinet/ip_var.h>
120#include <netinet/ip_icmp.h>
121
122#ifdef INET6
123#ifndef INET
124#include <netinet/in.h>
125#endif
126#include <netinet/ip6.h>
127#include <netinet6/in6_pcb.h>
128#endif
129
130#include <netinet/tcp.h>
131#include <netinet/tcp_fsm.h>
132#include <netinet/tcp_seq.h>
133#include <netinet/tcp_timer.h>
134#include <netinet/tcp_var.h>
135#include <netinet/tcp_private.h>
136#include <netinet/tcp_congctl.h>
137#include <netinet/tcpip.h>
138#ifdef TCP_DEBUG
139#include <netinet/tcp_debug.h>
140#endif
141
142/*
143 * Various tunable timer parameters.  These are initialized in tcp_init(),
144 * unless they are patched.
145 */
146u_int	tcp_keepinit = 0;
147u_int	tcp_keepidle = 0;
148u_int	tcp_keepintvl = 0;
149u_int	tcp_keepcnt = 0;		/* max idle probes */
150
151int	tcp_maxpersistidle = 0;		/* max idle time in persist */
152
153/*
154 * Time to delay the ACK.  This is initialized in tcp_init(), unless
155 * its patched.
156 */
157int	tcp_delack_ticks = 0;
158
159void	tcp_timer_rexmt(void *);
160void	tcp_timer_persist(void *);
161void	tcp_timer_keep(void *);
162void	tcp_timer_2msl(void *);
163
164const tcp_timer_func_t tcp_timer_funcs[TCPT_NTIMERS] = {
165	tcp_timer_rexmt,
166	tcp_timer_persist,
167	tcp_timer_keep,
168	tcp_timer_2msl,
169};
170
171/*
172 * Timer state initialization, called from tcp_init().
173 */
174void
175tcp_timer_init(void)
176{
177
178	if (tcp_keepinit == 0)
179		tcp_keepinit = TCPTV_KEEP_INIT;
180
181	if (tcp_keepidle == 0)
182		tcp_keepidle = TCPTV_KEEP_IDLE;
183
184	if (tcp_keepintvl == 0)
185		tcp_keepintvl = TCPTV_KEEPINTVL;
186
187	if (tcp_keepcnt == 0)
188		tcp_keepcnt = TCPTV_KEEPCNT;
189
190	if (tcp_maxpersistidle == 0)
191		tcp_maxpersistidle = TCPTV_KEEP_IDLE;
192
193	if (tcp_delack_ticks == 0)
194		tcp_delack_ticks = TCP_DELACK_TICKS;
195}
196
197/*
198 * Callout to process delayed ACKs for a TCPCB.
199 */
200void
201tcp_delack(void *arg)
202{
203	struct tcpcb *tp = arg;
204
205	/*
206	 * If tcp_output() wasn't able to transmit the ACK
207	 * for whatever reason, it will restart the delayed
208	 * ACK callout.
209	 */
210
211	mutex_enter(softnet_lock);
212	if ((tp->t_flags & (TF_DEAD | TF_DELACK)) != TF_DELACK) {
213		mutex_exit(softnet_lock);
214		return;
215	}
216	if (!callout_expired(&tp->t_delack_ch)) {
217		mutex_exit(softnet_lock);
218		return;
219	}
220
221	tp->t_flags |= TF_ACKNOW;
222	KERNEL_LOCK(1, NULL);
223	(void) tcp_output(tp);
224	KERNEL_UNLOCK_ONE(NULL);
225	mutex_exit(softnet_lock);
226}
227
228/*
229 * Tcp protocol timeout routine called every 500 ms.
230 * Updates the timers in all active tcb's and
231 * causes finite state machine actions if timers expire.
232 */
233void
234tcp_slowtimo(void *arg)
235{
236
237	mutex_enter(softnet_lock);
238	tcp_iss_seq += TCP_ISSINCR;			/* increment iss */
239	tcp_now++;					/* for timestamps */
240	mutex_exit(softnet_lock);
241
242	callout_schedule(&tcp_slowtimo_ch, hz / PR_SLOWHZ);
243}
244
245/*
246 * Cancel all timers for TCP tp.
247 */
248void
249tcp_canceltimers(struct tcpcb *tp)
250{
251	int i;
252
253	for (i = 0; i < TCPT_NTIMERS; i++)
254		TCP_TIMER_DISARM(tp, i);
255}
256
257const int	tcp_backoff[TCP_MAXRXTSHIFT + 1] =
258    { 1, 2, 4, 8, 16, 32, 64, 64, 64, 64, 64, 64, 64 };
259
260const int	tcp_totbackoff = 511;	/* sum of tcp_backoff[] */
261
262/*
263 * TCP timer processing.
264 */
265
266void
267tcp_timer_rexmt(void *arg)
268{
269	struct tcpcb *tp = arg;
270	uint32_t rto;
271#ifdef TCP_DEBUG
272	struct socket *so = NULL;
273	short ostate;
274#endif
275
276	mutex_enter(softnet_lock);
277	if ((tp->t_flags & TF_DEAD) != 0) {
278		mutex_exit(softnet_lock);
279		return;
280	}
281	if (!callout_expired(&tp->t_timer[TCPT_REXMT])) {
282		mutex_exit(softnet_lock);
283		return;
284	}
285
286	KERNEL_LOCK(1, NULL);
287	if ((tp->t_flags & TF_PMTUD_PEND) && tp->t_inpcb &&
288	    SEQ_GEQ(tp->t_pmtud_th_seq, tp->snd_una) &&
289	    SEQ_LT(tp->t_pmtud_th_seq, (int)(tp->snd_una + tp->t_ourmss))) {
290		extern struct sockaddr_in icmpsrc;
291		struct icmp icmp;
292
293		tp->t_flags &= ~TF_PMTUD_PEND;
294
295		/* XXX create fake icmp message with relevant entries */
296		icmp.icmp_nextmtu = tp->t_pmtud_nextmtu;
297		icmp.icmp_ip.ip_len = tp->t_pmtud_ip_len;
298		icmp.icmp_ip.ip_hl = tp->t_pmtud_ip_hl;
299		icmpsrc.sin_addr = tp->t_inpcb->inp_faddr;
300		icmp_mtudisc(&icmp, icmpsrc.sin_addr);
301
302		/*
303		 * Notify all connections to the same peer about
304		 * new mss and trigger retransmit.
305		 */
306		in_pcbnotifyall(&tcbtable, icmpsrc.sin_addr, EMSGSIZE,
307		    tcp_mtudisc);
308		KERNEL_UNLOCK_ONE(NULL);
309		mutex_exit(softnet_lock);
310 		return;
311 	}
312#ifdef TCP_DEBUG
313#ifdef INET
314	if (tp->t_inpcb)
315		so = tp->t_inpcb->inp_socket;
316#endif
317#ifdef INET6
318	if (tp->t_in6pcb)
319		so = tp->t_in6pcb->in6p_socket;
320#endif
321	ostate = tp->t_state;
322#endif /* TCP_DEBUG */
323
324	/*
325	 * Clear the SACK scoreboard, reset FACK estimate.
326	 */
327	tcp_free_sackholes(tp);
328	tp->snd_fack = tp->snd_una;
329
330	/*
331	 * Retransmission timer went off.  Message has not
332	 * been acked within retransmit interval.  Back off
333	 * to a longer retransmit interval and retransmit one segment.
334	 */
335
336	if (++tp->t_rxtshift > TCP_MAXRXTSHIFT) {
337		tp->t_rxtshift = TCP_MAXRXTSHIFT;
338		TCP_STATINC(TCP_STAT_TIMEOUTDROP);
339		tp = tcp_drop(tp, tp->t_softerror ?
340		    tp->t_softerror : ETIMEDOUT);
341		goto out;
342	}
343	TCP_STATINC(TCP_STAT_REXMTTIMEO);
344	rto = TCP_REXMTVAL(tp);
345	if (rto < tp->t_rttmin)
346		rto = tp->t_rttmin;
347	TCPT_RANGESET(tp->t_rxtcur, rto * tcp_backoff[tp->t_rxtshift],
348	    tp->t_rttmin, TCPTV_REXMTMAX);
349	TCP_TIMER_ARM(tp, TCPT_REXMT, tp->t_rxtcur);
350
351	/*
352	 * If we are losing and we are trying path MTU discovery,
353	 * try turning it off.  This will avoid black holes in
354	 * the network which suppress or fail to send "packet
355	 * too big" ICMP messages.  We should ideally do
356	 * lots more sophisticated searching to find the right
357	 * value here...
358	 */
359	if (tp->t_mtudisc && tp->t_rxtshift > TCP_MAXRXTSHIFT / 6) {
360		TCP_STATINC(TCP_STAT_PMTUBLACKHOLE);
361
362#ifdef INET
363		/* try turning PMTUD off */
364		if (tp->t_inpcb)
365			tp->t_mtudisc = 0;
366#endif
367#ifdef INET6
368		/* try using IPv6 minimum MTU */
369		if (tp->t_in6pcb)
370			tp->t_mtudisc = 0;
371#endif
372
373		/* XXX: more sophisticated Black hole recovery code? */
374	}
375
376	/*
377	 * If losing, let the lower level know and try for
378	 * a better route.  Also, if we backed off this far,
379	 * our srtt estimate is probably bogus.  Clobber it
380	 * so we'll take the next rtt measurement as our srtt;
381	 * move the current srtt into rttvar to keep the current
382	 * retransmit times until then.
383	 */
384	if (tp->t_rxtshift > TCP_MAXRXTSHIFT / 4) {
385#ifdef INET
386		if (tp->t_inpcb)
387			in_losing(tp->t_inpcb);
388#endif
389#ifdef INET6
390		if (tp->t_in6pcb)
391			in6_losing(tp->t_in6pcb);
392#endif
393		/*
394		 * This operation is not described in RFC2988.  The
395		 * point is to keep srtt+4*rttvar constant, so we
396		 * should shift right 2 bits to divide by 4, and then
397		 * shift right one bit because the storage
398		 * representation of rttvar is 1/16s vs 1/32s for
399		 * srtt.
400		 */
401		tp->t_rttvar += (tp->t_srtt >> TCP_RTT_SHIFT);
402		tp->t_srtt = 0;
403	}
404	tp->snd_nxt = tp->snd_una;
405	tp->snd_high = tp->snd_max;
406	/*
407	 * If timing a segment in this window, stop the timer.
408	 */
409	tp->t_rtttime = 0;
410	/*
411	 * Remember if we are retransmitting a SYN, because if
412	 * we do, set the initial congestion window must be set
413	 * to 1 segment.
414	 */
415	if (tp->t_state == TCPS_SYN_SENT)
416		tp->t_flags |= TF_SYN_REXMT;
417
418	/*
419	 * Adjust congestion control parameters.
420	 */
421	tp->t_congctl->slow_retransmit(tp);
422
423	(void) tcp_output(tp);
424
425 out:
426#ifdef TCP_DEBUG
427	if (tp && so->so_options & SO_DEBUG)
428		tcp_trace(TA_USER, ostate, tp, NULL,
429		    PRU_SLOWTIMO | (TCPT_REXMT << 8));
430#endif
431	KERNEL_UNLOCK_ONE(NULL);
432	mutex_exit(softnet_lock);
433}
434
435void
436tcp_timer_persist(void *arg)
437{
438	struct tcpcb *tp = arg;
439	uint32_t rto;
440#ifdef TCP_DEBUG
441	struct socket *so = NULL;
442	short ostate;
443#endif
444
445	mutex_enter(softnet_lock);
446	if ((tp->t_flags & TF_DEAD) != 0) {
447		mutex_exit(softnet_lock);
448		return;
449	}
450	if (!callout_expired(&tp->t_timer[TCPT_PERSIST])) {
451		mutex_exit(softnet_lock);
452		return;
453	}
454
455	KERNEL_LOCK(1, NULL);
456#ifdef TCP_DEBUG
457#ifdef INET
458	if (tp->t_inpcb)
459		so = tp->t_inpcb->inp_socket;
460#endif
461#ifdef INET6
462	if (tp->t_in6pcb)
463		so = tp->t_in6pcb->in6p_socket;
464#endif
465
466	ostate = tp->t_state;
467#endif /* TCP_DEBUG */
468
469	/*
470	 * Persistance timer into zero window.
471	 * Force a byte to be output, if possible.
472	 */
473
474	/*
475	 * Hack: if the peer is dead/unreachable, we do not
476	 * time out if the window is closed.  After a full
477	 * backoff, drop the connection if the idle time
478	 * (no responses to probes) reaches the maximum
479	 * backoff that we would use if retransmitting.
480	 */
481	rto = TCP_REXMTVAL(tp);
482	if (rto < tp->t_rttmin)
483		rto = tp->t_rttmin;
484	if (tp->t_rxtshift == TCP_MAXRXTSHIFT &&
485	    ((tcp_now - tp->t_rcvtime) >= tcp_maxpersistidle ||
486	    (tcp_now - tp->t_rcvtime) >= rto * tcp_totbackoff)) {
487		TCP_STATINC(TCP_STAT_PERSISTDROPS);
488		tp = tcp_drop(tp, ETIMEDOUT);
489		goto out;
490	}
491	TCP_STATINC(TCP_STAT_PERSISTTIMEO);
492	tcp_setpersist(tp);
493	tp->t_force = 1;
494	(void) tcp_output(tp);
495	tp->t_force = 0;
496
497 out:
498#ifdef TCP_DEBUG
499	if (tp && so->so_options & SO_DEBUG)
500		tcp_trace(TA_USER, ostate, tp, NULL,
501		    PRU_SLOWTIMO | (TCPT_PERSIST << 8));
502#endif
503	KERNEL_UNLOCK_ONE(NULL);
504	mutex_exit(softnet_lock);
505}
506
507void
508tcp_timer_keep(void *arg)
509{
510	struct tcpcb *tp = arg;
511	struct socket *so = NULL;	/* Quell compiler warning */
512#ifdef TCP_DEBUG
513	short ostate;
514#endif
515
516	mutex_enter(softnet_lock);
517	if ((tp->t_flags & TF_DEAD) != 0) {
518		mutex_exit(softnet_lock);
519		return;
520	}
521	if (!callout_expired(&tp->t_timer[TCPT_KEEP])) {
522		mutex_exit(softnet_lock);
523		return;
524	}
525
526	KERNEL_LOCK(1, NULL);
527
528#ifdef TCP_DEBUG
529	ostate = tp->t_state;
530#endif /* TCP_DEBUG */
531
532	/*
533	 * Keep-alive timer went off; send something
534	 * or drop connection if idle for too long.
535	 */
536
537	TCP_STATINC(TCP_STAT_KEEPTIMEO);
538	if (TCPS_HAVEESTABLISHED(tp->t_state) == 0)
539		goto dropit;
540#ifdef INET
541	if (tp->t_inpcb)
542		so = tp->t_inpcb->inp_socket;
543#endif
544#ifdef INET6
545	if (tp->t_in6pcb)
546		so = tp->t_in6pcb->in6p_socket;
547#endif
548	KASSERT(so != NULL);
549	if (so->so_options & SO_KEEPALIVE &&
550	    tp->t_state <= TCPS_CLOSE_WAIT) {
551	    	if ((tp->t_maxidle > 0) &&
552		    ((tcp_now - tp->t_rcvtime) >=
553		     tp->t_keepidle + tp->t_maxidle))
554			goto dropit;
555		/*
556		 * Send a packet designed to force a response
557		 * if the peer is up and reachable:
558		 * either an ACK if the connection is still alive,
559		 * or an RST if the peer has closed the connection
560		 * due to timeout or reboot.
561		 * Using sequence number tp->snd_una-1
562		 * causes the transmitted zero-length segment
563		 * to lie outside the receive window;
564		 * by the protocol spec, this requires the
565		 * correspondent TCP to respond.
566		 */
567		TCP_STATINC(TCP_STAT_KEEPPROBE);
568		if (tcp_compat_42) {
569			/*
570			 * The keepalive packet must have nonzero
571			 * length to get a 4.2 host to respond.
572			 */
573			(void)tcp_respond(tp, tp->t_template,
574			    NULL, NULL, tp->rcv_nxt - 1,
575			    tp->snd_una - 1, 0);
576		} else {
577			(void)tcp_respond(tp, tp->t_template,
578			    NULL, NULL, tp->rcv_nxt,
579			    tp->snd_una - 1, 0);
580		}
581		TCP_TIMER_ARM(tp, TCPT_KEEP, tp->t_keepintvl);
582	} else
583		TCP_TIMER_ARM(tp, TCPT_KEEP, tp->t_keepidle);
584
585#ifdef TCP_DEBUG
586	if (tp && so->so_options & SO_DEBUG)
587		tcp_trace(TA_USER, ostate, tp, NULL,
588		    PRU_SLOWTIMO | (TCPT_KEEP << 8));
589#endif
590	KERNEL_UNLOCK_ONE(NULL);
591	mutex_exit(softnet_lock);
592	return;
593
594 dropit:
595	TCP_STATINC(TCP_STAT_KEEPDROPS);
596	(void) tcp_drop(tp, ETIMEDOUT);
597	KERNEL_UNLOCK_ONE(NULL);
598	mutex_exit(softnet_lock);
599}
600
601void
602tcp_timer_2msl(void *arg)
603{
604	struct tcpcb *tp = arg;
605#ifdef TCP_DEBUG
606	struct socket *so = NULL;
607	short ostate;
608#endif
609
610	mutex_enter(softnet_lock);
611	if ((tp->t_flags & TF_DEAD) != 0) {
612		mutex_exit(softnet_lock);
613		return;
614	}
615	if (!callout_expired(&tp->t_timer[TCPT_2MSL])) {
616		mutex_exit(softnet_lock);
617		return;
618	}
619
620	/*
621	 * 2 MSL timeout went off, clear the SACK scoreboard, reset
622	 * the FACK estimate.
623	 */
624	KERNEL_LOCK(1, NULL);
625	tcp_free_sackholes(tp);
626	tp->snd_fack = tp->snd_una;
627
628#ifdef TCP_DEBUG
629#ifdef INET
630	if (tp->t_inpcb)
631		so = tp->t_inpcb->inp_socket;
632#endif
633#ifdef INET6
634	if (tp->t_in6pcb)
635		so = tp->t_in6pcb->in6p_socket;
636#endif
637
638	ostate = tp->t_state;
639#endif /* TCP_DEBUG */
640
641	/*
642	 * 2 MSL timeout in shutdown went off.  If we're closed but
643	 * still waiting for peer to close and connection has been idle
644	 * too long, or if 2MSL time is up from TIME_WAIT, delete connection
645	 * control block.  Otherwise, check again in a bit.
646	 */
647	if (tp->t_state != TCPS_TIME_WAIT &&
648	    ((tp->t_maxidle == 0) ||
649	    ((tcp_now - tp->t_rcvtime) <= tp->t_maxidle)))
650	    TCP_TIMER_ARM(tp, TCPT_2MSL, tp->t_keepintvl);
651	else
652		tp = tcp_close(tp);
653
654#ifdef TCP_DEBUG
655	if (tp && so->so_options & SO_DEBUG)
656		tcp_trace(TA_USER, ostate, tp, NULL,
657		    PRU_SLOWTIMO | (TCPT_2MSL << 8));
658#endif
659	mutex_exit(softnet_lock);
660	KERNEL_UNLOCK_ONE(NULL);
661}
662