| 378 | } |
| 379 | |
| 380 | static int |
| 381 | vlan_inshash(struct ifvlantrunk *trunk, struct ifvlan *ifv) |
| 382 | { |
| 383 | int i, b; |
| 384 | struct ifvlan *ifv2; |
| 385 | |
| 386 | VLAN_XLOCK_ASSERT(); |
| 387 | KASSERT(trunk->hwidth > 0, ("%s: hwidth not positive", __func__)); |
| 388 | |
| 389 | b = 1 << trunk->hwidth; |
| 390 | i = HASH(ifv->ifv_vid, trunk->hmask); |
| 391 | CK_SLIST_FOREACH(ifv2, &trunk->hash[i], ifv_list) |
| 392 | if (ifv->ifv_vid == ifv2->ifv_vid) |
| 393 | return (EEXIST); |
| 394 | |
| 395 | /* |
| 396 | * Grow the hash when the number of vlans exceeds half of the number of |
| 397 | * hash buckets squared. This will make the average linked-list length |
| 398 | * buckets/2. |
| 399 | */ |
| 400 | if (trunk->refcnt > (b * b) / 2) { |
| 401 | vlan_growhash(trunk, 1); |
| 402 | i = HASH(ifv->ifv_vid, trunk->hmask); |
| 403 | } |
| 404 | CK_SLIST_INSERT_HEAD(&trunk->hash[i], ifv, ifv_list); |
| 405 | trunk->refcnt++; |
| 406 | |
| 407 | return (0); |
| 408 | } |
| 409 | |
| 410 | static int |
| 411 | vlan_remhash(struct ifvlantrunk *trunk, struct ifvlan *ifv) |
no test coverage detected