t_vlan.sh revision 1.27 1 # $NetBSD: t_vlan.sh,v 1.27 2025/03/18 07:58:09 ozaki-r Exp $
2 #
3 # Copyright (c) 2016 Internet Initiative Japan Inc.
4 # All rights reserved.
5 #
6 # Redistribution and use in source and binary forms, with or without
7 # modification, are permitted provided that the following conditions
8 # are met:
9 # 1. Redistributions of source code must retain the above copyright
10 # notice, this list of conditions and the following disclaimer.
11 # 2. Redistributions in binary form must reproduce the above copyright
12 # notice, this list of conditions and the following disclaimer in the
13 # documentation and/or other materials provided with the distribution.
14 #
15 # THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
16 # ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
17 # TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
18 # PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
19 # BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
20 # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
21 # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
22 # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
23 # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
24 # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
25 # POSSIBILITY OF SUCH DAMAGE.
26 #
27
28 BUS=bus
29 SOCK_LOCAL=unix://commsock1
30 SOCK_REMOTE=unix://commsock2
31 IP_LOCAL0=10.0.0.1
32 IP_LOCAL1=10.0.1.1
33 IP_REMOTE0=10.0.0.2
34 IP_REMOTE1=10.0.1.2
35 IP_MCADDR0=224.0.0.10
36 IP6_LOCAL0=fc00::1
37 IP6_LOCAL1=fc00:1::1
38 IP6_REMOTE0=fc00::2
39 IP6_REMOTE1=fc00:1::2
40 IP6_MCADDR0=ff11::10
41 ETH_IP_MCADDR0=01:00:5e:00:00:0a
42 ETH_IP6_MCADDR0=33:33:00:00:00:10
43
44 DEBUG=${DEBUG:-false}
45
46 vlan_create_destroy_body_common()
47 {
48 local atf_ifconfig="atf_check -s exit:0 rump.ifconfig"
49
50 export RUMP_SERVER=${SOCK_LOCAL}
51
52 $atf_ifconfig vlan0 create
53 $atf_ifconfig vlan0 destroy
54
55 $atf_ifconfig vlan0 create
56 $atf_ifconfig vlan0 up
57 $atf_ifconfig vlan0 down
58 $atf_ifconfig vlan0 destroy
59
60 $atf_ifconfig shmif0 create
61 $atf_ifconfig vlan0 create
62 $atf_ifconfig vlan0 vlan 1 vlanif shmif0
63 $atf_ifconfig vlan0 up
64 $atf_ifconfig vlan0 destroy
65
66 # more than one vlan interface with a same parent interface
67 $atf_ifconfig shmif1 create
68 $atf_ifconfig vlan0 create
69 $atf_ifconfig vlan0 vlan 10 vlanif shmif0
70 $atf_ifconfig vlan1 create
71 $atf_ifconfig vlan1 vlan 11 vlanif shmif0
72
73 # more than one interface with another parent interface
74 $atf_ifconfig vlan2 create
75 $atf_ifconfig vlan2 vlan 12 vlanif shmif1
76 $atf_ifconfig vlan3 create
77 $atf_ifconfig vlan3 vlan 13 vlanif shmif1
78 $atf_ifconfig shmif0 destroy
79 atf_check -s exit:0 -o not-match:'shmif0' rump.ifconfig vlan0
80 atf_check -s exit:0 -o not-match:'shmif0' rump.ifconfig vlan1
81 atf_check -s exit:0 -o match:'shmif1' rump.ifconfig vlan2
82 atf_check -s exit:0 -o match:'shmif1' rump.ifconfig vlan3
83 $atf_ifconfig vlan0 destroy
84 $atf_ifconfig vlan1 destroy
85 $atf_ifconfig vlan2 destroy
86 $atf_ifconfig vlan3 destroy
87
88 }
89
90 test_create_destroy()
91 {
92 rump_server_start $SOCK_LOCAL vlan
93
94 vlan_create_destroy_body_common
95 }
96
97 test_create_destroy6()
98 {
99
100 rump_server_start $SOCK_LOCAL vlan netinet6
101
102 vlan_create_destroy_body_common
103 }
104
105 vlan_basic_body_common()
106 {
107 local atf_ifconfig="atf_check -s exit:0 rump.ifconfig"
108 local outfile=./out
109 local af=inet
110 local prefix=24
111 local local0=$IP_LOCAL0
112 local remote0=$IP_REMOTE0
113 local ping_cmd="rump.ping -n -w 1 -c 1"
114
115 if [ x"$1" = x"inet6" ]; then
116 af="inet6"
117 prefix=64
118 local0=$IP6_LOCAL0
119 remote0=$IP6_REMOTE0
120 ping_cmd="rump.ping6 -n -c 1"
121 fi
122
123 rump_server_add_iface $SOCK_LOCAL shmif0 $BUS
124 rump_server_add_iface $SOCK_REMOTE shmif0 $BUS
125
126 export RUMP_SERVER=$SOCK_LOCAL
127 $atf_ifconfig shmif0 up
128 export RUMP_SERVER=$SOCK_REMOTE
129 $atf_ifconfig shmif0 up
130
131 export RUMP_SERVER=$SOCK_LOCAL
132 $atf_ifconfig vlan0 create
133 $atf_ifconfig vlan0 vlan 10 vlanif shmif0
134 $atf_ifconfig vlan0 $af $local0/$prefix
135 $atf_ifconfig vlan0 up
136 $atf_ifconfig -w 10
137
138 export RUMP_SERVER=$SOCK_REMOTE
139 $atf_ifconfig vlan0 create
140 $atf_ifconfig vlan0 vlan 10 vlanif shmif0
141 $atf_ifconfig vlan0 $af $remote0/$prefix
142 $atf_ifconfig vlan0 up
143 $atf_ifconfig -w 10
144
145 extract_new_packets $BUS > $outfile
146
147 export RUMP_SERVER=$SOCK_LOCAL
148 atf_check -s exit:0 -o ignore $ping_cmd $remote0
149
150 extract_new_packets $BUS > $outfile
151 atf_check -s exit:0 -o match:'vlan 10' cat $outfile
152
153 $atf_ifconfig vlan0 -vlanif
154 $atf_ifconfig vlan0 vlan 20 vlanif shmif0
155 $atf_ifconfig vlan0 $af $local0/$prefix
156 $atf_ifconfig vlan0 up
157 $atf_ifconfig -w 10
158
159 extract_new_packets $BUS > $outfile
160 atf_check -s not-exit:0 -o ignore $ping_cmd $remote0
161
162 extract_new_packets $BUS > $outfile
163 atf_check -s exit:0 -o match:'vlan 20' cat $outfile
164
165 export RUMP_SERVER=$SOCK_LOCAL
166 $atf_ifconfig vlan0 -vlanif
167 $atf_ifconfig vlan0 vlan 10 vlanif shmif0
168 $atf_ifconfig vlan0 $af $local0/$prefix
169 $atf_ifconfig vlan0 up
170 $atf_ifconfig -w 10
171
172 atf_check -s exit:0 -o ignore rump.ifconfig -z vlan0
173 atf_check -s exit:0 -o ignore $ping_cmd $remote0
174 rump.ifconfig -v vlan0 > $outfile
175
176 atf_check -s exit:0 -o not-match:' 0 packets' cat $outfile
177 atf_check -s exit:0 -o not-match:' 0 bytes' cat $outfile
178 }
179
180 test_basic()
181 {
182 rump_server_start $SOCK_LOCAL vlan
183 rump_server_start $SOCK_REMOTE vlan
184
185 vlan_basic_body_common inet
186
187 }
188
189 test_basic6()
190 {
191 rump_server_start $SOCK_LOCAL vlan netinet6
192 rump_server_start $SOCK_REMOTE vlan netinet6
193
194 vlan_basic_body_common inet6
195 }
196
197 vlan_auto_follow_mtu_body_common()
198 {
199 local atf_ifconfig="atf_check -s exit:0 rump.ifconfig"
200 local outfile=./out
201 local af=inet
202 local prefix=24
203 local local0=$IP_LOCAL0
204 local remote0=$IP_REMOTE0
205 local ping_cmd="rump.ping -D -n -w 1 -c 1"
206 local mtu=1500
207 local vlan_mtu=`expr $mtu - 4`
208 # ipv4 header=20bytes, icmp header=8bytes
209 local padding=`expr $vlan_mtu - 20 - 8`
210 local over_padding=`expr $vlan_mtu - 20 - 8 + 1`
211 local nonfrag_msg="$local0 > $remote0: ICMP echo request"
212 # unused for ipv4
213 local frag_msg=""
214
215 if [ x"$1" = x"inet6" ]; then
216 af="inet6"
217 prefix=64
218 local0=$IP6_LOCAL0
219 remote0=$IP6_REMOTE0
220 # ipv6 header=40bytes, icmpv6 header=8bytes
221 padding=`expr $vlan_mtu - 40 - 8`
222 over_padding=`expr $vlan_mtu - 40 - 8 + 1`
223 ping_cmd="rump.ping6 -mm -n -c 1 -i 1"
224 nonfrag_msg="$local0 > $remote0: ICMP6, echo request"
225 frag_msg="$local0 > $remote0: frag .* ICMP6, echo request"
226 fi
227
228 rump_server_add_iface $SOCK_LOCAL shmif0 $BUS
229 rump_server_add_iface $SOCK_REMOTE shmif0 $BUS
230
231 export RUMP_SERVER=$SOCK_LOCAL
232 $atf_ifconfig shmif0 up
233 export RUMP_SERVER=$SOCK_REMOTE
234 $atf_ifconfig shmif0 up
235
236 export RUMP_SERVER=$SOCK_LOCAL
237 $atf_ifconfig vlan0 create
238
239 # since upper bound of shmif's mtu is 1500,
240 # so we lower vlan's mtu instead of raising shmif's.
241 # to do this, we change the interface's parameter
242 # such as ND_IFINFO(ifp)->maxmtu that is changed by SIOCSIFMTU.
243
244 # $atf_config shmif0 mtu 1600
245 $atf_ifconfig vlan0 vlan 10 vlanif shmif0
246 $atf_ifconfig vlan0 mtu 1400
247 $atf_ifconfig vlan0 -vlanif shmif0
248
249 $atf_ifconfig vlan0 vlan 10 vlanif shmif0
250 $atf_ifconfig vlan0 $af $local0/$prefix
251 $atf_ifconfig vlan0 up
252 $atf_ifconfig -w 10
253
254 export RUMP_SERVER=$SOCK_REMOTE
255 $atf_ifconfig vlan0 create
256 $atf_ifconfig vlan0 vlan 10 vlanif shmif0
257 $atf_ifconfig vlan0 $af $remote0/$prefix
258 $atf_ifconfig vlan0 up
259 $atf_ifconfig -w 10
260
261 extract_new_packets $BUS > $outfile
262 export RUMP_SERVER=$SOCK_LOCAL
263
264 atf_check -s exit:0 -o ignore $ping_cmd -s $padding $remote0
265 extract_new_packets $BUS > $outfile
266 atf_check -s exit:0 -o match:"$nonfrag_msg" cat $outfile
267
268 if [ x"$1" = x"inet6" ]; then
269 atf_check -s exit:0 -o ignore $ping_cmd -s $over_padding $remote0
270 extract_new_packets $BUS > $outfile
271 atf_check -s exit:0 -o match:"$frag_msg" cat $outfile
272 else
273 atf_check -s not-exit:0 -o ignore -e match:"Message too long" \
274 $ping_cmd -s $over_padding $remote0
275 fi
276 }
277
278 test_auto_follow_mtu()
279 {
280 rump_server_start $SOCK_LOCAL vlan
281 rump_server_start $SOCK_REMOTE vlan
282
283 vlan_auto_follow_mtu_body_common inet
284 }
285
286 test_auto_follow_mtu6()
287 {
288 rump_server_start $SOCK_LOCAL vlan netinet6
289 rump_server_start $SOCK_REMOTE vlan netinet6
290
291 vlan_auto_follow_mtu_body_common inet6
292 }
293
294 vlanid_config_and_ping()
295 {
296 local atf_ifconfig="atf_check -s exit:0 rump.ifconfig"
297 local vlanid=$1
298 shift
299
300 export RUMP_SERVER=$SOCK_LOCAL
301 $atf_ifconfig vlan0 vlan $vlanid vlanif shmif0
302 $atf_ifconfig vlan0 $IP_LOCAL0/24
303 $atf_ifconfig vlan0 up
304
305 export RUMP_SERVER=$SOCK_REMOTE
306 $atf_ifconfig vlan0 vlan $vlanid vlanif shmif0
307 $atf_ifconfig vlan0 $IP_REMOTE0/24
308 $atf_ifconfig vlan0 up
309
310 export RUMP_SERVER=$SOCK_LOCAL
311 atf_check -s exit:0 -o ignore rump.ping -n -w 1 -c 1 $IP_REMOTE0
312 $atf_ifconfig vlan0 -vlanif
313
314 export RUMP_SERVER=$SOCK_REMOTE
315 $atf_ifconfig vlan0 -vlanif
316 }
317
318 vlanid_config_and_ping6()
319 {
320 local atf_ifconfig="atf_check -s exit:0 rump.ifconfig"
321 local vlanid=$1
322 shift
323
324 export RUMP_SERVER=$SOCK_LOCAL
325 $atf_ifconfig vlan0 vlan $vlanid vlanif shmif0
326 $atf_ifconfig vlan0 inet6 $IP6_LOCAL0/64
327 $atf_ifconfig vlan0 up
328
329 export RUMP_SERVER=$SOCK_REMOTE
330 $atf_ifconfig vlan0 vlan $vlanid vlanif shmif0
331 $atf_ifconfig vlan0 inet6 $IP6_REMOTE0/64
332 $atf_ifconfig vlan0 up
333
334 export RUMP_SERVER=$SOCK_LOCAL
335 atf_check -s exit:0 -o ignore rump.ping6 -n -c 1 $IP6_REMOTE0
336 $atf_ifconfig vlan0 -vlanif
337
338 export RUMP_SERVER=$SOCK_REMOTE
339 $atf_ifconfig vlan0 -vlanif
340 }
341
342 vlan_vlanid_body_common()
343 {
344 local atf_ifconfig="atf_check -s exit:0 rump.ifconfig"
345 local af=inet
346 local prefix=24
347 local sysctl_param="net.inet.ip.dad_count=0"
348 local ping_cmd="rump.ping -n -w 1 -c 1"
349 local config_and_ping=vlanid_config_and_ping
350 local local0=$IP_LOCAL0
351 local local1=$IP_LOCAL1
352 local remote0=$IP_REMOTE0
353 local remote1=$IP_REMOTE1
354
355 if [ x"$1" = x"inet6" ]; then
356 af=inet6
357 prefix=64
358 sysctl_param="net.inet6.ip6.dad_count=0"
359 ping_cmd="rump.ping6 -n -c 1"
360 config_and_ping=vlanid_config_and_ping6
361 local0=$IP6_LOCAL0
362 local1=$IP6_LOCAL1
363 remote0=$IP6_REMOTE0
364 remote1=$IP6_REMOTE1
365 fi
366
367 rump_server_add_iface $SOCK_LOCAL shmif0 $BUS
368 rump_server_add_iface $SOCK_REMOTE shmif0 $BUS
369
370 export RUMP_SERVER=$SOCK_LOCAL
371 atf_check -s exit:0 -o ignore rump.sysctl -w $sysctl_param
372 $atf_ifconfig shmif0 up
373 $atf_ifconfig vlan0 create
374
375 export RUMP_SERVER=$SOCK_REMOTE
376 atf_check -s exit:0 -o ignore rump.sysctl -w $sysctl_param
377 $atf_ifconfig shmif0 up
378 $atf_ifconfig vlan0 create
379
380 export RUMP_SERVER=$SOCK_LOCAL
381 atf_check -s not-exit:0 -e match:"^usage: rump.ifconfig" \
382 rump.ifconfig vlan0 vlan -1 vlanif shmif0
383
384 # $config_and_ping 0 # reserved vlan id
385 $config_and_ping 1
386 $config_and_ping 4094
387 # $config_and_ping 4095 #reserved vlan id
388
389 if [ "${RANDOM:-0}" != "${RANDOM:-0}" ]
390 then
391 for TAG in $(( ${RANDOM:-0} % 4092 + 2 )) \
392 $(( ${RANDOM:-0} % 4092 + 2 )) \
393 $(( ${RANDOM:-0} % 4092 + 2 ))
394 do
395 $config_and_ping "${TAG}"
396 done
397 fi
398
399 export RUMP_SERVER=$SOCK_LOCAL
400 for TAG in 0 4095 4096 $((4096*4 + 1)) 65536 65537 $((65536 + 4095))
401 do
402 atf_check -s not-exit:0 -e not-empty \
403 rump.ifconfig vlan0 vlan "${TAG}" vlanif shmif0
404 done
405
406 $atf_ifconfig vlan0 vlan 1 vlanif shmif0
407 atf_check -s not-exit:0 -e match:"SIOCSETVLAN: Device busy" \
408 rump.ifconfig vlan0 vlan 2 vlanif shmif0
409
410 atf_check -s not-exit:0 -e match:"SIOCSETVLAN: Device busy" \
411 rump.ifconfig vlan0 vlan 1 vlanif shmif1
412
413 $atf_ifconfig vlan0 -vlanif
414 atf_check -s not-exit:0 -e match:"Invalid argument" \
415 rump.ifconfig vlan0 $af $local0/$prefix
416
417 export RUMP_SERVER=$SOCK_LOCAL
418 $atf_ifconfig vlan0 vlan 10 vlanif shmif0
419 $atf_ifconfig vlan0 $af $local0/$prefix
420 $atf_ifconfig vlan0 up
421 $atf_ifconfig vlan1 create
422 $atf_ifconfig vlan1 vlan 11 vlanif shmif0
423 $atf_ifconfig vlan1 $af $local1/$prefix
424 $atf_ifconfig vlan1 up
425
426 export RUMP_SERVER=$SOCK_REMOTE
427 $atf_ifconfig vlan0 -vlanif
428 $atf_ifconfig vlan0 vlan 10 vlanif shmif0
429 $atf_ifconfig vlan0 $af $remote0/$prefix
430 $atf_ifconfig vlan0 up
431 $atf_ifconfig vlan1 create
432 $atf_ifconfig vlan1 vlan 11 vlanif shmif0
433 $atf_ifconfig vlan1 $af $remote1/$prefix
434 $atf_ifconfig vlan1 up
435
436 export RUMP_SERVER=$SOCK_LOCAL
437 atf_check -s exit:0 -o ignore $ping_cmd $remote0
438 atf_check -s exit:0 -o ignore $ping_cmd $remote1
439 }
440
441 test_vlanid()
442 {
443 rump_server_start $SOCK_LOCAL vlan
444 rump_server_start $SOCK_REMOTE vlan
445
446 vlan_vlanid_body_common inet
447 }
448
449 test_vlanid6()
450 {
451 rump_server_start $SOCK_LOCAL vlan netinet6
452 rump_server_start $SOCK_REMOTE vlan netinet6
453
454 vlan_vlanid_body_common inet6
455 }
456
457 vlan_configs_body_common()
458 {
459 local atf_ifconfig="atf_check -s exit:0 rump.ifconfig"
460
461 export RUMP_SERVER=${SOCK_LOCAL}
462
463 $atf_ifconfig shmif0 create
464 $atf_ifconfig shmif1 create
465 # unset U/L bit to detect a bug fixed by if_vlan.c:r1.132
466 $atf_ifconfig shmif0 link b0:a0:75:00:01:00 active
467 $atf_ifconfig shmif1 link b0:a0:75:00:01:01 active
468 $atf_ifconfig vlan0 create
469
470 atf_check -s exit:0 -o match:'status: +down' \
471 rump.ifconfig vlan0
472 $atf_ifconfig vlan0 vlan 10 vlanif shmif0
473 $atf_ifconfig vlan0 -vlanif
474 atf_check -s exit:0 -o match:'status: +down' \
475 rump.ifconfig vlan0
476
477 $atf_ifconfig vlan0 vlan 10 vlanif shmif0
478 $atf_ifconfig vlan0 -vlanif shmif0
479
480 $atf_ifconfig vlan0 vlan 10 vlanif shmif0
481 atf_check -s exit:0 rump.ifconfig vlan0 -vlanif shmif1
482 atf_check -s exit:0 rump.ifconfig vlan0 -vlanif shmif2
483
484 $atf_ifconfig vlan0 -vlanif
485
486 $atf_ifconfig vlan0 vlan 10 vlanif shmif0
487 atf_check -s exit:0 -e match:'Invalid argument' \
488 rump.ifconfig vlan0 mtu 1497
489 $atf_ifconfig vlan0 mtu 1496
490 $atf_ifconfig vlan0 mtu 42
491 atf_check -s exit:0 -e match:'Invalid argument' \
492 rump.ifconfig vlan0 mtu 41
493 $atf_ifconfig vlan0 -vlanif
494
495 $atf_ifconfig vlan1 create
496 $atf_ifconfig vlan0 vlan 10 vlanif shmif0
497 atf_check -s not-exit:0 -e match:'File exists' \
498 rump.ifconfig vlan1 vlan 10 vlanif shmif0
499 $atf_ifconfig vlan1 vlan 10 vlanif shmif1
500
501 $atf_ifconfig vlan1 -vlanif shmif1
502 $atf_ifconfig vlan1 vlan 10 vlanif shmif1
503
504 $atf_ifconfig vlan0 -vlanif shmif0
505 $atf_ifconfig vlan0 vlan 10 vlanif shmif0
506 }
507
508 test_configs()
509 {
510
511 rump_server_start $SOCK_LOCAL vlan
512
513 vlan_configs_body_common
514
515 }
516
517 test_configs6()
518 {
519 rump_server_start $SOCK_LOCAL vlan netinet6
520
521 vlan_configs_body_common
522 }
523
524 vlan_bridge_body_common()
525 {
526 local atf_ifconfig="atf_check -s exit:0 rump.ifconfig"
527 local atf_brconfig="atf_check -s exit:0 $HIJACKING /sbin/brconfig"
528
529 rump_server_add_iface $SOCK_LOCAL shmif0 $BUS
530
531 export RUMP_SERVER=$SOCK_LOCAL
532 $atf_ifconfig shmif0 up
533
534 $atf_ifconfig vlan0 create
535 $DEBUG && rump.ifconfig vlan0
536
537 $atf_ifconfig bridge0 create
538 $atf_ifconfig bridge0 up
539
540 #
541 # Add vlan to bridge member
542 #
543 $atf_ifconfig bridge0 mtu 1496
544
545 # vlan0 can not add to bridge member
546 # because it is not an ethernet device
547 atf_check -s not-exit:0 -e match:'Invalid argument' \
548 $HIJACKING /sbin/brconfig bridge0 add vlan0
549
550 $atf_ifconfig vlan0 vlan 10 vlanif shmif0
551 $atf_ifconfig vlan0 up
552 atf_check -s exit:0 -o match:'mtu 1496' rump.ifconfig vlan0
553
554 # vlan0 becomes an ethernet device
555 # after attaching the parent interface
556 $atf_brconfig bridge0 add vlan0
557 $DEBUG && $HIJACKING /sbin/brconfig bridge0
558
559 $atf_brconfig bridge0 delete vlan0
560
561 $atf_brconfig bridge0 add vlan0
562 $atf_ifconfig vlan0 -vlanif
563 atf_check -s exit:0 -o not-match:'vlan0' \
564 $HIJACKING /sbin/brconfig bridge0
565 atf_check -s not-exit:0 -e match:'No such' \
566 $HIJACKING /sbin/brconfig bridge0 delete vlan0
567
568 #
569 # decrease MTU on adding to bridge member
570 #
571 $atf_ifconfig bridge0 mtu 1495
572 $atf_ifconfig vlan0 vlan 10 vlanif shmif0
573 $atf_ifconfig vlan0 up
574 atf_check -s exit:0 -o match:'mtu 1496' rump.ifconfig vlan0
575
576 $atf_brconfig bridge0 add vlan0
577 $DEBUG && $HIJACKING /sbin/brconfig bridge0
578 atf_check -s exit:0 -o match:'mtu 1495' rump.ifconfig vlan0
579 $atf_brconfig bridge0 delete vlan0
580
581 #
582 # increase MTU on adding to bridge member
583 #
584 $atf_ifconfig bridge0 mtu 1496
585 $atf_ifconfig vlan0 mtu 1495
586 $atf_brconfig bridge0 add vlan0
587
588 $DEBUG && $HIJACKING /sbin/brconfig bridge0
589 atf_check -s exit:0 -o match:'mtu 1496' rump.ifconfig vlan0
590 $atf_brconfig bridge0 delete vlan0
591
592 $atf_ifconfig bridge0 mtu 1497
593 atf_check -s not-exit:0 -o ignore -e ignore \
594 $HIJACKING /sbin/brconfig bridge0 add vlan0
595
596 #
597 # Destroy a vlan interface that is bridge member
598 #
599 $atf_ifconfig bridge0 mtu 1496
600 $atf_brconfig bridge0 add vlan0
601 $atf_ifconfig vlan0 destroy
602
603 rump_server_destroy_ifaces
604 }
605
606 test_bridge()
607 {
608
609 rump_server_start $SOCK_LOCAL vlan bridge
610 vlan_bridge_body_common
611 }
612
613 test_bridge6()
614 {
615
616 rump_server_start $SOCK_LOCAL vlan netinet6 bridge
617 vlan_bridge_body_common
618 }
619
620 vlan_multicast_body_common()
621 {
622 local atf_ifconfig="atf_check -s exit:0 rump.ifconfig"
623 local af="inet"
624 local local0=$IP_LOCAL0
625 local local1=$IP_LOCAL1
626 local mcaddr=$IP_MCADDR0
627 local eth_mcaddr=$ETH_IP_MCADDR0
628 local prefix=24
629 local siocXmulti="$(atf_get_srcdir)/siocXmulti"
630 local atf_siocXmulti="atf_check -s exit:0 $HIJACKING $siocXmulti"
631
632 if [ x"$1" = x"inet6" ]; then
633 af="inet6"
634 prefix=64
635 local0=$IP6_LOCAL0
636 local1=$IP6_LOCAL1
637 mcaddr=$IP6_MCADDR0
638 eth_mcaddr=$ETH_IP6_MCADDR0
639 fi
640
641 export RUMP_SERVER=$SOCK_LOCAL
642
643 $atf_ifconfig shmif0 create
644 $atf_ifconfig shmif0 linkstr net0 up
645 $atf_ifconfig vlan0 create
646 $atf_ifconfig vlan0 vlan 10 vlanif shmif0
647 $atf_ifconfig vlan0 $af $local0/$prefix up
648 $atf_ifconfig vlan1 create
649 $atf_ifconfig vlan1 vlan 11 vlanif shmif0
650 $atf_ifconfig vlan1 $af $local1/$prefix up
651 $atf_ifconfig -w 10
652
653 # check the initial state
654 atf_check -s exit:0 -o not-match:"$eth_mcaddr" $HIJACKING ifmcstat
655
656 # add a multicast address
657 $atf_siocXmulti add vlan0 $mcaddr
658 atf_check -s exit:0 -o match:"$eth_mcaddr" $HIJACKING ifmcstat
659
660 # delete the address
661 $atf_siocXmulti del vlan0 $mcaddr
662 atf_check -s exit:0 -o not-match:"$eth_mcaddr" $HIJACKING ifmcstat
663
664 # delete a non-existing address
665 atf_check -s not-exit:0 -e match:"Invalid argument" \
666 $HIJACKING $siocXmulti del vlan0 $mcaddr
667
668 # add an address to different interfaces
669 $atf_siocXmulti add vlan0 $mcaddr
670 $atf_siocXmulti add vlan1 $mcaddr
671 atf_check -s exit:0 -o match:"${eth_mcaddr} refcount 2" $HIJACKING ifmcstat
672 $atf_siocXmulti del vlan0 $mcaddr
673
674 # delete the address with invalid interface
675 atf_check -s not-exit:0 -e match:"Invalid argument" \
676 $HIJACKING $siocXmulti del vlan0 $mcaddr
677
678 $atf_siocXmulti del vlan1 $mcaddr
679
680 # add and delete a same address more than once
681 $atf_siocXmulti add vlan0 $mcaddr
682 $atf_siocXmulti add vlan0 $mcaddr
683 $atf_siocXmulti add vlan0 $mcaddr
684 atf_check -s exit:0 -o match:"${eth_mcaddr} refcount 3" $HIJACKING ifmcstat
685 $atf_siocXmulti del vlan0 $mcaddr
686 $atf_siocXmulti del vlan0 $mcaddr
687 $atf_siocXmulti del vlan0 $mcaddr
688 atf_check -s exit:0 -o not-match:"$eth_mcaddr" $HIJACKING ifmcstat
689
690 # delete all address added to parent device when remove
691 # the config of parent interface
692 $atf_siocXmulti add vlan0 $mcaddr
693 $atf_siocXmulti add vlan0 $mcaddr
694 $atf_siocXmulti add vlan0 $mcaddr
695 $atf_ifconfig vlan0 -vlanif shmif0
696 atf_check -s exit:0 -o not-match:"$eth_mcaddr" $HIJACKING ifmcstat
697 }
698
699 test_multicast()
700 {
701 rump_server_start $SOCK_LOCAL vlan
702
703 vlan_multicast_body_common inet
704 }
705
706 test_multicast6()
707 {
708 rump_server_start $SOCK_LOCAL vlan netinet6
709
710 vlan_multicast_body_common inet6
711 }
712
713 test_promisc()
714 {
715 local atf_ifconfig="atf_check -s exit:0 rump.ifconfig"
716 local atf_brconfig="atf_check -s exit:0 $HIJACKING /sbin/brconfig"
717 local atf_arp="atf_check -s exit:0 rump.arp"
718 local bpfopen="$HIJACKING $(atf_get_srcdir)/bpfopen"
719 bpfopen="$bpfopen -dv -b /rump/dev/bpf"
720 local pidfile="./bpfopen.pid"
721 local macaddr=""
722
723 rump_server_bpf_start $SOCK_LOCAL vlan bridge
724 rump_server_start $SOCK_REMOTE vlan
725
726 rump_server_add_iface $SOCK_LOCAL shmif0 $BUS
727 rump_server_add_iface $SOCK_LOCAL shmif1
728 rump_server_add_iface $SOCK_LOCAL vlan0
729 rump_server_add_iface $SOCK_LOCAL vlan1
730 rump_server_add_iface $SOCK_LOCAL bridge0
731
732 rump_server_add_iface $SOCK_REMOTE shmif0 $BUS
733 rump_server_add_iface $SOCK_REMOTE vlan0
734
735 macaddr=$(get_macaddr $SOCK_LOCAL shmif1)
736
737 export RUMP_SERVER=$SOCK_REMOTE
738 $atf_ifconfig vlan0 vlan 1 vlanif shmif0
739 $atf_ifconfig shmif0 up
740 $atf_ifconfig vlan0 inet $IP_REMOTE0/24
741 $atf_ifconfig vlan0 up
742 $atf_ifconfig -w 10
743 $atf_arp -s $IP_LOCAL0 $macaddr
744
745 export RUMP_SERVER=$SOCK_LOCAL
746 $atf_ifconfig bridge0 mtu 1496
747 #
748 # When vlan IF is PROMISC, the parent is also PROMISC
749 #
750 $atf_ifconfig vlan0 vlan 1 vlanif shmif0
751 $atf_ifconfig shmif0 up
752 $atf_ifconfig vlan0 up
753
754 atf_check -s exit:0 -o not-match:'PROMISC' rump.ifconfig vlan0
755 atf_check -s exit:0 -o not-match:'PROMISC' rump.ifconfig shmif0
756
757 $atf_brconfig bridge0 add vlan0
758 $atf_ifconfig bridge0 up
759 atf_check -s exit:0 -o match:'PROMISC' rump.ifconfig vlan0
760 atf_check -s exit:0 -o match:'PROMISC' rump.ifconfig shmif0
761
762 $atf_ifconfig bridge0 down
763 $atf_brconfig bridge0 delete vlan0
764 atf_check -s exit:0 -o not-match:'PROMISC' rump.ifconfig vlan0
765 atf_check -s exit:0 -o not-match:'PROMISC' rump.ifconfig shmif0
766 $atf_ifconfig vlan0 -vlanif
767
768 #
769 # drop unicast packets that is not for the host
770 #
771 $atf_ifconfig vlan0 vlan 1 vlanif shmif0
772 $atf_ifconfig -w 10
773
774 atf_check -s exit:0 -e match:'bpf opened' $bpfopen -p $pidfile shmif0
775
776 atf_check -s exit:0 -o not-match:'PROMISC' rump.ifconfig vlan0
777 atf_check -s exit:0 -o match:'PROMISC' rump.ifconfig shmif0
778 atf_check -s exit:0 -o ignore rump.ifconfig -z vlan0
779 atf_check -s exit:0 -o not-match:'input:.*errors' \
780 rump.ifconfig -v vlan0
781
782 export RUMP_SERVER=$SOCK_REMOTE
783 atf_check -s not-exit:0 -o ignore -e ignore \
784 rump.ping -c 3 -i 0.2 $IP_LOCAL0
785
786 export RUMP_SERVER=$SOCK_LOCAL
787 atf_check -s exit:0 -o match:'input:.*errors' \
788 rump.ifconfig -v vlan0
789
790 atf_check -s exit:0 kill -TERM $(cat $pidfile)
791 sleep 2
792
793 atf_check -s exit:0 -o not-match:'PROMISC' rump.ifconfig vlan0
794 atf_check -s exit:0 -o not-match:'PROMISC' rump.ifconfig shmif0
795 $atf_ifconfig vlan0 -vlanif
796
797 #
798 # clear IFF_PROMISC after bpf_detach called from ether_ifdetach
799 #
800 $atf_ifconfig vlan0 vlan 1 vlanif shmif0
801 $atf_ifconfig vlan0 up
802
803 atf_check -s exit:0 -e match:'bpf opened' $bpfopen -p $pidfile vlan0
804
805 atf_check -s exit:0 -o match:'PROMISC' rump.ifconfig vlan0
806 atf_check -s exit:0 -o match:'PROMISC' rump.ifconfig shmif0
807
808 $atf_ifconfig vlan0 -vlanif
809
810 atf_check -s exit:0 -o not-match:'PROMISC' rump.ifconfig vlan0
811 atf_check -s exit:0 -o not-match:'PROMISC' rump.ifconfig shmif0
812
813 atf_check -s exit:0 kill -TERM $(cat $pidfile)
814 sleep 2
815 atf_check -s exit:0 -o not-match:'PROMISC' rump.ifconfig vlan0
816 }
817
818 vlan_l2tp_body_common()
819 {
820 local atf_ifconfig="atf_check -s exit:0 rump.ifconfig"
821
822 local af=$1
823 local ping_cmd="rump.ping -c 1"
824 local pfx=24
825 local local0=$IP_LOCAL0
826 local local1=$IP_LOCAL1
827 local remote0=$IP_REMOTE0
828 local remote1=$IP_REMOTE1
829 local sysctl_param="net.inet.ip.dad_count=0"
830 local vid0=10
831 local vid1=11
832
833 local l2tp_laddr=10.222.222.1
834 local l2tp_lsession=1001
835 local l2tp_raddr=10.222.222.2
836 local l2tp_rsession=1002
837
838 if [ x"$af" = x"inet6" ]; then
839 ping_cmd="rump.ping6 -c 1"
840 rumplib="netinet6"
841 pfx=64
842 local0=$IP6_LOCAL0
843 local1=$IP6_LOCAL1
844 remote0=$IP6_REMOTE0
845 remote1=$IP6_REMOTE1
846 sysctl_param="net.inet6.ip6.dad_count=0"
847 fi
848
849 rump_server_add_iface $SOCK_LOCAL shmif0 $BUS
850 rump_server_add_iface $SOCK_LOCAL l2tp0
851 rump_server_add_iface $SOCK_LOCAL vlan0
852 rump_server_add_iface $SOCK_LOCAL vlan1
853
854 rump_server_add_iface $SOCK_REMOTE shmif0 $BUS
855 rump_server_add_iface $SOCK_REMOTE l2tp0
856 rump_server_add_iface $SOCK_REMOTE vlan0
857 rump_server_add_iface $SOCK_REMOTE vlan1
858
859 export RUMP_SERVER=$SOCK_LOCAL
860 atf_check -s exit:0 -o ignore rump.sysctl -w $sysctl_param
861 $atf_ifconfig shmif0 $l2tp_laddr/24
862 $atf_ifconfig l2tp0 tunnel $l2tp_laddr $l2tp_raddr
863 $atf_ifconfig l2tp0 session $l2tp_lsession $l2tp_rsession
864 $atf_ifconfig l2tp0 up
865
866 export RUMP_SERVER=$SOCK_REMOTE
867 atf_check -s exit:0 -o ignore rump.sysctl -w $sysctl_param
868 $atf_ifconfig shmif0 $l2tp_raddr/24
869 $atf_ifconfig l2tp0 tunnel $l2tp_raddr $l2tp_laddr
870 $atf_ifconfig l2tp0 session $l2tp_rsession $l2tp_lsession
871 $atf_ifconfig l2tp0 up
872
873 # configure vlans on l2tp(4)
874 export RUMP_SERVER=$SOCK_LOCAL
875 $atf_ifconfig vlan0 vlan $vid0 vlanif l2tp0
876 $atf_ifconfig vlan0 $af $local0/$pfx
877 $atf_ifconfig vlan1 vlan $vid1 vlanif l2tp0
878 $atf_ifconfig vlan1 $af $local1/$pfx
879 export RUMP_SERVER=$SOCK_REMOTE
880 $atf_ifconfig vlan0 vlan $vid0 vlanif l2tp0
881 $atf_ifconfig vlan0 $af $remote0/$pfx
882 $atf_ifconfig vlan1 vlan $vid1 vlanif l2tp0
883 $atf_ifconfig vlan1 $af $remote1/$pfx
884
885 # test for VLAN frame transfer
886 export RUMP_SERVER=$SOCK_LOCAL
887 atf_check -s exit:0 -o ignore $ping_cmd $remote0
888 atf_check -s exit:0 -o ignore $ping_cmd $remote1
889
890 # unconfig vlans
891 export RUMP_SERVER=$SOCK_LOCAL
892 $atf_ifconfig vlan0 -vlanif
893 export RUMP_SERVER=$SOCK_REMOTE
894 $atf_ifconfig vlan0 -vlanif
895
896 # remove l2tp0 that has vlan1
897 export RUMP_SERVER=$SOCK_LOCAL
898 $atf_ifconfig l2tp0 destroy
899 export RUMP_SERVER=$SOCK_REMOTE
900 $atf_ifconfig l2tp0 destroy
901 }
902
903 test_l2tp()
904 {
905
906 rump_server_start $SOCK_LOCAL vlan l2tp
907 rump_server_start $SOCK_REMOTE vlan l2tp
908
909 vlan_l2tp_body_common "inet"
910 }
911
912 test_l2tp6()
913 {
914
915 rump_server_start $SOCK_LOCAL vlan l2tp netinet6
916 rump_server_start $SOCK_REMOTE vlan l2tp netinet6
917
918 vlan_l2tp_body_common "inet6"
919 }
920
921 check_link_state()
922 {
923 local ifname=$1
924 local state=$2
925
926 atf_check -s exit:0 -o match:"linkstate: $state" $HIJACKING rump.ifconfig -v $ifname
927 }
928
929 create_interfaces()
930 {
931
932 atf_check -s exit:0 rump.ifconfig vlan0 create
933 atf_check -s exit:0 rump.ifconfig shmif0 create
934 }
935
936 destroy_interfaces()
937 {
938
939 atf_check -s exit:0 rump.ifconfig vlan0 destroy
940 atf_check -s exit:0 rump.ifconfig shmif0 destroy
941 }
942
943 test_link_state_sync()
944 {
945 local ifconfig="atf_check -s exit:0 rump.ifconfig"
946
947 rump_server_start $SOCK_LOCAL vlan
948
949 export RUMP_SERVER=${SOCK_LOCAL}
950
951 ## Alone
952 $ifconfig vlan0 create
953 # The default state is "down"
954 check_link_state vlan0 down
955 $ifconfig vlan0 up
956 check_link_state vlan0 down
957 $ifconfig vlan0 down
958 check_link_state vlan0 down
959 $ifconfig vlan0 destroy
960
961 ## "unknown" parent
962 create_interfaces
963 # shmif0 is "unknown" until ifconfig linkstr
964 check_link_state shmif0 unknown
965 $ifconfig vlan0 vlan 1 vlanif shmif0
966 # vlan0 syncs with the parent
967 check_link_state vlan0 unknown
968 $ifconfig vlan0 up
969 check_link_state vlan0 unknown
970 $ifconfig vlan0 -vlanif
971 # Back to the default
972 check_link_state vlan0 down
973 destroy_interfaces
974
975 ## "up" parent
976 create_interfaces
977 $ifconfig shmif0 linkstr $BUS
978 check_link_state shmif0 up
979 $ifconfig vlan0 vlan 1 vlanif shmif0
980 # vlan0 syncs with the parent
981 check_link_state vlan0 up
982 $ifconfig vlan0 -vlanif
983 # Back to the default
984 check_link_state vlan0 down
985 destroy_interfaces
986
987 ## Change parent's link state to "up", "down", then "up"
988 create_interfaces
989 $ifconfig shmif0 linkstr $BUS
990 check_link_state shmif0 up
991 $ifconfig vlan0 vlan 1 vlanif shmif0
992 check_link_state vlan0 up
993 # Down the parent
994 $ifconfig shmif0 media none
995 check_link_state shmif0 down
996 # vlan0 syncs with the parent
997 check_link_state vlan0 down
998 # Up the parent again
999 $ifconfig shmif0 media auto
1000 # vlan0 syncs with the parent
1001 check_link_state vlan0 up
1002 $ifconfig vlan0 -vlanif
1003 # Back to the default
1004 check_link_state vlan0 down
1005 destroy_interfaces
1006 }
1007
1008 add_test()
1009 {
1010 local name=$1
1011 local desc="$2"
1012
1013 atf_test_case "vlan_${name}" cleanup
1014 eval "vlan_${name}_head() {
1015 atf_set descr \"${desc}\"
1016 atf_set require.progs rump_server
1017 }
1018 vlan_${name}_body() {
1019 test_${name}
1020 }
1021 vlan_${name}_cleanup() {
1022 \$DEBUG && dump
1023 cleanup
1024 }"
1025 atf_add_test_case "vlan_${name}"
1026 }
1027
1028 atf_init_test_cases()
1029 {
1030
1031 add_test create_destroy "tests of creation and deletion of vlan interface"
1032 add_test basic "tests of communications over vlan interfaces"
1033 add_test auto_follow_mtu "tests of setting vlan mtu using IPv4"
1034 add_test vlanid "tests of configuration for vlan id"
1035 add_test configs "tests of configuration except vlan id"
1036 add_test bridge "tests of vlan interfaces with bridges (IPv4)"
1037 add_test multicast "tests of multicast address adding and deleting"
1038 add_test l2tp "tests of vlan(IPv4) over l2tp(IPv4)"
1039
1040 add_test create_destroy6 "tests of creation and deletion of vlan interface with IPv6"
1041 add_test basic6 "tests of communications over vlan interfaces using IPv6"
1042 add_test auto_follow_mtu6 "tests of setting vlan mtu using IPv6"
1043 add_test vlanid6 "tests of configuration for vlan id using IPv6"
1044 add_test configs6 "tests of configuration except vlan id using IPv6"
1045 add_test bridge6 "tests of vlan interfaces with bridges (IPv6)"
1046 add_test multicast6 "tests of multicast address adding and deleting with IPv6"
1047 add_test l2tp6 "tests of vlan(IPv6) over l2tp(IPv4)"
1048
1049 add_test promisc "tests of IFF_PROMISC of vlan"
1050 add_test link_state_sync "tests of link state sync with its parent"
1051 }
1052