xref: /netbsd-src/sys/netinet/tcp_timer.c (revision 7c3f385475147b6e1c4753f2bee961630e2dfc40)
1 /*	$NetBSD: tcp_timer.c,v 1.79 2008/04/12 05:58:22 thorpej 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.79 2008/04/12 05:58:22 thorpej 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  * Return how many timers are currently being invoked.
205  */
206 int
207 tcp_timers_invoking(struct tcpcb *tp)
208 {
209 	int i;
210 	int count = 0;
211 
212 	for (i = 0; i < TCPT_NTIMERS; i++)
213 		if (callout_invoking(&tp->t_timer[i]))
214 			count++;
215 	if (callout_invoking(&tp->t_delack_ch))
216 		count++;
217 
218 	return count;
219 }
220 
221 /*
222  * Callout to process delayed ACKs for a TCPCB.
223  */
224 void
225 tcp_delack(void *arg)
226 {
227 	struct tcpcb *tp = arg;
228 	int s;
229 
230 	/*
231 	 * If tcp_output() wasn't able to transmit the ACK
232 	 * for whatever reason, it will restart the delayed
233 	 * ACK callout.
234 	 */
235 
236 	s = splsoftnet();
237 	callout_ack(&tp->t_delack_ch);
238 	if (tcp_isdead(tp)) {
239 		splx(s);
240 		return;
241 	}
242 
243 	tp->t_flags |= TF_ACKNOW;
244 	(void) tcp_output(tp);
245 	splx(s);
246 }
247 
248 /*
249  * Tcp protocol timeout routine called every 500 ms.
250  * Updates the timers in all active tcb's and
251  * causes finite state machine actions if timers expire.
252  */
253 void
254 tcp_slowtimo(void)
255 {
256 	int s;
257 
258 	s = splsoftnet();
259 	tcp_iss_seq += TCP_ISSINCR;			/* increment iss */
260 	tcp_now++;					/* for timestamps */
261 	splx(s);
262 }
263 
264 /*
265  * Cancel all timers for TCP tp.
266  */
267 void
268 tcp_canceltimers(struct tcpcb *tp)
269 {
270 	int i;
271 
272 	for (i = 0; i < TCPT_NTIMERS; i++)
273 		TCP_TIMER_DISARM(tp, i);
274 }
275 
276 const int	tcp_backoff[TCP_MAXRXTSHIFT + 1] =
277     { 1, 2, 4, 8, 16, 32, 64, 64, 64, 64, 64, 64, 64 };
278 
279 const int	tcp_totbackoff = 511;	/* sum of tcp_backoff[] */
280 
281 /*
282  * TCP timer processing.
283  */
284 
285 void
286 tcp_timer_rexmt(void *arg)
287 {
288 	struct tcpcb *tp = arg;
289 	uint32_t rto;
290 	int s;
291 #ifdef TCP_DEBUG
292 	struct socket *so = NULL;
293 	short ostate;
294 #endif
295 
296 	s = splsoftnet();
297 	callout_ack(&tp->t_timer[TCPT_REXMT]);
298 	if (tcp_isdead(tp)) {
299 		splx(s);
300 		return;
301 	}
302 
303 	if ((tp->t_flags & TF_PMTUD_PEND) && tp->t_inpcb &&
304 	    SEQ_GEQ(tp->t_pmtud_th_seq, tp->snd_una) &&
305 	    SEQ_LT(tp->t_pmtud_th_seq, (int)(tp->snd_una + tp->t_ourmss))) {
306 		extern struct sockaddr_in icmpsrc;
307 		struct icmp icmp;
308 
309 		tp->t_flags &= ~TF_PMTUD_PEND;
310 
311 		/* XXX create fake icmp message with relevant entries */
312 		icmp.icmp_nextmtu = tp->t_pmtud_nextmtu;
313 		icmp.icmp_ip.ip_len = tp->t_pmtud_ip_len;
314 		icmp.icmp_ip.ip_hl = tp->t_pmtud_ip_hl;
315 		icmpsrc.sin_addr = tp->t_inpcb->inp_faddr;
316 		icmp_mtudisc(&icmp, icmpsrc.sin_addr);
317 
318 		/*
319 		 * Notify all connections to the same peer about
320 		 * new mss and trigger retransmit.
321 		 */
322 		in_pcbnotifyall(&tcbtable, icmpsrc.sin_addr, EMSGSIZE,
323 		    tcp_mtudisc);
324  		splx(s);
325  		return;
326  	}
327 #ifdef TCP_DEBUG
328 #ifdef INET
329 	if (tp->t_inpcb)
330 		so = tp->t_inpcb->inp_socket;
331 #endif
332 #ifdef INET6
333 	if (tp->t_in6pcb)
334 		so = tp->t_in6pcb->in6p_socket;
335 #endif
336 	ostate = tp->t_state;
337 #endif /* TCP_DEBUG */
338 
339 	/*
340 	 * Clear the SACK scoreboard, reset FACK estimate.
341 	 */
342 	tcp_free_sackholes(tp);
343 	tp->snd_fack = tp->snd_una;
344 
345 	/*
346 	 * Retransmission timer went off.  Message has not
347 	 * been acked within retransmit interval.  Back off
348 	 * to a longer retransmit interval and retransmit one segment.
349 	 */
350 
351 	if (++tp->t_rxtshift > TCP_MAXRXTSHIFT) {
352 		tp->t_rxtshift = TCP_MAXRXTSHIFT;
353 		TCP_STATINC(TCP_STAT_TIMEOUTDROP);
354 		tp = tcp_drop(tp, tp->t_softerror ?
355 		    tp->t_softerror : ETIMEDOUT);
356 		goto out;
357 	}
358 	TCP_STATINC(TCP_STAT_REXMTTIMEO);
359 	rto = TCP_REXMTVAL(tp);
360 	if (rto < tp->t_rttmin)
361 		rto = tp->t_rttmin;
362 	TCPT_RANGESET(tp->t_rxtcur, rto * tcp_backoff[tp->t_rxtshift],
363 	    tp->t_rttmin, TCPTV_REXMTMAX);
364 	TCP_TIMER_ARM(tp, TCPT_REXMT, tp->t_rxtcur);
365 
366 	/*
367 	 * If we are losing and we are trying path MTU discovery,
368 	 * try turning it off.  This will avoid black holes in
369 	 * the network which suppress or fail to send "packet
370 	 * too big" ICMP messages.  We should ideally do
371 	 * lots more sophisticated searching to find the right
372 	 * value here...
373 	 */
374 	if (tp->t_mtudisc && tp->t_rxtshift > TCP_MAXRXTSHIFT / 6) {
375 		TCP_STATINC(TCP_STAT_PMTUBLACKHOLE);
376 
377 #ifdef INET
378 		/* try turning PMTUD off */
379 		if (tp->t_inpcb)
380 			tp->t_mtudisc = 0;
381 #endif
382 #ifdef INET6
383 		/* try using IPv6 minimum MTU */
384 		if (tp->t_in6pcb)
385 			tp->t_mtudisc = 0;
386 #endif
387 
388 		/* XXX: more sophisticated Black hole recovery code? */
389 	}
390 
391 	/*
392 	 * If losing, let the lower level know and try for
393 	 * a better route.  Also, if we backed off this far,
394 	 * our srtt estimate is probably bogus.  Clobber it
395 	 * so we'll take the next rtt measurement as our srtt;
396 	 * move the current srtt into rttvar to keep the current
397 	 * retransmit times until then.
398 	 */
399 	if (tp->t_rxtshift > TCP_MAXRXTSHIFT / 4) {
400 #ifdef INET
401 		if (tp->t_inpcb)
402 			in_losing(tp->t_inpcb);
403 #endif
404 #ifdef INET6
405 		if (tp->t_in6pcb)
406 			in6_losing(tp->t_in6pcb);
407 #endif
408 		tp->t_rttvar += (tp->t_srtt >> TCP_RTT_SHIFT);
409 		tp->t_srtt = 0;
410 	}
411 	tp->snd_nxt = tp->snd_una;
412 	tp->snd_high = tp->snd_max;
413 	/*
414 	 * If timing a segment in this window, stop the timer.
415 	 */
416 	tp->t_rtttime = 0;
417 	/*
418 	 * Remember if we are retransmitting a SYN, because if
419 	 * we do, set the initial congestion window must be set
420 	 * to 1 segment.
421 	 */
422 	if (tp->t_state == TCPS_SYN_SENT)
423 		tp->t_flags |= TF_SYN_REXMT;
424 
425 	/*
426 	 * Adjust congestion control parameters.
427 	 */
428 	tp->t_congctl->slow_retransmit(tp);
429 
430 	(void) tcp_output(tp);
431 
432  out:
433 #ifdef TCP_DEBUG
434 	if (tp && so->so_options & SO_DEBUG)
435 		tcp_trace(TA_USER, ostate, tp, NULL,
436 		    PRU_SLOWTIMO | (TCPT_REXMT << 8));
437 #endif
438 	splx(s);
439 }
440 
441 void
442 tcp_timer_persist(void *arg)
443 {
444 	struct tcpcb *tp = arg;
445 	uint32_t rto;
446 	int s;
447 #ifdef TCP_DEBUG
448 	struct socket *so = NULL;
449 	short ostate;
450 #endif
451 
452 	s = splsoftnet();
453 	callout_ack(&tp->t_timer[TCPT_PERSIST]);
454 	if (tcp_isdead(tp)) {
455 		splx(s);
456 		return;
457 	}
458 
459 #ifdef TCP_DEBUG
460 #ifdef INET
461 	if (tp->t_inpcb)
462 		so = tp->t_inpcb->inp_socket;
463 #endif
464 #ifdef INET6
465 	if (tp->t_in6pcb)
466 		so = tp->t_in6pcb->in6p_socket;
467 #endif
468 
469 	ostate = tp->t_state;
470 #endif /* TCP_DEBUG */
471 
472 	/*
473 	 * Persistance timer into zero window.
474 	 * Force a byte to be output, if possible.
475 	 */
476 
477 	/*
478 	 * Hack: if the peer is dead/unreachable, we do not
479 	 * time out if the window is closed.  After a full
480 	 * backoff, drop the connection if the idle time
481 	 * (no responses to probes) reaches the maximum
482 	 * backoff that we would use if retransmitting.
483 	 */
484 	rto = TCP_REXMTVAL(tp);
485 	if (rto < tp->t_rttmin)
486 		rto = tp->t_rttmin;
487 	if (tp->t_rxtshift == TCP_MAXRXTSHIFT &&
488 	    ((tcp_now - tp->t_rcvtime) >= tcp_maxpersistidle ||
489 	    (tcp_now - tp->t_rcvtime) >= rto * tcp_totbackoff)) {
490 		TCP_STATINC(TCP_STAT_PERSISTDROPS);
491 		tp = tcp_drop(tp, ETIMEDOUT);
492 		goto out;
493 	}
494 	TCP_STATINC(TCP_STAT_PERSISTTIMEO);
495 	tcp_setpersist(tp);
496 	tp->t_force = 1;
497 	(void) tcp_output(tp);
498 	tp->t_force = 0;
499 
500  out:
501 #ifdef TCP_DEBUG
502 	if (tp && so->so_options & SO_DEBUG)
503 		tcp_trace(TA_USER, ostate, tp, NULL,
504 		    PRU_SLOWTIMO | (TCPT_PERSIST << 8));
505 #endif
506 	splx(s);
507 }
508 
509 void
510 tcp_timer_keep(void *arg)
511 {
512 	struct tcpcb *tp = arg;
513 	struct socket *so = NULL;	/* Quell compiler warning */
514 	int s;
515 #ifdef TCP_DEBUG
516 	short ostate;
517 #endif
518 
519 	s = splsoftnet();
520 	callout_ack(&tp->t_timer[TCPT_KEEP]);
521 	if (tcp_isdead(tp)) {
522 		splx(s);
523 		return;
524 	}
525 
526 #ifdef TCP_DEBUG
527 	ostate = tp->t_state;
528 #endif /* TCP_DEBUG */
529 
530 	/*
531 	 * Keep-alive timer went off; send something
532 	 * or drop connection if idle for too long.
533 	 */
534 
535 	TCP_STATINC(TCP_STAT_KEEPTIMEO);
536 	if (TCPS_HAVEESTABLISHED(tp->t_state) == 0)
537 		goto dropit;
538 #ifdef INET
539 	if (tp->t_inpcb)
540 		so = tp->t_inpcb->inp_socket;
541 #endif
542 #ifdef INET6
543 	if (tp->t_in6pcb)
544 		so = tp->t_in6pcb->in6p_socket;
545 #endif
546 	KASSERT(so != NULL);
547 	if (so->so_options & SO_KEEPALIVE &&
548 	    tp->t_state <= TCPS_CLOSE_WAIT) {
549 	    	if ((tp->t_maxidle > 0) &&
550 		    ((tcp_now - tp->t_rcvtime) >=
551 		     tp->t_keepidle + tp->t_maxidle))
552 			goto dropit;
553 		/*
554 		 * Send a packet designed to force a response
555 		 * if the peer is up and reachable:
556 		 * either an ACK if the connection is still alive,
557 		 * or an RST if the peer has closed the connection
558 		 * due to timeout or reboot.
559 		 * Using sequence number tp->snd_una-1
560 		 * causes the transmitted zero-length segment
561 		 * to lie outside the receive window;
562 		 * by the protocol spec, this requires the
563 		 * correspondent TCP to respond.
564 		 */
565 		TCP_STATINC(TCP_STAT_KEEPPROBE);
566 		if (tcp_compat_42) {
567 			/*
568 			 * The keepalive packet must have nonzero
569 			 * length to get a 4.2 host to respond.
570 			 */
571 			(void)tcp_respond(tp, tp->t_template,
572 			    (struct mbuf *)NULL, NULL, tp->rcv_nxt - 1,
573 			    tp->snd_una - 1, 0);
574 		} else {
575 			(void)tcp_respond(tp, tp->t_template,
576 			    (struct mbuf *)NULL, NULL, tp->rcv_nxt,
577 			    tp->snd_una - 1, 0);
578 		}
579 		TCP_TIMER_ARM(tp, TCPT_KEEP, tp->t_keepintvl);
580 	} else
581 		TCP_TIMER_ARM(tp, TCPT_KEEP, tp->t_keepidle);
582 
583 #ifdef TCP_DEBUG
584 	if (tp && so->so_options & SO_DEBUG)
585 		tcp_trace(TA_USER, ostate, tp, NULL,
586 		    PRU_SLOWTIMO | (TCPT_KEEP << 8));
587 #endif
588 	splx(s);
589 	return;
590 
591  dropit:
592 	TCP_STATINC(TCP_STAT_KEEPDROPS);
593 	(void) tcp_drop(tp, ETIMEDOUT);
594 	splx(s);
595 }
596 
597 void
598 tcp_timer_2msl(void *arg)
599 {
600 	struct tcpcb *tp = arg;
601 	int s;
602 #ifdef TCP_DEBUG
603 	struct socket *so = NULL;
604 	short ostate;
605 #endif
606 
607 	s = splsoftnet();
608 	callout_ack(&tp->t_timer[TCPT_2MSL]);
609 	if (tcp_isdead(tp)) {
610 		splx(s);
611 		return;
612 	}
613 
614 	/*
615 	 * 2 MSL timeout went off, clear the SACK scoreboard, reset
616 	 * the FACK estimate.
617 	 */
618 	tcp_free_sackholes(tp);
619 	tp->snd_fack = tp->snd_una;
620 
621 #ifdef TCP_DEBUG
622 #ifdef INET
623 	if (tp->t_inpcb)
624 		so = tp->t_inpcb->inp_socket;
625 #endif
626 #ifdef INET6
627 	if (tp->t_in6pcb)
628 		so = tp->t_in6pcb->in6p_socket;
629 #endif
630 
631 	ostate = tp->t_state;
632 #endif /* TCP_DEBUG */
633 
634 	/*
635 	 * 2 MSL timeout in shutdown went off.  If we're closed but
636 	 * still waiting for peer to close and connection has been idle
637 	 * too long, or if 2MSL time is up from TIME_WAIT, delete connection
638 	 * control block.  Otherwise, check again in a bit.
639 	 */
640 	if (tp->t_state != TCPS_TIME_WAIT &&
641 	    ((tp->t_maxidle == 0) ||
642 	    ((tcp_now - tp->t_rcvtime) <= tp->t_maxidle)))
643 	    TCP_TIMER_ARM(tp, TCPT_2MSL, tp->t_keepintvl);
644 	else
645 		tp = tcp_close(tp);
646 
647 #ifdef TCP_DEBUG
648 	if (tp && so->so_options & SO_DEBUG)
649 		tcp_trace(TA_USER, ostate, tp, NULL,
650 		    PRU_SLOWTIMO | (TCPT_2MSL << 8));
651 #endif
652 	splx(s);
653 }
654