@@ -2237,3 +2237,34 @@ void serial_test_tc_opts_detach_after(void)
2237
2237
test_tc_opts_detach_after_target (BPF_TCX_INGRESS );
2238
2238
test_tc_opts_detach_after_target (BPF_TCX_EGRESS );
2239
2239
}
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