mirror of
https://gitlab.freedesktop.org/NetworkManager/NetworkManager.git
synced 2026-01-07 00:50:16 +01:00
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.
(cherry picked from commit 416164aa29)
This commit is contained in:
parent
bb5ee41dc4
commit
7bb7b17408
10 changed files with 31 additions and 32 deletions
|
|
@ -396,7 +396,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))
|
||||
|
|
@ -1346,6 +1346,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);
|
||||
|
||||
|
|
@ -1373,8 +1374,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 */
|
||||
|
|
@ -1410,7 +1411,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;
|
||||
|
||||
|
|
@ -1470,7 +1471,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;
|
||||
|
|
@ -1489,7 +1491,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;
|
||||
|
|
|
|||
|
|
@ -151,7 +151,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;
|
||||
|
|
@ -188,7 +188,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)) {
|
||||
|
|
@ -214,7 +214,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;
|
||||
|
||||
|
|
|
|||
|
|
@ -373,7 +373,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);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -391,7 +391,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);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -11890,7 +11890,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;
|
||||
|
|
@ -11979,19 +11979,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 *
|
||||
|
|
@ -12048,7 +12040,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);
|
||||
|
|
@ -12522,10 +12514,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;
|
||||
|
|
|
|||
|
|
@ -364,8 +364,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);
|
||||
|
|
|
|||
|
|
@ -615,7 +615,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))
|
||||
|
|
@ -907,7 +907,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) {
|
||||
|
|
|
|||
|
|
@ -399,7 +399,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;
|
||||
|
||||
|
|
|
|||
|
|
@ -610,7 +610,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);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1874,7 +1874,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);
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue