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>
---
.../selftests/bpf/progs/mptcp_bpf_burst.c | 39 +++++++------------
1 file changed, 14 insertions(+), 25 deletions(-)
diff --git a/tools/testing/selftests/bpf/progs/mptcp_bpf_burst.c b/tools/testing/selftests/bpf/progs/mptcp_bpf_burst.c
index dcab196867fe..3bf0213d01b3 100644
--- a/tools/testing/selftests/bpf/progs/mptcp_bpf_burst.c
+++ b/tools/testing/selftests/bpf/progs/mptcp_bpf_burst.c
@@ -66,8 +66,7 @@ void BPF_PROG(mptcp_sched_burst_release, struct mptcp_sock *msk)
{
}
-static int bpf_burst_get_send(struct mptcp_sock *msk,
- struct mptcp_sched_data *data)
+static int bpf_burst_get_send(struct mptcp_sock *msk)
{
struct bpf_subflow_send_info send_info[SSK_MODE_MAX];
struct mptcp_subflow_context *subflow;
@@ -83,14 +82,8 @@ static int bpf_burst_get_send(struct mptcp_sock *msk,
send_info[i].linger_time = -1;
}
- for (i = 0; i < data->subflows && i < MPTCP_SUBFLOWS_MAX; i++) {
- bool backup;
-
- subflow = bpf_mptcp_subflow_ctx_by_pos(data, i);
- if (!subflow)
- break;
-
- backup = subflow->backup || subflow->request_bkup;
+ bpf_for_each(mptcp_subflow, subflow, msk) {
+ bool backup = subflow->backup || subflow->request_bkup;
ssk = mptcp_subflow_tcp_sock(subflow);
if (!mptcp_subflow_active(subflow))
@@ -108,7 +101,7 @@ static int bpf_burst_get_send(struct mptcp_sock *msk,
linger_time = div_u64((__u64)ssk->sk_wmem_queued << 32, pace);
if (linger_time < send_info[backup].linger_time) {
- send_info[backup].subflow_id = i;
+ send_info[backup].subflow_id = subflow->subflow_id;
send_info[backup].linger_time = linger_time;
}
}
@@ -118,7 +111,7 @@ static int bpf_burst_get_send(struct mptcp_sock *msk,
if (!nr_active)
send_info[SSK_MODE_ACTIVE].subflow_id = send_info[SSK_MODE_BACKUP].subflow_id;
- subflow = bpf_mptcp_subflow_ctx_by_pos(data, send_info[SSK_MODE_ACTIVE].subflow_id);
+ subflow = bpf_mptcp_lookup_subflow_by_id(msk, send_info[SSK_MODE_ACTIVE].subflow_id);
if (!subflow)
return -1;
ssk = mptcp_subflow_tcp_sock(subflow);
@@ -140,19 +133,15 @@ static int bpf_burst_get_send(struct mptcp_sock *msk,
return 0;
}
-static int bpf_burst_get_retrans(struct mptcp_sock *msk,
- struct mptcp_sched_data *data)
+static int bpf_burst_get_retrans(struct mptcp_sock *msk)
{
- int backup = MPTCP_SUBFLOWS_MAX, pick = MPTCP_SUBFLOWS_MAX, subflow_id;
+ int backup = MPTCP_SUBFLOWS_MAX, pick = MPTCP_SUBFLOWS_MAX;
struct mptcp_subflow_context *subflow;
int min_stale_count = INT_MAX;
struct sock *ssk;
+ int subflow_id;
- for (int i = 0; i < data->subflows && i < MPTCP_SUBFLOWS_MAX; i++) {
- subflow = bpf_mptcp_subflow_ctx_by_pos(data, i);
- if (!subflow)
- break;
-
+ bpf_for_each(mptcp_subflow, subflow, msk) {
if (!mptcp_subflow_active(subflow))
continue;
@@ -166,12 +155,12 @@ static int bpf_burst_get_retrans(struct mptcp_sock *msk,
if (subflow->backup || subflow->request_bkup) {
if (backup == MPTCP_SUBFLOWS_MAX)
- backup = i;
+ backup = subflow->subflow_id;
continue;
}
if (pick == MPTCP_SUBFLOWS_MAX)
- pick = i;
+ pick = subflow->subflow_id;
}
if (pick < MPTCP_SUBFLOWS_MAX) {
@@ -181,7 +170,7 @@ static int bpf_burst_get_retrans(struct mptcp_sock *msk,
subflow_id = min_stale_count > 1 ? backup : MPTCP_SUBFLOWS_MAX;
out:
- subflow = bpf_mptcp_subflow_ctx_by_pos(data, subflow_id);
+ subflow = bpf_mptcp_lookup_subflow_by_id(msk, subflow_id);
if (!subflow)
return -1;
mptcp_subflow_set_scheduled(subflow, true);
@@ -193,8 +182,8 @@ int BPF_PROG(bpf_burst_get_subflow, struct mptcp_sock *msk,
struct mptcp_sched_data *data)
{
if (data->reinject)
- return bpf_burst_get_retrans(msk, data);
- return bpf_burst_get_send(msk, data);
+ return bpf_burst_get_retrans(msk);
+ return bpf_burst_get_send(msk);
}
SEC(".struct_ops")
--
2.43.0