From alex@hugo.bmg.gv.at  Mon Jan 31 13:15:11 2005
Return-Path: <alex@hugo.bmg.gv.at>
Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125])
	by hub.freebsd.org (Postfix) with ESMTP id 1FD7F16A4CE
	for <FreeBSD-gnats-submit@freebsd.org>; Mon, 31 Jan 2005 13:15:11 +0000 (GMT)
Received: from m1.bmgf.gv.at (m1.bmgf.gv.at [194.48.236.129])
	by mx1.FreeBSD.org (Postfix) with ESMTP id BA82643D1F
	for <FreeBSD-gnats-submit@freebsd.org>; Mon, 31 Jan 2005 13:15:09 +0000 (GMT)
	(envelope-from alex@hugo.bmg.gv.at)
Message-Id: <200501311315.j0VDF6BF006738@hugo.bmg.gv.at>
Date: Mon, 31 Jan 2005 14:15:06 +0100 (MET)
From: Alexander Hausner <alex@hugo.bmg.gv.at>
Reply-To: Alexander Hausner <alex@hugo.bmg.gv.at>
To: FreeBSD-gnats-submit@freebsd.org
Cc:
Subject: [patch] em driver does not send routing messages on interface link state changes
X-Send-Pr-Version: 3.113
X-GNATS-Notify:

>Number:         76890
>Category:       kern
>Synopsis:       [em] [patch] em driver does not send routing messages on interface link state changes
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    glebius
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Mon Jan 31 13:20:21 GMT 2005
>Closed-Date:    Mon Nov 07 11:03:33 GMT 2005
>Last-Modified:  Mon Nov 07 11:03:33 GMT 2005
>Originator:     Alexander Hausner
>Release:        FreeBSD 5.3-STABLE i386
>Organization:
BMG
>Environment:
FreeBSD proxy1.bmg.gv.at 5.3-STABLE FreeBSD 5.3-STABLE #2: Wed Jan 26 15:59:34 CET 2005     root@proxy1.bmg.gv.at:/usr/src/sys/i386/compile/PROXY_CARP  i386


	
>Description:
Intel(R) PRO/1000 Gigabit Ethernet adapter driver (em) does not send routing messages on interface link state changes, which where needed by some kind of routing/failover software (zebra, ifstated etc.)
>How-To-Repeat:
If you unplug/plug the network-cable on an em-interface, you will get no routing messages on routing sockets.
>Fix:

	

--- if_em.c.patch begins here ---
--- sys/dev/em/if_em.c.orig	Mon Jan 31 13:32:37 2005
+++ sys/dev/em/if_em.c	Mon Jan 31 13:32:38 2005
@@ -34,6 +34,7 @@ POSSIBILITY OF SUCH DAMAGE.
 /*$FreeBSD: /repoman/r/ncvs/src/sys/dev/em/if_em.c,v 1.44.2.6 2005/01/30 06:05:12 yar Exp $*/
 
 #include <dev/em/if_em.h>
