1 /* SPDX-License-Identifier: GPL-2.0 */
6 #ifndef _WG_PEERLOOKUP_H
7 #define _WG_PEERLOOKUP_H
11 #include <linux/hashtable.h>
12 #include <linux/mutex.h>
13 #include <linux/siphash.h>
17 struct pubkey_hashtable {
18 /* TODO: move to rhashtable */
19 DECLARE_HASHTABLE(hashtable, 11);
24 struct pubkey_hashtable *wg_pubkey_hashtable_alloc(void);
25 void wg_pubkey_hashtable_add(struct pubkey_hashtable *table,
26 struct wg_peer *peer);
27 void wg_pubkey_hashtable_remove(struct pubkey_hashtable *table,
28 struct wg_peer *peer);
30 wg_pubkey_hashtable_lookup(struct pubkey_hashtable *table,
31 const u8 pubkey[NOISE_PUBLIC_KEY_LEN]);
33 struct index_hashtable {
34 /* TODO: move to rhashtable */
35 DECLARE_HASHTABLE(hashtable, 13);
39 enum index_hashtable_type {
40 INDEX_HASHTABLE_HANDSHAKE = 1U << 0,
41 INDEX_HASHTABLE_KEYPAIR = 1U << 1
44 struct index_hashtable_entry {
46 struct hlist_node index_hash;
47 enum index_hashtable_type type;
51 struct index_hashtable *wg_index_hashtable_alloc(void);
52 __le32 wg_index_hashtable_insert(struct index_hashtable *table,
53 struct index_hashtable_entry *entry);
54 bool wg_index_hashtable_replace(struct index_hashtable *table,
55 struct index_hashtable_entry *old,
56 struct index_hashtable_entry *new);
57 void wg_index_hashtable_remove(struct index_hashtable *table,
58 struct index_hashtable_entry *entry);
59 struct index_hashtable_entry *
60 wg_index_hashtable_lookup(struct index_hashtable *table,
61 const enum index_hashtable_type type_mask,
62 const __le32 index, struct wg_peer **peer);
64 #endif /* _WG_PEERLOOKUP_H */