Skip to content

Commit e7bc810

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 41a69b0 commit e7bc810

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
@@ -220,15 +220,26 @@ struct bpf_iter_mptcp_subflow_kern {
220220
__bpf_kfunc_start_defs();
221221

222222
__bpf_kfunc static struct mptcp_subflow_context *
223-
bpf_mptcp_subflow_ctx(const struct sock *sk)
223+
bpf_mptcp_subflow_ctx(const struct sock *sk__ign)
224224
{
225+
const struct sock *sk = sk__ign;
226+
225227
if (sk && sk_fullsock(sk) &&
226228
sk->sk_protocol == IPPROTO_TCP && sk_is_mptcp(sk))
227229
return mptcp_subflow_ctx(sk);
228230

229231
return NULL;
230232
}
231233

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+
232243
__bpf_kfunc static int
233244
bpf_iter_mptcp_subflow_new(struct bpf_iter_mptcp_subflow *it,
234245
struct sock *sk)
@@ -273,13 +284,37 @@ bpf_iter_mptcp_subflow_destroy(struct bpf_iter_mptcp_subflow *it)
273284
{
274285
}
275286

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+
276303
__bpf_kfunc_end_defs();
277304

278305
BTF_KFUNCS_START(bpf_mptcp_common_kfunc_ids)
279306
BTF_ID_FLAGS(func, bpf_mptcp_subflow_ctx, KF_RET_NULL)
307+
BTF_ID_FLAGS(func, bpf_mptcp_subflow_tcp_sock, KF_RET_NULL)
280308
BTF_ID_FLAGS(func, bpf_iter_mptcp_subflow_new, KF_ITER_NEW | KF_TRUSTED_ARGS)
281309
BTF_ID_FLAGS(func, bpf_iter_mptcp_subflow_next, KF_ITER_NEXT | KF_RET_NULL)
282310
BTF_ID_FLAGS(func, bpf_iter_mptcp_subflow_destroy, KF_ITER_DESTROY)
311+
BTF_ID_FLAGS(func, mptcp_subflow_set_scheduled)
312+
BTF_ID_FLAGS(func, mptcp_subflow_active)
313+
BTF_ID_FLAGS(func, mptcp_set_timeout)
314+
BTF_ID_FLAGS(func, mptcp_wnd_end)
315+
BTF_ID_FLAGS(func, bpf_sk_stream_memory_free, KF_RET_NULL)
316+
BTF_ID_FLAGS(func, bpf_mptcp_subflow_queues_empty)
317+
BTF_ID_FLAGS(func, mptcp_pm_subflow_chk_stale, KF_SLEEPABLE)
283318
BTF_KFUNCS_END(bpf_mptcp_common_kfunc_ids)
284319

285320
static const struct btf_kfunc_id_set bpf_mptcp_common_kfunc_set = {
@@ -294,6 +329,8 @@ static int __init bpf_mptcp_kfunc_init(void)
294329
ret = register_btf_fmodret_id_set(&bpf_mptcp_fmodret_set);
295330
ret = ret ?: register_btf_kfunc_id_set(BPF_PROG_TYPE_CGROUP_SOCKOPT,
296331
&bpf_mptcp_common_kfunc_set);
332+
ret = ret ?: register_btf_kfunc_id_set(BPF_PROG_TYPE_STRUCT_OPS,
333+
&bpf_mptcp_common_kfunc_set);
297334
#ifdef CONFIG_BPF_JIT
298335
ret = ret ?: register_bpf_struct_ops(&bpf_mptcp_sched_ops, mptcp_sched_ops);
299336
#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
icsk_timeout(inet_csk(ssk)) - 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
@@ -723,6 +723,8 @@ void __mptcp_subflow_send_ack(struct sock *ssk);
723723
void mptcp_subflow_reset(struct sock *ssk);
724724
void mptcp_subflow_queue_clean(struct sock *sk, struct sock *ssk);
725725
void mptcp_sock_graft(struct sock *sk, struct socket *parent);
726+
u64 mptcp_wnd_end(const struct mptcp_sock *msk);
727+
void mptcp_set_timeout(struct sock *sk);
726728
struct sock *__mptcp_nmpc_sk(struct mptcp_sock *msk);
727729
bool __mptcp_close(struct sock *sk, long timeout);
728730
void mptcp_cancel_work(struct sock *sk);

0 commit comments

Comments
 (0)