From trooper@www.trifle.net  Tue May 17 09:56:05 2005
Return-Path: <trooper@www.trifle.net>
Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125])
	by hub.freebsd.org (Postfix) with ESMTP id 3E24116A4CE
	for <FreeBSD-gnats-submit@freebsd.org>; Tue, 17 May 2005 09:56:05 +0000 (GMT)
Received: from www.trifle.net (ns2.trifle.net [195.24.128.164])
	by mx1.FreeBSD.org (Postfix) with ESMTP id D487143D2D
	for <FreeBSD-gnats-submit@freebsd.org>; Tue, 17 May 2005 09:56:01 +0000 (GMT)
	(envelope-from trooper@www.trifle.net)
Received: from www.trifle.net (localhost.trifle.net [127.0.0.1])
	by www.trifle.net (8.13.3/8.12.10) with ESMTP id j4H9tvKo064636
	for <FreeBSD-gnats-submit@freebsd.org>; Tue, 17 May 2005 12:55:57 +0300 (EEST)
	(envelope-from trooper@www.trifle.net)
Received: (from root@localhost)
	by www.trifle.net (8.13.3/8.12.10/Submit) id j4H9tvx4064635;
	Tue, 17 May 2005 12:55:57 +0300 (EEST)
	(envelope-from trooper)
Message-Id: <200505170955.j4H9tvx4064635@www.trifle.net>
Date: Tue, 17 May 2005 12:55:57 +0300 (EEST)
From: "Dmitry Sergienko" <dmitry@trifle.net>
Reply-To: "Dmitry Sergienko" <dmitry@trifle.net>
To: FreeBSD-gnats-submit@freebsd.org
Cc:
Subject: em0 reinitialization while adding aliases to interface
X-Send-Pr-Version: 3.113
X-GNATS-Notify:

>Number:         81147
>Category:       kern
>Synopsis:       [net] [patch] em0 reinitialization while adding aliases to interface
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    jfv
>State:          suspended
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Tue May 17 10:00:25 GMT 2005
>Closed-Date:    
>Last-Modified:  Mon Aug 23 18:21:50 UTC 2010
>Originator:     Dmitry Sergienko
>Release:        FreeBSD 5.4-RELEASE i386
>Organization:
Trifle Co., Ltd.
>Environment:
 FreeBSD www.trifle.net 5.4-RELEASE FreeBSD 5.4-RELEASE #3: Mon May 16 18:59:05 EEST 2005 trooper@www.trifle.net:/usr/obj/usr/src/sys/TRIFLE i386
 
 Machine
 ~~~~~~~
 CPU: Athlon 1700 XP+
 M/B: ASUS A7N8X
 Netcard: em0: <Intel(R) PRO/1000 Network Connection, Version - 1.7.35> port 0x9800-0x983f mem 0xd9120000-0xd913ffff,0xd9100000-0xd911ffff irq 5 at device 9.0 on pci1; device = '82547EI Gigabit Ethernet Controller'
 
 OS
 ~~
 This bug affects both 4.10-RELEASE and 5.4-RELEASE.
 
>Description:

Network card loses link while adding an alias to interface em0.
This affects only em0 - neither vlans with vlandev em0, nor fxp0.
Problem was detected on two different machines with the same netcards

>How-To-Repeat:

Initial state:

root@www:/home/trooper# ifconfig em0
em0: flags=8843<UP,BROADCAST,RUNNING,SIMPLEX,MULTICAST> mtu 1500
        options=4b<RXCSUM,TXCSUM,VLAN_MTU,POLLING>
        inet 195.24.128.164 netmask 0xfffffff0 broadcast 195.24.128.175
        inet 195.24.128.72 netmask 0xffffffe0 broadcast 195.24.128.95
        ether 00:0e:0c:33:c7:a8
        media: Ethernet autoselect (1000baseTX <full-duplex>)
        status: active

root@www:/home/trooper# dmesg
root@www:/home/trooper#

Now let's add an alias to interface em0:

root@www:/home/trooper# ifconfig em0 alias 85.198.128.1/24 ; while true; do
date +%H:%M:%S; ifconfig em0 | egrep '(media|status)' ; sleep 1s; done
15:44:14
        media: Ethernet autoselect
        status: no carrier
15:44:15
        media: Ethernet autoselect
        status: no carrier
15:44:16
        media: Ethernet autoselect
        status: no carrier
15:44:17
        media: Ethernet autoselect (1000baseTX <full-duplex>)
        status: active

