Skip to content

Commit 36ee728

Browse files
committed
Merge branch 'ip6gre-tests'
Ido Schimmel says: ==================== selftests: forwarding: Add ip6gre tests This patchset adds forwarding selftests for ip6gre. The tests can be run with veth pairs or with physical loopbacks. Patch #1 adds a new config option to determine if 'skip_sw' / 'skip_hw' flags are used when installing tc filters. By default, it is not set which means the flags are not used. 'skip_sw' is useful to ensure traffic is forwarded by the hardware data path. Patch #2 adds a new helper function. Patches #3-#4 add the forwarding selftests. Patch #5 adds a mlxsw-specific selftest to validate correct behavior of the 'decap_error' trap with IPv6 underlay. Patches #6-#8 align the corresponding IPv4 underlay test to the IPv6 one. ==================== Signed-off-by: David S. Miller <[email protected]>
2 parents 4c1e34c + 7f63cdd commit 36ee728

File tree

11 files changed

+1109
-32
lines changed

11 files changed

+1109
-32
lines changed

tools/testing/selftests/drivers/net/mlxsw/devlink_trap_tunnel_ipip.sh

Lines changed: 18 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
# |
1414
# +-------------------|-----+
1515
# | SW1 | |
16-
# | $swp1 + |
16+
# | $swp1 + |
1717
# | 192.0.2.2/28 |
1818
# | |
1919
# | + g1a (gre) |
@@ -27,8 +27,8 @@
2727
# |
2828
# +--|----------------------+
2929
# | | VRF2 |
30-
# | + $rp2 |
31-
# | 198.51.100.2/28 |
30+
# | + $rp2 |
31+
# | 198.51.100.2/28 |
3232
# +-------------------------+
3333

3434
lib_dir=$(dirname $0)/../../../net/forwarding
@@ -116,12 +116,16 @@ cleanup()
116116
forwarding_restore
117117
}
118118

