From 1db882ca63a577fd0d7adeb3af9f9bcaefe290bf Mon Sep 17 00:00:00 2001 From: Beniamino Galvani Date: Tue, 8 Oct 2024 11:30:20 +0200 Subject: [PATCH] dhcp: allow the plugin to be restarted In the next commit, a mechanism will be added to stop the DHCP plugin and restart it without destroying the NMDhcpClient object. For this to work, we must reset some members of the object when stopping or starting the plugin. --- src/core/dhcp/nm-dhcp-client.c | 5 +++-- src/core/dhcp/nm-dhcp-nettools.c | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/core/dhcp/nm-dhcp-client.c b/src/core/dhcp/nm-dhcp-client.c index 66466e61b5..6ff3245cb9 100644 --- a/src/core/dhcp/nm-dhcp-client.c +++ b/src/core/dhcp/nm-dhcp-client.c @@ -1360,6 +1360,8 @@ nm_dhcp_client_start(NMDhcpClient *self, GError **error) g_return_val_if_fail(priv->config.uuid, FALSE); nm_assert(!priv->effective_client_id); + priv->is_stopped = FALSE; + IS_IPv4 = NM_IS_IPv4(priv->config.addr_family); if (!IS_IPv4) { @@ -1473,6 +1475,7 @@ nm_dhcp_client_stop(NMDhcpClient *self, gboolean release) if (priv->is_stopped) return; + nm_clear_pointer(&priv->effective_client_id, g_bytes_unref); nm_clear_g_source_inst(&priv->previous_lease_timeout_source); priv->is_stopped = TRUE; @@ -1980,8 +1983,6 @@ dispose(GObject *object) nm_clear_g_source_inst(&priv->v6.dad_timeout_source); } - nm_clear_pointer(&priv->effective_client_id, g_bytes_unref); - nm_assert(!priv->watch_source); nm_assert(!priv->l3cd_next); nm_assert(!priv->l3cd_curr); diff --git a/src/core/dhcp/nm-dhcp-nettools.c b/src/core/dhcp/nm-dhcp-nettools.c index 9ac3b6f291..829a6726a6 100644 --- a/src/core/dhcp/nm-dhcp-nettools.c +++ b/src/core/dhcp/nm-dhcp-nettools.c @@ -1323,7 +1323,7 @@ ip4_start(NMDhcpClient *client, GError **error) g_return_val_if_fail(!priv->probe, FALSE); g_return_val_if_fail(client_config, FALSE); - if (!nettools_create(self, &effective_client_id, error)) + if (!priv->client && !nettools_create(self, &effective_client_id, error)) return FALSE; r = n_dhcp4_client_probe_config_new(&config);