Lines Matching defs:trunk

85 	struct	ifnet   *parent;	/* parent interface of this trunk */
157 * We also have a per-trunk rwlock, that is locked shared on packet
171 #define TRUNK_LOCK_INIT(trunk) rw_init(&(trunk)->rw, VLANNAME)
172 #define TRUNK_LOCK_DESTROY(trunk) rw_destroy(&(trunk)->rw)
173 #define TRUNK_LOCK(trunk) rw_wlock(&(trunk)->rw)
174 #define TRUNK_UNLOCK(trunk) rw_wunlock(&(trunk)->rw)
175 #define TRUNK_LOCK_ASSERT(trunk) rw_assert(&(trunk)->rw, RA_WLOCKED)
176 #define TRUNK_RLOCK(trunk) rw_rlock(&(trunk)->rw)
177 #define TRUNK_RUNLOCK(trunk) rw_runlock(&(trunk)->rw)
178 #define TRUNK_LOCK_RASSERT(trunk) rw_assert(&(trunk)->rw, RA_RLOCKED)
181 static void vlan_inithash(struct ifvlantrunk *trunk);
182 static void vlan_freehash(struct ifvlantrunk *trunk);
183 static int vlan_inshash(struct ifvlantrunk *trunk, struct ifvlan *ifv);
184 static int vlan_remhash(struct ifvlantrunk *trunk, struct ifvlan *ifv);
185 static void vlan_growhash(struct ifvlantrunk *trunk, int howmuch);
186 static __inline struct ifvlan * vlan_gethash(struct ifvlantrunk *trunk,
189 static void trunk_destroy(struct ifvlantrunk *trunk);
228 vlan_inithash(struct ifvlantrunk *trunk)
233 * The trunk must not be locked here since we call malloc(M_WAITOK).
234 * It is OK in case this function is called before the trunk struct
238 KASSERT(trunk->hwidth == 0 && trunk->hash == NULL,
241 trunk->hwidth = VLAN_DEF_HWIDTH;
242 n = 1 << trunk->hwidth;
243 trunk->hmask = n - 1;
244 trunk->hash = malloc(sizeof(struct ifvlanhead) * n, M_VLAN, M_WAITOK);
246 LIST_INIT(&trunk->hash[i]);
250 vlan_freehash(struct ifvlantrunk *trunk)
255 KASSERT(trunk->hwidth > 0, ("%s: hwidth not positive", __func__));
256 for (i = 0; i < (1 << trunk->hwidth); i++)
257 KASSERT(LIST_EMPTY(&trunk->hash[i]),
260 free(trunk->hash, M_VLAN);
261 trunk->hash = NULL;
262 trunk->hwidth = trunk->hmask = 0;
266 vlan_inshash(struct ifvlantrunk *trunk, struct ifvlan *ifv)
271 TRUNK_LOCK_ASSERT(trunk);
272 KASSERT(trunk->hwidth > 0, ("%s: hwidth not positive", __func__));
274 b = 1 << trunk->hwidth;
275 i = HASH(ifv->ifv_tag, trunk->hmask);
276 LIST_FOREACH(ifv2, &trunk->hash[i], ifv_list)
285 if (trunk->refcnt > (b * b) / 2) {
286 vlan_growhash(trunk, 1);
287 i = HASH(ifv->ifv_tag, trunk->hmask);
289 LIST_INSERT_HEAD(&trunk->hash[i], ifv, ifv_list);
290 trunk->refcnt++;
296 vlan_remhash(struct ifvlantrunk *trunk, struct ifvlan *ifv)
301 TRUNK_LOCK_ASSERT(trunk);
302 KASSERT(trunk->hwidth > 0, ("%s: hwidth not positive", __func__));
304 b = 1 << trunk->hwidth;
305 i = HASH(ifv->ifv_tag, trunk->hmask);
306 LIST_FOREACH(ifv2, &trunk->hash[i], ifv_list)
308 trunk->refcnt--;
310 if (trunk->refcnt < (b * b) / 2)
311 vlan_growhash(trunk, -1);
323 vlan_growhash(struct ifvlantrunk *trunk, int howmuch)
329 TRUNK_LOCK_ASSERT(trunk);
330 KASSERT(trunk->hwidth > 0, ("%s: hwidth not positive", __func__));
338 hwidth2 = trunk->hwidth + howmuch;
339 n = 1 << trunk->hwidth;
345 /* M_NOWAIT because we're called with trunk mutex held */
355 while ((ifv = LIST_FIRST(&trunk->hash[i])) != NULL) {
360 free(trunk->hash, M_VLAN);
361 trunk->hash = hash2;
362 trunk->hwidth = hwidth2;
363 trunk->hmask = n2 - 1;
366 if_printf(trunk->parent,
371 vlan_gethash(struct ifvlantrunk *trunk, uint16_t tag)
375 TRUNK_LOCK_RASSERT(trunk);
377 LIST_FOREACH(ifv, &trunk->hash[HASH(tag, trunk->hmask)], ifv_list)
386 vlan_dumphash(struct ifvlantrunk *trunk)
391 for (i = 0; i < (1 << trunk->hwidth); i++) {
393 LIST_FOREACH(ifv, &trunk->hash[i], ifv_list)
402 vlan_gethash(struct ifvlantrunk *trunk, uint16_t tag)
405 return trunk->vlans[tag];
409 vlan_inshash(struct ifvlantrunk *trunk, struct ifvlan *ifv)
412 if (trunk->vlans[ifv->ifv_tag] != NULL)
414 trunk->vlans[ifv->ifv_tag] = ifv;
415 trunk->refcnt++;
421 vlan_remhash(struct ifvlantrunk *trunk, struct ifvlan *ifv)
424 trunk->vlans[ifv->ifv_tag] = NULL;
425 trunk->refcnt--;
431 vlan_freehash(struct ifvlantrunk *trunk)
436 vlan_inithash(struct ifvlantrunk *trunk)
443 trunk_destroy(struct ifvlantrunk *trunk)
447 TRUNK_LOCK(trunk);
448 vlan_freehash(trunk);
449 trunk->parent->if_vlantrunk = NULL;
450 TRUNK_UNLOCK(trunk);
451 TRUNK_LOCK_DESTROY(trunk);
452 free(trunk, M_VLAN);
527 * Check if it's a trunk interface first of all
535 * OK, it's a trunk. Loop over and change all vlan's lladdrs on it.
556 * pointers or whatever if a trunk is ripped from under us, e.g.,
567 * Check if it's a trunk interface first of all
579 * OK, it's a trunk. Loop over and detach all vlan's on it.
580 * Check trunk pointer after each vlan_unconfig() as it will
596 goto restart; /* trunk->hwidth can change */
607 * Return the trunk device for a virtual interface.
677 struct ifvlantrunk *trunk;
680 trunk = ifp->if_vlantrunk;
681 if (trunk == NULL)
684 TRUNK_RLOCK(trunk);
685 ifv = vlan_gethash(trunk, tag);
688 TRUNK_RUNLOCK(trunk);
1112 struct ifvlantrunk *trunk = ifp->if_vlantrunk;
1116 KASSERT(trunk != NULL, ("%s: no trunk", __func__));
1163 TRUNK_RLOCK(trunk);
1164 ifv = vlan_gethash(trunk, tag);
1166 TRUNK_RUNLOCK(trunk);
1171 TRUNK_RUNLOCK(trunk);
1183 struct ifvlantrunk *trunk;
1199 trunk = malloc(sizeof(struct ifvlantrunk),
1201 vlan_inithash(trunk);
1205 vlan_freehash(trunk);
1206 free(trunk, M_VLAN);
1209 TRUNK_LOCK_INIT(trunk);
1210 TRUNK_LOCK(trunk);
1211 p->if_vlantrunk = trunk;
1212 trunk->parent = p;
1216 trunk = p->if_vlantrunk;
1217 TRUNK_LOCK(trunk);
1221 error = vlan_inshash(trunk, ifv);
1251 ifv->ifv_trunk = trunk;
1296 TRUNK_UNLOCK(trunk);
1316 struct ifvlantrunk *trunk;
1325 trunk = ifv->ifv_trunk;
1328 if (trunk != NULL) {
1330 TRUNK_LOCK(trunk);
1331 parent = trunk->parent;
1360 vlan_remhash(trunk, ifv);
1366 if (trunk->refcnt == 0) {
1367 trunk->parent->if_vlantrunk = NULL;
1370 * vlan_input() and is now blocked on the trunk
1375 TRUNK_UNLOCK(trunk);
1376 trunk_destroy(trunk);
1378 TRUNK_UNLOCK(trunk);
1453 struct ifvlantrunk *trunk = ifp->if_vlantrunk;
1457 TRUNK_LOCK(trunk);
1460 if (trunk->vlans[i] != NULL) {
1461 ifv = trunk->vlans[i];
1463 for (i = 0; i < (1 << trunk->hwidth); i++)
1464 LIST_FOREACH(ifv, &trunk->hash[i], ifv_list) {
1466 ifv->ifv_ifp->if_baudrate = trunk->parent->if_baudrate;
1468 trunk->parent->if_link_state);
1470 TRUNK_UNLOCK(trunk);
1536 struct ifvlantrunk *trunk = ifp->if_vlantrunk;
1540 TRUNK_LOCK(trunk);
1543 if (trunk->vlans[i] != NULL) {
1544 ifv = trunk->vlans[i];
1546 for (i = 0; i < (1 << trunk->hwidth); i++) {
1547 LIST_FOREACH(ifv, &trunk->hash[i], ifv_list)
1551 TRUNK_UNLOCK(trunk);