]> git.ipfire.org Git - people/stevee/network.git/blobdiff - header-zone
firewall: Add global ICMP filter table.
[people/stevee/network.git] / header-zone
index 3ece84863d0e1b776be9d49c16058db50cffe64c..8233f61241fe092a97e2a897d5c37f3183cb2fa5 100644 (file)
 #     conflict with any functions that were defined somewhere else.
 #
 
-. /lib/network/functions
-
-HOOK=$(basename ${0})
-
-while [ $# -gt 0 ]; do
-       case "${1}" in
-               -*)
-                       error "Unrecognized option: ${1}"
-                       exit ${EXIT_ERROR}
-                       ;;
-               *)
-                       action=${1}
-                       ;;
-       esac
-       shift
-
-       # If action argument was given, we will exit.
-       [ -n "${action}" ] && break
-done
-
 # _notimplemented
 #   Returns a soft error if a function was not implemented, yet.
 #
@@ -60,11 +40,11 @@ function _create() {
        local zone=${1}
        shift
 
-       config_read ${ZONE_DIR}/${zone}/settings
+       config_read $(zone_dir ${zone})/settings
 
        _parse_cmdline $@
 
-       config_write ${ZONE_DIR}/${zone}/settings ${HOOK_SETTINGS}
+       config_write $(zone_dir ${zone})/settings ${HOOK_SETTINGS}
 
        exit ${EXIT_OK}
 }
@@ -100,6 +80,17 @@ function _discover() {
        exit ${DISCOVER_NOT_SUPPORTED}
 }
 
+# The default help function.
+function _help() {
+       # If no man page has been configured, we print an error message.
+       if [ -z "${HOOK_MANPAGE}" ]; then
+               error "There is no help available for hook '${HOOK}'. Exiting."
+               exit ${EXIT_ERROR}
+       fi
+
+       cli_show_man ${HOOK_MANPAGE}
+}
+
 # Do nothing
 function _parse_cmdline() {
        return ${EXIT_OK}
@@ -113,7 +104,7 @@ function _port() {
        local ret
 
        case "${action}" in
-               create|edit|rem|show)
+               add|create|edit|rem|show)
                        _port_${action} ${zone} $@
                        ret=$?
                        ;;
@@ -126,42 +117,58 @@ function _port() {
        exit ${ret}
 }
 
