Skip to content

Commit c348227

Browse files
borkmannKernel Patches Daemon
authored and
Kernel Patches Daemon
committed
selftests/bpf: Add test for detachment on empty mprog entry
Add a detachment test case with miniq present to assert that with and without the miniq we get the same error. # ./test_progs -t tc_opts #244 tc_opts_after:OK #245 tc_opts_append:OK #246 tc_opts_basic:OK #247 tc_opts_before:OK #248 tc_opts_chain_classic:OK #249 tc_opts_delete_empty:OK #250 tc_opts_demixed:OK #251 tc_opts_detach:OK #252 tc_opts_detach_after:OK #253 tc_opts_detach_before:OK #254 tc_opts_dev_cleanup:OK #255 tc_opts_invalid:OK #256 tc_opts_mixed:OK #257 tc_opts_prepend:OK #258 tc_opts_replace:OK #259 tc_opts_revision:OK Summary: 16/0 PASSED, 0 SKIPPED, 0 FAILED Signed-off-by: Daniel Borkmann <[email protected]>
1 parent dd9dd27 commit c348227

File tree

1 file changed

+31
-0
lines changed
  • tools/testing/selftests/bpf/prog_tests

1 file changed

+31
-0
lines changed

tools/testing/selftests/bpf/prog_tests/tc_opts.c

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2237,3 +2237,34 @@ void serial_test_tc_opts_detach_after(void)
22372237
test_tc_opts_detach_after_target(BPF_TCX_INGRESS);
22382238
test_tc_opts_detach_after_target(BPF_TCX_EGRESS);
22392239
}
2240+
2241+
static void test_tc_opts_delete_empty(int target, bool chain_tc_old)
2242+
{
2243+
LIBBPF_OPTS(bpf_tc_hook, tc_hook, .ifindex = loopback);
2244+
LIBBPF_OPTS(bpf_prog_detach_opts, optd);
2245+
int err;
2246+
2247+
assert_mprog_count(target, 0);
2248+
if (chain_tc_old) {
2249+
tc_hook.attach_point = target == BPF_TCX_INGRESS ?
2250+
BPF_TC_INGRESS : BPF_TC_EGRESS;
2251+
err = bpf_tc_hook_create(&tc_hook);
2252+
ASSERT_OK(err, "bpf_tc_hook_create");
2253+
__assert_mprog_count(target, 0, true, loopback);
2254+
}
2255+
err = bpf_prog_detach_opts(0, loopback, target, &optd);
2256+
ASSERT_EQ(err, -ENOENT, "prog_detach");
2257+
if (chain_tc_old) {
2258+
tc_hook.attach_point = BPF_TC_INGRESS | BPF_TC_EGRESS;
2259+
bpf_tc_hook_destroy(&tc_hook);
2260+
}
2261+
assert_mprog_count(target, 0);
2262+
}
2263+
2264+
void serial_test_tc_opts_delete_empty(void)
2265+
{
2266+
test_tc_opts_delete_empty(BPF_TCX_INGRESS, false);
2267+
test_tc_opts_delete_empty(BPF_TCX_EGRESS, false);
2268+
test_tc_opts_delete_empty(BPF_TCX_INGRESS, true);
2269+
test_tc_opts_delete_empty(BPF_TCX_EGRESS, true);
2270+
}

0 commit comments

Comments
 (0)