From mdodd@FreeBSD.org  Mon Aug 29 22:59:23 2011
Return-Path: <mdodd@FreeBSD.org>
Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34])
	by hub.freebsd.org (Postfix) with ESMTP id E0D68106566C
	for <FreeBSD-gnats-submit@freebsd.org>; Mon, 29 Aug 2011 22:59:23 +0000 (UTC)
	(envelope-from mdodd@FreeBSD.org)
Received: from freefall.freebsd.org (freefall.freebsd.org [IPv6:2001:4f8:fff6::28])
	by mx1.freebsd.org (Postfix) with ESMTP id B72F68FC18
	for <FreeBSD-gnats-submit@freebsd.org>; Mon, 29 Aug 2011 22:59:23 +0000 (UTC)
Received: from freefall.freebsd.org (localhost [127.0.0.1])
	by freefall.freebsd.org (8.14.4/8.14.4) with ESMTP id p7TMxNf2046542
	for <FreeBSD-gnats-submit@freebsd.org>; Mon, 29 Aug 2011 22:59:23 GMT
	(envelope-from mdodd@freefall.freebsd.org)
Received: (from mdodd@localhost)
	by freefall.freebsd.org (8.14.4/8.14.4/Submit) id p7TMxN0n046541;
	Mon, 29 Aug 2011 22:59:23 GMT
	(envelope-from mdodd)
Message-Id: <201108292259.p7TMxN0n046541@freefall.freebsd.org>
Date: Mon, 29 Aug 2011 22:59:23 GMT
From: "Matthew N. Dodd" <mdodd@FreeBSD.org>
Reply-To: "Matthew N. Dodd" <mdodd@FreeBSD.org>
To: FreeBSD-gnats-submit@freebsd.org
Cc:
Subject: bridge(4) should attempt to use a static MAC address.
X-Send-Pr-Version: 3.113
X-GNATS-Notify:

>Number:         160300
>Category:       kern
>Synopsis:       [if_bridge] [patch] bridge(4) should attempt to use a static MAC address.
>Confidential:   no
>Severity:       non-critical
>Priority:       medium
>Responsible:    thompsa
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Mon Aug 29 23:00:19 UTC 2011
>Closed-Date:    Sun Sep 11 23:41:49 UTC 2011
>Last-Modified:  Sun Sep 11 23:41:49 UTC 2011
>Originator:     
>Release:        
>Organization:
>Environment:
System: FreeBSD neo-sasami.jurai.net 8.2-STABLE FreeBSD 8.2-STABLE #5 r224868M: Mon Aug 15 21:36:11 EDT 2011     root@neo-sasami.jurai.net:/vol/raid/svn/stable8/sys/i386/compile/DL380G3  i386


	
Description:
	bridge(4) uses a random number function to generate it's MAC
	address.  This causes issues with IPv6.

	<precise description of the problem (multiple lines)>
>Description:
 Submitter-Id:	current-users
 Originator:	Matthew N. Dodd
 Release:	FreeBSD 8.2-STABLE i386
>How-To-Repeat:
	
>Fix:
	Use the Hostid and interface unit number to generate a 
	MAC address and fall-back to the random number generator
	on conflict.

	

Index: if_bridge.c
===================================================================
--- if_bridge.c	(revision 224868)
+++ if_bridge.c	(working copy)
@@ -85,6 +85,7 @@
 #include <sys/malloc.h>
 #include <sys/protosw.h>
 #include <sys/systm.h>
+#include <sys/jail.h>
 #include <sys/time.h>
 #include <sys/socket.h> /* for net/if.h */
 #include <sys/sockio.h>