119-
ecn_payload_get()
119+
ipip_payload_get()
120120
{
121+
local flags=$1; shift
122+
local key=$1; shift
123+
121124
p=$(:
122-
)"0"$( : GRE flags
125+
)"$flags"$( : GRE flags
123126
)"0:00:"$( : Reserved + version
124127
)"08:00:"$( : ETH protocol type
128+
)"$key"$( : Key
125129
)"4"$( : IP version
126130
)"5:"$( : IHL
127131
)"00:"$( : IP TOS
@@ -137,6 +141,11 @@ ecn_payload_get()
137141
echo $p
138142
}
139143

144+
ecn_payload_get()
145+
{
146+
echo $(ipip_payload_get "0")
147+
}
148+
140149
ecn_decap_test()
141150
{
142151
local trap_name="decap_error"
@@ -171,31 +180,6 @@ ecn_decap_test()
171180
tc filter del dev $swp1 egress protocol ip pref 1 handle 101 flower
172181
}
173182

174-
ipip_payload_get()
175-
{
176-
local flags=$1; shift
177-
local key=$1; shift
178-
179-
p=$(:
180-
)"$flags"$( : GRE flags
181-
)"0:00:"$( : Reserved + version
182-
)"08:00:"$( : ETH protocol type
183-
)"$key"$( : Key
184-
)"4"$( : IP version
185-
)"5:"$( : IHL
186-
)"00:"$( : IP TOS
187-
)"00:14:"$( : IP total length
188-
)"00:00:"$( : IP identification
189-
)"20:00:"$( : IP flags + frag off
190-
)"30:"$( : IP TTL
191-
)"01:"$( : IP proto
192-
)"E7:E6:"$( : IP header csum
193-
)"C0:00:01:01:"$( : IP saddr : 192.0.1.1
194-
)"C0:00:02:01:"$( : IP daddr : 192.0.2.1
195-
)
196-
echo $p
197-
}
198-
199183
no_matching_tunnel_test()
200184
{
201185
local trap_name="decap_error"
@@ -239,7 +223,8 @@ decap_error_test()
239223
no_matching_tunnel_test "Decap error: Source IP check failed" \
240224
192.0.2.68 "0"
241225
no_matching_tunnel_test \
242-
"Decap error: Key exists but was not expected" $sip "2" ":E9:"
226+
"Decap error: Key exists but was not expected" $sip "2" \
227+
"00:00:00:E9:"
243228

244229
# Destroy the tunnel and create new one with key
245230
__addr_add_del g1 del 192.0.2.65/32
@@ -251,7 +236,8 @@ decap_error_test()
251236
no_matching_tunnel_test \
252237
"Decap error: Key does not exist but was expected" $sip "0"
253238
no_matching_tunnel_test \
254-
"Decap error: Packet has a wrong key field" $sip "2" "E8:"
239+
"Decap error: Packet has a wrong key field" $sip "2" \
240+
"00:00:00:E8:"
255241
}
256242

257243
trap cleanup EXIT
Lines changed: 250 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,250 @@
1+
#!/bin/bash
2+
# SPDX-License-Identifier: GPL-2.0
3+
#
4+
# Test devlink-trap tunnel exceptions functionality over mlxsw.
5+
# Check all exception traps to make sure they are triggered under the right
6+
# conditions.
7+
8+
# +-------------------------+
9+
# | H1 |
10+
# | $h1 + |
11+
# | 2001:db8:1::1/64 | |
12+
# +-------------------|-----+
13+
# |
14+
# +-------------------|-----+
15+
# | SW1 | |
16+
# | $swp1 + |
17+
# | 2001:db8:1::2/64 |
18+
# | |
19+
# | + g1 (ip6gre) |
20+
# | loc=2001:db8:3::1 |
21+
# | rem=2001:db8:3::2 |
22+
# | tos=inherit |
23+
# | |
24+
# | + $rp1 |
25+
# | | 2001:db8:10::1/64 |
26+
# +--|----------------------+
27+
# |
28+
# +--|----------------------+
29+
# | | VRF2 |
30+
# | + $rp2 |
31+
# | 2001:db8:10::2/64 |
32+
# +-------------------------+
33+
34+
lib_dir=$(dirname $0)/../../../../net/forwarding
35+
36+
ALL_TESTS="
37+
decap_error_test
38+
"
39+
40+
NUM_NETIFS=4
41+
source $lib_dir/lib.sh
42+
source $lib_dir/tc_common.sh
43+
source $lib_dir/devlink_lib.sh
44+
45+
h1_create()
46+
{
47+
simple_if_init $h1 2001:db8:1::1/64
48+
}
49+
50+
h1_destroy()
51+
{
52+
simple_if_fini $h1 2001:db8:1::1/64
53+
}
54+
55+
vrf2_create()
56+
{
57+
simple_if_init $rp2 2001:db8:10::2/64
58+
}
59+
60+
vrf2_destroy()
61+
{
62+
simple_if_fini $rp2 2001:db8:10::2/64
63+
}
64+
65+
switch_create()
66+
{
67+
ip link set dev $swp1 up
68+
__addr_add_del $swp1 add 2001:db8:1::2/64
69+
tc qdisc add dev $swp1 clsact
70+
71+
tunnel_create g1 ip6gre 2001:db8:3::1 2001:db8:3::2 tos inherit \
72+
ttl inherit
73+
ip link set dev g1 up
74+
__addr_add_del g1 add 2001:db8:3::1/128
75+
76+
ip link set dev $rp1 up
77+
__addr_add_del $rp1 add 2001:db8:10::1/64
78+
}
79+
80+
switch_destroy()
81+
{
82+
__addr_add_del $rp1 del 2001:db8:10::1/64
83+
ip link set dev $rp1 down
84+
85+
__addr_add_del g1 del 2001:db8:3::1/128
86+
ip link set dev g1 down
87+
tunnel_destroy g1
88+
89+
tc qdisc del dev $swp1 clsact
90+
__addr_add_del $swp1 del 2001:db8:1::2/64
91+
ip link set dev $swp1 down
92+
}
93+
94+
setup_prepare()
95+
{
96+
h1=${NETIFS[p1]}
97+
swp1=${NETIFS[p2]}
98+
99+
rp1=${NETIFS[p3]}
100+
rp2=${NETIFS[p4]}
101+
102+
forwarding_enable
103+
vrf_prepare
104+
h1_create
105+
switch_create
106+
vrf2_create
107+
}
108+
109+
cleanup()
110+
{
111+
pre_cleanup
112+
113+
vrf2_destroy
114+
switch_destroy
115+
h1_destroy
116+
vrf_cleanup
117+
forwarding_restore
118+
}
119+
120+
ipip_payload_get()
121+
{
122+
local saddr="20:01:0d:b8:00:02:00:00:00:00:00:00:00:00:00:01"
123+
local daddr="20:01:0d:b8:00:01:00:00:00:00:00:00:00:00:00:01"
124+
local flags=$1; shift
125+
local key=$1; shift
126+
127+
p=$(:
128+
)"$flags"$( : GRE flags
129+
)"0:00:"$( : Reserved + version
130+
)"86:dd:"$( : ETH protocol type
131+
)"$key"$( : Key
132+
)"6"$( : IP version
133+
)"0:0"$( : Traffic class
134+
)"0:00:00:"$( : Flow label
135+
)"00:00:"$( : Payload length
136+
)"3a:"$( : Next header
137+
)"04:"$( : Hop limit
138+
)"$saddr:"$( : IP saddr
139+
)"$daddr:"$( : IP daddr
140+
)
141+
echo $p
142+
}
143+
144+
ecn_payload_get()
145+
{
146+
echo $(ipip_payload_get "0")
147+
}
148+
149+
ecn_decap_test()
150+
{
151+
local trap_name="decap_error"
152+
local desc=$1; shift
153+
local ecn_desc=$1; shift
154+
local outer_tos=$1; shift
155+
local mz_pid
156+
157+
RET=0
158+
159+
tc filter add dev $swp1 egress protocol ipv6 pref 1 handle 101 \
160+
flower src_ip 2001:db8:2::1 dst_ip 2001:db8:1::1 skip_sw \
161+
action pass
162+
163+
rp1_mac=$(mac_get $rp1)
164+
rp2_mac=$(mac_get $rp2)
165+
payload=$(ecn_payload_get)
166+
167+
ip vrf exec v$rp2 $MZ -6 $rp2 -c 0 -d 1msec -a $rp2_mac -b $rp1_mac \
168+
-A 2001:db8:3::2 -B 2001:db8:3::1 -t ip \
169+
tos=$outer_tos,next=47,p=$payload -q &
170+
mz_pid=$!
171+
172+
devlink_trap_exception_test $trap_name
173+
174+
tc_check_packets "dev $swp1 egress" 101 0
175+
check_err $? "Packets were not dropped"
176+
177+
log_test "$desc: Inner ECN is not ECT and outer is $ecn_desc"
178+
179+
kill $mz_pid && wait $mz_pid &> /dev/null
180+
tc filter del dev $swp1 egress protocol ipv6 pref 1 handle 101 flower
181+
}
182+
183+
no_matching_tunnel_test()
184+
{
185+
local trap_name="decap_error"
186+
local desc=$1; shift
187+
local sip=$1; shift
188+
local mz_pid
189+
190+
RET=0
191+
192+
tc filter add dev $swp1 egress protocol ipv6 pref 1 handle 101 \
193+
flower src_ip 2001:db8:2::1 dst_ip 2001:db8:1::1 action pass
194+
195+
rp1_mac=$(mac_get $rp1)
196+
rp2_mac=$(mac_get $rp2)
197+
payload=$(ipip_payload_get "$@")
198+
199+
ip vrf exec v$rp2 $MZ -6 $rp2 -c 0 -d 1msec -a $rp2_mac -b $rp1_mac \
200+
-A $sip -B 2001:db8:3::1 -t ip next=47,p=$payload -q &
201+
mz_pid=$!
202+
203+
devlink_trap_exception_test $trap_name
204+
205+
tc_check_packets "dev $swp1 egress" 101 0
206+
check_err $? "Packets were not dropped"
207+
208+
log_test "$desc"
209+
210+
kill $mz_pid && wait $mz_pid &> /dev/null
211+
tc filter del dev $swp1 egress protocol ipv6 pref 1 handle 101 flower
212+
}
213+
214+
decap_error_test()
215+
{
216+
# Correct source IP - the remote address
217+
local sip=2001:db8:3::2
218+
219+
ecn_decap_test "Decap error" "ECT(1)" 01
220+
ecn_decap_test "Decap error" "ECT(0)" 02
221+
ecn_decap_test "Decap error" "CE" 03
222+
223+
no_matching_tunnel_test "Decap error: Source IP check failed" \
224+
2001:db8:4::2 "0"
225+
no_matching_tunnel_test \
226+
"Decap error: Key exists but was not expected" $sip "2" \
227+
"00:00:00:E9:"
228+
229+
# Destroy the tunnel and create new one with key
230+
__addr_add_del g1 del 2001:db8:3::1/128
231+
tunnel_destroy g1
232+
233+
tunnel_create g1 ip6gre 2001:db8:3::1 2001:db8:3::2 tos inherit \
234+
ttl inherit key 233
235+
__addr_add_del g1 add 2001:db8:3::1/128
236+
237+
no_matching_tunnel_test \
238+
"Decap error: Key does not exist but was expected" $sip "0"
239+
no_matching_tunnel_test \
240+
"Decap error: Packet has a wrong key field" $sip "2" \
241+
"00:00:00:E8:"
242+
}
243+
244+
trap cleanup EXIT
245+
246+
setup_prepare
247+
setup_wait
248+
tests_run
249+
250+
exit $EXIT_STATUS

tools/testing/selftests/net/forwarding/forwarding.config.sample

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,3 +39,6 @@ NETIF_CREATE=yes
3939
# Timeout (in seconds) before ping exits regardless of how many packets have
4040
# been sent or received
4141
PING_TIMEOUT=5
42+
# Flag for tc match, supposed to be skip_sw/skip_hw which means do not process
43+
# filter by software/hardware
44+
TC_FLAG=skip_hw

0 commit comments

Comments
 (0)