Lines Matching full:peer
26 * Hash a peer key.
60 /* Step through the peer address in 16-bit portions for speed */ in rxrpc_peer_hash_key()
69 * Compare a peer to a key. Return -ve, 0 or +ve to indicate less than, same
76 static long rxrpc_peer_cmp_key(const struct rxrpc_peer *peer, in rxrpc_peer_cmp_key() argument
83 diff = ((peer->hash_key - hash_key) ?: in rxrpc_peer_cmp_key()
84 ((unsigned long)peer->local - (unsigned long)local) ?: in rxrpc_peer_cmp_key()
85 (peer->srx.transport_type - srx->transport_type) ?: in rxrpc_peer_cmp_key()
86 (peer->srx.transport_len - srx->transport_len) ?: in rxrpc_peer_cmp_key()
87 (peer->srx.transport.family - srx->transport.family)); in rxrpc_peer_cmp_key()
93 return ((u16 __force)peer->srx.transport.sin.sin_port - in rxrpc_peer_cmp_key()
95 memcmp(&peer->srx.transport.sin.sin_addr, in rxrpc_peer_cmp_key()
100 return ((u16 __force)peer->srx.transport.sin6.sin6_port - in rxrpc_peer_cmp_key()
102 memcmp(&peer->srx.transport.sin6.sin6_addr, in rxrpc_peer_cmp_key()
119 struct rxrpc_peer *peer; in __rxrpc_lookup_peer_rcu() local
122 hash_for_each_possible_rcu(rxnet->peer_hash, peer, hash_link, hash_key) { in __rxrpc_lookup_peer_rcu()
123 if (rxrpc_peer_cmp_key(peer, local, srx, hash_key) == 0 && in __rxrpc_lookup_peer_rcu()
124 atomic_read(&peer->usage) > 0) in __rxrpc_lookup_peer_rcu()
125 return peer; in __rxrpc_lookup_peer_rcu()
137 struct rxrpc_peer *peer; in rxrpc_lookup_peer_rcu() local
140 peer = __rxrpc_lookup_peer_rcu(local, srx, hash_key); in rxrpc_lookup_peer_rcu()
141 if (peer) { in rxrpc_lookup_peer_rcu()
142 _net("PEER %d {%pISp}", peer->debug_id, &peer->srx.transport); in rxrpc_lookup_peer_rcu()
143 _leave(" = %p {u=%d}", peer, atomic_read(&peer->usage)); in rxrpc_lookup_peer_rcu()
145 return peer; in rxrpc_lookup_peer_rcu()
149 * assess the MTU size for the network interface through which this peer is
153 struct rxrpc_peer *peer) in rxrpc_assess_MTU_size() argument
164 peer->if_mtu = 1500; in rxrpc_assess_MTU_size()
167 switch (peer->srx.transport.family) { in rxrpc_assess_MTU_size()
171 peer->srx.transport.sin.sin_addr.s_addr, 0, in rxrpc_assess_MTU_size()
185 memcpy(&fl6->daddr, &peer->srx.transport.sin6.sin6_addr, in rxrpc_assess_MTU_size()
201 peer->if_mtu = dst_mtu(dst); in rxrpc_assess_MTU_size()
204 _leave(" [if_mtu %u]", peer->if_mtu); in rxrpc_assess_MTU_size()
208 * Allocate a peer.
213 struct rxrpc_peer *peer; in rxrpc_alloc_peer() local
217 peer = kzalloc(sizeof(struct rxrpc_peer), gfp); in rxrpc_alloc_peer()
218 if (peer) { in rxrpc_alloc_peer()
219 atomic_set(&peer->usage, 1); in rxrpc_alloc_peer()
220 peer->local = rxrpc_get_local(local); in rxrpc_alloc_peer()
221 INIT_HLIST_HEAD(&peer->error_targets); in rxrpc_alloc_peer()
222 peer->service_conns = RB_ROOT; in rxrpc_alloc_peer()
223 seqlock_init(&peer->service_conn_lock); in rxrpc_alloc_peer()
224 spin_lock_init(&peer->lock); in rxrpc_alloc_peer()
225 spin_lock_init(&peer->rtt_input_lock); in rxrpc_alloc_peer()
226 peer->debug_id = atomic_inc_return(&rxrpc_debug_id); in rxrpc_alloc_peer()
228 rxrpc_peer_init_rtt(peer); in rxrpc_alloc_peer()
231 peer->cong_cwnd = 2; in rxrpc_alloc_peer()
233 peer->cong_cwnd = 3; in rxrpc_alloc_peer()
235 peer->cong_cwnd = 4; in rxrpc_alloc_peer()
236 trace_rxrpc_peer(peer->debug_id, rxrpc_peer_new, 1, here); in rxrpc_alloc_peer()
239 _leave(" = %p", peer); in rxrpc_alloc_peer()
240 return peer; in rxrpc_alloc_peer()
244 * Initialise peer record.
246 static void rxrpc_init_peer(struct rxrpc_sock *rx, struct rxrpc_peer *peer, in rxrpc_init_peer() argument
249 peer->hash_key = hash_key; in rxrpc_init_peer()
250 rxrpc_assess_MTU_size(rx, peer); in rxrpc_init_peer()
251 peer->mtu = peer->if_mtu; in rxrpc_init_peer()
252 peer->rtt_last_req = ktime_get_real(); in rxrpc_init_peer()
254 switch (peer->srx.transport.family) { in rxrpc_init_peer()
256 peer->hdrsize = sizeof(struct iphdr); in rxrpc_init_peer()
260 peer->hdrsize = sizeof(struct ipv6hdr); in rxrpc_init_peer()
267 switch (peer->srx.transport_type) { in rxrpc_init_peer()
269 peer->hdrsize += sizeof(struct udphdr); in rxrpc_init_peer()
275 peer->hdrsize += sizeof(struct rxrpc_wire_header); in rxrpc_init_peer()
276 peer->maxdata = peer->mtu - peer->hdrsize; in rxrpc_init_peer()
280 * Set up a new peer.
288 struct rxrpc_peer *peer; in rxrpc_create_peer() local
292 peer = rxrpc_alloc_peer(local, gfp); in rxrpc_create_peer()
293 if (peer) { in rxrpc_create_peer()
294 memcpy(&peer->srx, srx, sizeof(*srx)); in rxrpc_create_peer()
295 rxrpc_init_peer(rx, peer, hash_key); in rxrpc_create_peer()
298 _leave(" = %p", peer); in rxrpc_create_peer()
299 return peer; in rxrpc_create_peer()
303 * Set up a new incoming peer. There shouldn't be any other matching peers
308 struct rxrpc_peer *peer) in rxrpc_new_incoming_peer() argument
313 hash_key = rxrpc_peer_hash_key(local, &peer->srx); in rxrpc_new_incoming_peer()
314 rxrpc_init_peer(rx, peer, hash_key); in rxrpc_new_incoming_peer()
317 hash_add_rcu(rxnet->peer_hash, &peer->hash_link, hash_key); in rxrpc_new_incoming_peer()
318 list_add_tail(&peer->keepalive_link, &rxnet->peer_keepalive_new); in rxrpc_new_incoming_peer()
329 struct rxrpc_peer *peer, *candidate; in rxrpc_lookup_peer() local
335 /* search the peer list first */ in rxrpc_lookup_peer()
337 peer = __rxrpc_lookup_peer_rcu(local, srx, hash_key); in rxrpc_lookup_peer()
338 if (peer && !rxrpc_get_peer_maybe(peer)) in rxrpc_lookup_peer()
339 peer = NULL; in rxrpc_lookup_peer()
342 if (!peer) { in rxrpc_lookup_peer()
343 /* The peer is not yet present in hash - create a candidate in rxrpc_lookup_peer()
355 peer = __rxrpc_lookup_peer_rcu(local, srx, hash_key); in rxrpc_lookup_peer()
356 if (peer && !rxrpc_get_peer_maybe(peer)) in rxrpc_lookup_peer()
357 peer = NULL; in rxrpc_lookup_peer()
358 if (!peer) { in rxrpc_lookup_peer()
367 if (peer) in rxrpc_lookup_peer()
370 peer = candidate; in rxrpc_lookup_peer()
373 _net("PEER %d {%pISp}", peer->debug_id, &peer->srx.transport); in rxrpc_lookup_peer()
375 _leave(" = %p {u=%d}", peer, atomic_read(&peer->usage)); in rxrpc_lookup_peer()
376 return peer; in rxrpc_lookup_peer()
380 * Get a ref on a peer record.
382 struct rxrpc_peer *rxrpc_get_peer(struct rxrpc_peer *peer) in rxrpc_get_peer() argument
387 n = atomic_inc_return(&peer->usage); in rxrpc_get_peer()
388 trace_rxrpc_peer(peer->debug_id, rxrpc_peer_got, n, here); in rxrpc_get_peer()
389 return peer; in rxrpc_get_peer()
393 * Get a ref on a peer record unless its usage has already reached 0.
395 struct rxrpc_peer *rxrpc_get_peer_maybe(struct rxrpc_peer *peer) in rxrpc_get_peer_maybe() argument
399 if (peer) { in rxrpc_get_peer_maybe()
400 int n = atomic_fetch_add_unless(&peer->usage, 1, 0); in rxrpc_get_peer_maybe()
402 trace_rxrpc_peer(peer->debug_id, rxrpc_peer_got, n + 1, here); in rxrpc_get_peer_maybe()
404 peer = NULL; in rxrpc_get_peer_maybe()
406 return peer; in rxrpc_get_peer_maybe()
410 * Discard a peer record.
412 static void __rxrpc_put_peer(struct rxrpc_peer *peer) in __rxrpc_put_peer() argument
414 struct rxrpc_net *rxnet = peer->local->rxnet; in __rxrpc_put_peer()
416 ASSERT(hlist_empty(&peer->error_targets)); in __rxrpc_put_peer()
419 hash_del_rcu(&peer->hash_link); in __rxrpc_put_peer()
420 list_del_init(&peer->keepalive_link); in __rxrpc_put_peer()
423 rxrpc_put_local(peer->local); in __rxrpc_put_peer()
424 kfree_rcu(peer, rcu); in __rxrpc_put_peer()
428 * Drop a ref on a peer record.
430 void rxrpc_put_peer(struct rxrpc_peer *peer) in rxrpc_put_peer() argument
436 if (peer) { in rxrpc_put_peer()
437 debug_id = peer->debug_id; in rxrpc_put_peer()
438 n = atomic_dec_return(&peer->usage); in rxrpc_put_peer()
441 __rxrpc_put_peer(peer); in rxrpc_put_peer()
446 * Drop a ref on a peer record where the caller already holds the
449 void rxrpc_put_peer_locked(struct rxrpc_peer *peer) in rxrpc_put_peer_locked() argument
452 unsigned int debug_id = peer->debug_id; in rxrpc_put_peer_locked()
455 n = atomic_dec_return(&peer->usage); in rxrpc_put_peer_locked()
458 hash_del_rcu(&peer->hash_link); in rxrpc_put_peer_locked()
459 list_del_init(&peer->keepalive_link); in rxrpc_put_peer_locked()
460 rxrpc_put_local(peer->local); in rxrpc_put_peer_locked()
461 kfree_rcu(peer, rcu); in rxrpc_put_peer_locked()
466 * Make sure all peer records have been discarded.
470 struct rxrpc_peer *peer; in rxrpc_destroy_all_peers() local
477 hlist_for_each_entry(peer, &rxnet->peer_hash[i], hash_link) { in rxrpc_destroy_all_peers()
478 pr_err("Leaked peer %u {%u} %pISp\n", in rxrpc_destroy_all_peers()
479 peer->debug_id, in rxrpc_destroy_all_peers()
480 atomic_read(&peer->usage), in rxrpc_destroy_all_peers()
481 &peer->srx.transport); in rxrpc_destroy_all_peers()
487 * rxrpc_kernel_get_peer - Get the peer address of a call
492 * Get the address of the remote peer in a call.
497 *_srx = call->peer->srx; in rxrpc_kernel_get_peer()
502 * rxrpc_kernel_get_srtt - Get a call's peer smoothed RTT
507 * Get the call's peer smoothed RTT in uS.
512 struct rxrpc_peer *peer = call->peer; in rxrpc_kernel_get_srtt() local
514 if (peer->rtt_count == 0) { in rxrpc_kernel_get_srtt()
519 *_srtt = call->peer->srtt_us >> 3; in rxrpc_kernel_get_srtt()