/[baselayout]/trunk/net.Linux/vlan.sh
Gentoo

Contents of /trunk/net.Linux/vlan.sh

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2616 - (show annotations) (download) (as text)
Tue Apr 17 11:27:47 2007 UTC (7 years, 5 months ago) by uberlord
File MIME type: text/x-sh
File size: 2236 byte(s)
Fix bridge, vlan and bonding modules to work together, #174792.
1 # Copyright 2004-2007 Gentoo Foundation
2 # Distributed under the terms of the GNU General Public License v2
3
4 vlan_depend() {
5 program /sbin/vconfig
6 after interface
7 before dhcp
8 }
9
10 _config_vars="$_config_vars vlans"
11
12 _is_vlan() {
13 [ ! -d /proc/net/vlan ] && return 1
14 [ -e /proc/net/vlan/"${IFACE}" ] && return 0
15 grep -Eq "^${IFACE}[[:space:]]+" /proc/net/vlan/config
16 }
17
18 _get_vlans() {
19 [ -e /proc/net/vlan/config ] || return 1
20 sed -n -e 's/^\(.*[0-9]\) \(.* \) .*'"${IFACE}"'$/\1/p' /proc/net/vlan/config
21 }
22
23 _check_vlan() {
24 if [ ! -d /proc/net/vlan ] ; then
25 modprobe 8021q
26 if [ ! -d /proc/net/vlan ] ; then
27 eerror "VLAN (802.1q) support is not present in this kernel"
28 return 1
29 fi
30 fi
31 }
32
33 vlan_pre_start() {
34 eval $(_get_array "vconfig_${IFVAR}")
35 [ $# = "0" ] && return 0
36
37 _check_vlan || return 1
38 _exists || return 1
39
40 local v= x= e=
41 for v in "$@" ; do
42 case "${v}" in
43 set_name_type" "*) x=${v} ;;
44 *) x="$(echo "${v}" | sed -e "s/ / ${IFACE} /g")"
45 [ "${x}" = "${v}" ] && x="${x} ${IFACE}"
46 ;;
47 esac
48
49 set -x
50 e="$(vconfig ${x} 2>&1 1>/dev/null)"
51 set +x
52 [ -z "${e}" ] && continue
53 eerror "${e}"
54 return 1
55 done
56 }
57
58 vlan_post_start() {
59 eval $(_get_array "vlans_${IFVAR}")
60 [ $# = "0" ] && return 0
61
62 _check_vlan || return 1
63 _exists || return 1
64
65 local vlan= e= s=
66 for vlan in "$@" ; do
67 einfo "Adding VLAN ${vlan} to ${IFACE}"
68 e="$(vconfig add "${IFACE}" "${vlan}" 2>&1 1>/dev/null)"
69 if [ -n "${e}" ] ; then
70 eend 1 "${e}"
71 continue
72 fi
73
74 # We may not want to start the vlan ourselves
75 eval s=\$vlan_start_${IFVAR}
76 [ "${s:-yes}" != "yes" ] && continue
77
78 # We need to work out the interface name of our new vlan id
79 local ifname="$( \
80 sed -n -e 's/^\([^[:space:]]*\) *| '"${vlan}"' *| .*'"${iface}"'$/\1/p' \
81 /proc/net/vlan/config )"
82 mark_service_started "net.${ifname}"
83 (
84 export SVCNAME="net.${ifname}"
85 start
86 ) || mark_service_stopped "net.${ifname}"
87 done
88
89 return 0
90 }
91
92 vlan_post_stop() {
93 local vlan=
94
95 for vlan in $(_get_vlans) ; do
96 einfo "Removing VLAN ${vlan##*.} from ${IFACE}"
97 (
98 export SVCNAME="net.${vlan}"
99 stop
100 ) && {
101 mark_service_stopped "net.${vlan}"
102 vconfig rem "${vlan}" >/dev/null
103 }
104 done
105
106 return 0
107 }
108
109 # vim: set ts=4 :

  ViewVC Help
Powered by ViewVC 1.1.20