From patchwork Thu Feb 8 01:53:47 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonatan Schlag X-Patchwork-Id: 1645 Return-Path: Received: from mail01.ipfire.org (unknown [172.28.1.200]) by web02.ipfire.org (Postfix) with ESMTP id A5B6D60993 for ; Wed, 7 Feb 2018 16:05:04 +0100 (CET) Received: from mail01.ipfire.org (localhost [IPv6:::1]) by mail01.ipfire.org (Postfix) with ESMTP id 58C13471D; Wed, 7 Feb 2018 16:05:04 +0100 (CET) Received: from localhost.localdomain (unknown [10.172.1.10]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-SHA256 (128/128 bits)) (Client did not present a certificate) by mail01.ipfire.org (Postfix) with ESMTPSA id 14FF847D6; Wed, 7 Feb 2018 15:53:51 +0100 (CET) From: Jonatan Schlag To: network@lists.ipfire.org Subject: [PATCH v2] Fix zone_config_check_same_setting Date: Wed, 7 Feb 2018 14:53:47 +0000 Message-Id: <1518015227-3539-1-git-send-email-jonatan.schlag@ipfire.org> X-Mailer: git-send-email 2.6.3 X-BeenThere: network@lists.ipfire.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List for the network package List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: network-bounces@lists.ipfire.org Sender: "network" 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 --- 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} }