Merge tag 'block-5.11-2021-01-10' of git://git.kernel.dk/linux-block
[linux/fpc-iii.git] / drivers / net / wireguard / peerlookup.h
blobced81179768006c1858fca52d8dc4990c18d8f75
1 /* SPDX-License-Identifier: GPL-2.0 */
2 /*
3 * Copyright (C) 2015-2019 Jason A. Donenfeld <Jason@zx2c4.com>. All Rights Reserved.
4 */
6 #ifndef _WG_PEERLOOKUP_H
7 #define _WG_PEERLOOKUP_H
9 #include "messages.h"
11 #include <linux/hashtable.h>
12 #include <linux/mutex.h>
13 #include <linux/siphash.h>
15 struct wg_peer;
17 struct pubkey_hashtable {
18 /* TODO: move to rhashtable */
19 DECLARE_HASHTABLE(hashtable, 11);
20 siphash_key_t key;
21 struct mutex lock;
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);
29 struct wg_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);
36 spinlock_t lock;
39 enum index_hashtable_type {
40 INDEX_HASHTABLE_HANDSHAKE = 1U << 0,
41 INDEX_HASHTABLE_KEYPAIR = 1U << 1
44 struct index_hashtable_entry {
45 struct wg_peer *peer;
46 struct hlist_node index_hash;
47 enum index_hashtable_type type;
48 __le32 index;
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 */