From 2181765d1c16758c03e4a5fd242d878a00b42e65 Mon Sep 17 00:00:00 2001 From: Michael Tremer Date: Wed, 8 May 2013 21:18:56 +0200 Subject: [PATCH] Renew hook function naming scheme. --- functions.constants | 1 + functions.hook | 65 +++++-- functions.ppp | 4 +- functions.util | 4 + header-port | 22 +-- header-zone | 248 ++++++++++++------------ hooks/ports/batman-adv | 14 +- hooks/ports/batman-adv-port | 14 +- hooks/ports/bonding | 10 +- hooks/ports/dummy | 12 +- hooks/ports/ethernet | 10 +- hooks/ports/macvlan | 10 +- hooks/ports/vlan | 10 +- hooks/ports/wireless-ap | 12 +- hooks/zones/6to4-tunnel | 10 +- hooks/zones/aiccu | 10 +- hooks/zones/bridge | 10 +- hooks/zones/bridge.configs/ipv4-dhcp | 10 +- hooks/zones/bridge.configs/ipv4-static | 10 +- hooks/zones/bridge.configs/ipv6-static | 10 +- hooks/zones/bridge.configs/pppoe-server | 10 +- hooks/zones/bridge.ports/ethernet | 16 +- hooks/zones/isdn | 10 +- hooks/zones/isdn-server | 10 +- hooks/zones/modem | 12 +- hooks/zones/pppoe | 14 +- hooks/zones/switch | 10 +- hooks/zones/teredo | 10 +- hooks/zones/wireless | 10 +- ppp/ip-updown | 28 ++- 30 files changed, 341 insertions(+), 285 deletions(-) diff --git a/functions.constants b/functions.constants index 21b44fca..01848841 100644 --- a/functions.constants +++ b/functions.constants @@ -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 diff --git a/functions.hook b/functions.hook index 792f2ba8..6ee527d5 100644 --- a/functions.hook +++ b/functions.hook @@ -19,6 +19,22 @@ # # ############################################################################### +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} } diff --git a/functions.ppp b/functions.ppp index 1b7d9a30..05ebed56 100644 --- a/functions.ppp +++ b/functions.ppp @@ -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 diff --git a/functions.util b/functions.util index 1fb19515..b975b6a0 100644 --- a/functions.util +++ b/functions.util @@ -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}} diff --git a/header-port b/header-port index b07c99c5..44e3cf18 100644 --- a/header-port +++ b/header-port @@ -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} } diff --git a/header-zone b/header-zone index 8233f612..74cec328 100644 --- a/header-zone +++ b/header-zone @@ -18,47 +18,36 @@ # along with this program. If not, see . # # # ############################################################################### -# -# 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: } -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 $? } diff --git a/hooks/ports/batman-adv b/hooks/ports/batman-adv index a2cb151e..76e9250e 100755 --- a/hooks/ports/batman-adv +++ b/hooks/ports/batman-adv @@ -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 diff --git a/hooks/ports/batman-adv-port b/hooks/ports/batman-adv-port index 0d44ba35..a9304684 100755 --- a/hooks/ports/batman-adv-port +++ b/hooks/ports/batman-adv-port @@ -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 diff --git a/hooks/ports/bonding b/hooks/ports/bonding index 3d8b987e..355eece1 100755 --- a/hooks/ports/bonding +++ b/hooks/ports/bonding @@ -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} diff --git a/hooks/ports/dummy b/hooks/ports/dummy index bfd0e506..3af50cd0 100755 --- a/hooks/ports/dummy +++ b/hooks/ports/dummy @@ -23,11 +23,11 @@ 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 diff --git a/hooks/ports/ethernet b/hooks/ports/ethernet index 327036ca..35a90bf9 100755 --- a/hooks/ports/ethernet +++ b/hooks/ports/ethernet @@ -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 diff --git a/hooks/ports/macvlan b/hooks/ports/macvlan index 5770e9db..0214465a 100755 --- a/hooks/ports/macvlan +++ b/hooks/ports/macvlan @@ -27,12 +27,12 @@ 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 diff --git a/hooks/ports/vlan b/hooks/ports/vlan index 66b98eb3..20550077 100755 --- a/hooks/ports/vlan +++ b/hooks/ports/vlan @@ -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 diff --git a/hooks/ports/wireless-ap b/hooks/ports/wireless-ap index 391e6828..c6d91da0 100755 --- a/hooks/ports/wireless-ap +++ b/hooks/ports/wireless-ap @@ -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 diff --git a/hooks/zones/6to4-tunnel b/hooks/zones/6to4-tunnel index 2fbb5bbf..450b7b93 100755 --- a/hooks/zones/6to4-tunnel +++ b/hooks/zones/6to4-tunnel @@ -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 diff --git a/hooks/zones/aiccu b/hooks/zones/aiccu index c5fbdd0f..e31f8977 100755 --- a/hooks/zones/aiccu +++ b/hooks/zones/aiccu @@ -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 diff --git a/hooks/zones/bridge b/hooks/zones/bridge index fabb008e..a534871b 100755 --- a/hooks/zones/bridge +++ b/hooks/zones/bridge @@ -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 diff --git a/hooks/zones/bridge.configs/ipv4-dhcp b/hooks/zones/bridge.configs/ipv4-dhcp index 63f99dc0..783c1226 100755 --- a/hooks/zones/bridge.configs/ipv4-dhcp +++ b/hooks/zones/bridge.configs/ipv4-dhcp @@ -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 diff --git a/hooks/zones/bridge.configs/ipv4-static b/hooks/zones/bridge.configs/ipv4-static index ba866ca6..f56a5551 100755 --- a/hooks/zones/bridge.configs/ipv4-static +++ b/hooks/zones/bridge.configs/ipv4-static @@ -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 diff --git a/hooks/zones/bridge.configs/ipv6-static b/hooks/zones/bridge.configs/ipv6-static index 57dfdefb..fb5513e0 100755 --- a/hooks/zones/bridge.configs/ipv6-static +++ b/hooks/zones/bridge.configs/ipv6-static @@ -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 diff --git a/hooks/zones/bridge.configs/pppoe-server b/hooks/zones/bridge.configs/pppoe-server index 0b1cd4cc..9bf279a9 100755 --- a/hooks/zones/bridge.configs/pppoe-server +++ b/hooks/zones/bridge.configs/pppoe-server @@ -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 diff --git a/hooks/zones/bridge.ports/ethernet b/hooks/zones/bridge.ports/ethernet index 4ff10a36..1b7d92b1 100755 --- a/hooks/zones/bridge.ports/ethernet +++ b/hooks/zones/bridge.ports/ethernet @@ -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} diff --git a/hooks/zones/isdn b/hooks/zones/isdn index 366a65c7..d0070681 100755 --- a/hooks/zones/isdn +++ b/hooks/zones/isdn @@ -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 diff --git a/hooks/zones/isdn-server b/hooks/zones/isdn-server index 856e00a1..e9d12cde 100755 --- a/hooks/zones/isdn-server +++ b/hooks/zones/isdn-server @@ -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 diff --git a/hooks/zones/modem b/hooks/zones/modem index 7794897c..fa37ddf9 100755 --- a/hooks/zones/modem +++ b/hooks/zones/modem @@ -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 diff --git a/hooks/zones/pppoe b/hooks/zones/pppoe index 2b0a5451..ee893464 100755 --- a/hooks/zones/pppoe +++ b/hooks/zones/pppoe @@ -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 diff --git a/hooks/zones/switch b/hooks/zones/switch index f1718e73..4e65e999 100755 --- a/hooks/zones/switch +++ b/hooks/zones/switch @@ -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 diff --git a/hooks/zones/teredo b/hooks/zones/teredo index 32f48d45..ece306de 100755 --- a/hooks/zones/teredo +++ b/hooks/zones/teredo @@ -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 diff --git a/hooks/zones/wireless b/hooks/zones/wireless index 327388ba..f4b853a4 100755 --- a/hooks/zones/wireless +++ b/hooks/zones/wireless @@ -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 diff --git a/ppp/ip-updown b/ppp/ip-updown index 656fa4b0..9c1ac7e1 100755 --- a/ppp/ip-updown +++ b/ppp/ip-updown @@ -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} -- 2.39.2