xref: /openbmc/linux/net/rxrpc/ar-internal.h (revision ad25f5cb)
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;
32cc8feb8eSDavid Howells 
3317926a79SDavid Howells /*
34ece64fecSDavid Howells  * Mark applied to socket buffers in skb->mark.  skb->priority is used
35ece64fecSDavid Howells  * to pass supplementary information.
36d001648eSDavid Howells  */
37d001648eSDavid Howells enum rxrpc_skb_mark {
38ece64fecSDavid Howells 	RXRPC_SKB_MARK_REJECT_BUSY,	/* Reject with BUSY */
39ece64fecSDavid Howells 	RXRPC_SKB_MARK_REJECT_ABORT,	/* Reject with ABORT (code in skb->priority) */
40d001648eSDavid Howells };
41d001648eSDavid Howells 
42d001648eSDavid Howells /*
4317926a79SDavid Howells  * sk_state for RxRPC sockets
4417926a79SDavid Howells  */
4517926a79SDavid Howells enum {
462341e077SDavid Howells 	RXRPC_UNBOUND = 0,
472341e077SDavid Howells 	RXRPC_CLIENT_UNBOUND,		/* Unbound socket used as client */
4817926a79SDavid Howells 	RXRPC_CLIENT_BOUND,		/* client local address bound */
4917926a79SDavid Howells 	RXRPC_SERVER_BOUND,		/* server local address bound */
5028036f44SDavid Howells 	RXRPC_SERVER_BOUND2,		/* second server local address bound */
5117926a79SDavid Howells 	RXRPC_SERVER_LISTENING,		/* server listening for connections */
52210f0353SDavid Howells 	RXRPC_SERVER_LISTEN_DISABLED,	/* server listening disabled */
5317926a79SDavid Howells 	RXRPC_CLOSE,			/* socket is being closed */
5417926a79SDavid Howells };
5517926a79SDavid Howells 
5617926a79SDavid Howells /*
572baec2c3SDavid Howells  * Per-network namespace data.
582baec2c3SDavid Howells  */
592baec2c3SDavid Howells struct rxrpc_net {
602baec2c3SDavid Howells 	struct proc_dir_entry	*proc_net;	/* Subdir in /proc/net */
612baec2c3SDavid Howells 	u32			epoch;		/* Local epoch for detecting local-end reset */
622baec2c3SDavid Howells 	struct list_head	calls;		/* List of calls active in this namespace */
63*ad25f5cbSDavid Howells 	spinlock_t		call_lock;	/* Lock for ->calls */
64d3be4d24SDavid Howells 	atomic_t		nr_calls;	/* Count of allocated calls */
652baec2c3SDavid Howells 
6631f5f9a1SDavid Howells 	atomic_t		nr_conns;
672baec2c3SDavid Howells 	struct list_head	conn_proc_list;	/* List of conns in this namespace for proc */
682baec2c3SDavid Howells 	struct list_head	service_conns;	/* Service conns in this namespace */
692baec2c3SDavid Howells 	rwlock_t		conn_lock;	/* Lock for ->conn_proc_list, ->service_conns */
703d18cbb7SDavid Howells 	struct work_struct	service_conn_reaper;
713d18cbb7SDavid Howells 	struct timer_list	service_conn_reap_timer;
722baec2c3SDavid Howells 
73f859ab61SDavid Howells 	bool			live;
74245500d8SDavid Howells 
75245500d8SDavid Howells 	bool			kill_all_client_conns;
76245500d8SDavid Howells 	atomic_t		nr_client_conns;
772baec2c3SDavid Howells 	spinlock_t		client_conn_cache_lock; /* Lock for ->*_client_conns */
782baec2c3SDavid Howells 	spinlock_t		client_conn_discard_lock; /* Prevent multiple discarders */
792baec2c3SDavid Howells 	struct list_head	idle_client_conns;
803d18cbb7SDavid Howells 	struct work_struct	client_conn_reaper;
813d18cbb7SDavid Howells 	struct timer_list	client_conn_reap_timer;
822baec2c3SDavid Howells 
8333912c26SDavid Howells 	struct hlist_head	local_endpoints;
842baec2c3SDavid Howells 	struct mutex		local_mutex;	/* Lock for ->local_endpoints */
852baec2c3SDavid Howells 
862baec2c3SDavid Howells 	DECLARE_HASHTABLE	(peer_hash, 10);
87ace45becSDavid Howells 	spinlock_t		peer_hash_lock;	/* Lock for ->peer_hash */
88ace45becSDavid Howells 
89ace45becSDavid Howells #define RXRPC_KEEPALIVE_TIME 20 /* NAT keepalive time in seconds */
90ace45becSDavid Howells 	u8			peer_keepalive_cursor;
91330bdcfaSDavid Howells 	time64_t		peer_keepalive_base;
92330bdcfaSDavid Howells 	struct list_head	peer_keepalive[32];
93330bdcfaSDavid Howells 	struct list_head	peer_keepalive_new;
94ace45becSDavid Howells 	struct timer_list	peer_keepalive_timer;
95ace45becSDavid Howells 	struct work_struct	peer_keepalive_work;
962baec2c3SDavid Howells };
972baec2c3SDavid Howells 
982baec2c3SDavid Howells /*
9900e90712SDavid Howells  * Service backlog preallocation.
10000e90712SDavid Howells  *
10100e90712SDavid Howells  * This contains circular buffers of preallocated peers, connections and calls
10200e90712SDavid Howells  * for incoming service calls and their head and tail pointers.  This allows
10300e90712SDavid Howells  * calls to be set up in the data_ready handler, thereby avoiding the need to
10400e90712SDavid Howells  * shuffle packets around so much.
10500e90712SDavid Howells  */
10600e90712SDavid Howells struct rxrpc_backlog {
10700e90712SDavid Howells 	unsigned short		peer_backlog_head;
10800e90712SDavid Howells 	unsigned short		peer_backlog_tail;
10900e90712SDavid Howells 	unsigned short		conn_backlog_head;
11000e90712SDavid Howells 	unsigned short		conn_backlog_tail;
11100e90712SDavid Howells 	unsigned short		call_backlog_head;
11200e90712SDavid Howells 	unsigned short		call_backlog_tail;
11300e90712SDavid Howells #define RXRPC_BACKLOG_MAX	32
11400e90712SDavid Howells 	struct rxrpc_peer	*peer_backlog[RXRPC_BACKLOG_MAX];
11500e90712SDavid Howells 	struct rxrpc_connection	*conn_backlog[RXRPC_BACKLOG_MAX];
11600e90712SDavid Howells 	struct rxrpc_call	*call_backlog[RXRPC_BACKLOG_MAX];
11700e90712SDavid Howells };
11800e90712SDavid Howells 
11900e90712SDavid Howells /*
12017926a79SDavid Howells  * RxRPC socket definition
12117926a79SDavid Howells  */
12217926a79SDavid Howells struct rxrpc_sock {
12317926a79SDavid Howells 	/* WARNING: sk has to be the first member */
12417926a79SDavid Howells 	struct sock		sk;
125d001648eSDavid Howells 	rxrpc_notify_new_call_t	notify_new_call; /* Func to notify of new call */
12600e90712SDavid Howells 	rxrpc_discard_new_call_t discard_new_call; /* Func to discard a new call */
12717926a79SDavid Howells 	struct rxrpc_local	*local;		/* local endpoint */
12800e90712SDavid Howells 	struct rxrpc_backlog	*backlog;	/* Preallocation for services */
129248f219cSDavid Howells 	spinlock_t		incoming_lock;	/* Incoming call vs service shutdown lock */
130248f219cSDavid Howells 	struct list_head	sock_calls;	/* List of calls owned by this socket */
131248f219cSDavid Howells 	struct list_head	to_be_accepted;	/* calls awaiting acceptance */
132248f219cSDavid Howells 	struct list_head	recvmsg_q;	/* Calls awaiting recvmsg's attention  */
133248f219cSDavid Howells 	rwlock_t		recvmsg_lock;	/* Lock for recvmsg_q */
13417926a79SDavid Howells 	struct key		*key;		/* security for this socket */
13517926a79SDavid Howells 	struct key		*securities;	/* list of server security descriptors */
13600e90712SDavid Howells 	struct rb_root		calls;		/* User ID -> call mapping */
13717926a79SDavid Howells 	unsigned long		flags;
1382341e077SDavid Howells #define RXRPC_SOCK_CONNECTED		0	/* connect_srx is set */
13917926a79SDavid Howells 	rwlock_t		call_lock;	/* lock for calls */
14017926a79SDavid Howells 	u32			min_sec_level;	/* minimum security level */
14117926a79SDavid Howells #define RXRPC_SECURITY_MAX	RXRPC_SECURITY_ENCRYPT
142cc8feb8eSDavid Howells 	bool			exclusive;	/* Exclusive connection for a client socket */
14328036f44SDavid Howells 	u16			second_service;	/* Additional service bound to the endpoint */
1444722974dSDavid Howells 	struct {
1454722974dSDavid Howells 		/* Service upgrade information */
1464722974dSDavid Howells 		u16		from;		/* Service ID to upgrade (if not 0) */
1474722974dSDavid Howells 		u16		to;		/* service ID to upgrade to */
1484722974dSDavid Howells 	} service_upgrade;
149cc8feb8eSDavid Howells 	sa_family_t		family;		/* Protocol family created with */
1504722974dSDavid Howells 	struct sockaddr_rxrpc	srx;		/* Primary Service/local addresses */
1512341e077SDavid Howells 	struct sockaddr_rxrpc	connect_srx;	/* Default client address from connect() */
15217926a79SDavid Howells };
15317926a79SDavid Howells 
15417926a79SDavid Howells #define rxrpc_sk(__sk) container_of((__sk), struct rxrpc_sock, sk)
15517926a79SDavid Howells 
15617926a79SDavid Howells /*
1570d12f8a4SDavid Howells  * CPU-byteorder normalised Rx packet header.
1580d12f8a4SDavid Howells  */
1590d12f8a4SDavid Howells struct rxrpc_host_header {
1600d12f8a4SDavid Howells 	u32		epoch;		/* client boot timestamp */
1610d12f8a4SDavid Howells 	u32		cid;		/* connection and channel ID */
1620d12f8a4SDavid Howells 	u32		callNumber;	/* call ID (0 for connection-level packets) */
1630d12f8a4SDavid Howells 	u32		seq;		/* sequence number of pkt in call stream */
1640d12f8a4SDavid Howells 	u32		serial;		/* serial number of pkt sent to network */
1650d12f8a4SDavid Howells 	u8		type;		/* packet type */
1660d12f8a4SDavid Howells 	u8		flags;		/* packet flags */
1670d12f8a4SDavid Howells 	u8		userStatus;	/* app-layer defined status */
1680d12f8a4SDavid Howells 	u8		securityIndex;	/* security protocol ID */
1690d12f8a4SDavid Howells 	union {
1700d12f8a4SDavid Howells 		u16	_rsvd;		/* reserved */
1710d12f8a4SDavid Howells 		u16	cksum;		/* kerberos security checksum */
1720d12f8a4SDavid Howells 	};
1730d12f8a4SDavid Howells 	u16		serviceId;	/* service ID */
1740d12f8a4SDavid Howells } __packed;
1750d12f8a4SDavid Howells 
1760d12f8a4SDavid Howells /*
17717926a79SDavid Howells  * RxRPC socket buffer private variables
17817926a79SDavid Howells  * - max 48 bytes (struct sk_buff::cb)
17917926a79SDavid Howells  */
18017926a79SDavid Howells struct rxrpc_skb_priv {
181987db9f7SDavid Howells 	atomic_t	nr_ring_pins;		/* Number of rxtx ring pins */
182c3c9e3dfSDavid Howells 	u8		nr_subpackets;		/* Number of subpackets */
183c3c9e3dfSDavid Howells 	u8		rx_flags;		/* Received packet flags */
184c3c9e3dfSDavid Howells #define RXRPC_SKB_INCL_LAST	0x01		/* - Includes last packet */
185b311e684SDavid Howells #define RXRPC_SKB_TX_BUFFER	0x02		/* - Is transmit buffer */
18617926a79SDavid Howells 	union {
18717926a79SDavid Howells 		int		remain;		/* amount of space remaining for next write */
188c3c9e3dfSDavid Howells 
189c3c9e3dfSDavid Howells 		/* List of requested ACKs on subpackets */
190c3c9e3dfSDavid Howells 		unsigned long	rx_req_ack[(RXRPC_MAX_NR_JUMBO + BITS_PER_LONG - 1) /
191c3c9e3dfSDavid Howells 					   BITS_PER_LONG];
19217926a79SDavid Howells 	};
19317926a79SDavid Howells 
1940d12f8a4SDavid Howells 	struct rxrpc_host_header hdr;		/* RxRPC packet header from this packet */
19517926a79SDavid Howells };
19617926a79SDavid Howells 
19717926a79SDavid Howells #define rxrpc_skb(__skb) ((struct rxrpc_skb_priv *) &(__skb)->cb)
19817926a79SDavid Howells 
19917926a79SDavid Howells /*
20017926a79SDavid Howells  * RxRPC security module interface
20117926a79SDavid Howells  */
20217926a79SDavid Howells struct rxrpc_security {
20317926a79SDavid Howells 	const char		*name;		/* name of this service */
20417926a79SDavid Howells 	u8			security_index;	/* security type provided */
205063c60d3SDavid Howells 	u32			no_key_abort;	/* Abort code indicating no key */
20617926a79SDavid Howells 
207648af7fcSDavid Howells 	/* Initialise a security service */
208648af7fcSDavid Howells 	int (*init)(void);
209648af7fcSDavid Howells 
210648af7fcSDavid Howells 	/* Clean up a security service */
211648af7fcSDavid Howells 	void (*exit)(void);
212648af7fcSDavid Howells 
21312da59fcSDavid Howells 	/* Parse the information from a server key */
21412da59fcSDavid Howells 	int (*preparse_server_key)(struct key_preparsed_payload *);
21512da59fcSDavid Howells 
21612da59fcSDavid Howells 	/* Clean up the preparse buffer after parsing a server key */
21712da59fcSDavid Howells 	void (*free_preparse_server_key)(struct key_preparsed_payload *);
21812da59fcSDavid Howells 
21912da59fcSDavid Howells 	/* Destroy the payload of a server key */
22012da59fcSDavid Howells 	void (*destroy_server_key)(struct key *);
22112da59fcSDavid Howells 
222d5953f65SDavid Howells 	/* Describe a server key */
223d5953f65SDavid Howells 	void (*describe_server_key)(const struct key *, struct seq_file *);
224d5953f65SDavid Howells 
22517926a79SDavid Howells 	/* initialise a connection's security */
22641057ebdSDavid Howells 	int (*init_connection_security)(struct rxrpc_connection *,
22741057ebdSDavid Howells 					struct rxrpc_key_token *);
22817926a79SDavid Howells 
229d7d775b1SDavid Howells 	/* Work out how much data we can store in a packet, given an estimate
230d7d775b1SDavid Howells 	 * of the amount of data remaining.
231d7d775b1SDavid Howells 	 */
232d7d775b1SDavid Howells 	int (*how_much_data)(struct rxrpc_call *, size_t,
233d7d775b1SDavid Howells 			     size_t *, size_t *, size_t *);
23417926a79SDavid Howells 
23517926a79SDavid Howells 	/* impose security on a packet */
236f4bdf3d6SDavid Howells 	int (*secure_packet)(struct rxrpc_call *, struct sk_buff *, size_t);
23717926a79SDavid Howells 
23817926a79SDavid Howells 	/* verify the security on a received packet */
2395a42976dSDavid Howells 	int (*verify_packet)(struct rxrpc_call *, struct sk_buff *,
240248f219cSDavid Howells 			     unsigned int, unsigned int, rxrpc_seq_t, u16);
241248f219cSDavid Howells 
2421db88c53SDavid Howells 	/* Free crypto request on a call */
2431db88c53SDavid Howells 	void (*free_call_crypto)(struct rxrpc_call *);
2441db88c53SDavid Howells 
245248f219cSDavid Howells 	/* Locate the data in a received packet that has been verified. */
246248f219cSDavid Howells 	void (*locate_data)(struct rxrpc_call *, struct sk_buff *,
247248f219cSDavid Howells 			    unsigned int *, unsigned int *);
24817926a79SDavid Howells 
24917926a79SDavid Howells 	/* issue a challenge */
25017926a79SDavid Howells 	int (*issue_challenge)(struct rxrpc_connection *);
25117926a79SDavid Howells 
25217926a79SDavid Howells 	/* respond to a challenge */
25317926a79SDavid Howells 	int (*respond_to_challenge)(struct rxrpc_connection *,
25417926a79SDavid Howells 				    struct sk_buff *,
25517926a79SDavid Howells 				    u32 *);
25617926a79SDavid Howells 
25717926a79SDavid Howells 	/* verify a response */
25817926a79SDavid Howells 	int (*verify_response)(struct rxrpc_connection *,
25917926a79SDavid Howells 			       struct sk_buff *,
26017926a79SDavid Howells 			       u32 *);
26117926a79SDavid Howells 
26217926a79SDavid Howells 	/* clear connection security */
26317926a79SDavid Howells 	void (*clear)(struct rxrpc_connection *);
26417926a79SDavid Howells };
26517926a79SDavid Howells 
26617926a79SDavid Howells /*
2674f95dd78SDavid Howells  * RxRPC local transport endpoint description
2684f95dd78SDavid Howells  * - owned by a single AF_RXRPC socket
2694f95dd78SDavid Howells  * - pointed to by transport socket struct sk_user_data
27017926a79SDavid Howells  */
27117926a79SDavid Howells struct rxrpc_local {
2724f95dd78SDavid Howells 	struct rcu_head		rcu;
273730c5fd4SDavid Howells 	atomic_t		active_users;	/* Number of users of the local endpoint */
274a0575429SDavid Howells 	refcount_t		ref;		/* Number of references to the structure */
2752baec2c3SDavid Howells 	struct rxrpc_net	*rxnet;		/* The network ns in which this resides */
27633912c26SDavid Howells 	struct hlist_node	link;
27717926a79SDavid Howells 	struct socket		*socket;	/* my UDP socket */
2784f95dd78SDavid Howells 	struct work_struct	processor;
2791e9e5c95SDavid Howells 	struct rxrpc_sock __rcu	*service;	/* Service(s) listening on this endpoint */
28017926a79SDavid Howells 	struct rw_semaphore	defrag_sem;	/* control re-enablement of IP DF bit */
28117926a79SDavid Howells 	struct sk_buff_head	reject_queue;	/* packets awaiting rejection */
28244ba0698SDavid Howells 	struct sk_buff_head	event_queue;	/* endpoint event packets awaiting processing */
283245500d8SDavid Howells 	struct rb_root		client_bundles;	/* Client connection bundles by socket params */
284245500d8SDavid Howells 	spinlock_t		client_bundles_lock; /* Lock for client_bundles */
28517926a79SDavid Howells 	spinlock_t		lock;		/* access lock */
28617926a79SDavid Howells 	rwlock_t		services_lock;	/* lock for services list */
28717926a79SDavid Howells 	int			debug_id;	/* debug ID for printks */
2884f95dd78SDavid Howells 	bool			dead;
289f859ab61SDavid Howells 	bool			service_closed;	/* Service socket closed */
29017926a79SDavid Howells 	struct sockaddr_rxrpc	srx;		/* local address */
29117926a79SDavid Howells };
29217926a79SDavid Howells 
29317926a79SDavid Howells /*
29417926a79SDavid Howells  * RxRPC remote transport endpoint definition
295be6e6707SDavid Howells  * - matched by local endpoint, remote port, address and protocol type
29617926a79SDavid Howells  */
29717926a79SDavid Howells struct rxrpc_peer {
298be6e6707SDavid Howells 	struct rcu_head		rcu;		/* This must be first */
299a0575429SDavid Howells 	refcount_t		ref;
300be6e6707SDavid Howells 	unsigned long		hash_key;
301be6e6707SDavid Howells 	struct hlist_node	hash_link;
302be6e6707SDavid Howells 	struct rxrpc_local	*local;
303f66d7490SDavid Howells 	struct hlist_head	error_targets;	/* targets for net error distribution */
304aa390bbeSDavid Howells 	struct rb_root		service_conns;	/* Service connections */
305330bdcfaSDavid Howells 	struct list_head	keepalive_link;	/* Link in net->peer_keepalive[] */
306ace45becSDavid Howells 	time64_t		last_tx_at;	/* Last time packet sent here */
3078496af50SDavid Howells 	seqlock_t		service_conn_lock;
30817926a79SDavid Howells 	spinlock_t		lock;		/* access lock */
30995c96174SEric Dumazet 	unsigned int		if_mtu;		/* interface MTU for this peer */
31095c96174SEric Dumazet 	unsigned int		mtu;		/* network MTU for this peer */
31195c96174SEric Dumazet 	unsigned int		maxdata;	/* data size (MTU - hdrsize) */
31217926a79SDavid Howells 	unsigned short		hdrsize;	/* header size (IP + UDP + RxRPC) */
31317926a79SDavid Howells 	int			debug_id;	/* debug ID for printks */
31417926a79SDavid Howells 	struct sockaddr_rxrpc	srx;		/* remote address */
31517926a79SDavid Howells 
31617926a79SDavid Howells 	/* calculated RTT cache */
31717926a79SDavid Howells #define RXRPC_RTT_CACHE_SIZE 32
318c1e15b49SDavid Howells 	spinlock_t		rtt_input_lock;	/* RTT lock for input routine */
3190d4b103cSDavid Howells 	ktime_t			rtt_last_req;	/* Time of last RTT request */
320c410bf01SDavid Howells 	unsigned int		rtt_count;	/* Number of samples we've got */
321c410bf01SDavid Howells 
322c410bf01SDavid Howells 	u32			srtt_us;	/* smoothed round trip time << 3 in usecs */
323c410bf01SDavid Howells 	u32			mdev_us;	/* medium deviation			*/
324c410bf01SDavid Howells 	u32			mdev_max_us;	/* maximal mdev for the last rtt period	*/
325c410bf01SDavid Howells 	u32			rttvar_us;	/* smoothed mdev_max			*/
326c410bf01SDavid Howells 	u32			rto_j;		/* Retransmission timeout in jiffies */
327c410bf01SDavid Howells 	u8			backoff;	/* Backoff timeout */
328f7aec129SDavid Howells 
329f7aec129SDavid Howells 	u8			cong_cwnd;	/* Congestion window size */
33017926a79SDavid Howells };
33117926a79SDavid Howells 
33217926a79SDavid Howells /*
33319ffa01cSDavid Howells  * Keys for matching a connection.
33419ffa01cSDavid Howells  */
33519ffa01cSDavid Howells struct rxrpc_conn_proto {
336e8d70ce1SDavid Howells 	union {
337e8d70ce1SDavid Howells 		struct {
33819ffa01cSDavid Howells 			u32	epoch;		/* epoch of this connection */
33919ffa01cSDavid Howells 			u32	cid;		/* connection ID */
340e8d70ce1SDavid Howells 		};
341e8d70ce1SDavid Howells 		u64		index_key;
34219ffa01cSDavid Howells 	};
34319ffa01cSDavid Howells };
34419ffa01cSDavid Howells 
34519ffa01cSDavid Howells struct rxrpc_conn_parameters {
34619ffa01cSDavid Howells 	struct rxrpc_local	*local;		/* Representation of local endpoint */
34719ffa01cSDavid Howells 	struct rxrpc_peer	*peer;		/* Remote endpoint */
34819ffa01cSDavid Howells 	struct key		*key;		/* Security details */
34919ffa01cSDavid Howells 	bool			exclusive;	/* T if conn is exclusive */
3504e255721SDavid Howells 	bool			upgrade;	/* T if service ID can be upgraded */
35119ffa01cSDavid Howells 	u16			service_id;	/* Service ID for this connection */
35219ffa01cSDavid Howells 	u32			security_level;	/* Security level selected */
35319ffa01cSDavid Howells };
35419ffa01cSDavid Howells 
35519ffa01cSDavid Howells /*
356bba304dbSDavid Howells  * Bits in the connection flags.
357bba304dbSDavid Howells  */
358bba304dbSDavid Howells enum rxrpc_conn_flag {
359bba304dbSDavid Howells 	RXRPC_CONN_HAS_IDR,		/* Has a client conn ID assigned */
360001c1122SDavid Howells 	RXRPC_CONN_IN_SERVICE_CONNS,	/* Conn is in peer->service_conns */
36145025bceSDavid Howells 	RXRPC_CONN_DONT_REUSE,		/* Don't reuse this connection */
3624e255721SDavid Howells 	RXRPC_CONN_PROBING_FOR_UPGRADE,	/* Probing for service upgrade */
3633136ef49SDavid Howells 	RXRPC_CONN_FINAL_ACK_0,		/* Need final ACK for channel 0 */
3643136ef49SDavid Howells 	RXRPC_CONN_FINAL_ACK_1,		/* Need final ACK for channel 1 */
3653136ef49SDavid Howells 	RXRPC_CONN_FINAL_ACK_2,		/* Need final ACK for channel 2 */
3663136ef49SDavid Howells 	RXRPC_CONN_FINAL_ACK_3,		/* Need final ACK for channel 3 */
367bba304dbSDavid Howells };
368bba304dbSDavid Howells 
3693136ef49SDavid Howells #define RXRPC_CONN_FINAL_ACK_MASK ((1UL << RXRPC_CONN_FINAL_ACK_0) |	\
3703136ef49SDavid Howells 				   (1UL << RXRPC_CONN_FINAL_ACK_1) |	\
3713136ef49SDavid Howells 				   (1UL << RXRPC_CONN_FINAL_ACK_2) |	\
3723136ef49SDavid Howells 				   (1UL << RXRPC_CONN_FINAL_ACK_3))
3733136ef49SDavid Howells 
374bba304dbSDavid Howells /*
375bba304dbSDavid Howells  * Events that can be raised upon a connection.
376bba304dbSDavid Howells  */
377bba304dbSDavid Howells enum rxrpc_conn_event {
378bba304dbSDavid Howells 	RXRPC_CONN_EV_CHALLENGE,	/* Send challenge packet */
379bba304dbSDavid Howells };
380bba304dbSDavid Howells 
381bba304dbSDavid Howells /*
382bba304dbSDavid Howells  * The connection protocol state.
383bba304dbSDavid Howells  */
384bba304dbSDavid Howells enum rxrpc_conn_proto_state {
385bba304dbSDavid Howells 	RXRPC_CONN_UNUSED,		/* Connection not yet attempted */
386bba304dbSDavid Howells 	RXRPC_CONN_CLIENT,		/* Client connection */
38700e90712SDavid Howells 	RXRPC_CONN_SERVICE_PREALLOC,	/* Service connection preallocation */
388bba304dbSDavid Howells 	RXRPC_CONN_SERVICE_UNSECURED,	/* Service unsecured connection */
389bba304dbSDavid Howells 	RXRPC_CONN_SERVICE_CHALLENGING,	/* Service challenging for security */
390bba304dbSDavid Howells 	RXRPC_CONN_SERVICE,		/* Service secured connection */
391bba304dbSDavid Howells 	RXRPC_CONN_REMOTELY_ABORTED,	/* Conn aborted by peer */
392bba304dbSDavid Howells 	RXRPC_CONN_LOCALLY_ABORTED,	/* Conn aborted locally */
393bba304dbSDavid Howells 	RXRPC_CONN__NR_STATES
394bba304dbSDavid Howells };
395bba304dbSDavid Howells 
396bba304dbSDavid Howells /*
397245500d8SDavid Howells  * RxRPC client connection bundle.
398245500d8SDavid Howells  */
399245500d8SDavid Howells struct rxrpc_bundle {
400245500d8SDavid Howells 	struct rxrpc_conn_parameters params;
401a0575429SDavid Howells 	refcount_t		ref;
402245500d8SDavid Howells 	unsigned int		debug_id;
403245500d8SDavid Howells 	bool			try_upgrade;	/* True if the bundle is attempting upgrade */
404245500d8SDavid Howells 	bool			alloc_conn;	/* True if someone's getting a conn */
4058806245aSDavid Howells 	short			alloc_error;	/* Error from last conn allocation */
406245500d8SDavid Howells 	spinlock_t		channel_lock;
407245500d8SDavid Howells 	struct rb_node		local_node;	/* Node in local->client_conns */
408245500d8SDavid Howells 	struct list_head	waiting_calls;	/* Calls waiting for channels */
409245500d8SDavid Howells 	unsigned long		avail_chans;	/* Mask of available channels */
410245500d8SDavid Howells 	struct rxrpc_connection	*conns[4];	/* The connections in the bundle (max 4) */
411245500d8SDavid Howells };
412245500d8SDavid Howells 
413245500d8SDavid Howells /*
41417926a79SDavid Howells  * RxRPC connection definition
415aa390bbeSDavid Howells  * - matched by { local, peer, epoch, conn_id, direction }
41617926a79SDavid Howells  * - each connection can only handle four simultaneous calls
41717926a79SDavid Howells  */
41817926a79SDavid Howells struct rxrpc_connection {
41919ffa01cSDavid Howells 	struct rxrpc_conn_proto	proto;
42019ffa01cSDavid Howells 	struct rxrpc_conn_parameters params;
42119ffa01cSDavid Howells 
422a0575429SDavid Howells 	refcount_t		ref;
42345025bceSDavid Howells 	struct rcu_head		rcu;
42445025bceSDavid Howells 	struct list_head	cache_link;
425a1399f8bSDavid Howells 
426245500d8SDavid Howells 	unsigned char		act_chans;	/* Mask of active channels */
427a1399f8bSDavid Howells 	struct rxrpc_channel {
4283136ef49SDavid Howells 		unsigned long		final_ack_at;	/* Time at which to issue final ACK */
429a1399f8bSDavid Howells 		struct rxrpc_call __rcu	*call;		/* Active call */
4304764c0daSDavid Howells 		unsigned int		call_debug_id;	/* call->debug_id */
431a1399f8bSDavid Howells 		u32			call_id;	/* ID of current call */
432a1399f8bSDavid Howells 		u32			call_counter;	/* Call ID counter */
433a1399f8bSDavid Howells 		u32			last_call;	/* ID of last call */
43418bfeba5SDavid Howells 		u8			last_type;	/* Type of last packet */
43518bfeba5SDavid Howells 		union {
43618bfeba5SDavid Howells 			u32		last_seq;
43718bfeba5SDavid Howells 			u32		last_abort;
43818bfeba5SDavid Howells 		};
439a1399f8bSDavid Howells 	} channels[RXRPC_MAXCALLS];
440999b69f8SDavid Howells 
4413136ef49SDavid Howells 	struct timer_list	timer;		/* Conn event timer */
44217926a79SDavid Howells 	struct work_struct	processor;	/* connection event processor */
443245500d8SDavid Howells 	struct rxrpc_bundle	*bundle;	/* Client connection bundle */
444aa390bbeSDavid Howells 	struct rb_node		service_node;	/* Node in peer->service_conns */
4454d028b2cSDavid Howells 	struct list_head	proc_link;	/* link in procfs list */
44617926a79SDavid Howells 	struct list_head	link;		/* link in master connection list */
44717926a79SDavid Howells 	struct sk_buff_head	rx_queue;	/* received conn-level packets */
448521bb304SDavid Howells 
449648af7fcSDavid Howells 	const struct rxrpc_security *security;	/* applied security module */
450521bb304SDavid Howells 	union {
451521bb304SDavid Howells 		struct {
45269d826faSKees Cook 			struct crypto_sync_skcipher *cipher;	/* encryption handle */
45317926a79SDavid Howells 			struct rxrpc_crypt csum_iv;	/* packet checksum base */
454521bb304SDavid Howells 			u32	nonce;		/* response re-use preventer */
455521bb304SDavid Howells 		} rxkad;
456521bb304SDavid Howells 	};
4574a3388c8SDavid Howells 	unsigned long		flags;
45817926a79SDavid Howells 	unsigned long		events;
459f51b4480SDavid Howells 	unsigned long		idle_timestamp;	/* Time at which last became idle */
46017926a79SDavid Howells 	spinlock_t		state_lock;	/* state-change lock */
461cf13258fSDavid Howells 	enum rxrpc_conn_proto_state state;	/* current state of connection */
46264753092SDavid Howells 	u32			abort_code;	/* Abort code of connection abort */
46317926a79SDavid Howells 	int			debug_id;	/* debug ID for printks */
46417926a79SDavid Howells 	atomic_t		serial;		/* packet serial number counter */
465563ea7d5SDavid Howells 	unsigned int		hi_serial;	/* highest serial number received */
466c1e15b49SDavid Howells 	u32			service_id;	/* Service ID, possibly upgraded */
46717926a79SDavid Howells 	u8			security_ix;	/* security type */
46817926a79SDavid Howells 	u8			out_clientflag;	/* RXRPC_CLIENT_INITIATED if we are client */
469245500d8SDavid Howells 	u8			bundle_shift;	/* Index into bundle->avail_chans */
47064753092SDavid Howells 	short			error;		/* Local error code */
47117926a79SDavid Howells };
47217926a79SDavid Howells 
473dc71db34SDavid Howells static inline bool rxrpc_to_server(const struct rxrpc_skb_priv *sp)
474dc71db34SDavid Howells {
475dc71db34SDavid Howells 	return sp->hdr.flags & RXRPC_CLIENT_INITIATED;
476dc71db34SDavid Howells }
477dc71db34SDavid Howells 
478dc71db34SDavid Howells static inline bool rxrpc_to_client(const struct rxrpc_skb_priv *sp)
479dc71db34SDavid Howells {
480dc71db34SDavid Howells 	return !rxrpc_to_server(sp);
481dc71db34SDavid Howells }
482dc71db34SDavid Howells 
48317926a79SDavid Howells /*
4845b8848d1SDavid Howells  * Flags in call->flags.
4855b8848d1SDavid Howells  */
4865b8848d1SDavid Howells enum rxrpc_call_flag {
4875b8848d1SDavid Howells 	RXRPC_CALL_RELEASED,		/* call has been released - no more message to userspace */
4885b8848d1SDavid Howells 	RXRPC_CALL_HAS_USERID,		/* has a user ID attached */
489dabe5a79SDavid Howells 	RXRPC_CALL_IS_SERVICE,		/* Call is service call */
49045025bceSDavid Howells 	RXRPC_CALL_EXPOSED,		/* The call was exposed to the world */
491248f219cSDavid Howells 	RXRPC_CALL_RX_LAST,		/* Received the last packet (at rxtx_top) */
492248f219cSDavid Howells 	RXRPC_CALL_TX_LAST,		/* Last packet in Tx buffer (at rxtx_top) */
493a5af7e1fSDavid Howells 	RXRPC_CALL_SEND_PING,		/* A ping will need to be sent */
49457494343SDavid Howells 	RXRPC_CALL_RETRANS_TIMEOUT,	/* Retransmission due to timeout occurred */
495c54e43d7SDavid Howells 	RXRPC_CALL_BEGAN_RX_TIMER,	/* We began the expect_rx_by timer */
4961a025028SDavid Howells 	RXRPC_CALL_RX_HEARD,		/* The peer responded at least once to this call */
497d0b35a42SDavid Howells 	RXRPC_CALL_RX_UNDERRUN,		/* Got data underrun */
4985273a191SDavid Howells 	RXRPC_CALL_DISCONNECTED,	/* The call has been disconnected */
499b7a7d674SDavid Howells 	RXRPC_CALL_KERNEL,		/* The call was made by the kernel */
500245500d8SDavid Howells 	RXRPC_CALL_UPGRADE,		/* Service upgrade was requested for the call */
5015b8848d1SDavid Howells };
5025b8848d1SDavid Howells 
5035b8848d1SDavid Howells /*
5045b8848d1SDavid Howells  * Events that can be raised on a call.
5055b8848d1SDavid Howells  */
5065b8848d1SDavid Howells enum rxrpc_call_event {
5074c198ad1SDavid Howells 	RXRPC_CALL_EV_ACK,		/* need to generate ACK */
5084c198ad1SDavid Howells 	RXRPC_CALL_EV_ABORT,		/* need to generate abort */
5094c198ad1SDavid Howells 	RXRPC_CALL_EV_RESEND,		/* Tx resend required */
510a5af7e1fSDavid Howells 	RXRPC_CALL_EV_PING,		/* Ping send required */
511a158bdd3SDavid Howells 	RXRPC_CALL_EV_EXPIRED,		/* Expiry occurred */
512bd1fdf8cSDavid Howells 	RXRPC_CALL_EV_ACK_LOST,		/* ACK may be lost, send ping */
5135b8848d1SDavid Howells };
5145b8848d1SDavid Howells 
5155b8848d1SDavid Howells /*
5165b8848d1SDavid Howells  * The states that a call can be in.
5175b8848d1SDavid Howells  */
5185b8848d1SDavid Howells enum rxrpc_call_state {
519999b69f8SDavid Howells 	RXRPC_CALL_UNINITIALISED,
520999b69f8SDavid Howells 	RXRPC_CALL_CLIENT_AWAIT_CONN,	/* - client waiting for connection to become available */
5215b8848d1SDavid Howells 	RXRPC_CALL_CLIENT_SEND_REQUEST,	/* - client sending request phase */
5225b8848d1SDavid Howells 	RXRPC_CALL_CLIENT_AWAIT_REPLY,	/* - client awaiting reply */
5235b8848d1SDavid Howells 	RXRPC_CALL_CLIENT_RECV_REPLY,	/* - client receiving reply phase */
52400e90712SDavid Howells 	RXRPC_CALL_SERVER_PREALLOC,	/* - service preallocation */
5255b8848d1SDavid Howells 	RXRPC_CALL_SERVER_SECURING,	/* - server securing request connection */
5265b8848d1SDavid Howells 	RXRPC_CALL_SERVER_RECV_REQUEST,	/* - server receiving request */
5275b8848d1SDavid Howells 	RXRPC_CALL_SERVER_ACK_REQUEST,	/* - server pending ACK of request */
5285b8848d1SDavid Howells 	RXRPC_CALL_SERVER_SEND_REPLY,	/* - server sending reply */
5295b8848d1SDavid Howells 	RXRPC_CALL_SERVER_AWAIT_ACK,	/* - server awaiting final ACK */
530f5c17aaeSDavid Howells 	RXRPC_CALL_COMPLETE,		/* - call complete */
531f5c17aaeSDavid Howells 	NR__RXRPC_CALL_STATES
532f5c17aaeSDavid Howells };
533f5c17aaeSDavid Howells 
534f5c17aaeSDavid Howells /*
535e122d845SDavid Howells  * Call completion condition (state == RXRPC_CALL_COMPLETE).
536e122d845SDavid Howells  */
537e122d845SDavid Howells enum rxrpc_call_completion {
538e122d845SDavid Howells 	RXRPC_CALL_SUCCEEDED,		/* - Normal termination */
539e122d845SDavid Howells 	RXRPC_CALL_REMOTELY_ABORTED,	/* - call aborted by peer */
540e122d845SDavid Howells 	RXRPC_CALL_LOCALLY_ABORTED,	/* - call aborted locally on error or close */
541e122d845SDavid Howells 	RXRPC_CALL_LOCAL_ERROR,		/* - call failed due to local error */
542e122d845SDavid Howells 	RXRPC_CALL_NETWORK_ERROR,	/* - call terminated by network error */
543e122d845SDavid Howells 	NR__RXRPC_CALL_COMPLETIONS
544e122d845SDavid Howells };
545e122d845SDavid Howells 
546e122d845SDavid Howells /*
54757494343SDavid Howells  * Call Tx congestion management modes.
54857494343SDavid Howells  */
54957494343SDavid Howells enum rxrpc_congest_mode {
55057494343SDavid Howells 	RXRPC_CALL_SLOW_START,
55157494343SDavid Howells 	RXRPC_CALL_CONGEST_AVOIDANCE,
55257494343SDavid Howells 	RXRPC_CALL_PACKET_LOSS,
55357494343SDavid Howells 	RXRPC_CALL_FAST_RETRANSMIT,
55457494343SDavid Howells 	NR__RXRPC_CONGEST_MODES
55557494343SDavid Howells };
55657494343SDavid Howells 
55757494343SDavid Howells /*
55817926a79SDavid Howells  * RxRPC call definition
55917926a79SDavid Howells  * - matched by { connection, call_id }
56017926a79SDavid Howells  */
56117926a79SDavid Howells struct rxrpc_call {
562dee46364SDavid Howells 	struct rcu_head		rcu;
56317926a79SDavid Howells 	struct rxrpc_connection	*conn;		/* connection carrying call */
564df5d8bf7SDavid Howells 	struct rxrpc_peer	*peer;		/* Peer record for remote address */
5658d94aa38SDavid Howells 	struct rxrpc_sock __rcu	*socket;	/* socket responsible */
566d3be4d24SDavid Howells 	struct rxrpc_net	*rxnet;		/* Network namespace to which call belongs */
56791fcfbe8SDavid Howells 	const struct rxrpc_security *security;	/* applied security module */
568540b1c48SDavid Howells 	struct mutex		user_mutex;	/* User access mutex */
569a158bdd3SDavid Howells 	unsigned long		ack_at;		/* When deferred ACK needs to happen */
570bd1fdf8cSDavid Howells 	unsigned long		ack_lost_at;	/* When ACK is figured as lost */
571a158bdd3SDavid Howells 	unsigned long		resend_at;	/* When next resend needs to happen */
572a158bdd3SDavid Howells 	unsigned long		ping_at;	/* When next to send a ping */
573415f44e4SDavid Howells 	unsigned long		keepalive_at;	/* When next to send a keepalive ping */
574a158bdd3SDavid Howells 	unsigned long		expect_rx_by;	/* When we expect to get a packet by */
575a158bdd3SDavid Howells 	unsigned long		expect_req_by;	/* When we expect to get a request DATA packet by */
576a158bdd3SDavid Howells 	unsigned long		expect_term_by;	/* When we expect call termination by */
577a158bdd3SDavid Howells 	u32			next_rx_timo;	/* Timeout for next Rx packet (jif) */
578a158bdd3SDavid Howells 	u32			next_req_timo;	/* Timeout for next Rx request packet (jif) */
5791db88c53SDavid Howells 	struct skcipher_request	*cipher_req;	/* Packet cipher request buffer */
580248f219cSDavid Howells 	struct timer_list	timer;		/* Combined event timer */
581248f219cSDavid Howells 	struct work_struct	processor;	/* Event processor */
582d001648eSDavid Howells 	rxrpc_notify_rx_t	notify_rx;	/* kernel service Rx notification function */
58317926a79SDavid Howells 	struct list_head	link;		/* link in master call list */
584245500d8SDavid Howells 	struct list_head	chan_wait_link;	/* Link in conn->bundle->waiting_calls */
585f66d7490SDavid Howells 	struct hlist_node	error_link;	/* link in error distribution list */
586248f219cSDavid Howells 	struct list_head	accept_link;	/* Link in rx->acceptq */
587248f219cSDavid Howells 	struct list_head	recvmsg_link;	/* Link in rx->recvmsg_q */
588248f219cSDavid Howells 	struct list_head	sock_link;	/* Link in rx->sock_calls */
589248f219cSDavid Howells 	struct rb_node		sock_node;	/* Node in rx->calls */
59017926a79SDavid Howells 	struct sk_buff		*tx_pending;	/* Tx socket buffer being filled */
59145025bceSDavid Howells 	wait_queue_head_t	waitq;		/* Wait queue for channel or Tx */
592e754eba6SDavid Howells 	s64			tx_total_len;	/* Total length left to be transmitted (or -1) */
593a263629dSHerbert Xu 	__be32			crypto_buf[2];	/* Temporary packet crypto buffer */
59417926a79SDavid Howells 	unsigned long		user_call_ID;	/* user-defined call ID */
59517926a79SDavid Howells 	unsigned long		flags;
59617926a79SDavid Howells 	unsigned long		events;
59717926a79SDavid Howells 	spinlock_t		lock;
59820acbd9aSDavid Howells 	spinlock_t		notify_lock;	/* Kernel notification lock */
59917926a79SDavid Howells 	rwlock_t		state_lock;	/* lock for state transition */
600f5c17aaeSDavid Howells 	u32			abort_code;	/* Local/remote abort code */
601f5c17aaeSDavid Howells 	int			error;		/* Local error incurred */
602cf13258fSDavid Howells 	enum rxrpc_call_state	state;		/* current state of call */
603cf13258fSDavid Howells 	enum rxrpc_call_completion completion;	/* Call completion condition */
604a0575429SDavid Howells 	refcount_t		ref;
605dabe5a79SDavid Howells 	u16			service_id;	/* service ID */
606278ac0cdSDavid Howells 	u8			security_ix;	/* Security type */
607e138aa7dSDavid Howells 	enum rxrpc_interruptibility interruptibility; /* At what point call may be interrupted */
608dabe5a79SDavid Howells 	u32			call_id;	/* call ID on connection  */
609dabe5a79SDavid Howells 	u32			cid;		/* connection ID plus channel index */
610dabe5a79SDavid Howells 	int			debug_id;	/* debug ID for printks */
6118e83134dSDavid Howells 	unsigned short		rx_pkt_offset;	/* Current recvmsg packet offset */
6128e83134dSDavid Howells 	unsigned short		rx_pkt_len;	/* Current recvmsg packet len */
613f9c32435SDavid Howells 	bool			rx_pkt_last;	/* Current recvmsg packet is last */
61417926a79SDavid Howells 
615248f219cSDavid Howells 	/* Rx/Tx circular buffer, depending on phase.
616248f219cSDavid Howells 	 *
617248f219cSDavid Howells 	 * In the Rx phase, packets are annotated with 0 or the number of the
618248f219cSDavid Howells 	 * segment of a jumbo packet each buffer refers to.  There can be up to
619248f219cSDavid Howells 	 * 47 segments in a maximum-size UDP packet.
620248f219cSDavid Howells 	 *
621248f219cSDavid Howells 	 * In the Tx phase, packets are annotated with which buffers have been
622248f219cSDavid Howells 	 * acked.
62317926a79SDavid Howells 	 */
624248f219cSDavid Howells #define RXRPC_RXTX_BUFF_SIZE	64
625248f219cSDavid Howells #define RXRPC_RXTX_BUFF_MASK	(RXRPC_RXTX_BUFF_SIZE - 1)
6264075295aSDavid Howells #define RXRPC_INIT_RX_WINDOW_SIZE 63
627248f219cSDavid Howells 	struct sk_buff		**rxtx_buffer;
628248f219cSDavid Howells 	u8			*rxtx_annotations;
629248f219cSDavid Howells #define RXRPC_TX_ANNO_ACK	0
630248f219cSDavid Howells #define RXRPC_TX_ANNO_UNACK	1
631248f219cSDavid Howells #define RXRPC_TX_ANNO_NAK	2
632248f219cSDavid Howells #define RXRPC_TX_ANNO_RETRANS	3
633f07373eaSDavid Howells #define RXRPC_TX_ANNO_MASK	0x03
63470790dbeSDavid Howells #define RXRPC_TX_ANNO_LAST	0x04
63570790dbeSDavid Howells #define RXRPC_TX_ANNO_RESENT	0x08
63670790dbeSDavid Howells 
637e2de6c40SDavid Howells #define RXRPC_RX_ANNO_SUBPACKET	0x3f		/* Subpacket number in jumbogram */
638248f219cSDavid Howells #define RXRPC_RX_ANNO_VERIFIED	0x80		/* Set if verified and decrypted */
639248f219cSDavid Howells 	rxrpc_seq_t		tx_hard_ack;	/* Dead slot in buffer; the first transmitted but
640248f219cSDavid Howells 						 * not hard-ACK'd packet follows this.
641248f219cSDavid Howells 						 */
642248f219cSDavid Howells 	rxrpc_seq_t		tx_top;		/* Highest Tx slot allocated. */
643c7e86acfSDavid Howells 	u16			tx_backoff;	/* Delay to insert due to Tx failure */
64457494343SDavid Howells 
64557494343SDavid Howells 	/* TCP-style slow-start congestion control [RFC5681].  Since the SMSS
64657494343SDavid Howells 	 * is fixed, we keep these numbers in terms of segments (ie. DATA
64757494343SDavid Howells 	 * packets) rather than bytes.
64857494343SDavid Howells 	 */
64957494343SDavid Howells #define RXRPC_TX_SMSS		RXRPC_JUMBO_DATALEN
65057494343SDavid Howells 	u8			cong_cwnd;	/* Congestion window size */
65157494343SDavid Howells 	u8			cong_extra;	/* Extra to send for congestion management */
65257494343SDavid Howells 	u8			cong_ssthresh;	/* Slow-start threshold */
65357494343SDavid Howells 	enum rxrpc_congest_mode	cong_mode:8;	/* Congestion management mode */
65457494343SDavid Howells 	u8			cong_dup_acks;	/* Count of ACKs showing missing packets */
65557494343SDavid Howells 	u8			cong_cumul_acks; /* Cumulative ACK count */
65657494343SDavid Howells 	ktime_t			cong_tstamp;	/* Last time cwnd was changed */
65757494343SDavid Howells 
658248f219cSDavid Howells 	rxrpc_seq_t		rx_hard_ack;	/* Dead slot in buffer; the first received but not
659248f219cSDavid Howells 						 * consumed packet follows this.
660248f219cSDavid Howells 						 */
661248f219cSDavid Howells 	rxrpc_seq_t		rx_top;		/* Highest Rx slot allocated. */
662248f219cSDavid Howells 	rxrpc_seq_t		rx_expect_next;	/* Expected next packet sequence number */
6631a025028SDavid Howells 	rxrpc_serial_t		rx_serial;	/* Highest serial received for this call */
664248f219cSDavid Howells 	u8			rx_winsize;	/* Size of Rx window */
665248f219cSDavid Howells 	u8			tx_winsize;	/* Maximum size of Tx window */
66671f3ca40SDavid Howells 	bool			tx_phase;	/* T if transmission phase, F if receive phase */
66775e42126SDavid Howells 	u8			nr_jumbo_bad;	/* Number of jumbo dups/exceeds-windows */
66817926a79SDavid Howells 
669c1e15b49SDavid Howells 	spinlock_t		input_lock;	/* Lock for packet input to this call */
670c1e15b49SDavid Howells 
67117926a79SDavid Howells 	/* receive-phase ACK management */
6724e36a95eSDavid Howells 	u8			ackr_reason;	/* reason to ACK */
6730d12f8a4SDavid Howells 	rxrpc_serial_t		ackr_serial;	/* serial of packet being ACK'd */
6741a2391c3SJeffrey Altman 	rxrpc_serial_t		ackr_first_seq;	/* first sequence number received */
675248f219cSDavid Howells 	rxrpc_seq_t		ackr_prev_seq;	/* previous sequence number received */
676805b21b9SDavid Howells 	rxrpc_seq_t		ackr_consumed;	/* Highest packet shown consumed */
677805b21b9SDavid Howells 	rxrpc_seq_t		ackr_seen;	/* Highest packet shown seen */
678a5af7e1fSDavid Howells 
6794700c4d8SDavid Howells 	/* RTT management */
6804700c4d8SDavid Howells 	rxrpc_serial_t		rtt_serial[4];	/* Serial number of DATA or PING sent */
6814700c4d8SDavid Howells 	ktime_t			rtt_sent_at[4];	/* Time packet sent */
6824700c4d8SDavid Howells 	unsigned long		rtt_avail;	/* Mask of available slots in bits 0-3,
6834700c4d8SDavid Howells 						 * Mask of pending samples in 8-11 */
6844700c4d8SDavid Howells #define RXRPC_CALL_RTT_AVAIL_MASK	0xf
6854700c4d8SDavid Howells #define RXRPC_CALL_RTT_PEND_SHIFT	8
68617926a79SDavid Howells 
687248f219cSDavid Howells 	/* transmission-phase ACK management */
68857494343SDavid Howells 	ktime_t			acks_latest_ts;	/* Timestamp of latest ACK received */
68931a1b989SDavid Howells 	rxrpc_seq_t		acks_lowest_nak; /* Lowest NACK in the buffer (or ==tx_hard_ack) */
690bd1fdf8cSDavid Howells 	rxrpc_seq_t		acks_lost_top;	/* tx_top at the time lost-ack ping sent */
691bd1fdf8cSDavid Howells 	rxrpc_serial_t		acks_lost_ping;	/* Serial number of probe ACK */
69231a1b989SDavid Howells };
69331a1b989SDavid Howells 
69431a1b989SDavid Howells /*
69557494343SDavid Howells  * Summary of a new ACK and the changes it made to the Tx buffer packet states.
69631a1b989SDavid Howells  */
69731a1b989SDavid Howells struct rxrpc_ack_summary {
69831a1b989SDavid Howells 	u8			ack_reason;
69931a1b989SDavid Howells 	u8			nr_acks;		/* Number of ACKs in packet */
70031a1b989SDavid Howells 	u8			nr_nacks;		/* Number of NACKs in packet */
70131a1b989SDavid Howells 	u8			nr_new_acks;		/* Number of new ACKs in packet */
70231a1b989SDavid Howells 	u8			nr_new_nacks;		/* Number of new NACKs in packet */
70331a1b989SDavid Howells 	u8			nr_rot_new_acks;	/* Number of rotated new ACKs */
70431a1b989SDavid Howells 	bool			new_low_nack;		/* T if new low NACK found */
70557494343SDavid Howells 	bool			retrans_timeo;		/* T if reTx due to timeout happened */
70657494343SDavid Howells 	u8			flight_size;		/* Number of unreceived transmissions */
70757494343SDavid Howells 	/* Place to stash values for tracing */
70857494343SDavid Howells 	enum rxrpc_congest_mode	mode:8;
70957494343SDavid Howells 	u8			cwnd;
71057494343SDavid Howells 	u8			ssthresh;
71157494343SDavid Howells 	u8			dup_acks;
71257494343SDavid Howells 	u8			cumulative_acks;
71317926a79SDavid Howells };
71417926a79SDavid Howells 
71548124178SDavid Howells /*
71648124178SDavid Howells  * sendmsg() cmsg-specified parameters.
71748124178SDavid Howells  */
71848124178SDavid Howells enum rxrpc_command {
71948124178SDavid Howells 	RXRPC_CMD_SEND_DATA,		/* send data message */
72048124178SDavid Howells 	RXRPC_CMD_SEND_ABORT,		/* request abort generation */
72148124178SDavid Howells 	RXRPC_CMD_REJECT_BUSY,		/* [server] reject a call as busy */
7222d914c1bSDavid Howells 	RXRPC_CMD_CHARGE_ACCEPT,	/* [server] charge accept preallocation */
72348124178SDavid Howells };
72448124178SDavid Howells 
72548124178SDavid Howells struct rxrpc_call_params {
72648124178SDavid Howells 	s64			tx_total_len;	/* Total Tx data length (if send data) */
72748124178SDavid Howells 	unsigned long		user_call_ID;	/* User's call ID */
72848124178SDavid Howells 	struct {
72948124178SDavid Howells 		u32		hard;		/* Maximum lifetime (sec) */
73048124178SDavid Howells 		u32		idle;		/* Max time since last data packet (msec) */
73148124178SDavid Howells 		u32		normal;		/* Max time since last call packet (msec) */
73248124178SDavid Howells 	} timeouts;
73348124178SDavid Howells 	u8			nr_timeouts;	/* Number of timeouts specified */
734b7a7d674SDavid Howells 	bool			kernel;		/* T if kernel is making the call */
735e138aa7dSDavid Howells 	enum rxrpc_interruptibility interruptibility; /* How is interruptible is the call? */
73648124178SDavid Howells };
73748124178SDavid Howells 
73848124178SDavid Howells struct rxrpc_send_params {
73948124178SDavid Howells 	struct rxrpc_call_params call;
74048124178SDavid Howells 	u32			abort_code;	/* Abort code to Tx (if abort) */
74148124178SDavid Howells 	enum rxrpc_command	command : 8;	/* The command to implement */
74248124178SDavid Howells 	bool			exclusive;	/* Shared or exclusive call */
74348124178SDavid Howells 	bool			upgrade;	/* If the connection is upgradeable */
74448124178SDavid Howells };
74548124178SDavid Howells 
746df844fd4SDavid Howells #include <trace/events/rxrpc.h>
747df844fd4SDavid Howells 
74817926a79SDavid Howells /*
749651350d1SDavid Howells  * af_rxrpc.c
75017926a79SDavid Howells  */
75171f3ca40SDavid Howells extern atomic_t rxrpc_n_tx_skbs, rxrpc_n_rx_skbs;
752651350d1SDavid Howells extern struct workqueue_struct *rxrpc_workqueue;
75317926a79SDavid Howells 
75417926a79SDavid Howells /*
7550d81a51aSDavid Howells  * call_accept.c
75617926a79SDavid Howells  */
75700e90712SDavid Howells int rxrpc_service_prealloc(struct rxrpc_sock *, gfp_t);
75800e90712SDavid Howells void rxrpc_discard_prealloc(struct rxrpc_sock *);
759248f219cSDavid Howells struct rxrpc_call *rxrpc_new_incoming_call(struct rxrpc_local *,
7600099dc58SDavid Howells 					   struct rxrpc_sock *,
761248f219cSDavid Howells 					   struct sk_buff *);
7624f95dd78SDavid Howells void rxrpc_accept_incoming_calls(struct rxrpc_local *);
7632d914c1bSDavid Howells int rxrpc_user_charge_accept(struct rxrpc_sock *, unsigned long);
76417926a79SDavid Howells 
76517926a79SDavid Howells /*
7660d81a51aSDavid Howells  * call_event.c
76717926a79SDavid Howells  */
768e8c3af6bSDavid Howells void rxrpc_propose_ACK(struct rxrpc_call *, u8, u32, bool, bool,
7699c7ad434SDavid Howells 		       enum rxrpc_propose_ack_trace);
770c1b1203dSJoe Perches void rxrpc_process_call(struct work_struct *);
77117926a79SDavid Howells 
7724a7f62f9SDavid Howells void rxrpc_reduce_call_timer(struct rxrpc_call *call,
773a158bdd3SDavid Howells 			     unsigned long expire_at,
774a158bdd3SDavid Howells 			     unsigned long now,
7754a7f62f9SDavid Howells 			     enum rxrpc_timer_trace why);
7764a7f62f9SDavid Howells 
7774a7f62f9SDavid Howells void rxrpc_delete_call_timer(struct rxrpc_call *call);
778a158bdd3SDavid Howells 
77917926a79SDavid Howells /*
7800d81a51aSDavid Howells  * call_object.c
78117926a79SDavid Howells  */
782f5c17aaeSDavid Howells extern const char *const rxrpc_call_states[];
783f5c17aaeSDavid Howells extern const char *const rxrpc_call_completions[];
784dad8aff7SDavid Howells extern unsigned int rxrpc_max_call_lifetime;
78517926a79SDavid Howells extern struct kmem_cache *rxrpc_call_jar;
78617926a79SDavid Howells 
7872341e077SDavid Howells struct rxrpc_call *rxrpc_find_call_by_user_ID(struct rxrpc_sock *, unsigned long);
788a25e21f0SDavid Howells struct rxrpc_call *rxrpc_alloc_call(struct rxrpc_sock *, gfp_t, unsigned int);
7892341e077SDavid Howells struct rxrpc_call *rxrpc_new_client_call(struct rxrpc_sock *,
79019ffa01cSDavid Howells 					 struct rxrpc_conn_parameters *,
791999b69f8SDavid Howells 					 struct sockaddr_rxrpc *,
792a25e21f0SDavid Howells 					 struct rxrpc_call_params *, gfp_t,
793a25e21f0SDavid Howells 					 unsigned int);
794248f219cSDavid Howells void rxrpc_incoming_call(struct rxrpc_sock *, struct rxrpc_call *,
79542886ffeSDavid Howells 			 struct sk_buff *);
7968d94aa38SDavid Howells void rxrpc_release_call(struct rxrpc_sock *, struct rxrpc_call *);
797c1b1203dSJoe Perches void rxrpc_release_calls_on_socket(struct rxrpc_sock *);
7988d94aa38SDavid Howells bool __rxrpc_queue_call(struct rxrpc_call *);
7998d94aa38SDavid Howells bool rxrpc_queue_call(struct rxrpc_call *);
800e34d4234SDavid Howells void rxrpc_see_call(struct rxrpc_call *);
8014a7f62f9SDavid Howells bool rxrpc_try_get_call(struct rxrpc_call *call, enum rxrpc_call_trace op);
802fff72429SDavid Howells void rxrpc_get_call(struct rxrpc_call *, enum rxrpc_call_trace);
803fff72429SDavid Howells void rxrpc_put_call(struct rxrpc_call *, enum rxrpc_call_trace);
80400e90712SDavid Howells void rxrpc_cleanup_call(struct rxrpc_call *);
8052baec2c3SDavid Howells void rxrpc_destroy_all_calls(struct rxrpc_net *);
80617926a79SDavid Howells 
807dabe5a79SDavid Howells static inline bool rxrpc_is_service_call(const struct rxrpc_call *call)
808dabe5a79SDavid Howells {
809dabe5a79SDavid Howells 	return test_bit(RXRPC_CALL_IS_SERVICE, &call->flags);
810dabe5a79SDavid Howells }
811dabe5a79SDavid Howells 
812dabe5a79SDavid Howells static inline bool rxrpc_is_client_call(const struct rxrpc_call *call)
813dabe5a79SDavid Howells {
814dabe5a79SDavid Howells 	return !rxrpc_is_service_call(call);
815dabe5a79SDavid Howells }
816dabe5a79SDavid Howells 
81717926a79SDavid Howells /*
8184a3388c8SDavid Howells  * conn_client.c
8194a3388c8SDavid Howells  */
82045025bceSDavid Howells extern unsigned int rxrpc_reap_client_connections;
821a158bdd3SDavid Howells extern unsigned long rxrpc_conn_idle_client_expiry;
822a158bdd3SDavid Howells extern unsigned long rxrpc_conn_idle_client_fast_expiry;
8234a3388c8SDavid Howells extern struct idr rxrpc_client_conn_ids;
8244a3388c8SDavid Howells 
825eb9b9d22SDavid Howells void rxrpc_destroy_client_conn_ids(void);
826245500d8SDavid Howells struct rxrpc_bundle *rxrpc_get_bundle(struct rxrpc_bundle *);
827245500d8SDavid Howells void rxrpc_put_bundle(struct rxrpc_bundle *);
8285e33a23bSDavid Howells int rxrpc_connect_call(struct rxrpc_sock *, struct rxrpc_call *,
8295e33a23bSDavid Howells 		       struct rxrpc_conn_parameters *, struct sockaddr_rxrpc *,
8305e33a23bSDavid Howells 		       gfp_t);
83145025bceSDavid Howells void rxrpc_expose_client_call(struct rxrpc_call *);
832245500d8SDavid Howells void rxrpc_disconnect_client_call(struct rxrpc_bundle *, struct rxrpc_call *);
83345025bceSDavid Howells void rxrpc_put_client_conn(struct rxrpc_connection *);
8342baec2c3SDavid Howells void rxrpc_discard_expired_client_conns(struct work_struct *);
8352baec2c3SDavid Howells void rxrpc_destroy_all_client_connections(struct rxrpc_net *);
836d12040b6SDavid Howells void rxrpc_clean_up_local_conns(struct rxrpc_local *);
8374a3388c8SDavid Howells 
8384a3388c8SDavid Howells /*
8390d81a51aSDavid Howells  * conn_event.c
8400d81a51aSDavid Howells  */
8410d81a51aSDavid Howells void rxrpc_process_connection(struct work_struct *);
842ddc7834aSDavid Howells void rxrpc_process_delayed_final_acks(struct rxrpc_connection *, bool);
8430d81a51aSDavid Howells 
8440d81a51aSDavid Howells /*
8450d81a51aSDavid Howells  * conn_object.c
84617926a79SDavid Howells  */
847dad8aff7SDavid Howells extern unsigned int rxrpc_connection_expiry;
848f859ab61SDavid Howells extern unsigned int rxrpc_closed_conn_expiry;
84917926a79SDavid Howells 
850c6d2b8d7SDavid Howells struct rxrpc_connection *rxrpc_alloc_connection(gfp_t);
8518496af50SDavid Howells struct rxrpc_connection *rxrpc_find_connection_rcu(struct rxrpc_local *,
8520099dc58SDavid Howells 						   struct sk_buff *,
8530099dc58SDavid Howells 						   struct rxrpc_peer **);
85445025bceSDavid Howells void __rxrpc_disconnect_call(struct rxrpc_connection *, struct rxrpc_call *);
855999b69f8SDavid Howells void rxrpc_disconnect_call(struct rxrpc_call *);
85645025bceSDavid Howells void rxrpc_kill_connection(struct rxrpc_connection *);
857363deeabSDavid Howells bool rxrpc_queue_conn(struct rxrpc_connection *);
858363deeabSDavid Howells void rxrpc_see_connection(struct rxrpc_connection *);
859245500d8SDavid Howells struct rxrpc_connection *rxrpc_get_connection(struct rxrpc_connection *);
860363deeabSDavid Howells struct rxrpc_connection *rxrpc_get_connection_maybe(struct rxrpc_connection *);
861363deeabSDavid Howells void rxrpc_put_service_conn(struct rxrpc_connection *);
8622baec2c3SDavid Howells void rxrpc_service_connection_reaper(struct work_struct *);
8632baec2c3SDavid Howells void rxrpc_destroy_all_connections(struct rxrpc_net *);
86417926a79SDavid Howells 
86519ffa01cSDavid Howells static inline bool rxrpc_conn_is_client(const struct rxrpc_connection *conn)
86619ffa01cSDavid Howells {
86719ffa01cSDavid Howells 	return conn->out_clientflag;
86819ffa01cSDavid Howells }
86919ffa01cSDavid Howells 
87019ffa01cSDavid Howells static inline bool rxrpc_conn_is_service(const struct rxrpc_connection *conn)
87119ffa01cSDavid Howells {
872e8d70ce1SDavid Howells 	return !rxrpc_conn_is_client(conn);
87319ffa01cSDavid Howells }
87419ffa01cSDavid Howells 
875f51b4480SDavid Howells static inline void rxrpc_put_connection(struct rxrpc_connection *conn)
876f51b4480SDavid Howells {
87745025bceSDavid Howells 	if (!conn)
87845025bceSDavid Howells 		return;
87945025bceSDavid Howells 
880363deeabSDavid Howells 	if (rxrpc_conn_is_client(conn))
88145025bceSDavid Howells 		rxrpc_put_client_conn(conn);
882363deeabSDavid Howells 	else
883363deeabSDavid Howells 		rxrpc_put_service_conn(conn);
8845acbee46SDavid Howells }
8855acbee46SDavid Howells 
8863136ef49SDavid Howells static inline void rxrpc_reduce_conn_timer(struct rxrpc_connection *conn,
8873136ef49SDavid Howells 					   unsigned long expire_at)
8883136ef49SDavid Howells {
8893136ef49SDavid Howells 	timer_reduce(&conn->timer, expire_at);
8903136ef49SDavid Howells }
8913136ef49SDavid Howells 
89217926a79SDavid Howells /*
8937877a4a4SDavid Howells  * conn_service.c
8947877a4a4SDavid Howells  */
8958496af50SDavid Howells struct rxrpc_connection *rxrpc_find_service_conn_rcu(struct rxrpc_peer *,
8968496af50SDavid Howells 						     struct sk_buff *);
8972baec2c3SDavid Howells struct rxrpc_connection *rxrpc_prealloc_service_connection(struct rxrpc_net *, gfp_t);
898063c60d3SDavid Howells void rxrpc_new_incoming_connection(struct rxrpc_sock *, struct rxrpc_connection *,
899ec832bd0SDavid Howells 				   const struct rxrpc_security *, struct sk_buff *);
900001c1122SDavid Howells void rxrpc_unpublish_service_conn(struct rxrpc_connection *);
9017877a4a4SDavid Howells 
9027877a4a4SDavid Howells /*
9030d81a51aSDavid Howells  * input.c
90417926a79SDavid Howells  */
9055271953cSDavid Howells int rxrpc_input_packet(struct sock *, struct sk_buff *);
90617926a79SDavid Howells 
90717926a79SDavid Howells /*
9080d81a51aSDavid Howells  * insecure.c
90917926a79SDavid Howells  */
9100d81a51aSDavid Howells extern const struct rxrpc_security rxrpc_no_security;
91117926a79SDavid Howells 
91217926a79SDavid Howells /*
9130d81a51aSDavid Howells  * key.c
91417926a79SDavid Howells  */
91517926a79SDavid Howells extern struct key_type key_type_rxrpc;
91617926a79SDavid Howells 
917a7b75c5aSChristoph Hellwig int rxrpc_request_key(struct rxrpc_sock *, sockptr_t , int);
91810674a03SBaolin Wang int rxrpc_get_server_data_key(struct rxrpc_connection *, const void *, time64_t,
919c1b1203dSJoe Perches 			      u32);
92017926a79SDavid Howells 
92117926a79SDavid Howells /*
92287563616SDavid Howells  * local_event.c
92387563616SDavid Howells  */
9244f95dd78SDavid Howells extern void rxrpc_process_local_events(struct rxrpc_local *);
92587563616SDavid Howells 
92687563616SDavid Howells /*
9270d81a51aSDavid Howells  * local_object.c
92817926a79SDavid Howells  */
9292baec2c3SDavid Howells struct rxrpc_local *rxrpc_lookup_local(struct net *, const struct sockaddr_rxrpc *);
93009d2bf59SDavid Howells struct rxrpc_local *rxrpc_get_local(struct rxrpc_local *);
93109d2bf59SDavid Howells struct rxrpc_local *rxrpc_get_local_maybe(struct rxrpc_local *);
93209d2bf59SDavid Howells void rxrpc_put_local(struct rxrpc_local *);
933730c5fd4SDavid Howells struct rxrpc_local *rxrpc_use_local(struct rxrpc_local *);
934730c5fd4SDavid Howells void rxrpc_unuse_local(struct rxrpc_local *);
93509d2bf59SDavid Howells void rxrpc_queue_local(struct rxrpc_local *);
9362baec2c3SDavid Howells void rxrpc_destroy_all_locals(struct rxrpc_net *);
937e0e4d82fSDavid Howells 
93804d36d74SDavid Howells static inline bool __rxrpc_unuse_local(struct rxrpc_local *local)
93904d36d74SDavid Howells {
94004d36d74SDavid Howells 	return atomic_dec_return(&local->active_users) == 0;
94104d36d74SDavid Howells }
94204d36d74SDavid Howells 
94304d36d74SDavid Howells static inline bool __rxrpc_use_local(struct rxrpc_local *local)
94404d36d74SDavid Howells {
94504d36d74SDavid Howells 	return atomic_fetch_add_unless(&local->active_users, 1, 0) != 0;
94604d36d74SDavid Howells }
94704d36d74SDavid Howells 
948e0e4d82fSDavid Howells /*
9498e688d9cSDavid Howells  * misc.c
9508e688d9cSDavid Howells  */
9510e119b41SDavid Howells extern unsigned int rxrpc_max_backlog __read_mostly;
952a158bdd3SDavid Howells extern unsigned long rxrpc_requested_ack_delay;
953a158bdd3SDavid Howells extern unsigned long rxrpc_soft_ack_delay;
954a158bdd3SDavid Howells extern unsigned long rxrpc_idle_ack_delay;
9558e688d9cSDavid Howells extern unsigned int rxrpc_rx_window_size;
9568e688d9cSDavid Howells extern unsigned int rxrpc_rx_mtu;
9578e688d9cSDavid Howells extern unsigned int rxrpc_rx_jumbo_max;
9588e688d9cSDavid Howells 
9598e688d9cSDavid Howells extern const s8 rxrpc_ack_priority[];
9608e688d9cSDavid Howells 
9618e688d9cSDavid Howells /*
9622baec2c3SDavid Howells  * net_ns.c
9632baec2c3SDavid Howells  */
9642baec2c3SDavid Howells extern unsigned int rxrpc_net_id;
9652baec2c3SDavid Howells extern struct pernet_operations rxrpc_net_ops;
9662baec2c3SDavid Howells 
9672baec2c3SDavid Howells static inline struct rxrpc_net *rxrpc_net(struct net *net)
9682baec2c3SDavid Howells {
9692baec2c3SDavid Howells 	return net_generic(net, rxrpc_net_id);
9702baec2c3SDavid Howells }
9712baec2c3SDavid Howells 
9722baec2c3SDavid Howells /*
9730d81a51aSDavid Howells  * output.c
9740d81a51aSDavid Howells  */
975bd1fdf8cSDavid Howells int rxrpc_send_ack_packet(struct rxrpc_call *, bool, rxrpc_serial_t *);
97626cb02aaSDavid Howells int rxrpc_send_abort_packet(struct rxrpc_call *);
977a1767077SDavid Howells int rxrpc_send_data_packet(struct rxrpc_call *, struct sk_buff *, bool);
978248f219cSDavid Howells void rxrpc_reject_packets(struct rxrpc_local *);
979ace45becSDavid Howells void rxrpc_send_keepalive(struct rxrpc_peer *);
9800d81a51aSDavid Howells 
9810d81a51aSDavid Howells /*
982abe89ef0SDavid Howells  * peer_event.c
9830d81a51aSDavid Howells  */
984abe89ef0SDavid Howells void rxrpc_error_report(struct sock *);
985ace45becSDavid Howells void rxrpc_peer_keepalive_worker(struct work_struct *);
9860d81a51aSDavid Howells 
9870d81a51aSDavid Howells /*
9880d81a51aSDavid Howells  * peer_object.c
9890d81a51aSDavid Howells  */
990be6e6707SDavid Howells struct rxrpc_peer *rxrpc_lookup_peer_rcu(struct rxrpc_local *,
991be6e6707SDavid Howells 					 const struct sockaddr_rxrpc *);
9925e33a23bSDavid Howells struct rxrpc_peer *rxrpc_lookup_peer(struct rxrpc_sock *, struct rxrpc_local *,
993be6e6707SDavid Howells 				     struct sockaddr_rxrpc *, gfp_t);
994be6e6707SDavid Howells struct rxrpc_peer *rxrpc_alloc_peer(struct rxrpc_local *, gfp_t);
9955e33a23bSDavid Howells void rxrpc_new_incoming_peer(struct rxrpc_sock *, struct rxrpc_local *,
9965e33a23bSDavid Howells 			     struct rxrpc_peer *);
99717226f12SDavid Howells void rxrpc_destroy_all_peers(struct rxrpc_net *);
9981159d4b4SDavid Howells struct rxrpc_peer *rxrpc_get_peer(struct rxrpc_peer *);
9991159d4b4SDavid Howells struct rxrpc_peer *rxrpc_get_peer_maybe(struct rxrpc_peer *);
10001159d4b4SDavid Howells void rxrpc_put_peer(struct rxrpc_peer *);
100160034d3dSDavid Howells void rxrpc_put_peer_locked(struct rxrpc_peer *);
10020d81a51aSDavid Howells 
10030d81a51aSDavid Howells /*
10040d81a51aSDavid Howells  * proc.c
10050d81a51aSDavid Howells  */
1006c3506372SChristoph Hellwig extern const struct seq_operations rxrpc_call_seq_ops;
1007c3506372SChristoph Hellwig extern const struct seq_operations rxrpc_connection_seq_ops;
1008bc0e7cf4SDavid Howells extern const struct seq_operations rxrpc_peer_seq_ops;
100933912c26SDavid Howells extern const struct seq_operations rxrpc_local_seq_ops;
10100d81a51aSDavid Howells 
10110d81a51aSDavid Howells /*
10120d81a51aSDavid Howells  * recvmsg.c
10130d81a51aSDavid Howells  */
1014248f219cSDavid Howells void rxrpc_notify_socket(struct rxrpc_call *);
10153067bf8cSDavid Howells bool __rxrpc_set_call_completion(struct rxrpc_call *, enum rxrpc_call_completion, u32, int);
10163067bf8cSDavid Howells bool rxrpc_set_call_completion(struct rxrpc_call *, enum rxrpc_call_completion, u32, int);
10173067bf8cSDavid Howells bool __rxrpc_call_completed(struct rxrpc_call *);
10183067bf8cSDavid Howells bool rxrpc_call_completed(struct rxrpc_call *);
10193067bf8cSDavid Howells bool __rxrpc_abort_call(const char *, struct rxrpc_call *, rxrpc_seq_t, u32, int);
10203067bf8cSDavid Howells bool rxrpc_abort_call(const char *, struct rxrpc_call *, rxrpc_seq_t, u32, int);
10210d81a51aSDavid Howells int rxrpc_recvmsg(struct socket *, struct msghdr *, size_t, int);
10220d81a51aSDavid Howells 
10230d81a51aSDavid Howells /*
10243067bf8cSDavid Howells  * Abort a call due to a protocol error.
10253067bf8cSDavid Howells  */
10263067bf8cSDavid Howells static inline bool __rxrpc_abort_eproto(struct rxrpc_call *call,
10273067bf8cSDavid Howells 					struct sk_buff *skb,
10283067bf8cSDavid Howells 					const char *eproto_why,
10293067bf8cSDavid Howells 					const char *why,
10303067bf8cSDavid Howells 					u32 abort_code)
10313067bf8cSDavid Howells {
10323067bf8cSDavid Howells 	struct rxrpc_skb_priv *sp = rxrpc_skb(skb);
10333067bf8cSDavid Howells 
10343067bf8cSDavid Howells 	trace_rxrpc_rx_eproto(call, sp->hdr.serial, eproto_why);
10353067bf8cSDavid Howells 	return rxrpc_abort_call(why, call, sp->hdr.seq, abort_code, -EPROTO);
10363067bf8cSDavid Howells }
10373067bf8cSDavid Howells 
10383067bf8cSDavid Howells #define rxrpc_abort_eproto(call, skb, eproto_why, abort_why, abort_code) \
10393067bf8cSDavid Howells 	__rxrpc_abort_eproto((call), (skb), tracepoint_string(eproto_why), \
10403067bf8cSDavid Howells 			     (abort_why), (abort_code))
10413067bf8cSDavid Howells 
10423067bf8cSDavid Howells /*
1043c410bf01SDavid Howells  * rtt.c
1044c410bf01SDavid Howells  */
10454700c4d8SDavid Howells void rxrpc_peer_add_rtt(struct rxrpc_call *, enum rxrpc_rtt_rx_trace, int,
1046c410bf01SDavid Howells 			rxrpc_serial_t, rxrpc_serial_t, ktime_t, ktime_t);
1047c410bf01SDavid Howells unsigned long rxrpc_get_rto_backoff(struct rxrpc_peer *, bool);
1048c410bf01SDavid Howells void rxrpc_peer_init_rtt(struct rxrpc_peer *);
1049c410bf01SDavid Howells 
1050c410bf01SDavid Howells /*
1051648af7fcSDavid Howells  * rxkad.c
1052648af7fcSDavid Howells  */
1053648af7fcSDavid Howells #ifdef CONFIG_RXKAD
1054648af7fcSDavid Howells extern const struct rxrpc_security rxkad;
1055648af7fcSDavid Howells #endif
1056648af7fcSDavid Howells 
1057648af7fcSDavid Howells /*
10580d81a51aSDavid Howells  * security.c
10590d81a51aSDavid Howells  */
10600d81a51aSDavid Howells int __init rxrpc_init_security(void);
106112da59fcSDavid Howells const struct rxrpc_security *rxrpc_security_lookup(u8);
10620d81a51aSDavid Howells void rxrpc_exit_security(void);
10630d81a51aSDavid Howells int rxrpc_init_client_conn_security(struct rxrpc_connection *);
1064ec832bd0SDavid Howells const struct rxrpc_security *rxrpc_get_incoming_security(struct rxrpc_sock *,
1065063c60d3SDavid Howells 							 struct sk_buff *);
1066ec832bd0SDavid Howells struct key *rxrpc_look_up_server_security(struct rxrpc_connection *,
1067ec832bd0SDavid Howells 					  struct sk_buff *, u32, u32);
10680d81a51aSDavid Howells 
10690d81a51aSDavid Howells /*
10700b58b8a1SDavid Howells  * sendmsg.c
10710b58b8a1SDavid Howells  */
10720b58b8a1SDavid Howells int rxrpc_do_sendmsg(struct rxrpc_sock *, struct msghdr *, size_t);
10730b58b8a1SDavid Howells 
10740b58b8a1SDavid Howells /*
1075ca7fb100SDavid Howells  * server_key.c
1076ca7fb100SDavid Howells  */
1077ca7fb100SDavid Howells extern struct key_type key_type_rxrpc_s;
1078ca7fb100SDavid Howells 
1079ca7fb100SDavid Howells int rxrpc_server_keyring(struct rxrpc_sock *, sockptr_t, int);
1080ca7fb100SDavid Howells 
1081ca7fb100SDavid Howells /*
10820d81a51aSDavid Howells  * skbuff.c
10830d81a51aSDavid Howells  */
1084d001648eSDavid Howells void rxrpc_kernel_data_consumed(struct rxrpc_call *, struct sk_buff *);
10850d81a51aSDavid Howells void rxrpc_packet_destructor(struct sk_buff *);
108671f3ca40SDavid Howells void rxrpc_new_skb(struct sk_buff *, enum rxrpc_skb_trace);
108771f3ca40SDavid Howells void rxrpc_see_skb(struct sk_buff *, enum rxrpc_skb_trace);
1088d0d5c0cdSDavid Howells void rxrpc_eaten_skb(struct sk_buff *, enum rxrpc_skb_trace);
108971f3ca40SDavid Howells void rxrpc_get_skb(struct sk_buff *, enum rxrpc_skb_trace);
109071f3ca40SDavid Howells void rxrpc_free_skb(struct sk_buff *, enum rxrpc_skb_trace);
1091df844fd4SDavid Howells void rxrpc_purge_queue(struct sk_buff_head *);
10920d81a51aSDavid Howells 
10930d81a51aSDavid Howells /*
10945873c083SDavid Howells  * sysctl.c
10955873c083SDavid Howells  */
10965873c083SDavid Howells #ifdef CONFIG_SYSCTL
10975873c083SDavid Howells extern int __init rxrpc_sysctl_init(void);
10985873c083SDavid Howells extern void rxrpc_sysctl_exit(void);
10995873c083SDavid Howells #else
11005873c083SDavid Howells static inline int __init rxrpc_sysctl_init(void) { return 0; }
11015873c083SDavid Howells static inline void rxrpc_sysctl_exit(void) {}
11025873c083SDavid Howells #endif
11035873c083SDavid Howells 
11045873c083SDavid Howells /*
1105be6e6707SDavid Howells  * utils.c
1106be6e6707SDavid Howells  */
11075a790b73SDavid Howells int rxrpc_extract_addr_from_skb(struct sockaddr_rxrpc *, struct sk_buff *);
1108be6e6707SDavid Howells 
1109248f219cSDavid Howells static inline bool before(u32 seq1, u32 seq2)
1110248f219cSDavid Howells {
1111248f219cSDavid Howells         return (s32)(seq1 - seq2) < 0;
1112248f219cSDavid Howells }
1113248f219cSDavid Howells static inline bool before_eq(u32 seq1, u32 seq2)
1114248f219cSDavid Howells {
1115248f219cSDavid Howells         return (s32)(seq1 - seq2) <= 0;
1116248f219cSDavid Howells }
1117248f219cSDavid Howells static inline bool after(u32 seq1, u32 seq2)
1118248f219cSDavid Howells {
1119248f219cSDavid Howells         return (s32)(seq1 - seq2) > 0;
1120248f219cSDavid Howells }
1121248f219cSDavid Howells static inline bool after_eq(u32 seq1, u32 seq2)
1122248f219cSDavid Howells {
1123248f219cSDavid Howells         return (s32)(seq1 - seq2) >= 0;
1124248f219cSDavid Howells }
1125248f219cSDavid Howells 
1126be6e6707SDavid Howells /*
112717926a79SDavid Howells  * debug tracing
112817926a79SDavid Howells  */
112995c96174SEric Dumazet extern unsigned int rxrpc_debug;
113017926a79SDavid Howells 
113117926a79SDavid Howells #define dbgprintk(FMT,...) \
11329f389f4bSSven Schnelle 	printk("[%-6.6s] "FMT"\n", current->comm ,##__VA_ARGS__)
113317926a79SDavid Howells 
11340dc47877SHarvey Harrison #define kenter(FMT,...)	dbgprintk("==> %s("FMT")",__func__ ,##__VA_ARGS__)
11350dc47877SHarvey Harrison #define kleave(FMT,...)	dbgprintk("<== %s()"FMT"",__func__ ,##__VA_ARGS__)
113617926a79SDavid Howells #define kdebug(FMT,...)	dbgprintk("    "FMT ,##__VA_ARGS__)
113717926a79SDavid Howells #define kproto(FMT,...)	dbgprintk("### "FMT ,##__VA_ARGS__)
113817926a79SDavid Howells #define knet(FMT,...)	dbgprintk("@@@ "FMT ,##__VA_ARGS__)
113917926a79SDavid Howells 
114017926a79SDavid Howells 
114117926a79SDavid Howells #if defined(__KDEBUG)
114217926a79SDavid Howells #define _enter(FMT,...)	kenter(FMT,##__VA_ARGS__)
114317926a79SDavid Howells #define _leave(FMT,...)	kleave(FMT,##__VA_ARGS__)
114417926a79SDavid Howells #define _debug(FMT,...)	kdebug(FMT,##__VA_ARGS__)
114517926a79SDavid Howells #define _proto(FMT,...)	kproto(FMT,##__VA_ARGS__)
114617926a79SDavid Howells #define _net(FMT,...)	knet(FMT,##__VA_ARGS__)
114717926a79SDavid Howells 
114817926a79SDavid Howells #elif defined(CONFIG_AF_RXRPC_DEBUG)
114917926a79SDavid Howells #define RXRPC_DEBUG_KENTER	0x01
115017926a79SDavid Howells #define RXRPC_DEBUG_KLEAVE	0x02
115117926a79SDavid Howells #define RXRPC_DEBUG_KDEBUG	0x04
115217926a79SDavid Howells #define RXRPC_DEBUG_KPROTO	0x08
115317926a79SDavid Howells #define RXRPC_DEBUG_KNET	0x10
115417926a79SDavid Howells 
115517926a79SDavid Howells #define _enter(FMT,...)					\
115617926a79SDavid Howells do {							\
115717926a79SDavid Howells 	if (unlikely(rxrpc_debug & RXRPC_DEBUG_KENTER))	\
115817926a79SDavid Howells 		kenter(FMT,##__VA_ARGS__);		\
115917926a79SDavid Howells } while (0)
116017926a79SDavid Howells 
116117926a79SDavid Howells #define _leave(FMT,...)					\
116217926a79SDavid Howells do {							\
116317926a79SDavid Howells 	if (unlikely(rxrpc_debug & RXRPC_DEBUG_KLEAVE))	\
116417926a79SDavid Howells 		kleave(FMT,##__VA_ARGS__);		\
116517926a79SDavid Howells } while (0)
116617926a79SDavid Howells 
116717926a79SDavid Howells #define _debug(FMT,...)					\
116817926a79SDavid Howells do {							\
116917926a79SDavid Howells 	if (unlikely(rxrpc_debug & RXRPC_DEBUG_KDEBUG))	\
117017926a79SDavid Howells 		kdebug(FMT,##__VA_ARGS__);		\
117117926a79SDavid Howells } while (0)
117217926a79SDavid Howells 
117317926a79SDavid Howells #define _proto(FMT,...)					\
117417926a79SDavid Howells do {							\
117517926a79SDavid Howells 	if (unlikely(rxrpc_debug & RXRPC_DEBUG_KPROTO))	\
117617926a79SDavid Howells 		kproto(FMT,##__VA_ARGS__);		\
117717926a79SDavid Howells } while (0)
117817926a79SDavid Howells 
117917926a79SDavid Howells #define _net(FMT,...)					\
118017926a79SDavid Howells do {							\
118117926a79SDavid Howells 	if (unlikely(rxrpc_debug & RXRPC_DEBUG_KNET))	\
118217926a79SDavid Howells 		knet(FMT,##__VA_ARGS__);		\
118317926a79SDavid Howells } while (0)
118417926a79SDavid Howells 
118517926a79SDavid Howells #else
118612fdff3fSDavid Howells #define _enter(FMT,...)	no_printk("==> %s("FMT")",__func__ ,##__VA_ARGS__)
118712fdff3fSDavid Howells #define _leave(FMT,...)	no_printk("<== %s()"FMT"",__func__ ,##__VA_ARGS__)
118812fdff3fSDavid Howells #define _debug(FMT,...)	no_printk("    "FMT ,##__VA_ARGS__)
118912fdff3fSDavid Howells #define _proto(FMT,...)	no_printk("### "FMT ,##__VA_ARGS__)
119012fdff3fSDavid Howells #define _net(FMT,...)	no_printk("@@@ "FMT ,##__VA_ARGS__)
119117926a79SDavid Howells #endif
119217926a79SDavid Howells 
119317926a79SDavid Howells /*
119417926a79SDavid Howells  * debug assertion checking
119517926a79SDavid Howells  */
119617926a79SDavid Howells #if 1 // defined(__KDEBUGALL)
119717926a79SDavid Howells 
119817926a79SDavid Howells #define ASSERT(X)						\
119917926a79SDavid Howells do {								\
120017926a79SDavid Howells 	if (unlikely(!(X))) {					\
12019b6d5398SJoe Perches 		pr_err("Assertion failed\n");			\
120217926a79SDavid Howells 		BUG();						\
120317926a79SDavid Howells 	}							\
120417926a79SDavid Howells } while (0)
120517926a79SDavid Howells 
120617926a79SDavid Howells #define ASSERTCMP(X, OP, Y)						\
120717926a79SDavid Howells do {									\
1208cf13258fSDavid Howells 	__typeof__(X) _x = (X);						\
1209cf13258fSDavid Howells 	__typeof__(Y) _y = (__typeof__(X))(Y);				\
12109b6d5398SJoe Perches 	if (unlikely(!(_x OP _y))) {					\
12119b6d5398SJoe Perches 		pr_err("Assertion failed - %lu(0x%lx) %s %lu(0x%lx) is false\n", \
1212cf13258fSDavid Howells 		       (unsigned long)_x, (unsigned long)_x, #OP,	\
1213cf13258fSDavid Howells 		       (unsigned long)_y, (unsigned long)_y);		\
121417926a79SDavid Howells 		BUG();							\
121517926a79SDavid Howells 	}								\
121617926a79SDavid Howells } while (0)
121717926a79SDavid Howells 
121817926a79SDavid Howells #define ASSERTIF(C, X)						\
121917926a79SDavid Howells do {								\
122017926a79SDavid Howells 	if (unlikely((C) && !(X))) {				\
12219b6d5398SJoe Perches 		pr_err("Assertion failed\n");			\
122217926a79SDavid Howells 		BUG();						\
122317926a79SDavid Howells 	}							\
122417926a79SDavid Howells } while (0)
122517926a79SDavid Howells 
122617926a79SDavid Howells #define ASSERTIFCMP(C, X, OP, Y)					\
122717926a79SDavid Howells do {									\
1228cf13258fSDavid Howells 	__typeof__(X) _x = (X);						\
1229cf13258fSDavid Howells 	__typeof__(Y) _y = (__typeof__(X))(Y);				\
12309b6d5398SJoe Perches 	if (unlikely((C) && !(_x OP _y))) {				\
12319b6d5398SJoe Perches 		pr_err("Assertion failed - %lu(0x%lx) %s %lu(0x%lx) is false\n", \
1232cf13258fSDavid Howells 		       (unsigned long)_x, (unsigned long)_x, #OP,	\
1233cf13258fSDavid Howells 		       (unsigned long)_y, (unsigned long)_y);		\
123417926a79SDavid Howells 		BUG();							\
123517926a79SDavid Howells 	}								\
123617926a79SDavid Howells } while (0)
123717926a79SDavid Howells 
123817926a79SDavid Howells #else
123917926a79SDavid Howells 
124017926a79SDavid Howells #define ASSERT(X)				\
124117926a79SDavid Howells do {						\
124217926a79SDavid Howells } while (0)
124317926a79SDavid Howells 
124417926a79SDavid Howells #define ASSERTCMP(X, OP, Y)			\
124517926a79SDavid Howells do {						\
124617926a79SDavid Howells } while (0)
124717926a79SDavid Howells 
124817926a79SDavid Howells #define ASSERTIF(C, X)				\
124917926a79SDavid Howells do {						\
125017926a79SDavid Howells } while (0)
125117926a79SDavid Howells 
125217926a79SDavid Howells #define ASSERTIFCMP(C, X, OP, Y)		\
125317926a79SDavid Howells do {						\
125417926a79SDavid Howells } while (0)
125517926a79SDavid Howells 
125617926a79SDavid Howells #endif /* __KDEBUGALL */
1257