summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/devices/nm-device-ethernet.c6
-rw-r--r--src/devices/nm-device-macvlan.c8
-rw-r--r--src/devices/nm-device-private.h4
-rw-r--r--src/devices/nm-device-tun.c2
-rw-r--r--src/devices/nm-device-vlan.c8
-rw-r--r--src/devices/nm-device-vxlan.c2
-rw-r--r--src/devices/nm-device.c76
-rw-r--r--src/devices/wifi/nm-device-wifi.c6
8 files changed, 72 insertions, 40 deletions
diff --git a/src/devices/nm-device-ethernet.c b/src/devices/nm-device-ethernet.c
index a3e88f390b..e8d826e4be 100644
--- a/src/devices/nm-device-ethernet.c
+++ b/src/devices/nm-device-ethernet.c
@@ -824,7 +824,7 @@ act_stage1_prepare (NMDevice *dev, NMDeviceStateReason *reason)
s_wired = (NMSettingWired *) nm_device_get_applied_setting (dev, NM_TYPE_SETTING_WIRED);
if (s_wired)
cloned_mac = nm_setting_wired_get_cloned_mac_address (s_wired);
- nm_device_set_hw_addr (dev, cloned_mac, "set", LOGD_ETHER);
+ nm_device_hw_addr_set (dev, cloned_mac);
/* If we're re-activating a PPPoE connection a short while after
* a previous PPPoE connection was torn down, wait a bit to allow the
@@ -1364,9 +1364,7 @@ deactivate (NMDevice *device)
if (nm_device_get_applied_setting (device, NM_TYPE_SETTING_PPPOE))
NM_DEVICE_ETHERNET_GET_PRIVATE (device)->last_pppoe_time = nm_utils_get_monotonic_timestamp_s ();
- /* Reset MAC address back to initial address */
- if (nm_device_get_initial_hw_address (device))
- nm_device_set_hw_addr (device, nm_device_get_initial_hw_address (device), "reset", LOGD_ETHER);
+ nm_device_hw_addr_reset (device);
}
static gboolean
diff --git a/src/devices/nm-device-macvlan.c b/src/devices/nm-device-macvlan.c
index d2ebc38c34..f829f99c31 100644
--- a/src/devices/nm-device-macvlan.c
+++ b/src/devices/nm-device-macvlan.c
@@ -516,7 +516,7 @@ act_stage1_prepare (NMDevice *dev, NMDeviceStateReason *reason)
s_wired = (NMSettingWired *) nm_device_get_applied_setting (dev, NM_TYPE_SETTING_WIRED);
if (s_wired)
cloned_mac = nm_setting_wired_get_cloned_mac_address (s_wired);
- nm_device_set_hw_addr (dev, cloned_mac, "set", LOGD_HW);
+ nm_device_hw_addr_set (dev, cloned_mac);
return TRUE;
}
@@ -550,11 +550,7 @@ realize_start_notify (NMDevice *device, const NMPlatformLink *plink)
static void
deactivate (NMDevice *device)
{
- /* Reset MAC address back to initial address */
- if (nm_device_get_initial_hw_address (device)) {
- nm_device_set_hw_addr (device, nm_device_get_initial_hw_address (device),
- "reset", LOGD_DEVICE);
- }
+ nm_device_hw_addr_reset (device);
}
/******************************************************************/
diff --git a/src/devices/nm-device-private.h b/src/devices/nm-device-private.h
index 418ae2d9ca..4d4bd720ac 100644
--- a/src/devices/nm-device-private.h
+++ b/src/devices/nm-device-private.h
@@ -56,8 +56,8 @@ gboolean nm_device_bring_up (NMDevice *self, gboolean wait, gboolean *no_firmwar
void nm_device_take_down (NMDevice *self, gboolean block);
-gboolean nm_device_set_hw_addr (NMDevice *device, const char *addr,
- const char *detail, guint64 hw_log_domain);
+gboolean nm_device_hw_addr_set (NMDevice *device, const char *addr);
+gboolean nm_device_hw_addr_reset (NMDevice *device);
void nm_device_set_firmware_missing (NMDevice *self, gboolean missing);
diff --git a/src/devices/nm-device-tun.c b/src/devices/nm-device-tun.c
index 63b3fd6173..238d3a97b5 100644
--- a/src/devices/nm-device-tun.c
+++ b/src/devices/nm-device-tun.c
@@ -308,7 +308,7 @@ act_stage1_prepare (NMDevice *device, NMDeviceStateReason *reason)
s_wired = (NMSettingWired *) nm_device_get_applied_setting (device, NM_TYPE_SETTING_WIRED);
if (s_wired)
cloned_mac = nm_setting_wired_get_cloned_mac_address (s_wired);
- nm_device_set_hw_addr (device, cloned_mac, "set", LOGD_DEVICE);
+ nm_device_hw_addr_set (device, cloned_mac);
return NM_ACT_STAGE_RETURN_SUCCESS;
}
diff --git a/src/devices/nm-device-vlan.c b/src/devices/nm-device-vlan.c
index ca3ed2cadc..2d6b64064f 100644
--- a/src/devices/nm-device-vlan.c
+++ b/src/devices/nm-device-vlan.c
@@ -114,7 +114,7 @@ parent_hwaddr_maybe_changed (NMDevice *parent,
_LOGD (LOGD_VLAN, "parent hardware address changed to %s%s%s",
NM_PRINT_FMT_QUOTE_STRING (new_mac));
if (new_mac) {
- nm_device_set_hw_addr (self, new_mac, "set", LOGD_VLAN);
+ nm_device_hw_addr_set (self, new_mac);
/* When changing the hw address the interface is taken down,
* removing the IPv6 configuration; reapply it.
*/
@@ -563,7 +563,7 @@ act_stage1_prepare (NMDevice *dev, NMDeviceStateReason *reason)
s_wired = (NMSettingWired *) nm_device_get_applied_setting (dev, NM_TYPE_SETTING_WIRED);
if (s_wired)
cloned_mac = nm_setting_wired_get_cloned_mac_address (s_wired);
- nm_device_set_hw_addr (dev, cloned_mac, "set", LOGD_VLAN);
+ nm_device_hw_addr_set (dev, cloned_mac);
/* Change MAC address to parent's one if needed */
if (priv->parent)
@@ -620,9 +620,7 @@ ip4_config_pre_commit (NMDevice *device, NMIP4Config *config)
static void
deactivate (NMDevice *device)
{
- /* Reset MAC address back to initial address */
- if (nm_device_get_initial_hw_address (device))
- nm_device_set_hw_addr (device, nm_device_get_initial_hw_address (device), "reset", LOGD_VLAN);
+ nm_device_hw_addr_reset (device);
}
/******************************************************************/
diff --git a/src/devices/nm-device-vxlan.c b/src/devices/nm-device-vxlan.c
index ffd05ac678..4bdada349d 100644
--- a/src/devices/nm-device-vxlan.c
+++ b/src/devices/nm-device-vxlan.c
@@ -524,7 +524,7 @@ act_stage1_prepare (NMDevice *device, NMDeviceStateReason *reason)
s_wired = (NMSettingWired *) nm_device_get_applied_setting (device, NM_TYPE_SETTING_WIRED);
if (s_wired)
cloned_mac = nm_setting_wired_get_cloned_mac_address (s_wired);
- nm_device_set_hw_addr (device, cloned_mac, "set", LOGD_DEVICE);
+ nm_device_hw_addr_set (device, cloned_mac);
return NM_ACT_STAGE_RETURN_SUCCESS;
}
diff --git a/src/devices/nm-device.c b/src/devices/nm-device.c
index 0d7b32e428..22af8b17ea 100644
--- a/src/devices/nm-device.c
+++ b/src/devices/nm-device.c
@@ -11406,49 +11406,58 @@ nm_device_update_initial_hw_address (NMDevice *self)
}
}
-gboolean
-nm_device_set_hw_addr (NMDevice *self, const char *addr,
- const char *detail, guint64 hw_log_domain)
+static gboolean
+_hw_addr_set (NMDevice *self,
+ const char *addr,
+ const char *detail)
{
- NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE (self);
+ NMDevicePrivate *priv;
gboolean success = FALSE;
- const char *cur_addr = nm_device_get_hw_address (self);
+ const char *cur_addr;
guint8 addr_bytes[NM_UTILS_HWADDR_LEN_MAX];
+ guint hw_addr_len;
- /* Fall back to the permanent address */
- if (!addr)
- addr = priv->perm_hw_addr;
- if (!addr)
- return FALSE;
+ nm_assert (NM_IS_DEVICE (self));
+ nm_assert (addr);
+ nm_assert (detail);
+
+ priv = NM_DEVICE_GET_PRIVATE (self);
+
+ cur_addr = nm_device_get_hw_address (self);
/* Do nothing if current MAC is same */
if (cur_addr && nm_utils_hwaddr_matches (cur_addr, -1, addr, -1)) {
- _LOGD (LOGD_DEVICE | hw_log_domain, "no MAC address change needed");
+ _LOGD (LOGD_DEVICE, "no MAC address change needed");
return TRUE;
}
- if (!nm_utils_hwaddr_aton (addr, addr_bytes, priv->hw_addr_len)) {
- _LOGW (LOGD_DEVICE | hw_log_domain, "invalid MAC address %s", addr);
+
+ hw_addr_len = priv->hw_addr_len;
+ if (!hw_addr_len)
+ hw_addr_len = _nm_utils_hwaddr_length (addr);
+ if ( !hw_addr_len
+ || !nm_utils_hwaddr_aton (addr, addr_bytes, hw_addr_len)) {
+ _LOGW (LOGD_DEVICE, "invalid MAC address %s", addr);
return FALSE;
}
/* Can't change MAC address while device is up */
nm_device_take_down (self, FALSE);
- success = nm_platform_link_set_address (NM_PLATFORM_GET, nm_device_get_ip_ifindex (self), addr_bytes, priv->hw_addr_len);
+ success = nm_platform_link_set_address (NM_PLATFORM_GET, nm_device_get_ip_ifindex (self), addr_bytes, hw_addr_len);
if (success) {
/* MAC address succesfully changed; update the current MAC to match */
nm_device_update_hw_address (self);
cur_addr = nm_device_get_hw_address (self);
if (cur_addr && nm_utils_hwaddr_matches (cur_addr, -1, addr, -1)) {
- _LOGI (LOGD_DEVICE | hw_log_domain, "%s MAC address to %s",
+ _LOGI (LOGD_DEVICE, "%s MAC address to %s",
detail, addr);
} else {
- _LOGW (LOGD_DEVICE | hw_log_domain,
+ _LOGW (LOGD_DEVICE,
"new MAC address %s not successfully set", addr);
success = FALSE;
}
} else {
- _LOGW (LOGD_DEVICE | hw_log_domain, "failed to %s MAC address to %s",
+ _LOGW (LOGD_DEVICE, "failed to %s MAC address to %s",
detail, addr);
}
nm_device_bring_up (self, TRUE, NULL);
@@ -11456,6 +11465,39 @@ nm_device_set_hw_addr (NMDevice *self, const char *addr,
return success;
}
+gboolean
+nm_device_hw_addr_set (NMDevice *self, const char *addr)
+{
+ NMDevicePrivate *priv;
+
+ g_return_val_if_fail (NM_IS_DEVICE (self), FALSE);
+
+ priv = NM_DEVICE_GET_PRIVATE (self);
+
+ if (!addr) {
+ addr = priv->perm_hw_addr;
+ if (!addr)
+ return FALSE;
+ }
+ return _hw_addr_set (self, addr, "set");
+}
+
+gboolean
+nm_device_hw_addr_reset (NMDevice *self)
+{
+ NMDevicePrivate *priv;
+ const char *addr;
+
+ g_return_val_if_fail (NM_IS_DEVICE (self), FALSE);
+
+ priv = NM_DEVICE_GET_PRIVATE (self);
+
+ addr = priv->initial_hw_addr;
+ if (!addr)
+ return FALSE;
+ return _hw_addr_set (self, addr, "reset");
+}
+
const char *
nm_device_get_permanent_hw_address (NMDevice *self)
{
diff --git a/src/devices/wifi/nm-device-wifi.c b/src/devices/wifi/nm-device-wifi.c
index 8db14d8f20..4bdc6e8e2a 100644
--- a/src/devices/wifi/nm-device-wifi.c
+++ b/src/devices/wifi/nm-device-wifi.c
@@ -491,9 +491,7 @@ deactivate (NMDevice *device)
/* Clear any critical protocol notification in the Wi-Fi stack */
nm_platform_wifi_indicate_addressing_running (NM_PLATFORM_GET, ifindex, FALSE);
- /* Reset MAC address back to initial address */
- if (nm_device_get_initial_hw_address (device))
- nm_device_set_hw_addr (device, nm_device_get_initial_hw_address (device), "reset", LOGD_WIFI);
+ nm_device_hw_addr_reset (device);
/* Ensure we're in infrastructure mode after deactivation; some devices
* (usually older ones) don't scan well in adhoc mode.
@@ -2328,7 +2326,7 @@ act_stage1_prepare (NMDevice *device, NMDeviceStateReason *reason)
/* Set spoof MAC to the interface */
cloned_mac = nm_setting_wireless_get_cloned_mac_address (s_wireless);
- nm_device_set_hw_addr (device, cloned_mac, "set", LOGD_WIFI);
+ nm_device_hw_addr_set (device, cloned_mac);
/* AP mode never uses a specific object or existing scanned AP */
if (priv->mode != NM_802_11_MODE_AP) {