summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Haller <thaller@redhat.com>2016-07-05 10:41:18 +0200
committerThomas Haller <thaller@redhat.com>2016-07-05 23:08:22 +0200
commitf9852821e39625787c9b97edd306839b326aa344 (patch)
tree307525a407d76191bff84ac48d085e019456fd1b
parent4041bf966f5c49300776e32c8048062ff77ec638 (diff)
downloadNetworkManager-f9852821e39625787c9b97edd306839b326aa344.tar.gz
core: don't warn when setting address of non-existing link
Trying to set a property on a device that does not exist is not something necessarily wrong. Don't print error/warning messages. <trace> [1467707267.2887] device[0x55a74adbdaf0] (enp0s25): set-hw-addr: setting MAC address to 'AA:BB:CC:DD:EE:FF' (reset, unmanage)... <debug> [1467707267.2887] platform: link: setting '(null)' (2) hardware address <debug> [1467707267.2887] platform-linux: link: change 2: address: 68:F7:28:61:68:F7 (6 bytes) <debug> [1467707267.2887] platform-linux: do-request-link: 2 <debug> [1467707267.2888] platform-linux: netlink: recvmsg: error message from kernel: No such device (19) for request 226 <debug> [1467707267.2888] platform-linux: netlink: recvmsg: error message from kernel: No such device (19) for request 227 <error> [1467707267.2888] platform-linux: do-change-link[2]: failure changing link: failure 19 (No such device) <warn> [1467707267.2888] device (enp0s25): set-hw-addr: failed to reset MAC address to 68:F7:28:61:68:F7 (unmanage)
-rw-r--r--src/devices/nm-device.c10
-rw-r--r--src/platform/nm-fake-platform.c6
-rw-r--r--src/platform/nm-linux-platform.c13
-rw-r--r--src/platform/nm-platform.c14
-rw-r--r--src/platform/nm-platform.h4
-rw-r--r--src/platform/tests/test-link.c2
6 files changed, 29 insertions, 20 deletions
diff --git a/src/devices/nm-device.c b/src/devices/nm-device.c
index fd70325069..24a4d99e43 100644
--- a/src/devices/nm-device.c
+++ b/src/devices/nm-device.c
@@ -11657,6 +11657,7 @@ _hw_addr_set (NMDevice *self,
{
NMDevicePrivate *priv;
gboolean success = FALSE;
+ NMPlatformError plerr;
const char *cur_addr;
guint8 addr_bytes[NM_UTILS_HWADDR_LEN_MAX];
guint hw_addr_len;
@@ -11691,7 +11692,8 @@ _hw_addr_set (NMDevice *self,
nm_device_take_down (self, FALSE);
}
- success = nm_platform_link_set_address (NM_PLATFORM_GET, nm_device_get_ip_ifindex (self), addr_bytes, hw_addr_len);
+ plerr = nm_platform_link_set_address (NM_PLATFORM_GET, nm_device_get_ip_ifindex (self), addr_bytes, hw_addr_len);
+ success = (plerr == NM_PLATFORM_ERROR_SUCCESS);
if (success) {
/* MAC address succesfully changed; update the current MAC to match */
nm_device_update_hw_address (self);
@@ -11706,8 +11708,10 @@ _hw_addr_set (NMDevice *self,
success = FALSE;
}
} else {
- _LOGW (LOGD_DEVICE, "set-hw-addr: failed to %s MAC address to %s (%s)",
- operation, addr, detail);
+ _NMLOG (plerr == NM_PLATFORM_ERROR_NOT_FOUND ? LOGL_DEBUG : LOGL_WARN,
+ LOGD_DEVICE, "set-hw-addr: failed to %s MAC address to %s (%s) (%s)",
+ operation, addr, detail,
+ nm_platform_error_to_string (plerr));
}
if (was_up) {
diff --git a/src/platform/nm-fake-platform.c b/src/platform/nm-fake-platform.c
index d0fb277462..8a4f69b69e 100644
--- a/src/platform/nm-fake-platform.c
+++ b/src/platform/nm-fake-platform.c
@@ -506,7 +506,7 @@ link_set_noarp (NMPlatform *platform, int ifindex)
return TRUE;
}
-static gboolean
+static NMPlatformError
link_set_address (NMPlatform *platform, int ifindex, gconstpointer addr, size_t len)
{
NMFakePlatformLink *device = link_get (platform, ifindex);
@@ -515,7 +515,7 @@ link_set_address (NMPlatform *platform, int ifindex, gconstpointer addr, size_t
|| len == 0
|| len > NM_UTILS_HWADDR_LEN_MAX
|| !addr)
- g_return_val_if_reached (FALSE);
+ g_return_val_if_reached (NM_PLATFORM_ERROR_BUG);
if ( device->link.addr.len != len
|| ( len > 0
@@ -525,7 +525,7 @@ link_set_address (NMPlatform *platform, int ifindex, gconstpointer addr, size_t
link_changed (platform, link_get (platform, ifindex), TRUE);
}
- return TRUE;
+ return NM_PLATFORM_ERROR_SUCCESS;
}
static gboolean
diff --git a/src/platform/nm-linux-platform.c b/src/platform/nm-linux-platform.c
index 2dcea911b4..9e98665b72 100644
--- a/src/platform/nm-linux-platform.c
+++ b/src/platform/nm-linux-platform.c
@@ -4089,6 +4089,9 @@ retry:
} else if (NM_IN_SET (-((int) seq_result), ESRCH, ENOENT)) {
log_detail = ", firmware not found";
result = NM_PLATFORM_ERROR_NO_FIRMWARE;
+ } else if (NM_IN_SET (-((int) seq_result), ENODEV)) {
+ log_level = LOGL_DEBUG;
+ result = NM_PLATFORM_ERROR_NOT_FOUND;
} else {
log_level = LOGL_ERR;
result = NM_PLATFORM_ERROR_UNSPECIFIED;
@@ -4405,14 +4408,14 @@ link_supports_vlans (NMPlatform *platform, int ifindex)
return nmp_utils_ethtool_supports_vlans (obj->link.name);
}
-static gboolean
+static NMPlatformError
link_set_address (NMPlatform *platform, int ifindex, gconstpointer address, size_t length)
{
nm_auto_nlmsg struct nl_msg *nlmsg = NULL;
gs_free char *mac = NULL;
if (!address || !length)
- g_return_val_if_reached (FALSE);
+ g_return_val_if_reached (NM_PLATFORM_ERROR_BUG);
_LOGD ("link: change %d: address: %s (%lu bytes)", ifindex,
(mac = nm_utils_hwaddr_ntoa (address, length)),
@@ -4425,13 +4428,13 @@ link_set_address (NMPlatform *platform, int ifindex, gconstpointer address, size
0,
0);
if (!nlmsg)
- return FALSE;
+ g_return_val_if_reached (NM_PLATFORM_ERROR_UNSPECIFIED);
NLA_PUT (nlmsg, IFLA_ADDRESS, length, address);
- return do_change_link (platform, ifindex, nlmsg) == NM_PLATFORM_ERROR_SUCCESS;
+ return do_change_link (platform, ifindex, nlmsg);
nla_put_failure:
- g_return_val_if_reached (FALSE);
+ g_return_val_if_reached (NM_PLATFORM_ERROR_UNSPECIFIED);
}
static gboolean
diff --git a/src/platform/nm-platform.c b/src/platform/nm-platform.c
index a6afcf33a9..fd8e32cb28 100644
--- a/src/platform/nm-platform.c
+++ b/src/platform/nm-platform.c
@@ -1003,16 +1003,18 @@ nm_platform_link_set_user_ipv6ll_enabled (NMPlatform *self, int ifindex, gboolea
*
* Set interface MAC address.
*/
-gboolean
+NMPlatformError
nm_platform_link_set_address (NMPlatform *self, int ifindex, gconstpointer address, size_t length)
{
- _CHECK_SELF (self, klass, FALSE);
+ _CHECK_SELF (self, klass, NM_PLATFORM_ERROR_BUG);
- g_return_val_if_fail (ifindex > 0, FALSE);
- g_return_val_if_fail (address, FALSE);
- g_return_val_if_fail (length > 0, FALSE);
+ g_return_val_if_fail (ifindex > 0, NM_PLATFORM_ERROR_BUG);
+ g_return_val_if_fail (address, NM_PLATFORM_ERROR_BUG);
+ g_return_val_if_fail (length > 0, NM_PLATFORM_ERROR_BUG);
- _LOGD ("link: setting '%s' (%d) hardware address", nm_platform_link_get_name (self, ifindex), ifindex);
+ _LOGD ("link: setting %s (%d) hardware address",
+ nm_strquote_a (20, nm_platform_link_get_name (self, ifindex)),
+ ifindex);
return klass->link_set_address (self, ifindex, address, length);
}
diff --git a/src/platform/nm-platform.h b/src/platform/nm-platform.h
index 72f4f6720a..f2d3ae64d3 100644
--- a/src/platform/nm-platform.h
+++ b/src/platform/nm-platform.h
@@ -526,7 +526,7 @@ typedef struct {
int ifindex,
guint8 *buf,
size_t *length);
- gboolean (*link_set_address) (NMPlatform *, int ifindex, gconstpointer address, size_t length);
+ NMPlatformError (*link_set_address) (NMPlatform *, int ifindex, gconstpointer address, size_t length);
gboolean (*link_set_mtu) (NMPlatform *, int ifindex, guint32 mtu);
char * (*link_get_physical_port_id) (NMPlatform *, int ifindex);
@@ -757,7 +757,7 @@ gboolean nm_platform_link_set_user_ipv6ll_enabled (NMPlatform *self, int ifindex
gboolean nm_platform_link_set_ipv6_token (NMPlatform *self, int ifindex, NMUtilsIPv6IfaceId iid);
gboolean nm_platform_link_get_permanent_address (NMPlatform *self, int ifindex, guint8 *buf, size_t *length);
-gboolean nm_platform_link_set_address (NMPlatform *self, int ifindex, const void *address, size_t length);
+NMPlatformError nm_platform_link_set_address (NMPlatform *self, int ifindex, const void *address, size_t length);
gboolean nm_platform_link_set_mtu (NMPlatform *self, int ifindex, guint32 mtu);
char *nm_platform_link_get_physical_port_id (NMPlatform *self, int ifindex);
diff --git a/src/platform/tests/test-link.c b/src/platform/tests/test-link.c
index 6eec946143..fe43751c02 100644
--- a/src/platform/tests/test-link.c
+++ b/src/platform/tests/test-link.c
@@ -592,7 +592,7 @@ test_internal (void)
g_assert (nm_platform_link_supports_vlans (NM_PLATFORM_GET, ifindex));
/* Set MAC address */
- g_assert (nm_platform_link_set_address (NM_PLATFORM_GET, ifindex, mac, sizeof (mac)));
+ g_assert (nm_platform_link_set_address (NM_PLATFORM_GET, ifindex, mac, sizeof (mac)) == NM_PLATFORM_ERROR_SUCCESS);
address = nm_platform_link_get_address (NM_PLATFORM_GET, ifindex, &addrlen);
g_assert (addrlen == sizeof(mac));
g_assert (!memcmp (address, mac, addrlen));