@@ -219,6 +219,27 @@ struct bpf_iter_mptcp_subflow_kern {
219219
220220__bpf_kfunc_start_defs ();
221221
222+ __bpf_kfunc static struct mptcp_subflow_context *
223+ bpf_mptcp_subflow_ctx (const struct sock * sk__ign )
224+ {
225+ const struct sock * sk = sk__ign ;
226+
227+ if (sk && sk_fullsock (sk ) &&
228+ sk -> sk_protocol == IPPROTO_TCP && sk_is_mptcp (sk ))
229+ return mptcp_subflow_ctx (sk );
230+
231+ return NULL ;
232+ }
233+
234+ __bpf_kfunc static struct sock *
235+ bpf_mptcp_subflow_tcp_sock (const struct mptcp_subflow_context * subflow )
236+ {
237+ if (!subflow )
238+ return NULL ;
239+
240+ return mptcp_subflow_tcp_sock (subflow );
241+ }
242+
222243__bpf_kfunc static int
223244bpf_iter_mptcp_subflow_new (struct bpf_iter_mptcp_subflow * it ,
224245 struct sock * sk )
@@ -263,6 +284,22 @@ bpf_iter_mptcp_subflow_destroy(struct bpf_iter_mptcp_subflow *it)
263284{
264285}
265286
287+ __bpf_kfunc static bool bpf_mptcp_subflow_queues_empty (struct sock * sk )
288+ {
289+ return tcp_rtx_queue_empty (sk );
290+ }
291+
292+ __bpf_kfunc static bool bpf_sk_stream_memory_free (const struct sock * sk__ign )
293+ {
294+ const struct sock * sk = sk__ign ;
295+
296+ if (sk && sk_fullsock (sk ) &&
297+ sk -> sk_protocol == IPPROTO_TCP && sk_is_mptcp (sk ))
298+ return sk_stream_memory_free (sk );
299+
300+ return NULL ;
301+ }
302+
266303__bpf_kfunc_end_defs ();
267304
268305BTF_KFUNCS_START (bpf_mptcp_iter_kfunc_ids )
@@ -276,13 +313,48 @@ static const struct btf_kfunc_id_set bpf_mptcp_iter_kfunc_set = {
276313 .set = & bpf_mptcp_iter_kfunc_ids ,
277314};
278315
316+ BTF_KFUNCS_START (bpf_mptcp_common_kfunc_ids )
317+ BTF_ID_FLAGS (func , bpf_mptcp_subflow_ctx , KF_RET_NULL )
318+ BTF_ID_FLAGS (func , bpf_mptcp_subflow_tcp_sock , KF_RET_NULL )
319+ BTF_ID_FLAGS (func , mptcp_subflow_set_scheduled )
320+ BTF_ID_FLAGS (func , mptcp_subflow_active )
321+ BTF_ID_FLAGS (func , mptcp_set_timeout )
322+ BTF_ID_FLAGS (func , mptcp_wnd_end )
323+ BTF_ID_FLAGS (func , bpf_sk_stream_memory_free , KF_RET_NULL )
324+ BTF_ID_FLAGS (func , bpf_mptcp_subflow_queues_empty )
325+ BTF_ID_FLAGS (func , mptcp_pm_subflow_chk_stale , KF_SLEEPABLE )
326+ BTF_KFUNCS_END (bpf_mptcp_common_kfunc_ids )
327+
328+ static int bpf_mptcp_common_kfunc_filter (const struct bpf_prog * prog , u32 kfunc_id )
329+ {
330+ if (!btf_id_set8_contains (& bpf_mptcp_common_kfunc_ids , kfunc_id ))
331+ return 0 ;
332+
333+ if (prog - > type != BPF_PROG_TYPE_STRUCT_OPS )
334+ return - EACCES ;
335+
336+ #ifdef CONFIG_BPF_JIT
337+ if (prog -> aux -> st_ops == & bpf_mptcp_sched_ops )
338+ return 0 ;
339+ #endif
340+ return - EACCES ;
341+ }
342+
343+ static const struct btf_kfunc_id_set bpf_mptcp_common_kfunc_set = {
344+ .owner = THIS_MODULE ,
345+ .set = & bpf_mptcp_common_kfunc_ids ,
346+ .filter = bpf_mptcp_common_kfunc_filter ,
347+ };
348+
279349static int __init bpf_mptcp_kfunc_init (void )
280350{
281351 int ret ;
282352
283353 ret = register_btf_fmodret_id_set (& bpf_mptcp_fmodret_set );
284354 ret = ret ?: register_btf_kfunc_id_set (BPF_PROG_TYPE_STRUCT_OPS ,
285355 & bpf_mptcp_iter_kfunc_set );
356+ ret = ret ?: register_btf_kfunc_id_set (BPF_PROG_TYPE_STRUCT_OPS ,
357+ & bpf_mptcp_common_kfunc_set );
286358#ifdef CONFIG_BPF_JIT
287359 ret = ret ?: register_bpf_struct_ops (& bpf_mptcp_sched_ops , mptcp_sched_ops );
288360#endif
0 commit comments