Lines Matching refs:sc

239 #define	BRIDGE_BPF_MTAP_INPUT(sc, m)					\
240 if (sc->sc_bpf_input) \
241 bridge_bpf_input(sc->sc_ifp, m)
258 #define BRIDGE_RTHASH_MASK(sc) ((sc)->sc_rthash_size - 1)
433 static void bridge_aging_timer(struct bridge_softc *sc);
514 static int bridge_ioctl_purge(struct bridge_softc *sc, void *);
841 bridge_lock(struct bridge_softc *sc)
845 BRIDGE_LOCK_ASSERT_NOTHELD(sc);
847 _BRIDGE_LOCK(sc);
849 sc->lock_lr[sc->next_lock_lr] = lr_saved;
850 sc->next_lock_lr = (sc->next_lock_lr+1) % SO_LCKDBG_MAX;
854 bridge_unlock(struct bridge_softc *sc)
858 BRIDGE_LOCK_ASSERT_HELD(sc);
860 sc->unlock_lr[sc->next_unlock_lr] = lr_saved;
861 sc->next_unlock_lr = (sc->next_unlock_lr+1) % SO_LCKDBG_MAX;
863 _BRIDGE_UNLOCK(sc);
867 bridge_lock2ref(struct bridge_softc *sc)
872 BRIDGE_LOCK_ASSERT_HELD(sc);
874 if (sc->sc_iflist_xcnt > 0)
877 sc->sc_iflist_ref++;
879 sc->unlock_lr[sc->next_unlock_lr] = lr_saved;
880 sc->next_unlock_lr = (sc->next_unlock_lr+1) % SO_LCKDBG_MAX;
882 _BRIDGE_UNLOCK(sc);
888 bridge_unref(struct bridge_softc *sc)
892 BRIDGE_LOCK_ASSERT_NOTHELD(sc);
894 _BRIDGE_LOCK(sc);
895 sc->lock_lr[sc->next_lock_lr] = lr_saved;
896 sc->next_lock_lr = (sc->next_lock_lr+1) % SO_LCKDBG_MAX;
898 sc->sc_iflist_ref--;
900 sc->unlock_lr[sc->next_unlock_lr] = lr_saved;
901 sc->next_unlock_lr = (sc->next_unlock_lr+1) % SO_LCKDBG_MAX;
902 if ((sc->sc_iflist_xcnt > 0) && (sc->sc_iflist_ref == 0)) {
903 _BRIDGE_UNLOCK(sc);
904 wakeup(&sc->sc_cv);
906 _BRIDGE_UNLOCK(sc);
910 bridge_xlock(struct bridge_softc *sc)
914 BRIDGE_LOCK_ASSERT_HELD(sc);
916 sc->sc_iflist_xcnt++;
917 while (sc->sc_iflist_ref > 0) {
918 sc->unlock_lr[sc->next_unlock_lr] = lr_saved;
919 sc->next_unlock_lr = (sc->next_unlock_lr+1) % SO_LCKDBG_MAX;
921 msleep(&sc->sc_cv, &sc->sc_mtx, PZERO, "BRIDGE_XLOCK", NULL);
923 sc->lock_lr[sc->next_lock_lr] = lr_saved;
924 sc->next_lock_lr = (sc->next_lock_lr+1) % SO_LCKDBG_MAX;
929 bridge_xdrop(struct bridge_softc *sc)
931 BRIDGE_LOCK_ASSERT_HELD(sc);
933 sc->sc_iflist_xcnt--;
1128 struct bridge_softc *sc, *sc2;
1137 sc = _MALLOC(sizeof (*sc), M_DEVBUF, M_WAITOK | M_ZERO);
1139 lck_mtx_init(&sc->sc_mtx, bridge_lock_grp, bridge_lock_attr);
1140 sc->sc_brtmax = BRIDGE_RTABLE_MAX;
1141 sc->sc_brttimeout = BRIDGE_RTABLE_TIMEOUT;
1142 sc->sc_filter_flags = IFBF_FILT_DEFAULT;
1149 sc->sc_filter_flags &= ~IFBF_FILT_USEIPF;
1153 error = bridge_rtable_init(sc);
1159 TAILQ_INIT(&sc->sc_iflist);
1160 TAILQ_INIT(&sc->sc_spanlist);
1163 snprintf(sc->sc_if_xname, sizeof (sc->sc_if_xname), "%s%d",
1174 init_params.uniqueid = sc->sc_if_xname;
1175 init_params.uniqueid_len = strlen(sc->sc_if_xname);
1186 init_params.softc = sc;
1197 sc->sc_ifp = ifp;
1236 read_random(&sc->sc_defaddr, ETHER_ADDR_LEN);
1237 sc->sc_defaddr[0] &= ~1; /* clear multicast bit */
1238 sc->sc_defaddr[0] |= 2; /* set the LAA bit */
1240 bcopy(&eth_hostid[0], &sc->sc_defaddr,
1242 sc->sc_defaddr[0] &= ~1; /* clear multicast bit */
1243 sc->sc_defaddr[0] |= 2; /* set the LAA bit */
1244 sc->sc_defaddr[3] = /* stir it up a bit */
1245 ((sc->sc_defaddr[3] & 0x0f) << 4) |
1246 ((sc->sc_defaddr[3] & 0xf0) >> 4);
1251 sc->sc_defaddr[4] =
1252 (((sc->sc_defaddr[4] & 0x0f) << 4) |
1253 ((sc->sc_defaddr[4] & 0xf0) >> 4)) ^
1254 sc->sc_defaddr[5];
1255 sc->sc_defaddr[5] = ifp->if_unit & 0xff;
1262 if (memcmp(sc->sc_defaddr,
1271 sdl->sdl_nlen = strlen(sc->sc_if_xname);
1274 memcpy(sdl->sdl_data, sc->sc_if_xname, sdl->sdl_nlen);
1275 memcpy(LLADDR(sdl), sc->sc_defaddr, ETHER_ADDR_LEN);
1277 sc->sc_flags &= ~SCF_MEDIA_ACTIVE;
1290 error = ifnet_set_lladdr_and_type(ifp, sc->sc_defaddr, ETHER_ADDR_LEN,
1302 error = bridge_set_tso(sc);
1309 bstp_attach(&sc->sc_stp, &bridge_ops);
1313 LIST_INSERT_HEAD(&bridge_list, sc, sc_list);
1337 struct bridge_softc *sc = ifp->if_softc;
1341 BRIDGE_LOCK(sc);
1342 if ((sc->sc_flags & SCF_DETACHING)) {
1343 BRIDGE_UNLOCK(sc);
1346 sc->sc_flags |= SCF_DETACHING;
1350 bridge_cancel_delayed_call(&sc->sc_resize_call);
1357 while ((bif = TAILQ_FIRST(&sc->sc_iflist)) != NULL)
1358 bridge_delete_member(sc, bif, 0);
1360 while ((bif = TAILQ_FIRST(&sc->sc_spanlist)) != NULL) {
1361 bridge_delete_span(sc, bif);
1364 BRIDGE_UNLOCK(sc);
1370 if ((sc = (struct bridge_softc *)ifnet_softc(ifp)) != NULL) {
1371 BRIDGE_LOCK(sc);
1372 sc->sc_flags &= ~SCF_DETACHING;
1373 BRIDGE_UNLOCK(sc);
1418 BRIDGE_LOCK(sc); \
1419 error = (*bc->bc_func)(sc, &args); \
1420 BRIDGE_UNLOCK(sc); \
1436 struct bridge_softc *sc = ifp->if_softc;
1441 BRIDGE_LOCK_ASSERT_NOTHELD(sc);
1471 BRIDGE_LOCK(sc);
1472 if (!(sc->sc_flags & SCF_DETACHING) &&
1473 (sc->sc_flags & SCF_MEDIA_ACTIVE)) {
1480 BRIDGE_UNLOCK(sc);
1537 BRIDGE_LOCK(sc);
1539 BRIDGE_UNLOCK(sc);
1546 BRIDGE_LOCK(sc);
1548 BRIDGE_UNLOCK(sc);
1565 BRIDGE_LOCK(sc);
1566 if (TAILQ_EMPTY(&sc->sc_iflist)) {
1567 sc->sc_ifp->if_mtu = ifr->ifr_mtu;
1568 BRIDGE_UNLOCK(sc);
1571 TAILQ_FOREACH(bif, &sc->sc_iflist, bif_next) {
1574 sc->sc_ifp->if_xname,
1582 sc->sc_ifp->if_mtu = ifr->ifr_mtu;
1583 BRIDGE_UNLOCK(sc);
1600 BRIDGE_LOCK_ASSERT_NOTHELD(sc);
1612 bridge_mutecaps(struct bridge_softc *sc)
1620 TAILQ_FOREACH(bif, &sc->sc_iflist, bif_next) {
1625 TAILQ_FOREACH(bif, &sc->sc_iflist, bif_next) {
1632 bridge_set_ifcap(sc, bif, enabled);
1638 bridge_set_ifcap(struct bridge_softc *sc, struct bridge_iflist *bif, int set)
1653 "on %s\n", __func__, sc->sc_ifp->if_xname,
1660 bridge_set_tso(struct bridge_softc *sc)
1669 offload = sc->sc_ifp->if_hwassist | IFNET_TSO_IPV4 | IFNET_TSO_IPV6;
1674 TAILQ_FOREACH(bif, &sc->sc_iflist, bif_next) {
1700 if (offload != sc->sc_ifp->if_hwassist) {
1701 error = ifnet_set_offload(sc->sc_ifp, offload);
1707 sc->sc_ifp->if_xname, offload, error);
1715 if (sc->sc_ifp->if_hwassist & IFNET_TSO_IPV4) {
1716 if (tso_v4_mtu < sc->sc_ifp->if_mtu)
1717 tso_v4_mtu = sc->sc_ifp->if_mtu;
1718 error = ifnet_set_tso_mtu(sc->sc_ifp, AF_INET,
1725 __func__, sc->sc_ifp->if_xname,
1731 if (sc->sc_ifp->if_hwassist & IFNET_TSO_IPV6) {
1732 if (tso_v6_mtu < sc->sc_ifp->if_mtu)
1733 tso_v6_mtu = sc->sc_ifp->if_mtu;
1734 error = ifnet_set_tso_mtu(sc->sc_ifp, AF_INET6,
1741 __func__, sc->sc_ifp->if_xname,
1758 bridge_lookup_member(struct bridge_softc *sc, const char *name)
1763 BRIDGE_LOCK_ASSERT_HELD(sc);
1765 TAILQ_FOREACH(bif, &sc->sc_iflist, bif_next) {
1780 bridge_lookup_member_if(struct bridge_softc *sc, struct ifnet *member_ifp)
1784 BRIDGE_LOCK_ASSERT_HELD(sc);
1786 TAILQ_FOREACH(bif, &sc->sc_iflist, bif_next) {
1801 struct bridge_softc *sc = bif->bif_sc;
1817 "frmlen %lu\n", __func__, sc->sc_ifp->if_xname,
1860 BRIDGE_LOCK_ASSERT_NOTHELD(sc);
1873 struct bridge_softc *sc = bif->bif_sc;
1882 sc->sc_ifp->if_xname, ifp->if_xname,
1888 error = bridge_member_output(sc, ifp, m);
1895 BRIDGE_LOCK_ASSERT_NOTHELD(sc);
1907 struct bridge_softc *sc = bif->bif_sc;
1952 BRIDGE_LOCK(sc);
1953 bridge_set_tso(sc);
1954 BRIDGE_UNLOCK(sc);
2041 bridge_delete_member(struct bridge_softc *sc, struct bridge_iflist *bif,
2044 struct ifnet *ifs = bif->bif_ifp, *bifp = sc->sc_ifp;
2049 BRIDGE_LOCK_ASSERT_HELD(sc);
2073 bridge_set_ifcap(sc, bif, bif->bif_savedcaps);
2079 BRIDGE_UNLOCK(sc);
2081 BRIDGE_LOCK(sc);
2088 BRIDGE_XLOCK(sc);
2089 TAILQ_REMOVE(&sc->sc_iflist, bif, bif_next);
2090 BRIDGE_XDROP(sc);
2097 if (bridge_inherit_mac && sc->sc_ifaddr == ifs) {
2098 ifnet_release(sc->sc_ifaddr);
2099 if (TAILQ_EMPTY(&sc->sc_iflist)) {
2100 bcopy(sc->sc_defaddr, eaddr, ETHER_ADDR_LEN);
2101 sc->sc_ifaddr = NULL;
2104 TAILQ_FIRST(&sc->sc_iflist)->bif_ifp;
2106 sc->sc_ifaddr = fif;
2113 bridge_mutecaps(sc); /* recalculate now this interface is removed */
2116 error = bridge_set_tso(sc);
2121 bridge_rtdelete(sc, ifs, IFBF_FLUSHALL);
2130 event_code = bridge_updatelinkstatus(sc);
2132 BRIDGE_UNLOCK(sc);
2153 BRIDGE_LOCK(sc);
2162 bridge_delete_span(struct bridge_softc *sc, struct bridge_iflist *bif)
2164 BRIDGE_LOCK_ASSERT_HELD(sc);
2171 TAILQ_REMOVE(&sc->sc_spanlist, bif, bif_next);
2176 bridge_ioctl_add(struct bridge_softc *sc, void *arg)
2180 struct ifnet *ifs, *bifp = sc->sc_ifp;
2193 TAILQ_FOREACH(bif, &sc->sc_spanlist, bif_next)
2197 if (ifs->if_bridge == sc)
2225 bif->bif_sc = sc;
2228 if (TAILQ_EMPTY(&sc->sc_iflist))
2229 sc->sc_ifp->if_mtu = ifs->if_mtu;
2230 else if (sc->sc_ifp->if_mtu != ifs->if_mtu) {
2232 sc->sc_ifp->if_xname,
2242 if (bridge_inherit_mac && TAILQ_EMPTY(&sc->sc_iflist) &&
2243 !memcmp(IF_LLADDR(sc->sc_ifp), sc->sc_defaddr, ETHER_ADDR_LEN)) {
2245 sc->sc_ifaddr = ifs;
2250 ifs->if_bridge = sc;
2252 bstp_create(&sc->sc_stp, &bif->bif_stp, bif->bif_ifp);
2258 TAILQ_INSERT_TAIL(&sc->sc_iflist, bif, bif_next);
2262 bridge_mutecaps(sc);
2265 bridge_set_tso(sc);
2297 event_code = bridge_updatelinkstatus(sc);
2302 BRIDGE_UNLOCK(sc);
2319 BRIDGE_LOCK(sc);
2331 BRIDGE_LOCK(sc);
2344 BRIDGE_LOCK(sc);
2348 bridge_delete_member(sc, bif, 1);
2354 bridge_ioctl_del(struct bridge_softc *sc, void *arg)
2359 bif = bridge_lookup_member(sc, req->ifbr_ifsname);
2363 bridge_delete_member(sc, bif, 0);
2369 bridge_ioctl_purge(struct bridge_softc *sc, void *arg)
2371 #pragma unused(sc, arg)
2376 bridge_ioctl_gifflags(struct bridge_softc *sc, void *arg)
2382 bif = bridge_lookup_member(sc, req->ifbr_ifsname);
2416 bridge_ioctl_sifflags(struct bridge_softc *sc, void *arg)
2425 bif = bridge_lookup_member(sc, req->ifbr_ifsname);
2465 bridge_ioctl_scache(struct bridge_softc *sc, void *arg)
2469 sc->sc_brtmax = param->ifbrp_csize;
2470 bridge_rttrim(sc);
2476 bridge_ioctl_gcache(struct bridge_softc *sc, void *arg)
2480 param->ifbrp_csize = sc->sc_brtmax;
2492 TAILQ_FOREACH(bif, &sc->sc_iflist, bif_next) \
2494 TAILQ_FOREACH(bif, &sc->sc_spanlist, bif_next) \
2502 BRIDGE_UNLOCK(sc); \
2504 BRIDGE_LOCK(sc); \
2510 TAILQ_FOREACH(bif, &sc->sc_iflist, bif_next) { \
2517 error = bridge_ioctl_gifflags(sc, &breq); \
2525 TAILQ_FOREACH(bif, &sc->sc_spanlist, bif_next) { \
2539 BRIDGE_UNLOCK(sc); \
2542 BRIDGE_LOCK(sc); \
2547 bridge_ioctl_gifs64(struct bridge_softc *sc, void *arg)
2558 bridge_ioctl_gifs32(struct bridge_softc *sc, void *arg)
2578 LIST_FOREACH(brt, &sc->sc_rtlist, brt_list) \
2582 BRIDGE_UNLOCK(sc); \
2584 BRIDGE_LOCK(sc); \
2590 LIST_FOREACH(brt, &sc->sc_rtlist, brt_list) { \
2612 BRIDGE_UNLOCK(sc); \
2615 BRIDGE_LOCK(sc); \
2621 bridge_ioctl_rts64(struct bridge_softc *sc, void *arg)
2633 bridge_ioctl_rts32(struct bridge_softc *sc, void *arg)
2645 bridge_ioctl_saddr32(struct bridge_softc *sc, void *arg)
2651 bif = bridge_lookup_member(sc, req->ifba_ifsname);
2655 error = bridge_rtupdate(sc, req->ifba_dst, req->ifba_vlan, bif, 1,
2662 bridge_ioctl_saddr64(struct bridge_softc *sc, void *arg)
2668 bif = bridge_lookup_member(sc, req->ifba_ifsname);
2672 error = bridge_rtupdate(sc, req->ifba_dst, req->ifba_vlan, bif, 1,
2679 bridge_ioctl_sto(struct bridge_softc *sc, void *arg)
2683 sc->sc_brttimeout = param->ifbrp_ctime;
2688 bridge_ioctl_gto(struct bridge_softc *sc, void *arg)
2692 param->ifbrp_ctime = sc->sc_brttimeout;
2697 bridge_ioctl_daddr32(struct bridge_softc *sc, void *arg)
2701 return (bridge_rtdaddr(sc, req->ifba_dst, req->ifba_vlan));
2705 bridge_ioctl_daddr64(struct bridge_softc *sc, void *arg)
2709 return (bridge_rtdaddr(sc, req->ifba_dst, req->ifba_vlan));
2713 bridge_ioctl_flush(struct bridge_softc *sc, void *arg)
2717 bridge_rtflush(sc, req->ifbr_ifsflags);
2722 bridge_ioctl_gpri(struct bridge_softc *sc, void *arg)
2725 struct bstp_state *bs = &sc->sc_stp;
2732 bridge_ioctl_spri(struct bridge_softc *sc, void *arg)
2737 return (bstp_set_priority(&sc->sc_stp, param->ifbrp_prio));
2739 #pragma unused(sc, arg)
2745 bridge_ioctl_ght(struct bridge_softc *sc, void *arg)
2748 struct bstp_state *bs = &sc->sc_stp;
2755 bridge_ioctl_sht(struct bridge_softc *sc, void *arg)
2760 return (bstp_set_htime(&sc->sc_stp, param->ifbrp_hellotime));
2762 #pragma unused(sc, arg)
2768 bridge_ioctl_gfd(struct bridge_softc *sc, void *arg)
2771 struct bstp_state *bs = &sc->sc_stp;
2778 bridge_ioctl_sfd(struct bridge_softc *sc, void *arg)
2783 return (bstp_set_fdelay(&sc->sc_stp, param->ifbrp_fwddelay));
2785 #pragma unused(sc, arg)
2791 bridge_ioctl_gma(struct bridge_softc *sc, void *arg)
2794 struct bstp_state *bs = &sc->sc_stp;
2801 bridge_ioctl_sma(struct bridge_softc *sc, void *arg)
2806 return (bstp_set_maxage(&sc->sc_stp, param->ifbrp_maxage));
2808 #pragma unused(sc, arg)
2814 bridge_ioctl_sifprio(struct bridge_softc *sc, void *arg)
2820 bif = bridge_lookup_member(sc, req->ifbr_ifsname);
2826 #pragma unused(sc, arg)
2832 bridge_ioctl_sifcost(struct bridge_softc *sc, void *arg)
2838 bif = bridge_lookup_member(sc, req->ifbr_ifsname);
2844 #pragma unused(sc, arg)
2850 bridge_ioctl_gfilt(struct bridge_softc *sc, void *arg)
2854 param->ifbrp_filter = sc->sc_filter_flags;
2860 bridge_ioctl_sfilt(struct bridge_softc *sc, void *arg)
2872 sc->sc_filter_flags = param->ifbrp_filter;
2878 bridge_ioctl_sifmaxaddr(struct bridge_softc *sc, void *arg)
2883 bif = bridge_lookup_member(sc, req->ifbr_ifsname);
2892 bridge_ioctl_addspan(struct bridge_softc *sc, void *arg)
2902 TAILQ_FOREACH(bif, &sc->sc_spanlist, bif_next)
2929 TAILQ_INSERT_HEAD(&sc->sc_spanlist, bif, bif_next);
2935 bridge_ioctl_delspan(struct bridge_softc *sc, void *arg)
2945 TAILQ_FOREACH(bif, &sc->sc_spanlist, bif_next)
2952 bridge_delete_span(sc, bif);
2958 struct bstp_state *bs = &sc->sc_stp; \
2983 bridge_ioctl_gbparam32(struct bridge_softc *sc, void *arg)
2993 bridge_ioctl_gbparam64(struct bridge_softc *sc, void *arg)
3003 bridge_ioctl_grte(struct bridge_softc *sc, void *arg)
3007 param->ifbrp_cexceeded = sc->sc_brtexceeded;
3019 TAILQ_FOREACH(bif, &sc->sc_iflist, bif_next) { \
3030 BRIDGE_UNLOCK(sc); \
3032 BRIDGE_LOCK(sc); \
3038 TAILQ_FOREACH(bif, &sc->sc_iflist, bif_next) { \
3059 BRIDGE_UNLOCK(sc); \
3062 BRIDGE_LOCK(sc); \
3068 bridge_ioctl_gifsstp32(struct bridge_softc *sc, void *arg)
3079 bridge_ioctl_gifsstp64(struct bridge_softc *sc, void *arg)
3090 bridge_ioctl_sproto(struct bridge_softc *sc, void *arg)
3095 return (bstp_set_protocol(&sc->sc_stp, param->ifbrp_proto));
3097 #pragma unused(sc, arg)
3103 bridge_ioctl_stxhc(struct bridge_softc *sc, void *arg)
3108 return (bstp_set_holdcount(&sc->sc_stp, param->ifbrp_txhc));
3110 #pragma unused(sc, arg)
3124 struct bridge_softc *sc = ifp->if_bridge;
3132 if (sc != NULL) {
3133 BRIDGE_LOCK(sc);
3134 bif = bridge_lookup_member_if(sc, ifp);
3136 bridge_delete_member(sc, bif, 1);
3137 BRIDGE_UNLOCK(sc);
3143 LIST_FOREACH(sc, &bridge_list, sc_list) {
3144 BRIDGE_LOCK(sc);
3145 TAILQ_FOREACH(bif, &sc->sc_spanlist, bif_next)
3147 bridge_delete_span(sc, bif);
3150 BRIDGE_UNLOCK(sc);
3183 bridge_updatelinkstatus(struct bridge_softc *sc)
3189 BRIDGE_LOCK_ASSERT_HELD(sc);
3194 TAILQ_FOREACH(bif, &sc->sc_iflist, bif_next) {
3201 if (active_member && !(sc->sc_flags & SCF_MEDIA_ACTIVE)) {
3202 sc->sc_flags |= SCF_MEDIA_ACTIVE;
3204 } else if (!active_member && (sc->sc_flags & SCF_MEDIA_ACTIVE)) {
3205 sc->sc_flags &= ~SCF_MEDIA_ACTIVE;
3218 struct bridge_softc *sc = ifp->if_bridge;
3228 if (sc == NULL)
3231 BRIDGE_LOCK(sc);
3232 bif = bridge_lookup_member_if(sc, ifp);
3239 event_code = bridge_updatelinkstatus(sc);
3241 BRIDGE_UNLOCK(sc);
3244 bridge_link_event(sc->sc_ifp, event_code);
3256 struct bridge_softc *sc = call->bdc_sc;
3275 BRIDGE_LOCK(sc);
3280 sc->sc_if_xname, (uint64_t)VM_KERNEL_ADDRPERM(call),
3287 if ((sc->sc_flags & SCF_DETACHING) == 0)
3288 (*call->bdc_func)(sc);
3291 BRIDGE_UNLOCK(sc);
3304 struct bridge_softc *sc = call->bdc_sc;
3306 BRIDGE_LOCK_ASSERT_HELD(sc);
3308 if ((sc->sc_flags & SCF_DETACHING) ||
3324 sc->sc_if_xname, (uint64_t)VM_KERNEL_ADDRPERM(call),
3343 struct bridge_softc *sc = call->bdc_sc;
3348 if (sc == NULL)
3351 BRIDGE_LOCK_ASSERT_HELD(sc);
3359 sc->sc_if_xname, (uint64_t)VM_KERNEL_ADDRPERM(call),
3374 msleep(call, &sc->sc_mtx, PZERO, __func__, NULL);
3388 struct bridge_softc *sc = (struct bridge_softc *)ifp->if_softc;
3391 BRIDGE_LOCK_ASSERT_HELD(sc);
3402 bridge_aging_timer(sc);
3406 bstp_init(&sc->sc_stp); /* Initialize Spanning Tree */
3421 struct bridge_softc *sc = ifp->if_softc;
3423 BRIDGE_LOCK_ASSERT_HELD(sc);
3428 bridge_cancel_delayed_call(&sc->sc_aging_timer);
3431 bstp_stop(&sc->sc_stp);
3434 bridge_rtflush(sc, IFBF_FLUSHDYN);
3446 bridge_enqueue(struct bridge_softc *sc, struct ifnet *dst_ifp, struct mbuf *m)
3504 (void) ifnet_stat_increment_out(sc->sc_ifp, 1, len, 0);
3506 (void) ifnet_stat_increment_out(sc->sc_ifp, 0, 0, 1);
3525 struct bridge_softc *sc;
3527 sc = ifp->if_bridge;
3534 if (sc == NULL) {
3540 if (bridge_pfil(&m, sc->sc_ifp, ifp, PFIL_OUT) != 0)
3546 (void) bridge_enqueue(sc, ifp, m);
3568 struct bridge_softc *sc;
3583 sc = ifp->if_bridge;
3586 BRIDGE_LOCK(sc);
3603 if ((sc->sc_ifp->if_flags & IFF_RUNNING) == 0) {
3615 dst_if = bridge_rtlookup(sc, eh->ether_dhost, vlan);
3621 bridge_span(sc, m);
3623 BRIDGE_LOCK2REF(sc, error);
3629 TAILQ_FOREACH(bif, &sc->sc_iflist, bif_next) {
3654 sc->sc_ifp, 0, 0, 1);
3659 (void) bridge_enqueue(sc, dst_if, mc);
3663 BRIDGE_UNREF(sc);
3672 bridge_span(sc, m);
3675 BRIDGE_UNLOCK(sc);
3679 BRIDGE_UNLOCK(sc);
3680 (void) bridge_enqueue(sc, dst_if, m);
3694 struct bridge_softc *sc = ifnet_softc(ifp);
3702 BRIDGE_LOCK(sc);
3704 dst_if = bridge_rtlookup(sc, eh->ether_dhost, 0);
3709 if (sc->sc_bpf_output)
3715 bridge_broadcast(sc, ifp, m, 0);
3717 BRIDGE_UNLOCK(sc);
3718 error = bridge_enqueue(sc, dst_if, m);
3818 bridge_forward(struct bridge_softc *sc, struct bridge_iflist *sbif,
3828 BRIDGE_LOCK_ASSERT_HELD(sc);
3832 printf("%s: %s m 0x%llx\n", __func__, sc->sc_ifp->if_xname,
3837 ifp = sc->sc_ifp;
3852 error = bridge_rtupdate(sc, eh->ether_shost, vlan,
3876 dst_if = bridge_rtlookup(sc, dst, vlan);
3910 if (sc->sc_bpf_input)
3918 BRIDGE_UNLOCK(sc);
3923 BRIDGE_LOCK(sc);
3928 bridge_broadcast(sc, src_if, m, 1);
3939 dbif = bridge_lookup_member_if(sc, dst_if);
3957 ++sc->sc_sc.sc_ifp.if_xdhcpra;
3963 BRIDGE_UNLOCK(sc);
3974 (void) bridge_enqueue(sc, dst_if, m);
3978 BRIDGE_UNLOCK(sc);
4006 struct bridge_softc *sc = ifp->if_bridge;
4017 sc->sc_ifp->if_xname, ifp->if_xname,
4022 if ((sc->sc_ifp->if_flags & IFF_RUNNING) == 0) {
4026 __func__, sc->sc_ifp->if_xname);
4031 bifp = sc->sc_ifp;
4043 BRIDGE_BPF_MTAP_INPUT(sc, m);
4057 BRIDGE_LOCK(sc);
4058 bif = bridge_lookup_member_if(sc, ifp);
4060 BRIDGE_UNLOCK(sc);
4064 __func__, sc->sc_ifp->if_xname);
4071 bridge_span(sc, m);
4096 BRIDGE_UNLOCK(sc);
4103 BRIDGE_UNLOCK(sc);
4114 BRIDGE_UNLOCK(sc);
4123 bridge_forward(sc, bif, mc);
4144 if (sc->sc_bpf_input)
4158 sc->sc_ifp->if_xname);
4170 BRIDGE_UNLOCK(sc);
4193 #define PFIL_PHYS(sc, ifp, m) do { \
4198 BRIDGE_UNLOCK(sc); \
4204 #define PFIL_PHYS(sc, ifp, m)
4214 BRIDGE_BPF_MTAP_INPUT(sc, m); \
4216 PFIL_PHYS(sc, iface, m); \
4219 error = bridge_rtupdate(sc, eh->ether_shost, \
4222 BRIDGE_UNLOCK(sc); \
4227 BRIDGE_UNLOCK(sc); \
4234 BRIDGE_UNLOCK(sc); \
4259 (void) bridge_rtupdate(sc, eh->ether_shost,
4262 BRIDGE_BPF_MTAP_INPUT(sc, m);
4270 BRIDGE_UNLOCK(sc);
4275 sc->sc_ifp->if_xname);
4302 BRIDGE_UNLOCK(sc);
4307 TAILQ_FOREACH(bif2, &sc->sc_iflist, bif_next) {
4320 bridge_forward(sc, bif, m);
4335 bridge_broadcast(struct bridge_softc *sc, struct ifnet *src_if,
4346 sbif = bridge_lookup_member_if(sc, src_if);
4348 BRIDGE_LOCK2REF(sc, error);
4357 if (bridge_pfil(&m, sc->sc_ifp, NULL, PFIL_OUT) != 0)
4364 TAILQ_FOREACH(dbif, &sc->sc_iflist, bif_next) {
4391 (void) ifnet_stat_increment_out(sc->sc_ifp,
4411 sc->sc_ifp, 0, 0, 1);
4422 (void) bridge_enqueue(sc, dst_if, mc);
4431 BRIDGE_UNREF(sc);
4441 bridge_span(struct bridge_softc *sc, struct mbuf *m)
4447 if (TAILQ_EMPTY(&sc->sc_spanlist))
4450 TAILQ_FOREACH(bif, &sc->sc_spanlist, bif_next) {
4458 (void) ifnet_stat_increment_out(sc->sc_ifp, 0, 0, 1);
4462 (void) bridge_enqueue(sc, dst_if, mc);
4473 bridge_rtupdate(struct bridge_softc *sc, const uint8_t *dst, uint16_t vlan,
4479 BRIDGE_LOCK_ASSERT_HELD(sc);
4496 if ((brt = bridge_rtnode_lookup(sc, dst, vlan)) == NULL) {
4497 if (sc->sc_brtcnt >= sc->sc_brtmax) {
4498 sc->sc_brtexceeded++;
4526 if ((error = bridge_rtnode_insert(sc, brt)) != 0) {
4537 sc->sc_ifp->if_xname, sc->sc_brtcnt,
4538 sc->sc_rthash_size);
4553 brt->brt_expire = now + sc->sc_brttimeout;
4568 bridge_rtlookup(struct bridge_softc *sc, const uint8_t *addr, uint16_t vlan)
4572 BRIDGE_LOCK_ASSERT_HELD(sc);
4574 if ((brt = bridge_rtnode_lookup(sc, addr, vlan)) == NULL)
4588 bridge_rttrim(struct bridge_softc *sc)
4592 BRIDGE_LOCK_ASSERT_HELD(sc);
4595 if (sc->sc_brtcnt <= sc->sc_brtmax)
4599 bridge_rtage(sc);
4600 if (sc->sc_brtcnt <= sc->sc_brtmax)
4603 LIST_FOREACH_SAFE(brt, &sc->sc_rtlist, brt_list, nbrt) {
4605 bridge_rtnode_destroy(sc, brt);
4606 if (sc->sc_brtcnt <= sc->sc_brtmax)
4618 bridge_aging_timer(struct bridge_softc *sc)
4620 BRIDGE_LOCK_ASSERT_HELD(sc);
4622 bridge_rtage(sc);
4624 if ((sc->sc_ifp->if_flags & IFF_RUNNING) &&
4625 (sc->sc_flags & SCF_DETACHING) == 0) {
4626 sc->sc_aging_timer.bdc_sc = sc;
4627 sc->sc_aging_timer.bdc_func = bridge_aging_timer;
4628 sc->sc_aging_timer.bdc_ts.tv_sec = bridge_rtable_prune_period;
4629 bridge_schedule_delayed_call(&sc->sc_aging_timer);
4639 bridge_rtage(struct bridge_softc *sc)
4644 BRIDGE_LOCK_ASSERT_HELD(sc);
4648 LIST_FOREACH_SAFE(brt, &sc->sc_rtlist, brt_list, nbrt) {
4651 bridge_rtnode_destroy(sc, brt);
4662 bridge_rtflush(struct bridge_softc *sc, int full)
4666 BRIDGE_LOCK_ASSERT_HELD(sc);
4668 LIST_FOREACH_SAFE(brt, &sc->sc_rtlist, brt_list, nbrt) {
4670 bridge_rtnode_destroy(sc, brt);
4680 bridge_rtdaddr(struct bridge_softc *sc, const uint8_t *addr, uint16_t vlan)
4685 BRIDGE_LOCK_ASSERT_HELD(sc);
4691 while ((brt = bridge_rtnode_lookup(sc, addr, vlan)) != NULL) {
4692 bridge_rtnode_destroy(sc, brt);
4705 bridge_rtdelete(struct bridge_softc *sc, struct ifnet *ifp, int full)
4709 BRIDGE_LOCK_ASSERT_HELD(sc);
4711 LIST_FOREACH_SAFE(brt, &sc->sc_rtlist, brt_list, nbrt) {
4714 bridge_rtnode_destroy(sc, brt);
4724 bridge_rtable_init(struct bridge_softc *sc)
4728 sc->sc_rthash = _MALLOC(sizeof (*sc->sc_rthash) * BRIDGE_RTHASH_SIZE,
4730 if (sc->sc_rthash == NULL) {
4734 sc->sc_rthash_size = BRIDGE_RTHASH_SIZE;
4736 for (i = 0; i < sc->sc_rthash_size; i++)
4737 LIST_INIT(&sc->sc_rthash[i]);
4739 sc->sc_rthash_key = RandomULong();
4741 LIST_INIT(&sc->sc_rtlist);
4752 bridge_rthash_delayed_resize(struct bridge_softc *sc)
4761 BRIDGE_LOCK_ASSERT_HELD(sc);
4766 if (sc->sc_brtcnt < sc->sc_rthash_size * 4)
4773 new_rthash_size = sc->sc_rthash_size * 2;
4775 sc->sc_flags |= SCF_RESIZING;
4776 BRIDGE_UNLOCK(sc);
4778 new_rthash = _MALLOC(sizeof (*sc->sc_rthash) * new_rthash_size,
4781 BRIDGE_LOCK(sc);
4782 sc->sc_flags &= ~SCF_RESIZING;
4788 if ((sc->sc_flags & SCF_DETACHING)) {
4795 old_rthash = sc->sc_rthash;
4796 sc->sc_rthash = new_rthash;
4797 sc->sc_rthash_size = new_rthash_size;
4803 sc->sc_rthash_key = RandomULong();
4805 for (i = 0; i < sc->sc_rthash_size; i++)
4806 LIST_INIT(&sc->sc_rthash[i]);
4808 LIST_FOREACH(brt, &sc->sc_rtlist, brt_list) {
4810 (void) bridge_rtnode_hash(sc, brt);
4817 sc->sc_ifp->if_xname, sc->sc_rthash_size);
4824 sc->sc_ifp->if_xname, error);
4837 bridge_rthash_resize(struct bridge_softc *sc)
4839 BRIDGE_LOCK_ASSERT_HELD(sc);
4841 if ((sc->sc_flags & SCF_DETACHING) || (sc->sc_flags & SCF_RESIZING))
4847 if (sc->sc_brtcnt < sc->sc_rthash_size * 4)
4852 if (sc->sc_rthash_size >= bridge_rtable_hash_size_max)
4855 sc->sc_resize_call.bdc_sc = sc;
4856 sc->sc_resize_call.bdc_func = bridge_rthash_delayed_resize;
4857 bridge_schedule_delayed_call(&sc->sc_resize_call);
4866 bridge_rtable_fini(struct bridge_softc *sc)
4868 KASSERT(sc->sc_brtcnt == 0,
4869 ("%s: %d bridge routes referenced", __func__, sc->sc_brtcnt));
4870 if (sc->sc_rthash) {
4871 _FREE(sc->sc_rthash, M_DEVBUF);
4872 sc->sc_rthash = NULL;
4894 bridge_rthash(struct bridge_softc *sc, const uint8_t *addr)
4896 uint32_t a = 0x9e3779b9, b = 0x9e3779b9, c = sc->sc_rthash_key;
4907 return (c & BRIDGE_RTHASH_MASK(sc));
4931 bridge_rtnode_lookup(struct bridge_softc *sc, const uint8_t *addr,
4938 BRIDGE_LOCK_ASSERT_HELD(sc);
4940 hash = bridge_rthash(sc, addr);
4941 LIST_FOREACH(brt, &sc->sc_rthash[hash], brt_hash) {
4960 bridge_rtnode_hash(struct bridge_softc *sc, struct bridge_rtnode *brt)
4966 BRIDGE_LOCK_ASSERT_HELD(sc);
4968 hash = bridge_rthash(sc, brt->brt_addr);
4970 lbrt = LIST_FIRST(&sc->sc_rthash[hash]);
4972 LIST_INSERT_HEAD(&sc->sc_rthash[hash], brt, brt_hash);
4983 __func__, sc->sc_ifp->if_xname,
5004 __func__, sc->sc_ifp->if_xname,
5020 bridge_rtnode_insert(struct bridge_softc *sc, struct bridge_rtnode *brt)
5024 error = bridge_rtnode_hash(sc, brt);
5028 LIST_INSERT_HEAD(&sc->sc_rtlist, brt, brt_list);
5029 sc->sc_brtcnt++;
5031 bridge_rthash_resize(sc);
5042 bridge_rtnode_destroy(struct bridge_softc *sc, struct bridge_rtnode *brt)
5044 BRIDGE_LOCK_ASSERT_HELD(sc);
5049 sc->sc_brtcnt--;
5063 struct bridge_softc *sc = ifp->if_bridge;
5066 BRIDGE_LOCK(sc);
5073 bridge_rtdelete(sc, ifp, IFBF_FLUSHDYN);
5079 LIST_FOREACH(brt, &sc->sc_rtlist, brt_list) {
5087 BRIDGE_UNLOCK(sc);
5098 struct bridge_softc *sc = ifp->if_bridge;
5110 sc->sc_ifp->if_xname,
5624 struct bridge_softc *sc = (struct bridge_softc *)ifnet_softc(ifp);
5627 if (sc == NULL || (sc->sc_flags & SCF_DETACHING)) {
5633 sc->sc_bpf_input = sc->sc_bpf_output = NULL;
5637 sc->sc_bpf_input = bpf_callback;
5641 sc->sc_bpf_output = bpf_callback;
5645 sc->sc_bpf_input = sc->sc_bpf_output = bpf_callback;
5663 struct bridge_softc *sc = (struct bridge_softc *)ifnet_softc(ifp);
5666 bstp_detach(&sc->sc_stp);
5670 bridge_rtable_fini(sc);
5673 LIST_REMOVE(sc, sc_list);
5678 lck_mtx_destroy(&sc->sc_mtx, bridge_lock_grp);
5680 _FREE(sc, M_DEVBUF);
5691 struct bridge_softc *sc = (struct bridge_softc *)ifnet_softc(ifp);
5693 if (sc->sc_bpf_input) {
5699 (*sc->sc_bpf_input)(ifp, m);
5712 struct bridge_softc *sc = (struct bridge_softc *)ifnet_softc(ifp);
5714 if (sc->sc_bpf_output) {
5715 (*sc->sc_bpf_output)(ifp, m);