print "${speed}"
}
+device_set_speed() {
+ local device="${1}"
+ assert isset device
+
+ local speed="${2}"
+ assert isinteger speed
+
+ if ! cmd_quiet ethtool --change "${device}" speed "${speed}"; then
+ log ERROR "Could not set speed of ${device} to ${speed} MBit/s"
+ return ${EXIT_ERROR}
+ fi
+
+ log DEBUG "Set speed of ${device} to ${speed} MBit/s"
+
+ return ${EXIT_OK}
+}
+
device_get_duplex() {
local device=${1}
# Default MTU
DEFAULT_MTU=1500
+# Selectable speeds in MBit/s
+VALID_SPEEDS="10000 1000 100 10"
+
# 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 MTU"
+HOOK_SETTINGS="HOOK ADDRESS DEVICE MTU SPEED"
hook_check_settings() {
assert ismac DEVICE
if isset MTU; then
assert mtu_is_valid "ethernet" "${MTU}"
fi
+
+ if isset SPEED; then
+ assert isoneof SPEED ${VALID_SPEEDS}
+ fi
}
hook_parse_cmdline() {
return ${EXIT_ERROR}
fi
;;
+
+ --speed=*)
+ SPEED="$(cli_get_val "${1}")"
+
+ if ! isoneof SPEED ${VALID_SPEEDS}; then
+ error "Invalid speed: ${SPEED}"
+ return ${EXIT_ERROR}
+ fi
+ ;;
+
*)
error "Unknown argument: ${1}"
return ${EXIT_ERROR}
device_set_mtu "${port}" "${DEFAULT_MTU}"
fi
+ # Set speed
+ if isset SPEED; then
+ device_set_speed "${port}" "${SPEED}"
+ fi
+
# Bring up the device
device_set_up "${port}"