staticstruct hlist_head *pubkey_bucket(struct pubkey_hashtable *table, const u8 pubkey[NOISE_PUBLIC_KEY_LEN])
{ /* siphash gives us a secure 64bit number based on a random key. Since *thebitsareuniformlydistributed,wecanthenmaskofftogetthe *bitsweneed.
*/ const u64 hash = siphash(pubkey, NOISE_PUBLIC_KEY_LEN, &table->key);
staticstruct hlist_head *index_bucket(struct index_hashtable *table, const __le32 index)
{ /* Since the indices are random and thus all bits are uniformly *distributed,wecanfinditsbucketsimplybymasking.
*/ return &table->hashtable[(__force u32)index &
(HASH_SIZE(table->hashtable) - 1)];
}
search_unused_slot: /* First we try to find an unused slot, randomly, while unlocked. */
entry->index = (__force __le32)get_random_u32();
hlist_for_each_entry_rcu_bh(existing_entry,
index_bucket(table, entry->index),
index_hash) { if (existing_entry->index == entry->index) /* If it's already in use, we continue searching. */ goto search_unused_slot;
}
/* Once we've found an unused slot, we lock it, and then double-check *thatnobodyelsestoleitfromus.
*/
spin_lock_bh(&table->lock);
hlist_for_each_entry_rcu_bh(existing_entry,
index_bucket(table, entry->index),
index_hash) { if (existing_entry->index == entry->index) {
spin_unlock_bh(&table->lock); /* If it was stolen, we start over. */ goto search_unused_slot;
}
} /* Otherwise, we know we have it exclusively (since we're locked), *soweinsert.
*/
hlist_add_head_rcu(&entry->index_hash,
index_bucket(table, entry->index));
spin_unlock_bh(&table->lock);
/* Calling init here NULLs out index_hash, and in fact after this *functionreturns,it'stheoreticallypossibleforthistoget *reinsertedelsewhere.ThatmeanstheRCUlookupbelowmighteither *terminateearlyorjumpbetweenbuckets,inwhichcasethepacket *simplygetsdropped,whichisn'tterrible.
*/
INIT_HLIST_NODE(&old->index_hash);
out:
spin_unlock_bh(&table->lock); return ret;
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.