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