summaryrefslogtreecommitdiffstats
path: root/tools
diff options
context:
space:
mode:
authorGeliang Tang <geliang.tang@suse.com>2022-05-19 16:30:16 -0700
committerAndrii Nakryiko <andrii@kernel.org>2022-05-20 15:36:48 -0700
commit4f90d034bba9bdcb06a3cb53c43012351c1b39ff (patch)
tree974deb3e8c67f808fc85fbb9644f6c2f4963c948 /tools
parentccc090f469000fd757049028eeb0dff43013f7c1 (diff)
downloadlinux-stable-4f90d034bba9bdcb06a3cb53c43012351c1b39ff.tar.gz
linux-stable-4f90d034bba9bdcb06a3cb53c43012351c1b39ff.tar.bz2
linux-stable-4f90d034bba9bdcb06a3cb53c43012351c1b39ff.zip
selftests/bpf: Verify first of struct mptcp_sock
This patch verifies the 'first' struct member of struct mptcp_sock, which points to the first subflow of msk. Save 'sk' in mptcp_storage, and verify it with 'first' in verify_msk(). v5: - Use ASSERT_EQ() instead of a manual comparison + log (Andrii). Signed-off-by: Geliang Tang <geliang.tang@suse.com> Signed-off-by: Mat Martineau <mathew.j.martineau@linux.intel.com> Signed-off-by: Andrii Nakryiko <andrii@kernel.org> Acked-by: Matthieu Baerts <matthieu.baerts@tessares.net> Link: https://lore.kernel.org/bpf/20220519233016.105670-8-mathew.j.martineau@linux.intel.com
Diffstat (limited to 'tools')
-rw-r--r--tools/testing/selftests/bpf/bpf_tcp_helpers.h1
-rw-r--r--tools/testing/selftests/bpf/prog_tests/mptcp.c5
-rw-r--r--tools/testing/selftests/bpf/progs/mptcp_sock.c5
3 files changed, 11 insertions, 0 deletions
diff --git a/tools/testing/selftests/bpf/bpf_tcp_helpers.h b/tools/testing/selftests/bpf/bpf_tcp_helpers.h
index c38c66d5c1e6..82a7c9de95f9 100644
--- a/tools/testing/selftests/bpf/bpf_tcp_helpers.h
+++ b/tools/testing/selftests/bpf/bpf_tcp_helpers.h
@@ -234,6 +234,7 @@ struct mptcp_sock {
struct inet_connection_sock sk;
__u32 token;
+ struct sock *first;
char ca_name[TCP_CA_NAME_MAX];
} __attribute__((preserve_access_index));
diff --git a/tools/testing/selftests/bpf/prog_tests/mptcp.c b/tools/testing/selftests/bpf/prog_tests/mptcp.c
index 33cafc619913..59f08d6d1d53 100644
--- a/tools/testing/selftests/bpf/prog_tests/mptcp.c
+++ b/tools/testing/selftests/bpf/prog_tests/mptcp.c
@@ -14,7 +14,9 @@
struct mptcp_storage {
__u32 invoked;
__u32 is_mptcp;
+ struct sock *sk;
__u32 token;
+ struct sock *first;
char ca_name[TCP_CA_NAME_MAX];
};
@@ -80,6 +82,9 @@ static int verify_msk(int map_fd, int client_fd, __u32 token)
if (!ASSERT_EQ(val.token, token, "unexpected token"))
err++;
+ if (!ASSERT_EQ(val.first, val.sk, "unexpected first"))
+ err++;
+
if (!ASSERT_STRNEQ(val.ca_name, ca_name, TCP_CA_NAME_MAX, "unexpected ca_name"))
err++;
diff --git a/tools/testing/selftests/bpf/progs/mptcp_sock.c b/tools/testing/selftests/bpf/progs/mptcp_sock.c
index 65e2b5543fc7..91a0d7eff2ac 100644
--- a/tools/testing/selftests/bpf/progs/mptcp_sock.c
+++ b/tools/testing/selftests/bpf/progs/mptcp_sock.c
@@ -12,7 +12,9 @@ __u32 token = 0;
struct mptcp_storage {
__u32 invoked;
__u32 is_mptcp;
+ struct sock *sk;
__u32 token;
+ struct sock *first;
char ca_name[TCP_CA_NAME_MAX];
};
@@ -53,6 +55,7 @@ int _sockops(struct bpf_sock_ops *ctx)
storage->token = 0;
__builtin_memset(storage->ca_name, 0, TCP_CA_NAME_MAX);
+ storage->first = NULL;
} else {
msk = bpf_skc_to_mptcp_sock(sk);
if (!msk)
@@ -65,9 +68,11 @@ int _sockops(struct bpf_sock_ops *ctx)
storage->token = msk->token;
__builtin_memcpy(storage->ca_name, msk->ca_name, TCP_CA_NAME_MAX);
+ storage->first = msk->first;
}
storage->invoked++;
storage->is_mptcp = is_mptcp;
+ storage->sk = (struct sock *)sk;
return 1;
}