diff options
Diffstat (limited to 'src/hashtables.c')
-rw-r--r-- | src/hashtables.c | 16 |
1 files changed, 14 insertions, 2 deletions
diff --git a/src/hashtables.c b/src/hashtables.c index 18cac91..8aedc17 100644 --- a/src/hashtables.c +++ b/src/hashtables.c @@ -19,11 +19,17 @@ static struct hlist_head *pubkey_bucket(struct pubkey_hashtable *table, return &table->hashtable[hash & (HASH_SIZE(table->hashtable) - 1)]; } -void wg_pubkey_hashtable_init(struct pubkey_hashtable *table) +struct pubkey_hashtable *wg_pubkey_hashtable_alloc(void) { + struct pubkey_hashtable *table = kvmalloc(sizeof(*table), GFP_KERNEL); + + if (!table) + return NULL; + get_random_bytes(&table->key, sizeof(table->key)); hash_init(table->hashtable); mutex_init(&table->lock); + return table; } void wg_pubkey_hashtable_add(struct pubkey_hashtable *table, @@ -74,10 +80,16 @@ static struct hlist_head *index_bucket(struct index_hashtable *table, (HASH_SIZE(table->hashtable) - 1)]; } -void wg_index_hashtable_init(struct index_hashtable *table) +struct index_hashtable *wg_index_hashtable_alloc(void) { + struct index_hashtable *table = kvmalloc(sizeof(*table), GFP_KERNEL); + + if (!table) + return NULL; + hash_init(table->hashtable); spin_lock_init(&table->lock); + return table; } /* At the moment, we limit ourselves to 2^20 total peers, which generally might |