Skip to content

Commit 075a234

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 trace for mptcp_subflow_get_send() to do this test and invoke kfuncs mptcp_subflow_active() and mptcp_subflow_set_scheduled() in the loop. Signed-off-by: Geliang Tang <[email protected]>
1 parent 0188a7e commit 075a234

File tree

3 files changed

+48
-0
lines changed

3 files changed

+48
-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: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,9 @@ mptcp_subflow_tcp_sock(const struct mptcp_subflow_context *subflow)
4646
extern void mptcp_subflow_set_scheduled(struct mptcp_subflow_context *subflow,
4747
bool scheduled) __ksym;
4848

49+
extern void bpf_rcu_read_lock(void) __ksym;
50+
extern void bpf_rcu_read_unlock(void) __ksym;
51+
4952
extern struct mptcp_subflow_context *
5053
bpf_mptcp_subflow_ctx_by_pos(const struct mptcp_sched_data *data, unsigned int pos) __ksym;
5154

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 pid;
10+
11+
extern bool mptcp_subflow_active(struct mptcp_subflow_context *subflow) __ksym;
12+
13+
SEC("fentry/mptcp_subflow_get_send")
14+
struct sock *BPF_PROG(trace_mptcp_subflow_get_send, struct mptcp_sock *msk)
15+
{
16+
struct mptcp_subflow_context *subflow;
17+
int i = 0;
18+
19+
if (bpf_get_current_pid_tgid() >> 32 != pid)
20+
return NULL;
21+
22+
bpf_rcu_read_lock();
23+
bpf_for_each(mptcp_subflow, subflow, msk) {
24+
if (i++ > MPTCP_SUBFLOWS_MAX)
25+
break;
26+
27+
if (subflow->token != msk->token)
28+
break;
29+
30+
if (!mptcp_subflow_active(subflow))
31+
continue;
32+
33+
mptcp_subflow_set_scheduled(subflow, false);
34+
}
35+
bpf_rcu_read_unlock();
36+
37+
return NULL;
38+
}

0 commit comments

Comments
 (0)