From e266c18ee33ca1f55d5ebad49de5ba33b923eb04 Mon Sep 17 00:00:00 2001 From: Michael Tremer Date: Fri, 18 Nov 2011 15:32:10 +0000 Subject: [PATCH] stp: Transition to mstpd. 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 | 57 ++++++++++++++++++++++++++-------------------- hooks/zones/bridge | 4 ++-- 2 files changed, 34 insertions(+), 27 deletions(-) diff --git a/functions.stp b/functions.stp index d6c5c996..b5bbd0f1 100644 --- a/functions.stp +++ b/functions.stp @@ -19,14 +19,14 @@ # # ############################################################################### -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} diff --git a/hooks/zones/bridge b/hooks/zones/bridge index 10836e9f..ed18e6fc 100755 --- a/hooks/zones/bridge +++ b/hooks/zones/bridge @@ -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} -- 2.39.2