From: Michael Tremer Date: Sat, 6 Sep 2014 12:08:44 +0000 (+0200) Subject: device: Rewrite device_set_address X-Git-Tag: 007~81 X-Git-Url: http://git.ipfire.org/?p=people%2Fms%2Fnetwork.git;a=commitdiff_plain;h=08c5b7898d9d56cd931c55cd8cf7cefcd9b1de64 device: Rewrite device_set_address --- diff --git a/src/functions/functions.device b/src/functions/functions.device index 4f47b7cd..cda8e7aa 100644 --- a/src/functions/functions.device +++ b/src/functions/functions.device @@ -379,31 +379,39 @@ function device_get_address() { } function device_set_address() { - local device=${1} - local addr=${2} + assert [ $# -eq 2 ] + + local device="${1}" + local addr="${2}" - if ! device_exists ${device}; then + if ! device_exists "${device}"; then error "Device '${device}' does not exist." return ${EXIT_ERROR} fi - log INFO "Setting address of '${device}' to '${addr}' - was $(device_get_address ${device})." + # Do nothing if the address has not changed + local old_addr="$(device_get_address "${device}")" + if [ -n "${old_addr}" -a "${addr}" = "${old_addr}" ]; then + return ${EXIT_OK} + fi + + log DEBUG "Setting address of '${device}' from '${old_addr}' to '${addr}'" local up - if device_is_up ${device}; then - device_set_down ${device} + if device_is_up "${device}"; then + device_set_down "${device}" up=1 fi - ip link set ${device} address ${addr} + ip link set "${device}" address "${addr}" local ret=$? if [ "${up}" = "1" ]; then - device_set_up ${device} + device_set_up "${device}" fi if [ "${ret}" != "0" ]; then - error_log "Could not set address '${addr}' on device '${device}'." + error_log "Could not set address '${addr}' on device '${device}'" fi return ${ret} diff --git a/src/functions/functions.hook b/src/functions/functions.hook index bebe99d0..20a71323 100644 --- a/src/functions/functions.hook +++ b/src/functions/functions.hook @@ -21,8 +21,8 @@ HOOK_COMMANDS_CONFIG="hook_create hook_down hook_status hook_up" -HOOK_COMMANDS_PORT="hook_create hook_down hook_hotplug hook_hotplug_rename \ - hook_info hook_status hook_up" +HOOK_COMMANDS_PORT="hook_create hook_down hook_edit hook_hotplug \ + hook_hotplug_rename hook_info hook_status hook_up" HOOK_COMMANDS_ZONE="hook_add hook_create hook_discover hook_down hook_edit hook_help \ hook_info hook_remove hook_status hook_up \