]> git.ipfire.org Git - people/ms/network.git/commitdiff
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 baeca5e3340daa79fab82ecff438b10e63d18c04..c6a775c5ea11fcdd2d3620836233d849083b5d99 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 ba5608a9f644832639b8f7fa5940e1c0fbeaa62a..127ce5915e3cbed2eca6ef44d809dffb65296be7 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 6fd90a538170cbaa74df58e3a46a1277612600da..ecfafcd69b2c7c118003e0f798111616123e0358 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 4d79549b19b33d668aae4936208108f920790775..e800bf4cada97c228d10ae80187101713ea3ef83 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 6fddc320f7f8b05b847ab19a02c2d6cd124b60a4..046183aa56e3e608830e96645b8aada64b4f5ae8 100644 (file)
@@ -21,6 +21,9 @@
 
 . /usr/lib/network/header-config
 
+# Allow multiple instances of this hook
+HOOK_UNIQUE="false"
+
 HOOK_SETTINGS=(
        "ADDRESS"
        "PREFIX"