On 9/11/24 8:16 AM, Matthieu Baerts (NGI0) wrote:
+static void test_subflow(void) +{
- int cgroup_fd, prog_fd, err;
- struct mptcp_subflow *skel;
- struct nstoken *nstoken;
- struct bpf_link *link;
- cgroup_fd = test__join_cgroup("/mptcp_subflow");
- if (!ASSERT_OK_FD(cgroup_fd, "join_cgroup: mptcp_subflow"))
return;
- skel = mptcp_subflow__open_and_load();
- if (!ASSERT_OK_PTR(skel, "skel_open_load: mptcp_subflow"))
goto close_cgroup;
- skel->bss->pid = getpid();
- err = mptcp_subflow__attach(skel);
This is not needed.
- if (!ASSERT_OK(err, "skel_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);
Use bpf_program__attach_cgroup here instead since ...
- if (!ASSERT_OK(err, "prog_attach"))
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);
... bpf_program__attach_cgroup is used here also.
Instead of declaring a local "link", use the skel->links.{mptcp_subflow, _getsockopt_subflow}. Then mptcp_subflow__destroy(skel) will take care of them also. e.g. "skel->links._getsockopt_subflow = bpf_program__attach_cgroup(...)"
pw-bot: cr