drm/atomic-helper: document drm_atomic_helper_check() restrictions
[drm/drm-misc.git] / tools / testing / selftests / net / forwarding / tc_tunnel_key.sh
blob79775b10b99f1e2d5a8c016ce4ae0333690cb889
1 #!/bin/bash
2 # SPDX-License-Identifier: GPL-2.0
4 ALL_TESTS="tunnel_key_nofrag_test"
6 NUM_NETIFS=4
7 source tc_common.sh
8 source lib.sh
10 tcflags="skip_hw"
12 h1_create()
14 simple_if_init $h1 192.0.2.1/24
15 forwarding_enable
16 mtu_set $h1 1500
17 tunnel_create h1-et vxlan 192.0.2.1 192.0.2.2 dev $h1 dstport 0 external
18 tc qdisc add dev h1-et clsact
19 mtu_set h1-et 1230
20 mtu_restore $h1
21 mtu_set $h1 1000
24 h1_destroy()
26 tc qdisc del dev h1-et clsact
27 tunnel_destroy h1-et
28 forwarding_restore
29 mtu_restore $h1
30 simple_if_fini $h1 192.0.2.1/24
33 h2_create()
35 simple_if_init $h2 192.0.2.2/24
38 h2_destroy()
40 simple_if_fini $h2 192.0.2.2/24
43 switch_create()
45 simple_if_init $swp1 192.0.2.2/24
46 tc qdisc add dev $swp1 clsact
47 simple_if_init $swp2 192.0.2.1/24
50 switch_destroy()
52 simple_if_fini $swp2 192.0.2.1/24
53 tc qdisc del dev $swp1 clsact
54 simple_if_fini $swp1 192.0.2.2/24
57 setup_prepare()
59 h1=${NETIFS[p1]}
60 swp1=${NETIFS[p2]}
62 swp2=${NETIFS[p3]}
63 h2=${NETIFS[p4]}
65 h1mac=$(mac_get $h1)
66 h2mac=$(mac_get $h2)
68 swp1origmac=$(mac_get $swp1)
69 swp2origmac=$(mac_get $swp2)
70 ip link set $swp1 address $h2mac
71 ip link set $swp2 address $h1mac
73 vrf_prepare
75 h1_create
76 h2_create
77 switch_create
79 if ! tc action add action tunnel_key help 2>&1 | grep -q nofrag; then
80 log_test "SKIP: iproute doesn't support nofrag"
81 exit $ksft_skip
85 cleanup()
87 pre_cleanup
89 switch_destroy
90 h2_destroy
91 h1_destroy
93 vrf_cleanup
95 ip link set $swp2 address $swp2origmac
96 ip link set $swp1 address $swp1origmac
99 tunnel_key_nofrag_test()
101 RET=0
102 local i
104 tc filter add dev $swp1 ingress protocol ip pref 100 handle 100 \
105 flower src_ip 192.0.2.1 dst_ip 192.0.2.2 ip_proto udp \
106 ip_flags nofrag action drop
107 tc filter add dev $swp1 ingress protocol ip pref 101 handle 101 \
108 flower src_ip 192.0.2.1 dst_ip 192.0.2.2 ip_proto udp \
109 ip_flags firstfrag action drop
110 tc filter add dev $swp1 ingress protocol ip pref 102 handle 102 \
111 flower src_ip 192.0.2.1 dst_ip 192.0.2.2 ip_proto udp \
112 ip_flags nofirstfrag action drop
114 # test 'nofrag' set
115 tc filter add dev h1-et egress protocol all pref 1 handle 1 matchall $tcflags \
116 action tunnel_key set src_ip 192.0.2.1 dst_ip 192.0.2.2 id 42 nofrag index 10
117 $MZ h1-et -c 1 -p 930 -a 00:aa:bb:cc:dd:ee -b 00:ee:dd:cc:bb:aa -t ip -q
118 tc_check_packets "dev $swp1 ingress" 100 1
119 check_err $? "packet smaller than MTU was not tunneled"
121 $MZ h1-et -c 1 -p 931 -a 00:aa:bb:cc:dd:ee -b 00:ee:dd:cc:bb:aa -t ip -q
122 tc_check_packets "dev $swp1 ingress" 100 1
123 check_err $? "packet bigger than MTU matched nofrag (nofrag was set)"
124 tc_check_packets "dev $swp1 ingress" 101 0
125 check_err $? "packet bigger than MTU matched firstfrag (nofrag was set)"
126 tc_check_packets "dev $swp1 ingress" 102 0
127 check_err $? "packet bigger than MTU matched nofirstfrag (nofrag was set)"
129 # test 'nofrag' cleared
130 tc actions change action tunnel_key set src_ip 192.0.2.1 dst_ip 192.0.2.2 id 42 index 10
131 $MZ h1-et -c 1 -p 931 -a 00:aa:bb:cc:dd:ee -b 00:ee:dd:cc:bb:aa -t ip -q
132 tc_check_packets "dev $swp1 ingress" 100 1
133 check_err $? "packet bigger than MTU matched nofrag (nofrag was unset)"
134 tc_check_packets "dev $swp1 ingress" 101 1
135 check_err $? "packet bigger than MTU didn't match firstfrag (nofrag was unset) "
136 tc_check_packets "dev $swp1 ingress" 102 1
137 check_err $? "packet bigger than MTU didn't match nofirstfrag (nofrag was unset) "
139 for i in 100 101 102; do
140 tc filter del dev $swp1 ingress protocol ip pref $i handle $i flower
141 done
142 tc filter del dev h1-et egress pref 1 handle 1 matchall
144 log_test "tunnel_key nofrag ($tcflags)"
147 trap cleanup EXIT
149 setup_prepare
150 setup_wait
152 tests_run
154 tc_offload_check
155 if [[ $? -ne 0 ]]; then
156 log_info "Could not test offloaded functionality"
157 else
158 tcflags="skip_sw"
159 tests_run
162 exit $EXIT_STATUS