]> git.ipfire.org Git - network.git/commitdiff
bridge: Make enable/disable STP independent from brctl.
authorMichael Tremer <michael.tremer@ipfire.org>
Sun, 23 Sep 2012 15:13:23 +0000 (15:13 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Sun, 23 Sep 2012 15:13:23 +0000 (15:13 +0000)
bridge-stp
functions.stp
hooks/zones/bridge

index fad73816ed68ac638bc800f37ff3233218faf358..fb8240f9cd7144f94b2dcbcbd9537e838d0ea84e 100755 (executable)
 #                                                                             #
 ###############################################################################
 
+EXIT_USERSPACE_STP=0
+EXIT_KERNEL_STP=1
+
 # Change LOG_FACILITY that we will find our messages in syslog.
 LOG_FACILITY=$(basename ${0})
 
 . /usr/lib/network/functions
 
 zone=${1}
-action=${2}
-
 assert isset zone
+
+action=${2}
 assert isset action
 
 # Exit immediately, if zone configuration does not exist.
 # This is for manually created bridges.
 if ! zone_exists ${zone}; then
-       exit 1
+       exit ${EXIT_KERNEL_STP}
 fi
 
-# Check if mstpd is running. If not, try to start it.
-if ! service_is_active mstpd; then
-       service_start "mstpd.service"
+# Read zone configuration.
+zone_config_read ${zone}
 
-       if ! service_is_active "mstpd.service"; then
-               log ERROR "mstpd is not running. STP might not work."
-               exit 1
-       fi
-fi
+# Make sure STP is enabled for this zone.
+assert enabled STP
 
-# Tell mstpd that STP has to be enabled/disabled.
-case "${action}" in
-       start)
-               log DEBUG "Enabling STP for zone '${zone}'."
-               exec mstpctl addbridge ${zone}
-               ;;
-       stop)
-               log DEBUG "Disabling STP for zone '${zone}'."
-               exec mstpctl delbridge ${zone}
+log DEBUG "Configured STP mode is '${STP_MODE}'"
+
+case "${STP_MODE}" in
+       rstp)
+               # Check if mstpd is running. If not, try to start it.
+               if ! service_is_active mstpd; then
+                       service_start "mstpd.service"
+
+                       if ! service_is_active "mstpd.service"; then
+                               log ERROR "mstpd is not running. STP might not work."
+                               exit 1
+                       fi
+               fi
+
+               # Tell mstpd that STP has to be enabled/disabled.
+               case "${action}" in
+                       start)
+                               log DEBUG "Enabling userspace STP for zone '${zone}'"
+                               exec mstpctl addbridge ${zone}
+                               ;;
+                       stop)
+                               log DEBUG "Disabling userspace STP for zone '${zone}'"
+                               exec mstpctl delbridge ${zone}
+                               ;;
+               esac
+
+               log ERROR "Could not properly exec mstpctl."
                ;;
-       *)
-               log ERROR "Unknown action given: ${action}."
-               exit 1
+       stp)
+               case "${action}" in
+                       start)
+                               log DEBUG "Enabling kernel STP for zone '${zone}'"
+                               exit ${EXIT_KERNEL_STP}
+                               ;;
+                       stop)
+                               log DEBUG "Disabling kernel STP for zone '${zone}'"
+                               exit ${EXIT_OK}
+                               ;;
+               esac
                ;;
 esac
 
-log ERROR "Could not properly exec mstpctl."
-exit 1
+# Fall back to kernel STP.
+exit ${EXIT_KERNEL_STP}
index 21505a648cc80c7a8975996840ac95b43818916b..9c3b2a26e9a719b2036b42b493a620f3fd077320 100644 (file)
@@ -30,28 +30,18 @@ STP_ALLOWED_MODES="rstp stp"
 
 function stp_enable() {
        local bridge=${1}
-       local mode=${2}
-
        assert isset bridge
-       assert zone_exists ${bridge}
 
        # Tell the kernel to enable STP.
-       brctl stp ${bridge} on
-
-       # Set the correct protocol version.
-       if [ -z "${mode}" ]; then
-               mode="${STP_DEFAULT_MODE}"
-       fi
-       stp_bridge_set_protocol ${bridge} ${mode}
+       print 1 > ${SYS_CLASS_NET}/${bridge}/bridge/stp_state
 }
 
 function stp_disable() {
        local bridge=${1}
-
        assert isset bridge
-       assert zone_exists ${bridge}
 
-       brctl stp ${bridge} off
+       # Tell the kernel to disable STP.
+       print 0 > ${SYS_CLASS_NET}/${bridge}/bridge/stp_state
 }
 
 function stp_is_enabled() {
@@ -90,9 +80,9 @@ function stp_get_name() {
 
 function stp_bridge_set_protocol() {
        local bridge=${1}
-       local mode=${2}
-
        assert isset bridge
+
+       local mode=${2}
        assert isset mode
 
        if ! listmatch ${mode} ${STP_ALLOWED_MODES}; then
index 6895de0fc51a93c82b65f2620486a8522bd80895..fabb008e3a157ea98ddcfb7493577542e7f94048 100755 (executable)
@@ -97,7 +97,7 @@ function _up() {
 
        # Enable STP
        if enabled STP; then
-               stp_enable ${zone} ${STP_MODE}
+               stp_enable ${zone}
 
                if [ -n "${STP_FORWARD_DELAY}" ]; then
                        stp_bridge_set_forward_delay ${zone} ${STP_FORWARD_DELAY}