core: rename NM_STATE_ASLEEP to NM_STATE_DISABLED

When we do `nmcli networking off` it's shown as state "sleeping". This
is confusing, and the only reason is that we share internally code to
handle both situations in a similar way.

Rename the state to the more generic name "disabled", situation that can
happen either because of sleeping or networking off.

Clients cannot differentiate the exact reason only with the NMState value,
but better that they show "network off" as this is the most common reason
that they will be able to display. If the system is suspending, there will
be only a short period of time that they can show the state, and showing
"network off" is not wrong because that's what NM has done as a response
to suspend.

In the logs, let's make explicit the exact reason why state is changing
to DISABLED: sleeping or networking off.

Logs before:
  manager: disable requested (sleeping: no  enabled: yes)
  manager: NetworkManager state is now ASLEEP

Logs after:
  manager: disable requested (sleeping: no  enabled: yes)
  manager: NetworkManager state is now DISABLED (NEWORKING OFF)

State before:
  $ nmcli general
  STATE  ...
  asleep ...

State after:
  $ nmcli general
  STATE       ...
  network off ...
This commit is contained in:
Íñigo Huguet 2025-09-15 14:43:22 +02:00
parent c36e0bedeb
commit 3355ba9380
7 changed files with 35 additions and 23 deletions

View file

