]> git.ipfire.org Git - people/ms/network.git/blobdiff - src/hooks/ports/ethernet
hooks: Import zone default settings, too
[people/ms/network.git] / src / hooks / ports / ethernet
index 78790e2c21e98c7f0f4d69fb9be8dece366982df..0d9c5cd62165ef8d6d40dfcf96a49e576efd712e 100644 (file)
 
 . /usr/lib/network/header-port
 
-# Default MTU
-DEFAULT_MTU=1500
-
 # 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="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
@@ -39,6 +39,13 @@ hook_check_settings() {
        if isset MTU; then
                assert mtu_is_valid "ethernet" "${MTU}"
        fi
+
+       if isset MODES; then
+               local mode
+               for mode in ${MODES}; do
+                       assert [ -n "${DEVICE_LINK_SPEEDS[${mode}]}" ]
+               done
+       fi
 }
 
 hook_parse_cmdline() {
@@ -53,6 +60,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}")"
 
@@ -61,6 +80,20 @@ hook_parse_cmdline() {
                                        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}
@@ -70,17 +103,27 @@ hook_parse_cmdline() {
        done
 }
 
+# This function is only called automatically by hotplug to create
+# a new ethernet port.
 hook_new() {
-       local port=${1}
+       local port="${1}"
        assert isset port
-       shift
 
-       ADDRESS=""
-       DEVICE=$(device_get_address ${port})
+       local device="${2}"
+       assert isset device
 
-       port_settings_write "${port}" ${HOOK_SETTINGS}
+       local DEVICE="$(device_get_address "${device}")"
 
-       exit ${EXIT_OK}
+       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}
 }
 
 hook_up() {
@@ -104,6 +147,18 @@ hook_up() {
                device_set_mtu "${port}" "${DEFAULT_MTU}"
        fi
 
+       # 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
        device_set_up "${port}"
 
@@ -131,8 +186,7 @@ hook_hotplug_rename() {
        # Check if the address matches with the configuration.
        if list_match "${address}" ${DEVICE} ${ADDRESS}; then
                log DEBUG "Device '${device}' equals port '${port}'."
-
-               hook_create "${device}"
+               exit ${EXIT_OK}
        fi
 
        log DEBUG "Device '${device}' does not equal port '${port}'."