1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /* AF_RXRPC implementation
4 * Copyright (C) 2007 Red Hat, Inc. All Rights Reserved.
5 * Written by David Howells (dhowells@redhat.com)
8 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
10 #include <linux/module.h>
11 #include <linux/kernel.h>
12 #include <linux/net.h>
13 #include <linux/slab.h>
14 #include <linux/skbuff.h>
15 #include <linux/random.h>
16 #include <linux/poll.h>
17 #include <linux/proc_fs.h>
18 #include <linux/key-type.h>
19 #include <net/net_namespace.h>
21 #include <net/af_rxrpc.h>
22 #define CREATE_TRACE_POINTS
23 #include "ar-internal.h"
25 MODULE_DESCRIPTION("RxRPC network protocol");
26 MODULE_AUTHOR("Red Hat, Inc.");
27 MODULE_LICENSE("GPL");
28 MODULE_ALIAS_NETPROTO(PF_RXRPC);
30 unsigned int rxrpc_debug; // = RXRPC_DEBUG_KPROTO;
31 module_param_named(debug, rxrpc_debug, uint, 0644);
32 MODULE_PARM_DESC(debug, "RxRPC debugging mask");
34 static struct proto rxrpc_proto;
35 static const struct proto_ops rxrpc_rpc_ops;
37 /* current debugging ID */
38 atomic_t rxrpc_debug_id;
39 EXPORT_SYMBOL(rxrpc_debug_id);
41 /* count of skbs currently in use */
42 atomic_t rxrpc_n_rx_skbs;
44 struct workqueue_struct *rxrpc_workqueue;
46 static void rxrpc_sock_destructor(struct sock *);
49 * see if an RxRPC socket is currently writable
51 static inline int rxrpc_writable(struct sock *sk)
53 return refcount_read(&sk->sk_wmem_alloc) < (size_t) sk->sk_sndbuf;
57 * wait for write bufferage to become available
59 static void rxrpc_write_space(struct sock *sk)
63 if (rxrpc_writable(sk)) {
64 struct socket_wq *wq = rcu_dereference(sk->sk_wq);
66 if (skwq_has_sleeper(wq))
67 wake_up_interruptible(&wq->wait);
68 sk_wake_async(sk, SOCK_WAKE_SPACE, POLL_OUT);
74 * validate an RxRPC address
76 static int rxrpc_validate_address(struct rxrpc_sock *rx,
77 struct sockaddr_rxrpc *srx,
82 if (len < sizeof(struct sockaddr_rxrpc))
85 if (srx->srx_family != AF_RXRPC)
88 if (srx->transport_type != SOCK_DGRAM)
89 return -ESOCKTNOSUPPORT;
91 len -= offsetof(struct sockaddr_rxrpc, transport);
92 if (srx->transport_len < sizeof(sa_family_t) ||
93 srx->transport_len > len)
96 switch (srx->transport.family) {
98 if (rx->family != AF_INET &&
99 rx->family != AF_INET6)
100 return -EAFNOSUPPORT;
101 if (srx->transport_len < sizeof(struct sockaddr_in))
103 tail = offsetof(struct sockaddr_rxrpc, transport.sin.__pad);
106 #ifdef CONFIG_AF_RXRPC_IPV6
108 if (rx->family != AF_INET6)
109 return -EAFNOSUPPORT;
110 if (srx->transport_len < sizeof(struct sockaddr_in6))
112 tail = offsetof(struct sockaddr_rxrpc, transport) +
113 sizeof(struct sockaddr_in6);
118 return -EAFNOSUPPORT;
122 memset((void *)srx + tail, 0, len - tail);
123 _debug("INET: %pISp", &srx->transport);
128 * bind a local address to an RxRPC socket
130 static int rxrpc_bind(struct socket *sock, struct sockaddr *saddr, int len)
132 struct sockaddr_rxrpc *srx = (struct sockaddr_rxrpc *)saddr;
133 struct rxrpc_local *local;
134 struct rxrpc_sock *rx = rxrpc_sk(sock->sk);
138 _enter("%p,%p,%d", rx, saddr, len);
140 ret = rxrpc_validate_address(rx, srx, len);
143 service_id = srx->srx_service;
147 switch (rx->sk.sk_state) {
150 local = rxrpc_lookup_local(sock_net(&rx->sk), &rx->srx);
152 ret = PTR_ERR(local);
157 write_lock(&local->services_lock);
158 if (rcu_access_pointer(local->service))
161 rcu_assign_pointer(local->service, rx);
162 write_unlock(&local->services_lock);
164 rx->sk.sk_state = RXRPC_SERVER_BOUND;
167 rx->sk.sk_state = RXRPC_CLIENT_BOUND;
171 case RXRPC_SERVER_BOUND:
176 if (service_id == rx->srx.srx_service)
179 srx->srx_service = rx->srx.srx_service;
180 if (memcmp(srx, &rx->srx, sizeof(*srx)) != 0)
182 rx->second_service = service_id;
183 rx->sk.sk_state = RXRPC_SERVER_BOUND2;
191 release_sock(&rx->sk);
196 write_unlock(&local->services_lock);
197 rxrpc_unuse_local(local, rxrpc_local_unuse_bind);
198 rxrpc_put_local(local, rxrpc_local_put_bind);
201 release_sock(&rx->sk);
203 _leave(" = %d", ret);
208 * set the number of pending calls permitted on a listening socket
210 static int rxrpc_listen(struct socket *sock, int backlog)
212 struct sock *sk = sock->sk;
213 struct rxrpc_sock *rx = rxrpc_sk(sk);
214 unsigned int max, old;
217 _enter("%p,%d", rx, backlog);
221 switch (rx->sk.sk_state) {
223 ret = -EADDRNOTAVAIL;
225 case RXRPC_SERVER_BOUND:
226 case RXRPC_SERVER_BOUND2:
227 ASSERT(rx->local != NULL);
228 max = READ_ONCE(rxrpc_max_backlog);
230 if (backlog == INT_MAX)
232 else if (backlog < 0 || backlog > max)
234 old = sk->sk_max_ack_backlog;
235 sk->sk_max_ack_backlog = backlog;
236 ret = rxrpc_service_prealloc(rx, GFP_KERNEL);
238 rx->sk.sk_state = RXRPC_SERVER_LISTENING;
240 sk->sk_max_ack_backlog = old;
242 case RXRPC_SERVER_LISTENING:
244 rx->sk.sk_state = RXRPC_SERVER_LISTEN_DISABLED;
245 sk->sk_max_ack_backlog = 0;
246 rxrpc_discard_prealloc(rx);
256 release_sock(&rx->sk);
257 _leave(" = %d", ret);
262 * rxrpc_kernel_begin_call - Allow a kernel service to begin a call
263 * @sock: The socket on which to make the call
264 * @srx: The address of the peer to contact
265 * @key: The security context to use (defaults to socket setting)
266 * @user_call_ID: The ID to use
267 * @tx_total_len: Total length of data to transmit during the call (or -1)
268 * @gfp: The allocation constraints
269 * @notify_rx: Where to send notifications instead of socket queue
270 * @upgrade: Request service upgrade for call
271 * @interruptibility: The call is interruptible, or can be canceled.
272 * @debug_id: The debug ID for tracing to be assigned to the call
274 * Allow a kernel service to begin a call on the nominated socket. This just
275 * sets up all the internal tracking structures and allocates connection and
276 * call IDs as appropriate. The call to be used is returned.
278 * The default socket destination address and security may be overridden by
279 * supplying @srx and @key.
281 struct rxrpc_call *rxrpc_kernel_begin_call(struct socket *sock,
282 struct sockaddr_rxrpc *srx,
284 unsigned long user_call_ID,
287 rxrpc_notify_rx_t notify_rx,
289 enum rxrpc_interruptibility interruptibility,
290 unsigned int debug_id)
292 struct rxrpc_conn_parameters cp;
293 struct rxrpc_call_params p;
294 struct rxrpc_call *call;
295 struct rxrpc_sock *rx = rxrpc_sk(sock->sk);
298 _enter(",,%x,%lx", key_serial(key), user_call_ID);
300 ret = rxrpc_validate_address(rx, srx, sizeof(*srx));
308 if (key && !key->payload.data[0])
309 key = NULL; /* a no-security key */
311 memset(&p, 0, sizeof(p));
312 p.user_call_ID = user_call_ID;
313 p.tx_total_len = tx_total_len;
314 p.interruptibility = interruptibility;
317 memset(&cp, 0, sizeof(cp));
318 cp.local = rx->local;
320 cp.security_level = rx->min_sec_level;
321 cp.exclusive = false;
322 cp.upgrade = upgrade;
323 cp.service_id = srx->srx_service;
324 call = rxrpc_new_client_call(rx, &cp, srx, &p, gfp, debug_id);
325 /* The socket has been unlocked. */
327 call->notify_rx = notify_rx;
328 mutex_unlock(&call->user_mutex);
331 rxrpc_put_peer(cp.peer, rxrpc_peer_put_discard_tmp);
332 _leave(" = %p", call);
335 EXPORT_SYMBOL(rxrpc_kernel_begin_call);
338 * Dummy function used to stop the notifier talking to recvmsg().
340 static void rxrpc_dummy_notify_rx(struct sock *sk, struct rxrpc_call *rxcall,
341 unsigned long call_user_ID)
346 * rxrpc_kernel_end_call - Allow a kernel service to end a call it was using
347 * @sock: The socket the call is on
348 * @call: The call to end
350 * Allow a kernel service to end a call it was using. The call must be
351 * complete before this is called (the call should be aborted if necessary).
353 void rxrpc_kernel_end_call(struct socket *sock, struct rxrpc_call *call)
355 _enter("%d{%d}", call->debug_id, refcount_read(&call->ref));
357 mutex_lock(&call->user_mutex);
358 rxrpc_release_call(rxrpc_sk(sock->sk), call);
360 /* Make sure we're not going to call back into a kernel service */
361 if (call->notify_rx) {
362 spin_lock_bh(&call->notify_lock);
363 call->notify_rx = rxrpc_dummy_notify_rx;
364 spin_unlock_bh(&call->notify_lock);
367 mutex_unlock(&call->user_mutex);
368 rxrpc_put_call(call, rxrpc_call_put_kernel);
370 EXPORT_SYMBOL(rxrpc_kernel_end_call);
373 * rxrpc_kernel_check_life - Check to see whether a call is still alive
374 * @sock: The socket the call is on
375 * @call: The call to check
377 * Allow a kernel service to find out whether a call is still alive -
378 * ie. whether it has completed.
380 bool rxrpc_kernel_check_life(const struct socket *sock,
381 const struct rxrpc_call *call)
383 return call->state != RXRPC_CALL_COMPLETE;
385 EXPORT_SYMBOL(rxrpc_kernel_check_life);
388 * rxrpc_kernel_get_epoch - Retrieve the epoch value from a call.
389 * @sock: The socket the call is on
390 * @call: The call to query
392 * Allow a kernel service to retrieve the epoch value from a service call to
393 * see if the client at the other end rebooted.
395 u32 rxrpc_kernel_get_epoch(struct socket *sock, struct rxrpc_call *call)
397 return call->conn->proto.epoch;
399 EXPORT_SYMBOL(rxrpc_kernel_get_epoch);
402 * rxrpc_kernel_new_call_notification - Get notifications of new calls
403 * @sock: The socket to intercept received messages on
404 * @notify_new_call: Function to be called when new calls appear
405 * @discard_new_call: Function to discard preallocated calls
407 * Allow a kernel service to be given notifications about new calls.
409 void rxrpc_kernel_new_call_notification(
411 rxrpc_notify_new_call_t notify_new_call,
412 rxrpc_discard_new_call_t discard_new_call)
414 struct rxrpc_sock *rx = rxrpc_sk(sock->sk);
416 rx->notify_new_call = notify_new_call;
417 rx->discard_new_call = discard_new_call;
419 EXPORT_SYMBOL(rxrpc_kernel_new_call_notification);
422 * rxrpc_kernel_set_max_life - Set maximum lifespan on a call
423 * @sock: The socket the call is on
424 * @call: The call to configure
425 * @hard_timeout: The maximum lifespan of the call in jiffies
427 * Set the maximum lifespan of a call. The call will end with ETIME or
428 * ETIMEDOUT if it takes longer than this.
430 void rxrpc_kernel_set_max_life(struct socket *sock, struct rxrpc_call *call,
431 unsigned long hard_timeout)
435 mutex_lock(&call->user_mutex);
439 WRITE_ONCE(call->expect_term_by, hard_timeout);
440 rxrpc_reduce_call_timer(call, hard_timeout, now, rxrpc_timer_set_for_hard);
442 mutex_unlock(&call->user_mutex);
444 EXPORT_SYMBOL(rxrpc_kernel_set_max_life);
447 * connect an RxRPC socket
448 * - this just targets it at a specific destination; no actual connection
449 * negotiation takes place
451 static int rxrpc_connect(struct socket *sock, struct sockaddr *addr,
452 int addr_len, int flags)
454 struct sockaddr_rxrpc *srx = (struct sockaddr_rxrpc *)addr;
455 struct rxrpc_sock *rx = rxrpc_sk(sock->sk);
458 _enter("%p,%p,%d,%d", rx, addr, addr_len, flags);
460 ret = rxrpc_validate_address(rx, srx, addr_len);
462 _leave(" = %d [bad addr]", ret);
469 if (test_bit(RXRPC_SOCK_CONNECTED, &rx->flags))
472 switch (rx->sk.sk_state) {
474 rx->sk.sk_state = RXRPC_CLIENT_UNBOUND;
476 case RXRPC_CLIENT_UNBOUND:
477 case RXRPC_CLIENT_BOUND:
484 rx->connect_srx = *srx;
485 set_bit(RXRPC_SOCK_CONNECTED, &rx->flags);
489 release_sock(&rx->sk);
494 * send a message through an RxRPC socket
495 * - in a client this does a number of things:
496 * - finds/sets up a connection for the security specified (if any)
497 * - initiates a call (ID in control data)
498 * - ends the request phase of a call (if MSG_MORE is not set)
499 * - sends a call data packet
500 * - may send an abort (abort code in control data)
502 static int rxrpc_sendmsg(struct socket *sock, struct msghdr *m, size_t len)
504 struct rxrpc_local *local;
505 struct rxrpc_sock *rx = rxrpc_sk(sock->sk);
508 _enter(",{%d},,%zu", rx->sk.sk_state, len);
510 if (m->msg_flags & MSG_OOB)
514 ret = rxrpc_validate_address(rx, m->msg_name, m->msg_namelen);
516 _leave(" = %d [bad addr]", ret);
523 switch (rx->sk.sk_state) {
525 case RXRPC_CLIENT_UNBOUND:
526 rx->srx.srx_family = AF_RXRPC;
527 rx->srx.srx_service = 0;
528 rx->srx.transport_type = SOCK_DGRAM;
529 rx->srx.transport.family = rx->family;
530 switch (rx->family) {
532 rx->srx.transport_len = sizeof(struct sockaddr_in);
534 #ifdef CONFIG_AF_RXRPC_IPV6
536 rx->srx.transport_len = sizeof(struct sockaddr_in6);
543 local = rxrpc_lookup_local(sock_net(sock->sk), &rx->srx);
545 ret = PTR_ERR(local);
550 rx->sk.sk_state = RXRPC_CLIENT_BOUND;
553 case RXRPC_CLIENT_BOUND:
555 test_bit(RXRPC_SOCK_CONNECTED, &rx->flags)) {
556 m->msg_name = &rx->connect_srx;
557 m->msg_namelen = sizeof(rx->connect_srx);
560 case RXRPC_SERVER_BOUND:
561 case RXRPC_SERVER_LISTENING:
562 ret = rxrpc_do_sendmsg(rx, m, len);
563 /* The socket has been unlocked */
571 release_sock(&rx->sk);
573 _leave(" = %d", ret);
577 int rxrpc_sock_set_min_security_level(struct sock *sk, unsigned int val)
579 if (sk->sk_state != RXRPC_UNBOUND)
581 if (val > RXRPC_SECURITY_MAX)
584 rxrpc_sk(sk)->min_sec_level = val;
588 EXPORT_SYMBOL(rxrpc_sock_set_min_security_level);
591 * set RxRPC socket options
593 static int rxrpc_setsockopt(struct socket *sock, int level, int optname,
594 sockptr_t optval, unsigned int optlen)
596 struct rxrpc_sock *rx = rxrpc_sk(sock->sk);
597 unsigned int min_sec_level;
598 u16 service_upgrade[2];
601 _enter(",%d,%d,,%d", level, optname, optlen);
606 if (level == SOL_RXRPC) {
608 case RXRPC_EXCLUSIVE_CONNECTION:
613 if (rx->sk.sk_state != RXRPC_UNBOUND)
615 rx->exclusive = true;
618 case RXRPC_SECURITY_KEY:
623 if (rx->sk.sk_state != RXRPC_UNBOUND)
625 ret = rxrpc_request_key(rx, optval, optlen);
628 case RXRPC_SECURITY_KEYRING:
633 if (rx->sk.sk_state != RXRPC_UNBOUND)
635 ret = rxrpc_server_keyring(rx, optval, optlen);
638 case RXRPC_MIN_SECURITY_LEVEL:
640 if (optlen != sizeof(unsigned int))
643 if (rx->sk.sk_state != RXRPC_UNBOUND)
645 ret = copy_from_sockptr(&min_sec_level, optval,
646 sizeof(unsigned int));
650 if (min_sec_level > RXRPC_SECURITY_MAX)
652 rx->min_sec_level = min_sec_level;
655 case RXRPC_UPGRADEABLE_SERVICE:
657 if (optlen != sizeof(service_upgrade) ||
658 rx->service_upgrade.from != 0)
661 if (rx->sk.sk_state != RXRPC_SERVER_BOUND2)
664 if (copy_from_sockptr(service_upgrade, optval,
665 sizeof(service_upgrade)) != 0)
668 if ((service_upgrade[0] != rx->srx.srx_service ||
669 service_upgrade[1] != rx->second_service) &&
670 (service_upgrade[0] != rx->second_service ||
671 service_upgrade[1] != rx->srx.srx_service))
673 rx->service_upgrade.from = service_upgrade[0];
674 rx->service_upgrade.to = service_upgrade[1];
685 release_sock(&rx->sk);
690 * Get socket options.
692 static int rxrpc_getsockopt(struct socket *sock, int level, int optname,
693 char __user *optval, int __user *_optlen)
697 if (level != SOL_RXRPC)
700 if (get_user(optlen, _optlen))
704 case RXRPC_SUPPORTED_CMSG:
705 if (optlen < sizeof(int))
707 if (put_user(RXRPC__SUPPORTED - 1, (int __user *)optval) ||
708 put_user(sizeof(int), _optlen))
718 * permit an RxRPC socket to be polled
720 static __poll_t rxrpc_poll(struct file *file, struct socket *sock,
723 struct sock *sk = sock->sk;
724 struct rxrpc_sock *rx = rxrpc_sk(sk);
727 sock_poll_wait(file, sock, wait);
730 /* the socket is readable if there are any messages waiting on the Rx
732 if (!list_empty(&rx->recvmsg_q))
733 mask |= EPOLLIN | EPOLLRDNORM;
735 /* the socket is writable if there is space to add new data to the
736 * socket; there is no guarantee that any particular call in progress
737 * on the socket may have space in the Tx ACK window */
738 if (rxrpc_writable(sk))
739 mask |= EPOLLOUT | EPOLLWRNORM;
745 * create an RxRPC socket
747 static int rxrpc_create(struct net *net, struct socket *sock, int protocol,
750 struct rxrpc_net *rxnet;
751 struct rxrpc_sock *rx;
754 _enter("%p,%d", sock, protocol);
756 /* we support transport protocol UDP/UDP6 only */
757 if (protocol != PF_INET &&
758 IS_ENABLED(CONFIG_AF_RXRPC_IPV6) && protocol != PF_INET6)
759 return -EPROTONOSUPPORT;
761 if (sock->type != SOCK_DGRAM)
762 return -ESOCKTNOSUPPORT;
764 sock->ops = &rxrpc_rpc_ops;
765 sock->state = SS_UNCONNECTED;
767 sk = sk_alloc(net, PF_RXRPC, GFP_KERNEL, &rxrpc_proto, kern);
771 sock_init_data(sock, sk);
772 sock_set_flag(sk, SOCK_RCU_FREE);
773 sk->sk_state = RXRPC_UNBOUND;
774 sk->sk_write_space = rxrpc_write_space;
775 sk->sk_max_ack_backlog = 0;
776 sk->sk_destruct = rxrpc_sock_destructor;
779 rx->family = protocol;
782 spin_lock_init(&rx->incoming_lock);
783 INIT_LIST_HEAD(&rx->sock_calls);
784 INIT_LIST_HEAD(&rx->to_be_accepted);
785 INIT_LIST_HEAD(&rx->recvmsg_q);
786 rwlock_init(&rx->recvmsg_lock);
787 rwlock_init(&rx->call_lock);
788 memset(&rx->srx, 0, sizeof(rx->srx));
790 rxnet = rxrpc_net(sock_net(&rx->sk));
791 timer_reduce(&rxnet->peer_keepalive_timer, jiffies + 1);
793 _leave(" = 0 [%p]", rx);
798 * Kill all the calls on a socket and shut it down.
800 static int rxrpc_shutdown(struct socket *sock, int flags)
802 struct sock *sk = sock->sk;
803 struct rxrpc_sock *rx = rxrpc_sk(sk);
806 _enter("%p,%d", sk, flags);
808 if (flags != SHUT_RDWR)
810 if (sk->sk_state == RXRPC_CLOSE)
815 spin_lock_bh(&sk->sk_receive_queue.lock);
816 if (sk->sk_state < RXRPC_CLOSE) {
817 sk->sk_state = RXRPC_CLOSE;
818 sk->sk_shutdown = SHUTDOWN_MASK;
822 spin_unlock_bh(&sk->sk_receive_queue.lock);
824 rxrpc_discard_prealloc(rx);
831 * RxRPC socket destructor
833 static void rxrpc_sock_destructor(struct sock *sk)
837 rxrpc_purge_queue(&sk->sk_receive_queue);
839 WARN_ON(refcount_read(&sk->sk_wmem_alloc));
840 WARN_ON(!sk_unhashed(sk));
841 WARN_ON(sk->sk_socket);
843 if (!sock_flag(sk, SOCK_DEAD)) {
844 printk("Attempt to release alive rxrpc socket: %p\n", sk);
850 * release an RxRPC socket
852 static int rxrpc_release_sock(struct sock *sk)
854 struct rxrpc_sock *rx = rxrpc_sk(sk);
856 _enter("%p{%d,%d}", sk, sk->sk_state, refcount_read(&sk->sk_refcnt));
858 /* declare the socket closed for business */
860 sk->sk_shutdown = SHUTDOWN_MASK;
862 /* We want to kill off all connections from a service socket
863 * as fast as possible because we can't share these; client
864 * sockets, on the other hand, can share an endpoint.
866 switch (sk->sk_state) {
867 case RXRPC_SERVER_BOUND:
868 case RXRPC_SERVER_BOUND2:
869 case RXRPC_SERVER_LISTENING:
870 case RXRPC_SERVER_LISTEN_DISABLED:
871 rx->local->service_closed = true;
875 spin_lock_bh(&sk->sk_receive_queue.lock);
876 sk->sk_state = RXRPC_CLOSE;
877 spin_unlock_bh(&sk->sk_receive_queue.lock);
879 if (rx->local && rcu_access_pointer(rx->local->service) == rx) {
880 write_lock(&rx->local->services_lock);
881 rcu_assign_pointer(rx->local->service, NULL);
882 write_unlock(&rx->local->services_lock);
885 /* try to flush out this socket */
886 rxrpc_discard_prealloc(rx);
887 rxrpc_release_calls_on_socket(rx);
888 flush_workqueue(rxrpc_workqueue);
889 rxrpc_purge_queue(&sk->sk_receive_queue);
891 rxrpc_unuse_local(rx->local, rxrpc_local_unuse_release_sock);
892 rxrpc_put_local(rx->local, rxrpc_local_put_release_sock);
896 key_put(rx->securities);
897 rx->securities = NULL;
905 * release an RxRPC BSD socket on close() or equivalent
907 static int rxrpc_release(struct socket *sock)
909 struct sock *sk = sock->sk;
911 _enter("%p{%p}", sock, sk);
918 return rxrpc_release_sock(sk);
922 * RxRPC network protocol
924 static const struct proto_ops rxrpc_rpc_ops = {
926 .owner = THIS_MODULE,
927 .release = rxrpc_release,
929 .connect = rxrpc_connect,
930 .socketpair = sock_no_socketpair,
931 .accept = sock_no_accept,
932 .getname = sock_no_getname,
934 .ioctl = sock_no_ioctl,
935 .listen = rxrpc_listen,
936 .shutdown = rxrpc_shutdown,
937 .setsockopt = rxrpc_setsockopt,
938 .getsockopt = rxrpc_getsockopt,
939 .sendmsg = rxrpc_sendmsg,
940 .recvmsg = rxrpc_recvmsg,
941 .mmap = sock_no_mmap,
942 .sendpage = sock_no_sendpage,
945 static struct proto rxrpc_proto = {
947 .owner = THIS_MODULE,
948 .obj_size = sizeof(struct rxrpc_sock),
949 .max_header = sizeof(struct rxrpc_wire_header),
952 static const struct net_proto_family rxrpc_family_ops = {
954 .create = rxrpc_create,
955 .owner = THIS_MODULE,
959 * initialise and register the RxRPC protocol
961 static int __init af_rxrpc_init(void)
966 BUILD_BUG_ON(sizeof(struct rxrpc_skb_priv) > sizeof_field(struct sk_buff, cb));
968 get_random_bytes(&tmp, sizeof(tmp));
972 idr_set_cursor(&rxrpc_client_conn_ids, tmp);
975 rxrpc_call_jar = kmem_cache_create(
976 "rxrpc_call_jar", sizeof(struct rxrpc_call), 0,
977 SLAB_HWCACHE_ALIGN, NULL);
978 if (!rxrpc_call_jar) {
979 pr_notice("Failed to allocate call jar\n");
983 rxrpc_workqueue = alloc_workqueue("krxrpcd", WQ_HIGHPRI | WQ_MEM_RECLAIM | WQ_UNBOUND, 1);
984 if (!rxrpc_workqueue) {
985 pr_notice("Failed to allocate work queue\n");
986 goto error_work_queue;
989 ret = rxrpc_init_security();
991 pr_crit("Cannot initialise security\n");
995 ret = register_pernet_device(&rxrpc_net_ops);
999 ret = proto_register(&rxrpc_proto, 1);
1001 pr_crit("Cannot register protocol\n");
1005 ret = sock_register(&rxrpc_family_ops);
1007 pr_crit("Cannot register socket family\n");
1011 ret = register_key_type(&key_type_rxrpc);
1013 pr_crit("Cannot register client key type\n");
1014 goto error_key_type;
1017 ret = register_key_type(&key_type_rxrpc_s);
1019 pr_crit("Cannot register server key type\n");
1020 goto error_key_type_s;
1023 ret = rxrpc_sysctl_init();
1025 pr_crit("Cannot register sysctls\n");
1032 unregister_key_type(&key_type_rxrpc_s);
1034 unregister_key_type(&key_type_rxrpc);
1036 sock_unregister(PF_RXRPC);
1038 proto_unregister(&rxrpc_proto);
1040 unregister_pernet_device(&rxrpc_net_ops);
1042 rxrpc_exit_security();
1044 destroy_workqueue(rxrpc_workqueue);
1046 kmem_cache_destroy(rxrpc_call_jar);
1052 * unregister the RxRPC protocol
1054 static void __exit af_rxrpc_exit(void)
1057 rxrpc_sysctl_exit();
1058 unregister_key_type(&key_type_rxrpc_s);
1059 unregister_key_type(&key_type_rxrpc);
1060 sock_unregister(PF_RXRPC);
1061 proto_unregister(&rxrpc_proto);
1062 unregister_pernet_device(&rxrpc_net_ops);
1063 ASSERTCMP(atomic_read(&rxrpc_n_rx_skbs), ==, 0);
1065 /* Make sure the local and peer records pinned by any dying connections
1069 rxrpc_destroy_client_conn_ids();
1071 destroy_workqueue(rxrpc_workqueue);
1072 rxrpc_exit_security();
1073 kmem_cache_destroy(rxrpc_call_jar);
1077 module_init(af_rxrpc_init);
1078 module_exit(af_rxrpc_exit);