From 59be16b91a8a817b372b019ca0db53a329a7414f Mon Sep 17 00:00:00 2001 From: Friedrich Altheide Date: Tue, 1 Apr 2025 18:30:01 +0200 Subject: [PATCH] device: renew dhcp lease only if carrier was down Make sure nm_device_update_dynamic_ip_setup is called every time a carrier was down before and the link is now up again. Previously the dhcp lease was not renewed if the carrier went down and then up again quickly enough. This led to cases where an old IP was retained even though the device was connected to a different network with a different DHCP server. This commit introduces device_link_carrier_changed_down Fixes: d6429d3ddbc7 ('device: ensure DHCP is restarted every time the link goes up') (cherry picked from commit 163c2574d885a2983702612788b3458c3d6ecc0d) --- src/core/devices/nm-device.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/core/devices/nm-device.c b/src/core/devices/nm-device.c index 4c1cc4160b..6acf3eb377 100644 --- a/src/core/devices/nm-device.c +++ b/src/core/devices/nm-device.c @@ -603,6 +603,7 @@ typedef struct _NMDevicePrivate { bool is_attached : 1; + bool device_link_carrier_changed_down : 1; bool device_link_changed_down : 1; bool concheck_rp_filter_checked : 1; @@ -7559,10 +7560,12 @@ device_link_changed(gpointer user_data) gboolean carrier_was_up; gboolean update_unmanaged_specs = FALSE; gboolean got_hw_addr = FALSE, had_hw_addr; + gboolean carrier_seen_down = priv->device_link_carrier_changed_down; gboolean seen_down = priv->device_link_changed_down; - priv->device_link_changed_id = 0; - priv->device_link_changed_down = FALSE; + priv->device_link_changed_id = 0; + priv->device_link_changed_down = FALSE; + priv->device_link_carrier_changed_down = FALSE; ifindex = nm_device_get_ifindex(self); if (ifindex <= 0) @@ -7713,7 +7716,8 @@ device_link_changed(gpointer user_data) if (priv->state >= NM_DEVICE_STATE_IP_CONFIG && priv->state <= NM_DEVICE_STATE_ACTIVATED && !nm_device_managed_type_is_external(self)) nm_device_l3cfg_commit(self, NM_L3_CFG_COMMIT_TYPE_REAPPLY, FALSE); - + } + if (priv->carrier && (!carrier_was_up || carrier_seen_down)) { /* If the device is active without a carrier (probably because it is * tagged for carrier ignore) ensure that when the carrier appears we * renew DHCP leases and such. @@ -7804,6 +7808,8 @@ link_changed_cb(NMPlatform *platform, priv = NM_DEVICE_GET_PRIVATE(self); if (ifindex == nm_device_get_ifindex(self)) { + if (!(pllink->n_ifi_flags & IFF_LOWER_UP)) + priv->device_link_carrier_changed_down = TRUE; if (!(pllink->n_ifi_flags & IFF_UP)) priv->device_link_changed_down = TRUE; if (!priv->device_link_changed_id) {