@@ -99,6 +99,16 @@ static int create_netkit(int mode, int policy, int peer_policy, int *ifindex,
9999 return err ;
100100}
101101
102+ static void move_netkit (void )
103+ {
104+ ASSERT_OK (system ("ip link set " netkit_peer " netns foo" ),
105+ "move peer" );
106+ ASSERT_OK (system ("ip netns exec foo ip link set dev "
107+ netkit_peer " up" ), "up peer" );
108+ ASSERT_OK (system ("ip netns exec foo ip addr add dev "
109+ netkit_peer " 10.0.0.2/24" ), "addr peer" );
110+ }
111+
102112static void destroy_netkit (void )
103113{
104114 ASSERT_OK (system ("ip link del dev " netkit_name ), "del primary" );
@@ -695,3 +705,77 @@ void serial_test_tc_netkit_neigh_links(void)
695705 serial_test_tc_netkit_neigh_links_target (NETKIT_L2 , BPF_NETKIT_PRIMARY );
696706 serial_test_tc_netkit_neigh_links_target (NETKIT_L3 , BPF_NETKIT_PRIMARY );
697707}
708+
709+ static void serial_test_tc_netkit_pkt_type_mode (int mode )
710+ {
711+ LIBBPF_OPTS (bpf_netkit_opts , optl_nk );
712+ LIBBPF_OPTS (bpf_tcx_opts , optl_tcx );
713+ int err , ifindex , ifindex2 ;
714+ struct test_tc_link * skel ;
715+ struct bpf_link * link ;
716+
717+ err = create_netkit (mode , NETKIT_PASS , NETKIT_PASS ,
718+ & ifindex , true);
719+ if (err )
720+ return ;
721+
722+ ifindex2 = if_nametoindex (netkit_peer );
723+ ASSERT_NEQ (ifindex , ifindex2 , "ifindex_1_2" );
724+
725+ skel = test_tc_link__open ();
726+ if (!ASSERT_OK_PTR (skel , "skel_open" ))
727+ goto cleanup ;
728+
729+ ASSERT_EQ (bpf_program__set_expected_attach_type (skel -> progs .tc1 ,
730+ BPF_NETKIT_PRIMARY ), 0 , "tc1_attach_type" );
731+ ASSERT_EQ (bpf_program__set_expected_attach_type (skel -> progs .tc7 ,
732+ BPF_TCX_INGRESS ), 0 , "tc7_attach_type" );
733+
734+ err = test_tc_link__load (skel );
735+ if (!ASSERT_OK (err , "skel_load" ))
736+ goto cleanup ;
737+
738+ assert_mprog_count_ifindex (ifindex , BPF_NETKIT_PRIMARY , 0 );
739+ assert_mprog_count_ifindex (ifindex2 , BPF_TCX_INGRESS , 0 );
740+
741+ link = bpf_program__attach_netkit (skel -> progs .tc1 , ifindex , & optl_nk );
742+ if (!ASSERT_OK_PTR (link , "link_attach" ))
743+ goto cleanup ;
744+
745+ skel -> links .tc1 = link ;
746+
747+ assert_mprog_count_ifindex (ifindex , BPF_NETKIT_PRIMARY , 1 );
748+ assert_mprog_count_ifindex (ifindex2 , BPF_TCX_INGRESS , 0 );
749+
750+ link = bpf_program__attach_tcx (skel -> progs .tc7 , ifindex2 , & optl_tcx );
751+ if (!ASSERT_OK_PTR (link , "link_attach" ))
752+ goto cleanup ;
753+
754+ skel -> links .tc7 = link ;
755+
756+ assert_mprog_count_ifindex (ifindex , BPF_NETKIT_PRIMARY , 1 );
757+ assert_mprog_count_ifindex (ifindex2 , BPF_TCX_INGRESS , 1 );
758+
759+ move_netkit ();
760+
761+ tc_skel_reset_all_seen (skel );
762+ skel -> bss -> set_type = true;
763+ ASSERT_EQ (send_icmp (), 0 , "icmp_pkt" );
764+
765+ ASSERT_EQ (skel -> bss -> seen_tc1 , true, "seen_tc1" );
766+ ASSERT_EQ (skel -> bss -> seen_tc7 , true, "seen_tc7" );
767+
768+ ASSERT_EQ (skel -> bss -> seen_host , true, "seen_host" );
769+ ASSERT_EQ (skel -> bss -> seen_mcast , true, "seen_mcast" );
770+ cleanup :
771+ test_tc_link__destroy (skel );
772+
773+ assert_mprog_count_ifindex (ifindex , BPF_NETKIT_PRIMARY , 0 );
774+ destroy_netkit ();
775+ }
776+
777+ void serial_test_tc_netkit_pkt_type (void )
778+ {
779+ serial_test_tc_netkit_pkt_type_mode (NETKIT_L2 );
780+ serial_test_tc_netkit_pkt_type_mode (NETKIT_L3 );
781+ }
0 commit comments