netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Eric Dumazet <eric.dumazet@gmail.com>
To: Prankur gupta <prankgup@fb.com>, bpf@vger.kernel.org
Cc: kernel-team@fb.com, netdev@vger.kernel.org
Subject: Re: [PATCH v3 bpf-next 1/2] bpf: Adds support for setting window clamp
Date: Wed, 2 Dec 2020 21:44:36 +0100	[thread overview]
Message-ID: <14fc7e89-29ae-0657-d626-e0417f2043e4@gmail.com> (raw)
In-Reply-To: <20201202202925.165803-2-prankgup@fb.com>



On 12/2/20 9:29 PM, Prankur gupta wrote:
> Adds a new bpf_setsockopt for TCP sockets, TCP_BPF_WINDOW_CLAMP,
> which sets the maximum receiver window size. It will be useful for
> limiting receiver window based on RTT.
> 
> Signed-off-by: Prankur gupta <prankgup@fb.com>
> ---
>  include/net/tcp.h |  1 +
>  net/core/filter.c |  3 +++
>  net/ipv4/tcp.c    | 23 ++++++++++++++---------
>  3 files changed, 18 insertions(+), 9 deletions(-)
> 
> diff --git a/include/net/tcp.h b/include/net/tcp.h
> index 4aba0f069b05..39ced5882fe3 100644
> --- a/include/net/tcp.h
> +++ b/include/net/tcp.h
> @@ -406,6 +406,7 @@ void tcp_syn_ack_timeout(const struct request_sock *req);
>  int tcp_recvmsg(struct sock *sk, struct msghdr *msg, size_t len, int nonblock,
>  		int flags, int *addr_len);
>  int tcp_set_rcvlowat(struct sock *sk, int val);
> +int tcp_set_window_clamp(struct sock *sk, struct tcp_sock *tp, int val);
>  void tcp_data_ready(struct sock *sk);
>  #ifdef CONFIG_MMU
>  int tcp_mmap(struct file *file, struct socket *sock,
> diff --git a/net/core/filter.c b/net/core/filter.c
> index 2ca5eecebacf..d6225842cfb1 100644
> --- a/net/core/filter.c
> +++ b/net/core/filter.c
> @@ -4910,6 +4910,9 @@ static int _bpf_setsockopt(struct sock *sk, int level, int optname,
>  				tp->notsent_lowat = val;
>  				sk->sk_write_space(sk);
>  				break;
> +			case TCP_WINDOW_CLAMP:
> +				ret = tcp_set_window_clamp(sk, tp, val);
> +				break;
>  			default:
>  				ret = -EINVAL;
>  			}
> diff --git a/net/ipv4/tcp.c b/net/ipv4/tcp.c
> index b2bc3d7fe9e8..312feb8fcae5 100644
> --- a/net/ipv4/tcp.c
> +++ b/net/ipv4/tcp.c
> @@ -3022,6 +3022,19 @@ int tcp_sock_set_keepcnt(struct sock *sk, int val)
>  }
>  EXPORT_SYMBOL(tcp_sock_set_keepcnt);
>  
> +int tcp_set_window_clamp(struct sock *sk, struct tcp_sock *tp, int val)

No TCP function pass both sk and tp (which are identical values)

Prefer :

int tcp_set_window_clamp(struct sock *sk, int val)
{
        struct tcp_sock *tp = tcp_sk(sk);
        ...

This will allow optimal code generation.

> +{
> +	if (!val) {
> +		if (sk->sk_state != TCP_CLOSE)
> +			return -EINVAL;
> +		tp->window_clamp = 0;
> +	} else {
> +		tp->window_clamp = val < SOCK_MIN_RCVBUF / 2 ?
> +			SOCK_MIN_RCVBUF / 2 : val;
> +	}
> +	return 0;
> +}
> +
>  /*
>   *	Socket option code for TCP.
>   */
> @@ -3235,15 +3248,7 @@ static int do_tcp_setsockopt(struct sock *sk, int level, int optname,
>  		break;
>  
>  	case TCP_WINDOW_CLAMP:
> -		if (!val) {
> -			if (sk->sk_state != TCP_CLOSE) {
> -				err = -EINVAL;
> -				break;
> -			}
> -			tp->window_clamp = 0;
> -		} else
> -			tp->window_clamp = val < SOCK_MIN_RCVBUF / 2 ?
> -						SOCK_MIN_RCVBUF / 2 : val;
> +		err = tcp_set_window_clamp(sk, tp, val);
>  		break;
>  
>  	case TCP_QUICKACK:
> 

  reply	other threads:[~2020-12-02 20:45 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-12-02 20:29 [PATCH v3 bpf-next 0/2] Add support to set window_clamp from bpf setsockops Prankur gupta
2020-12-02 20:29 ` [PATCH v3 bpf-next 1/2] bpf: Adds support for setting window clamp Prankur gupta
2020-12-02 20:44   ` Eric Dumazet [this message]
2020-12-02 20:29 ` [PATCH v3 bpf-next 2/2] selftests/bpf: Add Userspace tests for TCP_WINDOW_CLAMP Prankur gupta

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=14fc7e89-29ae-0657-d626-e0417f2043e4@gmail.com \
    --to=eric.dumazet@gmail.com \
    --cc=bpf@vger.kernel.org \
    --cc=kernel-team@fb.com \
    --cc=netdev@vger.kernel.org \
    --cc=prankgup@fb.com \
    /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;
as well as URLs for NNTP newsgroup(s).