. /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
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
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
}
hook_new() {
- if ! hook_parse_cmdline $@; then
+ if ! hook_parse_cmdline "$@"; then
return ${EXIT_ERROR}
fi
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}"
hook_edit() {
local port=${1}
- if ! hook_default_edit $@; then
+ if ! hook_default_edit "$@"; then
return ${EXIT_ERROR}
fi
# 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
# 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}" \
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
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}"
local port="${1}"
assert isset port
- port_settings_read "${port}" ${HOOK_SETTINGS}
+ port_settings_read "${port}" ${HOOK_SETTINGS[*]}
# Bring down all slaves
local slave
# 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