]> git.ipfire.org Git - people/ms/network.git/blame - src/header-zone
hostapd: Set default WMM settings
[people/ms/network.git] / src / header-zone
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###############################################################################
1848564d 21
1c6a4e30 22hook_info() {
1848564d
MT
23 echo "HOOK=\"${HOOK}\""
24}
25
1c6a4e30 26hook_hotplug() {
2a969c27
MT
27 # If the hook does not handle the hotplug event, it
28 # must return EXIT_NOT_HANDLED.
29 exit ${EXIT_NOT_HANDLED}
30}
31
1c6a4e30 32hook_new() {
2181765d
MT
33 local zone="${1}"
34 assert isset zone
1848564d
MT
35 shift
36
2212045f 37 if ! hook_parse_cmdline "$@"; then
79e5203e
JS
38 return ${EXIT_ERROR}
39 fi
1848564d 40
79e5203e
JS
41 if ! zone_settings_write "${zone}"; then
42 log ERROR "Could not write settings for zone ${zone}"
43 return ${EXIT_ERROR}
44 fi
1848564d
MT
45
46 exit ${EXIT_OK}
47}
48
1c6a4e30 49hook_edit() {
79e5203e
JS
50 local zone="${1}"
51 assert isset zone
52 shift
53
54 if ! zone_settings_read "${zone}"; then
55 log ERROR "Could not read settings for zone ${zone}"
56 return ${EXIT_ERROR}
57 fi
58
2212045f 59 if ! hook_parse_cmdline "$@"; then
79e5203e
JS
60 return ${EXIT_ERROR}
61 fi
62
63 if ! zone_settings_write "${zone}"; then
64 log ERROR "Could not write settings for zone ${zone}"
65 return ${EXIT_ERROR}
66 fi
67
68 exit ${EXIT_OK}
69
1848564d
MT
70}
71
1c6a4e30 72hook_remove() {
2181765d 73 cmd_not_implemented
1848564d
MT
74}
75
1c6a4e30 76hook_status() {
2181765d
MT
77 local zone="${1}"
78 assert isset zone
1848564d
MT
79
80 if device_is_up ${zone}; then
81 exit ${STATUS_UP}
82 fi
83
84 exit ${STATUS_DOWN}
85}
86
1c6a4e30 87hook_up() {
2181765d 88 cmd_not_implemented
1848564d
MT
89}
90
1c6a4e30 91hook_down() {
2181765d 92 cmd_not_implemented
1848564d
MT
93}
94
1c6a4e30 95hook_discover() {
1848564d
MT
96 # This hook does not support a discovery
97 exit ${DISCOVER_NOT_SUPPORTED}
98}
99
100# Do nothing
1c6a4e30 101hook_parse_cmdline() {
1848564d
MT
102 return ${EXIT_OK}
103}
104
1c6a4e30 105hook_port() {
2181765d
MT
106 local zone="${1}"
107 assert isset zone
108
109 local action="${2}"
1848564d
MT
110 shift 2
111
112 local ret
1848564d 113 case "${action}" in
e5f78859 114 add|create|edit|rem|show)
2212045f 115 hook_port_${action} "${zone}" "$@"
1848564d
MT
116 ret=$?
117 ;;
118 *)
119 error "Unrecognized argument: '${action}'"
120 exit ${EXIT_ERROR}
121 ;;
122 esac
123
124 exit ${ret}
125}
126
1c6a4e30 127hook_port_attach() {
828eb94a 128 return ${EXIT_NOT_SUPPORTED}
e5f78859
MT
129}
130
1c6a4e30 131hook_port_detach() {
828eb94a 132 return ${EXIT_NOT_SUPPORTED}
e5f78859
MT
133}
134
1c6a4e30 135hook_port_edit() {
828eb94a 136 return ${EXIT_NOT_SUPPORTED}
e5f78859
MT
137}
138
1c6a4e30 139hook_port_status() {
828eb94a 140 return ${EXIT_NOT_SUPPORTED}
1848564d
MT
141}
142
1c6a4e30 143hook_default_port_create() {
1ba6a2bb
MT
144 assert [ $# -ge 2 ]
145
146 local zone="${1}"
147 local port="${2}"
148
149 port_create "${port}"
150}
151
1c6a4e30 152hook_port_create() {
2212045f 153 hook_default_port_create "$@"
1ba6a2bb
MT
154}
155
1c6a4e30 156hook_default_port_remove() {
1ba6a2bb
MT
157 assert [ $# -ge 2 ]
158
159 local zone="${1}"
160 local port="${2}"
161
162 port_remove "${port}"
163}
164
1c6a4e30 165hook_port_remove() {
2212045f 166 hook_default_port_remove "$@"
1ba6a2bb
MT
167}
168
1c6a4e30 169hook_port_up() {
828eb94a 170 cmd_not_implemented
1848564d
MT
171}
172
1c6a4e30 173hook_port_down() {
828eb94a 174 cmd_not_implemented
1848564d
MT
175}
176
1c6a4e30 177hook_config() {
2181765d
MT
178 local zone="${1}"
179 assert isset zone
180
181 local action="${2}"
182 assert isset action
1848564d
MT
183 shift 2
184
185 local ret
1848564d 186 case "${action}" in
2a6b2397 187 new|destroy|edit|show)
2181765d
MT
188 hook_config_${action} "${zone}" "$@"
189 exit $?
1848564d
MT
190 ;;
191 *)
192 error "Unrecognized argument: '${action}'"
193 exit ${EXIT_ERROR}
194 ;;
195 esac
1848564d
MT
196}
197
1c6a4e30 198hook_config_cmd() {
2181765d
MT
199 local cmd="${1}"
200 assert isset cmd
1848564d 201
2181765d
MT
202 local zone="${2}"
203 assert isset zone
1848564d 204
2181765d
MT
205 local hook_config="${3}"
206 assert isset hook_config
207
208 shift 3
209
210 local hook_zone="$(zone_get_hook "${zone}")"
211 if ! hook_zone_exists "${hook_zone}"; then
212 log ERROR "Hook '${hook}' does not exist."
1848564d
MT
213 exit ${EXIT_ERROR}
214 fi
215
ea699552
MT
216 #if ! hook_config_exists "${hook_zone}" "${hook_config}"; then
217 # log ERROR "Hook '${hook_config}' is not supported for zone '${zone}'."
218 # exit ${EXIT_ERROR}
219 #fi
1848564d 220
ea699552 221 hook_config_exec "${hook_config}" "${cmd}" "${zone}" "$@"
1848564d
MT
222}
223
2a6b2397 224hook_config_new() {
51492358 225 assert [ $# -ge 2 ]
a5ebb169 226
2a6b2397 227 hook_config_cmd "new" "$@"
1848564d
MT
228}
229
2a6b2397 230hook_config_destroy() {
6002aef1
JS
231 assert [ $# -eq 2 ]
232 local zone=${1}
233 # The id must be the id and not the hid.
234 local id=${2}
235
236 shift 2
237
238 # Check if we get a valid id
239 if ! zone_config_id_is_valid ${zone} ${id}; then
240 log ERROR "ID: ${id} is not a valid id for zone ${zone}"
241 fi
242
243 local hook=$(zone_config_get_hook_from_id ${zone} ${id})
244 assert isset hook
245
a6ef0714
JS
246 # First we bring the hook down
247 hook_config_cmd "down" "${zone}" "${hook}" "${hook}.${id}"
248
249 # If a hook_destroy function is implemented in the hook this function will be executed.
250 # If not a empty defined in header-config is executed.
251 if ! hook_config_cmd "destroy" "${zone}" "${hook}" "${hook}.${id}" "$@"; then
252
253 # A better error message should printed inside the hook.
254 # We will not bring the config up because we do not know if it is safe or if some parts are already destroyed.
255 log ERROR "Could not destroy config with the follwoing id: ${id}"
256 return ${EXIT_ERROR}
257 fi
258
259 # Now we delete the config of the zone
260 zone_config_settings_destroy "${zone}" "${hook}.${id}"
1848564d
MT
261}
262
2a6b2397 263hook_config_edit() {
15be9d69 264 assert [ $# -ge 2 ]
9ee04d82
JS
265 local zone=${1}
266 # The id must be the id and not the hid.
267 local id=${2}
268
269 shift 2
270
271 # Check if we get a valid id
272 if ! zone_config_id_is_valid ${zone} ${id}; then
273 log ERROR "ID: ${id} is not a valid id for zone ${zone}"
274 fi
275
276 local hook=$(zone_config_get_hook_from_id ${zone} ${id})
277 assert isset hook
278
279 hook_config_cmd "edit" "${zone}" "${hook}" "${hook}.${id}" "$@"
1848564d
MT
280}
281
1c6a4e30 282hook_config_show() {
2181765d 283 cmd_not_implemented
1848564d
MT
284}
285
1c6a4e30 286hook_ppp_write_config() {
2181765d 287 cmd_not_implemented
97cb552e
MT
288
289 # Arguments: <zone> <filename>
290}
291
1c6a4e30 292hook_ppp_ip_pre_up() {
2181765d
MT
293 local zone="${1}"
294 assert isset zone
c7ad7801
MT
295 shift
296
2181765d
MT
297 if ! zone_exists "${zone}"; then
298 log ERROR "Zone '${zone}' does not exist."
c7ad7801
MT
299 exit ${EXIT_ERROR}
300 fi
301
2181765d 302 ppp_common_ip_pre_up "${zone}" "$@"
c7ad7801 303 exit $?
b4038eca
MT
304}
305
1c6a4e30 306hook_ppp_ipv4_up() {
2181765d
MT
307 local zone="${1}"
308 assert isset zone
c7ad7801
MT
309 shift
310
2181765d
MT
311 if ! zone_exists "${zone}"; then
312 log ERROR "Zone '${zone}' does not exist."
c7ad7801
MT
313 exit ${EXIT_ERROR}
314 fi
315
2181765d 316 ppp_common_ipv4_up "${zone}" "$@"
c7ad7801 317 exit $?
b4038eca
MT
318}
319
1c6a4e30 320hook_ppp_ipv4_down() {
2181765d
MT
321 local zone="${1}"
322 assert isset zone
c7ad7801
MT
323 shift
324
2181765d
MT
325 if ! zone_exists "${zone}"; then
326 log ERROR "Zone '${zone}' does not exist."
c7ad7801
MT
327 exit ${EXIT_ERROR}
328 fi
329
2181765d 330 ppp_common_ipv4_down "${zone}" "$@"
c7ad7801 331 exit $?
b4038eca
MT
332}
333
1c6a4e30 334hook_ppp_ipv6_up() {
2181765d
MT
335 local zone="${1}"
336 assert isset zone
201b7dff
MT
337 shift
338
2181765d 339 if ! zone_exists "${zone}"; then
201b7dff
MT
340 error "Zone '${zone}' does not exist."
341 exit ${EXIT_ERROR}
342 fi
343
2181765d 344 ppp_common_ipv6_up "${zone}" "$@"
201b7dff
MT
345 exit $?
346}
347
1c6a4e30 348hook_ppp_ipv6_down() {
2181765d
MT
349 local zone="${1}"
350 assert isset zone
201b7dff
MT
351 shift
352
2181765d 353 if ! zone_exists "${zone}"; then
201b7dff
MT
354 error "Zone '${zone}' does not exist."
355 exit ${EXIT_ERROR}
356 fi
357
2181765d 358 ppp_common_ipv6_down "${zone}" "$@"
201b7dff
MT
359 exit $?
360}