Every time we edited a config zone_config_check_same_setting returns that a identical config was found but this config was the config we want to edit. So we now generate the id inside hook_new and pass the id always to hook_parse_cmdline and to zone_config_check_same_setting.
So we can skip this config.
Fixes: #11451
Signed-off-by: Jonatan Schlag jonatan.schlag@ipfire.org --- src/functions/functions.zone | 18 +++++++++++------- src/header-config | 8 ++++++-- src/hooks/configs/dhcp | 10 ++++++++-- src/hooks/configs/ipv6-auto | 10 ++++++++-- src/hooks/configs/pppoe-server | 10 ++++++++-- 5 files changed, 41 insertions(+), 15 deletions(-)
diff --git a/src/functions/functions.zone b/src/functions/functions.zone index f724f50..58c0347 100644 --- a/src/functions/functions.zone +++ b/src/functions/functions.zone @@ -1097,22 +1097,29 @@ zone_config_check_same_setting() { # with the same setting is already configured for this zone. # Returns True when yes and False when no.
- assert [ $# -eq 4 ] + assert [ $# -eq 5 ]
local zone=${1} local hook=${2} - local key=${3} - local value=${4} + local id=${3} + local key=${4} + local value=${5}
# The key should be local for this function local ${key} local config
for config in $(zone_configs_list ${zone}); do + # Check if the config is eqal with the config we want to edit, when continue + if [[ "${config}" = "${hook}.${id}" ]]; then + continue + fi + # Check if the config is from the given hook, when not continue if [[ $(zone_config_get_hook "${zone}" "${config}") != ${hook} ]]; then continue fi + # Get the value of the key for a given function zone_config_settings_read "${zone}" "${config}" \ --ignore-superfluous-settings "${key}" @@ -1343,10 +1350,7 @@ zone_config_settings_write() { local hook="${2}" local id=${3}
- if ! isset id; then - id=$(zone_config_get_new_id ${zone}) - log DEBUG "ID for the config is: ${id}" - fi + assert isset id
local args if function_exists "hook_check_config_settings"; then diff --git a/src/header-config b/src/header-config index 141d52b..4458eaa 100644 --- a/src/header-config +++ b/src/header-config @@ -23,8 +23,12 @@ hook_new() { local zone="${1}" shift
+ local id=$(zone_config_get_new_id ${zone}) + log DEBUG "ID for the config is: ${id}" + # Parse command line arguments - if ! hook_parse_cmdline "$@"; then + if ! hook_parse_cmdline "${id}" "$@"; then + # Return an error if the parsing of the cmd line fails return ${EXIT_ERROR} fi
@@ -68,7 +72,7 @@ hook_edit() { return ${EXIT_ERROR} fi
- if ! hook_parse_cmdline "$@"; then + if ! hook_parse_cmdline "${id}" "$@"; then # Return an error if the parsing of the cmd line fails return ${EXIT_ERROR} fi diff --git a/src/hooks/configs/dhcp b/src/hooks/configs/dhcp index f22507c..b643022 100644 --- a/src/hooks/configs/dhcp +++ b/src/hooks/configs/dhcp @@ -35,6 +35,9 @@ hook_check_config_settings() { }
hook_parse_cmdline() { + local id="${1}" + shift + while [ $# -gt 0 ]; do case "${1}" in --enable-ipv6) @@ -72,12 +75,15 @@ hook_new() { return ${EXIT_ERROR} fi
- if ! hook_parse_cmdline "$@"; then + 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} } diff --git a/src/hooks/configs/ipv6-auto b/src/hooks/configs/ipv6-auto index bf1003d..8796723 100644 --- a/src/hooks/configs/ipv6-auto +++ b/src/hooks/configs/ipv6-auto @@ -31,6 +31,9 @@ hook_check_config_settings() { }
hook_parse_cmdline() { + local id="${1}" + shift + local arg
while read arg; do @@ -57,12 +60,15 @@ hook_new() { return ${EXIT_ERROR} fi
- if ! hook_parse_cmdline "$@"; then + 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} } diff --git a/src/hooks/configs/pppoe-server b/src/hooks/configs/pppoe-server index 7021be2..6a2c014 100644 --- a/src/hooks/configs/pppoe-server +++ b/src/hooks/configs/pppoe-server @@ -49,6 +49,9 @@ hook_check_config_settings() { }
hook_parse_cmdline() { + local id="${1}" + shift + while [ $# -gt 0 ]; do case "${1}" in --dns-server=*) @@ -105,12 +108,15 @@ hook_new() { return ${EXIT_ERROR} fi
- if ! hook_parse_cmdline "$@"; then + 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} }