|
12 | 12 | #include <sys/wait.h>
|
13 | 13 | #include <sys/mount.h>
|
14 | 14 | #include <sys/fcntl.h>
|
| 15 | +#include "network_helpers.h" |
15 | 16 |
|
16 | 17 | #define STACK_SIZE (1024 * 1024)
|
17 | 18 | static char child_stack[STACK_SIZE];
|
@@ -74,6 +75,50 @@ static int test_current_pid_tgid_tp(void *args)
|
74 | 75 | return ret;
|
75 | 76 | }
|
76 | 77 |
|
| 78 | +static int test_current_pid_tgid_cgrp(void *args) |
| 79 | +{ |
| 80 | + struct test_ns_current_pid_tgid__bss *bss; |
| 81 | + struct test_ns_current_pid_tgid *skel; |
| 82 | + int server_fd = -1, ret = -1, err; |
| 83 | + int cgroup_fd = *(int *)args; |
| 84 | + pid_t tgid, pid; |
| 85 | + |
| 86 | + skel = test_ns_current_pid_tgid__open(); |
| 87 | + if (!ASSERT_OK_PTR(skel, "test_ns_current_pid_tgid__open")) |
| 88 | + return ret; |
| 89 | + |
| 90 | + bpf_program__set_autoload(skel->progs.cgroup_bind4, true); |
| 91 | + |
| 92 | + err = test_ns_current_pid_tgid__load(skel); |
| 93 | + if (!ASSERT_OK(err, "test_ns_current_pid_tgid__load")) |
| 94 | + goto cleanup; |
| 95 | + |
| 96 | + bss = skel->bss; |
| 97 | + if (get_pid_tgid(&pid, &tgid, bss)) |
| 98 | + goto cleanup; |
| 99 | + |
| 100 | + skel->links.cgroup_bind4 = bpf_program__attach_cgroup( |
| 101 | + skel->progs.cgroup_bind4, cgroup_fd); |
| 102 | + if (!ASSERT_OK_PTR(skel->links.cgroup_bind4, "bpf_program__attach_cgroup")) |
| 103 | + goto cleanup; |
| 104 | + |
| 105 | + server_fd = start_server(AF_INET, SOCK_STREAM, NULL, 0, 0); |
| 106 | + if (!ASSERT_GE(server_fd, 0, "start_server")) |
| 107 | + goto cleanup; |
| 108 | + |
| 109 | + if (!ASSERT_EQ(bss->user_pid, pid, "pid")) |
| 110 | + goto cleanup; |
| 111 | + if (!ASSERT_EQ(bss->user_tgid, tgid, "tgid")) |
| 112 | + goto cleanup; |
| 113 | + ret = 0; |
| 114 | + |
| 115 | +cleanup: |
| 116 | + if (server_fd >= 0) |
| 117 | + close(server_fd); |
| 118 | + test_ns_current_pid_tgid__destroy(skel); |
| 119 | + return ret; |
| 120 | +} |
| 121 | + |
77 | 122 | static void test_ns_current_pid_tgid_new_ns(int (*fn)(void *), void *arg)
|
78 | 123 | {
|
79 | 124 | int wstatus;
|
@@ -102,4 +147,13 @@ void serial_test_ns_current_pid_tgid(void)
|
102 | 147 | test_current_pid_tgid_tp(NULL);
|
103 | 148 | if (test__start_subtest("new_ns_tp"))
|
104 | 149 | test_ns_current_pid_tgid_new_ns(test_current_pid_tgid_tp, NULL);
|
| 150 | + if (test__start_subtest("new_ns_cgrp")) { |
| 151 | + int cgroup_fd = -1; |
| 152 | + |
| 153 | + cgroup_fd = test__join_cgroup("/sock_addr"); |
| 154 | + if (ASSERT_GE(cgroup_fd, 0, "join_cgroup")) { |
| 155 | + test_ns_current_pid_tgid_new_ns(test_current_pid_tgid_cgrp, &cgroup_fd); |
| 156 | + close(cgroup_fd); |
| 157 | + } |
| 158 | + } |
105 | 159 | }
|
0 commit comments