Convert HOOK_SETTINGS into an array
authorMichael Tremer <michael.tremer@ipfire.org>
Sat, 30 Mar 2019 12:49:08 +0000 (13:49 +0100)
committerMichael Tremer <michael.tremer@ipfire.org>
Sat, 30 Mar 2019 12:49:08 +0000 (13:49 +0100)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
17 files changed:
src/functions/functions.hook
src/functions/functions.ports
src/functions/functions.zone
src/header-port
src/header-zone
src/hooks/ports/bonding
src/hooks/ports/dummy
src/hooks/ports/ethernet
src/hooks/ports/ip-tunnel
src/hooks/ports/vlan
src/hooks/ports/wireless-ap
src/hooks/ports/wireless-mesh
src/hooks/zones/bridge
src/hooks/zones/ip-tunnel
src/hooks/zones/modem
src/hooks/zones/pppoe
src/hooks/zones/wireless

index c0ebfcb..fb68037 100644 (file)
@@ -127,7 +127,7 @@ hook_help() {
 # Sets all settings in HOOK_SETTINGS to their DEFAULT_* values
 hook_set_defaults() {
        local setting
-       for setting in ${HOOK_SETTINGS}; do
+       for setting in ${HOOK_SETTINGS[*]}; do
                local default="DEFAULT_${setting}"
 
                # Sets the default or empty
index f70adf6..fb22715 100644 (file)
@@ -85,7 +85,7 @@ port_settings_read() {
        # Save the HOOK variable.
        local hook="${HOOK}"
 
-       settings_read "$(port_file "${port}")" ${HOOK_SETTINGS}
+       settings_read "$(port_file "${port}")" ${HOOK_SETTINGS[*]}
 
        # Restore hook.
        HOOK="${hook}"
@@ -100,7 +100,7 @@ port_settings_write() {
        if function_exists "hook_check_settings"; then
                list_append args "--check=\"hook_check_settings\""
        fi
-       list_append args HOOK ${HOOK_SETTINGS}
+       list_append args HOOK ${HOOK_SETTINGS[*]}
 
        settings_write "$(port_file "${port}")" ${args}
 }
index 57e0b71..a0d3cfb 100644 (file)
@@ -1248,8 +1248,8 @@ zone_settings_read() {
        shift
 
        local args
-       if [ $# -eq 0 ] && [ -n "${HOOK_SETTINGS}" ]; then
-               list_append args ${HOOK_SETTINGS}
+       if [ $# -eq 0 ] && [ -n "${HOOK_SETTINGS[*]}" ]; then
+               list_append args ${HOOK_SETTINGS[*]}
        else
                list_append args "$@"
        fi
@@ -1271,7 +1271,7 @@ zone_settings_write() {
        if function_exists "hook_check_settings"; then
                list_append args "--check=\"hook_check_settings\""
        fi
-       list_append args ${HOOK_SETTINGS}
+       list_append args HOOK ${HOOK_SETTINGS[*]}
 
        settings_write "${NETWORK_ZONES_DIR}/${zone}/settings" ${args}
 }
index 141228a..2d8a820 100644 (file)
@@ -43,7 +43,7 @@ hook_hotplug_rename() {
 }
 
 hook_default_new() {
-       local ${HOOK_SETTINGS}
+       local ${HOOK_SETTINGS[*]}
 
        # Import all default variables
        hook_set_defaults
@@ -57,7 +57,7 @@ hook_default_new() {
        local port=$(port_find_free ${HOOK_PORT_PATTERN})
        assert isset port
 
-       port_settings_write "${port}" ${HOOK_SETTINGS}
+       port_settings_write "${port}" ${HOOK_SETTINGS[*]}
 
        exit ${EXIT_OK}
 }
@@ -72,7 +72,7 @@ hook_default_edit() {
        shift
 
        # Read settings
-       if ! port_settings_read "${port}" ${HOOK_SETTINGS}; then
+       if ! port_settings_read "${port}" ${HOOK_SETTINGS[*]}; then
                error "Could not read settings for port ${port}"
                return ${EXIT_ERROR}
        fi
@@ -83,7 +83,7 @@ hook_default_edit() {
        fi
 
        # Save settings
-       if ! port_settings_write "${port}" ${HOOK_SETTINGS}; then
+       if ! port_settings_write "${port}" ${HOOK_SETTINGS[*]}; then
                error "Could not write settings for port ${port}"
                return ${EXIT_ERROR}
        fi
@@ -102,7 +102,7 @@ hook_edit() {
 hook_children() {
        local port="${1}"
 
-       if ! port_settings_read "${port}" ${HOOK_SETTINGS}; then
+       if ! port_settings_read "${port}" ${HOOK_SETTINGS[*]}; then
                log ERROR "Could not read port settings: ${port}"
                return ${EXIT_OK}
        fi
index 7ad3e39..2174b01 100644 (file)
@@ -34,7 +34,7 @@ hook_new() {
        assert isset zone
        shift
 
-       local ${HOOK_SETTINGS}
+       local ${HOOK_SETTINGS[*]}
 
        # Import all default variables
        hook_set_defaults
index f0572c3..09fb74f 100644 (file)
 
 . /usr/lib/network/header-port
 
-HOOK_SETTINGS="ADDRESS MIIMON MODE OFFLOADING SLAVES"
+HOOK_SETTINGS=(
+       "ADDRESS"
+       "MIIMON"
+       "MODE"
+       "OFFLOADING"
+       "SLAVES"
+)
 
 DEFAULT_MIIMON=100
 DEFAULT_MODE="balance-rr"
@@ -110,7 +116,7 @@ hook_new() {
        assert isset port
 
        # Save configuration
-       if port_settings_write "${port}" ${HOOK_SETTINGS}; then
+       if port_settings_write "${port}" ${HOOK_SETTINGS[*]}; then
                log INFO "New port ${port} has been created"
        else
                error "Could not save configuration for ${port}"
@@ -162,7 +168,7 @@ hook_create() {
        # Exit silently if the device already exists
        device_exists "${port}" && exit ${EXIT_OK}
 
-       port_settings_read "${port}" ${HOOK_SETTINGS}
+       port_settings_read "${port}" ${HOOK_SETTINGS[*]}
 
        # Create the bonding devices
        bonding_create "${port}" \
@@ -178,7 +184,7 @@ hook_remove() {
        local port="${1}"
        assert isset port
 
-       port_settings_read "${port}" ${HOOK_SETTINGS}
+       port_settings_read "${port}" ${HOOK_SETTINGS[*]}
 
        # Remove the bonding device
        if device_exists "${port}"; then
@@ -190,7 +196,7 @@ hook_up() {
        local port="${1}"
        assert isset port
 
-       port_settings_read "${port}" ${HOOK_SETTINGS}
+       port_settings_read "${port}" ${HOOK_SETTINGS[*]}
 
        # Auto-enable or disable hardware offloading
        if ! isset OFFLOADING || enabled OFFLOADING; then
@@ -213,7 +219,7 @@ hook_down() {
        local port="${1}"
        assert isset port
 
-       port_settings_read "${port}" ${HOOK_SETTINGS}
+       port_settings_read "${port}" ${HOOK_SETTINGS[*]}
 
        # Bring down all slaves
        local slave
@@ -234,7 +240,7 @@ hook_hotplug() {
                        # Handle events of the same interface
                        if hotplug_event_port_is_interface "${port}"; then
                                # Read configuration
-                               port_settings_read "${port}" ${HOOK_SETTINGS}
+                               port_settings_read "${port}" ${HOOK_SETTINGS[*]}
 
                                # Bring up all slaves
                                # Attach those which already exist and try to create
index 61d2f94..1c4b3c9 100644 (file)
@@ -21,7 +21,9 @@
 
 . /usr/lib/network/header-port
 
-HOOK_SETTINGS="ADDRESS"
+HOOK_SETTINGS=(
+       "ADDRESS"
+)
 
 hook_check_settings() {
        assert ismac ADDRESS
@@ -60,7 +62,7 @@ hook_new() {
        local port=$(port_find_free ${DUMMY_PORT_PATTERN})
        assert isset port
 
-       if port_settings_write "${port}" ${HOOK_SETTINGS}; then
+       if port_settings_write "${port}" ${HOOK_SETTINGS[*]}; then
                log INFO "New dummy port '${port}' has been created"
        fi
 
@@ -72,7 +74,7 @@ hook_create() {
        assert isset port
 
        # Read configuration
-       port_settings_read "${port}" ${HOOK_SETTINGS}
+       port_settings_read "${port}" ${HOOK_SETTINGS[*]}
 
        # Create the dummy device
        dummy_create "${port}" "${ADDRESS}"
@@ -115,7 +117,7 @@ hook_hotplug_rename() {
        local device=${2}
        assert isset device
 
-       port_settings_read "${port}" ${HOOK_SETTINGS}
+       port_settings_read "${port}" ${HOOK_SETTINGS[*]}
 
        if [ "${ADDRESS}" = "$(device_get_address ${device})" ]; then
                log DEBUG "Device '${device}' equals port '${port}'."
index 0d9c5cd..f3e3f9f 100644 (file)
 
 . /usr/lib/network/header-port
 
-# DEVICE equals the actual MAC address of the device.
-# If ADDRESS is set, the device will get ADDRESS set for its MAC address.
-
-HOOK_SETTINGS="ADDRESS ADVERTISED_LINK_SPEEDS DEVICE OFFLOADING MTU"
+HOOK_SETTINGS=(
+       "ADDRESS"
+       "ADVERTISED_LINK_SPEEDS"
+       "DEVICE"
+       "OFFLOADING"
+       "MTU"
+)
 
 hook_check_settings() {
        assert ismac DEVICE
@@ -114,7 +117,7 @@ hook_new() {
 
        local DEVICE="$(device_get_address "${device}")"
 
-       if ! port_settings_write "${port}" ${HOOK_SETTINGS}; then
+       if ! port_settings_write "${port}" ${HOOK_SETTINGS[*]}; then
                log ERROR "Could not write settings for port ${port}"
                return ${EXIT_ERROR}
        fi
@@ -129,8 +132,8 @@ hook_create() {
 hook_up() {
        local port="${1}"
 
-       local ${HOOK_SETTINGS}
-       if ! port_settings_read "${port}" ${HOOK_SETTINGS}; then
+       local ${HOOK_SETTINGS[*]}
+       if ! port_settings_read "${port}" ${HOOK_SETTINGS[*]}; then
                log ERROR "Could not read settings for port ${port}"
                return ${EXIT_ERROR}
        fi
@@ -177,7 +180,7 @@ hook_hotplug_rename() {
        assert isset device
 
        # Read in the conifguration file.
-       port_settings_read "${port}" ${HOOK_SETTINGS}
+       port_settings_read "${port}" ${HOOK_SETTINGS[*]}
 
        # Get the current MAC address of the device.
        local address=$(device_get_address ${device})
index 3943e4c..b426963 100644 (file)
 
 SUPPORTED_IP_TUNNEL_MODES="gretap"
 
-HOOK_SETTINGS="ADDRESS MARK MODE PEER LOCAL_ADDRESS"
+HOOK_SETTINGS=(
+       "ADDRESS"
+       "MARK"
+       "MODE"
+       "PEER"
+       "LOCAL_ADDRESS"
+)
 
 hook_check_settings() {
        assert isset MODE
@@ -108,8 +114,8 @@ hook_create() {
        local port="${1}"
        assert isset port
 
-       local ${HOOK_SETTINGS}
-       if ! port_settings_read "${port}" ${HOOK_SETTINGS}; then
+       local ${HOOK_SETTINGS[*]}
+       if ! port_settings_read "${port}" ${HOOK_SETTINGS[*]}; then
                log ERROR "Could not read settings for port ${port}"
                return ${EXIT_ERROR}
        fi
@@ -146,8 +152,8 @@ hook_hotplug_rename() {
        local device="${2}"
        assert isset device
 
-       local ${HOOK_SETTINGS}
-       if ! port_settings_read "${port}" ${HOOK_SETTINGS}; then
+       local ${HOOK_SETTINGS[*]}
+       if ! port_settings_read "${port}" ${HOOK_SETTINGS[*]}; then
                log ERROR "Could not read settings for port ${port}"
                return ${EXIT_ERROR}
        fi
index bc12a9e..e9aa545 100644 (file)
 
 . /usr/lib/network/header-port
 
-HOOK_SETTINGS="ADDRESS PARENT_DEVICE TAG"
+HOOK_SETTINGS=(
+       "ADDRESS"
+       "PARENT_DEVICE"
+       "TAG"
+)
 
 PORT_PARENTS_VAR="PARENT"
 
@@ -68,7 +72,7 @@ hook_new() {
 
        local port="${PARENT_DEVICE}${VLAN_PORT_INTERFIX}${TAG}"
 
-       port_settings_write "${port}" ${HOOK_SETTINGS}
+       port_settings_write "${port}" ${HOOK_SETTINGS[*]}
 
        exit ${EXIT_OK}
 }
@@ -78,7 +82,7 @@ hook_edit() {
        assert isset port
        shift
 
-       port_settings_read "${port}" ${HOOK_SETTINGS}
+       port_settings_read "${port}" ${HOOK_SETTINGS[*]}
 
        while [ $# -gt 0 ]; do
                case "${1}" in
@@ -92,7 +96,7 @@ hook_edit() {
                shift
        done
 
-       port_settings_write "${port}" ${HOOK_SETTINGS}
+       port_settings_write "${port}" ${HOOK_SETTINGS[*]}
 
        exit ${EXIT_OK} 
 }
@@ -104,7 +108,7 @@ hook_create() {
        device_exists "${port}" && exit ${EXIT_OK}
 
        # Read configruation
-       port_settings_read "${port}" ${HOOK_SETTINGS}
+       port_settings_read "${port}" ${HOOK_SETTINGS[*]}
 
        # Create the VLAN device
        vlan_create "${port}" "${PARENT_DEVICE}" "${TAG}" "${ADDRESS}"
index 2bb4977..8d495d2 100644 (file)
 
 HOOK_PORT_PATTERN="${PORT_PATTERN_ACCESSPOINT}"
 
-HOOK_SETTINGS="ADDRESS BROADCAST_SSID CHANNEL CHANNEL_BANDWIDTH DFS MODE PHY"
-HOOK_SETTINGS="${HOOK_SETTINGS} ENCRYPTION ENVIRONMENT KEY SSID"
-HOOK_SETTINGS="${HOOK_SETTINGS} MFP"
+HOOK_SETTINGS=(
+       "ADDRESS"
+       "BROADCAST_SSID"
+       "CHANNEL"
+       "CHANNEL_BANDWIDTH"
+       "DFS"
+       "ENCRYPTION"
+       "ENVIRONMENT"
+       "KEY"
+       "MFP"
+       "MODE"
+       "PHY"
+       "SSID"
+)
 
 # Broadcast SSID by default
 DEFAULT_BROADCAST_SSID="on"
@@ -186,7 +197,7 @@ hook_create() {
 
        device_exists "${port}" && exit ${EXIT_OK}
 
-       port_settings_read "${port}" ${HOOK_SETTINGS}
+       port_settings_read "${port}" ${HOOK_SETTINGS[*]}
 
        # Check if the PHY is present.
        local phy=$(phy_get ${PHY})
index 4fb4dc9..306263d 100644 (file)
 
 HOOK_PORT_PATTERN="${PORT_PATTERN_MESH}"
 
-HOOK_SETTINGS="ADDRESS MESH_ID CHANNEL PHY PSK"
+HOOK_SETTINGS=(
+       "ADDRESS"
+       "CHANNEL"
+       "MESH_ID"
+       "PHY"
+       "PSK"
+)
 
 hook_check_settings() {
        assert ismac ADDRESS
@@ -84,7 +90,7 @@ hook_create() {
        assert isset port
 
        # Read settings
-       port_settings_read "${port}" ${HOOK_SETTINGS}
+       port_settings_read "${port}" ${HOOK_SETTINGS[*]}
 
        # Check if the PHY is present.
        local phy="$(phy_get "${PHY}")"
@@ -143,7 +149,7 @@ hook_hotplug() {
        local port="${1}"
        assert isset port
 
-       port_settings_read "${port}" ${HOOK_SETTINGS}
+       port_settings_read "${port}" ${HOOK_SETTINGS[*]}
 
        case "$(hotplug_action)" in
                add)
index 33d5811..0b18331 100644 (file)
 
 HOOK_MANPAGE="network-zone-bridge"
 
-HOOK_SETTINGS="HOOK ADDRESS STP STP_FORWARD_DELAY STP_HELLO STP_MAXAGE"
-HOOK_SETTINGS="${HOOK_SETTINGS} STP_PRIORITY MTU"
-
-HOOK_PORT_SETTINGS="COST PRIORITY"
+HOOK_SETTINGS=(
+       "ADDRESS"
+       "STP"
+       "STP_FORWARD_DELAY"
+       "STP_HELLO STP_MAXAGE"
+       "STP_PRIORITY"
+       "MTU"
+)
+
+HOOK_PORT_SETTINGS=(
+       "COST"
+       "PRIORITY"
+)
 
 # Default values
 DEFAULT_STP="on"
index e4be361..634154e 100644 (file)
 
 SUPPORTED_IP_TUNNEL_MODES="gre vti"
 
-HOOK_SETTINGS="HOOK MARK MODE PEER LOCAL_ADDRESS"
+HOOK_SETTINGS=(
+       "MARK"
+       "MODE"
+       "PEER"
+       "LOCAL_ADDRESS"
+)
 
 # Default mode of the tunnel
 DEFAULT_MODE="gre"
index 50d43c7..e12b104 100644 (file)
 # Modems support all authentication methods, that pppd does support.
 MODEM_ALLOWED_AUTH_METHODS="${PPP_ALLOWED_AUTH_METHODS}"
 
-HOOK_SETTINGS="HOOK"
+HOOK_SETTINGS=(
+       "APN"
+       "AUTH"
+       "BAUDRATE"
+       "DEVICE"
+       "MONITOR_DEVICE"
+       "MTU"
+       "USERNAME"
+       "PASSWORD"
+       "PIN"
+       "PHONE_NUMBER"
+       "IMSI"
+)
 
-# Access Point Name.
-HOOK_SETTINGS="${HOOK_SETTINGS} APN"
-
-# Sets the authentication algortihm that must be used.
-HOOK_SETTINGS="${HOOK_SETTINGS} AUTH"
-
-# Baudrate.
 DEFAULT_BAUDRATE=921600
-HOOK_SETTINGS="${HOOK_SETTINGS} BAUDRATE"
-
-# The device name of the serial device.
-# XXX how can we make sure that this does not change all the time?
-HOOK_SETTINGS="${HOOK_SETTINGS} DEVICE"
-
-# A monitor device.
-# Send AT commands to this device, when the primary device is
-# connected.
-HOOK_SETTINGS="${HOOK_SETTINGS} MONITOR_DEVICE"
-
-# Maximum transmission unit.
-HOOK_SETTINGS="${HOOK_SETTINGS} MTU"
-
-# User credentials.
-HOOK_SETTINGS="${HOOK_SETTINGS} USERNAME PASSWORD"
-
-# PIN code.
-HOOK_SETTINGS="${HOOK_SETTINGS} PIN"
-
-# Phone number.
-HOOK_SETTINGS="${HOOK_SETTINGS} PHONE_NUMBER"
-
-# IMSI
-HOOK_SETTINGS="${HOOK_SETTINGS} IMSI"
 
 hook_check_settings() {
        assert isset DEVICE
index cd3913b..4f7ae51 100644 (file)
 
 . /usr/lib/network/header-zone
 
-HOOK_SETTINGS="HOOK ACCESS_CONCENTRATOR AUTH USERNAME PASSWORD"
-HOOK_SETTINGS="${HOOK_SETTINGS} SERVICE_NAME MTU IPV6 PREFIX_DELEGATION"
+HOOK_SETTINGS=(
+       "ACCESS_CONCENTRATOR"
+       "AUTH"
+       "USERNAME"
+       "PASSWORD"
+       "SERVICE_NAME"
+       "MTU"
+       "IPV6"
+       "PREFIX_DELEGATION"
+)
 
 # This hook can work with all authentication methods supported by pppd.
 PPPOE_SUPPORTED_AUTH_METHODS="${PPP_SUPPORTED_AUTH_METHODS}"
index 553d917..9c52dce 100644 (file)
 
 . /usr/lib/network/header-zone
 
-HOOK_SETTINGS="HOOK ADDRESS PHY"
+HOOK_SETTINGS=(
+       "ADDRESS"
+       "PHY"
+)
 
 hook_check_settings() {
        assert ismac ADDRESS