@ -23,8 +23,8 @@ static const char *
nm_state_to_string(NMState state)
{
switch (state) {
case NM_STATE_ASLEEP:
return "asleep";
case NM_STATE_DISABLED:
return "network off";
case NM_STATE_CONNECTING:
return "connecting";
case NM_STATE_CONNECTED_LOCAL:

View file

@ -1960,7 +1960,7 @@ find_device_by_iface(NMManager *self,
}
static gboolean
manager_sleeping(NMManager *self)
manager_is_disabled(NMManager *self)
{
NMManagerPrivate *priv = NM_MANAGER_GET_PRIVATE(self);
@ -1973,8 +1973,8 @@ static const char *
_nm_state_to_string(NMState state)
{
switch (state) {
case NM_STATE_ASLEEP:
return "ASLEEP";
case NM_STATE_DISABLED:
return "DISABLED";
case NM_STATE_DISCONNECTED:
return "DISCONNECTED";
case NM_STATE_DISCONNECTING:
@ -2078,15 +2078,18 @@ nm_manager_update_state(NMManager *self)
{
NMManagerPrivate *priv;
NMState new_state = NM_STATE_DISCONNECTED;
const char *detail = "";
g_return_if_fail(NM_IS_MANAGER(self));
priv = NM_MANAGER_GET_PRIVATE(self);
if (manager_sleeping(self))
new_state = NM_STATE_ASLEEP;
else
if (manager_is_disabled(self)) {
new_state = NM_STATE_DISABLED;
detail = priv->sleeping ? " (ASLEEP)" : " (NETWORKING OFF)";
} else {
new_state = find_best_device_state(self);
}
if (new_state >= NM_STATE_CONNECTED_LOCAL && priv->connectivity_state == NM_CONNECTIVITY_FULL) {
new_state = NM_STATE_CONNECTED_GLOBAL;
@ -2097,7 +2100,7 @@ nm_manager_update_state(NMManager *self)
priv->state = new_state;
_LOGI(LOGD_CORE, "NetworkManager state is now %s", _nm_state_to_string(new_state));
_LOGI(LOGD_CORE, "NetworkManager state is now %s%s", _nm_state_to_string(new_state), detail);
_notify(self, PROP_STATE);
nm_dbus_object_emit_signal(NM_DBUS_OBJECT(self),
@ -2956,7 +2959,7 @@ _rfkill_update_devices(NMManager *self, NMRfkillType rtype, gboolean enabled)
_notify(self, _rfkill_type_desc[rtype].prop_id);
/* Don't touch devices if asleep/networking disabled */
if (manager_sleeping(self))
if (manager_is_disabled(self))
return;
/* enable/disable wireless devices as required */
@ -3120,7 +3123,7 @@ _rfkill_update_from_user(NMManager *self, NMRfkillType rtype, gboolean enabled)
gboolean old_enabled, new_enabled;
/* Don't touch devices if asleep/networking disabled */
if (manager_sleeping(self))
if (manager_is_disabled(self))
return;
_LOGD(LOGD_RFKILL,
@ -4079,7 +4082,7 @@ add_device(NMManager *self, NMDevice *device, GError **error)
nm_device_set_unmanaged_by_user_settings(device, TRUE);
nm_device_set_unmanaged_flags(device, NM_UNMANAGED_SLEEPING, manager_sleeping(self));
nm_device_set_unmanaged_flags(device, NM_UNMANAGED_SLEEPING, manager_is_disabled(self));
dbus_path = nm_dbus_object_export(NM_DBUS_OBJECT(device));
_LOG2I(LOGD_DEVICE, device, "new %s device (%s)", type_desc, dbus_path);
@ -7352,8 +7355,10 @@ do_sleep_wake(NMManager *self, gboolean sleeping_changed)
suspending = sleeping_changed && priv->sleeping;
waking_from_suspend = sleeping_changed && !priv->sleeping;
if (manager_sleeping(self)) {
_LOGD(LOGD_SUSPEND, "sleep: %s...", suspending ? "sleeping" : "disabling");
if (manager_is_disabled(self)) {
_LOGD(suspending ? LOGD_SUSPEND : LOGD_CORE,
"%s...",
suspending ? "sleep: sleeping" : "networking: disabling");
/* FIXME: are there still hardware devices that need to be disabled around
* suspend/resume?
@ -7379,7 +7384,9 @@ do_sleep_wake(NMManager *self, gboolean sleeping_changed)
_handle_device_takedown(self, device, suspending, FALSE);
}
} else {
_LOGD(LOGD_SUSPEND, "sleep: %s...", waking_from_suspend ? "waking up" : "re-enabling");
_LOGD(waking_from_suspend ? LOGD_SUSPEND : LOGD_CORE,
"%s...",
waking_from_suspend ? "sleep: waking up" : "networking: re-enabling");
sleep_devices_clear(self);

View file

@ -1845,7 +1845,7 @@ nm_policy_device_recheck_auto_activate_schedule(NMPolicy *self, NMDevice *device
priv = NM_POLICY_GET_PRIVATE(self);
if (nm_manager_get_state(priv->manager) == NM_STATE_ASLEEP)
if (nm_manager_get_state(priv->manager) == NM_STATE_DISABLED)
return;
if (!nm_device_autoconnect_allowed(device))

View file

@ -145,8 +145,10 @@ typedef enum {
* and not disable controls that require network access.
* The graphical shells may hide the network accessibility indicator altogether
* since no meaningful status indication can be provided.
* @NM_STATE_ASLEEP: Networking is not enabled, the system is being suspended or
* resumed from suspend.
* @NM_STATE_ASLEEP: Deprecated: 1.56: Use %NM_STATE_DISABLED instead.
* @NM_STATE_DISABLED: NetworkManager is disabled, either because the user requested
* to disable networking or because the system is suspended or resuming from suspend.
* Since: 1.56.
* @NM_STATE_DISCONNECTED: There is no active network connection.
* The graphical shell should indicate no network connectivity and the
* applications should not attempt to access the network.
@ -170,7 +172,8 @@ typedef enum {
**/
typedef enum {
NM_STATE_UNKNOWN = 0,
NM_STATE_ASLEEP = 10,
NM_STATE_ASLEEP = 10, /* Deprecated */
NM_STATE_DISABLED = 10,
NM_STATE_DISCONNECTED = 20,
NM_STATE_DISCONNECTING = 30,
NM_STATE_CONNECTING = 40,

View file

@ -116,7 +116,8 @@ typedef enum {
NM_META_COLOR_PERMISSION_UNKNOWN,
NM_META_COLOR_PERMISSION_YES,
NM_META_COLOR_PROMPT,
NM_META_COLOR_STATE_ASLEEP,
NM_META_COLOR_STATE_DISABLED,
NM_META_COLOR_STATE_ASLEEP = NM_META_COLOR_STATE_DISABLED, /* Deprecated */
NM_META_COLOR_STATE_CONNECTED_GLOBAL,
NM_META_COLOR_STATE_CONNECTED_LOCAL,
NM_META_COLOR_STATE_CONNECTED_SITE,

View file

@ -28,7 +28,7 @@ static void permission_changed(GObject *gobject, GParamSpec *pspec, NmCli *nmc);
static NM_UTILS_LOOKUP_STR_DEFINE(nm_state_to_string,
NMState,
NM_UTILS_LOOKUP_DEFAULT(N_("unknown")),
NM_UTILS_LOOKUP_ITEM(NM_STATE_ASLEEP, N_("asleep")),
NM_UTILS_LOOKUP_ITEM(NM_STATE_DISABLED, N_("network off")),
NM_UTILS_LOOKUP_ITEM(NM_STATE_CONNECTING, N_("connecting")),
NM_UTILS_LOOKUP_ITEM(NM_STATE_CONNECTED_LOCAL,
N_("connected (local only)")),
@ -53,8 +53,8 @@ state_to_color(NMState state)
return NM_META_COLOR_STATE_CONNECTED_GLOBAL;
case NM_STATE_DISCONNECTING:
return NM_META_COLOR_STATE_DISCONNECTING;
case NM_STATE_ASLEEP:
return NM_META_COLOR_STATE_ASLEEP;
case NM_STATE_DISABLED:
return NM_META_COLOR_STATE_DISABLED;
case NM_STATE_DISCONNECTED:
return NM_META_COLOR_STATE_DISCONNECTED;
default:

View file

@ -581,6 +581,7 @@ static NM_UTILS_STRING_TABLE_LOOKUP_DEFINE(
{"permission-unknown", NM_META_COLOR_PERMISSION_UNKNOWN},
{"permission-yes", NM_META_COLOR_PERMISSION_YES},
{"prompt", NM_META_COLOR_PROMPT},
{"state-disabled", NM_META_COLOR_STATE_DISABLED},
{"state-asleep", NM_META_COLOR_STATE_ASLEEP},
{"state-connected-global", NM_META_COLOR_STATE_CONNECTED_GLOBAL},
{"state-connected-local", NM_META_COLOR_STATE_CONNECTED_LOCAL},