System doesn't detect unplugged network cable and doesn't set interface up properly with DHCP

John Baldwin jhb at freebsd.org
Fri Aug 17 15:54:20 UTC 2012


On Tuesday, August 14, 2012 8:31:51 pm Peter Jeremy wrote:
> On 2012-Jul-13 11:20:36 -0700, Yuri <yuri at rawbw.com> wrote:
> >On 07/13/2012 02:48, Peter Jeremy wrote:
> >> This is a bug in dhclient - see PR bin/166656, which includes a fix.
> >
> >I think this PR addresses part of the problem: dhclient doesn't exit when the link goes down.
> >But even if it exits, it leaves the IP address that it has set, which is wrong. This IP address survives through the next DHCP setup process and 
ends up being the second IP address.
> >Should be very easy to on exit remove any IP address that was set during dhclient process lifetime.
> 
> I agree that it _should_ be easy to remove the existing address and the
> existing patch in that PR should already do that.  Unfortunately,
> there seems to be another issue in dhclient that means that it isn't.

Hmm, I think I see the issue.  It doesn't export the existing lease info to
the script when running the FAIL action.  I just tested this change and it
removed the old IP on my laptop when I tested it just now.  Note that I
kept the warning as "Interface foo is down" rather than "Link foo is down"
since dhclient consistently uses that language elsewhere.

Index: dhclient.c
===================================================================
--- dhclient.c	(revision 239333)
+++ dhclient.c	(working copy)
@@ -278,6 +278,11 @@ routehandler(struct protocol *p)
 			    ifi->name);
 			goto die;
 		}
+		if (!interface_link_status(ifi->name)) {
+			warning("Interface %s is down, dhclient exiting",
+			    ifi->name);
+			goto die;
+		}
 		break;
 	case RTM_IFANNOUNCE:
 		ifan = (struct if_announcemsghdr *)rtm;
@@ -316,6 +321,8 @@ routehandler(struct protocol *p)
 
 die:
 	script_init("FAIL", NULL);
+	if (ip->client->active)
+		script_write_params("old_", ip->client->active);
 	if (ifi->client->alias)
 		script_write_params("alias_", ifi->client->alias);
 	script_go();

-- 
John Baldwin


More information about the freebsd-net mailing list