From nobody@FreeBSD.org  Thu Jun 16 09:19:19 2005
Return-Path: <nobody@FreeBSD.org>
Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125])
	by hub.freebsd.org (Postfix) with ESMTP id 3BC0216A41C
	for <freebsd-gnats-submit@FreeBSD.org>; Thu, 16 Jun 2005 09:19:19 +0000 (GMT)
	(envelope-from nobody@FreeBSD.org)
Received: from www.freebsd.org (www.freebsd.org [216.136.204.117])
	by mx1.FreeBSD.org (Postfix) with ESMTP id 1F9DF43D4C
	for <freebsd-gnats-submit@FreeBSD.org>; Thu, 16 Jun 2005 09:19:19 +0000 (GMT)
	(envelope-from nobody@FreeBSD.org)
Received: from www.freebsd.org (localhost [127.0.0.1])
	by www.freebsd.org (8.13.1/8.13.1) with ESMTP id j5G9JIWT047211
	for <freebsd-gnats-submit@FreeBSD.org>; Thu, 16 Jun 2005 09:19:19 GMT
	(envelope-from nobody@www.freebsd.org)
Received: (from nobody@localhost)
	by www.freebsd.org (8.13.1/8.13.1/Submit) id j5G9JIwF047210;
	Thu, 16 Jun 2005 09:19:18 GMT
	(envelope-from nobody)
Message-Id: <200506160919.j5G9JIwF047210@www.freebsd.org>
Date: Thu, 16 Jun 2005 09:19:18 GMT
From: Darren Pilgrim <dmp@bitfreak.org>
To: freebsd-gnats-submit@FreeBSD.org
Subject: /etc/rc.d/netif does not build the list of interfaces correctly.
X-Send-Pr-Version: www-2.3

>Number:         82314
>Category:       conf
>Synopsis:       [patch] /etc/rc.d/netif does not build the list of interfaces correctly.
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    brooks
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Thu Jun 16 09:20:16 GMT 2005
>Closed-Date:    Mon Oct 31 19:48:30 GMT 2005
>Last-Modified:  Mon Oct 31 19:48:30 GMT 2005
>Originator:     Darren Pilgrim
>Release:        6.0-current
>Organization:
n/a
>Environment:
FreeBSD Smiley.Blackthornes.LAN 6.0-CURRENT FreeBSD 6.0-CURRENT #0: Sat Jun 11 20:04:30 PDT 2005     root@Smiley.Blackthornes.LAN:/usr/obj/usr/src/sys/Smiley  i386

>Description:
/etc/rc.d/netif is called for two different purposes, each with its own calling method and requirements.  The first is at boot to set up the network interfaces configured in /etc/rc.conf.  To perform this task netif is run without any parameters.  The intention is for netif to realize its lack of parameters and configure all interfaces.

The second purpose of netif is to perform the interface configuration legwork for pccard_ether and possibly others.  In this mode, an interface name and the start/stop command are given as the parameters.  The intention is for netif to realize that it will be working with just the one interface.

The error occurs when netif goes to set _ifn_list to the list of valid interfaces for these modes.  The existing code works correctly for the first mode: network_common() calls list_net_interfaces(), which returns a list comprised of the contents of network_interfaces and cloned_interfaces.  However, this is not correct for the second mode and network_common() fails: in a configuration where some interfaces are handled through pccard_ether, the interface list needs to include not just list_net_interfaces(), but removable_interfaces as well.  If netif is being called from something other than pccard_ether, then the interface could be anything.  To make netif work in this scenario, _ifn_list should be set to those interfaces ifconfig knows about.

The attached patch changes the behavior of network_common() to set _ifn_list to list_net_interfaces() for the first mode and the output of `ifconfig -l` for the second mode.  This resulted in correct setup of interfaces when netif is run either directly or by pccard_ether.
>How-To-Repeat:
1: Configure your system to exclude an interface by setting network_interfaces in /etc/rc.conf.

2: Add the excluded interface to removable_interfaces, source /etc/rc.conf and run /etc/pccard_ether <interface> start.   Note the error stating the interface doesn't exist.

Alternate for 2: Run /etc/rc.d/netif start <interface>.  Note the error stating the interface doesn't exist.
>Fix:
      --- netif.orig  Thu Jun 16 00:26:36 2005
