Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0 */
0002 /*
0003  * Copyright (C) 2015-2019 Jason A. Donenfeld <Jason@zx2c4.com>. All Rights Reserved.
0004  */
0005 
0006 #ifndef _WG_PEER_H
0007 #define _WG_PEER_H
0008 
0009 #include "device.h"
0010 #include "noise.h"
0011 #include "cookie.h"
0012 
0013 #include <linux/types.h>
0014 #include <linux/netfilter.h>
0015 #include <linux/spinlock.h>
0016 #include <linux/kref.h>
0017 #include <net/dst_cache.h>
0018 
0019 struct wg_device;
0020 
0021 struct endpoint {
0022     union {
0023         struct sockaddr addr;
0024         struct sockaddr_in addr4;
0025         struct sockaddr_in6 addr6;
0026     };
0027     union {
0028         struct {
0029             struct in_addr src4;
0030             /* Essentially the same as addr6->scope_id */
0031             int src_if4;
0032         };
0033         struct in6_addr src6;
0034     };
0035 };
0036 
0037 struct wg_peer {
0038     struct wg_device *device;
0039     struct prev_queue tx_queue, rx_queue;
0040     struct sk_buff_head staged_packet_queue;
0041     int serial_work_cpu;
0042     bool is_dead;
0043     struct noise_keypairs keypairs;
0044     struct endpoint endpoint;
0045     struct dst_cache endpoint_cache;
0046     rwlock_t endpoint_lock;
0047     struct noise_handshake handshake;
0048     atomic64_t last_sent_handshake;
0049     struct work_struct transmit_handshake_work, clear_peer_work, transmit_packet_work;
0050     struct cookie latest_cookie;
0051     struct hlist_node pubkey_hash;
0052     u64 rx_bytes, tx_bytes;
0053     struct timer_list timer_retransmit_handshake, timer_send_keepalive;
0054     struct timer_list timer_new_handshake, timer_zero_key_material;
0055     struct timer_list timer_persistent_keepalive;
0056     unsigned int timer_handshake_attempts;
0057     u16 persistent_keepalive_interval;
0058     bool timer_need_another_keepalive;
0059     bool sent_lastminute_handshake;
0060     struct timespec64 walltime_last_handshake;
0061     struct kref refcount;
0062     struct rcu_head rcu;
0063     struct list_head peer_list;
0064     struct list_head allowedips_list;
0065     struct napi_struct napi;
0066     u64 internal_id;
0067 };
0068 
0069 struct wg_peer *wg_peer_create(struct wg_device *wg,
0070                    const u8 public_key[NOISE_PUBLIC_KEY_LEN],
0071                    const u8 preshared_key[NOISE_SYMMETRIC_KEY_LEN]);
0072 
0073 struct wg_peer *__must_check wg_peer_get_maybe_zero(struct wg_peer *peer);
0074 static inline struct wg_peer *wg_peer_get(struct wg_peer *peer)
0075 {
0076     kref_get(&peer->refcount);
0077     return peer;
0078 }
0079 void wg_peer_put(struct wg_peer *peer);
0080 void wg_peer_remove(struct wg_peer *peer);
0081 void wg_peer_remove_all(struct wg_device *wg);
0082 
0083 int wg_peer_init(void);
0084 void wg_peer_uninit(void);
0085 
0086 #endif /* _WG_PEER_H */