Lines Matching full:peer

6 #include "peer.h"
24 struct wg_peer *peer; in wg_peer_create() local
32 peer = kzalloc(sizeof(*peer), GFP_KERNEL); in wg_peer_create()
33 if (unlikely(!peer)) in wg_peer_create()
35 peer->device = wg; in wg_peer_create()
37 wg_noise_handshake_init(&peer->handshake, &wg->static_identity, in wg_peer_create()
38 public_key, preshared_key, peer); in wg_peer_create()
39 if (dst_cache_init(&peer->endpoint_cache, GFP_KERNEL)) in wg_peer_create()
41 if (wg_packet_queue_init(&peer->tx_queue, wg_packet_tx_worker, false, in wg_peer_create()
44 if (wg_packet_queue_init(&peer->rx_queue, NULL, false, in wg_peer_create()
48 peer->internal_id = atomic64_inc_return(&peer_counter); in wg_peer_create()
49 peer->serial_work_cpu = nr_cpumask_bits; in wg_peer_create()
50 wg_cookie_init(&peer->latest_cookie); in wg_peer_create()
51 wg_timers_init(peer); in wg_peer_create()
52 wg_cookie_checker_precompute_peer_keys(peer); in wg_peer_create()
53 spin_lock_init(&peer->keypairs.keypair_update_lock); in wg_peer_create()
54 INIT_WORK(&peer->transmit_handshake_work, in wg_peer_create()
56 rwlock_init(&peer->endpoint_lock); in wg_peer_create()
57 kref_init(&peer->refcount); in wg_peer_create()
58 skb_queue_head_init(&peer->staged_packet_queue); in wg_peer_create()
59 wg_noise_reset_last_sent_handshake(&peer->last_sent_handshake); in wg_peer_create()
60 set_bit(NAPI_STATE_NO_BUSY_POLL, &peer->napi.state); in wg_peer_create()
61 netif_napi_add(wg->dev, &peer->napi, wg_packet_rx_poll, in wg_peer_create()
63 napi_enable(&peer->napi); in wg_peer_create()
64 list_add_tail(&peer->peer_list, &wg->peer_list); in wg_peer_create()
65 INIT_LIST_HEAD(&peer->allowedips_list); in wg_peer_create()
66 wg_pubkey_hashtable_add(wg->peer_hashtable, peer); in wg_peer_create()
68 pr_debug("%s: Peer %llu created\n", wg->dev->name, peer->internal_id); in wg_peer_create()
69 return peer; in wg_peer_create()
72 wg_packet_queue_free(&peer->tx_queue, false); in wg_peer_create()
74 dst_cache_destroy(&peer->endpoint_cache); in wg_peer_create()
76 kfree(peer); in wg_peer_create()
80 struct wg_peer *wg_peer_get_maybe_zero(struct wg_peer *peer) in wg_peer_get_maybe_zero() argument
83 "Taking peer reference without holding the RCU read lock"); in wg_peer_get_maybe_zero()
84 if (unlikely(!peer || !kref_get_unless_zero(&peer->refcount))) in wg_peer_get_maybe_zero()
86 return peer; in wg_peer_get_maybe_zero()
89 static void peer_make_dead(struct wg_peer *peer) in peer_make_dead() argument
92 list_del_init(&peer->peer_list); in peer_make_dead()
93 wg_allowedips_remove_by_peer(&peer->device->peer_allowedips, peer, in peer_make_dead()
94 &peer->device->device_update_lock); in peer_make_dead()
95 wg_pubkey_hashtable_remove(peer->device->peer_hashtable, peer); in peer_make_dead()
98 WRITE_ONCE(peer->is_dead, true); in peer_make_dead()
103 static void peer_remove_after_dead(struct wg_peer *peer) in peer_remove_after_dead() argument
105 WARN_ON(!peer->is_dead); in peer_remove_after_dead()
107 /* No more keypairs can be created for this peer, since is_dead protects in peer_remove_after_dead()
110 wg_noise_keypairs_clear(&peer->keypairs); in peer_remove_after_dead()
115 wg_timers_stop(peer); in peer_remove_after_dead()
125 flush_workqueue(peer->device->packet_crypt_wq); in peer_remove_after_dead()
127 flush_workqueue(peer->device->packet_crypt_wq); in peer_remove_after_dead()
129 napi_disable(&peer->napi); in peer_remove_after_dead()
133 netif_napi_del(&peer->napi); in peer_remove_after_dead()
138 flush_workqueue(peer->device->handshake_send_wq); in peer_remove_after_dead()
140 /* After the above flushes, a peer might still be active in a few in peer_remove_after_dead()
153 * and in wg_cookie_message_consume, the lookup eventually gets a peer in peer_remove_after_dead()
157 --peer->device->num_peers; in peer_remove_after_dead()
158 wg_peer_put(peer); in peer_remove_after_dead()
162 * a peer is currently operating will eventually come to an end and not pass
165 void wg_peer_remove(struct wg_peer *peer) in wg_peer_remove() argument
167 if (unlikely(!peer)) in wg_peer_remove()
169 lockdep_assert_held(&peer->device->device_update_lock); in wg_peer_remove()
171 peer_make_dead(peer); in wg_peer_remove()
173 peer_remove_after_dead(peer); in wg_peer_remove()
178 struct wg_peer *peer, *temp; in wg_peer_remove_all() local
186 list_for_each_entry_safe(peer, temp, &wg->peer_list, peer_list) { in wg_peer_remove_all()
187 peer_make_dead(peer); in wg_peer_remove_all()
188 list_add_tail(&peer->peer_list, &dead_peers); in wg_peer_remove_all()
191 list_for_each_entry_safe(peer, temp, &dead_peers, peer_list) in wg_peer_remove_all()
192 peer_remove_after_dead(peer); in wg_peer_remove_all()
197 struct wg_peer *peer = container_of(rcu, struct wg_peer, rcu); in rcu_release() local
199 dst_cache_destroy(&peer->endpoint_cache); in rcu_release()
200 wg_packet_queue_free(&peer->rx_queue, false); in rcu_release()
201 wg_packet_queue_free(&peer->tx_queue, false); in rcu_release()
206 kfree_sensitive(peer); in rcu_release()
211 struct wg_peer *peer = container_of(refcount, struct wg_peer, refcount); in kref_release() local
213 pr_debug("%s: Peer %llu (%pISpfsc) destroyed\n", in kref_release()
214 peer->device->dev->name, peer->internal_id, in kref_release()
215 &peer->endpoint.addr); in kref_release()
220 wg_index_hashtable_remove(peer->device->index_hashtable, in kref_release()
221 &peer->handshake.entry); in kref_release()
226 wg_packet_purge_staged_packets(peer); in kref_release()
229 call_rcu(&peer->rcu, rcu_release); in kref_release()
232 void wg_peer_put(struct wg_peer *peer) in wg_peer_put() argument
234 if (unlikely(!peer)) in wg_peer_put()
236 kref_put(&peer->refcount, kref_release); in wg_peer_put()