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 .
/usr
/lib
/network
/header-zone
24 HOOK_MANPAGE
="network-zone-bridge"
26 HOOK_SETTINGS
="HOOK STP STP_FORWARD_DELAY STP_HELLO STP_MAXAGE STP_MODE"
27 HOOK_SETTINGS
="${HOOK_SETTINGS} STP_PRIORITY MAC MTU"
39 function hook_check
() {
42 assert isoneof STP_MODE stp rstp
43 assert isinteger STP_HELLO
44 assert isinteger STP_FORWARD_DELAY
45 assert isinteger STP_PRIORITY
49 function hook_parse_cmdline
() {
50 while [ $# -gt 0 ]; do
56 STP_MODE
=${1#--stp-mode=}
59 STP_HELLO
=${1#--stp-hello=}
61 --stp-forward-delay=*)
62 STP_FORWARD_DELAY
=${1#--stp-forward-delay=}
65 STP_PRIORITY
=${1#--stp-priority=}
74 warning
"Ignoring unknown option '${1}'"
85 zone_config_read
${zone}
87 # Create the bridge if it does not already exist.
88 if ! device_exists
${zone}; then
89 bridge_create
${zone} \
90 --address=${MAC} --mtu=${MTU}
92 # Adjust MAC address and MTU if needed.
94 device_set_address
${zone} ${MAC}
95 device_set_mtu
${zone} ${MTU}
102 if [ -n "${STP_FORWARD_DELAY}" ]; then
103 stp_bridge_set_forward_delay
${zone} ${STP_FORWARD_DELAY}
106 if [ -n "${STP_HELLO}" ]; then
107 stp_bridge_set_hello_time
${zone} ${STP_HELLO}
110 if [ -n "${STP_MAXAGE}" ]; then
111 stp_bridge_set_max_age
${zone} ${STP_MAXAGE}
114 if [ -n "${STP_PRIORITY}" ]; then
115 stp_bridge_set_priority
${zone} ${STP_PRIORITY}
121 device_set_up
${zone}
123 # XXX Currently, there is a bug (in the linux kernel?) that we need to
124 # set our bridges to promisc mode.
125 device_set_promisc
${zone} on
128 zone_ports_up
${zone}
129 zone_configs_up
${zone}
134 function hook_down
() {
138 if ! device_is_up
${zone}; then
139 warning
"Zone '${zone}' is not up"
143 zone_configs_down
${zone}
144 zone_ports_down
${zone}
146 # XXX See remark in _up().
147 device_set_promisc
${zone} off
149 device_set_down
${zone}
150 bridge_delete
${zone}
155 function hook_status
() {
159 # Print the default header.
160 cli_device_headline
${zone}
162 # Exit if zone is down
163 if ! zone_is_up
${zone}; then
168 cli_headline
2 "Spanning Tree Protocol information"
169 if stp_is_enabled
${zone}; then
170 local proto
=$
(stp_bridge_get_protocol
${zone})
172 cli_print_fmt1
2 "Version" "$(stp_get_name ${proto})"
173 cli_print_fmt1
2 "ID" "$(stp_bridge_get_id ${zone})"
174 cli_print_fmt1
2 "Priority" "$(stp_bridge_get_priority ${zone})"
176 if stp_bridge_is_root
${zone}; then
177 cli_print
2 "This bridge is root."
179 cli_print_fmt1
2 "Designated root" \
180 "$(stp_bridge_get_designated_root ${zone})"
181 cli_print_fmt1
2 "Root path cost" \
182 "$(stp_bridge_get_root_path_cost ${zone})"
186 # Topology information
187 cli_print_fmt1
2 "Topology changing" \
188 "$(stp_bridge_get_topology_change_detected ${zone})"
189 cli_print_fmt1
2 "Topology change time" \
190 "$(beautify_time $(stp_bridge_get_topology_change_timer ${zone}))"
191 cli_print_fmt1
2 "Topology change count" \
192 "$(stp_bridge_get_topology_change_count ${zone})"
195 cli_print
2 "Disabled"
199 cli_headline
2 "Ports"
200 zone_ports_status
${zone}
203 cli_headline
2 "Configurations"
204 zone_configs_cmd status
${zone}