. /usr/lib/network/header-port
-# Default MTU
-DEFAULT_MTU=1500
-
-# Selectable speeds in MBit/s
-VALID_SPEEDS="10000 1000 100 10"
-
-# We can run in full or half duplex
-VALID_DUPLEXES="full half"
-
-# 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="HOOK ADDRESS DEVICE DUPLEX MTU SPEED"
+HOOK_SETTINGS=(
+ "ADDRESS"
+ "ADVERTISED_LINK_SPEEDS"
+ "DEVICE"
+ "OFFLOADING"
+ "MTU"
+)
hook_check_settings() {
assert ismac DEVICE
+ # Invalid MAC addresses are not allowed
+ assert not isoneof DEVICE 00:00:00:00:00:00 ff:ff:ff:ff:ff:ff
+
if isset ADDRESS; then
assert ismac ADDRESS
fi
assert mtu_is_valid "ethernet" "${MTU}"
fi
- if isset DUPLEX; then
- assert isoneof DUPLEX ${VALID_DUPLEXES}
- fi
-
- if isset SPEED; then
- assert isoneof SPEED ${VALID_SPEEDS}
+ if isset MODES; then
+ local mode
+ for mode in ${MODES}; do
+ assert [ -n "${DEVICE_LINK_SPEEDS[${mode}]}" ]
+ done
fi
}
fi
;;
- --duplex=*)
- DUPLEX="$(cli_get_val "${1}")"
+ --advertised-link-speeds=*)
+ ADVERTISED_LINK_SPEEDS="$(cli_get_val "${1}")"
- if ! isoneof DUPLEX ${VALID_DUPLEXES}; then
- error "Invalid duplex mode: ${DUPLEX}"
- return ${EXIT_ERROR}
- fi
+ local speed
+ for speed in ${ADVERTISED_LINK_SPEEDS}; do
+ if [ -z "${DEVICE_LINK_SPEEDS[${speed}]}" ]; then
+ error "Unsupported link speed: ${speed}"
+ return ${EXIT_ERROR}
+ fi
+ done
;;
--mtu=*)
fi
;;
- --speed=*)
- SPEED="$(cli_get_val "${1}")"
+ --offloading=*)
+ OFFLOADING="$(cli_get_val "${1}")"
- if ! isoneof SPEED ${VALID_SPEEDS}; then
- error "Invalid speed: ${SPEED}"
+ if enabled OFFLOADING; then
+ OFFLOADING="on"
+ elif disabled OFFLOADING; then
+ OFFLOADING="off"
+ else
+ error "Invalid value for offloading: ${OFFLOADING}"
return ${EXIT_ERROR}
fi
;;
done
}
+# This function is only called automatically by hotplug to create
+# a new ethernet port.
+hook_new() {
+ local port="${1}"
+ assert isset port
+
+ local device="${2}"
+ assert isset device
+
+ local DEVICE="$(device_get_address "${device}")"
+
+ if ! port_settings_write "${port}"; then
+ log ERROR "Could not write settings for port ${port}"
+ return ${EXIT_ERROR}
+ fi
+
+ return ${EXIT_OK}
+}
+
hook_create() {
return ${EXIT_OK}
}
hook_up() {
local port="${1}"
- local ${HOOK_SETTINGS}
- if ! port_settings_read "${port}" ${HOOK_SETTINGS}; then
+ local ${HOOK_SETTINGS[*]}
+ if ! port_settings_read "${port}"; then
log ERROR "Could not read settings for port ${port}"
return ${EXIT_ERROR}
fi
device_set_mtu "${port}" "${DEFAULT_MTU}"
fi
- # Set duplex mode
- if isset DUPLEX; then
- device_set_duplex "${port}" "${DUPLEX}"
+ # Set link speeds
+ if isset ADVERTISED_LINK_SPEEDS; then
+ device_advertise_link_speeds "${port}" ${ADVERTISED_LINK_SPEEDS}
fi
- # Set speed
- if isset SPEED; then
- device_set_speed "${port}" "${SPEED}"
+ # Auto-enable or disable hardware offloading
+ if ! isset OFFLOADING || enabled OFFLOADING; then
+ offloading_auto "${port}"
+ else
+ offloading_disable_all "${port}"
fi
# Bring up the device
}
hook_hotplug_rename() {
- local port=${1}
- assert isset port
-
- local device=${2}
- assert isset device
-
- # Read in the conifguration file.
- port_settings_read "${port}" ${HOOK_SETTINGS}
-
- # Get the current MAC address of the device.
- local address=$(device_get_address ${device})
- assert isset address
-
- # Check if the address matches with the configuration.
- if list_match "${address}" ${DEVICE} ${ADDRESS}; then
- log DEBUG "Device '${device}' equals port '${port}'."
- exit ${EXIT_OK}
- fi
-
- log DEBUG "Device '${device}' does not equal port '${port}'."
- exit ${EXIT_ERROR}
+ hook_hotplug_rename_by_address "$@"
}