]> git.ipfire.org Git - people/ms/network.git/blobdiff - src/hooks/ports/bonding
hooks: Use cli_get_bool convenience function where ever possible
[people/ms/network.git] / src / hooks / ports / bonding
index 40d849fba16b2f84abc8a5e94c7cedc0cbcb06e6..96cb85434aa95ae74cc5a2a0f0b25b02a3852a8c 100644 (file)
 
 . /usr/lib/network/header-port
 
-HOOK_SETTINGS="ADDRESS MIIMON MODE OFFLOADING SLAVES"
+HOOK_SETTINGS=(
+       "ADDRESS"
+       "MIIMON"
+       "MODE"
+       "OFFLOADING"
+       "SLAVES"
+)
 
-SLAVES=""
-MIIMON=100
-MODE="balance-rr"
+DEFAULT_MIIMON=100
+DEFAULT_MODE="balance-rr"
 
 hook_check_settings() {
        assert isset ADDRESS
@@ -54,16 +59,7 @@ hook_parse_cmdline() {
                                MODE=$(cli_get_val "${1}")
                                ;;
                        --offloading=*)
-                               OFFLOADING="$(cli_get_val "${1}")"
-
-                               if enabled OFFLOADING; then
-                                       OFFLOADING="on"
-                               elif disabled OFFLOADING; then
-                                       OFFLOADING="off"
-                               else
-                                       error "Invalid value for offloading: ${OFFLOADING}"
-                                       return ${EXIT_ERROR}
-                               fi
+                               OFFLOADING="$(cli_get_bool "${1}")"
                                ;;
                        +*)
                                local slave=$(cli_get_val "${1:1}")
@@ -111,7 +107,7 @@ hook_new() {
        assert isset port
 
        # Save configuration
-       if port_settings_write "${port}" ${HOOK_SETTINGS}; then
+       if port_settings_write "${port}"; then
                log INFO "New port ${port} has been created"
        else
                error "Could not save configuration for ${port}"
@@ -163,7 +159,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}"
 
        # Create the bonding devices
        bonding_create "${port}" \
@@ -179,7 +175,7 @@ hook_remove() {
        local port="${1}"
        assert isset port
 
-       port_settings_read "${port}" ${HOOK_SETTINGS}
+       port_settings_read "${port}"
 
        # Remove the bonding device
        if device_exists "${port}"; then
@@ -191,7 +187,7 @@ hook_up() {
        local port="${1}"
        assert isset port
 
-       port_settings_read "${port}" ${HOOK_SETTINGS}
+       port_settings_read "${port}"
 
        # Auto-enable or disable hardware offloading
        if ! isset OFFLOADING || enabled OFFLOADING; then
@@ -214,7 +210,7 @@ hook_down() {
        local port="${1}"
        assert isset port
 
-       port_settings_read "${port}" ${HOOK_SETTINGS}
+       port_settings_read "${port}"
 
        # Bring down all slaves
        local slave
@@ -235,7 +231,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}"
 
                                # Bring up all slaves
                                # Attach those which already exist and try to create