Skip to content

Commit

Permalink
bpf: Add mptcp [gs]etsockopt per subflow
Browse files Browse the repository at this point in the history
Closes: multipath-tcp#76
Signed-off-by: Geliang Tang <tanggeliang@kylinos.cn>
  • Loading branch information
Geliang Tang committed Mar 19, 2024
1 parent 30711c8 commit 9018845
Show file tree
Hide file tree
Showing 2 changed files with 79 additions and 0 deletions.
65 changes: 65 additions & 0 deletions tools/testing/selftests/bpf/prog_tests/mptcp.c
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,69 @@ static void test_mptcpify(void)
close(cgroup_fd);
}

static int getsetsockopt(void)
{
int server_fd, client_fd, err = 0;

server_fd = start_mptcp_server(AF_INET, NULL, 0, 0);
if (!ASSERT_GE(server_fd, 0, "start_mptcp_server")) {
err = -EIO;
goto out;
}

client_fd = connect_to_fd(server_fd, 0);
if (!ASSERT_GE(client_fd, 0, "connect to fd")) {
err = -EIO;
goto close_server;
}

send_byte(client_fd);

close(client_fd);
close_server:
close(server_fd);
out:
return err;
}

static void run_test_sockopt(int cgroup_fd)
{
struct mptcp_sock *skel;

skel = mptcp_sock__open_and_load();
if (!ASSERT_OK_PTR(skel, "skel_load"))
goto cleanup;

skel->bss->page_size = getpagesize();

skel->links._setsockopt =
bpf_program__attach_cgroup(skel->progs._setsockopt, cgroup_fd);
if (!ASSERT_OK_PTR(skel->links._setsockopt, "setsockopt_link"))
goto cleanup;

skel->links._getsockopt =
bpf_program__attach_cgroup(skel->progs._getsockopt, cgroup_fd);
if (!ASSERT_OK_PTR(skel->links._getsockopt, "getsockopt_link"))
goto cleanup;

ASSERT_OK(getsetsockopt(), "getsetsockopt");

cleanup:
mptcp_sock__destroy(skel);
}

void test_sockopt_mptcp(void)
{
int cgroup_fd;

cgroup_fd = test__join_cgroup("/sockopt_mptcp");
if (!ASSERT_GE(cgroup_fd, 0, "join_cgroup /sockopt_mptcp"))
return;

run_test_sockopt(cgroup_fd);
close(cgroup_fd);
}

static const unsigned int total_bytes = 10 * 1024 * 1024;
static int stop, duration;

Expand Down Expand Up @@ -693,6 +756,8 @@ void test_mptcp(void)
test_base();
if (test__start_subtest("mptcpify"))
test_mptcpify();
if (test__start_subtest("sockopt"))
test_sockopt_mptcp();
if (test__start_subtest("default"))
test_default();
if (test__start_subtest("first"))
Expand Down
14 changes: 14 additions & 0 deletions tools/testing/selftests/bpf/progs/mptcp_sock.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
char _license[] SEC("license") = "GPL";
__u32 token = 0;

int page_size = 0; /* userspace should set it */

struct mptcp_storage {
__u32 invoked;
__u32 is_mptcp;
Expand Down Expand Up @@ -86,3 +88,15 @@ int BPF_PROG(trace_mptcp_pm_new_connection, struct mptcp_sock *msk,

return 0;
}

SEC("cgroup/getsockopt")
int _getsockopt(struct bpf_sockopt *ctx)
{
return 1;
}

SEC("cgroup/setsockopt")
int _setsockopt(struct bpf_sockopt *ctx)
{
return 1;
}

0 comments on commit 9018845

Please sign in to comment.