Lines Matching defs:trunk
100 struct ifnet *parent; /* parent interface of this trunk */
128 * This macro provides a facility to iterate over every vlan on a trunk with
145 * This macro provides a facility to iterate over every vlan on a trunk while
146 * also modifying the number of vlans on the trunk. The iteration continues
147 * until some condition is met or there are no more vlans on the trunk.
161 * current position. If acting on the touched element causes the trunk to be
260 * We also have a per-trunk mutex that should be acquired when changing
263 #define TRUNK_LOCK_INIT(trunk) mtx_init(&(trunk)->lock, vlanname, NULL, MTX_DEF)
264 #define TRUNK_LOCK_DESTROY(trunk) mtx_destroy(&(trunk)->lock)
265 #define TRUNK_WLOCK(trunk) mtx_lock(&(trunk)->lock)
266 #define TRUNK_WUNLOCK(trunk) mtx_unlock(&(trunk)->lock)
267 #define TRUNK_WLOCK_ASSERT(trunk) mtx_assert(&(trunk)->lock, MA_OWNED);
276 static void vlan_inithash(struct ifvlantrunk *trunk);
277 static void vlan_freehash(struct ifvlantrunk *trunk);
278 static int vlan_inshash(struct ifvlantrunk *trunk, struct ifvlan *ifv);
279 static int vlan_remhash(struct ifvlantrunk *trunk, struct ifvlan *ifv);
280 static void vlan_growhash(struct ifvlantrunk *trunk, int howmuch);
281 static __inline struct ifvlan * vlan_gethash(struct ifvlantrunk *trunk,
284 static void trunk_destroy(struct ifvlantrunk *trunk);
394 vlan_inithash(struct ifvlantrunk *trunk)
399 * The trunk must not be locked here since we call malloc(M_WAITOK).
400 * It is OK in case this function is called before the trunk struct
404 KASSERT(trunk->hwidth == 0 && trunk->hash == NULL,
407 trunk->hwidth = VLAN_DEF_HWIDTH;
408 n = 1 << trunk->hwidth;
409 trunk->hmask = n - 1;
410 trunk->hash = malloc(sizeof(struct ifvlanhead) * n, M_VLAN, M_WAITOK);
412 CK_SLIST_INIT(&trunk->hash[i]);
416 vlan_freehash(struct ifvlantrunk *trunk)
421 KASSERT(trunk->hwidth > 0, ("%s: hwidth not positive", __func__));
422 for (i = 0; i < (1 << trunk->hwidth); i++)
423 KASSERT(CK_SLIST_EMPTY(&trunk->hash[i]),
426 free(trunk->hash, M_VLAN);
427 trunk->hash = NULL;
428 trunk->hwidth = trunk->hmask = 0;
432 vlan_inshash(struct ifvlantrunk *trunk, struct ifvlan *ifv)
438 KASSERT(trunk->hwidth > 0, ("%s: hwidth not positive", __func__));
440 b = 1 << trunk->hwidth;
441 i = HASH(ifv->ifv_vid, trunk->hmask);
442 CK_SLIST_FOREACH(ifv2, &trunk->hash[i], ifv_list)
451 if (trunk->refcnt > (b * b) / 2) {
452 vlan_growhash(trunk, 1);
453 i = HASH(ifv->ifv_vid, trunk->hmask);
455 CK_SLIST_INSERT_HEAD(&trunk->hash[i], ifv, ifv_list);
456 trunk->refcnt++;
462 vlan_remhash(struct ifvlantrunk *trunk, struct ifvlan *ifv)
468 KASSERT(trunk->hwidth > 0, ("%s: hwidth not positive", __func__));
470 b = 1 << (trunk->hwidth - 1);
471 i = HASH(ifv->ifv_vid, trunk->hmask);
472 CK_SLIST_FOREACH(ifv2, &trunk->hash[i], ifv_list)
474 trunk->refcnt--;
475 CK_SLIST_REMOVE(&trunk->hash[i], ifv2, ifvlan, ifv_list);
476 if (trunk->refcnt < (b * b) / 2)
477 vlan_growhash(trunk, -1);
489 vlan_growhash(struct ifvlantrunk *trunk, int howmuch)
496 KASSERT(trunk->hwidth > 0, ("%s: hwidth not positive", __func__));
504 hwidth2 = trunk->hwidth + howmuch;
505 n = 1 << trunk->hwidth;
515 while ((ifv = CK_SLIST_FIRST(&trunk->hash[i])) != NULL) {
516 CK_SLIST_REMOVE(&trunk->hash[i], ifv, ifvlan, ifv_list);
521 free(trunk->hash, M_VLAN);
522 trunk->hash = hash2;
523 trunk->hwidth = hwidth2;
524 trunk->hmask = n2 - 1;
527 if_printf(trunk->parent,
532 vlan_gethash(struct ifvlantrunk *trunk, uint16_t vid)
538 CK_SLIST_FOREACH(ifv, &trunk->hash[HASH(vid, trunk->hmask)], ifv_list)
547 vlan_dumphash(struct ifvlantrunk *trunk)
552 for (i = 0; i < (1 << trunk->hwidth); i++) {
554 CK_SLIST_FOREACH(ifv, &trunk->hash[i], ifv_list)
563 vlan_gethash(struct ifvlantrunk *trunk, uint16_t vid)
566 return trunk->vlans[vid];
570 vlan_inshash(struct ifvlantrunk *trunk, struct ifvlan *ifv)
573 if (trunk->vlans[ifv->ifv_vid] != NULL)
575 trunk->vlans[ifv->ifv_vid] = ifv;
576 trunk->refcnt++;
582 vlan_remhash(struct ifvlantrunk *trunk, struct ifvlan *ifv)
585 trunk->vlans[ifv->ifv_vid] = NULL;
586 trunk->refcnt--;
592 vlan_freehash(struct ifvlantrunk *trunk)
597 vlan_inithash(struct ifvlantrunk *trunk)
604 trunk_destroy(struct ifvlantrunk *trunk)
608 vlan_freehash(trunk);
609 trunk->parent->if_vlantrunk = NULL;
610 TRUNK_LOCK_DESTROY(trunk);
611 if_rele(trunk->parent);
612 free(trunk, M_VLAN);
684 struct ifvlantrunk *trunk;
690 trunk = ifp->if_vlantrunk;
691 if (trunk == NULL) {
696 TRUNK_WLOCK(trunk);
697 VLAN_FOREACH(ifv, trunk) {
700 TRUNK_WUNLOCK(trunk);
715 struct ifvlantrunk *trunk;
720 trunk = ifp->if_vlantrunk;
721 if (trunk == NULL) {
727 * OK, it's a trunk. Loop over and change all vlan's lladdrs on it.
731 TRUNK_WLOCK(trunk);
732 VLAN_FOREACH(ifv, trunk) {
747 TRUNK_WUNLOCK(trunk);
754 * pointers or whatever if a trunk is ripped from under us, e.g.,
762 struct ifvlantrunk *trunk;
768 trunk = ifp->if_vlantrunk;
769 if (trunk == NULL) {
775 * OK, it's a trunk. Loop over and detach all vlan's on it.
776 * Check trunk pointer after each vlan_unconfig() as it will
789 * Return the trunk device for a virtual interface.
876 struct ifvlantrunk *trunk;
881 trunk = ifp->if_vlantrunk;
882 if (trunk == NULL)
885 ifv = vlan_gethash(trunk, vid);
1557 struct ifvlantrunk *trunk;
1564 trunk = ifp->if_vlantrunk;
1565 if (trunk == NULL) {
1617 ifv = vlan_gethash(trunk, vid);
1675 struct ifvlantrunk *trunk;
1697 trunk = ifv->ifv_trunk;
1698 if (trunk->parent != p)
1709 vlan_remhash(trunk, ifv);
1711 error = vlan_inshash(trunk, ifv);
1717 ret = vlan_inshash(trunk, ifv);
1727 trunk = malloc(sizeof(struct ifvlantrunk),
1729 vlan_inithash(trunk);
1730 TRUNK_LOCK_INIT(trunk);
1731 TRUNK_WLOCK(trunk);
1732 p->if_vlantrunk = trunk;
1733 trunk->parent = p;
1734 if_ref(trunk->parent);
1735 TRUNK_WUNLOCK(trunk);
1737 trunk = p->if_vlantrunk;
1742 error = vlan_inshash(trunk, ifv);
1774 ifv->ifv_trunk = trunk;
1860 struct ifvlantrunk *trunk;
1869 trunk = ifv->ifv_trunk;
1872 if (trunk != NULL) {
1873 parent = trunk->parent;
1903 vlan_remhash(trunk, ifv);
1909 if (trunk->refcnt == 0) {
1912 trunk_destroy(trunk);
1989 struct ifvlantrunk *trunk;
1993 trunk = ifp->if_vlantrunk;
1994 if (trunk == NULL) {
1999 TRUNK_WLOCK(trunk);
2000 VLAN_FOREACH(ifv, trunk) {
2001 ifv->ifv_ifp->if_baudrate = trunk->parent->if_baudrate;
2003 trunk->parent->if_link_state);
2005 TRUNK_WUNLOCK(trunk);
2063 if_t trunk;
2066 trunk = vlan_trunkdev(ifp);
2067 if (trunk == NULL)
2069 return (trunk->if_ipsec_accel_m->if_hwassist(trunk, sav,
2224 struct ifvlantrunk *trunk;
2228 trunk = ifp->if_vlantrunk;
2229 if (trunk == NULL) {
2234 VLAN_FOREACH(ifv, trunk)
2249 struct ifvlantrunk *trunk;
2305 trunk = TRUNK(ifv);
2306 if (trunk != NULL) {
2307 TRUNK_WLOCK(trunk);
2315 TRUNK_WUNLOCK(trunk);
2401 trunk = TRUNK(ifv);
2402 if (trunk != NULL)
2440 trunk = TRUNK(ifv);
2441 if (trunk != NULL) {