xref: /openbmc/linux/net/rxrpc/ar-internal.h (revision d5953f65)
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 #if 0
1917926a79SDavid Howells #define CHECK_SLAB_OKAY(X)				     \
2017926a79SDavid Howells 	BUG_ON(atomic_read((X)) >> (sizeof(atomic_t) - 2) == \
2117926a79SDavid Howells 	       (POISON_FREE << 8 | POISON_FREE))
2217926a79SDavid Howells #else
2317926a79SDavid Howells #define CHECK_SLAB_OKAY(X) do {} while (0)
2417926a79SDavid Howells #endif
2517926a79SDavid Howells 
2617926a79SDavid Howells #define FCRYPT_BSIZE 8
2717926a79SDavid Howells struct rxrpc_crypt {
2817926a79SDavid Howells 	union {
2917926a79SDavid Howells 		u8	x[FCRYPT_BSIZE];
3091e916cfSAl Viro 		__be32	n[2];
3117926a79SDavid Howells 	};
3217926a79SDavid Howells } __attribute__((aligned(8)));
3317926a79SDavid Howells 
34651350d1SDavid Howells #define rxrpc_queue_work(WS)	queue_work(rxrpc_workqueue, (WS))
35651350d1SDavid Howells #define rxrpc_queue_delayed_work(WS,D)	\
36651350d1SDavid Howells 	queue_delayed_work(rxrpc_workqueue, (WS), (D))
37651350d1SDavid Howells 
3812da59fcSDavid Howells struct key_preparsed_payload;
39cc8feb8eSDavid Howells struct rxrpc_connection;
40cc8feb8eSDavid Howells 
4117926a79SDavid Howells /*
42ece64fecSDavid Howells  * Mark applied to socket buffers in skb->mark.  skb->priority is used
43ece64fecSDavid Howells  * to pass supplementary information.
44d001648eSDavid Howells  */
45d001648eSDavid Howells enum rxrpc_skb_mark {
46ece64fecSDavid Howells 	RXRPC_SKB_MARK_REJECT_BUSY,	/* Reject with BUSY */
47ece64fecSDavid Howells 	RXRPC_SKB_MARK_REJECT_ABORT,	/* Reject with ABORT (code in skb->priority) */
48d001648eSDavid Howells };
49d001648eSDavid Howells 
50d001648eSDavid Howells /*
5117926a79SDavid Howells  * sk_state for RxRPC sockets
5217926a79SDavid Howells  */
5317926a79SDavid Howells enum {
542341e077SDavid Howells 	RXRPC_UNBOUND = 0,
552341e077SDavid Howells 	RXRPC_CLIENT_UNBOUND,		/* Unbound socket used as client */
5617926a79SDavid Howells 	RXRPC_CLIENT_BOUND,		/* client local address bound */
5717926a79SDavid Howells 	RXRPC_SERVER_BOUND,		/* server local address bound */
5828036f44SDavid Howells 	RXRPC_SERVER_BOUND2,		/* second server local address bound */
5917926a79SDavid Howells 	RXRPC_SERVER_LISTENING,		/* server listening for connections */
60210f0353SDavid Howells 	RXRPC_SERVER_LISTEN_DISABLED,	/* server listening disabled */
6117926a79SDavid Howells 	RXRPC_CLOSE,			/* socket is being closed */
6217926a79SDavid Howells };
6317926a79SDavid Howells 
6417926a79SDavid Howells /*
652baec2c3SDavid Howells  * Per-network namespace data.
662baec2c3SDavid Howells  */
672baec2c3SDavid Howells struct rxrpc_net {
682baec2c3SDavid Howells 	struct proc_dir_entry	*proc_net;	/* Subdir in /proc/net */
692baec2c3SDavid Howells 	u32			epoch;		/* Local epoch for detecting local-end reset */
702baec2c3SDavid Howells 	struct list_head	calls;		/* List of calls active in this namespace */
712baec2c3SDavid Howells 	rwlock_t		call_lock;	/* Lock for ->calls */
72d3be4d24SDavid Howells 	atomic_t		nr_calls;	/* Count of allocated calls */
732baec2c3SDavid Howells 
7431f5f9a1SDavid Howells 	atomic_t		nr_conns;
752baec2c3SDavid Howells 	struct list_head	conn_proc_list;	/* List of conns in this namespace for proc */
762baec2c3SDavid Howells 	struct list_head	service_conns;	/* Service conns in this namespace */
772baec2c3SDavid Howells 	rwlock_t		conn_lock;	/* Lock for ->conn_proc_list, ->service_conns */
783d18cbb7SDavid Howells 	struct work_struct	service_conn_reaper;
793d18cbb7SDavid Howells 	struct timer_list	service_conn_reap_timer;
802baec2c3SDavid Howells 
81f859ab61SDavid Howells 	bool			live;
82245500d8SDavid Howells 
83245500d8SDavid Howells 	bool			kill_all_client_conns;
84245500d8SDavid Howells 	atomic_t		nr_client_conns;
852baec2c3SDavid Howells 	spinlock_t		client_conn_cache_lock; /* Lock for ->*_client_conns */
862baec2c3SDavid Howells 	spinlock_t		client_conn_discard_lock; /* Prevent multiple discarders */
872baec2c3SDavid Howells 	struct list_head	idle_client_conns;
883d18cbb7SDavid Howells 	struct work_struct	client_conn_reaper;
893d18cbb7SDavid Howells 	struct timer_list	client_conn_reap_timer;
902baec2c3SDavid Howells 
912baec2c3SDavid Howells 	struct list_head	local_endpoints;
922baec2c3SDavid Howells 	struct mutex		local_mutex;	/* Lock for ->local_endpoints */
932baec2c3SDavid Howells 
942baec2c3SDavid Howells 	DECLARE_HASHTABLE	(peer_hash, 10);
95ace45becSDavid Howells 	spinlock_t		peer_hash_lock;	/* Lock for ->peer_hash */
96ace45becSDavid Howells 
97ace45becSDavid Howells #define RXRPC_KEEPALIVE_TIME 20 /* NAT keepalive time in seconds */
98ace45becSDavid Howells 	u8			peer_keepalive_cursor;
99330bdcfaSDavid Howells 	time64_t		peer_keepalive_base;
100330bdcfaSDavid Howells 	struct list_head	peer_keepalive[32];
101330bdcfaSDavid Howells 	struct list_head	peer_keepalive_new;
102ace45becSDavid Howells 	struct timer_list	peer_keepalive_timer;
103ace45becSDavid Howells 	struct work_struct	peer_keepalive_work;
1042baec2c3SDavid Howells };
1052baec2c3SDavid Howells 
1062baec2c3SDavid Howells /*
10700e90712SDavid Howells  * Service backlog preallocation.
10800e90712SDavid Howells  *
10900e90712SDavid Howells  * This contains circular buffers of preallocated peers, connections and calls
11000e90712SDavid Howells  * for incoming service calls and their head and tail pointers.  This allows
11100e90712SDavid Howells  * calls to be set up in the data_ready handler, thereby avoiding the need to
11200e90712SDavid Howells  * shuffle packets around so much.
11300e90712SDavid Howells  */
11400e90712SDavid Howells struct rxrpc_backlog {
11500e90712SDavid Howells 	unsigned short		peer_backlog_head;
11600e90712SDavid Howells 	unsigned short		peer_backlog_tail;
11700e90712SDavid Howells 	unsigned short		conn_backlog_head;
11800e90712SDavid Howells 	unsigned short		conn_backlog_tail;
11900e90712SDavid Howells 	unsigned short		call_backlog_head;
12000e90712SDavid Howells 	unsigned short		call_backlog_tail;
12100e90712SDavid Howells #define RXRPC_BACKLOG_MAX	32
12200e90712SDavid Howells 	struct rxrpc_peer	*peer_backlog[RXRPC_BACKLOG_MAX];
12300e90712SDavid Howells 	struct rxrpc_connection	*conn_backlog[RXRPC_BACKLOG_MAX];
12400e90712SDavid Howells 	struct rxrpc_call	*call_backlog[RXRPC_BACKLOG_MAX];
12500e90712SDavid Howells };
12600e90712SDavid Howells 
12700e90712SDavid Howells /*
12817926a79SDavid Howells  * RxRPC socket definition
12917926a79SDavid Howells  */
13017926a79SDavid Howells struct rxrpc_sock {
13117926a79SDavid Howells 	/* WARNING: sk has to be the first member */
13217926a79SDavid Howells 	struct sock		sk;
133d001648eSDavid Howells 	rxrpc_notify_new_call_t	notify_new_call; /* Func to notify of new call */
13400e90712SDavid Howells 	rxrpc_discard_new_call_t discard_new_call; /* Func to discard a new call */
13517926a79SDavid Howells 	struct rxrpc_local	*local;		/* local endpoint */
13600e90712SDavid Howells 	struct rxrpc_backlog	*backlog;	/* Preallocation for services */
137248f219cSDavid Howells 	spinlock_t		incoming_lock;	/* Incoming call vs service shutdown lock */
138248f219cSDavid Howells 	struct list_head	sock_calls;	/* List of calls owned by this socket */
139248f219cSDavid Howells 	struct list_head	to_be_accepted;	/* calls awaiting acceptance */
140248f219cSDavid Howells 	struct list_head	recvmsg_q;	/* Calls awaiting recvmsg's attention  */
141248f219cSDavid Howells 	rwlock_t		recvmsg_lock;	/* Lock for recvmsg_q */
14217926a79SDavid Howells 	struct key		*key;		/* security for this socket */
14317926a79SDavid Howells 	struct key		*securities;	/* list of server security descriptors */
14400e90712SDavid Howells 	struct rb_root		calls;		/* User ID -> call mapping */
14517926a79SDavid Howells 	unsigned long		flags;
1462341e077SDavid Howells #define RXRPC_SOCK_CONNECTED		0	/* connect_srx is set */
14717926a79SDavid Howells 	rwlock_t		call_lock;	/* lock for calls */
14817926a79SDavid Howells 	u32			min_sec_level;	/* minimum security level */
14917926a79SDavid Howells #define RXRPC_SECURITY_MAX	RXRPC_SECURITY_ENCRYPT
150cc8feb8eSDavid Howells 	bool			exclusive;	/* Exclusive connection for a client socket */
15128036f44SDavid Howells 	u16			second_service;	/* Additional service bound to the endpoint */
1524722974dSDavid Howells 	struct {
1534722974dSDavid Howells 		/* Service upgrade information */
1544722974dSDavid Howells 		u16		from;		/* Service ID to upgrade (if not 0) */
1554722974dSDavid Howells 		u16		to;		/* service ID to upgrade to */
1564722974dSDavid Howells 	} service_upgrade;
157cc8feb8eSDavid Howells 	sa_family_t		family;		/* Protocol family created with */
1584722974dSDavid Howells 	struct sockaddr_rxrpc	srx;		/* Primary Service/local addresses */
1592341e077SDavid Howells 	struct sockaddr_rxrpc	connect_srx;	/* Default client address from connect() */
16017926a79SDavid Howells };
16117926a79SDavid Howells 
16217926a79SDavid Howells #define rxrpc_sk(__sk) container_of((__sk), struct rxrpc_sock, sk)
16317926a79SDavid Howells 
16417926a79SDavid Howells /*
1650d12f8a4SDavid Howells  * CPU-byteorder normalised Rx packet header.
1660d12f8a4SDavid Howells  */
1670d12f8a4SDavid Howells struct rxrpc_host_header {
1680d12f8a4SDavid Howells 	u32		epoch;		/* client boot timestamp */
1690d12f8a4SDavid Howells 	u32		cid;		/* connection and channel ID */
1700d12f8a4SDavid Howells 	u32		callNumber;	/* call ID (0 for connection-level packets) */
1710d12f8a4SDavid Howells 	u32		seq;		/* sequence number of pkt in call stream */
1720d12f8a4SDavid Howells 	u32		serial;		/* serial number of pkt sent to network */
1730d12f8a4SDavid Howells 	u8		type;		/* packet type */
1740d12f8a4SDavid Howells 	u8		flags;		/* packet flags */
1750d12f8a4SDavid Howells 	u8		userStatus;	/* app-layer defined status */
1760d12f8a4SDavid Howells 	u8		securityIndex;	/* security protocol ID */
1770d12f8a4SDavid Howells 	union {
1780d12f8a4SDavid Howells 		u16	_rsvd;		/* reserved */
1790d12f8a4SDavid Howells 		u16	cksum;		/* kerberos security checksum */
1800d12f8a4SDavid Howells 	};
1810d12f8a4SDavid Howells 	u16		serviceId;	/* service ID */
1820d12f8a4SDavid Howells } __packed;
1830d12f8a4SDavid Howells 
1840d12f8a4SDavid Howells /*
18517926a79SDavid Howells  * RxRPC socket buffer private variables
18617926a79SDavid Howells  * - max 48 bytes (struct sk_buff::cb)
18717926a79SDavid Howells  */
18817926a79SDavid Howells struct rxrpc_skb_priv {
189987db9f7SDavid Howells 	atomic_t	nr_ring_pins;		/* Number of rxtx ring pins */
190c3c9e3dfSDavid Howells 	u8		nr_subpackets;		/* Number of subpackets */
191c3c9e3dfSDavid Howells 	u8		rx_flags;		/* Received packet flags */
192c3c9e3dfSDavid Howells #define RXRPC_SKB_INCL_LAST	0x01		/* - Includes last packet */
193b311e684SDavid Howells #define RXRPC_SKB_TX_BUFFER	0x02		/* - Is transmit buffer */
19417926a79SDavid Howells 	union {
19517926a79SDavid Howells 		int		remain;		/* amount of space remaining for next write */
196c3c9e3dfSDavid Howells 
197c3c9e3dfSDavid Howells 		/* List of requested ACKs on subpackets */
198c3c9e3dfSDavid Howells 		unsigned long	rx_req_ack[(RXRPC_MAX_NR_JUMBO + BITS_PER_LONG - 1) /
199c3c9e3dfSDavid Howells 					   BITS_PER_LONG];
20017926a79SDavid Howells 	};
20117926a79SDavid Howells 
2020d12f8a4SDavid Howells 	struct rxrpc_host_header hdr;		/* RxRPC packet header from this packet */
20317926a79SDavid Howells };
20417926a79SDavid Howells 
20517926a79SDavid Howells #define rxrpc_skb(__skb) ((struct rxrpc_skb_priv *) &(__skb)->cb)
20617926a79SDavid Howells 
20717926a79SDavid Howells /*
20817926a79SDavid Howells  * RxRPC security module interface
20917926a79SDavid Howells  */
21017926a79SDavid Howells struct rxrpc_security {
21117926a79SDavid Howells 	const char		*name;		/* name of this service */
21217926a79SDavid Howells 	u8			security_index;	/* security type provided */
213063c60d3SDavid Howells 	u32			no_key_abort;	/* Abort code indicating no key */
21417926a79SDavid Howells 
215648af7fcSDavid Howells 	/* Initialise a security service */
216648af7fcSDavid Howells 	int (*init)(void);
217648af7fcSDavid Howells 
218648af7fcSDavid Howells 	/* Clean up a security service */
219648af7fcSDavid Howells 	void (*exit)(void);
220648af7fcSDavid Howells 
22112da59fcSDavid Howells 	/* Parse the information from a server key */
22212da59fcSDavid Howells 	int (*preparse_server_key)(struct key_preparsed_payload *);
22312da59fcSDavid Howells 
22412da59fcSDavid Howells 	/* Clean up the preparse buffer after parsing a server key */
22512da59fcSDavid Howells 	void (*free_preparse_server_key)(struct key_preparsed_payload *);
22612da59fcSDavid Howells 
22712da59fcSDavid Howells 	/* Destroy the payload of a server key */
22812da59fcSDavid Howells 	void (*destroy_server_key)(struct key *);
22912da59fcSDavid Howells 
230*d5953f65SDavid Howells 	/* Describe a server key */
231*d5953f65SDavid Howells 	void (*describe_server_key)(const struct key *, struct seq_file *);
232*d5953f65SDavid Howells 
23317926a79SDavid Howells 	/* initialise a connection's security */
23441057ebdSDavid Howells 	int (*init_connection_security)(struct rxrpc_connection *,
23541057ebdSDavid Howells 					struct rxrpc_key_token *);
23617926a79SDavid Howells 
23717926a79SDavid Howells 	/* prime a connection's packet security */
238a263629dSHerbert Xu 	int (*prime_packet_security)(struct rxrpc_connection *);
23917926a79SDavid Howells 
24017926a79SDavid Howells 	/* impose security on a packet */
241a263629dSHerbert Xu 	int (*secure_packet)(struct rxrpc_call *,
24217926a79SDavid Howells 			     struct sk_buff *,
24317926a79SDavid Howells 			     size_t,
24417926a79SDavid Howells 			     void *);
24517926a79SDavid Howells 
24617926a79SDavid Howells 	/* verify the security on a received packet */
2475a42976dSDavid Howells 	int (*verify_packet)(struct rxrpc_call *, struct sk_buff *,
248248f219cSDavid Howells 			     unsigned int, unsigned int, rxrpc_seq_t, u16);
249248f219cSDavid Howells 
2501db88c53SDavid Howells 	/* Free crypto request on a call */
2511db88c53SDavid Howells 	void (*free_call_crypto)(struct rxrpc_call *);
2521db88c53SDavid Howells 
253248f219cSDavid Howells 	/* Locate the data in a received packet that has been verified. */
254248f219cSDavid Howells 	void (*locate_data)(struct rxrpc_call *, struct sk_buff *,
255248f219cSDavid Howells 			    unsigned int *, unsigned int *);
25617926a79SDavid Howells 
25717926a79SDavid Howells 	/* issue a challenge */
25817926a79SDavid Howells 	int (*issue_challenge)(struct rxrpc_connection *);
25917926a79SDavid Howells 
26017926a79SDavid Howells 	/* respond to a challenge */
26117926a79SDavid Howells 	int (*respond_to_challenge)(struct rxrpc_connection *,
26217926a79SDavid Howells 				    struct sk_buff *,
26317926a79SDavid Howells 				    u32 *);
26417926a79SDavid Howells 
26517926a79SDavid Howells 	/* verify a response */
26617926a79SDavid Howells 	int (*verify_response)(struct rxrpc_connection *,
26717926a79SDavid Howells 			       struct sk_buff *,
26817926a79SDavid Howells 			       u32 *);
26917926a79SDavid Howells 
27017926a79SDavid Howells 	/* clear connection security */
27117926a79SDavid Howells 	void (*clear)(struct rxrpc_connection *);
27217926a79SDavid Howells };
27317926a79SDavid Howells 
27417926a79SDavid Howells /*
2754f95dd78SDavid Howells  * RxRPC local transport endpoint description
2764f95dd78SDavid Howells  * - owned by a single AF_RXRPC socket
2774f95dd78SDavid Howells  * - pointed to by transport socket struct sk_user_data
27817926a79SDavid Howells  */
27917926a79SDavid Howells struct rxrpc_local {
2804f95dd78SDavid Howells 	struct rcu_head		rcu;
281730c5fd4SDavid Howells 	atomic_t		active_users;	/* Number of users of the local endpoint */
282730c5fd4SDavid Howells 	atomic_t		usage;		/* Number of references to the structure */
2832baec2c3SDavid Howells 	struct rxrpc_net	*rxnet;		/* The network ns in which this resides */
2844f95dd78SDavid Howells 	struct list_head	link;
28517926a79SDavid Howells 	struct socket		*socket;	/* my UDP socket */
2864f95dd78SDavid Howells 	struct work_struct	processor;
2871e9e5c95SDavid Howells 	struct rxrpc_sock __rcu	*service;	/* Service(s) listening on this endpoint */
28817926a79SDavid Howells 	struct rw_semaphore	defrag_sem;	/* control re-enablement of IP DF bit */
28917926a79SDavid Howells 	struct sk_buff_head	reject_queue;	/* packets awaiting rejection */
29044ba0698SDavid Howells 	struct sk_buff_head	event_queue;	/* endpoint event packets awaiting processing */
291245500d8SDavid Howells 	struct rb_root		client_bundles;	/* Client connection bundles by socket params */
292245500d8SDavid Howells 	spinlock_t		client_bundles_lock; /* Lock for client_bundles */
29317926a79SDavid Howells 	spinlock_t		lock;		/* access lock */
29417926a79SDavid Howells 	rwlock_t		services_lock;	/* lock for services list */
29517926a79SDavid Howells 	int			debug_id;	/* debug ID for printks */
2964f95dd78SDavid Howells 	bool			dead;
297f859ab61SDavid Howells 	bool			service_closed;	/* Service socket closed */
29817926a79SDavid Howells 	struct sockaddr_rxrpc	srx;		/* local address */
29917926a79SDavid Howells };
30017926a79SDavid Howells 
30117926a79SDavid Howells /*
30217926a79SDavid Howells  * RxRPC remote transport endpoint definition
303be6e6707SDavid Howells  * - matched by local endpoint, remote port, address and protocol type
30417926a79SDavid Howells  */
30517926a79SDavid Howells struct rxrpc_peer {
306be6e6707SDavid Howells 	struct rcu_head		rcu;		/* This must be first */
307be6e6707SDavid Howells 	atomic_t		usage;
308be6e6707SDavid Howells 	unsigned long		hash_key;
309be6e6707SDavid Howells 	struct hlist_node	hash_link;
310be6e6707SDavid Howells 	struct rxrpc_local	*local;
311f66d7490SDavid Howells 	struct hlist_head	error_targets;	/* targets for net error distribution */
312aa390bbeSDavid Howells 	struct rb_root		service_conns;	/* Service connections */
313330bdcfaSDavid Howells 	struct list_head	keepalive_link;	/* Link in net->peer_keepalive[] */
314ace45becSDavid Howells 	time64_t		last_tx_at;	/* Last time packet sent here */
3158496af50SDavid Howells 	seqlock_t		service_conn_lock;
31617926a79SDavid Howells 	spinlock_t		lock;		/* access lock */
31795c96174SEric Dumazet 	unsigned int		if_mtu;		/* interface MTU for this peer */
31895c96174SEric Dumazet 	unsigned int		mtu;		/* network MTU for this peer */
31995c96174SEric Dumazet 	unsigned int		maxdata;	/* data size (MTU - hdrsize) */
32017926a79SDavid Howells 	unsigned short		hdrsize;	/* header size (IP + UDP + RxRPC) */
32117926a79SDavid Howells 	int			debug_id;	/* debug ID for printks */
32217926a79SDavid Howells 	struct sockaddr_rxrpc	srx;		/* remote address */
32317926a79SDavid Howells 
32417926a79SDavid Howells 	/* calculated RTT cache */
32517926a79SDavid Howells #define RXRPC_RTT_CACHE_SIZE 32
326c1e15b49SDavid Howells 	spinlock_t		rtt_input_lock;	/* RTT lock for input routine */
3270d4b103cSDavid Howells 	ktime_t			rtt_last_req;	/* Time of last RTT request */
328c410bf01SDavid Howells 	unsigned int		rtt_count;	/* Number of samples we've got */
329c410bf01SDavid Howells 
330c410bf01SDavid Howells 	u32			srtt_us;	/* smoothed round trip time << 3 in usecs */
331c410bf01SDavid Howells 	u32			mdev_us;	/* medium deviation			*/
332c410bf01SDavid Howells 	u32			mdev_max_us;	/* maximal mdev for the last rtt period	*/
333c410bf01SDavid Howells 	u32			rttvar_us;	/* smoothed mdev_max			*/
334c410bf01SDavid Howells 	u32			rto_j;		/* Retransmission timeout in jiffies */
335c410bf01SDavid Howells 	u8			backoff;	/* Backoff timeout */
336f7aec129SDavid Howells 
337f7aec129SDavid Howells 	u8			cong_cwnd;	/* Congestion window size */
33817926a79SDavid Howells };
33917926a79SDavid Howells 
34017926a79SDavid Howells /*
34119ffa01cSDavid Howells  * Keys for matching a connection.
34219ffa01cSDavid Howells  */
34319ffa01cSDavid Howells struct rxrpc_conn_proto {
344e8d70ce1SDavid Howells 	union {
345e8d70ce1SDavid Howells 		struct {
34619ffa01cSDavid Howells 			u32	epoch;		/* epoch of this connection */
34719ffa01cSDavid Howells 			u32	cid;		/* connection ID */
348e8d70ce1SDavid Howells 		};
349e8d70ce1SDavid Howells 		u64		index_key;
35019ffa01cSDavid Howells 	};
35119ffa01cSDavid Howells };
35219ffa01cSDavid Howells 
35319ffa01cSDavid Howells struct rxrpc_conn_parameters {
35419ffa01cSDavid Howells 	struct rxrpc_local	*local;		/* Representation of local endpoint */
35519ffa01cSDavid Howells 	struct rxrpc_peer	*peer;		/* Remote endpoint */
35619ffa01cSDavid Howells 	struct key		*key;		/* Security details */
35719ffa01cSDavid Howells 	bool			exclusive;	/* T if conn is exclusive */
3584e255721SDavid Howells 	bool			upgrade;	/* T if service ID can be upgraded */
35919ffa01cSDavid Howells 	u16			service_id;	/* Service ID for this connection */
36019ffa01cSDavid Howells 	u32			security_level;	/* Security level selected */
36119ffa01cSDavid Howells };
36219ffa01cSDavid Howells 
36319ffa01cSDavid Howells /*
364bba304dbSDavid Howells  * Bits in the connection flags.
365bba304dbSDavid Howells  */
366bba304dbSDavid Howells enum rxrpc_conn_flag {
367bba304dbSDavid Howells 	RXRPC_CONN_HAS_IDR,		/* Has a client conn ID assigned */
368001c1122SDavid Howells 	RXRPC_CONN_IN_SERVICE_CONNS,	/* Conn is in peer->service_conns */
36945025bceSDavid Howells 	RXRPC_CONN_DONT_REUSE,		/* Don't reuse this connection */
3704e255721SDavid Howells 	RXRPC_CONN_PROBING_FOR_UPGRADE,	/* Probing for service upgrade */
3713136ef49SDavid Howells 	RXRPC_CONN_FINAL_ACK_0,		/* Need final ACK for channel 0 */
3723136ef49SDavid Howells 	RXRPC_CONN_FINAL_ACK_1,		/* Need final ACK for channel 1 */
3733136ef49SDavid Howells 	RXRPC_CONN_FINAL_ACK_2,		/* Need final ACK for channel 2 */
3743136ef49SDavid Howells 	RXRPC_CONN_FINAL_ACK_3,		/* Need final ACK for channel 3 */
375bba304dbSDavid Howells };
376bba304dbSDavid Howells 
3773136ef49SDavid Howells #define RXRPC_CONN_FINAL_ACK_MASK ((1UL << RXRPC_CONN_FINAL_ACK_0) |	\
3783136ef49SDavid Howells 				   (1UL << RXRPC_CONN_FINAL_ACK_1) |	\
3793136ef49SDavid Howells 				   (1UL << RXRPC_CONN_FINAL_ACK_2) |	\
3803136ef49SDavid Howells 				   (1UL << RXRPC_CONN_FINAL_ACK_3))
3813136ef49SDavid Howells 
382bba304dbSDavid Howells /*
383bba304dbSDavid Howells  * Events that can be raised upon a connection.
384bba304dbSDavid Howells  */
385bba304dbSDavid Howells enum rxrpc_conn_event {
386bba304dbSDavid Howells 	RXRPC_CONN_EV_CHALLENGE,	/* Send challenge packet */
387bba304dbSDavid Howells };
388bba304dbSDavid Howells 
389bba304dbSDavid Howells /*
390bba304dbSDavid Howells  * The connection protocol state.
391bba304dbSDavid Howells  */
392bba304dbSDavid Howells enum rxrpc_conn_proto_state {
393bba304dbSDavid Howells 	RXRPC_CONN_UNUSED,		/* Connection not yet attempted */
394bba304dbSDavid Howells 	RXRPC_CONN_CLIENT,		/* Client connection */
39500e90712SDavid Howells 	RXRPC_CONN_SERVICE_PREALLOC,	/* Service connection preallocation */
396bba304dbSDavid Howells 	RXRPC_CONN_SERVICE_UNSECURED,	/* Service unsecured connection */
397bba304dbSDavid Howells 	RXRPC_CONN_SERVICE_CHALLENGING,	/* Service challenging for security */
398bba304dbSDavid Howells 	RXRPC_CONN_SERVICE,		/* Service secured connection */
399bba304dbSDavid Howells 	RXRPC_CONN_REMOTELY_ABORTED,	/* Conn aborted by peer */
400bba304dbSDavid Howells 	RXRPC_CONN_LOCALLY_ABORTED,	/* Conn aborted locally */
401bba304dbSDavid Howells 	RXRPC_CONN__NR_STATES
402bba304dbSDavid Howells };
403bba304dbSDavid Howells 
404bba304dbSDavid Howells /*
405245500d8SDavid Howells  * RxRPC client connection bundle.
406245500d8SDavid Howells  */
407245500d8SDavid Howells struct rxrpc_bundle {
408245500d8SDavid Howells 	struct rxrpc_conn_parameters params;
409245500d8SDavid Howells 	atomic_t		usage;
410245500d8SDavid Howells 	unsigned int		debug_id;
411245500d8SDavid Howells 	bool			try_upgrade;	/* True if the bundle is attempting upgrade */
412245500d8SDavid Howells 	bool			alloc_conn;	/* True if someone's getting a conn */
4138806245aSDavid Howells 	short			alloc_error;	/* Error from last conn allocation */
414245500d8SDavid Howells 	spinlock_t		channel_lock;
415245500d8SDavid Howells 	struct rb_node		local_node;	/* Node in local->client_conns */
416245500d8SDavid Howells 	struct list_head	waiting_calls;	/* Calls waiting for channels */
417245500d8SDavid Howells 	unsigned long		avail_chans;	/* Mask of available channels */
418245500d8SDavid Howells 	struct rxrpc_connection	*conns[4];	/* The connections in the bundle (max 4) */
419245500d8SDavid Howells };
420245500d8SDavid Howells 
421245500d8SDavid Howells /*
42217926a79SDavid Howells  * RxRPC connection definition
423aa390bbeSDavid Howells  * - matched by { local, peer, epoch, conn_id, direction }
42417926a79SDavid Howells  * - each connection can only handle four simultaneous calls
42517926a79SDavid Howells  */
42617926a79SDavid Howells struct rxrpc_connection {
42719ffa01cSDavid Howells 	struct rxrpc_conn_proto	proto;
42819ffa01cSDavid Howells 	struct rxrpc_conn_parameters params;
42919ffa01cSDavid Howells 
43045025bceSDavid Howells 	atomic_t		usage;
43145025bceSDavid Howells 	struct rcu_head		rcu;
43245025bceSDavid Howells 	struct list_head	cache_link;
433a1399f8bSDavid Howells 
434245500d8SDavid Howells 	unsigned char		act_chans;	/* Mask of active channels */
435a1399f8bSDavid Howells 	struct rxrpc_channel {
4363136ef49SDavid Howells 		unsigned long		final_ack_at;	/* Time at which to issue final ACK */
437a1399f8bSDavid Howells 		struct rxrpc_call __rcu	*call;		/* Active call */
4384764c0daSDavid Howells 		unsigned int		call_debug_id;	/* call->debug_id */
439a1399f8bSDavid Howells 		u32			call_id;	/* ID of current call */
440a1399f8bSDavid Howells 		u32			call_counter;	/* Call ID counter */
441a1399f8bSDavid Howells 		u32			last_call;	/* ID of last call */
44218bfeba5SDavid Howells 		u8			last_type;	/* Type of last packet */
44318bfeba5SDavid Howells 		union {
44418bfeba5SDavid Howells 			u32		last_seq;
44518bfeba5SDavid Howells 			u32		last_abort;
44618bfeba5SDavid Howells 		};
447a1399f8bSDavid Howells 	} channels[RXRPC_MAXCALLS];
448999b69f8SDavid Howells 
4493136ef49SDavid Howells 	struct timer_list	timer;		/* Conn event timer */
45017926a79SDavid Howells 	struct work_struct	processor;	/* connection event processor */
451245500d8SDavid Howells 	struct rxrpc_bundle	*bundle;	/* Client connection bundle */
452aa390bbeSDavid Howells 	struct rb_node		service_node;	/* Node in peer->service_conns */
4534d028b2cSDavid Howells 	struct list_head	proc_link;	/* link in procfs list */
45417926a79SDavid Howells 	struct list_head	link;		/* link in master connection list */
45517926a79SDavid Howells 	struct sk_buff_head	rx_queue;	/* received conn-level packets */
456648af7fcSDavid Howells 	const struct rxrpc_security *security;	/* applied security module */
45769d826faSKees Cook 	struct crypto_sync_skcipher *cipher;	/* encryption handle */
45817926a79SDavid Howells 	struct rxrpc_crypt	csum_iv;	/* packet checksum base */
4594a3388c8SDavid Howells 	unsigned long		flags;
46017926a79SDavid Howells 	unsigned long		events;
461f51b4480SDavid Howells 	unsigned long		idle_timestamp;	/* Time at which last became idle */
46217926a79SDavid Howells 	spinlock_t		state_lock;	/* state-change lock */
463cf13258fSDavid Howells 	enum rxrpc_conn_proto_state state;	/* current state of connection */
46464753092SDavid Howells 	u32			abort_code;	/* Abort code of connection abort */
46517926a79SDavid Howells 	int			debug_id;	/* debug ID for printks */
46617926a79SDavid Howells 	atomic_t		serial;		/* packet serial number counter */
467563ea7d5SDavid Howells 	unsigned int		hi_serial;	/* highest serial number received */
46817926a79SDavid Howells 	u32			security_nonce;	/* response re-use preventer */
469c1e15b49SDavid Howells 	u32			service_id;	/* Service ID, possibly upgraded */
4705a924b89SDavid Howells 	u8			size_align;	/* data size alignment (for security) */
4715a924b89SDavid Howells 	u8			security_size;	/* security header size */
47217926a79SDavid Howells 	u8			security_ix;	/* security type */
47317926a79SDavid Howells 	u8			out_clientflag;	/* RXRPC_CLIENT_INITIATED if we are client */
474245500d8SDavid Howells 	u8			bundle_shift;	/* Index into bundle->avail_chans */
47564753092SDavid Howells 	short			error;		/* Local error code */
47617926a79SDavid Howells };
47717926a79SDavid Howells 
478dc71db34SDavid Howells static inline bool rxrpc_to_server(const struct rxrpc_skb_priv *sp)
479dc71db34SDavid Howells {
480dc71db34SDavid Howells 	return sp->hdr.flags & RXRPC_CLIENT_INITIATED;
481dc71db34SDavid Howells }
482dc71db34SDavid Howells 
483dc71db34SDavid Howells static inline bool rxrpc_to_client(const struct rxrpc_skb_priv *sp)
484dc71db34SDavid Howells {
485dc71db34SDavid Howells 	return !rxrpc_to_server(sp);
486dc71db34SDavid Howells }
487dc71db34SDavid Howells 
48817926a79SDavid Howells /*
4895b8848d1SDavid Howells  * Flags in call->flags.
4905b8848d1SDavid Howells  */
4915b8848d1SDavid Howells enum rxrpc_call_flag {
4925b8848d1SDavid Howells 	RXRPC_CALL_RELEASED,		/* call has been released - no more message to userspace */
4935b8848d1SDavid Howells 	RXRPC_CALL_HAS_USERID,		/* has a user ID attached */
494dabe5a79SDavid Howells 	RXRPC_CALL_IS_SERVICE,		/* Call is service call */
49545025bceSDavid Howells 	RXRPC_CALL_EXPOSED,		/* The call was exposed to the world */
496248f219cSDavid Howells 	RXRPC_CALL_RX_LAST,		/* Received the last packet (at rxtx_top) */
497248f219cSDavid Howells 	RXRPC_CALL_TX_LAST,		/* Last packet in Tx buffer (at rxtx_top) */
498a5af7e1fSDavid Howells 	RXRPC_CALL_SEND_PING,		/* A ping will need to be sent */
49957494343SDavid Howells 	RXRPC_CALL_RETRANS_TIMEOUT,	/* Retransmission due to timeout occurred */
500c54e43d7SDavid Howells 	RXRPC_CALL_BEGAN_RX_TIMER,	/* We began the expect_rx_by timer */
5011a025028SDavid Howells 	RXRPC_CALL_RX_HEARD,		/* The peer responded at least once to this call */
502d0b35a42SDavid Howells 	RXRPC_CALL_RX_UNDERRUN,		/* Got data underrun */
5035273a191SDavid Howells 	RXRPC_CALL_DISCONNECTED,	/* The call has been disconnected */
504b7a7d674SDavid Howells 	RXRPC_CALL_KERNEL,		/* The call was made by the kernel */
505245500d8SDavid Howells 	RXRPC_CALL_UPGRADE,		/* Service upgrade was requested for the call */
5065b8848d1SDavid Howells };
5075b8848d1SDavid Howells 
5085b8848d1SDavid Howells /*
5095b8848d1SDavid Howells  * Events that can be raised on a call.
5105b8848d1SDavid Howells  */
5115b8848d1SDavid Howells enum rxrpc_call_event {
5124c198ad1SDavid Howells 	RXRPC_CALL_EV_ACK,		/* need to generate ACK */
5134c198ad1SDavid Howells 	RXRPC_CALL_EV_ABORT,		/* need to generate abort */
5144c198ad1SDavid Howells 	RXRPC_CALL_EV_RESEND,		/* Tx resend required */
515a5af7e1fSDavid Howells 	RXRPC_CALL_EV_PING,		/* Ping send required */
516a158bdd3SDavid Howells 	RXRPC_CALL_EV_EXPIRED,		/* Expiry occurred */
517bd1fdf8cSDavid Howells 	RXRPC_CALL_EV_ACK_LOST,		/* ACK may be lost, send ping */
5185b8848d1SDavid Howells };
5195b8848d1SDavid Howells 
5205b8848d1SDavid Howells /*
5215b8848d1SDavid Howells  * The states that a call can be in.
5225b8848d1SDavid Howells  */
5235b8848d1SDavid Howells enum rxrpc_call_state {
524999b69f8SDavid Howells 	RXRPC_CALL_UNINITIALISED,
525999b69f8SDavid Howells 	RXRPC_CALL_CLIENT_AWAIT_CONN,	/* - client waiting for connection to become available */
5265b8848d1SDavid Howells 	RXRPC_CALL_CLIENT_SEND_REQUEST,	/* - client sending request phase */
5275b8848d1SDavid Howells 	RXRPC_CALL_CLIENT_AWAIT_REPLY,	/* - client awaiting reply */
5285b8848d1SDavid Howells 	RXRPC_CALL_CLIENT_RECV_REPLY,	/* - client receiving reply phase */
52900e90712SDavid Howells 	RXRPC_CALL_SERVER_PREALLOC,	/* - service preallocation */
5305b8848d1SDavid Howells 	RXRPC_CALL_SERVER_SECURING,	/* - server securing request connection */
5315b8848d1SDavid Howells 	RXRPC_CALL_SERVER_RECV_REQUEST,	/* - server receiving request */
5325b8848d1SDavid Howells 	RXRPC_CALL_SERVER_ACK_REQUEST,	/* - server pending ACK of request */
5335b8848d1SDavid Howells 	RXRPC_CALL_SERVER_SEND_REPLY,	/* - server sending reply */
5345b8848d1SDavid Howells 	RXRPC_CALL_SERVER_AWAIT_ACK,	/* - server awaiting final ACK */
535f5c17aaeSDavid Howells 	RXRPC_CALL_COMPLETE,		/* - call complete */
536f5c17aaeSDavid Howells 	NR__RXRPC_CALL_STATES
537f5c17aaeSDavid Howells };
538f5c17aaeSDavid Howells 
539f5c17aaeSDavid Howells /*
540e122d845SDavid Howells  * Call completion condition (state == RXRPC_CALL_COMPLETE).
541e122d845SDavid Howells  */
542e122d845SDavid Howells enum rxrpc_call_completion {
543e122d845SDavid Howells 	RXRPC_CALL_SUCCEEDED,		/* - Normal termination */
544e122d845SDavid Howells 	RXRPC_CALL_REMOTELY_ABORTED,	/* - call aborted by peer */
545e122d845SDavid Howells 	RXRPC_CALL_LOCALLY_ABORTED,	/* - call aborted locally on error or close */
546e122d845SDavid Howells 	RXRPC_CALL_LOCAL_ERROR,		/* - call failed due to local error */
547e122d845SDavid Howells 	RXRPC_CALL_NETWORK_ERROR,	/* - call terminated by network error */
548e122d845SDavid Howells 	NR__RXRPC_CALL_COMPLETIONS
549e122d845SDavid Howells };
550e122d845SDavid Howells 
551e122d845SDavid Howells /*
55257494343SDavid Howells  * Call Tx congestion management modes.
55357494343SDavid Howells  */
55457494343SDavid Howells enum rxrpc_congest_mode {
55557494343SDavid Howells 	RXRPC_CALL_SLOW_START,
55657494343SDavid Howells 	RXRPC_CALL_CONGEST_AVOIDANCE,
55757494343SDavid Howells 	RXRPC_CALL_PACKET_LOSS,
55857494343SDavid Howells 	RXRPC_CALL_FAST_RETRANSMIT,
55957494343SDavid Howells 	NR__RXRPC_CONGEST_MODES
56057494343SDavid Howells };
56157494343SDavid Howells 
56257494343SDavid Howells /*
56317926a79SDavid Howells  * RxRPC call definition
56417926a79SDavid Howells  * - matched by { connection, call_id }
56517926a79SDavid Howells  */
56617926a79SDavid Howells struct rxrpc_call {
567dee46364SDavid Howells 	struct rcu_head		rcu;
56817926a79SDavid Howells 	struct rxrpc_connection	*conn;		/* connection carrying call */
569df5d8bf7SDavid Howells 	struct rxrpc_peer	*peer;		/* Peer record for remote address */
5708d94aa38SDavid Howells 	struct rxrpc_sock __rcu	*socket;	/* socket responsible */
571d3be4d24SDavid Howells 	struct rxrpc_net	*rxnet;		/* Network namespace to which call belongs */
57291fcfbe8SDavid Howells 	const struct rxrpc_security *security;	/* applied security module */
573540b1c48SDavid Howells 	struct mutex		user_mutex;	/* User access mutex */
574a158bdd3SDavid Howells 	unsigned long		ack_at;		/* When deferred ACK needs to happen */
575bd1fdf8cSDavid Howells 	unsigned long		ack_lost_at;	/* When ACK is figured as lost */
576a158bdd3SDavid Howells 	unsigned long		resend_at;	/* When next resend needs to happen */
577a158bdd3SDavid Howells 	unsigned long		ping_at;	/* When next to send a ping */
578415f44e4SDavid Howells 	unsigned long		keepalive_at;	/* When next to send a keepalive ping */
579a158bdd3SDavid Howells 	unsigned long		expect_rx_by;	/* When we expect to get a packet by */
580a158bdd3SDavid Howells 	unsigned long		expect_req_by;	/* When we expect to get a request DATA packet by */
581a158bdd3SDavid Howells 	unsigned long		expect_term_by;	/* When we expect call termination by */
582a158bdd3SDavid Howells 	u32			next_rx_timo;	/* Timeout for next Rx packet (jif) */
583a158bdd3SDavid Howells 	u32			next_req_timo;	/* Timeout for next Rx request packet (jif) */
5841db88c53SDavid Howells 	struct skcipher_request	*cipher_req;	/* Packet cipher request buffer */
585248f219cSDavid Howells 	struct timer_list	timer;		/* Combined event timer */
586248f219cSDavid Howells 	struct work_struct	processor;	/* Event processor */
587d001648eSDavid Howells 	rxrpc_notify_rx_t	notify_rx;	/* kernel service Rx notification function */
58817926a79SDavid Howells 	struct list_head	link;		/* link in master call list */
589245500d8SDavid Howells 	struct list_head	chan_wait_link;	/* Link in conn->bundle->waiting_calls */
590f66d7490SDavid Howells 	struct hlist_node	error_link;	/* link in error distribution list */
591248f219cSDavid Howells 	struct list_head	accept_link;	/* Link in rx->acceptq */
592248f219cSDavid Howells 	struct list_head	recvmsg_link;	/* Link in rx->recvmsg_q */
593248f219cSDavid Howells 	struct list_head	sock_link;	/* Link in rx->sock_calls */
594248f219cSDavid Howells 	struct rb_node		sock_node;	/* Node in rx->calls */
59517926a79SDavid Howells 	struct sk_buff		*tx_pending;	/* Tx socket buffer being filled */
59645025bceSDavid Howells 	wait_queue_head_t	waitq;		/* Wait queue for channel or Tx */
597e754eba6SDavid Howells 	s64			tx_total_len;	/* Total length left to be transmitted (or -1) */
598a263629dSHerbert Xu 	__be32			crypto_buf[2];	/* Temporary packet crypto buffer */
59917926a79SDavid Howells 	unsigned long		user_call_ID;	/* user-defined call ID */
60017926a79SDavid Howells 	unsigned long		flags;
60117926a79SDavid Howells 	unsigned long		events;
60217926a79SDavid Howells 	spinlock_t		lock;
60320acbd9aSDavid Howells 	spinlock_t		notify_lock;	/* Kernel notification lock */
60417926a79SDavid Howells 	rwlock_t		state_lock;	/* lock for state transition */
605f5c17aaeSDavid Howells 	u32			abort_code;	/* Local/remote abort code */
606f5c17aaeSDavid Howells 	int			error;		/* Local error incurred */
607cf13258fSDavid Howells 	enum rxrpc_call_state	state;		/* current state of call */
608cf13258fSDavid Howells 	enum rxrpc_call_completion completion;	/* Call completion condition */
60917926a79SDavid Howells 	atomic_t		usage;
610dabe5a79SDavid Howells 	u16			service_id;	/* service ID */
611278ac0cdSDavid Howells 	u8			security_ix;	/* Security type */
612e138aa7dSDavid Howells 	enum rxrpc_interruptibility interruptibility; /* At what point call may be interrupted */
613dabe5a79SDavid Howells 	u32			call_id;	/* call ID on connection  */
614dabe5a79SDavid Howells 	u32			cid;		/* connection ID plus channel index */
615dabe5a79SDavid Howells 	int			debug_id;	/* debug ID for printks */
6168e83134dSDavid Howells 	unsigned short		rx_pkt_offset;	/* Current recvmsg packet offset */
6178e83134dSDavid Howells 	unsigned short		rx_pkt_len;	/* Current recvmsg packet len */
618f9c32435SDavid Howells 	bool			rx_pkt_last;	/* Current recvmsg packet is last */
61917926a79SDavid Howells 
620248f219cSDavid Howells 	/* Rx/Tx circular buffer, depending on phase.
621248f219cSDavid Howells 	 *
622248f219cSDavid Howells 	 * In the Rx phase, packets are annotated with 0 or the number of the
623248f219cSDavid Howells 	 * segment of a jumbo packet each buffer refers to.  There can be up to
624248f219cSDavid Howells 	 * 47 segments in a maximum-size UDP packet.
625248f219cSDavid Howells 	 *
626248f219cSDavid Howells 	 * In the Tx phase, packets are annotated with which buffers have been
627248f219cSDavid Howells 	 * acked.
62817926a79SDavid Howells 	 */
629248f219cSDavid Howells #define RXRPC_RXTX_BUFF_SIZE	64
630248f219cSDavid Howells #define RXRPC_RXTX_BUFF_MASK	(RXRPC_RXTX_BUFF_SIZE - 1)
6314075295aSDavid Howells #define RXRPC_INIT_RX_WINDOW_SIZE 63
632248f219cSDavid Howells 	struct sk_buff		**rxtx_buffer;
633248f219cSDavid Howells 	u8			*rxtx_annotations;
634248f219cSDavid Howells #define RXRPC_TX_ANNO_ACK	0
635248f219cSDavid Howells #define RXRPC_TX_ANNO_UNACK	1
636248f219cSDavid Howells #define RXRPC_TX_ANNO_NAK	2
637248f219cSDavid Howells #define RXRPC_TX_ANNO_RETRANS	3
638f07373eaSDavid Howells #define RXRPC_TX_ANNO_MASK	0x03
63970790dbeSDavid Howells #define RXRPC_TX_ANNO_LAST	0x04
64070790dbeSDavid Howells #define RXRPC_TX_ANNO_RESENT	0x08
64170790dbeSDavid Howells 
642e2de6c40SDavid Howells #define RXRPC_RX_ANNO_SUBPACKET	0x3f		/* Subpacket number in jumbogram */
643248f219cSDavid Howells #define RXRPC_RX_ANNO_VERIFIED	0x80		/* Set if verified and decrypted */
644248f219cSDavid Howells 	rxrpc_seq_t		tx_hard_ack;	/* Dead slot in buffer; the first transmitted but
645248f219cSDavid Howells 						 * not hard-ACK'd packet follows this.
646248f219cSDavid Howells 						 */
647248f219cSDavid Howells 	rxrpc_seq_t		tx_top;		/* Highest Tx slot allocated. */
648c7e86acfSDavid Howells 	u16			tx_backoff;	/* Delay to insert due to Tx failure */
64957494343SDavid Howells 
65057494343SDavid Howells 	/* TCP-style slow-start congestion control [RFC5681].  Since the SMSS
65157494343SDavid Howells 	 * is fixed, we keep these numbers in terms of segments (ie. DATA
65257494343SDavid Howells 	 * packets) rather than bytes.
65357494343SDavid Howells 	 */
65457494343SDavid Howells #define RXRPC_TX_SMSS		RXRPC_JUMBO_DATALEN
65557494343SDavid Howells 	u8			cong_cwnd;	/* Congestion window size */
65657494343SDavid Howells 	u8			cong_extra;	/* Extra to send for congestion management */
65757494343SDavid Howells 	u8			cong_ssthresh;	/* Slow-start threshold */
65857494343SDavid Howells 	enum rxrpc_congest_mode	cong_mode:8;	/* Congestion management mode */
65957494343SDavid Howells 	u8			cong_dup_acks;	/* Count of ACKs showing missing packets */
66057494343SDavid Howells 	u8			cong_cumul_acks; /* Cumulative ACK count */
66157494343SDavid Howells 	ktime_t			cong_tstamp;	/* Last time cwnd was changed */
66257494343SDavid Howells 
663248f219cSDavid Howells 	rxrpc_seq_t		rx_hard_ack;	/* Dead slot in buffer; the first received but not
664248f219cSDavid Howells 						 * consumed packet follows this.
665248f219cSDavid Howells 						 */
666248f219cSDavid Howells 	rxrpc_seq_t		rx_top;		/* Highest Rx slot allocated. */
667248f219cSDavid Howells 	rxrpc_seq_t		rx_expect_next;	/* Expected next packet sequence number */
6681a025028SDavid Howells 	rxrpc_serial_t		rx_serial;	/* Highest serial received for this call */
669248f219cSDavid Howells 	u8			rx_winsize;	/* Size of Rx window */
670248f219cSDavid Howells 	u8			tx_winsize;	/* Maximum size of Tx window */
67171f3ca40SDavid Howells 	bool			tx_phase;	/* T if transmission phase, F if receive phase */
67275e42126SDavid Howells 	u8			nr_jumbo_bad;	/* Number of jumbo dups/exceeds-windows */
67317926a79SDavid Howells 
674c1e15b49SDavid Howells 	spinlock_t		input_lock;	/* Lock for packet input to this call */
675c1e15b49SDavid Howells 
67617926a79SDavid Howells 	/* receive-phase ACK management */
6774e36a95eSDavid Howells 	u8			ackr_reason;	/* reason to ACK */
6780d12f8a4SDavid Howells 	rxrpc_serial_t		ackr_serial;	/* serial of packet being ACK'd */
6791a2391c3SJeffrey Altman 	rxrpc_serial_t		ackr_first_seq;	/* first sequence number received */
680248f219cSDavid Howells 	rxrpc_seq_t		ackr_prev_seq;	/* previous sequence number received */
681805b21b9SDavid Howells 	rxrpc_seq_t		ackr_consumed;	/* Highest packet shown consumed */
682805b21b9SDavid Howells 	rxrpc_seq_t		ackr_seen;	/* Highest packet shown seen */
683a5af7e1fSDavid Howells 
6844700c4d8SDavid Howells 	/* RTT management */
6854700c4d8SDavid Howells 	rxrpc_serial_t		rtt_serial[4];	/* Serial number of DATA or PING sent */
6864700c4d8SDavid Howells 	ktime_t			rtt_sent_at[4];	/* Time packet sent */
6874700c4d8SDavid Howells 	unsigned long		rtt_avail;	/* Mask of available slots in bits 0-3,
6884700c4d8SDavid Howells 						 * Mask of pending samples in 8-11 */
6894700c4d8SDavid Howells #define RXRPC_CALL_RTT_AVAIL_MASK	0xf
6904700c4d8SDavid Howells #define RXRPC_CALL_RTT_PEND_SHIFT	8
69117926a79SDavid Howells 
692248f219cSDavid Howells 	/* transmission-phase ACK management */
69357494343SDavid Howells 	ktime_t			acks_latest_ts;	/* Timestamp of latest ACK received */
69431a1b989SDavid Howells 	rxrpc_seq_t		acks_lowest_nak; /* Lowest NACK in the buffer (or ==tx_hard_ack) */
695bd1fdf8cSDavid Howells 	rxrpc_seq_t		acks_lost_top;	/* tx_top at the time lost-ack ping sent */
696bd1fdf8cSDavid Howells 	rxrpc_serial_t		acks_lost_ping;	/* Serial number of probe ACK */
69731a1b989SDavid Howells };
69831a1b989SDavid Howells 
69931a1b989SDavid Howells /*
70057494343SDavid Howells  * Summary of a new ACK and the changes it made to the Tx buffer packet states.
70131a1b989SDavid Howells  */
70231a1b989SDavid Howells struct rxrpc_ack_summary {
70331a1b989SDavid Howells 	u8			ack_reason;
70431a1b989SDavid Howells 	u8			nr_acks;		/* Number of ACKs in packet */
70531a1b989SDavid Howells 	u8			nr_nacks;		/* Number of NACKs in packet */
70631a1b989SDavid Howells 	u8			nr_new_acks;		/* Number of new ACKs in packet */
70731a1b989SDavid Howells 	u8			nr_new_nacks;		/* Number of new NACKs in packet */
70831a1b989SDavid Howells 	u8			nr_rot_new_acks;	/* Number of rotated new ACKs */
70931a1b989SDavid Howells 	bool			new_low_nack;		/* T if new low NACK found */
71057494343SDavid Howells 	bool			retrans_timeo;		/* T if reTx due to timeout happened */
71157494343SDavid Howells 	u8			flight_size;		/* Number of unreceived transmissions */
71257494343SDavid Howells 	/* Place to stash values for tracing */
71357494343SDavid Howells 	enum rxrpc_congest_mode	mode:8;
71457494343SDavid Howells 	u8			cwnd;
71557494343SDavid Howells 	u8			ssthresh;
71657494343SDavid Howells 	u8			dup_acks;
71757494343SDavid Howells 	u8			cumulative_acks;
71817926a79SDavid Howells };
71917926a79SDavid Howells 
72048124178SDavid Howells /*
72148124178SDavid Howells  * sendmsg() cmsg-specified parameters.
72248124178SDavid Howells  */
72348124178SDavid Howells enum rxrpc_command {
72448124178SDavid Howells 	RXRPC_CMD_SEND_DATA,		/* send data message */
72548124178SDavid Howells 	RXRPC_CMD_SEND_ABORT,		/* request abort generation */
72648124178SDavid Howells 	RXRPC_CMD_REJECT_BUSY,		/* [server] reject a call as busy */
7272d914c1bSDavid Howells 	RXRPC_CMD_CHARGE_ACCEPT,	/* [server] charge accept preallocation */
72848124178SDavid Howells };
72948124178SDavid Howells 
73048124178SDavid Howells struct rxrpc_call_params {
73148124178SDavid Howells 	s64			tx_total_len;	/* Total Tx data length (if send data) */
73248124178SDavid Howells 	unsigned long		user_call_ID;	/* User's call ID */
73348124178SDavid Howells 	struct {
73448124178SDavid Howells 		u32		hard;		/* Maximum lifetime (sec) */
73548124178SDavid Howells 		u32		idle;		/* Max time since last data packet (msec) */
73648124178SDavid Howells 		u32		normal;		/* Max time since last call packet (msec) */
73748124178SDavid Howells 	} timeouts;
73848124178SDavid Howells 	u8			nr_timeouts;	/* Number of timeouts specified */
739b7a7d674SDavid Howells 	bool			kernel;		/* T if kernel is making the call */
740e138aa7dSDavid Howells 	enum rxrpc_interruptibility interruptibility; /* How is interruptible is the call? */
74148124178SDavid Howells };
74248124178SDavid Howells 
74348124178SDavid Howells struct rxrpc_send_params {
74448124178SDavid Howells 	struct rxrpc_call_params call;
74548124178SDavid Howells 	u32			abort_code;	/* Abort code to Tx (if abort) */
74648124178SDavid Howells 	enum rxrpc_command	command : 8;	/* The command to implement */
74748124178SDavid Howells 	bool			exclusive;	/* Shared or exclusive call */
74848124178SDavid Howells 	bool			upgrade;	/* If the connection is upgradeable */
74948124178SDavid Howells };
75048124178SDavid Howells 
751df844fd4SDavid Howells #include <trace/events/rxrpc.h>
752df844fd4SDavid Howells 
75317926a79SDavid Howells /*
754651350d1SDavid Howells  * af_rxrpc.c
75517926a79SDavid Howells  */
75671f3ca40SDavid Howells extern atomic_t rxrpc_n_tx_skbs, rxrpc_n_rx_skbs;
757651350d1SDavid Howells extern struct workqueue_struct *rxrpc_workqueue;
75817926a79SDavid Howells 
75917926a79SDavid Howells /*
7600d81a51aSDavid Howells  * call_accept.c
76117926a79SDavid Howells  */
76200e90712SDavid Howells int rxrpc_service_prealloc(struct rxrpc_sock *, gfp_t);
76300e90712SDavid Howells void rxrpc_discard_prealloc(struct rxrpc_sock *);
764248f219cSDavid Howells struct rxrpc_call *rxrpc_new_incoming_call(struct rxrpc_local *,
7650099dc58SDavid Howells 					   struct rxrpc_sock *,
766248f219cSDavid Howells 					   struct sk_buff *);
7674f95dd78SDavid Howells void rxrpc_accept_incoming_calls(struct rxrpc_local *);
7682d914c1bSDavid Howells int rxrpc_user_charge_accept(struct rxrpc_sock *, unsigned long);
76917926a79SDavid Howells 
77017926a79SDavid Howells /*
7710d81a51aSDavid Howells  * call_event.c
77217926a79SDavid Howells  */
773e8c3af6bSDavid Howells void rxrpc_propose_ACK(struct rxrpc_call *, u8, u32, bool, bool,
7749c7ad434SDavid Howells 		       enum rxrpc_propose_ack_trace);
775c1b1203dSJoe Perches void rxrpc_process_call(struct work_struct *);
77617926a79SDavid Howells 
777a158bdd3SDavid Howells static inline void rxrpc_reduce_call_timer(struct rxrpc_call *call,
778a158bdd3SDavid Howells 					   unsigned long expire_at,
779a158bdd3SDavid Howells 					   unsigned long now,
780a158bdd3SDavid Howells 					   enum rxrpc_timer_trace why)
781a158bdd3SDavid Howells {
782a158bdd3SDavid Howells 	trace_rxrpc_timer(call, why, now);
783a158bdd3SDavid Howells 	timer_reduce(&call->timer, expire_at);
784a158bdd3SDavid Howells }
785a158bdd3SDavid Howells 
78617926a79SDavid Howells /*
7870d81a51aSDavid Howells  * call_object.c
78817926a79SDavid Howells  */
789f5c17aaeSDavid Howells extern const char *const rxrpc_call_states[];
790f5c17aaeSDavid Howells extern const char *const rxrpc_call_completions[];
791dad8aff7SDavid Howells extern unsigned int rxrpc_max_call_lifetime;
79217926a79SDavid Howells extern struct kmem_cache *rxrpc_call_jar;
79317926a79SDavid Howells 
7942341e077SDavid Howells struct rxrpc_call *rxrpc_find_call_by_user_ID(struct rxrpc_sock *, unsigned long);
795a25e21f0SDavid Howells struct rxrpc_call *rxrpc_alloc_call(struct rxrpc_sock *, gfp_t, unsigned int);
7962341e077SDavid Howells struct rxrpc_call *rxrpc_new_client_call(struct rxrpc_sock *,
79719ffa01cSDavid Howells 					 struct rxrpc_conn_parameters *,
798999b69f8SDavid Howells 					 struct sockaddr_rxrpc *,
799a25e21f0SDavid Howells 					 struct rxrpc_call_params *, gfp_t,
800a25e21f0SDavid Howells 					 unsigned int);
801248f219cSDavid Howells void rxrpc_incoming_call(struct rxrpc_sock *, struct rxrpc_call *,
80242886ffeSDavid Howells 			 struct sk_buff *);
8038d94aa38SDavid Howells void rxrpc_release_call(struct rxrpc_sock *, struct rxrpc_call *);
804c1b1203dSJoe Perches void rxrpc_release_calls_on_socket(struct rxrpc_sock *);
8058d94aa38SDavid Howells bool __rxrpc_queue_call(struct rxrpc_call *);
8068d94aa38SDavid Howells bool rxrpc_queue_call(struct rxrpc_call *);
807e34d4234SDavid Howells void rxrpc_see_call(struct rxrpc_call *);
808fff72429SDavid Howells void rxrpc_get_call(struct rxrpc_call *, enum rxrpc_call_trace);
809fff72429SDavid Howells void rxrpc_put_call(struct rxrpc_call *, enum rxrpc_call_trace);
81000e90712SDavid Howells void rxrpc_cleanup_call(struct rxrpc_call *);
8112baec2c3SDavid Howells void rxrpc_destroy_all_calls(struct rxrpc_net *);
81217926a79SDavid Howells 
813dabe5a79SDavid Howells static inline bool rxrpc_is_service_call(const struct rxrpc_call *call)
814dabe5a79SDavid Howells {
815dabe5a79SDavid Howells 	return test_bit(RXRPC_CALL_IS_SERVICE, &call->flags);
816dabe5a79SDavid Howells }
817dabe5a79SDavid Howells 
818dabe5a79SDavid Howells static inline bool rxrpc_is_client_call(const struct rxrpc_call *call)
819dabe5a79SDavid Howells {
820dabe5a79SDavid Howells 	return !rxrpc_is_service_call(call);
821dabe5a79SDavid Howells }
822dabe5a79SDavid Howells 
82317926a79SDavid Howells /*
8244a3388c8SDavid Howells  * conn_client.c
8254a3388c8SDavid Howells  */
82645025bceSDavid Howells extern unsigned int rxrpc_reap_client_connections;
827a158bdd3SDavid Howells extern unsigned long rxrpc_conn_idle_client_expiry;
828a158bdd3SDavid Howells extern unsigned long rxrpc_conn_idle_client_fast_expiry;
8294a3388c8SDavid Howells extern struct idr rxrpc_client_conn_ids;
8304a3388c8SDavid Howells 
831eb9b9d22SDavid Howells void rxrpc_destroy_client_conn_ids(void);
832245500d8SDavid Howells struct rxrpc_bundle *rxrpc_get_bundle(struct rxrpc_bundle *);
833245500d8SDavid Howells void rxrpc_put_bundle(struct rxrpc_bundle *);
8345e33a23bSDavid Howells int rxrpc_connect_call(struct rxrpc_sock *, struct rxrpc_call *,
8355e33a23bSDavid Howells 		       struct rxrpc_conn_parameters *, struct sockaddr_rxrpc *,
8365e33a23bSDavid Howells 		       gfp_t);
83745025bceSDavid Howells void rxrpc_expose_client_call(struct rxrpc_call *);
838245500d8SDavid Howells void rxrpc_disconnect_client_call(struct rxrpc_bundle *, struct rxrpc_call *);
83945025bceSDavid Howells void rxrpc_put_client_conn(struct rxrpc_connection *);
8402baec2c3SDavid Howells void rxrpc_discard_expired_client_conns(struct work_struct *);
8412baec2c3SDavid Howells void rxrpc_destroy_all_client_connections(struct rxrpc_net *);
842d12040b6SDavid Howells void rxrpc_clean_up_local_conns(struct rxrpc_local *);
8434a3388c8SDavid Howells 
8444a3388c8SDavid Howells /*
8450d81a51aSDavid Howells  * conn_event.c
8460d81a51aSDavid Howells  */
8470d81a51aSDavid Howells void rxrpc_process_connection(struct work_struct *);
848ddc7834aSDavid Howells void rxrpc_process_delayed_final_acks(struct rxrpc_connection *, bool);
8490d81a51aSDavid Howells 
8500d81a51aSDavid Howells /*
8510d81a51aSDavid Howells  * conn_object.c
85217926a79SDavid Howells  */
853dad8aff7SDavid Howells extern unsigned int rxrpc_connection_expiry;
854f859ab61SDavid Howells extern unsigned int rxrpc_closed_conn_expiry;
85517926a79SDavid Howells 
856c6d2b8d7SDavid Howells struct rxrpc_connection *rxrpc_alloc_connection(gfp_t);
8578496af50SDavid Howells struct rxrpc_connection *rxrpc_find_connection_rcu(struct rxrpc_local *,
8580099dc58SDavid Howells 						   struct sk_buff *,
8590099dc58SDavid Howells 						   struct rxrpc_peer **);
86045025bceSDavid Howells void __rxrpc_disconnect_call(struct rxrpc_connection *, struct rxrpc_call *);
861999b69f8SDavid Howells void rxrpc_disconnect_call(struct rxrpc_call *);
86245025bceSDavid Howells void rxrpc_kill_connection(struct rxrpc_connection *);
863363deeabSDavid Howells bool rxrpc_queue_conn(struct rxrpc_connection *);
864363deeabSDavid Howells void rxrpc_see_connection(struct rxrpc_connection *);
865245500d8SDavid Howells struct rxrpc_connection *rxrpc_get_connection(struct rxrpc_connection *);
866363deeabSDavid Howells struct rxrpc_connection *rxrpc_get_connection_maybe(struct rxrpc_connection *);
867363deeabSDavid Howells void rxrpc_put_service_conn(struct rxrpc_connection *);
8682baec2c3SDavid Howells void rxrpc_service_connection_reaper(struct work_struct *);
8692baec2c3SDavid Howells void rxrpc_destroy_all_connections(struct rxrpc_net *);
87017926a79SDavid Howells 
87119ffa01cSDavid Howells static inline bool rxrpc_conn_is_client(const struct rxrpc_connection *conn)
87219ffa01cSDavid Howells {
87319ffa01cSDavid Howells 	return conn->out_clientflag;
87419ffa01cSDavid Howells }
87519ffa01cSDavid Howells 
87619ffa01cSDavid Howells static inline bool rxrpc_conn_is_service(const struct rxrpc_connection *conn)
87719ffa01cSDavid Howells {
878e8d70ce1SDavid Howells 	return !rxrpc_conn_is_client(conn);
87919ffa01cSDavid Howells }
88019ffa01cSDavid Howells 
881f51b4480SDavid Howells static inline void rxrpc_put_connection(struct rxrpc_connection *conn)
882f51b4480SDavid Howells {
88345025bceSDavid Howells 	if (!conn)
88445025bceSDavid Howells 		return;
88545025bceSDavid Howells 
886363deeabSDavid Howells 	if (rxrpc_conn_is_client(conn))
88745025bceSDavid Howells 		rxrpc_put_client_conn(conn);
888363deeabSDavid Howells 	else
889363deeabSDavid Howells 		rxrpc_put_service_conn(conn);
8905acbee46SDavid Howells }
8915acbee46SDavid Howells 
8923136ef49SDavid Howells static inline void rxrpc_reduce_conn_timer(struct rxrpc_connection *conn,
8933136ef49SDavid Howells 					   unsigned long expire_at)
8943136ef49SDavid Howells {
8953136ef49SDavid Howells 	timer_reduce(&conn->timer, expire_at);
8963136ef49SDavid Howells }
8973136ef49SDavid Howells 
89817926a79SDavid Howells /*
8997877a4a4SDavid Howells  * conn_service.c
9007877a4a4SDavid Howells  */
9018496af50SDavid Howells struct rxrpc_connection *rxrpc_find_service_conn_rcu(struct rxrpc_peer *,
9028496af50SDavid Howells 						     struct sk_buff *);
9032baec2c3SDavid Howells struct rxrpc_connection *rxrpc_prealloc_service_connection(struct rxrpc_net *, gfp_t);
904063c60d3SDavid Howells void rxrpc_new_incoming_connection(struct rxrpc_sock *, struct rxrpc_connection *,
905ec832bd0SDavid Howells 				   const struct rxrpc_security *, struct sk_buff *);
906001c1122SDavid Howells void rxrpc_unpublish_service_conn(struct rxrpc_connection *);
9077877a4a4SDavid Howells 
9087877a4a4SDavid Howells /*
9090d81a51aSDavid Howells  * input.c
91017926a79SDavid Howells  */
9115271953cSDavid Howells int rxrpc_input_packet(struct sock *, struct sk_buff *);
91217926a79SDavid Howells 
91317926a79SDavid Howells /*
9140d81a51aSDavid Howells  * insecure.c
91517926a79SDavid Howells  */
9160d81a51aSDavid Howells extern const struct rxrpc_security rxrpc_no_security;
91717926a79SDavid Howells 
91817926a79SDavid Howells /*
9190d81a51aSDavid Howells  * key.c
92017926a79SDavid Howells  */
92117926a79SDavid Howells extern struct key_type key_type_rxrpc;
92217926a79SDavid Howells 
923a7b75c5aSChristoph Hellwig int rxrpc_request_key(struct rxrpc_sock *, sockptr_t , int);
92410674a03SBaolin Wang int rxrpc_get_server_data_key(struct rxrpc_connection *, const void *, time64_t,
925c1b1203dSJoe Perches 			      u32);
92617926a79SDavid Howells 
92717926a79SDavid Howells /*
92887563616SDavid Howells  * local_event.c
92987563616SDavid Howells  */
9304f95dd78SDavid Howells extern void rxrpc_process_local_events(struct rxrpc_local *);
93187563616SDavid Howells 
93287563616SDavid Howells /*
9330d81a51aSDavid Howells  * local_object.c
93417926a79SDavid Howells  */
9352baec2c3SDavid Howells struct rxrpc_local *rxrpc_lookup_local(struct net *, const struct sockaddr_rxrpc *);
93609d2bf59SDavid Howells struct rxrpc_local *rxrpc_get_local(struct rxrpc_local *);
93709d2bf59SDavid Howells struct rxrpc_local *rxrpc_get_local_maybe(struct rxrpc_local *);
93809d2bf59SDavid Howells void rxrpc_put_local(struct rxrpc_local *);
939730c5fd4SDavid Howells struct rxrpc_local *rxrpc_use_local(struct rxrpc_local *);
940730c5fd4SDavid Howells void rxrpc_unuse_local(struct rxrpc_local *);
94109d2bf59SDavid Howells void rxrpc_queue_local(struct rxrpc_local *);
9422baec2c3SDavid Howells void rxrpc_destroy_all_locals(struct rxrpc_net *);
943e0e4d82fSDavid Howells 
94404d36d74SDavid Howells static inline bool __rxrpc_unuse_local(struct rxrpc_local *local)
94504d36d74SDavid Howells {
94604d36d74SDavid Howells 	return atomic_dec_return(&local->active_users) == 0;
94704d36d74SDavid Howells }
94804d36d74SDavid Howells 
94904d36d74SDavid Howells static inline bool __rxrpc_use_local(struct rxrpc_local *local)
95004d36d74SDavid Howells {
95104d36d74SDavid Howells 	return atomic_fetch_add_unless(&local->active_users, 1, 0) != 0;
95204d36d74SDavid Howells }
95304d36d74SDavid Howells 
954e0e4d82fSDavid Howells /*
9558e688d9cSDavid Howells  * misc.c
9568e688d9cSDavid Howells  */
9570e119b41SDavid Howells extern unsigned int rxrpc_max_backlog __read_mostly;
958a158bdd3SDavid Howells extern unsigned long rxrpc_requested_ack_delay;
959a158bdd3SDavid Howells extern unsigned long rxrpc_soft_ack_delay;
960a158bdd3SDavid Howells extern unsigned long rxrpc_idle_ack_delay;
9618e688d9cSDavid Howells extern unsigned int rxrpc_rx_window_size;
9628e688d9cSDavid Howells extern unsigned int rxrpc_rx_mtu;
9638e688d9cSDavid Howells extern unsigned int rxrpc_rx_jumbo_max;
9648e688d9cSDavid Howells 
9658e688d9cSDavid Howells extern const s8 rxrpc_ack_priority[];
9668e688d9cSDavid Howells 
9678e688d9cSDavid Howells /*
9682baec2c3SDavid Howells  * net_ns.c
9692baec2c3SDavid Howells  */
9702baec2c3SDavid Howells extern unsigned int rxrpc_net_id;
9712baec2c3SDavid Howells extern struct pernet_operations rxrpc_net_ops;
9722baec2c3SDavid Howells 
9732baec2c3SDavid Howells static inline struct rxrpc_net *rxrpc_net(struct net *net)
9742baec2c3SDavid Howells {
9752baec2c3SDavid Howells 	return net_generic(net, rxrpc_net_id);
9762baec2c3SDavid Howells }
9772baec2c3SDavid Howells 
9782baec2c3SDavid Howells /*
9790d81a51aSDavid Howells  * output.c
9800d81a51aSDavid Howells  */
981bd1fdf8cSDavid Howells int rxrpc_send_ack_packet(struct rxrpc_call *, bool, rxrpc_serial_t *);
98226cb02aaSDavid Howells int rxrpc_send_abort_packet(struct rxrpc_call *);
983a1767077SDavid Howells int rxrpc_send_data_packet(struct rxrpc_call *, struct sk_buff *, bool);
984248f219cSDavid Howells void rxrpc_reject_packets(struct rxrpc_local *);
985ace45becSDavid Howells void rxrpc_send_keepalive(struct rxrpc_peer *);
9860d81a51aSDavid Howells 
9870d81a51aSDavid Howells /*
988abe89ef0SDavid Howells  * peer_event.c
9890d81a51aSDavid Howells  */
990abe89ef0SDavid Howells void rxrpc_error_report(struct sock *);
991ace45becSDavid Howells void rxrpc_peer_keepalive_worker(struct work_struct *);
9920d81a51aSDavid Howells 
9930d81a51aSDavid Howells /*
9940d81a51aSDavid Howells  * peer_object.c
9950d81a51aSDavid Howells  */
996be6e6707SDavid Howells struct rxrpc_peer *rxrpc_lookup_peer_rcu(struct rxrpc_local *,
997be6e6707SDavid Howells 					 const struct sockaddr_rxrpc *);
9985e33a23bSDavid Howells struct rxrpc_peer *rxrpc_lookup_peer(struct rxrpc_sock *, struct rxrpc_local *,
999be6e6707SDavid Howells 				     struct sockaddr_rxrpc *, gfp_t);
1000be6e6707SDavid Howells struct rxrpc_peer *rxrpc_alloc_peer(struct rxrpc_local *, gfp_t);
10015e33a23bSDavid Howells void rxrpc_new_incoming_peer(struct rxrpc_sock *, struct rxrpc_local *,
10025e33a23bSDavid Howells 			     struct rxrpc_peer *);
100317226f12SDavid Howells void rxrpc_destroy_all_peers(struct rxrpc_net *);
10041159d4b4SDavid Howells struct rxrpc_peer *rxrpc_get_peer(struct rxrpc_peer *);
10051159d4b4SDavid Howells struct rxrpc_peer *rxrpc_get_peer_maybe(struct rxrpc_peer *);
10061159d4b4SDavid Howells void rxrpc_put_peer(struct rxrpc_peer *);
100760034d3dSDavid Howells void rxrpc_put_peer_locked(struct rxrpc_peer *);
10080d81a51aSDavid Howells 
10090d81a51aSDavid Howells /*
10100d81a51aSDavid Howells  * proc.c
10110d81a51aSDavid Howells  */
1012c3506372SChristoph Hellwig extern const struct seq_operations rxrpc_call_seq_ops;
1013c3506372SChristoph Hellwig extern const struct seq_operations rxrpc_connection_seq_ops;
1014bc0e7cf4SDavid Howells extern const struct seq_operations rxrpc_peer_seq_ops;
10150d81a51aSDavid Howells 
10160d81a51aSDavid Howells /*
10170d81a51aSDavid Howells  * recvmsg.c
10180d81a51aSDavid Howells  */
1019248f219cSDavid Howells void rxrpc_notify_socket(struct rxrpc_call *);
10203067bf8cSDavid Howells bool __rxrpc_set_call_completion(struct rxrpc_call *, enum rxrpc_call_completion, u32, int);
10213067bf8cSDavid Howells bool rxrpc_set_call_completion(struct rxrpc_call *, enum rxrpc_call_completion, u32, int);
10223067bf8cSDavid Howells bool __rxrpc_call_completed(struct rxrpc_call *);
10233067bf8cSDavid Howells bool rxrpc_call_completed(struct rxrpc_call *);
10243067bf8cSDavid Howells bool __rxrpc_abort_call(const char *, struct rxrpc_call *, rxrpc_seq_t, u32, int);
10253067bf8cSDavid Howells bool rxrpc_abort_call(const char *, struct rxrpc_call *, rxrpc_seq_t, u32, int);
10260d81a51aSDavid Howells int rxrpc_recvmsg(struct socket *, struct msghdr *, size_t, int);
10270d81a51aSDavid Howells 
10280d81a51aSDavid Howells /*
10293067bf8cSDavid Howells  * Abort a call due to a protocol error.
10303067bf8cSDavid Howells  */
10313067bf8cSDavid Howells static inline bool __rxrpc_abort_eproto(struct rxrpc_call *call,
10323067bf8cSDavid Howells 					struct sk_buff *skb,
10333067bf8cSDavid Howells 					const char *eproto_why,
10343067bf8cSDavid Howells 					const char *why,
10353067bf8cSDavid Howells 					u32 abort_code)
10363067bf8cSDavid Howells {
10373067bf8cSDavid Howells 	struct rxrpc_skb_priv *sp = rxrpc_skb(skb);
10383067bf8cSDavid Howells 
10393067bf8cSDavid Howells 	trace_rxrpc_rx_eproto(call, sp->hdr.serial, eproto_why);
10403067bf8cSDavid Howells 	return rxrpc_abort_call(why, call, sp->hdr.seq, abort_code, -EPROTO);
10413067bf8cSDavid Howells }
10423067bf8cSDavid Howells 
10433067bf8cSDavid Howells #define rxrpc_abort_eproto(call, skb, eproto_why, abort_why, abort_code) \
10443067bf8cSDavid Howells 	__rxrpc_abort_eproto((call), (skb), tracepoint_string(eproto_why), \
10453067bf8cSDavid Howells 			     (abort_why), (abort_code))
10463067bf8cSDavid Howells 
10473067bf8cSDavid Howells /*
1048c410bf01SDavid Howells  * rtt.c
1049c410bf01SDavid Howells  */
10504700c4d8SDavid Howells void rxrpc_peer_add_rtt(struct rxrpc_call *, enum rxrpc_rtt_rx_trace, int,
1051c410bf01SDavid Howells 			rxrpc_serial_t, rxrpc_serial_t, ktime_t, ktime_t);
1052c410bf01SDavid Howells unsigned long rxrpc_get_rto_backoff(struct rxrpc_peer *, bool);
1053c410bf01SDavid Howells void rxrpc_peer_init_rtt(struct rxrpc_peer *);
1054c410bf01SDavid Howells 
1055c410bf01SDavid Howells /*
1056648af7fcSDavid Howells  * rxkad.c
1057648af7fcSDavid Howells  */
1058648af7fcSDavid Howells #ifdef CONFIG_RXKAD
1059648af7fcSDavid Howells extern const struct rxrpc_security rxkad;
1060648af7fcSDavid Howells #endif
1061648af7fcSDavid Howells 
1062648af7fcSDavid Howells /*
10630d81a51aSDavid Howells  * security.c
10640d81a51aSDavid Howells  */
10650d81a51aSDavid Howells int __init rxrpc_init_security(void);
106612da59fcSDavid Howells const struct rxrpc_security *rxrpc_security_lookup(u8);
10670d81a51aSDavid Howells void rxrpc_exit_security(void);
10680d81a51aSDavid Howells int rxrpc_init_client_conn_security(struct rxrpc_connection *);
1069ec832bd0SDavid Howells const struct rxrpc_security *rxrpc_get_incoming_security(struct rxrpc_sock *,
1070063c60d3SDavid Howells 							 struct sk_buff *);
1071ec832bd0SDavid Howells struct key *rxrpc_look_up_server_security(struct rxrpc_connection *,
1072ec832bd0SDavid Howells 					  struct sk_buff *, u32, u32);
10730d81a51aSDavid Howells 
10740d81a51aSDavid Howells /*
10750b58b8a1SDavid Howells  * sendmsg.c
10760b58b8a1SDavid Howells  */
10770b58b8a1SDavid Howells int rxrpc_do_sendmsg(struct rxrpc_sock *, struct msghdr *, size_t);
10780b58b8a1SDavid Howells 
10790b58b8a1SDavid Howells /*
1080ca7fb100SDavid Howells  * server_key.c
1081ca7fb100SDavid Howells  */
1082ca7fb100SDavid Howells extern struct key_type key_type_rxrpc_s;
1083ca7fb100SDavid Howells 
1084ca7fb100SDavid Howells int rxrpc_server_keyring(struct rxrpc_sock *, sockptr_t, int);
1085ca7fb100SDavid Howells 
1086ca7fb100SDavid Howells /*
10870d81a51aSDavid Howells  * skbuff.c
10880d81a51aSDavid Howells  */
1089d001648eSDavid Howells void rxrpc_kernel_data_consumed(struct rxrpc_call *, struct sk_buff *);
10900d81a51aSDavid Howells void rxrpc_packet_destructor(struct sk_buff *);
109171f3ca40SDavid Howells void rxrpc_new_skb(struct sk_buff *, enum rxrpc_skb_trace);
109271f3ca40SDavid Howells void rxrpc_see_skb(struct sk_buff *, enum rxrpc_skb_trace);
1093d0d5c0cdSDavid Howells void rxrpc_eaten_skb(struct sk_buff *, enum rxrpc_skb_trace);
109471f3ca40SDavid Howells void rxrpc_get_skb(struct sk_buff *, enum rxrpc_skb_trace);
109571f3ca40SDavid Howells void rxrpc_free_skb(struct sk_buff *, enum rxrpc_skb_trace);
1096df844fd4SDavid Howells void rxrpc_purge_queue(struct sk_buff_head *);
10970d81a51aSDavid Howells 
10980d81a51aSDavid Howells /*
10995873c083SDavid Howells  * sysctl.c
11005873c083SDavid Howells  */
11015873c083SDavid Howells #ifdef CONFIG_SYSCTL
11025873c083SDavid Howells extern int __init rxrpc_sysctl_init(void);
11035873c083SDavid Howells extern void rxrpc_sysctl_exit(void);
11045873c083SDavid Howells #else
11055873c083SDavid Howells static inline int __init rxrpc_sysctl_init(void) { return 0; }
11065873c083SDavid Howells static inline void rxrpc_sysctl_exit(void) {}
11075873c083SDavid Howells #endif
11085873c083SDavid Howells 
11095873c083SDavid Howells /*
1110be6e6707SDavid Howells  * utils.c
1111be6e6707SDavid Howells  */
11125a790b73SDavid Howells int rxrpc_extract_addr_from_skb(struct sockaddr_rxrpc *, struct sk_buff *);
1113be6e6707SDavid Howells 
1114248f219cSDavid Howells static inline bool before(u32 seq1, u32 seq2)
1115248f219cSDavid Howells {
1116248f219cSDavid Howells         return (s32)(seq1 - seq2) < 0;
1117248f219cSDavid Howells }
1118248f219cSDavid Howells static inline bool before_eq(u32 seq1, u32 seq2)
1119248f219cSDavid Howells {
1120248f219cSDavid Howells         return (s32)(seq1 - seq2) <= 0;
1121248f219cSDavid Howells }
1122248f219cSDavid Howells static inline bool after(u32 seq1, u32 seq2)
1123248f219cSDavid Howells {
1124248f219cSDavid Howells         return (s32)(seq1 - seq2) > 0;
1125248f219cSDavid Howells }
1126248f219cSDavid Howells static inline bool after_eq(u32 seq1, u32 seq2)
1127248f219cSDavid Howells {
1128248f219cSDavid Howells         return (s32)(seq1 - seq2) >= 0;
1129248f219cSDavid Howells }
1130248f219cSDavid Howells 
1131be6e6707SDavid Howells /*
113217926a79SDavid Howells  * debug tracing
113317926a79SDavid Howells  */
113495c96174SEric Dumazet extern unsigned int rxrpc_debug;
113517926a79SDavid Howells 
113617926a79SDavid Howells #define dbgprintk(FMT,...) \
11379f389f4bSSven Schnelle 	printk("[%-6.6s] "FMT"\n", current->comm ,##__VA_ARGS__)
113817926a79SDavid Howells 
11390dc47877SHarvey Harrison #define kenter(FMT,...)	dbgprintk("==> %s("FMT")",__func__ ,##__VA_ARGS__)
11400dc47877SHarvey Harrison #define kleave(FMT,...)	dbgprintk("<== %s()"FMT"",__func__ ,##__VA_ARGS__)
114117926a79SDavid Howells #define kdebug(FMT,...)	dbgprintk("    "FMT ,##__VA_ARGS__)
114217926a79SDavid Howells #define kproto(FMT,...)	dbgprintk("### "FMT ,##__VA_ARGS__)
114317926a79SDavid Howells #define knet(FMT,...)	dbgprintk("@@@ "FMT ,##__VA_ARGS__)
114417926a79SDavid Howells 
114517926a79SDavid Howells 
114617926a79SDavid Howells #if defined(__KDEBUG)
114717926a79SDavid Howells #define _enter(FMT,...)	kenter(FMT,##__VA_ARGS__)
114817926a79SDavid Howells #define _leave(FMT,...)	kleave(FMT,##__VA_ARGS__)
114917926a79SDavid Howells #define _debug(FMT,...)	kdebug(FMT,##__VA_ARGS__)
115017926a79SDavid Howells #define _proto(FMT,...)	kproto(FMT,##__VA_ARGS__)
115117926a79SDavid Howells #define _net(FMT,...)	knet(FMT,##__VA_ARGS__)
115217926a79SDavid Howells 
115317926a79SDavid Howells #elif defined(CONFIG_AF_RXRPC_DEBUG)
115417926a79SDavid Howells #define RXRPC_DEBUG_KENTER	0x01
115517926a79SDavid Howells #define RXRPC_DEBUG_KLEAVE	0x02
115617926a79SDavid Howells #define RXRPC_DEBUG_KDEBUG	0x04
115717926a79SDavid Howells #define RXRPC_DEBUG_KPROTO	0x08
115817926a79SDavid Howells #define RXRPC_DEBUG_KNET	0x10
115917926a79SDavid Howells 
116017926a79SDavid Howells #define _enter(FMT,...)					\
116117926a79SDavid Howells do {							\
116217926a79SDavid Howells 	if (unlikely(rxrpc_debug & RXRPC_DEBUG_KENTER))	\
116317926a79SDavid Howells 		kenter(FMT,##__VA_ARGS__);		\
116417926a79SDavid Howells } while (0)
116517926a79SDavid Howells 
116617926a79SDavid Howells #define _leave(FMT,...)					\
116717926a79SDavid Howells do {							\
116817926a79SDavid Howells 	if (unlikely(rxrpc_debug & RXRPC_DEBUG_KLEAVE))	\
116917926a79SDavid Howells 		kleave(FMT,##__VA_ARGS__);		\
117017926a79SDavid Howells } while (0)
117117926a79SDavid Howells 
117217926a79SDavid Howells #define _debug(FMT,...)					\
117317926a79SDavid Howells do {							\
117417926a79SDavid Howells 	if (unlikely(rxrpc_debug & RXRPC_DEBUG_KDEBUG))	\
117517926a79SDavid Howells 		kdebug(FMT,##__VA_ARGS__);		\
117617926a79SDavid Howells } while (0)
117717926a79SDavid Howells 
117817926a79SDavid Howells #define _proto(FMT,...)					\
117917926a79SDavid Howells do {							\
118017926a79SDavid Howells 	if (unlikely(rxrpc_debug & RXRPC_DEBUG_KPROTO))	\
118117926a79SDavid Howells 		kproto(FMT,##__VA_ARGS__);		\
118217926a79SDavid Howells } while (0)
118317926a79SDavid Howells 
118417926a79SDavid Howells #define _net(FMT,...)					\
118517926a79SDavid Howells do {							\
118617926a79SDavid Howells 	if (unlikely(rxrpc_debug & RXRPC_DEBUG_KNET))	\
118717926a79SDavid Howells 		knet(FMT,##__VA_ARGS__);		\
118817926a79SDavid Howells } while (0)
118917926a79SDavid Howells 
119017926a79SDavid Howells #else
119112fdff3fSDavid Howells #define _enter(FMT,...)	no_printk("==> %s("FMT")",__func__ ,##__VA_ARGS__)
119212fdff3fSDavid Howells #define _leave(FMT,...)	no_printk("<== %s()"FMT"",__func__ ,##__VA_ARGS__)
119312fdff3fSDavid Howells #define _debug(FMT,...)	no_printk("    "FMT ,##__VA_ARGS__)
119412fdff3fSDavid Howells #define _proto(FMT,...)	no_printk("### "FMT ,##__VA_ARGS__)
119512fdff3fSDavid Howells #define _net(FMT,...)	no_printk("@@@ "FMT ,##__VA_ARGS__)
119617926a79SDavid Howells #endif
119717926a79SDavid Howells 
119817926a79SDavid Howells /*
119917926a79SDavid Howells  * debug assertion checking
120017926a79SDavid Howells  */
120117926a79SDavid Howells #if 1 // defined(__KDEBUGALL)
120217926a79SDavid Howells 
120317926a79SDavid Howells #define ASSERT(X)						\
120417926a79SDavid Howells do {								\
120517926a79SDavid Howells 	if (unlikely(!(X))) {					\
12069b6d5398SJoe Perches 		pr_err("Assertion failed\n");			\
120717926a79SDavid Howells 		BUG();						\
120817926a79SDavid Howells 	}							\
120917926a79SDavid Howells } while (0)
121017926a79SDavid Howells 
121117926a79SDavid Howells #define ASSERTCMP(X, OP, Y)						\
121217926a79SDavid Howells do {									\
1213cf13258fSDavid Howells 	__typeof__(X) _x = (X);						\
1214cf13258fSDavid Howells 	__typeof__(Y) _y = (__typeof__(X))(Y);				\
12159b6d5398SJoe Perches 	if (unlikely(!(_x OP _y))) {					\
12169b6d5398SJoe Perches 		pr_err("Assertion failed - %lu(0x%lx) %s %lu(0x%lx) is false\n", \
1217cf13258fSDavid Howells 		       (unsigned long)_x, (unsigned long)_x, #OP,	\
1218cf13258fSDavid Howells 		       (unsigned long)_y, (unsigned long)_y);		\
121917926a79SDavid Howells 		BUG();							\
122017926a79SDavid Howells 	}								\
122117926a79SDavid Howells } while (0)
122217926a79SDavid Howells 
122317926a79SDavid Howells #define ASSERTIF(C, X)						\
122417926a79SDavid Howells do {								\
122517926a79SDavid Howells 	if (unlikely((C) && !(X))) {				\
12269b6d5398SJoe Perches 		pr_err("Assertion failed\n");			\
122717926a79SDavid Howells 		BUG();						\
122817926a79SDavid Howells 	}							\
122917926a79SDavid Howells } while (0)
123017926a79SDavid Howells 
123117926a79SDavid Howells #define ASSERTIFCMP(C, X, OP, Y)					\
123217926a79SDavid Howells do {									\
1233cf13258fSDavid Howells 	__typeof__(X) _x = (X);						\
1234cf13258fSDavid Howells 	__typeof__(Y) _y = (__typeof__(X))(Y);				\
12359b6d5398SJoe Perches 	if (unlikely((C) && !(_x OP _y))) {				\
12369b6d5398SJoe Perches 		pr_err("Assertion failed - %lu(0x%lx) %s %lu(0x%lx) is false\n", \
1237cf13258fSDavid Howells 		       (unsigned long)_x, (unsigned long)_x, #OP,	\
1238cf13258fSDavid Howells 		       (unsigned long)_y, (unsigned long)_y);		\
123917926a79SDavid Howells 		BUG();							\
124017926a79SDavid Howells 	}								\
124117926a79SDavid Howells } while (0)
124217926a79SDavid Howells 
124317926a79SDavid Howells #else
124417926a79SDavid Howells 
124517926a79SDavid Howells #define ASSERT(X)				\
124617926a79SDavid Howells do {						\
124717926a79SDavid Howells } while (0)
124817926a79SDavid Howells 
124917926a79SDavid Howells #define ASSERTCMP(X, OP, Y)			\
125017926a79SDavid Howells do {						\
125117926a79SDavid Howells } while (0)
125217926a79SDavid Howells 
125317926a79SDavid Howells #define ASSERTIF(C, X)				\
125417926a79SDavid Howells do {						\
125517926a79SDavid Howells } while (0)
125617926a79SDavid Howells 
125717926a79SDavid Howells #define ASSERTIFCMP(C, X, OP, Y)		\
125817926a79SDavid Howells do {						\
125917926a79SDavid Howells } while (0)
126017926a79SDavid Howells 
126117926a79SDavid Howells #endif /* __KDEBUGALL */
1262