12
12
#
13
13
# routing in h0 to hN is done with nexthop objects.
14
14
15
+ source lib.sh
15
16
PAUSE_ON_FAIL=no
16
17
VERBOSE=0
17
18
@@ -72,12 +73,6 @@ create_ns()
72
73
{
73
74
local ns=${1}
74
75
75
- ip netns del ${ns} 2> /dev/null
76
-
77
- ip netns add ${ns}
78
- ip -netns ${ns} addr add 127.0.0.1/8 dev lo
79
- ip -netns ${ns} link set lo up
80
-
81
76
ip netns exec ${ns} sysctl -q -w net.ipv6.conf.all.keep_addr_on_down=1
82
77
case ${ns} in
83
78
h* )
@@ -97,7 +92,13 @@ setup()
97
92
98
93
# set -e
99
94
100
- for ns in h0 r1 h1 h2 h3
95
+ setup_ns h0 r1 h1 h2 h3
96
+ h[0]=$h0
97
+ h[1]=$h1
98
+ h[2]=$h2
99
+ h[3]=$h3
100
+ r[1]=$r1
101
+ for ns in ${h[0]} ${r[1]} ${h[1]} ${h[2]} ${h[3]}
101
102
do
102
103
create_ns ${ns}
103
104
done
@@ -108,46 +109,43 @@ setup()
108
109
109
110
for i in 0 1 2 3
110
111
do
111
- ip -netns h ${i } li add eth0 type veth peer name r1h${i}
112
- ip -netns h ${i } li set eth0 up
113
- ip -netns h ${i } li set r1h${i} netns r1 name eth${i} up
114
-
115
- ip -netns h ${i } addr add dev eth0 172.16.10${i} .1/24
116
- ip -netns h ${i } -6 addr add dev eth0 2001:db8:10${i} ::1/64
117
- ip -netns r1 addr add dev eth${i} 172.16.10${i} .254/24
118
- ip -netns r1 -6 addr add dev eth${i} 2001:db8:10${i} ::64/64
112
+ ip -netns ${h[$i] } li add eth0 type veth peer name r1h${i}
113
+ ip -netns ${h[$i] } li set eth0 up
114
+ ip -netns ${h[$i] } li set r1h${i} netns ${r[1]} name eth${i} up
115
+
116
+ ip -netns ${h[$i] } addr add dev eth0 172.16.10${i} .1/24
117
+ ip -netns ${h[$i] } -6 addr add dev eth0 2001:db8:10${i} ::1/64
118
+ ip -netns ${r[1]} addr add dev eth${i} 172.16.10${i} .254/24
119
+ ip -netns ${r[1]} -6 addr add dev eth${i} 2001:db8:10${i} ::64/64
119
120
done
120
121
121
- ip -netns h0 nexthop add id 4 via 172.16.100.254 dev eth0
122
- ip -netns h0 nexthop add id 6 via 2001:db8:100::64 dev eth0
122
+ ip -netns ${h[0]} nexthop add id 4 via 172.16.100.254 dev eth0
123
+ ip -netns ${h[0]} nexthop add id 6 via 2001:db8:100::64 dev eth0
123
124
124
- # routing from h0 to h1-h3 and back
125
+ # routing from ${h[0]} to h1-h3 and back
125
126
for i in 1 2 3
126
127
do
127
- ip -netns h0 ro add 172.16.10${i} .0/24 nhid 4
128
- ip -netns h ${i } ro add 172.16.100.0/24 via 172.16.10${i} .254
128
+ ip -netns ${h[0]} ro add 172.16.10${i} .0/24 nhid 4
129
+ ip -netns ${h[$i] } ro add 172.16.100.0/24 via 172.16.10${i} .254
129
130
130
- ip -netns h0 -6 ro add 2001:db8:10${i} ::/64 nhid 6
131
- ip -netns h ${i } -6 ro add 2001:db8:100::/64 via 2001:db8:10${i} ::64
131
+ ip -netns ${h[0]} -6 ro add 2001:db8:10${i} ::/64 nhid 6
132
+ ip -netns ${h[$i] } -6 ro add 2001:db8:100::/64 via 2001:db8:10${i} ::64
132
133
done
133
134
134
135
if [ " $VERBOSE " = " 1" ]; then
135
136
echo
136
137
echo " host 1 config"
137
- ip -netns h0 li sh
138
- ip -netns h0 ro sh
139
- ip -netns h0 -6 ro sh
138
+ ip -netns ${h[0]} li sh
139
+ ip -netns ${h[0]} ro sh
140
+ ip -netns ${h[0]} -6 ro sh
140
141
fi
141
142
142
143
# set +e
143
144
}
144
145
145
146
cleanup ()
146
147
{
147
- for n in h0 r1 h1 h2 h3
148
- do
149
- ip netns del ${n} 2> /dev/null
150
- done
148
+ cleanup_all_ns
151
149
}
152
150
153
151
change_mtu ()
@@ -156,7 +154,7 @@ change_mtu()
156
154
local mtu=$2
157
155
158
156
run_cmd ip -netns h${hostid} li set eth0 mtu ${mtu}
159
- run_cmd ip -netns r1 li set eth${hostid} mtu ${mtu}
157
+ run_cmd ip -netns ${r1} li set eth${hostid} mtu ${mtu}
160
158
}
161
159
162
160
# ###############################################################################
@@ -168,23 +166,23 @@ validate_v4_exception()
168
166
local mtu=$2
169
167
local ping_sz=$3
170
168
local dst=" 172.16.10${i} .1"
171
- local h0 =172.16.100.1
172
- local r1 =172.16.100.254
169
+ local h0_ip =172.16.100.1
170
+ local r1_ip =172.16.100.254
173
171
local rc
174
172
175
173
if [ ${ping_sz} != " 0" ]; then
176
- run_cmd ip netns exec h0 ping -s ${ping_sz} -c5 -w5 ${dst}
174
+ run_cmd ip netns exec ${h0} ping -s ${ping_sz} -c5 -w5 ${dst}
177
175
fi
178
176
179
177
if [ " $VERBOSE " = " 1" ]; then
180
178
echo " Route get"
181
- ip -netns h0 ro get ${dst}
179
+ ip -netns ${h0} ro get ${dst}
182
180
echo " Searching for:"
183
181
echo " cache .* mtu ${mtu} "
184
182
echo
185
183
fi
186
184
187
- ip -netns h0 ro get ${dst} | \
185
+ ip -netns ${h0} ro get ${dst} | \
188
186
grep -q " cache .* mtu ${mtu} "
189
187
rc=$?
190
188
@@ -197,24 +195,24 @@ validate_v6_exception()
197
195
local mtu=$2
198
196
local ping_sz=$3
199
197
local dst=" 2001:db8:10${i} ::1"
200
- local h0 =2001:db8:100::1
201
- local r1 =2001:db8:100::64
198
+ local h0_ip =2001:db8:100::1
199
+ local r1_ip =2001:db8:100::64
202
200
local rc
203
201
204
202
if [ ${ping_sz} != " 0" ]; then
205
- run_cmd ip netns exec h0 ${ping6} -s ${ping_sz} -c5 -w5 ${dst}
203
+ run_cmd ip netns exec ${h0} ${ping6} -s ${ping_sz} -c5 -w5 ${dst}
206
204
fi
207
205
208
206
if [ " $VERBOSE " = " 1" ]; then
209
207
echo " Route get"
210
- ip -netns h0 -6 ro get ${dst}
208
+ ip -netns ${h0} -6 ro get ${dst}
211
209
echo " Searching for:"
212
- echo " ${dst} from :: via ${r1 } dev eth0 src ${h0 } .* mtu ${mtu} "
210
+ echo " ${dst} .* via ${r1_ip } dev eth0 src ${h0_ip } .* mtu ${mtu} "
213
211
echo
214
212
fi
215
213
216
- ip -netns h0 -6 ro get ${dst} | \
217
- grep -q " ${dst} from :: via ${r1 } dev eth0 src ${h0 } .* mtu ${mtu} "
214
+ ip -netns ${h0} -6 ro get ${dst} | \
215
+ grep -q " ${dst} .* via ${r1_ip } dev eth0 src ${h0_ip } .* mtu ${mtu} "
218
216
rc=$?
219
217
220
218
log_test $rc 0 " IPv6: host 0 to host ${i} , mtu ${mtu} "
@@ -242,11 +240,11 @@ for i in 1 2 3
242
240
do
243
241
# generate a cached route per-cpu
244
242
for c in ${cpus} ; do
245
- run_cmd taskset -c ${c} ip netns exec h0 ping -c1 -w1 172.16.10${i} .1
246
- [ $? -ne 0 ] && printf " \nERROR: ping to h ${i } failed\n" && ret=1
243
+ run_cmd taskset -c ${c} ip netns exec ${h0} ping -c1 -w1 172.16.10${i} .1
244
+ [ $? -ne 0 ] && printf " \nERROR: ping to ${h[$i] } failed\n" && ret=1
247
245
248
- run_cmd taskset -c ${c} ip netns exec h0 ${ping6} -c1 -w1 2001:db8:10${i} ::1
249
- [ $? -ne 0 ] && printf " \nERROR: ping6 to h ${i } failed\n" && ret=1
246
+ run_cmd taskset -c ${c} ip netns exec ${h0} ${ping6} -c1 -w1 2001:db8:10${i} ::1
247
+ [ $? -ne 0 ] && printf " \nERROR: ping6 to ${h[$i] } failed\n" && ret=1
250
248
251
249
[ $ret -ne 0 ] && break
252
250
done
@@ -282,11 +280,11 @@ if [ $ret -eq 0 ]; then
282
280
validate_v6_exception 3 1400 0
283
281
284
282
# targeted deletes to trigger cleanup paths in kernel
285
- ip -netns h0 ro del 172.16.102.0/24 nhid 4
286
- ip -netns h0 -6 ro del 2001:db8:102::/64 nhid 6
283
+ ip -netns ${h0} ro del 172.16.102.0/24 nhid 4
284
+ ip -netns ${h0} -6 ro del 2001:db8:102::/64 nhid 6
287
285
288
- ip -netns h0 nexthop del id 4
289
- ip -netns h0 nexthop del id 6
286
+ ip -netns ${h0} nexthop del id 4
287
+ ip -netns ${h0} nexthop del id 6
290
288
fi
291
289
292
290
cleanup
0 commit comments