diff options
-rw-r--r-- | src/hashtables.c | 7 | ||||
-rw-r--r-- | src/hashtables.h | 1 | ||||
-rw-r--r-- | src/wireguard.h | 4 |
3 files changed, 7 insertions, 5 deletions
diff --git a/src/hashtables.c b/src/hashtables.c index 965605b..2fb4322 100644 --- a/src/hashtables.c +++ b/src/hashtables.c @@ -61,7 +61,6 @@ static inline struct hlist_head *index_bucket(struct index_hashtable *table, con void index_hashtable_init(struct index_hashtable *table) { get_random_bytes(table->key, SIPHASH24_KEY_LEN); - atomic64_set(&table->counter, 0); hash_init(table->hashtable); spin_lock_init(&table->lock); } @@ -69,7 +68,7 @@ void index_hashtable_init(struct index_hashtable *table) __le32 index_hashtable_insert(struct index_hashtable *table, struct index_hashtable_entry *entry) { struct index_hashtable_entry *existing_entry; - uint64_t counter; + uint64_t rand; spin_lock(&table->lock); hlist_del_init_rcu(&entry->index_hash); @@ -79,8 +78,8 @@ __le32 index_hashtable_insert(struct index_hashtable *table, struct index_hashta search_unused_slot: /* First we try to find an unused slot, randomly, while unlocked. */ - counter = atomic64_inc_return(&table->counter); - entry->index = (__force __le32)siphash24((uint8_t *)&counter, sizeof(counter), table->key); + rand = get_random_long(); + entry->index = (__force __le32)siphash24((uint8_t *)&rand, sizeof(rand), table->key); hlist_for_each_entry_rcu(existing_entry, index_bucket(table, entry->index), index_hash) { if (existing_entry->index == entry->index) goto search_unused_slot; /* If it's already in use, we continue searching. */ diff --git a/src/hashtables.h b/src/hashtables.h index d51c0d8..89845f6 100644 --- a/src/hashtables.h +++ b/src/hashtables.h @@ -21,7 +21,6 @@ struct wireguard_peer *pubkey_hashtable_lookup(struct pubkey_hashtable *table, c struct index_hashtable { DECLARE_HASHTABLE(hashtable, 10); uint8_t key[SIPHASH24_KEY_LEN]; - atomic64_t counter; spinlock_t lock; }; struct index_hashtable_entry; diff --git a/src/wireguard.h b/src/wireguard.h index 5c83ab6..2985323 100644 --- a/src/wireguard.h +++ b/src/wireguard.h @@ -36,6 +36,10 @@ #define net_dbg_ratelimited(fmt, ...) do { if (0) no_printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__); } while (0) #endif +#if LINUX_VERSION_CODE < KERNEL_VERSION(4, 5, 0) +#define get_random_long() (((u64)get_random_int() << 32) | get_random_int()) +#endif + struct wireguard_device { struct sock __rcu *sock4, *sock6; u16 incoming_port; |