Add support to set window_clamp from bpf setsockops
Subsystems (6)
cover Add support to set window_clamp from bpf setsockops
This patch contains support to set tcp window_field field from bpf setsockops.
Prankur gupta (2):
bpf: Adds support for setting window clamp selftests/bpf: Add Userspace tests for TCP_WINDOW_CLAMP
net/core/filter.c | 8 +++++ tools/testing/selftests/bpf/bpf_tcp_helpers.h | 1 + .../selftests/bpf/prog_tests/tcpbpf_user.c | 4 +++ .../selftests/bpf/progs/test_tcpbpf_kern.c | 33 +++++++++++++++++++ tools/testing/selftests/bpf/test_tcpbpf.h | 2 ++ 5 files changed, 48 insertions(+)
Signature · 1 line
2.24.1
PATCH 1/2 bpf: Adds support for setting window clamp
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.
--- net/core/filter.c | 8 ++++++++ 1 file changed, 8 insertions(+)
net/core/filter.c +8 -0
@@ -4910,6 +4910,14 @@ 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 : +if (val <=0 ) + ret = -EINVAL ; +else + tp->window_clamp = +max_t (int, val, +SOCK_MIN_RCVBUF /2 ); +break ;default : ret = -EINVAL ; }
Signature · 1 line
2.24.1
Re: [PATCH bpf-next 1/2] bpf: Adds support for setting window clamp
Quoted 15 lines · Prankur gupta
Adds a new
bpf_setsockoptfor 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 <[email protected]>--- net/core/filter.c | 8 ++++++++ 1 file changed, 8 insertions(+)net/core/filter.c +0
-0
net/core/filter.c static int _bpf_setsockopt(struct sock *sk, int level, int optname, · line 4915
Quoted 6 lines
net/core/filter.c +3
-0@@ -4910,6 +4910,14 @@ 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 : +if (val <=0 ) + ret = -EINVAL ;
Why zero is not allowed?
Normal setsockopt() allows it.
Quoted 11 lines
net/core/filter.c +5
-1+else + tp->window_clamp = +max_t (int, val, +SOCK_MIN_RCVBUF /2 ); +break ;default : ret = -EINVAL ; } --2.24.1
From: Prankur Gupta <[email protected]>
No reason in particular.
Updated the code (patch v2) to have logic as tcp setsockopt for tCP_WINDOW_CLAMP.
PS: First time trying git send-em,ail, pleas elet me know if this is not the right way to reply.
Quoted 7 lines · Prankur gupta
From: Prankur Gupta <[email protected]>
No reason in particular.
Updated the code (patch v2) to have logic as tcp setsockopt fortCP_WINDOW_CLAMP.PS: First time trying git send-em,ail, pleas elet me know if this is not the right way to reply.
I use send-email for sending patches only, I reply from Gmail or Thunderbird (from work account). The latter has a plain text mode, while Outlook doesn't.
But also, you need to add v2 to each patch, not just cover letter. You can do that when using git format-patch --subject-prefix='PATCH v2 bpf-next' ....
PATCH 2/2 selftests/bpf: Add Userspace tests for TCP_WINDOW_CLAMP
In reply to Prankur guptaAdding selftests for new added functionality to set TCP_WINDOW_CLAMP from bpf setsockopt.
--- tools/testing/selftests/bpf/bpf_tcp_helpers.h | 1 + .../selftests/bpf/prog_tests/tcpbpf_user.c | 4 +++ .../selftests/bpf/progs/test_tcpbpf_kern.c | 33 +++++++++++++++++++ tools/testing/selftests/bpf/test_tcpbpf.h | 2 ++ 4 files changed, 40 insertions(+)
tools/testing/selftests/bpf/bpf_tcp_helpers.h +1 -0
@@ -56,6 +56,7 @@ struct tcp_sock {__u32 rcv_nxt;__u32 snd_nxt;__u32 snd_una; +__u32 window_clamp;__u8 ecn_flags;__u32 delivered;__u32 delivered_ce;
tools/testing/selftests/bpf/prog_tests/tcpbpf_user.c +4 -0
@@ -42,6 +42,10 @@ static void verify_result(struct tcpbpf_globals *result)/* check getsockopt for SAVED_SYN */ ASSERT_EQ (result->tcp_saved_syn,1 ,"tcp_saved_syn" ); + +/* check getsockopt for window_clamp */ +ASSERT_EQ (result->window_clamp_client,9216 ,"window_clamp_client" ); +ASSERT_EQ (result->window_clamp_server,9216 ,"window_clamp_server" ); }static void run_test (struct tcpbpf_globals *result)
tools/testing/selftests/bpf/progs/test_tcpbpf_kern.c +33 -0
@@ -12,17 +12,41 @@#include <linux/tcp.h> #include <bpf/bpf_helpers.h> #include <bpf/bpf_endian.h> +#include "bpf_tcp_helpers.h" #include "test_tcpbpf.h" struct tcpbpf_globals global = {}; int _version SEC("version") = 1; +/** +* SOL_TCP is defined in <netinet/tcp.h> while +* TCP_SAVED_SYN is defined in already included <linux/tcp.h> +*/ +#ifndef SOL_TCP +#define SOL_TCP 6 +#endif + +static __always_inline int get_tp_window_clamp(struct bpf_sock_ops *skops) +{ +struct bpf_sock *sk; +struct tcp_sock *tp; + + sk = skops->sk; +if (!sk) +return -1 ; + tp =bpf_skc_to_tcp_sock (sk); +if (!tp) +return -1 ; +return tp->window_clamp; +} + SEC("sockops")int bpf_testcb (struct bpf_sock_ops *skops) {char header[sizeof (struct ipv6hdr ) +sizeof (struct tcphdr )];struct bpf_sock_ops *reuse = skops;struct tcphdr *thdr; +int window_clamp =9216 ;int good_call_rv =0 ;int bad_call_rv =0 ;int save_syn =1 ;
@@ -75,6 +99,11 @@ int bpf_testcb(struct bpf_sock_ops *skops) global.event_map |= (1 << op);switch (op) { +case BPF_SOCK_OPS_TCP_CONNECT_CB : + rv =bpf_setsockopt (skops,SOL_TCP ,TCP_WINDOW_CLAMP , + &window_clamp,sizeof (window_clamp)); + global.window_clamp_client =get_tp_window_clamp (skops); +break ;case BPF_SOCK_OPS_ACTIVE_ESTABLISHED_CB :/* Test failure to set largest cb flag (assumes not defined) */ global.bad_cb_test_rv =bpf_sock_ops_cb_flags_set (skops,0x80 );
@@ -100,6 +129,10 @@ int bpf_testcb(struct bpf_sock_ops *skops) global.tcp_saved_syn = v; } } + rv =bpf_setsockopt (skops,SOL_TCP ,TCP_WINDOW_CLAMP , + &window_clamp,sizeof (window_clamp)); + + global.window_clamp_server =get_tp_window_clamp (skops);break ;case BPF_SOCK_OPS_RTO_CB :break ;
tools/testing/selftests/bpf/test_tcpbpf.h +2 -0
@@ -16,5 +16,7 @@ struct tcpbpf_globals {__u32 num_close_events;__u32 tcp_save_syn;__u32 tcp_saved_syn; +__u32 window_clamp_client; + __u32 window_clamp_server; };#endif
Signature · 1 line
2.24.1