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