Netdev List
 help / color / mirror / Atom feed
From: Eric Dumazet <eric.dumazet@gmail.com>
To: Flavio Leitner <fleitner@redhat.com>
Cc: netdev@vger.kernel.org, David Miller <davem@davemloft.net>,
	Ilpo <ilpo.jarvinen@helsinki.fi>
Subject: Re: [PATCH v4] TCP: avoid to send keepalive probes if receiving data
Date: Tue, 27 Apr 2010 07:06:51 +0200	[thread overview]
Message-ID: <1272344811.4861.4.camel@edumazet-laptop> (raw)
In-Reply-To: <1272342807-13379-1-git-send-email-fleitner@redhat.com>

Le mardi 27 avril 2010 à 01:33 -0300, Flavio Leitner a écrit :
> RFC 1122 says the following:
> ...
>   Keep-alive packets MUST only be sent when no data or
>   acknowledgement packets have been received for the
>   connection within an interval.
> ...
> 
> The acknowledgement packet is reseting the keepalive
> timer but the data packet isn't. This patch fixes it by
> checking the timestamp of the last received data packet
> too when the keepalive timer expires.
> 
> Signed-off-by: Flavio Leitner <fleitner@redhat.com>
> ---

Signed-off-by: Eric Dumazet <eric.dumazet@gmail.com>

>  include/net/tcp.h    |    8 ++++++++
>  net/ipv4/tcp.c       |    2 +-
>  net/ipv4/tcp_timer.c |    4 ++--
>  3 files changed, 11 insertions(+), 3 deletions(-)
> 
> diff --git a/include/net/tcp.h b/include/net/tcp.h
> index 75be5a2..305810e 100644
> --- a/include/net/tcp.h
> +++ b/include/net/tcp.h
> @@ -1032,6 +1032,14 @@ static inline int keepalive_probes(const struct tcp_sock *tp)
>  	return tp->keepalive_probes ? : sysctl_tcp_keepalive_probes;
>  }
>  
> +static inline u32 keepalive_time_elapsed(const struct tcp_sock *tp)
> +{
> +	const struct inet_connection_sock *icsk = &tp->inet_conn;
> +
> +	return min_t(u32, tcp_time_stamp - icsk->icsk_ack.lrcvtime,
> +			  tcp_time_stamp - tp->rcv_tstamp);
> +}
> +
>  static inline int tcp_fin_time(const struct sock *sk)
>  {
>  	int fin_timeout = tcp_sk(sk)->linger2 ? : sysctl_tcp_fin_timeout;
> diff --git a/net/ipv4/tcp.c b/net/ipv4/tcp.c
> index 0f8caf6..48a6f33 100644
> --- a/net/ipv4/tcp.c
> +++ b/net/ipv4/tcp.c
> @@ -2298,7 +2298,7 @@ static int do_tcp_setsockopt(struct sock *sk, int level,
>  			if (sock_flag(sk, SOCK_KEEPOPEN) &&
>  			    !((1 << sk->sk_state) &
>  			      (TCPF_CLOSE | TCPF_LISTEN))) {
> -				__u32 elapsed = tcp_time_stamp - tp->rcv_tstamp;
> +				u32 elapsed = keepalive_time_elapsed(tp);
>  				if (tp->keepalive_time > elapsed)
>  					elapsed = tp->keepalive_time - elapsed;
>  				else
> diff --git a/net/ipv4/tcp_timer.c b/net/ipv4/tcp_timer.c
> index 8a0ab29..a9155f9 100644
> --- a/net/ipv4/tcp_timer.c
> +++ b/net/ipv4/tcp_timer.c
> @@ -517,7 +517,7 @@ static void tcp_keepalive_timer (unsigned long data)
>  	struct sock *sk = (struct sock *) data;
>  	struct inet_connection_sock *icsk = inet_csk(sk);
>  	struct tcp_sock *tp = tcp_sk(sk);
> -	__u32 elapsed;
> +	u32 elapsed;
>  
>  	/* Only process if socket is not in use. */
>  	bh_lock_sock(sk);
> @@ -554,7 +554,7 @@ static void tcp_keepalive_timer (unsigned long data)
>  	if (tp->packets_out || tcp_send_head(sk))
>  		goto resched;
>  
> -	elapsed = tcp_time_stamp - tp->rcv_tstamp;
> +	elapsed = keepalive_time_elapsed(tp);
>  
>  	if (elapsed >= keepalive_time_when(tp)) {
>  		if (icsk->icsk_probes_out >= keepalive_probes(tp)) {



  reply	other threads:[~2010-04-27  5:06 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-04-16 15:06 TCP keepalive question Flavio Leitner
2010-04-17 17:28 ` [PATCH] TCP: avoid to send keepalive probes if it is receiving data Flavio Leitner
2010-04-18  9:06   ` Eric Dumazet
2010-04-18 14:55     ` [PATCH v2] " Flavio Leitner
2010-04-18 17:15       ` Eric Dumazet
2010-04-18 20:34         ` Ilpo Järvinen
2010-04-22  5:42           ` David Miller
2010-04-25 23:55             ` Flavio Leitner
2010-04-26  2:40               ` [PATCH v3] TCP: avoid to send keepalive probes if " Flavio Leitner
2010-04-26  9:47                 ` Ilpo Järvinen
2010-04-26 18:24                   ` David Miller
2010-04-27  4:33                     ` [PATCH v4] " Flavio Leitner
2010-04-27  5:06                       ` Eric Dumazet [this message]
2010-04-27  6:08                       ` Ilpo Järvinen
2010-04-27 19:55                         ` David Miller
2010-04-25 23:44         ` [PATCH v2] TCP: avoid to send keepalive probes if it is " Flavio Leitner

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1272344811.4861.4.camel@edumazet-laptop \
    --to=eric.dumazet@gmail.com \
    --cc=davem@davemloft.net \
    --cc=fleitner@redhat.com \
    --cc=ilpo.jarvinen@helsinki.fi \
    --cc=netdev@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox