2 ###############################################################################
4 # IPFire.org - A linux based firewall #
5 # Copyright (C) 2010 Michael Tremer & Christian Schmidt #
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. #
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. #
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/>. #
20 ###############################################################################
23 echo "HOOK=\"${HOOK}\""
27 # If the hook does not handle the hotplug event, it
28 # must return EXIT_NOT_HANDLED.
29 exit ${EXIT_NOT_HANDLED}
37 local ${HOOK_SETTINGS[*]}
39 # Import all default variables
42 if ! hook_parse_cmdline
"$@"; then
46 if ! zone_settings_write
"${zone}"; then
47 log ERROR
"Could not write settings for zone ${zone}"
59 if ! zone_settings_read
"${zone}"; then
60 log ERROR
"Could not read settings for zone ${zone}"
64 if ! hook_parse_cmdline
"$@"; then
68 if ! zone_settings_write
"${zone}"; then
69 log ERROR
"Could not write settings for zone ${zone}"
85 if device_is_up
${zone}; then
101 # This hook does not support a discovery
102 exit ${DISCOVER_NOT_SUPPORTED}
106 hook_parse_cmdline
() {
119 add|create|edit|rem|show
)
120 hook_port_
${action} "${zone}" "$@"
124 error
"Unrecognized argument: '${action}'"
133 return ${EXIT_NOT_SUPPORTED}
137 return ${EXIT_NOT_SUPPORTED}
141 return ${EXIT_NOT_SUPPORTED}
145 return ${EXIT_NOT_SUPPORTED}
148 hook_default_port_create
() {
154 port_create
"${port}"
158 hook_default_port_create
"$@"
161 hook_default_port_remove
() {
167 port_remove
"${port}"
171 hook_default_port_remove
"$@"
192 new|destroy|edit|show
)
193 hook_config_
${action} "${zone}" "$@"
197 error
"Unrecognized argument: '${action}'"
210 local hook_config
="${3}"
211 assert isset hook_config
215 local hook_zone
="$(zone_get_hook "${zone}")"
216 if ! hook_zone_exists
"${hook_zone}"; then
217 log ERROR
"Hook '${hook}' does not exist."
221 #if ! hook_config_exists "${hook_zone}" "${hook_config}"; then
222 # log ERROR "Hook '${hook_config}' is not supported for zone '${zone}'."
226 hook_config_exec
"${hook_config}" "${cmd}" "${zone}" "$@"
232 hook_config_cmd
"new" "$@"
235 hook_config_destroy
() {
238 # The id must be the id and not the hid.
243 # Check if we get a valid id
244 if ! zone_config_id_is_valid
${zone} ${id}; then
245 log ERROR
"ID: ${id} is not a valid id for zone ${zone}"
248 local hook
=$
(zone_config_get_hook_from_id
${zone} ${id})
251 # First we bring the hook down
252 hook_config_cmd
"down" "${zone}" "${hook}" "${hook}.${id}"
254 # If a hook_destroy function is implemented in the hook this function will be executed.
255 # If not a empty defined in header-config is executed.
256 if ! hook_config_cmd
"destroy" "${zone}" "${hook}" "${hook}.${id}" "$@"; then
258 # A better error message should printed inside the hook.
259 # We will not bring the config up because we do not know if it is safe or if some parts are already destroyed.
260 log ERROR
"Could not destroy config with the follwoing id: ${id}"
264 # Now we delete the config of the zone
265 zone_config_settings_destroy
"${zone}" "${hook}.${id}"
271 # The id must be the id and not the hid.
276 # Check if we get a valid id
277 if ! zone_config_id_is_valid
${zone} ${id}; then
278 log ERROR
"ID: ${id} is not a valid id for zone ${zone}"
281 local hook
=$
(zone_config_get_hook_from_id
${zone} ${id})
284 hook_config_cmd
"edit" "${zone}" "${hook}" "${hook}.${id}" "$@"
291 hook_ppp_write_config
() {
294 # Arguments: <zone> <filename>
297 hook_ppp_ip_pre_up
() {
302 if ! zone_exists
"${zone}"; then
303 log ERROR
"Zone '${zone}' does not exist."
307 ppp_common_ip_pre_up
"${zone}" "$@"
316 if ! zone_exists
"${zone}"; then
317 log ERROR
"Zone '${zone}' does not exist."
321 ppp_common_ipv4_up
"${zone}" "$@"
325 hook_ppp_ipv4_down
() {
330 if ! zone_exists
"${zone}"; then
331 log ERROR
"Zone '${zone}' does not exist."
335 ppp_common_ipv4_down
"${zone}" "$@"
344 if ! zone_exists
"${zone}"; then
345 error
"Zone '${zone}' does not exist."
349 ppp_common_ipv6_up
"${zone}" "$@"
353 hook_ppp_ipv6_down
() {
358 if ! zone_exists
"${zone}"; then
359 error
"Zone '${zone}' does not exist."
363 ppp_common_ipv6_down
"${zone}" "$@"