]> 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 84148ddd1e71bcd557c3ba1c0b301b5e3b1e9289..4d79549b19b33d668aae4936208108f920790775 100644 (file)
 
 . /usr/lib/network/header-config
 
-HOOK_SETTINGS="HOOK MTU SERVICE_NAME SUBNET MAX_SESSIONS"
+HOOK_SETTINGS=(
+       "DNS_SERVERS"
+       "MTU"
+       "SERVICE_NAME"
+       "SUBNET MAX_SESSIONS"
+)
 
-# Maximum Transmission Unit.
-MTU=1492
+DEFAULT_MTU=1492
+DEFAULT_MAX_SESSIONS=0
 
-# 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
-
-hook_check() {
+hook_check_config_settings() {
        assert isset MTU
        assert isset SUBNET
        assert isset MAX_SESSIONS
+
+       local server
+       for server in ${DNS_SERVERS}; do
+               assert ipv4_is_valid "${server}"
+       done
 }
 
-hook_create() {
-       local zone=${1}
+hook_parse_cmdline() {
+       local id="${1}"
        shift
 
        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
+}
+
+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}" ${HOOK_SETTINGS}
+       zone_config_settings_write "${zone}" "${HOOK}" "${id}"
 
        exit ${EXIT_OK}
 }
@@ -107,7 +152,7 @@ hook_status() {
                exit ${EXIT_ERROR}
        fi
 
-       zone_config_settings_read "${zone}" "${config}" ${HOOK_SETTINGS}
+       zone_config_settings_read "${zone}" "${config}"
 
        local status
        if pppoe_server_status ${zone}; then