. /usr/lib/network/header-zone
HOOK_SETTINGS="HOOK ACCESS_CONCENTRATOR AUTH USERNAME PASSWORD"
-HOOK_SETTINGS="${HOOK_SETTINGS} SERVICE_NAME MTU PORT IPV6 PREFIX_DELEGATION"
+HOOK_SETTINGS="${HOOK_SETTINGS} SERVICE_NAME MTU IPV6 PREFIX_DELEGATION"
# User credentials for the dialin.
USERNAME=""
# Set the authentication mechanism.
AUTH=
-# The physical ethernet port the modem is connected to.
-PORT=""
-
# Access Concentrator.
ACCESS_CONCENTRATOR=""
# Use IPv6 prefix delegation.
PREFIX_DELEGATION="false"
-function hook_check() {
+function hook_check_settings() {
assert isset USERNAME
assert isset PASSWORD
isset AUTH && assert isoneof AUTH ${PPPOE_SUPPORTED_AUTH_METHODS}
- # Check for a valid port setting.
- assert isset PORT
- assert port_exists ${PORT}
-
assert isset IPV6
assert isset PREFIX_DELEGATION
}
--password=*)
PASSWORD=$(cli_get_val ${1})
;;
- --port=*)
- PORT=$(cli_get_val ${1})
- ;;
--prefix-delegation=*)
PREFIX_DELEGATION="$(cli_get_bool "${1}")"
;;
local zone=${1}
assert isset zone
- zone_config_read ${zone}
+ # If this zone's port is not set, we will return
+ # with EXIT_OK so that this zone will remain active,
+ # but we cannot start pppd.
+ local port=$(__hook_get_port "${zone}")
+ if ! isset port || ! port_exists "${port}"; then
+ log WARNING "Could not bring up zone '${zone}' because no port is attached"
+ exit ${EXIT_OK}
+ fi
+
+ zone_settings_read "${zone}"
# Bring up the port.
- log DEBUG "Bringing up port '${PORT}'."
- port_up ${PORT}
+ port_up "${port}"
# Start the ppp daemon.
pppd_start ${zone}
local zone=${1}
assert isset zone
- zone_config_read ${zone}
+ zone_settings_read "${zone}"
# Stop the ppp daemon.
pppd_stop ${zone}
exit ${EXIT_OK}
}
+function hook_hotplug() {
+ local zone="${1}"
+
+ case "$(hotplug_action)" in
+ add)
+ if hotplug_event_interface_is_port_of_zone "${zone}"; then
+ # Bring up the zone if it is enabled but not active, yet.
+ zone_start_auto "${zone}"
+
+ exit ${EXIT_OK}
+ fi
+ ;;
+ remove)
+ # PPPoE cannot work if the ethernet device has been removed
+ if hotplug_event_interface_is_port_of_zone "${zone}"; then
+ if zone_is_active "${zone}"; then
+ zone_stop "${zone}"
+ fi
+
+ exit ${EXIT_OK}
+ fi
+ ;;
+ esac
+
+ exit ${EXIT_NOT_HANDLED}
+}
+
function hook_discover() {
local device=${1}
- if [ "$(device_get_type ${device})" != "real" ]; then
+ # This obviously only works on ethernet (or compatible) devices
+ if ! device_is_ethernet_compatible "${device}"; then
exit ${EXIT_ERROR}
fi
cli_device_headline ${zone}
- zone_config_read ${zone}
+ zone_settings_read "${zone}"
cli_headline 2 "Configuration"
cli_print_fmt1 2 "Username" "${USERNAME}"
cli_print_fmt1 2 "Password" "<hidden>"
- cli_print_fmt1 2 "Port" "${PORT}"
+
+ local port=$(__hook_get_port "${zone}")
+ if isset port; then
+ cli_print_fmt1 2 "Port" "${port}"
+ fi
cli_space
# Exit if zone is down
assert isset file
# Read in the configuration files.
- zone_config_read ${zone}
+ zone_settings_read "${zone}"
+
+ # A port has to be assigned for this action
+ local port=$(__hook_get_port "${zone}")
+ if ! isset port; then
+ error "No port assigned to pppoe hook of zone '${zone}'"
+ exit ${EXIT_ERROR}
+ fi
# Prepare the command line options for the pppoe plugin.
local plugin_options
fi
# The last argument must be the interface.
- plugin_options="${plugin_options} ${PORT}"
+ plugin_options="${plugin_options} ${port}"
pppd_write_config ${file} \
--interface="${zone}" \
exit ${EXIT_OK}
}
+
+function __hook_get_port() {
+ local zone="${1}"
+
+ local port
+ for port in $(zone_get_ports "${zone}"); do
+ echo "${port}"
+ return ${EXIT_OK}
+ done
+
+ return ${EXIT_ERROR}
+}
+
+function hook_port_attach() {
+ # Excepting at least two arguments here
+ assert [ $# -ge 2 ]
+
+ local zone="${1}"
+ local port="${2}"
+ shift 2
+
+ # PPPoE can only use one port
+ local ports_num="$(zone_get_ports_num "${zone}")"
+ if [ ${ports_num} -ge 1 ]; then
+ local ports="$(zone_get_ports "${zone}")"
+ error "The pppoe zone hook only supports assigning one port"
+ error " port '${ports}' has already been assigned to zone '${zone}'"
+ return ${EXIT_ERROR}
+ fi
+
+ if ! zone_port_settings_write "${zone}" "${port}"; then
+ exit ${EXIT_ERROR}
+ fi
+
+ exit ${EXIT_OK}
+}
+
+function hook_port_detach() {
+ assert [ $# -eq 2 ]
+
+ local zone="${1}"
+ local port="${2}"
+
+ # Shut down the entire zone here, because it cannot
+ # run without a port any way and removing the port would
+ # create a hotplug event which will be processed after the
+ # port has already been detached...
+ zone_stop "${zone}"
+
+ if ! zone_port_settings_remove "${zone}" "${port}"; then
+ exit ${EXIT_ERROR}
+ fi
+
+ exit ${EXIT_OK}
+}