]> git.ipfire.org Git - people/ms/network.git/commitdiff
device_{get,set}_mtu: Improve speed and logging
authorMichael Tremer <michael.tremer@ipfire.org>
Fri, 23 Sep 2016 19:33:16 +0000 (21:33 +0200)
committerMichael Tremer <michael.tremer@ipfire.org>
Fri, 23 Sep 2016 19:33:16 +0000 (21:33 +0200)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/functions/functions.device

index fc135297a6adf2b3fe605cb8bb10271a168542b8..571b1fb4c5a62fb711a55686f3bc788599dbbc2b 100644 (file)
@@ -646,10 +646,8 @@ device_set_parent_down() {
 device_get_mtu() {
        local device=${1}
 
-       if ! device_exists ${device}; then
-               error "Device '${device}' does not exist."
-               return ${EXIT_ERROR}
-       fi
+       # Return an error if the device does not exist
+       device_exists ${device} || return ${EXIT_ERROR}
 
        echo $(<${SYS_CLASS_NET}/${device}/mtu)
 }
@@ -659,19 +657,9 @@ device_set_mtu() {
        local device=${1}
        local mtu=${2}
 
-       if ! device_exists ${device}; then
-               error "Device '${device}' does not exist."
-               return ${EXIT_ERROR}
-       fi
-       
-       local oldmtu=$(device_get_mtu ${device})
-
-       if [ "${oldmtu}" = "${mtu}" ]; then
-               # No need to set mtu.
-               return ${EXIT_OK}
-       fi
+       assert device_exists ${device}
 
-       log INFO "Setting mtu of '${device}' to '${mtu}' - was ${oldmtu}."
+       log INFO "Setting MTU of ${device} to ${mtu}"
 
        local up
        if device_is_up ${device}; then
@@ -679,15 +667,15 @@ device_set_mtu() {
                up=1
        fi
 
-       ip link set ${device} mtu ${mtu}
-       local ret=$?
+       local ret=${EXIT_OK}
+       if ! cmd ip link set ${device} mtu ${mtu}; then
+               ret=${EXIT_ERROR}
 
-       if [ "${up}" = "1" ]; then
-               device_set_up ${device}
+               log ERROR "Could not set MTU ${mtu} on ${device}"
        fi
 
-       if [ "${ret}" != "0" ]; then
-               error_log "Could not set mtu '${mtu}' on device '${device}'."
+       if [ "${up}" = "1" ]; then
+               device_set_up ${device}
        fi
 
        return ${ret}