Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 18 Apr 2020 08:00:58 +0000 (UTC)
From:      Kristof Provost <kp@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r360069 - head/sys/net
Message-ID:  <202004180800.03I80wxq040207@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: kp
Date: Sat Apr 18 08:00:58 2020
New Revision: 360069
URL: https://svnweb.freebsd.org/changeset/base/360069

Log:
  bridge: Simplify mac address generation
  
  Unconditionally use ether_gen_addr() to generate bridge mac addresses.  This
  function is now less likely to generate duplicate mac addresses across jails.
  The old hand rolled hostid based code adds no value.
  
  Reviewed by:	bz
  Differential Revision:	https://reviews.freebsd.org/D24432

Modified:
  head/sys/net/if_bridge.c

Modified: head/sys/net/if_bridge.c
==============================================================================
--- head/sys/net/if_bridge.c	Sat Apr 18 07:50:30 2020	(r360068)
+++ head/sys/net/if_bridge.c	Sat Apr 18 08:00:58 2020	(r360069)
@@ -676,10 +676,8 @@ SYSCTL_PROC(_net_link_bridge, OID_AUTO, ipfw,
 static int
 bridge_clone_create(struct if_clone *ifc, int unit, caddr_t params)
 {
-	struct bridge_softc *sc, *sc2;
-	struct ifnet *bifp, *ifp;
-	int fb, retry;
-	unsigned long hostid;
+	struct bridge_softc *sc;
+	struct ifnet *ifp;
 
 	sc = malloc(sizeof(*sc), M_DEVBUF, M_WAITOK|M_ZERO);
 	ifp = sc->sc_ifp = if_alloc(IFT_ETHER);
@@ -709,41 +707,7 @@ bridge_clone_create(struct if_clone *ifc, int unit, ca
 	ifp->if_init = bridge_init;
 	ifp->if_type = IFT_BRIDGE;
 
-	/*
-	 * 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);
-	do {
-		if (fb || hostid == 0) {
-			ether_gen_addr(ifp, &sc->sc_defaddr);
-		} else {
-			sc->sc_defaddr.octet[0] = 0x2;
-			sc->sc_defaddr.octet[1] = (hostid >> 24) & 0xff;
-			sc->sc_defaddr.octet[2] = (hostid >> 16) & 0xff;
-			sc->sc_defaddr.octet[3] = (hostid >> 8 ) & 0xff;
-			sc->sc_defaddr.octet[4] =  hostid        & 0xff;
-			sc->sc_defaddr.octet[5] = ifp->if_dunit & 0xff;
-		}
-
-		fb = 1;
-		retry = 0;
-		BRIDGE_LIST_LOCK();
-		LIST_FOREACH(sc2, &V_bridge_list, sc_list) {
-			bifp = sc2->sc_ifp;
-			if (memcmp(sc->sc_defaddr.octet,
-			    IF_LLADDR(bifp), ETHER_ADDR_LEN) == 0) {
-				retry = 1;
-				break;
-			}
-		}
-		BRIDGE_LIST_UNLOCK();
-	} while (retry == 1);
+	ether_gen_addr(ifp, &sc->sc_defaddr);
 
 	bstp_attach(&sc->sc_stp, &bridge_ops);
 	ether_ifattach(ifp, sc->sc_defaddr.octet);



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