[PATCHv2] Fix hook for static address configuration.

Message ID 20180811192127.14322-1-stefan.schantl@ipfire.org
State Accepted
Commit b907d1e67e4feddd5a7e36c6a470760381d48f8c
Headers
Series [PATCHv2] Fix hook for static address configuration. |

Commit Message

Stefan Schantl Aug. 12, 2018, 5:21 a.m. UTC
  Add the required hook_new function and "id" information which have been
introduced in earlier commits to make this hook work again.

Signed-off-by: Stefan Schantl <stefan.schantl@ipfire.org>
---
 src/hooks/configs/static | 21 ++++++++++++++++++++-
 1 file changed, 20 insertions(+), 1 deletion(-)
  

Comments

Jonatan Schlag Sept. 15, 2018, 10:20 p.m. UTC | #1
Am Samstag, den 11.08.2018, 21:21 +0200 schrieb Stefan Schantl:
> Add the required hook_new function and "id" information which have
> been
> introduced in earlier commits to make this hook work again.
> 
> Signed-off-by: Stefan Schantl <stefan.schantl@ipfire.org>
> ---
>  src/hooks/configs/static | 21 ++++++++++++++++++++-
>  1 file changed, 20 insertions(+), 1 deletion(-)
> 
> diff --git a/src/hooks/configs/static b/src/hooks/configs/static
> index 91bba8a..23ae2d8 100644
> --- a/src/hooks/configs/static
> +++ b/src/hooks/configs/static
> @@ -52,6 +52,8 @@ hook_check_config_settings() {
>  
>  hook_parse_cmdline() {
>  	local protocol
> +	local id="${1}"
> +	shift
>  
>  	while [ $# -gt 0 ]; do
>  		case "${1}" in
> @@ -153,12 +155,29 @@ hook_parse_cmdline() {
>  	fi
>  
>  	# Check any conflicts
> -	if zone_config_check_same_setting "${zone}" "static"
> "ADDRESS" "${ADDRESS}"; then
> +	if zone_config_check_same_setting "${zone}" "static" "${id}"
> "ADDRESS" "${ADDRESS}"; then
>  		error "A static configuration with the same address
> is already configured"
>  		return ${EXIT_CONF_ERROR}
>  	fi
>  }
>  
> +hook_new() {
> +	local zone="${1}"
> +	shift
> +
> +	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}"
Tested-by: Jonatan Schlag <jonatan.schlag@ipfire.org>
  

Patch

diff --git a/src/hooks/configs/static b/src/hooks/configs/static
index 91bba8a..23ae2d8 100644
--- a/src/hooks/configs/static
+++ b/src/hooks/configs/static
@@ -52,6 +52,8 @@  hook_check_config_settings() {
 
 hook_parse_cmdline() {
 	local protocol
+	local id="${1}"
+	shift
 
 	while [ $# -gt 0 ]; do
 		case "${1}" in
@@ -153,12 +155,29 @@  hook_parse_cmdline() {
 	fi
 
 	# Check any conflicts
-	if zone_config_check_same_setting "${zone}" "static" "ADDRESS" "${ADDRESS}"; then
+	if zone_config_check_same_setting "${zone}" "static" "${id}" "ADDRESS" "${ADDRESS}"; then
 		error "A static configuration with the same address is already configured"
 		return ${EXIT_CONF_ERROR}
 	fi
 }
 
+hook_new() {
+	local zone="${1}"
+	shift
+
+	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}"