mirror of
https://gitlab.freedesktop.org/NetworkManager/NetworkManager.git
synced 2025-12-27 10:30:13 +01:00
dhcp: inject client-id in GBytes format from NMDevice to nm_dhcp_manager_start_ip4()
Convert the string representation of ipv4.dhcp-client-id property already in NMDevice to a GBytes. Next, we will support more client ID modes, and we will need the NMDevice context to generate the client id.
This commit is contained in:
parent
578c4af907
commit
7de078a394
6 changed files with 38 additions and 25 deletions
|
|
@ -48,6 +48,7 @@
|
|||
#include "ndisc/nm-ndisc.h"
|
||||
#include "ndisc/nm-lndp-ndisc.h"
|
||||
#include "dhcp/nm-dhcp-manager.h"
|
||||
#include "dhcp/nm-dhcp-utils.h"
|
||||
#include "nm-act-request.h"
|
||||
#include "nm-proxy-config.h"
|
||||
#include "nm-ip4-config.h"
|
||||
|
|
@ -6392,12 +6393,27 @@ get_dhcp_timeout (NMDevice *self, int addr_family)
|
|||
return timeout ?: NM_DHCP_TIMEOUT_DEFAULT;
|
||||
}
|
||||
|
||||
static GBytes *
|
||||
dhcp4_get_client_id (NMDevice *self, NMConnection *connection)
|
||||
{
|
||||
NMSettingIPConfig *s_ip4;
|
||||
const char *client_id;
|
||||
|
||||
s_ip4 = nm_connection_get_setting_ip4_config (connection);
|
||||
client_id = nm_setting_ip4_config_get_dhcp_client_id (NM_SETTING_IP4_CONFIG (s_ip4));
|
||||
|
||||
return client_id
|
||||
? nm_dhcp_utils_client_id_string_to_bytes (client_id)
|
||||
: NULL;
|
||||
}
|
||||
|
||||
static NMActStageReturn
|
||||
dhcp4_start (NMDevice *self)
|
||||
{
|
||||
NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE (self);
|
||||
NMSettingIPConfig *s_ip4;
|
||||
gs_unref_bytes GBytes *hwaddr = NULL;
|
||||
gs_unref_bytes GBytes *client_id = NULL;
|
||||
NMConnection *connection;
|
||||
|
||||
connection = nm_device_get_applied_connection (self);
|
||||
|
|
@ -6412,7 +6428,8 @@ dhcp4_start (NMDevice *self)
|
|||
hwaddr = nm_platform_link_get_address_as_bytes (nm_device_get_platform (self),
|
||||
nm_device_get_ip_ifindex (self));
|
||||
|
||||
/* Begin DHCP on the interface */
|
||||
client_id = dhcp4_get_client_id (self, connection);
|
||||
|
||||
g_warn_if_fail (priv->dhcp4.client == NULL);
|
||||
priv->dhcp4.client = nm_dhcp_manager_start_ip4 (nm_dhcp_manager_get (),
|
||||
nm_netns_get_multi_idx (nm_device_get_netns (self)),
|
||||
|
|
@ -6425,7 +6442,7 @@ dhcp4_start (NMDevice *self)
|
|||
nm_setting_ip_config_get_dhcp_send_hostname (s_ip4),
|
||||
nm_setting_ip_config_get_dhcp_hostname (s_ip4),
|
||||
nm_setting_ip4_config_get_dhcp_fqdn (NM_SETTING_IP4_CONFIG (s_ip4)),
|
||||
nm_setting_ip4_config_get_dhcp_client_id (NM_SETTING_IP4_CONFIG (s_ip4)),
|
||||
client_id,
|
||||
get_dhcp_timeout (self, AF_INET),
|
||||
priv->dhcp_anycast_address,
|
||||
NULL);
|
||||
|
|
|
|||
|
|
@ -239,20 +239,6 @@ nm_dhcp_client_set_client_id_bin (NMDhcpClient *self,
|
|||
_set_client_id (self, b, TRUE);
|
||||
}
|
||||
|
||||
void
|
||||
nm_dhcp_client_set_client_id_str (NMDhcpClient *self,
|
||||
const char *dhcp_client_id)
|
||||
{
|
||||
g_return_if_fail (NM_IS_DHCP_CLIENT (self));
|
||||
g_return_if_fail (!dhcp_client_id || dhcp_client_id[0]);
|
||||
|
||||
_set_client_id (self,
|
||||
dhcp_client_id
|
||||
? nm_dhcp_utils_client_id_string_to_bytes (dhcp_client_id)
|
||||
: NULL,
|
||||
TRUE);
|
||||
}
|
||||
|
||||
const char *
|
||||
nm_dhcp_client_get_hostname (NMDhcpClient *self)
|
||||
{
|
||||
|
|
@ -500,7 +486,7 @@ nm_dhcp_client_watch_child (NMDhcpClient *self, pid_t pid)
|
|||
|
||||
gboolean
|
||||
nm_dhcp_client_start_ip4 (NMDhcpClient *self,
|
||||
const char *dhcp_client_id,
|
||||
GBytes *client_id,
|
||||
const char *dhcp_anycast_addr,
|
||||
const char *hostname,
|
||||
const char *last_ip4_address)
|
||||
|
|
@ -519,7 +505,7 @@ nm_dhcp_client_start_ip4 (NMDhcpClient *self,
|
|||
else
|
||||
_LOGI ("activation: beginning transaction (timeout in %u seconds)", (guint) priv->timeout);
|
||||
|
||||
nm_dhcp_client_set_client_id_str (self, dhcp_client_id);
|
||||
nm_dhcp_client_set_client_id (self, client_id);
|
||||
|
||||
g_clear_pointer (&priv->hostname, g_free);
|
||||
priv->hostname = g_strdup (hostname);
|
||||
|
|
|
|||
|
|
@ -144,7 +144,7 @@ gboolean nm_dhcp_client_get_info_only (NMDhcpClient *self);
|
|||
gboolean nm_dhcp_client_get_use_fqdn (NMDhcpClient *self);
|
||||
|
||||
gboolean nm_dhcp_client_start_ip4 (NMDhcpClient *self,
|
||||
const char *dhcp_client_id,
|
||||
GBytes *client_id,
|
||||
const char *dhcp_anycast_addr,
|
||||
const char *hostname,
|
||||
const char *last_ip4_address);
|
||||
|
|
@ -185,8 +185,6 @@ void nm_dhcp_client_set_client_id_bin (NMDhcpClient *self,
|
|||
guint8 type,
|
||||
const guint8 *client_id,
|
||||
gsize len);
|
||||
void nm_dhcp_client_set_client_id_str (NMDhcpClient *self,
|
||||
const char *dhcp_client_id);
|
||||
|
||||
/*****************************************************************************
|
||||
* Client data
|
||||
|
|
|
|||
|
|
@ -163,7 +163,7 @@ client_start (NMDhcpManager *self,
|
|||
guint32 route_table,
|
||||
guint32 route_metric,
|
||||
const struct in6_addr *ipv6_ll_addr,
|
||||
const char *dhcp_client_id,
|
||||
GBytes *dhcp_client_id,
|
||||
guint32 timeout,
|
||||
const char *dhcp_anycast_addr,
|
||||
const char *hostname,
|
||||
|
|
@ -181,6 +181,7 @@ client_start (NMDhcpManager *self,
|
|||
g_return_val_if_fail (NM_IS_DHCP_MANAGER (self), NULL);
|
||||
g_return_val_if_fail (ifindex > 0, NULL);
|
||||
g_return_val_if_fail (uuid != NULL, NULL);
|
||||
g_return_val_if_fail (!dhcp_client_id || g_bytes_get_size (dhcp_client_id) >= 2, NULL);
|
||||
|
||||
priv = NM_DHCP_MANAGER_GET_PRIVATE (self);
|
||||
|
||||
|
|
@ -240,7 +241,7 @@ nm_dhcp_manager_start_ip4 (NMDhcpManager *self,
|
|||
gboolean send_hostname,
|
||||
const char *dhcp_hostname,
|
||||
const char *dhcp_fqdn,
|
||||
const char *dhcp_client_id,
|
||||
GBytes *dhcp_client_id,
|
||||
guint32 timeout,
|
||||
const char *dhcp_anycast_addr,
|
||||
const char *last_ip_address)
|
||||
|
|
|
|||
|
|
@ -56,7 +56,7 @@ NMDhcpClient * nm_dhcp_manager_start_ip4 (NMDhcpManager *manager,
|
|||
gboolean send_hostname,
|
||||
const char *dhcp_hostname,
|
||||
const char *dhcp_fqdn,
|
||||
const char *dhcp_client_id,
|
||||
GBytes *dhcp_client_id,
|
||||
guint32 timeout,
|
||||
const char *dhcp_anycast_addr,
|
||||
const char *last_ip_address);
|
||||
|
|
|
|||
|
|
@ -341,6 +341,7 @@ main (int argc, char *argv[])
|
|||
gs_unref_object NMDhcpClient *dhcp4_client = NULL;
|
||||
gs_unref_object NMNDisc *ndisc = NULL;
|
||||
gs_unref_bytes GBytes *hwaddr = NULL;
|
||||
gs_unref_bytes GBytes *client_id = NULL;
|
||||
gs_free NMUtilsIPv6IfaceId *iid = NULL;
|
||||
guint sd_id;
|
||||
char sysctl_path_buf[NM_UTILS_SYSCTL_IP_CONF_PATH_BUFSIZE];
|
||||
|
|
@ -441,6 +442,16 @@ main (int argc, char *argv[])
|
|||
iid = g_bytes_unref_to_data (bytes, &ignored);
|
||||
}
|
||||
|
||||
if (global_opt.dhcp4_clientid) {
|
||||
/* this string is just a plain hex-string. Unlike ipv4.dhcp-client-id, which
|
||||
* is parsed via nm_dhcp_utils_client_id_string_to_bytes(). */
|
||||
client_id = nm_utils_hexstr2bin (global_opt.dhcp4_clientid);
|
||||
if (!client_id || g_bytes_get_size (client_id) < 2) {
|
||||
fprintf (stderr, _("(%s): Invalid DHCP client-id %s\n"), global_opt.ifname, global_opt.dhcp4_clientid);
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
if (global_opt.dhcp4_address) {
|
||||
nm_platform_sysctl_set (NM_PLATFORM_GET, NMP_SYSCTL_PATHID_ABSOLUTE (nm_utils_sysctl_ip_conf_path (AF_INET, sysctl_path_buf, global_opt.ifname, "promote_secondaries")), "1");
|
||||
|
||||
|
|
@ -455,7 +466,7 @@ main (int argc, char *argv[])
|
|||
!!global_opt.dhcp4_hostname,
|
||||
global_opt.dhcp4_hostname,
|
||||
global_opt.dhcp4_fqdn,
|
||||
global_opt.dhcp4_clientid,
|
||||
client_id,
|
||||
NM_DHCP_TIMEOUT_DEFAULT,
|
||||
NULL,
|
||||
global_opt.dhcp4_address);
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue