Skip to content

Commit eca43ee

Browse files
tehnerdborkmann
authored andcommitted
bpf: Add tcp_notsent_lowat bpf setsockopt
Adding support for TCP_NOTSENT_LOWAT sockoption (https://lwn.net/Articles/560082/) in tcp bpf programs. Signed-off-by: Nikita V. Shirokov <[email protected]> Signed-off-by: Daniel Borkmann <[email protected]> Acked-by: Yonghong Song <[email protected]> Link: https://lore.kernel.org/bpf/[email protected]
1 parent c3f01fd commit eca43ee

File tree

4 files changed

+25
-2
lines changed

4 files changed

+25
-2
lines changed

include/uapi/linux/bpf.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1698,7 +1698,7 @@ union bpf_attr {
16981698
* **TCP_CONGESTION**, **TCP_BPF_IW**,
16991699
* **TCP_BPF_SNDCWND_CLAMP**, **TCP_SAVE_SYN**,
17001700
* **TCP_KEEPIDLE**, **TCP_KEEPINTVL**, **TCP_KEEPCNT**,
1701-
* **TCP_SYNCNT**, **TCP_USER_TIMEOUT**.
1701+
* **TCP_SYNCNT**, **TCP_USER_TIMEOUT**, **TCP_NOTSENT_LOWAT**.
17021702
* * **IPPROTO_IP**, which supports *optname* **IP_TOS**.
17031703
* * **IPPROTO_IPV6**, which supports *optname* **IPV6_TCLASS**.
17041704
* Return

net/core/filter.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4827,6 +4827,10 @@ static int _bpf_setsockopt(struct sock *sk, int level, int optname,
48274827
else
48284828
icsk->icsk_user_timeout = val;
48294829
break;
4830+
case TCP_NOTSENT_LOWAT:
4831+
tp->notsent_lowat = val;
4832+
sk->sk_write_space(sk);
4833+
break;
48304834
default:
48314835
ret = -EINVAL;
48324836
}

tools/include/uapi/linux/bpf.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1698,7 +1698,7 @@ union bpf_attr {
16981698
* **TCP_CONGESTION**, **TCP_BPF_IW**,
16991699
* **TCP_BPF_SNDCWND_CLAMP**, **TCP_SAVE_SYN**,
17001700
* **TCP_KEEPIDLE**, **TCP_KEEPINTVL**, **TCP_KEEPCNT**,
1701-
* **TCP_SYNCNT**, **TCP_USER_TIMEOUT**.
1701+
* **TCP_SYNCNT**, **TCP_USER_TIMEOUT**, **TCP_NOTSENT_LOWAT**.
17021702
* * **IPPROTO_IP**, which supports *optname* **IP_TOS**.
17031703
* * **IPPROTO_IPV6**, which supports *optname* **IPV6_TCLASS**.
17041704
* Return

tools/testing/selftests/bpf/progs/connect4_prog.c

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@
2323
#define TCP_CA_NAME_MAX 16
2424
#endif
2525

26+
#ifndef TCP_NOTSENT_LOWAT
27+
#define TCP_NOTSENT_LOWAT 25
28+
#endif
29+
2630
#ifndef IFNAMSIZ
2731
#define IFNAMSIZ 16
2832
#endif
@@ -128,6 +132,18 @@ static __inline int set_keepalive(struct bpf_sock_addr *ctx)
128132
return 0;
129133
}
130134

135+
static __inline int set_notsent_lowat(struct bpf_sock_addr *ctx)
136+
{
137+
int lowat = 65535;
138+
139+
if (ctx->type == SOCK_STREAM) {
140+
if (bpf_setsockopt(ctx, SOL_TCP, TCP_NOTSENT_LOWAT, &lowat, sizeof(lowat)))
141+
return 1;
142+
}
143+
144+
return 0;
145+
}
146+
131147
SEC("cgroup/connect4")
132148
int connect_v4_prog(struct bpf_sock_addr *ctx)
133149
{
@@ -148,6 +164,9 @@ int connect_v4_prog(struct bpf_sock_addr *ctx)
148164
if (set_keepalive(ctx))
149165
return 0;
150166

167+
if (set_notsent_lowat(ctx))
168+
return 0;
169+
151170
if (ctx->type != SOCK_STREAM && ctx->type != SOCK_DGRAM)
152171
return 0;
153172
else if (ctx->type == SOCK_STREAM)

0 commit comments

Comments
 (0)