echo "${NETWORK_HOOKS_DIR}${type}"
}
+NETWORK_HOOKS_DIR_ZONES="$(hook_dir zone)"
function hook_exists() {
local type=${1}
assert isset type
assert isset hook
- local hook_dir=$(hook_dir ${type})
+ # Add the path prefix.
+ hook="$(hook_dir ${type})/${hook}"
- [ -d "${hook_dir}/${hook}" ] && return ${EXIT_ERROR}
-
- [ -x "${hook_dir}/${hook}" ]
+ [ ! -d "${hook}" ] && [ -x "${hook}" ]
}
function hook_exec() {
local type=${1}
local hook=${2}
- shift 2
+ local cmd=${3}
+ shift 3
assert isset type
assert isset hook
+ assert isset cmd
- if ! hook_exists ${type} ${hook}; then
- error "Hook '${hook}' does not exist."
- return ${EXIT_ERROR}
+ assert hook_exists "${type}" "${hook}"
+
+ # For performance reasons, all hooks are executed
+ # in a subshell and so will inherit the currently
+ # running environment.
+ (
+ # Set the name of the hook.
+ HOOK=$(basename ${hook})
+
+ # Source the code of the hook.
+ source "$(hook_dir ${type})/${hook}"
+
+ # Make sure HOOK is still properly set.
+ assert isset HOOK
+
+ # Execute the requested command.
+ _${cmd} $@
+ )
+ local ret=$?
+
+ if [ ${ret} -eq ${EXIT_ERROR_ASSERT} ]; then
+ log ERROR "Hook exited with an assertion error."
+ exit ${ret}
fi
- exec_cmd $(hook_dir ${type})/${hook} $@
+ return ${ret}
}
function config_get_hook() {
)
}
-## Wrappers around the hook functions for zones
-
function hook_zone_exists() {
hook_exists zone $@
}
local hook_zone=${1}
local hook_port=${2}
- hook_zone_exists ${hook_zone} || return ${EXIT_ERROR}
-
- [ -x "$(hook_dir zone)/${hook_zone}.ports/${hook_port}" ]
+ hook_exists zone "${hook_zone}.ports/${hook_port}"
}
function hook_zone_config_exists() {
local hook_zone=${1}
local hook_config=${2}
- hook_zone_exists ${hook_zone} || return ${EXIT_ERROR}
-
- [ -x "$(hook_dir zone)/${hook_zone}.configs/${hook_config}" ]
+ hook_exists zone "${hook_zone}.configs/${hook_config}"
}
function hook_zone_has_ports() {
local hook=${1}
- [ -d "$(hook_dir zone)/${hook}.ports" ]
-}
-
-function hook_zone_port_exists() {
- : # XXX WANTED
+ [ -d "${NETWORK_HOOKS_DIR_ZONES}/${hook}.ports" ]
}
function hook_zone_has_configs() {
local hook=${1}
- [ -d "$(hook_dir zone)/${hook}.configs" ]
+ [ -d "${NETWORK_HOOKS_DIR_ZONES}/${hook}.configs" ]
}
function hook_zone_exec() {
local hook_port=${2}
shift 2
- if ! hook_exists zone ${hook_zone}; then
- error "Hook '${hook_zone}' does not exist."
- return ${EXIT_ERROR}
- fi
-
- if ! hook_zone_port_exists ${hook_zone} ${hook_port}; then
- error "Port hook '${hook_port}' does not exist."
- return ${EXIT_ERROR}
- fi
-
- exec_cmd $(hook_dir zone)/${hook_zone}.ports/${hook_port} $@
+ hook_zone_exec "${hook_zone}.ports/${hook_port}" $@
}
function hook_zone_config_exec() {
local hook_zone=${1}
- local hook_config=${2}
+ local hook_port=${2}
shift 2
- assert isset hook_zone
- assert isset hook_config
-
- if ! hook_zone_exists ${hook_zone}; then
- error "Hook '${hook_zone}' does not exist."
- return ${EXIT_ERROR}
- fi
-
- if ! hook_zone_config_exists ${hook_zone} ${hook_config}; then
- error "Config hook '${hook_config}' does not exist."
- return ${EXIT_ERROR}
- fi
-
- exec_cmd $(hook_dir zone)/${hook_zone}.configs/${hook_config} $@
+ hook_zone_exec "${hook_zone}.configs/${hook_port}" $@
}
function hook_zone_get_all() {
function zone_exists() {
local zone=${1}
-
assert isset zone
[ -d "$(zone_dir ${zone})" ]
function zone_name_is_valid() {
local zone=${1}
-
assert isset zone
[[ ${zone} =~ $(zone_match) ]]
function zone_get_hook() {
local zone=${1}
-
assert isset zone
config_get_hook $(zone_dir ${zone})/settings
assert isset hook_zone
assert isset hook_port
- assert hook_zone_port_exists ${hook_zone} ${hook_port}
-
hook_zone_port_exec ${hook_zone} ${hook_port} ${cmd} ${zone} ${port} $@
}
local port
for port in $(zone_get_ports ${zone}); do
- #zone_port_cmd ${cmd} ${zone} ${port} $@
hook_zone_exec ${hook} ${cmd} ${zone} ${port} $@
done
}
for config in $(zone_dir ${zone})/configs/*; do
[ -e "${config}" ] || continue
- echo $(basename ${config})
+ basename ${config}
done
}
# along with this program. If not, see <http://www.gnu.org/licenses/>. #
# #
###############################################################################
-
-. /lib/network/functions
-
-HOOK=$(basename ${0})
-
-while [ $# -gt 0 ]; do
- case "${1}" in
- -*)
- error "Unrecognized option: ${1}"
- exit ${EXIT_ERROR}
- ;;
- *)
- action=${1}
- ;;
- esac
- shift
- [ -n "${action}" ] && break
-done
-
-function run() {
- case "${action}" in
- edit|create|rem|up|down|status)
- _${action} $@
- ;;
- esac
-
- error "Config hook '${HOOK}' didn't exit properly."
- exit ${EXIT_ERROR}
-}
# #
###############################################################################
-. /usr/lib/network/functions
-
-HOOK=$(basename ${0})
INFO_SETTINGS="HOOK PORT_PARENTS PORT_CHILDREN"
-while [ $# -gt 0 ]; do
- case "${1}" in
- -*)
- error "Unrecognized option: ${1}"
- exit ${EXIT_ERROR}
- ;;
- *)
- action=${1}
- ;;
- esac
- shift
- [ -n "${action}" ] && break
-done
-
-function run() {
- case "${action}" in
- edit|add|create|rem|up|down|status|info|hotplug|hotplug_rename)
- _${action} $@
- ;;
- esac
-
- error "Port hook '${HOOK}' didn't exit properly."
- exit ${EXIT_ERROR}
-}
-
# This function is called after a device has been plugged
# into the system and got its correct name.
# The function is intended to create child ports and things
# conflict with any functions that were defined somewhere else.
#
-. /usr/lib/network/functions
-
-HOOK=$(basename ${0})
-
-while [ $# -gt 0 ]; do
- case "${1}" in
- -*)
- error "Unrecognized option: ${1}"
- exit ${EXIT_ERROR}
- ;;
- *)
- action=${1}
- ;;
- esac
- shift
-
- # If action argument was given, we will exit.
- [ -n "${action}" ] && break
-done
-
# _notimplemented
# Returns a soft error if a function was not implemented, yet.
#
exit $?
}
-
-function run() {
- # Replace all dashes by an underscore
- #action=${action//-/_}
-
- case "${action}" in
- # Main functions
- create|discover|down|edit|info|rem|status|up)
- _${action} $@
- ;;
-
- # Port callbacks
- port_add|port_rem|port_up|port_down|port_status)
- _${action} $@
- ;;
-
- # Configuration callbacks
- config_create)
- _${action} $@
- ;;
-
- # ppp daemon callbacks
- ppp-ip-pre-up|ppp-ip-up|ppp-ip-down|ppp-ipv6-up|ppp-ipv6-down)
- _${action} $@
- ;;
-
- # Help requested by the user.
- help)
- _help $@
- exit ${EXIT_OK}
- ;;
-
- *)
- error "Unknown action: ${action}"
- ;;
- esac
-
- error "Hook did not exit properly."
- exit ${EXIT_ERROR}
-}
exit ${EXIT_OK}
}
-
-run $@
# #
###############################################################################
-. /lib/network/header-zone
+. /usr/lib/network/header-zone
HOOK_SETTINGS="HOOK PROTOCOL USER SECRET SERVER TUNNEL_ID"
exit ${EXIT_OK}
}
-
-run $@
cli_space
exit ${EXIT_OK}
}
-
-run $@
# #
###############################################################################
-. /lib/network/header-config
+. /usr/lib/network/header-config
HOOK_SETTINGS="HOOK DELAY"
exit ${EXIT_OK}
}
-
-run $@
# #
###############################################################################
-. /lib/network/header-config
+. /usr/lib/network/header-config
HOOK_SETTINGS="HOOK ADDRESS PREFIX GATEWAY"
echo ${cidr}
fi
}
-
-run $@
# #
###############################################################################
-. /lib/network/header-port
+. /usr/lib/network/header-port
HOOK_SETTINGS="HOOK ADDRESS PREFIX GATEWAY"
exit ${EXIT_OK}
}
-
-run $@
# #
###############################################################################
-. /lib/network/header-port
+. /usr/lib/network/header-port
HOOK_SETTINGS="COST PRIORITY"
exit ${EXIT_OK}
}
-
-run $@
# #
###############################################################################
-. /lib/network/header-zone
+. /usr/lib/network/header-zone
HOOK_SETTINGS="HOOK AUTH LINKNAME USER SECRET PEERDNS DEFAULTROUTE MSN MTU"
HOOK_SETTINGS="${HOOK_SETTINGS} L2PROTO L3PROTO ENCAP PHONE"
exit ${EXIT_OK}
}
-
-run $@
# #
###############################################################################
-. /lib/network/header-zone
+. /usr/lib/network/header-zone
HOOK_SETTINGS="HOOK LOCAL_ADDRESS REMOTE_ADDRESS MSN MTU MRU"
HOOK_SETTINGS="${HOOK_SETTINGS} L2PROTO L3PROTO ENCAP"
echo # Empty line
exit ${EXIT_OK}
}
-
-run $@
echo # Empty line
exit ${EXIT_OK}
}
-
-run $@
# #
###############################################################################
-. /lib/network/header-zone
+. /usr/lib/network/header-zone
# TODO XXX AC name, service name, sync?
exit ${EXIT_OK}
}
-
-run $@
exit ${EXIT_OK}
}
-
-run $@
# #
###############################################################################
-. /lib/network/header-zone
+. /usr/lib/network/header-zone
HOOK_SETTINGS="HOOK PHY MAC MTU SSID KEY ENCRYPTION"
echo # Empty line
exit ${EXIT_OK}
}
-
-run $@