diff mbox series

[mptcp-next,5/8] Squash to "selftests/bpf: Add bpf_rr scheduler & test"

Message ID b47b7a3efea25e42271928d6e2a93b913c893b96.1727169534.git.tanggeliang@kylinos.cn (mailing list archive)
State Superseded, archived
Headers show
Series use bpf_iter in bpf schedulers | expand

Commit Message

Geliang Tang Sept. 24, 2024, 9:28 a.m. UTC
From: Geliang Tang <tanggeliang@kylinos.cn>

Use the newly added bpf_for_each() helper to walk the conn_list.

Signed-off-by: Geliang Tang <tanggeliang@kylinos.cn>
---
 .../testing/selftests/bpf/progs/mptcp_bpf_rr.c | 18 ++++++++++--------
 1 file changed, 10 insertions(+), 8 deletions(-)
diff mbox series

Patch

diff --git a/tools/testing/selftests/bpf/progs/mptcp_bpf_rr.c b/tools/testing/selftests/bpf/progs/mptcp_bpf_rr.c
index 638ea6aa63b7..c0b30733d987 100644
--- a/tools/testing/selftests/bpf/progs/mptcp_bpf_rr.c
+++ b/tools/testing/selftests/bpf/progs/mptcp_bpf_rr.c
@@ -37,7 +37,7 @@  int BPF_PROG(bpf_rr_get_subflow, struct mptcp_sock *msk,
 	struct mptcp_subflow_context *subflow;
 	struct mptcp_rr_storage *ptr;
 	struct sock *last_snd = NULL;
-	int nr = 0;
+	int id = 1;
 
 	ptr = bpf_sk_storage_get(&mptcp_rr_map, msk, 0,
 				 BPF_LOCAL_STORAGE_GET_F_CREATE);
@@ -46,22 +46,24 @@  int BPF_PROG(bpf_rr_get_subflow, struct mptcp_sock *msk,
 
 	last_snd = ptr->last_snd;
 
-	for (int i = 0; i < data->subflows && i < MPTCP_SUBFLOWS_MAX; i++) {
-		subflow = bpf_mptcp_subflow_ctx_by_pos(data, i);
-		if (!last_snd || !subflow)
+	bpf_for_each(mptcp_subflow, subflow, msk) {
+		if (!last_snd)
 			break;
 
 		if (mptcp_subflow_tcp_sock(subflow) == last_snd) {
-			if (i + 1 == MPTCP_SUBFLOWS_MAX ||
-			    !bpf_mptcp_subflow_ctx_by_pos(data, i + 1))
+			struct mptcp_subflow_context *next;
+
+			next = bpf_core_cast(list_next_entry(subflow, node),
+					     struct mptcp_subflow_context);
+			if (list_entry_is_head(next, &msk->conn_list, node))
 				break;
 
-			nr = i + 1;
+			id = next->subflow_id;
 			break;
 		}
 	}
 
-	subflow = bpf_mptcp_subflow_ctx_by_pos(data, nr);
+	subflow = bpf_mptcp_lookup_subflow_by_id(msk, id);
 	if (!subflow)
 		return -1;
 	mptcp_subflow_set_scheduled(subflow, true);