From gnats@FreeBSD.org  Wed Sep 20 14:39:08 2006
Return-Path: <gnats@FreeBSD.org>
Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125])
	by hub.freebsd.org (Postfix) with ESMTP id 6310816A412;
	Wed, 20 Sep 2006 14:39:08 +0000 (UTC)
	(envelope-from gnats@FreeBSD.org)
Received: from freefall.freebsd.org (freefall.freebsd.org [216.136.204.21])
	by mx1.FreeBSD.org (Postfix) with ESMTP id 218D643D5F;
	Wed, 20 Sep 2006 14:39:08 +0000 (GMT)
	(envelope-from gnats@FreeBSD.org)
Received: from freefall.freebsd.org (gnats@localhost [127.0.0.1])
	by freefall.freebsd.org (8.13.4/8.13.4) with ESMTP id k8KEd7jM047272;
	Wed, 20 Sep 2006 14:39:07 GMT
	(envelope-from gnats@freefall.freebsd.org)
Received: (from gnats@localhost)
	by freefall.freebsd.org (8.13.4/8.13.4/Submit) id k8KEd700047271;
	Wed, 20 Sep 2006 14:39:07 GMT
	(envelope-from gnats)
Message-Id: <200609201439.k8KEd700047271@freefall.freebsd.org>
Date: Wed, 20 Sep 2006 14:39:07 GMT
From: Rob Austein <sra@hactrn.net>
To: freebsd-gnats-submit@FreeBSD.org
Cc: Mark Linimon <linimon@FreeBSD.org>
Subject: devd(8): devd brings up network interfaces early and wrong
X-Send-Pr-Version: www-2.3

>Number:         103428
>Category:       conf
>Synopsis:       devd(8): devd brings up network interfaces early and wrong
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    brooks
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Wed Sep 20 14:40:31 GMT 2006
>Closed-Date:    Tue Sep 26 02:18:51 GMT 2006
>Last-Modified:  Tue Sep 26 02:20:29 GMT 2006
>Originator:     Rob Austein
>Release:        6.1-STABLE
>Organization:
>Environment:
FreeBSD adrilankha.hactrn.net 6.1-STABLE FreeBSD 6.1-STABLE #2: Tue Sep 12 08:43:49 UTC 2006     sra@adrilankha.hactrn.net:/usr/obj/usr/src/sys/GENERIC  i386

>Description:
Initial problem was that a machine with static IP address and route
configuration was losing the 2002::/16 route associated with its stf0
interface.  Upon investigation, machine was accepting router advertisements,
which it should not have been since all interfaces were staticly configured.
Following this trail eventually led to pccard_ether, which is not only
bringing up interfaces before the /etc/rc.d/network_ipv6 script has had a
chance to run but is also (incorrectly) enabling net.inet6.ip6.accept_rtadv.

pccard_ether checks for interfaces that are already up, so my guess is that
this mess is an accidental side effect of somebody having re-ordered the
scripts in /etc/rc.d so that devd now comes up earlier than it once did
(I have not checked CVS to confirm this theory).  In any case, what it does
now is wrong. :)
>How-To-Repeat:
Something like the following in /etc/rc.conf, on a network that sends IPv6
router advertisements:

ifconfig_foo0="inet 192.0.2.2 netmask 255.255.255.0"
defaultrouter="192.0.2.1"
ipv6_enable="YES"
ipv6_ifconfig_foo0="2001:db8::2 prefixlen 64"
ipv6_defaultrouter="2001:db8::1"
stf_interface_ipv4addr="192.0.2.2"
devd_enable="YES"

>Fix:
Workaround: disable devd. :)

Fix: reorder /etc/rc.d scripts or rewrite /etc/pccard_ether.
>Release-Note:
>Audit-Trail:

