From: Michael Tremer Date: Sun, 27 May 2012 13:07:08 +0000 (+0000) Subject: Add functions to set bridge properties. X-Git-Tag: 004~70 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=e2aa12b37e1814e9feffc230f21667d2f92503b3;p=people%2Fms%2Fnetwork.git Add functions to set bridge properties. --- diff --git a/functions.stp b/functions.stp index 8154a9ac..1d3efc69 100644 --- a/functions.stp +++ b/functions.stp @@ -127,7 +127,6 @@ function stp_bridge_get_protocol() { function stp_bridge_get_id() { local bridge=${1} - assert isset bridge __device_get_file ${bridge} "bridge/bridge_id" @@ -144,7 +143,115 @@ function stp_bridge_get_forward_delay() { } function stp_bridge_set_forward_delay() { - : # XXX WANTED + local bridge=${1} + assert isset bridge + + local fdelay=${2} + assert isinteger fdelay + + # Check if the setting we want is already set. + local current_fdelay=$(stp_bridge_get_forward_delay ${bridge}) + [ ${fdelay} -eq ${current_fdelay} ] && return ${EXIT_OK} + + # The smallest value that may be set is 2. + if [ ${fdelay} -lt 2 ]; then + fdelay=2 + fi + + # Set the new value. + log INFO "Changing forward delay for '${bridge}': ${current_fdelay} --> ${fdelay}." + brctl setfd ${bridge} ${fdelay} + + return ${EXIT_OK} +} + +function stp_bridge_get_hello_time() { + local bridge=${1} + assert isset bridge + + local ht=$(__device_get_file ${bridge} "bridge/hello_time") + + # ht is now in seconds * 100. + local split=$((${#ht} - 2)) + ht="${ht:0:${split}}.${ht:${split}:2}" + + # Round the output. + printf "%.0f\n" "${ht}" +} + +function stp_bridge_set_hello_time() { + local bridge=${1} + assert isset bridge + + local hello=${2} + assert isinteger hello + + # Check if the setting we want is already set. + local current_hello=$(stp_bridge_get_hello_time ${bridge}) + [ ${hello} -eq ${current_hello} ] && return ${EXIT_OK} + + # Set the new value. + log INFO "Changing hello time for '${bridge}': ${current_hello} --> ${hello}." + brctl sethello ${bridge} ${hello} + + return ${EXIT_OK} +} + +function stp_bridge_get_max_age() { + local bridge=${1} + assert isset bridge + + local maxage=$(__device_get_file ${bridge} "bridge/max_age") + + # maxage is now in seconds * 100. + local split=$((${#maxage} - 2)) + maxage="${maxage:0:${split}}.${maxage:${split}:2}" + + # Round the output. + printf "%.0f\n" "${maxage}" +} + +function stp_bridge_set_max_age() { + local bridge=${1} + assert isset bridge + + local maxage=${2} + assert isinteger maxage + + # Check if the setting we want is already set. + local current_maxage=$(stp_bridge_get_max_age ${bridge}) + [ ${maxage} -eq ${current_maxage} ] && return ${EXIT_OK} + + # Set the new value. + log INFO "Changing max age for '${bridge}': ${current_maxage} --> ${maxage}." + brctl setmaxage ${bridge} ${maxage} + + return ${EXIT_OK} +} + +function stp_bridge_get_priority() { + local bridge=${1} + assert isset bridge + + __device_get_file ${bridge} "bridge/priority" +} + +function stp_bridge_set_priority() { + local bridge=${1} + assert isset bridge + + local priority=${2} + assert isinteger priority + + # Check if the setting we want is already set. + local current_priority=$(stp_bridge_get_priority ${bridge}) + [ ${priority} -eq ${current_priority} ] && return ${EXIT_OK} + + # Set the new value. + log INFO "Changing priority for '${bridge}': ${current_priority} --> ${priority}." + brctl setbridgeprio ${bridge} ${priority} + + return ${EXIT_OK} } function stp_bridge_get_designated_root() { diff --git a/hooks/zones/bridge b/hooks/zones/bridge index 426a7d18..eae6ece1 100755 --- a/hooks/zones/bridge +++ b/hooks/zones/bridge @@ -19,7 +19,7 @@ # # ############################################################################### -. /lib/network/header-zone +. /usr/lib/network/header-zone HOOK_SETTINGS="HOOK STP STP_FORWARD_DELAY STP_HELLO STP_MAXAGE STP_MODE" HOOK_SETTINGS="${HOOK_SETTINGS} STP_PRIORITY MAC MTU" @@ -94,19 +94,19 @@ function _up() { stp_enable ${zone} ${STP_MODE} if [ -n "${STP_FORWARD_DELAY}" ]; then - brctl setfd ${zone} ${STP_FORWARD_DELAY} + stp_bridge_set_forward_delay ${zone} ${STP_FORWARD_DELAY} fi if [ -n "${STP_HELLO}" ]; then - brctl sethello ${zone} ${STP_HELLO} + stp_bridge_set_hello_time ${zone} ${STP_HELLO} fi if [ -n "${STP_MAXAGE}" ]; then - brctl setmaxage ${zone} ${STP_MAXAGE} + stp_bridge_set_max_age ${zone} ${STP_MAXAGE} fi if [ -n "${STP_PRIORITY}" ]; then - brctl setbridgeprio ${zone} ${STP_PRIORITY} + stp_bridge_set_priority ${zone} ${STP_PRIORITY} fi else stp_disable ${zone}