]> git.ipfire.org Git - people/stevee/network.git/commitdiff
bridge: Apply configured cost settings for each port
authorMichael Tremer <michael.tremer@ipfire.org>
Sun, 31 Aug 2014 15:50:21 +0000 (17:50 +0200)
committerMichael Tremer <michael.tremer@ipfire.org>
Sun, 31 Aug 2014 15:50:21 +0000 (17:50 +0200)
src/functions/functions.device
src/functions/functions.stp
src/hooks/zones/bridge

index 7bcee8d53a9d912c46d1d7ca06899a30b6b7561b..71265c40bbf43e4e40e3fd40afa625e6de2c400a 100644 (file)
@@ -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}
 
index 433fb34c8b888670531749d4092080d2029978d4..4195ad6e6e37ca4f2e1af3e3227528d515f99864 100644 (file)
@@ -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
index 872f4767285535c97f94e5d8bc841131b9e96a0f..e0a56ea6f7fb74d7973744e217d1d6f76550e315 100644 (file)
@@ -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}
 }