Lines Matching full:local
2 /* Local endpoint object management
42 void rxrpc_local_dont_fragment(const struct rxrpc_local *local, bool set) in rxrpc_local_dont_fragment() argument
45 ip_sock_set_mtu_discover(local->socket->sk, IP_PMTUDISC_DO); in rxrpc_local_dont_fragment()
47 ip_sock_set_mtu_discover(local->socket->sk, IP_PMTUDISC_DONT); in rxrpc_local_dont_fragment()
51 * Compare a local to an address. Return -ve, 0 or +ve to indicate less than,
59 static long rxrpc_local_cmp_key(const struct rxrpc_local *local, in rxrpc_local_cmp_key() argument
64 diff = ((local->srx.transport_type - srx->transport_type) ?: in rxrpc_local_cmp_key()
65 (local->srx.transport_len - srx->transport_len) ?: in rxrpc_local_cmp_key()
66 (local->srx.transport.family - srx->transport.family)); in rxrpc_local_cmp_key()
75 return ((u16 __force)local->srx.transport.sin.sin_port - in rxrpc_local_cmp_key()
77 memcmp(&local->srx.transport.sin.sin_addr, in rxrpc_local_cmp_key()
85 return ((u16 __force)local->srx.transport.sin6.sin6_port - in rxrpc_local_cmp_key()
87 memcmp(&local->srx.transport.sin6.sin6_addr, in rxrpc_local_cmp_key()
98 struct rxrpc_local *local = in rxrpc_client_conn_reap_timeout() local
101 if (!local->kill_all_client_conns && in rxrpc_client_conn_reap_timeout()
102 test_and_set_bit(RXRPC_CLIENT_CONN_REAP_TIMER, &local->client_conn_flags)) in rxrpc_client_conn_reap_timeout()
103 rxrpc_wake_up_io_thread(local); in rxrpc_client_conn_reap_timeout()
107 * Allocate a new local endpoint.
112 struct rxrpc_local *local; in rxrpc_alloc_local() local
115 local = kzalloc(sizeof(struct rxrpc_local), GFP_KERNEL); in rxrpc_alloc_local()
116 if (local) { in rxrpc_alloc_local()
117 refcount_set(&local->ref, 1); in rxrpc_alloc_local()
118 atomic_set(&local->active_users, 1); in rxrpc_alloc_local()
119 local->net = net; in rxrpc_alloc_local()
120 local->rxnet = rxrpc_net(net); in rxrpc_alloc_local()
121 INIT_HLIST_NODE(&local->link); in rxrpc_alloc_local()
122 init_completion(&local->io_thread_ready); in rxrpc_alloc_local()
124 skb_queue_head_init(&local->rx_delay_queue); in rxrpc_alloc_local()
126 skb_queue_head_init(&local->rx_queue); in rxrpc_alloc_local()
127 INIT_LIST_HEAD(&local->conn_attend_q); in rxrpc_alloc_local()
128 INIT_LIST_HEAD(&local->call_attend_q); in rxrpc_alloc_local()
130 local->client_bundles = RB_ROOT; in rxrpc_alloc_local()
131 spin_lock_init(&local->client_bundles_lock); in rxrpc_alloc_local()
132 local->kill_all_client_conns = false; in rxrpc_alloc_local()
133 INIT_LIST_HEAD(&local->idle_client_conns); in rxrpc_alloc_local()
134 timer_setup(&local->client_conn_reap_timer, in rxrpc_alloc_local()
137 spin_lock_init(&local->lock); in rxrpc_alloc_local()
138 rwlock_init(&local->services_lock); in rxrpc_alloc_local()
139 local->debug_id = atomic_inc_return(&rxrpc_debug_id); in rxrpc_alloc_local()
140 memcpy(&local->srx, srx, sizeof(*srx)); in rxrpc_alloc_local()
141 local->srx.srx_service = 0; in rxrpc_alloc_local()
142 idr_init(&local->conn_ids); in rxrpc_alloc_local()
147 idr_set_cursor(&local->conn_ids, tmp); in rxrpc_alloc_local()
148 INIT_LIST_HEAD(&local->new_client_calls); in rxrpc_alloc_local()
149 spin_lock_init(&local->client_call_lock); in rxrpc_alloc_local()
151 trace_rxrpc_local(local->debug_id, rxrpc_local_new, 1, 1); in rxrpc_alloc_local()
154 _leave(" = %p", local); in rxrpc_alloc_local()
155 return local; in rxrpc_alloc_local()
159 * create the local socket
162 static int rxrpc_open_socket(struct rxrpc_local *local, struct net *net) in rxrpc_open_socket() argument
165 struct sockaddr_rxrpc *srx = &local->srx; in rxrpc_open_socket()
172 local, srx->transport_type, srx->transport.family); in rxrpc_open_socket()
187 ret = udp_sock_create(net, &udp_conf, &local->socket); in rxrpc_open_socket()
196 tuncfg.sk_user_data = local; in rxrpc_open_socket()
197 setup_udp_tunnel_sock(net, local->socket, &tuncfg); in rxrpc_open_socket()
200 usk = local->socket->sk; in rxrpc_open_socket()
217 rxrpc_local_dont_fragment(local, true); in rxrpc_open_socket()
227 io_thread = kthread_run(rxrpc_io_thread, local, in rxrpc_open_socket()
234 wait_for_completion(&local->io_thread_ready); in rxrpc_open_socket()
235 WRITE_ONCE(local->io_thread, io_thread); in rxrpc_open_socket()
240 kernel_sock_shutdown(local->socket, SHUT_RDWR); in rxrpc_open_socket()
241 local->socket->sk->sk_user_data = NULL; in rxrpc_open_socket()
242 sock_release(local->socket); in rxrpc_open_socket()
243 local->socket = NULL; in rxrpc_open_socket()
248 * Look up or create a new local endpoint using the specified local address.
253 struct rxrpc_local *local; in rxrpc_lookup_local() local
265 local = hlist_entry(cursor, struct rxrpc_local, link); in rxrpc_lookup_local()
267 diff = rxrpc_local_cmp_key(local, srx); in rxrpc_lookup_local()
273 * but it may also still have the local transport address that in rxrpc_lookup_local()
277 local = NULL; in rxrpc_lookup_local()
283 * we're attempting to use a local address that the dying in rxrpc_lookup_local()
286 if (!rxrpc_use_local(local, rxrpc_local_use_lookup)) in rxrpc_lookup_local()
292 local = rxrpc_alloc_local(net, srx); in rxrpc_lookup_local()
293 if (!local) in rxrpc_lookup_local()
296 ret = rxrpc_open_socket(local, net); in rxrpc_lookup_local()
301 hlist_replace_rcu(cursor, &local->link); in rxrpc_lookup_local()
304 hlist_add_head_rcu(&local->link, &rxnet->local_endpoints); in rxrpc_lookup_local()
309 _leave(" = %p", local); in rxrpc_lookup_local()
310 return local; in rxrpc_lookup_local()
316 if (local) in rxrpc_lookup_local()
317 call_rcu(&local->rcu, rxrpc_local_rcu); in rxrpc_lookup_local()
328 * Get a ref on a local endpoint.
330 struct rxrpc_local *rxrpc_get_local(struct rxrpc_local *local, in rxrpc_get_local() argument
335 u = atomic_read(&local->active_users); in rxrpc_get_local()
336 __refcount_inc(&local->ref, &r); in rxrpc_get_local()
337 trace_rxrpc_local(local->debug_id, why, r + 1, u); in rxrpc_get_local()
338 return local; in rxrpc_get_local()
342 * Get a ref on a local endpoint unless its usage has already reached 0.
344 struct rxrpc_local *rxrpc_get_local_maybe(struct rxrpc_local *local, in rxrpc_get_local_maybe() argument
349 if (local && __refcount_inc_not_zero(&local->ref, &r)) { in rxrpc_get_local_maybe()
350 u = atomic_read(&local->active_users); in rxrpc_get_local_maybe()
351 trace_rxrpc_local(local->debug_id, why, r + 1, u); in rxrpc_get_local_maybe()
352 return local; in rxrpc_get_local_maybe()
359 * Drop a ref on a local endpoint.
361 void rxrpc_put_local(struct rxrpc_local *local, enum rxrpc_local_trace why) in rxrpc_put_local() argument
367 if (local) { in rxrpc_put_local()
368 debug_id = local->debug_id; in rxrpc_put_local()
370 u = atomic_read(&local->active_users); in rxrpc_put_local()
371 dead = __refcount_dec_and_test(&local->ref, &r); in rxrpc_put_local()
375 call_rcu(&local->rcu, rxrpc_local_rcu); in rxrpc_put_local()
380 * Start using a local endpoint.
382 struct rxrpc_local *rxrpc_use_local(struct rxrpc_local *local, in rxrpc_use_local() argument
385 local = rxrpc_get_local_maybe(local, rxrpc_local_get_for_use); in rxrpc_use_local()
386 if (!local) in rxrpc_use_local()
389 if (!__rxrpc_use_local(local, why)) { in rxrpc_use_local()
390 rxrpc_put_local(local, rxrpc_local_put_for_use); in rxrpc_use_local()
394 return local; in rxrpc_use_local()
398 * Cease using a local endpoint. Once the number of active users reaches 0, we
401 void rxrpc_unuse_local(struct rxrpc_local *local, enum rxrpc_local_trace why) in rxrpc_unuse_local() argument
406 if (local) { in rxrpc_unuse_local()
407 debug_id = local->debug_id; in rxrpc_unuse_local()
408 r = refcount_read(&local->ref); in rxrpc_unuse_local()
409 u = atomic_dec_return(&local->active_users); in rxrpc_unuse_local()
412 kthread_stop(local->io_thread); in rxrpc_unuse_local()
417 * Destroy a local endpoint's socket and then hand the record to RCU to dispose
423 void rxrpc_destroy_local(struct rxrpc_local *local) in rxrpc_destroy_local() argument
425 struct socket *socket = local->socket; in rxrpc_destroy_local()
426 struct rxrpc_net *rxnet = local->rxnet; in rxrpc_destroy_local()
428 _enter("%d", local->debug_id); in rxrpc_destroy_local()
430 local->dead = true; in rxrpc_destroy_local()
433 hlist_del_init_rcu(&local->link); in rxrpc_destroy_local()
436 rxrpc_clean_up_local_conns(local); in rxrpc_destroy_local()
438 ASSERT(!local->service); in rxrpc_destroy_local()
441 local->socket = NULL; in rxrpc_destroy_local()
448 * local endpoint. in rxrpc_destroy_local()
451 rxrpc_purge_queue(&local->rx_delay_queue); in rxrpc_destroy_local()
453 rxrpc_purge_queue(&local->rx_queue); in rxrpc_destroy_local()
454 rxrpc_purge_client_connections(local); in rxrpc_destroy_local()
458 * Destroy a local endpoint after the RCU grace period expires.
462 struct rxrpc_local *local = container_of(rcu, struct rxrpc_local, rcu); in rxrpc_local_rcu() local
464 rxrpc_see_local(local, rxrpc_local_free); in rxrpc_local_rcu()
465 kfree(local); in rxrpc_local_rcu()
469 * Verify the local endpoint list is empty by this point.
473 struct rxrpc_local *local; in rxrpc_destroy_all_locals() local
481 hlist_for_each_entry(local, &rxnet->local_endpoints, link) { in rxrpc_destroy_all_locals()
482 pr_err("AF_RXRPC: Leaked local %p {%d}\n", in rxrpc_destroy_all_locals()
483 local, refcount_read(&local->ref)); in rxrpc_destroy_all_locals()