device: leave device up when setting it as unmanaged by user

Before, setting a device to unmanaged causes it to go down and clear
the interface state.

It may be useful to instruct NetworkManager not to touch the device
anymore but leave the current state up. Changing behavior for

  nmcli device set "$DEV" managed no

To get the previous behavior, one has to first disconnect the interface
via

  nmcli device disconnect "$DEV"
  nmcli device set "$DEV" managed no

Note that non-permanent addresses like from DHCP will eventually time
out because NetworkManager stops the DHCP client. When instructing
NetworkManager to let go of the device, you have to take it over in
any way you see fit.

https://bugzilla.redhat.com/show_bug.cgi?id=1371433
(cherry picked from commit 9e8218f99a)
This commit is contained in:
Thomas Haller
2017-04-18 14:46:27 +02:00
parent 6d3ce7557e
commit 785b51ed02
2 changed files with 12 additions and 3 deletions

View File

@@ -11984,7 +11984,7 @@ nm_device_cleanup (NMDevice *self, NMDeviceStateReason reason, CleanupType clean
if (NM_DEVICE_GET_CLASS (self)->deactivate) if (NM_DEVICE_GET_CLASS (self)->deactivate)
NM_DEVICE_GET_CLASS (self)->deactivate (self); NM_DEVICE_GET_CLASS (self)->deactivate (self);
if (cleanup_type != CLEANUP_TYPE_KEEP) { if (cleanup_type == CLEANUP_TYPE_DECONFIGURE) {
/* master: release slaves */ /* master: release slaves */
nm_device_master_release_slaves (self); nm_device_master_release_slaves (self);
@@ -12379,6 +12379,7 @@ _set_state_full (NMDevice *self,
req = nm_g_object_ref (priv->act_request); req = nm_g_object_ref (priv->act_request);
if ( state > NM_DEVICE_STATE_UNMANAGED if ( state > NM_DEVICE_STATE_UNMANAGED
&& state <= NM_DEVICE_STATE_ACTIVATED
&& nm_device_state_reason_check (reason) == NM_DEVICE_STATE_REASON_NOW_MANAGED && nm_device_state_reason_check (reason) == NM_DEVICE_STATE_REASON_NOW_MANAGED
&& NM_IN_SET_TYPED (NMDeviceSysIfaceState, && NM_IN_SET_TYPED (NMDeviceSysIfaceState,
priv->sys_iface_state, priv->sys_iface_state,
@@ -13845,8 +13846,10 @@ set_property (GObject *object, guint prop_id,
managed = g_value_get_boolean (value); managed = g_value_get_boolean (value);
if (managed) if (managed)
reason = NM_DEVICE_STATE_REASON_CONNECTION_ASSUMED; reason = NM_DEVICE_STATE_REASON_CONNECTION_ASSUMED;
else else {
reason = NM_DEVICE_STATE_REASON_REMOVED; reason = NM_DEVICE_STATE_REASON_REMOVED;
nm_device_sys_iface_state_set (self, NM_DEVICE_SYS_IFACE_STATE_REMOVED);
}
nm_device_set_unmanaged_by_flags (self, nm_device_set_unmanaged_by_flags (self,
NM_UNMANAGED_USER_EXPLICIT, NM_UNMANAGED_USER_EXPLICIT,
!managed, !managed,

View File

@@ -34,6 +34,12 @@ typedef enum {
NM_DEVICE_SYS_IFACE_STATE_EXTERNAL, NM_DEVICE_SYS_IFACE_STATE_EXTERNAL,
NM_DEVICE_SYS_IFACE_STATE_ASSUME, NM_DEVICE_SYS_IFACE_STATE_ASSUME,
NM_DEVICE_SYS_IFACE_STATE_MANAGED, NM_DEVICE_SYS_IFACE_STATE_MANAGED,
/* the REMOVED state applies when the device is manually set to unmanaged
* or the link was externally removed. In both cases, we move the device
* to UNMANAGED state, without touching the link -- be it, because the link
* is already gone or because we want to release it (give it up).
*/
NM_DEVICE_SYS_IFACE_STATE_REMOVED, NM_DEVICE_SYS_IFACE_STATE_REMOVED,
} NMDeviceSysIfaceState; } NMDeviceSysIfaceState;