2 ###############################################################################
4 # IPFire.org - A linux based firewall #
5 # Copyright (C) 2010 Michael Tremer & Christian Schmidt #
7 # This program is free software: you can redistribute it and/or modify #
8 # it under the terms of the GNU General Public License as published by #
9 # the Free Software Foundation, either version 3 of the License, or #
10 # (at your option) any later version. #
12 # This program is distributed in the hope that it will be useful, #
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of #
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
15 # GNU General Public License for more details. #
17 # You should have received a copy of the GNU General Public License #
18 # along with this program. If not, see <http://www.gnu.org/licenses/>. #
20 ###############################################################################
26 # Tell the kernel to enable STP.
27 print
1 > ${SYS_CLASS_NET}/${bridge}/bridge
/stp_state
34 # Tell the kernel to disable STP.
35 print
0 > ${SYS_CLASS_NET}/${bridge}/bridge
/stp_state
42 local state
=$
(__device_get_file
${bridge} bridge
/stp_state
)
58 __device_get_file
${bridge} "bridge/bridge_id"
63 stp_bridge_get_forward_delay
() {
67 local output
=$
(__device_get_file
${bridge} bridge
/forward_delay
)
68 __stp_div_100
${output}
73 stp_bridge_set_forward_delay
() {
78 assert isinteger fdelay
80 # The smallest value that may be set is 2.
81 if [ ${fdelay} -lt 2 ]; then
85 # Check if the setting we want is already set.
86 local current_fdelay
=$
(stp_bridge_get_forward_delay
${bridge})
87 [ ${fdelay} -eq ${current_fdelay} ] && return ${EXIT_OK}
90 log DEBUG
"Setting forward delay on bridge '${bridge}' from '${current_fdelay}' to '${fdelay}'"
91 fappend
"${SYS_CLASS_NET}/${bridge}/bridge/forward_delay" "$(( ${fdelay} * 100 ))"
96 stp_bridge_get_hello_time
() {
100 local ht
=$
(__device_get_file
${bridge} bridge
/hello_time
)
106 stp_bridge_set_hello_time
() {
111 assert isinteger hello
113 # Check if the setting we want is already set.
114 local current_hello
=$
(stp_bridge_get_hello_time
${bridge})
115 [ ${hello} -eq ${current_hello} ] && return ${EXIT_OK}
118 log INFO
"Changing hello time for '${bridge}': ${current_hello} --> ${hello}"
119 print
"$(( ${hello} * 100 ))" > ${SYS_CLASS_NET}/${bridge}/bridge/hellow_time
124 stp_bridge_get_max_age() {
128 local maxage=$(__device_get_file ${bridge} "bridge
/max_age
")
129 __stp_div_100 ${maxage}
134 stp_bridge_set_max_age() {
139 assert isinteger maxage
141 # Check if the setting we want is already set.
142 local current_maxage=$(stp_bridge_get_max_age ${bridge})
143 [ ${maxage} -eq ${current_maxage} ] && return ${EXIT_OK}
146 log INFO "Changing max age
for '${bridge}': ${current_maxage} --> ${maxage}"
147 print "$(( ${maxage} * 100 ))" > ${SYS_CLASS_NET}/${bridge}/bridge/max_age
152 stp_bridge_get_priority() {
156 __device_get_file ${bridge} "bridge/priority"
160 stp_bridge_set_priority() {
165 assert isinteger priority
167 # Check if the setting we want is already set.
168 local current_priority=$(stp_bridge_get_priority ${bridge})
169 [ ${priority} -eq ${current_priority} ] && return ${EXIT_OK}
172 log INFO "Changing priority for '${bridge}': ${current_priority} --> ${priority}"
173 print "${priority}" > ${SYS_CLASS_NET}/${bridge}/bridge
/priority
178 stp_bridge_get_designated_root
() {
184 output
=$
(__device_get_file
${bridge} bridge
/root_id
)
187 # Print output (lowercase).
190 if isset output
; then
197 stp_bridge_get_root_path_cost
() {
201 __device_get_file
${bridge} bridge
/root_path_cost
204 stp_bridge_get_root_port_id
() {
208 __device_get_file
${bridge} bridge
/root_port_id
211 stp_bridge_get_root_port
() {
215 local id
=$
(stp_bridge_get_root_port_id
${bridge})
217 local member member_id
218 for member
in $
(bridge_get_members
${bridge}); do
219 member_id
=$
(stp_port_get_id
${bridge} ${member})
221 if [ "${id}" = "${member_id}" ]; then
230 stp_bridge_is_root
() {
234 local root_path_cost
=$
(stp_bridge_get_root_path_cost
${bridge})
236 if [ "${root_path_cost}" = "0" ]; then
243 stp_bridge_get_topology_change_count
() {
247 __device_get_file
${bridge} bridge
/topology_change
250 stp_bridge_get_topology_change_timer
() {
254 __device_get_file
${bridge} bridge
/topology_change_timer
257 stp_bridge_get_topology_change_detected
() {
263 change
=$
(__device_get_file
${bridge} bridge
/topology_change_detected
)
265 if enabled change
; then
274 stp_port_get_state
() {
281 local state
=$
(__device_get_file
${bridge} brif
/${port}/state
)
314 dec $
(__device_get_file
${bridge} "brif/${port}/port_no")
318 stp_port_get_cost
() {
325 __device_get_file
${bridge} brif
/${port}/path_cost
328 stp_port_set_cost
() {
335 local old_cost
="$(stp_port_get_cost "${bridge}" "${port}")"
336 if [ "${cost}" = "${old_cost}" ]; then
340 log DEBUG
"Setting STP path costs of port '${port}' (bridge '${bridge}') to '${cost}'"
342 __device_set_file
"${bridge}" "brif/${port}/path_cost" "${cost}"
345 stp_port_get_designated_root
() {
352 local output
=$
(__device_get_file
${bridge} brif
/${port}/designated_root
)
354 if isset output
; then
355 mac_format
${output:5}
365 local split=$
((${#val} - 2))
366 val
="${val:0:${split}}.${val:${split}:2}"
369 print
"%.0f" "${val}"