MCPcopy Create free account
hub / github.com/F-Stack/f-stack / vlan_inshash

Function vlan_inshash

freebsd/net/if_vlan.c:380–408  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

378}
379
380static int
381vlan_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
410static int
411vlan_remhash(struct ifvlantrunk *trunk, struct ifvlan *ifv)

Callers 1

vlan_configFunction · 0.85

Calls 1

vlan_growhashFunction · 0.85

Tested by

no test coverage detected