Index: if_vlan.c =================================================================== RCS file: /cvs/src/sys/net/if_vlan.c,v retrieving revision 1.135 diff -u -p -r1.135 if_vlan.c --- if_vlan.c 20 Jul 2015 22:16:41 -0000 1.135 +++ if_vlan.c 21 Aug 2015 06:06:59 -0000 @@ -57,6 +57,8 @@ #include #include #include +#include +#include #include #include @@ -72,12 +74,12 @@ #include #endif -u_long vlan_tagmask, svlan_tagmask; - -#define TAG_HASH_SIZE 32 -#define TAG_HASH(tag) (tag & vlan_tagmask) -LIST_HEAD(vlan_taghash, ifvlan) *vlan_tagh, *svlan_tagh; - +#define TAG_HASH_BITS 5 +#define TAG_HASH_SIZE (1 << TAG_HASH_BITS) +#define TAG_HASH_MASK (TAG_HASH_SIZE - 1) +#define TAG_HASH(tag) (tag & TAG_HASH_MASK) +struct srpl *vlan_tagh, *svlan_tagh; +struct rwlock vlan_tagh_lk = RWLOCK_INITIALIZER("vlantag"); int vlan_input(struct ifnet *, struct mbuf *); void vlan_start(struct ifnet *ifp); @@ -100,20 +102,25 @@ struct if_clone vlan_cloner = struct if_clone svlan_cloner = IF_CLONE_INITIALIZER("svlan", vlan_clone_create, vlan_clone_destroy); +void vlan_ref(void *, void *); +void vlan_unref(void *, void *); + +struct srpl_rc vlan_tagh_rc = SRPL_RC_INITIALIZER(vlan_ref, vlan_unref, NULL); + /* ARGSUSED */ void vlanattach(int count) { /* Normal VLAN */ - vlan_tagh = hashinit(TAG_HASH_SIZE, M_DEVBUF, M_NOWAIT, - &vlan_tagmask); + vlan_tagh = mallocarray(TAG_HASH_SIZE, sizeof(*vlan_tagh), + M_DEVBUF, M_NOWAIT); if (vlan_tagh == NULL) panic("vlanattach: hashinit"); if_clone_attach(&vlan_cloner); /* Service-VLAN for QinQ/802.1ad provider bridges */ - svlan_tagh = hashinit(TAG_HASH_SIZE, M_DEVBUF, M_NOWAIT, - &svlan_tagmask); + svlan_tagh = mallocarray(TAG_HASH_SIZE, sizeof(*svlan_tagh), + M_DEVBUF, M_NOWAIT); if (svlan_tagh == NULL) panic("vlanattach: hashinit"); if_clone_attach(&svlan_cloner); @@ -125,7 +132,8 @@ vlan_clone_create(struct if_clone *ifc, struct ifvlan *ifv; struct ifnet *ifp; - if ((ifv = malloc(sizeof(*ifv), M_DEVBUF, M_NOWAIT|M_ZERO)) == NULL) + ifv = malloc(sizeof(*ifv), M_DEVBUF, M_NOWAIT|M_ZERO); + if (ifv == NULL) return (ENOMEM); LIST_INIT(&ifv->vlan_mc_listhead); @@ -142,6 +150,8 @@ vlan_clone_create(struct if_clone *ifc, else ifv->ifv_type = ETHERTYPE_VLAN; + ifv->ifv_refs = 1; + ifp->if_start = vlan_start; ifp->if_ioctl = vlan_ioctl; IFQ_SET_MAXLEN(&ifp->if_snd, 1); @@ -153,15 +163,46 @@ vlan_clone_create(struct if_clone *ifc, return (0); } +void +vlan_ref(void *null, void *v) +{ + struct ifvlan *ifv = v; + + atomic_inc_int(&ifv->ifv_refs); +} + +void +vlan_unref(void *null, void *v) +{ + struct ifvlan *ifv = v; + + if (atomic_dec_int_nv(&ifv->ifv_refs) == 0) + wakeup(&ifv->ifv_refs); +} + int vlan_clone_destroy(struct ifnet *ifp) { struct ifvlan *ifv = ifp->if_softc; + struct sleep_state sls; + u_int refs; vlan_unconfig(ifp, NULL); ether_ifdetach(ifp); if_detach(ifp); + + refs = atomic_dec_int_nv(&ifv->ifv_refs); + while (refs) { + sleep_setup(&sls, &ifv->ifv_refs, PWAIT, "vlandel"); + + membar_consumer(); + refs = ifv->ifv_refs; + + sleep_finish(&sls, refs); + } + free(ifv, M_DEVBUF, sizeof(*ifv)); + return (0); } @@ -260,7 +301,8 @@ vlan_input(struct ifnet *ifp, struct mbu struct ifvlan *ifv; struct ether_vlan_header *evl; struct ether_header *eh; - struct vlan_taghash *tagh; + struct srpl *tagh, *list; + struct srpl_iter i; u_int tag; struct mbuf_list ml = MBUF_LIST_INITIALIZER(); u_int16_t etype; @@ -294,7 +336,8 @@ vlan_input(struct ifnet *ifp, struct mbu if (m->m_pkthdr.pf.prio <= 1) m->m_pkthdr.pf.prio = !m->m_pkthdr.pf.prio; - LIST_FOREACH(ifv, &tagh[TAG_HASH(tag)], ifv_list) { + list = &tagh[TAG_HASH(tag)]; + SRPL_FOREACH(ifv, list, &i, ifv_list) { if (ifp == ifv->ifv_p && tag == ifv->ifv_tag && etype == ifv->ifv_type) break; @@ -302,15 +345,12 @@ vlan_input(struct ifnet *ifp, struct mbu if (ifv == NULL) { ifp->if_noproto++; - m_freem(m); - return (1); + goto drop; } if ((ifv->ifv_if.if_flags & (IFF_UP|IFF_RUNNING)) != - (IFF_UP|IFF_RUNNING)) { - m_freem(m); - return (1); - } + (IFF_UP|IFF_RUNNING)) + goto drop; /* * Drop promiscuously received packets if we are not in @@ -320,10 +360,8 @@ vlan_input(struct ifnet *ifp, struct mbu (ifp->if_flags & IFF_PROMISC) && (ifv->ifv_if.if_flags & IFF_PROMISC) == 0) { if (bcmp(&ifv->ifv_ac.ac_enaddr, eh->ether_dhost, - ETHER_ADDR_LEN)) { - m_freem(m); - return (1); - } + ETHER_ADDR_LEN)) + goto drop; } /* @@ -341,6 +379,12 @@ vlan_input(struct ifnet *ifp, struct mbu ml_enqueue(&ml, m); if_input(&ifv->ifv_if, &ml); + SRPL_LEAVE(&i, ifv); + return (1); + +drop: + SRPL_LEAVE(&i, ifv); + m_freem(m); return (1); } @@ -348,7 +392,7 @@ int vlan_config(struct ifvlan *ifv, struct ifnet *p, u_int16_t tag) { struct sockaddr_dl *sdl1, *sdl2; - struct vlan_taghash *tagh; + struct srpl *tagh, *list; u_int flags; int s; @@ -433,16 +477,19 @@ vlan_config(struct ifvlan *ifv, struct i vlan_vlandev_state(ifv); - tagh = ifv->ifv_type == ETHERTYPE_QINQ ? svlan_tagh : vlan_tagh; - s = splnet(); /* Change input handler of the physical interface. */ if (++ifv->ifv_ifih->ifih_refcnt == 1) SLIST_INSERT_HEAD(&p->if_inputs, ifv->ifv_ifih, ifih_next); - - LIST_INSERT_HEAD(&tagh[TAG_HASH(tag)], ifv, ifv_list); splx(s); + tagh = ifv->ifv_type == ETHERTYPE_QINQ ? svlan_tagh : vlan_tagh; + list = &tagh[TAG_HASH(tag)]; + + rw_enter_write(&vlan_tagh_lk); + SRPL_INSERT_HEAD_LOCKED(&vlan_tagh_rc, list, ifv, ifv_list); + rw_exit_write(&vlan_tagh_lk); + return (0); } @@ -451,6 +498,7 @@ vlan_unconfig(struct ifnet *ifp, struct { struct sockaddr_dl *sdl; struct ifvlan *ifv; + struct srpl *tagh, *list; struct ifnet *p; int s; @@ -464,9 +512,14 @@ vlan_unconfig(struct ifnet *ifp, struct vlan_set_promisc(ifp); } - s = splnet(); - LIST_REMOVE(ifv, ifv_list); + tagh = ifv->ifv_type == ETHERTYPE_QINQ ? svlan_tagh : vlan_tagh; + list = &tagh[TAG_HASH(ifv->ifv_tag)]; + rw_enter_write(&vlan_tagh_lk); + SRPL_REMOVE_LOCKED(&vlan_tagh_rc, list, ifv, ifvlan, ifv_list); + rw_exit_write(&vlan_tagh_lk); + + s = splnet(); /* Restore previous input handler. */ if (--ifv->ifv_ifih->ifih_refcnt == 0) { SLIST_REMOVE(&p->if_inputs, ifv->ifv_ifih, ifih, ifih_next); Index: if_vlan_var.h =================================================================== RCS file: /cvs/src/sys/net/if_vlan_var.h,v retrieving revision 1.26 diff -u -p -r1.26 if_vlan_var.h --- if_vlan_var.h 20 May 2015 08:54:37 -0000 1.26 +++ if_vlan_var.h 21 Aug 2015 06:06:59 -0000 @@ -83,8 +83,9 @@ struct ifvlan { u_int16_t ifvm_type; /* non-standard ethertype or 0x8100 */ } ifv_mib; LIST_HEAD(__vlan_mchead, vlan_mc_entry) vlan_mc_listhead; - LIST_ENTRY(ifvlan) ifv_list; + struct srpl_entry ifv_list; int ifv_flags; + u_int ifv_refs; void *lh_cookie; void *dh_cookie; struct ifih *ifv_ifih;