Date: Thu, 12 Feb 2009 23:44:59 +0000 (UTC) From: Sam Leffler <sam@FreeBSD.org> To: src-committers@freebsd.org, svn-src-projects@freebsd.org Subject: svn commit: r188542 - in projects/vap7/sys: . contrib/pf dev dev/ath dev/ath/ath_hal dev/ath/ath_hal/ar5210 dev/ath/ath_hal/ar5211 dev/ath/ath_hal/ar5212 dev/ath/ath_hal/ar5312 dev/ath/ath_hal/ar54... Message-ID: <200902122344.n1CNixUS070143@svn.freebsd.org>
next in thread | raw e-mail | index | archive | help
Author: sam Date: Thu Feb 12 23:44:59 2009 New Revision: 188542 URL: http://svn.freebsd.org/changeset/base/188542 Log: merge r180140+r182862: add support to set the bridge MAC address to the MAC address of the first interface (conditional on net.link.bridge.inherit_mac) Modified: projects/vap7/sys/ (props changed) projects/vap7/sys/contrib/pf/ (props changed) projects/vap7/sys/dev/ (props changed) projects/vap7/sys/dev/ath/ (props changed) projects/vap7/sys/dev/ath/ath_hal/ (props changed) projects/vap7/sys/dev/ath/ath_hal/ar5210/ (props changed) projects/vap7/sys/dev/ath/ath_hal/ar5211/ (props changed) projects/vap7/sys/dev/ath/ath_hal/ar5212/ (props changed) projects/vap7/sys/dev/ath/ath_hal/ar5312/ (props changed) projects/vap7/sys/dev/ath/ath_hal/ar5416/ (props changed) projects/vap7/sys/dev/ath/if_ath.c projects/vap7/sys/dev/cxgb/ (props changed) projects/vap7/sys/dev/usb2/ (props changed) projects/vap7/sys/i386/conf/USB2 (props changed) projects/vap7/sys/modules/usb2/ (props changed) projects/vap7/sys/net/if_bridge.c Modified: projects/vap7/sys/dev/ath/if_ath.c ============================================================================== --- projects/vap7/sys/dev/ath/if_ath.c Thu Feb 12 23:34:58 2009 (r188541) +++ projects/vap7/sys/dev/ath/if_ath.c Thu Feb 12 23:44:59 2009 (r188542) @@ -39,6 +39,7 @@ __FBSDID("$FreeBSD$"); #include "opt_inet.h" #include "opt_ath.h" +#include "opt_wlan.h" #include <sys/param.h> #include <sys/systm.h> Modified: projects/vap7/sys/net/if_bridge.c ============================================================================== --- projects/vap7/sys/net/if_bridge.c Thu Feb 12 23:34:58 2009 (r188541) +++ projects/vap7/sys/net/if_bridge.c Thu Feb 12 23:44:59 2009 (r188542) @@ -220,6 +220,7 @@ struct bridge_softc { LIST_HEAD(, bridge_iflist) sc_spanlist; /* span ports list */ struct bstp_state sc_stp; /* STP state */ uint32_t sc_brtexceeded; /* # of cache drops */ + u_char sc_defaddr[6]; /* Default MAC address */ }; static struct mtx bridge_list_mtx; @@ -349,6 +350,7 @@ static int pfil_ipfw_arp = 0; /* layer static int pfil_local_phys = 0; /* run pfil hooks on the physical interface for locally destined packets */ static int log_stp = 0; /* log STP state changes */ +static int bridge_inherit_mac = 0; /* share MAC with first bridge member */ SYSCTL_INT(_net_link_bridge, OID_AUTO, pfil_onlyip, CTLFLAG_RW, &pfil_onlyip, 0, "Only pass IP packets when pfil is enabled"); SYSCTL_INT(_net_link_bridge, OID_AUTO, ipfw_arp, CTLFLAG_RW, @@ -362,6 +364,9 @@ SYSCTL_INT(_net_link_bridge, OID_AUTO, p "Packet filter on the physical interface for locally destined packets"); SYSCTL_INT(_net_link_bridge, OID_AUTO, log_stp, CTLFLAG_RW, &log_stp, 0, "Log STP state changes"); +SYSCTL_INT(_net_link_bridge, OID_AUTO, inherit_mac, CTLFLAG_RW, + &bridge_inherit_mac, 0, + "Inherit MAC address from the first bridge member"); struct bridge_control { int (*bc_func)(struct bridge_softc *, void *); @@ -552,7 +557,6 @@ bridge_clone_create(struct if_clone *ifc { struct bridge_softc *sc, *sc2; struct ifnet *bifp, *ifp; - u_char eaddr[6]; int retry; sc = malloc(sizeof(*sc), M_DEVBUF, M_WAITOK|M_ZERO); @@ -594,21 +598,22 @@ bridge_clone_create(struct if_clone *ifc * this hardware address isn't already in use on another bridge. */ for (retry = 1; retry != 0;) { - arc4rand(eaddr, ETHER_ADDR_LEN, 1); - eaddr[0] &= ~1; /* clear multicast bit */ - eaddr[0] |= 2; /* set the LAA bit */ + 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 */ retry = 0; mtx_lock(&bridge_list_mtx); LIST_FOREACH(sc2, &bridge_list, sc_list) { bifp = sc2->sc_ifp; - if (memcmp(eaddr, IF_LLADDR(bifp), ETHER_ADDR_LEN) == 0) + if (memcmp(sc->sc_defaddr, + IF_LLADDR(bifp), ETHER_ADDR_LEN) == 0) retry = 1; } mtx_unlock(&bridge_list_mtx); } bstp_attach(&sc->sc_stp, &bridge_ops); - ether_ifattach(ifp, eaddr); + ether_ifattach(ifp, sc->sc_defaddr); /* Now undo some of the damage... */ ifp->if_baudrate = 0; ifp->if_type = IFT_BRIDGE; @@ -880,6 +885,7 @@ bridge_delete_member(struct bridge_softc int gone) { struct ifnet *ifs = bif->bif_ifp; + struct ifnet *fif = NULL; BRIDGE_LOCK_ASSERT(sc); @@ -914,6 +920,24 @@ bridge_delete_member(struct bridge_softc LIST_REMOVE(bif, bif_next); BRIDGE_XDROP(sc); + /* + * If removing the interface that gave the bridge its mac address, set + * the mac address of the bridge to the address of the next member, or + * to its default address if no members are left. + */ + if (bridge_inherit_mac && + !memcmp(IF_LLADDR(sc->sc_ifp), IF_LLADDR(ifs), ETHER_ADDR_LEN)) { + if (LIST_EMPTY(&sc->sc_iflist)) + bcopy(sc->sc_defaddr, + IF_LLADDR(sc->sc_ifp), ETHER_ADDR_LEN); + else { + fif = LIST_FIRST(&sc->sc_iflist)->bif_ifp; + bcopy(IF_LLADDR(fif), + IF_LLADDR(sc->sc_ifp), ETHER_ADDR_LEN); + } + } + + bridge_mutecaps(sc); /* recalcuate now this interface is removed */ bridge_rtdelete(sc, ifs, IFBF_FLUSHALL); KASSERT(bif->bif_addrcnt == 0, @@ -1005,6 +1029,15 @@ bridge_ioctl_add(struct bridge_softc *sc goto out; } + /* + * Assign the interface's MAC address to the bridge if it's the first + * member and the MAC address of the bridge has not been changed from + * the default randomly generated one. + */ + if (bridge_inherit_mac && LIST_EMPTY(&sc->sc_iflist) && + !memcmp(IF_LLADDR(sc->sc_ifp), sc->sc_defaddr, ETHER_ADDR_LEN)) + bcopy(IF_LLADDR(ifs), IF_LLADDR(sc->sc_ifp), ETHER_ADDR_LEN); + ifs->if_bridge = sc; bstp_create(&sc->sc_stp, &bif->bif_stp, bif->bif_ifp); /*
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200902122344.n1CNixUS070143>