]>
Commit | Line | Data |
---|---|---|
ad02a0eb SH |
1 | #!/bin/sh |
2 | # | |
3 | # chkconfig: 2345 11 89 | |
4 | # description: Brings up and configures the ethernet bridge | |
5 | # processname: bridge | |
6 | ||
7 | # Source function library. | |
8 | . /etc/init.d/functions | |
9 | ||
10 | # Check that networking is up. | |
11 | if [ "$NETWORKING" = "no" ] | |
12 | then | |
13 | exit 0 | |
14 | fi | |
15 | ||
16 | RETVAL=0 | |
17 | ||
18 | [ -f /etc/rsbridgeinit.conf ] && . /etc/rsbridgeinit.conf | |
19 | ||
20 | ###### Sample of what /etc/rsbridgeinit.conf should look like | |
21 | # bridgeprefix="gbr" | |
22 | # #UPDATE_STRING=-b eth2 eth3 | |
23 | # BRIDGES="0" | |
24 | # CSIF[0]="eth2" | |
25 | # SSIF[0]="eth3" | |
26 | ########################## | |
27 | ||
28 | #Enable RSTP if we have /sbin/rstpd | |
29 | RSTPD=/sbin/rstpd | |
30 | RSTPCTL=/sbin/rstpctl | |
31 | RSTP=0 | |
32 | [ -x $RSTPD -a -x $RSTPCTL ] && RSTP=1 | |
33 | ||
34 | slaves () { | |
35 | cat /proc/net/bonding/$1 | grep 'Slave Interface' | cut -d: -f2 | |
36 | } | |
37 | ||
38 | # set interrupt affinity to first cpu | |
39 | setsmpaffinity() { | |
40 | if [[ $1 == bond* ]] ; then | |
41 | for sl in `slaves $1`; do | |
42 | irq=`grep $sl /proc/interrupts | cut -d: -f1` | |
43 | echo 1 > /proc/irq/$irq/smp_affinity | |
44 | done | |
45 | else | |
46 | irq=`grep $1 /proc/interrupts | cut -d: -f1` | |
47 | echo 1 > /proc/irq/$irq/smp_affinity | |
48 | fi | |
49 | } | |
50 | ||
51 | start () { | |
52 | [ $RSTP == 1 ] && echo Starting rstpd && daemon $RSTPD ">>" /var/log/rstpd.log "2>&1" | |
53 | for b in $BRIDGES ; do | |
54 | echo Starting service bridge $bridgeprefix$b | |
55 | brctl addbr $bridgeprefix$b || RETVAL=1 | |
56 | if [ $RSTP == 0 ] ; then | |
57 | brctl stp $bridgeprefix$b on | |
58 | brctl setbridgeprio $bridgeprefix$b 65000 | |
59 | fi | |
60 | ||
61 | for br in ${CSIF[$b]} ; do | |
62 | echo Adding CSIF $br on $bridgeprefix$b | |
63 | ifup $br | |
64 | brctl addif $bridgeprefix$b $br || RETVAL=1 | |
65 | done | |
66 | ||
67 | if [ "$1" != "client" ]; then | |
68 | for br in ${SSIF[$b]} ; do | |
69 | echo Adding SSIF $br on $bridgeprefix$b | |
70 | ifup $br | |
71 | if [[ $br == bond* ]] ; then | |
72 | for sl in `slaves $br`; do | |
73 | ifconfig $sl down | |
74 | done | |
75 | else | |
76 | ifconfig $br down | |
77 | fi | |
78 | brctl addif $bridgeprefix$b $br || RETVAL=1 | |
79 | done | |
80 | fi | |
81 | ifup $bridgeprefix$b | |
82 | if [ $RSTP == 1 ]; then | |
83 | rstpctl rstp $bridgeprefix$b on | |
84 | rstpctl setbridgeprio $bridgeprefix$b 61440 | |
85 | fi | |
86 | done | |
87 | ||
88 | for b in $BRIDGES ; do | |
89 | ||
90 | . /etc/sysconfig/network-scripts/ifcfg-$bridgeprefix$b | |
91 | # We will always have the subnet route entry. If there is a default gateway | |
92 | # on that subnet, we will have an entry for that as well | |
93 | if [ -n "$GATEWAY" ] ; then rttarget=2 ; else rttarget=1 ; fi | |
94 | rtcount=x | |
95 | ||
96 | count=1 | |
97 | while true ; do | |
98 | new_rtcount=`grep -c $bridgeprefix$b /proc/net/route`; | |
99 | if [ $new_rtcount != $rtcount ]; then | |
100 | #DEBUG echo Number of route entries for $bridgeprefix$b is $new_rtcount | |
101 | rtcount=$new_rtcount | |
102 | fi | |
103 | if [ $rtcount == $rttarget ]; then | |
104 | #DEBUG echo Reached target for $bridgeprefix$b | |
105 | break; | |
106 | fi | |
107 | count=`expr $count + 1` | |
108 | if [ $count -gt 12 ]; then | |
109 | echo Incomplete IP configuration for $bridgeprefix$b. Check network config. Aborting. | |
110 | break; | |
111 | fi | |
112 | echo Incomplete IP configuration for $bridgeprefix$b. Waiting 5 seconds. | |
113 | sleep 5 | |
114 | done | |
115 | done | |
116 | } | |
117 | ||
118 | stop () { | |
119 | for b in $BRIDGES ; do | |
120 | echo "Shutting down service bridge $bridgeprefix$b" | |
121 | for br in ${SSIF[$b]} ; do | |
122 | echo Removing SSIF $br on $bridgeprefix$b | |
123 | brctl delif $bridgeprefix$b $br || RETVAL=1 | |
124 | done | |
125 | for br in ${CSIF[$b]} ; do | |
126 | echo Removing CSIF $br on $bridgeprefix$b | |
127 | brctl delif $bridgeprefix$b $br || RETVAL=1 | |
128 | done | |
129 | ifconfig $bridgeprefix$b down || RETVAL=1 | |
130 | brctl delbr $bridgeprefix$b || RETVAL=1 | |
131 | done | |
132 | [ $RSTP == 1 ] && killproc rstpd | |
133 | ||
134 | } | |
135 | ||
136 | serverif () { | |
137 | case "$1" in | |
138 | up) | |
139 | for b in $BRIDGES ; do | |
140 | for br in ${SSIF[$b]} ; do | |
141 | echo Enabling $br on $bridgeprefix$b | |
142 | if [[ $br == bond* ]] ; then | |
143 | for sl in `slaves $br`; do | |
144 | echo ' ' Enabling slave $sl of $br | |
145 | ifconfig $sl up | |
146 | done | |
147 | else | |
148 | ifconfig $br up | |
149 | fi | |
150 | done | |
151 | done | |
152 | ;; | |
153 | down) | |
154 | for b in $BRIDGES ; do | |
155 | for br in ${SSIF[$b]} ; do | |
156 | echo Disabling $br on $bridgeprefix$b | |
157 | if [[ $br == bond* ]]; then | |
158 | for sl in `slaves $br`; do | |
159 | echo ' ' Disabling slave $sl of $br | |
160 | ifconfig $sl down | |
161 | done | |
162 | else | |
163 | ifconfig $br down | |
164 | fi | |
165 | done | |
166 | done | |
167 | ;; | |
168 | *) | |
169 | exit 1 | |
170 | esac | |
171 | } | |
172 | ||
173 | # See how we were called. | |
174 | case "$1" in | |
175 | start) | |
176 | start $2 | |
177 | ;; | |
178 | stop) | |
179 | stop $2 | |
180 | ;; | |
181 | status) | |
182 | for b in $BRIDGES ; do | |
183 | ifconfig $bridgeprefix$b | |
184 | brctl showstp $bridgeprefix$b | |
185 | done | |
186 | ;; | |
187 | serverif) | |
188 | serverif $2 | |
189 | ;; | |
190 | restart|reload) | |
191 | stop | |
192 | start | |
193 | ;; | |
194 | *) | |
195 | echo $"Usage: $0 {start|stop|status|restart|reload}" | |
196 | exit 1 | |
197 | esac | |
198 | ||
199 | exit $RETVAL |