aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--samples/bpf/test_cgrp2_attach2.c36
1 files changed, 24 insertions, 12 deletions
diff --git a/samples/bpf/test_cgrp2_attach2.c b/samples/bpf/test_cgrp2_attach2.c
index 3e8232cc04a8..1af412ec6007 100644
--- a/samples/bpf/test_cgrp2_attach2.c
+++ b/samples/bpf/test_cgrp2_attach2.c
@@ -78,7 +78,8 @@ static int test_foo_bar(void)
78 if (join_cgroup(FOO)) 78 if (join_cgroup(FOO))
79 goto err; 79 goto err;
80 80
81 if (bpf_prog_attach(drop_prog, foo, BPF_CGROUP_INET_EGRESS, 1)) { 81 if (bpf_prog_attach(drop_prog, foo, BPF_CGROUP_INET_EGRESS,
82 BPF_F_ALLOW_OVERRIDE)) {
82 log_err("Attaching prog to /foo"); 83 log_err("Attaching prog to /foo");
83 goto err; 84 goto err;
84 } 85 }
@@ -97,7 +98,8 @@ static int test_foo_bar(void)
97 printf("Attached DROP prog. This ping in cgroup /foo/bar should fail...\n"); 98 printf("Attached DROP prog. This ping in cgroup /foo/bar should fail...\n");
98 assert(system(PING_CMD) != 0); 99 assert(system(PING_CMD) != 0);
99 100
100 if (bpf_prog_attach(allow_prog, bar, BPF_CGROUP_INET_EGRESS, 1)) { 101 if (bpf_prog_attach(allow_prog, bar, BPF_CGROUP_INET_EGRESS,
102 BPF_F_ALLOW_OVERRIDE)) {
101 log_err("Attaching prog to /foo/bar"); 103 log_err("Attaching prog to /foo/bar");
102 goto err; 104 goto err;
103 } 105 }
@@ -114,7 +116,8 @@ static int test_foo_bar(void)
114 "This ping in cgroup /foo/bar should fail...\n"); 116 "This ping in cgroup /foo/bar should fail...\n");
115 assert(system(PING_CMD) != 0); 117 assert(system(PING_CMD) != 0);
116 118
117 if (bpf_prog_attach(allow_prog, bar, BPF_CGROUP_INET_EGRESS, 1)) { 119 if (bpf_prog_attach(allow_prog, bar, BPF_CGROUP_INET_EGRESS,
120 BPF_F_ALLOW_OVERRIDE)) {
118 log_err("Attaching prog to /foo/bar"); 121 log_err("Attaching prog to /foo/bar");
119 goto err; 122 goto err;
120 } 123 }
@@ -128,7 +131,8 @@ static int test_foo_bar(void)
128 "This ping in cgroup /foo/bar should pass...\n"); 131 "This ping in cgroup /foo/bar should pass...\n");
129 assert(system(PING_CMD) == 0); 132 assert(system(PING_CMD) == 0);
130 133
131 if (bpf_prog_attach(allow_prog, bar, BPF_CGROUP_INET_EGRESS, 1)) { 134 if (bpf_prog_attach(allow_prog, bar, BPF_CGROUP_INET_EGRESS,
135 BPF_F_ALLOW_OVERRIDE)) {
132 log_err("Attaching prog to /foo/bar"); 136 log_err("Attaching prog to /foo/bar");
133 goto err; 137 goto err;
134 } 138 }
@@ -161,13 +165,15 @@ static int test_foo_bar(void)
161 goto err; 165 goto err;
162 } 166 }
163 167
164 if (!bpf_prog_attach(allow_prog, bar, BPF_CGROUP_INET_EGRESS, 1)) { 168 if (!bpf_prog_attach(allow_prog, bar, BPF_CGROUP_INET_EGRESS,
169 BPF_F_ALLOW_OVERRIDE)) {
165 errno = 0; 170 errno = 0;
166 log_err("Unexpected success attaching overridable prog to /foo/bar"); 171 log_err("Unexpected success attaching overridable prog to /foo/bar");
167 goto err; 172 goto err;
168 } 173 }
169 174
170 if (!bpf_prog_attach(allow_prog, foo, BPF_CGROUP_INET_EGRESS, 1)) { 175 if (!bpf_prog_attach(allow_prog, foo, BPF_CGROUP_INET_EGRESS,
176 BPF_F_ALLOW_OVERRIDE)) {
171 errno = 0; 177 errno = 0;
172 log_err("Unexpected success attaching overridable prog to /foo"); 178 log_err("Unexpected success attaching overridable prog to /foo");
173 goto err; 179 goto err;
@@ -273,27 +279,33 @@ static int test_multiprog(void)
273 if (join_cgroup("/cg1/cg2/cg3/cg4/cg5")) 279 if (join_cgroup("/cg1/cg2/cg3/cg4/cg5"))
274 goto err; 280 goto err;
275 281
276 if (bpf_prog_attach(allow_prog[0], cg1, BPF_CGROUP_INET_EGRESS, 2)) { 282 if (bpf_prog_attach(allow_prog[0], cg1, BPF_CGROUP_INET_EGRESS,
283 BPF_F_ALLOW_MULTI)) {
277 log_err("Attaching prog to cg1"); 284 log_err("Attaching prog to cg1");
278 goto err; 285 goto err;
279 } 286 }
280 if (!bpf_prog_attach(allow_prog[0], cg1, BPF_CGROUP_INET_EGRESS, 2)) { 287 if (!bpf_prog_attach(allow_prog[0], cg1, BPF_CGROUP_INET_EGRESS,
288 BPF_F_ALLOW_MULTI)) {
281 log_err("Unexpected success attaching the same prog to cg1"); 289 log_err("Unexpected success attaching the same prog to cg1");
282 goto err; 290 goto err;
283 } 291 }
284 if (bpf_prog_attach(allow_prog[1], cg1, BPF_CGROUP_INET_EGRESS, 2)) { 292 if (bpf_prog_attach(allow_prog[1], cg1, BPF_CGROUP_INET_EGRESS,
293 BPF_F_ALLOW_MULTI)) {
285 log_err("Attaching prog2 to cg1"); 294 log_err("Attaching prog2 to cg1");
286 goto err; 295 goto err;
287 } 296 }
288 if (bpf_prog_attach(allow_prog[2], cg2, BPF_CGROUP_INET_EGRESS, 1)) { 297 if (bpf_prog_attach(allow_prog[2], cg2, BPF_CGROUP_INET_EGRESS,
298 BPF_F_ALLOW_OVERRIDE)) {
289 log_err("Attaching prog to cg2"); 299 log_err("Attaching prog to cg2");
290 goto err; 300 goto err;
291 } 301 }
292 if (bpf_prog_attach(allow_prog[3], cg3, BPF_CGROUP_INET_EGRESS, 2)) { 302 if (bpf_prog_attach(allow_prog[3], cg3, BPF_CGROUP_INET_EGRESS,
303 BPF_F_ALLOW_MULTI)) {
293 log_err("Attaching prog to cg3"); 304 log_err("Attaching prog to cg3");
294 goto err; 305 goto err;
295 } 306 }
296 if (bpf_prog_attach(allow_prog[4], cg4, BPF_CGROUP_INET_EGRESS, 1)) { 307 if (bpf_prog_attach(allow_prog[4], cg4, BPF_CGROUP_INET_EGRESS,
308 BPF_F_ALLOW_OVERRIDE)) {
297 log_err("Attaching prog to cg4"); 309 log_err("Attaching prog to cg4");
298 goto err; 310 goto err;
299 } 311 }