From: Geliang Tang <tanggeliang@kylinos.cn>
Address Martin's comments:
Drop mptcp_subflow__attach.
Use bpf_program__attach_cgroup instead of bpf_prog_attach.
Use the skel->links.{mptcp_subflow, _getsockopt_subflow}, instead of declaring a
local "link".
More subflows for endpoint_init:
Add two more test addresses ADDR_3 and ADDR_4, and adds a new parameter
"subflows" for endpoint_init() to control how many subflows are used for the
tests. This makes it more flexible.
Update the parameters of endpoint_init() in test_subflow().
Signed-off-by: Geliang Tang <tanggeliang@kylinos.cn>
---
.../testing/selftests/bpf/prog_tests/mptcp.c | 56 +++++++++++++------
1 file changed, 38 insertions(+), 18 deletions(-)
diff --git a/tools/testing/selftests/bpf/prog_tests/mptcp.c b/tools/testing/selftests/bpf/prog_tests/mptcp.c
index a3e68bc6afa3..167fd9b190ee 100644
--- a/tools/testing/selftests/bpf/prog_tests/mptcp.c
+++ b/tools/testing/selftests/bpf/prog_tests/mptcp.c
@@ -20,6 +20,8 @@
#define NS_TEST "mptcp_ns"
#define ADDR_1 "10.0.1.1"
#define ADDR_2 "10.0.1.2"
+#define ADDR_3 "10.0.1.3"
+#define ADDR_4 "10.0.1.4"
#define PORT_1 10001
#define WITH_DATA true
#define WITHOUT_DATA false
@@ -351,22 +353,46 @@ static void test_mptcpify(void)
close(cgroup_fd);
}
-static int endpoint_init(char *flags)
+static int endpoint_add(char *addr, char *flags)
{
+ return SYS_NOFAIL("ip -net %s mptcp endpoint add %s %s",
+ NS_TEST, addr, flags);
+}
+
+static int endpoint_init(char *flags, u8 subflows)
+{
+ int ret = -1;
+
+ if (!subflows || subflows > 4)
+ goto fail;
+
SYS(fail, "ip -net %s link add veth1 type veth peer name veth2", NS_TEST);
SYS(fail, "ip -net %s addr add %s/24 dev veth1", NS_TEST, ADDR_1);
SYS(fail, "ip -net %s link set dev veth1 up", NS_TEST);
SYS(fail, "ip -net %s addr add %s/24 dev veth2", NS_TEST, ADDR_2);
SYS(fail, "ip -net %s link set dev veth2 up", NS_TEST);
- if (SYS_NOFAIL("ip -net %s mptcp endpoint add %s %s", NS_TEST, ADDR_2, flags)) {
+
+ SYS(fail, "ip -net %s link add veth3 type veth peer name veth4", NS_TEST);
+ SYS(fail, "ip -net %s addr add %s/24 dev veth3", NS_TEST, ADDR_3);
+ SYS(fail, "ip -net %s link set dev veth3 up", NS_TEST);
+ SYS(fail, "ip -net %s addr add %s/24 dev veth4", NS_TEST, ADDR_4);
+ SYS(fail, "ip -net %s link set dev veth4 up", NS_TEST);
+
+ if (SYS_NOFAIL("ip -net %s mptcp limits set subflows 4", NS_TEST)) {
printf("'ip mptcp' not supported, skip this test.\n");
test__skip();
goto fail;
}
- return 0;
+ if (subflows > 1)
+ ret = endpoint_add(ADDR_2, flags);
+ if (subflows > 2)
+ ret = ret ?: endpoint_add(ADDR_3, flags);
+ if (subflows > 3)
+ ret = ret ?: endpoint_add(ADDR_4, flags);
+
fail:
- return -1;
+ return ret;
}
static void wait_for_new_subflows(int fd)
@@ -424,10 +450,9 @@ static void run_subflow(void)
static void test_subflow(void)
{
- int cgroup_fd, prog_fd, err;
struct mptcp_subflow *skel;
struct nstoken *nstoken;
- struct bpf_link *link;
+ int cgroup_fd;
cgroup_fd = test__join_cgroup("/mptcp_subflow");
if (!ASSERT_OK_FD(cgroup_fd, "join_cgroup: mptcp_subflow"))
@@ -439,30 +464,25 @@ static void test_subflow(void)
skel->bss->pid = getpid();
- err = mptcp_subflow__attach(skel);
- if (!ASSERT_OK(err, "skel_attach: mptcp_subflow"))
+ skel->links.mptcp_subflow =
+ bpf_program__attach_cgroup(skel->progs.mptcp_subflow, cgroup_fd);
+ if (!ASSERT_OK_PTR(skel->links.mptcp_subflow, "attach mptcp_subflow"))
goto skel_destroy;
- prog_fd = bpf_program__fd(skel->progs.mptcp_subflow);
- err = bpf_prog_attach(prog_fd, cgroup_fd, BPF_CGROUP_SOCK_OPS, 0);
- if (!ASSERT_OK(err, "prog_attach"))
+ skel->links._getsockopt_subflow =
+ bpf_program__attach_cgroup(skel->progs._getsockopt_subflow, cgroup_fd);
+ if (!ASSERT_OK_PTR(skel->links._getsockopt_subflow, "attach _getsockopt_subflow"))
goto skel_destroy;
nstoken = create_netns();
if (!ASSERT_OK_PTR(nstoken, "create_netns: mptcp_subflow"))
goto skel_destroy;
- if (endpoint_init("subflow") < 0)
- goto close_netns;
-
- link = bpf_program__attach_cgroup(skel->progs._getsockopt_subflow,
- cgroup_fd);
- if (!ASSERT_OK_PTR(link, "getsockopt prog"))
+ if (endpoint_init("subflow", 2) < 0)
goto close_netns;
run_subflow();
- bpf_link__destroy(link);
close_netns:
cleanup_netns(nstoken);
skel_destroy:
--
2.43.0
Hi Geliang, On 22/09/2024 03:00, Geliang Tang wrote: > From: Geliang Tang <tanggeliang@kylinos.cn> > > Address Martin's comments: Thank you for that! > Drop mptcp_subflow__attach. > Use bpf_program__attach_cgroup instead of bpf_prog_attach. > Use the skel->links.{mptcp_subflow, _getsockopt_subflow}, instead of declaring a > local "link". > > More subflows for endpoint_init: > > Add two more test addresses ADDR_3 and ADDR_4, and adds a new parameter > "subflows" for endpoint_init() to control how many subflows are used for the > tests. This makes it more flexible. Should we not split that and keep it for later? I mean: I think it would be better to only address Martin's comments, and modify endpoint_init() later because this is not needed for the moment if I'm not mistaken. When we will need more than 2 subflows, we can add these patches, no? It's just to minimise the differences between the versions already reviewed by Martin, and the future one. WDYT? I can already apply patches 1 and 2/6 from your v2. Then check later what is preferred before sending a new version upstream. Cheers, Matt -- Sponsored by the NGI0 Core fund.
© 2016 - 2024 Red Hat, Inc.