root@www:/home/trooper# ifconfig em0
em0: flags=8843<UP,BROADCAST,RUNNING,SIMPLEX,MULTICAST> mtu 1500
        options=4b<RXCSUM,TXCSUM,VLAN_MTU,POLLING>
        inet 195.24.128.164 netmask 0xfffffff0 broadcast 195.24.128.175
        inet 195.24.128.72 netmask 0xffffffe0 broadcast 195.24.128.95
        inet 85.198.128.1 netmask 0xffffff00 broadcast 85.198.128.255
        ether 00:0e:0c:33:c7:a8
        media: Ethernet autoselect (1000baseTX <full-duplex>)
        status: active

root@www:/home/trooper# dmesg
em0: Link is up 1000 Mbps Full Duplex
root@www:/home/trooper# 

Alias has been added, but interface was reinitialized.

>Fix:
No fix currently found.

>Release-Note:
>Audit-Trail:

From: Ruslan Ermilov <ru@freebsd.org>
To: Dmitry Sergienko <dmitry@trifle.net>
Cc: FreeBSD-gnats-submit@freebsd.org
Subject: Re: kern/81147: em0 reinitialization while adding aliases to interface
Date: Tue, 17 May 2005 15:06:56 +0300

 On Tue, May 17, 2005 at 12:55:57PM +0300, Dmitry Sergienko wrote:
 > Network card looses link while adding an alias to interface em0.
 > This affects only em0 - neither vlans with vlandev em0, nor fxp0.
 > Problem was detected on two different machines with the same netcards
 > 
 This simple patch works for me:
 
 %%%
 Index: if_em.c
 ===================================================================
 RCS file: /home/ncvs/src/sys/dev/em/if_em.c,v
 retrieving revision 1.63
 diff -u -p -r1.63 if_em.c
 --- if_em.c	5 Apr 2005 07:06:47 -0000	1.63
 +++ if_em.c	14 Apr 2005 19:03:36 -0000
 @@ -832,12 +832,14 @@ em_init_locked(struct adapter * adapter)
          bcopy(adapter->interface_data.ac_enaddr, adapter->hw.mac_addr,
                ETHER_ADDR_LEN);
  
 +#if 0
  	/* Initialize the hardware */
  	if (em_hardware_init(adapter)) {
  		printf("em%d: Unable to initialize the hardware\n", 
  		       adapter->unit);
  		return;
  	}
 +#endif
  
  	if (ifp->if_capenable & IFCAP_VLAN_HWTAGGING)
  		em_enable_vlans(adapter);
 %%%
 
 
 -- 
 Ruslan Ermilov
 ru@FreeBSD.org
 FreeBSD committer
Responsible-Changed-From-To: freebsd-bugs->tackerman 
Responsible-Changed-By: ru 
Responsible-Changed-When: Tue May 17 12:10:32 GMT 2005 
Responsible-Changed-Why:  
Pass the PR and patch over to an official maintainer. 

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

From: Dmitry Sergienko <dmitry@trifle.net>
To: bug-followup@FreeBSD.org, dmitry@trifle.net
Cc:  
Subject: Re: kern/81147: em0 reinitialization while adding aliases to interface
Date: Tue, 17 May 2005 17:29:55 +0300

 Thanks, this patch solved my problem on 5.4-RELEASE. Will also try on 4.10 later.
 Hope it will be committed ASAP.
 
 -- 
 Best wishes,
 Dmitry Sergienko (SDA104-RIPE)
 Trifle Co., Ltd.
 

From: =?ISO-8859-1?Q?B=E9la=EFd_A=EFtdahmane?= <belaid.aitdahmane@dbee.com>
To: bug-followup@FreeBSD.org, dmitry@trifle.net
Cc:  
Subject: Re: kern/81147: [em] [patch] em0 reinitialization while adding aliases
 to interface
