]> git.ipfire.org Git - people/ms/network.git/blobdiff - src/hooks/configs/dhcp
hooks: Add HOOK_UNIQUE which stops us from creating multiple instances
[people/ms/network.git] / src / hooks / configs / dhcp
index 5ac01b6fd8e9a9e6906f8ee685f7a3939b6c0ebb..127ce5915e3cbed2eca6ef44d809dffb65296be7 100644 (file)
 
 . /usr/lib/network/header-config
 
-HOOK_CONFIG_SETTINGS="HOOK DELAY ENABLE_IPV6 ENABLE_IPV4"
+HOOK_SETTINGS=(
+       "IPV6"
+       "IPV4"
+)
 
-# Default settings.
-DELAY=0
-ENABLE_IPV6="on"
-ENABLE_IPV4="on"
+DEFAULT_IPV6="on"
+DEFAULT_IPV4="on"
 
 hook_check_config_settings() {
-       assert isset DELAY
-       assert isinteger DELAY
-       assert isset ENABLE_IPV6
-       assert isbool ENABLE_IPV6
-       assert isset ENABLE_IPV4
-       assert isbool ENABLE_IPV4
+       assert isbool IPV6
+       assert isbool IPV4
 }
 
 hook_parse_cmdline() {
+       local id="${1}"
+       shift
+
        while [ $# -gt 0 ]; do
                case "${1}" in
-                       --delay=*)
-                               DELAY="$(cli_get_val "${1}")"
-                               ;;
-                       --enable-ipv6)
-                               ENABLE_IPV6="on"
-                               ;;
-                       --disable-ipv6)
-                               ENABLE_IPV6="off"
-                               ;;
-                       --enable-ipv4)
-                               ENABLE_IPV4="on"
+                       --ipv6=*)
+                               IPV6="$(cli_get_bool "${1}")"
                                ;;
-                       --disable-ipv4)
-                               ENABLE_IPV4="off"
+                       --ipv4=*)
+                               IPV4="$(cli_get_bool "${1}")"
                                ;;
                        *)
                                warning "Ignoring unknown option '${1}'"
@@ -61,32 +52,12 @@ hook_parse_cmdline() {
                esac
                shift
        done
-}
-
-hook_new() {
-       local zone="${1}"
-       shift
-
-       if zone_config_hook_is_configured ${zone} "dhcp"; then
-               log ERROR "You can configure the dhcp 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
+       # Check if the user disabled ipv6 and ipv4
+       if ! enabled IPV6 && ! enabled IPV4; then
+               error "You disabled IPv6 and IPv4. At least one must be enabled"
                return ${EXIT_ERROR}
        fi
-
-       # Check if the user disabled ipv4 and ipv6
-
-       if ! enabled ENABLE_IPV6 && ! enabled ENABLE_IPV4; then
-               log ERROR "You disabled IPv6 and IPv4. At least one must be enabled"
-               return ${EXIT_ERROR}
-       fi
-
-       zone_config_settings_write "${zone}" "${HOOK}"
-
-       exit ${EXIT_OK}
 }
 
 hook_up() {
@@ -102,12 +73,12 @@ hook_up() {
        zone_config_settings_read "${zone}" "${config}"
 
        # Start dhclient for IPv6 on this zone if enabled.
-       if enabled ENABLE_IPV6; then
+       if enabled IPV6; then
                dhclient_start ${zone} ipv6
        fi
 
        # Start dhclient for IPv4 on this zone if enabled.
-       if enabled ENABLE_IPV4; then
+       if enabled IPV4; then
                dhclient_start ${zone} ipv4
        fi
 
@@ -161,7 +132,7 @@ hook_status() {
 
                cli_print_fmt1 3 "${proto}"
 
-               if enabled ENABLE_${proto^^}; then
+               if enabled "${proto^^}"; then
                        cli_print_fmt1 4 "Status" "enabled"
 
                        local address="$(db_get "${zone}/${_proto}/local-ip-address")"