. /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=""
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}")"
;;
zone_config_read ${zone}
# Bring up the port.
- log DEBUG "Bringing up port '${PORT}'."
- port_up ${PORT}
+ local port=$(__hook_get_port "${zone}")
+ port_up "${port}"
# Start the ppp daemon.
pppd_start ${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
# Read in the configuration files.
zone_config_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_add() {
+ # 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 port=$(__hook_get_port "${zone}")
+ error "The pppoe zone hook only supports assigning one port"
+ error " port '${port}' has already been assigned to zone '${zone}'"
+ return ${EXIT_ERROR}
+ fi
+
+ config_write "$(zone_dir "${zone}")/ports/${port}"
+ log INFO "Port '${port}' has been added to zone '${zone}'"
+
+ exit ${EXIT_OK}
+}
+
+function hook_port_remove() {
+ assert [ $# -eq 2 ]
+
+ local zone="${1}"
+ local port="${2}"
+
+ # Shut down the port (if possible)
+ port_down "${port}"
+
+ log INFO "Port '${port}' has been removed from zone '${zone}'"
+ config_remove "$(zone_dir "${zone}")/ports/${port}"
+
+ exit ${EXIT_OK}
+}