]> git.ipfire.org Git - people/arne_f/network.git/blame - hooks/zones/bridge
network: STP: Make protocol version configureable.
[people/arne_f/network.git] / hooks / zones / bridge
CommitLineData
1848564d
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. /lib/network/header-zone
23
6b3f9c85
MT
24HOOK_SETTINGS="HOOK STP STP_FORWARD_DELAY STP_HELLO STP_MAXAGE STP_MODE"
25HOOK_SETTINGS="${HOOK_SETTINGS} STP_PRIORITY MAC MTU"
1848564d
MT
26
27# Default values
28MAC=$(mac_generate)
29MTU=1500
30STP="on"
6b3f9c85 31STP_MODE="rstp"
1848564d
MT
32STP_FORWARD_DELAY=0
33STP_HELLO=2
34STP_MAXAGE=20
d82cf370 35STP_PRIORITY=512 # XXX check out better value
1848564d
MT
36
37function _check() {
38 assert ismac MAC
39 assert isbool STP
6b3f9c85 40 assert isoneof STP_MODE stp rstp
1848564d
MT
41 assert isinteger STP_HELLO
42 assert isinteger STP_FORWARD_DELAY
d82cf370 43 assert isinteger STP_PRIORITY
1848564d
MT
44 assert isinteger MTU
45}
46
47function _parse_cmdline() {
48 while [ $# -gt 0 ]; do
49 case "${1}" in
50 --stp=*)
51 STP=${1#--stp=}
52 ;;
6b3f9c85
MT
53 --stp-mode=*)
54 STP_MODE=${1#--stp-mode=}
55 ;;
1848564d
MT
56 --stp-hello=*)
57 STP_HELLO=${1#--stp-hello=}
58 ;;
59 --stp-forward-delay=*)
60 STP_FORWARD_DELAY=${1#--stp-forward-delay=}
61 ;;
d82cf370
MT
62 --stp-priority=*)
63 STP_PRIORITY=${1#--stp-priority=}
64 ;;
1848564d
MT
65 --mtu=*)
66 MTU=${1#--mtu=}
67 ;;
68 --mac=*)
69 MAC=${1#--mac=}
70 ;;
71 *)
72 warning "Ignoring unknown option '${1}'"
73 ;;
74 esac
75 shift
76 done
77}
78
79function _up() {
80 local zone=${1}
81 shift
82
83 config_read ${ZONE_DIR}/${zone}/settings
84
85 if ! device_exists ${zone}; then
86 brctl addbr ${zone}
87 fi
88
7cbea20d 89 [ -n "${MAC}" ] && device_set_address ${zone} ${MAC}
1848564d
MT
90 [ -n "${MTU}" ] && device_set_mtu ${zone} ${MTU}
91
92 # Enable STP
93 if enabled STP; then
6b3f9c85 94 stp_enable ${zone}
1848564d
MT
95
96 if [ -n "${STP_FORWARD_DELAY}" ]; then
97 brctl setfd ${zone} ${STP_FORWARD_DELAY}
98 fi
99
100 if [ -n "${STP_HELLO}" ]; then
101 brctl sethello ${zone} ${STP_HELLO}
102 fi
103
104 if [ -n "${STP_MAXAGE}" ]; then
105 brctl setmaxage ${zone} ${STP_MAXAGE}
106 fi
d82cf370
MT
107
108 if [ -n "${STP_PRIORITY}" ]; then
109 brctl setbridgeprio ${zone} ${STP_PRIORITY}
110 fi
1848564d 111 else
6b3f9c85 112 stp_disable ${zone}
1848564d
MT
113 fi
114
115 device_set_up ${zone}
116
117 # Bring all ports up
118 zone_ports_up ${zone}
1848564d
MT
119 zone_configs_up ${zone}
120
121 event_interface_up ${zone}
8dcb2687
MT
122
123 exit ${EXIT_OK}
1848564d
MT
124}
125
126function _down() {
127 local zone=${1}
128 shift
129
130 if ! device_is_up ${zone}; then
131 warning "Zone '${zone}' is not up"
132 exit ${EXIT_OK}
133 fi
134
135 event_interface_down ${zone}
136
137 zone_configs_down ${zone}
138 zone_ports_down ${zone}
139
140 device_set_down ${zone}
141 brctl delbr ${zone}
142
8dcb2687 143 exit ${EXIT_OK}
1848564d
MT
144}
145
e84e4e76
MT
146function _status() {
147 local zone=${1}
148
149 cli_status_headline ${zone}
150
151 # Exit if zone is down
152 if ! zone_is_up ${zone}; then
153 echo # Empty line
154 exit ${EXIT_ERROR}
155 fi
156
d82cf370
MT
157 # XXX Add bridge stp priority here
158 # brctl does not give any information about that
159
e84e4e76
MT
160 cli_headline " Spanning Tree Protocol information:"
161 echo " Bridge ID : $(stp_bridge_id ${zone})"
162 echo " Designated root : $(stp_designated_root ${zone})"
163 echo " Path cost : $(stp_pathcost ${zone})"
164 echo # Empty line
165
166 # Topology information
167 printf " Topology changing : %6s\n" $(stp_topology_change ${zone})
d82cf370 168 printf " Topology change time : %6s\n" $(beautify_time $(stp_topology_change_time ${zone}))
e84e4e76
MT
169 printf " Topology change count : %6s\n" $(stp_topology_change_count ${zone})
170
171 cli_headline " Ports:"
711ffac1 172 zone_ports_status ${zone}
e84e4e76
MT
173
174 cli_headline " Configurations:"
175 zone_configs_cmd status ${zone}
176
177 echo # Empty line
178 exit ${EXIT_OK}
179}
180
1848564d 181run $@