Home | History | Annotate | Line # | Download | only in netinet
tcp_timer.c revision 1.68
      1 /*	$NetBSD: tcp_timer.c,v 1.68 2005/01/27 18:45:41 mycroft 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 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  *
     40  * Redistribution and use in source and binary forms, with or without
     41  * modification, are permitted provided that the following conditions
     42  * are met:
     43  * 1. Redistributions of source code must retain the above copyright
     44  *    notice, this list of conditions and the following disclaimer.
     45  * 2. Redistributions in binary form must reproduce the above copyright
     46  *    notice, this list of conditions and the following disclaimer in the
     47  *    documentation and/or other materials provided with the distribution.
     48  * 3. All advertising materials mentioning features or use of this software
     49  *    must display the following acknowledgement:
     50  *	This product includes software developed by the NetBSD
     51  *	Foundation, Inc. and its contributors.
     52  * 4. Neither the name of The NetBSD Foundation nor the names of its
     53  *    contributors may be used to endorse or promote products derived
     54  *    from this software without specific prior written permission.
     55  *
     56  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     57  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     58  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     59  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     60  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     61  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     62  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     63  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     64  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     65  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     66  * POSSIBILITY OF SUCH DAMAGE.
     67  */
     68 
     69 /*
     70  * Copyright (c) 1982, 1986, 1988, 1990, 1993, 1995
     71  *	The Regents of the University of California.  All rights reserved.
     72  *
     73  * Redistribution and use in source and binary forms, with or without
     74  * modification, are permitted provided that the following conditions
     75  * are met:
     76  * 1. Redistributions of source code must retain the above copyright
     77  *    notice, this list of conditions and the following disclaimer.
     78  * 2. Redistributions in binary form must reproduce the above copyright
     79  *    notice, this list of conditions and the following disclaimer in the
     80  *    documentation and/or other materials provided with the distribution.
     81  * 3. Neither the name of the University nor the names of its contributors
     82  *    may be used to endorse or promote products derived from this software
     83  *    without specific prior written permission.
     84  *
     85  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     86  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     87  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     88  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     89  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     90  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     91  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     92  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     93  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     94  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     95  * SUCH DAMAGE.
     96  *
     97  *	@(#)tcp_timer.c	8.2 (Berkeley) 5/24/95
     98  */
     99 
    100 #include <sys/cdefs.h>
    101 __KERNEL_RCSID(0, "$NetBSD: tcp_timer.c,v 1.68 2005/01/27 18:45:41 mycroft Exp $");
    102 
    103 #include "opt_inet.h"
    104 #include "opt_tcp_debug.h"
    105 
    106 #include <sys/param.h>
    107 #include <sys/systm.h>
    108 #include <sys/malloc.h>
    109 #include <sys/mbuf.h>
    110 #include <sys/socket.h>
    111 #include <sys/socketvar.h>
    112 #include <sys/protosw.h>
    113 #include <sys/errno.h>
    114 #include <sys/kernel.h>
    115 
    116 #include <net/if.h>
    117 #include <net/route.h>
    118 
    119 #include <netinet/in.h>
    120 #include <netinet/in_systm.h>
    121 #include <netinet/ip.h>
    122 #include <netinet/in_pcb.h>
    123 #include <netinet/ip_var.h>
    124 
    125 #ifdef INET6
    126 #ifndef INET
    127 #include <netinet/in.h>
    128 #endif
    129 #include <netinet/ip6.h>
    130 #include <netinet6/in6_pcb.h>
    131 #endif
    132 
    133 #include <netinet/tcp.h>
    134 #include <netinet/tcp_fsm.h>
    135 #include <netinet/tcp_seq.h>
    136 #include <netinet/tcp_timer.h>
    137 #include <netinet/tcp_var.h>
    138 #include <netinet/tcpip.h>
    139 #ifdef TCP_DEBUG
    140 #include <netinet/tcp_debug.h>
    141 #endif
    142 
    143 /*
    144  * Various tunable timer parameters.  These are initialized in tcp_init(),
    145  * unless they are patched.
    146  */
    147 int	tcp_keepidle = 0;
    148 int	tcp_keepintvl = 0;
    149 int	tcp_keepcnt = 0;		/* max idle probes */
    150 int	tcp_maxpersistidle = 0;		/* max idle time in persist */
    151 int	tcp_maxidle;			/* computed in tcp_slowtimo() */
    152 
    153 /*
    154  * Time to delay the ACK.  This is initialized in tcp_init(), unless
    155  * its patched.
    156  */
    157 int	tcp_delack_ticks = 0;
    158 
    159 void	tcp_timer_rexmt(void *);
    160 void	tcp_timer_persist(void *);
    161 void	tcp_timer_keep(void *);
    162 void	tcp_timer_2msl(void *);
    163 
    164 const 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  */
    174 void
    175 tcp_timer_init(void)
    176 {
    177 
    178 	if (tcp_keepidle == 0)
    179 		tcp_keepidle = TCPTV_KEEP_IDLE;
    180 
    181 	if (tcp_keepintvl == 0)
    182 		tcp_keepintvl = TCPTV_KEEPINTVL;
    183 
    184 	if (tcp_keepcnt == 0)
    185 		tcp_keepcnt = TCPTV_KEEPCNT;
    186 
    187 	if (tcp_maxpersistidle == 0)
    188 		tcp_maxpersistidle = TCPTV_KEEP_IDLE;
    189 
    190 	if (tcp_delack_ticks == 0)
    191 		tcp_delack_ticks = TCP_DELACK_TICKS;
    192 }
    193 
    194 /*
    195  * Return how many timers are currently being invoked.
    196  */
    197 int
    198 tcp_timers_invoking(struct tcpcb *tp)
    199 {
    200 	int i;
    201 	int count = 0;
    202 
    203 	for (i = 0; i < TCPT_NTIMERS; i++)
    204 		if (callout_invoking(&tp->t_timer[i]))
    205 			count++;
    206 	if (callout_invoking(&tp->t_delack_ch))
    207 		count++;
    208 
    209 	return count;
    210 }
    211 
    212 /*
    213  * Callout to process delayed ACKs for a TCPCB.
    214  */
    215 void
    216 tcp_delack(void *arg)
    217 {
    218 	struct tcpcb *tp = arg;
    219 	int s;
    220 
    221 	/*
    222 	 * If tcp_output() wasn't able to transmit the ACK
    223 	 * for whatever reason, it will restart the delayed
    224 	 * ACK callout.
    225 	 */
    226 
    227 	s = splsoftnet();
    228 	callout_ack(&tp->t_delack_ch);
    229 	if (tcp_isdead(tp)) {
    230 		splx(s);
    231 		return;
    232 	}
    233 
    234 	tp->t_flags |= TF_ACKNOW;
    235 	(void) tcp_output(tp);
    236 	splx(s);
    237 }
    238 
    239 /*
    240  * Tcp protocol timeout routine called every 500 ms.
    241  * Updates the timers in all active tcb's and
    242  * causes finite state machine actions if timers expire.
    243  */
    244 void
    245 tcp_slowtimo()
    246 {
    247 	int s;
    248 
    249 	s = splsoftnet();
    250 	tcp_maxidle = tcp_keepcnt * tcp_keepintvl;
    251 	tcp_iss_seq += TCP_ISSINCR;			/* increment iss */
    252 	tcp_now++;					/* for timestamps */
    253 	splx(s);
    254 }
    255 
    256 /*
    257  * Cancel all timers for TCP tp.
    258  */
    259 void
    260 tcp_canceltimers(tp)
    261 	struct tcpcb *tp;
    262 {
    263 	int i;
    264 
    265 	for (i = 0; i < TCPT_NTIMERS; i++)
    266 		TCP_TIMER_DISARM(tp, i);
    267 }
    268 
    269 const int	tcp_backoff[TCP_MAXRXTSHIFT + 1] =
    270     { 1, 2, 4, 8, 16, 32, 64, 64, 64, 64, 64, 64, 64 };
    271 
    272 const int	tcp_totbackoff = 511;	/* sum of tcp_backoff[] */
    273 
    274 /*
    275  * TCP timer processing.
    276  */
    277 
    278 void
    279 tcp_timer_rexmt(void *arg)
    280 {
    281 	struct tcpcb *tp = arg;
    282 	uint32_t rto;
    283 	int s;
    284 #ifdef TCP_DEBUG
    285 	struct socket *so = NULL;
    286 	short ostate;
    287 #endif
    288 
    289 	s = splsoftnet();
    290 	callout_ack(&tp->t_timer[TCPT_REXMT]);
    291 	if (tcp_isdead(tp)) {
    292 		splx(s);
    293 		return;
    294 	}
    295 
    296 #ifdef TCP_DEBUG
    297 #ifdef INET
    298 	if (tp->t_inpcb)
    299 		so = tp->t_inpcb->inp_socket;
    300 #endif
    301 #ifdef INET6
    302 	if (tp->t_in6pcb)
    303 		so = tp->t_in6pcb->in6p_socket;
    304 #endif
    305 	ostate = tp->t_state;
    306 #endif /* TCP_DEBUG */
    307 
    308 	/*
    309 	 * Retransmission timer went off.  Message has not
    310 	 * been acked within retransmit interval.  Back off
    311 	 * to a longer retransmit interval and retransmit one segment.
    312 	 */
    313 
    314 	if (++tp->t_rxtshift > TCP_MAXRXTSHIFT) {
    315 		tp->t_rxtshift = TCP_MAXRXTSHIFT;
    316 		tcpstat.tcps_timeoutdrop++;
    317 		tp = tcp_drop(tp, tp->t_softerror ?
    318 		    tp->t_softerror : ETIMEDOUT);
    319 		goto out;
    320 	}
    321 	tcpstat.tcps_rexmttimeo++;
    322 	rto = TCP_REXMTVAL(tp);
    323 	if (rto < tp->t_rttmin)
    324 		rto = tp->t_rttmin;
    325 	TCPT_RANGESET(tp->t_rxtcur, rto * tcp_backoff[tp->t_rxtshift],
    326 	    tp->t_rttmin, TCPTV_REXMTMAX);
    327 	TCP_TIMER_ARM(tp, TCPT_REXMT, tp->t_rxtcur);
    328 
    329 	/*
    330 	 * If we are losing and we are trying path MTU discovery,
    331 	 * try turning it off.  This will avoid black holes in
    332 	 * the network which suppress or fail to send "packet
    333 	 * too big" ICMP messages.  We should ideally do
    334 	 * lots more sophisticated searching to find the right
    335 	 * value here...
    336 	 */
    337 	if (tp->t_mtudisc && tp->t_rxtshift > TCP_MAXRXTSHIFT / 6) {
    338 		tcpstat.tcps_pmtublackhole++;
    339 
    340 #ifdef INET
    341 		/* try turning PMTUD off */
    342 		if (tp->t_inpcb)
    343 			tp->t_mtudisc = 0;
    344 #endif
    345 #ifdef INET6
    346 		/* try using IPv6 minimum MTU */
    347 		if (tp->t_in6pcb)
    348 			tp->t_mtudisc = 0;
    349 #endif
    350 
    351 		/* XXX: more sophisticated Black hole recovery code? */
    352 	}
    353 
    354 	/*
    355 	 * If losing, let the lower level know and try for
    356 	 * a better route.  Also, if we backed off this far,
    357 	 * our srtt estimate is probably bogus.  Clobber it
    358 	 * so we'll take the next rtt measurement as our srtt;
    359 	 * move the current srtt into rttvar to keep the current
    360 	 * retransmit times until then.
    361 	 */
    362 	if (tp->t_rxtshift > TCP_MAXRXTSHIFT / 4) {
    363 #ifdef INET
    364 		if (tp->t_inpcb)
    365 			in_losing(tp->t_inpcb);
    366 #endif
    367 #ifdef INET6
    368 		if (tp->t_in6pcb)
    369 			in6_losing(tp->t_in6pcb);
    370 #endif
    371 		tp->t_rttvar += (tp->t_srtt >> TCP_RTT_SHIFT);
    372 		tp->t_srtt = 0;
    373 	}
    374 	tp->snd_nxt = tp->snd_una;
    375 	tp->snd_high = tp->snd_max;
    376 	/*
    377 	 * If timing a segment in this window, stop the timer.
    378 	 */
    379 	tp->t_rtttime = 0;
    380 	/*
    381 	 * Remember if we are retransmitting a SYN, because if
    382 	 * we do, set the initial congestion window must be set
    383 	 * to 1 segment.
    384 	 */
    385 	if (tp->t_state == TCPS_SYN_SENT)
    386 		tp->t_flags |= TF_SYN_REXMT;
    387 	/*
    388 	 * Close the congestion window down to one segment
    389 	 * (we'll open it by one segment for each ack we get).
    390 	 * Since we probably have a window's worth of unacked
    391 	 * data accumulated, this "slow start" keeps us from
    392 	 * dumping all that data as back-to-back packets (which
    393 	 * might overwhelm an intermediate gateway).
    394 	 *
    395 	 * There are two phases to the opening: Initially we
    396 	 * open by one mss on each ack.  This makes the window
    397 	 * size increase exponentially with time.  If the
    398 	 * window is larger than the path can handle, this
    399 	 * exponential growth results in dropped packet(s)
    400 	 * almost immediately.  To get more time between
    401 	 * drops but still "push" the network to take advantage
    402 	 * of improving conditions, we switch from exponential
    403 	 * to linear window opening at some threshhold size.
    404 	 * For a threshhold, we use half the current window
    405 	 * size, truncated to a multiple of the mss.
    406 	 *
    407 	 * (the minimum cwnd that will give us exponential
    408 	 * growth is 2 mss.  We don't allow the threshhold
    409 	 * to go below this.)
    410 	 */
    411 	{
    412 	u_int win = min(tp->snd_wnd, tp->snd_cwnd) / 2 / tp->t_segsz;
    413 	if (win < 2)
    414 		win = 2;
    415 	/* Loss Window MUST be one segment. */
    416 	tp->snd_cwnd = tp->t_segsz;
    417 	tp->snd_ssthresh = win * tp->t_segsz;
    418 	tp->t_partialacks = -1;
    419 	tp->t_dupacks = 0;
    420 	}
    421 	(void) tcp_output(tp);
    422 
    423  out:
    424 #ifdef TCP_DEBUG
    425 	if (tp && so->so_options & SO_DEBUG)
    426 		tcp_trace(TA_USER, ostate, tp, NULL,
    427 		    PRU_SLOWTIMO | (TCPT_REXMT << 8));
    428 #endif
    429 	splx(s);
    430 }
    431 
    432 void
    433 tcp_timer_persist(void *arg)
    434 {
    435 	struct tcpcb *tp = arg;
    436 	uint32_t rto;
    437 	int s;
    438 #ifdef TCP_DEBUG
    439 	struct socket *so = NULL;
    440 	short ostate;
    441 #endif
    442 
    443 	s = splsoftnet();
    444 	callout_ack(&tp->t_timer[TCPT_PERSIST]);
    445 	if (tcp_isdead(tp)) {
    446 		splx(s);
    447 		return;
    448 	}
    449 
    450 #ifdef TCP_DEBUG
    451 #ifdef INET
    452 	if (tp->t_inpcb)
    453 		so = tp->t_inpcb->inp_socket;
    454 #endif
    455 #ifdef INET6
    456 	if (tp->t_in6pcb)
    457 		so = tp->t_in6pcb->in6p_socket;
    458 #endif
    459 
    460 	ostate = tp->t_state;
    461 #endif /* TCP_DEBUG */
    462 
    463 	/*
    464 	 * Persistance timer into zero window.
    465 	 * Force a byte to be output, if possible.
    466 	 */
    467 
    468 	/*
    469 	 * Hack: if the peer is dead/unreachable, we do not
    470 	 * time out if the window is closed.  After a full
    471 	 * backoff, drop the connection if the idle time
    472 	 * (no responses to probes) reaches the maximum
    473 	 * backoff that we would use if retransmitting.
    474 	 */
    475 	rto = TCP_REXMTVAL(tp);
    476 	if (rto < tp->t_rttmin)
    477 		rto = tp->t_rttmin;
    478 	if (tp->t_rxtshift == TCP_MAXRXTSHIFT &&
    479 	    ((tcp_now - tp->t_rcvtime) >= tcp_maxpersistidle ||
    480 	    (tcp_now - tp->t_rcvtime) >= rto * tcp_totbackoff)) {
    481 		tcpstat.tcps_persistdrops++;
    482 		tp = tcp_drop(tp, ETIMEDOUT);
    483 		goto out;
    484 	}
    485 	tcpstat.tcps_persisttimeo++;
    486 	tcp_setpersist(tp);
    487 	tp->t_force = 1;
    488 	(void) tcp_output(tp);
    489 	tp->t_force = 0;
    490 
    491  out:
    492 #ifdef TCP_DEBUG
    493 	if (tp && so->so_options & SO_DEBUG)
    494 		tcp_trace(TA_USER, ostate, tp, NULL,
    495 		    PRU_SLOWTIMO | (TCPT_PERSIST << 8));
    496 #endif
    497 	splx(s);
    498 }
    499 
    500 void
    501 tcp_timer_keep(void *arg)
    502 {
    503 	struct tcpcb *tp = arg;
    504 	struct socket *so = NULL;	/* Quell compiler warning */
    505 	int s;
    506 #ifdef TCP_DEBUG
    507 	short ostate;
    508 #endif
    509 
    510 	s = splsoftnet();
    511 	callout_ack(&tp->t_timer[TCPT_KEEP]);
    512 	if (tcp_isdead(tp)) {
    513 		splx(s);
    514 		return;
    515 	}
    516 
    517 #ifdef TCP_DEBUG
    518 	ostate = tp->t_state;
    519 #endif /* TCP_DEBUG */
    520 
    521 	/*
    522 	 * Keep-alive timer went off; send something
    523 	 * or drop connection if idle for too long.
    524 	 */
    525 
    526 	tcpstat.tcps_keeptimeo++;
    527 	if (TCPS_HAVEESTABLISHED(tp->t_state) == 0)
    528 		goto dropit;
    529 #ifdef INET
    530 	if (tp->t_inpcb)
    531 		so = tp->t_inpcb->inp_socket;
    532 #endif
    533 #ifdef INET6
    534 	if (tp->t_in6pcb)
    535 		so = tp->t_in6pcb->in6p_socket;
    536 #endif
    537 	if (so->so_options & SO_KEEPALIVE &&
    538 	    tp->t_state <= TCPS_CLOSE_WAIT) {
    539 	    	if ((tcp_maxidle > 0) &&
    540 		    ((tcp_now - tp->t_rcvtime) >=
    541 		     tcp_keepidle + tcp_maxidle))
    542 			goto dropit;
    543 		/*
    544 		 * Send a packet designed to force a response
    545 		 * if the peer is up and reachable:
    546 		 * either an ACK if the connection is still alive,
    547 		 * or an RST if the peer has closed the connection
    548 		 * due to timeout or reboot.
    549 		 * Using sequence number tp->snd_una-1
    550 		 * causes the transmitted zero-length segment
    551 		 * to lie outside the receive window;
    552 		 * by the protocol spec, this requires the
    553 		 * correspondent TCP to respond.
    554 		 */
    555 		tcpstat.tcps_keepprobe++;
    556 		if (tcp_compat_42) {
    557 			/*
    558 			 * The keepalive packet must have nonzero
    559 			 * length to get a 4.2 host to respond.
    560 			 */
    561 			(void)tcp_respond(tp, tp->t_template,
    562 			    (struct mbuf *)NULL, NULL, tp->rcv_nxt - 1,
    563 			    tp->snd_una - 1, 0);
    564 		} else {
    565 			(void)tcp_respond(tp, tp->t_template,
    566 			    (struct mbuf *)NULL, NULL, tp->rcv_nxt,
    567 			    tp->snd_una - 1, 0);
    568 		}
    569 		TCP_TIMER_ARM(tp, TCPT_KEEP, tcp_keepintvl);
    570 	} else
    571 		TCP_TIMER_ARM(tp, TCPT_KEEP, tcp_keepidle);
    572 
    573 #ifdef TCP_DEBUG
    574 	if (tp && so->so_options & SO_DEBUG)
    575 		tcp_trace(TA_USER, ostate, tp, NULL,
    576 		    PRU_SLOWTIMO | (TCPT_KEEP << 8));
    577 #endif
    578 	splx(s);
    579 	return;
    580 
    581  dropit:
    582 	tcpstat.tcps_keepdrops++;
    583 	(void) tcp_drop(tp, ETIMEDOUT);
    584 	splx(s);
    585 }
    586 
    587 void
    588 tcp_timer_2msl(void *arg)
    589 {
    590 	struct tcpcb *tp = arg;
    591 	int s;
    592 #ifdef TCP_DEBUG
    593 	struct socket *so = NULL;
    594 	short ostate;
    595 #endif
    596 
    597 	s = splsoftnet();
    598 	callout_ack(&tp->t_timer[TCPT_2MSL]);
    599 	if (tcp_isdead(tp)) {
    600 		splx(s);
    601 		return;
    602 	}
    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 	    ((tcp_maxidle == 0) || ((tcp_now - tp->t_rcvtime) <= tcp_maxidle)))
    625 		TCP_TIMER_ARM(tp, TCPT_2MSL, tcp_keepintvl);
    626 	else
    627 		tp = tcp_close(tp);
    628 
    629 #ifdef TCP_DEBUG
    630 	if (tp && so->so_options & SO_DEBUG)
    631 		tcp_trace(TA_USER, ostate, tp, NULL,
    632 		    PRU_SLOWTIMO | (TCPT_2MSL << 8));
    633 #endif
    634 	splx(s);
    635 }
    636