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
|
|
|
|
2011-02-21 15:11:48 +05:30
|
|
|
_ip()
|
|
|
|
{
|
|
|
|
if [ -x /bin/ip ]; then
|
|
|
|
echo /bin/ip
|
|
|
|
else
|
|
|
|
echo /sbin/ip
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2008-01-11 20:38:57 +05:30
|
|
|
vlan_depend()
|
|
|
|
{
|
2011-02-21 15:11:48 +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
|
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
|
|
|
|
eval vname=\$vlan${vlan}_name
|
|
|
|
[ -z "${vname}" ] && vname="${IFACE}.${vlan}"
|
|
|
|
# 2) flags
|
|
|
|
eval vflags=\$vlan${vlan}_flags
|
|
|
|
# 3) ingress/egress map
|
|
|
|
eval vingress=\$vlan${vlan}_ingress
|
|
|
|
[ -z "${vingress}" ] || vingress="ingress-qos-map ${vingress}"
|
|
|
|
eval vegress=\$vlan${vlan}_egress
|
|
|
|
[ -z "${vegress}" ] || vegress="egress-qos-map ${vegress}"
|
|
|
|
|
|
|
|
e="$(ip link add link "${IFACE}" name "${vname}" 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}"
|
|
|
|
(
|
2008-03-20 01:27:24 +05:30
|
|
|
export RC_SVCNAME="net.${ifname}"
|
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-09-21 16:56:47 +05:30
|
|
|
_exists || return 1
|
|
|
|
|
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}"
|
|
|
|
(
|
2008-03-20 01:27:24 +05:30
|
|
|
export RC_SVCNAME="net.${vlan}"
|
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
|
|
|
|
}
|