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