]> git.ipfire.org Git - people/stevee/network.git/blobdiff - src/hooks/ports/bonding
Convert HOOK_SETTINGS into an array
[people/stevee/network.git] / src / hooks / ports / bonding
index f4accc076fa4894ea220203aa5d4d745e1d2f6c5..09fb74f0ad541c072ddbd5afb6e1e766a5acfe37 100644 (file)
 
 . /usr/lib/network/header-port
 
-HOOK_SETTINGS="HOOK ADDRESS MIIMON MODE 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
@@ -39,16 +44,34 @@ hook_parse_cmdline() {
        while [ $# -gt 0 ]; do
                case "${1}" in
                        --address=*)
-                               ADDRESS=$(cli_get_val ${1})
+                               ADDRESS="$(cli_get_val "${1}")"
+
+                               if ! mac_is_valid "${ADDRESS}"; then
+                                       error "Invalid MAC address: ${ADDRESS}"
+                                       return ${EXIT_ERROR}
+                               fi
                                ;;
+
                        --miimon=*)
-                               MIIMON=$(cli_get_val ${1})
+                               MIIMON=$(cli_get_val "${1}")
                                ;;
                        --mode=*)
-                               MODE=$(cli_get_val ${1})
+                               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
                                ;;
                        +*)
-                               local slave=$(cli_get_val ${1:1})
+                               local slave=$(cli_get_val "${1:1}")
 
                                if port_exists "${slave}"; then
                                        if list_match "${slave}" ${SLAVES}; then
@@ -61,7 +84,7 @@ hook_parse_cmdline() {
                                fi
                                ;;
                        -*)
-                               local slave=$(cli_get_val ${1:1})
+                               local slave=$(cli_get_val "${1:1}")
                                if ! list_remove SLAVES "${slave}"; then
                                        warning "Port ${slave} is not a slave of this bonding device"
                                fi
@@ -84,7 +107,7 @@ hook_parse_cmdline() {
 }
 
 hook_new() {
-       if ! hook_parse_cmdline $@; then
+       if ! hook_parse_cmdline "$@"; then
                return ${EXIT_ERROR}
        fi
 
@@ -93,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}"
@@ -106,7 +129,7 @@ hook_new() {
 hook_edit() {
        local port=${1}
 
-       if ! hook_default_edit $@; then
+       if ! hook_default_edit "$@"; then
                return ${EXIT_ERROR}
        fi
 
@@ -117,7 +140,7 @@ hook_edit() {
                # and to recreate it again.
                local mode=$(bonding_get_mode "${port}")
                if [ "${mode}" != "${MODE}" ]; then
-                       port_remove "${port}" && port_create "${port}"
+                       port_restart "${port}"
                        return ${EXIT_OK}
                fi
 
@@ -145,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}" \
@@ -161,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
@@ -173,7 +196,14 @@ 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
+               offloading_auto "${port}"
+       else
+               offloading_disable_all "${port}"
+       fi
 
        # Execute the default action
        hook_default_up "${port}"
@@ -189,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
@@ -210,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