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 ###############################################################################
25 assert binary_exists brctl
26 assert binary_exists rstpctl
29 init_register stp_init
31 function __rstpctl_bridge_get
() {
40 rstpctl dumpbridge
${bridge} | \
41 while read bridge key val
; do
42 if [ "${key}" = "${param}" ]; then
51 function __rstpctl_port_get
() {
62 rstpctl dumpports
${bridge} | \
63 while read por key val
; do
64 if [ "${port}" = "${por}" -a "${key}" = "${param}" ]; then
73 function stp_enable
() {
77 assert zone_exists
${bridge}
79 brctl stp
${bridge} on
81 local mode
=$
(zone_config_get
${bridge} STP_MODE
)
85 rstpctl setforcevers
${bridge} slow
88 rstpctl setforcevers
${bridge} normal
91 error_log
"Unknown protocol version: ${mode}."
96 function stp_disable
() {
100 assert zone_exists
${bridge}
102 brctl stp
${bridge} off
105 function stp_bridge_get_protocol
() {
110 local mode
=$
(__rstpctl_bridge_get
${bridge} protocol_version
)
122 function stp_bridge_set_protocol
() {
126 function stp_bridge_get_id
() {
131 case "$(stp_bridge_get_protocol ${bridge})" in
133 __rstpctl_bridge_get
${bridge} "id"
137 __device_get_file
${bridge} "bridge/bridge_id"
145 function stp_bridge_get_forward_delay
() {
150 case "$(stp_bridge_get_protocol ${bridge})" in
152 __rstpctl_bridge_get
${bridge} "bridge_forward_delay"
156 __device_get_file
${bridge} "bridge/forward_delay"
164 function stp_bridge_get_hello_time
() {
169 case "$(stp_bridge_get_protocol ${bridge})" in
171 __rstpctl_bridge_get
${bridge} "bridge_hello_time"
175 __device_get_file
${bridge} "bridge/hello_time"
183 function stp_bridge_get_max_age
() {
188 case "$(stp_bridge_get_protocol ${bridge})" in
190 __rstpctl_bridge_get
${bridge} "bridge_max_age"
194 __device_get_file
${bridge} "bridge/max_age"
202 function stp_bridge_get_designated_root
() {
208 case "$(stp_bridge_get_protocol ${bridge})" in
210 output
=$
(__rstpctl_bridge_get
${bridge} "designated_root")
213 output
=$
(__device_get_file
${bridge} "bridge/root_id")
217 if ! isset output
; then
221 mac_format
"${output:5:12}"
226 function stp_bridge_get_root_path_cost
() {
231 case "$(stp_bridge_get_protocol ${bridge})" in
233 __rstpctl_bridge_get
${bridge} "root_path_cost"
237 __device_get_file
${bridge} "bridge/root_path_cost"
245 function stp_bridge_get_root_port_id
() {
250 case "$(stp_bridge_get_protocol ${bridge})" in
252 __rstpctl_bridge_get
${bridge} "root_port"
256 __device_get_file
${bridge} "bridge/root_port"
264 function stp_bridge_get_root_port
() {
269 local id
=$
(stp_bridge_get_root_port_id
${bridge})
273 for member
in $
(bridge_get_members
${bridge}); do
274 member_id
=$
(stp_port_get_id
${bridge} ${member})
276 if [ "${id}" = "${member_id}" ]; then
285 function stp_bridge_is_root
() {
290 [ -n "$(stp_bridge_get_root_port ${bridge})" ]
293 function stp_bridge_get_priority
() {
298 case "$(stp_bridge_get_protocol ${bridge})" in
300 local output
=$
(__rstpctl_bridge_get
${bridge} "root_path_cost")
305 __device_get_file
${bridge} "bridge/priority"
313 function stp_bridge_get_topology_change_count
() {
318 case "$(stp_bridge_get_protocol ${bridge})" in
320 __rstpctl_bridge_get
${bridge} "topology_change_count"
324 __device_get_file
${bridge} "bridge/topology_change"
332 function stp_bridge_get_topology_change_timer
() {
337 case "$(stp_bridge_get_protocol ${bridge})" in
339 __rstpctl_bridge_get
${bridge} "time_since_topology_change"
343 __device_get_file
${bridge} "bridge/topology_change_timer"
351 function stp_bridge_get_topology_change_detected
() {
356 case "$(stp_bridge_get_protocol ${bridge})" in
358 __rstpctl_bridge_get
${bridge} "topology_change"
362 __device_get_file
${bridge} "bridge/topology_change_detected"
371 STP_STATE
[0]="disabled"
372 STP_STATE
[1]="listening"
373 STP_STATE
[2]="learning"
374 STP_STATE
[3]="forwarding"
375 STP_STATE
[4]="blocking"
377 function stp_port_get_state
() {
385 case "$(stp_bridge_get_protocol ${bridge})" in
387 output
=$
(__rstpctl_port_get
${bridge} ${port} "state")
390 output
=$
(__device_get_file
${bridge} "brif/${port}/state")
392 # Translate int to name
393 output
="${STP_STATE[${output}]}"
397 if ! isset output
; then
406 function stp_port_get_id
() {
413 case "$(stp_bridge_get_protocol ${bridge})" in
415 __rstpctl_port_get
${bridge} ${port} "id"
419 dec $
(__device_get_file
${bridge} "brif/${port}/port_no")
427 function stp_port_get_cost
() {
434 case "$(stp_bridge_get_protocol ${bridge})" in
436 __rstpctl_port_get
${bridge} ${port} "path_cost"
440 __device_get_file
${bridge} "brif/${port}/path_cost"
448 function stp_port_get_designated_root
() {
456 case "$(stp_bridge_get_protocol ${bridge})" in
458 output
=$
(__rstpctl_port_get
${bridge} ${port} "designated_root")
461 output
=$
(__device_get_file
${bridge} "brif/${port}/designated_root")
465 mac_format
${output:5:12}