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)
}
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
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}