| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
#ifndef _NET_OVPN_DCO_OVPNPEER_H_ |
| 11 |
#define _NET_OVPN_DCO_OVPNPEER_H_ |
| 12 |
|
| 13 |
#include "addr.h" |
| 14 |
#include "bind.h" |
| 15 |
#include "sock.h" |
| 16 |
#include "stats.h" |
| 17 |
|
| 18 |
#include <linux/timer.h> |
| 19 |
#include <linux/ptr_ring.h> |
| 20 |
#include <net/dst_cache.h> |
| 21 |
|
| 22 |
struct ovpn_peer { |
| 23 |
struct ovpn_struct *ovpn; |
| 24 |
|
| 25 |
u32 id; |
| 26 |
|
| 27 |
struct { |
| 28 |
struct in_addr ipv4; |
| 29 |
struct in6_addr ipv6; |
| 30 |
} vpn_addrs; |
| 31 |
|
| 32 |
struct hlist_node hash_entry_id; |
| 33 |
struct hlist_node hash_entry_addr4; |
| 34 |
struct hlist_node hash_entry_addr6; |
| 35 |
struct hlist_node hash_entry_transp_addr; |
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
struct work_struct encrypt_work; |
| 41 |
struct work_struct decrypt_work; |
| 42 |
|
| 43 |
struct ptr_ring tx_ring; |
| 44 |
struct ptr_ring rx_ring; |
| 45 |
struct ptr_ring netif_rx_ring; |
| 46 |
|
| 47 |
struct napi_struct napi; |
| 48 |
|
| 49 |
struct ovpn_socket *sock; |
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
|
| 54 |
struct { |
| 55 |
struct ptr_ring tx_ring; |
| 56 |
struct work_struct tx_work; |
| 57 |
struct work_struct rx_work; |
| 58 |
|
| 59 |
u8 raw_len[sizeof(u16)]; |
| 60 |
struct sk_buff *skb; |
| 61 |
u16 offset; |
| 62 |
u16 data_len; |
| 63 |
struct { |
| 64 |
void (*sk_state_change)(struct sock *sk); |
| 65 |
void (*sk_data_ready)(struct sock *sk); |
| 66 |
void (*sk_write_space)(struct sock *sk); |
| 67 |
struct proto *prot; |
| 68 |
} sk_cb; |
| 69 |
} tcp; |
| 70 |
|
| 71 |
struct dst_cache dst_cache; |
| 72 |
|
| 73 |
|
| 74 |
struct ovpn_crypto_state crypto; |
| 75 |
|
| 76 |
|
| 77 |
struct ovpn_bind __rcu *bind; |
| 78 |
|
| 79 |
|
| 80 |
|
| 81 |
|
| 82 |
struct timer_list keepalive_xmit; |
| 83 |
|
| 84 |
unsigned long keepalive_interval; |
| 85 |
|
| 86 |
|
| 87 |
|
| 88 |
|
| 89 |
struct timer_list keepalive_recv; |
| 90 |
|
| 91 |
unsigned long keepalive_timeout; |
| 92 |
|
| 93 |
|
| 94 |
bool halt; |
| 95 |
|
| 96 |
|
| 97 |
struct ovpn_peer_stats vpn_stats; |
| 98 |
|
| 99 |
|
| 100 |
struct ovpn_peer_stats link_stats; |
| 101 |
|
| 102 |
|
| 103 |
enum ovpn_del_peer_reason delete_reason; |
| 104 |
|
| 105 |
|
| 106 |
|
| 107 |
|
| 108 |
spinlock_t lock; |
| 109 |
|
| 110 |
|
| 111 |
struct kref refcount; |
| 112 |
|
| 113 |
|
| 114 |
struct rcu_head rcu; |
| 115 |
|
| 116 |
|
| 117 |
struct work_struct delete_work; |
| 118 |
}; |
| 119 |
|
| 120 |
void ovpn_peer_release_kref(struct kref *kref); |
| 121 |
void ovpn_peer_release(struct ovpn_peer *peer); |
| 122 |
|
| 123 |
static inline bool ovpn_peer_hold(struct ovpn_peer *peer) |
| 124 |
{ |
| 125 |
return kref_get_unless_zero(&peer->refcount); |
| 126 |
} |
| 127 |
|
| 128 |
static inline void ovpn_peer_put(struct ovpn_peer *peer) |
| 129 |
{ |
| 130 |
kref_put(&peer->refcount, ovpn_peer_release_kref); |
| 131 |
} |
| 132 |
|
| 133 |
static inline void ovpn_peer_keepalive_recv_reset(struct ovpn_peer *peer) |
| 134 |
{ |
| 135 |
u32 delta = msecs_to_jiffies(peer->keepalive_timeout * MSEC_PER_SEC); |
| 136 |
|
| 137 |
if (unlikely(!delta)) |
| 138 |
return; |
| 139 |
|
| 140 |
mod_timer(&peer->keepalive_recv, jiffies + delta); |
| 141 |
} |
| 142 |
|
| 143 |
static inline void ovpn_peer_keepalive_xmit_reset(struct ovpn_peer *peer) |
| 144 |
{ |
| 145 |
u32 delta = msecs_to_jiffies(peer->keepalive_interval * MSEC_PER_SEC); |
| 146 |
|
| 147 |
if (unlikely(!delta)) |
| 148 |
return; |
| 149 |
|
| 150 |
mod_timer(&peer->keepalive_xmit, jiffies + delta); |
| 151 |
} |
| 152 |
|
| 153 |
struct ovpn_peer *ovpn_peer_new(struct ovpn_struct *ovpn, const struct sockaddr_storage *sa, |
| 154 |
struct socket *sock, u32 id, uint8_t *local_ip); |
| 155 |
|
| 156 |
void ovpn_peer_keepalive_set(struct ovpn_peer *peer, u32 interval, u32 timeout); |
| 157 |
|
| 158 |
int ovpn_peer_add(struct ovpn_struct *ovpn, struct ovpn_peer *peer); |
| 159 |
int ovpn_peer_del(struct ovpn_peer *peer, enum ovpn_del_peer_reason reason); |
| 160 |
struct ovpn_peer *ovpn_peer_find(struct ovpn_struct *ovpn, u32 peer_id); |
| 161 |
void ovpn_peer_release_p2p(struct ovpn_struct *ovpn); |
| 162 |
void ovpn_peers_free(struct ovpn_struct *ovpn); |
| 163 |
|
| 164 |
struct ovpn_peer *ovpn_peer_lookup_transp_addr(struct ovpn_struct *ovpn, struct sk_buff *skb); |
| 165 |
struct ovpn_peer *ovpn_peer_lookup_vpn_addr(struct ovpn_struct *ovpn, struct sk_buff *skb, |
| 166 |
bool use_src); |
| 167 |
struct ovpn_peer *ovpn_peer_lookup_id(struct ovpn_struct *ovpn, u32 peer_id); |
| 168 |
|
| 169 |
void ovpn_peer_update_local_endpoint(struct ovpn_peer *peer, struct sk_buff *skb); |
| 170 |
void ovpn_peer_float(struct ovpn_peer *peer, struct sk_buff *skb); |
| 171 |
|
| 172 |
#endif |