device.h 1.5 KB

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