Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
To be squashed in BPF topics.

Link: https://lore.kernel.org/all/20240509175026.3423614-1-martin.lau@linux.dev/T/
Signed-off-by: Matthieu Baerts (NGI0) <matttbe@kernel.org>
  • Loading branch information
matttbe committed May 14, 2024
1 parent 6186bbe commit b2fa488
Show file tree
Hide file tree
Showing 8 changed files with 65 additions and 37 deletions.
2 changes: 1 addition & 1 deletion MAINTAINERS
Original file line number Diff line number Diff line change
Expand Up @@ -15513,7 +15513,7 @@ F: include/net/mptcp.h
F: include/trace/events/mptcp.h
F: include/uapi/linux/mptcp*.h
F: net/mptcp/
F: tools/testing/selftests/bpf/*/*mptcp*.c
F: tools/testing/selftests/bpf/*/*mptcp*.[ch]
F: tools/testing/selftests/net/mptcp/

NETWORKING [TCP]
Expand Down
19 changes: 19 additions & 0 deletions tools/testing/selftests/bpf/progs/mptcp_bpf.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/* SPDX-License-Identifier: (LGPL-2.1 OR BSD-2-Clause) */
#ifndef __MPTCP_BPF_H__
#define __MPTCP_BPF_H__

#define MPTCP_SUBFLOWS_MAX 8

extern void mptcp_subflow_set_scheduled(struct mptcp_subflow_context *subflow,
bool scheduled) __ksym;

extern struct mptcp_subflow_context *
bpf_mptcp_subflow_ctx_by_pos(const struct mptcp_sched_data *data, unsigned int pos) __ksym;

static __always_inline struct sock *
mptcp_subflow_tcp_sock(const struct mptcp_subflow_context *subflow)
{
return subflow->tcp_sock;
}

#endif
14 changes: 8 additions & 6 deletions tools/testing/selftests/bpf/progs/mptcp_bpf_bkup.c
Original file line number Diff line number Diff line change
@@ -1,23 +1,25 @@
// SPDX-License-Identifier: GPL-2.0
/* Copyright (c) 2022, SUSE. */

#include <linux/bpf.h>
#include "bpf_tcp_helpers.h"
#include "bpf_tracing_net.h"
#include "mptcp_bpf.h"
#include <bpf/bpf_tracing.h>

char _license[] SEC("license") = "GPL";

SEC("struct_ops/mptcp_sched_bkup_init")
SEC("struct_ops")
void BPF_PROG(mptcp_sched_bkup_init, struct mptcp_sock *msk)
{
}

SEC("struct_ops/mptcp_sched_bkup_release")
SEC("struct_ops")
void BPF_PROG(mptcp_sched_bkup_release, struct mptcp_sock *msk)
{
}

int BPF_STRUCT_OPS(bpf_bkup_get_subflow, struct mptcp_sock *msk,
struct mptcp_sched_data *data)
SEC("struct_ops")
int BPF_PROG(bpf_bkup_get_subflow, struct mptcp_sock *msk,
struct mptcp_sched_data *data)
{
int nr = -1;

Expand Down
20 changes: 12 additions & 8 deletions tools/testing/selftests/bpf/progs/mptcp_bpf_burst.c
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
// SPDX-License-Identifier: GPL-2.0
/* Copyright (c) 2023, SUSE. */

#include <linux/bpf.h>
#include "bpf_tracing_net.h"
#include "mptcp_bpf.h"
#include <bpf/bpf_tracing.h>
#include <limits.h>
#include "bpf_tcp_helpers.h"

char _license[] SEC("license") = "GPL";

#define MPTCP_SEND_BURST_SIZE 65428

struct subflow_send_info {
#define min(a, b) ((a) < (b) ? (a) : (b))

struct bpf_subflow_send_info {
__u8 subflow_id;
__u64 linger_time;
};
Expand Down Expand Up @@ -55,20 +58,20 @@ static __always_inline bool sk_stream_memory_free(const struct sock *sk)
return __sk_stream_memory_free(sk, 0);
}

SEC("struct_ops/mptcp_sched_burst_init")
SEC("struct_ops")
void BPF_PROG(mptcp_sched_burst_init, struct mptcp_sock *msk)
{
}

SEC("struct_ops/mptcp_sched_burst_release")
SEC("struct_ops")
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)
{
struct subflow_send_info send_info[SSK_MODE_MAX];
struct bpf_subflow_send_info send_info[SSK_MODE_MAX];
struct mptcp_subflow_context *subflow;
struct sock *sk = (struct sock *)msk;
__u32 pace, burst, wmem;
Expand Down Expand Up @@ -182,8 +185,9 @@ static int bpf_burst_get_retrans(struct mptcp_sock *msk,
return 0;
}

int BPF_STRUCT_OPS(bpf_burst_get_subflow, struct mptcp_sock *msk,
struct mptcp_sched_data *data)
SEC("struct_ops")
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);
Expand Down
14 changes: 8 additions & 6 deletions tools/testing/selftests/bpf/progs/mptcp_bpf_first.c
Original file line number Diff line number Diff line change
@@ -1,23 +1,25 @@
// SPDX-License-Identifier: GPL-2.0
/* Copyright (c) 2022, SUSE. */

