Linux kernel mirror (for testing)
git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel
os
linux
1#!/bin/bash
2# SPDX-License-Identifier: GPL-2.0
3# Kselftest framework requirement - SKIP code is 4.
4ksft_skip=4
5
6ALL_TESTS="tunnel_key_nofrag_test"
7
8NUM_NETIFS=4
9source tc_common.sh
10source lib.sh
11
12tcflags="skip_hw"
13
14h1_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
26h1_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
35h2_create()
36{
37 simple_if_init $h2 192.0.2.2/24
38}
39
40h2_destroy()
41{
42 simple_if_fini $h2 192.0.2.2/24
43}
44
45switch_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
52switch_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
59setup_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
87cleanup()
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
101tunnel_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 src_ip 192.0.2.1 dst_ip 192.0.2.2 ip_proto udp \
108 ip_flags nofrag action drop
109 tc filter add dev $swp1 ingress protocol ip pref 101 handle 101 \
110 flower src_ip 192.0.2.1 dst_ip 192.0.2.2 ip_proto udp \
111 ip_flags firstfrag action drop
112 tc filter add dev $swp1 ingress protocol ip pref 102 handle 102 \
113 flower src_ip 192.0.2.1 dst_ip 192.0.2.2 ip_proto udp \
114 ip_flags nofirstfrag action drop
115
116 # test 'nofrag' set
117 tc filter add dev h1-et egress protocol all pref 1 handle 1 matchall $tcflags \
118 action tunnel_key set src_ip 192.0.2.1 dst_ip 192.0.2.2 id 42 nofrag index 10
119 $MZ h1-et -c 1 -p 930 -a 00:aa:bb:cc:dd:ee -b 00:ee:dd:cc:bb:aa -t ip -q
120 tc_check_packets "dev $swp1 ingress" 100 1
121 check_err $? "packet smaller than MTU was not tunneled"
122
123 $MZ h1-et -c 1 -p 931 -a 00:aa:bb:cc:dd:ee -b 00:ee:dd:cc:bb:aa -t ip -q
124 tc_check_packets "dev $swp1 ingress" 100 1
125 check_err $? "packet bigger than MTU matched nofrag (nofrag was set)"
126 tc_check_packets "dev $swp1 ingress" 101 0
127 check_err $? "packet bigger than MTU matched firstfrag (nofrag was set)"
128 tc_check_packets "dev $swp1 ingress" 102 0
129 check_err $? "packet bigger than MTU matched nofirstfrag (nofrag was set)"
130
131 # test 'nofrag' cleared
132 tc actions change action tunnel_key set src_ip 192.0.2.1 dst_ip 192.0.2.2 id 42 index 10
133 $MZ h1-et -c 1 -p 931 -a 00:aa:bb:cc:dd:ee -b 00:ee:dd:cc:bb:aa -t ip -q
134 tc_check_packets "dev $swp1 ingress" 100 1
135 check_err $? "packet bigger than MTU matched nofrag (nofrag was unset)"
136 tc_check_packets "dev $swp1 ingress" 101 1
137 check_err $? "packet bigger than MTU didn't match firstfrag (nofrag was unset) "
138 tc_check_packets "dev $swp1 ingress" 102 1
139 check_err $? "packet bigger than MTU didn't match nofirstfrag (nofrag was unset) "
140
141 for i in 100 101 102; do
142 tc filter del dev $swp1 ingress protocol ip pref $i handle $i flower
143 done
144 tc filter del dev h1-et egress pref 1 handle 1 matchall
145
146 log_test "tunnel_key nofrag ($tcflags)"
147}
148
149trap cleanup EXIT
150
151setup_prepare
152setup_wait
153
154tests_run
155
156tc_offload_check
157if [[ $? -ne 0 ]]; then
158 log_info "Could not test offloaded functionality"
159else
160 tcflags="skip_sw"
161 tests_run
162fi
163
164exit $EXIT_STATUS