summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Haller <thaller@redhat.com>2016-10-13 18:52:12 +0200
committerThomas Haller <thaller@redhat.com>2016-10-27 11:53:18 +0200
commit2c1a87acdf01cc60290f6200b13c780eaa48c296 (patch)
treebead8b4c33acefd2dfae8b41fafe89fa1b7b4ec1
parent0460070d0962b37bc6e28db4165655c75ed281cb (diff)
downloadNetworkManager-2c1a87acdf01cc60290f6200b13c780eaa48c296.tar.gz
device: treat fake permanent MAC address mostly like a real one
Now that we persist the fake permanent address across restart of NetworkManager, we want to consider fake addresses as good enough in most cases.
-rw-r--r--src/devices/nm-device-ethernet.c15
-rw-r--r--src/devices/nm-device-infiniband.c6
-rw-r--r--src/devices/nm-device-macvlan.c2
-rw-r--r--src/devices/nm-device-vlan.c2
-rw-r--r--src/devices/nm-device.c25
-rw-r--r--src/devices/nm-device.h3
-rw-r--r--src/devices/wifi/nm-device-wifi.c4
-rw-r--r--src/nm-config.c2
-rw-r--r--src/nm-manager.c2
-rw-r--r--src/settings/nm-settings.c2
10 files changed, 31 insertions, 32 deletions
diff --git a/src/devices/nm-device-ethernet.c b/src/devices/nm-device-ethernet.c
index b99271afdd..61d4c069f4 100644
--- a/src/devices/nm-device-ethernet.c
+++ b/src/devices/nm-device-ethernet.c
@@ -394,7 +394,7 @@ check_connection_compatible (NMDevice *device, NMConnection *connection)
if (!match_subchans (self, s_wired, &try_mac))
return FALSE;
- perm_hw_addr = nm_device_get_permanent_hw_address (device, TRUE);
+ perm_hw_addr = nm_device_get_permanent_hw_address (device);
mac = nm_setting_wired_get_mac_address (s_wired);
if (perm_hw_addr) {
if (try_mac && mac && !nm_utils_hwaddr_matches (mac, -1, perm_hw_addr, -1))
@@ -1344,6 +1344,7 @@ complete_connection (NMDevice *device,
NMSettingPppoe *s_pppoe;
const char *setting_mac;
const char *perm_hw_addr;
+ gboolean perm_hw_addr_is_fake;
s_pppoe = nm_connection_get_setting_pppoe (connection);
@@ -1371,8 +1372,8 @@ complete_connection (NMDevice *device,
nm_connection_add_setting (connection, NM_SETTING (s_wired));
}
- perm_hw_addr = nm_device_get_permanent_hw_address (device, FALSE);
- if (perm_hw_addr) {
+ perm_hw_addr = nm_device_get_permanent_hw_address_full (device, &perm_hw_addr_is_fake);
+ if (perm_hw_addr && !perm_hw_addr_is_fake) {
setting_mac = nm_setting_wired_get_mac_address (s_wired);
if (setting_mac) {
/* Make sure the setting MAC (if any) matches the device's permanent MAC */
@@ -1408,7 +1409,7 @@ new_default_connection (NMDevice *self)
if (nm_config_get_no_auto_default_for_device (nm_config_get (), self))
return NULL;
- perm_hw_addr = nm_device_get_permanent_hw_address (self, TRUE);
+ perm_hw_addr = nm_device_get_permanent_hw_address (self);
if (!perm_hw_addr)
return NULL;
@@ -1468,7 +1469,8 @@ update_connection (NMDevice *device, NMConnection *connection)
{
NMDeviceEthernetPrivate *priv = NM_DEVICE_ETHERNET_GET_PRIVATE ((NMDeviceEthernet *) device);
NMSettingWired *s_wired = nm_connection_get_setting_wired (connection);
- const char *perm_hw_addr = nm_device_get_permanent_hw_address (device, FALSE);
+ gboolean perm_hw_addr_is_fake;
+ const char *perm_hw_addr;
const char *mac = nm_device_get_hw_address (device);
const char *mac_prop = NM_SETTING_WIRED_MAC_ADDRESS;
GHashTableIter iter;
@@ -1487,7 +1489,8 @@ update_connection (NMDevice *device, NMConnection *connection)
/* If the device reports a permanent address, use that for the MAC address
* and the current MAC, if different, is the cloned MAC.
*/
- if (perm_hw_addr) {
+ perm_hw_addr = nm_device_get_permanent_hw_address_full (device, &perm_hw_addr_is_fake);
+ if (perm_hw_addr && !perm_hw_addr_is_fake) {
g_object_set (s_wired, NM_SETTING_WIRED_MAC_ADDRESS, perm_hw_addr, NULL);
mac_prop = NULL;
diff --git a/src/devices/nm-device-infiniband.c b/src/devices/nm-device-infiniband.c
index fa0d591754..88bd7c0aef 100644
--- a/src/devices/nm-device-infiniband.c
+++ b/src/devices/nm-device-infiniband.c
@@ -160,7 +160,7 @@ check_connection_compatible (NMDevice *device, NMConnection *connection)
mac = nm_setting_infiniband_get_mac_address (s_infiniband);
if (mac) {
- hw_addr = nm_device_get_permanent_hw_address (device, TRUE);
+ hw_addr = nm_device_get_permanent_hw_address (device);
if ( !hw_addr
|| !nm_utils_hwaddr_matches (mac, -1, hw_addr, -1))
return FALSE;
@@ -197,7 +197,7 @@ complete_connection (NMDevice *device,
}
setting_mac = nm_setting_infiniband_get_mac_address (s_infiniband);
- hw_address = nm_device_get_permanent_hw_address (device, TRUE);
+ hw_address = nm_device_get_permanent_hw_address (device);
if (setting_mac) {
/* Make sure the setting MAC (if any) matches the device's MAC */
if (!nm_utils_hwaddr_matches (setting_mac, -1, hw_address, -1)) {
@@ -223,7 +223,7 @@ static void
update_connection (NMDevice *device, NMConnection *connection)
{
NMSettingInfiniband *s_infiniband = nm_connection_get_setting_infiniband (connection);
- const char *mac = nm_device_get_permanent_hw_address (device, TRUE);
+ const char *mac = nm_device_get_permanent_hw_address (device);
const char *transport_mode = "datagram";
int ifindex;
diff --git a/src/devices/nm-device-macvlan.c b/src/devices/nm-device-macvlan.c
index 9e32694ffd..7b240ec6ae 100644
--- a/src/devices/nm-device-macvlan.c
+++ b/src/devices/nm-device-macvlan.c
@@ -369,7 +369,7 @@ match_hwaddr (NMDevice *device, NMConnection *connection, gboolean fail_if_no_hw
if (!priv->parent)
return !fail_if_no_hwaddr;
- parent_mac = nm_device_get_permanent_hw_address (priv->parent, FALSE);
+ parent_mac = nm_device_get_permanent_hw_address (priv->parent);
return parent_mac && nm_utils_hwaddr_matches (setting_mac, -1, parent_mac, -1);
}
diff --git a/src/devices/nm-device-vlan.c b/src/devices/nm-device-vlan.c
index 71364658e6..87a36130b8 100644
--- a/src/devices/nm-device-vlan.c
+++ b/src/devices/nm-device-vlan.c
@@ -384,7 +384,7 @@ match_hwaddr (NMDevice *device, NMConnection *connection, gboolean fail_if_no_hw
if (!priv->parent)
return !fail_if_no_hwaddr;
- parent_mac = nm_device_get_permanent_hw_address (priv->parent, FALSE);
+ parent_mac = nm_device_get_permanent_hw_address (priv->parent);
return parent_mac && nm_utils_hwaddr_matches (setting_mac, -1, parent_mac, -1);
}
diff --git a/src/devices/nm-device.c b/src/devices/nm-device.c
index 01581abbac..3ca72ec683 100644
--- a/src/devices/nm-device.c
+++ b/src/devices/nm-device.c
@@ -12001,7 +12001,7 @@ nm_device_hw_addr_set_cloned (NMDevice *self, NMConnection *connection, gboolean
}
if (nm_streq (addr, NM_CLONED_MAC_PERMANENT)) {
- addr = nm_device_get_permanent_hw_address (self, TRUE);
+ addr = nm_device_get_permanent_hw_address (self);
if (!addr)
return FALSE;
priv->hw_addr_type = HW_ADDR_TYPE_PERMANENT;
@@ -12090,19 +12090,11 @@ nm_device_get_permanent_hw_address_full (NMDevice *self, gboolean *out_is_fake)
}
const char *
-nm_device_get_permanent_hw_address (NMDevice *self, gboolean fallback_fake)
+nm_device_get_permanent_hw_address (NMDevice *self)
{
- NMDevicePrivate *priv;
-
g_return_val_if_fail (NM_IS_DEVICE (self), NULL);
- priv = NM_DEVICE_GET_PRIVATE (self);
- if (!priv->hw_addr_perm)
- return NULL;
- if ( priv->hw_addr_perm_fake
- && !fallback_fake)
- return NULL;
- return priv->hw_addr_perm;
+ return NM_DEVICE_GET_PRIVATE (self)->hw_addr_perm;
}
const char *
@@ -12159,7 +12151,7 @@ spec_match_list (NMDevice *self, const GSList *specs)
}
}
- hw_addr_perm = nm_device_get_permanent_hw_address (self, TRUE);
+ hw_addr_perm = nm_device_get_permanent_hw_address (self);
if (hw_addr_perm) {
m = nm_match_spec_hwaddr (specs, hw_addr_perm);
matched = MAX (matched, m);
@@ -12638,10 +12630,15 @@ get_property (GObject *object, guint prop_id,
case PROP_HW_ADDRESS:
g_value_set_string (value, priv->hw_addr);
break;
- case PROP_PERM_HW_ADDRESS:
+ case PROP_PERM_HW_ADDRESS: {
+ const char *perm_hw_addr;
+ gboolean perm_hw_addr_is_fake;
+
+ perm_hw_addr = nm_device_get_permanent_hw_address_full (self, &perm_hw_addr_is_fake);
/* this property is exposed on D-Bus for NMDeviceEthernet and NMDeviceWifi. */
- g_value_set_string (value, nm_device_get_permanent_hw_address (self, FALSE));
+ g_value_set_string (value, perm_hw_addr && !perm_hw_addr_is_fake ? perm_hw_addr : NULL);
break;
+ }
case PROP_HAS_PENDING_ACTION:
g_value_set_boolean (value, nm_device_has_pending_action (self));
break;
diff --git a/src/devices/nm-device.h b/src/devices/nm-device.h
index 9977c7c55e..9d00fc6e10 100644
--- a/src/devices/nm-device.h
+++ b/src/devices/nm-device.h
@@ -362,8 +362,7 @@ guint32 nm_device_get_ip4_route_metric (NMDevice *dev);
guint32 nm_device_get_ip6_route_metric (NMDevice *dev);
const char * nm_device_get_hw_address (NMDevice *dev);
-const char * nm_device_get_permanent_hw_address (NMDevice *dev,
- gboolean fallback_fake);
+const char * nm_device_get_permanent_hw_address (NMDevice *self);
const char * nm_device_get_permanent_hw_address_full (NMDevice *self,
gboolean *out_is_fake);
const char * nm_device_get_initial_hw_address (NMDevice *dev);
diff --git a/src/devices/wifi/nm-device-wifi.c b/src/devices/wifi/nm-device-wifi.c
index 320d3a1c55..8381aaccb3 100644
--- a/src/devices/wifi/nm-device-wifi.c
+++ b/src/devices/wifi/nm-device-wifi.c
@@ -603,7 +603,7 @@ check_connection_compatible (NMDevice *device, NMConnection *connection)
if (!s_wireless)
return FALSE;
- perm_hw_addr = nm_device_get_permanent_hw_address (device, FALSE);
+ perm_hw_addr = nm_device_get_permanent_hw_address (device);
mac = nm_setting_wireless_get_mac_address (s_wireless);
if (perm_hw_addr) {
if (mac && !nm_utils_hwaddr_matches (mac, -1, perm_hw_addr, -1))
@@ -895,7 +895,7 @@ complete_connection (NMDevice *device,
if (hidden)
g_object_set (s_wifi, NM_SETTING_WIRELESS_HIDDEN, TRUE, NULL);
- perm_hw_addr = nm_device_get_permanent_hw_address (device, FALSE);
+ perm_hw_addr = nm_device_get_permanent_hw_address (device);
if (perm_hw_addr) {
setting_mac = nm_setting_wireless_get_mac_address (s_wifi);
if (setting_mac) {
diff --git a/src/nm-config.c b/src/nm-config.c
index 7f22b54f74..3f492026a1 100644
--- a/src/nm-config.c
+++ b/src/nm-config.c
@@ -400,7 +400,7 @@ nm_config_set_no_auto_default_for_device (NMConfig *self, NMDevice *device)
priv = NM_CONFIG_GET_PRIVATE (self);
- hw_address = nm_device_get_permanent_hw_address (device, TRUE);
+ hw_address = nm_device_get_permanent_hw_address (device);
if (!hw_address)
return;
diff --git a/src/nm-manager.c b/src/nm-manager.c
index adfdc17420..34b6b2d3cd 100644
--- a/src/nm-manager.c
+++ b/src/nm-manager.c
@@ -613,7 +613,7 @@ find_device_by_permanent_hw_addr (NMManager *manager, const char *hwaddr)
if (nm_utils_hwaddr_valid (hwaddr, -1)) {
for (iter = NM_MANAGER_GET_PRIVATE (manager)->devices; iter; iter = iter->next) {
- device_addr = nm_device_get_permanent_hw_address (NM_DEVICE (iter->data), FALSE);
+ device_addr = nm_device_get_permanent_hw_address (NM_DEVICE (iter->data));
if (device_addr && nm_utils_hwaddr_matches (hwaddr, -1, device_addr, -1))
return NM_DEVICE (iter->data);
}
diff --git a/src/settings/nm-settings.c b/src/settings/nm-settings.c
index 385a917f62..ff7fea0152 100644
--- a/src/settings/nm-settings.c
+++ b/src/settings/nm-settings.c
@@ -1883,7 +1883,7 @@ have_connection_for_device (NMSettings *self, NMDevice *device)
g_return_val_if_fail (NM_IS_SETTINGS (self), FALSE);
- perm_hw_addr = nm_device_get_permanent_hw_address (device, FALSE);
+ perm_hw_addr = nm_device_get_permanent_hw_address (device);
/* Find a wired connection locked to the given MAC address, if any */
g_hash_table_iter_init (&iter, priv->connections);