From 5993ee8a8a4338bc8b8e1e836c1abae8882283c9 Mon Sep 17 00:00:00 2001 From: Wen Liang Date: Tue, 17 Dec 2024 14:40:59 -0500 Subject: [PATCH] nm-dhcp-client: add argument controlling whether to get next or current lease In the scenario for sending the release message, we need to guarantee that NM only sends the release message when the client received a lease from the server. However, there is some distinction between the `l3cd_curr` and `l3cd_next` when ACD is pending, because `l3cd_curr` is NULL but `l3cd_next` is not NULL when ACD is pending. Regardless of whether ACD is pending or completed, these are all considered the client have received the release from the server. Therefore, adapt the function `nm_dhcp_client_get_lease()` to control whether to get next or current lease. --- src/core/devices/nm-device.c | 2 +- src/core/dhcp/nm-dhcp-client.c | 19 +++++++++++++++++-- src/core/dhcp/nm-dhcp-client.h | 2 +- 3 files changed, 19 insertions(+), 4 deletions(-) diff --git a/src/core/devices/nm-device.c b/src/core/devices/nm-device.c index b7896fdc0b..45170d31ba 100644 --- a/src/core/devices/nm-device.c +++ b/src/core/devices/nm-device.c @@ -11617,7 +11617,7 @@ _dev_ipdhcpx_start(NMDevice *self, int addr_family) /* Take the NML3ConfigData from the previous lease (if any) that was passed to the NMDhcpClient. * This may be the old lease only used during the duration of a reapply until we get the * new lease. */ - previous_lease = nm_dhcp_client_get_lease(priv->ipdhcp_data_x[IS_IPv4].client); + previous_lease = nm_dhcp_client_get_lease(priv->ipdhcp_data_x[IS_IPv4].client, TRUE); if (!priv->ipdhcp_data_x[IS_IPv4].config) { priv->ipdhcp_data_x[IS_IPv4].config = nm_dhcp_config_new(addr_family, previous_lease); diff --git a/src/core/dhcp/nm-dhcp-client.c b/src/core/dhcp/nm-dhcp-client.c index f50a8e9fda..18ad4024b4 100644 --- a/src/core/dhcp/nm-dhcp-client.c +++ b/src/core/dhcp/nm-dhcp-client.c @@ -280,10 +280,25 @@ nm_dhcp_client_create_options_dict(NMDhcpClient *self, gboolean static_keys) return options; } +/** + * nm_dhcp_client_get_lease(): + * @self: the client + * @ignore_acd_pending: FALSE means to only return the lease that already + * passed ACD, thus it is in use by us. TRUE means to return a new lease + * that might still be pending of Address Collision Detection (ACD) check, + * if there is one, or return the current lease that passed ACD if not. + * + * Returns the current lease that passed ACD or a pending lease still under + * ACD check. + * + */ const NML3ConfigData * -nm_dhcp_client_get_lease(NMDhcpClient *self) +nm_dhcp_client_get_lease(NMDhcpClient *self, gboolean ignore_acd_pending) { - return NM_DHCP_CLIENT_GET_PRIVATE(self)->l3cd_curr; + if (ignore_acd_pending) + return NM_DHCP_CLIENT_GET_PRIVATE(self)->l3cd_curr; + else + return NM_DHCP_CLIENT_GET_PRIVATE(self)->l3cd_next; } /*****************************************************************************/ diff --git a/src/core/dhcp/nm-dhcp-client.h b/src/core/dhcp/nm-dhcp-client.h index 431d08f383..f26d88d86f 100644 --- a/src/core/dhcp/nm-dhcp-client.h +++ b/src/core/dhcp/nm-dhcp-client.h @@ -246,7 +246,7 @@ const NMDhcpClientConfig *nm_dhcp_client_get_config(NMDhcpClient *self); pid_t nm_dhcp_client_get_pid(NMDhcpClient *self); -const NML3ConfigData *nm_dhcp_client_get_lease(NMDhcpClient *self); +const NML3ConfigData *nm_dhcp_client_get_lease(NMDhcpClient *self, gboolean ignore_acd_pending); void nm_dhcp_client_stop(NMDhcpClient *self, gboolean release);