]> git.ipfire.org Git - people/arne_f/network.git/blame - functions.stp
network: Add some initialization handlers.
[people/arne_f/network.git] / functions.stp
CommitLineData
e84e4e76
MT
1#!/bin/bash
2###############################################################################
3# #
4# IPFire.org - A linux based firewall #
5# Copyright (C) 2010 Michael Tremer & Christian Schmidt #
6# #
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. #
11# #
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. #
16# #
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/>. #
19# #
20###############################################################################
21
22# XXX Very slow thing, caching?
23function __rstpctl_cmd() {
24 local command=$@
25
26 local line
27 local key
28 local val
29
30 rstpctl ${command} | \
31 sed -e "s/\t\t\t/\n/g" \
32 -e "s/^ //g" \
33 -e "s/\t\s*/___/g" | \
34 while read line; do
35 [ "${line}" = "${line/___/_}" ] && continue
36
37 key=${line%%___*}
38 key=${key// /_}
39 key=${key^^}
40
41 val=${line#*___}
42
43 echo "${key}=\"${val}\""
44 done
45}
46
47function __rstpctl_showbridge_get() {
48 local bridge=${1}
49 local param=${2^^}
50
51 local line
52 for line in $(__rstpctl_cmd showbridge ${bridge}); do
53 if [ "${line%%=*}" = "${param}" ]; then
54 line="${line##*=}"
55 echo "${line//\"/}"
56 return ${EXIT_OK}
57 fi
58 done
59
60 return ${EXIT_ERROR}
61}
62
63function __rstpctl_showportdetail_get() {
64 local bridge=${1}
65 local port=${2}
66 local param=${3^^}
67
68 local line
69 for line in $(__rstpctl_cmd showportdetail ${bridge} ${port}); do
70 if [ "${line%%=*}" = "${param}" ]; then
71 line="${line##*=}"
72 echo "${line//\"/}"
73 return ${EXIT_OK}
74 fi
75 done
76
77 return ${EXIT_ERROR}
78}
79
80function __rstp_port_enabled() {
81 local bridge=${1}
82 local port=${2}
83
84 local status=$(__rstpctl_showportdetail_get ${bridge} ${port} enabled)
85
86 if [ "${status}" = "yes" ]; then
87 return ${EXIT_OK}
88 fi
89
90 return ${EXIT_ERROR}
91}
92
93function __rstp_port_state() {
94 local bridge=${1}
95 local port=${2}
96
97 local output=$(__rstpctl_showportdetail_get ${bridge} ${port} state)
98 echo "${output^^}"
99}
100
101function __rstp_port_pathcost() {
102 local bridge=${1}
103 local port=${2}
104
105 __rstpctl_showportdetail_get ${bridge} ${port} path_cost
106}
107
108function __rstp_port_designated_root() {
109 local bridge=${1}
110 local port=${2}
111
112 __rstpctl_showportdetail_get ${bridge} ${port} designated_root
113}
114
115function __rstp_port_designated_bridge() {
116 local bridge=${1}
117 local port=${2}
118
119 __rstpctl_showportdetail_get ${bridge} ${port} designated_bridge
120}
121
122function __rstp_topology_change() {
123 local bridge=${1}
124
125 local state=$(__rstpctl_showbridge_get ${bridge} topology_change)
126
127 case "${state}" in
128 yes)
129 echo "${state}"
130 return ${EXIT_OK}
131 ;;
132 no)
133 echo "${state}"
134 return ${EXIT_ERROR}
135 ;;
136 esac
137}
138
139function __rstp_topology_change_count() {
140 local bridge=${1}
141
142 # XXX typo in rstpctl -> toplogy
143 __rstpctl_showbridge_get ${bridge} toplogy_change_count
144}
145
146function __rstp_topology_change_time() {
147 local bridge=${1}
148
149 __rstpctl_showbridge_get ${bridge} time_since_topology_change
150}
151
152function __rstp_bridge_id() {
153 local bridge=${1}
154
155 local id=$(__rstpctl_showbridge_get ${bridge} bridge_id)
156 id=${id:5:12}
157
158 mac_format "${id}"
159}
160
161function __rstp_designated_root() {
162 local bridge=${1}
163
164 local root=$(__rstpctl_showbridge_get ${bridge} designated_root)
165 root=${root:5:12}
166
167 mac_format "${root}"
168}
169
170function __rstp_pathcost() {
171 local bridge=${1}
172
173 __rstpctl_showbridge_get ${bridge} path_cost
174}
175
176function __stp_port_enabled() {
177 : # XXX TBD
178}
179
180function __stp_port_state() {
181 : # XXX TBD
182}
183
184function __stp_port_pathcost() {
185 : # XXX TBD
186}
187
188function __stp_port_designated_root() {
189 : # XXX TBD
190}
191
192function __stp_port_designated_bridge() {
193 : # XXX TBD
194}
195
196function stp_port_enabled() {
197 __stp_wrapper port_enabled $@
198}
199
200function stp_port_state() {
201 __stp_wrapper port_state $@
202}
203
204function stp_port_pathcost() {
205 __stp_wrapper port_pathcost $@
206}
207
208function stp_port_designated_root() {
209 local root=$(__stp_wrapper port_designated_root $@)
210
211 # Cut prefix 8000. and format mac
212 root="${root:5:12}"
213 mac_format "${root}"
214}
215
216function stp_port_designated_bridge() {
217 __stp_wrapper port_designated_bridge $@
218}
219
220function stp_topology_change() {
221 __stp_wrapper topology_change $@
222}
223
224function stp_topology_change_count() {
225 __stp_wrapper topology_change_count $@
226}
227
228function stp_topology_change_time() {
229 __stp_wrapper topology_change_time $@
230}
231
232function stp_bridge_id() {
233 __stp_wrapper bridge_id $@
234}
235
236function stp_designated_root() {
237 __stp_wrapper designated_root $@
238}
239
240function stp_pathcost() {
241 __stp_wrapper pathcost $@
242}
243
244function __stp_wrapper() {
245 local func=${1}
246 shift
247
248 # XXX we will detect what kind of protocol the
249 # bridge is running and process the correct funtions
250 local proto_version="rstp"
251
252 __${proto_version}_${func} $@
253}