2 ###############################################################################
4 # IPFire.org - A linux based firewall #
5 # Copyright (C) 2010 Michael Tremer & Christian Schmidt #
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. #
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. #
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/>. #
20 ###############################################################################
23 # We default to RSTP, because it has the better user experience and
24 # faster convergence times. Despite of that, it completely downgradeable
26 STP_DEFAULT_MODE
="rstp"
28 # Allowed modes of the spanning tree protocol.
29 STP_ALLOWED_MODES
="rstp stp"
31 function stp_enable
() {
36 assert zone_exists
${bridge}
38 # Tell the kernel to enable STP.
39 brctl stp
${bridge} on
41 # Set the correct protocol version.
42 if [ -z "${mode}" ]; then
43 mode
="${STP_DEFAULT_MODE}"
45 stp_bridge_set_protocol
${bridge} ${mode}
48 function stp_disable
() {
52 assert zone_exists
${bridge}
54 brctl stp
${bridge} off
57 function stp_get_name
() {
62 echo "Spanning Tree Protocol"
65 echo "Rapid Spanning Tree Protocol"
68 echo "Multiple Spanning Tree Protocol"
75 function stp_bridge_set_protocol
() {
82 if ! listmatch
${mode} ${STP_ALLOWED_MODES}; then
83 log WARNING
"Unknown protocol version: ${mode}."
84 log WARNING
"Using default mode."
86 mode
="${STP_DEFAULT_MODE}"
89 mstpctl setforcevers
${bridge} ${mode}
93 function stp_bridge_get_protocol
() {
98 # Let's check what the kernel is telling us about it's STP state.
99 local state
=$
(__device_get_file
${bridge} "bridge/stp_state")
107 # Kernel mode STP is running.
112 # User-space STP is running.
115 log ERROR
"Kernel is running in an unknown STP state."
120 # We get here, when STP is running in user-space mode.
122 # Get the current protocol version.
123 mstpctl showbridge
${bridge} force-protocol-version
128 function stp_bridge_get_id
() {
133 __device_get_file
${bridge} "bridge/bridge_id"
138 function stp_bridge_get_forward_delay
() {
143 mstpctl showbridge
${bridge} forward-delay
146 function stp_bridge_set_forward_delay
() {
150 function stp_bridge_get_designated_root
() {
156 local output
=$
(mstpctl showbridge
${bridge} designated-root
)
158 if ! isset output
; then
166 function stp_bridge_get_root_path_cost
() {
171 mstpctl showbridge
${bridge} path-cost
174 function stp_bridge_get_root_port_id
() {
179 local root_port
=$
(mstpctl showbridge
${bridge} root-port
)
181 # Return error, when there is no root port.
182 if [ "${root_port}" = "none" ]; then
190 function stp_bridge_get_root_port
() {
195 local id
=$
(stp_bridge_get_root_port_id
${bridge})
199 for member
in $
(bridge_get_members
${bridge}); do
200 member_id
=$
(stp_port_get_id
${bridge} ${member})
202 if [ "${id}" = "${member_id}" ]; then
211 function stp_bridge_is_root
() {
212 stp_bridge_get_root_port_id $@
>/dev
/null
215 if [ ${ret} -eq ${EXIT_ERROR} ]; then
222 function stp_bridge_get_priority
() {
227 local id
=$
(stp_bridge_get_id
${bridge})
232 function stp_bridge_get_topology_change_count
() {
237 mstpctl showbridge
${bridge} topology-change-count
240 function stp_bridge_get_topology_change_timer
() {
245 mstpctl showbridge
${bridge} time-since-topology-change
248 function stp_bridge_get_topology_change_detected
() {
253 local change
=$
(mstpctl showbridge
${bridge} topology-change
)
266 function stp_port_get_state
() {
273 local state
=$
(mstpctl showportdetail
${bridge} ${port} state
)
278 function stp_port_get_id
() {
285 local id
=$
(__device_get_file
${bridge} "brif/${port}/port_no")
292 function stp_port_get_cost
() {
299 mstpctl showportdetail
${bridge} ${port} external-port-cost
304 function stp_port_get_designated_root
() {
312 output
=$
(mstpctl showportdetail
${bridge} ${port} designated-root
)
314 if [ -n "${output}" ]; then