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 # XXX Very slow thing, caching?
32 function __rstpctl_cmd
() {
39 rstpctl
${command} | \
40 sed -e "s/\t\t\t/\n/g" \
42 -e "s/\t\s*/___/g" | \
44 [ "${line}" = "${line/___/_}" ] && continue
52 echo "${key}=\"${val}\""
56 function __rstpctl_showbridge_get
() {
61 for line
in $
(__rstpctl_cmd showbridge
${bridge}); do
62 if [ "${line%%=*}" = "${param}" ]; then
72 function __rstpctl_showportdetail_get
() {
78 for line
in $
(__rstpctl_cmd showportdetail
${bridge} ${port}); do
79 if [ "${line%%=*}" = "${param}" ]; then
89 function __rstp_port_enabled
() {
93 local status
=$
(__rstpctl_showportdetail_get
${bridge} ${port} enabled
)
95 if [ "${status}" = "yes" ]; then
102 function __rstp_port_state
() {
106 local output
=$
(__rstpctl_showportdetail_get
${bridge} ${port} state
)
110 function __rstp_port_pathcost
() {
114 __rstpctl_showportdetail_get
${bridge} ${port} path_cost
117 function __rstp_port_designated_root
() {
121 __rstpctl_showportdetail_get
${bridge} ${port} designated_root
124 function __rstp_port_designated_bridge
() {
128 __rstpctl_showportdetail_get
${bridge} ${port} designated_bridge
131 function __rstp_topology_change
() {
134 local state
=$
(__rstpctl_showbridge_get
${bridge} topology_change
)
148 function __rstp_topology_change_count
() {
151 # XXX typo in rstpctl -> toplogy
152 __rstpctl_showbridge_get
${bridge} toplogy_change_count
155 function __rstp_topology_change_time
() {
158 __rstpctl_showbridge_get
${bridge} time_since_topology_change
161 function __rstp_bridge_id
() {
164 local id
=$
(__rstpctl_showbridge_get
${bridge} bridge_id
)
170 function __rstp_designated_root
() {
173 local root
=$
(__rstpctl_showbridge_get
${bridge} designated_root
)
179 function __rstp_pathcost
() {
182 __rstpctl_showbridge_get
${bridge} path_cost
185 function __stp_port_enabled
() {
189 function __stp_port_state
() {
193 function __stp_port_pathcost
() {
197 function __stp_port_designated_root
() {
201 function __stp_port_designated_bridge
() {
205 function stp_port_enabled
() {
206 __stp_wrapper port_enabled $@
209 function stp_port_state
() {
210 __stp_wrapper port_state $@
213 function stp_port_pathcost
() {
214 __stp_wrapper port_pathcost $@
217 function stp_port_designated_root
() {
218 local root
=$
(__stp_wrapper port_designated_root $@
)
220 # Cut prefix 8000. and format mac
225 function stp_port_designated_bridge
() {
226 __stp_wrapper port_designated_bridge $@
229 function stp_topology_change
() {
230 __stp_wrapper topology_change $@
233 function stp_topology_change_count
() {
234 __stp_wrapper topology_change_count $@
237 function stp_topology_change_time
() {
238 __stp_wrapper topology_change_time $@
241 function stp_bridge_id
() {
242 __stp_wrapper bridge_id $@
245 function stp_designated_root
() {
246 __stp_wrapper designated_root $@
249 function stp_pathcost
() {
250 __stp_wrapper pathcost $@
253 function __stp_wrapper
() {
257 # XXX we will detect what kind of protocol the
258 # bridge is running and process the correct funtions
259 local proto_version
="rstp"
261 __
${proto_version}_
${func} $@
264 function stp_mode
() {
268 function stp_enable
() {
272 assert zone_exists
${bridge}
274 brctl stp
${bridge} on
276 local mode
=$
(zone_config_get
${bridge} STP_MODE
)
280 rstpctl setforcevers
${bridge} slow
283 rstpctl setforcevers
${bridge} normal
286 error_log
"Unknown protocol version: ${mode}."
291 function stp_disable
() {
295 assert zone_exists
${bridge}
297 brctl stp
${bridge} off