From f6d6a7e2eb924b9b5addebedd8b6ed9b96d44377 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=8D=C3=B1igo=20Huguet?= Date: Mon, 15 Sep 2025 15:05:36 +0200 Subject: [PATCH] core, libnm: add the "networking off" reason When we disable networking with `nmcli networking off` the reason that is logged is "sleeping". Explain instead that networking is disabled. Before: device (lo): state change: activated -> deactivating (reason 'sleeping' ... After: device (lo): state change: activated -> deactivating (reason 'networking-off' ... --- src/core/devices/nm-device-utils.c | 3 ++- src/core/nm-manager.c | 18 +++++++++++------- src/libnm-core-public/nm-dbus-interface.h | 3 ++- src/libnmc-base/nm-client-utils.c | 1 + 4 files changed, 16 insertions(+), 9 deletions(-) diff --git a/src/core/devices/nm-device-utils.c b/src/core/devices/nm-device-utils.c index 9fd7ac9dbf..61d8066a61 100644 --- a/src/core/devices/nm-device-utils.c +++ b/src/core/devices/nm-device-utils.c @@ -141,7 +141,8 @@ NM_UTILS_LOOKUP_STR_DEFINE( "unmanaged-user-explicit"), NM_UTILS_LOOKUP_STR_ITEM(NM_DEVICE_STATE_REASON_UNMANAGED_USER_SETTINGS, "unmanaged-user-settings"), - NM_UTILS_LOOKUP_STR_ITEM(NM_DEVICE_STATE_REASON_UNMANAGED_USER_UDEV, "unmanaged-user-udev"), ); + NM_UTILS_LOOKUP_STR_ITEM(NM_DEVICE_STATE_REASON_UNMANAGED_USER_UDEV, "unmanaged-user-udev"), + NM_UTILS_LOOKUP_STR_ITEM(NM_DEVICE_STATE_REASON_NETWORKING_OFF, "networking-off"), ); NM_UTILS_LOOKUP_STR_DEFINE(nm_device_mtu_source_to_string, NMDeviceMtuSource, diff --git a/src/core/nm-manager.c b/src/core/nm-manager.c index 6ebeb086d9..b614ec6a36 100644 --- a/src/core/nm-manager.c +++ b/src/core/nm-manager.c @@ -7324,24 +7324,26 @@ _handle_device_takedown(NMManager *self, gboolean suspending, gboolean is_shutdown) { + gboolean is_sleep = suspending || is_shutdown; + NMDeviceStateReason reason = + is_sleep ? NM_DEVICE_STATE_REASON_SLEEPING : NM_DEVICE_STATE_REASON_NETWORKING_OFF; + nm_device_notify_sleeping(device); if (nm_device_is_activating(device) || nm_device_get_state(device) == NM_DEVICE_STATE_ACTIVATED) { - _LOGD(LOGD_SUSPEND, + _LOGD(is_sleep ? LOGD_SUSPEND : LOGD_CORE, "%s: wait disconnection of device %s", - is_shutdown ? "shutdown" : "sleep", + is_sleep ? (is_shutdown ? "shutdown" : "sleep") : "networking off", nm_device_get_ip_iface(device)); if (sleep_devices_add(self, device, suspending)) - nm_device_queue_state(device, - NM_DEVICE_STATE_DEACTIVATING, - NM_DEVICE_STATE_REASON_SLEEPING); + nm_device_queue_state(device, NM_DEVICE_STATE_DEACTIVATING, reason); } else { nm_device_set_unmanaged_by_flags(device, NM_UNMANAGED_SLEEPING, NM_UNMAN_FLAG_OP_SET_UNMANAGED, - NM_DEVICE_STATE_REASON_SLEEPING); + reason); } } @@ -7431,7 +7433,9 @@ do_sleep_wake(NMManager *self, gboolean sleeping_changed) && !nm_device_get_unmanaged_flags(device, NM_UNMANAGED_SLEEPING)) { /* DHCP leases of software devices could have gone stale * so we need to renew them. */ - nm_device_update_dynamic_ip_setup(device, "wake up"); + nm_device_update_dynamic_ip_setup(device, + waking_from_suspend ? "wake up" + : "networking on"); continue; } diff --git a/src/libnm-core-public/nm-dbus-interface.h b/src/libnm-core-public/nm-dbus-interface.h index 5bbe7f98ee..65b007ccf1 100644 --- a/src/libnm-core-public/nm-dbus-interface.h +++ b/src/libnm-core-public/nm-dbus-interface.h @@ -645,7 +645,7 @@ typedef enum { * via settings plugin ('unmanaged-devices' for keyfile or 'NM_CONTROLLED=no' for ifcfg-rh). * Since: 1.48 * @NM_DEVICE_STATE_REASON_UNMANAGED_USER_UDEV: The device is unmanaged via udev rule. Since: 1.48 - + * @NM_DEVICE_STATE_REASON_NETWORKING_OFF: NetworkManager was disabled (networking off). Since: 1.56 * * Device state change reason codes */ @@ -728,6 +728,7 @@ typedef enum { NM_DEVICE_STATE_REASON_UNMANAGED_USER_EXPLICIT = 75, NM_DEVICE_STATE_REASON_UNMANAGED_USER_SETTINGS = 76, NM_DEVICE_STATE_REASON_UNMANAGED_USER_UDEV = 77, + NM_DEVICE_STATE_REASON_NETWORKING_OFF = 78, } NMDeviceStateReason; /** diff --git a/src/libnmc-base/nm-client-utils.c b/src/libnmc-base/nm-client-utils.c index c036c500e9..858b17b28a 100644 --- a/src/libnmc-base/nm-client-utils.c +++ b/src/libnmc-base/nm-client-utils.c @@ -492,6 +492,7 @@ NM_UTILS_LOOKUP_STR_DEFINE( NM_UTILS_LOOKUP_ITEM(NM_DEVICE_STATE_REASON_UNMANAGED_EXTERNAL_DOWN, N_("The device is unmanaged because it is an external device and is " "unconfigured (down or without addresses)")), + NM_UTILS_LOOKUP_ITEM(NM_DEVICE_STATE_REASON_NETWORKING_OFF, N_("Networking was disabled")), );