]> git.ipfire.org Git - network.git/commitdiff
network: STP: Make protocol version configureable.
authorMichael Tremer <michael.tremer@ipfire.org>
Fri, 23 Jul 2010 22:38:07 +0000 (00:38 +0200)
committerMichael Tremer <michael.tremer@ipfire.org>
Fri, 23 Jul 2010 22:38:07 +0000 (00:38 +0200)
functions.stp
functions.util
functions.zone
hooks/zones/bridge

index 3474f09d4d8fd89b8fb5523dbf169c0e8bd1956c..a85138f75c8ec67e9943acd38c67f17def5b12db 100644 (file)
 #                                                                             #
 ###############################################################################
 
+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
+}
index 1163634b2678b7bb730da2acef5805f133113f3d..8be825ee90db01de29afb9a2eadeba767f3192ea 100644 (file)
@@ -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}
+}
index 770ce99d5a7a95e3f401ed815332b1601ead7427..8df8c40de8a676061f1829f8b47fa5a528574d30 100644 (file)
@@ -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}"
+       )
+}
index a09f75538ffabb47e71676e9a9e0c0859af0a592..701d3abd15e6044b4bbd70f1f676e5f7a1029c16 100755 (executable)
 
 . /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}