0001
0002
0003
0004
0005
0006 #ifndef _WG_PEERLOOKUP_H
0007 #define _WG_PEERLOOKUP_H
0008
0009 #include "messages.h"
0010
0011 #include <linux/hashtable.h>
0012 #include <linux/mutex.h>
0013 #include <linux/siphash.h>
0014
0015 struct wg_peer;
0016
0017 struct pubkey_hashtable {
0018
0019 DECLARE_HASHTABLE(hashtable, 11);
0020 siphash_key_t key;
0021 struct mutex lock;
0022 };
0023
0024 struct pubkey_hashtable *wg_pubkey_hashtable_alloc(void);
0025 void wg_pubkey_hashtable_add(struct pubkey_hashtable *table,
0026 struct wg_peer *peer);
0027 void wg_pubkey_hashtable_remove(struct pubkey_hashtable *table,
0028 struct wg_peer *peer);
0029 struct wg_peer *
0030 wg_pubkey_hashtable_lookup(struct pubkey_hashtable *table,
0031 const u8 pubkey[NOISE_PUBLIC_KEY_LEN]);
0032
0033 struct index_hashtable {
0034
0035 DECLARE_HASHTABLE(hashtable, 13);
0036 spinlock_t lock;
0037 };
0038
0039 enum index_hashtable_type {
0040 INDEX_HASHTABLE_HANDSHAKE = 1U << 0,
0041 INDEX_HASHTABLE_KEYPAIR = 1U << 1
0042 };
0043
0044 struct index_hashtable_entry {
0045 struct wg_peer *peer;
0046 struct hlist_node index_hash;
0047 enum index_hashtable_type type;
0048 __le32 index;
0049 };
0050
0051 struct index_hashtable *wg_index_hashtable_alloc(void);
0052 __le32 wg_index_hashtable_insert(struct index_hashtable *table,
0053 struct index_hashtable_entry *entry);
0054 bool wg_index_hashtable_replace(struct index_hashtable *table,
0055 struct index_hashtable_entry *old,
0056 struct index_hashtable_entry *new);
0057 void wg_index_hashtable_remove(struct index_hashtable *table,
0058 struct index_hashtable_entry *entry);
0059 struct index_hashtable_entry *
0060 wg_index_hashtable_lookup(struct index_hashtable *table,
0061 const enum index_hashtable_type type_mask,
0062 const __le32 index, struct wg_peer **peer);
0063
0064 #endif