@@ -108,6 +108,16 @@ static int create_netkit(int mode, int policy, int peer_policy, int *ifindex,
108108 return err ;
109109}
110110
111+ static void move_netkit (void )
112+ {
113+ ASSERT_OK (system ("ip link set " netkit_peer " netns foo" ),
114+ "move peer" );
115+ ASSERT_OK (system ("ip netns exec foo ip link set dev "
116+ netkit_peer " up" ), "up peer" );
117+ ASSERT_OK (system ("ip netns exec foo ip addr add dev "
118+ netkit_peer " 10.0.0.2/24" ), "addr peer" );
119+ }
120+
111121static void destroy_netkit (void )
112122{
113123 ASSERT_OK (system ("ip link del dev " netkit_name ), "del primary" );
@@ -704,3 +714,77 @@ void serial_test_tc_netkit_neigh_links(void)
704714 serial_test_tc_netkit_neigh_links_target (NETKIT_L2 , BPF_NETKIT_PRIMARY );
705715 serial_test_tc_netkit_neigh_links_target (NETKIT_L3 , BPF_NETKIT_PRIMARY );
706716}
717+
718+ static void serial_test_tc_netkit_pkt_type_mode (int mode )
719+ {
720+ LIBBPF_OPTS (bpf_netkit_opts , optl_nk );
721+ LIBBPF_OPTS (bpf_tcx_opts , optl_tcx );
722+ int err , ifindex , ifindex2 ;
723+ struct test_tc_link * skel ;
724+ struct bpf_link * link ;
725+
726+ err = create_netkit (mode , NETKIT_PASS , NETKIT_PASS ,
727+ & ifindex , true);
728+ if (err )
729+ return ;
730+
731+ ifindex2 = if_nametoindex (netkit_peer );
732+ ASSERT_NEQ (ifindex , ifindex2 , "ifindex_1_2" );
733+
734+ skel = test_tc_link__open ();
735+ if (!ASSERT_OK_PTR (skel , "skel_open" ))
736+ goto cleanup ;
737+
738+ ASSERT_EQ (bpf_program__set_expected_attach_type (skel -> progs .tc1 ,
739+ BPF_NETKIT_PRIMARY ), 0 , "tc1_attach_type" );
740+ ASSERT_EQ (bpf_program__set_expected_attach_type (skel -> progs .tc7 ,
741+ BPF_TCX_INGRESS ), 0 , "tc7_attach_type" );
742+
743+ err = test_tc_link__load (skel );
744+ if (!ASSERT_OK (err , "skel_load" ))
745+ goto cleanup ;
746+
747+ assert_mprog_count_ifindex (ifindex , BPF_NETKIT_PRIMARY , 0 );
748+ assert_mprog_count_ifindex (ifindex2 , BPF_TCX_INGRESS , 0 );
749+
750+ link = bpf_program__attach_netkit (skel -> progs .tc1 , ifindex , & optl_nk );
751+ if (!ASSERT_OK_PTR (link , "link_attach" ))
752+ goto cleanup ;
753+
754+ skel -> links .tc1 = link ;
755+
756+ assert_mprog_count_ifindex (ifindex , BPF_NETKIT_PRIMARY , 1 );
757+ assert_mprog_count_ifindex (ifindex2 , BPF_TCX_INGRESS , 0 );
758+
759+ link = bpf_program__attach_tcx (skel -> progs .tc7 , ifindex2 , & optl_tcx );
760+ if (!ASSERT_OK_PTR (link , "link_attach" ))
761+ goto cleanup ;
762+
763+ skel -> links .tc7 = link ;
764+
765+ assert_mprog_count_ifindex (ifindex , BPF_NETKIT_PRIMARY , 1 );
766+ assert_mprog_count_ifindex (ifindex2 , BPF_TCX_INGRESS , 1 );
767+
768+ move_netkit ();
769+
770+ tc_skel_reset_all_seen (skel );
771+ skel -> bss -> set_type = true;
772+ ASSERT_EQ (send_icmp (), 0 , "icmp_pkt" );
773+
774+ ASSERT_EQ (skel -> bss -> seen_tc1 , true, "seen_tc1" );
775+ ASSERT_EQ (skel -> bss -> seen_tc7 , true, "seen_tc7" );
776+
777+ ASSERT_EQ (skel -> bss -> seen_host , true, "seen_host" );
778+ ASSERT_EQ (skel -> bss -> seen_mcast , true, "seen_mcast" );
779+ cleanup :
780+ test_tc_link__destroy (skel );
781+
782+ assert_mprog_count_ifindex (ifindex , BPF_NETKIT_PRIMARY , 0 );
783+ destroy_netkit ();
784+ }
785+
786+ void serial_test_tc_netkit_pkt_type (void )
787+ {
788+ serial_test_tc_netkit_pkt_type_mode (NETKIT_L2 );
789+ serial_test_tc_netkit_pkt_type_mode (NETKIT_L3 );
790+ }
0 commit comments