Lines Matching defs:sc

244 #define	BRIDGE_BPF_MTAP_INPUT(sc, m)					\
245 if (sc->sc_bpf_input) \
246 bridge_bpf_input(sc->sc_ifp, m)
263 #define BRIDGE_RTHASH_MASK(sc) ((sc)->sc_rthash_size - 1)
447 static void bridge_aging_timer(struct bridge_softc *sc);
528 static int bridge_ioctl_purge(struct bridge_softc *sc, void *);
876 bridge_lock(struct bridge_softc *sc)
880 BRIDGE_LOCK_ASSERT_NOTHELD(sc);
882 _BRIDGE_LOCK(sc);
884 sc->lock_lr[sc->next_lock_lr] = lr_saved;
885 sc->next_lock_lr = (sc->next_lock_lr+1) % SO_LCKDBG_MAX;
889 bridge_unlock(struct bridge_softc *sc)
893 BRIDGE_LOCK_ASSERT_HELD(sc);
895 sc->unlock_lr[sc->next_unlock_lr] = lr_saved;
896 sc->next_unlock_lr = (sc->next_unlock_lr+1) % SO_LCKDBG_MAX;
898 _BRIDGE_UNLOCK(sc);
902 bridge_lock2ref(struct bridge_softc *sc)
907 BRIDGE_LOCK_ASSERT_HELD(sc);
909 if (sc->sc_iflist_xcnt > 0)
912 sc->sc_iflist_ref++;
914 sc->unlock_lr[sc->next_unlock_lr] = lr_saved;
915 sc->next_unlock_lr = (sc->next_unlock_lr+1) % SO_LCKDBG_MAX;
917 _BRIDGE_UNLOCK(sc);
923 bridge_unref(struct bridge_softc *sc)
927 BRIDGE_LOCK_ASSERT_NOTHELD(sc);
929 _BRIDGE_LOCK(sc);
930 sc->lock_lr[sc->next_lock_lr] = lr_saved;
931 sc->next_lock_lr = (sc->next_lock_lr+1) % SO_LCKDBG_MAX;
933 sc->sc_iflist_ref--;
935 sc->unlock_lr[sc->next_unlock_lr] = lr_saved;
936 sc->next_unlock_lr = (sc->next_unlock_lr+1) % SO_LCKDBG_MAX;
937 if ((sc->sc_iflist_xcnt > 0) && (sc->sc_iflist_ref == 0)) {
938 _BRIDGE_UNLOCK(sc);
939 wakeup(&sc->sc_cv);
941 _BRIDGE_UNLOCK(sc);
945 bridge_xlock(struct bridge_softc *sc)
949 BRIDGE_LOCK_ASSERT_HELD(sc);
951 sc->sc_iflist_xcnt++;
952 while (sc->sc_iflist_ref > 0) {
953 sc->unlock_lr[sc->next_unlock_lr] = lr_saved;
954 sc->next_unlock_lr = (sc->next_unlock_lr+1) % SO_LCKDBG_MAX;
956 msleep(&sc->sc_cv, &sc->sc_mtx, PZERO, "BRIDGE_XLOCK", NULL);
958 sc->lock_lr[sc->next_lock_lr] = lr_saved;
959 sc->next_lock_lr = (sc->next_lock_lr+1) % SO_LCKDBG_MAX;
964 bridge_xdrop(struct bridge_softc *sc)
966 BRIDGE_LOCK_ASSERT_HELD(sc);
968 sc->sc_iflist_xcnt--;
1163 struct bridge_softc *sc, *sc2;
1172 sc = _MALLOC(sizeof (*sc), M_DEVBUF, M_WAITOK | M_ZERO);
1174 lck_mtx_init(&sc->sc_mtx, bridge_lock_grp, bridge_lock_attr);
1175 sc->sc_brtmax = BRIDGE_RTABLE_MAX;
1176 sc->sc_brttimeout = BRIDGE_RTABLE_TIMEOUT;
1177 sc->sc_filter_flags = IFBF_FILT_DEFAULT;
1184 sc->sc_filter_flags &= ~IFBF_FILT_USEIPF;
1188 error = bridge_rtable_init(sc);
1194 TAILQ_INIT(&sc->sc_iflist);
1195 TAILQ_INIT(&sc->sc_spanlist);
1198 snprintf(sc->sc_if_xname, sizeof (sc->sc_if_xname), "%s%d",
1209 init_params.uniqueid = sc->sc_if_xname;
1210 init_params.uniqueid_len = strlen(sc->sc_if_xname);
1221 init_params.softc = sc;
1232 sc->sc_ifp = ifp;
1271 read_random(&sc->sc_defaddr, ETHER_ADDR_LEN);
1272 sc->sc_defaddr[0] &= ~1; /* clear multicast bit */
1273 sc->sc_defaddr[0] |= 2; /* set the LAA bit */
1275 bcopy(&eth_hostid[0], &sc->sc_defaddr,
1277 sc->sc_defaddr[0] &= ~1; /* clear multicast bit */
1278 sc->sc_defaddr[0] |= 2; /* set the LAA bit */
1279 sc->sc_defaddr[3] = /* stir it up a bit */
1280 ((sc->sc_defaddr[3] & 0x0f) << 4) |
1281 ((sc->sc_defaddr[3] & 0xf0) >> 4);
1286 sc->sc_defaddr[4] =
1287 (((sc->sc_defaddr[4] & 0x0f) << 4) |
1288 ((sc->sc_defaddr[4] & 0xf0) >> 4)) ^
1289 sc->sc_defaddr[5];
1290 sc->sc_defaddr[5] = ifp->if_unit & 0xff;
1297 if (memcmp(sc->sc_defaddr,
1306 sdl->sdl_nlen = strlen(sc->sc_if_xname);
1309 memcpy(sdl->sdl_data, sc->sc_if_xname, sdl->sdl_nlen);
1310 memcpy(LLADDR(sdl), sc->sc_defaddr, ETHER_ADDR_LEN);
1312 sc->sc_flags &= ~SCF_MEDIA_ACTIVE;
1325 error = ifnet_set_lladdr_and_type(ifp, sc->sc_defaddr, ETHER_ADDR_LEN,
1337 error = bridge_set_tso(sc);
1344 bstp_attach(&sc->sc_stp, &bridge_ops);
1348 LIST_INSERT_HEAD(&bridge_list, sc, sc_list);
1372 struct bridge_softc *sc = ifp->if_softc;
1376 BRIDGE_LOCK(sc);
1377 if ((sc->sc_flags & SCF_DETACHING)) {
1378 BRIDGE_UNLOCK(sc);
1381 sc->sc_flags |= SCF_DETACHING;
1385 bridge_cancel_delayed_call(&sc->sc_resize_call);
1387 bridge_cleanup_delayed_call(&sc->sc_resize_call);
1388 bridge_cleanup_delayed_call(&sc->sc_aging_timer);
1395 while ((bif = TAILQ_FIRST(&sc->sc_iflist)) != NULL)
1396 bridge_delete_member(sc, bif, 0);
1398 while ((bif = TAILQ_FIRST(&sc->sc_spanlist)) != NULL) {
1399 bridge_delete_span(sc, bif);
1402 BRIDGE_UNLOCK(sc);
1408 if ((sc = (struct bridge_softc *)ifnet_softc(ifp)) != NULL) {
1409 BRIDGE_LOCK(sc);
1410 sc->sc_flags &= ~SCF_DETACHING;
1411 BRIDGE_UNLOCK(sc);
1456 BRIDGE_LOCK(sc); \
1457 error = (*bc->bc_func)(sc, &args); \
1458 BRIDGE_UNLOCK(sc); \
1474 struct bridge_softc *sc = ifp->if_softc;
1479 BRIDGE_LOCK_ASSERT_NOTHELD(sc);
1509 BRIDGE_LOCK(sc);
1510 if (!(sc->sc_flags & SCF_DETACHING) &&
1511 (sc->sc_flags & SCF_MEDIA_ACTIVE)) {
1518 BRIDGE_UNLOCK(sc);
1575 BRIDGE_LOCK(sc);
1577 BRIDGE_UNLOCK(sc);
1584 BRIDGE_LOCK(sc);
1586 BRIDGE_UNLOCK(sc);
1603 BRIDGE_LOCK(sc);
1604 if (TAILQ_EMPTY(&sc->sc_iflist)) {
1605 sc->sc_ifp->if_mtu = ifr->ifr_mtu;
1606 BRIDGE_UNLOCK(sc);
1609 TAILQ_FOREACH(bif, &sc->sc_iflist, bif_next) {
1612 sc->sc_ifp->if_xname,
1620 sc->sc_ifp->if_mtu = ifr->ifr_mtu;
1621 BRIDGE_UNLOCK(sc);
1638 BRIDGE_LOCK_ASSERT_NOTHELD(sc);
1650 bridge_mutecaps(struct bridge_softc *sc)
1658 TAILQ_FOREACH(bif, &sc->sc_iflist, bif_next) {
1663 TAILQ_FOREACH(bif, &sc->sc_iflist, bif_next) {
1670 bridge_set_ifcap(sc, bif, enabled);
1676 bridge_set_ifcap(struct bridge_softc *sc, struct bridge_iflist *bif, int set)
1691 "on %s\n", __func__, sc->sc_ifp->if_xname,
1698 bridge_set_tso(struct bridge_softc *sc)
1707 offload = sc->sc_ifp->if_hwassist | IFNET_TSO_IPV4 | IFNET_TSO_IPV6;
1712 TAILQ_FOREACH(bif, &sc->sc_iflist, bif_next) {
1738 if (offload != sc->sc_ifp->if_hwassist) {
1739 error = ifnet_set_offload(sc->sc_ifp, offload);
1745 sc->sc_ifp->if_xname, offload, error);
1753 if (sc->sc_ifp->if_hwassist & IFNET_TSO_IPV4) {
1754 if (tso_v4_mtu < sc->sc_ifp->if_mtu)
1755 tso_v4_mtu = sc->sc_ifp->if_mtu;
1756 error = ifnet_set_tso_mtu(sc->sc_ifp, AF_INET,
1763 __func__, sc->sc_ifp->if_xname,
1769 if (sc->sc_ifp->if_hwassist & IFNET_TSO_IPV6) {
1770 if (tso_v6_mtu < sc->sc_ifp->if_mtu)
1771 tso_v6_mtu = sc->sc_ifp->if_mtu;
1772 error = ifnet_set_tso_mtu(sc->sc_ifp, AF_INET6,
1779 __func__, sc->sc_ifp->if_xname,
1796 bridge_lookup_member(struct bridge_softc *sc, const char *name)
1801 BRIDGE_LOCK_ASSERT_HELD(sc);
1803 TAILQ_FOREACH(bif, &sc->sc_iflist, bif_next) {
1818 bridge_lookup_member_if(struct bridge_softc *sc, struct ifnet *member_ifp)
1822 BRIDGE_LOCK_ASSERT_HELD(sc);
1824 TAILQ_FOREACH(bif, &sc->sc_iflist, bif_next) {
1839 struct bridge_softc *sc = bif->bif_sc;
1855 "frmlen %lu\n", __func__, sc->sc_ifp->if_xname,
1898 BRIDGE_LOCK_ASSERT_NOTHELD(sc);
1911 struct bridge_softc *sc = bif->bif_sc;
1920 sc->sc_ifp->if_xname, ifp->if_xname,
1926 error = bridge_member_output(sc, ifp, m);
1933 BRIDGE_LOCK_ASSERT_NOTHELD(sc);
1945 struct bridge_softc *sc = bif->bif_sc;
1990 BRIDGE_LOCK(sc);
1991 bridge_set_tso(sc);
1992 BRIDGE_UNLOCK(sc);
2079 bridge_delete_member(struct bridge_softc *sc, struct bridge_iflist *bif,
2082 struct ifnet *ifs = bif->bif_ifp, *bifp = sc->sc_ifp;
2087 BRIDGE_LOCK_ASSERT_HELD(sc);
2111 bridge_set_ifcap(sc, bif, bif->bif_savedcaps);
2117 BRIDGE_UNLOCK(sc);
2119 BRIDGE_LOCK(sc);
2126 BRIDGE_XLOCK(sc);
2127 TAILQ_REMOVE(&sc->sc_iflist, bif, bif_next);
2128 BRIDGE_XDROP(sc);
2135 if (bridge_inherit_mac && sc->sc_ifaddr == ifs) {
2136 ifnet_release(sc->sc_ifaddr);
2137 if (TAILQ_EMPTY(&sc->sc_iflist)) {
2138 bcopy(sc->sc_defaddr, eaddr, ETHER_ADDR_LEN);
2139 sc->sc_ifaddr = NULL;
2142 TAILQ_FIRST(&sc->sc_iflist)->bif_ifp;
2144 sc->sc_ifaddr = fif;
2151 bridge_mutecaps(sc); /* recalculate now this interface is removed */
2154 error = bridge_set_tso(sc);
2159 bridge_rtdelete(sc, ifs, IFBF_FLUSHALL);
2168 event_code = bridge_updatelinkstatus(sc);
2170 BRIDGE_UNLOCK(sc);
2191 BRIDGE_LOCK(sc);
2200 bridge_delete_span(struct bridge_softc *sc, struct bridge_iflist *bif)
2202 BRIDGE_LOCK_ASSERT_HELD(sc);
2209 TAILQ_REMOVE(&sc->sc_spanlist, bif, bif_next);
2214 bridge_ioctl_add(struct bridge_softc *sc, void *arg)
2218 struct ifnet *ifs, *bifp = sc->sc_ifp;
2231 TAILQ_FOREACH(bif, &sc->sc_spanlist, bif_next)
2235 if (ifs->if_bridge == sc)
2263 bif->bif_sc = sc;
2266 if (TAILQ_EMPTY(&sc->sc_iflist))
2267 sc->sc_ifp->if_mtu = ifs->if_mtu;
2268 else if (sc->sc_ifp->if_mtu != ifs->if_mtu) {
2270 sc->sc_ifp->if_xname,
2280 if (bridge_inherit_mac && TAILQ_EMPTY(&sc->sc_iflist) &&
2281 !memcmp(IF_LLADDR(sc->sc_ifp), sc->sc_defaddr, ETHER_ADDR_LEN)) {
2283 sc->sc_ifaddr = ifs;
2288 ifs->if_bridge = sc;
2290 bstp_create(&sc->sc_stp, &bif->bif_stp, bif->bif_ifp);
2296 TAILQ_INSERT_TAIL(&sc->sc_iflist, bif, bif_next);
2300 bridge_mutecaps(sc);
2303 bridge_set_tso(sc);
2335 event_code = bridge_updatelinkstatus(sc);
2340 BRIDGE_UNLOCK(sc);
2357 BRIDGE_LOCK(sc);
2369 BRIDGE_LOCK(sc);
2382 BRIDGE_LOCK(sc);
2386 bridge_delete_member(sc, bif, 1);
2392 bridge_ioctl_del(struct bridge_softc *sc, void *arg)
2397 bif = bridge_lookup_member(sc, req->ifbr_ifsname);
2401 bridge_delete_member(sc, bif, 0);
2407 bridge_ioctl_purge(struct bridge_softc *sc, void *arg)
2409 #pragma unused(sc, arg)
2414 bridge_ioctl_gifflags(struct bridge_softc *sc, void *arg)
2420 bif = bridge_lookup_member(sc, req->ifbr_ifsname);
2454 bridge_ioctl_sifflags(struct bridge_softc *sc, void *arg)
2463 bif = bridge_lookup_member(sc, req->ifbr_ifsname);
2503 bridge_ioctl_scache(struct bridge_softc *sc, void *arg)
2507 sc->sc_brtmax = param->ifbrp_csize;
2508 bridge_rttrim(sc);
2514 bridge_ioctl_gcache(struct bridge_softc *sc, void *arg)
2518 param->ifbrp_csize = sc->sc_brtmax;
2530 TAILQ_FOREACH(bif, &sc->sc_iflist, bif_next) \
2532 TAILQ_FOREACH(bif, &sc->sc_spanlist, bif_next) \
2540 BRIDGE_UNLOCK(sc); \
2542 BRIDGE_LOCK(sc); \
2548 TAILQ_FOREACH(bif, &sc->sc_iflist, bif_next) { \
2555 error = bridge_ioctl_gifflags(sc, &breq); \
2563 TAILQ_FOREACH(bif, &sc->sc_spanlist, bif_next) { \
2577 BRIDGE_UNLOCK(sc); \
2580 BRIDGE_LOCK(sc); \
2585 bridge_ioctl_gifs64(struct bridge_softc *sc, void *arg)
2596 bridge_ioctl_gifs32(struct bridge_softc *sc, void *arg)
2616 LIST_FOREACH(brt, &sc->sc_rtlist, brt_list) \
2620 BRIDGE_UNLOCK(sc); \
2622 BRIDGE_LOCK(sc); \
2628 LIST_FOREACH(brt, &sc->sc_rtlist, brt_list) { \
2650 BRIDGE_UNLOCK(sc); \
2653 BRIDGE_LOCK(sc); \
2659 bridge_ioctl_rts64(struct bridge_softc *sc, void *arg)
2671 bridge_ioctl_rts32(struct bridge_softc *sc, void *arg)
2683 bridge_ioctl_saddr32(struct bridge_softc *sc, void *arg)
2689 bif = bridge_lookup_member(sc, req->ifba_ifsname);
2693 error = bridge_rtupdate(sc, req->ifba_dst, req->ifba_vlan, bif, 1,
2700 bridge_ioctl_saddr64(struct bridge_softc *sc, void *arg)
2706 bif = bridge_lookup_member(sc, req->ifba_ifsname);
2710 error = bridge_rtupdate(sc, req->ifba_dst, req->ifba_vlan, bif, 1,
2717 bridge_ioctl_sto(struct bridge_softc *sc, void *arg)
2721 sc->sc_brttimeout = param->ifbrp_ctime;
2726 bridge_ioctl_gto(struct bridge_softc *sc, void *arg)
2730 param->ifbrp_ctime = sc->sc_brttimeout;
2735 bridge_ioctl_daddr32(struct bridge_softc *sc, void *arg)
2739 return (bridge_rtdaddr(sc, req->ifba_dst, req->ifba_vlan));
2743 bridge_ioctl_daddr64(struct bridge_softc *sc, void *arg)
2747 return (bridge_rtdaddr(sc, req->ifba_dst, req->ifba_vlan));
2751 bridge_ioctl_flush(struct bridge_softc *sc, void *arg)
2755 bridge_rtflush(sc, req->ifbr_ifsflags);
2760 bridge_ioctl_gpri(struct bridge_softc *sc, void *arg)
2763 struct bstp_state *bs = &sc->sc_stp;
2770 bridge_ioctl_spri(struct bridge_softc *sc, void *arg)
2775 return (bstp_set_priority(&sc->sc_stp, param->ifbrp_prio));
2777 #pragma unused(sc, arg)
2783 bridge_ioctl_ght(struct bridge_softc *sc, void *arg)
2786 struct bstp_state *bs = &sc->sc_stp;
2793 bridge_ioctl_sht(struct bridge_softc *sc, void *arg)
2798 return (bstp_set_htime(&sc->sc_stp, param->ifbrp_hellotime));
2800 #pragma unused(sc, arg)
2806 bridge_ioctl_gfd(struct bridge_softc *sc, void *arg)
2809 struct bstp_state *bs = &sc->sc_stp;
2816 bridge_ioctl_sfd(struct bridge_softc *sc, void *arg)
2821 return (bstp_set_fdelay(&sc->sc_stp, param->ifbrp_fwddelay));
2823 #pragma unused(sc, arg)
2829 bridge_ioctl_gma(struct bridge_softc *sc, void *arg)
2832 struct bstp_state *bs = &sc->sc_stp;
2839 bridge_ioctl_sma(struct bridge_softc *sc, void *arg)
2844 return (bstp_set_maxage(&sc->sc_stp, param->ifbrp_maxage));
2846 #pragma unused(sc, arg)
2852 bridge_ioctl_sifprio(struct bridge_softc *sc, void *arg)
2858 bif = bridge_lookup_member(sc, req->ifbr_ifsname);
2864 #pragma unused(sc, arg)
2870 bridge_ioctl_sifcost(struct bridge_softc *sc, void *arg)
2876 bif = bridge_lookup_member(sc, req->ifbr_ifsname);
2882 #pragma unused(sc, arg)
2888 bridge_ioctl_gfilt(struct bridge_softc *sc, void *arg)
2892 param->ifbrp_filter = sc->sc_filter_flags;
2898 bridge_ioctl_sfilt(struct bridge_softc *sc, void *arg)
2910 sc->sc_filter_flags = param->ifbrp_filter;
2916 bridge_ioctl_sifmaxaddr(struct bridge_softc *sc, void *arg)
2921 bif = bridge_lookup_member(sc, req->ifbr_ifsname);
2930 bridge_ioctl_addspan(struct bridge_softc *sc, void *arg)
2940 TAILQ_FOREACH(bif, &sc->sc_spanlist, bif_next)
2967 TAILQ_INSERT_HEAD(&sc->sc_spanlist, bif, bif_next);
2973 bridge_ioctl_delspan(struct bridge_softc *sc, void *arg)
2983 TAILQ_FOREACH(bif, &sc->sc_spanlist, bif_next)
2990 bridge_delete_span(sc, bif);
2996 struct bstp_state *bs = &sc->sc_stp; \
3021 bridge_ioctl_gbparam32(struct bridge_softc *sc, void *arg)
3031 bridge_ioctl_gbparam64(struct bridge_softc *sc, void *arg)
3041 bridge_ioctl_grte(struct bridge_softc *sc, void *arg)
3045 param->ifbrp_cexceeded = sc->sc_brtexceeded;
3057 TAILQ_FOREACH(bif, &sc->sc_iflist, bif_next) { \
3068 BRIDGE_UNLOCK(sc); \
3070 BRIDGE_LOCK(sc); \
3076 TAILQ_FOREACH(bif, &sc->sc_iflist, bif_next) { \
3097 BRIDGE_UNLOCK(sc); \
3100 BRIDGE_LOCK(sc); \
3106 bridge_ioctl_gifsstp32(struct bridge_softc *sc, void *arg)
3117 bridge_ioctl_gifsstp64(struct bridge_softc *sc, void *arg)
3128 bridge_ioctl_sproto(struct bridge_softc *sc, void *arg)
3133 return (bstp_set_protocol(&sc->sc_stp, param->ifbrp_proto));
3135 #pragma unused(sc, arg)
3141 bridge_ioctl_stxhc(struct bridge_softc *sc, void *arg)
3146 return (bstp_set_holdcount(&sc->sc_stp, param->ifbrp_txhc));
3148 #pragma unused(sc, arg)
3155 bridge_ioctl_ghostfilter(struct bridge_softc *sc, void *arg)
3160 bif = bridge_lookup_member(sc, req->ifbrhf_ifsname);
3175 bridge_ioctl_shostfilter(struct bridge_softc *sc, void *arg)
3180 bif = bridge_lookup_member(sc, req->ifbrhf_ifsname);
3223 struct bridge_softc *sc = ifp->if_bridge;
3231 if (sc != NULL) {
3232 BRIDGE_LOCK(sc);
3233 bif = bridge_lookup_member_if(sc, ifp);
3235 bridge_delete_member(sc, bif, 1);
3236 BRIDGE_UNLOCK(sc);
3242 LIST_FOREACH(sc, &bridge_list, sc_list) {
3243 BRIDGE_LOCK(sc);
3244 TAILQ_FOREACH(bif, &sc->sc_spanlist, bif_next)
3246 bridge_delete_span(sc, bif);
3249 BRIDGE_UNLOCK(sc);
3282 bridge_updatelinkstatus(struct bridge_softc *sc)
3288 BRIDGE_LOCK_ASSERT_HELD(sc);
3293 TAILQ_FOREACH(bif, &sc->sc_iflist, bif_next) {
3300 if (active_member && !(sc->sc_flags & SCF_MEDIA_ACTIVE)) {
3301 sc->sc_flags |= SCF_MEDIA_ACTIVE;
3303 } else if (!active_member && (sc->sc_flags & SCF_MEDIA_ACTIVE)) {
3304 sc->sc_flags &= ~SCF_MEDIA_ACTIVE;
3317 struct bridge_softc *sc = ifp->if_bridge;
3327 if (sc == NULL)
3330 BRIDGE_LOCK(sc);
3331 bif = bridge_lookup_member_if(sc, ifp);
3338 event_code = bridge_updatelinkstatus(sc);
3340 BRIDGE_UNLOCK(sc);
3343 bridge_link_event(sc->sc_ifp, event_code);
3355 struct bridge_softc *sc = call->bdc_sc;
3374 BRIDGE_LOCK(sc);
3379 sc->sc_if_xname, (uint64_t)VM_KERNEL_ADDRPERM(call),
3386 if ((sc->sc_flags & SCF_DETACHING) == 0)
3387 (*call->bdc_func)(sc);
3390 BRIDGE_UNLOCK(sc);
3403 struct bridge_softc *sc = call->bdc_sc;
3405 BRIDGE_LOCK_ASSERT_HELD(sc);
3407 if ((sc->sc_flags & SCF_DETACHING) ||
3423 sc->sc_if_xname, (uint64_t)VM_KERNEL_ADDRPERM(call),
3451 struct bridge_softc *sc = call->bdc_sc;
3456 if (sc == NULL)
3459 BRIDGE_LOCK_ASSERT_HELD(sc);
3467 sc->sc_if_xname, (uint64_t)VM_KERNEL_ADDRPERM(call),
3482 msleep(call, &sc->sc_mtx, PZERO, __func__, NULL);
3498 struct bridge_softc *sc = call->bdc_sc;
3503 if (sc == NULL)
3506 BRIDGE_LOCK_ASSERT_HELD(sc);
3528 struct bridge_softc *sc = (struct bridge_softc *)ifp->if_softc;
3531 BRIDGE_LOCK_ASSERT_HELD(sc);
3542 bridge_aging_timer(sc);
3546 bstp_init(&sc->sc_stp); /* Initialize Spanning Tree */
3561 struct bridge_softc *sc = ifp->if_softc;
3563 BRIDGE_LOCK_ASSERT_HELD(sc);
3568 bridge_cancel_delayed_call(&sc->sc_aging_timer);
3571 bstp_stop(&sc->sc_stp);
3574 bridge_rtflush(sc, IFBF_FLUSHDYN);
3586 bridge_enqueue(struct bridge_softc *sc, struct ifnet *dst_ifp, struct mbuf *m)
3644 (void) ifnet_stat_increment_out(sc->sc_ifp, 1, len, 0);
3646 (void) ifnet_stat_increment_out(sc->sc_ifp, 0, 0, 1);
3665 struct bridge_softc *sc;
3667 sc = ifp->if_bridge;
3674 if (sc == NULL) {
3680 if (bridge_pfil(&m, sc->sc_ifp, ifp, PFIL_OUT) != 0)
3686 (void) bridge_enqueue(sc, ifp, m);
3708 struct bridge_softc *sc;
3723 sc = ifp->if_bridge;
3726 BRIDGE_LOCK(sc);
3743 if ((sc->sc_ifp->if_flags & IFF_RUNNING) == 0) {
3755 dst_if = bridge_rtlookup(sc, eh->ether_dhost, vlan);
3761 bridge_span(sc, m);
3763 BRIDGE_LOCK2REF(sc, error);
3769 TAILQ_FOREACH(bif, &sc->sc_iflist, bif_next) {
3794 sc->sc_ifp, 0, 0, 1);
3799 (void) bridge_enqueue(sc, dst_if, mc);
3803 BRIDGE_UNREF(sc);
3812 bridge_span(sc, m);
3815 BRIDGE_UNLOCK(sc);
3819 BRIDGE_UNLOCK(sc);
3820 (void) bridge_enqueue(sc, dst_if, m);
3834 struct bridge_softc *sc = ifnet_softc(ifp);
3842 BRIDGE_LOCK(sc);
3844 dst_if = bridge_rtlookup(sc, eh->ether_dhost, 0);
3849 if (sc->sc_bpf_output)
3855 bridge_broadcast(sc, ifp, m, 0);
3857 BRIDGE_UNLOCK(sc);
3858 error = bridge_enqueue(sc, dst_if, m);
3958 bridge_forward(struct bridge_softc *sc, struct bridge_iflist *sbif,
3968 BRIDGE_LOCK_ASSERT_HELD(sc);
3972 printf("%s: %s m 0x%llx\n", __func__, sc->sc_ifp->if_xname,
3977 ifp = sc->sc_ifp;
3992 error = bridge_rtupdate(sc, eh->ether_shost, vlan,
4016 dst_if = bridge_rtlookup(sc, dst, vlan);
4050 if (sc->sc_bpf_input)
4058 BRIDGE_UNLOCK(sc);
4063 BRIDGE_LOCK(sc);
4068 bridge_broadcast(sc, src_if, m, 1);
4079 dbif = bridge_lookup_member_if(sc, dst_if);
4097 ++sc->sc_sc.sc_ifp.if_xdhcpra;
4103 BRIDGE_UNLOCK(sc);
4114 (void) bridge_enqueue(sc, dst_if, m);
4118 BRIDGE_UNLOCK(sc);
4146 struct bridge_softc *sc = ifp->if_bridge;
4157 sc->sc_ifp->if_xname, ifp->if_xname,
4162 if ((sc->sc_ifp->if_flags & IFF_RUNNING) == 0) {
4166 __func__, sc->sc_ifp->if_xname);
4171 bifp = sc->sc_ifp;
4183 BRIDGE_BPF_MTAP_INPUT(sc, m);
4197 BRIDGE_LOCK(sc);
4198 bif = bridge_lookup_member_if(sc, ifp);
4200 BRIDGE_UNLOCK(sc);
4204 __func__, sc->sc_ifp->if_xname);
4215 BRIDGE_UNLOCK(sc);
4222 bridge_span(sc, m);
4247 BRIDGE_UNLOCK(sc);
4254 BRIDGE_UNLOCK(sc);
4265 BRIDGE_UNLOCK(sc);
4274 bridge_forward(sc, bif, mc);
4295 if (sc->sc_bpf_input)
4309 sc->sc_ifp->if_xname);
4321 BRIDGE_UNLOCK(sc);
4344 #define PFIL_PHYS(sc, ifp, m) do { \
4349 BRIDGE_UNLOCK(sc); \
4355 #define PFIL_PHYS(sc, ifp, m)
4365 BRIDGE_BPF_MTAP_INPUT(sc, m); \
4367 PFIL_PHYS(sc, iface, m); \
4370 error = bridge_rtupdate(sc, eh->ether_shost, \
4373 BRIDGE_UNLOCK(sc); \
4378 BRIDGE_UNLOCK(sc); \
4385 BRIDGE_UNLOCK(sc); \
4410 (void) bridge_rtupdate(sc, eh->ether_shost,
4413 BRIDGE_BPF_MTAP_INPUT(sc, m);
4421 BRIDGE_UNLOCK(sc);
4426 sc->sc_ifp->if_xname);
4453 BRIDGE_UNLOCK(sc);
4458 TAILQ_FOREACH(bif2, &sc->sc_iflist, bif_next) {
4471 bridge_forward(sc, bif, m);
4486 bridge_broadcast(struct bridge_softc *sc, struct ifnet *src_if,
4497 sbif = bridge_lookup_member_if(sc, src_if);
4499 BRIDGE_LOCK2REF(sc, error);
4508 if (bridge_pfil(&m, sc->sc_ifp, NULL, PFIL_OUT) != 0)
4515 TAILQ_FOREACH(dbif, &sc->sc_iflist, bif_next) {
4546 (void) ifnet_stat_increment_out(sc->sc_ifp,
4566 sc->sc_ifp, 0, 0, 1);
4577 (void) bridge_enqueue(sc, dst_if, mc);
4586 BRIDGE_UNREF(sc);
4596 bridge_span(struct bridge_softc *sc, struct mbuf *m)
4602 if (TAILQ_EMPTY(&sc->sc_spanlist))
4605 TAILQ_FOREACH(bif, &sc->sc_spanlist, bif_next) {
4613 (void) ifnet_stat_increment_out(sc->sc_ifp, 0, 0, 1);
4617 (void) bridge_enqueue(sc, dst_if, mc);
4628 bridge_rtupdate(struct bridge_softc *sc, const uint8_t *dst, uint16_t vlan,
4634 BRIDGE_LOCK_ASSERT_HELD(sc);
4651 if ((brt = bridge_rtnode_lookup(sc, dst, vlan)) == NULL) {
4652 if (sc->sc_brtcnt >= sc->sc_brtmax) {
4653 sc->sc_brtexceeded++;
4681 if ((error = bridge_rtnode_insert(sc, brt)) != 0) {
4692 sc->sc_ifp->if_xname, sc->sc_brtcnt,
4693 sc->sc_rthash_size);
4708 brt->brt_expire = now + sc->sc_brttimeout;
4723 bridge_rtlookup(struct bridge_softc *sc, const uint8_t *addr, uint16_t vlan)
4727 BRIDGE_LOCK_ASSERT_HELD(sc);
4729 if ((brt = bridge_rtnode_lookup(sc, addr, vlan)) == NULL)
4743 bridge_rttrim(struct bridge_softc *sc)
4747 BRIDGE_LOCK_ASSERT_HELD(sc);
4750 if (sc->sc_brtcnt <= sc->sc_brtmax)
4754 bridge_rtage(sc);
4755 if (sc->sc_brtcnt <= sc->sc_brtmax)
4758 LIST_FOREACH_SAFE(brt, &sc->sc_rtlist, brt_list, nbrt) {
4760 bridge_rtnode_destroy(sc, brt);
4761 if (sc->sc_brtcnt <= sc->sc_brtmax)
4773 bridge_aging_timer(struct bridge_softc *sc)
4775 BRIDGE_LOCK_ASSERT_HELD(sc);
4777 bridge_rtage(sc);
4779 if ((sc->sc_ifp->if_flags & IFF_RUNNING) &&
4780 (sc->sc_flags & SCF_DETACHING) == 0) {
4781 sc->sc_aging_timer.bdc_sc = sc;
4782 sc->sc_aging_timer.bdc_func = bridge_aging_timer;
4783 sc->sc_aging_timer.bdc_ts.tv_sec = bridge_rtable_prune_period;
4784 bridge_schedule_delayed_call(&sc->sc_aging_timer);
4794 bridge_rtage(struct bridge_softc *sc)
4799 BRIDGE_LOCK_ASSERT_HELD(sc);
4803 LIST_FOREACH_SAFE(brt, &sc->sc_rtlist, brt_list, nbrt) {
4806 bridge_rtnode_destroy(sc, brt);
4817 bridge_rtflush(struct bridge_softc *sc, int full)
4821 BRIDGE_LOCK_ASSERT_HELD(sc);
4823 LIST_FOREACH_SAFE(brt, &sc->sc_rtlist, brt_list, nbrt) {
4825 bridge_rtnode_destroy(sc, brt);
4835 bridge_rtdaddr(struct bridge_softc *sc, const uint8_t *addr, uint16_t vlan)
4840 BRIDGE_LOCK_ASSERT_HELD(sc);
4846 while ((brt = bridge_rtnode_lookup(sc, addr, vlan)) != NULL) {
4847 bridge_rtnode_destroy(sc, brt);
4860 bridge_rtdelete(struct bridge_softc *sc, struct ifnet *ifp, int full)
4864 BRIDGE_LOCK_ASSERT_HELD(sc);
4866 LIST_FOREACH_SAFE(brt, &sc->sc_rtlist, brt_list, nbrt) {
4869 bridge_rtnode_destroy(sc, brt);
4879 bridge_rtable_init(struct bridge_softc *sc)
4883 sc->sc_rthash = _MALLOC(sizeof (*sc->sc_rthash) * BRIDGE_RTHASH_SIZE,
4885 if (sc->sc_rthash == NULL) {
4889 sc->sc_rthash_size = BRIDGE_RTHASH_SIZE;
4891 for (i = 0; i < sc->sc_rthash_size; i++)
4892 LIST_INIT(&sc->sc_rthash[i]);
4894 sc->sc_rthash_key = RandomULong();
4896 LIST_INIT(&sc->sc_rtlist);
4907 bridge_rthash_delayed_resize(struct bridge_softc *sc)
4916 BRIDGE_LOCK_ASSERT_HELD(sc);
4921 if (sc->sc_brtcnt < sc->sc_rthash_size * 4)
4928 new_rthash_size = sc->sc_rthash_size * 2;
4930 sc->sc_flags |= SCF_RESIZING;
4931 BRIDGE_UNLOCK(sc);
4933 new_rthash = _MALLOC(sizeof (*sc->sc_rthash) * new_rthash_size,
4936 BRIDGE_LOCK(sc);
4937 sc->sc_flags &= ~SCF_RESIZING;
4943 if ((sc->sc_flags & SCF_DETACHING)) {
4950 old_rthash = sc->sc_rthash;
4951 sc->sc_rthash = new_rthash;
4952 sc->sc_rthash_size = new_rthash_size;
4958 sc->sc_rthash_key = RandomULong();
4960 for (i = 0; i < sc->sc_rthash_size; i++)
4961 LIST_INIT(&sc->sc_rthash[i]);
4963 LIST_FOREACH(brt, &sc->sc_rtlist, brt_list) {
4965 (void) bridge_rtnode_hash(sc, brt);
4972 sc->sc_ifp->if_xname, sc->sc_rthash_size);
4979 sc->sc_ifp->if_xname, error);
4992 bridge_rthash_resize(struct bridge_softc *sc)
4994 BRIDGE_LOCK_ASSERT_HELD(sc);
4996 if ((sc->sc_flags & SCF_DETACHING) || (sc->sc_flags & SCF_RESIZING))
5002 if (sc->sc_brtcnt < sc->sc_rthash_size * 4)
5007 if (sc->sc_rthash_size >= bridge_rtable_hash_size_max)
5010 sc->sc_resize_call.bdc_sc = sc;
5011 sc->sc_resize_call.bdc_func = bridge_rthash_delayed_resize;
5012 bridge_schedule_delayed_call(&sc->sc_resize_call);
5021 bridge_rtable_fini(struct bridge_softc *sc)
5023 KASSERT(sc->sc_brtcnt == 0,
5024 ("%s: %d bridge routes referenced", __func__, sc->sc_brtcnt));
5025 if (sc->sc_rthash) {
5026 _FREE(sc->sc_rthash, M_DEVBUF);
5027 sc->sc_rthash = NULL;
5049 bridge_rthash(struct bridge_softc *sc, const uint8_t *addr)
5051 uint32_t a = 0x9e3779b9, b = 0x9e3779b9, c = sc->sc_rthash_key;
5062 return (c & BRIDGE_RTHASH_MASK(sc));
5086 bridge_rtnode_lookup(struct bridge_softc *sc, const uint8_t *addr,
5093 BRIDGE_LOCK_ASSERT_HELD(sc);
5095 hash = bridge_rthash(sc, addr);
5096 LIST_FOREACH(brt, &sc->sc_rthash[hash], brt_hash) {
5115 bridge_rtnode_hash(struct bridge_softc *sc, struct bridge_rtnode *brt)
5121 BRIDGE_LOCK_ASSERT_HELD(sc);
5123 hash = bridge_rthash(sc, brt->brt_addr);
5125 lbrt = LIST_FIRST(&sc->sc_rthash[hash]);
5127 LIST_INSERT_HEAD(&sc->sc_rthash[hash], brt, brt_hash);
5138 __func__, sc->sc_ifp->if_xname,
5159 __func__, sc->sc_ifp->if_xname,
5175 bridge_rtnode_insert(struct bridge_softc *sc, struct bridge_rtnode *brt)
5179 error = bridge_rtnode_hash(sc, brt);
5183 LIST_INSERT_HEAD(&sc->sc_rtlist, brt, brt_list);
5184 sc->sc_brtcnt++;
5186 bridge_rthash_resize(sc);
5197 bridge_rtnode_destroy(struct bridge_softc *sc, struct bridge_rtnode *brt)
5199 BRIDGE_LOCK_ASSERT_HELD(sc);
5204 sc->sc_brtcnt--;
5218 struct bridge_softc *sc = ifp->if_bridge;
5221 BRIDGE_LOCK(sc);
5228 bridge_rtdelete(sc, ifp, IFBF_FLUSHDYN);
5234 LIST_FOREACH(brt, &sc->sc_rtlist, brt_list) {
5242 BRIDGE_UNLOCK(sc);
5253 struct bridge_softc *sc = ifp->if_bridge;
5265 sc->sc_ifp->if_xname,
5779 struct bridge_softc *sc = (struct bridge_softc *)ifnet_softc(ifp);
5782 if (sc == NULL || (sc->sc_flags & SCF_DETACHING)) {
5788 sc->sc_bpf_input = sc->sc_bpf_output = NULL;
5792 sc->sc_bpf_input = bpf_callback;
5796 sc->sc_bpf_output = bpf_callback;
5800 sc->sc_bpf_input = sc->sc_bpf_output = bpf_callback;
5818 struct bridge_softc *sc = (struct bridge_softc *)ifnet_softc(ifp);
5821 bstp_detach(&sc->sc_stp);
5825 bridge_rtable_fini(sc);
5828 LIST_REMOVE(sc, sc_list);
5833 lck_mtx_destroy(&sc->sc_mtx, bridge_lock_grp);
5835 _FREE(sc, M_DEVBUF);
5846 struct bridge_softc *sc = (struct bridge_softc *)ifnet_softc(ifp);
5848 if (sc->sc_bpf_input) {
5854 (*sc->sc_bpf_input)(ifp, m);
5867 struct bridge_softc *sc = (struct bridge_softc *)ifnet_softc(ifp);
5869 if (sc->sc_bpf_output) {
5870 (*sc->sc_bpf_output)(ifp, m);