From: Michael Tremer Date: Sun, 31 Aug 2014 15:50:21 +0000 (+0200) Subject: bridge: Apply configured cost settings for each port X-Git-Tag: 007~100 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=2c083d5749b566e8be0b9aee301d39cd12bed5ad;p=network.git bridge: Apply configured cost settings for each port --- diff --git a/src/functions/functions.device b/src/functions/functions.device index 7bcee8d5..71265c40 100644 --- a/src/functions/functions.device +++ b/src/functions/functions.device @@ -672,6 +672,22 @@ function __device_get_file() { echo "$(<${path})" } +function __device_set_file() { + assert [ $# -eq 3 ] + + local device="${1}" + local file="${2}" + local value="${3}" + + local path="${SYS_CLASS_NET}/${device}/${file}" + if [ ! -w "${path}" ]; then + log DEBUG "Cannot write to file '${file}' (${value})" + return ${EXIT_ERROR} + fi + + echo "${value}" > "${path}" +} + function device_get_rx_bytes() { local device=${1} diff --git a/src/functions/functions.stp b/src/functions/functions.stp index 433fb34c..4195ad6e 100644 --- a/src/functions/functions.stp +++ b/src/functions/functions.stp @@ -475,6 +475,27 @@ function stp_port_get_cost() { return ${EXIT_ERROR} } +function 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}" -eq "${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 +} + function stp_port_get_designated_root() { local bridge=${1} assert isset bridge diff --git a/src/hooks/zones/bridge b/src/hooks/zones/bridge index 872f4767..e0a56ea6 100644 --- a/src/hooks/zones/bridge +++ b/src/hooks/zones/bridge @@ -283,6 +283,8 @@ function hook_port_up() { local zone="${1}" local port="${2}" + config_read "$(zone_dir "${zone}")/ports/${port}" ${HOOK_PORT_SETTINGS} + port_up "${port}" # Set same MTU to device that the bridge has got @@ -290,7 +292,11 @@ function hook_port_up() { bridge_attach_device "${zone}" "${port}" - # XXX must set cost and prio here + if isset COST; then + stp_port_set_cost "${zone}" "${port}" "${COST}" + fi + + # TODO Apply priority (#10609) exit ${EXIT_OK} }