diff options
author | Benedikt Boehm <hollow@gentoo.org> | 2005-10-09 08:31:20 +0000 |
---|---|---|
committer | Benedikt Boehm <hollow@gentoo.org> | 2005-10-09 08:31:20 +0000 |
commit | 53c0ee2f8b484270b6ad60d53c5f7247e9a428db (patch) | |
tree | 693a49c846b08b89cc2c784dc692dd44904ed2ec /net-scripts/net.modules.d/vlan | |
parent | Refreshing baselayout-vserver with revision 1560 from baselayout. (diff) | |
download | baselayout-vserver-53c0ee2f8b484270b6ad60d53c5f7247e9a428db.tar.gz baselayout-vserver-53c0ee2f8b484270b6ad60d53c5f7247e9a428db.tar.bz2 baselayout-vserver-53c0ee2f8b484270b6ad60d53c5f7247e9a428db.zip |
add back net services
svn path=/baselayout-vserver/trunk/; revision=52
Diffstat (limited to 'net-scripts/net.modules.d/vlan')
-rw-r--r-- | net-scripts/net.modules.d/vlan | 169 |
1 files changed, 169 insertions, 0 deletions
diff --git a/net-scripts/net.modules.d/vlan b/net-scripts/net.modules.d/vlan new file mode 100644 index 0000000..a1966d5 --- /dev/null +++ b/net-scripts/net.modules.d/vlan @@ -0,0 +1,169 @@ +#!/bin/bash +# Copyright (c) 2004-2005 Gentoo Foundation +# Distributed under the terms of the GNU General Public License v2 + +# Contributed by Roy Marples (uberlord@gentoo.org) + +# Fix any potential localisation problems +# Note that LC_ALL trumps LC_anything_else according to locale(7) +vconfig() { + LC_ALL=C /sbin/vconfig "$@" +} + +# char* vlan_provides(void) +# +# Returns a string to change module definition for starting up +vlan_provides() { + echo "vlan" +} + +# void vlan_depend(void) +# +# Sets up the dependancies for the module +vlan_depend() { + after interface + before dhcp arping +} + +# bool vlan_check_installed(void) +# +# Returns 1 if vconfig is installed, otherwise 0 +vlan_check_installed() { + [[ -x /sbin/vconfig ]] && return 0 + ${1:-false} && eerror "For VLAN (802.1q) support, emerge net-misc/vconfig" + return 1 +} + +# bool vlan_check_depends(void) +# +# Checks to see if we have the needed functions +vlan_check_depends() { + local f + + for f in iface_start iface_stop; do + [[ $( type -t "${f}" ) == function ]] && continue + eerror "vlan: missing required function ${f}\n" + return 1 + done + + return 0 +} + +# char* vlan_get_vars(char *interface) +# +# Returns a string spaced with possible user set +# configuration variables +vlan_get_vars() { + echo "vlans_$1 iface_$1_vlans" +} + +# char* vlan_get_vlans(char *interface) +# +# Fetch the configured vlans for an interface. Outputs a space +# separated list on stdout. For example "eth0.1 eth0.2 eth0.3" +vlan_get_vlans() { + sed -n -e 's/^\(.*[0-9]\) \(.* \) .*'"$1"'$/\1/p' \ + /proc/net/vlan/config 2>/dev/null +} + +# bool vlan_check_kernel(void) +# +# Checks to see if the 802.1q module is present - if not try and load it +# Returns 1 if there is a problem +vlan_check_kernel() { + [[ -d /proc/net/vlan ]] && return 0 + /sbin/modprobe 8021q &>/dev/null + [[ -d /proc/net/vlan ]] && return 0 + eerror "VLAN (802.1q) support is not present in this kernel" + return 1 +} + +#bool vlan_pre_start(char *iface) +# +# Setup vconfig +vlan_pre_start() { + local iface="$1" opts i x e ifvar=$( bash_variable "$1" ) + + eval opts=( \"\$\{vconfig_${ifvar}\[@\]\}\" ) + [[ -z ${opts} ]] && return 0 + + vlan_check_kernel || return 1 + interface_exists "${iface}" || return 1 + + for (( i=0; i<${#opts[@]}; i++ )); do + if [[ ${opts[i]} == "set_name_type "* ]]; then + x="${opts[i]}" + else + x="${opts[i]/ / ${iface} }" + [[ ${x} == "${opts[i]}" ]] && x="${x} ${iface}" + fi + e=$( vconfig ${x} 2>&1 1>/dev/null ) + [[ -z ${e} ]] && continue + eerror "vconfig ${x}" + eerror "${e}" + return 1 + done + + return 0 +} + +# bool vlan_post_start(char *iface) +# +# Starts VLANs for a given interface +# +# Always returns 0 (true) +vlan_post_start() { + local iface="$1" vlan vlans vlans_old e ifname ifvar=$( bash_variable "$1" ) + + eval vlans=\"\$\{vlans_${ifvar}\}\" + + # BACKWARD COMPATIBILITY: check for old vlan variable name + eval vlans_old=\"\$\{iface_${ifvar}_vlans\}\" + [[ -n ${vlans_old} && -z ${vlans} ]] && vlans="${vlans_old}" + + [[ -z ${vlans} ]] && return 0 + + vlan_check_kernel || return 1 + interface_exists "${iface}" true || return 1 + + # Start vlans for this interface + for vlan in ${vlans}; do + einfo "Adding VLAN ${vlan} to ${iface}" + e=$( vconfig add "${iface}" "${vlan}" 2>&1 1>/dev/null ) + if [[ -n ${e} ]] ; then + eend 1 "${e}" + continue + fi + eend 0 + + # We need to work out the interface name of our new vlan id + ifname=$( \ + sed -n -e 's/^\([^ \t]*\) *| '"${vlan}"' *| .*'"${iface}"'$/\1/p' \ + /proc/net/vlan/config + ) + iface_start "${ifname}" + done + + return 0 +} + +# bool vlan_pre_stop(char *iface) +# +# Stops VLANs for a given interface +# +# Always returns 0 (true) +vlan_pre_stop() { + local iface="$1" vlan + + vlan_check_installed || return 0 + + for vlan in $( vlan_get_vlans "${iface}" ); do + einfo "Removing VLAN ${vlan##*.} from ${iface}" + iface_stop "${vlan}" + vconfig rem "${vlan}" >/dev/null + done + + return 0 +} + +# vim:ts=4 |