From: Brooks Davis <brooks@one-eyed-alien.net>
To: Rob Austein <sra@hactrn.net>
Cc: freebsd-gnats-submit@freebsd.org
Subject: Re: conf/103428: devd(8): devd brings up network interfaces early and wrong
Date: Wed, 20 Sep 2006 14:38:47 -0500

 I'm a bit confused by this one.  It's true devd now starts earlier and
 could start before network_ipv6, but it starts after netif and you
 have an IPv4 address configured so it should be up by the time devd
 starts up.  One possible issue is that the current check is bypased if
 grep isn't available (say if /usr is an nfs mount).  If that's the case
 for you, the following patch may fix things.
 
 The other thing I can think of is that there's a delay in the interface
 transitioning to the UP state.  If that's the case I'm not sure what
 the answer is.  We might need to use something else to de-bounce
 the interface configuration.  It might be worth a try to modify
 etc/rc.d/devd to run after network_ipv6.
 
 -- Brooks
 
 Index: pccard_ether
 ===================================================================
 RCS file: /home/ncvs/src/etc/pccard_ether,v
 retrieving revision 1.50
 diff -u -p -r1.50 pccard_ether
 --- pccard_ether	18 Aug 2006 13:19:45 -0000	1.50
 +++ pccard_ether	20 Sep 2006 19:34:13 -0000
 @@ -69,11 +69,13 @@ pccard_ether_start()
  {
  	ifexists $ifn || exit 1
  
 -	if [ -z "$rc_force" -a -x /usr/bin/grep ]; then
 -		if ifconfig $ifn | grep -s '[<,]UP[,>]' > /dev/null 2>&1; then
 -		    # Interface is already up, so ignore it.
 -		    exit 0
 -		fi
 +	if [ -z "$rc_force" ]; then
 +		for uif in `ifconfig -ul`; do
 +			if [ "${uif}" = "${ifn}" ]; then
 +				# Interface is already up, so ignore it.
 +				exit 0
 +			fi
 +		done
  	fi
  
  	/etc/rc.d/netif start $ifn

From: Rob Austein <sra@hactrn.net>
To: Brooks Davis <brooks@one-eyed-alien.net>
Cc: Rob Austein <sra@hactrn.net>,
        freebsd-gnats-submit@freebsd.org
Subject: Re: conf/103428: devd(8): devd brings up network interfaces early and wrong
Date: Wed, 20 Sep 2006 17:23:31 -0400

 > One possible issue is that the current check is bypased if grep
 > isn't available (say if /usr is an nfs mount).  If that's the case
 > for you, the following patch may fix things.
 
 Thanks, but no, local UFS2 filesystems.
 
 > The other thing I can think of is that there's a delay in the interface
 > transitioning to the UP state.  If that's the case I'm not sure what
 > the answer is.  We might need to use something else to de-bounce
 > the interface configuration.  It might be worth a try to modify
 > etc/rc.d/devd to run after network_ipv6.
 
 Just tried that, didn't help.  So the ordering is not the problem per
 se, sorry for the distraction, but pccard_ether is still messing up
 the IPv6 configuration.
 
 At this point I suspect that the problem is that pccard_ether is
 attempting to bring up IPv6 on interface hardware that's not connected
 to anything, which is confusing /etc/network.subr into listening for
 router advertisements when it should not.  I added a debug line to
 network.subr to make network6_interface_setup log the interface it's
 about to whack, enabled rc_debug, and got the console output below.
 It's not touching bge0 or lo0, but it's trying to bring up IPv6 on
 bge1 and plip0, neither of which is connected to anything.
 
 /etc/rc: DEBUG: Cloned: 
 bge0: flags=8843<UP,BROADCAST,RUNNING,SIMPLEX,MULTICAST> mtu 1500
         options=1b<RXCSUM,TXCSUM,VLAN_MTU,VLAN_HWTAGGING>
         inet6 fe80::230:48ff:fe82:11dc%bge0 prefixlen 64 tentative scopeid 0x1 
         inet 147.28.0.19 netmask 0xffffff00 broadcast 147.28.0.255
         ether 00:30:48:82:11:dc
         media: Ethernet autoselect (none)
         status: no carrier
 lo0: flags=8049<UP,LOOPBACK,RUNNING,MULTICAST> mtu 16384
         inet6 ::1 prefixlen 128 
         inet6 fe80::1%lo0 prefixlen 64 scopeid 0x4 
         inet 127.0.0.1 netmask 0xff000000 
 /etc/rc: DEBUG: The following interfaces were not configured: 
 /etc/rc.d/ipfilter: DEBUG: checkyesno: ipfilter_enable is set to NO.
 /etc/rc: DEBUG: checkyesno: devd_enable is set to YES.
 Starting devd.
 /etc/rc: DEBUG: run_rc_command: _doit: /sbin/devd  
 /etc/pccard_ether: DEBUG: run_rc_command: evaluating checkauto().
 /etc/pccard_ether: DEBUG: run_rc_command: evaluating pccard_ether_start().
 /etc/pccard_ether: DEBUG: run_rc_command: evaluating checkauto().
 /etc/pccard_ether: DEBUG: run_rc_command: evaluating pccard_ether_start().
 /etc/rc.d/netif: DEBUG: run_rc_command: evaluating network_start().
 /etc/rc.d/netif: DEBUG: The following interfaces were not configured:  bge1
 /etc/rc.d/ipfilter: DEBUG: checkyesno: ipfilter_enable is set to NO.
 /etc/rc.d/bridge: DEBUG: run_rc_command: evaluating bridge_start().
 /etc/pccard_ether: DEBUG: checkyesno: ipv6_enable is set to YES.
 /etc/pccard_ether: DEBUG: Interface: bge1
 net.inet6.ip6.accept_rtadv: 
 0
  -> 
 1
 
 /etc/pccard_ether: DEBUG: run_rc_command: evaluating checkauto().
 /etc/pccard_ether: DEBUG: run_rc_command: evaluating pccard_ether_start().
 /etc/rc.d/netif: DEBUG: run_rc_command: evaluating network_start().
 /etc/rc.d/netif: DEBUG: The following interfaces were not configured:  plip0
 /etc/rc.d/ipfilter: DEBUG: checkyesno: ipfilter_enable is set to NO.
 /etc/rc.d/bridge: DEBUG: run_rc_command: evaluating bridge_start().
 /etc/pccard_ether: DEBUG: checkyesno: ipv6_enable is set to YES.
 /etc/pccard_ether: DEBUG: Interface: plip0
 net.inet6.ip6.accept_rtadv: 
 1
  -> 
 1
 
 get_llflag() failed, anyway I'll try
 
 sendmsg on plip0: Can't assign requested address
 
 sendmsg on plip0: Can't assign requested address
 
 sendmsg on plip0: Can't assign requested address
 

From: Brooks Davis <brooks@one-eyed-alien.net>
To: Rob Austein <sra@hactrn.net>
Cc: Brooks Davis <brooks@one-eyed-alien.net>, freebsd-gnats-submit@freebsd.org
Subject: Re: conf/103428: devd(8): devd brings up network interfaces early and wrong
Date: Wed, 20 Sep 2006 17:10:07 -0500

 On Wed, Sep 20, 2006 at 05:23:31PM -0400, Rob Austein wrote:
 > At this point I suspect that the problem is that pccard_ether is
 > attempting to bring up IPv6 on interface hardware that's not connected
 > to anything, which is confusing /etc/network.subr into listening for
 > router advertisements when it should not.  I added a debug line to
 > network.subr to make network6_interface_setup log the interface it's
 > about to whack, enabled rc_debug, and got the console output below.
 > It's not touching bge0 or lo0, but it's trying to bring up IPv6 on
 > bge1 and plip0, neither of which is connected to anything.
 
 I see the problem, but solution is doesn't look like it's going to be
 easy, particularly for something we can MFC.  The following coupled with
 manually setting ipv6_network_interfaces might be a decent option for
 now.  Eventually I think we'll want to adjust the way this stuff works a
 fair bit, but there's a limit to how much we can change in stable since
 we definitely don't want to break existing setups.
 
 -- Brooks
 
 
 Index: network.subr
 ===================================================================
 RCS file: /home/ncvs/src/etc/network.subr,v
 retrieving revision 1.172
 diff -u -p -r1.172 network.subr
 --- network.subr	17 Aug 2006 03:03:38 -0000	1.172
 +++ network.subr	20 Sep 2006 22:06:53 -0000
 @@ -237,6 +237,30 @@ wpaif()
  	return 1
  }
  
 +# ipv6if if
 +#	Returns 0 if the interface should be configured for IPv6 and
 +#	1 otherwise.
 +ipv6if()
 +{
 +	if ! checkyesno ipv6_enable; then
 +		return 0
 +	fi
 +	case "${ipv6_network_interfaces}" in
 +	[Aa][Uu][Tt][Oo])
 +		return 0
 +		;;
 +	''|[Nn][Oo][Nn][Ee])
 +		return 1
 +		;;
 +	esac
 +	for v6if in ${ipv6_network_interfaces}; do
 +		if [ "${v6if}" = "${1}" ]; then
 +			return 0
 +		fi
 +	done
 +	return 1
 +}
 +
  # ifexists if
  #	Returns 0 if the interface exists and 1 otherwise.
  ifexists()
 Index: pccard_ether
 ===================================================================
 RCS file: /home/ncvs/src/etc/pccard_ether,v
 retrieving revision 1.52
 diff -u -p -r1.52 pccard_ether
 --- pccard_ether	20 Sep 2006 19:48:31 -0000	1.52
 +++ pccard_ether	20 Sep 2006 22:06:53 -0000
 @@ -89,7 +89,11 @@ pccard_ether_start()
  	fi
  
  	# IPv6 setup
 -	if checkyesno ipv6_enable; then
 +	if ipv6if $ifn; then
 +		# XXX: network6_interface_setup assumes you're calling
 +		# it with ALL the IPv6 interfaces at once and thus isn't
 +		# really appropraite for this job, but it's the best we've
 +		# got for now.
  		network6_interface_setup $ifn
  	fi
  }

