]> git.ipfire.org Git - people/ms/network.git/blobdiff - src/hooks/ports/ethernet
network-hotplug: Try to use fewer checks when deleting a device
[people/ms/network.git] / src / hooks / ports / ethernet
index beec3ccdb28bce88095bddab7edcde5fefcc0ad1..cdc3dec7d2c7e98279a48604c4d5cb7d4c6b8d08 100644 (file)
 
 . /usr/lib/network/header-port
 
-# 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 SPEED"
+HOOK_SETTINGS="ADDRESS ADVERTISED_LINK_SPEEDS DEVICE OFFLOADING MTU"
 
 hook_check_settings() {
        assert ismac DEVICE
@@ -43,8 +37,11 @@ hook_check_settings() {
                assert mtu_is_valid "ethernet" "${MTU}"
        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
 }
 
@@ -60,6 +57,18 @@ hook_parse_cmdline() {
                                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}")"
 
@@ -69,11 +78,15 @@ hook_parse_cmdline() {
                                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
                                ;;
@@ -87,6 +100,25 @@ hook_parse_cmdline() {
        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}" ${HOOK_SETTINGS}; then
+               log ERROR "Could not write settings for port ${port}"
+               return ${EXIT_ERROR}
+       fi
+
+       return ${EXIT_OK}
+}
+
 hook_create() {
        return ${EXIT_OK}
 }
@@ -112,9 +144,16 @@ hook_up() {
                device_set_mtu "${port}" "${DEFAULT_MTU}"
        fi
 
-       # Set speed
-       if isset SPEED; then
-               device_set_speed "${port}" "${SPEED}"
+       # Set link speeds
+       if isset ADVERTISED_LINK_SPEEDS; then
+               device_advertise_link_speeds "${port}" ${ADVERTISED_LINK_SPEEDS}
+       fi
+
+       # 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