18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 */
28c2ecf20Sopenharmony_ci/*
38c2ecf20Sopenharmony_ci * Copyright (C) 2015-2019 Jason A. Donenfeld <Jason@zx2c4.com>. All Rights Reserved.
48c2ecf20Sopenharmony_ci */
58c2ecf20Sopenharmony_ci
68c2ecf20Sopenharmony_ci#ifndef _WG_DEVICE_H
78c2ecf20Sopenharmony_ci#define _WG_DEVICE_H
88c2ecf20Sopenharmony_ci
98c2ecf20Sopenharmony_ci#include "noise.h"
108c2ecf20Sopenharmony_ci#include "allowedips.h"
118c2ecf20Sopenharmony_ci#include "peerlookup.h"
128c2ecf20Sopenharmony_ci#include "cookie.h"
138c2ecf20Sopenharmony_ci
148c2ecf20Sopenharmony_ci#include <linux/types.h>
158c2ecf20Sopenharmony_ci#include <linux/netdevice.h>
168c2ecf20Sopenharmony_ci#include <linux/workqueue.h>
178c2ecf20Sopenharmony_ci#include <linux/mutex.h>
188c2ecf20Sopenharmony_ci#include <linux/net.h>
198c2ecf20Sopenharmony_ci#include <linux/ptr_ring.h>
208c2ecf20Sopenharmony_ci
218c2ecf20Sopenharmony_cistruct wg_device;
228c2ecf20Sopenharmony_ci
238c2ecf20Sopenharmony_cistruct multicore_worker {
248c2ecf20Sopenharmony_ci	void *ptr;
258c2ecf20Sopenharmony_ci	struct work_struct work;
268c2ecf20Sopenharmony_ci};
278c2ecf20Sopenharmony_ci
288c2ecf20Sopenharmony_cistruct crypt_queue {
298c2ecf20Sopenharmony_ci	struct ptr_ring ring;
308c2ecf20Sopenharmony_ci	struct multicore_worker __percpu *worker;
318c2ecf20Sopenharmony_ci	int last_cpu;
328c2ecf20Sopenharmony_ci};
338c2ecf20Sopenharmony_ci
348c2ecf20Sopenharmony_cistruct prev_queue {
358c2ecf20Sopenharmony_ci	struct sk_buff *head, *tail, *peeked;
368c2ecf20Sopenharmony_ci	struct { struct sk_buff *next, *prev; } empty; // Match first 2 members of struct sk_buff.
378c2ecf20Sopenharmony_ci	atomic_t count;
388c2ecf20Sopenharmony_ci};
398c2ecf20Sopenharmony_ci
408c2ecf20Sopenharmony_cistruct wg_device {
418c2ecf20Sopenharmony_ci	struct net_device *dev;
428c2ecf20Sopenharmony_ci	struct crypt_queue encrypt_queue, decrypt_queue, handshake_queue;
438c2ecf20Sopenharmony_ci	struct sock __rcu *sock4, *sock6;
448c2ecf20Sopenharmony_ci	struct net __rcu *creating_net;
458c2ecf20Sopenharmony_ci	struct noise_static_identity static_identity;
468c2ecf20Sopenharmony_ci	struct workqueue_struct *packet_crypt_wq,*handshake_receive_wq, *handshake_send_wq;
478c2ecf20Sopenharmony_ci	struct cookie_checker cookie_checker;
488c2ecf20Sopenharmony_ci	struct pubkey_hashtable *peer_hashtable;
498c2ecf20Sopenharmony_ci	struct index_hashtable *index_hashtable;
508c2ecf20Sopenharmony_ci	struct allowedips peer_allowedips;
518c2ecf20Sopenharmony_ci	struct mutex device_update_lock, socket_update_lock;
528c2ecf20Sopenharmony_ci	struct list_head device_list, peer_list;
538c2ecf20Sopenharmony_ci	atomic_t handshake_queue_len;
548c2ecf20Sopenharmony_ci	unsigned int num_peers, device_update_gen;
558c2ecf20Sopenharmony_ci	u32 fwmark;
568c2ecf20Sopenharmony_ci	u16 incoming_port;
578c2ecf20Sopenharmony_ci};
588c2ecf20Sopenharmony_ci
598c2ecf20Sopenharmony_ciint wg_device_init(void);
608c2ecf20Sopenharmony_civoid wg_device_uninit(void);
618c2ecf20Sopenharmony_ci
628c2ecf20Sopenharmony_ci#endif /* _WG_DEVICE_H */
63