EXIT_OK=0
EXIT_ERROR=1
EXIT_CONF_ERROR=2
+EXIT_COMMAND_NOT_FOUND=127
EXIT_ERROR_ASSERT=128
EXIT_TRUE=0
# #
###############################################################################
+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}
}
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
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}
}
return ${EXIT_OK}
}
-function ppp_common_ip_up() {
+function ppp_common_ipv4_up() {
local zone=${1}
shift
return ${EXIT_OK}
}
-function ppp_common_ip_down() {
+function ppp_common_ipv4_down() {
local zone=${1}
shift
exit ${EXIT_ERROR}
}
+function cmd_not_implemented() {
+ assert false "not implemented"
+}
+
function seq() {
if [ $# -eq 2 ]; then
eval echo {${1}..${2}}
# 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}
}
# 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}
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}
}
# 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}
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."
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=$?
;;
*)
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 $?
}
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=*)
exit ${EXIT_OK}
}
-function _edit() {
+function hook_edit() {
local port=${1}
assert isset port
shift
exit ${EXIT_OK}
}
-function _up() {
+function hook_up() {
local port=${1}
assert isset port
exit ${EXIT_OK}
}
-function _down() {
+function hook_down() {
local port=${1}
assert isset port
exit ${EXIT_OK}
}
-function _hotplug() {
+function hook_hotplug() {
local port=${1}
assert isset port
exit ${EXIT_OK}
}
-function _status() {
+function hook_status() {
local port=${1}
assert isset port
# 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
assert isset SSID
}
-function _create() {
+function hook_create() {
while [ $# -gt 0 ]; do
case "${1}" in
--address=*)
exit ${EXIT_OK}
}
-function _edit() {
+function hook_edit() {
local port=${1}
assert isset port
shift
exit ${EXIT_OK}
}
-function _up() {
+function hook_up() {
local port=${1}
assert isset port
exit ${EXIT_OK}
}
-function _down() {
+function hook_down() {
local port=${1}
assert isset port
exit ${EXIT_OK}
}
-function _hotplug() {
+function hook_hotplug() {
local port=${1}
assert isset port
exit ${EXIT_OK}
}
-function _find_parent() {
+function hook_find_parent() {
local port=${1}
assert isset port
SLAVES=""
MIIMON=100
-function _check() {
+function hook_check() {
assert isset ADDRESS
assert ismac ADDRESS
assert isinteger MIIMON
}
-function _create() {
+function hook_create() {
_edit $@
}
-function _edit() {
+function hook_edit() {
local port=${1}
assert isset port
shift
exit ${EXIT_OK}
}
-function _up() {
+function hook_up() {
local device=${1}
assert isset device
exit ${EXIT_OK}
}
-function _down() {
+function hook_down() {
local device=${1}
bonding_remove ${device}
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=*)
exit ${EXIT_OK}
}
-function _edit() {
+function hook_edit() {
local port=${1}
assert isset port
shift
exit ${EXIT_OK}
}
-function _up() {
+function hook_up() {
local port=${1}
assert isset port
exit ${EXIT_OK}
}
-function _down() {
+function hook_down() {
local port=${1}
assert isset port
exit ${EXIT_OK}
}
-function _hotplug_rename() {
+function hook_hotplug_rename() {
local port=${1}
assert isset port
HOOK_SETTINGS="HOOK ADDRESS DEVICE"
-function _check() {
+function hook_check() {
assert ismac DEVICE
if isset ADDRESS; then
fi
}
-function _create() {
+function hook_create() {
local port=${1}
assert isset port
shift
exit ${EXIT_OK}
}
-function _up() {
+function hook_up() {
local port=${1}
assert isset port
exit ${EXIT_OK}
}
-function _down() {
+function hook_down() {
local port=${1}
assert isset port
exit ${EXIT_OK}
}
-function _hotplug_rename() {
+function hook_hotplug_rename() {
local port=${1}
assert isset port
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=*)
exit ${EXIT_OK}
}
-function _edit() {
+function hook_edit() {
local port=${1}
assert isset port
shift
exit ${EXIT_OK}
}
-function _up() {
+function hook_up() {
local port=${1}
assert isset port
exit ${EXIT_OK}
}
-function _down() {
+function hook_down() {
local port=${1}
assert isset port
PORT_PARENTS_VAR="PARENT"
-function _check() {
+function hook_check() {
assert isset PARENT_DEVICE
assert isinteger TAG
done
}
-function _create() {
+function hook_create() {
while [ $# -gt 0 ]; do
case "${1}" in
--parent-device=*)
exit ${EXIT_OK}
}
-function _edit() {
+function hook_edit() {
local port=${1}
assert isset port
shift
exit ${EXIT_OK}
}
-function _up() {
+function hook_up() {
local port=${1}
assert isset port
exit ${EXIT_OK}
}
-function _down() {
+function hook_down() {
local port=${1}
assert isset port
MODE="g"
SSID=
-function _check() {
+function hook_check() {
assert isset ADDRESS
assert ismac ADDRESS
assert isset BROADCAST_SSID
fi
}
-function _create() {
+function hook_create() {
while [ $# -gt 0 ]; do
case "${1}" in
--broadcast-ssid=*)
exit ${EXIT_OK}
}
-function _edit() {
+function hook_edit() {
local port=${1}
shift
exit ${EXIT_OK}
}
-function _up() {
+function hook_up() {
local port=${1}
assert isset port
exit ${EXIT_OK}
}
-function _down() {
+function hook_down() {
local port=${1}
assert isset port
exit ${EXIT_OK}
}
-function _hotplug() {
+function hook_hotplug() {
local port=${1}
assert isset port
USERNAME=
PASSWORD=
-function _check() {
+function hook_check() {
assert isset SERVER_ADDRESS
assert isset LOCAL_ADDRESS
assert isset LOCAL_ADDRESS6
fi
}
-function _parse_cmdline() {
+function hook_parse_cmdline() {
local value
while [ $# -gt 0 ]; do
done
}
-function _up() {
+function hook_up() {
local zone=${1}
assert isset zone
exit ${EXIT_OK}
}
-function _down() {
+function hook_down() {
local zone=${1}
assert isset zone
exit ${EXIT_OK}
}
-function _status() {
+function hook_status() {
local zone=${1}
assert isset zone
TUNNEL_ID=
REQUIRE_TLS="true"
-function _check() {
+function hook_check() {
assert isset USERNAME
assert isset PASSWORD
assert isset SERVER
fi
}
-function _parse_cmdline() {
+function hook_parse_cmdline() {
local value
while [ $# -gt 0 ]; do
done
}
-function _up() {
+function hook_up() {
local zone=${1}
assert isset zone
exit ${EXIT_OK}
}
-function _down() {
+function hook_down() {
local zone=${1}
assert isset zone
exit ${EXIT_OK}
}
-function _status() {
+function hook_status() {
local zone=${1}
assert isset zone
STP_MAXAGE=20
STP_PRIORITY=512
-function _check() {
+function hook_check() {
assert ismac MAC
assert isbool STP
assert isoneof STP_MODE stp rstp
assert isinteger MTU
}
-function _parse_cmdline() {
+function hook_parse_cmdline() {
while [ $# -gt 0 ]; do
case "${1}" in
--stp=*)
done
}
-function _up() {
+function hook_up() {
local zone=${1}
assert isset zone
exit ${EXIT_OK}
}
-function _down() {
+function hook_down() {
local zone=${1}
assert isset zone
exit ${EXIT_OK}
}
-function _status() {
+function hook_status() {
local zone=${1}
assert isset zone
# Default settings.
DELAY=0
-function _check() {
+function hook_check() {
assert isset DELAY
assert isinteger DELAY
}
-function _create() {
+function hook_create() {
local zone=${1}
shift
exit ${EXIT_OK}
}
-function _up() {
+function hook_up() {
local zone=${1}
local config=${2}
shift 2
exit ${EXIT_OK}
}
-function _down() {
+function hook_down() {
local zone=${1}
local config=${2}
shift 2
exit ${EXIT_OK}
}
-function _status() {
+function hook_status() {
local zone=${1}
local config=${2}
shift 2
HOOK_SETTINGS="HOOK ADDRESS PREFIX GATEWAY"
-function _check() {
+function hook_check() {
assert isset ADDRESS
assert isinteger PREFIX
fi
}
-function _create() {
+function hook_create() {
local zone=${1}
shift
exit ${EXIT_OK}
}
-function _up() {
+function hook_up() {
local zone=${1}
local config=${2}
shift 2
exit ${EXIT_OK}
}
-function _down() {
+function hook_down() {
local zone=${1}
local config=${2}
shift 2
exit ${EXIT_OK}
}
-function _status() {
+function hook_status() {
local zone=${1}
local config=${2}
shift 2
HOOK_SETTINGS="HOOK ADDRESS PREFIX GATEWAY"
-function _check() {
+function hook_check() {
assert isset ADDRESS
assert isinteger PREFIX
fi
}
-function _create() {
+function hook_create() {
local zone=${1}
shift
exit ${EXIT_OK}
}
-function _up() {
+function hook_up() {
local zone=${1}
local config=${2}
shift 2
exit ${EXIT_OK}
}
-function _down() {
+function hook_down() {
local zone=${1}
local config=${2}
shift 2
exit ${EXIT_OK}
}
-function _status() {
+function hook_status() {
local zone=${1}
local config=${2}
shift 2
# 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
exit ${EXIT_OK}
}
-function _up() {
+function hook_up() {
local zone=${1}
local config=${2}
shift 2
exit ${EXIT_OK}
}
-function _down() {
+function hook_down() {
local zone=${1}
local config=${2}
shift 2
exit ${EXIT_OK}
}
-function _status() {
+function hook_status() {
local zone=${1}
local config=${2}
shift 2
HOOK_SETTINGS="COST PRIORITY"
-function _check() {
+function hook_check() {
local i
for i in COST PRIORITY; do
if isset ${i}; then
done
}
-function _add() {
+function hook_add() {
local zone=${1}
local port=${2}
shift 2
exit ${EXIT_OK}
}
-function _edit() {
- _add $@
+function hook_edit() {
+ hook_add $@
}
-function _rem() {
+function hook_remove() {
local zone=${1}
local port=${2}
exit ${EXIT_OK}
}
-function _up() {
+function hook_up() {
local zone=${1}
local port=${2}
exit ${EXIT_OK}
}
-function _down() {
+function hook_down() {
local zone=${1}
local port=${2}
exit ${EXIT_OK}
}
-function _status() {
+function hook_status() {
local zone=${1}
local port=${2}
ISDN_ALLOWED_AUTHS="chap pap"
-function _check() {
+function hook_check() {
assert isset USER
assert isset SECRET
assert isset LINKNAME
isset AUTH && assert isoneof AUTH ${ISDN_ALLOWED_AUTHS}
}
-function _parse_cmdline() {
+function hook_parse_cmdline() {
local value
while [ $# -gt 0 ]; do
done
}
-function _up() {
+function hook_up() {
local zone=${1}
shift
exit ${EXIT_OK}
}
-function _down() {
+function hook_down() {
local zone=${1}
shift
exit ${EXIT_OK}
}
-function _status() {
+function hook_status() {
local zone=${1}
assert isset zone
MODE="persistent"
-function _check() {
+function hook_check() {
assert isset LOCAL_ADDRESS
assert isset REMOTE_ADDRESS
isset AUTH && assert isoneof AUTH ${ISDN_ALLOWED_AUTHS}
}
-function _parse_cmdline() {
+function hook_parse_cmdline() {
local value
while [ $# -gt 0 ]; do
done
}
-function _up() {
+function hook_up() {
local zone=${1}
shift
exit ${EXIT_OK}
}
-function _down() {
+function hook_down() {
local zone=${1}
shift
exit ${EXIT_OK}
}
-function _status() {
+function hook_status() {
local zone=${1}
assert isset zone
PHONE_NUMBER=
HOOK_SETTINGS="${HOOK_SETTINGS} PHONE_NUMBER"
-function _check() {
+function hook_check() {
assert isset DEVICE
assert isset PHONE_NUMBER
isset AUTH && assert isoneof AUTH ${MODEM_ALLOWED_AUTH_METHODS}
}
-function _parse_cmdline() {
+function hook_parse_cmdline() {
local value
while [ $# -gt 0 ]; do
done
}
-function _up() {
+function hook_up() {
local zone=${1}
assert isset zone
exit ${EXIT_OK}
}
-function _down() {
+function hook_down() {
local zone=${1}
assert isset zone
exit ${EXIT_OK}
}
-function _status() {
+function hook_status() {
local zone=${1}
assert isset zone
exit ${EXIT_OK}
}
-function _ppp_write_config() {
+function hook_ppp_write_config() {
local zone=${1}
assert isset zone
# Use IPv6 prefix delegation.
PREFIX_DELEGATION="false"
-function _check() {
+function hook_check() {
assert isset USERNAME
assert isset PASSWORD
assert isset PREFIX_DELEGATION
}
-function _parse_cmdline() {
+function hook_parse_cmdline() {
while [ $# -gt 0 ]; do
case "${1}" in
--access-concentrator=*)
done
}
-function _up() {
+function hook_up() {
local zone=${1}
assert isset zone
exit ${EXIT_OK}
}
-function _down() {
+function hook_down() {
local zone=${1}
assert isset zone
exit ${EXIT_OK}
}
-function _discover() {
+function hook_discover() {
local device=${1}
if [ "$(device_get_type ${device})" != "real" ]; then
exit ${DISCOVER_OK}
}
-function _status() {
+function hook_status() {
local zone=${1}
assert isset zone
exit ${EXIT_OK}
}
-function _ppp_write_config() {
+function hook_ppp_write_config() {
local zone=${1}
assert isset zone
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=*)
done
}
-function _up() {
+function hook_up() {
local zone=${1}
shift
exit ${EXIT_OK}
}
-function _down() {
+function hook_down() {
local zone=${1}
shift
exit ${EXIT_OK}
}
-function _status() {
+function hook_status() {
local zone=${1}
assert isset zone
SERVER=""
-function _check() {
+function hook_check() {
assert isset SERVER
}
-function _parse_cmdline() {
+function hook_parse_cmdline() {
local value
while [ $# -gt 0 ]; do
done
}
-function _up() {
+function hook_up() {
local zone=${1}
assert isset zone
exit ${EXIT_OK}
}
-function _down() {
+function hook_down() {
local zone=${1}
assert isset zone
exit ${EXIT_OK}
}
-function _status() {
+function hook_status() {
local zone=${1}
assert isset zone
KEY=
ENCRYPTION_MODE=
-function _check() {
+function hook_check() {
assert isset SSID
if isset ADDRESS; then
fi
}
-function _parse_cmdline() {
+function hook_parse_cmdline() {
while [ $# -gt 0 ]; do
case "${1}" in
--phy=*|--parent-device=*)
PHY=$(phy_get_address ${PHY})
}
-function _up() {
+function hook_up() {
local zone=${1}
assert isset zone
exit ${EXIT_OK}
}
-function _down() {
+function hook_down() {
local zone=${1}
shift
exit ${EXIT_OK}
}
-function _status() {
+function hook_status() {
local zone=${1}
assert isset zone
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}