From d2274bde5a9d3bedff55a350038f9a10ec627b26 Mon Sep 17 00:00:00 2001 From: Geliang Tang Date: Thu, 21 Nov 2024 15:10:08 +0800 Subject: [PATCH] Squash to "selftests/bpf: Add mptcp_subflow bpf_iter subtest" IPPROTO_MPTCP is checked in bpf_mptcp_sk(), no need to check it in BPF program. bpf_mptcp_sk() 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_iters.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/tools/testing/selftests/bpf/progs/mptcp_bpf_iters.c b/tools/testing/selftests/bpf/progs/mptcp_bpf_iters.c index 1bede22a7e3d12..5e475edf37b323 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) + if (!msk || msk->pm.server_side || !msk->pm.subflows) return 1; msk = bpf_mptcp_sock_acquire(msk); @@ -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;