@@ -560,7 +561,7 @@
 {
 	struct bridge_softc *sc, *sc2;
 	struct ifnet *bifp, *ifp;
-	int retry;
+	int fb, retry;
 
 	sc = malloc(sizeof(*sc), M_DEVBUF, M_WAITOK|M_ZERO);
 	ifp = sc->sc_ifp = if_alloc(IFT_ETHER);
@@ -600,10 +601,24 @@
 	 * possible that we might have address collisions, so make sure that
 	 * this hardware address isn't already in use on another bridge.
 	 */
+	fb = 0;
 	for (retry = 1; retry != 0;) {
-		arc4rand(sc->sc_defaddr, ETHER_ADDR_LEN, 1);
-		sc->sc_defaddr[0] &= ~1;	/* clear multicast bit */
-		sc->sc_defaddr[0] |= 2;		/* set the LAA bit */
+		if (fb) {
+			arc4rand(sc->sc_defaddr, ETHER_ADDR_LEN, 1);
+			sc->sc_defaddr[0] &= ~1;/* clear multicast bit */
+			sc->sc_defaddr[0] |= 2;	/* set the LAA bit */
+		} else {
+			unsigned long hostid;
+			getcredhostid(curthread->td_ucred, &hostid);
+			sc->sc_defaddr[0] = 0x2;
+			sc->sc_defaddr[1] = (hostid >> 24) & 0xff;
+			sc->sc_defaddr[2] = (hostid >> 16) & 0xff;
+			sc->sc_defaddr[3] = (hostid >> 8 ) & 0xff;
+			sc->sc_defaddr[4] =  hostid        & 0xff;
+			sc->sc_defaddr[5] = ifp->if_dunit & 0xff;
+		}
+
+		fb = 1;
 		retry = 0;
 		mtx_lock(&bridge_list_mtx);
 		LIST_FOREACH(sc2, &bridge_list, sc_list) {


>Release-Note:
>Audit-Trail:
Responsible-Changed-From-To: freebsd-bugs->freebsd-net 
Responsible-Changed-By: linimon 
Responsible-Changed-When: Tue Aug 30 01:46:51 UTC 2011 
Responsible-Changed-Why:  
Over to maintainer(s). 

http://www.freebsd.org/cgi/query-pr.cgi?pr=160300 
Responsible-Changed-From-To: freebsd-net->thompsa 
Responsible-Changed-By: thompsa 
Responsible-Changed-When: Tue Aug 30 01:49:53 UTC 2011 
Responsible-Changed-Why:  
Grab. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=160300 
State-Changed-From-To: open->patched 
State-Changed-By: thompsa 
State-Changed-When: Sun Sep 4 22:08:40 UTC 2011 
State-Changed-Why:  
Committed to HEAD 

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

From: dfilter@FreeBSD.ORG (dfilter service)
To: bug-followup@FreeBSD.org
Cc:  
Subject: Re: kern/160300: commit references a PR
Date: Sun,  4 Sep 2011 22:06:47 +0000 (UTC)

 Author: thompsa
 Date: Sun Sep  4 22:06:32 2011
 New Revision: 225380
 URL: http://svn.freebsd.org/changeset/base/225380
 
 Log:
   On the first loop for generating a bridge MAC address use the local
   hostid, this gives a good chance of keeping the same address over
   reboots. This is intended to help IPV6 and similar which generate
   their addresses from the mac.
   
   PR:		kern/160300
   Submitted by:	mdodd
   Approved by:	re (kib)
 
 Modified:
   head/sys/net/if_bridge.c
 
 Modified: head/sys/net/if_bridge.c
 ==============================================================================
 --- head/sys/net/if_bridge.c	Sun Sep  4 16:26:43 2011	(r225379)
 +++ head/sys/net/if_bridge.c	Sun Sep  4 22:06:32 2011	(r225380)
 @@ -85,6 +85,7 @@ __FBSDID("$FreeBSD$");
  #include <sys/malloc.h>
  #include <sys/protosw.h>
  #include <sys/systm.h>
 +#include <sys/jail.h>
  #include <sys/time.h>
  #include <sys/socket.h> /* for net/if.h */
  #include <sys/sockio.h>
 @@ -560,7 +561,8 @@ bridge_clone_create(struct if_clone *ifc
  {
  	struct bridge_softc *sc, *sc2;
  	struct ifnet *bifp, *ifp;
 -	int retry;
 +	int fb, retry;
 +	unsigned long hostid;
  
  	sc = malloc(sizeof(*sc), M_DEVBUF, M_WAITOK|M_ZERO);
  	ifp = sc->sc_ifp = if_alloc(IFT_ETHER);
 @@ -593,17 +595,30 @@ bridge_clone_create(struct if_clone *ifc
  	IFQ_SET_READY(&ifp->if_snd);
  
  	/*
 -	 * Generate a random ethernet address with a locally administered
 -	 * address.
 +	 * Generate an ethernet address with a locally administered address.
  	 *
  	 * Since we are using random ethernet addresses for the bridge, it is
  	 * possible that we might have address collisions, so make sure that
  	 * this hardware address isn't already in use on another bridge.
 +	 * The first try uses the hostid and falls back to arc4rand().
  	 */
 +	fb = 0;
 +	getcredhostid(curthread->td_ucred, &hostid);
  	for (retry = 1; retry != 0;) {
 -		arc4rand(sc->sc_defaddr, ETHER_ADDR_LEN, 1);
 -		sc->sc_defaddr[0] &= ~1;	/* clear multicast bit */
 -		sc->sc_defaddr[0] |= 2;		/* set the LAA bit */
 +		if (fb || hostid == 0) {
 +			arc4rand(sc->sc_defaddr, ETHER_ADDR_LEN, 1);
 +			sc->sc_defaddr[0] &= ~1;/* clear multicast bit */
 +			sc->sc_defaddr[0] |= 2;	/* set the LAA bit */
 +		} else {
 +			sc->sc_defaddr[0] = 0x2;
 +			sc->sc_defaddr[1] = (hostid >> 24) & 0xff;
 +			sc->sc_defaddr[2] = (hostid >> 16) & 0xff;
 +			sc->sc_defaddr[3] = (hostid >> 8 ) & 0xff;
 +			sc->sc_defaddr[4] =  hostid        & 0xff;
 +			sc->sc_defaddr[5] = ifp->if_dunit & 0xff;
 +		}
 +
 +		fb = 1;
  		retry = 0;
  		mtx_lock(&bridge_list_mtx);
  		LIST_FOREACH(sc2, &bridge_list, sc_list) {
 _______________________________________________
 svn-src-all@freebsd.org mailing list
 http://lists.freebsd.org/mailman/listinfo/svn-src-all
 To unsubscribe, send any mail to "svn-src-all-unsubscribe@freebsd.org"
 

From: dfilter@FreeBSD.ORG (dfilter service)
To: bug-followup@FreeBSD.org
Cc:  
Subject: Re: kern/160300: commit references a PR
Date: Sun, 11 Sep 2011 23:37:50 +0000 (UTC)

 Author: thompsa
 Date: Sun Sep 11 23:37:40 2011
 New Revision: 225495
 URL: http://svn.freebsd.org/changeset/base/225495
 
 Log:
   MFC r225380
   
    On the first loop for generating a bridge MAC address use the local
    hostid, this gives a good chance of keeping the same address over
    reboots. This is intended to help IPV6 and similar which generate
    their addresses from the mac.
   
   PR:		kern/160300
   Submitted by:	mdodd
 
 Modified:
   stable/8/sys/net/if_bridge.c
 Directory Properties:
   stable/8/sys/   (props changed)
   stable/8/sys/amd64/include/xen/   (props changed)
   stable/8/sys/cddl/contrib/opensolaris/   (props changed)
   stable/8/sys/contrib/dev/acpica/   (props changed)
   stable/8/sys/contrib/pf/   (props changed)
 
 Modified: stable/8/sys/net/if_bridge.c
 ==============================================================================
 --- stable/8/sys/net/if_bridge.c	Sun Sep 11 21:38:33 2011	(r225494)
 +++ stable/8/sys/net/if_bridge.c	Sun Sep 11 23:37:40 2011	(r225495)
 @@ -85,6 +85,7 @@ __FBSDID("$FreeBSD$");
  #include <sys/malloc.h>
  #include <sys/protosw.h>
  #include <sys/systm.h>
 +#include <sys/jail.h>
  #include <sys/time.h>
  #include <sys/socket.h> /* for net/if.h */
  #include <sys/sockio.h>
 @@ -560,7 +561,8 @@ bridge_clone_create(struct if_clone *ifc
  {
  	struct bridge_softc *sc, *sc2;
  	struct ifnet *bifp, *ifp;
 -	int retry;
 +	int fb, retry;
 +	unsigned long hostid;
  
  	sc = malloc(sizeof(*sc), M_DEVBUF, M_WAITOK|M_ZERO);
  	ifp = sc->sc_ifp = if_alloc(IFT_ETHER);
 @@ -593,17 +595,30 @@ bridge_clone_create(struct if_clone *ifc
  	IFQ_SET_READY(&ifp->if_snd);
  
  	/*
 -	 * Generate a random ethernet address with a locally administered
 -	 * address.
 +	 * Generate an ethernet address with a locally administered address.
  	 *
  	 * Since we are using random ethernet addresses for the bridge, it is
  	 * possible that we might have address collisions, so make sure that
  	 * this hardware address isn't already in use on another bridge.
 +	 * The first try uses the hostid and falls back to arc4rand().
  	 */
 +	fb = 0;
 +	getcredhostid(curthread->td_ucred, &hostid);
  	for (retry = 1; retry != 0;) {
 -		arc4rand(sc->sc_defaddr, ETHER_ADDR_LEN, 1);
 -		sc->sc_defaddr[0] &= ~1;	/* clear multicast bit */
 -		sc->sc_defaddr[0] |= 2;		/* set the LAA bit */
 +		if (fb || hostid == 0) {
 +			arc4rand(sc->sc_defaddr, ETHER_ADDR_LEN, 1);
 +			sc->sc_defaddr[0] &= ~1;/* clear multicast bit */
 +			sc->sc_defaddr[0] |= 2;	/* set the LAA bit */
 +		} else {
 +			sc->sc_defaddr[0] = 0x2;
 +			sc->sc_defaddr[1] = (hostid >> 24) & 0xff;
 +			sc->sc_defaddr[2] = (hostid >> 16) & 0xff;
 +			sc->sc_defaddr[3] = (hostid >> 8 ) & 0xff;
 +			sc->sc_defaddr[4] =  hostid        & 0xff;
 +			sc->sc_defaddr[5] = ifp->if_dunit & 0xff;
 +		}
 +
 +		fb = 1;
  		retry = 0;
  		mtx_lock(&bridge_list_mtx);
  		LIST_FOREACH(sc2, &bridge_list, sc_list) {
 _______________________________________________
 svn-src-all@freebsd.org mailing list
 http://lists.freebsd.org/mailman/listinfo/svn-src-all
 To unsubscribe, send any mail to "svn-src-all-unsubscribe@freebsd.org"
 
State-Changed-From-To: patched->closed 
State-Changed-By: thompsa 
State-Changed-When: Sun Sep 11 23:41:37 UTC 2011 
State-Changed-Why:  
Merged 

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