2019-05-20 17:08:01 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
2016-04-04 13:00:34 +00:00
|
|
|
/* Local endpoint object management
|
2007-04-26 22:48:28 +00:00
|
|
|
*
|
2016-04-04 13:00:35 +00:00
|
|
|
* Copyright (C) 2016 Red Hat, Inc. All Rights Reserved.
|
2007-04-26 22:48:28 +00:00
|
|
|
* Written by David Howells (dhowells@redhat.com)
|
|
|
|
*/
|
|
|
|
|
2016-06-02 19:08:52 +00:00
|
|
|
#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
|
|
|
|
|
2007-04-26 22:48:28 +00:00
|
|
|
#include <linux/module.h>
|
|
|
|
#include <linux/net.h>
|
|
|
|
#include <linux/skbuff.h>
|
include cleanup: Update gfp.h and slab.h includes to prepare for breaking implicit slab.h inclusion from percpu.h
percpu.h is included by sched.h and module.h and thus ends up being
included when building most .c files. percpu.h includes slab.h which
in turn includes gfp.h making everything defined by the two files
universally available and complicating inclusion dependencies.
percpu.h -> slab.h dependency is about to be removed. Prepare for
this change by updating users of gfp and slab facilities include those
headers directly instead of assuming availability. As this conversion
needs to touch large number of source files, the following script is
used as the basis of conversion.
http://userweb.kernel.org/~tj/misc/slabh-sweep.py
The script does the followings.
* Scan files for gfp and slab usages and update includes such that
only the necessary includes are there. ie. if only gfp is used,
gfp.h, if slab is used, slab.h.
* When the script inserts a new include, it looks at the include
blocks and try to put the new include such that its order conforms
to its surrounding. It's put in the include block which contains
core kernel includes, in the same order that the rest are ordered -
alphabetical, Christmas tree, rev-Xmas-tree or at the end if there
doesn't seem to be any matching order.
* If the script can't find a place to put a new include (mostly
because the file doesn't have fitting include block), it prints out
an error message indicating which .h file needs to be added to the
file.
The conversion was done in the following steps.
1. The initial automatic conversion of all .c files updated slightly
over 4000 files, deleting around 700 includes and adding ~480 gfp.h
and ~3000 slab.h inclusions. The script emitted errors for ~400
files.
2. Each error was manually checked. Some didn't need the inclusion,
some needed manual addition while adding it to implementation .h or
embedding .c file was more appropriate for others. This step added
inclusions to around 150 files.
3. The script was run again and the output was compared to the edits
from #2 to make sure no file was left behind.
4. Several build tests were done and a couple of problems were fixed.
e.g. lib/decompress_*.c used malloc/free() wrappers around slab
APIs requiring slab.h to be added manually.
5. The script was run on all .h files but without automatically
editing them as sprinkling gfp.h and slab.h inclusions around .h
files could easily lead to inclusion dependency hell. Most gfp.h
inclusion directives were ignored as stuff from gfp.h was usually
wildly available and often used in preprocessor macros. Each
slab.h inclusion directive was examined and added manually as
necessary.
6. percpu.h was updated not to include slab.h.
7. Build test were done on the following configurations and failures
were fixed. CONFIG_GCOV_KERNEL was turned off for all tests (as my
distributed build env didn't work with gcov compiles) and a few
more options had to be turned off depending on archs to make things
build (like ipr on powerpc/64 which failed due to missing writeq).
* x86 and x86_64 UP and SMP allmodconfig and a custom test config.
* powerpc and powerpc64 SMP allmodconfig
* sparc and sparc64 SMP allmodconfig
* ia64 SMP allmodconfig
* s390 SMP allmodconfig
* alpha SMP allmodconfig
* um on x86_64 SMP allmodconfig
8. percpu.h modifications were reverted so that it could be applied as
a separate patch and serve as bisection point.
Given the fact that I had only a couple of failures from tests on step
6, I'm fairly confident about the coverage of this conversion patch.
If there is a breakage, it's likely to be something in one of the arch
headers which should be easily discoverable easily on most builds of
the specific arch.
Signed-off-by: Tejun Heo <tj@kernel.org>
Guess-its-ok-by: Christoph Lameter <cl@linux-foundation.org>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Lee Schermerhorn <Lee.Schermerhorn@hp.com>
2010-03-24 08:04:11 +00:00
|
|
|
#include <linux/slab.h>
|
2015-04-01 15:31:26 +00:00
|
|
|
#include <linux/udp.h>
|
|
|
|
#include <linux/ip.h>
|
2016-04-04 13:00:35 +00:00
|
|
|
#include <linux/hashtable.h>
|
2007-04-26 22:48:28 +00:00
|
|
|
#include <net/sock.h>
|
2018-10-04 10:10:51 +00:00
|
|
|
#include <net/udp.h>
|
2021-02-03 08:54:23 +00:00
|
|
|
#include <net/udp_tunnel.h>
|
2007-04-26 22:48:28 +00:00
|
|
|
#include <net/af_rxrpc.h>
|
|
|
|
#include "ar-internal.h"
|
|
|
|
|
2016-04-04 13:00:35 +00:00
|
|
|
static void rxrpc_local_processor(struct work_struct *);
|
|
|
|
static void rxrpc_local_rcu(struct rcu_head *);
|
2007-04-26 22:48:28 +00:00
|
|
|
|
|
|
|
/*
|
2016-04-04 13:00:35 +00:00
|
|
|
* Compare a local to an address. Return -ve, 0 or +ve to indicate less than,
|
|
|
|
* same or greater than.
|
|
|
|
*
|
|
|
|
* We explicitly don't compare the RxRPC service ID as we want to reject
|
|
|
|
* conflicting uses by differing services. Further, we don't want to share
|
|
|
|
* addresses with different options (IPv6), so we don't compare those bits
|
|
|
|
* either.
|
2007-04-26 22:48:28 +00:00
|
|
|
*/
|
2016-04-04 13:00:35 +00:00
|
|
|
static long rxrpc_local_cmp_key(const struct rxrpc_local *local,
|
|
|
|
const struct sockaddr_rxrpc *srx)
|
|
|
|
{
|
|
|
|
long diff;
|
|
|
|
|
|
|
|
diff = ((local->srx.transport_type - srx->transport_type) ?:
|
|
|
|
(local->srx.transport_len - srx->transport_len) ?:
|
|
|
|
(local->srx.transport.family - srx->transport.family));
|
|
|
|
if (diff != 0)
|
|
|
|
return diff;
|
|
|
|
|
|
|
|
switch (srx->transport.family) {
|
|
|
|
case AF_INET:
|
|
|
|
/* If the choice of UDP port is left up to the transport, then
|
|
|
|
* the endpoint record doesn't match.
|
|
|
|
*/
|
|
|
|
return ((u16 __force)local->srx.transport.sin.sin_port -
|
|
|
|
(u16 __force)srx->transport.sin.sin_port) ?:
|
|
|
|
memcmp(&local->srx.transport.sin.sin_addr,
|
|
|
|
&srx->transport.sin.sin_addr,
|
|
|
|
sizeof(struct in_addr));
|
2016-09-17 06:26:01 +00:00
|
|
|
#ifdef CONFIG_AF_RXRPC_IPV6
|
2016-09-13 07:49:05 +00:00
|
|
|
case AF_INET6:
|
|
|
|
/* If the choice of UDP6 port is left up to the transport, then
|
|
|
|
* the endpoint record doesn't match.
|
|
|
|
*/
|
|
|
|
return ((u16 __force)local->srx.transport.sin6.sin6_port -
|
|
|
|
(u16 __force)srx->transport.sin6.sin6_port) ?:
|
|
|
|
memcmp(&local->srx.transport.sin6.sin6_addr,
|
|
|
|
&srx->transport.sin6.sin6_addr,
|
|
|
|
sizeof(struct in6_addr));
|
2016-09-17 06:26:01 +00:00
|
|
|
#endif
|
2016-04-04 13:00:35 +00:00
|
|
|
default:
|
|
|
|
BUG();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Allocate a new local endpoint.
|
|
|
|
*/
|
2017-05-24 16:02:32 +00:00
|
|
|
static struct rxrpc_local *rxrpc_alloc_local(struct rxrpc_net *rxnet,
|
|
|
|
const struct sockaddr_rxrpc *srx)
|
2007-04-26 22:48:28 +00:00
|
|
|
{
|
|
|
|
struct rxrpc_local *local;
|
|
|
|
|
|
|
|
local = kzalloc(sizeof(struct rxrpc_local), GFP_KERNEL);
|
|
|
|
if (local) {
|
2022-05-21 07:45:22 +00:00
|
|
|
refcount_set(&local->ref, 1);
|
2019-08-09 14:20:41 +00:00
|
|
|
atomic_set(&local->active_users, 1);
|
2017-05-24 16:02:32 +00:00
|
|
|
local->rxnet = rxnet;
|
2022-05-21 07:45:15 +00:00
|
|
|
INIT_HLIST_NODE(&local->link);
|
2016-04-04 13:00:35 +00:00
|
|
|
INIT_WORK(&local->processor, rxrpc_local_processor);
|
2007-04-26 22:48:28 +00:00
|
|
|
init_rwsem(&local->defrag_sem);
|
|
|
|
skb_queue_head_init(&local->reject_queue);
|
2015-04-01 15:31:26 +00:00
|
|
|
skb_queue_head_init(&local->event_queue);
|
rxrpc: Rewrite the client connection manager
Rewrite the rxrpc client connection manager so that it can support multiple
connections for a given security key to a peer. The following changes are
made:
(1) For each open socket, the code currently maintains an rbtree with the
connections placed into it, keyed by communications parameters. This
is tricky to maintain as connections can be culled from the tree or
replaced within it. Connections can require replacement for a number
of reasons, e.g. their IDs span too great a range for the IDR data
type to represent efficiently, the call ID numbers on that conn would
overflow or the conn got aborted.
This is changed so that there's now a connection bundle object placed
in the tree, keyed on the same parameters. The bundle, however, does
not need to be replaced.
(2) An rxrpc_bundle object can now manage the available channels for a set
of parallel connections. The lock that manages this is moved there
from the rxrpc_connection struct (channel_lock).
(3) There'a a dummy bundle for all incoming connections to share so that
they have a channel_lock too. It might be better to give each
incoming connection its own bundle. This bundle is not needed to
manage which channels incoming calls are made on because that's the
solely at whim of the client.
(4) The restrictions on how many client connections are around are
removed. Instead, a previous patch limits the number of client calls
that can be allocated. Ordinarily, client connections are reaped
after 2 minutes on the idle queue, but when more than a certain number
of connections are in existence, the reaper starts reaping them after
2s of idleness instead to get the numbers back down.
It could also be made such that new call allocations are forced to
wait until the number of outstanding connections subsides.
Signed-off-by: David Howells <dhowells@redhat.com>
2020-07-01 10:15:32 +00:00
|
|
|
local->client_bundles = RB_ROOT;
|
|
|
|
spin_lock_init(&local->client_bundles_lock);
|
2007-04-26 22:48:28 +00:00
|
|
|
spin_lock_init(&local->lock);
|
|
|
|
rwlock_init(&local->services_lock);
|
|
|
|
local->debug_id = atomic_inc_return(&rxrpc_debug_id);
|
|
|
|
memcpy(&local->srx, srx, sizeof(*srx));
|
2017-06-05 13:30:49 +00:00
|
|
|
local->srx.srx_service = 0;
|
2019-08-13 21:26:36 +00:00
|
|
|
trace_rxrpc_local(local->debug_id, rxrpc_local_new, 1, NULL);
|
2007-04-26 22:48:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
_leave(" = %p", local);
|
|
|
|
return local;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* create the local socket
|
2016-04-04 13:00:35 +00:00
|
|
|
* - must be called with rxrpc_local_mutex locked
|
2007-04-26 22:48:28 +00:00
|
|
|
*/
|
2017-05-24 16:02:32 +00:00
|
|
|
static int rxrpc_open_socket(struct rxrpc_local *local, struct net *net)
|
2007-04-26 22:48:28 +00:00
|
|
|
{
|
2021-02-07 08:23:14 +00:00
|
|
|
struct udp_tunnel_sock_cfg tuncfg = {NULL};
|
|
|
|
struct sockaddr_rxrpc *srx = &local->srx;
|
|
|
|
struct udp_port_cfg udp_conf = {0};
|
2018-10-04 10:10:51 +00:00
|
|
|
struct sock *usk;
|
2020-05-28 05:12:32 +00:00
|
|
|
int ret;
|
2007-04-26 22:48:28 +00:00
|
|
|
|
2016-09-13 07:49:05 +00:00
|
|
|
_enter("%p{%d,%d}",
|
2021-02-07 08:23:14 +00:00
|
|
|
local, srx->transport_type, srx->transport.family);
|
|
|
|
|
|
|
|
udp_conf.family = srx->transport.family;
|
2022-04-29 20:05:16 +00:00
|
|
|
udp_conf.use_udp_checksums = true;
|
2021-02-07 08:23:14 +00:00
|
|
|
if (udp_conf.family == AF_INET) {
|
|
|
|
udp_conf.local_ip = srx->transport.sin.sin_addr;
|
|
|
|
udp_conf.local_udp_port = srx->transport.sin.sin_port;
|
2021-02-12 10:48:14 +00:00
|
|
|
#if IS_ENABLED(CONFIG_AF_RXRPC_IPV6)
|
2021-02-07 08:23:14 +00:00
|
|
|
} else {
|
|
|
|
udp_conf.local_ip6 = srx->transport.sin6.sin6_addr;
|
|
|
|
udp_conf.local_udp_port = srx->transport.sin6.sin6_port;
|
2022-04-29 20:05:16 +00:00
|
|
|
udp_conf.use_udp6_tx_checksums = true;
|
|
|
|
udp_conf.use_udp6_rx_checksums = true;
|
2021-02-12 10:48:14 +00:00
|
|
|
#endif
|
2021-02-07 08:23:14 +00:00
|
|
|
}
|
|
|
|
ret = udp_sock_create(net, &udp_conf, &local->socket);
|
2007-04-26 22:48:28 +00:00
|
|
|
if (ret < 0) {
|
|
|
|
_leave(" = %d [socket]", ret);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2021-02-07 08:23:14 +00:00
|
|
|
tuncfg.encap_type = UDP_ENCAP_RXRPC;
|
|
|
|
tuncfg.encap_rcv = rxrpc_input_packet;
|
2022-08-26 14:39:28 +00:00
|
|
|
tuncfg.encap_err_rcv = rxrpc_encap_err_rcv;
|
2021-02-07 08:23:14 +00:00
|
|
|
tuncfg.sk_user_data = local;
|
|
|
|
setup_udp_tunnel_sock(net, local->socket, &tuncfg);
|
|
|
|
|
2018-10-05 13:05:35 +00:00
|
|
|
/* set the socket up */
|
2018-10-04 10:10:51 +00:00
|
|
|
usk = local->socket->sk;
|
|
|
|
usk->sk_error_report = rxrpc_error_report;
|
2018-10-05 13:05:35 +00:00
|
|
|
|
2021-02-07 08:23:14 +00:00
|
|
|
switch (srx->transport.family) {
|
2018-09-27 14:13:09 +00:00
|
|
|
case AF_INET6:
|
|
|
|
/* we want to receive ICMPv6 errors */
|
2021-02-07 08:23:14 +00:00
|
|
|
ip6_sock_set_recverr(usk);
|
2007-04-26 22:48:28 +00:00
|
|
|
|
2018-09-27 14:13:09 +00:00
|
|
|
/* Fall through and set IPv4 options too otherwise we don't get
|
|
|
|
* errors from IPv4 packets sent through the IPv6 socket.
|
|
|
|
*/
|
2020-08-23 22:36:59 +00:00
|
|
|
fallthrough;
|
2018-09-27 14:13:09 +00:00
|
|
|
case AF_INET:
|
2018-05-10 22:26:00 +00:00
|
|
|
/* we want to receive ICMP errors */
|
2021-02-07 08:23:14 +00:00
|
|
|
ip_sock_set_recverr(usk);
|
2018-05-10 22:26:00 +00:00
|
|
|
|
|
|
|
/* we want to set the don't fragment bit */
|
2021-02-07 08:23:14 +00:00
|
|
|
ip_sock_set_mtu_discover(usk, IP_PMTUDISC_DO);
|
2018-09-27 14:13:08 +00:00
|
|
|
|
|
|
|
/* We want receive timestamps. */
|
2021-02-07 08:23:14 +00:00
|
|
|
sock_enable_timestamps(usk);
|
2018-05-10 22:26:00 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
BUG();
|
2007-04-26 22:48:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
_leave(" = 0");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2016-04-04 13:00:35 +00:00
|
|
|
* Look up or create a new local endpoint using the specified local address.
|
2007-04-26 22:48:28 +00:00
|
|
|
*/
|
2017-05-24 16:02:32 +00:00
|
|
|
struct rxrpc_local *rxrpc_lookup_local(struct net *net,
|
|
|
|
const struct sockaddr_rxrpc *srx)
|
2007-04-26 22:48:28 +00:00
|
|
|
{
|
|
|
|
struct rxrpc_local *local;
|
2017-05-24 16:02:32 +00:00
|
|
|
struct rxrpc_net *rxnet = rxrpc_net(net);
|
2022-05-21 07:45:15 +00:00
|
|
|
struct hlist_node *cursor;
|
2016-04-04 13:00:35 +00:00
|
|
|
const char *age;
|
|
|
|
long diff;
|
2007-04-26 22:48:28 +00:00
|
|
|
int ret;
|
|
|
|
|
2016-09-13 07:49:05 +00:00
|
|
|
_enter("{%d,%d,%pISp}",
|
|
|
|
srx->transport_type, srx->transport.family, &srx->transport);
|
2007-04-26 22:48:28 +00:00
|
|
|
|
2017-05-24 16:02:32 +00:00
|
|
|
mutex_lock(&rxnet->local_mutex);
|
2007-04-26 22:48:28 +00:00
|
|
|
|
2022-05-21 07:45:15 +00:00
|
|
|
hlist_for_each(cursor, &rxnet->local_endpoints) {
|
|
|
|
local = hlist_entry(cursor, struct rxrpc_local, link);
|
2007-04-26 22:48:28 +00:00
|
|
|
|
2016-04-04 13:00:35 +00:00
|
|
|
diff = rxrpc_local_cmp_key(local, srx);
|
2022-05-21 07:45:15 +00:00
|
|
|
if (diff != 0)
|
2007-04-26 22:48:28 +00:00
|
|
|
continue;
|
2016-04-04 13:00:35 +00:00
|
|
|
|
|
|
|
/* Services aren't allowed to share transport sockets, so
|
|
|
|
* reject that here. It is possible that the object is dying -
|
|
|
|
* but it may also still have the local transport address that
|
|
|
|
* we want bound.
|
|
|
|
*/
|
|
|
|
if (srx->srx_service) {
|
|
|
|
local = NULL;
|
|
|
|
goto addr_in_use;
|
|
|
|
}
|
2007-04-26 22:48:28 +00:00
|
|
|
|
2022-05-21 07:45:15 +00:00
|
|
|
/* Found a match. We want to replace a dying object.
|
|
|
|
* Attempting to bind the transport socket may still fail if
|
|
|
|
* we're attempting to use a local address that the dying
|
|
|
|
* object is still using.
|
2016-04-04 13:00:35 +00:00
|
|
|
*/
|
2019-08-09 14:20:41 +00:00
|
|
|
if (!rxrpc_use_local(local))
|
2016-04-04 13:00:35 +00:00
|
|
|
break;
|
2007-04-26 22:48:28 +00:00
|
|
|
|
2016-04-04 13:00:35 +00:00
|
|
|
age = "old";
|
|
|
|
goto found;
|
|
|
|
}
|
2007-04-26 22:48:28 +00:00
|
|
|
|
2017-05-24 16:02:32 +00:00
|
|
|
local = rxrpc_alloc_local(rxnet, srx);
|
2016-04-04 13:00:35 +00:00
|
|
|
if (!local)
|
|
|
|
goto nomem;
|
2007-04-26 22:48:28 +00:00
|
|
|
|
2017-05-24 16:02:32 +00:00
|
|
|
ret = rxrpc_open_socket(local, net);
|
2016-04-04 13:00:35 +00:00
|
|
|
if (ret < 0)
|
|
|
|
goto sock_error;
|
|
|
|
|
2022-05-21 07:45:15 +00:00
|
|
|
if (cursor) {
|
|
|
|
hlist_replace_rcu(cursor, &local->link);
|
|
|
|
cursor->pprev = NULL;
|
|
|
|
} else {
|
|
|
|
hlist_add_head_rcu(&local->link, &rxnet->local_endpoints);
|
|
|
|
}
|
2016-04-04 13:00:35 +00:00
|
|
|
age = "new";
|
2007-04-26 22:48:28 +00:00
|
|
|
|
2016-04-04 13:00:35 +00:00
|
|
|
found:
|
2017-05-24 16:02:32 +00:00
|
|
|
mutex_unlock(&rxnet->local_mutex);
|
2007-04-26 22:48:28 +00:00
|
|
|
|
2016-09-13 07:49:05 +00:00
|
|
|
_net("LOCAL %s %d {%pISp}",
|
|
|
|
age, local->debug_id, &local->srx.transport);
|
2007-04-26 22:48:28 +00:00
|
|
|
|
2016-04-04 13:00:35 +00:00
|
|
|
_leave(" = %p", local);
|
2007-04-26 22:48:28 +00:00
|
|
|
return local;
|
|
|
|
|
2016-04-04 13:00:35 +00:00
|
|
|
nomem:
|
|
|
|
ret = -ENOMEM;
|
|
|
|
sock_error:
|
2017-05-24 16:02:32 +00:00
|
|
|
mutex_unlock(&rxnet->local_mutex);
|
2019-04-24 16:44:11 +00:00
|
|
|
if (local)
|
|
|
|
call_rcu(&local->rcu, rxrpc_local_rcu);
|
2016-04-04 13:00:35 +00:00
|
|
|
_leave(" = %d", ret);
|
|
|
|
return ERR_PTR(ret);
|
2007-04-26 22:48:28 +00:00
|
|
|
|
2016-04-04 13:00:35 +00:00
|
|
|
addr_in_use:
|
2017-05-24 16:02:32 +00:00
|
|
|
mutex_unlock(&rxnet->local_mutex);
|
2016-04-04 13:00:35 +00:00
|
|
|
_leave(" = -EADDRINUSE");
|
|
|
|
return ERR_PTR(-EADDRINUSE);
|
|
|
|
}
|
2007-04-26 22:48:28 +00:00
|
|
|
|
2018-03-30 20:05:28 +00:00
|
|
|
/*
|
|
|
|
* Get a ref on a local endpoint.
|
|
|
|
*/
|
|
|
|
struct rxrpc_local *rxrpc_get_local(struct rxrpc_local *local)
|
|
|
|
{
|
|
|
|
const void *here = __builtin_return_address(0);
|
2022-05-21 07:45:22 +00:00
|
|
|
int r;
|
2018-03-30 20:05:28 +00:00
|
|
|
|
2022-05-21 07:45:22 +00:00
|
|
|
__refcount_inc(&local->ref, &r);
|
|
|
|
trace_rxrpc_local(local->debug_id, rxrpc_local_got, r + 1, here);
|
2018-03-30 20:05:28 +00:00
|
|
|
return local;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Get a ref on a local endpoint unless its usage has already reached 0.
|
|
|
|
*/
|
|
|
|
struct rxrpc_local *rxrpc_get_local_maybe(struct rxrpc_local *local)
|
|
|
|
{
|
|
|
|
const void *here = __builtin_return_address(0);
|
2022-05-21 07:45:22 +00:00
|
|
|
int r;
|
2018-03-30 20:05:28 +00:00
|
|
|
|
|
|
|
if (local) {
|
2022-05-21 07:45:22 +00:00
|
|
|
if (__refcount_inc_not_zero(&local->ref, &r))
|
2019-08-13 21:26:36 +00:00
|
|
|
trace_rxrpc_local(local->debug_id, rxrpc_local_got,
|
2022-05-21 07:45:22 +00:00
|
|
|
r + 1, here);
|
2018-03-30 20:05:28 +00:00
|
|
|
else
|
|
|
|
local = NULL;
|
|
|
|
}
|
|
|
|
return local;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2019-08-13 21:26:36 +00:00
|
|
|
* Queue a local endpoint and pass the caller's reference to the work item.
|
2018-03-30 20:05:28 +00:00
|
|
|
*/
|
|
|
|
void rxrpc_queue_local(struct rxrpc_local *local)
|
|
|
|
{
|
|
|
|
const void *here = __builtin_return_address(0);
|
2019-08-13 21:26:36 +00:00
|
|
|
unsigned int debug_id = local->debug_id;
|
2022-05-21 07:45:22 +00:00
|
|
|
int r = refcount_read(&local->ref);
|
2018-03-30 20:05:28 +00:00
|
|
|
|
|
|
|
if (rxrpc_queue_work(&local->processor))
|
2022-05-21 07:45:22 +00:00
|
|
|
trace_rxrpc_local(debug_id, rxrpc_local_queued, r + 1, here);
|
2019-08-09 14:20:41 +00:00
|
|
|
else
|
|
|
|
rxrpc_put_local(local);
|
2007-04-26 22:48:28 +00:00
|
|
|
}
|
|
|
|
|
2018-03-30 20:05:28 +00:00
|
|
|
/*
|
|
|
|
* Drop a ref on a local endpoint.
|
|
|
|
*/
|
|
|
|
void rxrpc_put_local(struct rxrpc_local *local)
|
|
|
|
{
|
|
|
|
const void *here = __builtin_return_address(0);
|
2020-01-30 21:50:35 +00:00
|
|
|
unsigned int debug_id;
|
2022-05-21 07:45:22 +00:00
|
|
|
bool dead;
|
|
|
|
int r;
|
2018-03-30 20:05:28 +00:00
|
|
|
|
|
|
|
if (local) {
|
2020-01-30 21:50:35 +00:00
|
|
|
debug_id = local->debug_id;
|
|
|
|
|
2022-05-21 07:45:22 +00:00
|
|
|
dead = __refcount_dec_and_test(&local->ref, &r);
|
|
|
|
trace_rxrpc_local(debug_id, rxrpc_local_put, r, here);
|
2018-03-30 20:05:28 +00:00
|
|
|
|
2022-05-21 07:45:22 +00:00
|
|
|
if (dead)
|
2019-08-09 14:20:41 +00:00
|
|
|
call_rcu(&local->rcu, rxrpc_local_rcu);
|
2018-03-30 20:05:28 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-08-09 14:20:41 +00:00
|
|
|
/*
|
|
|
|
* Start using a local endpoint.
|
|
|
|
*/
|
|
|
|
struct rxrpc_local *rxrpc_use_local(struct rxrpc_local *local)
|
|
|
|
{
|
|
|
|
local = rxrpc_get_local_maybe(local);
|
|
|
|
if (!local)
|
|
|
|
return NULL;
|
|
|
|
|
2020-01-30 21:50:36 +00:00
|
|
|
if (!__rxrpc_use_local(local)) {
|
2019-08-09 14:20:41 +00:00
|
|
|
rxrpc_put_local(local);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return local;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Cease using a local endpoint. Once the number of active users reaches 0, we
|
|
|
|
* start the closure of the transport in the work processor.
|
|
|
|
*/
|
|
|
|
void rxrpc_unuse_local(struct rxrpc_local *local)
|
|
|
|
{
|
2019-08-09 21:47:47 +00:00
|
|
|
if (local) {
|
2020-01-30 21:50:36 +00:00
|
|
|
if (__rxrpc_unuse_local(local)) {
|
|
|
|
rxrpc_get_local(local);
|
2019-08-09 21:47:47 +00:00
|
|
|
rxrpc_queue_local(local);
|
2020-01-30 21:50:36 +00:00
|
|
|
}
|
2019-08-09 21:47:47 +00:00
|
|
|
}
|
2019-08-09 14:20:41 +00:00
|
|
|
}
|
|
|
|
|
2007-04-26 22:48:28 +00:00
|
|
|
/*
|
2016-04-04 13:00:35 +00:00
|
|
|
* Destroy a local endpoint's socket and then hand the record to RCU to dispose
|
|
|
|
* of.
|
|
|
|
*
|
|
|
|
* Closing the socket cannot be done from bottom half context or RCU callback
|
|
|
|
* context because it might sleep.
|
2007-04-26 22:48:28 +00:00
|
|
|
*/
|
2016-04-04 13:00:35 +00:00
|
|
|
static void rxrpc_local_destroyer(struct rxrpc_local *local)
|
2007-04-26 22:48:28 +00:00
|
|
|
{
|
2016-04-04 13:00:35 +00:00
|
|
|
struct socket *socket = local->socket;
|
2017-05-24 16:02:32 +00:00
|
|
|
struct rxrpc_net *rxnet = local->rxnet;
|
2007-04-26 22:48:28 +00:00
|
|
|
|
2016-04-04 13:00:35 +00:00
|
|
|
_enter("%d", local->debug_id);
|
2007-04-26 22:48:28 +00:00
|
|
|
|
2019-08-29 13:12:11 +00:00
|
|
|
local->dead = true;
|
|
|
|
|
2017-05-24 16:02:32 +00:00
|
|
|
mutex_lock(&rxnet->local_mutex);
|
2022-05-21 07:45:15 +00:00
|
|
|
hlist_del_init_rcu(&local->link);
|
2017-05-24 16:02:32 +00:00
|
|
|
mutex_unlock(&rxnet->local_mutex);
|
2016-04-04 13:00:35 +00:00
|
|
|
|
2019-08-29 13:12:11 +00:00
|
|
|
rxrpc_clean_up_local_conns(local);
|
|
|
|
rxrpc_service_connection_reaper(&rxnet->service_conn_reaper);
|
2016-09-29 21:37:15 +00:00
|
|
|
ASSERT(!local->service);
|
2016-04-04 13:00:35 +00:00
|
|
|
|
|
|
|
if (socket) {
|
|
|
|
local->socket = NULL;
|
|
|
|
kernel_sock_shutdown(socket, SHUT_RDWR);
|
|
|
|
socket->sk->sk_user_data = NULL;
|
|
|
|
sock_release(socket);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* At this point, there should be no more packets coming in to the
|
|
|
|
* local endpoint.
|
|
|
|
*/
|
|
|
|
rxrpc_purge_queue(&local->reject_queue);
|
|
|
|
rxrpc_purge_queue(&local->event_queue);
|
2007-04-26 22:48:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2019-08-09 14:20:41 +00:00
|
|
|
* Process events on an endpoint. The work item carries a ref which
|
|
|
|
* we must release.
|
2007-04-26 22:48:28 +00:00
|
|
|
*/
|
2016-04-04 13:00:35 +00:00
|
|
|
static void rxrpc_local_processor(struct work_struct *work)
|
2007-04-26 22:48:28 +00:00
|
|
|
{
|
|
|
|
struct rxrpc_local *local =
|
2016-04-04 13:00:35 +00:00
|
|
|
container_of(work, struct rxrpc_local, processor);
|
|
|
|
bool again;
|
2007-04-26 22:48:28 +00:00
|
|
|
|
2019-08-13 21:26:36 +00:00
|
|
|
trace_rxrpc_local(local->debug_id, rxrpc_local_processing,
|
2022-05-21 07:45:22 +00:00
|
|
|
refcount_read(&local->ref), NULL);
|
2007-04-26 22:48:28 +00:00
|
|
|
|
2016-04-04 13:00:35 +00:00
|
|
|
do {
|
|
|
|
again = false;
|
2020-01-30 21:50:36 +00:00
|
|
|
if (!__rxrpc_use_local(local)) {
|
2019-08-09 14:20:41 +00:00
|
|
|
rxrpc_local_destroyer(local);
|
|
|
|
break;
|
|
|
|
}
|
2007-04-26 22:48:28 +00:00
|
|
|
|
2016-04-04 13:00:35 +00:00
|
|
|
if (!skb_queue_empty(&local->reject_queue)) {
|
|
|
|
rxrpc_reject_packets(local);
|
|
|
|
again = true;
|
|
|
|
}
|
2007-04-26 22:48:28 +00:00
|
|
|
|
2016-04-04 13:00:35 +00:00
|
|
|
if (!skb_queue_empty(&local->event_queue)) {
|
|
|
|
rxrpc_process_local_events(local);
|
|
|
|
again = true;
|
|
|
|
}
|
2020-01-30 21:50:36 +00:00
|
|
|
|
|
|
|
__rxrpc_unuse_local(local);
|
2016-04-04 13:00:35 +00:00
|
|
|
} while (again);
|
2019-08-09 14:20:41 +00:00
|
|
|
|
|
|
|
rxrpc_put_local(local);
|
2016-04-04 13:00:35 +00:00
|
|
|
}
|
2007-04-26 22:48:28 +00:00
|
|
|
|
2016-04-04 13:00:35 +00:00
|
|
|
/*
|
|
|
|
* Destroy a local endpoint after the RCU grace period expires.
|
|
|
|
*/
|
|
|
|
static void rxrpc_local_rcu(struct rcu_head *rcu)
|
|
|
|
{
|
|
|
|
struct rxrpc_local *local = container_of(rcu, struct rxrpc_local, rcu);
|
2007-04-26 22:48:28 +00:00
|
|
|
|
2016-04-04 13:00:35 +00:00
|
|
|
_enter("%d", local->debug_id);
|
2007-04-26 22:48:28 +00:00
|
|
|
|
2016-04-04 13:00:35 +00:00
|
|
|
ASSERT(!work_pending(&local->processor));
|
2007-04-26 22:48:28 +00:00
|
|
|
|
|
|
|
_net("DESTROY LOCAL %d", local->debug_id);
|
|
|
|
kfree(local);
|
|
|
|
_leave("");
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2016-04-04 13:00:35 +00:00
|
|
|
* Verify the local endpoint list is empty by this point.
|
2007-04-26 22:48:28 +00:00
|
|
|
*/
|
2017-05-24 16:02:32 +00:00
|
|
|
void rxrpc_destroy_all_locals(struct rxrpc_net *rxnet)
|
2007-04-26 22:48:28 +00:00
|
|
|
{
|
2016-04-04 13:00:35 +00:00
|
|
|
struct rxrpc_local *local;
|
2007-04-26 22:48:28 +00:00
|
|
|
|
|
|
|
_enter("");
|
|
|
|
|
2016-06-27 16:11:19 +00:00
|
|
|
flush_workqueue(rxrpc_workqueue);
|
2007-04-26 22:48:28 +00:00
|
|
|
|
2022-05-21 07:45:15 +00:00
|
|
|
if (!hlist_empty(&rxnet->local_endpoints)) {
|
2017-05-24 16:02:32 +00:00
|
|
|
mutex_lock(&rxnet->local_mutex);
|
2022-05-21 07:45:15 +00:00
|
|
|
hlist_for_each_entry(local, &rxnet->local_endpoints, link) {
|
2016-06-27 16:11:19 +00:00
|
|
|
pr_err("AF_RXRPC: Leaked local %p {%d}\n",
|
2022-05-21 07:45:22 +00:00
|
|
|
local, refcount_read(&local->ref));
|
2016-06-27 16:11:19 +00:00
|
|
|
}
|
2017-05-24 16:02:32 +00:00
|
|
|
mutex_unlock(&rxnet->local_mutex);
|
2016-06-27 16:11:19 +00:00
|
|
|
BUG();
|
2007-04-26 22:48:28 +00:00
|
|
|
}
|
|
|
|
}
|