Skip to content

Commit

Permalink
selftests/bpf: verify first of struct mptcp_sock
Browse files Browse the repository at this point in the history
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).

Acked-by: Matthieu Baerts <matthieu.baerts@tessares.net>
Signed-off-by: Geliang Tang <geliang.tang@suse.com>
Signed-off-by: Mat Martineau <mathew.j.martineau@linux.intel.com>
  • Loading branch information
geliangtang authored and Kernel Patches Daemon committed May 19, 2022
1 parent 3949e95 commit 73bebec
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 0 deletions.
1 change: 1 addition & 0 deletions tools/testing/selftests/bpf/bpf_tcp_helpers.h
Expand Up @@ -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));

Expand Down
5 changes: 5 additions & 0 deletions tools/testing/selftests/bpf/prog_tests/mptcp.c
Expand Up @@ -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];
};

Expand Down Expand Up @@ -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++;

Expand Down
5 changes: 5 additions & 0 deletions tools/testing/selftests/bpf/progs/mptcp_sock.c
Expand Up @@ -13,7 +13,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];
};

Expand Down Expand Up @@ -54,6 +56,7 @@ int _sockops(struct bpf_sock_ops *ctx)

storage->token = 0;
bzero(storage->ca_name, TCP_CA_NAME_MAX);
storage->first = NULL;
} else {
msk = bpf_skc_to_mptcp_sock(sk);
if (!msk)
Expand All @@ -66,9 +69,11 @@ int _sockops(struct bpf_sock_ops *ctx)

storage->token = msk->token;
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;
}
Expand Down

0 comments on commit 73bebec

Please sign in to comment.