• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* SPDX-License-Identifier: GPL-2.0 */
2 /*
3  * Copyright (C) 2015-2019 Jason A. Donenfeld <Jason@zx2c4.com>. All Rights Reserved.
4  */
5 
6 #ifndef _WG_DEVICE_H
7 #define _WG_DEVICE_H
8 
9 #include "noise.h"
10 #include "allowedips.h"
11 #include "peerlookup.h"
12 #include "cookie.h"
13 
14 #include <linux/types.h>
15 #include <linux/netdevice.h>
16 #include <linux/workqueue.h>
17 #include <linux/mutex.h>
18 #include <linux/net.h>
19 #include <linux/ptr_ring.h>
20 
21 struct wg_device;
22 
23 struct multicore_worker {
24 	void *ptr;
25 	struct work_struct work;
26 };
27 
28 struct crypt_queue {
29 	struct ptr_ring ring;
30 	struct multicore_worker __percpu *worker;
31 	int last_cpu;
32 };
33 
34 struct prev_queue {
35 	struct sk_buff *head, *tail, *peeked;
36 	struct { struct sk_buff *next, *prev; } empty; // Match first 2 members of struct sk_buff.
37 	atomic_t count;
38 };
39 
40 struct wg_device {
41 	struct net_device *dev;
42 	struct crypt_queue encrypt_queue, decrypt_queue, handshake_queue;
43 	struct sock __rcu *sock4, *sock6;
44 	struct net __rcu *creating_net;
45 	struct noise_static_identity static_identity;
46 	struct workqueue_struct *packet_crypt_wq,*handshake_receive_wq, *handshake_send_wq;
47 	struct cookie_checker cookie_checker;
48 	struct pubkey_hashtable *peer_hashtable;
49 	struct index_hashtable *index_hashtable;
50 	struct allowedips peer_allowedips;
51 	struct mutex device_update_lock, socket_update_lock;
52 	struct list_head device_list, peer_list;
53 	atomic_t handshake_queue_len;
54 	unsigned int num_peers, device_update_gen;
55 	u32 fwmark;
56 	u16 incoming_port;
57 };
58 
59 int wg_device_init(void);
60 void wg_device_uninit(void);
61 
62 #endif /* _WG_DEVICE_H */
63