]> git.ipfire.org Git - people/ms/network.git/commitdiff
stp: Transition to mstpd.
authorMichael Tremer <michael.tremer@ipfire.org>
Fri, 18 Nov 2011 15:32:10 +0000 (15:32 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Fri, 18 Nov 2011 15:32:10 +0000 (15:32 +0000)
This is the first commit of changing the STP code, that will
fully rely on mstpd for STP.

In this commit, we tell mstpd about the settings, the user did.

functions.stp
hooks/zones/bridge

index d6c5c99676cd3b482c6dd5879d9c6067eb5f1141..b5bbd0f1dea25fd5bb93dcee2757449bce457ccb 100644 (file)
 #                                                                             #
 ###############################################################################
 
-function stp_init() {
-       module_load stp
+# The default mode.
+#   We default to RSTP, because it has the better user experience and
+#   faster convergence times. Despite of that, it completely downgradeable
+#   to plain STP.
+STP_DEFAULT_MODE="rstp"
 
-       assert binary_exists brctl
-       assert binary_exists rstpctl
-}
-
-init_register stp_init
+# Allowed modes of the spanning tree protocol.
+STP_ALLOWED_MODES="rstp stp"
 
 function __rstpctl_bridge_get() {
        local bridge=${1}
@@ -72,26 +72,19 @@ function __rstpctl_port_get() {
 
 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
 
-       local mode=$(zone_config_get ${bridge} STP_MODE)
-
-       case "${mode}" in
-               stp)
-                       rstpctl setforcevers ${bridge} slow
-                       ;;
-               rstp)
-                       rstpctl setforcevers ${bridge} normal
-                       ;;
-               *)
-                       log WARNING "Unknown protocol version: ${mode}."
-                       log WARNING "Using default mode."
-                       ;;
-       esac
+       # Set the correct protocol version.
+       if [ -z "${mode}" ]; then
+               mode="${STP_DEFAULT_MODE}"
+       fi
+       stp_bridge_set_protocol ${bridge} ${mode}
 }
 
 function stp_disable() {
@@ -103,6 +96,24 @@ function stp_disable() {
        brctl stp ${bridge} off
 }
 
+function stp_bridge_set_protocol() {
+       local bridge=${1}
+       local mode=${2}
+
+       assert isset bridge
+       assert isset mode
+
+       if ! listmatch ${mode} ${STP_ALLOWED_MODES}; then
+               log WARNING "Unknown protocol version: ${mode}."
+               log WARNING "Using default mode."
+
+               mode="${STP_DEFAULT_MODE}"
+       fi
+
+       mstpctl setforcevers ${bridge} ${mode}
+       assert [ $? -eq 0 ]
+}
+
 function stp_bridge_get_protocol() {
        local bridge=${1}
 
@@ -130,10 +141,6 @@ function stp_bridge_get_protocol() {
        esac
 }
 
-function stp_bridge_set_protocol() {
-       : XXX WANTED
-}
-
 function stp_bridge_get_id() {
        local bridge=${1}
 
index 10836e9f8412f0706b6fec4a4fdde6089eb5be2a..ed18e6fcc3e47336d0fb9b150ff521aeff93d86b 100755 (executable)
@@ -32,7 +32,7 @@ STP_MODE="rstp"
 STP_FORWARD_DELAY=0
 STP_HELLO=2
 STP_MAXAGE=20
-STP_PRIORITY=512 # XXX check out better value
+STP_PRIORITY=512
 
 function _check() {
        assert ismac MAC
@@ -91,7 +91,7 @@ function _up() {
 
        # Enable STP
        if enabled STP; then
-               stp_enable ${zone}
+               stp_enable ${zone} ${STP_MODE}
 
                if [ -n "${STP_FORWARD_DELAY}" ]; then
                        brctl setfd ${zone} ${STP_FORWARD_DELAY}