+++ netif       Thu Jun 16 01:32:14 2005
@@ -102,13 +102,11 @@
        fi
        [ -n "$2" ] && _verbose=yes

-       # Get a list of network interfaces.
-       _ifn_list="`list_net_interfaces`"
-
        # Set the scope of the command (all interfaces or just one).
        #
        _cooked_list=
        if [ -n "$_cmdifn" ]; then
+               _ifn_list="`ifconfig -l`"
                for i in $_cmdifn ; do
                        eval _if=\"`expr "$_ifn_list" : ".*\(${i}\).*"`\"
                        if [ -z "$_if" ]; then
@@ -117,7 +115,7 @@
                        _cooked_list="$_cooked_list $_if"
                done
        else
-               _cooked_list="$_ifn_list"
+               _cooked_list="`list_net_interfaces`"
        fi

        for ifn in ${_cooked_list}; do

>Release-Note:
>Audit-Trail:
Responsible-Changed-From-To: freebsd-bugs->brooks 
Responsible-Changed-By: brooks 
Responsible-Changed-When: Thu Jun 16 18:21:35 GMT 2005 
Responsible-Changed-Why:  
This is my bug. 

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

From: Brooks Davis <brooks@one-eyed-alien.net>
To: Darren Pilgrim <dmp@bitfreak.org>
Cc: freebsd-gnats-submit@freebsd.org
Subject: Re: conf/82314: /etc/rc.d/netif does not build the list of interfaces correctly.
Date: Thu, 16 Jun 2005 11:25:50 -0700

 I think I will fix this by removing support for network_interfaces,
 removable_interfaces, and pccard_ether.  The actual bug at the moment is
 in the way I key off pccard_ether.
 
 For now, the work around is to not set network_interfaces so it is
 filled with all current interfaces on the system
 
 -- Brooks

From: "Darren Pilgrim" <dmp@bitfreak.org>
To: "'Brooks Davis'" <brooks@one-eyed-alien.net>
Cc: <freebsd-gnats-submit@freebsd.org>
Subject: RE: conf/82314: /etc/rc.d/netif does not build the list of interfaces correctly.
Date: Thu, 16 Jun 2005 19:49:50 -0700

 From: Brooks Davis [mailto:brooks@one-eyed-alien.net] 
 > 
 > I think I will fix this by removing support for network_interfaces,
 > removable_interfaces, and pccard_ether.  The actual bug at 
 > the moment is in the way I key off pccard_ether.
 > 
 > For now, the work around is to not set network_interfaces so it is
 > filled with all current interfaces on the system.
 
 That breaks configurations in which not all interfaces listed in
 ifconfig are usable when netif is run at boot.  One example is the iwi
 driver.  The driver attaches and iwi* appears in ifconfig output, but
 you can't actually touch the interface until the firmware is loaded.
 

From: Brooks Davis <brooks@one-eyed-alien.net>
To: Darren Pilgrim <dmp@bitfreak.org>
Cc: "'Brooks Davis'" <brooks@one-eyed-alien.net>,
        freebsd-gnats-submit@freebsd.org
Subject: Re: conf/82314: /etc/rc.d/netif does not build the list of interfaces correctly.
Date: Thu, 16 Jun 2005 21:29:02 -0700

 On Thu, Jun 16, 2005 at 07:49:50PM -0700, Darren Pilgrim wrote:
 > From: Brooks Davis [mailto:brooks@one-eyed-alien.net] 
 > > 
 > > I think I will fix this by removing support for network_interfaces,
 > > removable_interfaces, and pccard_ether.  The actual bug at 
 > > the moment is in the way I key off pccard_ether.
 > > 
 > > For now, the work around is to not set network_interfaces so it is
 > > filled with all current interfaces on the system.
 > 
 > That breaks configurations in which not all interfaces listed in
 > ifconfig are usable when netif is run at boot.  One example is the iwi
 > driver.  The driver attaches and iwi* appears in ifconfig output, but
 > you can't actually touch the interface until the firmware is loaded.
 
 Yes, you can.  I have one, nothing bad happens if you attempt to
 configure it before the firmware is loaded, it just emits a reminder to
 load the firmware and continues.
 
 -- Brooks

