Lines Matching full:local

2 /* Local endpoint object management
27 * Compare a local to an address. Return -ve, 0 or +ve to indicate less than,
35 static long rxrpc_local_cmp_key(const struct rxrpc_local *local, in rxrpc_local_cmp_key() argument
40 diff = ((local->srx.transport_type - srx->transport_type) ?: in rxrpc_local_cmp_key()
41 (local->srx.transport_len - srx->transport_len) ?: in rxrpc_local_cmp_key()
42 (local->srx.transport.family - srx->transport.family)); in rxrpc_local_cmp_key()
51 return ((u16 __force)local->srx.transport.sin.sin_port - in rxrpc_local_cmp_key()
53 memcmp(&local->srx.transport.sin.sin_addr, in rxrpc_local_cmp_key()
61 return ((u16 __force)local->srx.transport.sin6.sin6_port - in rxrpc_local_cmp_key()
63 memcmp(&local->srx.transport.sin6.sin6_addr, in rxrpc_local_cmp_key()
73 * Allocate a new local endpoint.
78 struct rxrpc_local *local; in rxrpc_alloc_local() local
80 local = kzalloc(sizeof(struct rxrpc_local), GFP_KERNEL); in rxrpc_alloc_local()
81 if (local) { in rxrpc_alloc_local()
82 refcount_set(&local->ref, 1); in rxrpc_alloc_local()
83 atomic_set(&local->active_users, 1); in rxrpc_alloc_local()
84 local->rxnet = rxnet; in rxrpc_alloc_local()
85 INIT_HLIST_NODE(&local->link); in rxrpc_alloc_local()
86 INIT_WORK(&local->processor, rxrpc_local_processor); in rxrpc_alloc_local()
87 init_rwsem(&local->defrag_sem); in rxrpc_alloc_local()
88 skb_queue_head_init(&local->reject_queue); in rxrpc_alloc_local()
89 skb_queue_head_init(&local->event_queue); in rxrpc_alloc_local()
90 local->client_bundles = RB_ROOT; in rxrpc_alloc_local()
91 spin_lock_init(&local->client_bundles_lock); in rxrpc_alloc_local()
92 spin_lock_init(&local->lock); in rxrpc_alloc_local()
93 rwlock_init(&local->services_lock); in rxrpc_alloc_local()
94 local->debug_id = atomic_inc_return(&rxrpc_debug_id); in rxrpc_alloc_local()
95 memcpy(&local->srx, srx, sizeof(*srx)); in rxrpc_alloc_local()
96 local->srx.srx_service = 0; in rxrpc_alloc_local()
97 trace_rxrpc_local(local->debug_id, rxrpc_local_new, 1, NULL); in rxrpc_alloc_local()
100 _leave(" = %p", local); in rxrpc_alloc_local()
101 return local; in rxrpc_alloc_local()
105 * create the local socket
108 static int rxrpc_open_socket(struct rxrpc_local *local, struct net *net) in rxrpc_open_socket() argument
111 struct sockaddr_rxrpc *srx = &local->srx; in rxrpc_open_socket()
117 local, srx->transport_type, srx->transport.family); in rxrpc_open_socket()
132 ret = udp_sock_create(net, &udp_conf, &local->socket); in rxrpc_open_socket()
141 tuncfg.sk_user_data = local; in rxrpc_open_socket()
142 setup_udp_tunnel_sock(net, local->socket, &tuncfg); in rxrpc_open_socket()
145 usk = local->socket->sk; in rxrpc_open_socket()
177 * Look up or create a new local endpoint using the specified local address.
182 struct rxrpc_local *local; in rxrpc_lookup_local() local
195 local = hlist_entry(cursor, struct rxrpc_local, link); in rxrpc_lookup_local()
197 diff = rxrpc_local_cmp_key(local, srx); in rxrpc_lookup_local()
203 * but it may also still have the local transport address that in rxrpc_lookup_local()
207 local = NULL; in rxrpc_lookup_local()
213 * we're attempting to use a local address that the dying in rxrpc_lookup_local()
216 if (!rxrpc_use_local(local)) in rxrpc_lookup_local()
223 local = rxrpc_alloc_local(rxnet, srx); in rxrpc_lookup_local()
224 if (!local) in rxrpc_lookup_local()
227 ret = rxrpc_open_socket(local, net); in rxrpc_lookup_local()
232 hlist_replace_rcu(cursor, &local->link); in rxrpc_lookup_local()
235 hlist_add_head_rcu(&local->link, &rxnet->local_endpoints); in rxrpc_lookup_local()
242 _net("LOCAL %s %d {%pISp}", in rxrpc_lookup_local()
243 age, local->debug_id, &local->srx.transport); in rxrpc_lookup_local()
245 _leave(" = %p", local); in rxrpc_lookup_local()
246 return local; in rxrpc_lookup_local()
252 if (local) in rxrpc_lookup_local()
253 call_rcu(&local->rcu, rxrpc_local_rcu); in rxrpc_lookup_local()
264 * Get a ref on a local endpoint.
266 struct rxrpc_local *rxrpc_get_local(struct rxrpc_local *local) in rxrpc_get_local() argument
271 __refcount_inc(&local->ref, &r); in rxrpc_get_local()
272 trace_rxrpc_local(local->debug_id, rxrpc_local_got, r + 1, here); in rxrpc_get_local()
273 return local; in rxrpc_get_local()
277 * Get a ref on a local endpoint unless its usage has already reached 0.
279 struct rxrpc_local *rxrpc_get_local_maybe(struct rxrpc_local *local) in rxrpc_get_local_maybe() argument
284 if (local) { in rxrpc_get_local_maybe()
285 if (__refcount_inc_not_zero(&local->ref, &r)) in rxrpc_get_local_maybe()
286 trace_rxrpc_local(local->debug_id, rxrpc_local_got, in rxrpc_get_local_maybe()
289 local = NULL; in rxrpc_get_local_maybe()
291 return local; in rxrpc_get_local_maybe()
295 * Queue a local endpoint and pass the caller's reference to the work item.
297 void rxrpc_queue_local(struct rxrpc_local *local) in rxrpc_queue_local() argument
300 unsigned int debug_id = local->debug_id; in rxrpc_queue_local()
301 int r = refcount_read(&local->ref); in rxrpc_queue_local()
303 if (rxrpc_queue_work(&local->processor)) in rxrpc_queue_local()
306 rxrpc_put_local(local); in rxrpc_queue_local()
310 * Drop a ref on a local endpoint.
312 void rxrpc_put_local(struct rxrpc_local *local) in rxrpc_put_local() argument
319 if (local) { in rxrpc_put_local()
320 debug_id = local->debug_id; in rxrpc_put_local()
322 dead = __refcount_dec_and_test(&local->ref, &r); in rxrpc_put_local()
326 call_rcu(&local->rcu, rxrpc_local_rcu); in rxrpc_put_local()
331 * Start using a local endpoint.
333 struct rxrpc_local *rxrpc_use_local(struct rxrpc_local *local) in rxrpc_use_local() argument
335 local = rxrpc_get_local_maybe(local); in rxrpc_use_local()
336 if (!local) in rxrpc_use_local()
339 if (!__rxrpc_use_local(local)) { in rxrpc_use_local()
340 rxrpc_put_local(local); in rxrpc_use_local()
344 return local; in rxrpc_use_local()
348 * Cease using a local endpoint. Once the number of active users reaches 0, we
351 void rxrpc_unuse_local(struct rxrpc_local *local) in rxrpc_unuse_local() argument
353 if (local) { in rxrpc_unuse_local()
354 if (__rxrpc_unuse_local(local)) { in rxrpc_unuse_local()
355 rxrpc_get_local(local); in rxrpc_unuse_local()
356 rxrpc_queue_local(local); in rxrpc_unuse_local()
362 * Destroy a local endpoint's socket and then hand the record to RCU to dispose
368 static void rxrpc_local_destroyer(struct rxrpc_local *local) in rxrpc_local_destroyer() argument
370 struct socket *socket = local->socket; in rxrpc_local_destroyer()
371 struct rxrpc_net *rxnet = local->rxnet; in rxrpc_local_destroyer()
373 _enter("%d", local->debug_id); in rxrpc_local_destroyer()
375 local->dead = true; in rxrpc_local_destroyer()
378 hlist_del_init_rcu(&local->link); in rxrpc_local_destroyer()
381 rxrpc_clean_up_local_conns(local); in rxrpc_local_destroyer()
383 ASSERT(!local->service); in rxrpc_local_destroyer()
386 local->socket = NULL; in rxrpc_local_destroyer()
393 * local endpoint. in rxrpc_local_destroyer()
395 rxrpc_purge_queue(&local->reject_queue); in rxrpc_local_destroyer()
396 rxrpc_purge_queue(&local->event_queue); in rxrpc_local_destroyer()
405 struct rxrpc_local *local = in rxrpc_local_processor() local
409 if (local->dead) in rxrpc_local_processor()
412 trace_rxrpc_local(local->debug_id, rxrpc_local_processing, in rxrpc_local_processor()
413 refcount_read(&local->ref), NULL); in rxrpc_local_processor()
417 if (!__rxrpc_use_local(local)) { in rxrpc_local_processor()
418 rxrpc_local_destroyer(local); in rxrpc_local_processor()
422 if (!skb_queue_empty(&local->reject_queue)) { in rxrpc_local_processor()
423 rxrpc_reject_packets(local); in rxrpc_local_processor()
427 if (!skb_queue_empty(&local->event_queue)) { in rxrpc_local_processor()
428 rxrpc_process_local_events(local); in rxrpc_local_processor()
432 __rxrpc_unuse_local(local); in rxrpc_local_processor()
435 rxrpc_put_local(local); in rxrpc_local_processor()
439 * Destroy a local endpoint after the RCU grace period expires.
443 struct rxrpc_local *local = container_of(rcu, struct rxrpc_local, rcu); in rxrpc_local_rcu() local
445 _enter("%d", local->debug_id); in rxrpc_local_rcu()
447 ASSERT(!work_pending(&local->processor)); in rxrpc_local_rcu()
449 _net("DESTROY LOCAL %d", local->debug_id); in rxrpc_local_rcu()
450 kfree(local); in rxrpc_local_rcu()
455 * Verify the local endpoint list is empty by this point.
459 struct rxrpc_local *local; in rxrpc_destroy_all_locals() local
467 hlist_for_each_entry(local, &rxnet->local_endpoints, link) { in rxrpc_destroy_all_locals()
468 pr_err("AF_RXRPC: Leaked local %p {%d}\n", in rxrpc_destroy_all_locals()
469 local, refcount_read(&local->ref)); in rxrpc_destroy_all_locals()