hooks: Add HOOK_UNIQUE which stops us from creating multiple instances
authorMichael Tremer <michael.tremer@ipfire.org>
Sat, 30 Mar 2019 16:05:58 +0000 (17:05 +0100)
committerMichael Tremer <michael.tremer@ipfire.org>
Sat, 30 Mar 2019 16:05:58 +0000 (17:05 +0100)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/header-config
src/hooks/configs/dhcp
src/hooks/configs/ipv6-auto
src/hooks/configs/pppoe-server
src/hooks/configs/static

index baeca5e..c6a775c 100644 (file)
 #                                                                             #
 ###############################################################################
 
+# Allow only one instance of this hook
+HOOK_UNIQUE="true"
+
 hook_new() {
        local zone="${1}"
        shift
 
+       # Check if we are allowed to have multiple configurations of $HOOK
+       if enabled HOOK_UNIQUE && zone_config_hook_is_configured "${zone}" "${HOOK}"; then
+               error "You can only have one configuration of type ${HOOK}"
+               return ${EXIT_CONF_ERROR}
+       fi
+
        local id=$(zone_config_get_new_id ${zone})
        log DEBUG "ID for the config is: ${id}"
 
index ba5608a..127ce59 100644 (file)
@@ -60,31 +60,6 @@ hook_parse_cmdline() {
        fi
 }
 
-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
-
-       local id=$(zone_config_get_new_id ${zone})
-       log DEBUG "ID for the config is: ${id}"
-
-       # Import defaults
-       hook_set_defaults
-
-       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}" "${id}"
-
-       exit ${EXIT_OK}
-}
-
 hook_up() {
        local zone=${1}
        local config=${2}
index 6fd90a5..ecfafcd 100644 (file)
@@ -46,28 +46,6 @@ hook_parse_cmdline() {
        done <<< "$(args "$@")"
 }
 
-hook_new() {
-       local zone="${1}"
-       shift
-
-       if zone_config_hook_is_configured ${zone} "ipv6-auto"; then
-               log ERROR "You can configure the ipv6-auto 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}" "${id}"
-
-       exit ${EXIT_OK}
-}
-
 hook_up() {
        local zone=${1}
        shift
index 4d79549..e800bf4 100644 (file)
@@ -93,28 +93,6 @@ hook_parse_cmdline() {
        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}" "${id}"
-
-       exit ${EXIT_OK}
-}
-
 hook_up() {
        local zone=${1}
        local config=${2}
index 6fddc32..046183a 100644 (file)
@@ -21,6 +21,9 @@
 
 . /usr/lib/network/header-config
 
+# Allow multiple instances of this hook
+HOOK_UNIQUE="false"
+
 HOOK_SETTINGS=(
        "ADDRESS"
        "PREFIX"