Re: Getting NM to re-try DHCP



On Wed, 06 Apr 2011 17:24:44 -0500 Dan Williams wrote:
> On Tue, 2011-04-05 at 11:37 -0400, Derek Atkins wrote:
> > Hey all,
> > 
> > I have a strange issue.  I lost power last night and one of my
> > systems came up before my DHCP server did (which is surprising,
> > because my DHCP server usually comes up pretty quick!)  This
> > "client" system was supposed to get itself on the network (it has
> > an auto-logon system). However, NM didn't succeed because my DHCP
> > server wasn't responding, yet.
> > 
> > This is a hard-wired system (not wireless).  Is there any way to
> > get NM to periodically retry DHCP if at first it does not succeed?
> > 
> > I realize that DHCP has its own retry mechanism, but if the whole
> > process times out, can I set NM to retry every, say, 5 minutes?
> 
> We'd need some code changes in NM; basically for wired connections if
> the activation attempt fails a certain number of times (currently 3)
> then the connection is marked "invalid".  What probably should happen
> is that internally, in nm-policy.c, a timeout handler should be
> scheduled for the connection (using g_timeout_add_seconds()) that
> triggers after 5 minutes or so and if the connection isn't currently
> active (ie check the NMManager's active connection list) then the
> invalid flag is cleared from the connection, which will let it be
> automatically retried.

Not on this issue exactly, but this is reminded me about my old patch
which was written long time ago (it was just forgotten to submit, sorry).
If cable was unplugged, then when it is replugged this may be another
network, so NM should try to reconnect even if the connection was
early marked as "invalid".
This patch for the NM_0_8 branch, for master it should be remaked, but
I have no time to do this right now, sorry. And there may be no
necessary for a separate function to clear the tag.

-- 
WBR, Mikhail Efremov
>From 6ec40e1307186128ae4c3a3ada602576d453db13 Mon Sep 17 00:00:00 2001
From: Mikhail Efremov <sem altlinux org>
Date: Fri, 8 Apr 2011 19:19:54 +0400
Subject: [PATCH] Clear 'invalid' tag when cable is replugged.

---
 src/nm-policy.c |   34 +++++++++++++++++++++++++++++++++-
 1 files changed, 33 insertions(+), 1 deletions(-)

diff --git a/src/nm-policy.c b/src/nm-policy.c
index aed2f89..4e0a73f 100644
--- a/src/nm-policy.c
+++ b/src/nm-policy.c
@@ -846,6 +846,33 @@ get_device_connection (NMDevice *device)
 }
 
 static void
+clear_invalid_tag(NMPolicy *policy, NMDevice *device)
+{
+
+	NMConnection *best_connection;
+	char *specific_object = NULL;
+	GSList *connections;
+
+	g_assert (device);
+	g_assert (policy);
+
+	/* System connections first, then user connections */
+	connections = nm_manager_get_connections (policy->manager, NM_CONNECTION_SCOPE_SYSTEM);
+	connections = g_slist_concat (connections, nm_manager_get_connections (policy->manager, NM_CONNECTION_SCOPE_USER));
+
+	if (!connections)
+		return;
+
+	best_connection = nm_device_get_best_auto_connection (device, connections, &specific_object);
+
+	if (best_connection)
+		g_object_set_data (G_OBJECT (best_connection), INVALID_TAG, NULL);
+
+	g_slist_foreach (connections, (GFunc) g_object_unref, NULL);
+	g_slist_free (connections);
+}
+
+static void
 device_state_changed (NMDevice *device,
                       NMDeviceState new_state,
                       NMDeviceState old_state,
@@ -880,9 +907,14 @@ device_state_changed (NMDevice *device,
 
 		update_routing_and_dns (policy, FALSE);
 		break;
+	case NM_DEVICE_STATE_DISCONNECTED:
+		/* Clear INVALID_TAG when carrier on. If cable was unplugged
+		   and plugged again, we should try to reconnect */
+		if(reason == NM_DEVICE_STATE_REASON_CARRIER &&
+				old_state == NM_DEVICE_STATE_UNAVAILABLE)
+			clear_invalid_tag(policy, device);
 	case NM_DEVICE_STATE_UNMANAGED:
 	case NM_DEVICE_STATE_UNAVAILABLE:
-	case NM_DEVICE_STATE_DISCONNECTED:
 		update_routing_and_dns (policy, FALSE);
 		schedule_activate_check (policy, device, 0);
 		break;
-- 
1.7.4.3



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