BSD 4_3_Tahoe release
[unix-history] / usr / src / sys / netinet / tcp_timer.c
index 18d6a63..45f827f 100644 (file)
@@ -1,9 +1,20 @@
 /*
  * Copyright (c) 1982, 1986 Regents of the University of California.
 /*
  * Copyright (c) 1982, 1986 Regents of the University of California.
- * All rights reserved.  The Berkeley software License Agreement
- * specifies the terms and conditions for redistribution.
+ * All rights reserved.
  *
  *
- *     @(#)tcp_timer.c 7.9 (Berkeley) %G%
+ * Redistribution and use in source and binary forms are permitted
+ * provided that the above copyright notice and this paragraph are
+ * duplicated in all such forms and that any documentation,
+ * advertising materials, and other materials related to such
+ * distribution and use acknowledge that the software was developed
+ * by the University of California, Berkeley.  The name of the
+ * University may not be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
+ * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
+ *
+ *     @(#)tcp_timer.c 7.14 (Berkeley) 6/29/88
  */
 
 #include "param.h"
  */
 
 #include "param.h"
@@ -29,7 +40,9 @@
 #include "tcp_var.h"
 #include "tcpip.h"
 
 #include "tcp_var.h"
 #include "tcpip.h"
 
-int    tcpnodelack = 0;
+int    tcp_keepidle = TCPTV_KEEP_IDLE;
+int    tcp_keepintvl = TCPTV_KEEPINTVL;
+int    tcp_maxidle;
 /*
  * Fast timeout routine for processing delayed acks
  */
 /*
  * Fast timeout routine for processing delayed acks
  */
@@ -64,6 +77,7 @@ tcp_slowtimo()
        int s = splnet();
        register int i;
 
        int s = splnet();
        register int i;
 
+       tcp_maxidle = TCPTV_KEEPCNT * tcp_keepintvl;
        /*
         * Search through tcb's and update active timers.
         */
        /*
         * Search through tcb's and update active timers.
         */
@@ -135,8 +149,8 @@ tcp_timers(tp, timer)
         */
        case TCPT_2MSL:
                if (tp->t_state != TCPS_TIME_WAIT &&
         */
        case TCPT_2MSL:
                if (tp->t_state != TCPS_TIME_WAIT &&
-                   tp->t_idle <= TCPTV_MAXIDLE)
-                       tp->t_timer[TCPT_2MSL] = TCPTV_KEEP;
+                   tp->t_idle <= tcp_maxidle)
+                       tp->t_timer[TCPT_2MSL] = tcp_keepintvl;
                else
                        tp = tcp_close(tp);
                break;
                else
                        tp = tcp_close(tp);
                break;
@@ -183,8 +197,30 @@ tcp_timers(tp, timer)
                 * data accumulated, this "slow start" keeps us from
                 * dumping all that data as back-to-back packets (which
                 * might overwhelm an intermediate gateway).
                 * data accumulated, this "slow start" keeps us from
                 * dumping all that data as back-to-back packets (which
                 * might overwhelm an intermediate gateway).
+                *
+                * There are two phases to the opening: Initially we
+                * open by one mss on each ack.  This makes the window
+                * size increase exponentially with time.  If the
+                * window is larger than the path can handle, this
+                * exponential growth results in dropped packet(s)
+                * almost immediately.  To get more time between 
+                * drops but still "push" the network to take advantage
+                * of improving conditions, we switch from exponential
+                * to linear window opening at some threshhold size.
+                * For a threshhold, we use half the current window
+                * size, truncated to a multiple of the mss.
+                *
+                * (the minimum cwnd that will give us exponential
+                * growth is 2 mss.  We don't allow the threshhold
+                * to go below this.)
                 */
                 */
+               {
+               u_int win = MIN(tp->snd_wnd, tp->snd_cwnd) / 2 / tp->t_maxseg;
+               if (win < 2)
+                       win = 2;
                tp->snd_cwnd = tp->t_maxseg;
                tp->snd_cwnd = tp->t_maxseg;
+               tp->snd_ssthresh = win * tp->t_maxseg;
+               }
                (void) tcp_output(tp);
                break;
 
                (void) tcp_output(tp);
                break;
 
@@ -210,7 +246,7 @@ tcp_timers(tp, timer)
                        goto dropit;
                if (tp->t_inpcb->inp_socket->so_options & SO_KEEPALIVE &&
                    tp->t_state <= TCPS_CLOSE_WAIT) {
                        goto dropit;
                if (tp->t_inpcb->inp_socket->so_options & SO_KEEPALIVE &&
                    tp->t_state <= TCPS_CLOSE_WAIT) {
-                       if (tp->t_idle >= TCPTV_MAXIDLE)
+                       if (tp->t_idle >= tcp_keepidle + tcp_maxidle)
                                goto dropit;
                        /*
                         * Send a packet designed to force a response
                                goto dropit;
                        /*
                         * Send a packet designed to force a response
@@ -236,8 +272,9 @@ tcp_timers(tp, timer)
                        tcp_respond(tp, tp->t_template,
                            tp->rcv_nxt, tp->snd_una - 1, 0);
 #endif
                        tcp_respond(tp, tp->t_template,
                            tp->rcv_nxt, tp->snd_una - 1, 0);
 #endif
-               }
-               tp->t_timer[TCPT_KEEP] = TCPTV_KEEP;
+                       tp->t_timer[TCPT_KEEP] = tcp_keepintvl;
+               } else
+                       tp->t_timer[TCPT_KEEP] = tcp_keepidle;
                break;
        dropit:
                tcpstat.tcps_keepdrops++;
                break;
        dropit:
                tcpstat.tcps_keepdrops++;