diff options
author | Beniamino Galvani <bgalvani@redhat.com> | 2023-05-10 16:28:08 +0200 |
---|---|---|
committer | Beniamino Galvani <bgalvani@redhat.com> | 2023-05-15 10:11:16 +0200 |
commit | 5e3bef6ae9f8441a95767191b829d0d57673506c (patch) | |
tree | 7e7c1f41bd7cf0b2f283420336c048dc7f61302c | |
parent | 1494774bd129ae00f6bdf3a88881952fdf8a10a7 (diff) | |
download | NetworkManager-5e3bef6ae9f8441a95767191b829d0d57673506c.tar.gz |
manager: use the right reason for managing devices after wake/reenablebg/wake-assume-rh2193422
When managing the interface after wake/reenable, the reason determines
whether the device will be sys-iface-state=managed or external.
Commit 5a9a7623c5a4 ('core: set STATE_REASON_CONNECTION_ASSUMED when
waking up') changed the reason from 'now-managed' to
'connection-assumed'; the effect was that devices that were fully
managed before sleeping become external after a wake up. For example:
$ nmcli connection add type ethernet ifname enp1s0
Connection 'ethernet-enp1s0' (47fcd81e-bf00-4c02-b25b-354894f5657e) successfully added.
$ nmcli device | grep enp1s0
enp1s0 ethernet connected ethernet-enp1s0
$ nmcli networking off
$ nmcli device | grep enp1s0
enp1s0 ethernet unmanaged --
$ nmcli networking on
$ nmcli device | grep enp1s0
enp1s0 ethernet unavailable --
Set the correct reason during wake up so that the previous state is
restored.
Fixes: 5a9a7623c5a4 ('core: set STATE_REASON_CONNECTION_ASSUMED when waking up')
https://bugzilla.redhat.com/show_bug.cgi?id=2193422
-rw-r--r-- | src/core/nm-manager.c | 14 |
1 files changed, 12 insertions, 2 deletions
diff --git a/src/core/nm-manager.c b/src/core/nm-manager.c index c6cf2cb943..fc63fbcf04 100644 --- a/src/core/nm-manager.c +++ b/src/core/nm-manager.c @@ -7089,6 +7089,8 @@ do_sleep_wake(NMManager *self, gboolean sleeping_changed) continue; } + nm_device_notify_sleeping(device); + if (nm_device_is_activating(device) || nm_device_get_state(device) == NM_DEVICE_STATE_ACTIVATED) { _LOGD(LOGD_SUSPEND, @@ -7145,7 +7147,8 @@ do_sleep_wake(NMManager *self, gboolean sleeping_changed) /* Re-manage managed devices */ c_list_for_each_entry (device, &priv->devices_lst_head, devices_lst) { - guint i; + NMDeviceStateReason reason; + guint i; if (nm_device_is_software(device) && !nm_device_get_unmanaged_flags(device, NM_UNMANAGED_SLEEPING)) { @@ -7176,10 +7179,17 @@ do_sleep_wake(NMManager *self, gboolean sleeping_changed) nm_device_set_enabled(device, enabled); } + /* The reason determines whether the device will be sys-iface-state=managed + * or sys-iface-state=external. Pass the correct reason to restore the state + * that was set before sleeping. */ + reason = nm_device_get_sys_iface_state_before_sleep(device) + == NM_DEVICE_SYS_IFACE_STATE_EXTERNAL + ? NM_DEVICE_STATE_REASON_CONNECTION_ASSUMED + : NM_DEVICE_STATE_REASON_NOW_MANAGED; nm_device_set_unmanaged_by_flags(device, NM_UNMANAGED_SLEEPING, NM_UNMAN_FLAG_OP_SET_MANAGED, - NM_DEVICE_STATE_REASON_CONNECTION_ASSUMED); + reason); } /* Give the connections a chance to recreate the virtual devices. |