# Allowed modes of the spanning tree protocol.
STP_ALLOWED_MODES="rstp stp"
-function stp_enable() {
+stp_enable() {
local bridge=${1}
assert isset bridge
print 1 > ${SYS_CLASS_NET}/${bridge}/bridge/stp_state
}
-function stp_disable() {
+stp_disable() {
local bridge=${1}
assert isset bridge
print 0 > ${SYS_CLASS_NET}/${bridge}/bridge/stp_state
}
-function stp_is_enabled() {
+stp_is_enabled() {
local bridge=${1}
assert isset bridge
esac
}
-function stp_is_userspace() {
+stp_is_userspace() {
local bridge=${1}
assert isset bridge
esac
}
-function stp_get_name() {
+stp_get_name() {
local proto=${1}
case "${proto}" in
return ${EXIT_OK}
}
-function stp_bridge_set_protocol() {
+stp_bridge_set_protocol() {
local bridge=${1}
assert isset bridge
assert [ $? -eq 0 ]
}
-function stp_bridge_get_protocol() {
+stp_bridge_get_protocol() {
local bridge=${1}
assert isset bridge
return ${EXIT_OK}
}
-function stp_bridge_get_id() {
+stp_bridge_get_id() {
local bridge=${1}
assert isset bridge
return $?
}
-function stp_bridge_get_forward_delay() {
+stp_bridge_get_forward_delay() {
local bridge=${1}
assert isset bridge
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
return ${EXIT_OK}
}
-function stp_bridge_set_hello_time() {
+stp_bridge_set_hello_time() {
local bridge=${1}
assert isset bridge
return ${EXIT_OK}
}
-function stp_bridge_get_max_age() {
+stp_bridge_get_max_age() {
local bridge=${1}
assert isset bridge
return ${EXIT_OK}
}
-function stp_bridge_set_max_age() {
+stp_bridge_set_max_age() {
local bridge=${1}
assert isset bridge
return ${EXIT_OK}
}
-function stp_bridge_get_priority() {
+stp_bridge_get_priority() {
local bridge=${1}
assert isset bridge
return ${EXIT_OK}
}
-function stp_bridge_set_priority() {
+stp_bridge_set_priority() {
local bridge=${1}
assert isset bridge
return ${EXIT_OK}
}
-function stp_bridge_get_designated_root() {
+stp_bridge_get_designated_root() {
local bridge=${1}
assert isset bridge
fi
}
-function stp_bridge_get_root_path_cost() {
+stp_bridge_get_root_path_cost() {
local bridge=${1}
assert isset bridge
return ${EXIT_OK}
}
-function stp_bridge_get_root_port_id() {
+stp_bridge_get_root_port_id() {
local bridge=${1}
assert isset bridge
return ${EXIT_OK}
}
-function stp_bridge_get_root_port() {
+stp_bridge_get_root_port() {
local bridge=${1}
assert isset bridge
return ${EXIT_ERROR}
}
-function stp_bridge_is_root() {
+stp_bridge_is_root() {
local bridge=${1}
assert isset bridge
return ${EXIT_FALSE}
}
-function stp_bridge_get_topology_change_count() {
+stp_bridge_get_topology_change_count() {
local bridge=${1}
assert isset bridge
return ${EXIT_OK}
}
-function stp_bridge_get_topology_change_timer() {
+stp_bridge_get_topology_change_timer() {
local bridge=${1}
assert isset bridge
return ${EXIT_OK}
}
-function stp_bridge_get_topology_change_detected() {
+stp_bridge_get_topology_change_detected() {
local bridge=${1}
assert isset bridge
fi
}
-function stp_port_get_state() {
+stp_port_get_state() {
local bridge=${1}
assert isset bridge
return ${EXIT_OK}
}
-function stp_port_get_id() {
+stp_port_get_id() {
local bridge=${1}
assert isset bridge
return ${EXIT_OK}
}
-function stp_port_get_cost() {
+stp_port_get_cost() {
local bridge=${1}
assert isset bridge
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
return ${EXIT_ERROR}
}
-function __stp_div_100() {
+__stp_div_100() {
local val=${1}
local split=$((${#val} - 2))