X-Git-Url: http://git.ipfire.org/?p=people%2Fms%2Fnetwork.git;a=blobdiff_plain;f=src%2Fhooks%2Fports%2Fethernet;h=82664fa15376198d712e1fed7267d0025a2d21be;hp=d02884667325bc441f9b169a6870eec95e1a5416;hb=12f9c8d2550c8fcab536bb8b971caddfa8ee0c80;hpb=3ee5ccb1733c162bc927302337675127813b085d diff --git a/src/hooks/ports/ethernet b/src/hooks/ports/ethernet index d0288466..82664fa1 100644 --- a/src/hooks/ports/ethernet +++ b/src/hooks/ports/ethernet @@ -21,92 +21,157 @@ . /usr/lib/network/header-port -# 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" - -function hook_check() { +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 -} -function hook_create() { - local port=${1} - assert isset port - shift - - ADDRESS="" - DEVICE=$(device_get_address ${port}) + if isset MTU; then + assert mtu_is_valid "ethernet" "${MTU}" + fi - port_settings_write "${port}" ${HOOK_SETTINGS} + if isset MODES; then + local mode + for mode in ${MODES}; do + assert [ -n "${DEVICE_LINK_SPEEDS[${mode}]}" ] + done + fi +} - exit ${EXIT_OK} +hook_parse_cmdline() { + while [ $# -gt 0 ]; do + case "${1}" in + --address=*) + ADDRESS="$(cli_get_val "${1}")" + + if ! mac_is_valid "${ADDRESS}"; then + error "Invalid MAC address: ${ADDRESS}" + return ${EXIT_ERROR} + fi + ;; + + --advertised-link-speeds=*) + ADVERTISED_LINK_SPEEDS="$(cli_get_val "${1}")" + + 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=*) + MTU="$(cli_get_val "${1}")" + + if ! mtu_is_valid "ethernet" "${MTU}"; then + error "Invalid MTU: ${MTU}" + return ${EXIT_ERROR} + fi + ;; + + --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 + ;; + + *) + error "Unknown argument: ${1}" + return ${EXIT_ERROR} + ;; + esac + shift + done } -function hook_up() { - local port=${1} +# This function is only called automatically by hotplug to create +# a new ethernet port. +hook_new() { + local port="${1}" assert isset port - if ! device_exists "${port}"; then - log WARNING "Cannot bring up port '${port}' which does not exist" - exit ${EXIT_OK} - fi + local device="${2}" + assert isset device - # Read in the confguration file. - port_settings_read "${port}" ${HOOK_SETTINGS} + local DEVICE="$(device_get_address "${device}")" - # Check if the MAC address is the right one. - if isset ADDRESS; then - device_set_address "${device}" "${ADDRESS}" + if ! port_settings_write "${port}"; then + log ERROR "Could not write settings for port ${port}" + return ${EXIT_ERROR} fi - # Bring up the device. - device_set_up "${port}" - - exit ${EXIT_OK} + return ${EXIT_OK} } -function hook_down() { - local port=${1} - assert isset port +hook_create() { + return ${EXIT_OK} +} - # Set down the device. - device_set_down ${port} +hook_up() { + local port="${1}" - exit ${EXIT_OK} -} + local ${HOOK_SETTINGS[*]} + if ! port_settings_read "${port}"; then + log ERROR "Could not read settings for port ${port}" + return ${EXIT_ERROR} + fi -function hook_hotplug_rename() { - local port=${1} - assert isset port + # Set MAC address, if needed + if isset ADDRESS; then + device_set_address "${port}" "${ADDRESS}" + fi - local device=${2} - assert isset device + # Set MTU + if isset MTU; then + device_set_mtu "${port}" "${MTU}" + else + device_set_mtu "${port}" "${DEFAULT_MTU}" + fi - # Read in the conifguration file. - port_settings_read "${port}" ${HOOK_SETTINGS} + # Set link speeds + if isset ADVERTISED_LINK_SPEEDS; then + device_advertise_link_speeds "${port}" ${ADVERTISED_LINK_SPEEDS} + fi - # Get the current MAC address of the device. - local address=$(device_get_address ${device}) - assert isset address + # Auto-enable or disable hardware offloading + if ! isset OFFLOADING || enabled OFFLOADING; then + offloading_auto "${port}" + else + offloading_disable_all "${port}" + fi - # Check if the address matches with the configuration. - if list_match "${address}" ${DEVICE} ${ADDRESS}; then - log DEBUG "Device '${device}' equals port '${port}'." + # Bring up the device + device_set_up "${port}" - # Change the MAC address, if needed. - if isset ADDRESS; then - device_set_address "${device}" "${ADDRESS}" - fi + exit ${EXIT_OK} +} - # Everything is done. - exit ${EXIT_OK} - fi +hook_remove() { + exit ${EXIT_OK} +} - log DEBUG "Device '${device}' does not equal port '${port}'." - exit ${EXIT_ERROR} +hook_hotplug_rename() { + hook_hotplug_rename_by_address "$@" }