From fb8d5c6dd08d24fd5b9446fcab778124489e30b8 Mon Sep 17 00:00:00 2001 From: Sepherosa Ziehau Date: Thu, 19 Apr 2012 15:16:39 +0800 Subject: [PATCH] tcp: Reimplement TCP_FASTKEEP socket option using per-pcb keepidle Retired now used TF_FASTKEEP --- sys/netinet/tcp_input.c | 4 ++-- sys/netinet/tcp_timer.c | 10 +++------- sys/netinet/tcp_timer2.h | 13 ------------- sys/netinet/tcp_usrreq.c | 13 +++++-------- sys/netinet/tcp_var.h | 2 +- 5 files changed, 11 insertions(+), 31 deletions(-) diff --git a/sys/netinet/tcp_input.c b/sys/netinet/tcp_input.c index 84b20bf..d6773cc 100644 --- a/sys/netinet/tcp_input.c +++ b/sys/netinet/tcp_input.c @@ -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) { /* diff --git a/sys/netinet/tcp_timer.c b/sys/netinet/tcp_timer.c index aecddc9..66180d0 100644 --- a/sys/netinet/tcp_timer.c +++ b/sys/netinet/tcp_timer.c @@ -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); } diff --git a/sys/netinet/tcp_timer2.h b/sys/netinet/tcp_timer2.h index 1f17080..32abc96 100644 --- a/sys/netinet/tcp_timer2.h +++ b/sys/netinet/tcp_timer2.h @@ -64,19 +64,6 @@ #include #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) { diff --git a/sys/netinet/tcp_usrreq.c b/sys/netinet/tcp_usrreq.c index 1b3eb0c..74ca197 100644 --- a/sys/netinet/tcp_usrreq.c +++ b/sys/netinet/tcp_usrreq.c @@ -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: diff --git a/sys/netinet/tcp_var.h b/sys/netinet/tcp_var.h index f041c1f..523ddfc 100644 --- a/sys/netinet/tcp_var.h +++ b/sys/netinet/tcp_var.h @@ -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 */ -- 1.7.7.2