From 0f56957b77b0d86cf4cae3141e70f777cfc8847f Mon Sep 17 00:00:00 2001 From: Daniel Drake Date: Wed, 15 Jul 2009 13:48:28 -0400 Subject: core: allow device subclasses to override DHCP timeout --- 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(-) diff --git a/src/dhcp-manager/nm-dhcp-manager.c b/src/dhcp-manager/nm-dhcp-manager.c index 66044d72f0..22368b9677 100644 --- a/src/dhcp-manager/nm-dhcp-manager.c +++ b/src/dhcp-manager/nm-dhcp-manager.c @@ -508,8 +508,7 @@ 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 +624,11 @@ 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 %d seconds)", + 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 7cefbe5082..401d529af6 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 d460352123..39003938a8 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 */ -- cgit v1.2.3