^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) // SPDX-License-Identifier: GPL-2.0-or-later
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) /* Local endpoint object management
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) * Copyright (C) 2016 Red Hat, Inc. All Rights Reserved.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) * Written by David Howells (dhowells@redhat.com)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) #include <linux/net.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) #include <linux/skbuff.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) #include <linux/udp.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) #include <linux/ip.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) #include <linux/hashtable.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) #include <net/sock.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) #include <net/udp.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) #include <net/af_rxrpc.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) #include "ar-internal.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) static void rxrpc_local_processor(struct work_struct *);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) static void rxrpc_local_rcu(struct rcu_head *);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) * Compare a local to an address. Return -ve, 0 or +ve to indicate less than,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) * same or greater than.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) * We explicitly don't compare the RxRPC service ID as we want to reject
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) * conflicting uses by differing services. Further, we don't want to share
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) * addresses with different options (IPv6), so we don't compare those bits
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) * either.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) static long rxrpc_local_cmp_key(const struct rxrpc_local *local,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) const struct sockaddr_rxrpc *srx)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) long diff;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) diff = ((local->srx.transport_type - srx->transport_type) ?:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) (local->srx.transport_len - srx->transport_len) ?:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) (local->srx.transport.family - srx->transport.family));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) if (diff != 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) return diff;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) switch (srx->transport.family) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) case AF_INET:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) /* If the choice of UDP port is left up to the transport, then
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) * the endpoint record doesn't match.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) return ((u16 __force)local->srx.transport.sin.sin_port -
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) (u16 __force)srx->transport.sin.sin_port) ?:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) memcmp(&local->srx.transport.sin.sin_addr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) &srx->transport.sin.sin_addr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) sizeof(struct in_addr));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) #ifdef CONFIG_AF_RXRPC_IPV6
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) case AF_INET6:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) /* If the choice of UDP6 port is left up to the transport, then
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) * the endpoint record doesn't match.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) return ((u16 __force)local->srx.transport.sin6.sin6_port -
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) (u16 __force)srx->transport.sin6.sin6_port) ?:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) memcmp(&local->srx.transport.sin6.sin6_addr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) &srx->transport.sin6.sin6_addr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) sizeof(struct in6_addr));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) BUG();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) * Allocate a new local endpoint.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) static struct rxrpc_local *rxrpc_alloc_local(struct rxrpc_net *rxnet,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) const struct sockaddr_rxrpc *srx)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) struct rxrpc_local *local;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) local = kzalloc(sizeof(struct rxrpc_local), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) if (local) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) atomic_set(&local->usage, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) atomic_set(&local->active_users, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) local->rxnet = rxnet;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) INIT_LIST_HEAD(&local->link);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) INIT_WORK(&local->processor, rxrpc_local_processor);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) init_rwsem(&local->defrag_sem);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) skb_queue_head_init(&local->reject_queue);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) skb_queue_head_init(&local->event_queue);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) local->client_bundles = RB_ROOT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) spin_lock_init(&local->client_bundles_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) spin_lock_init(&local->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) rwlock_init(&local->services_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) local->debug_id = atomic_inc_return(&rxrpc_debug_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) memcpy(&local->srx, srx, sizeof(*srx));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) local->srx.srx_service = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) trace_rxrpc_local(local->debug_id, rxrpc_local_new, 1, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) _leave(" = %p", local);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) return local;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) * create the local socket
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) * - must be called with rxrpc_local_mutex locked
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) static int rxrpc_open_socket(struct rxrpc_local *local, struct net *net)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) struct sock *usk;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) _enter("%p{%d,%d}",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) local, local->srx.transport_type, local->srx.transport.family);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) /* create a socket to represent the local endpoint */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) ret = sock_create_kern(net, local->srx.transport.family,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) local->srx.transport_type, 0, &local->socket);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) if (ret < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) _leave(" = %d [socket]", ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) /* set the socket up */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) usk = local->socket->sk;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) inet_sk(usk)->mc_loop = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) /* Enable CHECKSUM_UNNECESSARY to CHECKSUM_COMPLETE conversion */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) inet_inc_convert_csum(usk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) rcu_assign_sk_user_data(usk, local);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) udp_sk(usk)->encap_type = UDP_ENCAP_RXRPC;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) udp_sk(usk)->encap_rcv = rxrpc_input_packet;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) udp_sk(usk)->encap_destroy = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) udp_sk(usk)->gro_receive = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) udp_sk(usk)->gro_complete = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) udp_encap_enable();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) #if IS_ENABLED(CONFIG_AF_RXRPC_IPV6)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) if (local->srx.transport.family == AF_INET6)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) udpv6_encap_enable();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) usk->sk_error_report = rxrpc_error_report;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) /* if a local address was supplied then bind it */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) if (local->srx.transport_len > sizeof(sa_family_t)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) _debug("bind");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) ret = kernel_bind(local->socket,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) (struct sockaddr *)&local->srx.transport,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) local->srx.transport_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) if (ret < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) _debug("bind failed %d", ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) goto error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) switch (local->srx.transport.family) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) case AF_INET6:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) /* we want to receive ICMPv6 errors */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) ip6_sock_set_recverr(local->socket->sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) /* Fall through and set IPv4 options too otherwise we don't get
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) * errors from IPv4 packets sent through the IPv6 socket.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) fallthrough;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) case AF_INET:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) /* we want to receive ICMP errors */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) ip_sock_set_recverr(local->socket->sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) /* we want to set the don't fragment bit */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) ip_sock_set_mtu_discover(local->socket->sk, IP_PMTUDISC_DO);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) /* We want receive timestamps. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) sock_enable_timestamps(local->socket->sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) BUG();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) _leave(" = 0");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) error:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) kernel_sock_shutdown(local->socket, SHUT_RDWR);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) local->socket->sk->sk_user_data = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) sock_release(local->socket);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) local->socket = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) _leave(" = %d", ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) * Look up or create a new local endpoint using the specified local address.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) struct rxrpc_local *rxrpc_lookup_local(struct net *net,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) const struct sockaddr_rxrpc *srx)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) struct rxrpc_local *local;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) struct rxrpc_net *rxnet = rxrpc_net(net);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) struct list_head *cursor;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) const char *age;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) long diff;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) _enter("{%d,%d,%pISp}",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) srx->transport_type, srx->transport.family, &srx->transport);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) mutex_lock(&rxnet->local_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) for (cursor = rxnet->local_endpoints.next;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) cursor != &rxnet->local_endpoints;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) cursor = cursor->next) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) local = list_entry(cursor, struct rxrpc_local, link);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) diff = rxrpc_local_cmp_key(local, srx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) if (diff < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) if (diff > 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) /* Services aren't allowed to share transport sockets, so
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) * reject that here. It is possible that the object is dying -
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) * but it may also still have the local transport address that
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) * we want bound.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) if (srx->srx_service) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) local = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) goto addr_in_use;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) /* Found a match. We replace a dying object. Attempting to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) * bind the transport socket may still fail if we're attempting
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) * to use a local address that the dying object is still using.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) if (!rxrpc_use_local(local))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) age = "old";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) goto found;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) local = rxrpc_alloc_local(rxnet, srx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) if (!local)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) goto nomem;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) ret = rxrpc_open_socket(local, net);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) goto sock_error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) if (cursor != &rxnet->local_endpoints)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) list_replace_init(cursor, &local->link);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) list_add_tail(&local->link, cursor);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) age = "new";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) found:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) mutex_unlock(&rxnet->local_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) _net("LOCAL %s %d {%pISp}",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) age, local->debug_id, &local->srx.transport);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) _leave(" = %p", local);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) return local;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) nomem:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) ret = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) sock_error:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) mutex_unlock(&rxnet->local_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) if (local)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) call_rcu(&local->rcu, rxrpc_local_rcu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) _leave(" = %d", ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) return ERR_PTR(ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) addr_in_use:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) mutex_unlock(&rxnet->local_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) _leave(" = -EADDRINUSE");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) return ERR_PTR(-EADDRINUSE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) * Get a ref on a local endpoint.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) struct rxrpc_local *rxrpc_get_local(struct rxrpc_local *local)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) const void *here = __builtin_return_address(0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) int n;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) n = atomic_inc_return(&local->usage);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) trace_rxrpc_local(local->debug_id, rxrpc_local_got, n, here);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) return local;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) * Get a ref on a local endpoint unless its usage has already reached 0.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) struct rxrpc_local *rxrpc_get_local_maybe(struct rxrpc_local *local)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) const void *here = __builtin_return_address(0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) if (local) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) int n = atomic_fetch_add_unless(&local->usage, 1, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) if (n > 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) trace_rxrpc_local(local->debug_id, rxrpc_local_got,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) n + 1, here);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) local = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) return local;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) * Queue a local endpoint and pass the caller's reference to the work item.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) void rxrpc_queue_local(struct rxrpc_local *local)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) const void *here = __builtin_return_address(0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) unsigned int debug_id = local->debug_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) int n = atomic_read(&local->usage);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) if (rxrpc_queue_work(&local->processor))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) trace_rxrpc_local(debug_id, rxrpc_local_queued, n, here);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) rxrpc_put_local(local);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) * Drop a ref on a local endpoint.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) void rxrpc_put_local(struct rxrpc_local *local)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) const void *here = __builtin_return_address(0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) unsigned int debug_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) int n;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) if (local) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) debug_id = local->debug_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) n = atomic_dec_return(&local->usage);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) trace_rxrpc_local(debug_id, rxrpc_local_put, n, here);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) if (n == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) call_rcu(&local->rcu, rxrpc_local_rcu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) * Start using a local endpoint.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) struct rxrpc_local *rxrpc_use_local(struct rxrpc_local *local)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) local = rxrpc_get_local_maybe(local);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) if (!local)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) if (!__rxrpc_use_local(local)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) rxrpc_put_local(local);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) return local;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) * Cease using a local endpoint. Once the number of active users reaches 0, we
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) * start the closure of the transport in the work processor.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) void rxrpc_unuse_local(struct rxrpc_local *local)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) if (local) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372) if (__rxrpc_unuse_local(local)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373) rxrpc_get_local(local);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) rxrpc_queue_local(local);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) * Destroy a local endpoint's socket and then hand the record to RCU to dispose
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381) * of.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383) * Closing the socket cannot be done from bottom half context or RCU callback
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384) * context because it might sleep.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386) static void rxrpc_local_destroyer(struct rxrpc_local *local)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388) struct socket *socket = local->socket;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389) struct rxrpc_net *rxnet = local->rxnet;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391) _enter("%d", local->debug_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393) local->dead = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395) mutex_lock(&rxnet->local_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396) list_del_init(&local->link);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397) mutex_unlock(&rxnet->local_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399) rxrpc_clean_up_local_conns(local);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400) rxrpc_service_connection_reaper(&rxnet->service_conn_reaper);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401) ASSERT(!local->service);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403) if (socket) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404) local->socket = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405) kernel_sock_shutdown(socket, SHUT_RDWR);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406) socket->sk->sk_user_data = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407) sock_release(socket);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410) /* At this point, there should be no more packets coming in to the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411) * local endpoint.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413) rxrpc_purge_queue(&local->reject_queue);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414) rxrpc_purge_queue(&local->event_queue);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418) * Process events on an endpoint. The work item carries a ref which
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419) * we must release.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 421) static void rxrpc_local_processor(struct work_struct *work)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 422) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 423) struct rxrpc_local *local =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 424) container_of(work, struct rxrpc_local, processor);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 425) bool again;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 426)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 427) trace_rxrpc_local(local->debug_id, rxrpc_local_processing,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 428) atomic_read(&local->usage), NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 429)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 430) do {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 431) again = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 432) if (!__rxrpc_use_local(local)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 433) rxrpc_local_destroyer(local);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 434) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 435) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 436)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 437) if (!skb_queue_empty(&local->reject_queue)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 438) rxrpc_reject_packets(local);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 439) again = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 440) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 441)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 442) if (!skb_queue_empty(&local->event_queue)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 443) rxrpc_process_local_events(local);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 444) again = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 445) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 446)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 447) __rxrpc_unuse_local(local);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 448) } while (again);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 449)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 450) rxrpc_put_local(local);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 451) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 452)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 453) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 454) * Destroy a local endpoint after the RCU grace period expires.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 455) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 456) static void rxrpc_local_rcu(struct rcu_head *rcu)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 457) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 458) struct rxrpc_local *local = container_of(rcu, struct rxrpc_local, rcu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 459)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 460) _enter("%d", local->debug_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 461)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 462) ASSERT(!work_pending(&local->processor));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 463)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 464) _net("DESTROY LOCAL %d", local->debug_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 465) kfree(local);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 466) _leave("");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 467) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 468)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 469) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 470) * Verify the local endpoint list is empty by this point.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 471) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 472) void rxrpc_destroy_all_locals(struct rxrpc_net *rxnet)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 473) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 474) struct rxrpc_local *local;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 475)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 476) _enter("");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 477)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 478) flush_workqueue(rxrpc_workqueue);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 479)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 480) if (!list_empty(&rxnet->local_endpoints)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 481) mutex_lock(&rxnet->local_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 482) list_for_each_entry(local, &rxnet->local_endpoints, link) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 483) pr_err("AF_RXRPC: Leaked local %p {%d}\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 484) local, atomic_read(&local->usage));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 485) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 486) mutex_unlock(&rxnet->local_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 487) BUG();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 488) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 489) }