forked from iwilson16/mstpd
-
Notifications
You must be signed in to change notification settings - Fork 1
/
bridge-stp
executable file
·70 lines (65 loc) · 1.73 KB
/
bridge-stp
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
#!/bin/bash
#
# Script to start/stop spanning tree called from kernel
# Make sure umask is sane
umask 022
# Set up a default search path.
PATH="/sbin:/usr/sbin:/bin:/usr/bin"
export PATH
if [ $# -ne 2 ]; then
echo "Usage: bridge-stp <bridge> {start|stop}"
exit 1
fi
bridge=$1
service=mstpd
pid_file=/var/run/${service}.pid
bin_dir=/sbin
net_dir=/sys/class/net
# Set this to the list of bridges for which MSTP should be used.
# Comment this out to allow any valid bridge to use used.
MSTP_BRIDGES="br0"
# Set $pid to pids from /var/run* for {program}. $pid should be declared
# local in the caller.
# Returns LSB exit code for the 'status' action.
checkpid()
{
pid=
if [ -f "$1" ] ; then
local line p
read line < "$pid_file"
for p in $line ; do
[ -z "${p//[0-9]/}" -a -d "/proc/$p" ] && pid="$pid $p"
done
if [ -n "$pid" ]; then
return 0
fi
return 1 # "Program is dead and /var/run pid file exists"
fi
return 3 # "Program is not running"
}
case $2 in
start)
checkpid $pid_file || exit 1
if [ -d "$net_dir/$bridge/bridge" ]; then
allowed=1
if [[ -n "$MSTP_BRIDGES" ]]; then
allowed=0
for b in $MSTP_BRIDGES; do
if [ "$bridge" == "$b" ]; then
allowed=1
fi
done
fi
if [[ "$allowed" -eq 1 ]]; then
exec $bin_dir/mstpctl addbridge $bridge
fi
fi
exit 1 ;;
stop)
exec $bin_dir/mstpctl delbridge $bridge
;;
*)
echo "Unknown action:" $2
echo "Usage: bridge-stp <bridge> {start|stop}"
exit 1
esac