drm/nouveau: fence: fix undefined fence state after emit
[platform/kernel/linux-rpi.git] / tools / testing / selftests / net / forwarding / tc_tunnel_key.sh
1 #!/bin/bash
2 # SPDX-License-Identifier: GPL-2.0
3 # Kselftest framework requirement - SKIP code is 4.
4 ksft_skip=4
5
6 ALL_TESTS="tunnel_key_nofrag_test"
7
8 NUM_NETIFS=4
9 source tc_common.sh
10 source lib.sh
11
12 tcflags="skip_hw"
13
14 h1_create()
15 {
16         simple_if_init $h1 192.0.2.1/24
17         forwarding_enable
18         mtu_set $h1 1500
19         tunnel_create h1-et vxlan 192.0.2.1 192.0.2.2 dev $h1 dstport 0 external
20         tc qdisc add dev h1-et clsact
21         mtu_set h1-et 1230
22         mtu_restore $h1
23         mtu_set $h1 1000
24 }
25
26 h1_destroy()
27 {
28         tc qdisc del dev h1-et clsact
29         tunnel_destroy h1-et
30         forwarding_restore
31         mtu_restore $h1
32         simple_if_fini $h1 192.0.2.1/24
33 }
34
35 h2_create()
36 {
37         simple_if_init $h2 192.0.2.2/24
38 }
39
40 h2_destroy()
41 {
42         simple_if_fini $h2 192.0.2.2/24
43 }
44
45 switch_create()
46 {
47         simple_if_init $swp1 192.0.2.2/24
48         tc qdisc add dev $swp1 clsact
49         simple_if_init $swp2 192.0.2.1/24
50 }
51
52 switch_destroy()
53 {
54         simple_if_fini $swp2 192.0.2.1/24
55         tc qdisc del dev $swp1 clsact
56         simple_if_fini $swp1 192.0.2.2/24
57 }
58
59 setup_prepare()
60 {
61         h1=${NETIFS[p1]}
62         swp1=${NETIFS[p2]}
63
64         swp2=${NETIFS[p3]}
65         h2=${NETIFS[p4]}
66
67         h1mac=$(mac_get $h1)
68         h2mac=$(mac_get $h2)
69
70         swp1origmac=$(mac_get $swp1)
71         swp2origmac=$(mac_get $swp2)
72         ip link set $swp1 address $h2mac
73         ip link set $swp2 address $h1mac
74
75         vrf_prepare
76
77         h1_create
78         h2_create
79         switch_create
80
81         if ! tc action add action tunnel_key help 2>&1 | grep -q nofrag; then
82                 log_test "SKIP: iproute doesn't support nofrag"
83                 exit $ksft_skip
84         fi
85 }
86
87 cleanup()
88 {
89         pre_cleanup
90
91         switch_destroy
92         h2_destroy
93         h1_destroy
94
95         vrf_cleanup
96
97         ip link set $swp2 address $swp2origmac
98         ip link set $swp1 address $swp1origmac
99 }
100
101 tunnel_key_nofrag_test()
102 {
103         RET=0
104         local i
105
106         tc filter add dev $swp1 ingress protocol ip pref 100 handle 100 \
107                 flower ip_flags nofrag action drop
108         tc filter add dev $swp1 ingress protocol ip pref 101 handle 101 \
109                 flower ip_flags firstfrag action drop
110         tc filter add dev $swp1 ingress protocol ip pref 102 handle 102 \
111                 flower ip_flags nofirstfrag action drop
112
113         # test 'nofrag' set
114         tc filter add dev h1-et egress protocol all pref 1 handle 1 matchall $tcflags \
115                 action tunnel_key set src_ip 192.0.2.1 dst_ip 192.0.2.2 id 42 nofrag index 10
116         $MZ h1-et -c 1 -p 930 -a 00:aa:bb:cc:dd:ee -b 00:ee:dd:cc:bb:aa -t ip -q
117         tc_check_packets "dev $swp1 ingress" 100 1
118         check_err $? "packet smaller than MTU was not tunneled"
119
120         $MZ h1-et -c 1 -p 931 -a 00:aa:bb:cc:dd:ee -b 00:ee:dd:cc:bb:aa -t ip -q
121         tc_check_packets "dev $swp1 ingress" 100 1
122         check_err $? "packet bigger than MTU matched nofrag (nofrag was set)"
123         tc_check_packets "dev $swp1 ingress" 101 0
124         check_err $? "packet bigger than MTU matched firstfrag (nofrag was set)"
125         tc_check_packets "dev $swp1 ingress" 102 0
126         check_err $? "packet bigger than MTU matched nofirstfrag (nofrag was set)"
127
128         # test 'nofrag' cleared
129         tc actions change action tunnel_key set src_ip 192.0.2.1 dst_ip 192.0.2.2 id 42 index 10
130         $MZ h1-et -c 1 -p 931 -a 00:aa:bb:cc:dd:ee -b 00:ee:dd:cc:bb:aa -t ip -q
131         tc_check_packets "dev $swp1  ingress" 100 1
132         check_err $? "packet bigger than MTU matched nofrag (nofrag was unset)"
133         tc_check_packets "dev $swp1  ingress" 101 1
134         check_err $? "packet bigger than MTU didn't match firstfrag (nofrag was unset) "
135         tc_check_packets "dev $swp1 ingress" 102 1
136         check_err $? "packet bigger than MTU didn't match nofirstfrag (nofrag was unset) "
137
138         for i in 100 101 102; do
139                 tc filter del dev $swp1 ingress protocol ip pref $i handle $i flower
140         done
141         tc filter del dev h1-et egress pref 1 handle 1 matchall
142
143         log_test "tunnel_key nofrag ($tcflags)"
144 }
145
146 trap cleanup EXIT
147
148 setup_prepare
149 setup_wait
150
151 tests_run
152
153 tc_offload_check
154 if [[ $? -ne 0 ]]; then
155         log_info "Could not test offloaded functionality"
156 else
157         tcflags="skip_sw"
158         tests_run
159 fi
160
161 exit $EXIT_STATUS