From 00525ff9beb3f339dad942b6501feea3f15980d8 Mon Sep 17 00:00:00 2001 From: Beniamino Galvani Date: Fri, 16 Feb 2024 11:19:40 +0100 Subject: [PATCH] dhcp: remove l3cds when the lease expires When the lease is lost, NM tries to get a new by restarting the DHCP transaction. However, it doesn't delete the existing l3cds (one from the DHCP client with flag ONLY_FOR_ACD, the other from NMDevice). Therefore, the l3cfg still tracks the ACD state of the address as "external-removed", and when NM gets the same address via DHCP, ACD is considered as failed; as a consequence, NM sends a DECLINE message to the server. Moreover, the l3cd added by NMDevice for DHCP has a zero ACD timeout, and so it's not possible to do ACD again on the same address. Remove those l3cds when the lease expires, so that any ACD state is cleared and DHCP can perform ACD again. Fixes: 240ec7f89119 ('dhcp: implement ACD (address collision detection) for DHCPv4') https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/1853 (cherry picked from commit a80fef9f37c890947f9d4f90965341a1d6cc8516) (cherry picked from commit fe734c5c1142d9b780be1ffa56c65923a0763e1f) --- src/core/devices/nm-device.c | 9 +++++++++ src/core/dhcp/nm-dhcp-client.c | 6 ++++++ 2 files changed, 15 insertions(+) diff --git a/src/core/devices/nm-device.c b/src/core/devices/nm-device.c index 50761f29ad..85e7b5ea9e 100644 --- a/src/core/devices/nm-device.c +++ b/src/core/devices/nm-device.c @@ -10587,7 +10587,16 @@ _dev_ipdhcpx_notify(NMDhcpClient *client, const NMDhcpClientNotifyData *notify_d case NM_DHCP_CLIENT_NOTIFY_TYPE_LEASE_UPDATE: if (!notify_data->lease_update.l3cd) { + const NML3ConfigData *dhcp_l3cd = priv->l3cds[L3_CONFIG_DATA_TYPE_DHCP_X(IS_IPv4)].d; + _LOGT_ipdhcp(addr_family, "lease lost"); + if (dhcp_l3cd + && nm_l3cfg_remove_config( + priv->l3cfg, + _dev_l3_config_data_tag_get(priv, L3_CONFIG_DATA_TYPE_DHCP_X(IS_IPv4)), + dhcp_l3cd)) { + _dev_l3_cfg_commit(self, FALSE); + } goto lease_update_out; } diff --git a/src/core/dhcp/nm-dhcp-client.c b/src/core/dhcp/nm-dhcp-client.c index 4be03f4bab..8770656b73 100644 --- a/src/core/dhcp/nm-dhcp-client.c +++ b/src/core/dhcp/nm-dhcp-client.c @@ -899,6 +899,12 @@ _nm_dhcp_client_notify(NMDhcpClient *self, l3_cfg_notify_check_connected(self); + if (!priv->l3cd_curr) { + /* When the lease is lost, any cached ACD information is no longer relevant. + * Remove it so that it doesn't interfere with a new lease we might get. */ + _acd_state_reset(self, TRUE, TRUE); + } + _emit_notify(self, NM_DHCP_CLIENT_NOTIFY_TYPE_LEASE_UPDATE, .lease_update = {