2009-05-01 19:41:40 +05:30
|
|
|
# Copyright (c) 2007-2008 Roy Marples <roy@marples.name>
|
2011-06-30 05:16:31 +05:30
|
|
|
# Released under the 2-clause BSD license.
|
2007-11-14 20:52:04 +05:30
|
|
|
|
2008-01-11 20:38:57 +05:30
|
|
|
vlan_depend()
|
|
|
|
{
|
2012-01-09 05:54:03 +05:30
|
|
|
program ip
|
2007-04-05 16:48:42 +05:30
|
|
|
after interface
|
|
|
|
before dhcp
|
|
|
|
}
|
|
|
|
|
|
|
|
_config_vars="$_config_vars vlans"
|
|
|
|
|
2008-01-11 20:38:57 +05:30
|
|
|
_is_vlan()
|
|
|
|
{
|
2007-04-05 16:48:42 +05:30
|
|
|
[ ! -d /proc/net/vlan ] && return 1
|
2007-04-17 16:57:47 +05:30
|
|
|
[ -e /proc/net/vlan/"${IFACE}" ] && return 0
|
|
|
|
grep -Eq "^${IFACE}[[:space:]]+" /proc/net/vlan/config
|
2007-04-05 16:48:42 +05:30
|
|
|
}
|
|
|
|
|
2008-01-11 20:38:57 +05:30
|
|
|
_get_vlans()
|
|
|
|
{
|
2007-04-05 16:48:42 +05:30
|
|
|
[ -e /proc/net/vlan/config ] || return 1
|
2010-08-20 02:47:38 +05:30
|
|
|
sed -n -e 's/^\W*\([^ ]*\) \(.* \) .*'"${IFACE}"'$/\1/p' /proc/net/vlan/config
|
2007-04-05 16:48:42 +05:30
|
|
|
}
|
|
|
|
|
2008-01-11 20:38:57 +05:30
|
|
|
_check_vlan()
|
|
|
|
{
|
2007-11-28 21:15:03 +05:30
|
|
|
if [ ! -d /proc/net/vlan ]; then
|
2007-04-05 16:48:42 +05:30
|
|
|
modprobe 8021q
|
2007-11-28 21:15:03 +05:30
|
|
|
if [ ! -d /proc/net/vlan ]; then
|
2007-04-05 16:48:42 +05:30
|
|
|
eerror "VLAN (802.1q) support is not present in this kernel"
|
|
|
|
return 1
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2008-01-11 20:38:57 +05:30
|
|
|
vlan_pre_start()
|
|
|
|
{
|
2011-02-21 15:11:48 +05:30
|
|
|
local vconfig
|
|
|
|
eval vconfig=\$vconfig_${IFVAR}
|
|
|
|
if [ -n "${vconfig}" ]; then
|
|
|
|
eerror "You must convert your vconfig_ VLAN entries to vlan${N} entries."
|
2007-04-05 16:48:42 +05:30
|
|
|
return 1
|
2011-02-21 15:11:48 +05:30
|
|
|
fi
|
2011-12-27 06:51:34 +05:30
|
|
|
local vlans=
|
|
|
|
eval vlans=\$vlans_${IFVAR}
|
|
|
|
[ -z "$vlans" ] && return 0
|
|
|
|
case " ${MODULES} " in
|
|
|
|
*" ifconfig "*)
|
|
|
|
eerror "sys-apps/iproute2 is required to configure VLANs"
|
|
|
|
return 1 ;;
|
|
|
|
esac
|
2007-04-05 16:48:42 +05:30
|
|
|
}
|
|
|
|
|
2008-01-11 20:38:57 +05:30
|
|
|
vlan_post_start()
|
|
|
|
{
|
2007-10-29 15:15:49 +05:30
|
|
|
local vlans=
|
2008-04-02 03:04:31 +05:30
|
|
|
eval vlans=\$vlans_${IFVAR}
|
2007-10-29 15:15:49 +05:30
|
|
|
[ -z "${vlans}" ] && return 0
|
2011-01-17 15:19:07 +05:30
|
|
|
|
2007-04-05 16:48:42 +05:30
|
|
|
_check_vlan || return 1
|
|
|
|
_exists || return 1
|
|
|
|
|
2011-02-21 15:11:48 +05:30
|
|
|
local vlan= e= s= vname= vflags= vingress= vegress=
|
2007-10-29 15:15:49 +05:30
|
|
|
for vlan in ${vlans}; do
|
2007-04-05 16:48:42 +05:30
|
|
|
einfo "Adding VLAN ${vlan} to ${IFACE}"
|
2011-02-21 15:11:48 +05:30
|
|
|
# We need to gather all interface configuration options
|
|
|
|
# 1) naming. Default to the standard "${IFACE}.${vlan}" but it can be anything
|
2012-07-20 22:50:19 +05:30
|
|
|
eval vname=\$${IFACE}_vlan${vlan}_name
|
|
|
|
[ -z "${vname}" ] && eval vname=\$vlan${vlan}_name
|
2011-02-21 15:11:48 +05:30
|
|
|
[ -z "${vname}" ] && vname="${IFACE}.${vlan}"
|
|
|
|
# 2) flags
|
2012-07-20 22:50:19 +05:30
|
|
|
eval vflags=\$${IFACE}_vlan${vlan}_flags
|
2013-02-18 03:07:27 +05:30
|
|
|
[ -z "${vflags}" ] && eval vflags=\$vlan${vlan}_flags
|
2011-02-21 15:11:48 +05:30
|
|
|
# 3) ingress/egress map
|
2012-07-20 22:50:19 +05:30
|
|
|
eval vingress=\$${IFACE}_vlan${vlan}_ingress
|
|
|
|
[ -z "${vingress}" ] && eval vingress=\$vlan${vlan}_ingress
|
2011-02-21 15:11:48 +05:30
|
|
|
[ -z "${vingress}" ] || vingress="ingress-qos-map ${vingress}"
|
2012-07-20 22:50:19 +05:30
|
|
|
eval vegress=\$${IFACE}_vlan${vlan}_egress
|
|
|
|
[ -z "${vegress}" ] && eval vegress=\$vlan${vlan}_egress
|
2011-02-21 15:11:48 +05:30
|
|
|
[ -z "${vegress}" ] || vegress="egress-qos-map ${vegress}"
|
|
|
|
|
2012-07-20 22:50:19 +05:30
|
|
|
# txqueue
|
2011-10-08 03:15:46 +05:30
|
|
|
local txqueuelen=
|
2012-07-20 22:50:19 +05:30
|
|
|
eval txqueuelen=\$txqueuelen_${IFACE}_vlan${vlan}
|
|
|
|
[ -z "${txqueuelen}" ] && eval txqueuelen=\$txqueuelen_vlan${vlan}
|
|
|
|
# mac
|
2011-10-08 03:15:46 +05:30
|
|
|
local mac=
|
2012-07-20 22:50:19 +05:30
|
|
|
eval mac=\$mac_${IFACE}_vlan${vlan}
|
|
|
|
[ -z "${mac}" ] && eval mac=\$mac_vlan${vlan}
|
|
|
|
# broadcast
|
2011-10-08 03:15:46 +05:30
|
|
|
local broadcast=
|
2012-07-20 22:50:19 +05:30
|
|
|
eval broadcast=\$broadcast_${IFACE}_vlan${vlan}
|
|
|
|
[ -z "${broadcast}" ] && eval broadcast=\$broadcast_vlan${vlan}
|
|
|
|
# mtu
|
2011-10-08 03:15:46 +05:30
|
|
|
local mtu=
|
2012-07-20 22:50:19 +05:30
|
|
|
eval mtu=\$mtu_${IFACE}_vlan${vlan}
|
|
|
|
[ -z "${mtu}" ] && eval mtu=\$mtu_vlan${vlan}
|
|
|
|
|
|
|
|
# combine it all
|
2011-12-13 12:22:09 +05:30
|
|
|
local opts="${txqueuelen:+txqueuelen} ${txqueuelen} ${mac:+address} ${mac} ${broadcast:+broadcast} ${broadcast} ${mtu:+mtu} ${mtu}"
|
2011-10-08 03:15:46 +05:30
|
|
|
|
2012-07-20 22:50:19 +05:30
|
|
|
veinfo "ip link add link \"${IFACE}\" name \"${vname}\" ${opts} type vlan id \"${vlan}\" ${vflags} ${vingress} ${vegress}"
|
2011-10-08 03:15:46 +05:30
|
|
|
e="$(ip link add link "${IFACE}" name "${vname}" ${opts} type vlan id "${vlan}" ${vflags} ${vingress} ${vegress} 2>&1 1>/dev/null)"
|
2007-11-28 21:15:03 +05:30
|
|
|
if [ -n "${e}" ]; then
|
2007-04-05 16:48:42 +05:30
|
|
|
eend 1 "${e}"
|
|
|
|
continue
|
|
|
|
fi
|
|
|
|
|
|
|
|
# We may not want to start the vlan ourselves
|
|
|
|
eval s=\$vlan_start_${IFVAR}
|
2007-11-22 19:01:19 +05:30
|
|
|
yesno ${s:-yes} || continue
|
2007-04-05 16:48:42 +05:30
|
|
|
|
|
|
|
# We need to work out the interface name of our new vlan id
|
2008-04-02 03:04:31 +05:30
|
|
|
local ifname="$(sed -n -e \
|
2009-12-31 01:32:08 +05:30
|
|
|
's/^\([^[:space:]]*\) *| '"${vlan}"' *| .*'"${IFACE}"'$/\1/p' \
|
2007-04-05 16:48:42 +05:30
|
|
|
/proc/net/vlan/config )"
|
|
|
|
mark_service_started "net.${ifname}"
|
|
|
|
(
|
2012-11-07 04:48:32 +05:30
|
|
|
RC_SVCNAME="net.${ifname}" ; export RC_SVCNAME
|
2008-04-02 03:04:31 +05:30
|
|
|
start
|
2007-04-05 16:48:42 +05:30
|
|
|
) || mark_service_stopped "net.${ifname}"
|
|
|
|
done
|
2011-01-17 15:19:07 +05:30
|
|
|
|
2007-04-05 16:48:42 +05:30
|
|
|
return 0
|
|
|
|
}
|
|
|
|
|
2011-09-21 16:56:47 +05:30
|
|
|
vlan_pre_stop()
|
2008-01-11 20:38:57 +05:30
|
|
|
{
|
2007-04-05 16:48:42 +05:30
|
|
|
local vlan=
|
|
|
|
|
2011-12-27 07:26:26 +05:30
|
|
|
_exists || return 0
|
2011-09-21 16:56:47 +05:30
|
|
|
|
2007-10-29 15:15:49 +05:30
|
|
|
for vlan in $(_get_vlans); do
|
2007-04-05 16:48:42 +05:30
|
|
|
einfo "Removing VLAN ${vlan##*.} from ${IFACE}"
|
|
|
|
(
|
2012-11-07 04:48:32 +05:30
|
|
|
RC_SVCNAME="net.${vlan}" ; export RC_SVCNAME
|
2007-04-05 16:48:42 +05:30
|
|
|
stop
|
|
|
|
) && {
|
|
|
|
mark_service_stopped "net.${vlan}"
|
2011-02-21 15:11:48 +05:30
|
|
|
ip link delete "${vlan}" type vlan >/dev/null
|
2007-04-05 16:48:42 +05:30
|
|
|
}
|
|
|
|
done
|
|
|
|
|
|
|
|
return 0
|
|
|
|
}
|