Skip to content

Commit 432849e

Browse files
Geliang Tangmatttbe
authored andcommitted
bpf: Export mptcp packet scheduler helpers
This patch adds a new struct btf_kfunc_id_set for MPTCP scheduler. Add mptcp_subflow_set_scheduled() and mptcp_sched_data_set_contexts() helpers into this id_set, and register it in bpf_mptcp_kfunc_init() to make sure these helpers can be accessed from the BPF context. Reviewed-by: Mat Martineau <[email protected]> Signed-off-by: Geliang Tang <[email protected]>
1 parent 5418b3e commit 432849e

File tree

3 files changed

+42
-3
lines changed

3 files changed

+42
-3
lines changed

net/mptcp/bpf.c

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -222,15 +222,26 @@ struct bpf_iter_mptcp_subflow_kern {
222222
__bpf_kfunc_start_defs();
223223

224224
__bpf_kfunc static struct mptcp_subflow_context *
225-
bpf_mptcp_subflow_ctx(const struct sock *sk)
225+
bpf_mptcp_subflow_ctx(const struct sock *sk__ign)
226226
{
227+
const struct sock *sk = sk__ign;
228+
227229
if (sk && sk_fullsock(sk) &&
228230
sk->sk_protocol == IPPROTO_TCP && sk_is_mptcp(sk))
229231
return mptcp_subflow_ctx(sk);
230232

231233
return NULL;
232234
}
233235

236+
__bpf_kfunc static struct sock *
237+
bpf_mptcp_subflow_tcp_sock(const struct mptcp_subflow_context *subflow)
238+
{
239+
if (!subflow)
240+
return NULL;
241+
242+
return mptcp_subflow_tcp_sock(subflow);
243+
}
244+
234245
__bpf_kfunc static int
235246
bpf_iter_mptcp_subflow_new(struct bpf_iter_mptcp_subflow *it,
236247
struct sock *sk)
@@ -275,13 +286,37 @@ bpf_iter_mptcp_subflow_destroy(struct bpf_iter_mptcp_subflow *it)
275286
{
276287
}
277288

289+
__bpf_kfunc static bool bpf_mptcp_subflow_queues_empty(struct sock *sk)
290+
{
291+
return tcp_rtx_queue_empty(sk);
292+
}
293+
294+
__bpf_kfunc static bool bpf_sk_stream_memory_free(const struct sock *sk__ign)
295+
{
296+
const struct sock *sk = sk__ign;
297+
298+
if (sk && sk_fullsock(sk) &&
299+
sk->sk_protocol == IPPROTO_TCP && sk_is_mptcp(sk))
300+
return sk_stream_memory_free(sk);
301+
302+
return NULL;
303+
}
304+
278305
__bpf_kfunc_end_defs();
279306

280307
BTF_KFUNCS_START(bpf_mptcp_common_kfunc_ids)
281308
BTF_ID_FLAGS(func, bpf_mptcp_subflow_ctx, KF_RET_NULL)
309+
BTF_ID_FLAGS(func, bpf_mptcp_subflow_tcp_sock, KF_RET_NULL)
282310
BTF_ID_FLAGS(func, bpf_iter_mptcp_subflow_new, KF_ITER_NEW | KF_TRUSTED_ARGS)
283311
BTF_ID_FLAGS(func, bpf_iter_mptcp_subflow_next, KF_ITER_NEXT | KF_RET_NULL)
284312
BTF_ID_FLAGS(func, bpf_iter_mptcp_subflow_destroy, KF_ITER_DESTROY)
313+
BTF_ID_FLAGS(func, mptcp_subflow_set_scheduled)
314+
BTF_ID_FLAGS(func, mptcp_subflow_active)
315+
BTF_ID_FLAGS(func, mptcp_set_timeout)
316+
BTF_ID_FLAGS(func, mptcp_wnd_end)
317+
BTF_ID_FLAGS(func, bpf_sk_stream_memory_free, KF_RET_NULL)
318+
BTF_ID_FLAGS(func, bpf_mptcp_subflow_queues_empty)
319+
BTF_ID_FLAGS(func, mptcp_pm_subflow_chk_stale, KF_SLEEPABLE)
285320
BTF_KFUNCS_END(bpf_mptcp_common_kfunc_ids)
286321

287322
static const struct btf_kfunc_id_set bpf_mptcp_common_kfunc_set = {
@@ -296,6 +331,8 @@ static int __init bpf_mptcp_kfunc_init(void)
296331
ret = register_btf_fmodret_id_set(&bpf_mptcp_fmodret_set);
297332
ret = ret ?: register_btf_kfunc_id_set(BPF_PROG_TYPE_CGROUP_SOCKOPT,
298333
&bpf_mptcp_common_kfunc_set);
334+
ret = ret ?: register_btf_kfunc_id_set(BPF_PROG_TYPE_STRUCT_OPS,
335+
&bpf_mptcp_common_kfunc_set);
299336
#ifdef CONFIG_BPF_JIT
300337
ret = ret ?: register_bpf_struct_ops(&bpf_mptcp_sched_ops, mptcp_sched_ops);
301338
#endif

net/mptcp/protocol.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ DEFINE_PER_CPU(struct mptcp_delegated_action, mptcp_delegated_actions);
5050
static struct net_device *mptcp_napi_dev;
5151

5252
/* Returns end sequence number of the receiver's advertised window */
53-
static u64 mptcp_wnd_end(const struct mptcp_sock *msk)
53+
u64 mptcp_wnd_end(const struct mptcp_sock *msk)
5454
{
5555
return READ_ONCE(msk->wnd_end);
5656
}
@@ -425,7 +425,7 @@ static long mptcp_timeout_from_subflow(const struct mptcp_subflow_context *subfl
425425
inet_csk(ssk)->icsk_timeout - jiffies : 0;
426426
}
427427

428-
static void mptcp_set_timeout(struct sock *sk)
428+
void mptcp_set_timeout(struct sock *sk)
429429
{
430430
struct mptcp_subflow_context *subflow;
431431
long tout = 0;

net/mptcp/protocol.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -716,6 +716,8 @@ void __mptcp_subflow_send_ack(struct sock *ssk);
716716
void mptcp_subflow_reset(struct sock *ssk);
717717
void mptcp_subflow_queue_clean(struct sock *sk, struct sock *ssk);
718718
void mptcp_sock_graft(struct sock *sk, struct socket *parent);
719+
u64 mptcp_wnd_end(const struct mptcp_sock *msk);
720+
void mptcp_set_timeout(struct sock *sk);
719721
struct sock *__mptcp_nmpc_sk(struct mptcp_sock *msk);
720722
bool __mptcp_close(struct sock *sk, long timeout);
721723
void mptcp_cancel_work(struct sock *sk);

0 commit comments

Comments
 (0)