dhcp: set effective-client-id for all DHCP plugins

This commit is contained in:
Thomas Haller
2022-12-12 20:38:34 +01:00
parent bea72c3d6d
commit 84b90fbdd3
4 changed files with 19 additions and 10 deletions

View File

@@ -256,7 +256,7 @@ nm_dhcp_client_set_effective_client_id(NMDhcpClient *self, GBytes *client_id)
g_bytes_unref(priv->effective_client_id); g_bytes_unref(priv->effective_client_id);
priv->effective_client_id = nm_g_bytes_ref(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->config.addr_family == AF_INET6 ? "duid" : "client-id",
priv->effective_client_id priv->effective_client_id
? (tmp_str = nm_dhcp_utils_duid_to_string(priv->effective_client_id)) ? (tmp_str = nm_dhcp_utils_duid_to_string(priv->effective_client_id))

View File

@@ -554,11 +554,11 @@ ip4_start(NMDhcpClient *client, GError **error)
return FALSE; return FALSE;
} }
if (new_client_id) { /* Note that the effective-client-id for IPv4 here might be unknown/NULL. */
nm_assert(!client_config->client_id); nm_assert(!new_client_id || !client_config->client_id);
nm_dhcp_client_set_effective_client_id(client, new_client_id); nm_dhcp_client_set_effective_client_id(client, client_config->client_id ?: new_client_id);
}
return dhclient_start(client, FALSE, FALSE, NULL, error); return dhclient_start(client, FALSE, FALSE, FALSE, NULL, error);
} }
static gboolean static gboolean

View File

@@ -1098,7 +1098,7 @@ dhcp4_event_cb(int fd, GIOCondition condition, gpointer user_data)
} }
static gboolean 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); NMDhcpNettoolsPrivate *priv = NM_DHCP_NETTOOLS_GET_PRIVATE(self);
nm_auto(n_dhcp4_client_config_freep) NDhcp4ClientConfig *config = NULL; 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); 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; return TRUE;
} }
@@ -1285,8 +1288,9 @@ static gboolean
ip4_start(NMDhcpClient *client, GError **error) ip4_start(NMDhcpClient *client, GError **error)
{ {
nm_auto(n_dhcp4_client_probe_config_freep) NDhcp4ClientProbeConfig *config = NULL; nm_auto(n_dhcp4_client_probe_config_freep) NDhcp4ClientProbeConfig *config = NULL;
NMDhcpNettools *self = NM_DHCP_NETTOOLS(client); NMDhcpNettools *self = NM_DHCP_NETTOOLS(client);
NMDhcpNettoolsPrivate *priv = NM_DHCP_NETTOOLS_GET_PRIVATE(self); NMDhcpNettoolsPrivate *priv = NM_DHCP_NETTOOLS_GET_PRIVATE(self);
gs_unref_bytes GBytes *effective_client_id = NULL;
const NMDhcpClientConfig *client_config; const NMDhcpClientConfig *client_config;
gs_free char *lease_file = NULL; gs_free char *lease_file = NULL;
struct in_addr last_addr = {0}; 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(!priv->probe, FALSE);
g_return_val_if_fail(client_config, FALSE); g_return_val_if_fail(client_config, FALSE);
if (!nettools_create(self, error)) if (!nettools_create(self, &effective_client_id, error))
return FALSE; return FALSE;
r = n_dhcp4_client_probe_config_new(&config); 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)); _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; return TRUE;
} }

View File

@@ -379,6 +379,8 @@ ip6_start(NMDhcpClient *client, const struct in6_addr *ll_addr, GError **error)
return FALSE; return FALSE;
} }
nm_dhcp_client_set_effective_client_id(client, duid);
return TRUE; return TRUE;
} }