From: Rob Austein <sra@hactrn.net>
To: Brooks Davis <brooks@one-eyed-alien.net>
Cc: Rob Austein <sra@hactrn.net>,
	freebsd-gnats-submit@freebsd.org
Subject: Re: conf/103428: devd(8): devd brings up network interfaces early and wrong
Date: Wed, 20 Sep 2006 19:02:40 -0400

 > The following coupled with manually setting ipv6_network_interfaces
 > might be a decent option for now.
 
 Er, the first return in ipv6if() needs to be 1, not 0 (if IPv6 is
 disabled system-wide, don't bring it up on this interface), but other
 than that, this patch worked and seems like a reasonable stopgap.
 
 > Eventually I think we'll want to adjust the way this stuff works a
 > fair bit, but there's a limit to how much we can change in stable
 > since we definitely don't want to break existing setups.
 
 Completely understand, and agree.
 
 Thanks!

From: Brooks Davis <brooks@one-eyed-alien.net>
To: Rob Austein <sra@hactrn.net>
Cc: Brooks Davis <brooks@one-eyed-alien.net>, freebsd-gnats-submit@freebsd.org
Subject: Re: conf/103428: devd(8): devd brings up network interfaces early and wrong
Date: Wed, 20 Sep 2006 20:17:19 -0500

 On Wed, Sep 20, 2006 at 07:02:40PM -0400, Rob Austein wrote:
 > > The following coupled with manually setting ipv6_network_interfaces
 > > might be a decent option for now.
 > 
 > Er, the first return in ipv6if() needs to be 1, not 0 (if IPv6 is
 > disabled system-wide, don't bring it up on this interface), but other
 > than that, this patch worked and seems like a reasonable stopgap.
 
 In shell 0 is true and !0 is false.
 
 -- Brooks

From: Brooks Davis <brooks@one-eyed-alien.net>
To: Brooks Davis <brooks@one-eyed-alien.net>
Cc: Rob Austein <sra@hactrn.net>, freebsd-gnats-submit@freebsd.org
Subject: Re: conf/103428: devd(8): devd brings up network interfaces early and wrong
Date: Wed, 20 Sep 2006 20:40:13 -0500

 On Wed, Sep 20, 2006 at 08:17:19PM -0500, Brooks Davis wrote:
 > On Wed, Sep 20, 2006 at 07:02:40PM -0400, Rob Austein wrote:
 > > > The following coupled with manually setting ipv6_network_interfaces
 > > > might be a decent option for now.
 > > 
 > > Er, the first return in ipv6if() needs to be 1, not 0 (if IPv6 is
 > > disabled system-wide, don't bring it up on this interface), but other
 > > than that, this patch worked and seems like a reasonable stopgap.
 
 Arg, you're correct.  Ignore my previous message.  I'll commit this
 change with the fix.
 
 -- Brooks

From: dfilter@FreeBSD.ORG (dfilter service)
To: bug-followup@FreeBSD.org
Cc:  
Subject: Re: conf/103428: commit references a PR
Date: Thu, 21 Sep 2006 01:44:58 +0000 (UTC)

 brooks      2006-09-21 01:44:52 UTC
 
   FreeBSD src repository
 
   Modified files:
     etc                  network.subr pccard_ether 
   Log:
   Introduce a new method ipv6if which attemptes to figure out if an
   interface is an IPv6 interface.
   
   Use this method to decide if we should attempt to configure an interface
   with an IPv6 address in pccard_ether.  The mechanism pccard_ether uses
   to do this is unsuited to the task because it assumes the list of
   interfaces it is passed is the full list of IPv6 interfaces and makes
   decissions based on that.  This is at least a step in the right
   direction and is probably about as much as we can MFC safely.
   
   PR:             conf/103428
   MFC after:      3 days
   
   Revision  Changes    Path
   1.173     +24 -0     src/etc/network.subr
   1.53      +5 -1      src/etc/pccard_ether
 _______________________________________________
 cvs-all@freebsd.org mailing list
 http://lists.freebsd.org/mailman/listinfo/cvs-all
 To unsubscribe, send any mail to "cvs-all-unsubscribe@freebsd.org"
 

From: Rob Austein <sra@hactrn.net>
To: Brooks Davis <brooks@one-eyed-alien.net>
Cc: Rob Austein <sra@hactrn.net>,
	freebsd-gnats-submit@freebsd.org
Subject: Re: conf/103428: devd(8): devd brings up network interfaces early and wrong
Date: Thu, 21 Sep 2006 10:07:33 -0400

 At Wed, 20 Sep 2006 20:40:13 -0500, Brooks Davis wrote:
 > 
 > I'll commit this change with the fix.
 
 Thanks, Brooks.
 
 After thinking about this overnight:
 
 a) The proposed fix is fine and will do until somebody has time to
    redesign this twisty maze.
 
 b) I still think that having devd attempt to bring up IPv6 before
    network_ipv6 does, while not a bug per se, is at the very least a
    violation of the Principal of Least Astonishment.  At the moment I
    don't see anything in network_ipv6 that absolutely must run before
    bringing up IPv6 on specific interfaces, but that might not be the
    case forever, and this activation path via devd is only obvious in
    retrospect.  So I'd recommend making sure that network_ipv6 runs
    before devd, by adding network_ipv6 to devd's REQUIRE: list.
 
 Thanks for all your help, whether you agree on (b) or not.
 
 --Rob
State-Changed-From-To: open->patched 
State-Changed-By: brooks 
State-Changed-When: Thu Sep 21 14:29:55 UTC 2006 
State-Changed-Why:  
Committed a workaround to HEAD. 


Responsible-Changed-From-To: freebsd-bugs->brooks 
Responsible-Changed-By: brooks 
Responsible-Changed-When: Thu Sep 21 14:29:55 UTC 2006 
Responsible-Changed-Why:  
Committed a workaround to HEAD. 

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

From: dfilter@FreeBSD.ORG (dfilter service)
To: bug-followup@FreeBSD.org
Cc:  
Subject: Re: conf/103428: commit references a PR
Date: Thu, 21 Sep 2006 14:29:50 +0000 (UTC)

 brooks      2006-09-21 14:29:32 UTC
 
   FreeBSD src repository
 
   Modified files:
     etc/rc.d             devd 
   Log:
   network_ipv6 also does some interface configuration so require it to run
   before starting devd so they don't trip over each other.
   
   PR:             conf/103428
   
   Revision  Changes    Path
   1.10      +1 -1      src/etc/rc.d/devd
 _______________________________________________
 cvs-all@freebsd.org mailing list
 http://lists.freebsd.org/mailman/listinfo/cvs-all
 To unsubscribe, send any mail to "cvs-all-unsubscribe@freebsd.org"
 

From: Brooks Davis <brooks@one-eyed-alien.net>
To: Rob Austein <sra@hactrn.net>
Cc: Brooks Davis <brooks@one-eyed-alien.net>, freebsd-gnats-submit@freebsd.org
Subject: Re: conf/103428: devd(8): devd brings up network interfaces early and wrong
Date: Thu, 21 Sep 2006 09:29:40 -0500

 On Thu, Sep 21, 2006 at 10:07:33AM -0400, Rob Austein wrote:
 > At Wed, 20 Sep 2006 20:40:13 -0500, Brooks Davis wrote:
 > > 
 > > I'll commit this change with the fix.
 > 
 > Thanks, Brooks.
 > 
 > After thinking about this overnight:
 > 
 > a) The proposed fix is fine and will do until somebody has time to
 >    redesign this twisty maze.
 
 Good, I'm planning to MFC it in a few days.
 
 > b) I still think that having devd attempt to bring up IPv6 before
 >    network_ipv6 does, while not a bug per se, is at the very least a
 >    violation of the Principal of Least Astonishment.  At the moment I
 >    don't see anything in network_ipv6 that absolutely must run before
 >    bringing up IPv6 on specific interfaces, but that might not be the
 >    case forever, and this activation path via devd is only obvious in
 >    retrospect.  So I'd recommend making sure that network_ipv6 runs
 >    before devd, by adding network_ipv6 to devd's REQUIRE: list.
 
 I agree.  I'll make that change.
 
 -- Brooks
State-Changed-From-To: patched->closed 
State-Changed-By: brooks 
State-Changed-When: Tue Sep 26 02:18:24 UTC 2006 
State-Changed-Why:  
Merged to RELENG_6. 

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

From: dfilter@FreeBSD.ORG (dfilter service)
To: bug-followup@FreeBSD.org
Cc:  
Subject: Re: conf/103428: commit references a PR
Date: Tue, 26 Sep 2006 02:15:27 +0000 (UTC)

 brooks      2006-09-26 02:15:15 UTC
 
   FreeBSD src repository
 
   Modified files:        (Branch: RELENG_6)
     etc/rc.d             devd 
   Log:
   MFC rev 1.10
   
     network_ipv6 also does some interface configuration so require it to
     run before starting devd so they don't trip over each other.
   
   PR:             conf/103428
   Approved by:    re (hrs)
   
   Revision  Changes    Path
   1.7.2.3   +1 -1      src/etc/rc.d/devd
 _______________________________________________
 cvs-all@freebsd.org mailing list
 http://lists.freebsd.org/mailman/listinfo/cvs-all
 To unsubscribe, send any mail to "cvs-all-unsubscribe@freebsd.org"
 

From: dfilter@FreeBSD.ORG (dfilter service)
To: bug-followup@FreeBSD.org
Cc:  
Subject: Re: conf/103428: commit references a PR
Date: Tue, 26 Sep 2006 02:17:50 +0000 (UTC)

 brooks      2006-09-26 02:17:43 UTC
 
   FreeBSD src repository
 
   Modified files:        (Branch: RELENG_6)
     etc                  network.subr pccard_ether 
   Log:
   MFC
   
   pccard_ether rev 1.51:
       Search the list of up interfaces provided by "ifconfig -ul" instead of
       greping for UP in "ifconfig $ifn".  This eliminates a dependancy on /usr.
   
   pccard_ether rev 1.53 and network.subr rev 1.173:
     Introduce a new method ipv6if which attemptes to figure out if an
     interface is an IPv6 interface.
   
     Use this method to decide if we should attempt to configure an interface
     with an IPv6 address in pccard_ether.  The mechanism pccard_ether uses
     to do this is unsuited to the task because it assumes the list of
     interfaces it is passed is the full list of IPv6 interfaces and makes
     decissions based on that.  This is at least a step in the right
     direction and is probably about as much as we can MFC safely.
   
   PR:             conf/103428
   Approved by:    re (hrs)
   
   Revision   Changes    Path
   1.164.2.4  +24 -0     src/etc/network.subr
   1.45.2.4   +12 -6     src/etc/pccard_ether
 _______________________________________________
 cvs-all@freebsd.org mailing list
 http://lists.freebsd.org/mailman/listinfo/cvs-all
 To unsubscribe, send any mail to "cvs-all-unsubscribe@freebsd.org"
 
>Unformatted:
