Skip to content

Commit 081af0b

Browse files
Geliang Tangintel-lab-lkp
authored andcommitted
Squash to "bpf: Register mptcp common kfunc set"
Address Martin's comments in v1: - check IPPROTO_MPTCP in bpf_mptcp_sk. - add null-checks for the wrappers. - add more BPF flags for the wrappers. - register this kfunc set to BPF_PROG_TYPE_CGROUP_SOCKOPT only, not BPF_PROG_TYPE_UNSPEC. Signed-off-by: Geliang Tang <[email protected]>
1 parent d68e608 commit 081af0b

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

net/mptcp/bpf.c

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -218,18 +218,27 @@ __bpf_kfunc_start_defs();
218218

219219
__bpf_kfunc static struct mptcp_sock *bpf_mptcp_sk(struct sock *sk)
220220
{
221+
if (!sk || sk->sk_protocol != IPPROTO_MPTCP)
222+
return NULL;
223+
221224
return mptcp_sk(sk);
222225
}
223226

224227
__bpf_kfunc static struct mptcp_subflow_context *
225228
bpf_mptcp_subflow_ctx(const struct sock *sk)
226229
{
230+
if (!sk)
231+
return NULL;
232+
227233
return mptcp_subflow_ctx(sk);
228234
}
229235

230236
__bpf_kfunc static struct sock *
231237
bpf_mptcp_subflow_tcp_sock(const struct mptcp_subflow_context *subflow)
232238
{
239+
if (!subflow)
240+
return NULL;
241+
233242
return mptcp_subflow_tcp_sock(subflow);
234243
}
235244

@@ -299,9 +308,9 @@ __bpf_kfunc static bool bpf_mptcp_subflow_queues_empty(struct sock *sk)
299308
__bpf_kfunc_end_defs();
300309

301310
BTF_KFUNCS_START(bpf_mptcp_common_kfunc_ids)
302-
BTF_ID_FLAGS(func, bpf_mptcp_sk)
303-
BTF_ID_FLAGS(func, bpf_mptcp_subflow_ctx)
304-
BTF_ID_FLAGS(func, bpf_mptcp_subflow_tcp_sock)
311+
BTF_ID_FLAGS(func, bpf_mptcp_sk, KF_TRUSTED_ARGS | KF_RET_NULL)
312+
BTF_ID_FLAGS(func, bpf_mptcp_subflow_ctx, KF_RET_NULL)
313+
BTF_ID_FLAGS(func, bpf_mptcp_subflow_tcp_sock, KF_RET_NULL)
305314
BTF_ID_FLAGS(func, bpf_iter_mptcp_subflow_new, KF_ITER_NEW | KF_TRUSTED_ARGS)
306315
BTF_ID_FLAGS(func, bpf_iter_mptcp_subflow_next, KF_ITER_NEXT | KF_RET_NULL)
307316
BTF_ID_FLAGS(func, bpf_iter_mptcp_subflow_destroy, KF_ITER_DESTROY)
@@ -335,7 +344,7 @@ static int __init bpf_mptcp_kfunc_init(void)
335344
int ret;
336345

337346
ret = register_btf_fmodret_id_set(&bpf_mptcp_fmodret_set);
338-
ret = ret ?: register_btf_kfunc_id_set(BPF_PROG_TYPE_UNSPEC,
347+
ret = ret ?: register_btf_kfunc_id_set(BPF_PROG_TYPE_CGROUP_SOCKOPT,
339348
&bpf_mptcp_common_kfunc_set);
340349
ret = ret ?: register_btf_kfunc_id_set(BPF_PROG_TYPE_STRUCT_OPS,
341350
&bpf_mptcp_sched_kfunc_set);

0 commit comments

Comments
 (0)