xref: /netbsd-src/tests/net/if_vlan/t_vlan.sh (revision bdc22b2e01993381dcefeff2bc9b56ca75a4235c)
1#	$NetBSD: t_vlan.sh,v 1.11 2018/06/14 08:38:24 yamaguchi 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
28BUS=bus
29SOCK_LOCAL=unix://commsock1
30SOCK_REMOTE=unix://commsock2
31IP_LOCAL0=10.0.0.1
32IP_LOCAL1=10.0.1.1
33IP_REMOTE0=10.0.0.2
34IP_REMOTE1=10.0.1.2
35IP_MCADDR0=224.0.0.10
36IP6_LOCAL0=fc00:0::1
37IP6_LOCAL1=fc00:1::1
38IP6_REMOTE0=fc00:0::2
39IP6_REMOTE1=fc00:1::2
40IP6_MCADDR0=ff11::10
41ETH_IP_MCADDR0=01:00:5e:00:00:0a
42ETH_IP6_MCADDR0=33:33:00:00:00:10
43
44DEBUG=${DEBUG:-false}
45
46vlan_create_destroy_body_common()
47{
48	export RUMP_SERVER=${SOCK_LOCAL}
49
50	atf_check -s exit:0 rump.ifconfig vlan0 create
51	atf_check -s exit:0 rump.ifconfig vlan0 destroy
52
53	atf_check -s exit:0 rump.ifconfig vlan0 create
54	atf_check -s exit:0 rump.ifconfig vlan0 up
55	atf_check -s exit:0 rump.ifconfig vlan0 down
56	atf_check -s exit:0 rump.ifconfig vlan0 destroy
57
58	atf_check -s exit:0 rump.ifconfig shmif0 create
59	atf_check -s exit:0 rump.ifconfig vlan0 create
60	atf_check -s exit:0 rump.ifconfig vlan0 vlan 1 vlanif shmif0
61	atf_check -s exit:0 rump.ifconfig vlan0 up
62	atf_check -s exit:0 rump.ifconfig vlan0 destroy
63
64	# more than one vlan interface with a same parent interface
65	atf_check -s exit:0 rump.ifconfig shmif1 create
66	atf_check -s exit:0 rump.ifconfig vlan0 create
67	atf_check -s exit:0 rump.ifconfig vlan0 vlan 10 vlanif shmif0
68	atf_check -s exit:0 rump.ifconfig vlan1 create
69	atf_check -s exit:0 rump.ifconfig vlan1 vlan 11 vlanif shmif0
70
71	# more than one interface with another parent interface
72	atf_check -s exit:0 rump.ifconfig vlan2 create
73	atf_check -s exit:0 rump.ifconfig vlan2 vlan 12 vlanif shmif1
74	atf_check -s exit:0 rump.ifconfig vlan3 create
75	atf_check -s exit:0 rump.ifconfig vlan3 vlan 13 vlanif shmif1
76	atf_check -s exit:0 rump.ifconfig shmif0 destroy
77	atf_check -s exit:0 -o not-match:'shmif0' rump.ifconfig vlan0
78	atf_check -s exit:0 -o not-match:'shmif0' rump.ifconfig vlan1
79	atf_check -s exit:0 -o match:'shmif1' rump.ifconfig vlan2
80	atf_check -s exit:0 -o match:'shmif1' rump.ifconfig vlan3
81	atf_check -s exit:0 rump.ifconfig vlan0 destroy
82	atf_check -s exit:0 rump.ifconfig vlan1 destroy
83	atf_check -s exit:0 rump.ifconfig vlan2 destroy
84	atf_check -s exit:0 rump.ifconfig vlan3 destroy
85
86}
87
88atf_test_case vlan_create_destroy cleanup
89vlan_create_destroy_head()
90{
91
92	atf_set "descr" "tests of creation and deletion of vlan interface"
93	atf_set "require.progs" "rump_server"
94}
95
96vlan_create_destroy_body()
97{
98	rump_server_start $SOCK_LOCAL vlan
99
100	vlan_create_destroy_body_common
101}
102
103
104vlan_create_destroy_cleanup()
105{
106
107	$DEBUG && dump
108	cleanup
109}
110
111atf_test_case vlan_create_destroy6 cleanup
112vlan_create_destroy6_head()
113{
114
115	atf_set "descr" "tests of creation and deletion of vlan interface with IPv6"
116	atf_set "require.progs" "rump_server"
117}
118
119vlan_create_destroy6_body()
120{
121
122	rump_server_start $SOCK_LOCAL vlan netinet6
123
124	vlan_create_destroy_body_common
125}
126
127vlan_create_destroy6_cleanup()
128{
129
130	$DEBUG && dump
131	cleanup
132}
133
134vlan_basic_body_common()
135{
136	local outfile=./out
137	local af=inet
138	local prefix=24
139	local local0=$IP_LOCAL0
140	local remote0=$IP_REMOTE0
141	local ping_cmd="rump.ping -n -w 1 -c 1"
142
143	if [ x"$1" = x"inet6" ]; then
144		af="inet6"
145		prefix=64
146		local0=$IP6_LOCAL0
147		remote0=$IP6_REMOTE0
148		ping_cmd="rump.ping6 -n -c 1"
149	fi
150
151	rump_server_add_iface $SOCK_LOCAL shmif0 $BUS
152	rump_server_add_iface $SOCK_REMOTE shmif0 $BUS
153
154	export RUMP_SERVER=$SOCK_LOCAL
155	atf_check -s exit:0 rump.ifconfig shmif0 up
156	export RUMP_SERVER=$SOCK_REMOTE
157	atf_check -s exit:0 rump.ifconfig shmif0 up
158
159	export RUMP_SERVER=$SOCK_LOCAL
160	atf_check -s exit:0 rump.ifconfig vlan0 create
161	atf_check -s exit:0 rump.ifconfig vlan0 vlan 10 vlanif shmif0
162	atf_check -s exit:0 rump.ifconfig vlan0 $af $local0/$prefix
163	atf_check -s exit:0 rump.ifconfig vlan0 up
164	atf_check -s exit:0 rump.ifconfig -w 10
165
166	export RUMP_SERVER=$SOCK_REMOTE
167	atf_check -s exit:0 rump.ifconfig vlan0 create
168	atf_check -s exit:0 rump.ifconfig vlan0 vlan 10 vlanif shmif0
169	atf_check -s exit:0 rump.ifconfig vlan0 $af $remote0/$prefix
170	atf_check -s exit:0 rump.ifconfig vlan0 up
171	atf_check -s exit:0 rump.ifconfig -w 10
172
173	extract_new_packets $BUS > $outfile
174
175	export RUMP_SERVER=$SOCK_LOCAL
176	atf_check -s exit:0 -o ignore $ping_cmd $remote0
177
178	extract_new_packets $BUS > $outfile
179	atf_check -s exit:0 -o match:'vlan 10' cat $outfile
180
181	atf_check -s exit:0 rump.ifconfig vlan0 -vlanif
182	atf_check -s exit:0 rump.ifconfig vlan0 vlan 20 vlanif shmif0
183	atf_check -s exit:0 rump.ifconfig vlan0 $af $local0/$prefix
184	atf_check -s exit:0 rump.ifconfig vlan0 up
185	atf_check -s exit:0 rump.ifconfig -w 10
186
187	extract_new_packets $BUS > $outfile
188	atf_check -s not-exit:0 -o ignore $ping_cmd $remote0
189
190	extract_new_packets $BUS > $outfile
191	atf_check -s exit:0 -o match:'vlan 20' cat $outfile
192
193	export RUMP_SERVER=$SOCK_LOCAL
194	atf_check -s exit:0 rump.ifconfig vlan0 -vlanif
195	atf_check -s exit:0 rump.ifconfig vlan0 vlan 10 vlanif shmif0
196	atf_check -s exit:0 rump.ifconfig vlan0 $af $local0/$prefix
197	atf_check -s exit:0 rump.ifconfig vlan0 up
198	atf_check -s exit:0 rump.ifconfig -w 10
199
200	atf_check -s exit:0 -o ignore rump.ifconfig -z vlan0
201	atf_check -s exit:0 -o ignore $ping_cmd $remote0
202	rump.ifconfig -v vlan0 > $outfile
203
204	atf_check -s exit:0 -o not-match:' 0 packets' cat $outfile
205	atf_check -s exit:0 -o not-match:' 0 bytes' cat $outfile
206}
207
208atf_test_case vlan_basic cleanup
209vlan_basic_head()
210{
211
212	atf_set "descr" "tests of communications over vlan interfaces"
213	atf_set "require.progs" "rump_server"
214}
215
216vlan_basic_body()
217{
218	rump_server_start $SOCK_LOCAL vlan
219	rump_server_start $SOCK_REMOTE vlan
220
221	vlan_basic_body_common inet
222
223}
224
225vlan_basic_cleanup()
226{
227
228	$DEBUG && dump
229	cleanup
230}
231
232atf_test_case vlan_basic6 cleanup
233vlan_basic6_head()
234{
235
236	atf_set "descr" "tests of communications over vlan interfaces using IPv6"
237	atf_set "require.progs" "rump_server"
238}
239
240vlan_basic6_body()
241{
242	rump_server_start $SOCK_LOCAL vlan netinet6
243	rump_server_start $SOCK_REMOTE vlan netinet6
244
245	vlan_basic_body_common inet6
246}
247
248vlan_basic6_cleanup()
249{
250
251	$DEBUG && dump
252	cleanup
253}
254
255vlanid_config_and_ping()
256{
257	local vlanid=$1
258	shift
259
260	export RUMP_SERVER=$SOCK_LOCAL
261	atf_check -s exit:0 rump.ifconfig vlan0 vlan $vlanid vlanif shmif0
262	atf_check -s exit:0 rump.ifconfig vlan0 $IP_LOCAL0/24
263	atf_check -s exit:0 rump.ifconfig vlan0 up
264
265	export RUMP_SERVER=$SOCK_REMOTE
266	atf_check -s exit:0 rump.ifconfig vlan0 vlan $vlanid vlanif shmif0
267	atf_check -s exit:0 rump.ifconfig vlan0 $IP_REMOTE0/24
268	atf_check -s exit:0 rump.ifconfig vlan0 up
269
270	export RUMP_SERVER=$SOCK_LOCAL
271	atf_check -s exit:0 -o ignore rump.ping -n -w 1 -c 1 $IP_REMOTE0
272	atf_check -s exit:0 rump.ifconfig vlan0 -vlanif
273
274	export RUMP_SERVER=$SOCK_REMOTE
275	atf_check -s exit:0 rump.ifconfig vlan0 -vlanif
276}
277
278vlanid_config_and_ping6()
279{
280	local vlanid=$1
281	shift
282
283	export RUMP_SERVER=$SOCK_LOCAL
284	atf_check -s exit:0 rump.ifconfig vlan0 vlan $vlanid vlanif shmif0
285	atf_check -s exit:0 rump.ifconfig vlan0 inet6 $IP6_LOCAL0/64
286	atf_check -s exit:0 rump.ifconfig vlan0 up
287
288	export RUMP_SERVER=$SOCK_REMOTE
289	atf_check -s exit:0 rump.ifconfig vlan0 vlan $vlanid vlanif shmif0
290	atf_check -s exit:0 rump.ifconfig vlan0 inet6 $IP6_REMOTE0/64
291	atf_check -s exit:0 rump.ifconfig vlan0 up
292
293	export RUMP_SERVER=$SOCK_LOCAL
294	atf_check -s exit:0 -o ignore rump.ping6 -n -c 1 $IP6_REMOTE0
295	atf_check -s exit:0 rump.ifconfig vlan0 -vlanif
296
297	export RUMP_SERVER=$SOCK_REMOTE
298	atf_check -s exit:0 rump.ifconfig vlan0 -vlanif
299}
300
301vlan_vlanid_body_common()
302{
303	local af=inet
304	local prefix=24
305	local sysctl_param="net.inet.ip.dad_count=0"
306	local ping_cmd="rump.ping -n -w 1 -c 1"
307	local config_and_ping=vlanid_config_and_ping
308	local local0=$IP_LOCAL0
309	local local1=$IP_LOCAL1
310	local remote0=$IP_REMOTE0
311	local remote1=$IP_REMOTE1
312
313	if [ x"$1" = x"inet6" ]; then
314		af=inet6
315		prefix=64
316		sysctl_param="net.inet6.ip6.dad_count=0"
317		ping_cmd="rump.ping6 -n -c 1"
318		config_and_ping=vlanid_config_and_ping6
319		local0=$IP6_LOCAL0
320		local1=$IP6_LOCAL1
321		remote0=$IP6_REMOTE0
322		remote1=$IP6_REMOTE1
323	fi
324
325	rump_server_add_iface $SOCK_LOCAL shmif0 $BUS
326	rump_server_add_iface $SOCK_REMOTE shmif0 $BUS
327
328	export RUMP_SERVER=$SOCK_LOCAL
329	atf_check -s exit:0 -o ignore rump.sysctl -w $sysctl_param
330	atf_check -s exit:0 rump.ifconfig shmif0 up
331	atf_check -s exit:0 rump.ifconfig vlan0 create
332
333	export RUMP_SERVER=$SOCK_REMOTE
334	atf_check -s exit:0 -o ignore rump.sysctl -w $sysctl_param
335	atf_check -s exit:0 rump.ifconfig shmif0 up
336	atf_check -s exit:0 rump.ifconfig vlan0 create
337
338	export RUMP_SERVER=$SOCK_LOCAL
339	atf_check -s not-exit:0 -e ignore\
340	    rump.ifconfig vlan0 vlan -1 vlanif shmif0
341
342	# $config_and_ping 0 # reserved vlan id
343	$config_and_ping 1
344	$config_and_ping 4094
345	# $config_and_ping 4095 #reserved vlan id
346
347	if [ "${RANDOM:-0}" != "${RANDOM:-0}" ]
348	then
349		for TAG in $(( ${RANDOM:-0} % 4092 + 2 )) \
350			   $(( ${RANDOM:-0} % 4092 + 2 )) \
351			   $(( ${RANDOM:-0} % 4092 + 2 ))
352		do
353			$config_and_ping "${TAG}"
354		done
355	fi
356
357	export RUMP_SERVER=$SOCK_LOCAL
358	for TAG in 0 4095 4096 $((4096*4 + 1)) 65536 65537 $((65536 + 4095))
359	do
360		atf_check -s not-exit:0 -e not-empty \
361		    rump.ifconfig vlan0 vlan "${TAG}" vlanif shmif0
362	done
363
364	atf_check -s exit:0 rump.ifconfig vlan0 vlan 1 vlanif shmif0
365	atf_check -s not-exit:0 -e ignore \
366	    rump.ifconfig vlan0 vlan 2 vlanif shmif0
367
368	atf_check -s not-exit:0 -e ignore \
369	    rump.ifconfig vlan0 vlan 1 vlanif shmif1
370
371	atf_check -s exit:0 rump.ifconfig vlan0 -vlanif
372	atf_check -s not-exit:0 -e ignore \
373	    rump.ifconfig vlan0 $local0/$prefix
374
375	export RUMP_SERVER=$SOCK_LOCAL
376	atf_check -s exit:0 rump.ifconfig vlan0 vlan 10 vlanif shmif0
377	atf_check -s exit:0 rump.ifconfig vlan0 $af $local0/$prefix
378	atf_check -s exit:0 rump.ifconfig vlan0 up
379	atf_check -s exit:0 rump.ifconfig vlan1 create
380	atf_check -s exit:0 rump.ifconfig vlan1 vlan 11 vlanif shmif0
381	atf_check -s exit:0 rump.ifconfig vlan1 $af $local1/$prefix
382	atf_check -s exit:0 rump.ifconfig vlan1 up
383
384	export RUMP_SERVER=$SOCK_REMOTE
385	atf_check -s exit:0 rump.ifconfig vlan0 -vlanif
386	atf_check -s exit:0 rump.ifconfig vlan0 vlan 10 vlanif shmif0
387	atf_check -s exit:0 rump.ifconfig vlan0 $af $remote0/$prefix
388	atf_check -s exit:0 rump.ifconfig vlan0 up
389	atf_check -s exit:0 rump.ifconfig vlan1 create
390	atf_check -s exit:0 rump.ifconfig vlan1 vlan 11 vlanif shmif0
391	atf_check -s exit:0 rump.ifconfig vlan1 $af $remote1/$prefix
392	atf_check -s exit:0 rump.ifconfig vlan1 up
393
394	export RUMP_SERVER=$SOCK_LOCAL
395	atf_check -s exit:0 -o ignore $ping_cmd $remote0
396	atf_check -s exit:0 -o ignore $ping_cmd $remote1
397}
398
399atf_test_case vlan_vlanid cleanup
400vlan_vlanid_head()
401{
402
403	atf_set "descr" "tests of configuration for vlan id"
404	atf_set "require.progs" "rump_server"
405}
406
407vlan_vlanid_body()
408{
409	rump_server_start $SOCK_LOCAL vlan
410	rump_server_start $SOCK_REMOTE vlan
411
412	vlan_vlanid_body_common inet
413}
414
415vlan_vlanid_cleanup()
416{
417
418	$DEBUG && dump
419	cleanup
420}
421
422atf_test_case vlan_vlanid6 cleanup
423vlan_vlanid6_head()
424{
425
426	atf_set "descr" "tests of configuration for vlan id using IPv6"
427	atf_set "require.progs" "rump_server"
428}
429
430
431vlan_vlanid6_body()
432{
433	rump_server_start $SOCK_LOCAL vlan netinet6
434	rump_server_start $SOCK_REMOTE vlan netinet6
435
436	vlan_vlanid_body_common inet6
437}
438
439vlan_vlanid6_cleanup()
440{
441
442	$DEBUG && dump
443	cleanup
444}
445
446vlan_configs_body_common()
447{
448	export RUMP_SERVER=${SOCK_LOCAL}
449
450	atf_check -s exit:0 rump.ifconfig shmif0 create
451	atf_check -s exit:0 rump.ifconfig shmif1 create
452	atf_check -s exit:0 rump.ifconfig vlan0 create
453
454	atf_check -s exit:0 rump.ifconfig vlan0 vlan 10 vlanif shmif0
455	atf_check -s exit:0 rump.ifconfig vlan0 -vlanif
456
457	atf_check -s exit:0 rump.ifconfig vlan0 vlan 10 vlanif shmif0
458	atf_check -s exit:0 rump.ifconfig vlan0 -vlanif shmif0
459
460	atf_check -s exit:0 rump.ifconfig vlan0 vlan 10 vlanif shmif0
461	atf_check -s exit:0 -e ignore rump.ifconfig vlan0 -vlanif shmif1
462	atf_check -s exit:0 -e ignore rump.ifconfig vlan0 -vlanif shmif2
463
464	atf_check -s exit:0 rump.ifconfig vlan0 -vlanif
465
466	atf_check -s exit:0 rump.ifconfig vlan0 vlan 10 vlanif shmif0
467	atf_check -s exit:0 -e match:'Invalid argument' \
468	    rump.ifconfig vlan0 mtu 1497
469	atf_check -s exit:0 rump.ifconfig vlan0 mtu 1496
470	atf_check -s exit:0 rump.ifconfig vlan0 mtu 42
471	atf_check -s exit:0 -e match:'Invalid argument' \
472	    rump.ifconfig vlan0 mtu 41
473	atf_check -s exit:0 rump.ifconfig vlan0 -vlanif
474
475	atf_check -s exit:0 rump.ifconfig vlan1 create
476	atf_check -s exit:0 rump.ifconfig vlan0 vlan 10 vlanif shmif0
477	atf_check -s not-exit:0 -e match:'File exists' \
478	    rump.ifconfig vlan1 vlan 10 vlanif shmif0
479	atf_check -s exit:0 rump.ifconfig vlan1 vlan 10 vlanif shmif1
480
481	atf_check -s exit:0 rump.ifconfig vlan1 -vlanif shmif1
482	atf_check -s exit:0 rump.ifconfig vlan1 vlan 10 vlanif shmif1
483
484	atf_check -s exit:0 rump.ifconfig vlan0 -vlanif shmif0
485	atf_check -s exit:0 rump.ifconfig vlan0 vlan 10 vlanif shmif0
486}
487
488atf_test_case vlan_configs cleanup
489vlan_configs_head()
490{
491	atf_set "descr" "tests of configuration except vlan id"
492	atf_set "require.progs" "rump_server"
493}
494
495vlan_configs_body()
496{
497
498	rump_server_start $SOCK_LOCAL vlan
499
500	vlan_configs_body_common
501
502}
503
504vlan_configs_cleanup()
505{
506
507	$DEBUG && dump
508	cleanup
509}
510
511atf_test_case vlan_configs6 cleanup
512vlan_configs6_head()
513{
514	atf_set "descr" "tests of configuration except vlan id using IPv6"
515	atf_set "require.progs" "rump_server"
516}
517
518vlan_configs6_body()
519{
520	rump_server_start $SOCK_LOCAL vlan netinet6
521
522	vlan_configs_body_common
523}
524
525vlan_configs6_cleanup()
526{
527	$DEBUG && dump
528	cleanup
529}
530
531vlan_bridge_body_common()
532{
533
534	rump_server_add_iface $SOCK_LOCAL shmif0 $BUS
535
536	export RUMP_SERVER=$SOCK_LOCAL
537	atf_check -s exit:0 rump.ifconfig shmif0 up
538
539	atf_check -s exit:0 rump.ifconfig vlan0 create
540	atf_check -s exit:0 rump.ifconfig vlan0 vlan 10 vlanif shmif0
541	atf_check -s exit:0 rump.ifconfig vlan0 up
542	$DEBUG && rump.ifconfig vlan0
543
544	atf_check -s exit:0 rump.ifconfig bridge0 create
545	# Adjust to the MTU of a vlan on a shmif
546	atf_check -s exit:0 rump.ifconfig bridge0 mtu 1496
547	atf_check -s exit:0 rump.ifconfig bridge0 up
548	# Test brconfig add
549	atf_check -s exit:0 $HIJACKING brconfig bridge0 add vlan0
550	$DEBUG && brconfig bridge0
551	# Test brconfig delete
552	atf_check -s exit:0 $HIJACKING brconfig bridge0 delete vlan0
553
554	atf_check -s exit:0 $HIJACKING brconfig bridge0 add vlan0
555	# Test vlan destruction with bridge
556	atf_check -s exit:0 rump.ifconfig vlan0 destroy
557
558	rump_server_destroy_ifaces
559}
560
561atf_test_case vlan_bridge cleanup
562vlan_bridge_head()
563{
564
565	atf_set "descr" "tests of vlan interfaces with bridges (IPv4)"
566	atf_set "require.progs" "rump_server"
567}
568
569vlan_bridge_body()
570{
571
572	rump_server_start $SOCK_LOCAL vlan bridge
573	vlan_bridge_body_common
574}
575
576vlan_bridge_cleanup()
577{
578
579	$DEBUG && dump
580	cleanup
581}
582
583atf_test_case vlan_bridge6 cleanup
584vlan_bridge6_head()
585{
586
587	atf_set "descr" "tests of vlan interfaces with bridges (IPv6)"
588	atf_set "require.progs" "rump_server"
589}
590
591vlan_bridge6_body()
592{
593
594	rump_server_start $SOCK_LOCAL vlan netinet6 bridge
595	vlan_bridge_body_common
596}
597
598vlan_bridge6_cleanup()
599{
600
601	$DEBUG && dump
602	cleanup
603}
604
605vlan_multicast_body_common()
606{
607
608	local af="inet"
609	local local0=$IP_LOCAL0
610	local local1=$IP_LOCAL1
611	local mcaddr=$IP_MCADDR0
612	local eth_mcaddr=$ETH_IP_MCADDR0
613	local prefix=24
614	local siocXmulti="$(atf_get_srcdir)/siocXmulti"
615
616	if [ x"$1" =  x"inet6" ]; then
617		af="inet6"
618		prefix=64
619		local0=$IP6_LOCAL0
620		local1=$IP6_LOCAL1
621		mcaddr=$IP6_MCADDR0
622		eth_mcaddr=$ETH_IP6_MCADDR0
623	fi
624
625	export RUMP_SERVER=$SOCK_LOCAL
626
627	atf_check -s exit:0 rump.ifconfig shmif0 create
628	atf_check -s exit:0 rump.ifconfig shmif0 linkstr net0 up
629	atf_check -s exit:0 rump.ifconfig vlan0 create
630	atf_check -s exit:0 rump.ifconfig vlan0 vlan 10 vlanif shmif0
631	atf_check -s exit:0 rump.ifconfig vlan0 $af $local0/$prefix up
632	atf_check -s exit:0 rump.ifconfig vlan1 create
633	atf_check -s exit:0 rump.ifconfig vlan1 vlan 11 vlanif shmif0
634	atf_check -s exit:0 rump.ifconfig vlan1 $af $local1/$prefix up
635	atf_check -s exit:0 rump.ifconfig -w 10
636
637	# check the initial state
638	atf_check -s exit:0 -o not-match:"$eth_mcaddr" $HIJACKING ifmcstat
639
640	# add a multicast address
641	atf_check -s exit:0 $HIJACKING $siocXmulti add vlan0 $mcaddr
642	atf_check -s exit:0 -o match:"$eth_mcaddr" $HIJACKING ifmcstat
643
644	# delete the address
645	atf_check -s exit:0 $HIJACKING $siocXmulti del vlan0 $mcaddr
646	atf_check -s exit:0 -o not-match:"$eth_mcaddr" $HIJACKING ifmcstat
647
648	# delete a non-existing address
649	atf_check -s not-exit:0 -e ignore $HIJACKING $siocXmulti del vlan0 $mcaddr
650
651	# add an address to different interfaces
652	atf_check -s exit:0 $HIJACKING $siocXmulti add vlan0 $mcaddr
653	atf_check -s exit:0 $HIJACKING $siocXmulti add vlan1 $mcaddr
654	atf_check -s exit:0 -o match:"${eth_mcaddr}: 2" $HIJACKING ifmcstat
655	atf_check -s exit:0 $HIJACKING $siocXmulti del vlan0 $mcaddr
656
657	# delete the address with invalid interface
658	atf_check -s not-exit:0 -e match:"Invalid argument" \
659	    $HIJACKING $siocXmulti del vlan0 $mcaddr
660
661	atf_check -s exit:0 $HIJACKING $siocXmulti del vlan1 $mcaddr
662
663	# add and delete a same address more than once
664	atf_check -s exit:0 $HIJACKING $siocXmulti add vlan0 $mcaddr
665	atf_check -s exit:0 $HIJACKING $siocXmulti add vlan0 $mcaddr
666	atf_check -s exit:0 $HIJACKING $siocXmulti add vlan0 $mcaddr
667	atf_check -s exit:0 -o match:"${eth_mcaddr}: 3" $HIJACKING ifmcstat
668	atf_check -s exit:0 $HIJACKING $siocXmulti del vlan0 $mcaddr
669	atf_check -s exit:0 $HIJACKING $siocXmulti del vlan0 $mcaddr
670	atf_check -s exit:0 $HIJACKING $siocXmulti del vlan0 $mcaddr
671	atf_check -s exit:0 -o not-match:"$eth_mcaddr" $HIJACKING ifmcstat
672
673	# delete all address added to parent device when remove
674	# the config of parent interface
675	atf_check -s exit:0 $HIJACKING $siocXmulti add vlan0 $mcaddr
676	atf_check -s exit:0 $HIJACKING $siocXmulti add vlan0 $mcaddr
677	atf_check -s exit:0 $HIJACKING $siocXmulti add vlan0 $mcaddr
678	atf_check -s exit:0 rump.ifconfig vlan0 -vlanif shmif0
679	atf_check -s exit:0 -o not-match:"$eth_mcaddr" $HIJACKING ifmcstat
680}
681
682atf_test_case vlan_multicast cleanup
683vlan_multicast_head()
684{
685	atf_set "descr" "tests of multicast address adding and deleting"
686	atf_set "require.progs" "rump_server"
687}
688
689vlan_multicast_body()
690{
691	rump_server_start $SOCK_LOCAL vlan
692
693	vlan_multicast_body_common inet
694}
695
696vlan_multicast_cleanup()
697{
698	$DEBUG && dump
699	cleanup
700}
701
702atf_test_case vlan_multicast6 cleanup
703vlan_multicast6_head()
704{
705	atf_set "descr" "tests of multicast address adding and deleting with IPv6"
706	atf_set "require.progs" "rump_server"
707}
708
709vlan_multicast6_body()
710{
711	rump_server_start $SOCK_LOCAL vlan netinet6
712
713	vlan_multicast_body_common inet6
714}
715
716vlan_multicast6_cleanup()
717{
718	$DEBUG && dump
719	cleanup
720}
721
722atf_init_test_cases()
723{
724
725	atf_add_test_case vlan_create_destroy
726	atf_add_test_case vlan_basic
727	atf_add_test_case vlan_vlanid
728	atf_add_test_case vlan_configs
729	atf_add_test_case vlan_bridge
730	atf_add_test_case vlan_multicast
731
732	atf_add_test_case vlan_create_destroy6
733	atf_add_test_case vlan_basic6
734	atf_add_test_case vlan_vlanid6
735	atf_add_test_case vlan_configs6
736	atf_add_test_case vlan_bridge6
737	atf_add_test_case vlan_multicast6
738}
739