From ef53293cc7e9e1a73cb4956c727cb101942811ae Mon Sep 17 00:00:00 2001 From: Michael Tremer Date: Thu, 20 Sep 2018 23:01:42 +0100 Subject: [PATCH] port: ethernet: Allow setting the MTU Signed-off-by: Michael Tremer --- src/functions/functions.util | 2 +- src/hooks/ports/ethernet | 36 ++++++++++++++++++++++++++++++++++-- 2 files changed, 35 insertions(+), 3 deletions(-) diff --git a/src/functions/functions.util b/src/functions/functions.util index 73778180..a326d239 100644 --- a/src/functions/functions.util +++ b/src/functions/functions.util @@ -399,7 +399,7 @@ mtu_is_valid() { local mtu=${2} case ${proto} in - ipv4) + ethernet|ipv4) [ ${mtu} -ge 576 ] && [ ${mtu} -le 9000 ] ;; ipv6) diff --git a/src/hooks/ports/ethernet b/src/hooks/ports/ethernet index ce48ecdd..78790e2c 100644 --- a/src/hooks/ports/ethernet +++ b/src/hooks/ports/ethernet @@ -21,10 +21,13 @@ . /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} } -- 2.39.2