]> git.ipfire.org Git - people/stevee/network.git/blob - src/helpers/bridge-stp
c98d6a1beea4ba6c6aa3d162649c3fd070a9e4bd
[people/stevee/network.git] / src / helpers / bridge-stp
1 #!/bin/sh
2 ###############################################################################
3 # #
4 # IPFire - An Open Source Firewall Solution #
5 # Copyright (C) 2011 IPFire development team #
6 # #
7 # This program is free software: you can redistribute it and/or modify #
8 # it under the terms of the GNU General Public License as published by #
9 # the Free Software Foundation, either version 3 of the License, or #
10 # (at your option) any later version. #
11 # #
12 # This program is distributed in the hope that it will be useful, #
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of #
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
15 # GNU General Public License for more details. #
16 # #
17 # You should have received a copy of the GNU General Public License #
18 # along with this program. If not, see <http://www.gnu.org/licenses/>. #
19 # #
20 ###############################################################################
21
22 EXIT_USERSPACE_STP=0
23 EXIT_KERNEL_STP=1
24
25 # Change LOG_FACILITY that we will find our messages in syslog.
26 LOG_FACILITY=$(basename ${0})
27
28 . /usr/lib/network/functions
29
30 # Read network configuration.
31 network_config_read
32
33 zone=${1}
34 assert isset zone
35
36 action=${2}
37 assert isset action
38
39 # Exit immediately, if zone configuration does not exist.
40 # This is for manually created bridges.
41 if ! zone_exists ${zone}; then
42 exit ${EXIT_KERNEL_STP}
43 fi
44
45 # Read zone configuration.
46 zone_config_read ${zone}
47
48 # Make sure STP is enabled for this zone.
49 assert enabled STP
50
51 log DEBUG "Configured STP mode is '${STP_MODE}'"
52
53 case "${STP_MODE}" in
54 rstp)
55 # Check if mstpd is running. If not, try to start it.
56 if ! service_is_active mstpd; then
57 service_start "mstpd.service"
58
59 if ! service_is_active "mstpd.service"; then
60 log ERROR "mstpd is not running. STP might not work."
61 exit 1
62 fi
63 fi
64
65 # Set the right protocol that should be used.
66 # Do this after the bridge has been added.
67 (
68 sleep 2
69 stp_bridge_set_protocol "${zone}" "${STP_MODE}"
70 ) &
71
72 # Tell mstpd that STP has to be enabled/disabled.
73 case "${action}" in
74 start)
75 log DEBUG "Enabling userspace STP for zone '${zone}'"
76 exec mstpctl addbridge ${zone}
77 ;;
78 stop)
79 log DEBUG "Disabling userspace STP for zone '${zone}'"
80 exec mstpctl delbridge ${zone}
81 ;;
82 esac
83
84 log ERROR "Could not properly exec mstpctl."
85 ;;
86 stp)
87 case "${action}" in
88 start)
89 log DEBUG "Enabling kernel STP for zone '${zone}'"
90 exit ${EXIT_KERNEL_STP}
91 ;;
92 stop)
93 log DEBUG "Disabling kernel STP for zone '${zone}'"
94 exit ${EXIT_OK}
95 ;;
96 esac
97 ;;
98 esac
99
100 # Fall back to kernel STP.
101 exit ${EXIT_KERNEL_STP}