From 833dd8c7bc24030f7fc9f656ee680e7e861c0966 Mon Sep 17 00:00:00 2001 From: Geliang Tang Date: Wed, 11 Dec 2024 11:11:56 +0800 Subject: [PATCH] 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 --- tools/testing/selftests/bpf/progs/mptcp_bpf.h | 1 - tools/testing/selftests/bpf/progs/mptcp_bpf_iters.c | 11 +++++------ 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/tools/testing/selftests/bpf/progs/mptcp_bpf.h b/tools/testing/selftests/bpf/progs/mptcp_bpf.h index 3b20cfd44505ee..b1f6e1fb467e0f 100644 --- a/tools/testing/selftests/bpf/progs/mptcp_bpf.h +++ b/tools/testing/selftests/bpf/progs/mptcp_bpf.h @@ -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 * diff --git a/tools/testing/selftests/bpf/progs/mptcp_bpf_iters.c b/tools/testing/selftests/bpf/progs/mptcp_bpf_iters.c index 1bede22a7e3d12..fd5691a4073b22 100644 --- a/tools/testing/selftests/bpf/progs/mptcp_bpf_iters.c +++ b/tools/testing/selftests/bpf/progs/mptcp_bpf_iters.c @@ -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); @@ -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) @@ -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;