1 /* $NetBSD: tcp_timer.c,v 1.88 2014/11/10 18:52:51 maxv 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.88 2014/11/10 18:52:51 maxv Exp $"); 97 98 #include "opt_inet.h" 99 #include "opt_tcp_debug.h" 100 101 #include <sys/param.h> 102 #include <sys/systm.h> 103 #include <sys/mbuf.h> 104 #include <sys/socket.h> 105 #include <sys/socketvar.h> 106 #include <sys/protosw.h> 107 #include <sys/errno.h> 108 #include <sys/kernel.h> 109 110 #include <net/if.h> 111 #include <net/route.h> 112 113 #include <netinet/in.h> 114 #include <netinet/in_systm.h> 115 #include <netinet/ip.h> 116 #include <netinet/in_pcb.h> 117 #include <netinet/ip_var.h> 118 #include <netinet/ip_icmp.h> 119 120 #ifdef INET6 121 #ifndef INET 122 #include <netinet/in.h> 123 #endif 124 #include <netinet/ip6.h> 125 #include <netinet6/in6_pcb.h> 126 #endif 127 128 #include <netinet/tcp.h> 129 #include <netinet/tcp_fsm.h> 130 #include <netinet/tcp_seq.h> 131 #include <netinet/tcp_timer.h> 132 #include <netinet/tcp_var.h> 133 #include <netinet/tcp_private.h> 134 #include <netinet/tcp_congctl.h> 135 #include <netinet/tcpip.h> 136 #ifdef TCP_DEBUG 137 #include <netinet/tcp_debug.h> 138 #endif 139 140 /* 141 * Various tunable timer parameters. These are initialized in tcp_init(), 142 * unless they are patched. 143 */ 144 u_int tcp_keepinit = 0; 145 u_int tcp_keepidle = 0; 146 u_int tcp_keepintvl = 0; 147 u_int tcp_keepcnt = 0; /* max idle probes */ 148 149 int tcp_maxpersistidle = 0; /* max idle time in persist */ 150 151 /* 152 * Time to delay the ACK. This is initialized in tcp_init(), unless 153 * its patched. 154 */ 155 int tcp_delack_ticks = 0; 156 157 void tcp_timer_rexmt(void *); 158 void tcp_timer_persist(void *); 159 void tcp_timer_keep(void *); 160 void tcp_timer_2msl(void *); 161 162 const tcp_timer_func_t tcp_timer_funcs[TCPT_NTIMERS] = { 163 tcp_timer_rexmt, 164 tcp_timer_persist, 165 tcp_timer_keep, 166 tcp_timer_2msl, 167 }; 168 169 /* 170 * Timer state initialization, called from tcp_init(). 171 */ 172 void 173 tcp_timer_init(void) 174 { 175 176 if (tcp_keepinit == 0) 177 tcp_keepinit = TCPTV_KEEP_INIT; 178 179 if (tcp_keepidle == 0) 180 tcp_keepidle = TCPTV_KEEP_IDLE; 181 182 if (tcp_keepintvl == 0) 183 tcp_keepintvl = TCPTV_KEEPINTVL; 184 185 if (tcp_keepcnt == 0) 186 tcp_keepcnt = TCPTV_KEEPCNT; 187 188 if (tcp_maxpersistidle == 0) 189 tcp_maxpersistidle = TCPTV_KEEP_IDLE; 190 191 if (tcp_delack_ticks == 0) 192 tcp_delack_ticks = TCP_DELACK_TICKS; 193 } 194 195 /* 196 * Callout to process delayed ACKs for a TCPCB. 197 */ 198 void 199 tcp_delack(void *arg) 200 { 201 struct tcpcb *tp = arg; 202 203 /* 204 * If tcp_output() wasn't able to transmit the ACK 205 * for whatever reason, it will restart the delayed 206 * ACK callout. 207 */ 208 209 mutex_enter(softnet_lock); 210 if ((tp->t_flags & (TF_DEAD | TF_DELACK)) != TF_DELACK) { 211 mutex_exit(softnet_lock); 212 return; 213 } 214 if (!callout_expired(&tp->t_delack_ch)) { 215 mutex_exit(softnet_lock); 216 return; 217 } 218 219 tp->t_flags |= TF_ACKNOW; 220 KERNEL_LOCK(1, NULL); 221 (void) tcp_output(tp); 222 KERNEL_UNLOCK_ONE(NULL); 223 mutex_exit(softnet_lock); 224 } 225 226 /* 227 * Tcp protocol timeout routine called every 500 ms. 228 * Updates the timers in all active tcb's and 229 * causes finite state machine actions if timers expire. 230 */ 231 void 232 tcp_slowtimo(void *arg) 233 { 234 235 mutex_enter(softnet_lock); 236 tcp_iss_seq += TCP_ISSINCR; /* increment iss */ 237 tcp_now++; /* for timestamps */ 238 mutex_exit(softnet_lock); 239 240 callout_schedule(&tcp_slowtimo_ch, hz / PR_SLOWHZ); 241 } 242 243 /* 244 * Cancel all timers for TCP tp. 245 */ 246 void 247 tcp_canceltimers(struct tcpcb *tp) 248 { 249 int i; 250 251 for (i = 0; i < TCPT_NTIMERS; i++) 252 TCP_TIMER_DISARM(tp, i); 253 } 254 255 const int tcp_backoff[TCP_MAXRXTSHIFT + 1] = 256 { 1, 2, 4, 8, 16, 32, 64, 64, 64, 64, 64, 64, 64 }; 257 258 const int tcp_totbackoff = 511; /* sum of tcp_backoff[] */ 259 260 /* 261 * TCP timer processing. 262 */ 263 264 void 265 tcp_timer_rexmt(void *arg) 266 { 267 struct tcpcb *tp = arg; 268 uint32_t rto; 269 #ifdef TCP_DEBUG 270 struct socket *so = NULL; 271 short ostate; 272 #endif 273 274 mutex_enter(softnet_lock); 275 if ((tp->t_flags & TF_DEAD) != 0) { 276 mutex_exit(softnet_lock); 277 return; 278 } 279 if (!callout_expired(&tp->t_timer[TCPT_REXMT])) { 280 mutex_exit(softnet_lock); 281 return; 282 } 283 284 KERNEL_LOCK(1, NULL); 285 if ((tp->t_flags & TF_PMTUD_PEND) && tp->t_inpcb && 286 SEQ_GEQ(tp->t_pmtud_th_seq, tp->snd_una) && 287 SEQ_LT(tp->t_pmtud_th_seq, (int)(tp->snd_una + tp->t_ourmss))) { 288 extern struct sockaddr_in icmpsrc; 289 struct icmp icmp; 290 291 tp->t_flags &= ~TF_PMTUD_PEND; 292 293 /* XXX create fake icmp message with relevant entries */ 294 icmp.icmp_nextmtu = tp->t_pmtud_nextmtu; 295 icmp.icmp_ip.ip_len = tp->t_pmtud_ip_len; 296 icmp.icmp_ip.ip_hl = tp->t_pmtud_ip_hl; 297 icmpsrc.sin_addr = tp->t_inpcb->inp_faddr; 298 icmp_mtudisc(&icmp, icmpsrc.sin_addr); 299 300 /* 301 * Notify all connections to the same peer about 302 * new mss and trigger retransmit. 303 */ 304 in_pcbnotifyall(&tcbtable, icmpsrc.sin_addr, EMSGSIZE, 305 tcp_mtudisc); 306 KERNEL_UNLOCK_ONE(NULL); 307 mutex_exit(softnet_lock); 308 return; 309 } 310 #ifdef TCP_DEBUG 311 #ifdef INET 312 if (tp->t_inpcb) 313 so = tp->t_inpcb->inp_socket; 314 #endif 315 #ifdef INET6 316 if (tp->t_in6pcb) 317 so = tp->t_in6pcb->in6p_socket; 318 #endif 319 ostate = tp->t_state; 320 #endif /* TCP_DEBUG */ 321 322 /* 323 * Clear the SACK scoreboard, reset FACK estimate. 324 */ 325 tcp_free_sackholes(tp); 326 tp->snd_fack = tp->snd_una; 327 328 /* 329 * Retransmission timer went off. Message has not 330 * been acked within retransmit interval. Back off 331 * to a longer retransmit interval and retransmit one segment. 332 */ 333 334 if (++tp->t_rxtshift > TCP_MAXRXTSHIFT) { 335 tp->t_rxtshift = TCP_MAXRXTSHIFT; 336 TCP_STATINC(TCP_STAT_TIMEOUTDROP); 337 tp = tcp_drop(tp, tp->t_softerror ? 338 tp->t_softerror : ETIMEDOUT); 339 goto out; 340 } 341 TCP_STATINC(TCP_STAT_REXMTTIMEO); 342 rto = TCP_REXMTVAL(tp); 343 if (rto < tp->t_rttmin) 344 rto = tp->t_rttmin; 345 TCPT_RANGESET(tp->t_rxtcur, rto * tcp_backoff[tp->t_rxtshift], 346 tp->t_rttmin, TCPTV_REXMTMAX); 347 TCP_TIMER_ARM(tp, TCPT_REXMT, tp->t_rxtcur); 348 349 /* 350 * If we are losing and we are trying path MTU discovery, 351 * try turning it off. This will avoid black holes in 352 * the network which suppress or fail to send "packet 353 * too big" ICMP messages. We should ideally do 354 * lots more sophisticated searching to find the right 355 * value here... 356 */ 357 if (tp->t_mtudisc && tp->t_rxtshift > TCP_MAXRXTSHIFT / 6) { 358 TCP_STATINC(TCP_STAT_PMTUBLACKHOLE); 359 360 #ifdef INET 361 /* try turning PMTUD off */ 362 if (tp->t_inpcb) 363 tp->t_mtudisc = 0; 364 #endif 365 #ifdef INET6 366 /* try using IPv6 minimum MTU */ 367 if (tp->t_in6pcb) 368 tp->t_mtudisc = 0; 369 #endif 370 371 /* XXX: more sophisticated Black hole recovery code? */ 372 } 373 374 /* 375 * If losing, let the lower level know and try for 376 * a better route. Also, if we backed off this far, 377 * our srtt estimate is probably bogus. Clobber it 378 * so we'll take the next rtt measurement as our srtt; 379 * move the current srtt into rttvar to keep the current 380 * retransmit times until then. 381 */ 382 if (tp->t_rxtshift > TCP_MAXRXTSHIFT / 4) { 383 #ifdef INET 384 if (tp->t_inpcb) 385 in_losing(tp->t_inpcb); 386 #endif 387 #ifdef INET6 388 if (tp->t_in6pcb) 389 in6_losing(tp->t_in6pcb); 390 #endif 391 /* 392 * This operation is not described in RFC2988. The 393 * point is to keep srtt+4*rttvar constant, so we 394 * should shift right 2 bits to divide by 4, and then 395 * shift right one bit because the storage 396 * representation of rttvar is 1/16s vs 1/32s for 397 * srtt. 398 */ 399 tp->t_rttvar += (tp->t_srtt >> TCP_RTT_SHIFT); 400 tp->t_srtt = 0; 401 } 402 tp->snd_nxt = tp->snd_una; 403 tp->snd_high = tp->snd_max; 404 /* 405 * If timing a segment in this window, stop the timer. 406 */ 407 tp->t_rtttime = 0; 408 /* 409 * Remember if we are retransmitting a SYN, because if 410 * we do, set the initial congestion window must be set 411 * to 1 segment. 412 */ 413 if (tp->t_state == TCPS_SYN_SENT) 414 tp->t_flags |= TF_SYN_REXMT; 415 416 /* 417 * Adjust congestion control parameters. 418 */ 419 tp->t_congctl->slow_retransmit(tp); 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 KERNEL_UNLOCK_ONE(NULL); 430 mutex_exit(softnet_lock); 431 } 432 433 void 434 tcp_timer_persist(void *arg) 435 { 436 struct tcpcb *tp = arg; 437 uint32_t rto; 438 #ifdef TCP_DEBUG 439 struct socket *so = NULL; 440 short ostate; 441 #endif 442 443 mutex_enter(softnet_lock); 444 if ((tp->t_flags & TF_DEAD) != 0) { 445 mutex_exit(softnet_lock); 446 return; 447 } 448 if (!callout_expired(&tp->t_timer[TCPT_PERSIST])) { 449 mutex_exit(softnet_lock); 450 return; 451 } 452 453 KERNEL_LOCK(1, NULL); 454 #ifdef TCP_DEBUG 455 #ifdef INET 456 if (tp->t_inpcb) 457 so = tp->t_inpcb->inp_socket; 458 #endif 459 #ifdef INET6 460 if (tp->t_in6pcb) 461 so = tp->t_in6pcb->in6p_socket; 462 #endif 463 464 ostate = tp->t_state; 465 #endif /* TCP_DEBUG */ 466 467 /* 468 * Persistance timer into zero window. 469 * Force a byte to be output, if possible. 470 */ 471 472 /* 473 * Hack: if the peer is dead/unreachable, we do not 474 * time out if the window is closed. After a full 475 * backoff, drop the connection if the idle time 476 * (no responses to probes) reaches the maximum 477 * backoff that we would use if retransmitting. 478 */ 479 rto = TCP_REXMTVAL(tp); 480 if (rto < tp->t_rttmin) 481 rto = tp->t_rttmin; 482 if (tp->t_rxtshift == TCP_MAXRXTSHIFT && 483 ((tcp_now - tp->t_rcvtime) >= tcp_maxpersistidle || 484 (tcp_now - tp->t_rcvtime) >= rto * tcp_totbackoff)) { 485 TCP_STATINC(TCP_STAT_PERSISTDROPS); 486 tp = tcp_drop(tp, ETIMEDOUT); 487 goto out; 488 } 489 TCP_STATINC(TCP_STAT_PERSISTTIMEO); 490 tcp_setpersist(tp); 491 tp->t_force = 1; 492 (void) tcp_output(tp); 493 tp->t_force = 0; 494 495 out: 496 #ifdef TCP_DEBUG 497 if (tp && so->so_options & SO_DEBUG) 498 tcp_trace(TA_USER, ostate, tp, NULL, 499 PRU_SLOWTIMO | (TCPT_PERSIST << 8)); 500 #endif 501 KERNEL_UNLOCK_ONE(NULL); 502 mutex_exit(softnet_lock); 503 } 504 505 void 506 tcp_timer_keep(void *arg) 507 { 508 struct tcpcb *tp = arg; 509 struct socket *so = NULL; /* Quell compiler warning */ 510 #ifdef TCP_DEBUG 511 short ostate; 512 #endif 513 514 mutex_enter(softnet_lock); 515 if ((tp->t_flags & TF_DEAD) != 0) { 516 mutex_exit(softnet_lock); 517 return; 518 } 519 if (!callout_expired(&tp->t_timer[TCPT_KEEP])) { 520 mutex_exit(softnet_lock); 521 return; 522 } 523 524 KERNEL_LOCK(1, NULL); 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 NULL, NULL, tp->rcv_nxt - 1, 573 tp->snd_una - 1, 0); 574 } else { 575 (void)tcp_respond(tp, tp->t_template, 576 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 KERNEL_UNLOCK_ONE(NULL); 589 mutex_exit(softnet_lock); 590 return; 591 592 dropit: 593 TCP_STATINC(TCP_STAT_KEEPDROPS); 594 (void) tcp_drop(tp, ETIMEDOUT); 595 KERNEL_UNLOCK_ONE(NULL); 596 mutex_exit(softnet_lock); 597 } 598 599 void 600 tcp_timer_2msl(void *arg) 601 { 602 struct tcpcb *tp = arg; 603 #ifdef TCP_DEBUG 604 struct socket *so = NULL; 605 short ostate; 606 #endif 607 608 mutex_enter(softnet_lock); 609 if ((tp->t_flags & TF_DEAD) != 0) { 610 mutex_exit(softnet_lock); 611 return; 612 } 613 if (!callout_expired(&tp->t_timer[TCPT_2MSL])) { 614 mutex_exit(softnet_lock); 615 return; 616 } 617 618 /* 619 * 2 MSL timeout went off, clear the SACK scoreboard, reset 620 * the FACK estimate. 621 */ 622 KERNEL_LOCK(1, NULL); 623 tcp_free_sackholes(tp); 624 tp->snd_fack = tp->snd_una; 625 626 #ifdef TCP_DEBUG 627 #ifdef INET 628 if (tp->t_inpcb) 629 so = tp->t_inpcb->inp_socket; 630 #endif 631 #ifdef INET6 632 if (tp->t_in6pcb) 633 so = tp->t_in6pcb->in6p_socket; 634 #endif 635 636 ostate = tp->t_state; 637 #endif /* TCP_DEBUG */ 638 639 /* 640 * 2 MSL timeout in shutdown went off. If we're closed but 641 * still waiting for peer to close and connection has been idle 642 * too long, or if 2MSL time is up from TIME_WAIT, delete connection 643 * control block. Otherwise, check again in a bit. 644 */ 645 if (tp->t_state != TCPS_TIME_WAIT && 646 ((tp->t_maxidle == 0) || 647 ((tcp_now - tp->t_rcvtime) <= tp->t_maxidle))) 648 TCP_TIMER_ARM(tp, TCPT_2MSL, tp->t_keepintvl); 649 else 650 tp = tcp_close(tp); 651 652 #ifdef TCP_DEBUG 653 if (tp && so->so_options & SO_DEBUG) 654 tcp_trace(TA_USER, ostate, tp, NULL, 655 PRU_SLOWTIMO | (TCPT_2MSL << 8)); 656 #endif 657 mutex_exit(softnet_lock); 658 KERNEL_UNLOCK_ONE(NULL); 659 } 660