#include <linux/bpf.h>
#include "bpf_tcp_helpers.h"
#include "bpf_tracing_net.h"
#include "mptcp_bpf.h"
#include <bpf/bpf_tracing.h>

char _license[] SEC("license") = "GPL";

SEC("struct_ops/mptcp_sched_first_init")
SEC("struct_ops")
void BPF_PROG(mptcp_sched_first_init, struct mptcp_sock *msk)
{
}

SEC("struct_ops/mptcp_sched_first_release")
SEC("struct_ops")
void BPF_PROG(mptcp_sched_first_release, struct mptcp_sock *msk)
{
}

int BPF_STRUCT_OPS(bpf_first_get_subflow, struct mptcp_sock *msk,
struct mptcp_sched_data *data)
SEC("struct_ops")
int BPF_PROG(bpf_first_get_subflow, struct mptcp_sock *msk,
struct mptcp_sched_data *data)
{
mptcp_subflow_set_scheduled(bpf_mptcp_subflow_ctx_by_pos(data, 0), true);
return 0;
Expand Down
14 changes: 8 additions & 6 deletions tools/testing/selftests/bpf/progs/mptcp_bpf_red.c
Original file line number Diff line number Diff line change
@@ -1,23 +1,25 @@
// SPDX-License-Identifier: GPL-2.0
/* Copyright (c) 2022, SUSE. */

#include <linux/bpf.h>
#include "bpf_tcp_helpers.h"
#include "bpf_tracing_net.h"
#include "mptcp_bpf.h"
#include <bpf/bpf_tracing.h>

char _license[] SEC("license") = "GPL";

SEC("struct_ops/mptcp_sched_red_init")
SEC("struct_ops")
void BPF_PROG(mptcp_sched_red_init, struct mptcp_sock *msk)
{
}

SEC("struct_ops/mptcp_sched_red_release")
SEC("struct_ops")
void BPF_PROG(mptcp_sched_red_release, struct mptcp_sock *msk)
{
}

int BPF_STRUCT_OPS(bpf_red_get_subflow, struct mptcp_sock *msk,
struct mptcp_sched_data *data)
SEC("struct_ops")
int BPF_PROG(bpf_red_get_subflow, struct mptcp_sock *msk,
struct mptcp_sched_data *data)
{
for (int i = 0; i < data->subflows && i < MPTCP_SUBFLOWS_MAX; i++) {
if (!bpf_mptcp_subflow_ctx_by_pos(data, i))
Expand Down
14 changes: 8 additions & 6 deletions tools/testing/selftests/bpf/progs/mptcp_bpf_rr.c
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
// SPDX-License-Identifier: GPL-2.0
/* Copyright (c) 2022, SUSE. */

#include <linux/bpf.h>
#include "bpf_tcp_helpers.h"
#include "bpf_tracing_net.h"
#include "mptcp_bpf.h"
#include <bpf/bpf_tracing.h>

char _license[] SEC("license") = "GPL";

Expand All @@ -17,21 +18,22 @@ struct {
__type(value, struct mptcp_rr_storage);
} mptcp_rr_map SEC(".maps");

SEC("struct_ops/mptcp_sched_rr_init")
SEC("struct_ops")
void BPF_PROG(mptcp_sched_rr_init, struct mptcp_sock *msk)
{
bpf_sk_storage_get(&mptcp_rr_map, msk, 0,
BPF_LOCAL_STORAGE_GET_F_CREATE);
}

SEC("struct_ops/mptcp_sched_rr_release")
SEC("struct_ops")
void BPF_PROG(mptcp_sched_rr_release, struct mptcp_sock *msk)
{
bpf_sk_storage_delete(&mptcp_rr_map, msk);
}

int BPF_STRUCT_OPS(bpf_rr_get_subflow, struct mptcp_sock *msk,
struct mptcp_sched_data *data)
SEC("struct_ops")
int BPF_PROG(bpf_rr_get_subflow, struct mptcp_sock *msk,
struct mptcp_sched_data *data)
{
struct mptcp_subflow_context *subflow;
struct mptcp_rr_storage *ptr;
Expand Down
5 changes: 1 addition & 4 deletions tools/testing/selftests/bpf/progs/mptcp_subflow.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,8 @@
/* Copyright (c) 2020, Tessares SA. */
/* Copyright (c) 2024, Kylin Software */

#include <sys/socket.h> // SOL_SOCKET, SO_MARK, ...
#include <linux/tcp.h> // TCP_CONGESTION
#include <linux/bpf.h>
#include "bpf_tracing_net.h"
#include <bpf/bpf_helpers.h>
#include "bpf_tcp_helpers.h"

char _license[] SEC("license") = "GPL";

Expand Down

0 comments on commit b2fa488

Please sign in to comment.