diff options
author | Beniamino Galvani <bgalvani@redhat.com> | 2023-05-15 10:12:21 +0200 |
---|---|---|
committer | Beniamino Galvani <bgalvani@redhat.com> | 2023-05-15 10:12:21 +0200 |
commit | eb9f3b1e3bcbf29eec8eaaac7866265bbad4a80e (patch) | |
tree | 7e7c1f41bd7cf0b2f283420336c048dc7f61302c | |
parent | fc0fc4ab0dd0f36c39f4633d21599f6cf5468908 (diff) | |
parent | 5e3bef6ae9f8441a95767191b829d0d57673506c (diff) | |
download | NetworkManager-eb9f3b1e3bcbf29eec8eaaac7866265bbad4a80e.tar.gz |
merge: branch 'bg/wake-assume-rh2193422'
https://bugzilla.redhat.com/show_bug.cgi?id=2193422
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/1624
-rw-r--r-- | src/core/devices/nm-device.c | 24 | ||||
-rw-r--r-- | src/core/devices/nm-device.h | 4 | ||||
-rw-r--r-- | src/core/nm-manager.c | 14 |
3 files changed, 39 insertions, 3 deletions
diff --git a/src/core/devices/nm-device.c b/src/core/devices/nm-device.c index 6639492ee5..516fc657a0 100644 --- a/src/core/devices/nm-device.c +++ b/src/core/devices/nm-device.c @@ -570,6 +570,8 @@ typedef struct _NMDevicePrivate { NMDeviceSysIfaceState sys_iface_state_; }; + NMDeviceSysIfaceState sys_iface_state_before_sleep; + bool carrier : 1; bool ignore_carrier : 1; @@ -3052,6 +3054,22 @@ nm_device_sys_iface_state_set(NMDevice *self, NMDeviceSysIfaceState sys_iface_st nm_assert(priv->sys_iface_state == sys_iface_state); } +void +nm_device_notify_sleeping(NMDevice *self) +{ + NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE(self); + + priv->sys_iface_state_before_sleep = priv->sys_iface_state; +} + +NMDeviceSysIfaceState +nm_device_get_sys_iface_state_before_sleep(NMDevice *self) +{ + NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE(self); + + return priv->sys_iface_state_before_sleep; +} + static void _active_connection_set_state_flags_full(NMDevice *self, NMActivationStateFlags flags, @@ -17961,7 +17979,11 @@ nm_device_init(NMDevice *self) priv->unmanaged_mask = priv->unmanaged_flags; priv->available_connections = g_hash_table_new_full(nm_direct_hash, NULL, g_object_unref, NULL); priv->ip6_saved_properties = g_hash_table_new_full(nm_str_hash, g_str_equal, NULL, g_free); - priv->sys_iface_state_ = NM_DEVICE_SYS_IFACE_STATE_EXTERNAL; + + priv->sys_iface_state_ = NM_DEVICE_SYS_IFACE_STATE_EXTERNAL; + /* If networking is already disabled at boot, we want to manage all devices + * after re-enabling networking; hence, the initial state is MANAGED. */ + priv->sys_iface_state_before_sleep = NM_DEVICE_SYS_IFACE_STATE_MANAGED; priv->promisc_reset = NM_OPTION_BOOL_DEFAULT; } diff --git a/src/core/devices/nm-device.h b/src/core/devices/nm-device.h index d32b77dc83..8d8249d1a2 100644 --- a/src/core/devices/nm-device.h +++ b/src/core/devices/nm-device.h @@ -728,6 +728,10 @@ gboolean nm_device_sys_iface_state_is_external_or_assume(NMDevice *self); void nm_device_sys_iface_state_set(NMDevice *device, NMDeviceSysIfaceState sys_iface_state); +void nm_device_notify_sleeping(NMDevice *self); + +NMDeviceSysIfaceState nm_device_get_sys_iface_state_before_sleep(NMDevice *self); + void nm_device_state_changed(NMDevice *device, NMDeviceState state, NMDeviceStateReason reason); void nm_device_queue_state(NMDevice *self, NMDeviceState state, NMDeviceStateReason reason); 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. |