summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDan Williams <dcbw@redhat.com>2014-11-03 18:12:25 -0600
committerDan Williams <dcbw@redhat.com>2014-11-07 12:18:33 -0600
commit034917e1299513ebcdd3ecbfb9d4c0adb5a641f5 (patch)
tree54addb81aa34a6af2b6b5ff2a119d9c77af6468d
parente43174f368f4cb319897626207afea30f5896147 (diff)
downloadNetworkManager-034917e1299513ebcdd3ecbfb9d4c0adb5a641f5.tar.gz
dhcp: preserve hostname for later use
-rw-r--r--src/dhcp-manager/nm-dhcp-client.c18
-rw-r--r--src/dhcp-manager/nm-dhcp-client.h6
-rw-r--r--src/dhcp-manager/nm-dhcp-dhclient.c11
-rw-r--r--src/dhcp-manager/nm-dhcp-dhcpcd.c10
-rw-r--r--src/dhcp-manager/nm-dhcp-systemd.c7
5 files changed, 31 insertions, 21 deletions
diff --git a/src/dhcp-manager/nm-dhcp-client.c b/src/dhcp-manager/nm-dhcp-client.c
index f455efa732..69ed1120d6 100644
--- a/src/dhcp-manager/nm-dhcp-client.c
+++ b/src/dhcp-manager/nm-dhcp-client.c
@@ -46,6 +46,7 @@ typedef struct {
guint32 timeout;
GByteArray * duid;
GBytes * client_id;
+ char * hostname;
NMDhcpState state;
pid_t pid;
@@ -167,6 +168,14 @@ nm_dhcp_client_set_client_id (NMDhcpClient *self, GBytes *client_id)
priv->client_id = client_id ? g_bytes_ref (client_id) : NULL;
}
+const char *
+nm_dhcp_client_get_hostname (NMDhcpClient *self)
+{
+ g_return_val_if_fail (NM_IS_DHCP_CLIENT (self), NULL);
+
+ return NM_DHCP_CLIENT_GET_PRIVATE (self)->hostname;
+}
+
/********************************************/
static const char *state_table[NM_DHCP_STATE_MAX + 1] = {
@@ -400,7 +409,10 @@ nm_dhcp_client_start_ip4 (NMDhcpClient *self,
nm_dhcp_client_set_client_id (self, dhcp_client_id ? nm_dhcp_utils_client_id_string_to_bytes (dhcp_client_id) : NULL);
- return NM_DHCP_CLIENT_GET_CLASS (self)->ip4_start (self, dhcp_anycast_addr, hostname);
+ g_clear_pointer (&priv->hostname, g_free);
+ priv->hostname = g_strdup (hostname);
+
+ return NM_DHCP_CLIENT_GET_CLASS (self)->ip4_start (self, dhcp_anycast_addr);
}
/* uuid_parse does not work for machine-id, so we use our own converter */
@@ -544,6 +556,9 @@ nm_dhcp_client_start_ip6 (NMDhcpClient *self,
g_free (str);
}
+ g_clear_pointer (&priv->hostname, g_free);
+ priv->hostname = g_strdup (hostname);
+
priv->info_only = info_only;
nm_log_info (LOGD_DHCP, "Activation (%s) Beginning DHCPv6 transaction (timeout in %d seconds)",
@@ -551,7 +566,6 @@ nm_dhcp_client_start_ip6 (NMDhcpClient *self,
return NM_DHCP_CLIENT_GET_CLASS (self)->ip6_start (self,
dhcp_anycast_addr,
- hostname,
info_only,
privacy,
priv->duid);
diff --git a/src/dhcp-manager/nm-dhcp-client.h b/src/dhcp-manager/nm-dhcp-client.h
index fda14cf4a5..5651c52025 100644
--- a/src/dhcp-manager/nm-dhcp-client.h
+++ b/src/dhcp-manager/nm-dhcp-client.h
@@ -64,12 +64,10 @@ typedef struct {
/* Methods */
gboolean (*ip4_start) (NMDhcpClient *self,
- const char *anycast_addr,
- const char *hostname);
+ const char *anycast_addr);
gboolean (*ip6_start) (NMDhcpClient *self,
const char *anycast_addr,
- const char *hostname,
gboolean info_only,
NMSettingIP6ConfigPrivacy privacy,
const GByteArray *duid);
@@ -127,6 +125,8 @@ guint32 nm_dhcp_client_get_priority (NMDhcpClient *self);
GBytes *nm_dhcp_client_get_client_id (NMDhcpClient *self);
+const char *nm_dhcp_client_get_hostname (NMDhcpClient *self);
+
gboolean nm_dhcp_client_start_ip4 (NMDhcpClient *self,
const char *dhcp_client_id,
const char *dhcp_anycast_addr,
diff --git a/src/dhcp-manager/nm-dhcp-dhclient.c b/src/dhcp-manager/nm-dhcp-dhclient.c
index 76e8d68c2c..c953c80d21 100644
--- a/src/dhcp-manager/nm-dhcp-dhclient.c
+++ b/src/dhcp-manager/nm-dhcp-dhclient.c
@@ -477,19 +477,18 @@ dhclient_start (NMDhcpClient *client,
}
static gboolean
-ip4_start (NMDhcpClient *client,
- const char *dhcp_anycast_addr,
- const char *hostname)
+ip4_start (NMDhcpClient *client, const char *dhcp_anycast_addr)
{
NMDhcpDhclientPrivate *priv = NM_DHCP_DHCLIENT_GET_PRIVATE (client);
GBytes *client_id;
gs_unref_bytes GBytes *new_client_id = NULL;
- const char *iface, *uuid;
+ const char *iface, *uuid, *hostname;
gboolean success = FALSE;
iface = nm_dhcp_client_get_iface (client);
uuid = nm_dhcp_client_get_uuid (client);
client_id = nm_dhcp_client_get_client_id (client);
+ hostname = nm_dhcp_client_get_hostname (client);
priv->conf_file = create_dhclient_config (iface, FALSE, uuid, client_id, dhcp_anycast_addr, hostname, &new_client_id);
if (priv->conf_file) {
@@ -505,16 +504,16 @@ ip4_start (NMDhcpClient *client,
static gboolean
ip6_start (NMDhcpClient *client,
const char *dhcp_anycast_addr,
- const char *hostname,
gboolean info_only,
NMSettingIP6ConfigPrivacy privacy,
const GByteArray *duid)
{
NMDhcpDhclientPrivate *priv = NM_DHCP_DHCLIENT_GET_PRIVATE (client);
- const char *iface, *uuid;
+ const char *iface, *uuid, *hostname;
iface = nm_dhcp_client_get_iface (client);
uuid = nm_dhcp_client_get_uuid (client);
+ hostname = nm_dhcp_client_get_hostname (client);
priv->conf_file = create_dhclient_config (iface, TRUE, uuid, NULL, dhcp_anycast_addr, hostname, NULL);
if (!priv->conf_file) {
diff --git a/src/dhcp-manager/nm-dhcp-dhcpcd.c b/src/dhcp-manager/nm-dhcp-dhcpcd.c
index 5a3aee3f4d..a39f953dbe 100644
--- a/src/dhcp-manager/nm-dhcp-dhcpcd.c
+++ b/src/dhcp-manager/nm-dhcp-dhcpcd.c
@@ -73,16 +73,14 @@ dhcpcd_child_setup (gpointer user_data G_GNUC_UNUSED)
}
static gboolean
-ip4_start (NMDhcpClient *client,
- const char *dhcp_anycast_addr,
- const char *hostname)
+ip4_start (NMDhcpClient *client, const char *dhcp_anycast_addr)
{
NMDhcpDhcpcdPrivate *priv = NM_DHCP_DHCPCD_GET_PRIVATE (client);
GPtrArray *argv = NULL;
pid_t pid = -1;
GError *error = NULL;
char *pid_contents = NULL, *binary_name, *cmd_str;
- const char *iface, *dhcpcd_path = NULL;
+ const char *iface, *dhcpcd_path, *hostname;
g_return_val_if_fail (priv->pid_file == NULL, FALSE);
@@ -129,7 +127,8 @@ ip4_start (NMDhcpClient *client,
g_ptr_array_add (argv, (gpointer) "-4");
#endif
- if (hostname && strlen (hostname)) {
+ hostname = nm_dhcp_client_get_hostname (client);
+ if (hostname) {
g_ptr_array_add (argv, (gpointer) "-h"); /* Send hostname to DHCP server */
g_ptr_array_add (argv, (gpointer) hostname );
}
@@ -160,7 +159,6 @@ ip4_start (NMDhcpClient *client,
static gboolean
ip6_start (NMDhcpClient *client,
const char *dhcp_anycast_addr,
- const char *hostname,
gboolean info_only,
NMSettingIP6ConfigPrivacy privacy,
const GByteArray *duid)
diff --git a/src/dhcp-manager/nm-dhcp-systemd.c b/src/dhcp-manager/nm-dhcp-systemd.c
index 35b08a1d3b..6d5204c8d9 100644
--- a/src/dhcp-manager/nm-dhcp-systemd.c
+++ b/src/dhcp-manager/nm-dhcp-systemd.c
@@ -515,9 +515,7 @@ get_arp_type (const GByteArray *hwaddr)
}
static gboolean
-ip4_start (NMDhcpClient *client,
- const char *dhcp_anycast_addr,
- const char *hostname)
+ip4_start (NMDhcpClient *client, const char *dhcp_anycast_addr)
{
NMDhcpSystemdPrivate *priv = NM_DHCP_SYSTEMD_GET_PRIVATE (client);
const char *iface = nm_dhcp_client_get_iface (client);
@@ -527,6 +525,7 @@ ip4_start (NMDhcpClient *client,
const uint8_t *client_id = NULL;
size_t client_id_len = 0;
struct in_addr last_addr;
+ const char *hostname;
int r, i;
g_assert (priv->client4 == NULL);
@@ -621,6 +620,7 @@ ip4_start (NMDhcpClient *client,
sd_dhcp_client_set_request_option (priv->client4, dhcp4_requests[i].num);
}
+ hostname = nm_dhcp_client_get_hostname (client);
if (hostname) {
r = sd_dhcp_client_set_hostname (priv->client4, hostname);
if (r < 0) {
@@ -683,7 +683,6 @@ dhcp6_event_cb (sd_dhcp6_client *client, int event, gpointer user_data)
static gboolean
ip6_start (NMDhcpClient *client,
const char *dhcp_anycast_addr,
- const char *hostname,
gboolean info_only,
NMSettingIP6ConfigPrivacy privacy,
const GByteArray *duid)