Skip to content

Commit e570493

Browse files
Geliang Tangintel-lab-lkp
authored andcommitted
selftests/bpf: Add mptcp_subflow bpf_iter test prog
This patch adds a new mptcp bpf selftest program for the newly added mptcp_subflow bpf_iter. Export bpf_iter_mptcp_subflow_new/_next/_destroy into bpf_experimental.h then use bpf_for_each(mptcp_subflow, subflow, msk) to walk the mptcp subflow list. Add a ftrace hook for mptcp_sched_get_send() to do this test and invoke kfuncs mptcp_subflow_active() and mptcp_subflow_set_scheduled() in the loops. Signed-off-by: Geliang Tang <[email protected]>
1 parent daa0597 commit e570493

File tree

3 files changed

+49
-0
lines changed

3 files changed

+49
-0
lines changed

tools/testing/selftests/bpf/bpf_experimental.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -549,6 +549,13 @@ extern int bpf_iter_css_new(struct bpf_iter_css *it,
549549
extern struct cgroup_subsys_state *bpf_iter_css_next(struct bpf_iter_css *it) __weak __ksym;
550550
extern void bpf_iter_css_destroy(struct bpf_iter_css *it) __weak __ksym;
551551

552+
struct bpf_iter_mptcp_subflow;
553+
extern int bpf_iter_mptcp_subflow_new(struct bpf_iter_mptcp_subflow *it,
554+
struct mptcp_sock *msk) __weak __ksym;
555+
extern struct mptcp_subflow_context *
556+
bpf_iter_mptcp_subflow_next(struct bpf_iter_mptcp_subflow *it) __weak __ksym;
557+
extern void bpf_iter_mptcp_subflow_destroy(struct bpf_iter_mptcp_subflow *it) __weak __ksym;
558+
552559
extern int bpf_wq_init(struct bpf_wq *wq, void *p__map, unsigned int flags) __weak __ksym;
553560
extern int bpf_wq_start(struct bpf_wq *wq, unsigned int flags) __weak __ksym;
554561
extern int bpf_wq_set_callback_impl(struct bpf_wq *wq,

tools/testing/selftests/bpf/progs/mptcp_bpf.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,13 @@ mptcp_subflow_tcp_sock(const struct mptcp_subflow_context *subflow)
4343
}
4444

4545
/* ksym */
46+
extern bool mptcp_subflow_active(struct mptcp_subflow_context *subflow) __ksym;
4647
extern void mptcp_subflow_set_scheduled(struct mptcp_subflow_context *subflow,
4748
bool scheduled) __ksym;
4849

50+
extern void bpf_rcu_read_lock(void) __ksym;
51+
extern void bpf_rcu_read_unlock(void) __ksym;
52+
4953
extern struct mptcp_subflow_context *
5054
bpf_mptcp_subflow_ctx_by_pos(const struct mptcp_sched_data *data, unsigned int pos) __ksym;
5155

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
// SPDX-License-Identifier: GPL-2.0
2+
/* Copyright (c) 2024, Kylin Software */
3+
4+
/* vmlinux.h, bpf_helpers.h and other 'define' */
5+
#include "bpf_tracing_net.h"
6+
#include "mptcp_bpf.h"
7+
8+
char _license[] SEC("license") = "GPL";
9+
int iter = 0;
10+
int pid;
11+
12+
SEC("fentry/mptcp_sched_get_send")
13+
int BPF_PROG(trace_mptcp_sched_get_send, struct mptcp_sock *msk)
14+
{
15+
struct mptcp_subflow_context *subflow;
16+
int i = 0;
17+
18+
if (bpf_get_current_pid_tgid() >> 32 != pid)
19+
return 0;
20+
21+
bpf_rcu_read_lock();
22+
bpf_for_each(mptcp_subflow, subflow, msk) {
23+
if (i++ >= MPTCP_SUBFLOWS_MAX)
24+
break;
25+
26+
if (subflow->token != msk->token)
27+
break;
28+
29+
if (!mptcp_subflow_active(subflow))
30+
continue;
31+
32+
mptcp_subflow_set_scheduled(subflow, false);
33+
}
34+
bpf_rcu_read_unlock();
35+
36+
iter = i;
37+
return 0;
38+
}

0 commit comments

Comments
 (0)