Lines Matching refs:peer
25 struct wg_peer *peer; in wg_peer_create() local
33 peer = kmem_cache_zalloc(peer_cache, GFP_KERNEL); in wg_peer_create()
34 if (unlikely(!peer)) in wg_peer_create()
36 if (unlikely(dst_cache_init(&peer->endpoint_cache, GFP_KERNEL))) in wg_peer_create()
39 peer->device = wg; in wg_peer_create()
40 wg_noise_handshake_init(&peer->handshake, &wg->static_identity, in wg_peer_create()
41 public_key, preshared_key, peer); in wg_peer_create()
42 peer->internal_id = atomic64_inc_return(&peer_counter); in wg_peer_create()
43 peer->serial_work_cpu = nr_cpumask_bits; in wg_peer_create()
44 wg_cookie_init(&peer->latest_cookie); in wg_peer_create()
45 wg_timers_init(peer); in wg_peer_create()
46 wg_cookie_checker_precompute_peer_keys(peer); in wg_peer_create()
47 spin_lock_init(&peer->keypairs.keypair_update_lock); in wg_peer_create()
48 INIT_WORK(&peer->transmit_handshake_work, wg_packet_handshake_send_worker); in wg_peer_create()
49 INIT_WORK(&peer->transmit_packet_work, wg_packet_tx_worker); in wg_peer_create()
50 wg_prev_queue_init(&peer->tx_queue); in wg_peer_create()
51 wg_prev_queue_init(&peer->rx_queue); in wg_peer_create()
52 rwlock_init(&peer->endpoint_lock); in wg_peer_create()
53 kref_init(&peer->refcount); in wg_peer_create()
54 skb_queue_head_init(&peer->staged_packet_queue); in wg_peer_create()
55 wg_noise_reset_last_sent_handshake(&peer->last_sent_handshake); in wg_peer_create()
56 set_bit(NAPI_STATE_NO_BUSY_POLL, &peer->napi.state); in wg_peer_create()
57 netif_napi_add(wg->dev, &peer->napi, wg_packet_rx_poll); in wg_peer_create()
58 napi_enable(&peer->napi); in wg_peer_create()
59 list_add_tail(&peer->peer_list, &wg->peer_list); in wg_peer_create()
60 INIT_LIST_HEAD(&peer->allowedips_list); in wg_peer_create()
61 wg_pubkey_hashtable_add(wg->peer_hashtable, peer); in wg_peer_create()
63 pr_debug("%s: Peer %llu created\n", wg->dev->name, peer->internal_id); in wg_peer_create()
64 return peer; in wg_peer_create()
67 kmem_cache_free(peer_cache, peer); in wg_peer_create()
71 struct wg_peer *wg_peer_get_maybe_zero(struct wg_peer *peer) in wg_peer_get_maybe_zero() argument
75 if (unlikely(!peer || !kref_get_unless_zero(&peer->refcount))) in wg_peer_get_maybe_zero()
77 return peer; in wg_peer_get_maybe_zero()
80 static void peer_make_dead(struct wg_peer *peer) in peer_make_dead() argument
83 list_del_init(&peer->peer_list); in peer_make_dead()
84 wg_allowedips_remove_by_peer(&peer->device->peer_allowedips, peer, in peer_make_dead()
85 &peer->device->device_update_lock); in peer_make_dead()
86 wg_pubkey_hashtable_remove(peer->device->peer_hashtable, peer); in peer_make_dead()
89 WRITE_ONCE(peer->is_dead, true); in peer_make_dead()
94 static void peer_remove_after_dead(struct wg_peer *peer) in peer_remove_after_dead() argument
96 WARN_ON(!peer->is_dead); in peer_remove_after_dead()
101 wg_noise_keypairs_clear(&peer->keypairs); in peer_remove_after_dead()
106 wg_timers_stop(peer); in peer_remove_after_dead()
116 flush_workqueue(peer->device->packet_crypt_wq); in peer_remove_after_dead()
118 flush_workqueue(peer->device->packet_crypt_wq); in peer_remove_after_dead()
120 napi_disable(&peer->napi); in peer_remove_after_dead()
124 netif_napi_del(&peer->napi); in peer_remove_after_dead()
129 flush_workqueue(peer->device->handshake_send_wq); in peer_remove_after_dead()
148 --peer->device->num_peers; in peer_remove_after_dead()
149 wg_peer_put(peer); in peer_remove_after_dead()
156 void wg_peer_remove(struct wg_peer *peer) in wg_peer_remove() argument
158 if (unlikely(!peer)) in wg_peer_remove()
160 lockdep_assert_held(&peer->device->device_update_lock); in wg_peer_remove()
162 peer_make_dead(peer); in wg_peer_remove()
164 peer_remove_after_dead(peer); in wg_peer_remove()
169 struct wg_peer *peer, *temp; in wg_peer_remove_all() local
177 list_for_each_entry_safe(peer, temp, &wg->peer_list, peer_list) { in wg_peer_remove_all()
178 peer_make_dead(peer); in wg_peer_remove_all()
179 list_add_tail(&peer->peer_list, &dead_peers); in wg_peer_remove_all()
182 list_for_each_entry_safe(peer, temp, &dead_peers, peer_list) in wg_peer_remove_all()
183 peer_remove_after_dead(peer); in wg_peer_remove_all()
188 struct wg_peer *peer = container_of(rcu, struct wg_peer, rcu); in rcu_release() local
190 dst_cache_destroy(&peer->endpoint_cache); in rcu_release()
191 WARN_ON(wg_prev_queue_peek(&peer->tx_queue) || wg_prev_queue_peek(&peer->rx_queue)); in rcu_release()
196 memzero_explicit(peer, sizeof(*peer)); in rcu_release()
197 kmem_cache_free(peer_cache, peer); in rcu_release()
202 struct wg_peer *peer = container_of(refcount, struct wg_peer, refcount); in kref_release() local
205 peer->device->dev->name, peer->internal_id, in kref_release()
206 &peer->endpoint.addr); in kref_release()
211 wg_index_hashtable_remove(peer->device->index_hashtable, in kref_release()
212 &peer->handshake.entry); in kref_release()
217 wg_packet_purge_staged_packets(peer); in kref_release()
220 call_rcu(&peer->rcu, rcu_release); in kref_release()
223 void wg_peer_put(struct wg_peer *peer) in wg_peer_put() argument
225 if (unlikely(!peer)) in wg_peer_put()
227 kref_put(&peer->refcount, kref_release); in wg_peer_put()