device: delay evaluating unmanaged-by-user-settings flags until link initialized

Before the link is initialized, that is before UDEV completed
initializing the device, we should not evaluate the user-settings
unmanaged flags.

The reason is, that evaluating it likely involves looking at the
permanent MAC address, which might use the wrong fake MAC address
(before UDEV set the right one). Also, it might use the wrong ifname
to lookup the permanent MAC address via ethtool.
This commit is contained in:
Thomas Haller 2016-10-25 15:27:57 +02:00
parent 7b7c653c4f
commit c0d249b733
3 changed files with 40 additions and 16 deletions

View file

@ -1874,7 +1874,7 @@ device_link_changed (NMDevice *self)
ip_ifname_changed = !priv->ip_iface;
if (nm_device_get_unmanaged_flags (self, NM_UNMANAGED_PLATFORM_INIT))
nm_device_set_unmanaged_by_user_settings (self, nm_settings_get_unmanaged_specs (priv->settings));
nm_device_set_unmanaged_by_user_settings (self);
else
update_unmanaged_specs = TRUE;
@ -1953,7 +1953,7 @@ device_link_changed (NMDevice *self)
}
if (update_unmanaged_specs)
nm_device_set_unmanaged_by_user_settings (self, nm_settings_get_unmanaged_specs (priv->settings));
nm_device_set_unmanaged_by_user_settings (self);
if ( got_hw_addr
&& !priv->up
@ -9938,6 +9938,21 @@ _set_unmanaged_flags (NMDevice *self,
allow_state_transition = FALSE;
was_managed = allow_state_transition && nm_device_get_managed (self, FALSE);
if ( NM_FLAGS_HAS (priv->unmanaged_flags, NM_UNMANAGED_PLATFORM_INIT)
&& NM_FLAGS_HAS (flags, NM_UNMANAGED_PLATFORM_INIT)
&& NM_IN_SET (set_op, NM_UNMAN_FLAG_OP_SET_MANAGED)) {
/* we are clearing the platform-init flags. This triggers additional actions. */
if (!NM_FLAGS_HAS (flags, NM_UNMANAGED_USER_SETTINGS)) {
gboolean unmanaged;
unmanaged = nm_device_spec_match_list (self,
nm_settings_get_unmanaged_specs (NM_DEVICE_GET_PRIVATE (self)->settings));
nm_device_set_unmanaged_flags (self,
NM_UNMANAGED_USER_SETTINGS,
!!unmanaged);
}
}
old_flags = priv->unmanaged_flags;
old_mask = priv->unmanaged_mask;
@ -10052,20 +10067,30 @@ nm_device_set_unmanaged_by_flags_queue (NMDevice *self,
}
void
nm_device_set_unmanaged_by_user_settings (NMDevice *self, const GSList *unmanaged_specs)
nm_device_set_unmanaged_by_user_settings (NMDevice *self)
{
NMDevicePrivate *priv;
gboolean unmanaged;
g_return_if_fail (NM_IS_DEVICE (self));
priv = NM_DEVICE_GET_PRIVATE (self);
if (nm_device_get_unmanaged_flags (self, NM_UNMANAGED_PLATFORM_INIT)) {
/* the device is already unmanaged due to platform-init.
*
* We want to delay evaluating the device spec, because it will freeze
* the permanent MAC address. That should not be done, before the platform
* link is fully initialized (via UDEV).
*
* Note that when clearing NM_UNMANAGED_PLATFORM_INIT, we will re-evaluate
* whether the device is unmanaged by user-settings. */
return;
}
unmanaged = nm_device_spec_match_list (self, unmanaged_specs);
unmanaged = nm_device_spec_match_list (self,
nm_settings_get_unmanaged_specs (NM_DEVICE_GET_PRIVATE (self)->settings));
nm_device_set_unmanaged_by_flags (self,
NM_UNMANAGED_USER_SETTINGS,
unmanaged,
!!unmanaged,
unmanaged
? NM_DEVICE_STATE_REASON_NOW_UNMANAGED
: NM_DEVICE_STATE_REASON_NOW_MANAGED);

View file

@ -508,7 +508,7 @@ void nm_device_set_unmanaged_by_flags_queue (NMDevice *self,
NMUnmanagedFlags flags,
NMUnmanFlagOp set_op,
NMDeviceStateReason reason);
void nm_device_set_unmanaged_by_user_settings (NMDevice *self, const GSList *unmanaged_specs);
void nm_device_set_unmanaged_by_user_settings (NMDevice *self);
void nm_device_set_unmanaged_by_user_udev (NMDevice *self);
void nm_device_set_unmanaged_by_quitting (NMDevice *device);

View file

@ -1331,11 +1331,10 @@ system_unmanaged_devices_changed_cb (NMSettings *settings,
{
NMManager *self = NM_MANAGER (user_data);
NMManagerPrivate *priv = NM_MANAGER_GET_PRIVATE (self);
const GSList *unmanaged_specs, *iter;
const GSList *iter;
unmanaged_specs = nm_settings_get_unmanaged_specs (priv->settings);
for (iter = priv->devices; iter; iter = g_slist_next (iter))
nm_device_set_unmanaged_by_user_settings (NM_DEVICE (iter->data), unmanaged_specs);
nm_device_set_unmanaged_by_user_settings (NM_DEVICE (iter->data));
}
static void
@ -2004,7 +2003,7 @@ add_device (NMManager *self, NMDevice *device, GError **error)
type_desc = nm_device_get_type_desc (device);
g_assert (type_desc);
nm_device_set_unmanaged_by_user_settings (device, nm_settings_get_unmanaged_specs (priv->settings));
nm_device_set_unmanaged_by_user_settings (device);
nm_device_set_unmanaged_flags (device,
NM_UNMANAGED_SLEEPING,
@ -2880,15 +2879,15 @@ unmanaged_to_disconnected (NMDevice *device)
if (nm_device_get_state (device) == NM_DEVICE_STATE_UNMANAGED) {
nm_device_state_changed (device,
NM_DEVICE_STATE_UNAVAILABLE,
NM_DEVICE_STATE_REASON_USER_REQUESTED);
NM_DEVICE_STATE_UNAVAILABLE,
NM_DEVICE_STATE_REASON_USER_REQUESTED);
}
if ( nm_device_is_available (device, NM_DEVICE_CHECK_DEV_AVAILABLE_FOR_USER_REQUEST)
&& (nm_device_get_state (device) == NM_DEVICE_STATE_UNAVAILABLE)) {
nm_device_state_changed (device,
NM_DEVICE_STATE_DISCONNECTED,
NM_DEVICE_STATE_REASON_USER_REQUESTED);
NM_DEVICE_STATE_DISCONNECTED,
NM_DEVICE_STATE_REASON_USER_REQUESTED);
}
}