. /usr/lib/network/header-config
-HOOK_SETTINGS="HOOK MTU SERVICE_NAME SUBNET MAX_SESSIONS"
+HOOK_CONFIG_SETTINGS="HOOK DNS_SERVERS MTU SERVICE_NAME SUBNET MAX_SESSIONS"
# Maximum Transmission Unit.
MTU=1492
# 0 = unlimited.
MAX_SESSIONS=0
-function hook_check() {
+hook_check_config_settings() {
assert isset MTU
assert isset SUBNET
assert isset MAX_SESSIONS
-}
-function hook_create() {
- local zone=${1}
- shift
+ local server
+ for server in ${DNS_SERVERS}; do
+ assert ipv4_is_valid "${server}"
+ done
+}
+hook_parse_cmdline() {
while [ $# -gt 0 ]; do
case "${1}" in
+ --dns-server=*)
+ local dns_servers="$(cli_get_val "${1}")"
+
+ local dns_server
+ for dns_server in ${dns_servers}; do
+ if ! ipv4_is_valid "${dns_server}"; then
+ warning "Invalid IPv4 address: ${dns_server}. Skipped."
+ continue
+ fi
+
+ list_append DNS_SERVERS "${dns_server}"
+ done
+ ;;
--max-sessions=*)
- MAX_SESSIONS=$(cli_get_val ${1})
+ MAX_SESSIONS=$(cli_get_val "${1}")
+ if ! isinteger ${MAX_SESSIONS} || ! [ ${MAX_SESSIONS} -ge 0 ]; then
+ error "Invalid value for '--max-session'. This value must be an integer greate or eqal zero."
+ exit ${EXIT_ERROR}
+ fi
;;
--mtu=*)
- MTU=$(cli_get_val ${1})
+ MTU=$(cli_get_val "${1}")
+ if ! mtu_is_valid "ipv4" ${MTU}; then
+ error "Invalid value for '--mtu'. Cannot be larger then 9000 or smaller than 576"
+ exit ${EXIT_ERROR}
+ fi
;;
--service-name=*)
- SERVICE_NAME=$(cli_get_val ${1})
+ SERVICE_NAME=$(cli_get_val "${1}")
;;
--subnet=*)
- SUBNET=$(cli_get_val ${1})
+ SUBNET=$(cli_get_val "${1}")
+ if ! ipv4_net_is_valid "${SUBNET}"; then
+ error "Invalid IPv4 Subnet ${SUBNET}."
+ exit ${EXIT_ERROR}
+ fi
+ ;;
+ *)
+ warning "Ignoring unknown option '${1}'"
;;
esac
shift
done
+}
- config_write $(zone_dir ${zone})/configs/${HOOK} ${HOOK_SETTINGS}
+hook_new() {
+ local zone=${1}
+ shift
+
+ if zone_config_hook_is_configured ${zone} "pppoe-server"; then
+ log ERROR "You can configure the pppoe-server hook only once for a zone"
+ return ${EXIT_ERROR}
+ fi
+
+ if ! hook_parse_cmdline "$@"; then
+ # Return an error if the parsing of the cmd line fails
+ return ${EXIT_ERROR}
+ fi
+
+ zone_config_settings_write "${zone}" "${HOOK}"
exit ${EXIT_OK}
}
-function hook_up() {
+hook_up() {
local zone=${1}
local config=${2}
shift 2
exit ${EXIT_OK}
}
-function hook_down() {
+hook_down() {
local zone=${1}
local config=${2}
shift 2
exit ${EXIT_OK}
}
-function hook_status() {
+hook_status() {
local zone=${1}
local config=${2}
shift 2
error "Zone '${zone}' doesn't exist."
exit ${EXIT_ERROR}
fi
-
- config_read $(zone_dir ${zone})/configs/${config}
+
+ zone_config_settings_read "${zone}" "${config}"
local status
if pppoe_server_status ${zone}; then