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

Geliang Tang posted 8 patches 2 months, 4 weeks ago
There is a newer version of this series
[PATCH mptcp-next 5/8] Squash to "selftests/bpf: Add bpf_rr scheduler & test"
Posted by Geliang Tang 2 months, 4 weeks ago
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 --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);
-- 
2.43.0