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 ###############################################################################
22 # XXX Very slow thing, caching?
23 function __rstpctl_cmd
() {
30 rstpctl
${command} | \
31 sed -e "s/\t\t\t/\n/g" \
33 -e "s/\t\s*/___/g" | \
35 [ "${line}" = "${line/___/_}" ] && continue
43 echo "${key}=\"${val}\""
47 function __rstpctl_showbridge_get
() {
52 for line
in $
(__rstpctl_cmd showbridge
${bridge}); do
53 if [ "${line%%=*}" = "${param}" ]; then
63 function __rstpctl_showportdetail_get
() {
69 for line
in $
(__rstpctl_cmd showportdetail
${bridge} ${port}); do
70 if [ "${line%%=*}" = "${param}" ]; then
80 function __rstp_port_enabled
() {
84 local status
=$
(__rstpctl_showportdetail_get
${bridge} ${port} enabled
)
86 if [ "${status}" = "yes" ]; then
93 function __rstp_port_state
() {
97 local output
=$
(__rstpctl_showportdetail_get
${bridge} ${port} state
)
101 function __rstp_port_pathcost
() {
105 __rstpctl_showportdetail_get
${bridge} ${port} path_cost
108 function __rstp_port_designated_root
() {
112 __rstpctl_showportdetail_get
${bridge} ${port} designated_root
115 function __rstp_port_designated_bridge
() {
119 __rstpctl_showportdetail_get
${bridge} ${port} designated_bridge
122 function __rstp_topology_change
() {
125 local state
=$
(__rstpctl_showbridge_get
${bridge} topology_change
)
139 function __rstp_topology_change_count
() {
142 # XXX typo in rstpctl -> toplogy
143 __rstpctl_showbridge_get
${bridge} toplogy_change_count
146 function __rstp_topology_change_time
() {
149 __rstpctl_showbridge_get
${bridge} time_since_topology_change
152 function __rstp_bridge_id
() {
155 local id
=$
(__rstpctl_showbridge_get
${bridge} bridge_id
)
161 function __rstp_designated_root
() {
164 local root
=$
(__rstpctl_showbridge_get
${bridge} designated_root
)
170 function __rstp_pathcost
() {
173 __rstpctl_showbridge_get
${bridge} path_cost
176 function __stp_port_enabled
() {
180 function __stp_port_state
() {
184 function __stp_port_pathcost
() {
188 function __stp_port_designated_root
() {
192 function __stp_port_designated_bridge
() {
196 function stp_port_enabled
() {
197 __stp_wrapper port_enabled $@
200 function stp_port_state
() {
201 __stp_wrapper port_state $@
204 function stp_port_pathcost
() {
205 __stp_wrapper port_pathcost $@
208 function stp_port_designated_root
() {
209 local root
=$
(__stp_wrapper port_designated_root $@
)
211 # Cut prefix 8000. and format mac
216 function stp_port_designated_bridge
() {
217 __stp_wrapper port_designated_bridge $@
220 function stp_topology_change
() {
221 __stp_wrapper topology_change $@
224 function stp_topology_change_count
() {
225 __stp_wrapper topology_change_count $@
228 function stp_topology_change_time
() {
229 __stp_wrapper topology_change_time $@
232 function stp_bridge_id
() {
233 __stp_wrapper bridge_id $@
236 function stp_designated_root
() {
237 __stp_wrapper designated_root $@
240 function stp_pathcost
() {
241 __stp_wrapper pathcost $@
244 function __stp_wrapper
() {
248 # XXX we will detect what kind of protocol the
249 # bridge is running and process the correct funtions
250 local proto_version
="rstp"
252 __
${proto_version}_
${func} $@