[PATCH] Make DHCP timeout overridable



The OLPC mesh device will want a lower timeout as it probes the various
channels for different connectivity portals.
---
 src/dhcp-manager/nm-dhcp-manager.c |   12 ++++++------
 src/nm-device.c                    |   13 ++++++++++++-
 src/nm-device.h                    |    2 ++
 3 files changed, 20 insertions(+), 7 deletions(-)

For master branch

diff --git a/src/dhcp-manager/nm-dhcp-manager.c b/src/dhcp-manager/nm-dhcp-manager.c
index 66044d7..c068f10 100644
--- a/src/dhcp-manager/nm-dhcp-manager.c
+++ b/src/dhcp-manager/nm-dhcp-manager.c
@@ -508,8 +508,8 @@ nm_dhcp_manager_handle_timeout (gpointer user_data)
 {
 	NMDHCPDevice *device = (NMDHCPDevice *) user_data;
 
-	nm_info ("(%s): DHCP transaction took too long (>%ds), stopping it.",
-			 device->iface, NM_DHCP_TIMEOUT);
+	nm_info ("(%s): DHCP transaction took too long, stopping it.",
+			 device->iface);
 
 	nm_dhcp_manager_cancel_transaction (device->manager, device->iface);
 
@@ -625,7 +625,10 @@ nm_dhcp_manager_begin_transaction (NMDHCPManager *manager,
 		setting = s_ip4 ? g_object_ref (s_ip4) : NULL;
 	}
 
-	nm_info ("Activation (%s) Beginning DHCP transaction.", iface);
+	if (timeout == 0)
+		timeout = NM_DHCP_TIMEOUT;
+
+	nm_info ("Activation (%s) Beginning DHCP transaction (timeout in %dsecs)", iface, timeout);
 	device->pid = nm_dhcp_client_start (device, uuid, setting);
 
 	if (setting)
@@ -634,9 +637,6 @@ nm_dhcp_manager_begin_transaction (NMDHCPManager *manager,
 	if (device->pid == 0)
 		return FALSE;
 
-	if (timeout == 0)
-		timeout = NM_DHCP_TIMEOUT;
-
 	/* Set up a timeout on the transaction to kill it after the timeout */
 	device->timeout_id = g_timeout_add_seconds (timeout,
 	                                            nm_dhcp_manager_handle_timeout,
diff --git a/src/nm-device.c b/src/nm-device.c
index 55a8fed..114712c 100644
--- a/src/nm-device.c
+++ b/src/nm-device.c
@@ -89,6 +89,7 @@ typedef struct {
 	/* IP configuration info */
 	NMIP4Config *   ip4_config;			/* Config from DHCP, PPP, or system config files */
 	NMDHCPManager * dhcp_manager;
+	guint32         dhcp_timeout;
 	gulong          dhcp_state_sigid;
 	gulong          dhcp_timeout_sigid;
 	NMDHCP4Config * dhcp4_config;
@@ -142,6 +143,7 @@ nm_device_init (NMDevice *self)
 	priv->capabilities = NM_DEVICE_CAP_NONE;
 	memset (&priv->ip6_address, 0, sizeof (struct in6_addr));
 	priv->state = NM_DEVICE_STATE_UNMANAGED;
+	priv->dhcp_timeout = 0;
 }
 
 static GObject*
@@ -899,7 +901,7 @@ real_act_stage3_ip_config_start (NMDevice *self, NMDeviceStateReason *reason)
 		/* DHCP manager will cancel any transaction already in progress and we do not
 		   want to cancel this activation if we get "down" state from that. */
 		g_signal_handler_block (priv->dhcp_manager, priv->dhcp_state_sigid);
-		success = nm_dhcp_manager_begin_transaction (priv->dhcp_manager, ip_iface, uuid, s_ip4, 45);
+		success = nm_dhcp_manager_begin_transaction (priv->dhcp_manager, ip_iface, uuid, s_ip4, priv->dhcp_timeout);
 		g_signal_handler_unblock (priv->dhcp_manager, priv->dhcp_state_sigid);
 
 		if (success) {
@@ -2536,3 +2538,12 @@ nm_device_spec_match_list (NMDeviceInterface *device, const GSList *specs)
 	return FALSE;
 }
 
+void
+nm_device_set_dhcp_timeout (NMDevice *device,
+                            guint32 timeout)
+{
+	g_return_if_fail (NM_IS_DEVICE (device));
+
+	NM_DEVICE_GET_PRIVATE (device)->dhcp_timeout = timeout;
+}
+
diff --git a/src/nm-device.h b/src/nm-device.h
index d460352..3900393 100644
--- a/src/nm-device.h
+++ b/src/nm-device.h
@@ -162,6 +162,8 @@ void nm_device_set_managed (NMDevice *device,
                             gboolean managed,
                             NMDeviceStateReason reason);
 
+void nm_device_set_dhcp_timeout (NMDevice *device, guint32 timeout);
+
 G_END_DECLS
 
 #endif	/* NM_DEVICE_H */
-- 
1.6.2.5



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]