]> git.ipfire.org Git - people/stevee/network.git/blame - src/header-zone
Fix hook settings writing and checking
[people/stevee/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
2181765d 22function hook_info() {
1848564d
MT
23 echo "HOOK=\"${HOOK}\""
24}
25
2a969c27
MT
26function hook_hotplug() {
27 # If the hook does not handle the hotplug event, it
28 # must return EXIT_NOT_HANDLED.
29 exit ${EXIT_NOT_HANDLED}
30}
31
cf0fc8ab 32function hook_new() {
2181765d
MT
33 local zone="${1}"
34 assert isset zone
1848564d
MT
35 shift
36
1e6f187e 37 zone_settings_read "${zone}"
1848564d 38
2181765d 39 hook_parse_cmdline $@
1848564d 40
1e6f187e 41 zone_settings_write "${zone}"
1848564d
MT
42
43 exit ${EXIT_OK}
44}
45
2181765d 46function hook_edit() {
1e6f187e 47 hook_new $@
1848564d
MT
48}
49
2181765d
MT
50function hook_remove() {
51 cmd_not_implemented
1848564d
MT
52}
53
2181765d
MT
54function hook_status() {
55 local zone="${1}"
56 assert isset zone
1848564d
MT
57
58 if device_is_up ${zone}; then
59 exit ${STATUS_UP}
60 fi
61
62 exit ${STATUS_DOWN}
63}
64
2181765d
MT
65function hook_up() {
66 cmd_not_implemented
1848564d
MT
67}
68
2181765d
MT
69function hook_down() {
70 cmd_not_implemented
1848564d
MT
71}
72
2181765d 73function hook_discover() {
1848564d
MT
74 # This hook does not support a discovery
75 exit ${DISCOVER_NOT_SUPPORTED}
76}
77
78# Do nothing
c2441156 79function hook_parse_cmdline() {
1848564d
MT
80 return ${EXIT_OK}
81}
82
2181765d
MT
83function hook_port() {
84 local zone="${1}"
85 assert isset zone
86
87 local action="${2}"
1848564d
MT
88 shift 2
89
90 local ret
1848564d 91 case "${action}" in
e5f78859 92 add|create|edit|rem|show)
2181765d 93 hook_port_${action} "${zone}" $@
1848564d
MT
94 ret=$?
95 ;;
96 *)
97 error "Unrecognized argument: '${action}'"
98 exit ${EXIT_ERROR}
99 ;;
100 esac
101
102 exit ${ret}
103}
104
2181765d 105function hook_port_add() {
828eb94a 106 return ${EXIT_NOT_SUPPORTED}
e5f78859
MT
107}
108
2181765d 109function hook_port_edit() {
828eb94a 110 return ${EXIT_NOT_SUPPORTED}
e5f78859
MT
111}
112
1ba6a2bb 113function hook_port_destroy() {
828eb94a 114 return ${EXIT_NOT_SUPPORTED}
e5f78859
MT
115}
116
2181765d
MT
117function hook_port_show() {
118 cmd_not_implemented
e5f78859
MT
119}
120
2181765d 121function hook_port_status() {
828eb94a 122 return ${EXIT_NOT_SUPPORTED}
1848564d
MT
123}
124
1ba6a2bb
MT
125function hook_default_port_create() {
126 assert [ $# -ge 2 ]
127
128 local zone="${1}"
129 local port="${2}"
130
131 port_create "${port}"
132}
133
134function hook_port_create() {
135 hook_default_port_create $@
136}
137
138function hook_default_port_remove() {
139 assert [ $# -ge 2 ]
140
141 local zone="${1}"
142 local port="${2}"
143
144 port_remove "${port}"
145}
146
147function hook_port_remove() {
148 hook_default_port_remove $@
149}
150
2181765d 151function hook_port_up() {
828eb94a 152 cmd_not_implemented
1848564d
MT
153}
154
2181765d 155function hook_port_down() {
828eb94a 156 cmd_not_implemented
1848564d
MT
157}
158
2181765d
MT
159function hook_config() {
160 local zone="${1}"
161 assert isset zone
162
163 local action="${2}"
164 assert isset action
1848564d
MT
165 shift 2
166
167 local ret
1848564d
MT
168 case "${action}" in
169 create|edit|rem|show)
2181765d
MT
170 hook_config_${action} "${zone}" "$@"
171 exit $?
1848564d
MT
172 ;;
173 *)
174 error "Unrecognized argument: '${action}'"
175 exit ${EXIT_ERROR}
176 ;;
177 esac
1848564d
MT
178}
179
2181765d
MT
180function hook_config_cmd() {
181 local cmd="${1}"
182 assert isset cmd
1848564d 183
2181765d
MT
184 local zone="${2}"
185 assert isset zone
1848564d 186
2181765d
MT
187 local hook_config="${3}"
188 assert isset hook_config
189
190 shift 3
191
192 local hook_zone="$(zone_get_hook "${zone}")"
193 if ! hook_zone_exists "${hook_zone}"; then
194 log ERROR "Hook '${hook}' does not exist."
1848564d
MT
195 exit ${EXIT_ERROR}
196 fi
197
ea699552
MT
198 #if ! hook_config_exists "${hook_zone}" "${hook_config}"; then
199 # log ERROR "Hook '${hook_config}' is not supported for zone '${zone}'."
200 # exit ${EXIT_ERROR}
201 #fi
1848564d 202
ea699552 203 hook_config_exec "${hook_config}" "${cmd}" "${zone}" "$@"
1848564d
MT
204}
205
2181765d 206function hook_config_create() {
ea699552 207 assert [ $# -gt 2 ]
a5ebb169 208
ea699552 209 hook_config_cmd "create" "$@"
1848564d
MT
210}
211
2181765d 212function hook_config_edit() {
ea699552 213 hook_config_cmd "edit" "$@"
1848564d
MT
214}
215
2181765d 216function hook_config_remove() {
ea699552 217 hook_config_cmd "remove" "$@"
1848564d
MT
218}
219
2181765d
MT
220function hook_config_show() {
221 cmd_not_implemented
1848564d
MT
222}
223
2181765d
MT
224function hook_ppp_write_config() {
225 cmd_not_implemented
97cb552e
MT
226
227 # Arguments: <zone> <filename>
228}
229
2181765d
MT
230function hook_ppp_ip_pre_up() {
231 local zone="${1}"
232 assert isset zone
c7ad7801
MT
233 shift
234
2181765d
MT
235 if ! zone_exists "${zone}"; then
236 log ERROR "Zone '${zone}' does not exist."
c7ad7801
MT
237 exit ${EXIT_ERROR}
238 fi
239
2181765d 240 ppp_common_ip_pre_up "${zone}" "$@"
c7ad7801 241 exit $?
b4038eca
MT
242}
243
2181765d
MT
244function hook_ppp_ipv4_up() {
245 local zone="${1}"
246 assert isset zone
c7ad7801
MT
247 shift
248
2181765d
MT
249 if ! zone_exists "${zone}"; then
250 log ERROR "Zone '${zone}' does not exist."
c7ad7801
MT
251 exit ${EXIT_ERROR}
252 fi
253
2181765d 254 ppp_common_ipv4_up "${zone}" "$@"
c7ad7801 255 exit $?
b4038eca
MT
256}
257
2181765d
MT
258function hook_ppp_ipv4_down() {
259 local zone="${1}"
260 assert isset zone
c7ad7801
MT
261 shift
262
2181765d
MT
263 if ! zone_exists "${zone}"; then
264 log ERROR "Zone '${zone}' does not exist."
c7ad7801
MT
265 exit ${EXIT_ERROR}
266 fi
267
2181765d 268 ppp_common_ipv4_down "${zone}" "$@"
c7ad7801 269 exit $?
b4038eca
MT
270}
271
2181765d
MT
272function hook_ppp_ipv6_up() {
273 local zone="${1}"
274 assert isset zone
201b7dff
MT
275 shift
276
2181765d 277 if ! zone_exists "${zone}"; then
201b7dff
MT
278 error "Zone '${zone}' does not exist."
279 exit ${EXIT_ERROR}
280 fi
281
2181765d 282 ppp_common_ipv6_up "${zone}" "$@"
201b7dff
MT
283 exit $?
284}
285
2181765d
MT
286function hook_ppp_ipv6_down() {
287 local zone="${1}"
288 assert isset zone
201b7dff
MT
289 shift
290
2181765d 291 if ! zone_exists "${zone}"; then
201b7dff
MT
292 error "Zone '${zone}' does not exist."
293 exit ${EXIT_ERROR}
294 fi
295
2181765d 296 ppp_common_ipv6_down "${zone}" "$@"
201b7dff
MT
297 exit $?
298}