Home | History | Annotate | Line # | Download | only in if_vlan
t_vlan.sh revision 1.24
      1 #	$NetBSD: t_vlan.sh,v 1.24 2021/08/19 03:27:05 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_check -s exit:0 -o match:'status: +down' \
    593 	    rump.ifconfig vlan0
    594 	$atf_ifconfig vlan0 vlan 10 vlanif shmif0
    595 	$atf_ifconfig vlan0 -vlanif
    596 	atf_check -s exit:0 -o match:'status: +down' \
    597 	    rump.ifconfig vlan0
    598 
    599 	$atf_ifconfig vlan0 vlan 10 vlanif shmif0
    600 	$atf_ifconfig vlan0 -vlanif shmif0
    601 
    602 	$atf_ifconfig vlan0 vlan 10 vlanif shmif0
    603 	atf_check -s exit:0 rump.ifconfig vlan0 -vlanif shmif1
    604 	atf_check -s exit:0 rump.ifconfig vlan0 -vlanif shmif2
    605 
    606 	$atf_ifconfig vlan0 -vlanif
    607 
    608 	$atf_ifconfig vlan0 vlan 10 vlanif shmif0
    609 	atf_check -s exit:0 -e match:'Invalid argument' \
    610 	    rump.ifconfig vlan0 mtu 1497
    611 	$atf_ifconfig vlan0 mtu 1496
    612 	$atf_ifconfig vlan0 mtu 42
    613 	atf_check -s exit:0 -e match:'Invalid argument' \
    614 	    rump.ifconfig vlan0 mtu 41
    615 	$atf_ifconfig vlan0 -vlanif
    616 
    617 	$atf_ifconfig vlan1 create
    618 	$atf_ifconfig vlan0 vlan 10 vlanif shmif0
    619 	atf_check -s not-exit:0 -e match:'File exists' \
    620 	    rump.ifconfig vlan1 vlan 10 vlanif shmif0
    621 	$atf_ifconfig vlan1 vlan 10 vlanif shmif1
    622 
    623 	$atf_ifconfig vlan1 -vlanif shmif1
    624 	$atf_ifconfig vlan1 vlan 10 vlanif shmif1
    625 
    626 	$atf_ifconfig vlan0 -vlanif shmif0
    627 	$atf_ifconfig vlan0 vlan 10 vlanif shmif0
    628 }
    629 
    630 atf_test_case vlan_configs cleanup
    631 vlan_configs_head()
    632 {
    633 	atf_set "descr" "tests of configuration except vlan id"
    634 	atf_set "require.progs" "rump_server"
    635 }
    636 
    637 vlan_configs_body()
    638 {
    639 
    640 	rump_server_start $SOCK_LOCAL vlan
    641 
    642 	vlan_configs_body_common
    643 
    644 }
    645 
    646 vlan_configs_cleanup()
    647 {
    648 
    649 	$DEBUG && dump
    650 	cleanup
    651 }
    652 
    653 atf_test_case vlan_configs6 cleanup
    654 vlan_configs6_head()
    655 {
    656 	atf_set "descr" "tests of configuration except vlan id using IPv6"
    657 	atf_set "require.progs" "rump_server"
    658 }
    659 
    660 vlan_configs6_body()
    661 {
    662 	rump_server_start $SOCK_LOCAL vlan netinet6
    663 
    664 	vlan_configs_body_common
    665 }
    666 
    667 vlan_configs6_cleanup()
    668 {
    669 	$DEBUG && dump
    670 	cleanup
    671 }
    672 
    673 vlan_bridge_body_common()
    674 {
    675 	local atf_ifconfig="atf_check -s exit:0 rump.ifconfig"
    676 	local atf_brconfig="atf_check -s exit:0 $HIJACKING /sbin/brconfig"
    677 
    678 	rump_server_add_iface $SOCK_LOCAL shmif0 $BUS
    679 
    680 	export RUMP_SERVER=$SOCK_LOCAL
    681 	$atf_ifconfig shmif0 up
    682 
    683 	$atf_ifconfig vlan0 create
    684 	$DEBUG && rump.ifconfig vlan0
    685 
    686 	$atf_ifconfig bridge0 create
    687 	$atf_ifconfig bridge0 up
    688 
    689 	#
    690 	# Add vlan to bridge member
    691 	#
    692 	$atf_ifconfig bridge0 mtu 1496
    693 
    694 	# vlan0 can not add to bridge member
    695 	# because it is not an ethernet device
    696 	atf_check -s not-exit:0 -e match:'Invalid argument' \
    697 	    $HIJACKING /sbin/brconfig bridge0 add vlan0
    698 
    699 	$atf_ifconfig vlan0 vlan 10 vlanif shmif0
    700 	$atf_ifconfig vlan0 up
    701 	atf_check -s exit:0 -o match:'mtu 1496' rump.ifconfig vlan0
    702 
    703 	# vlan0 becomes an ethernet device
    704 	# after attaching the parent interface
    705 	$atf_brconfig bridge0 add vlan0
    706 	$DEBUG && $HIJACKING /sbin/brconfig bridge0
    707 
    708 	$atf_brconfig bridge0 delete vlan0
    709 
    710 	$atf_brconfig bridge0 add vlan0
    711 	$atf_ifconfig vlan0 -vlanif
    712 	atf_check -s exit:0 -o not-match:'vlan0' \
    713 	    $HIJACKING /sbin/brconfig bridge0
    714 	atf_check -s not-exit:0 -e match:'No such' \
    715 	    $HIJACKING /sbin/brconfig bridge0 delete vlan0
    716 
    717 	#
    718 	# decrease MTU on adding to bridge member
    719 	#
    720 	$atf_ifconfig bridge0 mtu 1495
    721 	$atf_ifconfig vlan0 vlan 10 vlanif shmif0
    722 	$atf_ifconfig vlan0 up
    723 	atf_check -s exit:0 -o match:'mtu 1496' rump.ifconfig vlan0
    724 
    725 	$atf_brconfig bridge0 add vlan0
    726 	$DEBUG && $HIJACKING /sbin/brconfig bridge0
    727 	atf_check -s exit:0 -o match:'mtu 1495' rump.ifconfig vlan0
    728 	$atf_brconfig bridge0 delete vlan0
    729 
    730 	#
    731 	# increase MTU on adding to bridge member
    732 	#
    733 	$atf_ifconfig bridge0 mtu 1496
    734 	$atf_ifconfig vlan0 mtu 1495
    735 	$atf_brconfig bridge0 add vlan0
    736 
    737 	$DEBUG && $HIJACKING /sbin/brconfig bridge0
    738 	atf_check -s exit:0 -o match:'mtu 1496' rump.ifconfig vlan0
    739 	$atf_brconfig bridge0 delete vlan0
    740 
    741 	$atf_ifconfig bridge0 mtu 1497
    742 	atf_check -s not-exit:0 -o ignore -e ignore \
    743 	    $HIJACKING /sbin/brconfig bridge0 add vlan0
    744 
    745 	#
    746 	# Destroy a vlan interface that is bridge member
    747 	#
    748 	$atf_ifconfig bridge0 mtu 1496
    749 	$atf_brconfig bridge0 add vlan0
    750 	$atf_ifconfig vlan0 destroy
    751 
    752 	rump_server_destroy_ifaces
    753 }
    754 
    755 atf_test_case vlan_bridge cleanup
    756 vlan_bridge_head()
    757 {
    758 
    759 	atf_set "descr" "tests of vlan interfaces with bridges (IPv4)"
    760 	atf_set "require.progs" "rump_server"
    761 }
    762 
    763 vlan_bridge_body()
    764 {
    765 
    766 	rump_server_start $SOCK_LOCAL vlan bridge
    767 	vlan_bridge_body_common
    768 }
    769 
    770 vlan_bridge_cleanup()
    771 {
    772 
    773 	$DEBUG && dump
    774 	cleanup
    775 }
    776 
    777 atf_test_case vlan_bridge6 cleanup
    778 vlan_bridge6_head()
    779 {
    780 
    781 	atf_set "descr" "tests of vlan interfaces with bridges (IPv6)"
    782 	atf_set "require.progs" "rump_server"
    783 }
    784 
    785 vlan_bridge6_body()
    786 {
    787 
    788 	rump_server_start $SOCK_LOCAL vlan netinet6 bridge
    789 	vlan_bridge_body_common
    790 }
    791 
    792 vlan_bridge6_cleanup()
    793 {
    794 
    795 	$DEBUG && dump
    796 	cleanup
    797 }
    798 
    799 vlan_multicast_body_common()
    800 {
    801 	local atf_ifconfig="atf_check -s exit:0 rump.ifconfig"
    802 	local af="inet"
    803 	local local0=$IP_LOCAL0
    804 	local local1=$IP_LOCAL1
    805 	local mcaddr=$IP_MCADDR0
    806 	local eth_mcaddr=$ETH_IP_MCADDR0
    807 	local prefix=24
    808 	local siocXmulti="$(atf_get_srcdir)/siocXmulti"
    809 	local atf_siocXmulti="atf_check -s exit:0 $HIJACKING $siocXmulti"
    810 
    811 	if [ x"$1" =  x"inet6" ]; then
    812 		af="inet6"
    813 		prefix=64
    814 		local0=$IP6_LOCAL0
    815 		local1=$IP6_LOCAL1
    816 		mcaddr=$IP6_MCADDR0
    817 		eth_mcaddr=$ETH_IP6_MCADDR0
    818 	fi
    819 
    820 	export RUMP_SERVER=$SOCK_LOCAL
    821 
    822 	$atf_ifconfig shmif0 create
    823 	$atf_ifconfig shmif0 linkstr net0 up
    824 	$atf_ifconfig vlan0 create
    825 	$atf_ifconfig vlan0 vlan 10 vlanif shmif0
    826 	$atf_ifconfig vlan0 $af $local0/$prefix up
    827 	$atf_ifconfig vlan1 create
    828 	$atf_ifconfig vlan1 vlan 11 vlanif shmif0
    829 	$atf_ifconfig vlan1 $af $local1/$prefix up
    830 	$atf_ifconfig -w 10
    831 
    832 	# check the initial state
    833 	atf_check -s exit:0 -o not-match:"$eth_mcaddr" $HIJACKING ifmcstat
    834 
    835 	# add a multicast address
    836 	$atf_siocXmulti add vlan0 $mcaddr
    837 	atf_check -s exit:0 -o match:"$eth_mcaddr" $HIJACKING ifmcstat
    838 
    839 	# delete the address
    840 	$atf_siocXmulti del vlan0 $mcaddr
    841 	atf_check -s exit:0 -o not-match:"$eth_mcaddr" $HIJACKING ifmcstat
    842 
    843 	# delete a non-existing address
    844 	atf_check -s not-exit:0 -e match:"Invalid argument" \
    845 	    $HIJACKING $siocXmulti del vlan0 $mcaddr
    846 
    847 	# add an address to different interfaces
    848 	$atf_siocXmulti add vlan0 $mcaddr
    849 	$atf_siocXmulti add vlan1 $mcaddr
    850 	atf_check -s exit:0 -o match:"${eth_mcaddr} refcount 2" $HIJACKING ifmcstat
    851 	$atf_siocXmulti del vlan0 $mcaddr
    852 
    853 	# delete the address with invalid interface
    854 	atf_check -s not-exit:0 -e match:"Invalid argument" \
    855 	    $HIJACKING $siocXmulti del vlan0 $mcaddr
    856 
    857 	$atf_siocXmulti del vlan1 $mcaddr
    858 
    859 	# add and delete a same address more than once
    860 	$atf_siocXmulti add vlan0 $mcaddr
    861 	$atf_siocXmulti add vlan0 $mcaddr
    862 	$atf_siocXmulti add vlan0 $mcaddr
    863 	atf_check -s exit:0 -o match:"${eth_mcaddr} refcount 3" $HIJACKING ifmcstat
    864 	$atf_siocXmulti del vlan0 $mcaddr
    865 	$atf_siocXmulti del vlan0 $mcaddr
    866 	$atf_siocXmulti del vlan0 $mcaddr
    867 	atf_check -s exit:0 -o not-match:"$eth_mcaddr" $HIJACKING ifmcstat
    868 
    869 	# delete all address added to parent device when remove
    870 	# the config of parent interface
    871 	$atf_siocXmulti add vlan0 $mcaddr
    872 	$atf_siocXmulti add vlan0 $mcaddr
    873 	$atf_siocXmulti add vlan0 $mcaddr
    874 	$atf_ifconfig vlan0 -vlanif shmif0
    875 	atf_check -s exit:0 -o not-match:"$eth_mcaddr" $HIJACKING ifmcstat
    876 }
    877 
    878 atf_test_case vlan_multicast cleanup
    879 vlan_multicast_head()
    880 {
    881 	atf_set "descr" "tests of multicast address adding and deleting"
    882 	atf_set "require.progs" "rump_server"
    883 }
    884 
    885 vlan_multicast_body()
    886 {
    887 	rump_server_start $SOCK_LOCAL vlan
    888 
    889 	vlan_multicast_body_common inet
    890 }
    891 
    892 vlan_multicast_cleanup()
    893 {
    894 	$DEBUG && dump
    895 	cleanup
    896 }
    897 
    898 atf_test_case vlan_multicast6 cleanup
    899 vlan_multicast6_head()
    900 {
    901 	atf_set "descr" "tests of multicast address adding and deleting with IPv6"
    902 	atf_set "require.progs" "rump_server"
    903 }
    904 
    905 vlan_multicast6_body()
    906 {
    907 	rump_server_start $SOCK_LOCAL vlan netinet6
    908 
    909 	vlan_multicast_body_common inet6
    910 }
    911 
    912 vlan_multicast6_cleanup()
    913 {
    914 	$DEBUG && dump
    915 	cleanup
    916 }
    917 
    918 atf_test_case vlan_promisc cleanup
    919 vlan_promisc_head()
    920 {
    921 
    922 	atf_set "descr" "tests of IFF_PROMISC of vlan"
    923 	atf_set "require.progs" "rump_server"
    924 }
    925 
    926 vlan_promisc_body()
    927 {
    928 	local atf_ifconfig="atf_check -s exit:0 rump.ifconfig"
    929 	local atf_brconfig="atf_check -s exit:0 $HIJACKING /sbin/brconfig"
    930 	local atf_arp="atf_check -s exit:0 rump.arp"
    931 	local bpfopen="$HIJACKING $(atf_get_srcdir)/bpfopen"
    932 	bpfopen="$bpfopen -dv -b /rump/dev/bpf"
    933 	local pidfile="./bpfopen.pid"
    934 	local macaddr=""
    935 
    936 	rump_server_bpf_start $SOCK_LOCAL vlan bridge
    937 	rump_server_start $SOCK_REMOTE vlan
    938 
    939 	rump_server_add_iface $SOCK_LOCAL shmif0 $BUS
    940 	rump_server_add_iface $SOCK_LOCAL shmif1
    941 	rump_server_add_iface $SOCK_LOCAL vlan0
    942 	rump_server_add_iface $SOCK_LOCAL vlan1
    943 	rump_server_add_iface $SOCK_LOCAL bridge0
    944 
    945 	rump_server_add_iface $SOCK_REMOTE shmif0 $BUS
    946 	rump_server_add_iface $SOCK_REMOTE vlan0
    947 
    948 	macaddr=$(get_macaddr $SOCK_LOCAL shmif1)
    949 
    950 	export RUMP_SERVER=$SOCK_REMOTE
    951 	$atf_ifconfig vlan0 vlan 1 vlanif shmif0
    952 	$atf_ifconfig shmif0 up
    953 	$atf_ifconfig vlan0 inet $IP_REMOTE0/24
    954 	$atf_ifconfig vlan0 up
    955 	$atf_ifconfig -w 10
    956 	$atf_arp -s $IP_LOCAL0 $macaddr
    957 
    958 	export RUMP_SERVER=$SOCK_LOCAL
    959 	$atf_ifconfig bridge0 mtu 1496
    960 	#
    961 	# When vlan IF is PROMISC, the parent is also PROMISC
    962 	#
    963 	$atf_ifconfig vlan0 vlan 1 vlanif shmif0
    964 	$atf_ifconfig shmif0 up
    965 	$atf_ifconfig vlan0 up
    966 
    967 	atf_check -s exit:0 -o not-match:'PROMISC' rump.ifconfig vlan0
    968 	atf_check -s exit:0 -o not-match:'PROMISC' rump.ifconfig shmif0
    969 
    970 	$atf_brconfig bridge0 add vlan0
    971 	$atf_ifconfig bridge0 up
    972 	atf_check -s exit:0 -o match:'PROMISC' rump.ifconfig vlan0
    973 	atf_check -s exit:0 -o match:'PROMISC' rump.ifconfig shmif0
    974 
    975 	$atf_ifconfig bridge0 down
    976 	$atf_brconfig bridge0 delete vlan0
    977 	atf_check -s exit:0 -o not-match:'PROMISC' rump.ifconfig vlan0
    978 	atf_check -s exit:0 -o not-match:'PROMISC' rump.ifconfig shmif0
    979 	$atf_ifconfig vlan0 -vlanif
    980 
    981 	#
    982 	# drop unicast packets that is not for the host
    983 	#
    984 	$atf_ifconfig vlan0 vlan 1 vlanif shmif0
    985 	$atf_ifconfig -w 10
    986 
    987 	atf_check -s exit:0 -e match:'bpf opened' $bpfopen -p $pidfile shmif0
    988 
    989 	atf_check -s exit:0 -o not-match:'PROMISC' rump.ifconfig vlan0
    990 	atf_check -s exit:0 -o match:'PROMISC' rump.ifconfig shmif0
    991 	atf_check -s exit:0 -o ignore rump.ifconfig -z vlan0
    992 	atf_check -s exit:0 -o not-match:'input:.*errors' \
    993 	    rump.ifconfig -v vlan0
    994 
    995 	export RUMP_SERVER=$SOCK_REMOTE
    996 	atf_check -s not-exit:0 -o ignore -e ignore \
    997 	    rump.ping -c 3 -i 0.2 $IP_LOCAL0
    998 
    999 	export RUMP_SERVER=$SOCK_LOCAL
   1000 	atf_check -s exit:0 -o match:'input:.*errors' \
   1001 	    rump.ifconfig -v vlan0
   1002 
   1003 	atf_check -s exit:0 kill -TERM $(cat $pidfile)
   1004 	sleep 2
   1005 
   1006 	atf_check -s exit:0 -o not-match:'PROMISC' rump.ifconfig vlan0
   1007 	atf_check -s exit:0 -o not-match:'PROMISC' rump.ifconfig shmif0
   1008 	$atf_ifconfig vlan0 -vlanif
   1009 
   1010 	#
   1011 	# clear IFF_PROMISC after bpf_detach called from ether_ifdetach
   1012 	#
   1013 	$atf_ifconfig vlan0 vlan 1 vlanif shmif0
   1014 	$atf_ifconfig vlan0 up
   1015 
   1016 	atf_check -s exit:0 -e match:'bpf opened' $bpfopen -p $pidfile vlan0
   1017 
   1018 	atf_check -s exit:0 -o match:'PROMISC' rump.ifconfig vlan0
   1019 	atf_check -s exit:0 -o match:'PROMISC' rump.ifconfig shmif0
   1020 
   1021 	$atf_ifconfig vlan0 -vlanif
   1022 
   1023 	atf_check -s exit:0 -o not-match:'PROMISC' rump.ifconfig vlan0
   1024 	atf_check -s exit:0 -o not-match:'PROMISC' rump.ifconfig shmif0
   1025 
   1026 	atf_check -s exit:0 kill -TERM $(cat $pidfile)
   1027 	sleep 2
   1028 	atf_check -s exit:0 -o not-match:'PROMISC' rump.ifconfig vlan0
   1029 }
   1030 
   1031 vlan_promisc_cleanup()
   1032 {
   1033 
   1034 	$DEBUG && dump
   1035 	cleanup
   1036 }
   1037 
   1038 atf_init_test_cases()
   1039 {
   1040 
   1041 	atf_add_test_case vlan_create_destroy
   1042 	atf_add_test_case vlan_basic
   1043 	atf_add_test_case vlan_auto_follow_mtu
   1044 	atf_add_test_case vlan_vlanid
   1045 	atf_add_test_case vlan_configs
   1046 	atf_add_test_case vlan_bridge
   1047 	atf_add_test_case vlan_multicast
   1048 	atf_add_test_case vlan_promisc
   1049 
   1050 	atf_add_test_case vlan_create_destroy6
   1051 	atf_add_test_case vlan_basic6
   1052 	atf_add_test_case vlan_auto_follow_mtu6
   1053 	atf_add_test_case vlan_vlanid6
   1054 	atf_add_test_case vlan_configs6
   1055 	atf_add_test_case vlan_bridge6
   1056 	atf_add_test_case vlan_multicast6
   1057 }
   1058