summaryrefslogtreecommitdiffstats
path: root/bridge
blob: cf0d1d3e57348852d80c6ab827980bdebcc78200 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
#!/bin/sh
#
# chkconfig: 2345 11 89
# description:	Brings up and configures the ethernet bridge
# processname: bridge

# Source function library.
. /etc/init.d/functions

# Check that networking is up.
if [ "$NETWORKING" = "no" ]
then
	exit 0
fi

RETVAL=0

[ -f /etc/rsbridgeinit.conf ] && . /etc/rsbridgeinit.conf

###### Sample of what /etc/rsbridgeinit.conf should look like
#   bridgeprefix="gbr"
#   #UPDATE_STRING=-b eth2 eth3
#   BRIDGES="0"
#   CSIF[0]="eth2"
#   SSIF[0]="eth3"
##########################

#Enable RSTP if we have /sbin/rstpd
RSTPD=/sbin/rstpd
RSTPCTL=/sbin/rstpctl
RSTP=0
[ -x $RSTPD -a -x $RSTPCTL ] && RSTP=1

slaves () {
 cat /proc/net/bonding/$1 | grep 'Slave Interface' | cut -d: -f2
}

# set interrupt affinity to first cpu
setsmpaffinity() {
    if [[ $1 == bond* ]] ; then
        for sl in `slaves $1`; do
            irq=`grep $sl /proc/interrupts | cut -d: -f1`
            echo 1 > /proc/irq/$irq/smp_affinity
        done
    else
        irq=`grep $1 /proc/interrupts | cut -d: -f1`
        echo 1 > /proc/irq/$irq/smp_affinity
    fi
}

start () {
        [ $RSTP == 1 ] && echo Starting rstpd && daemon $RSTPD ">>" /var/log/rstpd.log "2>&1"
        for b in $BRIDGES ; do
            echo Starting service bridge $bridgeprefix$b
            brctl addbr $bridgeprefix$b  ||  RETVAL=1
            if [ $RSTP == 0 ] ; then
              brctl stp $bridgeprefix$b on 
              brctl setbridgeprio $bridgeprefix$b 65000
            fi

            for br in ${CSIF[$b]} ; do
                echo Adding CSIF $br on $bridgeprefix$b
                ifup $br
                brctl addif $bridgeprefix$b $br  ||  RETVAL=1
            done

            if [ "$1" != "client" ]; then
                for br in ${SSIF[$b]} ; do
                    echo Adding SSIF $br on $bridgeprefix$b
                    ifup $br
                    if [[ $br == bond* ]] ; then
                      for sl in `slaves $br`; do
                        ifconfig $sl down
                      done
                    else
                      ifconfig $br down
                    fi
                    brctl addif $bridgeprefix$b $br  ||  RETVAL=1
                done
            fi
            ifup $bridgeprefix$b
            if [ $RSTP == 1 ]; then 
              rstpctl rstp $bridgeprefix$b on
              rstpctl setbridgeprio $bridgeprefix$b 61440
            fi
        done

        for b in $BRIDGES ; do

            . /etc/sysconfig/network-scripts/ifcfg-$bridgeprefix$b
# We will always have the subnet route entry. If there is a default gateway
# on that subnet, we will have an entry for that as well
            if [ -n "$GATEWAY" ] ; then rttarget=2 ; else rttarget=1 ; fi
            rtcount=x
            
            count=1
            while true ; do
                new_rtcount=`grep -c $bridgeprefix$b /proc/net/route`;
                if [ $new_rtcount != $rtcount ]; then
#DEBUG              echo Number of route entries for $bridgeprefix$b is $new_rtcount
                rtcount=$new_rtcount
                fi
                if [ $rtcount == $rttarget ]; then
#DEBUG              echo Reached target for $bridgeprefix$b
                    break;
                fi
                count=`expr $count + 1`
                if [ $count -gt 12 ]; then
                    echo Incomplete IP configuration for $bridgeprefix$b. Check network config. Aborting.
                    break;
                fi
                echo Incomplete IP configuration for $bridgeprefix$b. Waiting 5 seconds.
                sleep 5
            done
        done
}

stop () {
    for b in $BRIDGES ; do
        echo "Shutting down service bridge $bridgeprefix$b"
        for br in ${SSIF[$b]} ; do
            echo Removing SSIF $br on $bridgeprefix$b
            brctl delif $bridgeprefix$b $br  ||  RETVAL=1
        done
        for br in ${CSIF[$b]} ; do
            echo Removing CSIF $br on $bridgeprefix$b
            brctl delif $bridgeprefix$b $br  ||  RETVAL=1
        done
        ifconfig $bridgeprefix$b down || RETVAL=1
        brctl delbr $bridgeprefix$b  ||  RETVAL=1
     done
     [ $RSTP == 1 ] && killproc rstpd

}

serverif () {
    case "$1" in
      up)
        for b in $BRIDGES ; do
            for br in ${SSIF[$b]} ; do
                echo Enabling $br on $bridgeprefix$b
                if [[ $br == bond* ]] ; then
                  for sl in `slaves $br`; do
                    echo ' ' Enabling slave $sl of $br
                    ifconfig $sl up
                  done
                else
                  ifconfig $br up
                fi
            done
        done
        ;;
      down)
        for b in $BRIDGES ; do
            for br in ${SSIF[$b]} ; do
                echo Disabling $br on $bridgeprefix$b
                if [[ $br == bond* ]]; then
                  for sl in `slaves $br`; do
                    echo ' ' Disabling slave $sl of $br
                    ifconfig $sl down
                  done
                else 
                  ifconfig $br down
                fi
            done
        done
        ;;
      *)
        exit 1
    esac
}

# See how we were called.
case "$1" in
  start)
	start $2
	;;
  stop)
	stop $2
	;;
  status)
    for b in $BRIDGES ; do
        ifconfig $bridgeprefix$b
        brctl showstp $bridgeprefix$b
    done
    ;;
  serverif)
    serverif $2
    ;;
  restart|reload)
	stop
	start
	;;
  *)
	echo $"Usage: $0 {start|stop|status|restart|reload}"
	exit 1
esac

exit $RETVAL