tcp: Reimplement TCP_FASTKEEP socket option using per-pcb keepidle
authorSepherosa Ziehau <sephe@dragonflybsd.org>
Thu, 19 Apr 2012 07:16:39 +0000 (15:16 +0800)
committerSepherosa Ziehau <sephe@dragonflybsd.org>
Thu, 19 Apr 2012 07:16:39 +0000 (15:16 +0800)
Retired now used TF_FASTKEEP

sys/netinet/tcp_input.c
sys/netinet/tcp_timer.c
sys/netinet/tcp_timer2.h
sys/netinet/tcp_usrreq.c
sys/netinet/tcp_var.h

index 84b20bf..d6773cc 100644 (file)
@@ -3167,7 +3167,7 @@ tcp_timer_keep_activity(struct tcpcb *tp, int thflags)
                        tp->t_rcvtime = ticks;
                        tp->t_flags &= ~TF_KEEPALIVE;
                        tcp_callout_reset(tp, tp->tt_keep,
-                                         tcp_getkeepidle(tp),
+                                         tp->t_keepidle,
                                          tcp_timer_keep);
                }
        }
@@ -3203,7 +3203,7 @@ static void
 tcp_established(struct tcpcb *tp)
 {
        tp->t_state = TCPS_ESTABLISHED;
-       tcp_callout_reset(tp, tp->tt_keep, tcp_getkeepidle(tp), tcp_timer_keep);
+       tcp_callout_reset(tp, tp->tt_keep, tp->t_keepidle, tcp_timer_keep);
 
        if (tp->t_rxtsyn > 0) {
                /*
index aecddc9..66180d0 100644 (file)
@@ -316,13 +316,9 @@ tcp_timer_keep_handler(struct tcpcb *tp)
 {
        struct tcptemp *t_template;
 #ifdef TCPDEBUG
-       int ostate;
+       int ostate = tp->t_state;
 #endif
-       int keepidle = tcp_getkeepidle(tp);
 
-#ifdef TCPDEBUG
-       ostate = tp->t_state;
-#endif
        /*
         * Keep-alive timer went off; send something
         * or drop connection if idle for too long.
@@ -333,7 +329,7 @@ tcp_timer_keep_handler(struct tcpcb *tp)
        if ((always_keepalive || (tp->t_flags & TF_KEEPALIVE) ||
             (tp->t_inpcb->inp_socket->so_options & SO_KEEPALIVE)) &&
            tp->t_state <= TCPS_CLOSING) {
-               if ((ticks - tp->t_rcvtime) >= keepidle + tp->t_maxidle)
+               if ((ticks - tp->t_rcvtime) >= tp->t_keepidle + tp->t_maxidle)
                        goto dropit;
                /*
                 * Send a packet designed to force a response
@@ -358,7 +354,7 @@ tcp_timer_keep_handler(struct tcpcb *tp)
                tcp_callout_reset(tp, tp->tt_keep, tp->t_keepintvl,
                                  tcp_timer_keep);
        } else {
-               tcp_callout_reset(tp, tp->tt_keep, keepidle,
+               tcp_callout_reset(tp, tp->tt_keep, tp->t_keepidle,
                                  tcp_timer_keep);
        }
 
index 1f17080..32abc96 100644 (file)
 #include <netinet/tcp_timer.h>
 #endif
 
-/*
- * The TCP_FASTKEEP option uses keepintvl for the initial keepidle timeout
- * instead of keepidle.
- */
-static __inline int
-tcp_getkeepidle(struct tcpcb *_tp)
-{
-       if (_tp->t_flags & TF_FASTKEEP)
-               return (_tp->t_keepintvl);
-       else
-               return (_tp->t_keepidle);
-}
-
 static __inline void
 tcp_callout_stop(struct tcpcb *_tp, struct tcp_callout *_tc)
 {
index 1b3eb0c..74ca197 100644 (file)
@@ -1342,14 +1342,11 @@ tcp_ctloutput(netmsg_t msg)
                        break;
                switch (sopt->sopt_name) {
                case TCP_FASTKEEP:
-                       if (optval > 0) {
-                               if ((tp->t_flags & TF_FASTKEEP) == 0) {
-                                       tp->t_flags |= TF_FASTKEEP;
-                                       tcp_timer_keep_activity(tp, 0);
-                               }
-                       } else {
-                               tp->t_flags &= ~TF_FASTKEEP;
-                       }
+                       if (optval > 0)
+                               tp->t_keepidle = tp->t_keepintvl;
+                       else
+                               tp->t_keepidle = tcp_keepidle;
+                       tcp_timer_keep_activity(tp, 0);
                        break;
 #ifdef TCP_SIGNATURE
                case TCP_SIGNATURE_ENABLE:
index f041c1f..523ddfc 100644 (file)
@@ -162,7 +162,7 @@ struct tcpcb {
 #define        TF_NOPUSH       0x00001000      /* don't push */
 #define TF_LISTEN      0x00002000      /* listen(2) has been called */
 #define TF_SIGNATURE   0x00004000      /* require MD5 digests (RFC2385) */
-#define TF_FASTKEEP    0x00008000      /* use a faster tcp_keepidle */
+#define TF_UNUSED01    0x00008000      /* unused */
 #define        TF_MORETOCOME   0x00010000      /* More data to be appended to sock */
 #define        TF_UNUSED00     0x00020000      /* unused */
 #define        TF_LASTIDLE     0x00040000      /* connection was previously idle */