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".
Signed-off-by: Geliang Tang <tanggeliang@kylinos.cn>
---
.../testing/selftests/bpf/prog_tests/mptcp.c | 20 +++++++------------
1 file changed, 7 insertions(+), 13 deletions(-)
diff --git a/tools/testing/selftests/bpf/prog_tests/mptcp.c b/tools/testing/selftests/bpf/prog_tests/mptcp.c
index a3e68bc6afa3..acd79be134cd 100644
--- a/tools/testing/selftests/bpf/prog_tests/mptcp.c
+++ b/tools/testing/selftests/bpf/prog_tests/mptcp.c
@@ -424,10 +424,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,13 +438,14 @@ 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();
@@ -455,14 +455,8 @@ static void test_subflow(void)
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"))
- goto close_netns;
-
run_subflow();
- bpf_link__destroy(link);
close_netns:
cleanup_netns(nstoken);
skel_destroy:
--
2.43.0