Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 29 Aug 2011 22:59:23 GMT
From:      "Matthew N. Dodd" <mdodd@FreeBSD.org>
To:        FreeBSD-gnats-submit@FreeBSD.org
Subject:   kern/160300: bridge(4) should attempt to use a static MAC address.
Message-ID:  <201108292259.p7TMxN0n046541@freefall.freebsd.org>
Resent-Message-ID: <201108292300.p7TN0KYX046685@freefall.freebsd.org>

next in thread | raw e-mail | index | archive | help

>Number:         160300
>Category:       kern
>Synopsis:       bridge(4) should attempt to use a static MAC address.
>Confidential:   no
>Severity:       non-critical
>Priority:       medium
>Responsible:    freebsd-bugs
>State:          open
>Quarter:        
>Keywords:       
>Date-Required:
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Mon Aug 29 23:00:19 UTC 2011
>Closed-Date:
>Last-Modified:
>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:
>Unformatted:



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201108292259.p7TMxN0n046541>