+#include <net/route.h>
 
 /*********************************************************************
  *  Set this to one to display debug statistics                                                   
@@ -1016,6 +1017,7 @@ em_intr(void *arg)
 		callout_stop(&adapter->timer);
                 adapter->hw.get_link_status = 1;
                 em_check_for_link(&adapter->hw);
+                rt_ifmsg(ifp);
                 em_print_link_status(adapter);
 		callout_reset(&adapter->timer, 2*hz, em_local_timer, adapter);
         }
--- if_em.c.patch ends here ---


>Release-Note:
>Audit-Trail:

From: Gleb Smirnoff <glebius@freebsd.org>
To: Alexander Hausner <alex@hugo.bmg.gv.at>
Cc: FreeBSD-gnats-submit@freebsd.org
Subject: Re: kern/76890: [patch] em driver does not send routing messages on interface link state changes
Date: Wed, 2 Feb 2005 16:52:05 +0300

   Alexander,
 
 A> Intel(R) PRO/1000 Gigabit Ethernet adapter driver (em) does not send
 A> routing messages on interface link state changes, which where needed
 A> by some kind of routing/failover software (zebra, ifstated etc.)
 
 A> If you unplug/plug the network-cable on an em-interface, you will get
 A> no routing messages on routing sockets.
 
 A>  /*********************************************************************
 A>   *  Set this to one to display debug statistics                                                   
 A> @@ -1016,6 +1017,7 @@ em_intr(void *arg)
 A>  		callout_stop(&adapter->timer);
 A>                  adapter->hw.get_link_status = 1;
 A>                  em_check_for_link(&adapter->hw);
 A> +                rt_ifmsg(ifp);
 A>                  em_print_link_status(adapter);
 A>  		callout_reset(&adapter->timer, 2*hz, em_local_timer, adapter);
 A>          }
 
 The problem is that em(4) is not miibus(4) aware. All miibus(4) aware drivers send
 routing message when link state changes.
 
 Suggested patch looks like a hack, and has one significant problem - rt_ifmsg()
 would be called hz/2 times per second, while we need to call only when link
 state does changes.
 
 I'd propose this patch, which is still hack alike... Sorry, but it can be applied
 only to HEAD, where if_link_state_change() has been introduced. I'd be happy to MFC
 this change to RELENG_5 but it will cause binary incompatibilty between miibus.ko
 and kernel.
 
 Index: if_em.c
 ===================================================================
 RCS file: /home/ncvs/src/sys/dev/em/if_em.c,v
 retrieving revision 1.60
 diff -u -r1.60 if_em.c
 --- if_em.c	26 Jan 2005 19:45:51 -0000	1.60
 +++ if_em.c	2 Feb 2005 12:45:49 -0000
 @@ -1654,6 +1654,8 @@
  static void
  em_print_link_status(struct adapter * adapter)
  {
 +	struct ifnet *ifp = &adapter->interface_data.ac_if;
 +
  	if (E1000_READ_REG(&adapter->hw, STATUS) & E1000_STATUS_LU) {
  		if (adapter->link_active == 0) {
  			em_get_speed_and_duplex(&adapter->hw, 
 @@ -1667,6 +1669,7 @@
  					"Full Duplex" : "Half Duplex"));
  			adapter->link_active = 1;
  			adapter->smartspeed = 0;
 +			if_link_state_change(ifp, LINK_STATE_UP);
  		}
  	} else {
  		if (adapter->link_active == 1) {
 @@ -1675,6 +1678,7 @@
  			if (bootverbose)
  				printf("em%d: Link is Down\n", adapter->unit);
  			adapter->link_active = 0;
 +			if_link_state_change(ifp, LINK_STATE_DOWN);
  		}
  	}
  
 Index: if_em.h
 ===================================================================
 RCS file: /home/ncvs/src/sys/dev/em/if_em.h,v
 retrieving revision 1.30
 diff -u -r1.30 if_em.h
 --- if_em.h	15 Jan 2005 20:52:15 -0000	1.30
 +++ if_em.h	1 Feb 2005 14:52:19 -0000
 @@ -53,6 +53,7 @@
  #include <net/ethernet.h>
  #include <net/if_dl.h>
  #include <net/if_media.h>
 +#include <net/if_var.h>
  
  #include <net/bpf.h>
  #include <net/if_types.h>
 
 -- 
 Totus tuus, Glebius.
 GLEBIUS-RIPN GLEB-RIPE
State-Changed-From-To: open->patched 
State-Changed-By: glebius 
State-Changed-When: Fri Feb 4 18:35:48 GMT 2005 
State-Changed-Why:  
Now em(4) calls if_link_state_change(), which generates route message. 


Responsible-Changed-From-To: freebsd-bugs->glebius 
Responsible-Changed-By: glebius 
Responsible-Changed-When: Fri Feb 4 18:35:48 GMT 2005 
Responsible-Changed-Why:  
I've done the change. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=76890 
State-Changed-From-To: patched->closed 
State-Changed-By: glebius 
State-Changed-When: Mon Nov 7 11:03:16 GMT 2005 
State-Changed-Why:  
Fixed in 6.0-RELEASE. 

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