Lines Matching refs:peer
21 static void wg_packet_send_handshake_initiation(struct wg_peer *peer) in wg_packet_send_handshake_initiation() argument
25 if (!wg_birthdate_has_expired(atomic64_read(&peer->last_sent_handshake), in wg_packet_send_handshake_initiation()
29 atomic64_set(&peer->last_sent_handshake, ktime_get_coarse_boottime_ns()); in wg_packet_send_handshake_initiation()
31 peer->device->dev->name, peer->internal_id, in wg_packet_send_handshake_initiation()
32 &peer->endpoint.addr); in wg_packet_send_handshake_initiation()
34 if (wg_noise_handshake_create_initiation(&packet, &peer->handshake)) { in wg_packet_send_handshake_initiation()
35 wg_cookie_add_mac_to_packet(&packet, sizeof(packet), peer); in wg_packet_send_handshake_initiation()
36 wg_timers_any_authenticated_packet_traversal(peer); in wg_packet_send_handshake_initiation()
37 wg_timers_any_authenticated_packet_sent(peer); in wg_packet_send_handshake_initiation()
38 atomic64_set(&peer->last_sent_handshake, in wg_packet_send_handshake_initiation()
40 wg_socket_send_buffer_to_peer(peer, &packet, sizeof(packet), in wg_packet_send_handshake_initiation()
42 wg_timers_handshake_initiated(peer); in wg_packet_send_handshake_initiation()
48 struct wg_peer *peer = container_of(work, struct wg_peer, in wg_packet_handshake_send_worker() local
51 wg_packet_send_handshake_initiation(peer); in wg_packet_handshake_send_worker()
52 wg_peer_put(peer); in wg_packet_handshake_send_worker()
55 void wg_packet_send_queued_handshake_initiation(struct wg_peer *peer, in wg_packet_send_queued_handshake_initiation() argument
59 peer->timer_handshake_attempts = 0; in wg_packet_send_queued_handshake_initiation()
66 if (!wg_birthdate_has_expired(atomic64_read(&peer->last_sent_handshake), in wg_packet_send_queued_handshake_initiation()
68 unlikely(READ_ONCE(peer->is_dead))) in wg_packet_send_queued_handshake_initiation()
71 wg_peer_get(peer); in wg_packet_send_queued_handshake_initiation()
75 if (!queue_work(peer->device->handshake_send_wq, in wg_packet_send_queued_handshake_initiation()
76 &peer->transmit_handshake_work)) in wg_packet_send_queued_handshake_initiation()
80 wg_peer_put(peer); in wg_packet_send_queued_handshake_initiation()
85 void wg_packet_send_handshake_response(struct wg_peer *peer) in wg_packet_send_handshake_response() argument
89 atomic64_set(&peer->last_sent_handshake, ktime_get_coarse_boottime_ns()); in wg_packet_send_handshake_response()
91 peer->device->dev->name, peer->internal_id, in wg_packet_send_handshake_response()
92 &peer->endpoint.addr); in wg_packet_send_handshake_response()
94 if (wg_noise_handshake_create_response(&packet, &peer->handshake)) { in wg_packet_send_handshake_response()
95 wg_cookie_add_mac_to_packet(&packet, sizeof(packet), peer); in wg_packet_send_handshake_response()
96 if (wg_noise_handshake_begin_session(&peer->handshake, in wg_packet_send_handshake_response()
97 &peer->keypairs)) { in wg_packet_send_handshake_response()
98 wg_timers_session_derived(peer); in wg_packet_send_handshake_response()
99 wg_timers_any_authenticated_packet_traversal(peer); in wg_packet_send_handshake_response()
100 wg_timers_any_authenticated_packet_sent(peer); in wg_packet_send_handshake_response()
101 atomic64_set(&peer->last_sent_handshake, in wg_packet_send_handshake_response()
103 wg_socket_send_buffer_to_peer(peer, &packet, in wg_packet_send_handshake_response()
124 static void keep_key_fresh(struct wg_peer *peer) in keep_key_fresh() argument
130 keypair = rcu_dereference_bh(peer->keypairs.current_keypair); in keep_key_fresh()
138 wg_packet_send_queued_handshake_initiation(peer, false); in keep_key_fresh()
221 void wg_packet_send_keepalive(struct wg_peer *peer) in wg_packet_send_keepalive() argument
225 if (skb_queue_empty(&peer->staged_packet_queue)) { in wg_packet_send_keepalive()
231 skb->dev = peer->device->dev; in wg_packet_send_keepalive()
233 skb_queue_tail(&peer->staged_packet_queue, skb); in wg_packet_send_keepalive()
235 peer->device->dev->name, peer->internal_id, in wg_packet_send_keepalive()
236 &peer->endpoint.addr); in wg_packet_send_keepalive()
239 wg_packet_send_staged_packets(peer); in wg_packet_send_keepalive()
243 struct wg_peer *peer) in wg_packet_create_data_done() argument
248 wg_timers_any_authenticated_packet_traversal(peer); in wg_packet_create_data_done()
249 wg_timers_any_authenticated_packet_sent(peer); in wg_packet_create_data_done()
252 if (likely(!wg_socket_send_skb_to_peer(peer, skb, in wg_packet_create_data_done()
258 wg_timers_data_sent(peer); in wg_packet_create_data_done()
260 keep_key_fresh(peer); in wg_packet_create_data_done()
270 struct wg_peer *peer; in wg_packet_tx_worker() local
276 peer = PACKET_PEER(first); in wg_packet_tx_worker()
280 wg_packet_create_data_done(first, peer); in wg_packet_tx_worker()
285 wg_peer_put(peer); in wg_packet_tx_worker()
318 struct wg_peer *peer = PACKET_PEER(first); in wg_packet_create_data() local
319 struct wg_device *wg = peer->device; in wg_packet_create_data()
323 if (unlikely(READ_ONCE(peer->is_dead))) in wg_packet_create_data()
327 &peer->tx_queue, first, in wg_packet_create_data()
331 wg_queue_enqueue_per_peer(&peer->tx_queue, first, in wg_packet_create_data()
338 wg_peer_put(peer); in wg_packet_create_data()
342 void wg_packet_purge_staged_packets(struct wg_peer *peer) in wg_packet_purge_staged_packets() argument
344 spin_lock_bh(&peer->staged_packet_queue.lock); in wg_packet_purge_staged_packets()
345 peer->device->dev->stats.tx_dropped += peer->staged_packet_queue.qlen; in wg_packet_purge_staged_packets()
346 __skb_queue_purge(&peer->staged_packet_queue); in wg_packet_purge_staged_packets()
347 spin_unlock_bh(&peer->staged_packet_queue.lock); in wg_packet_purge_staged_packets()
350 void wg_packet_send_staged_packets(struct wg_peer *peer) in wg_packet_send_staged_packets() argument
358 spin_lock_bh(&peer->staged_packet_queue.lock); in wg_packet_send_staged_packets()
359 skb_queue_splice_init(&peer->staged_packet_queue, &packets); in wg_packet_send_staged_packets()
360 spin_unlock_bh(&peer->staged_packet_queue.lock); in wg_packet_send_staged_packets()
367 rcu_dereference_bh(peer->keypairs.current_keypair)); in wg_packet_send_staged_packets()
394 wg_peer_get(keypair->entry.peer); in wg_packet_send_staged_packets()
414 spin_lock_bh(&peer->staged_packet_queue.lock); in wg_packet_send_staged_packets()
415 skb_queue_splice(&packets, &peer->staged_packet_queue); in wg_packet_send_staged_packets()
416 spin_unlock_bh(&peer->staged_packet_queue.lock); in wg_packet_send_staged_packets()
421 wg_packet_send_queued_handshake_initiation(peer, false); in wg_packet_send_staged_packets()