The Design and Implementation of the FreeBSD Operating System, Second Edition
Now available: The Design and Implementation of the FreeBSD Operating System (Second Edition)


[ source navigation ] [ diff markup ] [ identifier search ] [ freetext search ] [ file search ] [ list types ] [ track identifier ]

FreeBSD/Linux Kernel Cross Reference
sys/netinet/tcp_timer.c

Version: -  FREEBSD  -  FREEBSD-12-STABLE  -  FREEBSD-12-0  -  FREEBSD-11-STABLE  -  FREEBSD-11-2  -  FREEBSD-11-1  -  FREEBSD-11-0  -  FREEBSD-10-STABLE  -  FREEBSD-10-4  -  FREEBSD-10-3  -  FREEBSD-10-2  -  FREEBSD-10-1  -  FREEBSD-10-0  -  FREEBSD-9-STABLE  -  FREEBSD-9-3  -  FREEBSD-9-2  -  FREEBSD-9-1  -  FREEBSD-9-0  -  FREEBSD-8-STABLE  -  FREEBSD-8-4  -  FREEBSD-8-3  -  FREEBSD-8-2  -  FREEBSD-8-1  -  FREEBSD-8-0  -  FREEBSD-7-STABLE  -  FREEBSD-7-4  -  FREEBSD-7-3  -  FREEBSD-7-2  -  FREEBSD-7-1  -  FREEBSD-7-0  -  FREEBSD-6-STABLE  -  FREEBSD-6-4  -  FREEBSD-6-3  -  FREEBSD-6-2  -  FREEBSD-6-1  -  FREEBSD-6-0  -  FREEBSD-5-STABLE  -  FREEBSD-5-5  -  FREEBSD-5-4  -  FREEBSD-5-3  -  FREEBSD-5-2  -  FREEBSD-5-1  -  FREEBSD-5-0  -  FREEBSD-4-STABLE  -  FREEBSD-3-STABLE  -  FREEBSD22  -  linux-2.6  -  linux-2.4.22  -  MK83  -  MK84  -  PLAN9  -  DFBSD  -  NETBSD  -  NETBSD5  -  NETBSD4  -  NETBSD3  -  NETBSD20  -  OPENBSD  -  xnu-517  -  xnu-792  -  xnu-792.6.70  -  xnu-1228  -  xnu-1456.1.26  -  xnu-1699.24.8  -  xnu-2050.18.24  -  OPENSOLARIS  -  minix-3-1-1 
SearchContext: -  none  -  3  -  10 

    1 /*-
    2  * Copyright (c) 1982, 1986, 1988, 1990, 1993, 1995
    3  *      The Regents of the University of California.  All rights reserved.
    4  *
    5  * Redistribution and use in source and binary forms, with or without
    6  * modification, are permitted provided that the following conditions
    7  * are met:
    8  * 1. Redistributions of source code must retain the above copyright
    9  *    notice, this list of conditions and the following disclaimer.
   10  * 2. Redistributions in binary form must reproduce the above copyright
   11  *    notice, this list of conditions and the following disclaimer in the
   12  *    documentation and/or other materials provided with the distribution.
   13  * 4. Neither the name of the University nor the names of its contributors
   14  *    may be used to endorse or promote products derived from this software
   15  *    without specific prior written permission.
   16  *
   17  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
   18  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
   19  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
   20  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
   21  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
   22  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
   23  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
   24  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
   25  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
   26  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   27  * SUCH DAMAGE.
   28  *
   29  *      @(#)tcp_timer.c 8.2 (Berkeley) 5/24/95
   30  */
   31 
   32 #include <sys/cdefs.h>
   33 __FBSDID("$FreeBSD: stable/7/sys/netinet/tcp_timer.c 222935 2011-06-10 18:47:10Z jhb $");
   34 
   35 #include "opt_inet6.h"
   36 #include "opt_tcpdebug.h"
   37 
   38 #include <sys/param.h>
   39 #include <sys/kernel.h>
   40 #include <sys/lock.h>
   41 #include <sys/mbuf.h>
   42 #include <sys/mutex.h>
   43 #include <sys/protosw.h>
   44 #include <sys/socket.h>
   45 #include <sys/socketvar.h>
   46 #include <sys/sysctl.h>
   47 #include <sys/systm.h>
   48 
   49 #include <net/route.h>
   50 
   51 #include <netinet/in.h>
   52 #include <netinet/in_pcb.h>
   53 #include <netinet/in_systm.h>
   54 #ifdef INET6
   55 #include <netinet6/in6_pcb.h>
   56 #endif
   57 #include <netinet/ip_var.h>
   58 #include <netinet/tcp.h>
   59 #include <netinet/tcp_fsm.h>
   60 #include <netinet/tcp_timer.h>
   61 #include <netinet/tcp_var.h>
   62 #include <netinet/tcpip.h>
   63 #ifdef TCPDEBUG
   64 #include <netinet/tcp_debug.h>
   65 #endif
   66 
   67 int     tcp_keepinit;
   68 SYSCTL_PROC(_net_inet_tcp, TCPCTL_KEEPINIT, keepinit, CTLTYPE_INT|CTLFLAG_RW,
   69     &tcp_keepinit, 0, sysctl_msec_to_ticks, "I", "");
   70 
   71 int     tcp_keepidle;
   72 SYSCTL_PROC(_net_inet_tcp, TCPCTL_KEEPIDLE, keepidle, CTLTYPE_INT|CTLFLAG_RW,
   73     &tcp_keepidle, 0, sysctl_msec_to_ticks, "I", "");
   74 
   75 int     tcp_keepintvl;
   76 SYSCTL_PROC(_net_inet_tcp, TCPCTL_KEEPINTVL, keepintvl, CTLTYPE_INT|CTLFLAG_RW,
   77     &tcp_keepintvl, 0, sysctl_msec_to_ticks, "I", "");
   78 
   79 int     tcp_delacktime;
   80 SYSCTL_PROC(_net_inet_tcp, TCPCTL_DELACKTIME, delacktime, CTLTYPE_INT|CTLFLAG_RW,
   81     &tcp_delacktime, 0, sysctl_msec_to_ticks, "I",
   82     "Time before a delayed ACK is sent");
   83 
   84 int     tcp_msl;
   85 SYSCTL_PROC(_net_inet_tcp, OID_AUTO, msl, CTLTYPE_INT|CTLFLAG_RW,
   86     &tcp_msl, 0, sysctl_msec_to_ticks, "I", "Maximum segment lifetime");
   87 
   88 int     tcp_rexmit_min;
   89 SYSCTL_PROC(_net_inet_tcp, OID_AUTO, rexmit_min, CTLTYPE_INT|CTLFLAG_RW,
   90     &tcp_rexmit_min, 0, sysctl_msec_to_ticks, "I",
   91     "Minimum Retransmission Timeout");
   92 
   93 int     tcp_rexmit_slop;
   94 SYSCTL_PROC(_net_inet_tcp, OID_AUTO, rexmit_slop, CTLTYPE_INT|CTLFLAG_RW,
   95     &tcp_rexmit_slop, 0, sysctl_msec_to_ticks, "I",
   96     "Retransmission Timer Slop");
   97 
   98 static int      always_keepalive = 1;
   99 SYSCTL_INT(_net_inet_tcp, OID_AUTO, always_keepalive, CTLFLAG_RW,
  100     &always_keepalive , 0, "Assume SO_KEEPALIVE on all TCP connections");
  101 
  102 int    tcp_fast_finwait2_recycle = 0;
  103 SYSCTL_INT(_net_inet_tcp, OID_AUTO, fast_finwait2_recycle, CTLFLAG_RW, 
  104     &tcp_fast_finwait2_recycle, 0,
  105     "Recycle closed FIN_WAIT_2 connections faster");
  106 
  107 int    tcp_finwait2_timeout;
  108 SYSCTL_PROC(_net_inet_tcp, OID_AUTO, finwait2_timeout, CTLTYPE_INT|CTLFLAG_RW,
  109     &tcp_finwait2_timeout, 0, sysctl_msec_to_ticks, "I", "FIN-WAIT2 timeout");
  110 
  111 
  112 static int      tcp_keepcnt = TCPTV_KEEPCNT;
  113         /* max idle probes */
  114 int     tcp_maxpersistidle;
  115         /* max idle time in persist */
  116 int     tcp_maxidle;
  117 
  118 /*
  119  * Tcp protocol timeout routine called every 500 ms.
  120  * Updates timestamps used for TCP
  121  * causes finite state machine actions if timers expire.
  122  */
  123 void
  124 tcp_slowtimo(void)
  125 {
  126 
  127         tcp_maxidle = tcp_keepcnt * tcp_keepintvl;
  128         INP_INFO_WLOCK(&tcbinfo);
  129         (void) tcp_tw_2msl_scan(0);
  130         INP_INFO_WUNLOCK(&tcbinfo);
  131 }
  132 
  133 int     tcp_syn_backoff[TCP_MAXRXTSHIFT + 1] =
  134     { 1, 1, 1, 1, 1, 2, 4, 8, 16, 32, 64, 64, 64 };
  135 
  136 int     tcp_backoff[TCP_MAXRXTSHIFT + 1] =
  137     { 1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 512, 512, 512 };
  138 
  139 static int tcp_totbackoff = 2559;       /* sum of tcp_backoff[] */
  140 
  141 static int tcp_timer_race;
  142 SYSCTL_INT(_net_inet_tcp, OID_AUTO, timer_race, CTLFLAG_RD, &tcp_timer_race,
  143     0, "Count of t_inpcb races on tcp_discardcb");
  144 
  145 /*
  146  * TCP timer processing.
  147  */
  148 
  149 void
  150 tcp_timer_delack(void *xtp)
  151 {
  152         struct tcpcb *tp = xtp;
  153         struct inpcb *inp;
  154 
  155         INP_INFO_RLOCK(&tcbinfo);
  156         inp = tp->t_inpcb;
  157         /*
  158          * XXXRW: While this assert is in fact correct, bugs in the tcpcb
  159          * tear-down mean we need it as a work-around for races between
  160          * timers and tcp_discardcb().
  161          *
  162          * KASSERT(inp != NULL, ("tcp_timer_delack: inp == NULL"));
  163          */
  164         if (inp == NULL) {
  165                 tcp_timer_race++;
  166                 INP_INFO_RUNLOCK(&tcbinfo);
  167                 return;
  168         }
  169         INP_WLOCK(inp);
  170         INP_INFO_RUNLOCK(&tcbinfo);
  171         if ((inp->inp_flags & INP_DROPPED) || callout_pending(&tp->t_timers->tt_delack)
  172             || !callout_active(&tp->t_timers->tt_delack)) {
  173                 INP_WUNLOCK(inp);
  174                 return;
  175         }
  176         callout_deactivate(&tp->t_timers->tt_delack);
  177 
  178         tp->t_flags |= TF_ACKNOW;
  179         tcpstat.tcps_delack++;
  180         (void) tcp_output(tp);
  181         INP_WUNLOCK(inp);
  182 }
  183 
  184 void
  185 tcp_timer_2msl(void *xtp)
  186 {
  187         struct tcpcb *tp = xtp;
  188         struct inpcb *inp;
  189 #ifdef TCPDEBUG
  190         int ostate;
  191 
  192         ostate = tp->t_state;
  193 #endif
  194         /*
  195          * XXXRW: Does this actually happen?
  196          */
  197         INP_INFO_WLOCK(&tcbinfo);
  198         inp = tp->t_inpcb;
  199         /*
  200          * XXXRW: While this assert is in fact correct, bugs in the tcpcb
  201          * tear-down mean we need it as a work-around for races between
  202          * timers and tcp_discardcb().
  203          *
  204          * KASSERT(inp != NULL, ("tcp_timer_2msl: inp == NULL"));
  205          */
  206         if (inp == NULL) {
  207                 tcp_timer_race++;
  208                 INP_INFO_WUNLOCK(&tcbinfo);
  209                 return;
  210         }
  211         INP_WLOCK(inp);
  212         tcp_free_sackholes(tp);
  213         if ((inp->inp_flags & INP_DROPPED) || callout_pending(&tp->t_timers->tt_2msl) ||
  214             !callout_active(&tp->t_timers->tt_2msl)) {
  215                 INP_WUNLOCK(tp->t_inpcb);
  216                 INP_INFO_WUNLOCK(&tcbinfo);
  217                 return;
  218         }
  219         callout_deactivate(&tp->t_timers->tt_2msl);
  220         /*
  221          * 2 MSL timeout in shutdown went off.  If we're closed but
  222          * still waiting for peer to close and connection has been idle
  223          * too long, or if 2MSL time is up from TIME_WAIT, delete connection
  224          * control block.  Otherwise, check again in a bit.
  225          *
  226          * If fastrecycle of FIN_WAIT_2, in FIN_WAIT_2 and receiver has closed, 
  227          * there's no point in hanging onto FIN_WAIT_2 socket. Just close it. 
  228          * Ignore fact that there were recent incoming segments.
  229          */
  230         if (tcp_fast_finwait2_recycle && tp->t_state == TCPS_FIN_WAIT_2 &&
  231             tp->t_inpcb && tp->t_inpcb->inp_socket && 
  232             (tp->t_inpcb->inp_socket->so_rcv.sb_state & SBS_CANTRCVMORE)) {
  233                 tcpstat.tcps_finwait2_drops++;
  234                 tp = tcp_close(tp);             
  235         } else {
  236                 if (tp->t_state != TCPS_TIME_WAIT &&
  237                     (ticks - (int)tp->t_rcvtime) <= tcp_maxidle)
  238                        callout_reset(&tp->t_timers->tt_2msl, tcp_keepintvl,
  239                                      tcp_timer_2msl, tp);
  240                else
  241                        tp = tcp_close(tp);
  242        }
  243 
  244 #ifdef TCPDEBUG
  245         if (tp != NULL && (tp->t_inpcb->inp_socket->so_options & SO_DEBUG))
  246                 tcp_trace(TA_USER, ostate, tp, (void *)0, (struct tcphdr *)0,
  247                           PRU_SLOWTIMO);
  248 #endif
  249         if (tp != NULL)
  250                 INP_WUNLOCK(inp);
  251         INP_INFO_WUNLOCK(&tcbinfo);
  252 }
  253 
  254 void
  255 tcp_timer_keep(void *xtp)
  256 {
  257         struct tcpcb *tp = xtp;
  258         struct tcptemp *t_template;
  259         struct inpcb *inp;
  260 #ifdef TCPDEBUG
  261         int ostate;
  262 
  263         ostate = tp->t_state;
  264 #endif
  265         INP_INFO_WLOCK(&tcbinfo);
  266         inp = tp->t_inpcb;
  267         /*
  268          * XXXRW: While this assert is in fact correct, bugs in the tcpcb
  269          * tear-down mean we need it as a work-around for races between
  270          * timers and tcp_discardcb().
  271          *
  272          * KASSERT(inp != NULL, ("tcp_timer_keep: inp == NULL"));
  273          */
  274         if (inp == NULL) {
  275                 tcp_timer_race++;
  276                 INP_INFO_WUNLOCK(&tcbinfo);
  277                 return;
  278         }
  279         INP_WLOCK(inp);
  280         if ((inp->inp_flags & INP_DROPPED) || callout_pending(&tp->t_timers->tt_keep)
  281             || !callout_active(&tp->t_timers->tt_keep)) {
  282                 INP_WUNLOCK(inp);
  283                 INP_INFO_WUNLOCK(&tcbinfo);
  284                 return;
  285         }
  286         callout_deactivate(&tp->t_timers->tt_keep);
  287         /*
  288          * Keep-alive timer went off; send something
  289          * or drop connection if idle for too long.
  290          */
  291         tcpstat.tcps_keeptimeo++;
  292         if (tp->t_state < TCPS_ESTABLISHED)
  293                 goto dropit;
  294         if ((always_keepalive || inp->inp_socket->so_options & SO_KEEPALIVE) &&
  295             tp->t_state <= TCPS_CLOSING) {
  296                 if ((ticks - (int)tp->t_rcvtime) >= tcp_keepidle + tcp_maxidle)
  297                         goto dropit;
  298                 /*
  299                  * Send a packet designed to force a response
  300                  * if the peer is up and reachable:
  301                  * either an ACK if the connection is still alive,
  302                  * or an RST if the peer has closed the connection
  303                  * due to timeout or reboot.
  304                  * Using sequence number tp->snd_una-1
  305                  * causes the transmitted zero-length segment
  306                  * to lie outside the receive window;
  307                  * by the protocol spec, this requires the
  308                  * correspondent TCP to respond.
  309                  */
  310                 tcpstat.tcps_keepprobe++;
  311                 t_template = tcpip_maketemplate(inp);
  312                 if (t_template) {
  313                         tcp_respond(tp, t_template->tt_ipgen,
  314                                     &t_template->tt_t, (struct mbuf *)NULL,
  315                                     tp->rcv_nxt, tp->snd_una - 1, 0);
  316                         free(t_template, M_TEMP);
  317                 }
  318                 callout_reset(&tp->t_timers->tt_keep, tcp_keepintvl, tcp_timer_keep, tp);
  319         } else
  320                 callout_reset(&tp->t_timers->tt_keep, tcp_keepidle, tcp_timer_keep, tp);
  321 
  322 #ifdef TCPDEBUG
  323         if (inp->inp_socket->so_options & SO_DEBUG)
  324                 tcp_trace(TA_USER, ostate, tp, (void *)0, (struct tcphdr *)0,
  325                           PRU_SLOWTIMO);
  326 #endif
  327         INP_WUNLOCK(inp);
  328         INP_INFO_WUNLOCK(&tcbinfo);
  329         return;
  330 
  331 dropit:
  332         tcpstat.tcps_keepdrops++;
  333         tp = tcp_drop(tp, ETIMEDOUT);
  334 
  335 #ifdef TCPDEBUG
  336         if (tp != NULL && (tp->t_inpcb->inp_socket->so_options & SO_DEBUG))
  337                 tcp_trace(TA_USER, ostate, tp, (void *)0, (struct tcphdr *)0,
  338                           PRU_SLOWTIMO);
  339 #endif
  340         if (tp != NULL)
  341                 INP_WUNLOCK(tp->t_inpcb);
  342         INP_INFO_WUNLOCK(&tcbinfo);
  343 }
  344 
  345 void
  346 tcp_timer_persist(void *xtp)
  347 {
  348         struct tcpcb *tp = xtp;
  349         struct inpcb *inp;
  350 #ifdef TCPDEBUG
  351         int ostate;
  352 
  353         ostate = tp->t_state;
  354 #endif
  355         INP_INFO_WLOCK(&tcbinfo);
  356         inp = tp->t_inpcb;
  357         /*
  358          * XXXRW: While this assert is in fact correct, bugs in the tcpcb
  359          * tear-down mean we need it as a work-around for races between
  360          * timers and tcp_discardcb().
  361          *
  362          * KASSERT(inp != NULL, ("tcp_timer_persist: inp == NULL"));
  363          */
  364         if (inp == NULL) {
  365                 tcp_timer_race++;
  366                 INP_INFO_WUNLOCK(&tcbinfo);
  367                 return;
  368         }
  369         INP_WLOCK(inp);
  370         if ((inp->inp_flags & INP_DROPPED) || callout_pending(&tp->t_timers->tt_persist)
  371             || !callout_active(&tp->t_timers->tt_persist)) {
  372                 INP_WUNLOCK(inp);
  373                 INP_INFO_WUNLOCK(&tcbinfo);
  374                 return;
  375         }
  376         callout_deactivate(&tp->t_timers->tt_persist);
  377         /*
  378          * Persistance timer into zero window.
  379          * Force a byte to be output, if possible.
  380          */
  381         tcpstat.tcps_persisttimeo++;
  382         /*
  383          * Hack: if the peer is dead/unreachable, we do not
  384          * time out if the window is closed.  After a full
  385          * backoff, drop the connection if the idle time
  386          * (no responses to probes) reaches the maximum
  387          * backoff that we would use if retransmitting.
  388          */
  389         if (tp->t_rxtshift == TCP_MAXRXTSHIFT &&
  390             ((ticks - (int)tp->t_rcvtime) >= tcp_maxpersistidle ||
  391              (ticks - (int)tp->t_rcvtime) >= TCP_REXMTVAL(tp) * tcp_totbackoff)) {
  392                 tcpstat.tcps_persistdrop++;
  393                 tp = tcp_drop(tp, ETIMEDOUT);
  394                 goto out;
  395         }
  396         tcp_setpersist(tp);
  397         tp->t_flags |= TF_FORCEDATA;
  398         (void) tcp_output(tp);
  399         tp->t_flags &= ~TF_FORCEDATA;
  400 
  401 out:
  402 #ifdef TCPDEBUG
  403         if (tp != NULL && tp->t_inpcb->inp_socket->so_options & SO_DEBUG)
  404                 tcp_trace(TA_USER, ostate, tp, NULL, NULL, PRU_SLOWTIMO);
  405 #endif
  406         if (tp != NULL)
  407                 INP_WUNLOCK(inp);
  408         INP_INFO_WUNLOCK(&tcbinfo);
  409 }
  410 
  411 void
  412 tcp_timer_rexmt(void * xtp)
  413 {
  414         struct tcpcb *tp = xtp;
  415         int rexmt;
  416         int headlocked;
  417         struct inpcb *inp;
  418 #ifdef TCPDEBUG
  419         int ostate;
  420 
  421         ostate = tp->t_state;
  422 #endif
  423         INP_INFO_WLOCK(&tcbinfo);
  424         headlocked = 1;
  425         inp = tp->t_inpcb;
  426         /*
  427          * XXXRW: While this assert is in fact correct, bugs in the tcpcb
  428          * tear-down mean we need it as a work-around for races between
  429          * timers and tcp_discardcb().
  430          *
  431          * KASSERT(inp != NULL, ("tcp_timer_rexmt: inp == NULL"));
  432          */
  433         if (inp == NULL) {
  434                 tcp_timer_race++;
  435                 INP_INFO_WUNLOCK(&tcbinfo);
  436                 return;
  437         }
  438         INP_WLOCK(inp);
  439         if ((inp->inp_flags & INP_DROPPED) || callout_pending(&tp->t_timers->tt_rexmt)
  440             || !callout_active(&tp->t_timers->tt_rexmt)) {
  441                 INP_WUNLOCK(inp);
  442                 INP_INFO_WUNLOCK(&tcbinfo);
  443                 return;
  444         }
  445         callout_deactivate(&tp->t_timers->tt_rexmt);
  446         tcp_free_sackholes(tp);
  447         /*
  448          * Retransmission timer went off.  Message has not
  449          * been acked within retransmit interval.  Back off
  450          * to a longer retransmit interval and retransmit one segment.
  451          */
  452         if (++tp->t_rxtshift > TCP_MAXRXTSHIFT) {
  453                 tp->t_rxtshift = TCP_MAXRXTSHIFT;
  454                 tcpstat.tcps_timeoutdrop++;
  455                 tp = tcp_drop(tp, tp->t_softerror ?
  456                               tp->t_softerror : ETIMEDOUT);
  457                 goto out;
  458         }
  459         INP_INFO_WUNLOCK(&tcbinfo);
  460         headlocked = 0;
  461         if (tp->t_rxtshift == 1) {
  462                 /*
  463                  * first retransmit; record ssthresh and cwnd so they can
  464                  * be recovered if this turns out to be a "bad" retransmit.
  465                  * A retransmit is considered "bad" if an ACK for this
  466                  * segment is received within RTT/2 interval; the assumption
  467                  * here is that the ACK was already in flight.  See
  468                  * "On Estimating End-to-End Network Path Properties" by
  469                  * Allman and Paxson for more details.
  470                  */
  471                 tp->snd_cwnd_prev = tp->snd_cwnd;
  472                 tp->snd_ssthresh_prev = tp->snd_ssthresh;
  473                 tp->snd_recover_prev = tp->snd_recover;
  474                 if (IN_FASTRECOVERY(tp))
  475                   tp->t_flags |= TF_WASFRECOVERY;
  476                 else
  477                   tp->t_flags &= ~TF_WASFRECOVERY;
  478                 tp->t_badrxtwin = ticks + (tp->t_srtt >> (TCP_RTT_SHIFT + 1));
  479                 tp->t_flags |= TF_PREVVALID;
  480         } else
  481                 tp->t_flags &= ~TF_PREVVALID;
  482         tcpstat.tcps_rexmttimeo++;
  483         if (tp->t_state == TCPS_SYN_SENT)
  484                 rexmt = TCP_REXMTVAL(tp) * tcp_syn_backoff[tp->t_rxtshift];
  485         else
  486                 rexmt = TCP_REXMTVAL(tp) * tcp_backoff[tp->t_rxtshift];
  487         TCPT_RANGESET(tp->t_rxtcur, rexmt,
  488                       tp->t_rttmin, TCPTV_REXMTMAX);
  489         /*
  490          * Disable rfc1323 if we haven't got any response to
  491          * our third SYN to work-around some broken terminal servers
  492          * (most of which have hopefully been retired) that have bad VJ
  493          * header compression code which trashes TCP segments containing
  494          * unknown-to-them TCP options.
  495          */
  496         if ((tp->t_state == TCPS_SYN_SENT) && (tp->t_rxtshift == 3))
  497                 tp->t_flags &= ~(TF_REQ_SCALE|TF_REQ_TSTMP);
  498         /*
  499          * If we backed off this far, our srtt estimate is probably bogus.
  500          * Clobber it so we'll take the next rtt measurement as our srtt;
  501          * move the current srtt into rttvar to keep the current
  502          * retransmit times until then.
  503          */
  504         if (tp->t_rxtshift > TCP_MAXRXTSHIFT / 4) {
  505 #ifdef INET6
  506                 if ((tp->t_inpcb->inp_vflag & INP_IPV6) != 0)
  507                         in6_losing(tp->t_inpcb);
  508                 else
  509 #endif
  510                 tp->t_rttvar += (tp->t_srtt >> TCP_RTT_SHIFT);
  511                 tp->t_srtt = 0;
  512         }
  513         tp->snd_nxt = tp->snd_una;
  514         tp->snd_recover = tp->snd_max;
  515         /*
  516          * Force a segment to be sent.
  517          */
  518         tp->t_flags |= TF_ACKNOW;
  519         /*
  520          * If timing a segment in this window, stop the timer.
  521          */
  522         tp->t_rtttime = 0;
  523         /*
  524          * Close the congestion window down to one segment
  525          * (we'll open it by one segment for each ack we get).
  526          * Since we probably have a window's worth of unacked
  527          * data accumulated, this "slow start" keeps us from
  528          * dumping all that data as back-to-back packets (which
  529          * might overwhelm an intermediate gateway).
  530          *
  531          * There are two phases to the opening: Initially we
  532          * open by one mss on each ack.  This makes the window
  533          * size increase exponentially with time.  If the
  534          * window is larger than the path can handle, this
  535          * exponential growth results in dropped packet(s)
  536          * almost immediately.  To get more time between
  537          * drops but still "push" the network to take advantage
  538          * of improving conditions, we switch from exponential
  539          * to linear window opening at some threshhold size.
  540          * For a threshhold, we use half the current window
  541          * size, truncated to a multiple of the mss.
  542          *
  543          * (the minimum cwnd that will give us exponential
  544          * growth is 2 mss.  We don't allow the threshhold
  545          * to go below this.)
  546          */
  547         {
  548                 u_int win = min(tp->snd_wnd, tp->snd_cwnd) / 2 / tp->t_maxseg;
  549                 if (win < 2)
  550                         win = 2;
  551                 tp->snd_cwnd = tp->t_maxseg;
  552                 tp->snd_ssthresh = win * tp->t_maxseg;
  553                 tp->t_dupacks = 0;
  554         }
  555         EXIT_FASTRECOVERY(tp);
  556         (void) tcp_output(tp);
  557 
  558 out:
  559 #ifdef TCPDEBUG
  560         if (tp != NULL && (tp->t_inpcb->inp_socket->so_options & SO_DEBUG))
  561                 tcp_trace(TA_USER, ostate, tp, (void *)0, (struct tcphdr *)0,
  562                           PRU_SLOWTIMO);
  563 #endif
  564         if (tp != NULL)
  565                 INP_WUNLOCK(inp);
  566         if (headlocked)
  567                 INP_INFO_WUNLOCK(&tcbinfo);
  568 }
  569 
  570 void
  571 tcp_timer_activate(struct tcpcb *tp, int timer_type, u_int delta)
  572 {
  573         struct callout *t_callout;
  574         void *f_callout;
  575 
  576         switch (timer_type) {
  577                 case TT_DELACK:
  578                         t_callout = &tp->t_timers->tt_delack;
  579                         f_callout = tcp_timer_delack;
  580                         break;
  581                 case TT_REXMT:
  582                         t_callout = &tp->t_timers->tt_rexmt;
  583                         f_callout = tcp_timer_rexmt;
  584                         break;
  585                 case TT_PERSIST:
  586                         t_callout = &tp->t_timers->tt_persist;
  587                         f_callout = tcp_timer_persist;
  588                         break;
  589                 case TT_KEEP:
  590                         t_callout = &tp->t_timers->tt_keep;
  591                         f_callout = tcp_timer_keep;
  592                         break;
  593                 case TT_2MSL:
  594                         t_callout = &tp->t_timers->tt_2msl;
  595                         f_callout = tcp_timer_2msl;
  596                         break;
  597                 default:
  598                         panic("bad timer_type");
  599                 }
  600         if (delta == 0) {
  601                 callout_stop(t_callout);
  602         } else {
  603                 callout_reset(t_callout, delta, f_callout, tp);
  604         }
  605 }
  606 
  607 int
  608 tcp_timer_active(struct tcpcb *tp, int timer_type)
  609 {
  610         struct callout *t_callout;
  611 
  612         switch (timer_type) {
  613                 case TT_DELACK:
  614                         t_callout = &tp->t_timers->tt_delack;
  615                         break;
  616                 case TT_REXMT:
  617                         t_callout = &tp->t_timers->tt_rexmt;
  618                         break;
  619                 case TT_PERSIST:
  620                         t_callout = &tp->t_timers->tt_persist;
  621                         break;
  622                 case TT_KEEP:
  623                         t_callout = &tp->t_timers->tt_keep;
  624                         break;
  625                 case TT_2MSL:
  626                         t_callout = &tp->t_timers->tt_2msl;
  627                         break;
  628                 default:
  629                         panic("bad timer_type");
  630                 }
  631         return callout_active(t_callout);
  632 }

Cache object: 8bf7301a22f355a1e3b28511d3d59b43


[ source navigation ] [ diff markup ] [ identifier search ] [ freetext search ] [ file search ] [ list types ] [ track identifier ]


This page is part of the FreeBSD/Linux Linux Kernel Cross-Reference, and was automatically generated using a modified version of the LXR engine.