]> git.ipfire.org Git - people/stevee/network.git/commitdiff
port: ethernet: Allow setting the MTU
authorMichael Tremer <michael.tremer@ipfire.org>
Thu, 20 Sep 2018 22:01:42 +0000 (23:01 +0100)
committerMichael Tremer <michael.tremer@ipfire.org>
Thu, 20 Sep 2018 22:01:42 +0000 (23:01 +0100)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/functions/functions.util
src/hooks/ports/ethernet

index 7377818049d5b1953cf54bb0e53bd41348373579..a326d239225463c832bac1e2b9d8af55a6b326c0 100644 (file)
@@ -399,7 +399,7 @@ mtu_is_valid() {
        local mtu=${2}
 
        case ${proto} in
-               ipv4)
+               ethernet|ipv4)
                        [ ${mtu} -ge 576 ] && [ ${mtu} -le 9000 ]
                        ;;
                ipv6)
index ce48ecdd4967428f17586aa29adc96325ce829e7..78790e2c21e98c7f0f4d69fb9be8dece366982df 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"
+HOOK_SETTINGS="HOOK ADDRESS DEVICE MTU"
 
 hook_check_settings() {
        assert ismac DEVICE
@@ -32,6 +35,10 @@ hook_check_settings() {
        if isset ADDRESS; then
                assert ismac ADDRESS
        fi
+
+       if isset MTU; then
+               assert mtu_is_valid "ethernet" "${MTU}"
+       fi
 }
 
 hook_parse_cmdline() {
@@ -45,6 +52,15 @@ hook_parse_cmdline() {
                                        return ${EXIT_ERROR}
                                fi
                                ;;
+
+                       --mtu=*)
+                               MTU="$(cli_get_val "${1}")"
+
+                               if ! mtu_is_valid "ethernet" "${MTU}"; then
+                                       error "Invalid MTU: ${MTU}"
+                                       return ${EXIT_ERROR}
+                               fi
+                               ;;
                        *)
                                error "Unknown argument: ${1}"
                                return ${EXIT_ERROR}
@@ -67,14 +83,30 @@ hook_new() {
        exit ${EXIT_OK}
 }
 
-hook_create() {
+hook_up() {
        local port="${1}"
 
+       local ${HOOK_SETTINGS}
+       if ! port_settings_read "${port}" ${HOOK_SETTINGS}; then
+               log ERROR "Could not read settings for port ${port}"
+               return ${EXIT_ERROR}
+       fi
+
        # Set MAC address, if needed
        if isset ADDRESS; then
                device_set_address "${port}" "${ADDRESS}"
        fi
 
+       # Set MTU
+       if isset MTU; then
+               device_set_mtu "${port}" "${MTU}"
+       else
+               device_set_mtu "${port}" "${DEFAULT_MTU}"
+       fi
+
+       # Bring up the device
+       device_set_up "${port}"
+
        exit ${EXIT_OK}
 }