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.
This commit is contained in:
Beniamino Galvani 2017-05-02 14:26:55 +02:00
parent d67d12ebe1
commit 82ef497cc9
3 changed files with 23 additions and 0 deletions

View file

@ -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)
{

View file

@ -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);

View file

@ -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.