From nobody@FreeBSD.org  Tue Mar 13 20:30:51 2007
Return-Path: <nobody@FreeBSD.org>
Received: from mx1.freebsd.org (mx1.freebsd.org [69.147.83.52])
	by hub.freebsd.org (Postfix) with ESMTP id DABBC16A400
	for <freebsd-gnats-submit@FreeBSD.org>; Tue, 13 Mar 2007 20:30:51 +0000 (UTC)
	(envelope-from nobody@FreeBSD.org)
Received: from www.freebsd.org (www.freebsd.org [69.147.83.33])
	by mx1.freebsd.org (Postfix) with ESMTP id C0AD113C44B
	for <freebsd-gnats-submit@FreeBSD.org>; Tue, 13 Mar 2007 20:30:51 +0000 (UTC)
	(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 l2DKUpgK069160
	for <freebsd-gnats-submit@FreeBSD.org>; Tue, 13 Mar 2007 20:30:51 GMT
	(envelope-from nobody@www.freebsd.org)
Received: (from nobody@localhost)
	by www.freebsd.org (8.13.1/8.13.1/Submit) id l2DKUpc6069159;
	Tue, 13 Mar 2007 20:30:51 GMT
	(envelope-from nobody)
Message-Id: <200703132030.l2DKUpc6069159@www.freebsd.org>
Date: Tue, 13 Mar 2007 20:30:51 GMT
From: "Devon H. O'Dell"<devon.odell@coyotepoint.com>
To: freebsd-gnats-submit@FreeBSD.org
Subject: [PATCH] Invalid Assumption in SIOCSIFADDR in ether_ioctl()
X-Send-Pr-Version: www-3.0

>Number:         110284
>Category:       kern
>Synopsis:       [if_ethersubr] Invalid Assumption in SIOCSIFADDR in ether_ioctl()
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    freebsd-net
>State:          open
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Tue Mar 13 20:40:05 GMT 2007
>Closed-Date:    
>Last-Modified:  Fri May 18 14:30:08 UTC 2012
>Originator:     Devon H. O'Dell
>Release:        6.2-STABLE
>Organization:
Coyote Point Systems, Inc.
>Environment:
FreeBSD dho.coyotepoint.com 6.2-STABLE FreeBSD 6.2-STABLE #3: Fri Feb 23 16:45:30 EST 2007     dho@dho.coyotepoint.com:/usr/obj/usr/src/sys/SMP  i386
>Description:
Many NICs simply offload ioctls for SIOCSIFADDR to ether_ioctl(). When in
ether_ioctl(), we call the interface's if_init() routine. This is good 
when the interface is down and we haven't assigned an IP address yet. 
However, this routine is also called when aliases are added to the 
interface.

Calling if_init() at this point is undesirable because the chip is 
lready running and doesn't need to be initialized again. Additionally, 
for some chips (em(4) and vr(4) in my observations) the number of chip 
resets and the time required to autonegotiate is significant enough to 
cause the NIC to go OTL for a significant period of time (>15 seconds).

The attached patch only calls if_init() if the driver's if_flags field 
*DOES NOT* have the IFF_RUNNING bit set.

The gratuitous ARP (which is sent, if I understand correctly, because of
the succeeding arp_ifinit() call) should still be sent in either case.
>How-To-Repeat:
I'm not sure whether this is visible on all em(4) or vr(4) chips. To
visualize the problem, open two terminal sessions. In one, ping a machine
on the same network. On another, add an interface alias. Some number of
packets should never reach their destination.
>Fix:
A patch is available at http://databits.net/~dho/if_ethersubr.patch

I would have attached it, but the form doesn't like the Content-type
of my if_ethersubr.patch :(
>Release-Note:
>Audit-Trail:
Responsible-Changed-From-To: freebsd-bugs->kmacy 
Responsible-Changed-By: kmacy 
Responsible-Changed-When: Fri Nov 16 06:33:58 UTC 2007 
Responsible-Changed-Why:  

This shouldn't be hard for me to fix. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=110284 
Responsible-Changed-From-To: kmacy->freebsd-net 
Responsible-Changed-By: gavin 
Responsible-Changed-When: Sun May 29 22:42:43 UTC 2011 
Responsible-Changed-Why:  
kmacy has asked for all of his PRs to be reassigned back to the pool. 

The patch no longer seems to be available, but should be trivial to 
re-implenment given the description in the PR.  Hopefully somebody 
will know if this fix is correct. 

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

From: "Devon H. O'Dell" <devon.odell@gmail.com>
To: bug-followup@FreeBSD.org, freebsd-net@freebsd.org, gavin@freebsd.org
Cc:  
Subject: Re: kern/110284: [if_ethersubr] Invalid Assumption in SIOCSIFADDR in ether_ioctl()
Date: Wed, 16 May 2012 22:33:31 -0400

 Hi Gavin, freebsd-net,
 
 I submitted this PR when I worked at Coyote Point. I'm no longer
 there, but I do remember this issue well. The discussion around this
 patch happened on IRC and not the PR, which is unfortunate. If I
 recall correctly, rwatson's stance was that the real fix was to fix
 the heinous layer between ioctl and device. As far as I'm aware, this
 is still an issue with current drivers, and this patch still solves
 the issue. CP ran with it successfully for years. (And unsuccessfully
 for a time before it was implemented :)).
 
 The patch is basically (forgive formatting):
 
 --- if_ethersubr.c      2011-09-22 20:51:37.000000000 -0400
 +++ /home/dho/if_ethersubr.c    2012-05-16 22:27:17.000000000 -0400
 @@ -1146,7 +1146,9 @@
                 switch (ifa->ifa_addr->sa_family) {
  #ifdef INET
                 case AF_INET:
 -                       ifp->if_init(ifp->if_softc);    /* before arpwhohas */
 +                       if (ifp->if_flags & IFF_RUNNING == 0) {
 +                               ifp->if_init(ifp->if_softc);    /*
 before arpwhohas */
 +                       }
                         arp_ifinit(ifp, ifa);
                         break;
  #endif

From: "Devon H. O'Dell" <devon.odell@gmail.com>
To: bug-followup@freebsd.org, freebsd-net@freebsd.org, gavin@freebsd.org
Cc:  
Subject: Re: kern/110284: [if_ethersubr] Invalid Assumption in SIOCSIFADDR in ether_ioctl()
Date: Wed, 16 May 2012 22:37:36 -0400

 2012/5/16 Devon H. O'Dell <devon.odell@gmail.com>:
 > Hi Gavin, freebsd-net,
 >
 > --- if_ethersubr.c =A0 =A0 =A02011-09-22 20:51:37.000000000 -0400
 > +++ /home/dho/if_ethersubr.c =A0 =A02012-05-16 22:27:17.000000000 -0400
 > @@ -1146,7 +1146,9 @@
 > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0switch (ifa->ifa_addr->sa_family) {
 > =A0#ifdef INET
 > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0case AF_INET:
 > - =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 ifp->if_init(ifp->if_softc)=
 ; =A0 =A0/* before arpwhohas */
 > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 if (ifp->if_flags & IFF_RUN=
 NING =3D=3D 0) {
 
 That's probably ((ifp->if_flags & IFF_RUNNING) =3D=3D 0). Also, I'm not on
 freebsd-net or cc'ed on the PR afaik, so please cc me explicitly on
 followups if more information is needed.
 
 --dho
 
 > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 ifp->if_ini=
 t(ifp->if_softc); =A0 =A0/*
 > before arpwhohas */
 > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 }
 > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0arp_ifinit(ifp, ifa);
 > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0break;
 > =A0#endif

From: John Baldwin <jhb@freebsd.org>
To: freebsd-net@freebsd.org
Cc: "Devon H. O'Dell" <devon.odell@gmail.com>,
 bug-followup@freebsd.org,
 gavin@freebsd.org,
 Robert Watson <rwatson@freebsd.org>
Subject: Re: kern/110284: [if_ethersubr] Invalid Assumption in SIOCSIFADDR in ether_ioctl()
Date: Fri, 18 May 2012 10:27:49 -0400

 On Wednesday, May 16, 2012 10:37:36 pm Devon H. O'Dell wrote:
 > 2012/5/16 Devon H. O'Dell <devon.odell@gmail.com>:
 > > Hi Gavin, freebsd-net,
 > >
 > > --- if_ethersubr.c      2011-09-22 20:51:37.000000000 -0400
 > > +++ /home/dho/if_ethersubr.c    2012-05-16 22:27:17.000000000 -0400
 > > @@ -1146,7 +1146,9 @@
 > >                switch (ifa->ifa_addr->sa_family) {
 > >  #ifdef INET
 > >                case AF_INET:
 > > -                       ifp->if_init(ifp->if_softc);    /* before 
 arpwhohas */
 > > +                       if (ifp->if_flags & IFF_RUNNING == 0) {
 > 
 > That's probably ((ifp->if_flags & IFF_RUNNING) == 0). Also, I'm not on
 > freebsd-net or cc'ed on the PR afaik, so please cc me explicitly on
 > followups if more information is needed.
 
 You mean if_drv_flags and IF_DRV_RUNNING.
 
 It's a bit fugly, yes, and the new check would be racey.
 
 -- 
 John Baldwin
>Unformatted:
