From a245554984ef281c8f5ba8be5d8db3d60b304a19 Mon Sep 17 00:00:00 2001 From: Francesco Giudici Date: Mon, 11 Sep 2017 16:11:57 +0200 Subject: [PATCH 1/2] dhcp: consider a timeout equal to MAXINT32 as infinity This will avoid to spawn internally a timer for the lease to complete. --- src/dhcp/nm-dhcp-client.c | 15 ++++++++++++--- src/dhcp/nm-dhcp-client.h | 2 ++ 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/src/dhcp/nm-dhcp-client.c b/src/dhcp/nm-dhcp-client.c index e9e67565d..afa6b6a73 100644 --- a/src/dhcp/nm-dhcp-client.c +++ b/src/dhcp/nm-dhcp-client.c @@ -404,6 +404,10 @@ nm_dhcp_client_start_timeout (NMDhcpClient *self) /* Set up a timeout on the transaction to kill it after the timeout */ g_assert (priv->timeout_id == 0); + + if (priv->timeout == NM_DHCP_TIMEOUT_INFINITY) + return; + priv->timeout_id = g_timeout_add_seconds (priv->timeout, transaction_timeout, self); @@ -441,7 +445,10 @@ nm_dhcp_client_start_ip4 (NMDhcpClient *self, g_return_val_if_fail (priv->addr_family == AF_INET, FALSE); g_return_val_if_fail (priv->uuid != NULL, FALSE); - _LOGI ("activation: beginning transaction (timeout in %u seconds)", (guint) priv->timeout); + if (priv->timeout == NM_DHCP_TIMEOUT_INFINITY) + _LOGI ("activation: beginning transaction (no timeout)"); + else + _LOGI ("activation: beginning transaction (timeout in %u seconds)", (guint) priv->timeout); if (dhcp_client_id) tmp = nm_dhcp_utils_client_id_string_to_bytes (dhcp_client_id); @@ -556,8 +563,10 @@ nm_dhcp_client_start_ip6 (NMDhcpClient *self, priv->info_only = info_only; - _LOGI ("activation: beginning transaction (timeout in %u seconds)", - (guint) priv->timeout); + if (priv->timeout == NM_DHCP_TIMEOUT_INFINITY) + _LOGI ("activation: beginning transaction (no timeout)"); + else + _LOGI ("activation: beginning transaction (timeout in %u seconds)", (guint) priv->timeout); return NM_DHCP_CLIENT_GET_CLASS (self)->ip6_start (self, dhcp_anycast_addr, diff --git a/src/dhcp/nm-dhcp-client.h b/src/dhcp/nm-dhcp-client.h index 38f9c6de1..91dc2299b 100644 --- a/src/dhcp/nm-dhcp-client.h +++ b/src/dhcp/nm-dhcp-client.h @@ -25,6 +25,7 @@ #include "nm-ip6-config.h" #define NM_DHCP_TIMEOUT_DEFAULT ((guint32) 45) /* default DHCP timeout, in seconds */ +#define NM_DHCP_TIMEOUT_INFINITY G_MAXINT32 #define NM_TYPE_DHCP_CLIENT (nm_dhcp_client_get_type ()) #define NM_DHCP_CLIENT(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), NM_TYPE_DHCP_CLIENT, NMDhcpClient)) @@ -45,6 +46,7 @@ #define NM_DHCP_CLIENT_SIGNAL_STATE_CHANGED "state-changed" #define NM_DHCP_CLIENT_SIGNAL_PREFIX_DELEGATED "prefix-delegated" + typedef enum { NM_DHCP_STATE_UNKNOWN = 0, NM_DHCP_STATE_BOUND, /* new lease or lease changed */ From e04c9af5fddb0c2e159206af1c5464117ed8bfbc Mon Sep 17 00:00:00 2001 From: Francesco Giudici Date: Mon, 11 Sep 2017 18:22:11 +0200 Subject: [PATCH 2/2] nmcli: allow to set dhcp-timeout as "infinity" DHCP timeout may now be explicitly disabled by setting the ipv[4,6].dhcp-timeout options to "infinity". This will set the DHCP timeout value to MAXINT32. --- clients/common/nm-meta-setting-desc.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/clients/common/nm-meta-setting-desc.c b/clients/common/nm-meta-setting-desc.c index 4a4eb13ab..6a9ad8e34 100644 --- a/clients/common/nm-meta-setting-desc.c +++ b/clients/common/nm-meta-setting-desc.c @@ -5364,6 +5364,19 @@ static const NMMetaPropertyInfo *const property_infos_IP4_CONFIG[] = { ), PROPERTY_INFO (NM_SETTING_IP_CONFIG_DHCP_TIMEOUT, DESCRIBE_DOC_NM_SETTING_IP4_CONFIG_DHCP_TIMEOUT, .property_type = &_pt_gobject_int, + .property_typ_data = DEFINE_PROPERTY_TYP_DATA_SUBTYPE (gobject_int, + .value_infos = INT_VALUE_INFOS ( + { + .value = 0, + .nick = "default", + }, + { + .value = G_MAXINT32, + .nick = "infinity", + } + ), + ), + ), PROPERTY_INFO (NM_SETTING_IP_CONFIG_DHCP_SEND_HOSTNAME, DESCRIBE_DOC_NM_SETTING_IP4_CONFIG_DHCP_SEND_HOSTNAME, .property_type = &_pt_gobject_bool,