From: "Darren Pilgrim" <dmp@bitfreak.org>
To: "'Brooks Davis'" <brooks@one-eyed-alien.net>
Cc: <freebsd-gnats-submit@freebsd.org>
Subject: RE: conf/82314: /etc/rc.d/netif does not build the list of interfaces correctly.
Date: Thu, 16 Jun 2005 21:45:48 -0700

 From: Brooks Davis [mailto:brooks@one-eyed-alien.net]=20
 > On Thu, Jun 16, 2005 at 07:49:50PM -0700, Darren Pilgrim wrote:
 >> From: Brooks Davis [mailto:brooks@one-eyed-alien.net]=20
 >>>=20
 >>> I think I will fix this by removing support for network_interfaces,
 >>> removable_interfaces, and pccard_ether.  The actual bug at=20
 >>> the moment is in the way I key off pccard_ether.
 >>>=20
 >>> For now, the work around is to not set network_interfaces so it is
 >>> filled with all current interfaces on the system.
 >>=20
 >> That breaks configurations in which not all interfaces listed in
 >> ifconfig are usable when netif is run at boot.  One example is the
 >> iwi driver.  The driver attaches and iwi* appears in ifconfig
 >> output, but you can't actually touch the interface until the
 >> firmware is loaded.
 >=20
 > Yes, you can.  I have one, nothing bad happens if you attempt to
 > configure it before the firmware is loaded, it just emits a=20
 > reminder to load the firmware and continues.
 
 That's making a pretty hefty assumption about the driver.  Sure, the iwi
 driver may handle it ok, but there may be other drivers now or in the
 that will do Bad Things.  It would be better to have a configuration
 option to exclude such interfaces.
 

From: Brooks Davis <brooks@one-eyed-alien.net>
To: Darren Pilgrim <dmp@bitfreak.org>
Cc: "'Brooks Davis'" <brooks@one-eyed-alien.net>,
        freebsd-gnats-submit@freebsd.org
Subject: Re: conf/82314: /etc/rc.d/netif does not build the list of interfaces correctly.
Date: Thu, 16 Jun 2005 22:41:44 -0700

 On Thu, Jun 16, 2005 at 09:45:48PM -0700, Darren Pilgrim wrote:
 > From: Brooks Davis [mailto:brooks@one-eyed-alien.net] 
 > > On Thu, Jun 16, 2005 at 07:49:50PM -0700, Darren Pilgrim wrote:
 > >> From: Brooks Davis [mailto:brooks@one-eyed-alien.net] 
 > >>> 
 > >>> I think I will fix this by removing support for network_interfaces,
 > >>> removable_interfaces, and pccard_ether.  The actual bug at 
 > >>> the moment is in the way I key off pccard_ether.
 > >>> 
 > >>> For now, the work around is to not set network_interfaces so it is
 > >>> filled with all current interfaces on the system.
 > >> 
 > >> That breaks configurations in which not all interfaces listed in
 > >> ifconfig are usable when netif is run at boot.  One example is the
 > >> iwi driver.  The driver attaches and iwi* appears in ifconfig
 > >> output, but you can't actually touch the interface until the
 > >> firmware is loaded.
 > > 
 > > Yes, you can.  I have one, nothing bad happens if you attempt to
 > > configure it before the firmware is loaded, it just emits a 
 > > reminder to load the firmware and continues.
 > 
 > That's making a pretty hefty assumption about the driver.  Sure, the iwi
 > driver may handle it ok, but there may be other drivers now or in the
 > that will do Bad Things.  It would be better to have a configuration
 > option to exclude such interfaces.
 
 If a driver calls if_attach() it must not panic or othwerwise harm the
 system as a result of attempting to use the resulting user visiable
 network interface.  If the driver can't make that promise, it has
 no business calling if_attach() until it can.  Any driver that does
 otherwise is broken.
 
 -- Brooks
State-Changed-From-To: open->closed 
State-Changed-By: brooks 
State-Changed-When: Mon Oct 31 19:47:45 GMT 2005 
State-Changed-Why:  
This code has been significantly rewritten and I believe the issues 
described have been resolved. 

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