selftests/bpf: Verify bpf-tcp-cc rejects TCP_NODELAY

Add a bpf_tcp_ca selftest for the TCP_NODELAY restriction in
bpf-tcp-cc.

Update bpf_cubic to exercise init() and cwnd_event_tx_start(),
and check that both callbacks reject bpf_setsockopt(TCP_NODELAY)
with -EOPNOTSUPP.

Signed-off-by: KaFai Wan <kafai.wan@linux.dev>
Signed-off-by: Martin KaFai Lau <martin.lau@kernel.org>
Link: https://patch.msgid.link/20260421155804.135786-5-kafai.wan@linux.dev
This commit is contained in:
KaFai Wan 2026-04-21 23:58:04 +08:00 committed by Martin KaFai Lau
parent 52b6b53349
commit 2c7e33f1fc
2 changed files with 18 additions and 0 deletions

View File

@ -112,6 +112,10 @@ static void test_cubic(void)
ASSERT_EQ(cubic_skel->bss->bpf_cubic_acked_called, 1, "pkts_acked called");
ASSERT_TRUE(cubic_skel->bss->nodelay_init_reject, "init reject nodelay option");
ASSERT_TRUE(cubic_skel->bss->nodelay_cwnd_event_tx_start_reject,
"cwnd_event_tx_start reject nodelay option");
bpf_link__destroy(link);
bpf_cubic__destroy(cubic_skel);
}

View File

@ -16,6 +16,7 @@
#include "bpf_tracing_net.h"
#include <bpf/bpf_tracing.h>
#include <errno.h>
char _license[] SEC("license") = "GPL";
@ -170,10 +171,18 @@ static void bictcp_hystart_reset(struct sock *sk)
ca->sample_cnt = 0;
}
bool nodelay_init_reject = false;
bool nodelay_cwnd_event_tx_start_reject = false;
SEC("struct_ops")
void BPF_PROG(bpf_cubic_init, struct sock *sk)
{
struct bpf_bictcp *ca = inet_csk_ca(sk);
int true_val = 1, ret;
ret = bpf_setsockopt(sk, SOL_TCP, TCP_NODELAY, &true_val, sizeof(true_val));
if (ret == -EOPNOTSUPP)
nodelay_init_reject = true;
bictcp_reset(ca);
@ -189,8 +198,13 @@ void BPF_PROG(bpf_cubic_cwnd_event_tx_start, struct sock *sk)
{
struct bpf_bictcp *ca = inet_csk_ca(sk);
__u32 now = tcp_jiffies32;
int true_val = 1, ret;
__s32 delta;
ret = bpf_setsockopt(sk, SOL_TCP, TCP_NODELAY, &true_val, sizeof(true_val));
if (ret == -EOPNOTSUPP)
nodelay_cwnd_event_tx_start_reject = true;
delta = now - tcp_sk(sk)->lsndtime;
/* We were application limited (idle) for a while.