Home | History | Annotate | Line # | Download | only in if_vlan
t_vlan.sh revision 1.20
      1 #	$NetBSD: t_vlan.sh,v 1.20 2021/07/09 05:54:11 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 	$atf_ifconfig vlan0 vlan 10 vlanif shmif0
    685 	$atf_ifconfig vlan0 up
    686 	$DEBUG && rump.ifconfig vlan0
    687 
    688 	$atf_ifconfig bridge0 create
    689 	$atf_ifconfig bridge0 up
    690 
    691 	#
    692 	# Add vlan to bridge member
    693 	#
    694 	$atf_ifconfig bridge0 mtu 1496
    695 	atf_check -s exit:0 -o match:'mtu 1496' rump.ifconfig vlan0
    696 
    697 	$atf_brconfig bridge0 add vlan0
    698 	$DEBUG && brconfig bridge0
    699 	$atf_brconfig bridge0 delete vlan0
    700 
    701 	#
    702 	# decrease MTU on adding to bridge member
    703 	#
    704 	$atf_ifconfig bridge0 mtu 1495
    705 	atf_check -s exit:0 -o match:'mtu 1496' rump.ifconfig vlan0
    706 
    707 	$atf_brconfig bridge0 add vlan0
    708 	$DEBUG && brconfig bridge0
    709 	atf_check -s exit:0 -o match:'mtu 1495' rump.ifconfig vlan0
    710 	$atf_brconfig bridge0 delete vlan0
    711 
    712 	#
    713 	# increase MTU on adding to bridge member
    714 	#
    715 	$atf_ifconfig bridge0 mtu 1496
    716 	$atf_ifconfig vlan0 mtu 1495
    717 	$atf_brconfig bridge0 add vlan0
    718 
    719 	$DEBUG && brconfig bridge0
    720 	atf_check -s exit:0 -o match:'mtu 1496' rump.ifconfig vlan0
    721 	$atf_brconfig bridge0 delete vlan0
    722 
    723 	$atf_ifconfig bridge0 mtu 1497
    724 	atf_check -s not-exit:0 -o ignore -e ignore \
    725 	    /sbin/brconfig bridge0 add vlan0
    726 
    727 	#
    728 	# Destroy a vlan interface that is bridge member
    729 	#
    730 	$atf_ifconfig bridge0 mtu 1496
    731 	$atf_brconfig bridge0 add vlan0
    732 	$atf_ifconfig vlan0 destroy
    733 
    734 	rump_server_destroy_ifaces
    735 }
    736 
    737 atf_test_case vlan_bridge cleanup
    738 vlan_bridge_head()
    739 {
    740 
    741 	atf_set "descr" "tests of vlan interfaces with bridges (IPv4)"
    742 	atf_set "require.progs" "rump_server"
    743 }
    744 
    745 vlan_bridge_body()
    746 {
    747 
    748 	rump_server_start $SOCK_LOCAL vlan bridge
    749 	vlan_bridge_body_common
    750 }
    751 
    752 vlan_bridge_cleanup()
    753 {
    754 
    755 	$DEBUG && dump
    756 	cleanup
    757 }
    758 
    759 atf_test_case vlan_bridge6 cleanup
    760 vlan_bridge6_head()
    761 {
    762 
    763 	atf_set "descr" "tests of vlan interfaces with bridges (IPv6)"
    764 	atf_set "require.progs" "rump_server"
    765 }
    766 
    767 vlan_bridge6_body()
    768 {
    769 
    770 	rump_server_start $SOCK_LOCAL vlan netinet6 bridge
    771 	vlan_bridge_body_common
    772 }
    773 
    774 vlan_bridge6_cleanup()
    775 {
    776 
    777 	$DEBUG && dump
    778 	cleanup
    779 }
    780 
    781 vlan_multicast_body_common()
    782 {
    783 	local atf_ifconfig="atf_check -s exit:0 rump.ifconfig"
    784 	local af="inet"
    785 	local local0=$IP_LOCAL0
    786 	local local1=$IP_LOCAL1
    787 	local mcaddr=$IP_MCADDR0
    788 	local eth_mcaddr=$ETH_IP_MCADDR0
    789 	local prefix=24
    790 	local siocXmulti="$(atf_get_srcdir)/siocXmulti"
    791 	local atf_siocXmulti="atf_check -s exit:0 $HIJACKING $siocXmulti"
    792 
    793 	if [ x"$1" =  x"inet6" ]; then
    794 		af="inet6"
    795 		prefix=64
    796 		local0=$IP6_LOCAL0
    797 		local1=$IP6_LOCAL1
    798 		mcaddr=$IP6_MCADDR0
    799 		eth_mcaddr=$ETH_IP6_MCADDR0
    800 	fi
    801 
    802 	export RUMP_SERVER=$SOCK_LOCAL
    803 
    804 	$atf_ifconfig shmif0 create
    805 	$atf_ifconfig shmif0 linkstr net0 up
    806 	$atf_ifconfig vlan0 create
    807 	$atf_ifconfig vlan0 vlan 10 vlanif shmif0
    808 	$atf_ifconfig vlan0 $af $local0/$prefix up
    809 	$atf_ifconfig vlan1 create
    810 	$atf_ifconfig vlan1 vlan 11 vlanif shmif0
    811 	$atf_ifconfig vlan1 $af $local1/$prefix up
    812 	$atf_ifconfig -w 10
    813 
    814 	# check the initial state
    815 	atf_check -s exit:0 -o not-match:"$eth_mcaddr" $HIJACKING ifmcstat
    816 
    817 	# add a multicast address
    818 	$atf_siocXmulti add vlan0 $mcaddr
    819 	atf_check -s exit:0 -o match:"$eth_mcaddr" $HIJACKING ifmcstat
    820 
    821 	# delete the address
    822 	$atf_siocXmulti del vlan0 $mcaddr
    823 	atf_check -s exit:0 -o not-match:"$eth_mcaddr" $HIJACKING ifmcstat
    824 
    825 	# delete a non-existing address
    826 	atf_check -s not-exit:0 -e match:"Invalid argument" \
    827 	    $HIJACKING $siocXmulti del vlan0 $mcaddr
    828 
    829 	# add an address to different interfaces
    830 	$atf_siocXmulti add vlan0 $mcaddr
    831 	$atf_siocXmulti add vlan1 $mcaddr
    832 	atf_check -s exit:0 -o match:"${eth_mcaddr} refcount 2" $HIJACKING ifmcstat
    833 	$atf_siocXmulti del vlan0 $mcaddr
    834 
    835 	# delete the address with invalid interface
    836 	atf_check -s not-exit:0 -e match:"Invalid argument" \
    837 	    $HIJACKING $siocXmulti del vlan0 $mcaddr
    838 
    839 	$atf_siocXmulti del vlan1 $mcaddr
    840 
    841 	# add and delete a same address more than once
    842 	$atf_siocXmulti add vlan0 $mcaddr
    843 	$atf_siocXmulti add vlan0 $mcaddr
    844 	$atf_siocXmulti add vlan0 $mcaddr
    845 	atf_check -s exit:0 -o match:"${eth_mcaddr} refcount 3" $HIJACKING ifmcstat
    846 	$atf_siocXmulti del vlan0 $mcaddr
    847 	$atf_siocXmulti del vlan0 $mcaddr
    848 	$atf_siocXmulti del vlan0 $mcaddr
    849 	atf_check -s exit:0 -o not-match:"$eth_mcaddr" $HIJACKING ifmcstat
    850 
    851 	# delete all address added to parent device when remove
    852 	# the config of parent interface
    853 	$atf_siocXmulti add vlan0 $mcaddr
    854 	$atf_siocXmulti add vlan0 $mcaddr
    855 	$atf_siocXmulti add vlan0 $mcaddr
    856 	$atf_ifconfig vlan0 -vlanif shmif0
    857 	atf_check -s exit:0 -o not-match:"$eth_mcaddr" $HIJACKING ifmcstat
    858 }
    859 
    860 atf_test_case vlan_multicast cleanup
    861 vlan_multicast_head()
    862 {
    863 	atf_set "descr" "tests of multicast address adding and deleting"
    864 	atf_set "require.progs" "rump_server"
    865 }
    866 
    867 vlan_multicast_body()
    868 {
    869 	rump_server_start $SOCK_LOCAL vlan
    870 
    871 	vlan_multicast_body_common inet
    872 }
    873 
    874 vlan_multicast_cleanup()
    875 {
    876 	$DEBUG && dump
    877 	cleanup
    878 }
    879 
    880 atf_test_case vlan_multicast6 cleanup
    881 vlan_multicast6_head()
    882 {
    883 	atf_set "descr" "tests of multicast address adding and deleting with IPv6"
    884 	atf_set "require.progs" "rump_server"
    885 }
    886 
    887 vlan_multicast6_body()
    888 {
    889 	rump_server_start $SOCK_LOCAL vlan netinet6
    890 
    891 	vlan_multicast_body_common inet6
    892 }
    893 
    894 vlan_multicast6_cleanup()
    895 {
    896 	$DEBUG && dump
    897 	cleanup
    898 }
    899 
    900 atf_test_case vlan_promisc cleanup
    901 vlan_promisc_head()
    902 {
    903 
    904 	atf_set "descr" "tests of IFF_PROMISC of vlan"
    905 	atf_set "require.progs" "rump_server"
    906 }
    907 
    908 vlan_promisc_body()
    909 {
    910 	local atf_ifconfig="atf_check -s exit:0 rump.ifconfig"
    911 	local atf_brconfig="atf_check -s exit:0 $HIJACKING /sbin/brconfig"
    912 	local atf_arp="atf_check -s exit:0 rump.arp"
    913 	local bpfopen="$HIJACKING $(atf_get_srcdir)/bpfopen"
    914 	local macaddr=""
    915 
    916 	rump_server_bpf_start $SOCK_LOCAL vlan bridge
    917 	rump_server_start $SOCK_REMOTE vlan
    918 
    919 	rump_server_add_iface $SOCK_LOCAL shmif0 $BUS
    920 	rump_server_add_iface $SOCK_LOCAL shmif1
    921 	rump_server_add_iface $SOCK_LOCAL vlan0
    922 	rump_server_add_iface $SOCK_LOCAL vlan1
    923 	rump_server_add_iface $SOCK_LOCAL bridge0
    924 
    925 	rump_server_add_iface $SOCK_REMOTE shmif0 $BUS
    926 	rump_server_add_iface $SOCK_REMOTE vlan0
    927 
    928 	macaddr=$(get_macaddr $SOCK_LOCAL shmif1)
    929 
    930 	export RUMP_SERVER=$SOCK_REMOTE
    931 	$atf_ifconfig vlan0 vlan 1 vlanif shmif0
    932 	$atf_ifconfig shmif0 up
    933 	$atf_ifconfig vlan0 inet $IP_REMOTE0/24
    934 	$atf_ifconfig vlan0 up
    935 	$atf_ifconfig -w 10
    936 	$atf_arp -s $IP_LOCAL0 $macaddr
    937 
    938 	export RUMP_SERVER=$SOCK_LOCAL
    939 	$atf_ifconfig bridge0 mtu 1496
    940 	#
    941 	# When vlan IF is PROMISC, the parent is also PROMISC
    942 	#
    943 	$atf_ifconfig vlan0 vlan 1 vlanif shmif0
    944 	$atf_ifconfig shmif0 up
    945 	$atf_ifconfig vlan0 up
    946 
    947 	atf_check -s exit:0 -o not-match:'PROMISC' rump.ifconfig vlan0
    948 	atf_check -s exit:0 -o not-match:'PROMISC' rump.ifconfig shmif0
    949 
    950 	$atf_brconfig bridge0 add vlan0
    951 	$atf_ifconfig bridge0 up
    952 	atf_check -s exit:0 -o match:'PROMISC' rump.ifconfig vlan0
    953 	atf_check -s exit:0 -o match:'PROMISC' rump.ifconfig shmif0
    954 
    955 	$atf_ifconfig bridge0 down
    956 	$atf_brconfig bridge0 delete vlan0
    957 	atf_check -s exit:0 -o not-match:'PROMISC' rump.ifconfig vlan0
    958 	atf_check -s exit:0 -o not-match:'PROMISC' rump.ifconfig shmif0
    959 	$atf_ifconfig vlan0 -vlanif
    960 
    961 	#
    962 	# drop unicast packets that is not for the host
    963 	#
    964 	$atf_ifconfig vlan0 vlan 1 vlanif shmif0
    965 	$atf_ifconfig -w 10
    966 
    967 	$bpfopen -r shmif0 &
    968 	pid=$!
    969 
    970 	atf_check -s exit:0 -o not-match:'PROMISC' rump.ifconfig vlan0
    971 	atf_check -s exit:0 -o match:'PROMISC' rump.ifconfig shmif0
    972 	atf_check -s exit:0 -o ignore rump.ifconfig -z vlan0
    973 	atf_check -s exit:0 -o not-match:'input:.*errors' \
    974 	    rump.ifconfig -v vlan0
    975 
    976 	export RUMP_SERVER=$SOCK_REMOTE
    977 	atf_check -s not-exit:0 -o ignore -e ignore \
    978 	    rump.ping -c 3 -i 0.2 $IP_LOCAL0
    979 
    980 	export RUMP_SERVER=$SOCK_LOCAL
    981 	atf_check -s exit:0 -o match:'input:.*errors' \
    982 	    rump.ifconfig -v vlan0
    983 
    984 	kill -TERM $pid
    985 	sleep 2
    986 
    987 	atf_check -s exit:0 -o not-match:'PROMISC' rump.ifconfig vlan0
    988 	atf_check -s exit:0 -o not-match:'PROMISC' rump.ifconfig shmif0
    989 }
    990 
    991 vlan_promisc_cleanup()
    992 {
    993 
    994 	$DEBUG && dump
    995 	cleanup
    996 }
    997 
    998 atf_init_test_cases()
    999 {
   1000 
   1001 	atf_add_test_case vlan_create_destroy
   1002 	atf_add_test_case vlan_basic
   1003 	atf_add_test_case vlan_auto_follow_mtu
   1004 	atf_add_test_case vlan_vlanid
   1005 	atf_add_test_case vlan_configs
   1006 	atf_add_test_case vlan_bridge
   1007 	atf_add_test_case vlan_multicast
   1008 	atf_add_test_case vlan_promisc
   1009 
   1010 	atf_add_test_case vlan_create_destroy6
   1011 	atf_add_test_case vlan_basic6
   1012 	atf_add_test_case vlan_auto_follow_mtu6
   1013 	atf_add_test_case vlan_vlanid6
   1014 	atf_add_test_case vlan_configs6
   1015 	atf_add_test_case vlan_bridge6
   1016 	atf_add_test_case vlan_multicast6
   1017 }
   1018