summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Haller <thaller@redhat.com>2022-12-12 20:38:34 +0100
committerThomas Haller <thaller@redhat.com>2022-12-19 11:29:12 +0100
commit84b90fbdd38aa6b39a7ac018e9216aecbb6f298c (patch)
treec9be9b868850d848d5504265649b01163147bcf0
parentbea72c3d6de5a294a89fc659e475fe9db0abf6ac (diff)
downloadNetworkManager-84b90fbdd38aa6b39a7ac018e9216aecbb6f298c.tar.gz
dhcp: set effective-client-id for all DHCP plugins
-rw-r--r--src/core/dhcp/nm-dhcp-client.c2
-rw-r--r--src/core/dhcp/nm-dhcp-dhclient.c10
-rw-r--r--src/core/dhcp/nm-dhcp-nettools.c15
-rw-r--r--src/core/dhcp/nm-dhcp-systemd.c2
4 files changed, 19 insertions, 10 deletions
diff --git a/src/core/dhcp/nm-dhcp-client.c b/src/core/dhcp/nm-dhcp-client.c
index 3674198a21..c450f355a5 100644
--- a/src/core/dhcp/nm-dhcp-client.c
+++ b/src/core/dhcp/nm-dhcp-client.c
@@ -256,7 +256,7 @@ nm_dhcp_client_set_effective_client_id(NMDhcpClient *self, GBytes *client_id)
g_bytes_unref(priv->effective_client_id);
priv->effective_client_id = nm_g_bytes_ref(client_id);
- _LOGT("%s: set %s",
+ _LOGT("%s: set effective %s",
priv->config.addr_family == AF_INET6 ? "duid" : "client-id",
priv->effective_client_id
? (tmp_str = nm_dhcp_utils_duid_to_string(priv->effective_client_id))
diff --git a/src/core/dhcp/nm-dhcp-dhclient.c b/src/core/dhcp/nm-dhcp-dhclient.c
index 34aa7d44e0..8c762a5ccc 100644
--- a/src/core/dhcp/nm-dhcp-dhclient.c
+++ b/src/core/dhcp/nm-dhcp-dhclient.c
@@ -554,11 +554,11 @@ ip4_start(NMDhcpClient *client, GError **error)
return FALSE;
}
- if (new_client_id) {
- nm_assert(!client_config->client_id);
- nm_dhcp_client_set_effective_client_id(client, new_client_id);
- }
- return dhclient_start(client, FALSE, FALSE, NULL, error);
+ /* Note that the effective-client-id for IPv4 here might be unknown/NULL. */
+ nm_assert(!new_client_id || !client_config->client_id);
+ nm_dhcp_client_set_effective_client_id(client, client_config->client_id ?: new_client_id);
+
+ return dhclient_start(client, FALSE, FALSE, FALSE, NULL, error);
}
static gboolean
diff --git a/src/core/dhcp/nm-dhcp-nettools.c b/src/core/dhcp/nm-dhcp-nettools.c
index 51729ecdda..12f5620547 100644
--- a/src/core/dhcp/nm-dhcp-nettools.c
+++ b/src/core/dhcp/nm-dhcp-nettools.c
@@ -1098,7 +1098,7 @@ dhcp4_event_cb(int fd, GIOCondition condition, gpointer user_data)
}
static gboolean
-nettools_create(NMDhcpNettools *self, GError **error)
+nettools_create(NMDhcpNettools *self, GBytes **out_effective_client_id, GError **error)
{
NMDhcpNettoolsPrivate *priv = NM_DHCP_NETTOOLS_GET_PRIVATE(self);
nm_auto(n_dhcp4_client_config_freep) NDhcp4ClientConfig *config = NULL;
@@ -1195,6 +1195,9 @@ nettools_create(NMDhcpNettools *self, GError **error)
priv->event_source = nm_g_unix_fd_add_source(fd, G_IO_IN, dhcp4_event_cb, self);
+ *out_effective_client_id =
+ (client_id == client_id_new) ? g_steal_pointer(&client_id_new) : g_bytes_ref(client_id);
+
return TRUE;
}
@@ -1285,8 +1288,9 @@ static gboolean
ip4_start(NMDhcpClient *client, GError **error)
{
nm_auto(n_dhcp4_client_probe_config_freep) NDhcp4ClientProbeConfig *config = NULL;
- NMDhcpNettools *self = NM_DHCP_NETTOOLS(client);
- NMDhcpNettoolsPrivate *priv = NM_DHCP_NETTOOLS_GET_PRIVATE(self);
+ NMDhcpNettools *self = NM_DHCP_NETTOOLS(client);
+ NMDhcpNettoolsPrivate *priv = NM_DHCP_NETTOOLS_GET_PRIVATE(self);
+ gs_unref_bytes GBytes *effective_client_id = NULL;
const NMDhcpClientConfig *client_config;
gs_free char *lease_file = NULL;
struct in_addr last_addr = {0};
@@ -1297,7 +1301,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, error))
+ if (!nettools_create(self, &effective_client_id, error))
return FALSE;
r = n_dhcp4_client_probe_config_new(&config);
@@ -1443,6 +1447,9 @@ ip4_start(NMDhcpClient *client, GError **error)
}
_LOGT("dhcp-client4: start " NM_HASH_OBFUSCATE_PTR_FMT, NM_HASH_OBFUSCATE_PTR(priv->client));
+
+ nm_dhcp_client_set_effective_client_id(client, effective_client_id);
+
return TRUE;
}
diff --git a/src/core/dhcp/nm-dhcp-systemd.c b/src/core/dhcp/nm-dhcp-systemd.c
index 3b6ba96d48..af7f6c3244 100644
--- a/src/core/dhcp/nm-dhcp-systemd.c
+++ b/src/core/dhcp/nm-dhcp-systemd.c
@@ -379,6 +379,8 @@ ip6_start(NMDhcpClient *client, const struct in6_addr *ll_addr, GError **error)
return FALSE;
}
+ nm_dhcp_client_set_effective_client_id(client, duid);
+
return TRUE;
}