# $NetBSD: t_vlan.sh,v 1.27 2025/03/18 07:58:09 ozaki-r Exp $
#
# Copyright (c) 2016 Internet Initiative Japan Inc.
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
# 1. Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# 2. Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in the
# documentation and/or other materials provided with the distribution.
#
# THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.
#
vlan_basic_body_common()
{
local atf_ifconfig="atf_check -s exit:0 rump.ifconfig"
local outfile=./out
local af=inet
local prefix=24
local local0=$IP_LOCAL0
local remote0=$IP_REMOTE0
local ping_cmd="rump.ping -n -w 1 -c 1"
if [ x"$1" = x"inet6" ]; then
af="inet6"
prefix=64
local0=$IP6_LOCAL0
remote0=$IP6_REMOTE0
ping_cmd="rump.ping6 -n -c 1"
fi
vlan_auto_follow_mtu_body_common()
{
local atf_ifconfig="atf_check -s exit:0 rump.ifconfig"
local outfile=./out
local af=inet
local prefix=24
local local0=$IP_LOCAL0
local remote0=$IP_REMOTE0
local ping_cmd="rump.ping -D -n -w 1 -c 1"
local mtu=1500
local vlan_mtu=`expr $mtu - 4`
# ipv4 header=20bytes, icmp header=8bytes
local padding=`expr $vlan_mtu - 20 - 8`
local over_padding=`expr $vlan_mtu - 20 - 8 + 1`
local nonfrag_msg="$local0 > $remote0: ICMP echo request"
# unused for ipv4
local frag_msg=""
# since upper bound of shmif's mtu is 1500,
# so we lower vlan's mtu instead of raising shmif's.
# to do this, we change the interface's parameter
# such as ND_IFINFO(ifp)->maxmtu that is changed by SIOCSIFMTU.
# $atf_config shmif0 mtu 1600
$atf_ifconfig vlan0 vlan 10 vlanif shmif0
$atf_ifconfig vlan0 mtu 1400
$atf_ifconfig vlan0 -vlanif shmif0
vlan_vlanid_body_common()
{
local atf_ifconfig="atf_check -s exit:0 rump.ifconfig"
local af=inet
local prefix=24
local sysctl_param="net.inet.ip.dad_count=0"
local ping_cmd="rump.ping -n -w 1 -c 1"
local config_and_ping=vlanid_config_and_ping
local local0=$IP_LOCAL0
local local1=$IP_LOCAL1
local remote0=$IP_REMOTE0
local remote1=$IP_REMOTE1
if [ x"$1" = x"inet6" ]; then
af=inet6
prefix=64
sysctl_param="net.inet6.ip6.dad_count=0"
ping_cmd="rump.ping6 -n -c 1"
config_and_ping=vlanid_config_and_ping6
local0=$IP6_LOCAL0
local1=$IP6_LOCAL1
remote0=$IP6_REMOTE0
remote1=$IP6_REMOTE1
fi
vlan_configs_body_common()
{
local atf_ifconfig="atf_check -s exit:0 rump.ifconfig"
export RUMP_SERVER=${SOCK_LOCAL}
$atf_ifconfig shmif0 create
$atf_ifconfig shmif1 create
# unset U/L bit to detect a bug fixed by if_vlan.c:r1.132
$atf_ifconfig shmif0 link b0:a0:75:00:01:00 active
$atf_ifconfig shmif1 link b0:a0:75:00:01:01 active
$atf_ifconfig vlan0 create
$atf_ifconfig bridge0 create
$atf_ifconfig bridge0 up
#
# Add vlan to bridge member
#
$atf_ifconfig bridge0 mtu 1496
# vlan0 can not add to bridge member
# because it is not an ethernet device
atf_check -s not-exit:0 -e match:'Invalid argument' \
$HIJACKING /sbin/brconfig bridge0 add vlan0
vlan_multicast_body_common()
{
local atf_ifconfig="atf_check -s exit:0 rump.ifconfig"
local af="inet"
local local0=$IP_LOCAL0
local local1=$IP_LOCAL1
local mcaddr=$IP_MCADDR0
local eth_mcaddr=$ETH_IP_MCADDR0
local prefix=24
local siocXmulti="$(atf_get_srcdir)/siocXmulti"
local atf_siocXmulti="atf_check -s exit:0 $HIJACKING $siocXmulti"
if [ x"$1" = x"inet6" ]; then
af="inet6"
prefix=64
local0=$IP6_LOCAL0
local1=$IP6_LOCAL1
mcaddr=$IP6_MCADDR0
eth_mcaddr=$ETH_IP6_MCADDR0
fi
test_promisc()
{
local atf_ifconfig="atf_check -s exit:0 rump.ifconfig"
local atf_brconfig="atf_check -s exit:0 $HIJACKING /sbin/brconfig"
local atf_arp="atf_check -s exit:0 rump.arp"
local bpfopen="$HIJACKING $(atf_get_srcdir)/bpfopen"
bpfopen="$bpfopen -dv -b /rump/dev/bpf"
local pidfile="./bpfopen.pid"
local macaddr=""
export RUMP_SERVER=$SOCK_LOCAL
$atf_ifconfig bridge0 mtu 1496
#
# When vlan IF is PROMISC, the parent is also PROMISC
#
$atf_ifconfig vlan0 vlan 1 vlanif shmif0
$atf_ifconfig shmif0 up
$atf_ifconfig vlan0 up
vlan_l2tp_body_common()
{
local atf_ifconfig="atf_check -s exit:0 rump.ifconfig"
local af=$1
local ping_cmd="rump.ping -c 1"
local pfx=24
local local0=$IP_LOCAL0
local local1=$IP_LOCAL1
local remote0=$IP_REMOTE0
local remote1=$IP_REMOTE1
local sysctl_param="net.inet.ip.dad_count=0"
local vid0=10
local vid1=11
local l2tp_laddr=10.222.222.1
local l2tp_lsession=1001
local l2tp_raddr=10.222.222.2
local l2tp_rsession=1002
if [ x"$af" = x"inet6" ]; then
ping_cmd="rump.ping6 -c 1"
rumplib="netinet6"
pfx=64
local0=$IP6_LOCAL0
local1=$IP6_LOCAL1
remote0=$IP6_REMOTE0
remote1=$IP6_REMOTE1
sysctl_param="net.inet6.ip6.dad_count=0"
fi
test_link_state_sync()
{
local ifconfig="atf_check -s exit:0 rump.ifconfig"
rump_server_start $SOCK_LOCAL vlan
export RUMP_SERVER=${SOCK_LOCAL}
## Alone
$ifconfig vlan0 create
# The default state is "down"
check_link_state vlan0 down
$ifconfig vlan0 up
check_link_state vlan0 down
$ifconfig vlan0 down
check_link_state vlan0 down
$ifconfig vlan0 destroy
## "unknown" parent
create_interfaces
# shmif0 is "unknown" until ifconfig linkstr
check_link_state shmif0 unknown
$ifconfig vlan0 vlan 1 vlanif shmif0
# vlan0 syncs with the parent
check_link_state vlan0 unknown
$ifconfig vlan0 up
check_link_state vlan0 unknown
$ifconfig vlan0 -vlanif
# Back to the default
check_link_state vlan0 down
destroy_interfaces
## "up" parent
create_interfaces
$ifconfig shmif0 linkstr $BUS
check_link_state shmif0 up
$ifconfig vlan0 vlan 1 vlanif shmif0
# vlan0 syncs with the parent
check_link_state vlan0 up
$ifconfig vlan0 -vlanif
# Back to the default
check_link_state vlan0 down
destroy_interfaces
## Change parent's link state to "up", "down", then "up"
create_interfaces
$ifconfig shmif0 linkstr $BUS
check_link_state shmif0 up
$ifconfig vlan0 vlan 1 vlanif shmif0
check_link_state vlan0 up
# Down the parent
$ifconfig shmif0 media none
check_link_state shmif0 down
# vlan0 syncs with the parent
check_link_state vlan0 down
# Up the parent again
$ifconfig shmif0 media auto
# vlan0 syncs with the parent
check_link_state vlan0 up
$ifconfig vlan0 -vlanif
# Back to the default
check_link_state vlan0 down
destroy_interfaces
}
add_test create_destroy "tests of creation and deletion of vlan interface"
add_test basic "tests of communications over vlan interfaces"
add_test auto_follow_mtu "tests of setting vlan mtu using IPv4"
add_test vlanid "tests of configuration for vlan id"
add_test configs "tests of configuration except vlan id"
add_test bridge "tests of vlan interfaces with bridges (IPv4)"
add_test multicast "tests of multicast address adding and deleting"
add_test l2tp "tests of vlan(IPv4) over l2tp(IPv4)"
add_test create_destroy6 "tests of creation and deletion of vlan interface with IPv6"
add_test basic6 "tests of communications over vlan interfaces using IPv6"
add_test auto_follow_mtu6 "tests of setting vlan mtu using IPv6"
add_test vlanid6 "tests of configuration for vlan id using IPv6"
add_test configs6 "tests of configuration except vlan id using IPv6"
add_test bridge6 "tests of vlan interfaces with bridges (IPv6)"
add_test multicast6 "tests of multicast address adding and deleting with IPv6"
add_test l2tp6 "tests of vlan(IPv6) over l2tp(IPv4)"
add_test promisc "tests of IFF_PROMISC of vlan"
add_test link_state_sync "tests of link state sync with its parent"
}