From 6b3f9c8534debe894b0cd9528c522968c86cbfd9 Mon Sep 17 00:00:00 2001 From: Michael Tremer Date: Sat, 24 Jul 2010 00:38:07 +0200 Subject: [PATCH] network: STP: Make protocol version configureable. --- functions.stp | 45 +++++++++++++++++++++++++++++++++++++++++++++ functions.util | 10 ++++++++++ functions.zone | 14 ++++++++++++++ hooks/zones/bridge | 13 +++++++++---- 4 files changed, 78 insertions(+), 4 deletions(-) diff --git a/functions.stp b/functions.stp index 3474f09d..a85138f7 100644 --- a/functions.stp +++ b/functions.stp @@ -19,6 +19,15 @@ # # ############################################################################### +function stp_init() { + module_load stp + + assert binary_exists brctl + assert binary_exists rstpctl +} + +init_register stp_init + # XXX Very slow thing, caching? function __rstpctl_cmd() { local command=$@ @@ -251,3 +260,39 @@ function __stp_wrapper() { __${proto_version}_${func} $@ } + +function stp_mode() { + : # XXX wanted +} + +function stp_enable() { + local bridge=${1} + + assert isset bridge + assert zone_exists ${bridge} + + 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 + ;; + *) + error_log "Unknown protocol version: ${mode}." + ;; + esac +} + +function stp_disable() { + local bridge=${1} + + assert isset bridge + assert zone_exists ${bridge} + + brctl stp ${bridge} off +} diff --git a/functions.util b/functions.util index 1163634b..8be825ee 100644 --- a/functions.util +++ b/functions.util @@ -376,3 +376,13 @@ function module_load() { modprobe ${module} fi } + +function binary_exists() { + local binary=${1} + + if [ -n "$(type -p ${binary})" ]; then + return ${EXIT_OK} + fi + + return ${EXIT_ERROR} +} diff --git a/functions.zone b/functions.zone index 770ce99d..8df8c40d 100644 --- a/functions.zone +++ b/functions.zone @@ -643,3 +643,17 @@ function zone_config_set() { zone_config_write ${zone} ) } + +function zone_config_get() { + local zone=${1} + local key=${2} + + assert isset zone + assert isset key + + ( + zone_config_read ${zone} + + echo "${!key}" + ) +} diff --git a/hooks/zones/bridge b/hooks/zones/bridge index a09f7553..701d3abd 100755 --- a/hooks/zones/bridge +++ b/hooks/zones/bridge @@ -21,13 +21,14 @@ . /lib/network/header-zone -HOOK_SETTINGS="HOOK STP STP_FORWARD_DELAY STP_HELLO STP_MAXAGE STP_PRIORITY" -HOOK_SETTINGS="${HOOK_SETTINGS} MAC MTU" +HOOK_SETTINGS="HOOK STP STP_FORWARD_DELAY STP_HELLO STP_MAXAGE STP_MODE" +HOOK_SETTINGS="${HOOK_SETTINGS} STP_PRIORITY MAC MTU" # Default values MAC=$(mac_generate) MTU=1500 STP="on" +STP_MODE="rstp" STP_FORWARD_DELAY=0 STP_HELLO=2 STP_MAXAGE=20 @@ -36,6 +37,7 @@ STP_PRIORITY=512 # XXX check out better value function _check() { assert ismac MAC assert isbool STP + assert isoneof STP_MODE stp rstp assert isinteger STP_HELLO assert isinteger STP_FORWARD_DELAY assert isinteger STP_PRIORITY @@ -48,6 +50,9 @@ function _parse_cmdline() { --stp=*) STP=${1#--stp=} ;; + --stp-mode=*) + STP_MODE=${1#--stp-mode=} + ;; --stp-hello=*) STP_HELLO=${1#--stp-hello=} ;; @@ -86,7 +91,7 @@ function _up() { # Enable STP if enabled STP; then - brctl stp ${zone} on + stp_enable ${zone} if [ -n "${STP_FORWARD_DELAY}" ]; then brctl setfd ${zone} ${STP_FORWARD_DELAY} @@ -104,7 +109,7 @@ function _up() { brctl setbridgeprio ${zone} ${STP_PRIORITY} fi else - brctl stp ${zone} off + stp_disable ${zone} fi device_set_up ${zone} -- 2.39.2