Skip to content

Commit 51de082

Browse files
dsahernborkmann
authored andcommitted
samples/bpf: Convert magic numbers to names in multi-prog cgroup test case
Attach flag 1 == BPF_F_ALLOW_OVERRIDE; attach flag 2 == BPF_F_ALLOW_MULTI. Update the calls to bpf_prog_attach() in test_cgrp2_attach2.c to use the names over the magic numbers. Fixes: 39323e7 ("samples/bpf: add multi-prog cgroup test case") Signed-off-by: David Ahern <[email protected]> Signed-off-by: Daniel Borkmann <[email protected]>
1 parent 9f66816 commit 51de082

File tree

1 file changed

+24
-12
lines changed

1 file changed

+24
-12
lines changed

samples/bpf/test_cgrp2_attach2.c

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,8 @@ static int test_foo_bar(void)
7878
if (join_cgroup(FOO))
7979
goto err;
8080

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)) {
8283
log_err("Attaching prog to /foo");
8384
goto err;
8485
}
@@ -97,7 +98,8 @@ static int test_foo_bar(void)
9798
printf("Attached DROP prog. This ping in cgroup /foo/bar should fail...\n");
9899
assert(system(PING_CMD) != 0);
99100

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)) {
101103
log_err("Attaching prog to /foo/bar");
102104
goto err;
103105
}
@@ -114,7 +116,8 @@ static int test_foo_bar(void)
114116
"This ping in cgroup /foo/bar should fail...\n");
115117
assert(system(PING_CMD) != 0);
116118

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)) {
118121
log_err("Attaching prog to /foo/bar");
119122
goto err;
120123
}
@@ -128,7 +131,8 @@ static int test_foo_bar(void)
128131
"This ping in cgroup /foo/bar should pass...\n");
129132
assert(system(PING_CMD) == 0);
130133

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)) {
132136
log_err("Attaching prog to /foo/bar");
133137
goto err;
134138
}
@@ -161,13 +165,15 @@ static int test_foo_bar(void)
161165
goto err;
162166
}
163167

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)) {
165170
errno = 0;
166171
log_err("Unexpected success attaching overridable prog to /foo/bar");
167172
goto err;
168173
}
169174

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)) {
171177
errno = 0;
172178
log_err("Unexpected success attaching overridable prog to /foo");
173179
goto err;
@@ -273,27 +279,33 @@ static int test_multiprog(void)
273279
if (join_cgroup("/cg1/cg2/cg3/cg4/cg5"))
274280
goto err;
275281

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)) {
277284
log_err("Attaching prog to cg1");
278285
goto err;
279286
}
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)) {
281289
log_err("Unexpected success attaching the same prog to cg1");
282290
goto err;
283291
}
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)) {
285294
log_err("Attaching prog2 to cg1");
286295
goto err;
287296
}
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)) {
289299
log_err("Attaching prog to cg2");
290300
goto err;
291301
}
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)) {
293304
log_err("Attaching prog to cg3");
294305
goto err;
295306
}
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)) {
297309
log_err("Attaching prog to cg4");
298310
goto err;
299311
}

0 commit comments

Comments
 (0)