From: Michael Tremer Date: Sat, 30 Mar 2019 16:05:58 +0000 (+0100) Subject: hooks: Add HOOK_UNIQUE which stops us from creating multiple instances X-Git-Url: http://git.ipfire.org/?p=people%2Fms%2Fnetwork.git;a=commitdiff_plain;h=fdd9ac5fdd66b6cbdf014554281a9bb11ed0379d hooks: Add HOOK_UNIQUE which stops us from creating multiple instances Signed-off-by: Michael Tremer --- diff --git a/src/header-config b/src/header-config index baeca5e3..c6a775c5 100644 --- a/src/header-config +++ b/src/header-config @@ -19,10 +19,19 @@ # # ############################################################################### +# 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}" diff --git a/src/hooks/configs/dhcp b/src/hooks/configs/dhcp index ba5608a9..127ce591 100644 --- a/src/hooks/configs/dhcp +++ b/src/hooks/configs/dhcp @@ -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} diff --git a/src/hooks/configs/ipv6-auto b/src/hooks/configs/ipv6-auto index 6fd90a53..ecfafcd6 100644 --- a/src/hooks/configs/ipv6-auto +++ b/src/hooks/configs/ipv6-auto @@ -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 diff --git a/src/hooks/configs/pppoe-server b/src/hooks/configs/pppoe-server index 4d79549b..e800bf4c 100644 --- a/src/hooks/configs/pppoe-server +++ b/src/hooks/configs/pppoe-server @@ -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} diff --git a/src/hooks/configs/static b/src/hooks/configs/static index 6fddc320..046183aa 100644 --- a/src/hooks/configs/static +++ b/src/hooks/configs/static @@ -21,6 +21,9 @@ . /usr/lib/network/header-config +# Allow multiple instances of this hook +HOOK_UNIQUE="false" + HOOK_SETTINGS=( "ADDRESS" "PREFIX"