Skip to content

Commit e8ef222

Browse files
Geliang Tangintel-lab-lkp
authored andcommitted
Squash to "selftests/bpf: Add mptcp_subflow bpf_iter subtest"
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 <[email protected]>
1 parent 539f3b5 commit e8ef222

File tree

2 files changed

+5
-7
lines changed

2 files changed

+5
-7
lines changed

tools/testing/selftests/bpf/progs/mptcp_bpf.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@ mptcp_subflow_tcp_sock(const struct mptcp_subflow_context *subflow)
4646
extern struct mptcp_sock *bpf_mptcp_sock_acquire(struct mptcp_sock *msk) __ksym;
4747
extern void bpf_mptcp_sock_release(struct mptcp_sock *msk) __ksym;
4848

49-
extern struct mptcp_sock *bpf_mptcp_sk(struct sock *sk) __ksym;
5049
extern struct mptcp_subflow_context *
5150
bpf_mptcp_subflow_ctx(const struct sock *sk) __ksym;
5251
extern struct sock *

tools/testing/selftests/bpf/progs/mptcp_bpf_iters.c

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,11 @@ int iters_subflow(struct bpf_sockopt *ctx)
2121
struct mptcp_sock *msk;
2222
int local_ids = 0;
2323

24-
if (!sk || sk->protocol != IPPROTO_MPTCP ||
25-
ctx->level != SOL_TCP || ctx->optname != TCP_IS_MPTCP)
24+
if (ctx->level != SOL_TCP || ctx->optname != TCP_IS_MPTCP)
2625
return 1;
2726

28-
msk = bpf_mptcp_sk((struct sock *)sk);
29-
if (msk->pm.server_side || !msk->pm.subflows)
27+
msk = bpf_skc_to_mptcp_sock(sk);
28+
if (!msk || msk->pm.server_side || !msk->pm.subflows)
3029
return 1;
3130

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

4342
/* only to check the following kfunc works */
44-
ssk = bpf_mptcp_subflow_tcp_sock(subflow);
43+
ssk = mptcp_subflow_tcp_sock(subflow);
4544
}
4645

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

5453
/* only to check the following kfunc works */
5554
subflow = bpf_mptcp_subflow_ctx(ssk);
56-
if (subflow->token != msk->token)
55+
if (!subflow || subflow->token != msk->token)
5756
goto out;
5857

5958
ids = local_ids;

0 commit comments

Comments
 (0)