]> git.ipfire.org Git - people/ms/network.git/commitdiff
Renew hook function naming scheme.
authorMichael Tremer <michael.tremer@ipfire.org>
Wed, 8 May 2013 19:18:56 +0000 (21:18 +0200)
committerMichael Tremer <michael.tremer@ipfire.org>
Wed, 8 May 2013 19:18:56 +0000 (21:18 +0200)
30 files changed:
functions.constants
functions.hook
functions.ppp
functions.util
header-port
header-zone
hooks/ports/batman-adv
hooks/ports/batman-adv-port
hooks/ports/bonding
hooks/ports/dummy
hooks/ports/ethernet
hooks/ports/macvlan
hooks/ports/vlan
hooks/ports/wireless-ap
hooks/zones/6to4-tunnel
hooks/zones/aiccu
hooks/zones/bridge
hooks/zones/bridge.configs/ipv4-dhcp
hooks/zones/bridge.configs/ipv4-static
hooks/zones/bridge.configs/ipv6-static
hooks/zones/bridge.configs/pppoe-server
hooks/zones/bridge.ports/ethernet
hooks/zones/isdn
hooks/zones/isdn-server
hooks/zones/modem
hooks/zones/pppoe
hooks/zones/switch
hooks/zones/teredo
hooks/zones/wireless
ppp/ip-updown

index 21b44fcad413fb47250bafc20e15f565fccda768..018488411649c111884862ca0a510e9aa997dcf2 100644 (file)
@@ -51,6 +51,7 @@ NETWORK_CONFIG_ROUTES_PARAMS="network gateway unreachable prohibit blackhole mtu
 EXIT_OK=0
 EXIT_ERROR=1
 EXIT_CONF_ERROR=2
+EXIT_COMMAND_NOT_FOUND=127
 EXIT_ERROR_ASSERT=128
 
 EXIT_TRUE=0
index 792f2ba8e30e8df47f5dc19846acb477ad534d2a..6ee527d5a7c316c38b9ba5cdf26c7f88be7059f5 100644 (file)
 #                                                                             #
 ###############################################################################
 
+HOOK_COMMANDS_CONFIG="hook_create hook_down hook_status hook_up"
+
+HOOK_COMMANDS_PORT="hook_create hook_down hook_hotplug hook_hotplug_rename \
+       hook_info hook_status hook_up"
+
+HOOK_COMMANDS_ZONE="hook_create hook_discover hook_down hook_edit hook_help \
+       hook_info hook_remove hook_status hook_up \
+       \
+       hook_config_create hook_config_edit hook_config_remove hook_config_show \
+       \
+       hook_port hook_port_add hook_port_edit hook_port_remove hook_port_show \
+       hook_port_status hook_port_up hook_port_down \
+       \
+       hook_ppp_ip_pre_up hook_ppp_ipv4_down hook_ppp_ipv4_up \
+       hook_ipv6_down hook_ipv6_up hook_ppp_write_config"
+
 function hook_dir() {
        local type=${1}
 
@@ -44,16 +60,37 @@ function hook_exists() {
 }
 
 function hook_exec() {
-       local type=${1}
-       local hook=${2}
-       local cmd=${3}
-       shift 3
-
+       local type="${1}"
        assert isset type
+
+       local hook="${2}"
        assert isset hook
+
+       local cmd="${3}"
        assert isset cmd
 
        assert hook_exists "${type}" "${hook}"
+       shift 3
+
+       # Complete the hook command by prepending "hook_"
+       local hook_cmd="hook_${cmd}"
+
+       # Check if the hook action is valid.
+       local valid_commands
+       case "${type}" in
+               "config")
+                       valid_commands="${HOOK_COMMANDS_CONFIG}"
+                       ;;
+               "port")
+                       valid_commands="${HOOK_COMMANDS_PORT}"
+                       ;;
+               "zone")
+                       valid_commands="${HOOK_COMMANDS_ZONE}"
+                       ;;
+       esac
+       isset valid_commands && assert list_match "${hook_cmd}" ${valid_commands}
+
+       local hook_path="$(hook_dir ${type})/${hook}"
 
        # For performance reasons, all hooks are executed
        # in a subshell and so will inherit the currently
@@ -63,20 +100,26 @@ function hook_exec() {
                HOOK=$(basename ${hook})
 
                # Source the code of the hook.
-               source "$(hook_dir ${type})/${hook}"
+               source "${hook_path}"
 
                # Make sure HOOK is still properly set.
                assert isset HOOK
 
                # Execute the requested command.
-               _${cmd} $@
+               cmd "${hook_cmd}" "$@"
        )
        local ret=$?
 
-       if [ ${ret} -eq ${EXIT_ERROR_ASSERT} ]; then
-               log ERROR "Hook exited with an assertion error."
-               exit ${ret}
-       fi
+       case "${ret}" in
+               ${EXIT_COMMAND_NOT_FOUND})
+                       log ERROR "Hook command not implemented: ${hook_command} ($@)"
+                       exit ${EXIT_COMMAND_NOT_FOUND}
+                       ;;
+               ${EXIT_ERROR_ASSERT})
+                       log ERROR "Hook exited with an assertion error."
+                       exit ${EXIT_ERROR_ASSERT}
+                       ;;
+       esac
 
        return ${ret}
 }
index 1b7d9a30e223a394fd2d7b6591294e6aa289c593..05ebed56e0738035990b025b7e0e07fe788c9084 100644 (file)
@@ -87,7 +87,7 @@ function ppp_common_ip_pre_up() {
        return ${EXIT_OK}
 }
 
