Beniamino Galvani
2023-05-15 10:12:21 +02:00
3 changed files with 39 additions and 3 deletions

View File

@@ -570,6 +570,8 @@ typedef struct _NMDevicePrivate {
NMDeviceSysIfaceState sys_iface_state_; NMDeviceSysIfaceState sys_iface_state_;
}; };
NMDeviceSysIfaceState sys_iface_state_before_sleep;
bool carrier : 1; bool carrier : 1;
bool ignore_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); 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 static void
_active_connection_set_state_flags_full(NMDevice *self, _active_connection_set_state_flags_full(NMDevice *self,
NMActivationStateFlags flags, NMActivationStateFlags flags,
@@ -17961,7 +17979,11 @@ nm_device_init(NMDevice *self)
priv->unmanaged_mask = priv->unmanaged_flags; priv->unmanaged_mask = priv->unmanaged_flags;
priv->available_connections = g_hash_table_new_full(nm_direct_hash, NULL, g_object_unref, NULL); 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->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; priv->promisc_reset = NM_OPTION_BOOL_DEFAULT;
} }

View File

@@ -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_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_state_changed(NMDevice *device, NMDeviceState state, NMDeviceStateReason reason);
void nm_device_queue_state(NMDevice *self, NMDeviceState state, NMDeviceStateReason reason); void nm_device_queue_state(NMDevice *self, NMDeviceState state, NMDeviceStateReason reason);

View File

@@ -7089,6 +7089,8 @@ do_sleep_wake(NMManager *self, gboolean sleeping_changed)
continue; continue;
} }
nm_device_notify_sleeping(device);
if (nm_device_is_activating(device) if (nm_device_is_activating(device)
|| nm_device_get_state(device) == NM_DEVICE_STATE_ACTIVATED) { || nm_device_get_state(device) == NM_DEVICE_STATE_ACTIVATED) {
_LOGD(LOGD_SUSPEND, _LOGD(LOGD_SUSPEND,
@@ -7145,7 +7147,8 @@ do_sleep_wake(NMManager *self, gboolean sleeping_changed)
/* Re-manage managed devices */ /* Re-manage managed devices */
c_list_for_each_entry (device, &priv->devices_lst_head, devices_lst) { c_list_for_each_entry (device, &priv->devices_lst_head, devices_lst) {
guint i; NMDeviceStateReason reason;
guint i;
if (nm_device_is_software(device) if (nm_device_is_software(device)
&& !nm_device_get_unmanaged_flags(device, NM_UNMANAGED_SLEEPING)) { && !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); 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_device_set_unmanaged_by_flags(device,
NM_UNMANAGED_SLEEPING, NM_UNMANAGED_SLEEPING,
NM_UNMAN_FLAG_OP_SET_MANAGED, NM_UNMAN_FLAG_OP_SET_MANAGED,
NM_DEVICE_STATE_REASON_CONNECTION_ASSUMED); reason);
} }
/* Give the connections a chance to recreate the virtual devices. /* Give the connections a chance to recreate the virtual devices.