Skip to content

Commit

Permalink
Squash to "selftests/bpf: Add mptcp_subflow bpf_iter subtest"
Browse files Browse the repository at this point in the history
Use bpf_skc_to_mptcp_sock() and mptcp_subflow_tcp_sock() instead of
bpf_mptcp_sk() and bpf_mptcp_subflow_tcp_sock().

IPPROTO_MPTCP is checked in bpf_skc_to_mptcp_sock(), no need to check
it in BPF program.

bpf_skc_to_mptcp_sock() and bpf_mptcp_subflow_ctx() may return NULL,
need to check the return values.

Signed-off-by: Geliang Tang <tanggeliang@kylinos.cn>
  • Loading branch information
Geliang Tang authored and intel-lab-lkp committed Dec 11, 2024
1 parent 53c7e22 commit 833dd8c
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 7 deletions.
1 change: 0 additions & 1 deletion tools/testing/selftests/bpf/progs/mptcp_bpf.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ mptcp_subflow_tcp_sock(const struct mptcp_subflow_context *subflow)
extern struct mptcp_sock *bpf_mptcp_sock_acquire(struct mptcp_sock *msk) __ksym;
extern void bpf_mptcp_sock_release(struct mptcp_sock *msk) __ksym;

extern struct mptcp_sock *bpf_mptcp_sk(struct sock *sk) __ksym;
extern struct mptcp_subflow_context *
bpf_mptcp_subflow_ctx(const struct sock *sk) __ksym;
extern struct sock *
Expand Down
11 changes: 5 additions & 6 deletions tools/testing/selftests/bpf/progs/mptcp_bpf_iters.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,11 @@ int iters_subflow(struct bpf_sockopt *ctx)
struct mptcp_sock *msk;
int local_ids = 0;

if (!sk || sk->protocol != IPPROTO_MPTCP ||
ctx->level != SOL_TCP || ctx->optname != TCP_IS_MPTCP)
if (ctx->level != SOL_TCP || ctx->optname != TCP_IS_MPTCP)
return 1;

msk = bpf_mptcp_sk((struct sock *)sk);
if (msk->pm.server_side || !msk->pm.subflows)
msk = bpf_skc_to_mptcp_sock(sk);
if (!msk || msk->pm.server_side || !msk->pm.subflows)
return 1;

msk = bpf_mptcp_sock_acquire(msk);
Expand All @@ -41,7 +40,7 @@ int iters_subflow(struct bpf_sockopt *ctx)
local_ids += subflow->subflow_id;

/* only to check the following kfunc works */
ssk = bpf_mptcp_subflow_tcp_sock(subflow);
ssk = mptcp_subflow_tcp_sock(subflow);
}

if (!ssk)
Expand All @@ -53,7 +52,7 @@ int iters_subflow(struct bpf_sockopt *ctx)

/* only to check the following kfunc works */
subflow = bpf_mptcp_subflow_ctx(ssk);
if (subflow->token != msk->token)
if (!subflow || subflow->token != msk->token)
goto out;

ids = local_ids;
Expand Down

0 comments on commit 833dd8c

Please sign in to comment.