]> git.ipfire.org Git - people/stevee/network.git/blob - header-zone
firewall: Add global ICMP filter table.
[people/stevee/network.git] / header-zone
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 # Notes:
23 # - All functions in this scope must start with an underline (_) to not
24 # conflict with any functions that were defined somewhere else.
25 #
26
27 # _notimplemented
28 # Returns a soft error if a function was not implemented, yet.
29 #
30 function _notimplemented() {
31 warning "'$@' was not implemented."
32 exit ${EXIT_CONF_ERROR}
33 }
34
35 function _info() {
36 echo "HOOK=\"${HOOK}\""
37 }
38
39 function _create() {
40 local zone=${1}
41 shift
42
43 config_read $(zone_dir ${zone})/settings
44
45 _parse_cmdline $@
46
47 config_write $(zone_dir ${zone})/settings ${HOOK_SETTINGS}
48
49 exit ${EXIT_OK}
50 }
51
52 function _edit() {
53 _create $@
54 }
55
56 function _rem() {
57 _notimplemented _rem
58 }
59
60 function _status() {
61 local zone=${1}
62
63 if device_is_up ${zone}; then
64 exit ${STATUS_UP}
65 fi
66
67 exit ${STATUS_DOWN}
68 }
69
70 function _up() {
71 _notimplemented _up
72 }
73
74 function _down() {
75 _notimplemented _down
76 }
77
78 function _discover() {
79 # This hook does not support a discovery
80 exit ${DISCOVER_NOT_SUPPORTED}
81 }
82
83 # The default help function.
84 function _help() {
85 # If no man page has been configured, we print an error message.
86 if [ -z "${HOOK_MANPAGE}" ]; then
87 error "There is no help available for hook '${HOOK}'. Exiting."
88 exit ${EXIT_ERROR}
89 fi
90
91 cli_show_man ${HOOK_MANPAGE}
92 }
93
94 # Do nothing
95 function _parse_cmdline() {
96 return ${EXIT_OK}
97 }
98
99 function _port() {
100 local zone=${1}
101 local action=${2}
102 shift 2
103
104 local ret
105
106 case "${action}" in
107 add|create|edit|rem|show)
108 _port_${action} ${zone} $@
109 ret=$?
110 ;;
111 *)
112 error "Unrecognized argument: '${action}'"
113 exit ${EXIT_ERROR}
114 ;;
115 esac
116
117 exit ${ret}
118 }
119
120 function _port_add() {
121 _port_cmd add $@
122 }
123
124 function _port_edit() {
125 _port_cmd edit $@
126 }
127
128 function _port_rem() {
129 _port_cmd rem $@
130 }
131
132 function _port_show() {
133 _notimplemented _port_show
134 }
135
136 function _port_status() {
137 _port_cmd status $@
138 }
139
140 function _port_cmd() {
141 local cmd=${1}
142 local zone=${2}
143 local port=${3}
144 shift 3
145
146 assert isset cmd
147 assert isset zone
148 assert isset port
149
150 local hook_zone=$(zone_get_hook ${zone})
151 local hook_port=$(port_get_hook ${port})
152
153 assert isset hook_zone
154 assert isset hook_port
155
156 if ! listmatch ${hook_port} $(zone_get_supported_port_hooks ${zone}); then
157 error_log "Zone '${zone}' does not support port of type '${hook_port}'."
158 exit ${EXIT_ERROR}
159 fi
160
161 hook_zone_port_exec ${hook_zone} ${hook_port} ${cmd} ${zone} ${port} $@
162
163 exit $?
164 }
165
166 function _port_up() {
167 _port_cmd up $@
168 }
169
170 function _port_down() {
171 _port_cmd down $@
172 }
173
174 function _config() {
175 local zone=${1}
176 local action=${2}
177 shift 2
178
179 local ret
180
181 case "${action}" in
182 create|edit|rem|show)
183 _config_${action} ${zone} $@
184 ret=$?
185 ;;
186 *)
187 error "Unrecognized argument: '${action}'"
188 exit ${EXIT_ERROR}
189 ;;
190 esac
191
192 exit ${ret}
193 }
194
195 # This function is not a public one
196 function __configcmd() {
197 local cmd=${1}
198 local zone=${2}
199 local hook_config=${3}
200 shift 3
201
202 local hook_zone=$(zone_get_hook ${zone})
203
204 if ! hook_zone_exists ${hook_zone}; then
205 error "Hook '${hook}' does not exist."
206 exit ${EXIT_ERROR}
207 fi
208
209 if ! hook_config_exists ${hook_zone} ${hook_config}; then
210 error "Hook '${hook_config}' is not supported for zone '${zone}'."
211 exit ${EXIT_ERROR}
212 fi
213
214 hook_zone_config_exec ${hook_zone} ${hook_config} ${cmd} ${zone} $@
215 }
216
217 function _config_create() {
218 local zone=${1}
219 local hook_config=${2}
220 shift 2
221
222 assert isset zone
223 assert isset hook_config
224 assert zone_exists ${zone}
225
226 if ! listmatch ${hook_config} $(zone_get_supported_config_hooks ${zone}); then
227 error_log "Zone '${zone}' does not support configuration of type '${hook_config}'."
228 exit ${EXIT_ERROR}
229 fi
230
231 local hook_zone=$(zone_get_hook ${zone})
232 assert isset hook_zone
233
234 hook_zone_config_exec ${hook_zone} ${hook_config} create ${zone} $@
235
236 exit $?
237 }
238
239 function _config_edit() {
240 __configcmd edit $@
241 }
242
243 function _config_rem() {
244 _notimplemented _config_rem
245 }
246
247 function _config_show() {
248 _notimplemented _config_show
249 }
250
251 function _ppp-write-config() {
252 _notimplemented _ppp_write_config
253
254 # Arguments: <zone> <filename>
255 }
256
257 function _ppp-ip-pre-up() {
258 local zone=${1}
259 shift
260
261 if ! zone_exists ${zone}; then
262 error "Zone '${zone}' does not exist."
263 exit ${EXIT_ERROR}
264 fi
265
266 ppp_common_ip_pre_up ${zone} $@
267
268 exit $?
269 }
270
271 function _ppp-ip-up() {
272 local zone=${1}
273 shift
274
275 if ! zone_exists ${zone}; then
276 error "Zone '${zone}' does not exist."
277 exit ${EXIT_ERROR}
278 fi
279
280 ppp_common_ip_up ${zone} $@
281
282 exit $?
283 }
284
285 function _ppp-ip-down() {
286 local zone=${1}
287 shift
288
289 if ! zone_exists ${zone}; then
290 error "Zone '${zone}' does not exist."
291 exit ${EXIT_ERROR}
292 fi
293
294 ppp_common_ip_down ${zone} $@
295
296 exit $?
297 }
298
299 function _ppp-ipv6-up() {
300 local zone=${1}
301 shift
302
303 if ! zone_exists ${zone}; then
304 error "Zone '${zone}' does not exist."
305 exit ${EXIT_ERROR}
306 fi
307
308 ppp_common_ipv6_up ${zone} $@
309
310 exit $?
311 }
312
313 function _ppp-ipv6-down() {
314 local zone=${1}
315 shift
316
317 if ! zone_exists ${zone}; then
318 error "Zone '${zone}' does not exist."
319 exit ${EXIT_ERROR}
320 fi
321
322 ppp_common_ipv6_down ${zone} $@
323
324 exit $?
325 }