/[vps]/baselayout-vserver/trunk/lib/rcscripts/net.modules.d/vlan
Gentoo

Contents of /baselayout-vserver/trunk/lib/rcscripts/net.modules.d/vlan

Parent Directory Parent Directory | Revision Log Revision Log


Revision 3 - (show annotations) (download)
Sat Sep 3 16:10:27 2005 UTC (9 years, 7 months ago) by hollow
File size: 3763 byte(s)
import initial baselayout sources (1.12.0_pre8)
1 #!/bin/bash
2 # Copyright (c) 2004-2005 Gentoo Foundation
3 # Distributed under the terms of the GNU General Public License v2
4
5 # Contributed by Roy Marples (uberlord@gentoo.org)
6
7 # Fix any potential localisation problems
8 # Note that LC_ALL trumps LC_anything_else according to locale(7)
9 vconfig() {
10 LC_ALL=C /sbin/vconfig "$@"
11 }
12
13 # char* vlan_provides(void)
14 #
15 # Returns a string to change module definition for starting up
16 vlan_provides() {
17 echo "vlan"
18 }
19
20 # void vlan_depend(void)
21 #
22 # Sets up the dependancies for the module
23 vlan_depend() {
24 after interface
25 before apipa dhcp
26 }
27
28 # bool vlan_check_installed(void)
29 #
30 # Returns 1 if vconfig is installed, otherwise 0
31 vlan_check_installed() {
32 [[ -x /sbin/vconfig ]] && return 0
33 ${1:-false} && eerror "For VLAN (802.1q) support, emerge net-misc/vconfig"
34 return 1
35 }
36
37 # bool vlan_check_depends(void)
38 #
39 # Checks to see if we have the needed functions
40 vlan_check_depends() {
41 local f
42
43 for f in iface_start iface_stop; do
44 [[ $( type -t "${f}" ) == function ]] && continue
45 eerror "vlan: missing required function ${f}\n"
46 return 1
47 done
48
49 return 0
50 }
51
52 # char* vlan_get_vars(char *interface)
53 #
54 # Returns a string spaced with possible user set
55 # configuration variables
56 vlan_get_vars() {
57 echo "vlans_$1 iface_$1_vlans"
58 }
59
60 # char* vlan_get_vlans(char *interface)
61 #
62 # Fetch the configured vlans for an interface. Outputs a space
63 # separated list on stdout. For example "eth0.1 eth0.2 eth0.3"
64 vlan_get_vlans() {
65 sed -n -e 's/^\(.*[0-9]\) \(.* \) .*'"$1"'$/\1/p' \
66 /proc/net/vlan/config 2>/dev/null
67 }
68
69 # bool vlan_check_kernel(void)
70 #
71 # Checks to see if the 802.1q module is present - if not try and load it
72 # Returns 1 if there is a problem
73 vlan_check_kernel() {
74 [[ -d /proc/net/vlan ]] && return 0
75 /sbin/modprobe 8021q &>/dev/null
76 [[ -d /proc/net/vlan ]] && return 0
77 eerror "VLAN (802.1q) support is not present in this kernel"
78 return 1
79 }
80
81 #bool vlan_pre_start(char *iface)
82 #
83 # Setup vconfig
84 vlan_pre_start() {
85 local iface="$1" opts i x e ifvar=$( bash_variable "$1" )
86
87 eval opts=( \"\$\{vconfig_${ifvar}\[@\]\}\" )
88 [[ -z ${opts} ]] && return 0
89
90 vlan_check_kernel || return 1
91
92 for (( i=0; i<${#opts[@]}; i++ )); do
93 if [[ ${opts[i]} == "set_name_type "* ]]; then
94 x="${opts[i]}"
95 else
96 x="${opts[i]/ / ${iface} }"
97 [[ ${x} == "${opts[i]}" ]] && x="${x} ${iface}"
98 fi
99 e=$( vconfig ${x} 2>&1 1>/dev/null )
100 [[ -z ${e} ]] && continue
101 eerror "vconfig ${x}"
102 eerror "${e}"
103 return 1
104 done
105
106 return 0
107 }
108
109 # bool vlan_post_start(char *iface)
110 #
111 # Starts VLANs for a given interface
112 #
113 # Always returns 0 (true)
114 vlan_post_start() {
115 local iface="$1" vlan vlans vlans_old e ifname ifvar=$( bash_variable "$1" )
116
117 eval vlans=\"\$\{vlans_${ifvar}\}\"
118
119 # BACKWARD COMPATIBILITY: check for old vlan variable name
120 eval vlans_old=\"\$\{iface_${ifvar}_vlans\}\"
121 [[ -n ${vlans_old} && -z ${vlans} ]] && vlans="${vlans_old}"
122
123 [[ -z ${vlans} ]] && return 0
124
125 vlan_check_kernel || return 1
126
127 # Start vlans for this interface
128 for vlan in ${vlans}; do
129 einfo "Adding VLAN ${vlan} to ${iface}"
130 e=$( vconfig add "${iface}" "${vlan}" 2>&1 1>/dev/null )
131 if [[ -n ${e} ]] ; then
132 eend 1 "${e}"
133 continue
134 fi
135 eend 0
136
137 # We need to work out the interface name of our new vlan id
138 ifname=$( \
139 sed -n -e 's/^\([^ \t]*\) *| '"${vlan}"' *| .*'"${iface}"'$/\1/p' \
140 /proc/net/vlan/config
141 )
142 iface_start "${ifname}"
143 done
144
145 return 0
146 }
147
148 # bool vlan_pre_stop(char *iface)
149 #
150 # Stops VLANs for a given interface
151 #
152 # Always returns 0 (true)
153 vlan_pre_stop() {
154 local iface="$1" vlan
155
156 vlan_check_installed || return 0
157
158 for vlan in $( vlan_get_vlans "${iface}" ); do
159 einfo "Removing VLAN ${vlan##*.} from ${iface}"
160 iface_stop "${vlan}"
161 vconfig rem "${vlan}" >/dev/null
162 done
163
164 return 0
165 }
166
167 # vim:ts=4

  ViewVC Help
Powered by ViewVC 1.1.20