Date: Thu, 19 Jan 2006 18:51:43 +0100

 The problem seems to be at a higher level : ether_ioctl (net/if_ethersubr.c)
 
 The process when alias is added :
 
 1) in_control (netinet/in.c) :
 
 int
 in_control(so, cmd, data, ifp, td)
 	struct socket *so;
 	u_long cmd;
 	caddr_t data;
 	register struct ifnet *ifp;
 	struct thread *td;
 {
 ...
 
 case SIOCAIFADDR:
 ...
 		if (ifra->ifra_addr.sin_family == AF_INET &&
 		    (hostIsNew || maskIsNew))
 			error = in_ifinit(ifp, ia, &ifra->ifra_addr, 0);
 
 
 
 2) in_ifinit (netinet/in.c) :
 
 static int
 in_ifinit(ifp, ia, sin, scrub)
 	register struct ifnet *ifp;
 	register struct in_ifaddr *ia;
 	struct sockaddr_in *sin;
 	int scrub;
 {
 ...
 	/*
 	 * Give the interface a chance to initialize
 	 * if this is its first address,
 	 * and to validate the address if necessary.
 	 */
 	if (ifp->if_ioctl) {
 		error = (*ifp->if_ioctl)(ifp, SIOCSIFADDR, (caddr_t)ia);
 
 
 3) em_ioctl (dev/em/if_em.c) :
 
 static int
 em_ioctl(struct ifnet *ifp, u_long command, caddr_t data)
 {
 ...
 	case SIOCSIFADDR:
 	case SIOCGIFADDR:
 		IOCTL_DEBUGOUT("ioctl rcv'd: SIOCxIFADDR (Get/Set Interface Addr)");
 		ether_ioctl(ifp, command, data);
 		break;
 
 
 4) ether_ioctl (net/f_ethersubr.c) :
 
 int
 ether_ioctl(struct ifnet *ifp, int command, caddr_t data)
 {
 ...
 #ifdef INET
 		case AF_INET:
 			ifp->if_init(ifp->if_softc);	/* before arpwhohas */
 			arp_ifinit(ifp, ifa);
 			break;
 #endif
 
 
 
 At this step, the interface is reinitialized  by the driver (em_init is 
 registered as the interface init function).
 
 The question is : why do we need to reinitialize the hardware when the 
 interface is up and running ?
 
 This behaviour seems to be transparent on some drivers (fxp, bge etc.) 
 but certainly not with em.
 
 The patch that follows is inspired by NetBSD code :
 
 *** sys/net/if_ethersubr.c.gen    Thu Jan 19 17:29:40 2006
 --- sys/net/if_ethersubr.c    Thu Jan 19 18:17:02 2006
 ***************
 *** 1057,1063 ****
           switch (ifa->ifa_addr->sa_family) {
   #ifdef INET
           case AF_INET:
 !             ifp->if_init(ifp->if_softc);    /* before arpwhohas */
               arp_ifinit(ifp, ifa);
               break;
   #endif
 --- 1057,1065 ----
           switch (ifa->ifa_addr->sa_family) {
   #ifdef INET
           case AF_INET:
 !             /* init only if not running */
 !             if ((ifp->if_flags & IFF_RUNNING) == 0)
 !                 ifp->if_init(ifp->if_softc);    /* before arpwhohas */
               arp_ifinit(ifp, ifa);
               break;
   #endif
 
 
 This patch has been tested and is functionnal with fxp, em, bge on 
 5.4-STABLE / i386.
 
 It could be applied on 5.x and 6.x (not looked at 4.x).
 
 Belaid Aitdahmane.
 
 
 
 
State-Changed-From-To: open->feedback 
State-Changed-By: linimon 
State-Changed-When: Wed Apr 5 00:40:15 UTC 2006 
State-Changed-Why:  
Is this still a problem with current versions of FreeBSD? 


Responsible-Changed-From-To: tackerman->linimon 
Responsible-Changed-By: linimon 
Responsible-Changed-When: Wed Apr 5 00:40:15 UTC 2006 
Responsible-Changed-Why:  
Reset PR assigned to inactive committer. 

Hat:	gnats-admin 

http://www.freebsd.org/cgi/query-pr.cgi?pr=81147 
State-Changed-From-To: feedback->suspended 
State-Changed-By: linimon 
State-Changed-When: Mon Sep 4 16:31:11 UTC 2006 
State-Changed-Why:  
Feedback timeout.  Set to suspended since it contains a patch. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=81147 
Responsible-Changed-From-To: linimon->freebsd-bugs 
Responsible-Changed-By: linimon 
Responsible-Changed-When: Sun May 6 00:46:55 UTC 2007 
Responsible-Changed-Why:  
Return this one to the pool. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=81147 
Responsible-Changed-From-To: freebsd-bugs->freebsd-net 
Responsible-Changed-By: linimon 
Responsible-Changed-When: Tue May 8 22:30:12 UTC 2007 
Responsible-Changed-Why:  
I'm going to reclassify this one.  The original submitter did indeed 
submit a patch, which was kind of hacky; I got no response when asking 
for feedback.  However, a later correspondant noted that this was more of 
a general problem, and submitted a patch against sys/net/if_ethersubr.c. 
Since that patch may need to be evaluated, I'll reassign this to -net. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=81147 
Responsible-Changed-From-To: freebsd-net->jfv 
Responsible-Changed-By: andre 
Responsible-Changed-When: Mon Aug 23 18:21:16 UTC 2010 
Responsible-Changed-Why:  
Over to maintainer. 

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