-# This function is not a public one
-function __portcmd() {
+function _port_add() {
+       _port_cmd add $@
+}
+
+function _port_edit() {
+       _port_cmd edit $@
+}
+
+function _port_rem() {
+       _port_cmd rem $@
+}
+
+function _port_show() {
+       _notimplemented _port_show
+}
+
+function _port_status() {
+       _port_cmd status $@
+}
+
+function _port_cmd() {
        local cmd=${1}
        local zone=${2}
-       local hook_port=${3}
+       local port=${3}
        shift 3
 
+       assert isset cmd
+       assert isset zone
+       assert isset port
+
        local hook_zone=$(zone_get_hook ${zone})
+       local hook_port=$(port_get_hook ${port})
 
-       if ! hook_exists ${hook_zone}; then
-               error "Hook '${hook}' does not exist."
-               exit ${EXIT_ERROR}
-       fi
+       assert isset hook_zone
+       assert isset hook_port
 
-       if ! hook_port_exists ${hook_zone} ${hook_port}; then
-               error "Hook '${hook_port}' is not supported for zone '${zone}'."
+       if ! listmatch ${hook_port} $(zone_get_supported_port_hooks ${zone}); then
+               error_log "Zone '${zone}' does not support port of type '${hook_port}'."
                exit ${EXIT_ERROR}
        fi
 
-       hook_port_exec ${hook_zone} ${hook_port} ${cmd} ${zone} $@
-}
+       hook_zone_port_exec ${hook_zone} ${hook_port} ${cmd} ${zone} ${port} $@
 
-function _port_create() {
-       __portcmd create $@
+       exit $?
 }
 
-function _port_edit() {
-       __portcmd edit $@
-}
-
-function _port_rem() {
-       _notimplemented _port_rem
+function _port_up() {
+       _port_cmd up $@
 }
 
-function _port_show() {
-       _notimplemented _port_show
+function _port_down() {
+       _port_cmd down $@
 }
 
 function _config() {
@@ -194,7 +201,7 @@ function __configcmd() {
 
        local hook_zone=$(zone_get_hook ${zone})
 
-       if ! hook_exists ${hook_zone}; then
+       if ! hook_zone_exists ${hook_zone}; then
                error "Hook '${hook}' does not exist."
                exit ${EXIT_ERROR}
        fi
@@ -204,11 +211,29 @@ function __configcmd() {
                exit ${EXIT_ERROR}
        fi
 
-       hook_config_exec ${hook_zone} ${hook_config} ${cmd} ${zone} $@
+       hook_zone_config_exec ${hook_zone} ${hook_config} ${cmd} ${zone} $@
 }
 
 function _config_create() {
-       __configcmd create $@
+       local zone=${1}
+       local hook_config=${2}
+       shift 2
+
+       assert isset zone
+       assert isset hook_config
+       assert zone_exists ${zone}
+
+       if ! listmatch ${hook_config} $(zone_get_supported_config_hooks ${zone}); then
+               error_log "Zone '${zone}' does not support configuration of type '${hook_config}'."
+               exit ${EXIT_ERROR}
+       fi
+
+       local hook_zone=$(zone_get_hook ${zone})
+       assert isset hook_zone
+
+       hook_zone_config_exec ${hook_zone} ${hook_config} create ${zone} $@
+
+       exit $?
 }
 
 function _config_edit() {
@@ -223,49 +248,78 @@ function _config_show() {
        _notimplemented _config_show
 }
 
-# These tree functions exit silently
+function _ppp-write-config() {
+       _notimplemented _ppp_write_config
+
+       # Arguments: <zone> <filename>
+}
+
 function _ppp-ip-pre-up() {
-       exit ${EXIT_OK}
+       local zone=${1}
+       shift
+
+       if ! zone_exists ${zone}; then
+               error "Zone '${zone}' does not exist."
+               exit ${EXIT_ERROR}
+       fi
+
+       ppp_common_ip_pre_up ${zone} $@
+
+       exit $?
 }
 
 function _ppp-ip-up() {
-       exit ${EXIT_OK}
+       local zone=${1}
+       shift
+
+       if ! zone_exists ${zone}; then
+               error "Zone '${zone}' does not exist."
+               exit ${EXIT_ERROR}
+       fi
+
+       ppp_common_ip_up ${zone} $@
+
+       exit $?
 }
 
 function _ppp-ip-down() {
-       exit ${EXIT_OK}
+       local zone=${1}
+       shift
+
+       if ! zone_exists ${zone}; then
+               error "Zone '${zone}' does not exist."
+               exit ${EXIT_ERROR}
+       fi
+
+       ppp_common_ip_down ${zone} $@
+
+       exit $?
 }
 
-function run() {
-       case "${action}" in
-               create|discover|down|edit|info|rem|status|up)
-                       _${action} $@
-                       ;;
+function _ppp-ipv6-up() {
+       local zone=${1}
+       shift
 
-               port)
-                       if ! hook_has_ports ${HOOK}; then
-                               error "Hook '${HOOK}' does not support ports."
-                               exit ${EXIT_ERROR}
-                       fi
+       if ! zone_exists ${zone}; then
+               error "Zone '${zone}' does not exist."
+               exit ${EXIT_ERROR}
+       fi
 
-                       _port $@
-                       ;;
+       ppp_common_ipv6_up ${zone} $@
 
-               config)
-                       if ! hook_has_configs ${HOOK}; then
-                               error "Hook '${HOOK}' does not support configurations."
-                               exit ${EXIT_ERROR}
-                       fi
+       exit $?
+}
 
-                       _config $@
-                       ;;
+function _ppp-ipv6-down() {
+       local zone=${1}
+       shift
 
-               ppp-ip-pre-up|ppp-ip-up|ppp-ip-down)
-                       _${action} $@
-                       ;;
+       if ! zone_exists ${zone}; then
+               error "Zone '${zone}' does not exist."
+               exit ${EXIT_ERROR}
+       fi
 
-       esac
+       ppp_common_ipv6_down ${zone} $@
 
-       error "Hook did not exit properly."
-       exit ${EXIT_ERROR}
+       exit $?
 }