David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 1 | /* AF_RXRPC implementation |
| 2 | * |
| 3 | * Copyright (C) 2007 Red Hat, Inc. All Rights Reserved. |
| 4 | * Written by David Howells (dhowells@redhat.com) |
| 5 | * |
| 6 | * This program is free software; you can redistribute it and/or |
| 7 | * modify it under the terms of the GNU General Public License |
| 8 | * as published by the Free Software Foundation; either version |
| 9 | * 2 of the License, or (at your option) any later version. |
| 10 | */ |
| 11 | |
Joe Perches | 9b6d539 | 2016-06-02 12:08:52 -0700 | [diff] [blame^] | 12 | #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt |
| 13 | |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 14 | #include <linux/module.h> |
YOSHIFUJI Hideaki / 吉藤英明 | ce6654c | 2013-01-09 07:20:01 +0000 | [diff] [blame] | 15 | #include <linux/kernel.h> |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 16 | #include <linux/net.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 17 | #include <linux/slab.h> |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 18 | #include <linux/skbuff.h> |
| 19 | #include <linux/poll.h> |
| 20 | #include <linux/proc_fs.h> |
David Howells | 76181c1 | 2007-10-16 23:29:46 -0700 | [diff] [blame] | 21 | #include <linux/key-type.h> |
Eric W. Biederman | 457c4cb | 2007-09-12 12:01:34 +0200 | [diff] [blame] | 22 | #include <net/net_namespace.h> |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 23 | #include <net/sock.h> |
| 24 | #include <net/af_rxrpc.h> |
| 25 | #include "ar-internal.h" |
| 26 | |
| 27 | MODULE_DESCRIPTION("RxRPC network protocol"); |
| 28 | MODULE_AUTHOR("Red Hat, Inc."); |
| 29 | MODULE_LICENSE("GPL"); |
| 30 | MODULE_ALIAS_NETPROTO(PF_RXRPC); |
| 31 | |
Eric Dumazet | 95c9617 | 2012-04-15 05:58:06 +0000 | [diff] [blame] | 32 | unsigned int rxrpc_debug; // = RXRPC_DEBUG_KPROTO; |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 33 | module_param_named(debug, rxrpc_debug, uint, S_IWUSR | S_IRUGO); |
Paul Bolle | 424b00e | 2008-04-16 11:08:22 +0100 | [diff] [blame] | 34 | MODULE_PARM_DESC(debug, "RxRPC debugging mask"); |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 35 | |
| 36 | static int sysctl_rxrpc_max_qlen __read_mostly = 10; |
| 37 | |
| 38 | static struct proto rxrpc_proto; |
| 39 | static const struct proto_ops rxrpc_rpc_ops; |
| 40 | |
| 41 | /* local epoch for detecting local-end reset */ |
David Howells | 0d12f8a | 2016-03-04 15:53:46 +0000 | [diff] [blame] | 42 | u32 rxrpc_epoch; |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 43 | |
| 44 | /* current debugging ID */ |
| 45 | atomic_t rxrpc_debug_id; |
| 46 | |
| 47 | /* count of skbs currently in use */ |
| 48 | atomic_t rxrpc_n_skbs; |
| 49 | |
David Howells | 651350d | 2007-04-26 15:50:17 -0700 | [diff] [blame] | 50 | struct workqueue_struct *rxrpc_workqueue; |
| 51 | |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 52 | static void rxrpc_sock_destructor(struct sock *); |
| 53 | |
| 54 | /* |
| 55 | * see if an RxRPC socket is currently writable |
| 56 | */ |
| 57 | static inline int rxrpc_writable(struct sock *sk) |
| 58 | { |
| 59 | return atomic_read(&sk->sk_wmem_alloc) < (size_t) sk->sk_sndbuf; |
| 60 | } |
| 61 | |
| 62 | /* |
| 63 | * wait for write bufferage to become available |
| 64 | */ |
| 65 | static void rxrpc_write_space(struct sock *sk) |
| 66 | { |
| 67 | _enter("%p", sk); |
Eric Dumazet | 4381548 | 2010-04-29 11:01:49 +0000 | [diff] [blame] | 68 | rcu_read_lock(); |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 69 | if (rxrpc_writable(sk)) { |
Eric Dumazet | 4381548 | 2010-04-29 11:01:49 +0000 | [diff] [blame] | 70 | struct socket_wq *wq = rcu_dereference(sk->sk_wq); |
| 71 | |
Herbert Xu | 1ce0bf5 | 2015-11-26 13:55:39 +0800 | [diff] [blame] | 72 | if (skwq_has_sleeper(wq)) |
Eric Dumazet | 4381548 | 2010-04-29 11:01:49 +0000 | [diff] [blame] | 73 | wake_up_interruptible(&wq->wait); |
Pavel Emelyanov | 8d8ad9d | 2007-11-26 20:10:50 +0800 | [diff] [blame] | 74 | sk_wake_async(sk, SOCK_WAKE_SPACE, POLL_OUT); |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 75 | } |
Eric Dumazet | 4381548 | 2010-04-29 11:01:49 +0000 | [diff] [blame] | 76 | rcu_read_unlock(); |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 77 | } |
| 78 | |
| 79 | /* |
| 80 | * validate an RxRPC address |
| 81 | */ |
| 82 | static int rxrpc_validate_address(struct rxrpc_sock *rx, |
| 83 | struct sockaddr_rxrpc *srx, |
| 84 | int len) |
| 85 | { |
David Howells | dad8aff | 2016-03-09 23:22:56 +0000 | [diff] [blame] | 86 | unsigned int tail; |
David Howells | ab802ee | 2016-03-04 15:59:49 +0000 | [diff] [blame] | 87 | |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 88 | if (len < sizeof(struct sockaddr_rxrpc)) |
| 89 | return -EINVAL; |
| 90 | |
| 91 | if (srx->srx_family != AF_RXRPC) |
| 92 | return -EAFNOSUPPORT; |
| 93 | |
| 94 | if (srx->transport_type != SOCK_DGRAM) |
| 95 | return -ESOCKTNOSUPPORT; |
| 96 | |
| 97 | len -= offsetof(struct sockaddr_rxrpc, transport); |
| 98 | if (srx->transport_len < sizeof(sa_family_t) || |
| 99 | srx->transport_len > len) |
| 100 | return -EINVAL; |
| 101 | |
| 102 | if (srx->transport.family != rx->proto) |
| 103 | return -EAFNOSUPPORT; |
| 104 | |
| 105 | switch (srx->transport.family) { |
| 106 | case AF_INET: |
Harvey Harrison | 21454aa | 2008-10-31 00:54:56 -0700 | [diff] [blame] | 107 | _debug("INET: %x @ %pI4", |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 108 | ntohs(srx->transport.sin.sin_port), |
Harvey Harrison | 21454aa | 2008-10-31 00:54:56 -0700 | [diff] [blame] | 109 | &srx->transport.sin.sin_addr); |
David Howells | ab802ee | 2016-03-04 15:59:49 +0000 | [diff] [blame] | 110 | tail = offsetof(struct sockaddr_rxrpc, transport.sin.__pad); |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 111 | break; |
| 112 | |
| 113 | case AF_INET6: |
| 114 | default: |
| 115 | return -EAFNOSUPPORT; |
| 116 | } |
| 117 | |
David Howells | ab802ee | 2016-03-04 15:59:49 +0000 | [diff] [blame] | 118 | if (tail < len) |
| 119 | memset((void *)srx + tail, 0, len - tail); |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 120 | return 0; |
| 121 | } |
| 122 | |
| 123 | /* |
| 124 | * bind a local address to an RxRPC socket |
| 125 | */ |
| 126 | static int rxrpc_bind(struct socket *sock, struct sockaddr *saddr, int len) |
| 127 | { |
David Howells | b4f1342 | 2016-03-04 15:56:19 +0000 | [diff] [blame] | 128 | struct sockaddr_rxrpc *srx = (struct sockaddr_rxrpc *)saddr; |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 129 | struct sock *sk = sock->sk; |
| 130 | struct rxrpc_local *local; |
| 131 | struct rxrpc_sock *rx = rxrpc_sk(sk), *prx; |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 132 | int ret; |
| 133 | |
| 134 | _enter("%p,%p,%d", rx, saddr, len); |
| 135 | |
| 136 | ret = rxrpc_validate_address(rx, srx, len); |
| 137 | if (ret < 0) |
| 138 | goto error; |
| 139 | |
| 140 | lock_sock(&rx->sk); |
| 141 | |
| 142 | if (rx->sk.sk_state != RXRPC_UNCONNECTED) { |
| 143 | ret = -EINVAL; |
| 144 | goto error_unlock; |
| 145 | } |
| 146 | |
| 147 | memcpy(&rx->srx, srx, sizeof(rx->srx)); |
| 148 | |
David Howells | b4f1342 | 2016-03-04 15:56:19 +0000 | [diff] [blame] | 149 | /* Find or create a local transport endpoint to use */ |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 150 | local = rxrpc_lookup_local(&rx->srx); |
| 151 | if (IS_ERR(local)) { |
| 152 | ret = PTR_ERR(local); |
| 153 | goto error_unlock; |
| 154 | } |
| 155 | |
| 156 | rx->local = local; |
| 157 | if (srx->srx_service) { |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 158 | write_lock_bh(&local->services_lock); |
| 159 | list_for_each_entry(prx, &local->services, listen_link) { |
David Howells | 0d12f8a | 2016-03-04 15:53:46 +0000 | [diff] [blame] | 160 | if (prx->srx.srx_service == srx->srx_service) |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 161 | goto service_in_use; |
| 162 | } |
| 163 | |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 164 | list_add_tail(&rx->listen_link, &local->services); |
| 165 | write_unlock_bh(&local->services_lock); |
| 166 | |
| 167 | rx->sk.sk_state = RXRPC_SERVER_BOUND; |
| 168 | } else { |
| 169 | rx->sk.sk_state = RXRPC_CLIENT_BOUND; |
| 170 | } |
| 171 | |
| 172 | release_sock(&rx->sk); |
| 173 | _leave(" = 0"); |
| 174 | return 0; |
| 175 | |
| 176 | service_in_use: |
| 177 | ret = -EADDRINUSE; |
| 178 | write_unlock_bh(&local->services_lock); |
| 179 | error_unlock: |
| 180 | release_sock(&rx->sk); |
| 181 | error: |
| 182 | _leave(" = %d", ret); |
| 183 | return ret; |
| 184 | } |
| 185 | |
| 186 | /* |
| 187 | * set the number of pending calls permitted on a listening socket |
| 188 | */ |
| 189 | static int rxrpc_listen(struct socket *sock, int backlog) |
| 190 | { |
| 191 | struct sock *sk = sock->sk; |
| 192 | struct rxrpc_sock *rx = rxrpc_sk(sk); |
| 193 | int ret; |
| 194 | |
| 195 | _enter("%p,%d", rx, backlog); |
| 196 | |
| 197 | lock_sock(&rx->sk); |
| 198 | |
| 199 | switch (rx->sk.sk_state) { |
| 200 | case RXRPC_UNCONNECTED: |
| 201 | ret = -EADDRNOTAVAIL; |
| 202 | break; |
| 203 | case RXRPC_CLIENT_BOUND: |
| 204 | case RXRPC_CLIENT_CONNECTED: |
| 205 | default: |
| 206 | ret = -EBUSY; |
| 207 | break; |
| 208 | case RXRPC_SERVER_BOUND: |
| 209 | ASSERT(rx->local != NULL); |
| 210 | sk->sk_max_ack_backlog = backlog; |
| 211 | rx->sk.sk_state = RXRPC_SERVER_LISTENING; |
| 212 | ret = 0; |
| 213 | break; |
| 214 | } |
| 215 | |
| 216 | release_sock(&rx->sk); |
| 217 | _leave(" = %d", ret); |
| 218 | return ret; |
| 219 | } |
| 220 | |
| 221 | /* |
| 222 | * find a transport by address |
| 223 | */ |
| 224 | static struct rxrpc_transport *rxrpc_name_to_transport(struct socket *sock, |
| 225 | struct sockaddr *addr, |
David Howells | 651350d | 2007-04-26 15:50:17 -0700 | [diff] [blame] | 226 | int addr_len, int flags, |
| 227 | gfp_t gfp) |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 228 | { |
| 229 | struct sockaddr_rxrpc *srx = (struct sockaddr_rxrpc *) addr; |
| 230 | struct rxrpc_transport *trans; |
| 231 | struct rxrpc_sock *rx = rxrpc_sk(sock->sk); |
| 232 | struct rxrpc_peer *peer; |
| 233 | |
| 234 | _enter("%p,%p,%d,%d", rx, addr, addr_len, flags); |
| 235 | |
| 236 | ASSERT(rx->local != NULL); |
| 237 | ASSERT(rx->sk.sk_state > RXRPC_UNCONNECTED); |
| 238 | |
| 239 | if (rx->srx.transport_type != srx->transport_type) |
| 240 | return ERR_PTR(-ESOCKTNOSUPPORT); |
| 241 | if (rx->srx.transport.family != srx->transport.family) |
| 242 | return ERR_PTR(-EAFNOSUPPORT); |
| 243 | |
| 244 | /* find a remote transport endpoint from the local one */ |
David Howells | 651350d | 2007-04-26 15:50:17 -0700 | [diff] [blame] | 245 | peer = rxrpc_get_peer(srx, gfp); |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 246 | if (IS_ERR(peer)) |
David Howells | e231c2e | 2008-02-07 00:15:26 -0800 | [diff] [blame] | 247 | return ERR_CAST(peer); |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 248 | |
| 249 | /* find a transport */ |
David Howells | 651350d | 2007-04-26 15:50:17 -0700 | [diff] [blame] | 250 | trans = rxrpc_get_transport(rx->local, peer, gfp); |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 251 | rxrpc_put_peer(peer); |
| 252 | _leave(" = %p", trans); |
| 253 | return trans; |
| 254 | } |
| 255 | |
David Howells | 651350d | 2007-04-26 15:50:17 -0700 | [diff] [blame] | 256 | /** |
| 257 | * rxrpc_kernel_begin_call - Allow a kernel service to begin a call |
| 258 | * @sock: The socket on which to make the call |
| 259 | * @srx: The address of the peer to contact (defaults to socket setting) |
| 260 | * @key: The security context to use (defaults to socket setting) |
| 261 | * @user_call_ID: The ID to use |
| 262 | * |
| 263 | * Allow a kernel service to begin a call on the nominated socket. This just |
| 264 | * sets up all the internal tracking structures and allocates connection and |
| 265 | * call IDs as appropriate. The call to be used is returned. |
| 266 | * |
| 267 | * The default socket destination address and security may be overridden by |
| 268 | * supplying @srx and @key. |
| 269 | */ |
| 270 | struct rxrpc_call *rxrpc_kernel_begin_call(struct socket *sock, |
| 271 | struct sockaddr_rxrpc *srx, |
| 272 | struct key *key, |
| 273 | unsigned long user_call_ID, |
| 274 | gfp_t gfp) |
| 275 | { |
| 276 | struct rxrpc_conn_bundle *bundle; |
| 277 | struct rxrpc_transport *trans; |
| 278 | struct rxrpc_call *call; |
| 279 | struct rxrpc_sock *rx = rxrpc_sk(sock->sk); |
David Howells | 651350d | 2007-04-26 15:50:17 -0700 | [diff] [blame] | 280 | |
| 281 | _enter(",,%x,%lx", key_serial(key), user_call_ID); |
| 282 | |
| 283 | lock_sock(&rx->sk); |
| 284 | |
| 285 | if (srx) { |
| 286 | trans = rxrpc_name_to_transport(sock, (struct sockaddr *) srx, |
| 287 | sizeof(*srx), 0, gfp); |
| 288 | if (IS_ERR(trans)) { |
David Howells | e231c2e | 2008-02-07 00:15:26 -0800 | [diff] [blame] | 289 | call = ERR_CAST(trans); |
David Howells | 651350d | 2007-04-26 15:50:17 -0700 | [diff] [blame] | 290 | trans = NULL; |
David Howells | 15bde72 | 2009-02-06 21:50:52 -0800 | [diff] [blame] | 291 | goto out_notrans; |
David Howells | 651350d | 2007-04-26 15:50:17 -0700 | [diff] [blame] | 292 | } |
| 293 | } else { |
| 294 | trans = rx->trans; |
| 295 | if (!trans) { |
| 296 | call = ERR_PTR(-ENOTCONN); |
David Howells | 15bde72 | 2009-02-06 21:50:52 -0800 | [diff] [blame] | 297 | goto out_notrans; |
David Howells | 651350d | 2007-04-26 15:50:17 -0700 | [diff] [blame] | 298 | } |
| 299 | atomic_inc(&trans->usage); |
| 300 | } |
| 301 | |
David Howells | 0d12f8a | 2016-03-04 15:53:46 +0000 | [diff] [blame] | 302 | if (!srx) |
| 303 | srx = &rx->srx; |
David Howells | 651350d | 2007-04-26 15:50:17 -0700 | [diff] [blame] | 304 | if (!key) |
| 305 | key = rx->key; |
David Howells | 146aa8b | 2015-10-21 14:04:48 +0100 | [diff] [blame] | 306 | if (key && !key->payload.data[0]) |
David Howells | 651350d | 2007-04-26 15:50:17 -0700 | [diff] [blame] | 307 | key = NULL; /* a no-security key */ |
| 308 | |
David Howells | 0d12f8a | 2016-03-04 15:53:46 +0000 | [diff] [blame] | 309 | bundle = rxrpc_get_bundle(rx, trans, key, srx->srx_service, gfp); |
David Howells | 651350d | 2007-04-26 15:50:17 -0700 | [diff] [blame] | 310 | if (IS_ERR(bundle)) { |
David Howells | e231c2e | 2008-02-07 00:15:26 -0800 | [diff] [blame] | 311 | call = ERR_CAST(bundle); |
David Howells | 651350d | 2007-04-26 15:50:17 -0700 | [diff] [blame] | 312 | goto out; |
| 313 | } |
| 314 | |
| 315 | call = rxrpc_get_client_call(rx, trans, bundle, user_call_ID, true, |
| 316 | gfp); |
| 317 | rxrpc_put_bundle(trans, bundle); |
| 318 | out: |
| 319 | rxrpc_put_transport(trans); |
David Howells | 15bde72 | 2009-02-06 21:50:52 -0800 | [diff] [blame] | 320 | out_notrans: |
David Howells | 651350d | 2007-04-26 15:50:17 -0700 | [diff] [blame] | 321 | release_sock(&rx->sk); |
| 322 | _leave(" = %p", call); |
| 323 | return call; |
| 324 | } |
David Howells | 651350d | 2007-04-26 15:50:17 -0700 | [diff] [blame] | 325 | EXPORT_SYMBOL(rxrpc_kernel_begin_call); |
| 326 | |
| 327 | /** |
| 328 | * rxrpc_kernel_end_call - Allow a kernel service to end a call it was using |
| 329 | * @call: The call to end |
| 330 | * |
| 331 | * Allow a kernel service to end a call it was using. The call must be |
| 332 | * complete before this is called (the call should be aborted if necessary). |
| 333 | */ |
| 334 | void rxrpc_kernel_end_call(struct rxrpc_call *call) |
| 335 | { |
| 336 | _enter("%d{%d}", call->debug_id, atomic_read(&call->usage)); |
| 337 | rxrpc_remove_user_ID(call->socket, call); |
| 338 | rxrpc_put_call(call); |
| 339 | } |
David Howells | 651350d | 2007-04-26 15:50:17 -0700 | [diff] [blame] | 340 | EXPORT_SYMBOL(rxrpc_kernel_end_call); |
| 341 | |
| 342 | /** |
| 343 | * rxrpc_kernel_intercept_rx_messages - Intercept received RxRPC messages |
| 344 | * @sock: The socket to intercept received messages on |
| 345 | * @interceptor: The function to pass the messages to |
| 346 | * |
| 347 | * Allow a kernel service to intercept messages heading for the Rx queue on an |
| 348 | * RxRPC socket. They get passed to the specified function instead. |
| 349 | * @interceptor should free the socket buffers it is given. @interceptor is |
| 350 | * called with the socket receive queue spinlock held and softirqs disabled - |
| 351 | * this ensures that the messages will be delivered in the right order. |
| 352 | */ |
| 353 | void rxrpc_kernel_intercept_rx_messages(struct socket *sock, |
| 354 | rxrpc_interceptor_t interceptor) |
| 355 | { |
| 356 | struct rxrpc_sock *rx = rxrpc_sk(sock->sk); |
| 357 | |
| 358 | _enter(""); |
| 359 | rx->interceptor = interceptor; |
| 360 | } |
| 361 | |
| 362 | EXPORT_SYMBOL(rxrpc_kernel_intercept_rx_messages); |
| 363 | |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 364 | /* |
| 365 | * connect an RxRPC socket |
| 366 | * - this just targets it at a specific destination; no actual connection |
| 367 | * negotiation takes place |
| 368 | */ |
| 369 | static int rxrpc_connect(struct socket *sock, struct sockaddr *addr, |
| 370 | int addr_len, int flags) |
| 371 | { |
| 372 | struct sockaddr_rxrpc *srx = (struct sockaddr_rxrpc *) addr; |
| 373 | struct sock *sk = sock->sk; |
| 374 | struct rxrpc_transport *trans; |
| 375 | struct rxrpc_local *local; |
| 376 | struct rxrpc_sock *rx = rxrpc_sk(sk); |
| 377 | int ret; |
| 378 | |
| 379 | _enter("%p,%p,%d,%d", rx, addr, addr_len, flags); |
| 380 | |
| 381 | ret = rxrpc_validate_address(rx, srx, addr_len); |
| 382 | if (ret < 0) { |
| 383 | _leave(" = %d [bad addr]", ret); |
| 384 | return ret; |
| 385 | } |
| 386 | |
| 387 | lock_sock(&rx->sk); |
| 388 | |
| 389 | switch (rx->sk.sk_state) { |
| 390 | case RXRPC_UNCONNECTED: |
| 391 | /* find a local transport endpoint if we don't have one already */ |
| 392 | ASSERTCMP(rx->local, ==, NULL); |
| 393 | rx->srx.srx_family = AF_RXRPC; |
| 394 | rx->srx.srx_service = 0; |
| 395 | rx->srx.transport_type = srx->transport_type; |
| 396 | rx->srx.transport_len = sizeof(sa_family_t); |
| 397 | rx->srx.transport.family = srx->transport.family; |
| 398 | local = rxrpc_lookup_local(&rx->srx); |
| 399 | if (IS_ERR(local)) { |
| 400 | release_sock(&rx->sk); |
| 401 | return PTR_ERR(local); |
| 402 | } |
| 403 | rx->local = local; |
| 404 | rx->sk.sk_state = RXRPC_CLIENT_BOUND; |
| 405 | case RXRPC_CLIENT_BOUND: |
| 406 | break; |
| 407 | case RXRPC_CLIENT_CONNECTED: |
| 408 | release_sock(&rx->sk); |
| 409 | return -EISCONN; |
| 410 | default: |
| 411 | release_sock(&rx->sk); |
| 412 | return -EBUSY; /* server sockets can't connect as well */ |
| 413 | } |
| 414 | |
David Howells | 651350d | 2007-04-26 15:50:17 -0700 | [diff] [blame] | 415 | trans = rxrpc_name_to_transport(sock, addr, addr_len, flags, |
| 416 | GFP_KERNEL); |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 417 | if (IS_ERR(trans)) { |
| 418 | release_sock(&rx->sk); |
| 419 | _leave(" = %ld", PTR_ERR(trans)); |
| 420 | return PTR_ERR(trans); |
| 421 | } |
| 422 | |
| 423 | rx->trans = trans; |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 424 | rx->sk.sk_state = RXRPC_CLIENT_CONNECTED; |
| 425 | |
| 426 | release_sock(&rx->sk); |
| 427 | return 0; |
| 428 | } |
| 429 | |
| 430 | /* |
| 431 | * send a message through an RxRPC socket |
| 432 | * - in a client this does a number of things: |
| 433 | * - finds/sets up a connection for the security specified (if any) |
| 434 | * - initiates a call (ID in control data) |
| 435 | * - ends the request phase of a call (if MSG_MORE is not set) |
| 436 | * - sends a call data packet |
| 437 | * - may send an abort (abort code in control data) |
| 438 | */ |
Ying Xue | 1b78414 | 2015-03-02 15:37:48 +0800 | [diff] [blame] | 439 | static int rxrpc_sendmsg(struct socket *sock, struct msghdr *m, size_t len) |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 440 | { |
| 441 | struct rxrpc_transport *trans; |
| 442 | struct rxrpc_sock *rx = rxrpc_sk(sock->sk); |
| 443 | int ret; |
| 444 | |
| 445 | _enter(",{%d},,%zu", rx->sk.sk_state, len); |
| 446 | |
| 447 | if (m->msg_flags & MSG_OOB) |
| 448 | return -EOPNOTSUPP; |
| 449 | |
| 450 | if (m->msg_name) { |
| 451 | ret = rxrpc_validate_address(rx, m->msg_name, m->msg_namelen); |
| 452 | if (ret < 0) { |
| 453 | _leave(" = %d [bad addr]", ret); |
| 454 | return ret; |
| 455 | } |
| 456 | } |
| 457 | |
| 458 | trans = NULL; |
| 459 | lock_sock(&rx->sk); |
| 460 | |
| 461 | if (m->msg_name) { |
| 462 | ret = -EISCONN; |
| 463 | trans = rxrpc_name_to_transport(sock, m->msg_name, |
David Howells | 651350d | 2007-04-26 15:50:17 -0700 | [diff] [blame] | 464 | m->msg_namelen, 0, GFP_KERNEL); |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 465 | if (IS_ERR(trans)) { |
| 466 | ret = PTR_ERR(trans); |
| 467 | trans = NULL; |
| 468 | goto out; |
| 469 | } |
| 470 | } else { |
| 471 | trans = rx->trans; |
| 472 | if (trans) |
| 473 | atomic_inc(&trans->usage); |
| 474 | } |
| 475 | |
| 476 | switch (rx->sk.sk_state) { |
| 477 | case RXRPC_SERVER_LISTENING: |
| 478 | if (!m->msg_name) { |
Ying Xue | 1b78414 | 2015-03-02 15:37:48 +0800 | [diff] [blame] | 479 | ret = rxrpc_server_sendmsg(rx, m, len); |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 480 | break; |
| 481 | } |
| 482 | case RXRPC_SERVER_BOUND: |
| 483 | case RXRPC_CLIENT_BOUND: |
| 484 | if (!m->msg_name) { |
| 485 | ret = -ENOTCONN; |
| 486 | break; |
| 487 | } |
| 488 | case RXRPC_CLIENT_CONNECTED: |
Ying Xue | 1b78414 | 2015-03-02 15:37:48 +0800 | [diff] [blame] | 489 | ret = rxrpc_client_sendmsg(rx, trans, m, len); |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 490 | break; |
| 491 | default: |
| 492 | ret = -ENOTCONN; |
| 493 | break; |
| 494 | } |
| 495 | |
| 496 | out: |
| 497 | release_sock(&rx->sk); |
| 498 | if (trans) |
| 499 | rxrpc_put_transport(trans); |
| 500 | _leave(" = %d", ret); |
| 501 | return ret; |
| 502 | } |
| 503 | |
| 504 | /* |
| 505 | * set RxRPC socket options |
| 506 | */ |
| 507 | static int rxrpc_setsockopt(struct socket *sock, int level, int optname, |
David S. Miller | b705884 | 2009-09-30 16:12:20 -0700 | [diff] [blame] | 508 | char __user *optval, unsigned int optlen) |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 509 | { |
| 510 | struct rxrpc_sock *rx = rxrpc_sk(sock->sk); |
Eric Dumazet | 95c9617 | 2012-04-15 05:58:06 +0000 | [diff] [blame] | 511 | unsigned int min_sec_level; |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 512 | int ret; |
| 513 | |
| 514 | _enter(",%d,%d,,%d", level, optname, optlen); |
| 515 | |
| 516 | lock_sock(&rx->sk); |
| 517 | ret = -EOPNOTSUPP; |
| 518 | |
| 519 | if (level == SOL_RXRPC) { |
| 520 | switch (optname) { |
| 521 | case RXRPC_EXCLUSIVE_CONNECTION: |
| 522 | ret = -EINVAL; |
| 523 | if (optlen != 0) |
| 524 | goto error; |
| 525 | ret = -EISCONN; |
| 526 | if (rx->sk.sk_state != RXRPC_UNCONNECTED) |
| 527 | goto error; |
| 528 | set_bit(RXRPC_SOCK_EXCLUSIVE_CONN, &rx->flags); |
| 529 | goto success; |
| 530 | |
| 531 | case RXRPC_SECURITY_KEY: |
| 532 | ret = -EINVAL; |
| 533 | if (rx->key) |
| 534 | goto error; |
| 535 | ret = -EISCONN; |
| 536 | if (rx->sk.sk_state != RXRPC_UNCONNECTED) |
| 537 | goto error; |
| 538 | ret = rxrpc_request_key(rx, optval, optlen); |
| 539 | goto error; |
| 540 | |
| 541 | case RXRPC_SECURITY_KEYRING: |
| 542 | ret = -EINVAL; |
| 543 | if (rx->key) |
| 544 | goto error; |
| 545 | ret = -EISCONN; |
| 546 | if (rx->sk.sk_state != RXRPC_UNCONNECTED) |
| 547 | goto error; |
| 548 | ret = rxrpc_server_keyring(rx, optval, optlen); |
| 549 | goto error; |
| 550 | |
| 551 | case RXRPC_MIN_SECURITY_LEVEL: |
| 552 | ret = -EINVAL; |
Eric Dumazet | 95c9617 | 2012-04-15 05:58:06 +0000 | [diff] [blame] | 553 | if (optlen != sizeof(unsigned int)) |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 554 | goto error; |
| 555 | ret = -EISCONN; |
| 556 | if (rx->sk.sk_state != RXRPC_UNCONNECTED) |
| 557 | goto error; |
| 558 | ret = get_user(min_sec_level, |
Eric Dumazet | 95c9617 | 2012-04-15 05:58:06 +0000 | [diff] [blame] | 559 | (unsigned int __user *) optval); |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 560 | if (ret < 0) |
| 561 | goto error; |
| 562 | ret = -EINVAL; |
| 563 | if (min_sec_level > RXRPC_SECURITY_MAX) |
| 564 | goto error; |
| 565 | rx->min_sec_level = min_sec_level; |
| 566 | goto success; |
| 567 | |
| 568 | default: |
| 569 | break; |
| 570 | } |
| 571 | } |
| 572 | |
| 573 | success: |
| 574 | ret = 0; |
| 575 | error: |
| 576 | release_sock(&rx->sk); |
| 577 | return ret; |
| 578 | } |
| 579 | |
| 580 | /* |
| 581 | * permit an RxRPC socket to be polled |
| 582 | */ |
| 583 | static unsigned int rxrpc_poll(struct file *file, struct socket *sock, |
| 584 | poll_table *wait) |
| 585 | { |
| 586 | unsigned int mask; |
| 587 | struct sock *sk = sock->sk; |
| 588 | |
Eric Dumazet | aa39514 | 2010-04-20 13:03:51 +0000 | [diff] [blame] | 589 | sock_poll_wait(file, sk_sleep(sk), wait); |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 590 | mask = 0; |
| 591 | |
| 592 | /* the socket is readable if there are any messages waiting on the Rx |
| 593 | * queue */ |
| 594 | if (!skb_queue_empty(&sk->sk_receive_queue)) |
| 595 | mask |= POLLIN | POLLRDNORM; |
| 596 | |
| 597 | /* the socket is writable if there is space to add new data to the |
| 598 | * socket; there is no guarantee that any particular call in progress |
| 599 | * on the socket may have space in the Tx ACK window */ |
| 600 | if (rxrpc_writable(sk)) |
| 601 | mask |= POLLOUT | POLLWRNORM; |
| 602 | |
| 603 | return mask; |
| 604 | } |
| 605 | |
| 606 | /* |
| 607 | * create an RxRPC socket |
| 608 | */ |
Eric Paris | 3f378b6 | 2009-11-05 22:18:14 -0800 | [diff] [blame] | 609 | static int rxrpc_create(struct net *net, struct socket *sock, int protocol, |
| 610 | int kern) |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 611 | { |
| 612 | struct rxrpc_sock *rx; |
| 613 | struct sock *sk; |
| 614 | |
| 615 | _enter("%p,%d", sock, protocol); |
| 616 | |
Octavian Purdila | 09ad9bc | 2009-11-25 15:14:13 -0800 | [diff] [blame] | 617 | if (!net_eq(net, &init_net)) |
Eric W. Biederman | 1b8d7ae | 2007-10-08 23:24:22 -0700 | [diff] [blame] | 618 | return -EAFNOSUPPORT; |
| 619 | |
David Howells | b4f1342 | 2016-03-04 15:56:19 +0000 | [diff] [blame] | 620 | /* we support transport protocol UDP/UDP6 only */ |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 621 | if (protocol != PF_INET) |
| 622 | return -EPROTONOSUPPORT; |
| 623 | |
| 624 | if (sock->type != SOCK_DGRAM) |
| 625 | return -ESOCKTNOSUPPORT; |
| 626 | |
| 627 | sock->ops = &rxrpc_rpc_ops; |
| 628 | sock->state = SS_UNCONNECTED; |
| 629 | |
Eric W. Biederman | 11aa9c2 | 2015-05-08 21:09:13 -0500 | [diff] [blame] | 630 | sk = sk_alloc(net, PF_RXRPC, GFP_KERNEL, &rxrpc_proto, kern); |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 631 | if (!sk) |
| 632 | return -ENOMEM; |
| 633 | |
| 634 | sock_init_data(sock, sk); |
| 635 | sk->sk_state = RXRPC_UNCONNECTED; |
| 636 | sk->sk_write_space = rxrpc_write_space; |
| 637 | sk->sk_max_ack_backlog = sysctl_rxrpc_max_qlen; |
| 638 | sk->sk_destruct = rxrpc_sock_destructor; |
| 639 | |
| 640 | rx = rxrpc_sk(sk); |
| 641 | rx->proto = protocol; |
| 642 | rx->calls = RB_ROOT; |
| 643 | |
| 644 | INIT_LIST_HEAD(&rx->listen_link); |
| 645 | INIT_LIST_HEAD(&rx->secureq); |
| 646 | INIT_LIST_HEAD(&rx->acceptq); |
| 647 | rwlock_init(&rx->call_lock); |
| 648 | memset(&rx->srx, 0, sizeof(rx->srx)); |
| 649 | |
| 650 | _leave(" = 0 [%p]", rx); |
| 651 | return 0; |
| 652 | } |
| 653 | |
| 654 | /* |
| 655 | * RxRPC socket destructor |
| 656 | */ |
| 657 | static void rxrpc_sock_destructor(struct sock *sk) |
| 658 | { |
| 659 | _enter("%p", sk); |
| 660 | |
| 661 | rxrpc_purge_queue(&sk->sk_receive_queue); |
| 662 | |
Ilpo Järvinen | 547b792 | 2008-07-25 21:43:18 -0700 | [diff] [blame] | 663 | WARN_ON(atomic_read(&sk->sk_wmem_alloc)); |
| 664 | WARN_ON(!sk_unhashed(sk)); |
| 665 | WARN_ON(sk->sk_socket); |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 666 | |
| 667 | if (!sock_flag(sk, SOCK_DEAD)) { |
| 668 | printk("Attempt to release alive rxrpc socket: %p\n", sk); |
| 669 | return; |
| 670 | } |
| 671 | } |
| 672 | |
| 673 | /* |
| 674 | * release an RxRPC socket |
| 675 | */ |
| 676 | static int rxrpc_release_sock(struct sock *sk) |
| 677 | { |
| 678 | struct rxrpc_sock *rx = rxrpc_sk(sk); |
| 679 | |
| 680 | _enter("%p{%d,%d}", sk, sk->sk_state, atomic_read(&sk->sk_refcnt)); |
| 681 | |
| 682 | /* declare the socket closed for business */ |
| 683 | sock_orphan(sk); |
| 684 | sk->sk_shutdown = SHUTDOWN_MASK; |
| 685 | |
| 686 | spin_lock_bh(&sk->sk_receive_queue.lock); |
| 687 | sk->sk_state = RXRPC_CLOSE; |
| 688 | spin_unlock_bh(&sk->sk_receive_queue.lock); |
| 689 | |
| 690 | ASSERTCMP(rx->listen_link.next, !=, LIST_POISON1); |
| 691 | |
| 692 | if (!list_empty(&rx->listen_link)) { |
| 693 | write_lock_bh(&rx->local->services_lock); |
| 694 | list_del(&rx->listen_link); |
| 695 | write_unlock_bh(&rx->local->services_lock); |
| 696 | } |
| 697 | |
| 698 | /* try to flush out this socket */ |
| 699 | rxrpc_release_calls_on_socket(rx); |
David Howells | 651350d | 2007-04-26 15:50:17 -0700 | [diff] [blame] | 700 | flush_workqueue(rxrpc_workqueue); |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 701 | rxrpc_purge_queue(&sk->sk_receive_queue); |
| 702 | |
| 703 | if (rx->conn) { |
| 704 | rxrpc_put_connection(rx->conn); |
| 705 | rx->conn = NULL; |
| 706 | } |
| 707 | |
| 708 | if (rx->bundle) { |
| 709 | rxrpc_put_bundle(rx->trans, rx->bundle); |
| 710 | rx->bundle = NULL; |
| 711 | } |
| 712 | if (rx->trans) { |
| 713 | rxrpc_put_transport(rx->trans); |
| 714 | rx->trans = NULL; |
| 715 | } |
| 716 | if (rx->local) { |
| 717 | rxrpc_put_local(rx->local); |
| 718 | rx->local = NULL; |
| 719 | } |
| 720 | |
| 721 | key_put(rx->key); |
| 722 | rx->key = NULL; |
| 723 | key_put(rx->securities); |
| 724 | rx->securities = NULL; |
| 725 | sock_put(sk); |
| 726 | |
| 727 | _leave(" = 0"); |
| 728 | return 0; |
| 729 | } |
| 730 | |
| 731 | /* |
| 732 | * release an RxRPC BSD socket on close() or equivalent |
| 733 | */ |
| 734 | static int rxrpc_release(struct socket *sock) |
| 735 | { |
| 736 | struct sock *sk = sock->sk; |
| 737 | |
| 738 | _enter("%p{%p}", sock, sk); |
| 739 | |
| 740 | if (!sk) |
| 741 | return 0; |
| 742 | |
| 743 | sock->sk = NULL; |
| 744 | |
| 745 | return rxrpc_release_sock(sk); |
| 746 | } |
| 747 | |
| 748 | /* |
| 749 | * RxRPC network protocol |
| 750 | */ |
| 751 | static const struct proto_ops rxrpc_rpc_ops = { |
David Howells | e33b3d9 | 2016-03-04 15:54:27 +0000 | [diff] [blame] | 752 | .family = PF_RXRPC, |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 753 | .owner = THIS_MODULE, |
| 754 | .release = rxrpc_release, |
| 755 | .bind = rxrpc_bind, |
| 756 | .connect = rxrpc_connect, |
| 757 | .socketpair = sock_no_socketpair, |
| 758 | .accept = sock_no_accept, |
| 759 | .getname = sock_no_getname, |
| 760 | .poll = rxrpc_poll, |
| 761 | .ioctl = sock_no_ioctl, |
| 762 | .listen = rxrpc_listen, |
| 763 | .shutdown = sock_no_shutdown, |
| 764 | .setsockopt = rxrpc_setsockopt, |
| 765 | .getsockopt = sock_no_getsockopt, |
| 766 | .sendmsg = rxrpc_sendmsg, |
| 767 | .recvmsg = rxrpc_recvmsg, |
| 768 | .mmap = sock_no_mmap, |
| 769 | .sendpage = sock_no_sendpage, |
| 770 | }; |
| 771 | |
| 772 | static struct proto rxrpc_proto = { |
| 773 | .name = "RXRPC", |
| 774 | .owner = THIS_MODULE, |
| 775 | .obj_size = sizeof(struct rxrpc_sock), |
David Howells | 0d12f8a | 2016-03-04 15:53:46 +0000 | [diff] [blame] | 776 | .max_header = sizeof(struct rxrpc_wire_header), |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 777 | }; |
| 778 | |
Stephen Hemminger | ec1b4cf | 2009-10-05 05:58:39 +0000 | [diff] [blame] | 779 | static const struct net_proto_family rxrpc_family_ops = { |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 780 | .family = PF_RXRPC, |
| 781 | .create = rxrpc_create, |
| 782 | .owner = THIS_MODULE, |
| 783 | }; |
| 784 | |
| 785 | /* |
| 786 | * initialise and register the RxRPC protocol |
| 787 | */ |
| 788 | static int __init af_rxrpc_init(void) |
| 789 | { |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 790 | int ret = -1; |
| 791 | |
YOSHIFUJI Hideaki / 吉藤英明 | ce6654c | 2013-01-09 07:20:01 +0000 | [diff] [blame] | 792 | BUILD_BUG_ON(sizeof(struct rxrpc_skb_priv) > FIELD_SIZEOF(struct sk_buff, cb)); |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 793 | |
David Howells | 0d12f8a | 2016-03-04 15:53:46 +0000 | [diff] [blame] | 794 | rxrpc_epoch = get_seconds(); |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 795 | |
David Howells | 651350d | 2007-04-26 15:50:17 -0700 | [diff] [blame] | 796 | ret = -ENOMEM; |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 797 | rxrpc_call_jar = kmem_cache_create( |
| 798 | "rxrpc_call_jar", sizeof(struct rxrpc_call), 0, |
Paul Mundt | 20c2df8 | 2007-07-20 10:11:58 +0900 | [diff] [blame] | 799 | SLAB_HWCACHE_ALIGN, NULL); |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 800 | if (!rxrpc_call_jar) { |
Joe Perches | 9b6d539 | 2016-06-02 12:08:52 -0700 | [diff] [blame^] | 801 | pr_notice("Failed to allocate call jar\n"); |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 802 | goto error_call_jar; |
| 803 | } |
| 804 | |
Tejun Heo | e1fcc7e | 2011-01-14 15:56:31 +0000 | [diff] [blame] | 805 | rxrpc_workqueue = alloc_workqueue("krxrpcd", 0, 1); |
David Howells | 651350d | 2007-04-26 15:50:17 -0700 | [diff] [blame] | 806 | if (!rxrpc_workqueue) { |
Joe Perches | 9b6d539 | 2016-06-02 12:08:52 -0700 | [diff] [blame^] | 807 | pr_notice("Failed to allocate work queue\n"); |
David Howells | 651350d | 2007-04-26 15:50:17 -0700 | [diff] [blame] | 808 | goto error_work_queue; |
| 809 | } |
| 810 | |
David Howells | 648af7f | 2016-04-07 17:23:51 +0100 | [diff] [blame] | 811 | ret = rxrpc_init_security(); |
| 812 | if (ret < 0) { |
Joe Perches | 9b6d539 | 2016-06-02 12:08:52 -0700 | [diff] [blame^] | 813 | pr_crit("Cannot initialise security\n"); |
David Howells | 648af7f | 2016-04-07 17:23:51 +0100 | [diff] [blame] | 814 | goto error_security; |
| 815 | } |
| 816 | |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 817 | ret = proto_register(&rxrpc_proto, 1); |
YOSHIFUJI Hideaki | 1c89964 | 2007-07-19 10:44:44 +0900 | [diff] [blame] | 818 | if (ret < 0) { |
Joe Perches | 9b6d539 | 2016-06-02 12:08:52 -0700 | [diff] [blame^] | 819 | pr_crit("Cannot register protocol\n"); |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 820 | goto error_proto; |
| 821 | } |
| 822 | |
| 823 | ret = sock_register(&rxrpc_family_ops); |
| 824 | if (ret < 0) { |
Joe Perches | 9b6d539 | 2016-06-02 12:08:52 -0700 | [diff] [blame^] | 825 | pr_crit("Cannot register socket family\n"); |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 826 | goto error_sock; |
| 827 | } |
| 828 | |
| 829 | ret = register_key_type(&key_type_rxrpc); |
| 830 | if (ret < 0) { |
Joe Perches | 9b6d539 | 2016-06-02 12:08:52 -0700 | [diff] [blame^] | 831 | pr_crit("Cannot register client key type\n"); |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 832 | goto error_key_type; |
| 833 | } |
| 834 | |
| 835 | ret = register_key_type(&key_type_rxrpc_s); |
| 836 | if (ret < 0) { |
Joe Perches | 9b6d539 | 2016-06-02 12:08:52 -0700 | [diff] [blame^] | 837 | pr_crit("Cannot register server key type\n"); |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 838 | goto error_key_type_s; |
| 839 | } |
| 840 | |
David Howells | 5873c08 | 2014-02-07 18:58:44 +0000 | [diff] [blame] | 841 | ret = rxrpc_sysctl_init(); |
| 842 | if (ret < 0) { |
Joe Perches | 9b6d539 | 2016-06-02 12:08:52 -0700 | [diff] [blame^] | 843 | pr_crit("Cannot register sysctls\n"); |
David Howells | 5873c08 | 2014-02-07 18:58:44 +0000 | [diff] [blame] | 844 | goto error_sysctls; |
| 845 | } |
| 846 | |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 847 | #ifdef CONFIG_PROC_FS |
Gao feng | d4beaa6 | 2013-02-18 01:34:54 +0000 | [diff] [blame] | 848 | proc_create("rxrpc_calls", 0, init_net.proc_net, &rxrpc_call_seq_fops); |
| 849 | proc_create("rxrpc_conns", 0, init_net.proc_net, |
| 850 | &rxrpc_connection_seq_fops); |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 851 | #endif |
| 852 | return 0; |
| 853 | |
David Howells | 5873c08 | 2014-02-07 18:58:44 +0000 | [diff] [blame] | 854 | error_sysctls: |
| 855 | unregister_key_type(&key_type_rxrpc_s); |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 856 | error_key_type_s: |
| 857 | unregister_key_type(&key_type_rxrpc); |
| 858 | error_key_type: |
| 859 | sock_unregister(PF_RXRPC); |
| 860 | error_sock: |
| 861 | proto_unregister(&rxrpc_proto); |
| 862 | error_proto: |
David Howells | 651350d | 2007-04-26 15:50:17 -0700 | [diff] [blame] | 863 | destroy_workqueue(rxrpc_workqueue); |
David Howells | 648af7f | 2016-04-07 17:23:51 +0100 | [diff] [blame] | 864 | error_security: |
| 865 | rxrpc_exit_security(); |
David Howells | 651350d | 2007-04-26 15:50:17 -0700 | [diff] [blame] | 866 | error_work_queue: |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 867 | kmem_cache_destroy(rxrpc_call_jar); |
| 868 | error_call_jar: |
| 869 | return ret; |
| 870 | } |
| 871 | |
| 872 | /* |
| 873 | * unregister the RxRPC protocol |
| 874 | */ |
| 875 | static void __exit af_rxrpc_exit(void) |
| 876 | { |
| 877 | _enter(""); |
David Howells | 5873c08 | 2014-02-07 18:58:44 +0000 | [diff] [blame] | 878 | rxrpc_sysctl_exit(); |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 879 | unregister_key_type(&key_type_rxrpc_s); |
| 880 | unregister_key_type(&key_type_rxrpc); |
| 881 | sock_unregister(PF_RXRPC); |
| 882 | proto_unregister(&rxrpc_proto); |
| 883 | rxrpc_destroy_all_calls(); |
| 884 | rxrpc_destroy_all_connections(); |
| 885 | rxrpc_destroy_all_transports(); |
| 886 | rxrpc_destroy_all_peers(); |
| 887 | rxrpc_destroy_all_locals(); |
| 888 | |
| 889 | ASSERTCMP(atomic_read(&rxrpc_n_skbs), ==, 0); |
| 890 | |
| 891 | _debug("flush scheduled work"); |
David Howells | 651350d | 2007-04-26 15:50:17 -0700 | [diff] [blame] | 892 | flush_workqueue(rxrpc_workqueue); |
Gao feng | ece31ff | 2013-02-18 01:34:56 +0000 | [diff] [blame] | 893 | remove_proc_entry("rxrpc_conns", init_net.proc_net); |
| 894 | remove_proc_entry("rxrpc_calls", init_net.proc_net); |
David Howells | 651350d | 2007-04-26 15:50:17 -0700 | [diff] [blame] | 895 | destroy_workqueue(rxrpc_workqueue); |
David Howells | 648af7f | 2016-04-07 17:23:51 +0100 | [diff] [blame] | 896 | rxrpc_exit_security(); |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 897 | kmem_cache_destroy(rxrpc_call_jar); |
| 898 | _leave(""); |
| 899 | } |
| 900 | |
| 901 | module_init(af_rxrpc_init); |
| 902 | module_exit(af_rxrpc_exit); |