* Add a new host entry to the table. This assumes the host doesn't * already exist in the table. Returns 1 on success, 0 if there * was a memory allocation failure. */
| 895 | * was a memory allocation failure. |
| 896 | */ |
| 897 | static int |
| 898 | ng_bridge_put(priv_p priv, const u_char *addr, link_p link) |
| 899 | { |
| 900 | const int bucket = HASH(addr, priv->hashMask); |
| 901 | struct ng_bridge_hent *hent; |
| 902 | |
| 903 | #ifdef INVARIANTS |
| 904 | /* Assert that entry does not already exist in hashtable */ |
| 905 | SLIST_FOREACH(hent, &priv->tab[bucket], next) { |
| 906 | KASSERT(!ETHER_EQUAL(hent->host.addr, addr), |
| 907 | ("%s: entry %6D exists in table", __func__, addr, ":")); |
| 908 | } |
| 909 | #endif |
| 910 | |
| 911 | /* Allocate and initialize new hashtable entry */ |
| 912 | hent = malloc(sizeof(*hent), M_NETGRAPH_BRIDGE, M_NOWAIT); |
| 913 | if (hent == NULL) |
| 914 | return (0); |
| 915 | bcopy(addr, hent->host.addr, ETHER_ADDR_LEN); |
| 916 | hent->host.link = link; |
| 917 | hent->host.staleness = 0; |
| 918 | hent->host.age = 0; |
| 919 | |
| 920 | /* Add new element to hash bucket */ |
| 921 | SLIST_INSERT_HEAD(&priv->tab[bucket], hent, next); |
| 922 | priv->numHosts++; |
| 923 | |
| 924 | /* Resize table if necessary */ |
| 925 | ng_bridge_rehash(priv); |
| 926 | return (1); |
| 927 | } |
| 928 | |
| 929 | /* |
| 930 | * Resize the hash table. We try to maintain the number of buckets |
no test coverage detected