2009-05-01 19:41:40 +05:30
|
|
|
# Copyright (c) 2007-2008 Roy Marples <roy@marples.name>
|
2008-01-11 21:01:10 +05:30
|
|
|
# All rights reserved. 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()
|
|
|
|
{
|
2007-04-05 16:48:42 +05:30
|
|
|
program /sbin/vconfig
|
|
|
|
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()
|
|
|
|
{
|
2007-10-29 15:15:49 +05:30
|
|
|
local vc="$(_get_array "vconfig_${IFVAR}")"
|
|
|
|
[ -z "${vc}" ] && return 0
|
2007-04-05 16:48:42 +05:30
|
|
|
|
|
|
|
_check_vlan || return 1
|
|
|
|
_exists || return 1
|
|
|
|
|
|
|
|
local v= x= e=
|
2007-10-30 17:08:23 +05:30
|
|
|
local IFS="$__IFS"
|
2007-10-29 15:15:49 +05:30
|
|
|
for v in ${vc}; do
|
|
|
|
unset IFS
|
2007-04-05 16:48:42 +05:30
|
|
|
case "${v}" in
|
2007-11-28 21:15:03 +05:30
|
|
|
set_name_type" "*) x=${v};;
|
2007-10-30 18:38:29 +05:30
|
|
|
*)
|
|
|
|
set -- ${v}
|
|
|
|
x="$1 ${IFACE}"
|
|
|
|
shift
|
|
|
|
x="${x} $@"
|
2007-11-28 21:15:03 +05:30
|
|
|
;;
|
2007-04-05 16:48:42 +05:30
|
|
|
esac
|
|
|
|
|
|
|
|
e="$(vconfig ${x} 2>&1 1>/dev/null)"
|
|
|
|
[ -z "${e}" ] && continue
|
|
|
|
eerror "${e}"
|
|
|
|
return 1
|
|
|
|
done
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
|
|
|
|
local vlan= e= s=
|
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}"
|
|
|
|
e="$(vconfig add "${IFACE}" "${vlan}" 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
|
|
|
|
}
|
|
|
|
|
2008-01-11 20:38:57 +05:30
|
|
|
vlan_post_stop()
|
|
|
|
{
|
2007-04-05 16:48:42 +05:30
|
|
|
local vlan=
|
|
|
|
|
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}"
|
|
|
|
vconfig rem "${vlan}" >/dev/null
|
|
|
|
}
|
|
|
|
done
|
|
|
|
|
|
|
|
return 0
|
|
|
|
}
|