linux/drivers/net/wireguard/peer.h
<<
>>
Prefs
   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_PEER_H
   7#define _WG_PEER_H
   8
   9#include "device.h"
  10#include "noise.h"
  11#include "cookie.h"
  12
  13#include <linux/types.h>
  14#include <linux/netfilter.h>
  15#include <linux/spinlock.h>
  16#include <linux/kref.h>
  17#include <net/dst_cache.h>
  18
  19struct wg_device;
  20
  21struct endpoint {
  22        union {
  23                struct sockaddr addr;
  24                struct sockaddr_in addr4;
  25                struct sockaddr_in6 addr6;
  26        };
  27        union {
  28                struct {
  29                        struct in_addr src4;
  30                        /* Essentially the same as addr6->scope_id */
  31                        int src_if4;
  32                };
  33                struct in6_addr src6;
  34        };
  35};
  36
  37struct wg_peer {
  38        struct wg_device *device;
  39        struct crypt_queue tx_queue, rx_queue;
  40        struct sk_buff_head staged_packet_queue;
  41        int serial_work_cpu;
  42        struct noise_keypairs keypairs;
  43        struct endpoint endpoint;
  44        struct dst_cache endpoint_cache;
  45        rwlock_t endpoint_lock;
  46        struct noise_handshake handshake;
  47        atomic64_t last_sent_handshake;
  48        struct work_struct transmit_handshake_work, clear_peer_work;
  49        struct cookie latest_cookie;
  50        struct hlist_node pubkey_hash;
  51        u64 rx_bytes, tx_bytes;
  52        struct timer_list timer_retransmit_handshake, timer_send_keepalive;
  53        struct timer_list timer_new_handshake, timer_zero_key_material;
  54        struct timer_list timer_persistent_keepalive;
  55        unsigned int timer_handshake_attempts;
  56        u16 persistent_keepalive_interval;
  57        bool timer_need_another_keepalive;
  58        bool sent_lastminute_handshake;
  59        struct timespec64 walltime_last_handshake;
  60        struct kref refcount;
  61        struct rcu_head rcu;
  62        struct list_head peer_list;
  63        struct list_head allowedips_list;
  64        u64 internal_id;
  65        struct napi_struct napi;
  66        bool is_dead;
  67};
  68
  69struct wg_peer *wg_peer_create(struct wg_device *wg,
  70                               const u8 public_key[NOISE_PUBLIC_KEY_LEN],
  71                               const u8 preshared_key[NOISE_SYMMETRIC_KEY_LEN]);
  72
  73struct wg_peer *__must_check wg_peer_get_maybe_zero(struct wg_peer *peer);
  74static inline struct wg_peer *wg_peer_get(struct wg_peer *peer)
  75{
  76        kref_get(&peer->refcount);
  77        return peer;
  78}
  79void wg_peer_put(struct wg_peer *peer);
  80void wg_peer_remove(struct wg_peer *peer);
  81void wg_peer_remove_all(struct wg_device *wg);
  82
  83#endif /* _WG_PEER_H */
  84