summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBeniamino Galvani <bgalvani@redhat.com>2017-05-02 14:26:55 +0200
committerBeniamino Galvani <bgalvani@redhat.com>2017-05-02 15:30:53 +0200
commit82ef497cc9e2728e73cb0426efbae85c83bec3fe (patch)
treece32517e3e411b9ebde95f2d6827aec8dd926c7b
parentd67d12ebe1996a74f33610eaf2d9f46258901c61 (diff)
downloadNetworkManager-82ef497cc9e2728e73cb0426efbae85c83bec3fe.tar.gz
dhcp: dhclient: fix timeout greater than 60 seconds
The default timeout in dhclient is 60 seconds; if a lease can't be obtained during such interval, dhclient sends to NM a FAIL event and then the IP method fails. Thus, even if user specified a greater dhcp-timeout, NM terminated DHCP after 60 seconds. Fix this by passing an explicit timeout to dhclient.
-rw-r--r--src/dhcp/nm-dhcp-client.c8
-rw-r--r--src/dhcp/nm-dhcp-client.h2
-rw-r--r--src/dhcp/nm-dhcp-dhclient.c13
3 files changed, 23 insertions, 0 deletions
diff --git a/src/dhcp/nm-dhcp-client.c b/src/dhcp/nm-dhcp-client.c
index 5a465d8f94..17986aa825 100644
--- a/src/dhcp/nm-dhcp-client.c
+++ b/src/dhcp/nm-dhcp-client.c
@@ -147,6 +147,14 @@ nm_dhcp_client_get_priority (NMDhcpClient *self)
return NM_DHCP_CLIENT_GET_PRIVATE (self)->priority;
}
+guint32
+nm_dhcp_client_get_timeout (NMDhcpClient *self)
+{
+ g_return_val_if_fail (NM_IS_DHCP_CLIENT (self), 0);
+
+ return NM_DHCP_CLIENT_GET_PRIVATE (self)->timeout;
+}
+
GBytes *
nm_dhcp_client_get_client_id (NMDhcpClient *self)
{
diff --git a/src/dhcp/nm-dhcp-client.h b/src/dhcp/nm-dhcp-client.h
index 23ea349e88..d790e3e10a 100644
--- a/src/dhcp/nm-dhcp-client.h
+++ b/src/dhcp/nm-dhcp-client.h
@@ -117,6 +117,8 @@ const GByteArray *nm_dhcp_client_get_hw_addr (NMDhcpClient *self);
guint32 nm_dhcp_client_get_priority (NMDhcpClient *self);
+guint32 nm_dhcp_client_get_timeout (NMDhcpClient *self);
+
GBytes *nm_dhcp_client_get_client_id (NMDhcpClient *self);
const char *nm_dhcp_client_get_hostname (NMDhcpClient *self);
diff --git a/src/dhcp/nm-dhcp-dhclient.c b/src/dhcp/nm-dhcp-dhclient.c
index 64d93744f2..dc66be25dd 100644
--- a/src/dhcp/nm-dhcp-dhclient.c
+++ b/src/dhcp/nm-dhcp-dhclient.c
@@ -342,6 +342,8 @@ dhclient_start (NMDhcpClient *client,
char *binary_name, *cmd_str, *pid_file = NULL, *system_bus_address_env = NULL;
gboolean ipv6, success;
char *escaped, *preferred_leasefile_path = NULL;
+ guint32 timeout;
+ char timeout_str[64];
g_return_val_if_fail (priv->pid_file == NULL, FALSE);
@@ -444,6 +446,17 @@ dhclient_start (NMDhcpClient *client,
g_ptr_array_add (argv, (gpointer) priv->conf_file);
}
+ /* Specify a timeout longer than configuration's one,
+ * so that dhclient doesn't send back a FAIL event before
+ * that time.
+ */
+ timeout = nm_dhcp_client_get_timeout (client);
+ if (timeout >= 60) {
+ timeout = timeout < G_MAXINT32 ? timeout + 1 : G_MAXINT32;
+ g_ptr_array_add (argv, (gpointer) "-timeout");
+ g_ptr_array_add (argv, (gpointer) nm_sprintf_buf (timeout_str, "%u", (unsigned) timeout));
+ }
+
/* Usually the system bus address is well-known; but if it's supposed
* to be something else, we need to push it to dhclient, since dhclient
* sanitizes the environment it gives the action scripts.