-function ppp_common_ip_up() {
+function ppp_common_ipv4_up() {
        local zone=${1}
        shift
 
@@ -103,7 +103,7 @@ function ppp_common_ip_up() {
        return ${EXIT_OK}
 }
 
-function ppp_common_ip_down() {
+function ppp_common_ipv4_down() {
        local zone=${1}
        shift
 
index 1fb1951529c5eb22c306aac60b264ed52d940afa..b975b6a0b926b25a8b58663df99cfeddcd42106b 100644 (file)
@@ -340,6 +340,10 @@ function cmd_exec() {
        exit ${EXIT_ERROR}
 }
 
+function cmd_not_implemented() {
+       assert false "not implemented"
+}
+
 function seq() {
        if [ $# -eq 2 ]; then
                eval echo {${1}..${2}}
index b07c99c5b4da1830906fa0cddc4417951a47c635..44e3cf18aab1995a88c45bd3d48b128bac320c76 100644 (file)
@@ -25,7 +25,7 @@ INFO_SETTINGS="HOOK PORT_PARENTS PORT_CHILDREN"
 # into the system and got its correct name.
 # The function is intended to create child ports and things
 # like that.
-function _hotplug() {
+function hook_hotplug() {
        exit ${EXIT_OK}
 }
 
@@ -34,20 +34,18 @@ function _hotplug() {
 # The first argument is the port which should be tested
 # against the second argument which is the device that
 # has been plugged in.
-function _hotplug_rename() {
+function hook_hotplug_rename() {
        exit ${EXIT_FALSE}
 }
 
-function _info() {
-       local port=${1}
-       shift
-
+function hook_info() {
+       local port="${1}"
        assert isset port
+       shift
 
-       config_read $(port_file ${port})
+       config_read "$(port_file ${port})"
 
-       local key
-       local val
+       local key val
        for key in PORT_PARENTS PORT_CHILDREN; do
                val="${key}_VAR"
                val=${!val}
@@ -61,10 +59,10 @@ function _info() {
        exit ${ERROR_OK}
 }
 
-function _status() {
-       local port=${1}
+function hook_status() {
+       local port="${1}"
        assert isset port
 
-       cli_device_headline ${port} --long
+       cli_device_headline "${port}" --long
        exit ${EXIT_OK}
 }
index 8233f61241fe092a97e2a897d5c37f3183cb2fa5..74cec328cd0002a39800e6ddb42af1267169e284 100644 (file)
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.       #
 #                                                                             #
 ###############################################################################
-#
-# Notes:
-#   - All functions in this scope must start with an underline (_) to not
-#     conflict with any functions that were defined somewhere else.
-#
-
-# _notimplemented
-#   Returns a soft error if a function was not implemented, yet.
-#
-function _notimplemented() {
-       warning "'$@' was not implemented."
-       exit ${EXIT_CONF_ERROR}
-}
 
-function _info() {
+function hook_info() {
        echo "HOOK=\"${HOOK}\""
 }
 
-function _create() {
-       local zone=${1}
+function hook_create() {
+       local zone="${1}"
+       assert isset zone
        shift
 
        config_read $(zone_dir ${zone})/settings
 
-       _parse_cmdline $@
+       hook_parse_cmdline $@
 
        config_write $(zone_dir ${zone})/settings ${HOOK_SETTINGS}
 
        exit ${EXIT_OK}
 }
 
-function _edit() {
-       _create $@
+function hook_edit() {
+       hook_create $@
 }
 
-function _rem() {
-       _notimplemented _rem
+function hook_remove() {
+       cmd_not_implemented
 }
 
-function _status() {
-       local zone=${1}
+function hook_status() {
+       local zone="${1}"
+       assert isset zone
 
        if device_is_up ${zone}; then
                exit ${STATUS_UP}
@@ -67,21 +56,21 @@ function _status() {
        exit ${STATUS_DOWN}
 }
 
-function _up() {
-       _notimplemented _up
+function hook_up() {
+       cmd_not_implemented
 }
 
-function _down() {
-       _notimplemented _down
+function hook_down() {
+       cmd_not_implemented
 }
 
-function _discover() {
+function hook_discover() {
        # This hook does not support a discovery
        exit ${DISCOVER_NOT_SUPPORTED}
 }
 
 # The default help function.
-function _help() {
+function hook_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."
@@ -96,16 +85,17 @@ function _parse_cmdline() {
        return ${EXIT_OK}
 }
 
-function _port() {
-       local zone=${1}
-       local action=${2}
+function hook_port() {
+       local zone="${1}"
+       assert isset zone
+
+       local action="${2}"
        shift 2
 
        local ret
-
        case "${action}" in
                add|create|edit|rem|show)
-                       _port_${action} ${zone} $@
+                       hook_port_${action} "${zone}" $@
                        ret=$?
                        ;;
                *)
@@ -117,209 +107,213 @@ function _port() {
        exit ${ret}
 }
 
-function _port_add() {
-       _port_cmd add $@
+function hook_port_add() {
+       hook_port_cmd add "$@"
 }
 
-function _port_edit() {
-       _port_cmd edit $@
+function hook_port_edit() {
+       _port_cmd edit "$@"
 }
 
-function _port_rem() {
-       _port_cmd rem $@
+function hook_port_rem() {
+       hook_port_cmd remove "$@"
 }
 
-function _port_show() {
-       _notimplemented _port_show
+function hook_port_show() {
+       cmd_not_implemented
 }
 
-function _port_status() {
-       _port_cmd status $@
+function hook_port_status() {
+       hook_port_cmd status "$@"
 }
 
-function _port_cmd() {
-       local cmd=${1}
-       local zone=${2}
-       local port=${3}
-       shift 3
-
+function hook_port_cmd() {
+       local cmd="${1}"
        assert isset cmd
+
+       local zone="${2}"
        assert isset zone
+
+       local port="${3}"
        assert isset port
 
-       local hook_zone=$(zone_get_hook ${zone})
-       local hook_port=$(port_get_hook ${port})
+       shift 3
 
+       local hook_zone="$(zone_get_hook ${zone})"
        assert isset hook_zone
+
+       local hook_port="$(port_get_hook ${port})"
        assert isset hook_port
 
-       if ! listmatch ${hook_port} $(zone_get_supported_port_hooks ${zone}); then
-               error_log "Zone '${zone}' does not support port of type '${hook_port}'."
+       if ! listmatch "${hook_port}" $(zone_get_supported_port_hooks ${zone}); then
+               log ERROR "Zone '${zone}' does not support port of type '${hook_port}'."
                exit ${EXIT_ERROR}
        fi
 
-       hook_zone_port_exec ${hook_zone} ${hook_port} ${cmd} ${zone} ${port} $@
-
+       hook_zone_port_exec "${hook_zone}" "${hook_port}" "${cmd}" "${zone}" "${port}" "$@"
        exit $?
 }
 
-function _port_up() {
-       _port_cmd up $@
+function hook_port_up() {
+       hook_port_cmd up "$@"
 }
 
-function _port_down() {
-       _port_cmd down $@
+function hook_port_down() {
+       hook_port_cmd down "$@"
 }
 
-function _config() {
-       local zone=${1}
-       local action=${2}
+function hook_config() {
+       local zone="${1}"
+       assert isset zone
+
+       local action="${2}"
+       assert isset action
        shift 2
 
        local ret
-
        case "${action}" in
                create|edit|rem|show)
-                       _config_${action} ${zone} $@
-                       ret=$?
+                       hook_config_${action} "${zone}" "$@"
+                       exit $?
                        ;;
                *)
                        error "Unrecognized argument: '${action}'"
                        exit ${EXIT_ERROR}
                        ;;
        esac
-
-       exit ${ret}
 }
 
-# This function is not a public one
-function __configcmd() {
-       local cmd=${1}
-       local zone=${2}
-       local hook_config=${3}
-       shift 3
+function hook_config_cmd() {
+       local cmd="${1}"
+       assert isset cmd
 
-       local hook_zone=$(zone_get_hook ${zone})
+       local zone="${2}"
+       assert isset zone
 
-       if ! hook_zone_exists ${hook_zone}; then
-               error "Hook '${hook}' does not exist."
+       local hook_config="${3}"
+       assert isset hook_config
+
+       shift 3
+
+       local hook_zone="$(zone_get_hook "${zone}")"
+       if ! hook_zone_exists "${hook_zone}"; then
+               log ERROR "Hook '${hook}' does not exist."
                exit ${EXIT_ERROR}
        fi
 
-       if ! hook_config_exists ${hook_zone} ${hook_config}; then
-               error "Hook '${hook_config}' is not supported for zone '${zone}'."
+       if ! hook_config_exists "${hook_zone}" "${hook_config}"; then
+               log ERROR "Hook '${hook_config}' is not supported for zone '${zone}'."
                exit ${EXIT_ERROR}
        fi
 
-       hook_zone_config_exec ${hook_zone} ${hook_config} ${cmd} ${zone} $@
+       hook_zone_config_exec "${hook_zone}" "${hook_config}" "${cmd}" "${zone}" "$@"
 }
 
-function _config_create() {
-       local zone=${1}
-       local hook_config=${2}
-       shift 2
-
+function hook_config_create() {
+       local zone="${1}"
        assert isset zone
+
+       local hook_config="${2}"
        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}'."
+       shift 2
+
+       if ! listmatch "${hook_config}" $(zone_get_supported_config_hooks ${zone}); then
+               log ERROR "Zone '${zone}' does not support configuration of type '${hook_config}'."
                exit ${EXIT_ERROR}
        fi
 
-       local hook_zone=$(zone_get_hook ${zone})
+       local hook_zone="$(zone_get_hook "${zone}")"
        assert isset hook_zone
 
-       hook_zone_config_exec ${hook_zone} ${hook_config} create ${zone} $@
-
+       hook_zone_config_exec "${hook_zone}" "${hook_config}" create "${zone}" "$@"
        exit $?
 }
 
-function _config_edit() {
-       __configcmd edit $@
+function hook_config_edit() {
+       hook_config_cmd edit "$@"
 }
 
-function _config_rem() {
-       _notimplemented _config_rem
+function hook_config_remove() {
+       cmd_not_implemented
 }
 
-function _config_show() {
-       _notimplemented _config_show
+function hook_config_show() {
+       cmd_not_implemented
 }
 
-function _ppp-write-config() {
-       _notimplemented _ppp_write_config
+function hook_ppp_write_config() {
+       cmd_not_implemented
 
        # Arguments: <zone> <filename>
 }
 
-function _ppp-ip-pre-up() {
-       local zone=${1}
+function hook_ppp_ip_pre_up() {
+       local zone="${1}"
+       assert isset zone
        shift
 
-       if ! zone_exists ${zone}; then
-               error "Zone '${zone}' does not exist."
+       if ! zone_exists "${zone}"; then
+               log ERROR "Zone '${zone}' does not exist."
                exit ${EXIT_ERROR}
        fi
 
-       ppp_common_ip_pre_up ${zone} $@
-
+       ppp_common_ip_pre_up "${zone}" "$@"
        exit $?
 }
 
-function _ppp-ip-up() {
-       local zone=${1}
+function hook_ppp_ipv4_up() {
+       local zone="${1}"
+       assert isset zone
        shift
 
-       if ! zone_exists ${zone}; then
-               error "Zone '${zone}' does not exist."
+       if ! zone_exists "${zone}"; then
+               log ERROR "Zone '${zone}' does not exist."
                exit ${EXIT_ERROR}
        fi
 
-       ppp_common_ip_up ${zone} $@
-
+       ppp_common_ipv4_up "${zone}" "$@"
        exit $?
 }
 
-function _ppp-ip-down() {
-       local zone=${1}
+function hook_ppp_ipv4_down() {
+       local zone="${1}"
+       assert isset zone
        shift
 
-       if ! zone_exists ${zone}; then
-               error "Zone '${zone}' does not exist."
+       if ! zone_exists "${zone}"; then
+               log ERROR "Zone '${zone}' does not exist."
                exit ${EXIT_ERROR}
        fi
 
-       ppp_common_ip_down ${zone} $@
-
+       ppp_common_ipv4_down "${zone}" "$@"
        exit $?
 }
 
-function _ppp-ipv6-up() {
-       local zone=${1}
+function hook_ppp_ipv6_up() {
+       local zone="${1}"
+       assert isset zone
        shift
 
-       if ! zone_exists ${zone}; then
+       if ! zone_exists "${zone}"; then
                error "Zone '${zone}' does not exist."
                exit ${EXIT_ERROR}
        fi
 
-       ppp_common_ipv6_up ${zone} $@
-
+       ppp_common_ipv6_up "${zone}" "$@"
        exit $?
 }
 
-function _ppp-ipv6-down() {
-       local zone=${1}
+function hook_ppp_ipv6_down() {
+       local zone="${1}"
+       assert isset zone
        shift
 
-       if ! zone_exists ${zone}; then
+       if ! zone_exists "${zone}"; then
                error "Zone '${zone}' does not exist."
                exit ${EXIT_ERROR}
        fi
 
-       ppp_common_ipv6_down ${zone} $@
-
+       ppp_common_ipv6_down "${zone}" "$@"
        exit $?
 }
index a2cb151e0a055883a1519b5dd1e3c32dc28fdb7a..76e9250e6b635c5529fc70d01928f365c047cdf4 100755 (executable)
@@ -28,12 +28,12 @@ PORT_CHILDREN_VAR="SLAVES"
 ADDRESS=$(mac_generate)
 SLAVES=
 
-function _check() {
+function hook_check() {
        assert isset ADDRESS
        assert ismac ADDRESS
 }
 
-function _create() {
+function hook_create() {
        while [ $# -gt 0 ]; do
                case "${1}" in
                        --address=*)
@@ -57,7 +57,7 @@ function _create() {
        exit ${EXIT_OK}
 }
 
-function _edit() {
+function hook_edit() {
        local port=${1}
        assert isset port
        shift
@@ -94,7 +94,7 @@ function _edit() {
        exit ${EXIT_OK}
 }
 
-function _up() {
+function hook_up() {
        local port=${1}
        assert isset port
 
@@ -120,7 +120,7 @@ function _up() {
        exit ${EXIT_OK}
 }
 
-function _down() {
+function hook_down() {
        local port=${1}
        assert isset port
 
@@ -134,7 +134,7 @@ function _down() {
        exit ${EXIT_OK}
 }
 
-function _hotplug() {
+function hook_hotplug() {
        local port=${1}
        assert isset port
 
@@ -147,7 +147,7 @@ function _hotplug() {
        exit ${EXIT_OK}
 }
 
-function _status() {
+function hook_status() {
        local port=${1}
        assert isset port
 
index 0d44ba3532a94747c80bf936a1e0b603e01a0513..a9304684e8627e7f50355c5ea97bd0a7329cbe66 100755 (executable)
@@ -33,7 +33,7 @@ SSID=
 # to 1528, that normal ethernet packets with 1500 bytes can pass the network.
 MTU=1528
 
-function _check() {
+function hook_check() {
        assert isset ADDRESS
        assert ismac ADDRESS
        assert isset CHANNEL
@@ -45,7 +45,7 @@ function _check() {
        assert isset SSID
 }
 
-function _create() {
+function hook_create() {
        while [ $# -gt 0 ]; do
                case "${1}" in
                        --address=*)
@@ -85,7 +85,7 @@ function _create() {
        exit ${EXIT_OK}
 }
 
-function _edit() {
+function hook_edit() {
        local port=${1}
        assert isset port
        shift
@@ -118,7 +118,7 @@ function _edit() {
        exit ${EXIT_OK}
 }
 
-function _up() {
+function hook_up() {
        local port=${1}
        assert isset port
 
@@ -155,7 +155,7 @@ function _up() {
        exit ${EXIT_OK}
 }
 
-function _down() {
+function hook_down() {
        local port=${1}
        assert isset port
 
@@ -173,7 +173,7 @@ function _down() {
        exit ${EXIT_OK}
 }
 
-function _hotplug() {
+function hook_hotplug() {
        local port=${1}
        assert isset port
 
@@ -198,7 +198,7 @@ function _hotplug() {
        exit ${EXIT_OK}
 }
 
-function _find_parent() {
+function hook_find_parent() {
        local port=${1}
        assert isset port
 
index 3d8b987e2e8ac0eceff780a00c92d5c7334759b1..355eece1d53ca10bd2d8050f0727ee43b2dbe45f 100755 (executable)
@@ -27,7 +27,7 @@ ADDRESS=$(mac_generate)
 SLAVES=""
 MIIMON=100
 
-function _check() {
+function hook_check() {
        assert isset ADDRESS
        assert ismac ADDRESS
 
@@ -35,11 +35,11 @@ function _check() {
        assert isinteger MIIMON
 }
 
-function _create() {
+function hook_create() {
        _edit $@
 }
 
-function _edit() {
+function hook_edit() {
        local port=${1}
        assert isset port
        shift
@@ -95,7 +95,7 @@ function _edit() {
        exit ${EXIT_OK}
 }
 
-function _up() {
+function hook_up() {
        local device=${1}
        assert isset device
 
@@ -134,7 +134,7 @@ function _up() {
        exit ${EXIT_OK}
 }
 
-function _down() {
+function hook_down() {
        local device=${1}
 
        bonding_remove ${device}
index bfd0e5060ae2028205ab9c8bb9ff1169ba18e0fc..3af50cd070951c36cd032bcdca2cce5b45a9c571 100755 (executable)
 
 HOOK_SETTINGS="HOOK ADDRESS"
 
-function _check() {
+function hook_check() {
        assert ismac ADDRESS
 }
 
-function _create() {
+function hook_create() {
        while [ $# -gt 0 ]; do
                case "${1}" in
                        --address=*)
@@ -55,7 +55,7 @@ function _create() {
        exit ${EXIT_OK}
 }
 
-function _edit() {
+function hook_edit() {
        local port=${1}
        assert isset port
        shift
@@ -79,7 +79,7 @@ function _edit() {
        exit ${EXIT_OK} 
 }
 
-function _up() {
+function hook_up() {
        local port=${1}
        assert isset port
 
@@ -96,7 +96,7 @@ function _up() {
        exit ${EXIT_OK}
 }
 
-function _down() {
+function hook_down() {
        local port=${1}
        assert isset port
 
@@ -113,7 +113,7 @@ function _down() {
        exit ${EXIT_OK}
 }
 
-function _hotplug_rename() {
+function hook_hotplug_rename() {
        local port=${1}
        assert isset port
 
index 327036cad75a63978584fd16729a4c022511a47c..35a90bf9eef0d22bd5bd629b3fe6aa754bdc5a7e 100755 (executable)
@@ -26,7 +26,7 @@
 
 HOOK_SETTINGS="HOOK ADDRESS DEVICE"
 
-function _check() {
+function hook_check() {
        assert ismac DEVICE
 
        if isset ADDRESS; then
@@ -34,7 +34,7 @@ function _check() {
        fi
 }
 
-function _create() {
+function hook_create() {
        local port=${1}
        assert isset port
        shift
@@ -47,7 +47,7 @@ function _create() {
        exit ${EXIT_OK}
 }
 
-function _up() {
+function hook_up() {
        local port=${1}
        assert isset port
 
@@ -65,7 +65,7 @@ function _up() {
        exit ${EXIT_OK}
 }
 
-function _down() {
+function hook_down() {
        local port=${1}
        assert isset port
 
@@ -75,7 +75,7 @@ function _down() {
        exit ${EXIT_OK}
 }
 
-function _hotplug_rename() {
+function hook_hotplug_rename() {
        local port=${1}
        assert isset port
 
index 5770e9db4069f28a162b4e85db9c92096cfcb964..0214465ad9fa42a27509b6e35f6fcd04b2432a00 100755 (executable)
 
 HOOK_SETTINGS="HOOK ADDRESS PARENT"
 
-function _check() {
+function hook_check() {
        assert isset PARENT
        assert ismac ADDRESS
 }
 
-function _create() {
+function hook_create() {
        while [ $# -gt 0 ]; do
                case "${1}" in
                        --parent-device=*)
@@ -58,7 +58,7 @@ function _create() {
        exit ${EXIT_OK}
 }
 
-function _edit() {
+function hook_edit() {
        local port=${1}
        assert isset port
        shift
@@ -82,7 +82,7 @@ function _edit() {
        exit ${EXIT_OK} 
 }
 
-function _up() {
+function hook_up() {
        local port=${1}
        assert isset port
 
@@ -96,7 +96,7 @@ function _up() {
        exit ${EXIT_OK}
 }
 
-function _down() {
+function hook_down() {
        local port=${1}
 
        assert isset port
index 66b98eb3c7a156d3b06226494fcc7136b944b8ad..20550077fc3e8ab188709e855c76061da82149ed 100755 (executable)
@@ -25,7 +25,7 @@ HOOK_SETTINGS="HOOK ADDRESS PARENT_DEVICE TAG"
 
 PORT_PARENTS_VAR="PARENT"
 
-function _check() {
+function hook_check() {
        assert isset PARENT_DEVICE
        assert isinteger TAG
 
@@ -47,7 +47,7 @@ function _check() {
        done
 }
 
-function _create() {
+function hook_create() {
        while [ $# -gt 0 ]; do
                case "${1}" in
                        --parent-device=*)
@@ -73,7 +73,7 @@ function _create() {
        exit ${EXIT_OK}
 }
 
-function _edit() {
+function hook_edit() {
        local port=${1}
        assert isset port
        shift
@@ -97,7 +97,7 @@ function _edit() {
        exit ${EXIT_OK} 
 }
 
-function _up() {
+function hook_up() {
        local port=${1}
        assert isset port
 
@@ -114,7 +114,7 @@ function _up() {
        exit ${EXIT_OK}
 }
 
-function _down() {
+function hook_down() {
        local port=${1}
        assert isset port
 
index 391e682800257520c6b13dba49cc00658abbef67..c6d91da042a75b78e06c4132e17abe72a338947d 100755 (executable)
@@ -33,7 +33,7 @@ KEY=""
 MODE="g"
 SSID=
 
-function _check() {
+function hook_check() {
        assert isset ADDRESS
        assert ismac ADDRESS
        assert isset BROADCAST_SSID
@@ -55,7 +55,7 @@ function _check() {
        fi
 }
 
-function _create() {
+function hook_create() {
        while [ $# -gt 0 ]; do
                case "${1}" in
                        --broadcast-ssid=*)
@@ -104,7 +104,7 @@ function _create() {
        exit ${EXIT_OK}
 }
 
-function _edit() {
+function hook_edit() {
        local port=${1}
        shift
 
@@ -147,7 +147,7 @@ function _edit() {
        exit ${EXIT_OK} 
 }
 
-function _up() {
+function hook_up() {
        local port=${1}
        assert isset port
 
@@ -178,7 +178,7 @@ function _up() {
        exit ${EXIT_OK}
 }
 
-function _down() {
+function hook_down() {
        local port=${1}
        assert isset port
 
@@ -193,7 +193,7 @@ function _down() {
        exit ${EXIT_OK}
 }
 
-function _hotplug() {
+function hook_hotplug() {
        local port=${1}
        assert isset port
 
index 2fbb5bbfc8e942783b8b7501102835c9c0658412..450b7b9399db6d26514d6d497b530a7fe13032d0 100755 (executable)
@@ -44,7 +44,7 @@ TUNNEL_ID=
 USERNAME=
 PASSWORD=
 
-function _check() {
+function hook_check() {
        assert isset SERVER_ADDRESS
        assert isset LOCAL_ADDRESS
        assert isset LOCAL_ADDRESS6
@@ -56,7 +56,7 @@ function _check() {
        fi
 }
 
-function _parse_cmdline() {
+function hook_parse_cmdline() {
        local value
 
        while [ $# -gt 0 ]; do
@@ -97,7 +97,7 @@ function _parse_cmdline() {
        done
 }
 
-function _up() {
+function hook_up() {
        local zone=${1}
        assert isset zone
 
@@ -135,7 +135,7 @@ function _up() {
        exit ${EXIT_OK}
 }
 
-function _down() {
+function hook_down() {
        local zone=${1}
        assert isset zone
 
@@ -150,7 +150,7 @@ function _down() {
        exit ${EXIT_OK}
 }
 
-function _status() {
+function hook_status() {
        local zone=${1}
        assert isset zone
 
index c5fbdd0f5c9e74e93262670d8cc1aea8986744f0..e31f897775180184bc0deedd858bbfc023ff26bb 100755 (executable)
@@ -30,7 +30,7 @@ PROTOCOL="tic"
 TUNNEL_ID=
 REQUIRE_TLS="true"
 
-function _check() {
+function hook_check() {
        assert isset USERNAME
        assert isset PASSWORD
        assert isset SERVER
@@ -45,7 +45,7 @@ function _check() {
        fi
 }
 
-function _parse_cmdline() {
+function hook_parse_cmdline() {
        local value
 
        while [ $# -gt 0 ]; do
@@ -83,7 +83,7 @@ function _parse_cmdline() {
        done
 }
 
-function _up() {
+function hook_up() {
        local zone=${1}
        assert isset zone
 
@@ -93,7 +93,7 @@ function _up() {
        exit ${EXIT_OK}
 }
 
-function _down() {
+function hook_down() {
        local zone=${1}
        assert isset zone
 
@@ -103,7 +103,7 @@ function _down() {
        exit ${EXIT_OK}
 }
 
-function _status() {
+function hook_status() {
        local zone=${1}
        assert isset zone
 
index fabb008e3a157ea98ddcfb7493577542e7f94048..a534871bb3ba26998541fd2ecb46348f47154ce5 100755 (executable)
@@ -36,7 +36,7 @@ STP_HELLO=2
 STP_MAXAGE=20
 STP_PRIORITY=512
 
-function _check() {
+function hook_check() {
        assert ismac MAC
        assert isbool STP
        assert isoneof STP_MODE stp rstp
@@ -46,7 +46,7 @@ function _check() {
        assert isinteger MTU
 }
 
-function _parse_cmdline() {
+function hook_parse_cmdline() {
        while [ $# -gt 0 ]; do
                case "${1}" in
                        --stp=*)
@@ -78,7 +78,7 @@ function _parse_cmdline() {
        done
 }
 
-function _up() {
+function hook_up() {
        local zone=${1}
        assert isset zone
 
@@ -131,7 +131,7 @@ function _up() {
        exit ${EXIT_OK}
 }
 
-function _down() {
+function hook_down() {
        local zone=${1}
        assert isset zone
 
@@ -152,7 +152,7 @@ function _down() {
        exit ${EXIT_OK}
 }
 
-function _status() {
+function hook_status() {
        local zone=${1}
        assert isset zone
 
index 63f99dc0200fb254d9d6a46ebc6d8d8ce143964f..783c122699ded9d2cefd83e552f8db1f23319be7 100755 (executable)
@@ -26,12 +26,12 @@ HOOK_SETTINGS="HOOK DELAY"
 # Default settings.
 DELAY=0
 
-function _check() {
+function hook_check() {
        assert isset DELAY
        assert isinteger DELAY
 }
 
-function _create() {
+function hook_create() {
        local zone=${1}
        shift
 
@@ -49,7 +49,7 @@ function _create() {
        exit ${EXIT_OK}
 }
 
-function _up() {
+function hook_up() {
        local zone=${1}
        local config=${2}
        shift 2
@@ -65,7 +65,7 @@ function _up() {
        exit ${EXIT_OK}
 }
 
-function _down() {
+function hook_down() {
        local zone=${1}
        local config=${2}
        shift 2
@@ -81,7 +81,7 @@ function _down() {
        exit ${EXIT_OK}
 }
 
-function _status() {
+function hook_status() {
        local zone=${1}
        local config=${2}
        shift 2
index ba866ca6e5b31344cea3fcc083cbcdb14b28bb3a..f56a5551352ed2c15073c4a7df643c76f34aff7d 100755 (executable)
@@ -23,7 +23,7 @@
 
 HOOK_SETTINGS="HOOK ADDRESS PREFIX GATEWAY"
 
-function _check() {
+function hook_check() {
        assert isset ADDRESS
        assert isinteger PREFIX
 
@@ -33,7 +33,7 @@ function _check() {
        fi
 }
 
-function _create() {
+function hook_create() {
        local zone=${1}
        shift
 
@@ -65,7 +65,7 @@ function _create() {
        exit ${EXIT_OK}
 }
 
-function _up() {
+function hook_up() {
        local zone=${1}
        local config=${2}
        shift 2
@@ -91,7 +91,7 @@ function _up() {
        exit ${EXIT_OK}
 }
 
-function _down() {
+function hook_down() {
        local zone=${1}
        local config=${2}
        shift 2
@@ -111,7 +111,7 @@ function _down() {
        exit ${EXIT_OK}
 }
 
-function _status() {
+function hook_status() {
        local zone=${1}
        local config=${2}
        shift 2
index 57dfdefbe8bff54e5d313419c1e1c5fd432cd4e4..fb5513e0fbf967b8c9bebdb74a68711d34fbac41 100755 (executable)
@@ -23,7 +23,7 @@
 
 HOOK_SETTINGS="HOOK ADDRESS PREFIX GATEWAY"
 
-function _check() {
+function hook_check() {
        assert isset ADDRESS
        assert isinteger PREFIX
 
@@ -33,7 +33,7 @@ function _check() {
        fi
 }
 
-function _create() {
+function hook_create() {
        local zone=${1}
        shift
 
@@ -64,7 +64,7 @@ function _create() {
        exit ${EXIT_OK}
 }
 
-function _up() {
+function hook_up() {
        local zone=${1}
        local config=${2}
        shift 2
@@ -86,7 +86,7 @@ function _up() {
        exit ${EXIT_OK}
 }
 
-function _down() {
+function hook_down() {
        local zone=${1}
        local config=${2}
        shift 2
@@ -109,7 +109,7 @@ function _down() {
        exit ${EXIT_OK}
 }
 
-function _status() {
+function hook_status() {
        local zone=${1}
        local config=${2}
        shift 2
index 0b1cd4cc27828a7c150bc89c6d291ab81c82926d..9bf279a90ca349488878b8968cd98dd9ae61d3bb 100755 (executable)
@@ -37,13 +37,13 @@ SUBNET=
 # 0 = unlimited.
 MAX_SESSIONS=0
 
-function _check() {
+function hook_check() {
        assert isset MTU
        assert isset SUBNET
        assert isset MAX_SESSIONS
 }
 
-function _create() {
+function hook_create() {
        local zone=${1}
        shift
 
@@ -70,7 +70,7 @@ function _create() {
        exit ${EXIT_OK}
 }
 
-function _up() {
+function hook_up() {
        local zone=${1}
        local config=${2}
        shift 2
@@ -81,7 +81,7 @@ function _up() {
        exit ${EXIT_OK}
 }
 
-function _down() {
+function hook_down() {
        local zone=${1}
        local config=${2}
        shift 2
@@ -97,7 +97,7 @@ function _down() {
        exit ${EXIT_OK}
 }
 
-function _status() {
+function hook_status() {
        local zone=${1}
        local config=${2}
        shift 2
index 4ff10a36c80224dec25ac99e1e1e555cf66d8995..1b7d92b1e8f2fda33249b8905c6f732219da297b 100755 (executable)
@@ -23,7 +23,7 @@
 
 HOOK_SETTINGS="COST PRIORITY"
 
-function _check() {
+function hook_check() {
        local i
        for i in COST PRIORITY; do
                if isset ${i}; then
@@ -32,7 +32,7 @@ function _check() {
        done
 }
 
-function _add() {
+function hook_add() {
        local zone=${1}
        local port=${2}
        shift 2
@@ -64,11 +64,11 @@ function _add() {
        exit ${EXIT_OK}
 }
 
-function _edit() {
-       _add $@
+function hook_edit() {
+       hook_add $@
 }
 
-function _rem() {
+function hook_remove() {
        local zone=${1}
        local port=${2}
 
@@ -92,7 +92,7 @@ function _rem() {
        exit ${EXIT_OK}
 }
 
-function _up() {
+function hook_up() {
        local zone=${1}
        local port=${2}
 
@@ -114,7 +114,7 @@ function _up() {
        exit ${EXIT_OK}
 }
 
-function _down() {
+function hook_down() {
        local zone=${1}
        local port=${2}
 
@@ -131,7 +131,7 @@ function _down() {
        exit ${EXIT_OK}
 }
 
-function _status() {
+function hook_status() {
        local zone=${1}
        local port=${2}
 
index 366a65c7fbf186bb3d6940e42495078d1752dc20..d00706811bf10a7f127d6558ba2b5361521b789d 100755 (executable)
@@ -43,7 +43,7 @@ MODE="persistent"
 
 ISDN_ALLOWED_AUTHS="chap pap"
 
-function _check() {
+function hook_check() {
        assert isset USER
        assert isset SECRET
        assert isset LINKNAME
@@ -60,7 +60,7 @@ function _check() {
        isset AUTH && assert isoneof AUTH ${ISDN_ALLOWED_AUTHS}
 }
 
-function _parse_cmdline() {
+function hook_parse_cmdline() {
        local value
 
        while [ $# -gt 0 ]; do
@@ -117,7 +117,7 @@ function _parse_cmdline() {
        done
 }
 
-function _up() {
+function hook_up() {
        local zone=${1}
        shift
 
@@ -156,7 +156,7 @@ function _up() {
        exit ${EXIT_OK}
 }
 
-function _down() {
+function hook_down() {
        local zone=${1}
        shift
 
@@ -169,7 +169,7 @@ function _down() {
        exit ${EXIT_OK}
 }
 
-function _status() {
+function hook_status() {
        local zone=${1}
        assert isset zone
 
index 856e00a18eeb421166792466e681ae6fe526f3ec..e9d12cde56cde2ba3559d72cfee5e54d6d2bc28e 100755 (executable)
@@ -39,7 +39,7 @@ TIMEOUT=10
 
 MODE="persistent"
 
-function _check() {
+function hook_check() {
        assert isset LOCAL_ADDRESS
        assert isset REMOTE_ADDRESS
 
@@ -52,7 +52,7 @@ function _check() {
        isset AUTH && assert isoneof AUTH ${ISDN_ALLOWED_AUTHS}
 }
 
-function _parse_cmdline() {
+function hook_parse_cmdline() {
        local value
 
        while [ $# -gt 0 ]; do
@@ -112,7 +112,7 @@ function _parse_cmdline() {
        done
 }
 
-function _up() {
+function hook_up() {
        local zone=${1}
        shift
 
@@ -169,7 +169,7 @@ function _up() {
        exit ${EXIT_OK}
 }
 
-function _down() {
+function hook_down() {
        local zone=${1}
        shift
 
@@ -185,7 +185,7 @@ function _down() {
        exit ${EXIT_OK}
 }
 
-function _status() {
+function hook_status() {
        local zone=${1}
        assert isset zone
 
index 7794897ce0ccb2929159de49667fcb7c414b34b4..fa37ddf9f5f3b6b9c34f531ccae42b2273a68a57 100755 (executable)
@@ -66,7 +66,7 @@ HOOK_SETTINGS="${HOOK_SETTINGS} PIN"
 PHONE_NUMBER=
 HOOK_SETTINGS="${HOOK_SETTINGS} PHONE_NUMBER"
 
-function _check() {
+function hook_check() {
        assert isset DEVICE
        assert isset PHONE_NUMBER
 
@@ -82,7 +82,7 @@ function _check() {
        isset AUTH && assert isoneof AUTH ${MODEM_ALLOWED_AUTH_METHODS}
 }
 
-function _parse_cmdline() {
+function hook_parse_cmdline() {
        local value
 
        while [ $# -gt 0 ]; do
@@ -128,7 +128,7 @@ function _parse_cmdline() {
        done
 }
 
-function _up() {
+function hook_up() {
        local zone=${1}
        assert isset zone
 
@@ -174,7 +174,7 @@ function _up() {
        exit ${EXIT_OK}
 }
 
-function _down() {
+function hook_down() {
        local zone=${1}
        assert isset zone
 
@@ -184,7 +184,7 @@ function _down() {
        exit ${EXIT_OK}
 }
 
-function _status() {
+function hook_status() {
        local zone=${1}
        assert isset zone
 
@@ -275,7 +275,7 @@ function _status() {
        exit ${EXIT_OK}
 }
 
-function _ppp_write_config() {
+function hook_ppp_write_config() {
        local zone=${1}
        assert isset zone
 
index 2b0a5451b13a4e74bff19f379bee04197efd55e4..ee89346487b53a219e6304be4d8704b7e4aaf25f 100755 (executable)
@@ -54,7 +54,7 @@ IPV6="true"
 # Use IPv6 prefix delegation.
 PREFIX_DELEGATION="false"
 
-function _check() {
+function hook_check() {
        assert isset USERNAME
        assert isset PASSWORD
 
@@ -68,7 +68,7 @@ function _check() {
        assert isset PREFIX_DELEGATION
 }
 
-function _parse_cmdline() {
+function hook_parse_cmdline() {
        while [ $# -gt 0 ]; do
                case "${1}" in
                        --access-concentrator=*)
@@ -111,7 +111,7 @@ function _parse_cmdline() {
        done
 }
 
-function _up() {
+function hook_up() {
        local zone=${1}
        assert isset zone
 
@@ -127,7 +127,7 @@ function _up() {
        exit ${EXIT_OK}
 }
 
-function _down() {
+function hook_down() {
        local zone=${1}
        assert isset zone
 
@@ -143,7 +143,7 @@ function _down() {
        exit ${EXIT_OK}
 }
 
-function _discover() {
+function hook_discover() {
        local device=${1}
 
        if [ "$(device_get_type ${device})" != "real" ]; then
@@ -173,7 +173,7 @@ function _discover() {
        exit ${DISCOVER_OK}
 }
 
-function _status() {
+function hook_status() {
        local zone=${1}
        assert isset zone
 
@@ -225,7 +225,7 @@ function _status() {
        exit ${EXIT_OK}
 }
 
-function _ppp_write_config() {
+function hook_ppp_write_config() {
        local zone=${1}
        assert isset zone
 
index f1718e730c97fd4740248ae2aee3c46d961a8236..4e65e9990840ec39a5638e37d51e9c74ad3f309b 100755 (executable)
@@ -27,12 +27,12 @@ HOOK_SETTINGS="HOOK MAC MTU"
 MAC=$(mac_generate)
 MTU=1500
 
-function _check() {
+function hook_check() {
        assert ismac MAC
        assert isinteger MTU
 }
 
-function _parse_cmdline() {
+function hook_parse_cmdline() {
        while [ $# -gt 0 ]; do
                case "${1}" in
                        --mtu=*)
@@ -49,7 +49,7 @@ function _parse_cmdline() {
        done
 }
 
-function _up() {
+function hook_up() {
        local zone=${1}
        shift
 
@@ -72,7 +72,7 @@ function _up() {
        exit ${EXIT_OK}
 }
 
-function _down() {
+function hook_down() {
        local zone=${1}
        shift
 
@@ -89,7 +89,7 @@ function _down() {
        exit ${EXIT_OK}
 }
 
-function _status() {
+function hook_status() {
        local zone=${1}
        assert isset zone
 
index 32f48d451f93e29552109201f7bfa382a45843cb..ece306de8945e8c7b418e5360d33811c1886a8ae 100755 (executable)
@@ -25,11 +25,11 @@ HOOK_SETTINGS="HOOK SERVER"
 
 SERVER=""
 
-function _check() {
+function hook_check() {
        assert isset SERVER
 }
 
-function _parse_cmdline() {
+function hook_parse_cmdline() {
        local value
 
        while [ $# -gt 0 ]; do
@@ -46,7 +46,7 @@ function _parse_cmdline() {
        done
 }
 
-function _up() {
+function hook_up() {
        local zone=${1}
        assert isset zone
 
@@ -55,7 +55,7 @@ function _up() {
        exit ${EXIT_OK}
 }
 
-function _down() {
+function hook_down() {
        local zone=${1}
        assert isset zone
 
@@ -64,7 +64,7 @@ function _down() {
        exit ${EXIT_OK}
 }
 
-function _status() {
+function hook_status() {
        local zone=${1}
        assert isset zone
 
index 327388ba2cbc8e6beeb394924303a60e5cd9263f..f4b853a4b354feb29fa8b95f0bfdd6b787669d63 100755 (executable)
@@ -31,7 +31,7 @@ SSID=
 KEY=
 ENCRYPTION_MODE=
 
-function _check() {
+function hook_check() {
        assert isset SSID
 
        if isset ADDRESS; then
@@ -46,7 +46,7 @@ function _check() {
        fi
 }
 
-function _parse_cmdline() {
+function hook_parse_cmdline() {
        while [ $# -gt 0 ]; do
                case "${1}" in
                        --phy=*|--parent-device=*)
@@ -76,7 +76,7 @@ function _parse_cmdline() {
        PHY=$(phy_get_address ${PHY})
 }
 
-function _up() {
+function hook_up() {
        local zone=${1}
        assert isset zone
 
@@ -100,7 +100,7 @@ function _up() {
        exit ${EXIT_OK}
 }
 
-function _down() {
+function hook_down() {
        local zone=${1}
        shift
 
@@ -118,7 +118,7 @@ function _down() {
        exit ${EXIT_OK}
 }
 
-function _status() {
+function hook_status() {
        local zone=${1}
        assert isset zone
 
index 656fa4b0d6ebba8a5bae0dd61578205d0745b6fb..9c1ac7e1d1a6a82b0cce0acb27c03a1d16d169d7 100755 (executable)
@@ -53,15 +53,31 @@ if isset ZONE && zone_exists ${ZONE}; then
        assert hook_zone_exists ${HOOK}
 
        PROGNAME=$(basename ${0})
-       assert isset PROGNAME
+       METHOD=""
+       case "${PROGNAME}" in
+               ip-pre-up)
+                       METHOD="ppp_ip_pre_up"
+                       ;;
+               ipv6-down)
+                       METHOD="ppp_ipv6_down"
+                       ;;
+               ipv6-up)
+                       METHOD="ppp_ipv6_up"
+                       ;;
+               ip-down)
+                       METHOD="ppp_ipv4_down"
+                       ;;
+               ip-up)
+                       METHOD="ppp_ipv4_up"
+                       ;;
+       esac
+       assert isset METHOD
 
-       log DEBUG "${PROGNAME} was called with the following parameters:"
+       log DEBUG "${PROGNAME}/${METHOD} was called with the following parameters:"
        log DEBUG "  $@"
 
-       hook_zone_exec ${HOOK} ppp-${PROGNAME} ${ZONE}
-       ret=$?
-
-       exit ${ret}
+       hook_zone_exec "${HOOK}" "${METHOD}" "${ZONE}"
+       exit $?
 fi
 
 exit ${EXIT_OK}