]> git.ipfire.org Git - network.git/blobdiff - src/hooks/configs/pppoe-server
Fix zone_config_check_same_setting
[network.git] / src / hooks / configs / pppoe-server
index d952ecc24b9f237b81040658d0af14aaedbe8177..6a2c014c21935a0353e99103a7c5289fd2bf6db6 100644 (file)
@@ -21,7 +21,7 @@
 
 . /usr/lib/network/header-config
 
-HOOK_CONFIG_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
@@ -41,31 +41,82 @@ 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_new() {
-       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}"
+       zone_config_settings_write "${zone}" "${HOOK}" "${id}"
 
        exit ${EXIT_OK}
 }