# #
###############################################################################
+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=$@
__${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
+}
modprobe ${module}
fi
}
+
+function binary_exists() {
+ local binary=${1}
+
+ if [ -n "$(type -p ${binary})" ]; then
+ return ${EXIT_OK}
+ fi
+
+ return ${EXIT_ERROR}
+}
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}"
+ )
+}
. /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
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
--stp=*)
STP=${1#--stp=}
;;
+ --stp-mode=*)
+ STP_MODE=${1#--stp-mode=}
+ ;;
--stp-hello=*)
STP_HELLO=${1#--stp-hello=}
;;
# 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}
brctl setbridgeprio ${zone} ${STP_PRIORITY}
fi
else
- brctl stp ${zone} off
+ stp_disable ${zone}
fi
device_set_up ${zone}