Allow the test to support any number of supported callback flags. Provided that BPF_SOCK_OPS_ALL_CB_FLAGS is correctly updated when new flags are added, left shifting it always leads to a non existing flag.
Signed-off-by: Mathieu Jadin mathjadin@gmail.com --- tools/testing/selftests/bpf/prog_tests/tcpbpf_user.c | 4 +++- tools/testing/selftests/bpf/progs/test_tcpbpf_kern.c | 9 +++++++-- 2 files changed, 10 insertions(+), 3 deletions(-)
diff --git a/tools/testing/selftests/bpf/prog_tests/tcpbpf_user.c b/tools/testing/selftests/bpf/prog_tests/tcpbpf_user.c index 87923d2865b7..56d007bf4011 100644 --- a/tools/testing/selftests/bpf/prog_tests/tcpbpf_user.c +++ b/tools/testing/selftests/bpf/prog_tests/tcpbpf_user.c @@ -12,6 +12,8 @@ static __u32 duration;
static void verify_result(struct tcpbpf_globals *result) { + __u32 non_existing_flag = (BPF_SOCK_OPS_ALL_CB_FLAGS << 1) & + ~BPF_SOCK_OPS_ALL_CB_FLAGS; __u32 expected_events = ((1 << BPF_SOCK_OPS_TIMEOUT_INIT) | (1 << BPF_SOCK_OPS_RWND_INIT) | (1 << BPF_SOCK_OPS_TCP_CONNECT_CB) | @@ -30,7 +32,7 @@ static void verify_result(struct tcpbpf_globals *result) ASSERT_EQ(result->bytes_acked, 1002, "bytes_acked"); ASSERT_EQ(result->data_segs_in, 1, "data_segs_in"); ASSERT_EQ(result->data_segs_out, 1, "data_segs_out"); - ASSERT_EQ(result->bad_cb_test_rv, 0x80, "bad_cb_test_rv"); + ASSERT_EQ(result->bad_cb_test_rv, non_existing_flag, "bad_cb_test_rv"); ASSERT_EQ(result->good_cb_test_rv, 0, "good_cb_test_rv"); ASSERT_EQ(result->num_listen, 1, "num_listen");
diff --git a/tools/testing/selftests/bpf/progs/test_tcpbpf_kern.c b/tools/testing/selftests/bpf/progs/test_tcpbpf_kern.c index 3ded05280757..c37ba5940e3d 100644 --- a/tools/testing/selftests/bpf/progs/test_tcpbpf_kern.c +++ b/tools/testing/selftests/bpf/progs/test_tcpbpf_kern.c @@ -43,6 +43,8 @@ SEC("sockops") int bpf_testcb(struct bpf_sock_ops *skops) { char header[sizeof(struct ipv6hdr) + sizeof(struct tcphdr)]; + __u32 non_existing_flag = (BPF_SOCK_OPS_ALL_CB_FLAGS << 1) & + ~BPF_SOCK_OPS_ALL_CB_FLAGS; struct bpf_sock_ops *reuse = skops; struct tcphdr *thdr; int window_clamp = 9216; @@ -104,8 +106,11 @@ int bpf_testcb(struct bpf_sock_ops *skops) 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); + /* Test failure to set largest cb flag + * (assumes that BPF_SOCK_OPS_ALL_CB_FLAGS masks all cb flags) + */ + global.bad_cb_test_rv = bpf_sock_ops_cb_flags_set(skops, + non_existing_flag); /* Set callback */ global.good_cb_test_rv = bpf_sock_ops_cb_flags_set(skops, BPF_SOCK_OPS_STATE_CB_FLAG);