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 # - All functions in this scope must start with an underline (_) to not
24 # conflict with any functions that were defined somewhere else.
27 .
/lib
/network
/functions
31 while [ $# -gt 0 ]; do
34 error
"Unrecognized option: ${1}"
43 # If action argument was given, we will exit.
44 [ -n "${action}" ] && break
48 # Returns a soft error if a function was not implemented, yet.
50 function _notimplemented
() {
51 warning
"'$@' was not implemented."
52 exit ${EXIT_CONF_ERROR}
56 echo "HOOK=\"${HOOK}\""
63 config_read $
(zone_dir
${zone})/settings
67 config_write $
(zone_dir
${zone})/settings
${HOOK_SETTINGS}
83 if device_is_up
${zone}; then
98 function _discover
() {
99 # This hook does not support a discovery
100 exit ${DISCOVER_NOT_SUPPORTED}
104 function _parse_cmdline
() {
116 add|create|edit|rem|show
)
117 _port_
${action} ${zone} $@
121 error
"Unrecognized argument: '${action}'"
129 function _port_add
() {
133 function _port_edit
() {
137 function _port_rem
() {
141 function _port_show
() {
142 _notimplemented _port_show
145 function _port_status
() {
149 function _port_cmd
() {
159 local hook_zone
=$
(zone_get_hook
${zone})
160 local hook_port
=$
(port_get_hook
${port})
162 assert isset hook_zone
163 assert isset hook_port
165 if ! listmatch
${hook_port} $
(zone_get_supported_port_hooks
${zone}); then
166 error_log
"Zone '${zone}' does not support port of type '${hook_port}'."
170 hook_zone_port_exec
${hook_zone} ${hook_port} ${cmd} ${zone} ${port} $@
175 function _port_up
() {
179 function _port_down
() {
191 create|edit|rem|show
)
192 _config_
${action} ${zone} $@
196 error
"Unrecognized argument: '${action}'"
204 # This function is not a public one
205 function __configcmd
() {
208 local hook_config
=${3}
211 local hook_zone
=$
(zone_get_hook
${zone})
213 if ! hook_zone_exists
${hook_zone}; then
214 error
"Hook '${hook}' does not exist."
218 if ! hook_config_exists
${hook_zone} ${hook_config}; then
219 error
"Hook '${hook_config}' is not supported for zone '${zone}'."
223 hook_zone_config_exec
${hook_zone} ${hook_config} ${cmd} ${zone} $@
226 function _config_create
() {
228 local hook_config
=${2}
232 assert isset hook_config
233 assert zone_exists
${zone}
235 if ! listmatch
${hook_config} $
(zone_get_supported_config_hooks
${zone}); then
236 error_log
"Zone '${zone}' does not support configuration of type '${hook_config}'."
240 local hook_zone
=$
(zone_get_hook
${zone})
241 assert isset hook_zone
243 hook_zone_config_exec
${hook_zone} ${hook_config} create ${zone} $@
248 function _config_edit
() {
252 function _config_rem
() {
253 _notimplemented _config_rem
256 function _config_show
() {
257 _notimplemented _config_show
260 function _ppp-ip-pre-up
() {
264 if ! zone_exists
${zone}; then
265 error
"Zone '${zone}' does not exist."
269 ppp_common_ip_pre_up
${zone} $@
274 function _ppp-ip-up
() {
278 if ! zone_exists
${zone}; then
279 error
"Zone '${zone}' does not exist."
283 ppp_common_ip_up
${zone} $@
288 function _ppp-ip-down
() {
292 if ! zone_exists
${zone}; then
293 error
"Zone '${zone}' does not exist."
297 ppp_common_ip_down
${zone} $@
303 # Replace all dashes by an underscore
304 #action=${action//-/_}
308 create|discover|down|edit|info|rem|status|up
)
313 port_add|port_rem|port_up|port_down|port_status
)
317 # Configuration callbacks
322 # ppp daemon callbacks
323 ppp-ip-pre-up|ppp-ip-up|ppp-ip-down
)
328 error
"Unknown action: ${action}"
332 error
"Hook did not exit properly."