From 636f1b96fc0b60c47cf5636f95b1ee6c856a701c Mon Sep 17 00:00:00 2001 From: Michael Tremer Date: Sat, 30 Mar 2019 16:54:04 +0100 Subject: [PATCH] hook: Rename HOOK_CONFIG_SETTINGS to HOOK_SETTINGS Signed-off-by: Michael Tremer --- src/functions/functions.zone | 8 ++++---- src/header-config | 5 ++++- src/hooks/configs/dhcp | 13 +++++++++---- src/hooks/configs/ipv6-auto | 15 +++++---------- src/hooks/configs/pppoe-server | 24 +++++++++--------------- src/hooks/configs/static | 6 +++++- 6 files changed, 36 insertions(+), 35 deletions(-) diff --git a/src/functions/functions.zone b/src/functions/functions.zone index e81371b9..28fbecd5 100644 --- a/src/functions/functions.zone +++ b/src/functions/functions.zone @@ -1312,8 +1312,8 @@ zone_config_settings_read() { shift 2 local args - if [ $# -eq 0 ] && [ -n "${HOOK_CONFIG_SETTINGS}" ]; then - list_append args ${HOOK_CONFIG_SETTINGS} + if [ $# -eq 0 ] && [ -n "${HOOK_SETTINGS[*]}" ]; then + list_append args ${HOOK_SETTINGS[*]} else list_append args "$@" fi @@ -1323,7 +1323,7 @@ zone_config_settings_read() { } zone_config_settings_write() { - assert [ $# -eq 2 ] + assert [ $# -eq 3 ] local zone="${1}" local hook="${2}" @@ -1333,7 +1333,7 @@ zone_config_settings_write() { local path="${NETWORK_ZONES_DIR}/${zone}/configs/${hook}.${id}" settings_write "${path}" \ - --check="hook_check_config_settings" ${HOOK_CONFIG_SETTINGS[*]} + --check="hook_check_config_settings" HOOK ${HOOK_SETTINGS[*]} } zone_config_settings_destroy() { diff --git a/src/header-config b/src/header-config index 4458eaa9..baeca5e3 100644 --- a/src/header-config +++ b/src/header-config @@ -26,6 +26,9 @@ hook_new() { local id=$(zone_config_get_new_id ${zone}) log DEBUG "ID for the config is: ${id}" + # Import all default variables + hook_set_defaults + # Parse command line arguments if ! hook_parse_cmdline "${id}" "$@"; then # Return an error if the parsing of the cmd line fails @@ -64,7 +67,7 @@ hook_edit() { fi fi - local ${HOOK_CONFIG_SETTINGS} + local ${HOOK_SETTINGS} # If reading the config fails we cannot go on if ! zone_config_settings_read "${zone}" "${config}"; then diff --git a/src/hooks/configs/dhcp b/src/hooks/configs/dhcp index b643022a..1ad06947 100644 --- a/src/hooks/configs/dhcp +++ b/src/hooks/configs/dhcp @@ -21,11 +21,13 @@ . /usr/lib/network/header-config -HOOK_CONFIG_SETTINGS="HOOK ENABLE_IPV6 ENABLE_IPV4" +HOOK_SETTINGS=( + "ENABLE_IPV6" + "ENABLE_IPV4" +) -# Default settings. -ENABLE_IPV6="on" -ENABLE_IPV4="on" +DEFAULT_ENABLE_IPV6="on" +DEFAULT_ENABLE_IPV4="on" hook_check_config_settings() { assert isset ENABLE_IPV6 @@ -78,6 +80,9 @@ hook_new() { 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} diff --git a/src/hooks/configs/ipv6-auto b/src/hooks/configs/ipv6-auto index 8796723e..6fd90a53 100644 --- a/src/hooks/configs/ipv6-auto +++ b/src/hooks/configs/ipv6-auto @@ -21,10 +21,12 @@ . /usr/lib/network/header-config -HOOK_CONFIG_SETTINGS="HOOK PRIVACY_EXTENSIONS" +HOOK_SETTINGS=( + "PRIVACY_EXTENSIONS" +) # Privacy Extensions are disabled by default -PRIVACY_EXTENSIONS="off" +DEFAULT_PRIVACY_EXTENSIONS="off" hook_check_config_settings() { assert isbool PRIVACY_EXTENSIONS @@ -35,17 +37,10 @@ hook_parse_cmdline() { shift local arg - while read arg; do case "${arg}" in --privacy-extensions=*) - local val="$(cli_get_val "${arg}")" - - if enabled val; then - PRIVACY_EXTENSIONS="on" - else - PRIVACY_EXTENSIONS="off" - fi + PRIVACY_EXTENSIONS="$(cli_get_bool "${arg}")" ;; esac done <<< "$(args "$@")" diff --git a/src/hooks/configs/pppoe-server b/src/hooks/configs/pppoe-server index 6a2c014c..4d79549b 100644 --- a/src/hooks/configs/pppoe-server +++ b/src/hooks/configs/pppoe-server @@ -21,21 +21,15 @@ . /usr/lib/network/header-config -HOOK_CONFIG_SETTINGS="HOOK DNS_SERVERS MTU SERVICE_NAME SUBNET MAX_SESSIONS" - -# Maximum Transmission Unit. -MTU=1492 - -# Service Name. -SERVICE_NAME= - -# A subnet. Addresses from this subnet will be given to the remote hosts. -# The net address will be the gateway address for the PPPoE server. -SUBNET= - -# Defines the max. number of sessions per MAC address. -# 0 = unlimited. -MAX_SESSIONS=0 +HOOK_SETTINGS=( + "DNS_SERVERS" + "MTU" + "SERVICE_NAME" + "SUBNET MAX_SESSIONS" +) + +DEFAULT_MTU=1492 +DEFAULT_MAX_SESSIONS=0 hook_check_config_settings() { assert isset MTU diff --git a/src/hooks/configs/static b/src/hooks/configs/static index 23ae2d89..6fddc320 100644 --- a/src/hooks/configs/static +++ b/src/hooks/configs/static @@ -21,7 +21,11 @@ . /usr/lib/network/header-config -HOOK_CONFIG_SETTINGS="HOOK ADDRESS PREFIX GATEWAY" +HOOK_SETTINGS=( + "ADDRESS" + "PREFIX" + "GATEWAY" +) hook_check_config_settings() { local protocol="$(ip_detect_protocol "${ADDRESS}")" -- 2.47.2