From lyndon@messagingdirect.com  Mon Sep 18 13:53:20 2000
Return-Path: <lyndon@messagingdirect.com>
Received: from gollum.esys.ca (dhcp198-59.esys.ca [198.161.92.59])
	by hub.freebsd.org (Postfix) with ESMTP id B472F37B423
	for <FreeBSD-gnats-submit@freebsd.org>; Mon, 18 Sep 2000 13:53:11 -0700 (PDT)
Received: by gollum.esys.ca (Postfix, from userid 1001)
	id BF8069936C; Mon, 18 Sep 2000 14:53:04 -0600 (MDT)
Message-Id: <20000918205304.BF8069936C@gollum.esys.ca>
Date: Mon, 18 Sep 2000 14:53:04 -0600 (MDT)
From: lyndon@messagingdirect.com
Reply-To: lyndon@messagingdirect.com
To: FreeBSD-gnats-submit@freebsd.org
Subject: [PATCH] dhclient runs away on interface removal
X-Send-Pr-Version: 3.2

>Number:         21375
>Category:       bin
>Synopsis:       [PATCH] dhclient runs away on interface removal
>Confidential:   no
>Severity:       serious
>Priority:       high
>Responsible:    mbr
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Mon Sep 18 14:00:01 PDT 2000
>Closed-Date:    Mon Jul 28 11:56:44 PDT 2003
>Last-Modified:  Mon Jul 28 11:56:44 PDT 2003
>Originator:     Lyndon Nerenberg
>Release:        FreeBSD 4.1-STABLE i386
>Organization:
>Environment:

4.1-STABLE laptop with PCCard NIC controlled by pccardd and
configured to use DHCP.

>Description:

Once the NIC is up and dhclient has configured the NIC, removing
the card causes dhclient to go into a spin loop on the select() in
the dispatch() routine. The call to got_one() gets an error from
the read() on the socket, but doesn't do anything special with the
error. got_one() returns and the whole thing repeats, grabbing most
of the CPU in the process (and generating gobs of syslog cruft).

>How-To-Repeat:

>Fix:

Fixing this correctly would require dhclient be able to handle
dynamic interfaces correctly. Short of doing that rewrite, the
following patch adds a test for the read() returning ENXIO, and shuts
down the application in that event. This is definately a bit if a hack.
It's based on the premise that the failing dhclient was launched from
pccardd (via pccard_ether) and that pccardd will start another dhclient
the next time the NIC is inserted. I think this is safe -- I can't think
of another normal dhclient scenario where one of the interfaces
would just disappear.

An alternative fix would be to invalidate the interface on dhclient's
internal interface list (removing it from the FD set), and terminate if
the interface count goes to zero.

Patch against /usr/src/contrib/isc-dhcp/common/dispatch.c:

--- dispatch.c.old	Mon Sep 18 14:12:22 2000
+++ dispatch.c	Mon Sep 18 14:34:26 2000
@@ -701,7 +701,26 @@
 
 	if ((result =
 	     receive_packet (ip, u.packbuf, sizeof u, &from, &hfrom)) < 0) {
+		int save_errno = errno;
+
 		warn ("receive_packet failed on %s: %m", ip -> name);
+		if (save_errno == ENXIO) {
+			/* 
+			 * The interface went away. All we can do for now
+			 * is terminate since there is no support
+			 * here for handling dynamic interfaces.
+			 *
+			 * This behaviour is relatively safe. The
+			 * only time an interface should go away in
+			 * normal operation is when a laptop NIC card
+			 * is removed. If that happens there's no reason
+			 * for us to stick around. The laptop's OS should
+			 * handle restarting us when the interface comes
+			 * back.
+			 */
+			error("%s: interface removed?",
+			      ip -> name);
+		}
 		return;
 	}
 	if (result == 0)

>Release-Note:
>Audit-Trail:
Responsible-Changed-From-To: freebsd-bugs->obrien 
Responsible-Changed-By: johan 
Responsible-Changed-When: Tue Sep 19 11:09:40 PDT 2000 
Responsible-Changed-Why:  
Over to dhcp maintainer. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=21375 
State-Changed-From-To: open->analyzed 
State-Changed-By: obrien 
State-Changed-When: Sat Nov 4 12:25:14 PST 2000 
State-Changed-Why:  
I don't want the FreeBSD dhclient to become its own mutant. 
I'll only apply a change such as this one if you can get the ISC to make 
the same [exact] change to the version 3 client.  If this change is already 
in the version 3 software, pointing out the exact CVS revisions where the 
change entered would greatly increase my agreement to make the change 
and greatly speed my analysis of the change. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=21375 

From: Lyndon Nerenberg <lyndon@orthanc.ab.ca>
To: freebsd-gnats-submit@FreeBSD.org, lyndon@messagingdirect.com
Cc:  
Subject: Re: bin/21375: [PATCH] dhclient runs away on interface removal
Date: Wed, 08 Nov 2000 10:43:07 -0700

 Does this mean ISC version 3 will be imported once it's released? If
 that's the case then you can close the PR and I'll submit this directly
 to ISC.
 
 
Responsible-Changed-From-To: obrien->freebsd-bugs 
Responsible-Changed-By: obrien 
Responsible-Changed-When: Sat Dec 23 11:20:22 PST 2000 
Responsible-Changed-Why:  
I am not the single dhclient maintainer now. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=21375 
State-Changed-From-To: analyzed->closed 
State-Changed-By: bmah 
State-Changed-When: Mon Apr 16 11:24:57 PDT 2001 
State-Changed-Why:  
Closed by submitter's request. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=21375 
State-Changed-From-To: closed->open 
State-Changed-By: mbr 
State-Changed-When: Mon Feb 10 01:38:50 PST 2003 
State-Changed-Why:  
Fix is still not committed to the ISC repo. I'll deal 
with this mess. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=21375 
Responsible-Changed-From-To: freebsd-bugs->mbr 
Responsible-Changed-By: mbr 
Responsible-Changed-When: Mon Feb 10 01:50:20 PST 2003 
Responsible-Changed-Why:  
Take this PR 

http://www.freebsd.org/cgi/query-pr.cgi?pr=21375 
State-Changed-From-To: open->analyzed 
State-Changed-By: mbr 
State-Changed-When: Sat Apr 26 16:52:02 PDT 2003 
State-Changed-Why:  
Fixed some time ago in dhclient. The patch committed is 
not the same, but almost: 

bpf.c: line 427 

#ifdef __FreeBSD__ 
if (errno == ENXIO) { 
#else 
if (errno == EIO) { 
#endif 
dhcp_interface_remove 
((omapi_object_t *)interface, 
(omapi_object_t *)0); 

Can you test if it still fails with recent BSD's. Unfortunatly 
all pccards and cardbus cards fail here to work on my laptop. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=21375 
State-Changed-From-To: analyzed->closed 
State-Changed-By: mbr 
State-Changed-When: Mon Jul 28 11:56:23 PDT 2003 
State-Changed-Why:  
Submitter timeout. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=21375 
>Unformatted:
