]> git.ipfire.org Git - people/stevee/network.git/blobdiff - src/hooks/configs/pppoe-server
hook: Rename HOOK_CONFIG_SETTINGS to HOOK_SETTINGS
[people/stevee/network.git] / src / hooks / configs / pppoe-server
index 1ef3ba9c5208ecbef1a262a9bdfa7be57546ea0c..4d79549b19b33d668aae4936208108f920790775 100644 (file)
 
 . /usr/lib/network/header-config
 
-HOOK_CONFIG_SETTINGS="HOOK DNS_SERVERS MTU SERVICE_NAME SUBNET MAX_SESSIONS"
+HOOK_SETTINGS=(
+       "DNS_SERVERS"
+       "MTU"
+       "SERVICE_NAME"
+       "SUBNET MAX_SESSIONS"
+)
 
-# Maximum Transmission Unit.
-MTU=1492
-
-# Service Name.
-SERVICE_NAME=
-
-# A subnet. Addresses from this subnet will be given to the remote hosts.
-# The net address will be the gateway address for the PPPoE server.
-SUBNET=
-
-# Defines the max. number of sessions per MAC address.
-# 0 = unlimited.
-MAX_SESSIONS=0
+DEFAULT_MTU=1492
+DEFAULT_MAX_SESSIONS=0
 
 hook_check_config_settings() {
        assert isset MTU
@@ -48,8 +42,8 @@ hook_check_config_settings() {
        done
 }
 
-hook_new() {
-       local zone=${1}
+hook_parse_cmdline() {
+       local id="${1}"
        shift
 
        while [ $# -gt 0 ]; do
@@ -68,22 +62,55 @@ hook_new() {
                                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
+}
+
+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
+
+       local id=$(zone_config_get_new_id ${zone})
+       log DEBUG "ID for the config is: ${id}"
+
+       if ! hook_parse_cmdline "${id}" "$@"; then
+               # Return an error if the parsing of the cmd line fails
+               return ${EXIT_ERROR}
+       fi
 
-       zone_config_settings_write "${zone}" "${HOOK}"
+       zone_config_settings_write "${zone}" "${HOOK}" "${id}"
 
        exit ${EXIT_OK}
 }