14
14
#include "netlink_helpers.h"
15
15
#include "tc_helpers.h"
16
16
17
- #define ICMP_ECHO 8
17
+ #define MARK 42
18
+ #define PRIO 0xeb9f
19
+ #define ICMP_ECHO 8
18
20
19
21
struct icmphdr {
20
22
__u8 type ;
@@ -33,7 +35,7 @@ struct iplink_req {
33
35
};
34
36
35
37
static int create_netkit (int mode , int policy , int peer_policy , int * ifindex ,
36
- bool same_netns )
38
+ bool same_netns , int scrub , int peer_scrub )
37
39
{
38
40
struct rtnl_handle rth = { .fd = -1 };
39
41
struct iplink_req req = {};
@@ -58,6 +60,8 @@ static int create_netkit(int mode, int policy, int peer_policy, int *ifindex,
58
60
data = addattr_nest (& req .n , sizeof (req ), IFLA_INFO_DATA );
59
61
addattr32 (& req .n , sizeof (req ), IFLA_NETKIT_POLICY , policy );
60
62
addattr32 (& req .n , sizeof (req ), IFLA_NETKIT_PEER_POLICY , peer_policy );
63
+ addattr32 (& req .n , sizeof (req ), IFLA_NETKIT_SCRUB , scrub );
64
+ addattr32 (& req .n , sizeof (req ), IFLA_NETKIT_PEER_SCRUB , peer_scrub );
61
65
addattr32 (& req .n , sizeof (req ), IFLA_NETKIT_MODE , mode );
62
66
addattr_nest_end (& req .n , data );
63
67
addattr_nest_end (& req .n , linkinfo );
@@ -118,9 +122,9 @@ static void destroy_netkit(void)
118
122
119
123
static int __send_icmp (__u32 dest )
120
124
{
125
+ int sock , ret , mark = MARK , prio = PRIO ;
121
126
struct sockaddr_in addr ;
122
127
struct icmphdr icmp ;
123
- int sock , ret ;
124
128
125
129
ret = write_sysctl ("/proc/sys/net/ipv4/ping_group_range" , "0 0" );
126
130
if (!ASSERT_OK (ret , "write_sysctl(net.ipv4.ping_group_range)" ))
@@ -135,6 +139,15 @@ static int __send_icmp(__u32 dest)
135
139
if (!ASSERT_OK (ret , "setsockopt(SO_BINDTODEVICE)" ))
136
140
goto out ;
137
141
142
+ ret = setsockopt (sock , SOL_SOCKET , SO_MARK , & mark , sizeof (mark ));
143
+ if (!ASSERT_OK (ret , "setsockopt(SO_MARK)" ))
144
+ goto out ;
145
+
146
+ ret = setsockopt (sock , SOL_SOCKET , SO_PRIORITY ,
147
+ & prio , sizeof (prio ));
148
+ if (!ASSERT_OK (ret , "setsockopt(SO_PRIORITY)" ))
149
+ goto out ;
150
+
138
151
memset (& addr , 0 , sizeof (addr ));
139
152
addr .sin_family = AF_INET ;
140
153
addr .sin_addr .s_addr = htonl (dest );
@@ -171,7 +184,8 @@ void serial_test_tc_netkit_basic(void)
171
184
int err , ifindex ;
172
185
173
186
err = create_netkit (NETKIT_L2 , NETKIT_PASS , NETKIT_PASS ,
174
- & ifindex , false);
187
+ & ifindex , false, NETKIT_SCRUB_DEFAULT ,
188
+ NETKIT_SCRUB_DEFAULT );
175
189
if (err )
176
190
return ;
177
191
@@ -285,7 +299,8 @@ static void serial_test_tc_netkit_multi_links_target(int mode, int target)
285
299
int err , ifindex ;
286
300
287
301
err = create_netkit (mode , NETKIT_PASS , NETKIT_PASS ,
288
- & ifindex , false);
302
+ & ifindex , false, NETKIT_SCRUB_DEFAULT ,
303
+ NETKIT_SCRUB_DEFAULT );
289
304
if (err )
290
305
return ;
291
306
@@ -413,7 +428,8 @@ static void serial_test_tc_netkit_multi_opts_target(int mode, int target)
413
428
int err , ifindex ;
414
429
415
430
err = create_netkit (mode , NETKIT_PASS , NETKIT_PASS ,
416
- & ifindex , false);
431
+ & ifindex , false, NETKIT_SCRUB_DEFAULT ,
432
+ NETKIT_SCRUB_DEFAULT );
417
433
if (err )
418
434
return ;
419
435
@@ -527,7 +543,8 @@ void serial_test_tc_netkit_device(void)
527
543
int err , ifindex , ifindex2 ;
528
544
529
545
err = create_netkit (NETKIT_L3 , NETKIT_PASS , NETKIT_PASS ,
530
- & ifindex , true);
546
+ & ifindex , true, NETKIT_SCRUB_DEFAULT ,
547
+ NETKIT_SCRUB_DEFAULT );
531
548
if (err )
532
549
return ;
533
550
@@ -638,7 +655,8 @@ static void serial_test_tc_netkit_neigh_links_target(int mode, int target)
638
655
int err , ifindex ;
639
656
640
657
err = create_netkit (mode , NETKIT_PASS , NETKIT_PASS ,
641
- & ifindex , false);
658
+ & ifindex , false, NETKIT_SCRUB_DEFAULT ,
659
+ NETKIT_SCRUB_DEFAULT );
642
660
if (err )
643
661
return ;
644
662
@@ -715,7 +733,8 @@ static void serial_test_tc_netkit_pkt_type_mode(int mode)
715
733
struct bpf_link * link ;
716
734
717
735
err = create_netkit (mode , NETKIT_PASS , NETKIT_PASS ,
718
- & ifindex , true);
736
+ & ifindex , true, NETKIT_SCRUB_DEFAULT ,
737
+ NETKIT_SCRUB_DEFAULT );
719
738
if (err )
720
739
return ;
721
740
@@ -779,3 +798,60 @@ void serial_test_tc_netkit_pkt_type(void)
779
798
serial_test_tc_netkit_pkt_type_mode (NETKIT_L2 );
780
799
serial_test_tc_netkit_pkt_type_mode (NETKIT_L3 );
781
800
}
801
+
802
+ void serial_test_tc_netkit_scrub_type (int scrub )
803
+ {
804
+ LIBBPF_OPTS (bpf_netkit_opts , optl );
805
+ struct test_tc_link * skel ;
806
+ struct bpf_link * link ;
807
+ int err , ifindex ;
808
+
809
+ err = create_netkit (NETKIT_L2 , NETKIT_PASS , NETKIT_PASS ,
810
+ & ifindex , false, scrub , scrub );
811
+ if (err )
812
+ return ;
813
+
814
+ skel = test_tc_link__open ();
815
+ if (!ASSERT_OK_PTR (skel , "skel_open" ))
816
+ goto cleanup ;
817
+
818
+ ASSERT_EQ (bpf_program__set_expected_attach_type (skel -> progs .tc8 ,
819
+ BPF_NETKIT_PRIMARY ), 0 , "tc8_attach_type" );
820
+
821
+ err = test_tc_link__load (skel );
822
+ if (!ASSERT_OK (err , "skel_load" ))
823
+ goto cleanup ;
824
+
825
+ assert_mprog_count_ifindex (ifindex , BPF_NETKIT_PRIMARY , 0 );
826
+ assert_mprog_count_ifindex (ifindex , BPF_NETKIT_PEER , 0 );
827
+
828
+ ASSERT_EQ (skel -> bss -> seen_tc8 , false, "seen_tc8" );
829
+
830
+ link = bpf_program__attach_netkit (skel -> progs .tc8 , ifindex , & optl );
831
+ if (!ASSERT_OK_PTR (link , "link_attach" ))
832
+ goto cleanup ;
833
+
834
+ skel -> links .tc8 = link ;
835
+
836
+ assert_mprog_count_ifindex (ifindex , BPF_NETKIT_PRIMARY , 1 );
837
+ assert_mprog_count_ifindex (ifindex , BPF_NETKIT_PEER , 0 );
838
+
839
+ tc_skel_reset_all_seen (skel );
840
+ ASSERT_EQ (send_icmp (), 0 , "icmp_pkt" );
841
+
842
+ ASSERT_EQ (skel -> bss -> seen_tc8 , true, "seen_tc8" );
843
+ ASSERT_EQ (skel -> bss -> mark , scrub == NETKIT_SCRUB_NONE ? MARK : 0 , "mark" );
844
+ ASSERT_EQ (skel -> bss -> prio , scrub == NETKIT_SCRUB_NONE ? PRIO : 0 , "prio" );
845
+ cleanup :
846
+ test_tc_link__destroy (skel );
847
+
848
+ assert_mprog_count_ifindex (ifindex , BPF_NETKIT_PRIMARY , 0 );
849
+ assert_mprog_count_ifindex (ifindex , BPF_NETKIT_PEER , 0 );
850
+ destroy_netkit ();
851
+ }
852
+
853
+ void serial_test_tc_netkit_scrub (void )
854
+ {
855
+ serial_test_tc_netkit_scrub_type (NETKIT_SCRUB_DEFAULT );
856
+ serial_test_tc_netkit_scrub_type (NETKIT_SCRUB_NONE );
857
+ }
0 commit comments