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