]> git.ipfire.org Git - people/stevee/network.git/blobdiff - src/functions/functions.stp
Remove the function keyword which is a bashism
[people/stevee/network.git] / src / functions / functions.stp
index 433fb34c8b888670531749d4092080d2029978d4..0e6ae3923f6fe1b7b7eb38008d62591ed71922b9 100644 (file)
@@ -28,7 +28,7 @@ STP_DEFAULT_MODE="rstp"
 # Allowed modes of the spanning tree protocol.
 STP_ALLOWED_MODES="rstp stp"
 
-function stp_enable() {
+stp_enable() {
        local bridge=${1}
        assert isset bridge
 
@@ -36,7 +36,7 @@ function stp_enable() {
        print 1 > ${SYS_CLASS_NET}/${bridge}/bridge/stp_state
 }
 
-function stp_disable() {
+stp_disable() {
        local bridge=${1}
        assert isset bridge
 
@@ -44,7 +44,7 @@ function stp_disable() {
        print 0 > ${SYS_CLASS_NET}/${bridge}/bridge/stp_state
 }
 
-function stp_is_enabled() {
+stp_is_enabled() {
        local bridge=${1}
        assert isset bridge
 
@@ -60,7 +60,7 @@ function stp_is_enabled() {
        esac
 }
 
-function stp_is_userspace() {
+stp_is_userspace() {
        local bridge=${1}
        assert isset bridge
 
@@ -75,7 +75,7 @@ function stp_is_userspace() {
        esac
 }
 
-function stp_get_name() {
+stp_get_name() {
        local proto=${1}
 
        case "${proto}" in
@@ -93,7 +93,7 @@ function stp_get_name() {
        return ${EXIT_OK}
 }
 
-function stp_bridge_set_protocol() {
+stp_bridge_set_protocol() {
        local bridge=${1}
        assert isset bridge
 
@@ -111,7 +111,7 @@ function stp_bridge_set_protocol() {
        assert [ $? -eq 0 ]
 }
 
-function stp_bridge_get_protocol() {
+stp_bridge_get_protocol() {
        local bridge=${1}
 
        assert isset bridge
@@ -146,7 +146,7 @@ function stp_bridge_get_protocol() {
        return ${EXIT_OK}
 }
 
-function stp_bridge_get_id() {
+stp_bridge_get_id() {
        local bridge=${1}
        assert isset bridge
 
@@ -155,7 +155,7 @@ function stp_bridge_get_id() {
        return $?
 }
 
-function stp_bridge_get_forward_delay() {
+stp_bridge_get_forward_delay() {
        local bridge=${1}
        assert isset bridge
 
@@ -169,30 +169,30 @@ function stp_bridge_get_forward_delay() {
        return ${EXIT_OK}
 }
 
-function stp_bridge_set_forward_delay() {
+stp_bridge_set_forward_delay() {
        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
 
+       # 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}
+
        # Set the new value.
-       log INFO "Changing forward delay for '${bridge}': ${current_fdelay} --> ${fdelay}"
-       print "$(( ${fdelay} * 100 ))" > ${SYS_CLASS_NET}/${bridge}/bridge/forward_delay
+       log DEBUG "Setting forward delay on bridge '${bridge}' from '${current_fdelay}' to '${fdelay}'"
+       fwrite "${SYS_CLASS_NET}/${bridge}/bridge/forward_delay" "$(( ${fdelay} * 100 ))"
 
        return ${EXIT_OK}
 }
 
-function stp_bridge_get_hello_time() {
+stp_bridge_get_hello_time() {
        local bridge=${1}
        assert isset bridge
 
@@ -202,7 +202,7 @@ function stp_bridge_get_hello_time() {
        return ${EXIT_OK}
 }
 
-function stp_bridge_set_hello_time() {
+stp_bridge_set_hello_time() {
        local bridge=${1}
        assert isset bridge
 
@@ -220,7 +220,7 @@ function stp_bridge_set_hello_time() {
        return ${EXIT_OK}
 }
 
-function stp_bridge_get_max_age() {
+stp_bridge_get_max_age() {
        local bridge=${1}
        assert isset bridge
 
@@ -230,7 +230,7 @@ function stp_bridge_get_max_age() {
        return ${EXIT_OK}
 }
 
-function stp_bridge_set_max_age() {
+stp_bridge_set_max_age() {
        local bridge=${1}
        assert isset bridge
 
@@ -248,7 +248,7 @@ function stp_bridge_set_max_age() {
        return ${EXIT_OK}
 }
 
-function stp_bridge_get_priority() {
+stp_bridge_get_priority() {
        local bridge=${1}
        assert isset bridge
 
@@ -256,7 +256,7 @@ function stp_bridge_get_priority() {
        return ${EXIT_OK}
 }
 
-function stp_bridge_set_priority() {
+stp_bridge_set_priority() {
        local bridge=${1}
        assert isset bridge
 
@@ -274,7 +274,7 @@ function stp_bridge_set_priority() {
        return ${EXIT_OK}
 }
 
-function stp_bridge_get_designated_root() {
+stp_bridge_get_designated_root() {
        local bridge=${1}
        assert isset bridge
 
@@ -297,7 +297,7 @@ function stp_bridge_get_designated_root() {
        fi
 }
 
-function stp_bridge_get_root_path_cost() {
+stp_bridge_get_root_path_cost() {
        local bridge=${1}
        assert isset bridge
 
@@ -310,7 +310,7 @@ function stp_bridge_get_root_path_cost() {
        return ${EXIT_OK}
 }
 
-function stp_bridge_get_root_port_id() {
+stp_bridge_get_root_port_id() {
        local bridge=${1}
        assert isset bridge
 
@@ -330,7 +330,7 @@ function stp_bridge_get_root_port_id() {
        return ${EXIT_OK}
 }
 
-function stp_bridge_get_root_port() {
+stp_bridge_get_root_port() {
        local bridge=${1}
        assert isset bridge
 
@@ -349,7 +349,7 @@ function stp_bridge_get_root_port() {
        return ${EXIT_ERROR}
 }
 
-function stp_bridge_is_root() {
+stp_bridge_is_root() {
        local bridge=${1}
        assert isset bridge
 
@@ -362,7 +362,7 @@ function stp_bridge_is_root() {
        return ${EXIT_FALSE}
 }
 
-function stp_bridge_get_topology_change_count() {
+stp_bridge_get_topology_change_count() {
        local bridge=${1}
        assert isset bridge
 
@@ -375,7 +375,7 @@ function stp_bridge_get_topology_change_count() {
        return ${EXIT_OK}
 }
 
-function stp_bridge_get_topology_change_timer() {
+stp_bridge_get_topology_change_timer() {
        local bridge=${1}
        assert isset bridge
 
@@ -388,7 +388,7 @@ function stp_bridge_get_topology_change_timer() {
        return ${EXIT_OK}
 }
 
-function stp_bridge_get_topology_change_detected() {
+stp_bridge_get_topology_change_detected() {
        local bridge=${1}
        assert isset bridge
 
@@ -409,7 +409,7 @@ function stp_bridge_get_topology_change_detected() {
        fi
 }
 
-function stp_port_get_state() {
+stp_port_get_state() {
        local bridge=${1}
        assert isset bridge
 
@@ -448,7 +448,7 @@ function stp_port_get_state() {
        return ${EXIT_OK}
 }
 
-function stp_port_get_id() {
+stp_port_get_id() {
        local bridge=${1}
        assert isset bridge
 
@@ -459,7 +459,7 @@ function stp_port_get_id() {
        return ${EXIT_OK}
 }
 
-function stp_port_get_cost() {
+stp_port_get_cost() {
        local bridge=${1}
        assert isset bridge
 
@@ -475,7 +475,28 @@ function stp_port_get_cost() {
        return ${EXIT_ERROR}
 }
 
-function stp_port_get_designated_root() {
+stp_port_set_cost() {
+       assert [ $# -eq 3 ]
+
+       local bridge="${1}"
+       local port="${2}"
+       local cost="${3}"
+
+       local old_cost="$(stp_port_get_cost "${bridge}" "${port}")"
+       if [ "${cost}" = "${old_cost}" ]; then
+               return ${EXIT_OK}
+       fi
+
+       log DEBUG "Setting STP path costs of port '${port}' (bridge '${bridge}') to '${cost}'"
+
+       if stp_is_userspace "${bridge}"; then
+               cmd mstpctl setportpathcost "${bridge}" "${port}" "${cost}"
+       else
+               __device_set_file "${bridge}" "brif/${port}/path_cost" "${cost}"
+       fi
+}
+
+stp_port_get_designated_root() {
        local bridge=${1}
        assert isset bridge
 
@@ -500,7 +521,7 @@ function stp_port_get_designated_root() {
        return ${EXIT_ERROR}
 }
 
-function __stp_div_100() {
+__stp_div_100() {
        local val=${1}
 
        local split=$((${#val} - 2))