From: Michael Tremer Date: Sun, 23 Sep 2012 15:13:23 +0000 (+0000) Subject: bridge: Make enable/disable STP independent from brctl. X-Git-Tag: 005~25 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=7d85603e043674a337e620842214f6470ccacd7d;p=network.git bridge: Make enable/disable STP independent from brctl. --- diff --git a/bridge-stp b/bridge-stp index fad73816..fb8240f9 100755 --- a/bridge-stp +++ b/bridge-stp @@ -19,48 +19,73 @@ # # ############################################################################### +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} diff --git a/functions.stp b/functions.stp index 21505a64..9c3b2a26 100644 --- a/functions.stp +++ b/functions.stp @@ -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 diff --git a/hooks/zones/bridge b/hooks/zones/bridge index 6895de0f..fabb008e 100755 --- a/hooks/zones/bridge +++ b/hooks/zones/bridge @@ -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}