@@ -2629,3 +2629,62 @@ void serial_test_tc_opts_query(void)
2629
2629
test_tc_opts_query_target (BPF_TCX_INGRESS );
2630
2630
test_tc_opts_query_target (BPF_TCX_EGRESS );
2631
2631
}
2632
+
2633
+ static void test_tc_opts_query_attach_target (int target )
2634
+ {
2635
+ LIBBPF_OPTS (bpf_prog_attach_opts , opta );
2636
+ LIBBPF_OPTS (bpf_prog_detach_opts , optd );
2637
+ LIBBPF_OPTS (bpf_prog_query_opts , optq );
2638
+ struct test_tc_link * skel ;
2639
+ __u32 prog_ids [2 ];
2640
+ __u32 fd1 , id1 ;
2641
+ int err ;
2642
+
2643
+ skel = test_tc_link__open_and_load ();
2644
+ if (!ASSERT_OK_PTR (skel , "skel_load" ))
2645
+ goto cleanup ;
2646
+
2647
+ fd1 = bpf_program__fd (skel -> progs .tc1 );
2648
+ id1 = id_from_prog_fd (fd1 );
2649
+
2650
+ err = bpf_prog_query_opts (loopback , target , & optq );
2651
+ if (!ASSERT_OK (err , "prog_query" ))
2652
+ goto cleanup ;
2653
+
2654
+ ASSERT_EQ (optq .count , 0 , "count" );
2655
+ ASSERT_EQ (optq .revision , 1 , "revision" );
2656
+
2657
+ LIBBPF_OPTS_RESET (opta ,
2658
+ .expected_revision = optq .revision ,
2659
+ );
2660
+
2661
+ err = bpf_prog_attach_opts (fd1 , loopback , target , & opta );
2662
+ if (!ASSERT_EQ (err , 0 , "prog_attach" ))
2663
+ goto cleanup ;
2664
+
2665
+ memset (prog_ids , 0 , sizeof (prog_ids ));
2666
+ optq .prog_ids = prog_ids ;
2667
+ optq .count = ARRAY_SIZE (prog_ids );
2668
+
2669
+ err = bpf_prog_query_opts (loopback , target , & optq );
2670
+ if (!ASSERT_OK (err , "prog_query" ))
2671
+ goto cleanup1 ;
2672
+
2673
+ ASSERT_EQ (optq .count , 1 , "count" );
2674
+ ASSERT_EQ (optq .revision , 2 , "revision" );
2675
+ ASSERT_EQ (optq .prog_ids [0 ], id1 , "prog_ids[0]" );
2676
+ ASSERT_EQ (optq .prog_ids [1 ], 0 , "prog_ids[1]" );
2677
+
2678
+ cleanup1 :
2679
+ err = bpf_prog_detach_opts (fd1 , loopback , target , & optd );
2680
+ ASSERT_OK (err , "prog_detach" );
2681
+ assert_mprog_count (target , 0 );
2682
+ cleanup :
2683
+ test_tc_link__destroy (skel );
2684
+ }
2685
+
2686
+ void serial_test_tc_opts_query_attach (void )
2687
+ {
2688
+ test_tc_opts_query_attach_target (BPF_TCX_INGRESS );
2689
+ test_tc_opts_query_attach_target (BPF_TCX_EGRESS );
2690
+ }
0 commit comments