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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2624 - (show annotations) (download) (as text)
Thu Apr 19 06:46:29 2007 UTC (7 years, 7 months ago) by uberlord
File MIME type: text/x-sh
File size: 2274 byte(s)
Fix bridge some more, remove superflous warning from vewarn and error when no interface correctly
1 # Copyright 2004-2007 Gentoo Foundation
2 # Distributed under the terms of the GNU General Public License v2
3
4 bridge_depend() {
5 before interface macnet
6 program /sbin/brctl
7 }
8
9 _config_vars="$_config_vars bridge bridge_add brctl"
10
11 _is_bridge() {
12 brctl show 2>/dev/null | grep -q "^${IFACE}[[:space:]]"
13 }
14
15 bridge_pre_start() {
16 local ports= brif= opts= iface="${IFACE}" e= x=
17 eval $(_get_array "bridge_${IFVAR}")
18 ports="$@"
19 eval brif=\$bridge_add_${IFVAR}
20 eval $(_get_array "brctl_${IFVAR}")
21 opts="$@"
22 [ -z "${ports}" -a -z "${brif}" -a -z "${opts}" ] && return 0
23
24 [ -n "${ports}" ] && bridge_post_stop
25
26 (
27 if [ -z "${ports}" -a -n "${brif}" ] ; then
28 ports="${IFACE}"
29 IFACE="${brif}"
30 else
31 ports="${ports}"
32 metric=1000
33 fi
34
35 if ! _is_bridge ; then
36 ebegin "Creating bridge ${IFACE}"
37 if ! brctl addbr "${IFACE}" ; then
38 eend 1
39 return 1
40 fi
41 fi
42
43 eval $(_get_array "brctl_${IFVAR}")
44 for x in "$@" ; do
45 set -- ${x}
46 x=$1
47 shift
48 set -- "${x}" "${IFACE}" "$@"
49 brctl "$@"
50 done
51
52 if [ -n "${ports}" ] ; then
53 einfo "Adding ports to ${IFACE}"
54 eindent
55
56 eval set -- ${ports}
57 for x in "$@" ; do
58 ebegin "${x}"
59 ifconfig "${x}" promisc up
60 if ! brctl addif "${IFACE}" "${x}" ; then
61 ifconfig "${x}" -promisc 2>/dev/null
62 eend 1
63 return 1
64 fi
65 eend 0
66 done
67 eoutdent
68 fi
69 ) || return 1
70
71 # Bring up the bridge
72 _up
73 }
74
75 bridge_post_stop() {
76 local port= ports= delete=false extra=
77
78 if _is_bridge ; then
79 ebegin "Destroying bridge ${IFACE}"
80 _down
81 ports="$( brctl show 2>/dev/null | \
82 sed -n -e '/^'"${IFACE}"'[[:space:]]/,/^\S/ { /^\('"${IFACE}"'[[:space:]]\|\t\)/s/^.*\t//p }')"
83 delete=true
84 iface=${IFACE}
85 eindent
86 else
87 # Work out if we're added to a bridge for removal or not
88 eval set -- $(brctl show 2>/dev/null | sed -e "s/'/'\\\\''/g" -e "s/$/'/g" -e "s/^/'/g")
89 local line=
90 for line in "$@" ; do
91 set -- ${line}
92 if [ "$3" = "${IFACE}" ] ; then
93 iface=$1
94 break
95 fi
96 done
97 [ -z "${iface}" ] && return 0
98 extra=" from ${iface}"
99 fi
100
101 for port in ${ports} ; do
102 ebegin "Removing port ${port}${extra}"
103 ifconfig "${port}" -promisc
104 brctl delif "${iface}" "${port}"
105 eend $?
106 done
107
108 if ${delete} ; then
109 eoutdent
110 brctl delbr "${iface}"
111 eend $?
112 fi
113
114 return 0
115 }
116
117 # vim: set ts=4 :

  ViewVC Help
Powered by ViewVC 1.1.20