xref: /openbmc/linux/net/rxrpc/ar-internal.h (revision 2c9dc472)
12874c5fdSThomas Gleixner /* SPDX-License-Identifier: GPL-2.0-or-later */
217926a79SDavid Howells /* AF_RXRPC internal definitions
317926a79SDavid Howells  *
417926a79SDavid Howells  * Copyright (C) 2007 Red Hat, Inc. All Rights Reserved.
517926a79SDavid Howells  * Written by David Howells (dhowells@redhat.com)
617926a79SDavid Howells  */
717926a79SDavid Howells 
8be6e6707SDavid Howells #include <linux/atomic.h>
98496af50SDavid Howells #include <linux/seqlock.h>
10c410bf01SDavid Howells #include <linux/win_minmax.h>
112baec2c3SDavid Howells #include <net/net_namespace.h>
122baec2c3SDavid Howells #include <net/netns/generic.h>
13e0e4d82fSDavid Howells #include <net/sock.h>
14be6e6707SDavid Howells #include <net/af_rxrpc.h>
1541057ebdSDavid Howells #include <keys/rxrpc-type.h>
16ddc6c70fSDavid Howells #include "protocol.h"
1717926a79SDavid Howells 
1817926a79SDavid Howells #define FCRYPT_BSIZE 8
1917926a79SDavid Howells struct rxrpc_crypt {
2017926a79SDavid Howells 	union {
2117926a79SDavid Howells 		u8	x[FCRYPT_BSIZE];
2291e916cfSAl Viro 		__be32	n[2];
2317926a79SDavid Howells 	};
2417926a79SDavid Howells } __attribute__((aligned(8)));
2517926a79SDavid Howells 
26651350d1SDavid Howells #define rxrpc_queue_work(WS)	queue_work(rxrpc_workqueue, (WS))
27651350d1SDavid Howells #define rxrpc_queue_delayed_work(WS,D)	\
28651350d1SDavid Howells 	queue_delayed_work(rxrpc_workqueue, (WS), (D))
29651350d1SDavid Howells 
3012da59fcSDavid Howells struct key_preparsed_payload;
31cc8feb8eSDavid Howells struct rxrpc_connection;
3202a19356SDavid Howells struct rxrpc_txbuf;
33cc8feb8eSDavid Howells 
3417926a79SDavid Howells /*
35ece64fecSDavid Howells  * Mark applied to socket buffers in skb->mark.  skb->priority is used
36ece64fecSDavid Howells  * to pass supplementary information.
37d001648eSDavid Howells  */
38d001648eSDavid Howells enum rxrpc_skb_mark {
39446b3e14SDavid Howells 	RXRPC_SKB_MARK_PACKET,		/* Received packet */
40ff734825SDavid Howells 	RXRPC_SKB_MARK_ERROR,		/* Error notification */
412953d3b8SDavid Howells 	RXRPC_SKB_MARK_SERVICE_CONN_SECURED, /* Service connection response has been verified */
42ece64fecSDavid Howells 	RXRPC_SKB_MARK_REJECT_BUSY,	/* Reject with BUSY */
43ece64fecSDavid Howells 	RXRPC_SKB_MARK_REJECT_ABORT,	/* Reject with ABORT (code in skb->priority) */
44d001648eSDavid Howells };
45d001648eSDavid Howells 
46d001648eSDavid Howells /*
4717926a79SDavid Howells  * sk_state for RxRPC sockets
4817926a79SDavid Howells  */
4917926a79SDavid Howells enum {
502341e077SDavid Howells 	RXRPC_UNBOUND = 0,
512341e077SDavid Howells 	RXRPC_CLIENT_UNBOUND,		/* Unbound socket used as client */
5217926a79SDavid Howells 	RXRPC_CLIENT_BOUND,		/* client local address bound */
5317926a79SDavid Howells 	RXRPC_SERVER_BOUND,		/* server local address bound */
5428036f44SDavid Howells 	RXRPC_SERVER_BOUND2,		/* second server local address bound */
5517926a79SDavid Howells 	RXRPC_SERVER_LISTENING,		/* server listening for connections */
56210f0353SDavid Howells 	RXRPC_SERVER_LISTEN_DISABLED,	/* server listening disabled */
5717926a79SDavid Howells 	RXRPC_CLOSE,			/* socket is being closed */
5817926a79SDavid Howells };
5917926a79SDavid Howells 
6017926a79SDavid Howells /*
612baec2c3SDavid Howells  * Per-network namespace data.
622baec2c3SDavid Howells  */
632baec2c3SDavid Howells struct rxrpc_net {
642baec2c3SDavid Howells 	struct proc_dir_entry	*proc_net;	/* Subdir in /proc/net */
652baec2c3SDavid Howells 	u32			epoch;		/* Local epoch for detecting local-end reset */
662baec2c3SDavid Howells 	struct list_head	calls;		/* List of calls active in this namespace */
67ad25f5cbSDavid Howells 	spinlock_t		call_lock;	/* Lock for ->calls */
68d3be4d24SDavid Howells 	atomic_t		nr_calls;	/* Count of allocated calls */
692baec2c3SDavid Howells 
7031f5f9a1SDavid Howells 	atomic_t		nr_conns;
712baec2c3SDavid Howells 	struct list_head	conn_proc_list;	/* List of conns in this namespace for proc */
722baec2c3SDavid Howells 	struct list_head	service_conns;	/* Service conns in this namespace */
732baec2c3SDavid Howells 	rwlock_t		conn_lock;	/* Lock for ->conn_proc_list, ->service_conns */
743d18cbb7SDavid Howells 	struct work_struct	service_conn_reaper;
753d18cbb7SDavid Howells 	struct timer_list	service_conn_reap_timer;
762baec2c3SDavid Howells 
77f859ab61SDavid Howells 	bool			live;
78245500d8SDavid Howells 
79245500d8SDavid Howells 	atomic_t		nr_client_conns;
802baec2c3SDavid Howells 
8133912c26SDavid Howells 	struct hlist_head	local_endpoints;
822baec2c3SDavid Howells 	struct mutex		local_mutex;	/* Lock for ->local_endpoints */
832baec2c3SDavid Howells 
842baec2c3SDavid Howells 	DECLARE_HASHTABLE	(peer_hash, 10);
85ace45becSDavid Howells 	spinlock_t		peer_hash_lock;	/* Lock for ->peer_hash */
86ace45becSDavid Howells 
87ace45becSDavid Howells #define RXRPC_KEEPALIVE_TIME 20 /* NAT keepalive time in seconds */
88ace45becSDavid Howells 	u8			peer_keepalive_cursor;
89330bdcfaSDavid Howells 	time64_t		peer_keepalive_base;
90330bdcfaSDavid Howells 	struct list_head	peer_keepalive[32];
91330bdcfaSDavid Howells 	struct list_head	peer_keepalive_new;
92ace45becSDavid Howells 	struct timer_list	peer_keepalive_timer;
93ace45becSDavid Howells 	struct work_struct	peer_keepalive_work;
94b0154246SDavid Howells 
95b0154246SDavid Howells 	atomic_t		stat_tx_data;
96b0154246SDavid Howells 	atomic_t		stat_tx_data_retrans;
97b0154246SDavid Howells 	atomic_t		stat_tx_data_send;
98b0154246SDavid Howells 	atomic_t		stat_tx_data_send_frag;
9932cf8edbSDavid Howells 	atomic_t		stat_tx_data_send_fail;
10032cf8edbSDavid Howells 	atomic_t		stat_tx_data_underflow;
10132cf8edbSDavid Howells 	atomic_t		stat_tx_data_cwnd_reset;
102b0154246SDavid Howells 	atomic_t		stat_rx_data;
103b0154246SDavid Howells 	atomic_t		stat_rx_data_reqack;
104b0154246SDavid Howells 	atomic_t		stat_rx_data_jumbo;
105f2a676d1SDavid Howells 
106f2a676d1SDavid Howells 	atomic_t		stat_tx_ack_fill;
107f2a676d1SDavid Howells 	atomic_t		stat_tx_ack_send;
108f2a676d1SDavid Howells 	atomic_t		stat_tx_ack_skip;
109f2a676d1SDavid Howells 	atomic_t		stat_tx_acks[256];
110f2a676d1SDavid Howells 	atomic_t		stat_rx_acks[256];
111f7fa5242SDavid Howells 
112f7fa5242SDavid Howells 	atomic_t		stat_why_req_ack[8];
113a275da62SDavid Howells 
114a275da62SDavid Howells 	atomic_t		stat_io_loop;
1152baec2c3SDavid Howells };
1162baec2c3SDavid Howells 
1172baec2c3SDavid Howells /*
11800e90712SDavid Howells  * Service backlog preallocation.
11900e90712SDavid Howells  *
12000e90712SDavid Howells  * This contains circular buffers of preallocated peers, connections and calls
12100e90712SDavid Howells  * for incoming service calls and their head and tail pointers.  This allows
12200e90712SDavid Howells  * calls to be set up in the data_ready handler, thereby avoiding the need to
12300e90712SDavid Howells  * shuffle packets around so much.
12400e90712SDavid Howells  */
12500e90712SDavid Howells struct rxrpc_backlog {
12600e90712SDavid Howells 	unsigned short		peer_backlog_head;
12700e90712SDavid Howells 	unsigned short		peer_backlog_tail;
12800e90712SDavid Howells 	unsigned short		conn_backlog_head;
12900e90712SDavid Howells 	unsigned short		conn_backlog_tail;
13000e90712SDavid Howells 	unsigned short		call_backlog_head;
13100e90712SDavid Howells 	unsigned short		call_backlog_tail;
13200e90712SDavid Howells #define RXRPC_BACKLOG_MAX	32
13300e90712SDavid Howells 	struct rxrpc_peer	*peer_backlog[RXRPC_BACKLOG_MAX];
13400e90712SDavid Howells 	struct rxrpc_connection	*conn_backlog[RXRPC_BACKLOG_MAX];
13500e90712SDavid Howells 	struct rxrpc_call	*call_backlog[RXRPC_BACKLOG_MAX];
13600e90712SDavid Howells };
13700e90712SDavid Howells 
13800e90712SDavid Howells /*
13917926a79SDavid Howells  * RxRPC socket definition
14017926a79SDavid Howells  */
14117926a79SDavid Howells struct rxrpc_sock {
14217926a79SDavid Howells 	/* WARNING: sk has to be the first member */
14317926a79SDavid Howells 	struct sock		sk;
144d001648eSDavid Howells 	rxrpc_notify_new_call_t	notify_new_call; /* Func to notify of new call */
14500e90712SDavid Howells 	rxrpc_discard_new_call_t discard_new_call; /* Func to discard a new call */
14617926a79SDavid Howells 	struct rxrpc_local	*local;		/* local endpoint */
14700e90712SDavid Howells 	struct rxrpc_backlog	*backlog;	/* Preallocation for services */
148248f219cSDavid Howells 	spinlock_t		incoming_lock;	/* Incoming call vs service shutdown lock */
149248f219cSDavid Howells 	struct list_head	sock_calls;	/* List of calls owned by this socket */
150248f219cSDavid Howells 	struct list_head	to_be_accepted;	/* calls awaiting acceptance */
151248f219cSDavid Howells 	struct list_head	recvmsg_q;	/* Calls awaiting recvmsg's attention  */
152223f5901SDavid Howells 	spinlock_t		recvmsg_lock;	/* Lock for recvmsg_q */
15317926a79SDavid Howells 	struct key		*key;		/* security for this socket */
15417926a79SDavid Howells 	struct key		*securities;	/* list of server security descriptors */
15500e90712SDavid Howells 	struct rb_root		calls;		/* User ID -> call mapping */
15617926a79SDavid Howells 	unsigned long		flags;
1572341e077SDavid Howells #define RXRPC_SOCK_CONNECTED		0	/* connect_srx is set */
15817926a79SDavid Howells 	rwlock_t		call_lock;	/* lock for calls */
15917926a79SDavid Howells 	u32			min_sec_level;	/* minimum security level */
16017926a79SDavid Howells #define RXRPC_SECURITY_MAX	RXRPC_SECURITY_ENCRYPT
161cc8feb8eSDavid Howells 	bool			exclusive;	/* Exclusive connection for a client socket */
16228036f44SDavid Howells 	u16			second_service;	/* Additional service bound to the endpoint */
1634722974dSDavid Howells 	struct {
1644722974dSDavid Howells 		/* Service upgrade information */
1654722974dSDavid Howells 		u16		from;		/* Service ID to upgrade (if not 0) */
1664722974dSDavid Howells 		u16		to;		/* service ID to upgrade to */
1674722974dSDavid Howells 	} service_upgrade;
168cc8feb8eSDavid Howells 	sa_family_t		family;		/* Protocol family created with */
1694722974dSDavid Howells 	struct sockaddr_rxrpc	srx;		/* Primary Service/local addresses */
1702341e077SDavid Howells 	struct sockaddr_rxrpc	connect_srx;	/* Default client address from connect() */
17117926a79SDavid Howells };
17217926a79SDavid Howells 
17317926a79SDavid Howells #define rxrpc_sk(__sk) container_of((__sk), struct rxrpc_sock, sk)
17417926a79SDavid Howells 
17517926a79SDavid Howells /*
1760d12f8a4SDavid Howells  * CPU-byteorder normalised Rx packet header.
1770d12f8a4SDavid Howells  */
1780d12f8a4SDavid Howells struct rxrpc_host_header {
1790d12f8a4SDavid Howells 	u32		epoch;		/* client boot timestamp */
1800d12f8a4SDavid Howells 	u32		cid;		/* connection and channel ID */
1810d12f8a4SDavid Howells 	u32		callNumber;	/* call ID (0 for connection-level packets) */
1820d12f8a4SDavid Howells 	u32		seq;		/* sequence number of pkt in call stream */
1830d12f8a4SDavid Howells 	u32		serial;		/* serial number of pkt sent to network */
1840d12f8a4SDavid Howells 	u8		type;		/* packet type */
1850d12f8a4SDavid Howells 	u8		flags;		/* packet flags */
1860d12f8a4SDavid Howells 	u8		userStatus;	/* app-layer defined status */
1870d12f8a4SDavid Howells 	u8		securityIndex;	/* security protocol ID */
1880d12f8a4SDavid Howells 	union {
1890d12f8a4SDavid Howells 		u16	_rsvd;		/* reserved */
1900d12f8a4SDavid Howells 		u16	cksum;		/* kerberos security checksum */
1910d12f8a4SDavid Howells 	};
1920d12f8a4SDavid Howells 	u16		serviceId;	/* service ID */
1930d12f8a4SDavid Howells } __packed;
1940d12f8a4SDavid Howells 
1950d12f8a4SDavid Howells /*
19617926a79SDavid Howells  * RxRPC socket buffer private variables
19717926a79SDavid Howells  * - max 48 bytes (struct sk_buff::cb)
19817926a79SDavid Howells  */
19917926a79SDavid Howells struct rxrpc_skb_priv {
200f2cce89aSDavid Howells 	struct rxrpc_connection *conn;	/* Connection referred to (poke packet) */
201d4d02d8bSDavid Howells 	u16		offset;		/* Offset of data */
202d4d02d8bSDavid Howells 	u16		len;		/* Length of data */
203d4d02d8bSDavid Howells 	u8		flags;
204d4d02d8bSDavid Howells #define RXRPC_RX_VERIFIED	0x01
20517926a79SDavid Howells 
2060d12f8a4SDavid Howells 	struct rxrpc_host_header hdr;	/* RxRPC packet header from this packet */
20717926a79SDavid Howells };
20817926a79SDavid Howells 
20917926a79SDavid Howells #define rxrpc_skb(__skb) ((struct rxrpc_skb_priv *) &(__skb)->cb)
21017926a79SDavid Howells 
21117926a79SDavid Howells /*
21217926a79SDavid Howells  * RxRPC security module interface
21317926a79SDavid Howells  */
21417926a79SDavid Howells struct rxrpc_security {
21517926a79SDavid Howells 	const char		*name;		/* name of this service */
21617926a79SDavid Howells 	u8			security_index;	/* security type provided */
217063c60d3SDavid Howells 	u32			no_key_abort;	/* Abort code indicating no key */
21817926a79SDavid Howells 
219648af7fcSDavid Howells 	/* Initialise a security service */
220648af7fcSDavid Howells 	int (*init)(void);
221648af7fcSDavid Howells 
222648af7fcSDavid Howells 	/* Clean up a security service */
223648af7fcSDavid Howells 	void (*exit)(void);
224648af7fcSDavid Howells 
22512da59fcSDavid Howells 	/* Parse the information from a server key */
22612da59fcSDavid Howells 	int (*preparse_server_key)(struct key_preparsed_payload *);
22712da59fcSDavid Howells 
22812da59fcSDavid Howells 	/* Clean up the preparse buffer after parsing a server key */
22912da59fcSDavid Howells 	void (*free_preparse_server_key)(struct key_preparsed_payload *);
23012da59fcSDavid Howells 
23112da59fcSDavid Howells 	/* Destroy the payload of a server key */
23212da59fcSDavid Howells 	void (*destroy_server_key)(struct key *);
23312da59fcSDavid Howells 
234d5953f65SDavid Howells 	/* Describe a server key */
235d5953f65SDavid Howells 	void (*describe_server_key)(const struct key *, struct seq_file *);
236d5953f65SDavid Howells 
23717926a79SDavid Howells 	/* initialise a connection's security */
23841057ebdSDavid Howells 	int (*init_connection_security)(struct rxrpc_connection *,
23941057ebdSDavid Howells 					struct rxrpc_key_token *);
24017926a79SDavid Howells 
241d7d775b1SDavid Howells 	/* Work out how much data we can store in a packet, given an estimate
242d7d775b1SDavid Howells 	 * of the amount of data remaining.
243d7d775b1SDavid Howells 	 */
244d7d775b1SDavid Howells 	int (*how_much_data)(struct rxrpc_call *, size_t,
245d7d775b1SDavid Howells 			     size_t *, size_t *, size_t *);
24617926a79SDavid Howells 
24717926a79SDavid Howells 	/* impose security on a packet */
248a4ea4c47SDavid Howells 	int (*secure_packet)(struct rxrpc_call *, struct rxrpc_txbuf *);
24917926a79SDavid Howells 
25017926a79SDavid Howells 	/* verify the security on a received packet */
251d4d02d8bSDavid Howells 	int (*verify_packet)(struct rxrpc_call *, struct sk_buff *);
252248f219cSDavid Howells 
2531db88c53SDavid Howells 	/* Free crypto request on a call */
2541db88c53SDavid Howells 	void (*free_call_crypto)(struct rxrpc_call *);
2551db88c53SDavid Howells 
25617926a79SDavid Howells 	/* issue a challenge */
25717926a79SDavid Howells 	int (*issue_challenge)(struct rxrpc_connection *);
25817926a79SDavid Howells 
25917926a79SDavid Howells 	/* respond to a challenge */
26017926a79SDavid Howells 	int (*respond_to_challenge)(struct rxrpc_connection *,
261a00ce28bSDavid Howells 				    struct sk_buff *);
26217926a79SDavid Howells 
26317926a79SDavid Howells 	/* verify a response */
26417926a79SDavid Howells 	int (*verify_response)(struct rxrpc_connection *,
265a00ce28bSDavid Howells 			       struct sk_buff *);
26617926a79SDavid Howells 
26717926a79SDavid Howells 	/* clear connection security */
26817926a79SDavid Howells 	void (*clear)(struct rxrpc_connection *);
26917926a79SDavid Howells };
27017926a79SDavid Howells 
27117926a79SDavid Howells /*
2724f95dd78SDavid Howells  * RxRPC local transport endpoint description
2734f95dd78SDavid Howells  * - owned by a single AF_RXRPC socket
2744f95dd78SDavid Howells  * - pointed to by transport socket struct sk_user_data
27517926a79SDavid Howells  */
27617926a79SDavid Howells struct rxrpc_local {
2774f95dd78SDavid Howells 	struct rcu_head		rcu;
278730c5fd4SDavid Howells 	atomic_t		active_users;	/* Number of users of the local endpoint */
279a0575429SDavid Howells 	refcount_t		ref;		/* Number of references to the structure */
2808a758d98SDavid Howells 	struct net		*net;		/* The network namespace */
2818a758d98SDavid Howells 	struct rxrpc_net	*rxnet;		/* Our bits in the network namespace */
28233912c26SDavid Howells 	struct hlist_node	link;
28317926a79SDavid Howells 	struct socket		*socket;	/* my UDP socket */
284a275da62SDavid Howells 	struct task_struct	*io_thread;
2858fbcc833SDavid Howells 	struct completion	io_thread_ready; /* Indication that the I/O thread started */
28642f229c3SDavid Howells 	struct rxrpc_sock	*service;	/* Service(s) listening on this endpoint */
287af094824SDavid Howells #ifdef CONFIG_AF_RXRPC_INJECT_RX_DELAY
288af094824SDavid Howells 	struct sk_buff_head	rx_delay_queue;	/* Delay injection queue */
289af094824SDavid Howells #endif
290a275da62SDavid Howells 	struct sk_buff_head	rx_queue;	/* Received packets */
291f2cce89aSDavid Howells 	struct list_head	conn_attend_q;	/* Conns requiring immediate attention */
29215f661dcSDavid Howells 	struct list_head	call_attend_q;	/* Calls requiring immediate attention */
2930d6bf319SDavid Howells 
294245500d8SDavid Howells 	struct rb_root		client_bundles;	/* Client connection bundles by socket params */
295245500d8SDavid Howells 	spinlock_t		client_bundles_lock; /* Lock for client_bundles */
2960d6bf319SDavid Howells 	bool			kill_all_client_conns;
2970d6bf319SDavid Howells 	struct list_head	idle_client_conns;
2980d6bf319SDavid Howells 	struct timer_list	client_conn_reap_timer;
2990d6bf319SDavid Howells 	unsigned long		client_conn_flags;
3000d6bf319SDavid Howells #define RXRPC_CLIENT_CONN_REAP_TIMER	0	/* The client conn reap timer expired */
3010d6bf319SDavid Howells 
30217926a79SDavid Howells 	spinlock_t		lock;		/* access lock */
30317926a79SDavid Howells 	rwlock_t		services_lock;	/* lock for services list */
30417926a79SDavid Howells 	int			debug_id;	/* debug ID for printks */
3054f95dd78SDavid Howells 	bool			dead;
306f859ab61SDavid Howells 	bool			service_closed;	/* Service socket closed */
307f06cb291SDavid Howells 	struct idr		conn_ids;	/* List of connection IDs */
3089d35d880SDavid Howells 	struct list_head	new_client_calls; /* Newly created client calls need connection */
3099d35d880SDavid Howells 	spinlock_t		client_call_lock; /* Lock for ->new_client_calls */
31017926a79SDavid Howells 	struct sockaddr_rxrpc	srx;		/* local address */
31117926a79SDavid Howells };
31217926a79SDavid Howells 
31317926a79SDavid Howells /*
31417926a79SDavid Howells  * RxRPC remote transport endpoint definition
315be6e6707SDavid Howells  * - matched by local endpoint, remote port, address and protocol type
31617926a79SDavid Howells  */
31717926a79SDavid Howells struct rxrpc_peer {
318be6e6707SDavid Howells 	struct rcu_head		rcu;		/* This must be first */
319a0575429SDavid Howells 	refcount_t		ref;
320be6e6707SDavid Howells 	unsigned long		hash_key;
321be6e6707SDavid Howells 	struct hlist_node	hash_link;
322be6e6707SDavid Howells 	struct rxrpc_local	*local;
323f66d7490SDavid Howells 	struct hlist_head	error_targets;	/* targets for net error distribution */
324aa390bbeSDavid Howells 	struct rb_root		service_conns;	/* Service connections */
325330bdcfaSDavid Howells 	struct list_head	keepalive_link;	/* Link in net->peer_keepalive[] */
326ace45becSDavid Howells 	time64_t		last_tx_at;	/* Last time packet sent here */
3278496af50SDavid Howells 	seqlock_t		service_conn_lock;
32817926a79SDavid Howells 	spinlock_t		lock;		/* access lock */
32995c96174SEric Dumazet 	unsigned int		if_mtu;		/* interface MTU for this peer */
33095c96174SEric Dumazet 	unsigned int		mtu;		/* network MTU for this peer */
33195c96174SEric Dumazet 	unsigned int		maxdata;	/* data size (MTU - hdrsize) */
33217926a79SDavid Howells 	unsigned short		hdrsize;	/* header size (IP + UDP + RxRPC) */
33317926a79SDavid Howells 	int			debug_id;	/* debug ID for printks */
33417926a79SDavid Howells 	struct sockaddr_rxrpc	srx;		/* remote address */
33517926a79SDavid Howells 
33617926a79SDavid Howells 	/* calculated RTT cache */
33717926a79SDavid Howells #define RXRPC_RTT_CACHE_SIZE 32
338c1e15b49SDavid Howells 	spinlock_t		rtt_input_lock;	/* RTT lock for input routine */
3390d4b103cSDavid Howells 	ktime_t			rtt_last_req;	/* Time of last RTT request */
340c410bf01SDavid Howells 	unsigned int		rtt_count;	/* Number of samples we've got */
341c410bf01SDavid Howells 
342c410bf01SDavid Howells 	u32			srtt_us;	/* smoothed round trip time << 3 in usecs */
343c410bf01SDavid Howells 	u32			mdev_us;	/* medium deviation			*/
344c410bf01SDavid Howells 	u32			mdev_max_us;	/* maximal mdev for the last rtt period	*/
345c410bf01SDavid Howells 	u32			rttvar_us;	/* smoothed mdev_max			*/
346c410bf01SDavid Howells 	u32			rto_j;		/* Retransmission timeout in jiffies */
347c410bf01SDavid Howells 	u8			backoff;	/* Backoff timeout */
348f7aec129SDavid Howells 
3491fc4fa2aSDavid Howells 	u8			cong_ssthresh;	/* Congestion slow-start threshold */
35017926a79SDavid Howells };
35117926a79SDavid Howells 
35217926a79SDavid Howells /*
35319ffa01cSDavid Howells  * Keys for matching a connection.
35419ffa01cSDavid Howells  */
35519ffa01cSDavid Howells struct rxrpc_conn_proto {
356e8d70ce1SDavid Howells 	union {
357e8d70ce1SDavid Howells 		struct {
35819ffa01cSDavid Howells 			u32	epoch;		/* epoch of this connection */
35919ffa01cSDavid Howells 			u32	cid;		/* connection ID */
360e8d70ce1SDavid Howells 		};
361e8d70ce1SDavid Howells 		u64		index_key;
36219ffa01cSDavid Howells 	};
36319ffa01cSDavid Howells };
36419ffa01cSDavid Howells 
36519ffa01cSDavid Howells struct rxrpc_conn_parameters {
36619ffa01cSDavid Howells 	struct rxrpc_local	*local;		/* Representation of local endpoint */
36719ffa01cSDavid Howells 	struct key		*key;		/* Security details */
36819ffa01cSDavid Howells 	bool			exclusive;	/* T if conn is exclusive */
3694e255721SDavid Howells 	bool			upgrade;	/* T if service ID can be upgraded */
37019ffa01cSDavid Howells 	u16			service_id;	/* Service ID for this connection */
37119ffa01cSDavid Howells 	u32			security_level;	/* Security level selected */
37219ffa01cSDavid Howells };
37319ffa01cSDavid Howells 
37419ffa01cSDavid Howells /*
375a00ce28bSDavid Howells  * Call completion condition (state == RXRPC_CALL_COMPLETE).
376a00ce28bSDavid Howells  */
377a00ce28bSDavid Howells enum rxrpc_call_completion {
378a00ce28bSDavid Howells 	RXRPC_CALL_SUCCEEDED,		/* - Normal termination */
379a00ce28bSDavid Howells 	RXRPC_CALL_REMOTELY_ABORTED,	/* - call aborted by peer */
380a00ce28bSDavid Howells 	RXRPC_CALL_LOCALLY_ABORTED,	/* - call aborted locally on error or close */
381a00ce28bSDavid Howells 	RXRPC_CALL_LOCAL_ERROR,		/* - call failed due to local error */
382a00ce28bSDavid Howells 	RXRPC_CALL_NETWORK_ERROR,	/* - call terminated by network error */
383a00ce28bSDavid Howells 	NR__RXRPC_CALL_COMPLETIONS
384a00ce28bSDavid Howells };
385a00ce28bSDavid Howells 
386a00ce28bSDavid Howells /*
387bba304dbSDavid Howells  * Bits in the connection flags.
388bba304dbSDavid Howells  */
389bba304dbSDavid Howells enum rxrpc_conn_flag {
390001c1122SDavid Howells 	RXRPC_CONN_IN_SERVICE_CONNS,	/* Conn is in peer->service_conns */
39145025bceSDavid Howells 	RXRPC_CONN_DONT_REUSE,		/* Don't reuse this connection */
3924e255721SDavid Howells 	RXRPC_CONN_PROBING_FOR_UPGRADE,	/* Probing for service upgrade */
3933136ef49SDavid Howells 	RXRPC_CONN_FINAL_ACK_0,		/* Need final ACK for channel 0 */
3943136ef49SDavid Howells 	RXRPC_CONN_FINAL_ACK_1,		/* Need final ACK for channel 1 */
3953136ef49SDavid Howells 	RXRPC_CONN_FINAL_ACK_2,		/* Need final ACK for channel 2 */
3963136ef49SDavid Howells 	RXRPC_CONN_FINAL_ACK_3,		/* Need final ACK for channel 3 */
397bba304dbSDavid Howells };
398bba304dbSDavid Howells 
3993136ef49SDavid Howells #define RXRPC_CONN_FINAL_ACK_MASK ((1UL << RXRPC_CONN_FINAL_ACK_0) |	\
4003136ef49SDavid Howells 				   (1UL << RXRPC_CONN_FINAL_ACK_1) |	\
4013136ef49SDavid Howells 				   (1UL << RXRPC_CONN_FINAL_ACK_2) |	\
4023136ef49SDavid Howells 				   (1UL << RXRPC_CONN_FINAL_ACK_3))
4033136ef49SDavid Howells 
404bba304dbSDavid Howells /*
405bba304dbSDavid Howells  * Events that can be raised upon a connection.
406bba304dbSDavid Howells  */
407bba304dbSDavid Howells enum rxrpc_conn_event {
408bba304dbSDavid Howells 	RXRPC_CONN_EV_CHALLENGE,	/* Send challenge packet */
409a00ce28bSDavid Howells 	RXRPC_CONN_EV_ABORT_CALLS,	/* Abort attached calls */
410bba304dbSDavid Howells };
411bba304dbSDavid Howells 
412bba304dbSDavid Howells /*
413bba304dbSDavid Howells  * The connection protocol state.
414bba304dbSDavid Howells  */
415bba304dbSDavid Howells enum rxrpc_conn_proto_state {
416bba304dbSDavid Howells 	RXRPC_CONN_UNUSED,		/* Connection not yet attempted */
4179d35d880SDavid Howells 	RXRPC_CONN_CLIENT_UNSECURED,	/* Client connection needs security init */
418bba304dbSDavid Howells 	RXRPC_CONN_CLIENT,		/* Client connection */
41900e90712SDavid Howells 	RXRPC_CONN_SERVICE_PREALLOC,	/* Service connection preallocation */
420bba304dbSDavid Howells 	RXRPC_CONN_SERVICE_UNSECURED,	/* Service unsecured connection */
421bba304dbSDavid Howells 	RXRPC_CONN_SERVICE_CHALLENGING,	/* Service challenging for security */
422bba304dbSDavid Howells 	RXRPC_CONN_SERVICE,		/* Service secured connection */
423a00ce28bSDavid Howells 	RXRPC_CONN_ABORTED,		/* Conn aborted */
424bba304dbSDavid Howells 	RXRPC_CONN__NR_STATES
425bba304dbSDavid Howells };
426bba304dbSDavid Howells 
427bba304dbSDavid Howells /*
428245500d8SDavid Howells  * RxRPC client connection bundle.
429245500d8SDavid Howells  */
430245500d8SDavid Howells struct rxrpc_bundle {
4312cc80086SDavid Howells 	struct rxrpc_local	*local;		/* Representation of local endpoint */
4322cc80086SDavid Howells 	struct rxrpc_peer	*peer;		/* Remote endpoint */
4332cc80086SDavid Howells 	struct key		*key;		/* Security details */
4341bab27afSDavid Howells 	const struct rxrpc_security *security;	/* applied security module */
435a0575429SDavid Howells 	refcount_t		ref;
4363bcd6c7eSDavid Howells 	atomic_t		active;		/* Number of active users */
437245500d8SDavid Howells 	unsigned int		debug_id;
4382cc80086SDavid Howells 	u32			security_level;	/* Security level selected */
4392cc80086SDavid Howells 	u16			service_id;	/* Service ID for this connection */
440245500d8SDavid Howells 	bool			try_upgrade;	/* True if the bundle is attempting upgrade */
4412cc80086SDavid Howells 	bool			exclusive;	/* T if conn is exclusive */
4422cc80086SDavid Howells 	bool			upgrade;	/* T if service ID can be upgraded */
4439d35d880SDavid Howells 	unsigned short		alloc_error;	/* Error from last conn allocation */
444245500d8SDavid Howells 	struct rb_node		local_node;	/* Node in local->client_conns */
445245500d8SDavid Howells 	struct list_head	waiting_calls;	/* Calls waiting for channels */
446245500d8SDavid Howells 	unsigned long		avail_chans;	/* Mask of available channels */
447245500d8SDavid Howells 	struct rxrpc_connection	*conns[4];	/* The connections in the bundle (max 4) */
448245500d8SDavid Howells };
449245500d8SDavid Howells 
450245500d8SDavid Howells /*
45117926a79SDavid Howells  * RxRPC connection definition
452aa390bbeSDavid Howells  * - matched by { local, peer, epoch, conn_id, direction }
45317926a79SDavid Howells  * - each connection can only handle four simultaneous calls
45417926a79SDavid Howells  */
45517926a79SDavid Howells struct rxrpc_connection {
45619ffa01cSDavid Howells 	struct rxrpc_conn_proto	proto;
4572cc80086SDavid Howells 	struct rxrpc_local	*local;		/* Representation of local endpoint */
4582cc80086SDavid Howells 	struct rxrpc_peer	*peer;		/* Remote endpoint */
4593cec055cSDavid Howells 	struct rxrpc_net	*rxnet;		/* Network namespace to which call belongs */
4602cc80086SDavid Howells 	struct key		*key;		/* Security details */
461f2cce89aSDavid Howells 	struct list_head	attend_link;	/* Link in local->conn_attend_q */
46219ffa01cSDavid Howells 
463a0575429SDavid Howells 	refcount_t		ref;
4643cec055cSDavid Howells 	atomic_t		active;		/* Active count for service conns */
46545025bceSDavid Howells 	struct rcu_head		rcu;
46645025bceSDavid Howells 	struct list_head	cache_link;
467a1399f8bSDavid Howells 
468245500d8SDavid Howells 	unsigned char		act_chans;	/* Mask of active channels */
469a1399f8bSDavid Howells 	struct rxrpc_channel {
4703136ef49SDavid Howells 		unsigned long		final_ack_at;	/* Time at which to issue final ACK */
4719d35d880SDavid Howells 		struct rxrpc_call	*call;		/* Active call */
4724764c0daSDavid Howells 		unsigned int		call_debug_id;	/* call->debug_id */
473a1399f8bSDavid Howells 		u32			call_id;	/* ID of current call */
474a1399f8bSDavid Howells 		u32			call_counter;	/* Call ID counter */
475a1399f8bSDavid Howells 		u32			last_call;	/* ID of last call */
47618bfeba5SDavid Howells 		u8			last_type;	/* Type of last packet */
47718bfeba5SDavid Howells 		union {
47818bfeba5SDavid Howells 			u32		last_seq;
47918bfeba5SDavid Howells 			u32		last_abort;
48018bfeba5SDavid Howells 		};
481a1399f8bSDavid Howells 	} channels[RXRPC_MAXCALLS];
482999b69f8SDavid Howells 
4833136ef49SDavid Howells 	struct timer_list	timer;		/* Conn event timer */
48417926a79SDavid Howells 	struct work_struct	processor;	/* connection event processor */
4853cec055cSDavid Howells 	struct work_struct	destructor;	/* In-process-context destroyer */
486245500d8SDavid Howells 	struct rxrpc_bundle	*bundle;	/* Client connection bundle */
487aa390bbeSDavid Howells 	struct rb_node		service_node;	/* Node in peer->service_conns */
4884d028b2cSDavid Howells 	struct list_head	proc_link;	/* link in procfs list */
48917926a79SDavid Howells 	struct list_head	link;		/* link in master connection list */
49017926a79SDavid Howells 	struct sk_buff_head	rx_queue;	/* received conn-level packets */
491521bb304SDavid Howells 
4929d35d880SDavid Howells 	struct mutex		security_lock;	/* Lock for security management */
493648af7fcSDavid Howells 	const struct rxrpc_security *security;	/* applied security module */
494521bb304SDavid Howells 	union {
495521bb304SDavid Howells 		struct {
49669d826faSKees Cook 			struct crypto_sync_skcipher *cipher;	/* encryption handle */
49717926a79SDavid Howells 			struct rxrpc_crypt csum_iv;	/* packet checksum base */
498521bb304SDavid Howells 			u32	nonce;		/* response re-use preventer */
499521bb304SDavid Howells 		} rxkad;
500521bb304SDavid Howells 	};
5014a3388c8SDavid Howells 	unsigned long		flags;
50217926a79SDavid Howells 	unsigned long		events;
503f51b4480SDavid Howells 	unsigned long		idle_timestamp;	/* Time at which last became idle */
50417926a79SDavid Howells 	spinlock_t		state_lock;	/* state-change lock */
505cf13258fSDavid Howells 	enum rxrpc_conn_proto_state state;	/* current state of connection */
506a00ce28bSDavid Howells 	enum rxrpc_call_completion completion;	/* Completion condition */
507a00ce28bSDavid Howells 	s32			abort_code;	/* Abort code of connection abort */
50817926a79SDavid Howells 	int			debug_id;	/* debug ID for printks */
509*2c9dc472SDavid Howells 	rxrpc_serial_t		tx_serial;	/* Outgoing packet serial number counter */
510563ea7d5SDavid Howells 	unsigned int		hi_serial;	/* highest serial number received */
511c1e15b49SDavid Howells 	u32			service_id;	/* Service ID, possibly upgraded */
5122cc80086SDavid Howells 	u32			security_level;	/* Security level selected */
51317926a79SDavid Howells 	u8			security_ix;	/* security type */
51417926a79SDavid Howells 	u8			out_clientflag;	/* RXRPC_CLIENT_INITIATED if we are client */
515245500d8SDavid Howells 	u8			bundle_shift;	/* Index into bundle->avail_chans */
5162cc80086SDavid Howells 	bool			exclusive;	/* T if conn is exclusive */
5172cc80086SDavid Howells 	bool			upgrade;	/* T if service ID can be upgraded */
5182cc80086SDavid Howells 	u16			orig_service_id; /* Originally requested service ID */
51964753092SDavid Howells 	short			error;		/* Local error code */
52017926a79SDavid Howells };
52117926a79SDavid Howells 
522dc71db34SDavid Howells static inline bool rxrpc_to_server(const struct rxrpc_skb_priv *sp)
523dc71db34SDavid Howells {
524dc71db34SDavid Howells 	return sp->hdr.flags & RXRPC_CLIENT_INITIATED;
525dc71db34SDavid Howells }
526dc71db34SDavid Howells 
527dc71db34SDavid Howells static inline bool rxrpc_to_client(const struct rxrpc_skb_priv *sp)
528dc71db34SDavid Howells {
529dc71db34SDavid Howells 	return !rxrpc_to_server(sp);
530dc71db34SDavid Howells }
531dc71db34SDavid Howells 
53217926a79SDavid Howells /*
5335b8848d1SDavid Howells  * Flags in call->flags.
5345b8848d1SDavid Howells  */
5355b8848d1SDavid Howells enum rxrpc_call_flag {
5365b8848d1SDavid Howells 	RXRPC_CALL_RELEASED,		/* call has been released - no more message to userspace */
5375b8848d1SDavid Howells 	RXRPC_CALL_HAS_USERID,		/* has a user ID attached */
538dabe5a79SDavid Howells 	RXRPC_CALL_IS_SERVICE,		/* Call is service call */
53945025bceSDavid Howells 	RXRPC_CALL_EXPOSED,		/* The call was exposed to the world */
540248f219cSDavid Howells 	RXRPC_CALL_RX_LAST,		/* Received the last packet (at rxtx_top) */
541248f219cSDavid Howells 	RXRPC_CALL_TX_LAST,		/* Last packet in Tx buffer (at rxtx_top) */
542a4ea4c47SDavid Howells 	RXRPC_CALL_TX_ALL_ACKED,	/* Last packet has been hard-acked */
543a5af7e1fSDavid Howells 	RXRPC_CALL_SEND_PING,		/* A ping will need to be sent */
54457494343SDavid Howells 	RXRPC_CALL_RETRANS_TIMEOUT,	/* Retransmission due to timeout occurred */
545c54e43d7SDavid Howells 	RXRPC_CALL_BEGAN_RX_TIMER,	/* We began the expect_rx_by timer */
5461a025028SDavid Howells 	RXRPC_CALL_RX_HEARD,		/* The peer responded at least once to this call */
5475273a191SDavid Howells 	RXRPC_CALL_DISCONNECTED,	/* The call has been disconnected */
548b7a7d674SDavid Howells 	RXRPC_CALL_KERNEL,		/* The call was made by the kernel */
549245500d8SDavid Howells 	RXRPC_CALL_UPGRADE,		/* Service upgrade was requested for the call */
550f3441d41SDavid Howells 	RXRPC_CALL_EXCLUSIVE,		/* The call uses a once-only connection */
55193368b6bSDavid Howells 	RXRPC_CALL_RX_IS_IDLE,		/* recvmsg() is idle - send an ACK */
55293368b6bSDavid Howells 	RXRPC_CALL_RECVMSG_READ_ALL,	/* recvmsg() read all of the received data */
5535b8848d1SDavid Howells };
5545b8848d1SDavid Howells 
5555b8848d1SDavid Howells /*
5565b8848d1SDavid Howells  * Events that can be raised on a call.
5575b8848d1SDavid Howells  */
5585b8848d1SDavid Howells enum rxrpc_call_event {
559bd1fdf8cSDavid Howells 	RXRPC_CALL_EV_ACK_LOST,		/* ACK may be lost, send ping */
5605e6ef4f1SDavid Howells 	RXRPC_CALL_EV_INITIAL_PING,	/* Send initial ping for a new service call */
5615b8848d1SDavid Howells };
5625b8848d1SDavid Howells 
5635b8848d1SDavid Howells /*
5645b8848d1SDavid Howells  * The states that a call can be in.
5655b8848d1SDavid Howells  */
5665b8848d1SDavid Howells enum rxrpc_call_state {
567999b69f8SDavid Howells 	RXRPC_CALL_UNINITIALISED,
568999b69f8SDavid Howells 	RXRPC_CALL_CLIENT_AWAIT_CONN,	/* - client waiting for connection to become available */
5695b8848d1SDavid Howells 	RXRPC_CALL_CLIENT_SEND_REQUEST,	/* - client sending request phase */
5705b8848d1SDavid Howells 	RXRPC_CALL_CLIENT_AWAIT_REPLY,	/* - client awaiting reply */
5715b8848d1SDavid Howells 	RXRPC_CALL_CLIENT_RECV_REPLY,	/* - client receiving reply phase */
57200e90712SDavid Howells 	RXRPC_CALL_SERVER_PREALLOC,	/* - service preallocation */
5735b8848d1SDavid Howells 	RXRPC_CALL_SERVER_SECURING,	/* - server securing request connection */
5745b8848d1SDavid Howells 	RXRPC_CALL_SERVER_RECV_REQUEST,	/* - server receiving request */
5755b8848d1SDavid Howells 	RXRPC_CALL_SERVER_ACK_REQUEST,	/* - server pending ACK of request */
5765b8848d1SDavid Howells 	RXRPC_CALL_SERVER_SEND_REPLY,	/* - server sending reply */
5775b8848d1SDavid Howells 	RXRPC_CALL_SERVER_AWAIT_ACK,	/* - server awaiting final ACK */
578f5c17aaeSDavid Howells 	RXRPC_CALL_COMPLETE,		/* - call complete */
579f5c17aaeSDavid Howells 	NR__RXRPC_CALL_STATES
580f5c17aaeSDavid Howells };
581f5c17aaeSDavid Howells 
582f5c17aaeSDavid Howells /*
58357494343SDavid Howells  * Call Tx congestion management modes.
58457494343SDavid Howells  */
58557494343SDavid Howells enum rxrpc_congest_mode {
58657494343SDavid Howells 	RXRPC_CALL_SLOW_START,
58757494343SDavid Howells 	RXRPC_CALL_CONGEST_AVOIDANCE,
58857494343SDavid Howells 	RXRPC_CALL_PACKET_LOSS,
58957494343SDavid Howells 	RXRPC_CALL_FAST_RETRANSMIT,
59057494343SDavid Howells 	NR__RXRPC_CONGEST_MODES
59157494343SDavid Howells };
59257494343SDavid Howells 
59357494343SDavid Howells /*
59417926a79SDavid Howells  * RxRPC call definition
59517926a79SDavid Howells  * - matched by { connection, call_id }
59617926a79SDavid Howells  */
59717926a79SDavid Howells struct rxrpc_call {
598dee46364SDavid Howells 	struct rcu_head		rcu;
59917926a79SDavid Howells 	struct rxrpc_connection	*conn;		/* connection carrying call */
6001bab27afSDavid Howells 	struct rxrpc_bundle	*bundle;	/* Connection bundle to use */
601df5d8bf7SDavid Howells 	struct rxrpc_peer	*peer;		/* Peer record for remote address */
602f3441d41SDavid Howells 	struct rxrpc_local	*local;		/* Representation of local endpoint */
6038d94aa38SDavid Howells 	struct rxrpc_sock __rcu	*socket;	/* socket responsible */
604d3be4d24SDavid Howells 	struct rxrpc_net	*rxnet;		/* Network namespace to which call belongs */
605f3441d41SDavid Howells 	struct key		*key;		/* Security details */
60691fcfbe8SDavid Howells 	const struct rxrpc_security *security;	/* applied security module */
607540b1c48SDavid Howells 	struct mutex		user_mutex;	/* User access mutex */
608f3441d41SDavid Howells 	struct sockaddr_rxrpc	dest_srx;	/* Destination address */
609530403d9SDavid Howells 	unsigned long		delay_ack_at;	/* When DELAY ACK needs to happen */
610bd1fdf8cSDavid Howells 	unsigned long		ack_lost_at;	/* When ACK is figured as lost */
611a158bdd3SDavid Howells 	unsigned long		resend_at;	/* When next resend needs to happen */
612a158bdd3SDavid Howells 	unsigned long		ping_at;	/* When next to send a ping */
613415f44e4SDavid Howells 	unsigned long		keepalive_at;	/* When next to send a keepalive ping */
614a158bdd3SDavid Howells 	unsigned long		expect_rx_by;	/* When we expect to get a packet by */
615a158bdd3SDavid Howells 	unsigned long		expect_req_by;	/* When we expect to get a request DATA packet by */
616a158bdd3SDavid Howells 	unsigned long		expect_term_by;	/* When we expect call termination by */
617a158bdd3SDavid Howells 	u32			next_rx_timo;	/* Timeout for next Rx packet (jif) */
618a158bdd3SDavid Howells 	u32			next_req_timo;	/* Timeout for next Rx request packet (jif) */
619db099c62SDavid Howells 	u32			hard_timo;	/* Maximum lifetime or 0 (jif) */
620248f219cSDavid Howells 	struct timer_list	timer;		/* Combined event timer */
6213feda9d6SDavid Howells 	struct work_struct	destroyer;	/* In-process-context destroyer */
622d001648eSDavid Howells 	rxrpc_notify_rx_t	notify_rx;	/* kernel service Rx notification function */
62317926a79SDavid Howells 	struct list_head	link;		/* link in master call list */
6249d35d880SDavid Howells 	struct list_head	wait_link;	/* Link in local->new_client_calls */
625f66d7490SDavid Howells 	struct hlist_node	error_link;	/* link in error distribution list */
626248f219cSDavid Howells 	struct list_head	accept_link;	/* Link in rx->acceptq */
627248f219cSDavid Howells 	struct list_head	recvmsg_link;	/* Link in rx->recvmsg_q */
628248f219cSDavid Howells 	struct list_head	sock_link;	/* Link in rx->sock_calls */
629248f219cSDavid Howells 	struct rb_node		sock_node;	/* Node in rx->calls */
63015f661dcSDavid Howells 	struct list_head	attend_link;	/* Link in local->call_attend_q */
631a4ea4c47SDavid Howells 	struct rxrpc_txbuf	*tx_pending;	/* Tx buffer being filled */
63245025bceSDavid Howells 	wait_queue_head_t	waitq;		/* Wait queue for channel or Tx */
633e754eba6SDavid Howells 	s64			tx_total_len;	/* Total length left to be transmitted (or -1) */
63417926a79SDavid Howells 	unsigned long		user_call_ID;	/* user-defined call ID */
63517926a79SDavid Howells 	unsigned long		flags;
63617926a79SDavid Howells 	unsigned long		events;
63720acbd9aSDavid Howells 	spinlock_t		notify_lock;	/* Kernel notification lock */
63857af281eSDavid Howells 	unsigned int		send_abort_why; /* Why the abort [enum rxrpc_abort_reason] */
639a343b174SDavid Howells 	s32			send_abort;	/* Abort code to be sent */
640a343b174SDavid Howells 	short			send_abort_err;	/* Error to be associated with the abort */
64157af281eSDavid Howells 	rxrpc_seq_t		send_abort_seq;	/* DATA packet that incurred the abort (or 0) */
642a343b174SDavid Howells 	s32			abort_code;	/* Local/remote abort code */
643f5c17aaeSDavid Howells 	int			error;		/* Local error incurred */
64496b4059fSDavid Howells 	enum rxrpc_call_state	_state;		/* Current state of call (needs barrier) */
645cf13258fSDavid Howells 	enum rxrpc_call_completion completion;	/* Call completion condition */
646a0575429SDavid Howells 	refcount_t		ref;
647278ac0cdSDavid Howells 	u8			security_ix;	/* Security type */
648e138aa7dSDavid Howells 	enum rxrpc_interruptibility interruptibility; /* At what point call may be interrupted */
649dabe5a79SDavid Howells 	u32			call_id;	/* call ID on connection  */
650dabe5a79SDavid Howells 	u32			cid;		/* connection ID plus channel index */
651f3441d41SDavid Howells 	u32			security_level;	/* Security level selected */
652dabe5a79SDavid Howells 	int			debug_id;	/* debug ID for printks */
6538e83134dSDavid Howells 	unsigned short		rx_pkt_offset;	/* Current recvmsg packet offset */
6548e83134dSDavid Howells 	unsigned short		rx_pkt_len;	/* Current recvmsg packet len */
65517926a79SDavid Howells 
6565d7edbc9SDavid Howells 	/* Transmitted data tracking. */
657a4ea4c47SDavid Howells 	spinlock_t		tx_lock;	/* Transmit queue lock */
658cf37b598SDavid Howells 	struct list_head	tx_sendmsg;	/* Sendmsg prepared packets */
659a4ea4c47SDavid Howells 	struct list_head	tx_buffer;	/* Buffer of transmissible packets */
660a4ea4c47SDavid Howells 	rxrpc_seq_t		tx_bottom;	/* First packet in buffer */
661a4ea4c47SDavid Howells 	rxrpc_seq_t		tx_transmitted;	/* Highest packet transmitted */
662cf37b598SDavid Howells 	rxrpc_seq_t		tx_prepared;	/* Highest Tx slot prepared. */
663248f219cSDavid Howells 	rxrpc_seq_t		tx_top;		/* Highest Tx slot allocated. */
664c7e86acfSDavid Howells 	u16			tx_backoff;	/* Delay to insert due to Tx failure */
6655d7edbc9SDavid Howells 	u8			tx_winsize;	/* Maximum size of Tx window */
666a4ea4c47SDavid Howells #define RXRPC_TX_MAX_WINDOW	128
6671fc4fa2aSDavid Howells 	ktime_t			tx_last_sent;	/* Last time a transmission occurred */
6685d7edbc9SDavid Howells 
6695d7edbc9SDavid Howells 	/* Received data tracking */
6705d7edbc9SDavid Howells 	struct sk_buff_head	recvmsg_queue;	/* Queue of packets ready for recvmsg() */
6715d7edbc9SDavid Howells 	struct sk_buff_head	rx_oos_queue;	/* Queue of out of sequence packets */
6725d7edbc9SDavid Howells 
6735d7edbc9SDavid Howells 	rxrpc_seq_t		rx_highest_seq;	/* Higest sequence number received */
6745d7edbc9SDavid Howells 	rxrpc_seq_t		rx_consumed;	/* Highest packet consumed */
6755d7edbc9SDavid Howells 	rxrpc_serial_t		rx_serial;	/* Highest serial received for this call */
6765d7edbc9SDavid Howells 	u8			rx_winsize;	/* Size of Rx window */
67757494343SDavid Howells 
67857494343SDavid Howells 	/* TCP-style slow-start congestion control [RFC5681].  Since the SMSS
67957494343SDavid Howells 	 * is fixed, we keep these numbers in terms of segments (ie. DATA
68057494343SDavid Howells 	 * packets) rather than bytes.
68157494343SDavid Howells 	 */
68257494343SDavid Howells #define RXRPC_TX_SMSS		RXRPC_JUMBO_DATALEN
6835086d9a9SDavid Howells #define RXRPC_MIN_CWND		(RXRPC_TX_SMSS > 2190 ? 2 : RXRPC_TX_SMSS > 1095 ? 3 : 4)
68457494343SDavid Howells 	u8			cong_cwnd;	/* Congestion window size */
68557494343SDavid Howells 	u8			cong_extra;	/* Extra to send for congestion management */
68657494343SDavid Howells 	u8			cong_ssthresh;	/* Slow-start threshold */
68757494343SDavid Howells 	enum rxrpc_congest_mode	cong_mode:8;	/* Congestion management mode */
68857494343SDavid Howells 	u8			cong_dup_acks;	/* Count of ACKs showing missing packets */
68957494343SDavid Howells 	u8			cong_cumul_acks; /* Cumulative ACK count */
69057494343SDavid Howells 	ktime_t			cong_tstamp;	/* Last time cwnd was changed */
69157494343SDavid Howells 
6928940ba3cSDavid Howells 	/* Receive-phase ACK management (ACKs we send). */
6934e36a95eSDavid Howells 	u8			ackr_reason;	/* reason to ACK */
694f21e9348SDavid Howells 	u16			ackr_sack_base;	/* Starting slot in SACK table ring */
6950d12f8a4SDavid Howells 	rxrpc_serial_t		ackr_serial;	/* serial of packet being ACK'd */
6965bbf9533SDavid Howells 	rxrpc_seq_t		ackr_window;	/* Base of SACK window */
6975bbf9533SDavid Howells 	rxrpc_seq_t		ackr_wtop;	/* Base of SACK window */
6985bbf9533SDavid Howells 	unsigned int		ackr_nr_unacked; /* Number of unacked packets */
6999a3dedcfSDavid Howells 	atomic_t		ackr_nr_consumed; /* Number of packets needing hard ACK */
7005d7edbc9SDavid Howells 	struct {
7015d7edbc9SDavid Howells #define RXRPC_SACK_SIZE 256
7025d7edbc9SDavid Howells 		 /* SACK table for soft-acked packets */
7035d7edbc9SDavid Howells 		u8		ackr_sack_table[RXRPC_SACK_SIZE];
7045d7edbc9SDavid Howells 	} __aligned(8);
705a5af7e1fSDavid Howells 
7064700c4d8SDavid Howells 	/* RTT management */
7074700c4d8SDavid Howells 	rxrpc_serial_t		rtt_serial[4];	/* Serial number of DATA or PING sent */
7084700c4d8SDavid Howells 	ktime_t			rtt_sent_at[4];	/* Time packet sent */
7094700c4d8SDavid Howells 	unsigned long		rtt_avail;	/* Mask of available slots in bits 0-3,
7104700c4d8SDavid Howells 						 * Mask of pending samples in 8-11 */
7114700c4d8SDavid Howells #define RXRPC_CALL_RTT_AVAIL_MASK	0xf
7124700c4d8SDavid Howells #define RXRPC_CALL_RTT_PEND_SHIFT	8
71317926a79SDavid Howells 
7148940ba3cSDavid Howells 	/* Transmission-phase ACK management (ACKs we've received). */
71557494343SDavid Howells 	ktime_t			acks_latest_ts;	/* Timestamp of latest ACK received */
7168940ba3cSDavid Howells 	rxrpc_seq_t		acks_first_seq;	/* first sequence number received */
71781524b63SDavid Howells 	rxrpc_seq_t		acks_prev_seq;	/* Highest previousPacket received */
718a4ea4c47SDavid Howells 	rxrpc_seq_t		acks_hard_ack;	/* Latest hard-ack point */
71931a1b989SDavid Howells 	rxrpc_seq_t		acks_lowest_nak; /* Lowest NACK in the buffer (or ==tx_hard_ack) */
720589a0c1eSDavid Howells 	rxrpc_serial_t		acks_highest_serial; /* Highest serial number ACK'd */
72131a1b989SDavid Howells };
72231a1b989SDavid Howells 
72331a1b989SDavid Howells /*
72457494343SDavid Howells  * Summary of a new ACK and the changes it made to the Tx buffer packet states.
72531a1b989SDavid Howells  */
72631a1b989SDavid Howells struct rxrpc_ack_summary {
7271fc4fa2aSDavid Howells 	u16			nr_acks;		/* Number of ACKs in packet */
7281fc4fa2aSDavid Howells 	u16			nr_new_acks;		/* Number of new ACKs in packet */
7291fc4fa2aSDavid Howells 	u16			nr_rot_new_acks;	/* Number of rotated new ACKs */
73031a1b989SDavid Howells 	u8			ack_reason;
731d57a3a15SDavid Howells 	bool			saw_nacks;		/* Saw NACKs in packet */
73231a1b989SDavid Howells 	bool			new_low_nack;		/* T if new low NACK found */
73357494343SDavid Howells 	bool			retrans_timeo;		/* T if reTx due to timeout happened */
73457494343SDavid Howells 	u8			flight_size;		/* Number of unreceived transmissions */
73557494343SDavid Howells 	/* Place to stash values for tracing */
73657494343SDavid Howells 	enum rxrpc_congest_mode	mode:8;
73757494343SDavid Howells 	u8			cwnd;
73857494343SDavid Howells 	u8			ssthresh;
73957494343SDavid Howells 	u8			dup_acks;
74057494343SDavid Howells 	u8			cumulative_acks;
74117926a79SDavid Howells };
74217926a79SDavid Howells 
74348124178SDavid Howells /*
74448124178SDavid Howells  * sendmsg() cmsg-specified parameters.
74548124178SDavid Howells  */
74648124178SDavid Howells enum rxrpc_command {
74748124178SDavid Howells 	RXRPC_CMD_SEND_DATA,		/* send data message */
74848124178SDavid Howells 	RXRPC_CMD_SEND_ABORT,		/* request abort generation */
74948124178SDavid Howells 	RXRPC_CMD_REJECT_BUSY,		/* [server] reject a call as busy */
7502d914c1bSDavid Howells 	RXRPC_CMD_CHARGE_ACCEPT,	/* [server] charge accept preallocation */
75148124178SDavid Howells };
75248124178SDavid Howells 
75348124178SDavid Howells struct rxrpc_call_params {
75448124178SDavid Howells 	s64			tx_total_len;	/* Total Tx data length (if send data) */
75548124178SDavid Howells 	unsigned long		user_call_ID;	/* User's call ID */
75648124178SDavid Howells 	struct {
75748124178SDavid Howells 		u32		hard;		/* Maximum lifetime (sec) */
75848124178SDavid Howells 		u32		idle;		/* Max time since last data packet (msec) */
75948124178SDavid Howells 		u32		normal;		/* Max time since last call packet (msec) */
76048124178SDavid Howells 	} timeouts;
76148124178SDavid Howells 	u8			nr_timeouts;	/* Number of timeouts specified */
762b7a7d674SDavid Howells 	bool			kernel;		/* T if kernel is making the call */
763e138aa7dSDavid Howells 	enum rxrpc_interruptibility interruptibility; /* How is interruptible is the call? */
76448124178SDavid Howells };
76548124178SDavid Howells 
76648124178SDavid Howells struct rxrpc_send_params {
76748124178SDavid Howells 	struct rxrpc_call_params call;
76848124178SDavid Howells 	u32			abort_code;	/* Abort code to Tx (if abort) */
76948124178SDavid Howells 	enum rxrpc_command	command : 8;	/* The command to implement */
77048124178SDavid Howells 	bool			exclusive;	/* Shared or exclusive call */
77148124178SDavid Howells 	bool			upgrade;	/* If the connection is upgradeable */
77248124178SDavid Howells };
77348124178SDavid Howells 
77402a19356SDavid Howells /*
77502a19356SDavid Howells  * Buffer of data to be output as a packet.
77602a19356SDavid Howells  */
77702a19356SDavid Howells struct rxrpc_txbuf {
77802a19356SDavid Howells 	struct rcu_head		rcu;
779cf37b598SDavid Howells 	struct list_head	call_link;	/* Link in call->tx_sendmsg/tx_buffer */
78002a19356SDavid Howells 	struct list_head	tx_link;	/* Link in live Enc queue or Tx queue */
78102a19356SDavid Howells 	ktime_t			last_sent;	/* Time at which last transmitted */
78202a19356SDavid Howells 	refcount_t		ref;
78302a19356SDavid Howells 	rxrpc_seq_t		seq;		/* Sequence number of this packet */
78402a19356SDavid Howells 	unsigned int		call_debug_id;
78502a19356SDavid Howells 	unsigned int		debug_id;
78602a19356SDavid Howells 	unsigned int		len;		/* Amount of data in buffer */
78702a19356SDavid Howells 	unsigned int		space;		/* Remaining data space */
78802a19356SDavid Howells 	unsigned int		offset;		/* Offset of fill point */
78902a19356SDavid Howells 	unsigned long		flags;
790d57a3a15SDavid Howells #define RXRPC_TXBUF_LAST	0		/* Set if last packet in Tx phase */
791d57a3a15SDavid Howells #define RXRPC_TXBUF_RESENT	1		/* Set if has been resent */
79272f0c6fbSDavid Howells 	u8 /*enum rxrpc_propose_ack_trace*/ ack_why;	/* If ack, why */
79302a19356SDavid Howells 	struct {
79402a19356SDavid Howells 		/* The packet for encrypting and DMA'ing.  We align it such
79502a19356SDavid Howells 		 * that data[] aligns correctly for any crypto blocksize.
79602a19356SDavid Howells 		 */
79702a19356SDavid Howells 		u8		pad[64 - sizeof(struct rxrpc_wire_header)];
79802a19356SDavid Howells 		struct rxrpc_wire_header wire;	/* Network-ready header */
79972f0c6fbSDavid Howells 		union {
80002a19356SDavid Howells 			u8	data[RXRPC_JUMBO_DATALEN]; /* Data packet */
80172f0c6fbSDavid Howells 			struct {
80272f0c6fbSDavid Howells 				struct rxrpc_ackpacket ack;
803b2ba00c2SStephen Rothwell 				DECLARE_FLEX_ARRAY(u8, acks);
80472f0c6fbSDavid Howells 			};
80572f0c6fbSDavid Howells 		};
80602a19356SDavid Howells 	} __aligned(64);
80702a19356SDavid Howells };
80802a19356SDavid Howells 
80902a19356SDavid Howells static inline bool rxrpc_sending_to_server(const struct rxrpc_txbuf *txb)
81002a19356SDavid Howells {
81102a19356SDavid Howells 	return txb->wire.flags & RXRPC_CLIENT_INITIATED;
81202a19356SDavid Howells }
81302a19356SDavid Howells 
81402a19356SDavid Howells static inline bool rxrpc_sending_to_client(const struct rxrpc_txbuf *txb)
81502a19356SDavid Howells {
81602a19356SDavid Howells 	return !rxrpc_sending_to_server(txb);
81702a19356SDavid Howells }
81802a19356SDavid Howells 
819df844fd4SDavid Howells #include <trace/events/rxrpc.h>
820df844fd4SDavid Howells 
82117926a79SDavid Howells /*
822*2c9dc472SDavid Howells  * Allocate the next serial number on a connection.  0 must be skipped.
823*2c9dc472SDavid Howells  */
824*2c9dc472SDavid Howells static inline rxrpc_serial_t rxrpc_get_next_serial(struct rxrpc_connection *conn)
825*2c9dc472SDavid Howells {
826*2c9dc472SDavid Howells 	rxrpc_serial_t serial;
827*2c9dc472SDavid Howells 
828*2c9dc472SDavid Howells 	serial = conn->tx_serial;
829*2c9dc472SDavid Howells 	if (serial == 0)
830*2c9dc472SDavid Howells 		serial = 1;
831*2c9dc472SDavid Howells 	conn->tx_serial = serial + 1;
832*2c9dc472SDavid Howells 	return serial;
833*2c9dc472SDavid Howells }
834*2c9dc472SDavid Howells 
835*2c9dc472SDavid Howells /*
836651350d1SDavid Howells  * af_rxrpc.c
83717926a79SDavid Howells  */
838a4ea4c47SDavid Howells extern atomic_t rxrpc_n_rx_skbs;
839651350d1SDavid Howells extern struct workqueue_struct *rxrpc_workqueue;
84017926a79SDavid Howells 
84117926a79SDavid Howells /*
8420d81a51aSDavid Howells  * call_accept.c
84317926a79SDavid Howells  */
84400e90712SDavid Howells int rxrpc_service_prealloc(struct rxrpc_sock *, gfp_t);
84500e90712SDavid Howells void rxrpc_discard_prealloc(struct rxrpc_sock *);
84657af281eSDavid Howells bool rxrpc_new_incoming_call(struct rxrpc_local *local,
84757af281eSDavid Howells 			     struct rxrpc_peer *peer,
84857af281eSDavid Howells 			     struct rxrpc_connection *conn,
84957af281eSDavid Howells 			     struct sockaddr_rxrpc *peer_srx,
85057af281eSDavid Howells 			     struct sk_buff *skb);
8514f95dd78SDavid Howells void rxrpc_accept_incoming_calls(struct rxrpc_local *);
8522d914c1bSDavid Howells int rxrpc_user_charge_accept(struct rxrpc_sock *, unsigned long);
85317926a79SDavid Howells 
85417926a79SDavid Howells /*
8550d81a51aSDavid Howells  * call_event.c
85617926a79SDavid Howells  */
85772f0c6fbSDavid Howells void rxrpc_propose_ping(struct rxrpc_call *call, u32 serial,
85872f0c6fbSDavid Howells 			enum rxrpc_propose_ack_trace why);
85972f0c6fbSDavid Howells void rxrpc_send_ACK(struct rxrpc_call *, u8, rxrpc_serial_t, enum rxrpc_propose_ack_trace);
860530403d9SDavid Howells void rxrpc_propose_delay_ACK(struct rxrpc_call *, rxrpc_serial_t,
861530403d9SDavid Howells 			     enum rxrpc_propose_ack_trace);
862a4ea4c47SDavid Howells void rxrpc_shrink_call_tx_buffer(struct rxrpc_call *);
8635e6ef4f1SDavid Howells void rxrpc_resend(struct rxrpc_call *call, struct sk_buff *ack_skb);
86417926a79SDavid Howells 
8654a7f62f9SDavid Howells void rxrpc_reduce_call_timer(struct rxrpc_call *call,
866a158bdd3SDavid Howells 			     unsigned long expire_at,
867a158bdd3SDavid Howells 			     unsigned long now,
8684a7f62f9SDavid Howells 			     enum rxrpc_timer_trace why);
8694a7f62f9SDavid Howells 
87057af281eSDavid Howells bool rxrpc_input_call_event(struct rxrpc_call *call, struct sk_buff *skb);
8715e6ef4f1SDavid Howells 
87217926a79SDavid Howells /*
8730d81a51aSDavid Howells  * call_object.c
87417926a79SDavid Howells  */
875f5c17aaeSDavid Howells extern const char *const rxrpc_call_states[];
876f5c17aaeSDavid Howells extern const char *const rxrpc_call_completions[];
87717926a79SDavid Howells extern struct kmem_cache *rxrpc_call_jar;
87817926a79SDavid Howells 
87915f661dcSDavid Howells void rxrpc_poke_call(struct rxrpc_call *call, enum rxrpc_call_poke_trace what);
8802341e077SDavid Howells struct rxrpc_call *rxrpc_find_call_by_user_ID(struct rxrpc_sock *, unsigned long);
881a25e21f0SDavid Howells struct rxrpc_call *rxrpc_alloc_call(struct rxrpc_sock *, gfp_t, unsigned int);
8822341e077SDavid Howells struct rxrpc_call *rxrpc_new_client_call(struct rxrpc_sock *,
88319ffa01cSDavid Howells 					 struct rxrpc_conn_parameters *,
884999b69f8SDavid Howells 					 struct sockaddr_rxrpc *,
885a25e21f0SDavid Howells 					 struct rxrpc_call_params *, gfp_t,
886a25e21f0SDavid Howells 					 unsigned int);
8879d35d880SDavid Howells void rxrpc_start_call_timer(struct rxrpc_call *call);
888248f219cSDavid Howells void rxrpc_incoming_call(struct rxrpc_sock *, struct rxrpc_call *,
88942886ffeSDavid Howells 			 struct sk_buff *);
8908d94aa38SDavid Howells void rxrpc_release_call(struct rxrpc_sock *, struct rxrpc_call *);
891c1b1203dSJoe Perches void rxrpc_release_calls_on_socket(struct rxrpc_sock *);
892cb0fc0c9SDavid Howells void rxrpc_see_call(struct rxrpc_call *, enum rxrpc_call_trace);
8935e6ef4f1SDavid Howells struct rxrpc_call *rxrpc_try_get_call(struct rxrpc_call *, enum rxrpc_call_trace);
894fff72429SDavid Howells void rxrpc_get_call(struct rxrpc_call *, enum rxrpc_call_trace);
895fff72429SDavid Howells void rxrpc_put_call(struct rxrpc_call *, enum rxrpc_call_trace);
89600e90712SDavid Howells void rxrpc_cleanup_call(struct rxrpc_call *);
8972baec2c3SDavid Howells void rxrpc_destroy_all_calls(struct rxrpc_net *);
89817926a79SDavid Howells 
899dabe5a79SDavid Howells static inline bool rxrpc_is_service_call(const struct rxrpc_call *call)
900dabe5a79SDavid Howells {
901dabe5a79SDavid Howells 	return test_bit(RXRPC_CALL_IS_SERVICE, &call->flags);
902dabe5a79SDavid Howells }
903dabe5a79SDavid Howells 
904dabe5a79SDavid Howells static inline bool rxrpc_is_client_call(const struct rxrpc_call *call)
905dabe5a79SDavid Howells {
906dabe5a79SDavid Howells 	return !rxrpc_is_service_call(call);
907dabe5a79SDavid Howells }
908dabe5a79SDavid Howells 
90917926a79SDavid Howells /*
9100b9bb322SDavid Howells  * call_state.c
9110b9bb322SDavid Howells  */
9120b9bb322SDavid Howells bool rxrpc_set_call_completion(struct rxrpc_call *call,
9130b9bb322SDavid Howells 			       enum rxrpc_call_completion compl,
9140b9bb322SDavid Howells 			       u32 abort_code,
9150b9bb322SDavid Howells 			       int error);
9160b9bb322SDavid Howells bool rxrpc_call_completed(struct rxrpc_call *call);
9170b9bb322SDavid Howells bool rxrpc_abort_call(struct rxrpc_call *call, rxrpc_seq_t seq,
9180b9bb322SDavid Howells 		      u32 abort_code, int error, enum rxrpc_abort_reason why);
91996b4059fSDavid Howells void rxrpc_prefail_call(struct rxrpc_call *call, enum rxrpc_call_completion compl,
92096b4059fSDavid Howells 			int error);
92196b4059fSDavid Howells 
92296b4059fSDavid Howells static inline void rxrpc_set_call_state(struct rxrpc_call *call,
92396b4059fSDavid Howells 					enum rxrpc_call_state state)
92496b4059fSDavid Howells {
92596b4059fSDavid Howells 	/* Order write of completion info before write of ->state. */
92696b4059fSDavid Howells 	smp_store_release(&call->_state, state);
9279d35d880SDavid Howells 	wake_up(&call->waitq);
92896b4059fSDavid Howells }
92996b4059fSDavid Howells 
93096b4059fSDavid Howells static inline enum rxrpc_call_state __rxrpc_call_state(const struct rxrpc_call *call)
93196b4059fSDavid Howells {
93296b4059fSDavid Howells 	return call->_state; /* Only inside I/O thread */
93396b4059fSDavid Howells }
93496b4059fSDavid Howells 
93596b4059fSDavid Howells static inline bool __rxrpc_call_is_complete(const struct rxrpc_call *call)
93696b4059fSDavid Howells {
93796b4059fSDavid Howells 	return __rxrpc_call_state(call) == RXRPC_CALL_COMPLETE;
93896b4059fSDavid Howells }
9390b9bb322SDavid Howells 
940d41b3f5bSDavid Howells static inline enum rxrpc_call_state rxrpc_call_state(const struct rxrpc_call *call)
941d41b3f5bSDavid Howells {
94296b4059fSDavid Howells 	/* Order read ->state before read of completion info. */
94396b4059fSDavid Howells 	return smp_load_acquire(&call->_state);
944d41b3f5bSDavid Howells }
945d41b3f5bSDavid Howells 
946d41b3f5bSDavid Howells static inline bool rxrpc_call_is_complete(const struct rxrpc_call *call)
947d41b3f5bSDavid Howells {
948d41b3f5bSDavid Howells 	return rxrpc_call_state(call) == RXRPC_CALL_COMPLETE;
949d41b3f5bSDavid Howells }
950d41b3f5bSDavid Howells 
951d41b3f5bSDavid Howells static inline bool rxrpc_call_has_failed(const struct rxrpc_call *call)
952d41b3f5bSDavid Howells {
953d41b3f5bSDavid Howells 	return rxrpc_call_is_complete(call) && call->completion != RXRPC_CALL_SUCCEEDED;
954d41b3f5bSDavid Howells }
955d41b3f5bSDavid Howells 
9560b9bb322SDavid Howells /*
9574a3388c8SDavid Howells  * conn_client.c
9584a3388c8SDavid Howells  */
95945025bceSDavid Howells extern unsigned int rxrpc_reap_client_connections;
960a158bdd3SDavid Howells extern unsigned long rxrpc_conn_idle_client_expiry;
961a158bdd3SDavid Howells extern unsigned long rxrpc_conn_idle_client_fast_expiry;
9624a3388c8SDavid Howells 
9639d35d880SDavid Howells void rxrpc_purge_client_connections(struct rxrpc_local *local);
964fa3492abSDavid Howells struct rxrpc_bundle *rxrpc_get_bundle(struct rxrpc_bundle *, enum rxrpc_bundle_trace);
965fa3492abSDavid Howells void rxrpc_put_bundle(struct rxrpc_bundle *, enum rxrpc_bundle_trace);
9669d35d880SDavid Howells int rxrpc_look_up_bundle(struct rxrpc_call *call, gfp_t gfp);
9679d35d880SDavid Howells void rxrpc_connect_client_calls(struct rxrpc_local *local);
96845025bceSDavid Howells void rxrpc_expose_client_call(struct rxrpc_call *);
969245500d8SDavid Howells void rxrpc_disconnect_client_call(struct rxrpc_bundle *, struct rxrpc_call *);
9701bab27afSDavid Howells void rxrpc_deactivate_bundle(struct rxrpc_bundle *bundle);
9717fa25105SDavid Howells void rxrpc_put_client_conn(struct rxrpc_connection *, enum rxrpc_conn_trace);
9720d6bf319SDavid Howells void rxrpc_discard_expired_client_conns(struct rxrpc_local *local);
973d12040b6SDavid Howells void rxrpc_clean_up_local_conns(struct rxrpc_local *);
9744a3388c8SDavid Howells 
9754a3388c8SDavid Howells /*
9760d81a51aSDavid Howells  * conn_event.c
9770d81a51aSDavid Howells  */
97830df927bSDavid Howells void rxrpc_conn_retransmit_call(struct rxrpc_connection *conn, struct sk_buff *skb,
97930df927bSDavid Howells 				unsigned int channel);
980a00ce28bSDavid Howells int rxrpc_abort_conn(struct rxrpc_connection *conn, struct sk_buff *skb,
98157af281eSDavid Howells 		     s32 abort_code, int err, enum rxrpc_abort_reason why);
9820d81a51aSDavid Howells void rxrpc_process_connection(struct work_struct *);
983ddc7834aSDavid Howells void rxrpc_process_delayed_final_acks(struct rxrpc_connection *, bool);
98457af281eSDavid Howells bool rxrpc_input_conn_packet(struct rxrpc_connection *conn, struct sk_buff *skb);
985f2cce89aSDavid Howells void rxrpc_input_conn_event(struct rxrpc_connection *conn, struct sk_buff *skb);
9860d81a51aSDavid Howells 
987a00ce28bSDavid Howells static inline bool rxrpc_is_conn_aborted(const struct rxrpc_connection *conn)
988a00ce28bSDavid Howells {
989a00ce28bSDavid Howells 	/* Order reading the abort info after the state check. */
990a00ce28bSDavid Howells 	return smp_load_acquire(&conn->state) == RXRPC_CONN_ABORTED;
991a00ce28bSDavid Howells }
992a00ce28bSDavid Howells 
9930d81a51aSDavid Howells /*
9940d81a51aSDavid Howells  * conn_object.c
99517926a79SDavid Howells  */
996dad8aff7SDavid Howells extern unsigned int rxrpc_connection_expiry;
997f859ab61SDavid Howells extern unsigned int rxrpc_closed_conn_expiry;
99817926a79SDavid Howells 
999f2cce89aSDavid Howells void rxrpc_poke_conn(struct rxrpc_connection *conn, enum rxrpc_conn_trace why);
10003cec055cSDavid Howells struct rxrpc_connection *rxrpc_alloc_connection(struct rxrpc_net *, gfp_t);
10015e6ef4f1SDavid Howells struct rxrpc_connection *rxrpc_find_client_connection_rcu(struct rxrpc_local *,
1002393a2a20SDavid Howells 							  struct sockaddr_rxrpc *,
10035e6ef4f1SDavid Howells 							  struct sk_buff *);
100445025bceSDavid Howells void __rxrpc_disconnect_call(struct rxrpc_connection *, struct rxrpc_call *);
1005999b69f8SDavid Howells void rxrpc_disconnect_call(struct rxrpc_call *);
10063cec055cSDavid Howells void rxrpc_kill_client_conn(struct rxrpc_connection *);
10073cec055cSDavid Howells void rxrpc_queue_conn(struct rxrpc_connection *, enum rxrpc_conn_trace);
10087fa25105SDavid Howells void rxrpc_see_connection(struct rxrpc_connection *, enum rxrpc_conn_trace);
10097fa25105SDavid Howells struct rxrpc_connection *rxrpc_get_connection(struct rxrpc_connection *,
10107fa25105SDavid Howells 					      enum rxrpc_conn_trace);
10117fa25105SDavid Howells struct rxrpc_connection *rxrpc_get_connection_maybe(struct rxrpc_connection *,
10127fa25105SDavid Howells 						    enum rxrpc_conn_trace);
10133cec055cSDavid Howells void rxrpc_put_connection(struct rxrpc_connection *, enum rxrpc_conn_trace);
10142baec2c3SDavid Howells void rxrpc_service_connection_reaper(struct work_struct *);
10152baec2c3SDavid Howells void rxrpc_destroy_all_connections(struct rxrpc_net *);
101617926a79SDavid Howells 
101719ffa01cSDavid Howells static inline bool rxrpc_conn_is_client(const struct rxrpc_connection *conn)
101819ffa01cSDavid Howells {
101919ffa01cSDavid Howells 	return conn->out_clientflag;
102019ffa01cSDavid Howells }
102119ffa01cSDavid Howells 
102219ffa01cSDavid Howells static inline bool rxrpc_conn_is_service(const struct rxrpc_connection *conn)
102319ffa01cSDavid Howells {
1024e8d70ce1SDavid Howells 	return !rxrpc_conn_is_client(conn);
102519ffa01cSDavid Howells }
102619ffa01cSDavid Howells 
10273136ef49SDavid Howells static inline void rxrpc_reduce_conn_timer(struct rxrpc_connection *conn,
10283136ef49SDavid Howells 					   unsigned long expire_at)
10293136ef49SDavid Howells {
10303136ef49SDavid Howells 	timer_reduce(&conn->timer, expire_at);
10313136ef49SDavid Howells }
10323136ef49SDavid Howells 
103317926a79SDavid Howells /*
10347877a4a4SDavid Howells  * conn_service.c
10357877a4a4SDavid Howells  */
10368496af50SDavid Howells struct rxrpc_connection *rxrpc_find_service_conn_rcu(struct rxrpc_peer *,
10378496af50SDavid Howells 						     struct sk_buff *);
10382baec2c3SDavid Howells struct rxrpc_connection *rxrpc_prealloc_service_connection(struct rxrpc_net *, gfp_t);
1039063c60d3SDavid Howells void rxrpc_new_incoming_connection(struct rxrpc_sock *, struct rxrpc_connection *,
1040ec832bd0SDavid Howells 				   const struct rxrpc_security *, struct sk_buff *);
1041001c1122SDavid Howells void rxrpc_unpublish_service_conn(struct rxrpc_connection *);
10427877a4a4SDavid Howells 
10437877a4a4SDavid Howells /*
10440d81a51aSDavid Howells  * input.c
104517926a79SDavid Howells  */
10465086d9a9SDavid Howells void rxrpc_congestion_degrade(struct rxrpc_call *);
10475e6ef4f1SDavid Howells void rxrpc_input_call_packet(struct rxrpc_call *, struct sk_buff *);
10485e6ef4f1SDavid Howells void rxrpc_implicit_end_call(struct rxrpc_call *, struct sk_buff *);
104996b2d69bSDavid Howells 
105096b2d69bSDavid Howells /*
105196b2d69bSDavid Howells  * io_thread.c
105296b2d69bSDavid Howells  */
1053446b3e14SDavid Howells int rxrpc_encap_rcv(struct sock *, struct sk_buff *);
1054ff734825SDavid Howells void rxrpc_error_report(struct sock *);
105557af281eSDavid Howells bool rxrpc_direct_abort(struct sk_buff *skb, enum rxrpc_abort_reason why,
105657af281eSDavid Howells 			s32 abort_code, int err);
1057a275da62SDavid Howells int rxrpc_io_thread(void *data);
1058a275da62SDavid Howells static inline void rxrpc_wake_up_io_thread(struct rxrpc_local *local)
1059a275da62SDavid Howells {
1060a275da62SDavid Howells 	wake_up_process(local->io_thread);
1061a275da62SDavid Howells }
106217926a79SDavid Howells 
106357af281eSDavid Howells static inline bool rxrpc_protocol_error(struct sk_buff *skb, enum rxrpc_abort_reason why)
106457af281eSDavid Howells {
106557af281eSDavid Howells 	return rxrpc_direct_abort(skb, why, RX_PROTOCOL_ERROR, -EPROTO);
106657af281eSDavid Howells }
106757af281eSDavid Howells 
106817926a79SDavid Howells /*
10690d81a51aSDavid Howells  * insecure.c
107017926a79SDavid Howells  */
10710d81a51aSDavid Howells extern const struct rxrpc_security rxrpc_no_security;
107217926a79SDavid Howells 
107317926a79SDavid Howells /*
10740d81a51aSDavid Howells  * key.c
107517926a79SDavid Howells  */
107617926a79SDavid Howells extern struct key_type key_type_rxrpc;
107717926a79SDavid Howells 
1078a7b75c5aSChristoph Hellwig int rxrpc_request_key(struct rxrpc_sock *, sockptr_t , int);
107910674a03SBaolin Wang int rxrpc_get_server_data_key(struct rxrpc_connection *, const void *, time64_t,
1080c1b1203dSJoe Perches 			      u32);
108117926a79SDavid Howells 
108217926a79SDavid Howells /*
108387563616SDavid Howells  * local_event.c
108487563616SDavid Howells  */
1085020c69c1SDavid Howells void rxrpc_gen_version_string(void);
10865e6ef4f1SDavid Howells void rxrpc_send_version_request(struct rxrpc_local *local,
10875e6ef4f1SDavid Howells 				struct rxrpc_host_header *hdr,
10885e6ef4f1SDavid Howells 				struct sk_buff *skb);
108987563616SDavid Howells 
109087563616SDavid Howells /*
10910d81a51aSDavid Howells  * local_object.c
109217926a79SDavid Howells  */
10935c4017a2SDavid Howells void rxrpc_local_dont_fragment(const struct rxrpc_local *local, bool set);
10942baec2c3SDavid Howells struct rxrpc_local *rxrpc_lookup_local(struct net *, const struct sockaddr_rxrpc *);
10950fde882fSDavid Howells struct rxrpc_local *rxrpc_get_local(struct rxrpc_local *, enum rxrpc_local_trace);
10960fde882fSDavid Howells struct rxrpc_local *rxrpc_get_local_maybe(struct rxrpc_local *, enum rxrpc_local_trace);
10970fde882fSDavid Howells void rxrpc_put_local(struct rxrpc_local *, enum rxrpc_local_trace);
10980fde882fSDavid Howells struct rxrpc_local *rxrpc_use_local(struct rxrpc_local *, enum rxrpc_local_trace);
10990fde882fSDavid Howells void rxrpc_unuse_local(struct rxrpc_local *, enum rxrpc_local_trace);
1100a275da62SDavid Howells void rxrpc_destroy_local(struct rxrpc_local *local);
11012baec2c3SDavid Howells void rxrpc_destroy_all_locals(struct rxrpc_net *);
1102e0e4d82fSDavid Howells 
11030fde882fSDavid Howells static inline bool __rxrpc_use_local(struct rxrpc_local *local,
11040fde882fSDavid Howells 				     enum rxrpc_local_trace why)
110504d36d74SDavid Howells {
11060fde882fSDavid Howells 	int r, u;
11070fde882fSDavid Howells 
11080fde882fSDavid Howells 	r = refcount_read(&local->ref);
11090fde882fSDavid Howells 	u = atomic_fetch_add_unless(&local->active_users, 1, 0);
11100fde882fSDavid Howells 	trace_rxrpc_local(local->debug_id, why, r, u);
11110fde882fSDavid Howells 	return u != 0;
11120fde882fSDavid Howells }
11130fde882fSDavid Howells 
11140fde882fSDavid Howells static inline void rxrpc_see_local(struct rxrpc_local *local,
11150fde882fSDavid Howells 				   enum rxrpc_local_trace why)
11160fde882fSDavid Howells {
11170fde882fSDavid Howells 	int r, u;
11180fde882fSDavid Howells 
11190fde882fSDavid Howells 	r = refcount_read(&local->ref);
11200fde882fSDavid Howells 	u = atomic_read(&local->active_users);
11210fde882fSDavid Howells 	trace_rxrpc_local(local->debug_id, why, r, u);
112204d36d74SDavid Howells }
112304d36d74SDavid Howells 
1124e0e4d82fSDavid Howells /*
11258e688d9cSDavid Howells  * misc.c
11268e688d9cSDavid Howells  */
11270e119b41SDavid Howells extern unsigned int rxrpc_max_backlog __read_mostly;
1128a158bdd3SDavid Howells extern unsigned long rxrpc_soft_ack_delay;
1129a158bdd3SDavid Howells extern unsigned long rxrpc_idle_ack_delay;
11308e688d9cSDavid Howells extern unsigned int rxrpc_rx_window_size;
11318e688d9cSDavid Howells extern unsigned int rxrpc_rx_mtu;
11328e688d9cSDavid Howells extern unsigned int rxrpc_rx_jumbo_max;
1133af094824SDavid Howells #ifdef CONFIG_AF_RXRPC_INJECT_RX_DELAY
1134af094824SDavid Howells extern unsigned long rxrpc_inject_rx_delay;
1135af094824SDavid Howells #endif
11368e688d9cSDavid Howells 
11378e688d9cSDavid Howells /*
11382baec2c3SDavid Howells  * net_ns.c
11392baec2c3SDavid Howells  */
11402baec2c3SDavid Howells extern unsigned int rxrpc_net_id;
11412baec2c3SDavid Howells extern struct pernet_operations rxrpc_net_ops;
11422baec2c3SDavid Howells 
11432baec2c3SDavid Howells static inline struct rxrpc_net *rxrpc_net(struct net *net)
11442baec2c3SDavid Howells {
11452baec2c3SDavid Howells 	return net_generic(net, rxrpc_net_id);
11462baec2c3SDavid Howells }
11472baec2c3SDavid Howells 
11482baec2c3SDavid Howells /*
11490d81a51aSDavid Howells  * output.c
11500d81a51aSDavid Howells  */
1151b0346843SDavid Howells int rxrpc_send_ack_packet(struct rxrpc_call *call, struct rxrpc_txbuf *txb);
115226cb02aaSDavid Howells int rxrpc_send_abort_packet(struct rxrpc_call *);
1153a4ea4c47SDavid Howells int rxrpc_send_data_packet(struct rxrpc_call *, struct rxrpc_txbuf *);
1154a00ce28bSDavid Howells void rxrpc_send_conn_abort(struct rxrpc_connection *conn);
11555e6ef4f1SDavid Howells void rxrpc_reject_packet(struct rxrpc_local *local, struct sk_buff *skb);
1156ace45becSDavid Howells void rxrpc_send_keepalive(struct rxrpc_peer *);
1157cf37b598SDavid Howells void rxrpc_transmit_one(struct rxrpc_call *call, struct rxrpc_txbuf *txb);
11580d81a51aSDavid Howells 
11590d81a51aSDavid Howells /*
1160abe89ef0SDavid Howells  * peer_event.c
11610d81a51aSDavid Howells  */
1162ff734825SDavid Howells void rxrpc_input_error(struct rxrpc_local *, struct sk_buff *);
1163ace45becSDavid Howells void rxrpc_peer_keepalive_worker(struct work_struct *);
11640d81a51aSDavid Howells 
11650d81a51aSDavid Howells /*
11660d81a51aSDavid Howells  * peer_object.c
11670d81a51aSDavid Howells  */
1168be6e6707SDavid Howells struct rxrpc_peer *rxrpc_lookup_peer_rcu(struct rxrpc_local *,
1169be6e6707SDavid Howells 					 const struct sockaddr_rxrpc *);
11708a758d98SDavid Howells struct rxrpc_peer *rxrpc_lookup_peer(struct rxrpc_local *local,
11718a758d98SDavid Howells 				     struct sockaddr_rxrpc *srx, gfp_t gfp);
117247c810a7SDavid Howells struct rxrpc_peer *rxrpc_alloc_peer(struct rxrpc_local *, gfp_t,
117347c810a7SDavid Howells 				    enum rxrpc_peer_trace);
11748a758d98SDavid Howells void rxrpc_new_incoming_peer(struct rxrpc_local *local, struct rxrpc_peer *peer);
117517226f12SDavid Howells void rxrpc_destroy_all_peers(struct rxrpc_net *);
117647c810a7SDavid Howells struct rxrpc_peer *rxrpc_get_peer(struct rxrpc_peer *, enum rxrpc_peer_trace);
117747c810a7SDavid Howells struct rxrpc_peer *rxrpc_get_peer_maybe(struct rxrpc_peer *, enum rxrpc_peer_trace);
117847c810a7SDavid Howells void rxrpc_put_peer(struct rxrpc_peer *, enum rxrpc_peer_trace);
11790d81a51aSDavid Howells 
11800d81a51aSDavid Howells /*
11810d81a51aSDavid Howells  * proc.c
11820d81a51aSDavid Howells  */
1183c3506372SChristoph Hellwig extern const struct seq_operations rxrpc_call_seq_ops;
1184c3506372SChristoph Hellwig extern const struct seq_operations rxrpc_connection_seq_ops;
1185bc0e7cf4SDavid Howells extern const struct seq_operations rxrpc_peer_seq_ops;
118633912c26SDavid Howells extern const struct seq_operations rxrpc_local_seq_ops;
11870d81a51aSDavid Howells 
11880d81a51aSDavid Howells /*
11890d81a51aSDavid Howells  * recvmsg.c
11900d81a51aSDavid Howells  */
1191248f219cSDavid Howells void rxrpc_notify_socket(struct rxrpc_call *);
11920d81a51aSDavid Howells int rxrpc_recvmsg(struct socket *, struct msghdr *, size_t, int);
11930d81a51aSDavid Howells 
11940d81a51aSDavid Howells /*
11953067bf8cSDavid Howells  * Abort a call due to a protocol error.
11963067bf8cSDavid Howells  */
119757af281eSDavid Howells static inline int rxrpc_abort_eproto(struct rxrpc_call *call,
11983067bf8cSDavid Howells 				     struct sk_buff *skb,
119957af281eSDavid Howells 				     s32 abort_code,
120057af281eSDavid Howells 				     enum rxrpc_abort_reason why)
12013067bf8cSDavid Howells {
12023067bf8cSDavid Howells 	struct rxrpc_skb_priv *sp = rxrpc_skb(skb);
12033067bf8cSDavid Howells 
120457af281eSDavid Howells 	rxrpc_abort_call(call, sp->hdr.seq, abort_code, -EPROTO, why);
120557af281eSDavid Howells 	return -EPROTO;
12063067bf8cSDavid Howells }
12073067bf8cSDavid Howells 
12083067bf8cSDavid Howells /*
1209c410bf01SDavid Howells  * rtt.c
1210c410bf01SDavid Howells  */
12114700c4d8SDavid Howells void rxrpc_peer_add_rtt(struct rxrpc_call *, enum rxrpc_rtt_rx_trace, int,
1212c410bf01SDavid Howells 			rxrpc_serial_t, rxrpc_serial_t, ktime_t, ktime_t);
1213c410bf01SDavid Howells unsigned long rxrpc_get_rto_backoff(struct rxrpc_peer *, bool);
1214c410bf01SDavid Howells void rxrpc_peer_init_rtt(struct rxrpc_peer *);
1215c410bf01SDavid Howells 
1216c410bf01SDavid Howells /*
1217648af7fcSDavid Howells  * rxkad.c
1218648af7fcSDavid Howells  */
1219648af7fcSDavid Howells #ifdef CONFIG_RXKAD
1220648af7fcSDavid Howells extern const struct rxrpc_security rxkad;
1221648af7fcSDavid Howells #endif
1222648af7fcSDavid Howells 
1223648af7fcSDavid Howells /*
12240d81a51aSDavid Howells  * security.c
12250d81a51aSDavid Howells  */
12260d81a51aSDavid Howells int __init rxrpc_init_security(void);
122712da59fcSDavid Howells const struct rxrpc_security *rxrpc_security_lookup(u8);
12280d81a51aSDavid Howells void rxrpc_exit_security(void);
1229f3441d41SDavid Howells int rxrpc_init_client_call_security(struct rxrpc_call *);
12300d81a51aSDavid Howells int rxrpc_init_client_conn_security(struct rxrpc_connection *);
1231ec832bd0SDavid Howells const struct rxrpc_security *rxrpc_get_incoming_security(struct rxrpc_sock *,
1232063c60d3SDavid Howells 							 struct sk_buff *);
1233ec832bd0SDavid Howells struct key *rxrpc_look_up_server_security(struct rxrpc_connection *,
1234ec832bd0SDavid Howells 					  struct sk_buff *, u32, u32);
12350d81a51aSDavid Howells 
12360d81a51aSDavid Howells /*
12370b58b8a1SDavid Howells  * sendmsg.c
12380b58b8a1SDavid Howells  */
123957af281eSDavid Howells bool rxrpc_propose_abort(struct rxrpc_call *call, s32 abort_code, int error,
124057af281eSDavid Howells 			 enum rxrpc_abort_reason why);
12410b58b8a1SDavid Howells int rxrpc_do_sendmsg(struct rxrpc_sock *, struct msghdr *, size_t);
12420b58b8a1SDavid Howells 
12430b58b8a1SDavid Howells /*
1244ca7fb100SDavid Howells  * server_key.c
1245ca7fb100SDavid Howells  */
1246ca7fb100SDavid Howells extern struct key_type key_type_rxrpc_s;
1247ca7fb100SDavid Howells 
1248ca7fb100SDavid Howells int rxrpc_server_keyring(struct rxrpc_sock *, sockptr_t, int);
1249ca7fb100SDavid Howells 
1250ca7fb100SDavid Howells /*
12510d81a51aSDavid Howells  * skbuff.c
12520d81a51aSDavid Howells  */
1253d001648eSDavid Howells void rxrpc_kernel_data_consumed(struct rxrpc_call *, struct sk_buff *);
125471f3ca40SDavid Howells void rxrpc_new_skb(struct sk_buff *, enum rxrpc_skb_trace);
125571f3ca40SDavid Howells void rxrpc_see_skb(struct sk_buff *, enum rxrpc_skb_trace);
1256d0d5c0cdSDavid Howells void rxrpc_eaten_skb(struct sk_buff *, enum rxrpc_skb_trace);
125771f3ca40SDavid Howells void rxrpc_get_skb(struct sk_buff *, enum rxrpc_skb_trace);
125871f3ca40SDavid Howells void rxrpc_free_skb(struct sk_buff *, enum rxrpc_skb_trace);
1259df844fd4SDavid Howells void rxrpc_purge_queue(struct sk_buff_head *);
12600d81a51aSDavid Howells 
12610d81a51aSDavid Howells /*
1262b0154246SDavid Howells  * stats.c
1263b0154246SDavid Howells  */
1264b0154246SDavid Howells int rxrpc_stats_show(struct seq_file *seq, void *v);
1265b0154246SDavid Howells int rxrpc_stats_clear(struct file *file, char *buf, size_t size);
1266b0154246SDavid Howells 
1267b0154246SDavid Howells #define rxrpc_inc_stat(rxnet, s) atomic_inc(&(rxnet)->s)
1268b0154246SDavid Howells #define rxrpc_dec_stat(rxnet, s) atomic_dec(&(rxnet)->s)
1269b0154246SDavid Howells 
1270b0154246SDavid Howells /*
12715873c083SDavid Howells  * sysctl.c
12725873c083SDavid Howells  */
12735873c083SDavid Howells #ifdef CONFIG_SYSCTL
12745873c083SDavid Howells extern int __init rxrpc_sysctl_init(void);
12755873c083SDavid Howells extern void rxrpc_sysctl_exit(void);
12765873c083SDavid Howells #else
12775873c083SDavid Howells static inline int __init rxrpc_sysctl_init(void) { return 0; }
12785873c083SDavid Howells static inline void rxrpc_sysctl_exit(void) {}
12795873c083SDavid Howells #endif
12805873c083SDavid Howells 
12815873c083SDavid Howells /*
128202a19356SDavid Howells  * txbuf.c
128302a19356SDavid Howells  */
128402a19356SDavid Howells extern atomic_t rxrpc_nr_txbuf;
128502a19356SDavid Howells struct rxrpc_txbuf *rxrpc_alloc_txbuf(struct rxrpc_call *call, u8 packet_type,
128602a19356SDavid Howells 				      gfp_t gfp);
128702a19356SDavid Howells void rxrpc_get_txbuf(struct rxrpc_txbuf *txb, enum rxrpc_txbuf_trace what);
128802a19356SDavid Howells void rxrpc_see_txbuf(struct rxrpc_txbuf *txb, enum rxrpc_txbuf_trace what);
128902a19356SDavid Howells void rxrpc_put_txbuf(struct rxrpc_txbuf *txb, enum rxrpc_txbuf_trace what);
129002a19356SDavid Howells 
129102a19356SDavid Howells /*
1292be6e6707SDavid Howells  * utils.c
1293be6e6707SDavid Howells  */
12945a790b73SDavid Howells int rxrpc_extract_addr_from_skb(struct sockaddr_rxrpc *, struct sk_buff *);
1295be6e6707SDavid Howells 
1296248f219cSDavid Howells static inline bool before(u32 seq1, u32 seq2)
1297248f219cSDavid Howells {
1298248f219cSDavid Howells         return (s32)(seq1 - seq2) < 0;
1299248f219cSDavid Howells }
1300248f219cSDavid Howells static inline bool before_eq(u32 seq1, u32 seq2)
1301248f219cSDavid Howells {
1302248f219cSDavid Howells         return (s32)(seq1 - seq2) <= 0;
1303248f219cSDavid Howells }
1304248f219cSDavid Howells static inline bool after(u32 seq1, u32 seq2)
1305248f219cSDavid Howells {
1306248f219cSDavid Howells         return (s32)(seq1 - seq2) > 0;
1307248f219cSDavid Howells }
1308248f219cSDavid Howells static inline bool after_eq(u32 seq1, u32 seq2)
1309248f219cSDavid Howells {
1310248f219cSDavid Howells         return (s32)(seq1 - seq2) >= 0;
1311248f219cSDavid Howells }
1312248f219cSDavid Howells 
1313be6e6707SDavid Howells /*
131417926a79SDavid Howells  * debug tracing
131517926a79SDavid Howells  */
131695c96174SEric Dumazet extern unsigned int rxrpc_debug;
131717926a79SDavid Howells 
131817926a79SDavid Howells #define dbgprintk(FMT,...) \
13199f389f4bSSven Schnelle 	printk("[%-6.6s] "FMT"\n", current->comm ,##__VA_ARGS__)
132017926a79SDavid Howells 
13210dc47877SHarvey Harrison #define kenter(FMT,...)	dbgprintk("==> %s("FMT")",__func__ ,##__VA_ARGS__)
13220dc47877SHarvey Harrison #define kleave(FMT,...)	dbgprintk("<== %s()"FMT"",__func__ ,##__VA_ARGS__)
132317926a79SDavid Howells #define kdebug(FMT,...)	dbgprintk("    "FMT ,##__VA_ARGS__)
132417926a79SDavid Howells 
132517926a79SDavid Howells 
132617926a79SDavid Howells #if defined(__KDEBUG)
132717926a79SDavid Howells #define _enter(FMT,...)	kenter(FMT,##__VA_ARGS__)
132817926a79SDavid Howells #define _leave(FMT,...)	kleave(FMT,##__VA_ARGS__)
132917926a79SDavid Howells #define _debug(FMT,...)	kdebug(FMT,##__VA_ARGS__)
133017926a79SDavid Howells 
133117926a79SDavid Howells #elif defined(CONFIG_AF_RXRPC_DEBUG)
133217926a79SDavid Howells #define RXRPC_DEBUG_KENTER	0x01
133317926a79SDavid Howells #define RXRPC_DEBUG_KLEAVE	0x02
133417926a79SDavid Howells #define RXRPC_DEBUG_KDEBUG	0x04
133517926a79SDavid Howells 
133617926a79SDavid Howells #define _enter(FMT,...)					\
133717926a79SDavid Howells do {							\
133817926a79SDavid Howells 	if (unlikely(rxrpc_debug & RXRPC_DEBUG_KENTER))	\
133917926a79SDavid Howells 		kenter(FMT,##__VA_ARGS__);		\
134017926a79SDavid Howells } while (0)
134117926a79SDavid Howells 
134217926a79SDavid Howells #define _leave(FMT,...)					\
134317926a79SDavid Howells do {							\
134417926a79SDavid Howells 	if (unlikely(rxrpc_debug & RXRPC_DEBUG_KLEAVE))	\
134517926a79SDavid Howells 		kleave(FMT,##__VA_ARGS__);		\
134617926a79SDavid Howells } while (0)
134717926a79SDavid Howells 
134817926a79SDavid Howells #define _debug(FMT,...)					\
134917926a79SDavid Howells do {							\
135017926a79SDavid Howells 	if (unlikely(rxrpc_debug & RXRPC_DEBUG_KDEBUG))	\
135117926a79SDavid Howells 		kdebug(FMT,##__VA_ARGS__);		\
135217926a79SDavid Howells } while (0)
135317926a79SDavid Howells 
135417926a79SDavid Howells #else
135512fdff3fSDavid Howells #define _enter(FMT,...)	no_printk("==> %s("FMT")",__func__ ,##__VA_ARGS__)
135612fdff3fSDavid Howells #define _leave(FMT,...)	no_printk("<== %s()"FMT"",__func__ ,##__VA_ARGS__)
135712fdff3fSDavid Howells #define _debug(FMT,...)	no_printk("    "FMT ,##__VA_ARGS__)
135817926a79SDavid Howells #endif
135917926a79SDavid Howells 
136017926a79SDavid Howells /*
136117926a79SDavid Howells  * debug assertion checking
136217926a79SDavid Howells  */
136317926a79SDavid Howells #if 1 // defined(__KDEBUGALL)
136417926a79SDavid Howells 
136517926a79SDavid Howells #define ASSERT(X)						\
136617926a79SDavid Howells do {								\
136717926a79SDavid Howells 	if (unlikely(!(X))) {					\
13689b6d5398SJoe Perches 		pr_err("Assertion failed\n");			\
136917926a79SDavid Howells 		BUG();						\
137017926a79SDavid Howells 	}							\
137117926a79SDavid Howells } while (0)
137217926a79SDavid Howells 
137317926a79SDavid Howells #define ASSERTCMP(X, OP, Y)						\
137417926a79SDavid Howells do {									\
1375cf13258fSDavid Howells 	__typeof__(X) _x = (X);						\
1376cf13258fSDavid Howells 	__typeof__(Y) _y = (__typeof__(X))(Y);				\
13779b6d5398SJoe Perches 	if (unlikely(!(_x OP _y))) {					\
13789b6d5398SJoe Perches 		pr_err("Assertion failed - %lu(0x%lx) %s %lu(0x%lx) is false\n", \
1379cf13258fSDavid Howells 		       (unsigned long)_x, (unsigned long)_x, #OP,	\
1380cf13258fSDavid Howells 		       (unsigned long)_y, (unsigned long)_y);		\
138117926a79SDavid Howells 		BUG();							\
138217926a79SDavid Howells 	}								\
138317926a79SDavid Howells } while (0)
138417926a79SDavid Howells 
138517926a79SDavid Howells #define ASSERTIF(C, X)						\
138617926a79SDavid Howells do {								\
138717926a79SDavid Howells 	if (unlikely((C) && !(X))) {				\
13889b6d5398SJoe Perches 		pr_err("Assertion failed\n");			\
138917926a79SDavid Howells 		BUG();						\
139017926a79SDavid Howells 	}							\
139117926a79SDavid Howells } while (0)
139217926a79SDavid Howells 
139317926a79SDavid Howells #define ASSERTIFCMP(C, X, OP, Y)					\
139417926a79SDavid Howells do {									\
1395cf13258fSDavid Howells 	__typeof__(X) _x = (X);						\
1396cf13258fSDavid Howells 	__typeof__(Y) _y = (__typeof__(X))(Y);				\
13979b6d5398SJoe Perches 	if (unlikely((C) && !(_x OP _y))) {				\
13989b6d5398SJoe Perches 		pr_err("Assertion failed - %lu(0x%lx) %s %lu(0x%lx) is false\n", \
1399cf13258fSDavid Howells 		       (unsigned long)_x, (unsigned long)_x, #OP,	\
1400cf13258fSDavid Howells 		       (unsigned long)_y, (unsigned long)_y);		\
140117926a79SDavid Howells 		BUG();							\
140217926a79SDavid Howells 	}								\
140317926a79SDavid Howells } while (0)
140417926a79SDavid Howells 
140517926a79SDavid Howells #else
140617926a79SDavid Howells 
140717926a79SDavid Howells #define ASSERT(X)				\
140817926a79SDavid Howells do {						\
140917926a79SDavid Howells } while (0)
141017926a79SDavid Howells 
141117926a79SDavid Howells #define ASSERTCMP(X, OP, Y)			\
141217926a79SDavid Howells do {						\
141317926a79SDavid Howells } while (0)
141417926a79SDavid Howells 
141517926a79SDavid Howells #define ASSERTIF(C, X)				\
141617926a79SDavid Howells do {						\
141717926a79SDavid Howells } while (0)
141817926a79SDavid Howells 
141917926a79SDavid Howells #define ASSERTIFCMP(C, X, OP, Y)		\
142017926a79SDavid Howells do {						\
142117926a79SDavid Howells } while (0)
142217926a79SDavid Howells 
142317926a79SDavid Howells #endif /* __KDEBUGALL */
1424