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#
4# Author: Justin Iurman <justin.iurman@uliege.be>
5#
6# WARNING
7# -------
8# This is just a dummy script that triggers encap cases with possible dst cache
9# reference loops in affected lwt users (see list below). Some cases are
10# pathological configurations for simplicity, others are valid. Overall, we
11# don't want this issue to happen, no matter what. In order to catch any
12# reference loops, kmemleak MUST be used. The results alone are always blindly
13# successful, don't rely on them. Note that the following tests may crash the
14# kernel if the fix to prevent lwtunnel_{input|output|xmit}() reentry loops is
15# not present.
16#
17# Affected lwt users so far (please update accordingly if needed):
18# - ila_lwt (output only)
19# - ioam6_iptunnel (output only)
20# - rpl_iptunnel (both input and output)
21# - seg6_iptunnel (both input and output)
22
23source lib.sh
24
25check_compatibility()
26{
27 setup_ns tmp_node &>/dev/null
28 if [ $? != 0 ]; then
29 echo "SKIP: Cannot create netns."
30 exit $ksft_skip
31 fi
32
33 ip link add name veth0 netns $tmp_node type veth \
34 peer name veth1 netns $tmp_node &>/dev/null
35 local ret=$?
36
37 ip -netns $tmp_node link set veth0 up &>/dev/null
38 ret=$((ret + $?))
39
40 ip -netns $tmp_node link set veth1 up &>/dev/null
41 ret=$((ret + $?))
42
43 if [ $ret != 0 ]; then
44 echo "SKIP: Cannot configure links."
45 cleanup_ns $tmp_node
46 exit $ksft_skip
47 fi
48
49 lsmod 2>/dev/null | grep -q "ila"
50 ila_lsmod=$?
51 [ $ila_lsmod != 0 ] && modprobe ila &>/dev/null
52
53 ip -netns $tmp_node route add 2001:db8:1::/64 \
54 encap ila 1:2:3:4 csum-mode no-action ident-type luid \
55 hook-type output \
56 dev veth0 &>/dev/null
57
58 ip -netns $tmp_node route add 2001:db8:2::/64 \
59 encap ioam6 trace prealloc type 0x800000 ns 0 size 4 \
60 dev veth0 &>/dev/null
61
62 ip -netns $tmp_node route add 2001:db8:3::/64 \
63 encap rpl segs 2001:db8:3::1 dev veth0 &>/dev/null
64
65 ip -netns $tmp_node route add 2001:db8:4::/64 \
66 encap seg6 mode inline segs 2001:db8:4::1 dev veth0 &>/dev/null
67
68 ip -netns $tmp_node -6 route 2>/dev/null | grep -q "encap ila"
69 skip_ila=$?
70
71 ip -netns $tmp_node -6 route 2>/dev/null | grep -q "encap ioam6"
72 skip_ioam6=$?
73
74 ip -netns $tmp_node -6 route 2>/dev/null | grep -q "encap rpl"
75 skip_rpl=$?
76
77 ip -netns $tmp_node -6 route 2>/dev/null | grep -q "encap seg6"
78 skip_seg6=$?
79
80 cleanup_ns $tmp_node
81}
82
83setup()
84{
85 setup_ns alpha beta gamma &>/dev/null
86
87 ip link add name veth-alpha netns $alpha type veth \
88 peer name veth-betaL netns $beta &>/dev/null
89
90 ip link add name veth-betaR netns $beta type veth \
91 peer name veth-gamma netns $gamma &>/dev/null
92
93 ip -netns $alpha link set veth-alpha name veth0 &>/dev/null
94 ip -netns $beta link set veth-betaL name veth0 &>/dev/null
95 ip -netns $beta link set veth-betaR name veth1 &>/dev/null
96 ip -netns $gamma link set veth-gamma name veth0 &>/dev/null
97
98 ip -netns $alpha addr add 2001:db8:1::2/64 dev veth0 &>/dev/null
99 ip -netns $alpha link set veth0 up &>/dev/null
100 ip -netns $alpha link set lo up &>/dev/null
101 ip -netns $alpha route add 2001:db8:2::/64 \
102 via 2001:db8:1::1 dev veth0 &>/dev/null
103
104 ip -netns $beta addr add 2001:db8:1::1/64 dev veth0 &>/dev/null
105 ip -netns $beta addr add 2001:db8:2::1/64 dev veth1 &>/dev/null
106 ip -netns $beta link set veth0 up &>/dev/null
107 ip -netns $beta link set veth1 up &>/dev/null
108 ip -netns $beta link set lo up &>/dev/null
109 ip -netns $beta route del 2001:db8:2::/64
110 ip -netns $beta route add 2001:db8:2::/64 dev veth1
111 ip netns exec $beta \
112 sysctl -wq net.ipv6.conf.all.forwarding=1 &>/dev/null
113
114 ip -netns $gamma addr add 2001:db8:2::2/64 dev veth0 &>/dev/null
115 ip -netns $gamma link set veth0 up &>/dev/null
116 ip -netns $gamma link set lo up &>/dev/null
117 ip -netns $gamma route add 2001:db8:1::/64 \
118 via 2001:db8:2::1 dev veth0 &>/dev/null
119
120 sleep 1
121
122 ip netns exec $alpha ping6 -c 5 -W 1 2001:db8:2::2 &>/dev/null
123 if [ $? != 0 ]; then
124 echo "SKIP: Setup failed."
125 exit $ksft_skip
126 fi
127
128 sleep 1
129}
130
131cleanup()
132{
133 cleanup_ns $alpha $beta $gamma
134 [ $ila_lsmod != 0 ] && modprobe -r ila &>/dev/null
135}
136
137run_ila()
138{
139 if [ $skip_ila != 0 ]; then
140 echo "SKIP: ila (output)"
141 return
142 fi
143
144 ip -netns $beta route del 2001:db8:2::/64
145 ip -netns $beta route add 2001:db8:2:0:0:0:0:2/128 \
146 encap ila 2001:db8:2:0 csum-mode no-action ident-type luid \
147 hook-type output \
148 dev veth1 &>/dev/null
149 sleep 1
150
151 echo "TEST: ila (output)"
152 ip netns exec $beta ping6 -c 2 -W 1 2001:db8:2::2 &>/dev/null
153 sleep 1
154
155 ip -netns $beta route del 2001:db8:2:0:0:0:0:2/128
156 ip -netns $beta route add 2001:db8:2::/64 dev veth1
157 sleep 1
158}
159
160run_ioam6()
161{
162 if [ $skip_ioam6 != 0 ]; then
163 echo "SKIP: ioam6 (output)"
164 return
165 fi
166
167 ip -netns $beta route change 2001:db8:2::/64 \
168 encap ioam6 trace prealloc type 0x800000 ns 1 size 4 \
169 dev veth1 &>/dev/null
170 sleep 1
171
172 echo "TEST: ioam6 (output)"
173 ip netns exec $beta ping6 -c 2 -W 1 2001:db8:2::2 &>/dev/null
174 sleep 1
175}
176
177run_rpl()
178{
179 if [ $skip_rpl != 0 ]; then
180 echo "SKIP: rpl (input)"
181 echo "SKIP: rpl (output)"
182 return
183 fi
184
185 ip -netns $beta route change 2001:db8:2::/64 \
186 encap rpl segs 2001:db8:2::2 \
187 dev veth1 &>/dev/null
188 sleep 1
189
190 echo "TEST: rpl (input)"
191 ip netns exec $alpha ping6 -c 2 -W 1 2001:db8:2::2 &>/dev/null
192 sleep 1
193
194 echo "TEST: rpl (output)"
195 ip netns exec $beta ping6 -c 2 -W 1 2001:db8:2::2 &>/dev/null
196 sleep 1
197}
198
199run_seg6()
200{
201 if [ $skip_seg6 != 0 ]; then
202 echo "SKIP: seg6 (input)"
203 echo "SKIP: seg6 (output)"
204 return
205 fi
206
207 ip -netns $beta route change 2001:db8:2::/64 \
208 encap seg6 mode inline segs 2001:db8:2::2 \
209 dev veth1 &>/dev/null
210 sleep 1
211
212 echo "TEST: seg6 (input)"
213 ip netns exec $alpha ping6 -c 2 -W 1 2001:db8:2::2 &>/dev/null
214 sleep 1
215
216 echo "TEST: seg6 (output)"
217 ip netns exec $beta ping6 -c 2 -W 1 2001:db8:2::2 &>/dev/null
218 sleep 1
219}
220
221run()
222{
223 run_ila
224 run_ioam6
225 run_rpl
226 run_seg6
227}
228
229if [ "$(id -u)" -ne 0 ]; then
230 echo "SKIP: Need root privileges."
231 exit $ksft_skip
232fi
233
234if [ ! -x "$(command -v ip)" ]; then
235 echo "SKIP: Could not run test without ip tool."
236 exit $ksft_skip
237fi
238
239check_compatibility
240
241trap cleanup EXIT
242
243setup
244run
245
246exit $ksft_pass