forked from torvalds/linux
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
selftests/bpf: Add mptcp_subflow bpf_iter test prog
This patch adds a ftrace hook for mptcp_sched_get_send() to test the newly added mptcp_subflow bpf_iter. This test simulates a typical mptcp packet scheduler, which selects a subflow from multiple subflows of an mptcp socket to send data. Export mptcp_subflow helpers bpf_iter_mptcp_subflow_new/_next/_destroy, bpf_mptcp_sock_acquire/_release and other helpers into bpf_experimental.h. Use _acquire() to acquire the msk, then use bpf_for_each(mptcp_subflow) to walk the subflow list of this msk. Invoke kfuncs mptcp_subflow_active() and bpf_mptcp_subflow_tcp_sock() in the loop to pick a subsocket. Finally use bpf_mptcp_subflow_ctx() to get the subflow context of this subsocket and use mptcp_subflow_set_scheduled() to set it as being scheduled. Signed-off-by: Geliang Tang <[email protected]>
- Loading branch information
1 parent
0ec1195
commit 514c07e
Showing
3 changed files
with
58 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 42 additions & 0 deletions
42
tools/testing/selftests/bpf/progs/mptcp_bpf_iters_subflow.c
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
// SPDX-License-Identifier: GPL-2.0 | ||
/* Copyright (c) 2024, Kylin Software */ | ||
|
||
/* vmlinux.h, bpf_helpers.h and other 'define' */ | ||
#include "bpf_tracing_net.h" | ||
#include "mptcp_bpf.h" | ||
|
||
char _license[] SEC("license") = "GPL"; | ||
int subflows; | ||
int pid; | ||
|
||
SEC("fentry/mptcp_sched_get_send") | ||
int BPF_PROG(trace_mptcp_sched_get_send, struct mptcp_sock *msk) | ||
{ | ||
struct mptcp_subflow_context *subflow; | ||
struct sock *ssk = NULL; | ||
|
||
if (bpf_get_current_pid_tgid() >> 32 != pid) | ||
return 0; | ||
|
||
msk = bpf_mptcp_sock_acquire(msk); | ||
if (!msk) | ||
return 0; | ||
bpf_for_each(mptcp_subflow, subflow, msk) { | ||
if (subflow->token != msk->token) | ||
break; | ||
|
||
if (!mptcp_subflow_active(subflow)) | ||
continue; | ||
|
||
ssk = bpf_mptcp_subflow_tcp_sock(subflow); | ||
} | ||
bpf_mptcp_sock_release(msk); | ||
|
||
if (!ssk) | ||
return 0; | ||
subflow = bpf_mptcp_subflow_ctx(ssk); | ||
mptcp_subflow_set_scheduled(subflow, true); | ||
subflows = subflow->subflow_id; | ||
|
||
return 0; | ||
} |