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_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
() {
227 __configcmd create $@
230 function _config_edit
() {
234 function _config_rem
() {
235 _notimplemented _config_rem
238 function _config_show
() {
239 _notimplemented _config_show
242 function _ppp-ip-pre-up
() {
246 if ! zone_exists
${zone}; then
247 error
"Zone '${zone}' does not exist."
251 ppp_common_ip_pre_up
${zone} $@
256 function _ppp-ip-up
() {
260 if ! zone_exists
${zone}; then
261 error
"Zone '${zone}' does not exist."
265 ppp_common_ip_up
${zone} $@
270 function _ppp-ip-down
() {
274 if ! zone_exists
${zone}; then
275 error
"Zone '${zone}' does not exist."
279 ppp_common_ip_down
${zone} $@
285 # Replace all dashes by an underscore
286 #action=${action//-/_}
289 create|discover|down|edit|info|rem|status|up|port_add|port_rem|port_up|port_down|port_status
)
294 if ! hook_zone_has_ports
${HOOK}; then
295 error
"Hook '${HOOK}' does not support ports."
303 if ! hook_zone_has_configs
${HOOK}; then
304 error
"Hook '${HOOK}' does not support configurations."
311 ppp-ip-pre-up|ppp-ip-up|ppp-ip-down
)
317 error
"Hook did not exit properly."