Home | History | Annotate | Line # | Download | only in if_vlan
t_vlan.sh revision 1.18
      1 #	$NetBSD: t_vlan.sh,v 1.18 2021/07/02 04:38:10 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 
     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 atf_test_case vlan_create_destroy cleanup
     91 vlan_create_destroy_head()
     92 {
     93 
     94 	atf_set "descr" "tests of creation and deletion of vlan interface"
     95 	atf_set "require.progs" "rump_server"
     96 }
     97 
     98 vlan_create_destroy_body()
     99 {
    100 	rump_server_start $SOCK_LOCAL vlan
    101 
    102 	vlan_create_destroy_body_common
    103 }
    104 
    105 
    106 vlan_create_destroy_cleanup()
    107 {
    108 
    109 	$DEBUG && dump
    110 	cleanup
    111 }
    112 
    113 atf_test_case vlan_create_destroy6 cleanup
    114 vlan_create_destroy6_head()
    115 {
    116 
    117 	atf_set "descr" "tests of creation and deletion of vlan interface with IPv6"
    118 	atf_set "require.progs" "rump_server"
    119 }
    120 
    121 vlan_create_destroy6_body()
    122 {
    123 
    124 	rump_server_start $SOCK_LOCAL vlan netinet6
    125 
    126 	vlan_create_destroy_body_common
    127 }
    128 
    129 vlan_create_destroy6_cleanup()
    130 {
    131 
    132 	$DEBUG && dump
    133 	cleanup
    134 }
    135 
    136 vlan_basic_body_common()
    137 {
    138 	local atf_ifconfig="atf_check -s exit:0 rump.ifconfig"
    139 	local outfile=./out
    140 	local af=inet
    141 	local prefix=24
    142 	local local0=$IP_LOCAL0
    143 	local remote0=$IP_REMOTE0
    144 	local ping_cmd="rump.ping -n -w 1 -c 1"
    145 
    146 	if [ x"$1" = x"inet6" ]; then
    147 		af="inet6"
    148 		prefix=64
    149 		local0=$IP6_LOCAL0
    150 		remote0=$IP6_REMOTE0
    151 		ping_cmd="rump.ping6 -n -c 1"
    152 	fi
    153 
    154 	rump_server_add_iface $SOCK_LOCAL shmif0 $BUS
    155 	rump_server_add_iface $SOCK_REMOTE shmif0 $BUS
    156 
    157 	export RUMP_SERVER=$SOCK_LOCAL
    158 	$atf_ifconfig shmif0 up
    159 	export RUMP_SERVER=$SOCK_REMOTE
    160 	$atf_ifconfig shmif0 up
    161 
    162 	export RUMP_SERVER=$SOCK_LOCAL
    163 	$atf_ifconfig vlan0 create
    164 	$atf_ifconfig vlan0 vlan 10 vlanif shmif0
    165 	$atf_ifconfig vlan0 $af $local0/$prefix
    166 	$atf_ifconfig vlan0 up
    167 	$atf_ifconfig -w 10
    168 
    169 	export RUMP_SERVER=$SOCK_REMOTE
    170 	$atf_ifconfig vlan0 create
    171 	$atf_ifconfig vlan0 vlan 10 vlanif shmif0
    172 	$atf_ifconfig vlan0 $af $remote0/$prefix
    173 	$atf_ifconfig vlan0 up
    174 	$atf_ifconfig -w 10
    175 
    176 	extract_new_packets $BUS > $outfile
    177 
    178 	export RUMP_SERVER=$SOCK_LOCAL
    179 	atf_check -s exit:0 -o ignore $ping_cmd $remote0
    180 
    181 	extract_new_packets $BUS > $outfile
    182 	atf_check -s exit:0 -o match:'vlan 10' cat $outfile
    183 
    184 	$atf_ifconfig vlan0 -vlanif
    185 	$atf_ifconfig vlan0 vlan 20 vlanif shmif0
    186 	$atf_ifconfig vlan0 $af $local0/$prefix
    187 	$atf_ifconfig vlan0 up
    188 	$atf_ifconfig -w 10
    189 
    190 	extract_new_packets $BUS > $outfile
    191 	atf_check -s not-exit:0 -o ignore $ping_cmd $remote0
    192 
    193 	extract_new_packets $BUS > $outfile
    194 	atf_check -s exit:0 -o match:'vlan 20' cat $outfile
    195 
    196 	export RUMP_SERVER=$SOCK_LOCAL
    197 	$atf_ifconfig vlan0 -vlanif
    198 	$atf_ifconfig vlan0 vlan 10 vlanif shmif0
    199 	$atf_ifconfig vlan0 $af $local0/$prefix
    200 	$atf_ifconfig vlan0 up
    201 	$atf_ifconfig -w 10
    202 
    203 	atf_check -s exit:0 -o ignore rump.ifconfig -z vlan0
    204 	atf_check -s exit:0 -o ignore $ping_cmd $remote0
    205 	rump.ifconfig -v vlan0 > $outfile
    206 
    207 	atf_check -s exit:0 -o not-match:' 0 packets' cat $outfile
    208 	atf_check -s exit:0 -o not-match:' 0 bytes' cat $outfile
    209 }
    210 
    211 atf_test_case vlan_basic cleanup
    212 vlan_basic_head()
    213 {
    214 
    215 	atf_set "descr" "tests of communications over vlan interfaces"
    216 	atf_set "require.progs" "rump_server"
    217 }
    218 
    219 vlan_basic_body()
    220 {
    221 	rump_server_start $SOCK_LOCAL vlan
    222 	rump_server_start $SOCK_REMOTE vlan
    223 
    224 	vlan_basic_body_common inet
    225 
    226 }
    227 
    228 vlan_basic_cleanup()
    229 {
    230 
    231 	$DEBUG && dump
    232 	cleanup
    233 }
    234 
    235 atf_test_case vlan_basic6 cleanup
    236 vlan_basic6_head()
    237 {
    238 
    239 	atf_set "descr" "tests of communications over vlan interfaces using IPv6"
    240 	atf_set "require.progs" "rump_server"
    241 }
    242 
    243 vlan_basic6_body()
    244 {
    245 	rump_server_start $SOCK_LOCAL vlan netinet6
    246 	rump_server_start $SOCK_REMOTE vlan netinet6
    247 
    248 	vlan_basic_body_common inet6
    249 }
    250 
    251 vlan_basic6_cleanup()
    252 {
    253 
    254 	$DEBUG && dump
    255 	cleanup
    256 }
    257 
    258 vlan_auto_follow_mtu_body_common()
    259 {
    260 	local atf_ifconfig="atf_check -s exit:0 rump.ifconfig"
    261 	local outfile=./out
    262 	local af=inet
    263 	local prefix=24
    264 	local local0=$IP_LOCAL0
    265 	local remote0=$IP_REMOTE0
    266 	local ping_cmd="rump.ping -D -n -w 1 -c 1"
    267 	local mtu=1500
    268 	local vlan_mtu=`expr $mtu - 4`
    269 	# ipv4 header=20bytes, icmp header=8bytes
    270 	local padding=`expr $vlan_mtu - 20 - 8`
    271 	local over_padding=`expr $vlan_mtu - 20 - 8 + 1`
    272 	local nonfrag_msg="$local0 > $remote0: ICMP echo request"
    273 	# unused for ipv4
    274 	local frag_msg=""
    275 
    276 	if [ x"$1" = x"inet6" ]; then
    277 		af="inet6"
    278 		prefix=64
    279 		local0=$IP6_LOCAL0
    280 		remote0=$IP6_REMOTE0
    281 		# ipv6 header=40bytes, icmpv6 header=8bytes
    282 		padding=`expr $vlan_mtu - 40 - 8`
    283 		over_padding=`expr $vlan_mtu - 40 - 8 + 1`
    284 		ping_cmd="rump.ping6 -mm -n -c 1 -i 1"
    285 		nonfrag_msg="$local0 > $remote0: ICMP6, echo request"
    286 		frag_msg="$local0 > $remote0: frag .* ICMP6, echo request"
    287 	fi
    288 
    289 	rump_server_add_iface $SOCK_LOCAL shmif0 $BUS
    290 	rump_server_add_iface $SOCK_REMOTE shmif0 $BUS
    291 
    292 	export RUMP_SERVER=$SOCK_LOCAL
    293 	$atf_ifconfig shmif0 up
    294 	export RUMP_SERVER=$SOCK_REMOTE
    295 	$atf_ifconfig shmif0 up
    296 
    297 	export RUMP_SERVER=$SOCK_LOCAL
    298 	$atf_ifconfig vlan0 create
    299 
    300 	# since upper bound of shmif's mtu is 1500,
    301 	# so we lower vlan's mtu instead of raising shmif's.
    302 	# to do this, we change the interface's parameter
    303 	# such as ND_IFINFO(ifp)->maxmtu that is changed by SIOCSIFMTU.
    304 
    305 	# $atf_config shmif0 mtu 1600
    306 	$atf_ifconfig vlan0 vlan 10 vlanif shmif0
    307 	$atf_ifconfig vlan0 mtu 1400
    308 	$atf_ifconfig vlan0 -vlanif shmif0
    309 
    310 	$atf_ifconfig vlan0 vlan 10 vlanif shmif0
    311 	$atf_ifconfig vlan0 $af $local0/$prefix
    312 	$atf_ifconfig vlan0 up
    313 	$atf_ifconfig -w 10
    314 
    315 	export RUMP_SERVER=$SOCK_REMOTE
    316 	$atf_ifconfig vlan0 create
    317 	$atf_ifconfig vlan0 vlan 10 vlanif shmif0
    318 	$atf_ifconfig vlan0 $af $remote0/$prefix
    319 	$atf_ifconfig vlan0 up
    320 	$atf_ifconfig -w 10
    321 
    322 	extract_new_packets $BUS > $outfile
    323 	export RUMP_SERVER=$SOCK_LOCAL
    324 
    325 	atf_check -s exit:0 -o ignore $ping_cmd -s $padding $remote0
    326 	extract_new_packets $BUS > $outfile
    327 	atf_check -s exit:0 -o match:"$nonfrag_msg" cat $outfile
    328 
    329 	if [ x"$1" = x"inet6" ]; then
    330 		atf_check -s exit:0 -o ignore $ping_cmd -s $over_padding $remote0
    331 		extract_new_packets $BUS > $outfile
    332 		atf_check -s exit:0 -o match:"$frag_msg" cat $outfile
    333 	else
    334 		atf_check -s not-exit:0 -o ignore -e match:"Message too long" \
    335 				$ping_cmd -s $over_padding $remote0
    336 	fi
    337 }
    338 
    339 atf_test_case vlan_auto_follow_mtu cleanup
    340 vlan_auto_follow_mtu_head()
    341 {
    342 
    343 	atf_set "descr" "tests of setting vlan mtu using IPv4"
    344 	atf_set "require.progs" "rump_server"
    345 }
    346 
    347 vlan_auto_follow_mtu_body()
    348 {
    349 	rump_server_start $SOCK_LOCAL vlan
    350 	rump_server_start $SOCK_REMOTE vlan
    351 
    352 	vlan_auto_follow_mtu_body_common inet
    353 }
    354 
    355 vlan_auto_follow_mtu_cleanup()
    356 {
    357 
    358 	$DEBUG && dump
    359 	cleanup
    360 }
    361 
    362 atf_test_case vlan_auto_follow_mtu6 cleanup
    363 vlan_auto_follow_mtu6_head()
    364 {
    365 
    366 	atf_set "descr" "tests of setting vlan mtu using IPv6"
    367 	atf_set "require.progs" "rump_server"
    368 }
    369 
    370 vlan_auto_follow_mtu6_body()
    371 {
    372 	rump_server_start $SOCK_LOCAL vlan netinet6
    373 	rump_server_start $SOCK_REMOTE vlan netinet6
    374 
    375 	vlan_auto_follow_mtu_body_common inet6
    376 }
    377 
    378 vlan_auto_follow_mtu6_cleanup()
    379 {
    380 
    381 	$DEBUG && dump
    382 	cleanup
    383 }
    384 
    385 vlanid_config_and_ping()
    386 {
    387 	local atf_ifconfig="atf_check -s exit:0 rump.ifconfig"
    388 	local vlanid=$1
    389 	shift
    390 
    391 	export RUMP_SERVER=$SOCK_LOCAL
    392 	$atf_ifconfig vlan0 vlan $vlanid vlanif shmif0
    393 	$atf_ifconfig vlan0 $IP_LOCAL0/24
    394 	$atf_ifconfig vlan0 up
    395 
    396 	export RUMP_SERVER=$SOCK_REMOTE
    397 	$atf_ifconfig vlan0 vlan $vlanid vlanif shmif0
    398 	$atf_ifconfig vlan0 $IP_REMOTE0/24
    399 	$atf_ifconfig vlan0 up
    400 
    401 	export RUMP_SERVER=$SOCK_LOCAL
    402 	atf_check -s exit:0 -o ignore rump.ping -n -w 1 -c 1 $IP_REMOTE0
    403 	$atf_ifconfig vlan0 -vlanif
    404 
    405 	export RUMP_SERVER=$SOCK_REMOTE
    406 	$atf_ifconfig vlan0 -vlanif
    407 }
    408 
    409 vlanid_config_and_ping6()
    410 {
    411 	local atf_ifconfig="atf_check -s exit:0 rump.ifconfig"
    412 	local vlanid=$1
    413 	shift
    414 
    415 	export RUMP_SERVER=$SOCK_LOCAL
    416 	$atf_ifconfig vlan0 vlan $vlanid vlanif shmif0
    417 	$atf_ifconfig vlan0 inet6 $IP6_LOCAL0/64
    418 	$atf_ifconfig vlan0 up
    419 
    420 	export RUMP_SERVER=$SOCK_REMOTE
    421 	$atf_ifconfig vlan0 vlan $vlanid vlanif shmif0
    422 	$atf_ifconfig vlan0 inet6 $IP6_REMOTE0/64
    423 	$atf_ifconfig vlan0 up
    424 
    425 	export RUMP_SERVER=$SOCK_LOCAL
    426 	atf_check -s exit:0 -o ignore rump.ping6 -n -c 1 $IP6_REMOTE0
    427 	$atf_ifconfig vlan0 -vlanif
    428 
    429 	export RUMP_SERVER=$SOCK_REMOTE
    430 	$atf_ifconfig vlan0 -vlanif
    431 }
    432 
    433 vlan_vlanid_body_common()
    434 {
    435 	local atf_ifconfig="atf_check -s exit:0 rump.ifconfig"
    436 	local af=inet
    437 	local prefix=24
    438 	local sysctl_param="net.inet.ip.dad_count=0"
    439 	local ping_cmd="rump.ping -n -w 1 -c 1"
    440 	local config_and_ping=vlanid_config_and_ping
    441 	local local0=$IP_LOCAL0
    442 	local local1=$IP_LOCAL1
    443 	local remote0=$IP_REMOTE0
    444 	local remote1=$IP_REMOTE1
    445 
    446 	if [ x"$1" = x"inet6" ]; then
    447 		af=inet6
    448 		prefix=64
    449 		sysctl_param="net.inet6.ip6.dad_count=0"
    450 		ping_cmd="rump.ping6 -n -c 1"
    451 		config_and_ping=vlanid_config_and_ping6
    452 		local0=$IP6_LOCAL0
    453 		local1=$IP6_LOCAL1
    454 		remote0=$IP6_REMOTE0
    455 		remote1=$IP6_REMOTE1
    456 	fi
    457 
    458 	rump_server_add_iface $SOCK_LOCAL shmif0 $BUS
    459 	rump_server_add_iface $SOCK_REMOTE shmif0 $BUS
    460 
    461 	export RUMP_SERVER=$SOCK_LOCAL
    462 	atf_check -s exit:0 -o ignore rump.sysctl -w $sysctl_param
    463 	$atf_ifconfig shmif0 up
    464 	$atf_ifconfig vlan0 create
    465 
    466 	export RUMP_SERVER=$SOCK_REMOTE
    467 	atf_check -s exit:0 -o ignore rump.sysctl -w $sysctl_param
    468 	$atf_ifconfig shmif0 up
    469 	$atf_ifconfig vlan0 create
    470 
    471 	export RUMP_SERVER=$SOCK_LOCAL
    472 	atf_check -s not-exit:0 -e match:"^usage: rump.ifconfig" \
    473 	    rump.ifconfig vlan0 vlan -1 vlanif shmif0
    474 
    475 	# $config_and_ping 0 # reserved vlan id
    476 	$config_and_ping 1
    477 	$config_and_ping 4094
    478 	# $config_and_ping 4095 #reserved vlan id
    479 
    480 	if [ "${RANDOM:-0}" != "${RANDOM:-0}" ]
    481 	then
    482 		for TAG in $(( ${RANDOM:-0} % 4092 + 2 )) \
    483 			   $(( ${RANDOM:-0} % 4092 + 2 )) \
    484 			   $(( ${RANDOM:-0} % 4092 + 2 ))
    485 		do
    486 			$config_and_ping "${TAG}"
    487 		done
    488 	fi
    489 
    490 	export RUMP_SERVER=$SOCK_LOCAL
    491 	for TAG in 0 4095 4096 $((4096*4 + 1)) 65536 65537 $((65536 + 4095))
    492 	do
    493 		atf_check -s not-exit:0 -e not-empty \
    494 		    rump.ifconfig vlan0 vlan "${TAG}" vlanif shmif0
    495 	done
    496 
    497 	$atf_ifconfig vlan0 vlan 1 vlanif shmif0
    498 	atf_check -s not-exit:0 -e match:"SIOCSETVLAN: Device busy" \
    499 	    rump.ifconfig vlan0 vlan 2 vlanif shmif0
    500 
    501 	atf_check -s not-exit:0 -e match:"SIOCSETVLAN: Device busy" \
    502 	    rump.ifconfig vlan0 vlan 1 vlanif shmif1
    503 
    504 	$atf_ifconfig vlan0 -vlanif
    505 	atf_check -s not-exit:0 -e match:"Invalid argument" \
    506 	    rump.ifconfig vlan0 $af $local0/$prefix
    507 
    508 	export RUMP_SERVER=$SOCK_LOCAL
    509 	$atf_ifconfig vlan0 vlan 10 vlanif shmif0
    510 	$atf_ifconfig vlan0 $af $local0/$prefix
    511 	$atf_ifconfig vlan0 up
    512 	$atf_ifconfig vlan1 create
    513 	$atf_ifconfig vlan1 vlan 11 vlanif shmif0
    514 	$atf_ifconfig vlan1 $af $local1/$prefix
    515 	$atf_ifconfig vlan1 up
    516 
    517 	export RUMP_SERVER=$SOCK_REMOTE
    518 	$atf_ifconfig vlan0 -vlanif
    519 	$atf_ifconfig vlan0 vlan 10 vlanif shmif0
    520 	$atf_ifconfig vlan0 $af $remote0/$prefix
    521 	$atf_ifconfig vlan0 up
    522 	$atf_ifconfig vlan1 create
    523 	$atf_ifconfig vlan1 vlan 11 vlanif shmif0
    524 	$atf_ifconfig vlan1 $af $remote1/$prefix
    525 	$atf_ifconfig vlan1 up
    526 
    527 	export RUMP_SERVER=$SOCK_LOCAL
    528 	atf_check -s exit:0 -o ignore $ping_cmd $remote0
    529 	atf_check -s exit:0 -o ignore $ping_cmd $remote1
    530 }
    531 
    532 atf_test_case vlan_vlanid cleanup
    533 vlan_vlanid_head()
    534 {
    535 
    536 	atf_set "descr" "tests of configuration for vlan id"
    537 	atf_set "require.progs" "rump_server"
    538 }
    539 
    540 vlan_vlanid_body()
    541 {
    542 	rump_server_start $SOCK_LOCAL vlan
    543 	rump_server_start $SOCK_REMOTE vlan
    544 
    545 	vlan_vlanid_body_common inet
    546 }
    547 
    548 vlan_vlanid_cleanup()
    549 {
    550 
    551 	$DEBUG && dump
    552 	cleanup
    553 }
    554 
    555 atf_test_case vlan_vlanid6 cleanup
    556 vlan_vlanid6_head()
    557 {
    558 
    559 	atf_set "descr" "tests of configuration for vlan id using IPv6"
    560 	atf_set "require.progs" "rump_server"
    561 }
    562 
    563 
    564 vlan_vlanid6_body()
    565 {
    566 	rump_server_start $SOCK_LOCAL vlan netinet6
    567 	rump_server_start $SOCK_REMOTE vlan netinet6
    568 
    569 	vlan_vlanid_body_common inet6
    570 }
    571 
    572 vlan_vlanid6_cleanup()
    573 {
    574 
    575 	$DEBUG && dump
    576 	cleanup
    577 }
    578 
    579 vlan_configs_body_common()
    580 {
    581 	local atf_ifconfig="atf_check -s exit:0 rump.ifconfig"
    582 
    583 	export RUMP_SERVER=${SOCK_LOCAL}
    584 
    585 	$atf_ifconfig shmif0 create
    586 	$atf_ifconfig shmif1 create
    587 	# unset U/L bit to detect a bug fixed by if_vlan.c:r1.132
    588 	$atf_ifconfig shmif0 link b0:a0:75:00:01:00 active
    589 	$atf_ifconfig shmif1 link b0:a0:75:00:01:01 active
    590 	$atf_ifconfig vlan0 create
    591 
    592 	$atf_ifconfig vlan0 vlan 10 vlanif shmif0
    593 	$atf_ifconfig vlan0 -vlanif
    594 
    595 	$atf_ifconfig vlan0 vlan 10 vlanif shmif0
    596 	$atf_ifconfig vlan0 -vlanif shmif0
    597 
    598 	$atf_ifconfig vlan0 vlan 10 vlanif shmif0
    599 	atf_check -s exit:0 rump.ifconfig vlan0 -vlanif shmif1
    600 	atf_check -s exit:0 rump.ifconfig vlan0 -vlanif shmif2
    601 
    602 	$atf_ifconfig vlan0 -vlanif
    603 
    604 	$atf_ifconfig vlan0 vlan 10 vlanif shmif0
    605 	atf_check -s exit:0 -e match:'Invalid argument' \
    606 	    rump.ifconfig vlan0 mtu 1497
    607 	$atf_ifconfig vlan0 mtu 1496
    608 	$atf_ifconfig vlan0 mtu 42
    609 	atf_check -s exit:0 -e match:'Invalid argument' \
    610 	    rump.ifconfig vlan0 mtu 41
    611 	$atf_ifconfig vlan0 -vlanif
    612 
    613 	$atf_ifconfig vlan1 create
    614 	$atf_ifconfig vlan0 vlan 10 vlanif shmif0
    615 	atf_check -s not-exit:0 -e match:'File exists' \
    616 	    rump.ifconfig vlan1 vlan 10 vlanif shmif0
    617 	$atf_ifconfig vlan1 vlan 10 vlanif shmif1
    618 
    619 	$atf_ifconfig vlan1 -vlanif shmif1
    620 	$atf_ifconfig vlan1 vlan 10 vlanif shmif1
    621 
    622 	$atf_ifconfig vlan0 -vlanif shmif0
    623 	$atf_ifconfig vlan0 vlan 10 vlanif shmif0
    624 }
    625 
    626 atf_test_case vlan_configs cleanup
    627 vlan_configs_head()
    628 {
    629 	atf_set "descr" "tests of configuration except vlan id"
    630 	atf_set "require.progs" "rump_server"
    631 }
    632 
    633 vlan_configs_body()
    634 {
    635 
    636 	rump_server_start $SOCK_LOCAL vlan
    637 
    638 	vlan_configs_body_common
    639 
    640 }
    641 
    642 vlan_configs_cleanup()
    643 {
    644 
    645 	$DEBUG && dump
    646 	cleanup
    647 }
    648 
    649 atf_test_case vlan_configs6 cleanup
    650 vlan_configs6_head()
    651 {
    652 	atf_set "descr" "tests of configuration except vlan id using IPv6"
    653 	atf_set "require.progs" "rump_server"
    654 }
    655 
    656 vlan_configs6_body()
    657 {
    658 	rump_server_start $SOCK_LOCAL vlan netinet6
    659 
    660 	vlan_configs_body_common
    661 }
    662 
    663 vlan_configs6_cleanup()
    664 {
    665 	$DEBUG && dump
    666 	cleanup
    667 }
    668 
    669 vlan_bridge_body_common()
    670 {
    671 	local atf_ifconfig="atf_check -s exit:0 rump.ifconfig"
    672 	local atf_brconfig="atf_check -s exit:0 $HIJACKING /sbin/brconfig"
    673 
    674 	rump_server_add_iface $SOCK_LOCAL shmif0 $BUS
    675 
    676 	export RUMP_SERVER=$SOCK_LOCAL
    677 	$atf_ifconfig shmif0 up
    678 
    679 	$atf_ifconfig vlan0 create
    680 	$atf_ifconfig vlan0 vlan 10 vlanif shmif0
    681 	$atf_ifconfig vlan0 up
    682 	$DEBUG && rump.ifconfig vlan0
    683 
    684 	$atf_ifconfig bridge0 create
    685 	$atf_ifconfig bridge0 up
    686 
    687 	#
    688 	# Add vlan to bridge member
    689 	#
    690 	$atf_ifconfig bridge0 mtu 1496
    691 	atf_check -s exit:0 -o match:'mtu 1496' rump.ifconfig vlan0
    692 
    693 	$atf_brconfig bridge0 add vlan0
    694 	$DEBUG && brconfig bridge0
    695 	$atf_brconfig bridge0 delete vlan0
    696 
    697 	#
    698 	# decrease MTU on adding to bridge member
    699 	#
    700 	$atf_ifconfig bridge0 mtu 1495
    701 	atf_check -s exit:0 -o match:'mtu 1496' rump.ifconfig vlan0
    702 
    703 	$atf_brconfig bridge0 add vlan0
    704 	$DEBUG && brconfig bridge0
    705 	atf_check -s exit:0 -o match:'mtu 1495' rump.ifconfig vlan0
    706 	$atf_brconfig bridge0 delete vlan0
    707 
    708 	#
    709 	# increase MTU on adding to bridge member
    710 	#
    711 	$atf_ifconfig bridge0 mtu 1496
    712 	$atf_ifconfig vlan0 mtu 1495
    713 	$atf_brconfig bridge0 add vlan0
    714 
    715 	$DEBUG && brconfig bridge0
    716 	atf_check -s exit:0 -o match:'mtu 1496' rump.ifconfig vlan0
    717 	$atf_brconfig bridge0 delete vlan0
    718 
    719 	$atf_ifconfig bridge0 mtu 1497
    720 	atf_check -s not-exit:0 -o ignore -e ignore \
    721 	    /sbin/brconfig bridge0 add vlan0
    722 
    723 	#
    724 	# Destroy a vlan interface that is bridge member
    725 	#
    726 	$atf_ifconfig bridge0 mtu 1496
    727 	$atf_brconfig bridge0 add vlan0
    728 	$atf_ifconfig vlan0 destroy
    729 
    730 	rump_server_destroy_ifaces
    731 }
    732 
    733 atf_test_case vlan_bridge cleanup
    734 vlan_bridge_head()
    735 {
    736 
    737 	atf_set "descr" "tests of vlan interfaces with bridges (IPv4)"
    738 	atf_set "require.progs" "rump_server"
    739 }
    740 
    741 vlan_bridge_body()
    742 {
    743 
    744 	rump_server_start $SOCK_LOCAL vlan bridge
    745 	vlan_bridge_body_common
    746 }
    747 
    748 vlan_bridge_cleanup()
    749 {
    750 
    751 	$DEBUG && dump
    752 	cleanup
    753 }
    754 
    755 atf_test_case vlan_bridge6 cleanup
    756 vlan_bridge6_head()
    757 {
    758 
    759 	atf_set "descr" "tests of vlan interfaces with bridges (IPv6)"
    760 	atf_set "require.progs" "rump_server"
    761 }
    762 
    763 vlan_bridge6_body()
    764 {
    765 
    766 	rump_server_start $SOCK_LOCAL vlan netinet6 bridge
    767 	vlan_bridge_body_common
    768 }
    769 
    770 vlan_bridge6_cleanup()
    771 {
    772 
    773 	$DEBUG && dump
    774 	cleanup
    775 }
    776 
    777 vlan_multicast_body_common()
    778 {
    779 	local atf_ifconfig="atf_check -s exit:0 rump.ifconfig"
    780 	local af="inet"
    781 	local local0=$IP_LOCAL0
    782 	local local1=$IP_LOCAL1
    783 	local mcaddr=$IP_MCADDR0
    784 	local eth_mcaddr=$ETH_IP_MCADDR0
    785 	local prefix=24
    786 	local siocXmulti="$(atf_get_srcdir)/siocXmulti"
    787 	local atf_siocXmulti="atf_check -s exit:0 $HIJACKING $siocXmulti"
    788 
    789 	if [ x"$1" =  x"inet6" ]; then
    790 		af="inet6"
    791 		prefix=64
    792 		local0=$IP6_LOCAL0
    793 		local1=$IP6_LOCAL1
    794 		mcaddr=$IP6_MCADDR0
    795 		eth_mcaddr=$ETH_IP6_MCADDR0
    796 	fi
    797 
    798 	export RUMP_SERVER=$SOCK_LOCAL
    799 
    800 	$atf_ifconfig shmif0 create
    801 	$atf_ifconfig shmif0 linkstr net0 up
    802 	$atf_ifconfig vlan0 create
    803 	$atf_ifconfig vlan0 vlan 10 vlanif shmif0
    804 	$atf_ifconfig vlan0 $af $local0/$prefix up
    805 	$atf_ifconfig vlan1 create
    806 	$atf_ifconfig vlan1 vlan 11 vlanif shmif0
    807 	$atf_ifconfig vlan1 $af $local1/$prefix up
    808 	$atf_ifconfig -w 10
    809 
    810 	# check the initial state
    811 	atf_check -s exit:0 -o not-match:"$eth_mcaddr" $HIJACKING ifmcstat
    812 
    813 	# add a multicast address
    814 	$atf_siocXmulti add vlan0 $mcaddr
    815 	atf_check -s exit:0 -o match:"$eth_mcaddr" $HIJACKING ifmcstat
    816 
    817 	# delete the address
    818 	$atf_siocXmulti del vlan0 $mcaddr
    819 	atf_check -s exit:0 -o not-match:"$eth_mcaddr" $HIJACKING ifmcstat
    820 
    821 	# delete a non-existing address
    822 	atf_check -s not-exit:0 -e match:"Invalid argument" \
    823 	    $HIJACKING $siocXmulti del vlan0 $mcaddr
    824 
    825 	# add an address to different interfaces
    826 	$atf_siocXmulti add vlan0 $mcaddr
    827 	$atf_siocXmulti add vlan1 $mcaddr
    828 	atf_check -s exit:0 -o match:"${eth_mcaddr} refcount 2" $HIJACKING ifmcstat
    829 	$atf_siocXmulti del vlan0 $mcaddr
    830 
    831 	# delete the address with invalid interface
    832 	atf_check -s not-exit:0 -e match:"Invalid argument" \
    833 	    $HIJACKING $siocXmulti del vlan0 $mcaddr
    834 
    835 	$atf_siocXmulti del vlan1 $mcaddr
    836 
    837 	# add and delete a same address more than once
    838 	$atf_siocXmulti add vlan0 $mcaddr
    839 	$atf_siocXmulti add vlan0 $mcaddr
    840 	$atf_siocXmulti add vlan0 $mcaddr
    841 	atf_check -s exit:0 -o match:"${eth_mcaddr} refcount 3" $HIJACKING ifmcstat
    842 	$atf_siocXmulti del vlan0 $mcaddr
    843 	$atf_siocXmulti del vlan0 $mcaddr
    844 	$atf_siocXmulti del vlan0 $mcaddr
    845 	atf_check -s exit:0 -o not-match:"$eth_mcaddr" $HIJACKING ifmcstat
    846 
    847 	# delete all address added to parent device when remove
    848 	# the config of parent interface
    849 	$atf_siocXmulti add vlan0 $mcaddr
    850 	$atf_siocXmulti add vlan0 $mcaddr
    851 	$atf_siocXmulti add vlan0 $mcaddr
    852 	$atf_ifconfig vlan0 -vlanif shmif0
    853 	atf_check -s exit:0 -o not-match:"$eth_mcaddr" $HIJACKING ifmcstat
    854 }
    855 
    856 atf_test_case vlan_multicast cleanup
    857 vlan_multicast_head()
    858 {
    859 	atf_set "descr" "tests of multicast address adding and deleting"
    860 	atf_set "require.progs" "rump_server"
    861 }
    862 
    863 vlan_multicast_body()
    864 {
    865 	rump_server_start $SOCK_LOCAL vlan
    866 
    867 	vlan_multicast_body_common inet
    868 }
    869 
    870 vlan_multicast_cleanup()
    871 {
    872 	$DEBUG && dump
    873 	cleanup
    874 }
    875 
    876 atf_test_case vlan_multicast6 cleanup
    877 vlan_multicast6_head()
    878 {
    879 	atf_set "descr" "tests of multicast address adding and deleting with IPv6"
    880 	atf_set "require.progs" "rump_server"
    881 }
    882 
    883 vlan_multicast6_body()
    884 {
    885 	rump_server_start $SOCK_LOCAL vlan netinet6
    886 
    887 	vlan_multicast_body_common inet6
    888 }
    889 
    890 vlan_multicast6_cleanup()
    891 {
    892 	$DEBUG && dump
    893 	cleanup
    894 }
    895 
    896 atf_init_test_cases()
    897 {
    898 
    899 	atf_add_test_case vlan_create_destroy
    900 	atf_add_test_case vlan_basic
    901 	atf_add_test_case vlan_auto_follow_mtu
    902 	atf_add_test_case vlan_vlanid
    903 	atf_add_test_case vlan_configs
    904 	atf_add_test_case vlan_bridge
    905 	atf_add_test_case vlan_multicast
    906 
    907 	atf_add_test_case vlan_create_destroy6
    908 	atf_add_test_case vlan_basic6
    909 	atf_add_test_case vlan_auto_follow_mtu6
    910 	atf_add_test_case vlan_vlanid6
    911 	atf_add_test_case vlan_configs6
    912 	atf_add_test_case vlan_bridge6
    913 	atf_add_test_case vlan_multicast6
    914 }
    915