* [PATCH bpf-next] bpf: add tcp_notsent_lowat bpf setsockopt
@ 2020-10-09 5:08 Nikita V. Shirokov
2020-10-09 6:27 ` Yonghong Song
0 siblings, 1 reply; 3+ messages in thread
From: Nikita V. Shirokov @ 2020-10-09 5:08 UTC (permalink / raw)
To: bpf
Cc: Alexei Starovoitov, Daniel Borkmann, Martin KaFai Lau, netdev,
Nikita V. Shirokov
Adding support for TCP_NOTSENT_LOWAT sockoption
(https://lwn.net/Articles/560082/) in tcpbpf
Signed-off-by: Nikita V. Shirokov <tehnerd@tehnerd.com>
---
include/uapi/linux/bpf.h | 2 +-
net/core/filter.c | 4 ++++
tools/testing/selftests/bpf/progs/connect4_prog.c | 15 +++++++++++++++
3 files changed, 20 insertions(+), 1 deletion(-)
diff --git a/include/uapi/linux/bpf.h b/include/uapi/linux/bpf.h
index d83561e8cd2c..42d2df799397 100644
--- a/include/uapi/linux/bpf.h
+++ b/include/uapi/linux/bpf.h
@@ -1698,7 +1698,7 @@ union bpf_attr {
* **TCP_CONGESTION**, **TCP_BPF_IW**,
* **TCP_BPF_SNDCWND_CLAMP**, **TCP_SAVE_SYN**,
* **TCP_KEEPIDLE**, **TCP_KEEPINTVL**, **TCP_KEEPCNT**,
- * **TCP_SYNCNT**, **TCP_USER_TIMEOUT**.
+ * **TCP_SYNCNT**, **TCP_USER_TIMEOUT**, **TCP_NOTSENT_LOWAT**.
* * **IPPROTO_IP**, which supports *optname* **IP_TOS**.
* * **IPPROTO_IPV6**, which supports *optname* **IPV6_TCLASS**.
* Return
diff --git a/net/core/filter.c b/net/core/filter.c
index 05df73780dd3..5da44b11e1ec 100644
--- a/net/core/filter.c
+++ b/net/core/filter.c
@@ -4827,6 +4827,10 @@ static int _bpf_setsockopt(struct sock *sk, int level, int optname,
else
icsk->icsk_user_timeout = val;
break;
+ case TCP_NOTSENT_LOWAT:
+ tp->notsent_lowat = val;
+ sk->sk_write_space(sk);
+ break;
default:
ret = -EINVAL;
}
diff --git a/tools/testing/selftests/bpf/progs/connect4_prog.c b/tools/testing/selftests/bpf/progs/connect4_prog.c
index b1b2773c0b9d..b10e7fbace7b 100644
--- a/tools/testing/selftests/bpf/progs/connect4_prog.c
+++ b/tools/testing/selftests/bpf/progs/connect4_prog.c
@@ -128,6 +128,18 @@ static __inline int set_keepalive(struct bpf_sock_addr *ctx)
return 0;
}
+static __inline int set_notsent_lowat(struct bpf_sock_addr *ctx)
+{
+ int lowat = 65535;
+
+ if (ctx->type == SOCK_STREAM) {
+ if (bpf_setsockopt(ctx, SOL_TCP, TCP_NOTSENT_LOWAT, &lowat, sizeof(lowat)))
+ return 1;
+ }
+
+ return 0;
+}
+
SEC("cgroup/connect4")
int connect_v4_prog(struct bpf_sock_addr *ctx)
{
@@ -148,6 +160,9 @@ int connect_v4_prog(struct bpf_sock_addr *ctx)
if (set_keepalive(ctx))
return 0;
+ if (set_notsent_lowat(ctx))
+ return 0;
+
if (ctx->type != SOCK_STREAM && ctx->type != SOCK_DGRAM)
return 0;
else if (ctx->type == SOCK_STREAM)
--
2.25.1
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH bpf-next] bpf: add tcp_notsent_lowat bpf setsockopt
2020-10-09 5:08 [PATCH bpf-next] bpf: add tcp_notsent_lowat bpf setsockopt Nikita V. Shirokov
@ 2020-10-09 6:27 ` Yonghong Song
2020-10-09 6:56 ` Nikita Shirokov
0 siblings, 1 reply; 3+ messages in thread
From: Yonghong Song @ 2020-10-09 6:27 UTC (permalink / raw)
To: Nikita V. Shirokov, bpf
Cc: Alexei Starovoitov, Daniel Borkmann, Martin KaFai Lau, netdev
On 10/8/20 10:08 PM, Nikita V. Shirokov wrote:
> Adding support for TCP_NOTSENT_LOWAT sockoption
> (https://lwn.net/Articles/560082/ ) in tcpbpf
>
> Signed-off-by: Nikita V. Shirokov <tehnerd@tehnerd.com>
> ---
> include/uapi/linux/bpf.h | 2 +-
> net/core/filter.c | 4 ++++
> tools/testing/selftests/bpf/progs/connect4_prog.c | 15 +++++++++++++++
> 3 files changed, 20 insertions(+), 1 deletion(-)
>
> diff --git a/include/uapi/linux/bpf.h b/include/uapi/linux/bpf.h
> index d83561e8cd2c..42d2df799397 100644
> --- a/include/uapi/linux/bpf.h
> +++ b/include/uapi/linux/bpf.h
> @@ -1698,7 +1698,7 @@ union bpf_attr {
> * **TCP_CONGESTION**, **TCP_BPF_IW**,
> * **TCP_BPF_SNDCWND_CLAMP**, **TCP_SAVE_SYN**,
> * **TCP_KEEPIDLE**, **TCP_KEEPINTVL**, **TCP_KEEPCNT**,
> - * **TCP_SYNCNT**, **TCP_USER_TIMEOUT**.
> + * **TCP_SYNCNT**, **TCP_USER_TIMEOUT**, **TCP_NOTSENT_LOWAT**.
> * * **IPPROTO_IP**, which supports *optname* **IP_TOS**.
> * * **IPPROTO_IPV6**, which supports *optname* **IPV6_TCLASS**.
> * Return
> diff --git a/net/core/filter.c b/net/core/filter.c
> index 05df73780dd3..5da44b11e1ec 100644
> --- a/net/core/filter.c
> +++ b/net/core/filter.c
> @@ -4827,6 +4827,10 @@ static int _bpf_setsockopt(struct sock *sk, int level, int optname,
> else
> icsk->icsk_user_timeout = val;
> break;
> + case TCP_NOTSENT_LOWAT:
> + tp->notsent_lowat = val;
> + sk->sk_write_space(sk);
> + break;
This looks good to me. It is the same as in do_tcp_setsockopt().
> default:
> ret = -EINVAL;
> }
> diff --git a/tools/testing/selftests/bpf/progs/connect4_prog.c b/tools/testing/selftests/bpf/progs/connect4_prog.c
> index b1b2773c0b9d..b10e7fbace7b 100644
> --- a/tools/testing/selftests/bpf/progs/connect4_prog.c
> +++ b/tools/testing/selftests/bpf/progs/connect4_prog.c
> @@ -128,6 +128,18 @@ static __inline int set_keepalive(struct bpf_sock_addr *ctx)
> return 0;
> }
>
> +static __inline int set_notsent_lowat(struct bpf_sock_addr *ctx)
> +{
> + int lowat = 65535;
> +
> + if (ctx->type == SOCK_STREAM) {
> + if (bpf_setsockopt(ctx, SOL_TCP, TCP_NOTSENT_LOWAT, &lowat, sizeof(lowat)))
In my build system, I hit a compilation error.
progs/connect4_prog.c:137:36: error: use of undeclared identifier
'TCP_NOTSENT_LOWAT'
if (bpf_setsockopt(ctx, SOL_TCP, TCP_NOTSENT_LOWAT,
&lowat, sizeof(lowat)))
TCP_NOTSENT_LOWAT is included in /usr/include/linux/tcp.h. But this file
includes netinet/tcp.h and it contains some same symbol definitions as
linux/tcp.h so I can include both.
Adding the following can fix the issue
#ifndef TCP_NOTSENT_LOWAT
#define TCP_NOTSENT_LOWAT 25
#endif
Not sure where TCP_NOTSENT_LOWAT is defined in your system.
> + return 1;
> + }
> +
> + return 0;
> +}
> +
> SEC("cgroup/connect4")
> int connect_v4_prog(struct bpf_sock_addr *ctx)
> {
> @@ -148,6 +160,9 @@ int connect_v4_prog(struct bpf_sock_addr *ctx)
> if (set_keepalive(ctx))
> return 0;
>
> + if (set_notsent_lowat(ctx))
> + return 0;
> +
> if (ctx->type != SOCK_STREAM && ctx->type != SOCK_DGRAM)
> return 0;
> else if (ctx->type == SOCK_STREAM)
>
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH bpf-next] bpf: add tcp_notsent_lowat bpf setsockopt
2020-10-09 6:27 ` Yonghong Song
@ 2020-10-09 6:56 ` Nikita Shirokov
0 siblings, 0 replies; 3+ messages in thread
From: Nikita Shirokov @ 2020-10-09 6:56 UTC (permalink / raw)
To: Yonghong Song
Cc: bpf, Alexei Starovoitov, Daniel Borkmann, Martin KaFai Lau, netdev
чт, 8 окт. 2020 г. в 23:27, Yonghong Song <yhs@fb.com>:
>
>
>
> On 10/8/20 10:08 PM, Nikita V. Shirokov wrote:
> > Adding support for TCP_NOTSENT_LOWAT sockoption
> > (https://lwn.net/Articles/560082/ ) in tcpbpf
> >
> > Signed-off-by: Nikita V. Shirokov <tehnerd@tehnerd.com>
> > ---
> > include/uapi/linux/bpf.h | 2 +-
> > net/core/filter.c | 4 ++++
> > tools/testing/selftests/bpf/progs/connect4_prog.c | 15 +++++++++++++++
> > 3 files changed, 20 insertions(+), 1 deletion(-)
> >
> > diff --git a/include/uapi/linux/bpf.h b/include/uapi/linux/bpf.h
> > index d83561e8cd2c..42d2df799397 100644
> > --- a/include/uapi/linux/bpf.h
> > +++ b/include/uapi/linux/bpf.h
> > @@ -1698,7 +1698,7 @@ union bpf_attr {
> > * **TCP_CONGESTION**, **TCP_BPF_IW**,
> > * **TCP_BPF_SNDCWND_CLAMP**, **TCP_SAVE_SYN**,
> > * **TCP_KEEPIDLE**, **TCP_KEEPINTVL**, **TCP_KEEPCNT**,
> > - * **TCP_SYNCNT**, **TCP_USER_TIMEOUT**.
> > + * **TCP_SYNCNT**, **TCP_USER_TIMEOUT**, **TCP_NOTSENT_LOWAT**.
> > * * **IPPROTO_IP**, which supports *optname* **IP_TOS**.
> > * * **IPPROTO_IPV6**, which supports *optname* **IPV6_TCLASS**.
> > * Return
> > diff --git a/net/core/filter.c b/net/core/filter.c
> > index 05df73780dd3..5da44b11e1ec 100644
> > --- a/net/core/filter.c
> > +++ b/net/core/filter.c
> > @@ -4827,6 +4827,10 @@ static int _bpf_setsockopt(struct sock *sk, int level, int optname,
> > else
> > icsk->icsk_user_timeout = val;
> > break;
> > + case TCP_NOTSENT_LOWAT:
> > + tp->notsent_lowat = val;
> > + sk->sk_write_space(sk);
> > + break;
>
> This looks good to me. It is the same as in do_tcp_setsockopt().
>
> > default:
> > ret = -EINVAL;
> > }
> > diff --git a/tools/testing/selftests/bpf/progs/connect4_prog.c b/tools/testing/selftests/bpf/progs/connect4_prog.c
> > index b1b2773c0b9d..b10e7fbace7b 100644
> > --- a/tools/testing/selftests/bpf/progs/connect4_prog.c
> > +++ b/tools/testing/selftests/bpf/progs/connect4_prog.c
> > @@ -128,6 +128,18 @@ static __inline int set_keepalive(struct bpf_sock_addr *ctx)
> > return 0;
> > }
> >
> > +static __inline int set_notsent_lowat(struct bpf_sock_addr *ctx)
> > +{
> > + int lowat = 65535;
> > +
> > + if (ctx->type == SOCK_STREAM) {
> > + if (bpf_setsockopt(ctx, SOL_TCP, TCP_NOTSENT_LOWAT, &lowat, sizeof(lowat)))
>
> In my build system, I hit a compilation error.
>
> progs/connect4_prog.c:137:36: error: use of undeclared identifier
> 'TCP_NOTSENT_LOWAT'
> if (bpf_setsockopt(ctx, SOL_TCP, TCP_NOTSENT_LOWAT,
> &lowat, sizeof(lowat)))
>
> TCP_NOTSENT_LOWAT is included in /usr/include/linux/tcp.h. But this file
> includes netinet/tcp.h and it contains some same symbol definitions as
> linux/tcp.h so I can include both.
>
> Adding the following can fix the issue
>
> #ifndef TCP_NOTSENT_LOWAT
> #define TCP_NOTSENT_LOWAT 25
> #endif
>
> Not sure where TCP_NOTSENT_LOWAT is defined in your system.
Hey, thanks for checking. will send v2 in a few. as for my system it
is defined here:
/usr/include/netinet/tcp.h
64:#define TCP_NOTSENT_LOWAT 25 /* Limit number of unsent bytes in
>
> > + return 1;
> > + }
> > +
> > + return 0;
> > +}
> > +
> > SEC("cgroup/connect4")
> > int connect_v4_prog(struct bpf_sock_addr *ctx)
> > {
> > @@ -148,6 +160,9 @@ int connect_v4_prog(struct bpf_sock_addr *ctx)
> > if (set_keepalive(ctx))
> > return 0;
> >
> > + if (set_notsent_lowat(ctx))
> > + return 0;
> > +
> > if (ctx->type != SOCK_STREAM && ctx->type != SOCK_DGRAM)
> > return 0;
> > else if (ctx->type == SOCK_STREAM)
> >
--
Nikita
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2020-10-09 6:56 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-10-09 5:08 [PATCH bpf-next] bpf: add tcp_notsent_lowat bpf setsockopt Nikita V. Shirokov
2020-10-09 6:27 ` Yonghong Song
2020-10-09 6:56 ` Nikita Shirokov
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).