xref: /openbmc/linux/net/rxrpc/ar-internal.h (revision 26cb02aa)
117926a79SDavid Howells /* AF_RXRPC internal definitions
217926a79SDavid Howells  *
317926a79SDavid Howells  * Copyright (C) 2007 Red Hat, Inc. All Rights Reserved.
417926a79SDavid Howells  * Written by David Howells (dhowells@redhat.com)
517926a79SDavid Howells  *
617926a79SDavid Howells  * This program is free software; you can redistribute it and/or
717926a79SDavid Howells  * modify it under the terms of the GNU General Public License
817926a79SDavid Howells  * as published by the Free Software Foundation; either version
917926a79SDavid Howells  * 2 of the License, or (at your option) any later version.
1017926a79SDavid Howells  */
1117926a79SDavid Howells 
12be6e6707SDavid Howells #include <linux/atomic.h>
138496af50SDavid Howells #include <linux/seqlock.h>
14e0e4d82fSDavid Howells #include <net/sock.h>
15be6e6707SDavid Howells #include <net/af_rxrpc.h>
1617926a79SDavid Howells #include <rxrpc/packet.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 
38cc8feb8eSDavid Howells struct rxrpc_connection;
39cc8feb8eSDavid Howells 
4017926a79SDavid Howells /*
41d001648eSDavid Howells  * Mark applied to socket buffers.
42d001648eSDavid Howells  */
43d001648eSDavid Howells enum rxrpc_skb_mark {
44d001648eSDavid Howells 	RXRPC_SKB_MARK_DATA,		/* data message */
45d001648eSDavid Howells 	RXRPC_SKB_MARK_FINAL_ACK,	/* final ACK received message */
46d001648eSDavid Howells 	RXRPC_SKB_MARK_BUSY,		/* server busy message */
47d001648eSDavid Howells 	RXRPC_SKB_MARK_REMOTE_ABORT,	/* remote abort message */
48d001648eSDavid Howells 	RXRPC_SKB_MARK_LOCAL_ABORT,	/* local abort message */
49d001648eSDavid Howells 	RXRPC_SKB_MARK_NET_ERROR,	/* network error message */
50d001648eSDavid Howells 	RXRPC_SKB_MARK_LOCAL_ERROR,	/* local error message */
51d001648eSDavid Howells 	RXRPC_SKB_MARK_NEW_CALL,	/* local error message */
52d001648eSDavid Howells };
53d001648eSDavid Howells 
54d001648eSDavid Howells /*
5517926a79SDavid Howells  * sk_state for RxRPC sockets
5617926a79SDavid Howells  */
5717926a79SDavid Howells enum {
582341e077SDavid Howells 	RXRPC_UNBOUND = 0,
592341e077SDavid Howells 	RXRPC_CLIENT_UNBOUND,		/* Unbound socket used as client */
6017926a79SDavid Howells 	RXRPC_CLIENT_BOUND,		/* client local address bound */
6117926a79SDavid Howells 	RXRPC_SERVER_BOUND,		/* server local address bound */
6217926a79SDavid Howells 	RXRPC_SERVER_LISTENING,		/* server listening for connections */
6317926a79SDavid Howells 	RXRPC_CLOSE,			/* socket is being closed */
6417926a79SDavid Howells };
6517926a79SDavid Howells 
6617926a79SDavid Howells /*
6700e90712SDavid Howells  * Service backlog preallocation.
6800e90712SDavid Howells  *
6900e90712SDavid Howells  * This contains circular buffers of preallocated peers, connections and calls
7000e90712SDavid Howells  * for incoming service calls and their head and tail pointers.  This allows
7100e90712SDavid Howells  * calls to be set up in the data_ready handler, thereby avoiding the need to
7200e90712SDavid Howells  * shuffle packets around so much.
7300e90712SDavid Howells  */
7400e90712SDavid Howells struct rxrpc_backlog {
7500e90712SDavid Howells 	unsigned short		peer_backlog_head;
7600e90712SDavid Howells 	unsigned short		peer_backlog_tail;
7700e90712SDavid Howells 	unsigned short		conn_backlog_head;
7800e90712SDavid Howells 	unsigned short		conn_backlog_tail;
7900e90712SDavid Howells 	unsigned short		call_backlog_head;
8000e90712SDavid Howells 	unsigned short		call_backlog_tail;
8100e90712SDavid Howells #define RXRPC_BACKLOG_MAX	32
8200e90712SDavid Howells 	struct rxrpc_peer	*peer_backlog[RXRPC_BACKLOG_MAX];
8300e90712SDavid Howells 	struct rxrpc_connection	*conn_backlog[RXRPC_BACKLOG_MAX];
8400e90712SDavid Howells 	struct rxrpc_call	*call_backlog[RXRPC_BACKLOG_MAX];
8500e90712SDavid Howells };
8600e90712SDavid Howells 
8700e90712SDavid Howells /*
8817926a79SDavid Howells  * RxRPC socket definition
8917926a79SDavid Howells  */
9017926a79SDavid Howells struct rxrpc_sock {
9117926a79SDavid Howells 	/* WARNING: sk has to be the first member */
9217926a79SDavid Howells 	struct sock		sk;
93d001648eSDavid Howells 	rxrpc_notify_new_call_t	notify_new_call; /* Func to notify of new call */
9400e90712SDavid Howells 	rxrpc_discard_new_call_t discard_new_call; /* Func to discard a new call */
9517926a79SDavid Howells 	struct rxrpc_local	*local;		/* local endpoint */
9600e90712SDavid Howells 	struct rxrpc_backlog	*backlog;	/* Preallocation for services */
97248f219cSDavid Howells 	spinlock_t		incoming_lock;	/* Incoming call vs service shutdown lock */
98248f219cSDavid Howells 	struct list_head	sock_calls;	/* List of calls owned by this socket */
99248f219cSDavid Howells 	struct list_head	to_be_accepted;	/* calls awaiting acceptance */
100248f219cSDavid Howells 	struct list_head	recvmsg_q;	/* Calls awaiting recvmsg's attention  */
101248f219cSDavid Howells 	rwlock_t		recvmsg_lock;	/* Lock for recvmsg_q */
10217926a79SDavid Howells 	struct key		*key;		/* security for this socket */
10317926a79SDavid Howells 	struct key		*securities;	/* list of server security descriptors */
10400e90712SDavid Howells 	struct rb_root		calls;		/* User ID -> call mapping */
10517926a79SDavid Howells 	unsigned long		flags;
1062341e077SDavid Howells #define RXRPC_SOCK_CONNECTED		0	/* connect_srx is set */
10717926a79SDavid Howells 	rwlock_t		call_lock;	/* lock for calls */
10817926a79SDavid Howells 	u32			min_sec_level;	/* minimum security level */
10917926a79SDavid Howells #define RXRPC_SECURITY_MAX	RXRPC_SECURITY_ENCRYPT
110cc8feb8eSDavid Howells 	bool			exclusive;	/* Exclusive connection for a client socket */
111cc8feb8eSDavid Howells 	sa_family_t		family;		/* Protocol family created with */
11217926a79SDavid Howells 	struct sockaddr_rxrpc	srx;		/* local address */
1132341e077SDavid Howells 	struct sockaddr_rxrpc	connect_srx;	/* Default client address from connect() */
11417926a79SDavid Howells };
11517926a79SDavid Howells 
11617926a79SDavid Howells #define rxrpc_sk(__sk) container_of((__sk), struct rxrpc_sock, sk)
11717926a79SDavid Howells 
11817926a79SDavid Howells /*
1190d12f8a4SDavid Howells  * CPU-byteorder normalised Rx packet header.
1200d12f8a4SDavid Howells  */
1210d12f8a4SDavid Howells struct rxrpc_host_header {
1220d12f8a4SDavid Howells 	u32		epoch;		/* client boot timestamp */
1230d12f8a4SDavid Howells 	u32		cid;		/* connection and channel ID */
1240d12f8a4SDavid Howells 	u32		callNumber;	/* call ID (0 for connection-level packets) */
1250d12f8a4SDavid Howells 	u32		seq;		/* sequence number of pkt in call stream */
1260d12f8a4SDavid Howells 	u32		serial;		/* serial number of pkt sent to network */
1270d12f8a4SDavid Howells 	u8		type;		/* packet type */
1280d12f8a4SDavid Howells 	u8		flags;		/* packet flags */
1290d12f8a4SDavid Howells 	u8		userStatus;	/* app-layer defined status */
1300d12f8a4SDavid Howells 	u8		securityIndex;	/* security protocol ID */
1310d12f8a4SDavid Howells 	union {
1320d12f8a4SDavid Howells 		u16	_rsvd;		/* reserved */
1330d12f8a4SDavid Howells 		u16	cksum;		/* kerberos security checksum */
1340d12f8a4SDavid Howells 	};
1350d12f8a4SDavid Howells 	u16		serviceId;	/* service ID */
1360d12f8a4SDavid Howells } __packed;
1370d12f8a4SDavid Howells 
1380d12f8a4SDavid Howells /*
13917926a79SDavid Howells  * RxRPC socket buffer private variables
14017926a79SDavid Howells  * - max 48 bytes (struct sk_buff::cb)
14117926a79SDavid Howells  */
14217926a79SDavid Howells struct rxrpc_skb_priv {
143248f219cSDavid Howells 	union {
144248f219cSDavid Howells 		u8		nr_jumbo;	/* Number of jumbo subpackets */
145248f219cSDavid Howells 	};
14617926a79SDavid Howells 	union {
14717926a79SDavid Howells 		int		remain;		/* amount of space remaining for next write */
14817926a79SDavid Howells 	};
14917926a79SDavid Howells 
1500d12f8a4SDavid Howells 	struct rxrpc_host_header hdr;		/* RxRPC packet header from this packet */
15117926a79SDavid Howells };
15217926a79SDavid Howells 
15317926a79SDavid Howells #define rxrpc_skb(__skb) ((struct rxrpc_skb_priv *) &(__skb)->cb)
15417926a79SDavid Howells 
15517926a79SDavid Howells /*
15617926a79SDavid Howells  * RxRPC security module interface
15717926a79SDavid Howells  */
15817926a79SDavid Howells struct rxrpc_security {
15917926a79SDavid Howells 	const char		*name;		/* name of this service */
16017926a79SDavid Howells 	u8			security_index;	/* security type provided */
16117926a79SDavid Howells 
162648af7fcSDavid Howells 	/* Initialise a security service */
163648af7fcSDavid Howells 	int (*init)(void);
164648af7fcSDavid Howells 
165648af7fcSDavid Howells 	/* Clean up a security service */
166648af7fcSDavid Howells 	void (*exit)(void);
167648af7fcSDavid Howells 
16817926a79SDavid Howells 	/* initialise a connection's security */
16917926a79SDavid Howells 	int (*init_connection_security)(struct rxrpc_connection *);
17017926a79SDavid Howells 
17117926a79SDavid Howells 	/* prime a connection's packet security */
172a263629dSHerbert Xu 	int (*prime_packet_security)(struct rxrpc_connection *);
17317926a79SDavid Howells 
17417926a79SDavid Howells 	/* impose security on a packet */
175a263629dSHerbert Xu 	int (*secure_packet)(struct rxrpc_call *,
17617926a79SDavid Howells 			     struct sk_buff *,
17717926a79SDavid Howells 			     size_t,
17817926a79SDavid Howells 			     void *);
17917926a79SDavid Howells 
18017926a79SDavid Howells 	/* verify the security on a received packet */
1815a42976dSDavid Howells 	int (*verify_packet)(struct rxrpc_call *, struct sk_buff *,
182248f219cSDavid Howells 			     unsigned int, unsigned int, rxrpc_seq_t, u16);
183248f219cSDavid Howells 
184248f219cSDavid Howells 	/* Locate the data in a received packet that has been verified. */
185248f219cSDavid Howells 	void (*locate_data)(struct rxrpc_call *, struct sk_buff *,
186248f219cSDavid Howells 			    unsigned int *, unsigned int *);
18717926a79SDavid Howells 
18817926a79SDavid Howells 	/* issue a challenge */
18917926a79SDavid Howells 	int (*issue_challenge)(struct rxrpc_connection *);
19017926a79SDavid Howells 
19117926a79SDavid Howells 	/* respond to a challenge */
19217926a79SDavid Howells 	int (*respond_to_challenge)(struct rxrpc_connection *,
19317926a79SDavid Howells 				    struct sk_buff *,
19417926a79SDavid Howells 				    u32 *);
19517926a79SDavid Howells 
19617926a79SDavid Howells 	/* verify a response */
19717926a79SDavid Howells 	int (*verify_response)(struct rxrpc_connection *,
19817926a79SDavid Howells 			       struct sk_buff *,
19917926a79SDavid Howells 			       u32 *);
20017926a79SDavid Howells 
20117926a79SDavid Howells 	/* clear connection security */
20217926a79SDavid Howells 	void (*clear)(struct rxrpc_connection *);
20317926a79SDavid Howells };
20417926a79SDavid Howells 
20517926a79SDavid Howells /*
2064f95dd78SDavid Howells  * RxRPC local transport endpoint description
2074f95dd78SDavid Howells  * - owned by a single AF_RXRPC socket
2084f95dd78SDavid Howells  * - pointed to by transport socket struct sk_user_data
20917926a79SDavid Howells  */
21017926a79SDavid Howells struct rxrpc_local {
2114f95dd78SDavid Howells 	struct rcu_head		rcu;
2124f95dd78SDavid Howells 	atomic_t		usage;
2134f95dd78SDavid Howells 	struct list_head	link;
21417926a79SDavid Howells 	struct socket		*socket;	/* my UDP socket */
2154f95dd78SDavid Howells 	struct work_struct	processor;
2161e9e5c95SDavid Howells 	struct rxrpc_sock __rcu	*service;	/* Service(s) listening on this endpoint */
21717926a79SDavid Howells 	struct rw_semaphore	defrag_sem;	/* control re-enablement of IP DF bit */
21817926a79SDavid Howells 	struct sk_buff_head	reject_queue;	/* packets awaiting rejection */
21944ba0698SDavid Howells 	struct sk_buff_head	event_queue;	/* endpoint event packets awaiting processing */
220999b69f8SDavid Howells 	struct rb_root		client_conns;	/* Client connections by socket params */
221999b69f8SDavid Howells 	spinlock_t		client_conns_lock; /* Lock for client_conns */
22217926a79SDavid Howells 	spinlock_t		lock;		/* access lock */
22317926a79SDavid Howells 	rwlock_t		services_lock;	/* lock for services list */
22417926a79SDavid Howells 	int			debug_id;	/* debug ID for printks */
2254f95dd78SDavid Howells 	bool			dead;
22617926a79SDavid Howells 	struct sockaddr_rxrpc	srx;		/* local address */
22717926a79SDavid Howells };
22817926a79SDavid Howells 
22917926a79SDavid Howells /*
23017926a79SDavid Howells  * RxRPC remote transport endpoint definition
231be6e6707SDavid Howells  * - matched by local endpoint, remote port, address and protocol type
23217926a79SDavid Howells  */
23317926a79SDavid Howells struct rxrpc_peer {
234be6e6707SDavid Howells 	struct rcu_head		rcu;		/* This must be first */
235be6e6707SDavid Howells 	atomic_t		usage;
236be6e6707SDavid Howells 	unsigned long		hash_key;
237be6e6707SDavid Howells 	struct hlist_node	hash_link;
238be6e6707SDavid Howells 	struct rxrpc_local	*local;
239f66d7490SDavid Howells 	struct hlist_head	error_targets;	/* targets for net error distribution */
240f66d7490SDavid Howells 	struct work_struct	error_distributor;
241aa390bbeSDavid Howells 	struct rb_root		service_conns;	/* Service connections */
2428496af50SDavid Howells 	seqlock_t		service_conn_lock;
24317926a79SDavid Howells 	spinlock_t		lock;		/* access lock */
24495c96174SEric Dumazet 	unsigned int		if_mtu;		/* interface MTU for this peer */
24595c96174SEric Dumazet 	unsigned int		mtu;		/* network MTU for this peer */
24695c96174SEric Dumazet 	unsigned int		maxdata;	/* data size (MTU - hdrsize) */
24717926a79SDavid Howells 	unsigned short		hdrsize;	/* header size (IP + UDP + RxRPC) */
24817926a79SDavid Howells 	int			debug_id;	/* debug ID for printks */
249f66d7490SDavid Howells 	int			error_report;	/* Net (+0) or local (+1000000) to distribute */
250f66d7490SDavid Howells #define RXRPC_LOCAL_ERROR_OFFSET 1000000
25117926a79SDavid Howells 	struct sockaddr_rxrpc	srx;		/* remote address */
25217926a79SDavid Howells 
25317926a79SDavid Howells 	/* calculated RTT cache */
25417926a79SDavid Howells #define RXRPC_RTT_CACHE_SIZE 32
2550d4b103cSDavid Howells 	ktime_t			rtt_last_req;	/* Time of last RTT request */
256cf1a6474SDavid Howells 	u64			rtt;		/* Current RTT estimate (in nS) */
257cf1a6474SDavid Howells 	u64			rtt_sum;	/* Sum of cache contents */
258cf1a6474SDavid Howells 	u64			rtt_cache[RXRPC_RTT_CACHE_SIZE]; /* Determined RTT cache */
259cf1a6474SDavid Howells 	u8			rtt_cursor;	/* next entry at which to insert */
260cf1a6474SDavid Howells 	u8			rtt_usage;	/* amount of cache actually used */
26117926a79SDavid Howells };
26217926a79SDavid Howells 
26317926a79SDavid Howells /*
26419ffa01cSDavid Howells  * Keys for matching a connection.
26519ffa01cSDavid Howells  */
26619ffa01cSDavid Howells struct rxrpc_conn_proto {
267e8d70ce1SDavid Howells 	union {
268e8d70ce1SDavid Howells 		struct {
26919ffa01cSDavid Howells 			u32	epoch;		/* epoch of this connection */
27019ffa01cSDavid Howells 			u32	cid;		/* connection ID */
271e8d70ce1SDavid Howells 		};
272e8d70ce1SDavid Howells 		u64		index_key;
27319ffa01cSDavid Howells 	};
27419ffa01cSDavid Howells };
27519ffa01cSDavid Howells 
27619ffa01cSDavid Howells struct rxrpc_conn_parameters {
27719ffa01cSDavid Howells 	struct rxrpc_local	*local;		/* Representation of local endpoint */
27819ffa01cSDavid Howells 	struct rxrpc_peer	*peer;		/* Remote endpoint */
27919ffa01cSDavid Howells 	struct key		*key;		/* Security details */
28019ffa01cSDavid Howells 	bool			exclusive;	/* T if conn is exclusive */
28119ffa01cSDavid Howells 	u16			service_id;	/* Service ID for this connection */
28219ffa01cSDavid Howells 	u32			security_level;	/* Security level selected */
28319ffa01cSDavid Howells };
28419ffa01cSDavid Howells 
28519ffa01cSDavid Howells /*
286bba304dbSDavid Howells  * Bits in the connection flags.
287bba304dbSDavid Howells  */
288bba304dbSDavid Howells enum rxrpc_conn_flag {
289bba304dbSDavid Howells 	RXRPC_CONN_HAS_IDR,		/* Has a client conn ID assigned */
290001c1122SDavid Howells 	RXRPC_CONN_IN_SERVICE_CONNS,	/* Conn is in peer->service_conns */
291001c1122SDavid Howells 	RXRPC_CONN_IN_CLIENT_CONNS,	/* Conn is in local->client_conns */
29245025bceSDavid Howells 	RXRPC_CONN_EXPOSED,		/* Conn has extra ref for exposure */
29345025bceSDavid Howells 	RXRPC_CONN_DONT_REUSE,		/* Don't reuse this connection */
29445025bceSDavid Howells 	RXRPC_CONN_COUNTED,		/* Counted by rxrpc_nr_client_conns */
295bba304dbSDavid Howells };
296bba304dbSDavid Howells 
297bba304dbSDavid Howells /*
298bba304dbSDavid Howells  * Events that can be raised upon a connection.
299bba304dbSDavid Howells  */
300bba304dbSDavid Howells enum rxrpc_conn_event {
301bba304dbSDavid Howells 	RXRPC_CONN_EV_CHALLENGE,	/* Send challenge packet */
302bba304dbSDavid Howells };
303bba304dbSDavid Howells 
304bba304dbSDavid Howells /*
30545025bceSDavid Howells  * The connection cache state.
30645025bceSDavid Howells  */
30745025bceSDavid Howells enum rxrpc_conn_cache_state {
30845025bceSDavid Howells 	RXRPC_CONN_CLIENT_INACTIVE,	/* Conn is not yet listed */
30945025bceSDavid Howells 	RXRPC_CONN_CLIENT_WAITING,	/* Conn is on wait list, waiting for capacity */
31045025bceSDavid Howells 	RXRPC_CONN_CLIENT_ACTIVE,	/* Conn is on active list, doing calls */
31145025bceSDavid Howells 	RXRPC_CONN_CLIENT_CULLED,	/* Conn is culled and delisted, doing calls */
31245025bceSDavid Howells 	RXRPC_CONN_CLIENT_IDLE,		/* Conn is on idle list, doing mostly nothing */
313363deeabSDavid Howells 	RXRPC_CONN__NR_CACHE_STATES
31445025bceSDavid Howells };
31545025bceSDavid Howells 
31645025bceSDavid Howells /*
317bba304dbSDavid Howells  * The connection protocol state.
318bba304dbSDavid Howells  */
319bba304dbSDavid Howells enum rxrpc_conn_proto_state {
320bba304dbSDavid Howells 	RXRPC_CONN_UNUSED,		/* Connection not yet attempted */
321bba304dbSDavid Howells 	RXRPC_CONN_CLIENT,		/* Client connection */
32200e90712SDavid Howells 	RXRPC_CONN_SERVICE_PREALLOC,	/* Service connection preallocation */
323bba304dbSDavid Howells 	RXRPC_CONN_SERVICE_UNSECURED,	/* Service unsecured connection */
324bba304dbSDavid Howells 	RXRPC_CONN_SERVICE_CHALLENGING,	/* Service challenging for security */
325bba304dbSDavid Howells 	RXRPC_CONN_SERVICE,		/* Service secured connection */
326bba304dbSDavid Howells 	RXRPC_CONN_REMOTELY_ABORTED,	/* Conn aborted by peer */
327bba304dbSDavid Howells 	RXRPC_CONN_LOCALLY_ABORTED,	/* Conn aborted locally */
328bba304dbSDavid Howells 	RXRPC_CONN__NR_STATES
329bba304dbSDavid Howells };
330bba304dbSDavid Howells 
331bba304dbSDavid Howells /*
33217926a79SDavid Howells  * RxRPC connection definition
333aa390bbeSDavid Howells  * - matched by { local, peer, epoch, conn_id, direction }
33417926a79SDavid Howells  * - each connection can only handle four simultaneous calls
33517926a79SDavid Howells  */
33617926a79SDavid Howells struct rxrpc_connection {
33719ffa01cSDavid Howells 	struct rxrpc_conn_proto	proto;
33819ffa01cSDavid Howells 	struct rxrpc_conn_parameters params;
33919ffa01cSDavid Howells 
34045025bceSDavid Howells 	atomic_t		usage;
34145025bceSDavid Howells 	struct rcu_head		rcu;
34245025bceSDavid Howells 	struct list_head	cache_link;
343a1399f8bSDavid Howells 
34445025bceSDavid Howells 	spinlock_t		channel_lock;
34545025bceSDavid Howells 	unsigned char		active_chans;	/* Mask of active channels */
34645025bceSDavid Howells #define RXRPC_ACTIVE_CHANS_MASK	((1 << RXRPC_MAXCALLS) - 1)
34745025bceSDavid Howells 	struct list_head	waiting_calls;	/* Calls waiting for channels */
348a1399f8bSDavid Howells 	struct rxrpc_channel {
349a1399f8bSDavid Howells 		struct rxrpc_call __rcu	*call;		/* Active call */
350a1399f8bSDavid Howells 		u32			call_id;	/* ID of current call */
351a1399f8bSDavid Howells 		u32			call_counter;	/* Call ID counter */
352a1399f8bSDavid Howells 		u32			last_call;	/* ID of last call */
35318bfeba5SDavid Howells 		u8			last_type;	/* Type of last packet */
35418bfeba5SDavid Howells 		u16			last_service_id;
35518bfeba5SDavid Howells 		union {
35618bfeba5SDavid Howells 			u32		last_seq;
35718bfeba5SDavid Howells 			u32		last_abort;
35818bfeba5SDavid Howells 		};
359a1399f8bSDavid Howells 	} channels[RXRPC_MAXCALLS];
360999b69f8SDavid Howells 
36117926a79SDavid Howells 	struct work_struct	processor;	/* connection event processor */
362999b69f8SDavid Howells 	union {
363999b69f8SDavid Howells 		struct rb_node	client_node;	/* Node in local->client_conns */
364aa390bbeSDavid Howells 		struct rb_node	service_node;	/* Node in peer->service_conns */
365999b69f8SDavid Howells 	};
3664d028b2cSDavid Howells 	struct list_head	proc_link;	/* link in procfs list */
36717926a79SDavid Howells 	struct list_head	link;		/* link in master connection list */
36817926a79SDavid Howells 	struct sk_buff_head	rx_queue;	/* received conn-level packets */
369648af7fcSDavid Howells 	const struct rxrpc_security *security;	/* applied security module */
37017926a79SDavid Howells 	struct key		*server_key;	/* security for this service */
3711afe593bSHerbert Xu 	struct crypto_skcipher	*cipher;	/* encryption handle */
37217926a79SDavid Howells 	struct rxrpc_crypt	csum_iv;	/* packet checksum base */
3734a3388c8SDavid Howells 	unsigned long		flags;
37417926a79SDavid Howells 	unsigned long		events;
375f51b4480SDavid Howells 	unsigned long		idle_timestamp;	/* Time at which last became idle */
37617926a79SDavid Howells 	spinlock_t		state_lock;	/* state-change lock */
377cf13258fSDavid Howells 	enum rxrpc_conn_cache_state cache_state;
378cf13258fSDavid Howells 	enum rxrpc_conn_proto_state state;	/* current state of connection */
379dc44b3a0SDavid Howells 	u32			local_abort;	/* local abort code */
380dc44b3a0SDavid Howells 	u32			remote_abort;	/* remote abort code */
38117926a79SDavid Howells 	int			debug_id;	/* debug ID for printks */
38217926a79SDavid Howells 	atomic_t		serial;		/* packet serial number counter */
383563ea7d5SDavid Howells 	unsigned int		hi_serial;	/* highest serial number received */
38417926a79SDavid Howells 	u32			security_nonce;	/* response re-use preventer */
3855a924b89SDavid Howells 	u8			size_align;	/* data size alignment (for security) */
3865a924b89SDavid Howells 	u8			security_size;	/* security header size */
38717926a79SDavid Howells 	u8			security_ix;	/* security type */
38817926a79SDavid Howells 	u8			out_clientflag;	/* RXRPC_CLIENT_INITIATED if we are client */
38917926a79SDavid Howells };
39017926a79SDavid Howells 
39117926a79SDavid Howells /*
3925b8848d1SDavid Howells  * Flags in call->flags.
3935b8848d1SDavid Howells  */
3945b8848d1SDavid Howells enum rxrpc_call_flag {
3955b8848d1SDavid Howells 	RXRPC_CALL_RELEASED,		/* call has been released - no more message to userspace */
3965b8848d1SDavid Howells 	RXRPC_CALL_HAS_USERID,		/* has a user ID attached */
397dabe5a79SDavid Howells 	RXRPC_CALL_IS_SERVICE,		/* Call is service call */
39845025bceSDavid Howells 	RXRPC_CALL_EXPOSED,		/* The call was exposed to the world */
399248f219cSDavid Howells 	RXRPC_CALL_RX_LAST,		/* Received the last packet (at rxtx_top) */
400248f219cSDavid Howells 	RXRPC_CALL_TX_LAST,		/* Last packet in Tx buffer (at rxtx_top) */
4018e83134dSDavid Howells 	RXRPC_CALL_PINGING,		/* Ping in process */
40257494343SDavid Howells 	RXRPC_CALL_RETRANS_TIMEOUT,	/* Retransmission due to timeout occurred */
4035b8848d1SDavid Howells };
4045b8848d1SDavid Howells 
4055b8848d1SDavid Howells /*
4065b8848d1SDavid Howells  * Events that can be raised on a call.
4075b8848d1SDavid Howells  */
4085b8848d1SDavid Howells enum rxrpc_call_event {
4094c198ad1SDavid Howells 	RXRPC_CALL_EV_ACK,		/* need to generate ACK */
4104c198ad1SDavid Howells 	RXRPC_CALL_EV_ABORT,		/* need to generate abort */
411248f219cSDavid Howells 	RXRPC_CALL_EV_TIMER,		/* Timer expired */
4124c198ad1SDavid Howells 	RXRPC_CALL_EV_RESEND,		/* Tx resend required */
4135b8848d1SDavid Howells };
4145b8848d1SDavid Howells 
4155b8848d1SDavid Howells /*
4165b8848d1SDavid Howells  * The states that a call can be in.
4175b8848d1SDavid Howells  */
4185b8848d1SDavid Howells enum rxrpc_call_state {
419999b69f8SDavid Howells 	RXRPC_CALL_UNINITIALISED,
420999b69f8SDavid Howells 	RXRPC_CALL_CLIENT_AWAIT_CONN,	/* - client waiting for connection to become available */
4215b8848d1SDavid Howells 	RXRPC_CALL_CLIENT_SEND_REQUEST,	/* - client sending request phase */
4225b8848d1SDavid Howells 	RXRPC_CALL_CLIENT_AWAIT_REPLY,	/* - client awaiting reply */
4235b8848d1SDavid Howells 	RXRPC_CALL_CLIENT_RECV_REPLY,	/* - client receiving reply phase */
42400e90712SDavid Howells 	RXRPC_CALL_SERVER_PREALLOC,	/* - service preallocation */
4255b8848d1SDavid Howells 	RXRPC_CALL_SERVER_SECURING,	/* - server securing request connection */
4265b8848d1SDavid Howells 	RXRPC_CALL_SERVER_ACCEPTING,	/* - server accepting request */
4275b8848d1SDavid Howells 	RXRPC_CALL_SERVER_RECV_REQUEST,	/* - server receiving request */
4285b8848d1SDavid Howells 	RXRPC_CALL_SERVER_ACK_REQUEST,	/* - server pending ACK of request */
4295b8848d1SDavid Howells 	RXRPC_CALL_SERVER_SEND_REPLY,	/* - server sending reply */
4305b8848d1SDavid Howells 	RXRPC_CALL_SERVER_AWAIT_ACK,	/* - server awaiting final ACK */
431f5c17aaeSDavid Howells 	RXRPC_CALL_COMPLETE,		/* - call complete */
432f5c17aaeSDavid Howells 	NR__RXRPC_CALL_STATES
433f5c17aaeSDavid Howells };
434f5c17aaeSDavid Howells 
435f5c17aaeSDavid Howells /*
436f5c17aaeSDavid Howells  * Call completion condition (state == RXRPC_CALL_COMPLETE).
437f5c17aaeSDavid Howells  */
438f5c17aaeSDavid Howells enum rxrpc_call_completion {
439f5c17aaeSDavid Howells 	RXRPC_CALL_SUCCEEDED,		/* - Normal termination */
4405b8848d1SDavid Howells 	RXRPC_CALL_REMOTELY_ABORTED,	/* - call aborted by peer */
4415b8848d1SDavid Howells 	RXRPC_CALL_LOCALLY_ABORTED,	/* - call aborted locally on error or close */
442f5c17aaeSDavid Howells 	RXRPC_CALL_LOCAL_ERROR,		/* - call failed due to local error */
4435b8848d1SDavid Howells 	RXRPC_CALL_NETWORK_ERROR,	/* - call terminated by network error */
444f5c17aaeSDavid Howells 	NR__RXRPC_CALL_COMPLETIONS
4455b8848d1SDavid Howells };
4465b8848d1SDavid Howells 
4475b8848d1SDavid Howells /*
44857494343SDavid Howells  * Call Tx congestion management modes.
44957494343SDavid Howells  */
45057494343SDavid Howells enum rxrpc_congest_mode {
45157494343SDavid Howells 	RXRPC_CALL_SLOW_START,
45257494343SDavid Howells 	RXRPC_CALL_CONGEST_AVOIDANCE,
45357494343SDavid Howells 	RXRPC_CALL_PACKET_LOSS,
45457494343SDavid Howells 	RXRPC_CALL_FAST_RETRANSMIT,
45557494343SDavid Howells 	NR__RXRPC_CONGEST_MODES
45657494343SDavid Howells };
45757494343SDavid Howells 
45857494343SDavid Howells /*
45917926a79SDavid Howells  * RxRPC call definition
46017926a79SDavid Howells  * - matched by { connection, call_id }
46117926a79SDavid Howells  */
46217926a79SDavid Howells struct rxrpc_call {
463dee46364SDavid Howells 	struct rcu_head		rcu;
46417926a79SDavid Howells 	struct rxrpc_connection	*conn;		/* connection carrying call */
465df5d8bf7SDavid Howells 	struct rxrpc_peer	*peer;		/* Peer record for remote address */
4668d94aa38SDavid Howells 	struct rxrpc_sock __rcu	*socket;	/* socket responsible */
467df0adc78SDavid Howells 	ktime_t			ack_at;		/* When deferred ACK needs to happen */
468df0adc78SDavid Howells 	ktime_t			resend_at;	/* When next resend needs to happen */
469df0adc78SDavid Howells 	ktime_t			expire_at;	/* When the call times out */
470248f219cSDavid Howells 	struct timer_list	timer;		/* Combined event timer */
471248f219cSDavid Howells 	struct work_struct	processor;	/* Event processor */
472d001648eSDavid Howells 	rxrpc_notify_rx_t	notify_rx;	/* kernel service Rx notification function */
47317926a79SDavid Howells 	struct list_head	link;		/* link in master call list */
47445025bceSDavid Howells 	struct list_head	chan_wait_link;	/* Link in conn->waiting_calls */
475f66d7490SDavid Howells 	struct hlist_node	error_link;	/* link in error distribution list */
476248f219cSDavid Howells 	struct list_head	accept_link;	/* Link in rx->acceptq */
477248f219cSDavid Howells 	struct list_head	recvmsg_link;	/* Link in rx->recvmsg_q */
478248f219cSDavid Howells 	struct list_head	sock_link;	/* Link in rx->sock_calls */
479248f219cSDavid Howells 	struct rb_node		sock_node;	/* Node in rx->calls */
48017926a79SDavid Howells 	struct sk_buff		*tx_pending;	/* Tx socket buffer being filled */
48145025bceSDavid Howells 	wait_queue_head_t	waitq;		/* Wait queue for channel or Tx */
482a263629dSHerbert Xu 	__be32			crypto_buf[2];	/* Temporary packet crypto buffer */
48317926a79SDavid Howells 	unsigned long		user_call_ID;	/* user-defined call ID */
48417926a79SDavid Howells 	unsigned long		flags;
48517926a79SDavid Howells 	unsigned long		events;
48617926a79SDavid Howells 	spinlock_t		lock;
48717926a79SDavid Howells 	rwlock_t		state_lock;	/* lock for state transition */
488f5c17aaeSDavid Howells 	u32			abort_code;	/* Local/remote abort code */
489f5c17aaeSDavid Howells 	int			error;		/* Local error incurred */
490cf13258fSDavid Howells 	enum rxrpc_call_state	state;		/* current state of call */
491cf13258fSDavid Howells 	enum rxrpc_call_completion completion;	/* Call completion condition */
49217926a79SDavid Howells 	atomic_t		usage;
493dabe5a79SDavid Howells 	u16			service_id;	/* service ID */
494278ac0cdSDavid Howells 	u8			security_ix;	/* Security type */
495dabe5a79SDavid Howells 	u32			call_id;	/* call ID on connection  */
496dabe5a79SDavid Howells 	u32			cid;		/* connection ID plus channel index */
497dabe5a79SDavid Howells 	int			debug_id;	/* debug ID for printks */
4988e83134dSDavid Howells 	unsigned short		rx_pkt_offset;	/* Current recvmsg packet offset */
4998e83134dSDavid Howells 	unsigned short		rx_pkt_len;	/* Current recvmsg packet len */
50017926a79SDavid Howells 
501248f219cSDavid Howells 	/* Rx/Tx circular buffer, depending on phase.
502248f219cSDavid Howells 	 *
503248f219cSDavid Howells 	 * In the Rx phase, packets are annotated with 0 or the number of the
504248f219cSDavid Howells 	 * segment of a jumbo packet each buffer refers to.  There can be up to
505248f219cSDavid Howells 	 * 47 segments in a maximum-size UDP packet.
506248f219cSDavid Howells 	 *
507248f219cSDavid Howells 	 * In the Tx phase, packets are annotated with which buffers have been
508248f219cSDavid Howells 	 * acked.
50917926a79SDavid Howells 	 */
510248f219cSDavid Howells #define RXRPC_RXTX_BUFF_SIZE	64
511248f219cSDavid Howells #define RXRPC_RXTX_BUFF_MASK	(RXRPC_RXTX_BUFF_SIZE - 1)
51275e42126SDavid Howells #define RXRPC_INIT_RX_WINDOW_SIZE 32
513248f219cSDavid Howells 	struct sk_buff		**rxtx_buffer;
514248f219cSDavid Howells 	u8			*rxtx_annotations;
515248f219cSDavid Howells #define RXRPC_TX_ANNO_ACK	0
516248f219cSDavid Howells #define RXRPC_TX_ANNO_UNACK	1
517248f219cSDavid Howells #define RXRPC_TX_ANNO_NAK	2
518248f219cSDavid Howells #define RXRPC_TX_ANNO_RETRANS	3
519f07373eaSDavid Howells #define RXRPC_TX_ANNO_MASK	0x03
52070790dbeSDavid Howells #define RXRPC_TX_ANNO_LAST	0x04
52170790dbeSDavid Howells #define RXRPC_TX_ANNO_RESENT	0x08
52270790dbeSDavid Howells 
523248f219cSDavid Howells #define RXRPC_RX_ANNO_JUMBO	0x3f		/* Jumbo subpacket number + 1 if not zero */
524248f219cSDavid Howells #define RXRPC_RX_ANNO_JLAST	0x40		/* Set if last element of a jumbo packet */
525248f219cSDavid Howells #define RXRPC_RX_ANNO_VERIFIED	0x80		/* Set if verified and decrypted */
526248f219cSDavid Howells 	rxrpc_seq_t		tx_hard_ack;	/* Dead slot in buffer; the first transmitted but
527248f219cSDavid Howells 						 * not hard-ACK'd packet follows this.
528248f219cSDavid Howells 						 */
529248f219cSDavid Howells 	rxrpc_seq_t		tx_top;		/* Highest Tx slot allocated. */
53057494343SDavid Howells 
53157494343SDavid Howells 	/* TCP-style slow-start congestion control [RFC5681].  Since the SMSS
53257494343SDavid Howells 	 * is fixed, we keep these numbers in terms of segments (ie. DATA
53357494343SDavid Howells 	 * packets) rather than bytes.
53457494343SDavid Howells 	 */
53557494343SDavid Howells #define RXRPC_TX_SMSS		RXRPC_JUMBO_DATALEN
53657494343SDavid Howells 	u8			cong_cwnd;	/* Congestion window size */
53757494343SDavid Howells 	u8			cong_extra;	/* Extra to send for congestion management */
53857494343SDavid Howells 	u8			cong_ssthresh;	/* Slow-start threshold */
53957494343SDavid Howells 	enum rxrpc_congest_mode	cong_mode:8;	/* Congestion management mode */
54057494343SDavid Howells 	u8			cong_dup_acks;	/* Count of ACKs showing missing packets */
54157494343SDavid Howells 	u8			cong_cumul_acks; /* Cumulative ACK count */
54257494343SDavid Howells 	ktime_t			cong_tstamp;	/* Last time cwnd was changed */
54357494343SDavid Howells 
544248f219cSDavid Howells 	rxrpc_seq_t		rx_hard_ack;	/* Dead slot in buffer; the first received but not
545248f219cSDavid Howells 						 * consumed packet follows this.
546248f219cSDavid Howells 						 */
547248f219cSDavid Howells 	rxrpc_seq_t		rx_top;		/* Highest Rx slot allocated. */
548248f219cSDavid Howells 	rxrpc_seq_t		rx_expect_next;	/* Expected next packet sequence number */
549248f219cSDavid Howells 	u8			rx_winsize;	/* Size of Rx window */
550248f219cSDavid Howells 	u8			tx_winsize;	/* Maximum size of Tx window */
55171f3ca40SDavid Howells 	bool			tx_phase;	/* T if transmission phase, F if receive phase */
55275e42126SDavid Howells 	u8			nr_jumbo_bad;	/* Number of jumbo dups/exceeds-windows */
55317926a79SDavid Howells 
55417926a79SDavid Howells 	/* receive-phase ACK management */
5554e36a95eSDavid Howells 	u8			ackr_reason;	/* reason to ACK */
556563ea7d5SDavid Howells 	u16			ackr_skew;	/* skew on packet being ACK'd */
5570d12f8a4SDavid Howells 	rxrpc_serial_t		ackr_serial;	/* serial of packet being ACK'd */
558248f219cSDavid Howells 	rxrpc_seq_t		ackr_prev_seq;	/* previous sequence number received */
559805b21b9SDavid Howells 	rxrpc_seq_t		ackr_consumed;	/* Highest packet shown consumed */
560805b21b9SDavid Howells 	rxrpc_seq_t		ackr_seen;	/* Highest packet shown seen */
5618e83134dSDavid Howells 	rxrpc_serial_t		ackr_ping;	/* Last ping sent */
5628e83134dSDavid Howells 	ktime_t			ackr_ping_time;	/* Time last ping sent */
56317926a79SDavid Howells 
564248f219cSDavid Howells 	/* transmission-phase ACK management */
56557494343SDavid Howells 	ktime_t			acks_latest_ts;	/* Timestamp of latest ACK received */
566248f219cSDavid Howells 	rxrpc_serial_t		acks_latest;	/* serial number of latest ACK received */
56731a1b989SDavid Howells 	rxrpc_seq_t		acks_lowest_nak; /* Lowest NACK in the buffer (or ==tx_hard_ack) */
56831a1b989SDavid Howells };
56931a1b989SDavid Howells 
57031a1b989SDavid Howells /*
57157494343SDavid Howells  * Summary of a new ACK and the changes it made to the Tx buffer packet states.
57231a1b989SDavid Howells  */
57331a1b989SDavid Howells struct rxrpc_ack_summary {
57431a1b989SDavid Howells 	u8			ack_reason;
57531a1b989SDavid Howells 	u8			nr_acks;		/* Number of ACKs in packet */
57631a1b989SDavid Howells 	u8			nr_nacks;		/* Number of NACKs in packet */
57731a1b989SDavid Howells 	u8			nr_new_acks;		/* Number of new ACKs in packet */
57831a1b989SDavid Howells 	u8			nr_new_nacks;		/* Number of new NACKs in packet */
57931a1b989SDavid Howells 	u8			nr_rot_new_acks;	/* Number of rotated new ACKs */
58031a1b989SDavid Howells 	bool			new_low_nack;		/* T if new low NACK found */
58157494343SDavid Howells 	bool			retrans_timeo;		/* T if reTx due to timeout happened */
58257494343SDavid Howells 	u8			flight_size;		/* Number of unreceived transmissions */
58357494343SDavid Howells 	/* Place to stash values for tracing */
58457494343SDavid Howells 	enum rxrpc_congest_mode	mode:8;
58557494343SDavid Howells 	u8			cwnd;
58657494343SDavid Howells 	u8			ssthresh;
58757494343SDavid Howells 	u8			dup_acks;
58857494343SDavid Howells 	u8			cumulative_acks;
58917926a79SDavid Howells };
59017926a79SDavid Howells 
59171f3ca40SDavid Howells enum rxrpc_skb_trace {
59271f3ca40SDavid Howells 	rxrpc_skb_rx_cleaned,
59371f3ca40SDavid Howells 	rxrpc_skb_rx_freed,
59471f3ca40SDavid Howells 	rxrpc_skb_rx_got,
59571f3ca40SDavid Howells 	rxrpc_skb_rx_lost,
59671f3ca40SDavid Howells 	rxrpc_skb_rx_received,
59771f3ca40SDavid Howells 	rxrpc_skb_rx_rotated,
59871f3ca40SDavid Howells 	rxrpc_skb_rx_purged,
59971f3ca40SDavid Howells 	rxrpc_skb_rx_seen,
60071f3ca40SDavid Howells 	rxrpc_skb_tx_cleaned,
60171f3ca40SDavid Howells 	rxrpc_skb_tx_freed,
60271f3ca40SDavid Howells 	rxrpc_skb_tx_got,
60371f3ca40SDavid Howells 	rxrpc_skb_tx_new,
60471f3ca40SDavid Howells 	rxrpc_skb_tx_rotated,
60571f3ca40SDavid Howells 	rxrpc_skb_tx_seen,
60671f3ca40SDavid Howells 	rxrpc_skb__nr_trace
60771f3ca40SDavid Howells };
60871f3ca40SDavid Howells 
60971f3ca40SDavid Howells extern const char rxrpc_skb_traces[rxrpc_skb__nr_trace][7];
61071f3ca40SDavid Howells 
611363deeabSDavid Howells enum rxrpc_conn_trace {
612363deeabSDavid Howells 	rxrpc_conn_new_client,
613363deeabSDavid Howells 	rxrpc_conn_new_service,
614363deeabSDavid Howells 	rxrpc_conn_queued,
615363deeabSDavid Howells 	rxrpc_conn_seen,
616363deeabSDavid Howells 	rxrpc_conn_got,
617363deeabSDavid Howells 	rxrpc_conn_put_client,
618363deeabSDavid Howells 	rxrpc_conn_put_service,
619363deeabSDavid Howells 	rxrpc_conn__nr_trace
620363deeabSDavid Howells };
621363deeabSDavid Howells 
622363deeabSDavid Howells extern const char rxrpc_conn_traces[rxrpc_conn__nr_trace][4];
623363deeabSDavid Howells 
624363deeabSDavid Howells enum rxrpc_client_trace {
625363deeabSDavid Howells 	rxrpc_client_activate_chans,
626363deeabSDavid Howells 	rxrpc_client_alloc,
627363deeabSDavid Howells 	rxrpc_client_chan_activate,
628363deeabSDavid Howells 	rxrpc_client_chan_disconnect,
629363deeabSDavid Howells 	rxrpc_client_chan_pass,
630363deeabSDavid Howells 	rxrpc_client_chan_unstarted,
631363deeabSDavid Howells 	rxrpc_client_cleanup,
632363deeabSDavid Howells 	rxrpc_client_count,
633363deeabSDavid Howells 	rxrpc_client_discard,
634363deeabSDavid Howells 	rxrpc_client_duplicate,
635363deeabSDavid Howells 	rxrpc_client_exposed,
636363deeabSDavid Howells 	rxrpc_client_replace,
637363deeabSDavid Howells 	rxrpc_client_to_active,
638363deeabSDavid Howells 	rxrpc_client_to_culled,
639363deeabSDavid Howells 	rxrpc_client_to_idle,
640363deeabSDavid Howells 	rxrpc_client_to_inactive,
641363deeabSDavid Howells 	rxrpc_client_to_waiting,
642363deeabSDavid Howells 	rxrpc_client_uncount,
643363deeabSDavid Howells 	rxrpc_client__nr_trace
644363deeabSDavid Howells };
645363deeabSDavid Howells 
646363deeabSDavid Howells extern const char rxrpc_client_traces[rxrpc_client__nr_trace][7];
647363deeabSDavid Howells extern const char rxrpc_conn_cache_states[RXRPC_CONN__NR_CACHE_STATES][5];
648363deeabSDavid Howells 
649fff72429SDavid Howells enum rxrpc_call_trace {
650fff72429SDavid Howells 	rxrpc_call_new_client,
651fff72429SDavid Howells 	rxrpc_call_new_service,
652fff72429SDavid Howells 	rxrpc_call_queued,
653fff72429SDavid Howells 	rxrpc_call_queued_ref,
654fff72429SDavid Howells 	rxrpc_call_seen,
655a84a46d7SDavid Howells 	rxrpc_call_connected,
656a84a46d7SDavid Howells 	rxrpc_call_release,
657fff72429SDavid Howells 	rxrpc_call_got,
658fff72429SDavid Howells 	rxrpc_call_got_userid,
659cbd00891SDavid Howells 	rxrpc_call_got_kernel,
660fff72429SDavid Howells 	rxrpc_call_put,
661fff72429SDavid Howells 	rxrpc_call_put_userid,
662cbd00891SDavid Howells 	rxrpc_call_put_kernel,
663fff72429SDavid Howells 	rxrpc_call_put_noqueue,
664a84a46d7SDavid Howells 	rxrpc_call_error,
665fff72429SDavid Howells 	rxrpc_call__nr_trace
666fff72429SDavid Howells };
667fff72429SDavid Howells 
668fff72429SDavid Howells extern const char rxrpc_call_traces[rxrpc_call__nr_trace][4];
669fff72429SDavid Howells 
670a124fe3eSDavid Howells enum rxrpc_transmit_trace {
671a124fe3eSDavid Howells 	rxrpc_transmit_wait,
672a124fe3eSDavid Howells 	rxrpc_transmit_queue,
673a124fe3eSDavid Howells 	rxrpc_transmit_queue_last,
674a124fe3eSDavid Howells 	rxrpc_transmit_rotate,
67570790dbeSDavid Howells 	rxrpc_transmit_rotate_last,
67670790dbeSDavid Howells 	rxrpc_transmit_await_reply,
677a124fe3eSDavid Howells 	rxrpc_transmit_end,
678a124fe3eSDavid Howells 	rxrpc_transmit__nr_trace
679a124fe3eSDavid Howells };
680a124fe3eSDavid Howells 
681a124fe3eSDavid Howells extern const char rxrpc_transmit_traces[rxrpc_transmit__nr_trace][4];
682a124fe3eSDavid Howells 
68358dc63c9SDavid Howells enum rxrpc_receive_trace {
68458dc63c9SDavid Howells 	rxrpc_receive_incoming,
68558dc63c9SDavid Howells 	rxrpc_receive_queue,
68658dc63c9SDavid Howells 	rxrpc_receive_queue_last,
68758dc63c9SDavid Howells 	rxrpc_receive_front,
68858dc63c9SDavid Howells 	rxrpc_receive_rotate,
68958dc63c9SDavid Howells 	rxrpc_receive_end,
69058dc63c9SDavid Howells 	rxrpc_receive__nr_trace
69158dc63c9SDavid Howells };
69258dc63c9SDavid Howells 
69358dc63c9SDavid Howells extern const char rxrpc_receive_traces[rxrpc_receive__nr_trace][4];
69458dc63c9SDavid Howells 
69584997905SDavid Howells enum rxrpc_recvmsg_trace {
69684997905SDavid Howells 	rxrpc_recvmsg_enter,
69784997905SDavid Howells 	rxrpc_recvmsg_wait,
69884997905SDavid Howells 	rxrpc_recvmsg_dequeue,
69984997905SDavid Howells 	rxrpc_recvmsg_hole,
70084997905SDavid Howells 	rxrpc_recvmsg_next,
70184997905SDavid Howells 	rxrpc_recvmsg_cont,
70284997905SDavid Howells 	rxrpc_recvmsg_full,
70384997905SDavid Howells 	rxrpc_recvmsg_data_return,
70484997905SDavid Howells 	rxrpc_recvmsg_terminal,
70584997905SDavid Howells 	rxrpc_recvmsg_to_be_accepted,
70684997905SDavid Howells 	rxrpc_recvmsg_return,
70784997905SDavid Howells 	rxrpc_recvmsg__nr_trace
70884997905SDavid Howells };
70984997905SDavid Howells 
71084997905SDavid Howells extern const char rxrpc_recvmsg_traces[rxrpc_recvmsg__nr_trace][5];
71184997905SDavid Howells 
712cf1a6474SDavid Howells enum rxrpc_rtt_tx_trace {
713cf1a6474SDavid Howells 	rxrpc_rtt_tx_ping,
71450235c4bSDavid Howells 	rxrpc_rtt_tx_data,
715cf1a6474SDavid Howells 	rxrpc_rtt_tx__nr_trace
716cf1a6474SDavid Howells };
717cf1a6474SDavid Howells 
718cf1a6474SDavid Howells extern const char rxrpc_rtt_tx_traces[rxrpc_rtt_tx__nr_trace][5];
719cf1a6474SDavid Howells 
720cf1a6474SDavid Howells enum rxrpc_rtt_rx_trace {
721cf1a6474SDavid Howells 	rxrpc_rtt_rx_ping_response,
72250235c4bSDavid Howells 	rxrpc_rtt_rx_requested_ack,
723cf1a6474SDavid Howells 	rxrpc_rtt_rx__nr_trace
724cf1a6474SDavid Howells };
725cf1a6474SDavid Howells 
726cf1a6474SDavid Howells extern const char rxrpc_rtt_rx_traces[rxrpc_rtt_rx__nr_trace][5];
727cf1a6474SDavid Howells 
728fc7ab6d2SDavid Howells enum rxrpc_timer_trace {
729fc7ab6d2SDavid Howells 	rxrpc_timer_begin,
730dd7c1ee5SDavid Howells 	rxrpc_timer_init_for_reply,
731fc7ab6d2SDavid Howells 	rxrpc_timer_expired,
732fc7ab6d2SDavid Howells 	rxrpc_timer_set_for_ack,
733fc7ab6d2SDavid Howells 	rxrpc_timer_set_for_resend,
734fc7ab6d2SDavid Howells 	rxrpc_timer_set_for_send,
735fc7ab6d2SDavid Howells 	rxrpc_timer__nr_trace
736fc7ab6d2SDavid Howells };
737fc7ab6d2SDavid Howells 
738fc7ab6d2SDavid Howells extern const char rxrpc_timer_traces[rxrpc_timer__nr_trace][8];
739fc7ab6d2SDavid Howells 
7409c7ad434SDavid Howells enum rxrpc_propose_ack_trace {
7410d967960SDavid Howells 	rxrpc_propose_ack_client_tx_end,
7429c7ad434SDavid Howells 	rxrpc_propose_ack_input_data,
74357494343SDavid Howells 	rxrpc_propose_ack_ping_for_lost_ack,
7440d967960SDavid Howells 	rxrpc_propose_ack_ping_for_lost_reply,
7459c7ad434SDavid Howells 	rxrpc_propose_ack_ping_for_params,
7469c7ad434SDavid Howells 	rxrpc_propose_ack_respond_to_ack,
7479c7ad434SDavid Howells 	rxrpc_propose_ack_respond_to_ping,
7489c7ad434SDavid Howells 	rxrpc_propose_ack_retry_tx,
749805b21b9SDavid Howells 	rxrpc_propose_ack_rotate_rx,
7509c7ad434SDavid Howells 	rxrpc_propose_ack_terminal_ack,
7519c7ad434SDavid Howells 	rxrpc_propose_ack__nr_trace
7529c7ad434SDavid Howells };
7539c7ad434SDavid Howells 
7549c7ad434SDavid Howells enum rxrpc_propose_ack_outcome {
7559c7ad434SDavid Howells 	rxrpc_propose_ack_use,
7569c7ad434SDavid Howells 	rxrpc_propose_ack_update,
7579c7ad434SDavid Howells 	rxrpc_propose_ack_subsume,
7589c7ad434SDavid Howells 	rxrpc_propose_ack__nr_outcomes
7599c7ad434SDavid Howells };
7609c7ad434SDavid Howells 
7619c7ad434SDavid Howells extern const char rxrpc_propose_ack_traces[rxrpc_propose_ack__nr_trace][8];
7629c7ad434SDavid Howells extern const char *const rxrpc_propose_ack_outcomes[rxrpc_propose_ack__nr_outcomes];
7639c7ad434SDavid Howells 
76457494343SDavid Howells enum rxrpc_congest_change {
76557494343SDavid Howells 	rxrpc_cong_begin_retransmission,
76657494343SDavid Howells 	rxrpc_cong_cleared_nacks,
76757494343SDavid Howells 	rxrpc_cong_new_low_nack,
76857494343SDavid Howells 	rxrpc_cong_no_change,
76957494343SDavid Howells 	rxrpc_cong_progress,
77057494343SDavid Howells 	rxrpc_cong_retransmit_again,
77157494343SDavid Howells 	rxrpc_cong_rtt_window_end,
77257494343SDavid Howells 	rxrpc_cong_saw_nack,
77357494343SDavid Howells 	rxrpc_congest__nr_change
77457494343SDavid Howells };
77557494343SDavid Howells 
77657494343SDavid Howells extern const char rxrpc_congest_modes[NR__RXRPC_CONGEST_MODES][10];
77757494343SDavid Howells extern const char rxrpc_congest_changes[rxrpc_congest__nr_change][9];
77857494343SDavid Howells 
779a3868bfcSDavid Howells extern const char *const rxrpc_pkts[];
78019c0dbd5SDavid Howells extern const char rxrpc_ack_names[RXRPC_ACK__INVALID + 1][4];
781a3868bfcSDavid Howells 
782df844fd4SDavid Howells #include <trace/events/rxrpc.h>
783df844fd4SDavid Howells 
78417926a79SDavid Howells /*
785651350d1SDavid Howells  * af_rxrpc.c
78617926a79SDavid Howells  */
78771f3ca40SDavid Howells extern atomic_t rxrpc_n_tx_skbs, rxrpc_n_rx_skbs;
7880d12f8a4SDavid Howells extern u32 rxrpc_epoch;
789651350d1SDavid Howells extern atomic_t rxrpc_debug_id;
790651350d1SDavid Howells extern struct workqueue_struct *rxrpc_workqueue;
79117926a79SDavid Howells 
79217926a79SDavid Howells /*
7930d81a51aSDavid Howells  * call_accept.c
79417926a79SDavid Howells  */
79500e90712SDavid Howells int rxrpc_service_prealloc(struct rxrpc_sock *, gfp_t);
79600e90712SDavid Howells void rxrpc_discard_prealloc(struct rxrpc_sock *);
797248f219cSDavid Howells struct rxrpc_call *rxrpc_new_incoming_call(struct rxrpc_local *,
798248f219cSDavid Howells 					   struct rxrpc_connection *,
799248f219cSDavid Howells 					   struct sk_buff *);
8004f95dd78SDavid Howells void rxrpc_accept_incoming_calls(struct rxrpc_local *);
801d001648eSDavid Howells struct rxrpc_call *rxrpc_accept_call(struct rxrpc_sock *, unsigned long,
802d001648eSDavid Howells 				     rxrpc_notify_rx_t);
803c1b1203dSJoe Perches int rxrpc_reject_call(struct rxrpc_sock *);
80417926a79SDavid Howells 
80517926a79SDavid Howells /*
8060d81a51aSDavid Howells  * call_event.c
80717926a79SDavid Howells  */
808df0adc78SDavid Howells void rxrpc_set_timer(struct rxrpc_call *, enum rxrpc_timer_trace, ktime_t);
8099c7ad434SDavid Howells void rxrpc_propose_ACK(struct rxrpc_call *, u8, u16, u32, bool, bool,
8109c7ad434SDavid Howells 		       enum rxrpc_propose_ack_trace);
811c1b1203dSJoe Perches void rxrpc_process_call(struct work_struct *);
81217926a79SDavid Howells 
81317926a79SDavid Howells /*
8140d81a51aSDavid Howells  * call_object.c
81517926a79SDavid Howells  */
816f5c17aaeSDavid Howells extern const char *const rxrpc_call_states[];
817f5c17aaeSDavid Howells extern const char *const rxrpc_call_completions[];
818dad8aff7SDavid Howells extern unsigned int rxrpc_max_call_lifetime;
81917926a79SDavid Howells extern struct kmem_cache *rxrpc_call_jar;
82017926a79SDavid Howells extern struct list_head rxrpc_calls;
82117926a79SDavid Howells extern rwlock_t rxrpc_call_lock;
82217926a79SDavid Howells 
8232341e077SDavid Howells struct rxrpc_call *rxrpc_find_call_by_user_ID(struct rxrpc_sock *, unsigned long);
82400e90712SDavid Howells struct rxrpc_call *rxrpc_alloc_call(gfp_t);
8252341e077SDavid Howells struct rxrpc_call *rxrpc_new_client_call(struct rxrpc_sock *,
82619ffa01cSDavid Howells 					 struct rxrpc_conn_parameters *,
827999b69f8SDavid Howells 					 struct sockaddr_rxrpc *,
8282341e077SDavid Howells 					 unsigned long, gfp_t);
829248f219cSDavid Howells void rxrpc_incoming_call(struct rxrpc_sock *, struct rxrpc_call *,
83042886ffeSDavid Howells 			 struct sk_buff *);
8318d94aa38SDavid Howells void rxrpc_release_call(struct rxrpc_sock *, struct rxrpc_call *);
832c1b1203dSJoe Perches void rxrpc_release_calls_on_socket(struct rxrpc_sock *);
8338d94aa38SDavid Howells bool __rxrpc_queue_call(struct rxrpc_call *);
8348d94aa38SDavid Howells bool rxrpc_queue_call(struct rxrpc_call *);
835e34d4234SDavid Howells void rxrpc_see_call(struct rxrpc_call *);
836fff72429SDavid Howells void rxrpc_get_call(struct rxrpc_call *, enum rxrpc_call_trace);
837fff72429SDavid Howells void rxrpc_put_call(struct rxrpc_call *, enum rxrpc_call_trace);
83800e90712SDavid Howells void rxrpc_cleanup_call(struct rxrpc_call *);
839c1b1203dSJoe Perches void __exit rxrpc_destroy_all_calls(void);
84017926a79SDavid Howells 
841dabe5a79SDavid Howells static inline bool rxrpc_is_service_call(const struct rxrpc_call *call)
842dabe5a79SDavid Howells {
843dabe5a79SDavid Howells 	return test_bit(RXRPC_CALL_IS_SERVICE, &call->flags);
844dabe5a79SDavid Howells }
845dabe5a79SDavid Howells 
846dabe5a79SDavid Howells static inline bool rxrpc_is_client_call(const struct rxrpc_call *call)
847dabe5a79SDavid Howells {
848dabe5a79SDavid Howells 	return !rxrpc_is_service_call(call);
849dabe5a79SDavid Howells }
850dabe5a79SDavid Howells 
85117926a79SDavid Howells /*
852f5c17aaeSDavid Howells  * Transition a call to the complete state.
853f5c17aaeSDavid Howells  */
854f5c17aaeSDavid Howells static inline bool __rxrpc_set_call_completion(struct rxrpc_call *call,
855f5c17aaeSDavid Howells 					       enum rxrpc_call_completion compl,
856f5c17aaeSDavid Howells 					       u32 abort_code,
857f5c17aaeSDavid Howells 					       int error)
858f5c17aaeSDavid Howells {
859f5c17aaeSDavid Howells 	if (call->state < RXRPC_CALL_COMPLETE) {
860f5c17aaeSDavid Howells 		call->abort_code = abort_code;
861f5c17aaeSDavid Howells 		call->error = error;
862f5c17aaeSDavid Howells 		call->completion = compl,
863f5c17aaeSDavid Howells 		call->state = RXRPC_CALL_COMPLETE;
864c0d058c2SDavid Howells 		wake_up(&call->waitq);
865f5c17aaeSDavid Howells 		return true;
866f5c17aaeSDavid Howells 	}
867f5c17aaeSDavid Howells 	return false;
868f5c17aaeSDavid Howells }
869f5c17aaeSDavid Howells 
870f5c17aaeSDavid Howells static inline bool rxrpc_set_call_completion(struct rxrpc_call *call,
871f5c17aaeSDavid Howells 					     enum rxrpc_call_completion compl,
872f5c17aaeSDavid Howells 					     u32 abort_code,
873f5c17aaeSDavid Howells 					     int error)
874f5c17aaeSDavid Howells {
875e8d6bbb0SDavid Howells 	bool ret;
876f5c17aaeSDavid Howells 
877f5c17aaeSDavid Howells 	write_lock_bh(&call->state_lock);
878f5c17aaeSDavid Howells 	ret = __rxrpc_set_call_completion(call, compl, abort_code, error);
879f5c17aaeSDavid Howells 	write_unlock_bh(&call->state_lock);
880f5c17aaeSDavid Howells 	return ret;
881f5c17aaeSDavid Howells }
882f5c17aaeSDavid Howells 
883f5c17aaeSDavid Howells /*
884f5c17aaeSDavid Howells  * Record that a call successfully completed.
885f5c17aaeSDavid Howells  */
886e8d6bbb0SDavid Howells static inline bool __rxrpc_call_completed(struct rxrpc_call *call)
887f5c17aaeSDavid Howells {
888e8d6bbb0SDavid Howells 	return __rxrpc_set_call_completion(call, RXRPC_CALL_SUCCEEDED, 0, 0);
889f5c17aaeSDavid Howells }
890f5c17aaeSDavid Howells 
891e8d6bbb0SDavid Howells static inline bool rxrpc_call_completed(struct rxrpc_call *call)
892f5c17aaeSDavid Howells {
893e8d6bbb0SDavid Howells 	bool ret;
894e8d6bbb0SDavid Howells 
895f5c17aaeSDavid Howells 	write_lock_bh(&call->state_lock);
896e8d6bbb0SDavid Howells 	ret = __rxrpc_call_completed(call);
897f5c17aaeSDavid Howells 	write_unlock_bh(&call->state_lock);
898e8d6bbb0SDavid Howells 	return ret;
899f5c17aaeSDavid Howells }
900f5c17aaeSDavid Howells 
901f5c17aaeSDavid Howells /*
902f5c17aaeSDavid Howells  * Record that a call is locally aborted.
903f5c17aaeSDavid Howells  */
9045a42976dSDavid Howells static inline bool __rxrpc_abort_call(const char *why, struct rxrpc_call *call,
9055a42976dSDavid Howells 				      rxrpc_seq_t seq,
906f5c17aaeSDavid Howells 				      u32 abort_code, int error)
907f5c17aaeSDavid Howells {
9085a42976dSDavid Howells 	trace_rxrpc_abort(why, call->cid, call->call_id, seq,
9095a42976dSDavid Howells 			  abort_code, error);
910248f219cSDavid Howells 	return __rxrpc_set_call_completion(call, RXRPC_CALL_LOCALLY_ABORTED,
911248f219cSDavid Howells 					   abort_code, error);
912f5c17aaeSDavid Howells }
913f5c17aaeSDavid Howells 
9145a42976dSDavid Howells static inline bool rxrpc_abort_call(const char *why, struct rxrpc_call *call,
9155a42976dSDavid Howells 				    rxrpc_seq_t seq, u32 abort_code, int error)
916f5c17aaeSDavid Howells {
917f5c17aaeSDavid Howells 	bool ret;
918f5c17aaeSDavid Howells 
919f5c17aaeSDavid Howells 	write_lock_bh(&call->state_lock);
9205a42976dSDavid Howells 	ret = __rxrpc_abort_call(why, call, seq, abort_code, error);
921f5c17aaeSDavid Howells 	write_unlock_bh(&call->state_lock);
922f5c17aaeSDavid Howells 	return ret;
923f5c17aaeSDavid Howells }
924f5c17aaeSDavid Howells 
925f5c17aaeSDavid Howells /*
9264a3388c8SDavid Howells  * conn_client.c
9274a3388c8SDavid Howells  */
92845025bceSDavid Howells extern unsigned int rxrpc_max_client_connections;
92945025bceSDavid Howells extern unsigned int rxrpc_reap_client_connections;
93045025bceSDavid Howells extern unsigned int rxrpc_conn_idle_client_expiry;
93145025bceSDavid Howells extern unsigned int rxrpc_conn_idle_client_fast_expiry;
9324a3388c8SDavid Howells extern struct idr rxrpc_client_conn_ids;
9334a3388c8SDavid Howells 
934eb9b9d22SDavid Howells void rxrpc_destroy_client_conn_ids(void);
935c6d2b8d7SDavid Howells int rxrpc_connect_call(struct rxrpc_call *, struct rxrpc_conn_parameters *,
936c6d2b8d7SDavid Howells 		       struct sockaddr_rxrpc *, gfp_t);
93745025bceSDavid Howells void rxrpc_expose_client_call(struct rxrpc_call *);
93845025bceSDavid Howells void rxrpc_disconnect_client_call(struct rxrpc_call *);
93945025bceSDavid Howells void rxrpc_put_client_conn(struct rxrpc_connection *);
94045025bceSDavid Howells void __exit rxrpc_destroy_all_client_connections(void);
9414a3388c8SDavid Howells 
9424a3388c8SDavid Howells /*
9430d81a51aSDavid Howells  * conn_event.c
9440d81a51aSDavid Howells  */
9450d81a51aSDavid Howells void rxrpc_process_connection(struct work_struct *);
9460d81a51aSDavid Howells 
9470d81a51aSDavid Howells /*
9480d81a51aSDavid Howells  * conn_object.c
94917926a79SDavid Howells  */
950dad8aff7SDavid Howells extern unsigned int rxrpc_connection_expiry;
95117926a79SDavid Howells extern struct list_head rxrpc_connections;
9524d028b2cSDavid Howells extern struct list_head rxrpc_connection_proc_list;
95317926a79SDavid Howells extern rwlock_t rxrpc_connection_lock;
95417926a79SDavid Howells 
9558496af50SDavid Howells int rxrpc_extract_addr_from_skb(struct sockaddr_rxrpc *, struct sk_buff *);
956c6d2b8d7SDavid Howells struct rxrpc_connection *rxrpc_alloc_connection(gfp_t);
9578496af50SDavid Howells struct rxrpc_connection *rxrpc_find_connection_rcu(struct rxrpc_local *,
958aa390bbeSDavid Howells 						   struct sk_buff *);
95945025bceSDavid Howells void __rxrpc_disconnect_call(struct rxrpc_connection *, struct rxrpc_call *);
960999b69f8SDavid Howells void rxrpc_disconnect_call(struct rxrpc_call *);
96145025bceSDavid Howells void rxrpc_kill_connection(struct rxrpc_connection *);
962363deeabSDavid Howells bool rxrpc_queue_conn(struct rxrpc_connection *);
963363deeabSDavid Howells void rxrpc_see_connection(struct rxrpc_connection *);
964363deeabSDavid Howells void rxrpc_get_connection(struct rxrpc_connection *);
965363deeabSDavid Howells struct rxrpc_connection *rxrpc_get_connection_maybe(struct rxrpc_connection *);
966363deeabSDavid Howells void rxrpc_put_service_conn(struct rxrpc_connection *);
967c1b1203dSJoe Perches void __exit rxrpc_destroy_all_connections(void);
96817926a79SDavid Howells 
96919ffa01cSDavid Howells static inline bool rxrpc_conn_is_client(const struct rxrpc_connection *conn)
97019ffa01cSDavid Howells {
97119ffa01cSDavid Howells 	return conn->out_clientflag;
97219ffa01cSDavid Howells }
97319ffa01cSDavid Howells 
97419ffa01cSDavid Howells static inline bool rxrpc_conn_is_service(const struct rxrpc_connection *conn)
97519ffa01cSDavid Howells {
976e8d70ce1SDavid Howells 	return !rxrpc_conn_is_client(conn);
97719ffa01cSDavid Howells }
97819ffa01cSDavid Howells 
979f51b4480SDavid Howells static inline void rxrpc_put_connection(struct rxrpc_connection *conn)
980f51b4480SDavid Howells {
98145025bceSDavid Howells 	if (!conn)
98245025bceSDavid Howells 		return;
98345025bceSDavid Howells 
984363deeabSDavid Howells 	if (rxrpc_conn_is_client(conn))
98545025bceSDavid Howells 		rxrpc_put_client_conn(conn);
986363deeabSDavid Howells 	else
987363deeabSDavid Howells 		rxrpc_put_service_conn(conn);
9885acbee46SDavid Howells }
9895acbee46SDavid Howells 
99017926a79SDavid Howells /*
9917877a4a4SDavid Howells  * conn_service.c
9927877a4a4SDavid Howells  */
9938496af50SDavid Howells struct rxrpc_connection *rxrpc_find_service_conn_rcu(struct rxrpc_peer *,
9948496af50SDavid Howells 						     struct sk_buff *);
99500e90712SDavid Howells struct rxrpc_connection *rxrpc_prealloc_service_connection(gfp_t);
996248f219cSDavid Howells void rxrpc_new_incoming_connection(struct rxrpc_connection *, struct sk_buff *);
997001c1122SDavid Howells void rxrpc_unpublish_service_conn(struct rxrpc_connection *);
9987877a4a4SDavid Howells 
9997877a4a4SDavid Howells /*
10000d81a51aSDavid Howells  * input.c
100117926a79SDavid Howells  */
1002676d2369SDavid S. Miller void rxrpc_data_ready(struct sock *);
100317926a79SDavid Howells 
100417926a79SDavid Howells /*
10050d81a51aSDavid Howells  * insecure.c
100617926a79SDavid Howells  */
10070d81a51aSDavid Howells extern const struct rxrpc_security rxrpc_no_security;
100817926a79SDavid Howells 
100917926a79SDavid Howells /*
10100d81a51aSDavid Howells  * key.c
101117926a79SDavid Howells  */
101217926a79SDavid Howells extern struct key_type key_type_rxrpc;
101317926a79SDavid Howells extern struct key_type key_type_rxrpc_s;
101417926a79SDavid Howells 
1015c1b1203dSJoe Perches int rxrpc_request_key(struct rxrpc_sock *, char __user *, int);
1016c1b1203dSJoe Perches int rxrpc_server_keyring(struct rxrpc_sock *, char __user *, int);
1017c1b1203dSJoe Perches int rxrpc_get_server_data_key(struct rxrpc_connection *, const void *, time_t,
1018c1b1203dSJoe Perches 			      u32);
101917926a79SDavid Howells 
102017926a79SDavid Howells /*
102187563616SDavid Howells  * local_event.c
102287563616SDavid Howells  */
10234f95dd78SDavid Howells extern void rxrpc_process_local_events(struct rxrpc_local *);
102487563616SDavid Howells 
102587563616SDavid Howells /*
10260d81a51aSDavid Howells  * local_object.c
102717926a79SDavid Howells  */
10284f95dd78SDavid Howells struct rxrpc_local *rxrpc_lookup_local(const struct sockaddr_rxrpc *);
10294f95dd78SDavid Howells void __rxrpc_put_local(struct rxrpc_local *);
10300d81a51aSDavid Howells void __exit rxrpc_destroy_all_locals(void);
1031e0e4d82fSDavid Howells 
10324f95dd78SDavid Howells static inline void rxrpc_get_local(struct rxrpc_local *local)
10334f95dd78SDavid Howells {
10344f95dd78SDavid Howells 	atomic_inc(&local->usage);
10354f95dd78SDavid Howells }
10364f95dd78SDavid Howells 
10374f95dd78SDavid Howells static inline
10384f95dd78SDavid Howells struct rxrpc_local *rxrpc_get_local_maybe(struct rxrpc_local *local)
10394f95dd78SDavid Howells {
10404f95dd78SDavid Howells 	return atomic_inc_not_zero(&local->usage) ? local : NULL;
10414f95dd78SDavid Howells }
10424f95dd78SDavid Howells 
10434f95dd78SDavid Howells static inline void rxrpc_put_local(struct rxrpc_local *local)
10444f95dd78SDavid Howells {
10455627cc8bSDavid Howells 	if (local && atomic_dec_and_test(&local->usage))
10464f95dd78SDavid Howells 		__rxrpc_put_local(local);
10474f95dd78SDavid Howells }
10484f95dd78SDavid Howells 
10495acbee46SDavid Howells static inline void rxrpc_queue_local(struct rxrpc_local *local)
10505acbee46SDavid Howells {
10515acbee46SDavid Howells 	rxrpc_queue_work(&local->processor);
10525acbee46SDavid Howells }
10535acbee46SDavid Howells 
1054e0e4d82fSDavid Howells /*
10558e688d9cSDavid Howells  * misc.c
10568e688d9cSDavid Howells  */
10570e119b41SDavid Howells extern unsigned int rxrpc_max_backlog __read_mostly;
10588e688d9cSDavid Howells extern unsigned int rxrpc_requested_ack_delay;
10598e688d9cSDavid Howells extern unsigned int rxrpc_soft_ack_delay;
10608e688d9cSDavid Howells extern unsigned int rxrpc_idle_ack_delay;
10618e688d9cSDavid Howells extern unsigned int rxrpc_rx_window_size;
10628e688d9cSDavid Howells extern unsigned int rxrpc_rx_mtu;
10638e688d9cSDavid Howells extern unsigned int rxrpc_rx_jumbo_max;
10640b58b8a1SDavid Howells extern unsigned int rxrpc_resend_timeout;
10658e688d9cSDavid Howells 
10668e688d9cSDavid Howells extern const s8 rxrpc_ack_priority[];
10678e688d9cSDavid Howells 
10688e688d9cSDavid Howells /*
10690d81a51aSDavid Howells  * output.c
10700d81a51aSDavid Howells  */
107126cb02aaSDavid Howells int rxrpc_send_ack_packet(struct rxrpc_call *);
107226cb02aaSDavid Howells int rxrpc_send_abort_packet(struct rxrpc_call *);
1073a1767077SDavid Howells int rxrpc_send_data_packet(struct rxrpc_call *, struct sk_buff *, bool);
1074248f219cSDavid Howells void rxrpc_reject_packets(struct rxrpc_local *);
10750d81a51aSDavid Howells 
10760d81a51aSDavid Howells /*
1077abe89ef0SDavid Howells  * peer_event.c
10780d81a51aSDavid Howells  */
1079abe89ef0SDavid Howells void rxrpc_error_report(struct sock *);
1080f66d7490SDavid Howells void rxrpc_peer_error_distributor(struct work_struct *);
1081cf1a6474SDavid Howells void rxrpc_peer_add_rtt(struct rxrpc_call *, enum rxrpc_rtt_rx_trace,
1082cf1a6474SDavid Howells 			rxrpc_serial_t, rxrpc_serial_t, ktime_t, ktime_t);
10830d81a51aSDavid Howells 
10840d81a51aSDavid Howells /*
10850d81a51aSDavid Howells  * peer_object.c
10860d81a51aSDavid Howells  */
1087be6e6707SDavid Howells struct rxrpc_peer *rxrpc_lookup_peer_rcu(struct rxrpc_local *,
1088be6e6707SDavid Howells 					 const struct sockaddr_rxrpc *);
1089be6e6707SDavid Howells struct rxrpc_peer *rxrpc_lookup_peer(struct rxrpc_local *,
1090be6e6707SDavid Howells 				     struct sockaddr_rxrpc *, gfp_t);
1091be6e6707SDavid Howells struct rxrpc_peer *rxrpc_alloc_peer(struct rxrpc_local *, gfp_t);
1092248f219cSDavid Howells struct rxrpc_peer *rxrpc_lookup_incoming_peer(struct rxrpc_local *,
1093248f219cSDavid Howells 					      struct rxrpc_peer *);
1094be6e6707SDavid Howells 
1095df5d8bf7SDavid Howells static inline struct rxrpc_peer *rxrpc_get_peer(struct rxrpc_peer *peer)
1096be6e6707SDavid Howells {
1097be6e6707SDavid Howells 	atomic_inc(&peer->usage);
1098df5d8bf7SDavid Howells 	return peer;
1099be6e6707SDavid Howells }
1100be6e6707SDavid Howells 
1101be6e6707SDavid Howells static inline
1102be6e6707SDavid Howells struct rxrpc_peer *rxrpc_get_peer_maybe(struct rxrpc_peer *peer)
1103be6e6707SDavid Howells {
1104be6e6707SDavid Howells 	return atomic_inc_not_zero(&peer->usage) ? peer : NULL;
1105be6e6707SDavid Howells }
1106be6e6707SDavid Howells 
1107be6e6707SDavid Howells extern void __rxrpc_put_peer(struct rxrpc_peer *peer);
1108be6e6707SDavid Howells static inline void rxrpc_put_peer(struct rxrpc_peer *peer)
1109be6e6707SDavid Howells {
11105627cc8bSDavid Howells 	if (peer && atomic_dec_and_test(&peer->usage))
1111be6e6707SDavid Howells 		__rxrpc_put_peer(peer);
1112be6e6707SDavid Howells }
11130d81a51aSDavid Howells 
11140d81a51aSDavid Howells /*
11150d81a51aSDavid Howells  * proc.c
11160d81a51aSDavid Howells  */
11170d81a51aSDavid Howells extern const struct file_operations rxrpc_call_seq_fops;
11180d81a51aSDavid Howells extern const struct file_operations rxrpc_connection_seq_fops;
11190d81a51aSDavid Howells 
11200d81a51aSDavid Howells /*
11210d81a51aSDavid Howells  * recvmsg.c
11220d81a51aSDavid Howells  */
1123248f219cSDavid Howells void rxrpc_notify_socket(struct rxrpc_call *);
11240d81a51aSDavid Howells int rxrpc_recvmsg(struct socket *, struct msghdr *, size_t, int);
11250d81a51aSDavid Howells 
11260d81a51aSDavid Howells /*
1127648af7fcSDavid Howells  * rxkad.c
1128648af7fcSDavid Howells  */
1129648af7fcSDavid Howells #ifdef CONFIG_RXKAD
1130648af7fcSDavid Howells extern const struct rxrpc_security rxkad;
1131648af7fcSDavid Howells #endif
1132648af7fcSDavid Howells 
1133648af7fcSDavid Howells /*
11340d81a51aSDavid Howells  * security.c
11350d81a51aSDavid Howells  */
11360d81a51aSDavid Howells int __init rxrpc_init_security(void);
11370d81a51aSDavid Howells void rxrpc_exit_security(void);
11380d81a51aSDavid Howells int rxrpc_init_client_conn_security(struct rxrpc_connection *);
11390d81a51aSDavid Howells int rxrpc_init_server_conn_security(struct rxrpc_connection *);
11400d81a51aSDavid Howells 
11410d81a51aSDavid Howells /*
11420b58b8a1SDavid Howells  * sendmsg.c
11430b58b8a1SDavid Howells  */
11440b58b8a1SDavid Howells int rxrpc_do_sendmsg(struct rxrpc_sock *, struct msghdr *, size_t);
11450b58b8a1SDavid Howells 
11460b58b8a1SDavid Howells /*
11470d81a51aSDavid Howells  * skbuff.c
11480d81a51aSDavid Howells  */
1149d001648eSDavid Howells void rxrpc_kernel_data_consumed(struct rxrpc_call *, struct sk_buff *);
11500d81a51aSDavid Howells void rxrpc_packet_destructor(struct sk_buff *);
115171f3ca40SDavid Howells void rxrpc_new_skb(struct sk_buff *, enum rxrpc_skb_trace);
115271f3ca40SDavid Howells void rxrpc_see_skb(struct sk_buff *, enum rxrpc_skb_trace);
115371f3ca40SDavid Howells void rxrpc_get_skb(struct sk_buff *, enum rxrpc_skb_trace);
115471f3ca40SDavid Howells void rxrpc_free_skb(struct sk_buff *, enum rxrpc_skb_trace);
115571f3ca40SDavid Howells void rxrpc_lose_skb(struct sk_buff *, enum rxrpc_skb_trace);
1156df844fd4SDavid Howells void rxrpc_purge_queue(struct sk_buff_head *);
11570d81a51aSDavid Howells 
11580d81a51aSDavid Howells /*
11595873c083SDavid Howells  * sysctl.c
11605873c083SDavid Howells  */
11615873c083SDavid Howells #ifdef CONFIG_SYSCTL
11625873c083SDavid Howells extern int __init rxrpc_sysctl_init(void);
11635873c083SDavid Howells extern void rxrpc_sysctl_exit(void);
11645873c083SDavid Howells #else
11655873c083SDavid Howells static inline int __init rxrpc_sysctl_init(void) { return 0; }
11665873c083SDavid Howells static inline void rxrpc_sysctl_exit(void) {}
11675873c083SDavid Howells #endif
11685873c083SDavid Howells 
11695873c083SDavid Howells /*
1170be6e6707SDavid Howells  * utils.c
1171be6e6707SDavid Howells  */
1172d991b4a3SDavid Howells int rxrpc_extract_addr_from_skb(struct sockaddr_rxrpc *, struct sk_buff *);
1173be6e6707SDavid Howells 
1174248f219cSDavid Howells static inline bool before(u32 seq1, u32 seq2)
1175248f219cSDavid Howells {
1176248f219cSDavid Howells         return (s32)(seq1 - seq2) < 0;
1177248f219cSDavid Howells }
1178248f219cSDavid Howells static inline bool before_eq(u32 seq1, u32 seq2)
1179248f219cSDavid Howells {
1180248f219cSDavid Howells         return (s32)(seq1 - seq2) <= 0;
1181248f219cSDavid Howells }
1182248f219cSDavid Howells static inline bool after(u32 seq1, u32 seq2)
1183248f219cSDavid Howells {
1184248f219cSDavid Howells         return (s32)(seq1 - seq2) > 0;
1185248f219cSDavid Howells }
1186248f219cSDavid Howells static inline bool after_eq(u32 seq1, u32 seq2)
1187248f219cSDavid Howells {
1188248f219cSDavid Howells         return (s32)(seq1 - seq2) >= 0;
1189248f219cSDavid Howells }
1190248f219cSDavid Howells 
1191be6e6707SDavid Howells /*
119217926a79SDavid Howells  * debug tracing
119317926a79SDavid Howells  */
119495c96174SEric Dumazet extern unsigned int rxrpc_debug;
119517926a79SDavid Howells 
119617926a79SDavid Howells #define dbgprintk(FMT,...) \
11979f389f4bSSven Schnelle 	printk("[%-6.6s] "FMT"\n", current->comm ,##__VA_ARGS__)
119817926a79SDavid Howells 
11990dc47877SHarvey Harrison #define kenter(FMT,...)	dbgprintk("==> %s("FMT")",__func__ ,##__VA_ARGS__)
12000dc47877SHarvey Harrison #define kleave(FMT,...)	dbgprintk("<== %s()"FMT"",__func__ ,##__VA_ARGS__)
120117926a79SDavid Howells #define kdebug(FMT,...)	dbgprintk("    "FMT ,##__VA_ARGS__)
120217926a79SDavid Howells #define kproto(FMT,...)	dbgprintk("### "FMT ,##__VA_ARGS__)
120317926a79SDavid Howells #define knet(FMT,...)	dbgprintk("@@@ "FMT ,##__VA_ARGS__)
120417926a79SDavid Howells 
120517926a79SDavid Howells 
120617926a79SDavid Howells #if defined(__KDEBUG)
120717926a79SDavid Howells #define _enter(FMT,...)	kenter(FMT,##__VA_ARGS__)
120817926a79SDavid Howells #define _leave(FMT,...)	kleave(FMT,##__VA_ARGS__)
120917926a79SDavid Howells #define _debug(FMT,...)	kdebug(FMT,##__VA_ARGS__)
121017926a79SDavid Howells #define _proto(FMT,...)	kproto(FMT,##__VA_ARGS__)
121117926a79SDavid Howells #define _net(FMT,...)	knet(FMT,##__VA_ARGS__)
121217926a79SDavid Howells 
121317926a79SDavid Howells #elif defined(CONFIG_AF_RXRPC_DEBUG)
121417926a79SDavid Howells #define RXRPC_DEBUG_KENTER	0x01
121517926a79SDavid Howells #define RXRPC_DEBUG_KLEAVE	0x02
121617926a79SDavid Howells #define RXRPC_DEBUG_KDEBUG	0x04
121717926a79SDavid Howells #define RXRPC_DEBUG_KPROTO	0x08
121817926a79SDavid Howells #define RXRPC_DEBUG_KNET	0x10
121917926a79SDavid Howells 
122017926a79SDavid Howells #define _enter(FMT,...)					\
122117926a79SDavid Howells do {							\
122217926a79SDavid Howells 	if (unlikely(rxrpc_debug & RXRPC_DEBUG_KENTER))	\
122317926a79SDavid Howells 		kenter(FMT,##__VA_ARGS__);		\
122417926a79SDavid Howells } while (0)
122517926a79SDavid Howells 
122617926a79SDavid Howells #define _leave(FMT,...)					\
122717926a79SDavid Howells do {							\
122817926a79SDavid Howells 	if (unlikely(rxrpc_debug & RXRPC_DEBUG_KLEAVE))	\
122917926a79SDavid Howells 		kleave(FMT,##__VA_ARGS__);		\
123017926a79SDavid Howells } while (0)
123117926a79SDavid Howells 
123217926a79SDavid Howells #define _debug(FMT,...)					\
123317926a79SDavid Howells do {							\
123417926a79SDavid Howells 	if (unlikely(rxrpc_debug & RXRPC_DEBUG_KDEBUG))	\
123517926a79SDavid Howells 		kdebug(FMT,##__VA_ARGS__);		\
123617926a79SDavid Howells } while (0)
123717926a79SDavid Howells 
123817926a79SDavid Howells #define _proto(FMT,...)					\
123917926a79SDavid Howells do {							\
124017926a79SDavid Howells 	if (unlikely(rxrpc_debug & RXRPC_DEBUG_KPROTO))	\
124117926a79SDavid Howells 		kproto(FMT,##__VA_ARGS__);		\
124217926a79SDavid Howells } while (0)
124317926a79SDavid Howells 
124417926a79SDavid Howells #define _net(FMT,...)					\
124517926a79SDavid Howells do {							\
124617926a79SDavid Howells 	if (unlikely(rxrpc_debug & RXRPC_DEBUG_KNET))	\
124717926a79SDavid Howells 		knet(FMT,##__VA_ARGS__);		\
124817926a79SDavid Howells } while (0)
124917926a79SDavid Howells 
125017926a79SDavid Howells #else
125112fdff3fSDavid Howells #define _enter(FMT,...)	no_printk("==> %s("FMT")",__func__ ,##__VA_ARGS__)
125212fdff3fSDavid Howells #define _leave(FMT,...)	no_printk("<== %s()"FMT"",__func__ ,##__VA_ARGS__)
125312fdff3fSDavid Howells #define _debug(FMT,...)	no_printk("    "FMT ,##__VA_ARGS__)
125412fdff3fSDavid Howells #define _proto(FMT,...)	no_printk("### "FMT ,##__VA_ARGS__)
125512fdff3fSDavid Howells #define _net(FMT,...)	no_printk("@@@ "FMT ,##__VA_ARGS__)
125617926a79SDavid Howells #endif
125717926a79SDavid Howells 
125817926a79SDavid Howells /*
125917926a79SDavid Howells  * debug assertion checking
126017926a79SDavid Howells  */
126117926a79SDavid Howells #if 1 // defined(__KDEBUGALL)
126217926a79SDavid Howells 
126317926a79SDavid Howells #define ASSERT(X)						\
126417926a79SDavid Howells do {								\
126517926a79SDavid Howells 	if (unlikely(!(X))) {					\
12669b6d5398SJoe Perches 		pr_err("Assertion failed\n");			\
126717926a79SDavid Howells 		BUG();						\
126817926a79SDavid Howells 	}							\
126917926a79SDavid Howells } while (0)
127017926a79SDavid Howells 
127117926a79SDavid Howells #define ASSERTCMP(X, OP, Y)						\
127217926a79SDavid Howells do {									\
1273cf13258fSDavid Howells 	__typeof__(X) _x = (X);						\
1274cf13258fSDavid Howells 	__typeof__(Y) _y = (__typeof__(X))(Y);				\
12759b6d5398SJoe Perches 	if (unlikely(!(_x OP _y))) {					\
12769b6d5398SJoe Perches 		pr_err("Assertion failed - %lu(0x%lx) %s %lu(0x%lx) is false\n", \
1277cf13258fSDavid Howells 		       (unsigned long)_x, (unsigned long)_x, #OP,	\
1278cf13258fSDavid Howells 		       (unsigned long)_y, (unsigned long)_y);		\
127917926a79SDavid Howells 		BUG();							\
128017926a79SDavid Howells 	}								\
128117926a79SDavid Howells } while (0)
128217926a79SDavid Howells 
128317926a79SDavid Howells #define ASSERTIF(C, X)						\
128417926a79SDavid Howells do {								\
128517926a79SDavid Howells 	if (unlikely((C) && !(X))) {				\
12869b6d5398SJoe Perches 		pr_err("Assertion failed\n");			\
128717926a79SDavid Howells 		BUG();						\
128817926a79SDavid Howells 	}							\
128917926a79SDavid Howells } while (0)
129017926a79SDavid Howells 
129117926a79SDavid Howells #define ASSERTIFCMP(C, X, OP, Y)					\
129217926a79SDavid Howells do {									\
1293cf13258fSDavid Howells 	__typeof__(X) _x = (X);						\
1294cf13258fSDavid Howells 	__typeof__(Y) _y = (__typeof__(X))(Y);				\
12959b6d5398SJoe Perches 	if (unlikely((C) && !(_x OP _y))) {				\
12969b6d5398SJoe Perches 		pr_err("Assertion failed - %lu(0x%lx) %s %lu(0x%lx) is false\n", \
1297cf13258fSDavid Howells 		       (unsigned long)_x, (unsigned long)_x, #OP,	\
1298cf13258fSDavid Howells 		       (unsigned long)_y, (unsigned long)_y);		\
129917926a79SDavid Howells 		BUG();							\
130017926a79SDavid Howells 	}								\
130117926a79SDavid Howells } while (0)
130217926a79SDavid Howells 
130317926a79SDavid Howells #else
130417926a79SDavid Howells 
130517926a79SDavid Howells #define ASSERT(X)				\
130617926a79SDavid Howells do {						\
130717926a79SDavid Howells } while (0)
130817926a79SDavid Howells 
130917926a79SDavid Howells #define ASSERTCMP(X, OP, Y)			\
131017926a79SDavid Howells do {						\
131117926a79SDavid Howells } while (0)
131217926a79SDavid Howells 
131317926a79SDavid Howells #define ASSERTIF(C, X)				\
131417926a79SDavid Howells do {						\
131517926a79SDavid Howells } while (0)
131617926a79SDavid Howells 
131717926a79SDavid Howells #define ASSERTIFCMP(C, X, OP, Y)		\
131817926a79SDavid Howells do {						\
131917926a79SDavid Howells } while (0)
132017926a79SDavid Howells 
132117926a79SDavid Howells #endif /* __KDEBUGALL */
1322