Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 12 Jul 2008 17:05:25 +0300
From:      "Niki Denev" <nike_d@cytexbg.com>
To:        "FreeBSD Current" <freebsd-current@freebsd.org>
Subject:   [PATCH] dhclient link timeout option
Message-ID:  <2e77fc10807120705ud76cea2g1cc634c3012df684@mail.gmail.com>

next in thread | raw e-mail | index | archive | help

[-- Attachment #1 --]
Hello,

I've noticed that when I have both my wired and wireless interfaces on
my laptop enabled with DHCP,
it is always started on boot, but if there is no cable plugged or
known wifi ap, dhclient waits for 10 seconds
for link for each interface and thus delaying the boot process by 20
seconds. (background_dhclient didn't help).
So I've decided to add a link timeout option to dhclient to specify
how long it should wait for link on startup,
which seems to work pretty nicely in my setup. I hope others might
find this useful too.

Regards,
Niki

[-- Attachment #2 --]
diff -ur sbin/dhclient.orig/dhclient.8 sbin/dhclient/dhclient.8
--- sbin/dhclient.orig/dhclient.8	2008-07-12 09:40:39.000000000 +0300
+++ sbin/dhclient/dhclient.8	2008-07-12 09:53:17.000000000 +0300
@@ -83,6 +83,8 @@
 Specify an alternate location,
 .Ar file ,
 for the leases file.
+.It Fl t Ar timeout
+Specify how many seconds to wait for link.
 .It Fl q
 Forces
 .Nm
diff -ur sbin/dhclient.orig/dhclient.c sbin/dhclient/dhclient.c
--- sbin/dhclient.orig/dhclient.c	2008-07-12 09:40:39.000000000 +0300
+++ sbin/dhclient/dhclient.c	2008-07-12 09:53:46.000000000 +0300
@@ -312,13 +312,14 @@
 	int			 ch, fd, quiet = 0, i = 0;
 	int			 pipe_fd[2];
 	int			 immediate_daemon = 0;
+	int			 link_timeout = 10;
 	struct passwd		*pw;
 
 	/* Initially, log errors to stderr as well as to syslogd. */
 	openlog(__progname, LOG_PID | LOG_NDELAY, DHCPD_LOG_FACILITY);
 	setlogmask(LOG_UPTO(LOG_DEBUG));
 
-	while ((ch = getopt(argc, argv, "bc:dl:qu")) != -1)
+	while ((ch = getopt(argc, argv, "bc:dl:t:qu")) != -1)
 		switch (ch) {
 		case 'b':
 			immediate_daemon = 1;
@@ -335,6 +336,13 @@
 		case 'q':
 			quiet = 1;
 			break;
+		case 't':
+			link_timeout = (int)strtol(optarg, (char **)NULL, 10);
+			if (link_timeout < 0)
+			   link_timeout = 0;
+			if (link_timeout > 10)
+			   link_timeout = 10;
+			break;
 		case 'u':
 			unknown_ok = 0;
 			break;
@@ -378,7 +386,7 @@
 		while (!interface_link_status(ifi->name)) {
 			fprintf(stderr, ".");
 			fflush(stderr);
-			if (++i > 10) {
+			if (++i > link_timeout) {
 				fprintf(stderr, " giving up\n");
 				exit(1);
 			}
@@ -455,7 +463,8 @@
 	extern char	*__progname;
 
 	fprintf(stderr, "usage: %s [-bdqu] ", __progname);
-	fprintf(stderr, "[-c conffile] [-l leasefile] interface\n");
+	fprintf(stderr, "[-t link timeout] [-c conffile] ");
+	fprintf(stderr, "[-l leasefile] interface\n");
 	exit(1);
 }
 

Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?2e77fc10807120705ud76cea2g1cc634c3012df684>