xref: /openbmc/linux/net/rxrpc/ar-internal.h (revision 00e90712)
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 */
96de8d6c74SDavid Howells 	struct hlist_node	listen_link;	/* link in the local endpoint's listen list */
9717926a79SDavid Howells 	struct list_head	secureq;	/* calls awaiting connection security clearance */
9817926a79SDavid Howells 	struct list_head	acceptq;	/* calls awaiting acceptance */
9900e90712SDavid Howells 	struct rxrpc_backlog	*backlog;	/* Preallocation for services */
10017926a79SDavid Howells 	struct key		*key;		/* security for this socket */
10117926a79SDavid Howells 	struct key		*securities;	/* list of server security descriptors */
10200e90712SDavid Howells 	struct rb_root		calls;		/* User ID -> call mapping */
10317926a79SDavid Howells 	unsigned long		flags;
1042341e077SDavid Howells #define RXRPC_SOCK_CONNECTED		0	/* connect_srx is set */
10517926a79SDavid Howells 	rwlock_t		call_lock;	/* lock for calls */
10617926a79SDavid Howells 	u32			min_sec_level;	/* minimum security level */
10717926a79SDavid Howells #define RXRPC_SECURITY_MAX	RXRPC_SECURITY_ENCRYPT
108cc8feb8eSDavid Howells 	bool			exclusive;	/* Exclusive connection for a client socket */
109cc8feb8eSDavid Howells 	sa_family_t		family;		/* Protocol family created with */
11017926a79SDavid Howells 	struct sockaddr_rxrpc	srx;		/* local address */
1112341e077SDavid Howells 	struct sockaddr_rxrpc	connect_srx;	/* Default client address from connect() */
11217926a79SDavid Howells };
11317926a79SDavid Howells 
11417926a79SDavid Howells #define rxrpc_sk(__sk) container_of((__sk), struct rxrpc_sock, sk)
11517926a79SDavid Howells 
11617926a79SDavid Howells /*
1170d12f8a4SDavid Howells  * CPU-byteorder normalised Rx packet header.
1180d12f8a4SDavid Howells  */
1190d12f8a4SDavid Howells struct rxrpc_host_header {
1200d12f8a4SDavid Howells 	u32		epoch;		/* client boot timestamp */
1210d12f8a4SDavid Howells 	u32		cid;		/* connection and channel ID */
1220d12f8a4SDavid Howells 	u32		callNumber;	/* call ID (0 for connection-level packets) */
1230d12f8a4SDavid Howells 	u32		seq;		/* sequence number of pkt in call stream */
1240d12f8a4SDavid Howells 	u32		serial;		/* serial number of pkt sent to network */
1250d12f8a4SDavid Howells 	u8		type;		/* packet type */
1260d12f8a4SDavid Howells 	u8		flags;		/* packet flags */
1270d12f8a4SDavid Howells 	u8		userStatus;	/* app-layer defined status */
1280d12f8a4SDavid Howells 	u8		securityIndex;	/* security protocol ID */
1290d12f8a4SDavid Howells 	union {
1300d12f8a4SDavid Howells 		u16	_rsvd;		/* reserved */
1310d12f8a4SDavid Howells 		u16	cksum;		/* kerberos security checksum */
1320d12f8a4SDavid Howells 	};
1330d12f8a4SDavid Howells 	u16		serviceId;	/* service ID */
1340d12f8a4SDavid Howells } __packed;
1350d12f8a4SDavid Howells 
1360d12f8a4SDavid Howells /*
13717926a79SDavid Howells  * RxRPC socket buffer private variables
13817926a79SDavid Howells  * - max 48 bytes (struct sk_buff::cb)
13917926a79SDavid Howells  */
14017926a79SDavid Howells struct rxrpc_skb_priv {
14117926a79SDavid Howells 	struct rxrpc_call	*call;		/* call with which associated */
14217926a79SDavid Howells 	unsigned long		resend_at;	/* time in jiffies at which to resend */
14317926a79SDavid Howells 	union {
14495c96174SEric Dumazet 		unsigned int	offset;		/* offset into buffer of next read */
14517926a79SDavid Howells 		int		remain;		/* amount of space remaining for next write */
14617926a79SDavid Howells 		u32		error;		/* network error code */
14717926a79SDavid Howells 		bool		need_resend;	/* T if needs resending */
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 *,
1825a42976dSDavid Howells 			     rxrpc_seq_t, u16);
18317926a79SDavid Howells 
18417926a79SDavid Howells 	/* issue a challenge */
18517926a79SDavid Howells 	int (*issue_challenge)(struct rxrpc_connection *);
18617926a79SDavid Howells 
18717926a79SDavid Howells 	/* respond to a challenge */
18817926a79SDavid Howells 	int (*respond_to_challenge)(struct rxrpc_connection *,
18917926a79SDavid Howells 				    struct sk_buff *,
19017926a79SDavid Howells 				    u32 *);
19117926a79SDavid Howells 
19217926a79SDavid Howells 	/* verify a response */
19317926a79SDavid Howells 	int (*verify_response)(struct rxrpc_connection *,
19417926a79SDavid Howells 			       struct sk_buff *,
19517926a79SDavid Howells 			       u32 *);
19617926a79SDavid Howells 
19717926a79SDavid Howells 	/* clear connection security */
19817926a79SDavid Howells 	void (*clear)(struct rxrpc_connection *);
19917926a79SDavid Howells };
20017926a79SDavid Howells 
20117926a79SDavid Howells /*
2024f95dd78SDavid Howells  * RxRPC local transport endpoint description
2034f95dd78SDavid Howells  * - owned by a single AF_RXRPC socket
2044f95dd78SDavid Howells  * - pointed to by transport socket struct sk_user_data
20517926a79SDavid Howells  */
20617926a79SDavid Howells struct rxrpc_local {
2074f95dd78SDavid Howells 	struct rcu_head		rcu;
2084f95dd78SDavid Howells 	atomic_t		usage;
2094f95dd78SDavid Howells 	struct list_head	link;
21017926a79SDavid Howells 	struct socket		*socket;	/* my UDP socket */
2114f95dd78SDavid Howells 	struct work_struct	processor;
212de8d6c74SDavid Howells 	struct hlist_head	services;	/* services listening on this endpoint */
21317926a79SDavid Howells 	struct rw_semaphore	defrag_sem;	/* control re-enablement of IP DF bit */
21417926a79SDavid Howells 	struct sk_buff_head	accept_queue;	/* incoming calls awaiting acceptance */
21517926a79SDavid Howells 	struct sk_buff_head	reject_queue;	/* packets awaiting rejection */
21644ba0698SDavid Howells 	struct sk_buff_head	event_queue;	/* endpoint event packets awaiting processing */
217999b69f8SDavid Howells 	struct rb_root		client_conns;	/* Client connections by socket params */
218999b69f8SDavid Howells 	spinlock_t		client_conns_lock; /* Lock for client_conns */
21917926a79SDavid Howells 	spinlock_t		lock;		/* access lock */
22017926a79SDavid Howells 	rwlock_t		services_lock;	/* lock for services list */
22117926a79SDavid Howells 	int			debug_id;	/* debug ID for printks */
2224f95dd78SDavid Howells 	bool			dead;
22317926a79SDavid Howells 	struct sockaddr_rxrpc	srx;		/* local address */
22417926a79SDavid Howells };
22517926a79SDavid Howells 
22617926a79SDavid Howells /*
22717926a79SDavid Howells  * RxRPC remote transport endpoint definition
228be6e6707SDavid Howells  * - matched by local endpoint, remote port, address and protocol type
22917926a79SDavid Howells  */
23017926a79SDavid Howells struct rxrpc_peer {
231be6e6707SDavid Howells 	struct rcu_head		rcu;		/* This must be first */
232be6e6707SDavid Howells 	atomic_t		usage;
233be6e6707SDavid Howells 	unsigned long		hash_key;
234be6e6707SDavid Howells 	struct hlist_node	hash_link;
235be6e6707SDavid Howells 	struct rxrpc_local	*local;
236f66d7490SDavid Howells 	struct hlist_head	error_targets;	/* targets for net error distribution */
237f66d7490SDavid Howells 	struct work_struct	error_distributor;
238aa390bbeSDavid Howells 	struct rb_root		service_conns;	/* Service connections */
2398496af50SDavid Howells 	seqlock_t		service_conn_lock;
24017926a79SDavid Howells 	spinlock_t		lock;		/* access lock */
24195c96174SEric Dumazet 	unsigned int		if_mtu;		/* interface MTU for this peer */
24295c96174SEric Dumazet 	unsigned int		mtu;		/* network MTU for this peer */
24395c96174SEric Dumazet 	unsigned int		maxdata;	/* data size (MTU - hdrsize) */
24417926a79SDavid Howells 	unsigned short		hdrsize;	/* header size (IP + UDP + RxRPC) */
24517926a79SDavid Howells 	int			debug_id;	/* debug ID for printks */
246f66d7490SDavid Howells 	int			error_report;	/* Net (+0) or local (+1000000) to distribute */
247f66d7490SDavid Howells #define RXRPC_LOCAL_ERROR_OFFSET 1000000
24817926a79SDavid Howells 	struct sockaddr_rxrpc	srx;		/* remote address */
24917926a79SDavid Howells 
25017926a79SDavid Howells 	/* calculated RTT cache */
25117926a79SDavid Howells #define RXRPC_RTT_CACHE_SIZE 32
25217926a79SDavid Howells 	suseconds_t		rtt;		/* current RTT estimate (in uS) */
25395c96174SEric Dumazet 	unsigned int		rtt_point;	/* next entry at which to insert */
25495c96174SEric Dumazet 	unsigned int		rtt_usage;	/* amount of cache actually used */
25517926a79SDavid Howells 	suseconds_t		rtt_cache[RXRPC_RTT_CACHE_SIZE]; /* calculated RTT cache */
25617926a79SDavid Howells };
25717926a79SDavid Howells 
25817926a79SDavid Howells /*
25919ffa01cSDavid Howells  * Keys for matching a connection.
26019ffa01cSDavid Howells  */
26119ffa01cSDavid Howells struct rxrpc_conn_proto {
262e8d70ce1SDavid Howells 	union {
263e8d70ce1SDavid Howells 		struct {
26419ffa01cSDavid Howells 			u32	epoch;		/* epoch of this connection */
26519ffa01cSDavid Howells 			u32	cid;		/* connection ID */
266e8d70ce1SDavid Howells 		};
267e8d70ce1SDavid Howells 		u64		index_key;
26819ffa01cSDavid Howells 	};
26919ffa01cSDavid Howells };
27019ffa01cSDavid Howells 
27119ffa01cSDavid Howells struct rxrpc_conn_parameters {
27219ffa01cSDavid Howells 	struct rxrpc_local	*local;		/* Representation of local endpoint */
27319ffa01cSDavid Howells 	struct rxrpc_peer	*peer;		/* Remote endpoint */
27419ffa01cSDavid Howells 	struct key		*key;		/* Security details */
27519ffa01cSDavid Howells 	bool			exclusive;	/* T if conn is exclusive */
27619ffa01cSDavid Howells 	u16			service_id;	/* Service ID for this connection */
27719ffa01cSDavid Howells 	u32			security_level;	/* Security level selected */
27819ffa01cSDavid Howells };
27919ffa01cSDavid Howells 
28019ffa01cSDavid Howells /*
281bba304dbSDavid Howells  * Bits in the connection flags.
282bba304dbSDavid Howells  */
283bba304dbSDavid Howells enum rxrpc_conn_flag {
284bba304dbSDavid Howells 	RXRPC_CONN_HAS_IDR,		/* Has a client conn ID assigned */
285001c1122SDavid Howells 	RXRPC_CONN_IN_SERVICE_CONNS,	/* Conn is in peer->service_conns */
286001c1122SDavid Howells 	RXRPC_CONN_IN_CLIENT_CONNS,	/* Conn is in local->client_conns */
28745025bceSDavid Howells 	RXRPC_CONN_EXPOSED,		/* Conn has extra ref for exposure */
28845025bceSDavid Howells 	RXRPC_CONN_DONT_REUSE,		/* Don't reuse this connection */
28945025bceSDavid Howells 	RXRPC_CONN_COUNTED,		/* Counted by rxrpc_nr_client_conns */
290bba304dbSDavid Howells };
291bba304dbSDavid Howells 
292bba304dbSDavid Howells /*
293bba304dbSDavid Howells  * Events that can be raised upon a connection.
294bba304dbSDavid Howells  */
295bba304dbSDavid Howells enum rxrpc_conn_event {
296bba304dbSDavid Howells 	RXRPC_CONN_EV_CHALLENGE,	/* Send challenge packet */
297bba304dbSDavid Howells };
298bba304dbSDavid Howells 
299bba304dbSDavid Howells /*
30045025bceSDavid Howells  * The connection cache state.
30145025bceSDavid Howells  */
30245025bceSDavid Howells enum rxrpc_conn_cache_state {
30345025bceSDavid Howells 	RXRPC_CONN_CLIENT_INACTIVE,	/* Conn is not yet listed */
30445025bceSDavid Howells 	RXRPC_CONN_CLIENT_WAITING,	/* Conn is on wait list, waiting for capacity */
30545025bceSDavid Howells 	RXRPC_CONN_CLIENT_ACTIVE,	/* Conn is on active list, doing calls */
30645025bceSDavid Howells 	RXRPC_CONN_CLIENT_CULLED,	/* Conn is culled and delisted, doing calls */
30745025bceSDavid Howells 	RXRPC_CONN_CLIENT_IDLE,		/* Conn is on idle list, doing mostly nothing */
30845025bceSDavid Howells };
30945025bceSDavid Howells 
31045025bceSDavid Howells /*
311bba304dbSDavid Howells  * The connection protocol state.
312bba304dbSDavid Howells  */
313bba304dbSDavid Howells enum rxrpc_conn_proto_state {
314bba304dbSDavid Howells 	RXRPC_CONN_UNUSED,		/* Connection not yet attempted */
315bba304dbSDavid Howells 	RXRPC_CONN_CLIENT,		/* Client connection */
31600e90712SDavid Howells 	RXRPC_CONN_SERVICE_PREALLOC,	/* Service connection preallocation */
317bba304dbSDavid Howells 	RXRPC_CONN_SERVICE_UNSECURED,	/* Service unsecured connection */
318bba304dbSDavid Howells 	RXRPC_CONN_SERVICE_CHALLENGING,	/* Service challenging for security */
319bba304dbSDavid Howells 	RXRPC_CONN_SERVICE,		/* Service secured connection */
320bba304dbSDavid Howells 	RXRPC_CONN_REMOTELY_ABORTED,	/* Conn aborted by peer */
321bba304dbSDavid Howells 	RXRPC_CONN_LOCALLY_ABORTED,	/* Conn aborted locally */
322bba304dbSDavid Howells 	RXRPC_CONN__NR_STATES
323bba304dbSDavid Howells };
324bba304dbSDavid Howells 
325bba304dbSDavid Howells /*
32617926a79SDavid Howells  * RxRPC connection definition
327aa390bbeSDavid Howells  * - matched by { local, peer, epoch, conn_id, direction }
32817926a79SDavid Howells  * - each connection can only handle four simultaneous calls
32917926a79SDavid Howells  */
33017926a79SDavid Howells struct rxrpc_connection {
33119ffa01cSDavid Howells 	struct rxrpc_conn_proto	proto;
33219ffa01cSDavid Howells 	struct rxrpc_conn_parameters params;
33319ffa01cSDavid Howells 
33445025bceSDavid Howells 	atomic_t		usage;
33545025bceSDavid Howells 	struct rcu_head		rcu;
33645025bceSDavid Howells 	struct list_head	cache_link;
337a1399f8bSDavid Howells 
33845025bceSDavid Howells 	spinlock_t		channel_lock;
33945025bceSDavid Howells 	unsigned char		active_chans;	/* Mask of active channels */
34045025bceSDavid Howells #define RXRPC_ACTIVE_CHANS_MASK	((1 << RXRPC_MAXCALLS) - 1)
34145025bceSDavid Howells 	struct list_head	waiting_calls;	/* Calls waiting for channels */
342a1399f8bSDavid Howells 	struct rxrpc_channel {
343a1399f8bSDavid Howells 		struct rxrpc_call __rcu	*call;		/* Active call */
344a1399f8bSDavid Howells 		u32			call_id;	/* ID of current call */
345a1399f8bSDavid Howells 		u32			call_counter;	/* Call ID counter */
346a1399f8bSDavid Howells 		u32			last_call;	/* ID of last call */
34718bfeba5SDavid Howells 		u8			last_type;	/* Type of last packet */
34818bfeba5SDavid Howells 		u16			last_service_id;
34918bfeba5SDavid Howells 		union {
35018bfeba5SDavid Howells 			u32		last_seq;
35118bfeba5SDavid Howells 			u32		last_abort;
35218bfeba5SDavid Howells 		};
353a1399f8bSDavid Howells 	} channels[RXRPC_MAXCALLS];
354999b69f8SDavid Howells 
35517926a79SDavid Howells 	struct work_struct	processor;	/* connection event processor */
356999b69f8SDavid Howells 	union {
357999b69f8SDavid Howells 		struct rb_node	client_node;	/* Node in local->client_conns */
358aa390bbeSDavid Howells 		struct rb_node	service_node;	/* Node in peer->service_conns */
359999b69f8SDavid Howells 	};
3604d028b2cSDavid Howells 	struct list_head	proc_link;	/* link in procfs list */
36117926a79SDavid Howells 	struct list_head	link;		/* link in master connection list */
36217926a79SDavid Howells 	struct sk_buff_head	rx_queue;	/* received conn-level packets */
363648af7fcSDavid Howells 	const struct rxrpc_security *security;	/* applied security module */
36417926a79SDavid Howells 	struct key		*server_key;	/* security for this service */
3651afe593bSHerbert Xu 	struct crypto_skcipher	*cipher;	/* encryption handle */
36617926a79SDavid Howells 	struct rxrpc_crypt	csum_iv;	/* packet checksum base */
3674a3388c8SDavid Howells 	unsigned long		flags;
36817926a79SDavid Howells 	unsigned long		events;
369f51b4480SDavid Howells 	unsigned long		idle_timestamp;	/* Time at which last became idle */
37017926a79SDavid Howells 	spinlock_t		state_lock;	/* state-change lock */
371cf13258fSDavid Howells 	enum rxrpc_conn_cache_state cache_state;
372cf13258fSDavid Howells 	enum rxrpc_conn_proto_state state;	/* current state of connection */
373dc44b3a0SDavid Howells 	u32			local_abort;	/* local abort code */
374dc44b3a0SDavid Howells 	u32			remote_abort;	/* remote abort code */
37517926a79SDavid Howells 	int			debug_id;	/* debug ID for printks */
37617926a79SDavid Howells 	atomic_t		serial;		/* packet serial number counter */
377563ea7d5SDavid Howells 	unsigned int		hi_serial;	/* highest serial number received */
37817926a79SDavid Howells 	u8			size_align;	/* data size alignment (for security) */
37917926a79SDavid Howells 	u8			header_size;	/* rxrpc + security header size */
38017926a79SDavid Howells 	u8			security_size;	/* security header size */
38117926a79SDavid Howells 	u32			security_nonce;	/* response re-use preventer */
38217926a79SDavid Howells 	u8			security_ix;	/* security type */
38317926a79SDavid Howells 	u8			out_clientflag;	/* RXRPC_CLIENT_INITIATED if we are client */
38417926a79SDavid Howells };
38517926a79SDavid Howells 
38617926a79SDavid Howells /*
3875b8848d1SDavid Howells  * Flags in call->flags.
3885b8848d1SDavid Howells  */
3895b8848d1SDavid Howells enum rxrpc_call_flag {
3905b8848d1SDavid Howells 	RXRPC_CALL_RELEASED,		/* call has been released - no more message to userspace */
3915b8848d1SDavid Howells 	RXRPC_CALL_TERMINAL_MSG,	/* call has given the socket its final message */
3925b8848d1SDavid Howells 	RXRPC_CALL_RCVD_LAST,		/* all packets received */
3935b8848d1SDavid Howells 	RXRPC_CALL_RUN_RTIMER,		/* Tx resend timer started */
3945b8848d1SDavid Howells 	RXRPC_CALL_TX_SOFT_ACK,		/* sent some soft ACKs */
3955b8848d1SDavid Howells 	RXRPC_CALL_INIT_ACCEPT,		/* acceptance was initiated */
3965b8848d1SDavid Howells 	RXRPC_CALL_HAS_USERID,		/* has a user ID attached */
3975b8848d1SDavid Howells 	RXRPC_CALL_EXPECT_OOS,		/* expect out of sequence packets */
398dabe5a79SDavid Howells 	RXRPC_CALL_IS_SERVICE,		/* Call is service call */
39945025bceSDavid Howells 	RXRPC_CALL_EXPOSED,		/* The call was exposed to the world */
400d001648eSDavid Howells 	RXRPC_CALL_RX_NO_MORE,		/* Don't indicate MSG_MORE from recvmsg() */
4015b8848d1SDavid Howells };
4025b8848d1SDavid Howells 
4035b8848d1SDavid Howells /*
4045b8848d1SDavid Howells  * Events that can be raised on a call.
4055b8848d1SDavid Howells  */
4065b8848d1SDavid Howells enum rxrpc_call_event {
4074c198ad1SDavid Howells 	RXRPC_CALL_EV_RCVD_ACKALL,	/* ACKALL or reply received */
4084c198ad1SDavid Howells 	RXRPC_CALL_EV_RCVD_BUSY,	/* busy packet received */
4094c198ad1SDavid Howells 	RXRPC_CALL_EV_RCVD_ABORT,	/* abort packet received */
4104c198ad1SDavid Howells 	RXRPC_CALL_EV_RCVD_ERROR,	/* network error received */
4114c198ad1SDavid Howells 	RXRPC_CALL_EV_ACK_FINAL,	/* need to generate final ACK (and release call) */
4124c198ad1SDavid Howells 	RXRPC_CALL_EV_ACK,		/* need to generate ACK */
4134c198ad1SDavid Howells 	RXRPC_CALL_EV_REJECT_BUSY,	/* need to generate busy message */
4144c198ad1SDavid Howells 	RXRPC_CALL_EV_ABORT,		/* need to generate abort */
4154c198ad1SDavid Howells 	RXRPC_CALL_EV_CONN_ABORT,	/* local connection abort generated */
4164c198ad1SDavid Howells 	RXRPC_CALL_EV_RESEND_TIMER,	/* Tx resend timer expired */
4174c198ad1SDavid Howells 	RXRPC_CALL_EV_RESEND,		/* Tx resend required */
4184c198ad1SDavid Howells 	RXRPC_CALL_EV_DRAIN_RX_OOS,	/* drain the Rx out of sequence queue */
4194c198ad1SDavid Howells 	RXRPC_CALL_EV_LIFE_TIMER,	/* call's lifetimer ran out */
4204c198ad1SDavid Howells 	RXRPC_CALL_EV_ACCEPTED,		/* incoming call accepted by userspace app */
4214c198ad1SDavid Howells 	RXRPC_CALL_EV_SECURED,		/* incoming call's connection is now secure */
4224c198ad1SDavid Howells 	RXRPC_CALL_EV_POST_ACCEPT,	/* need to post an "accept?" message to the app */
4235b8848d1SDavid Howells };
4245b8848d1SDavid Howells 
4255b8848d1SDavid Howells /*
4265b8848d1SDavid Howells  * The states that a call can be in.
4275b8848d1SDavid Howells  */
4285b8848d1SDavid Howells enum rxrpc_call_state {
429999b69f8SDavid Howells 	RXRPC_CALL_UNINITIALISED,
430999b69f8SDavid Howells 	RXRPC_CALL_CLIENT_AWAIT_CONN,	/* - client waiting for connection to become available */
4315b8848d1SDavid Howells 	RXRPC_CALL_CLIENT_SEND_REQUEST,	/* - client sending request phase */
4325b8848d1SDavid Howells 	RXRPC_CALL_CLIENT_AWAIT_REPLY,	/* - client awaiting reply */
4335b8848d1SDavid Howells 	RXRPC_CALL_CLIENT_RECV_REPLY,	/* - client receiving reply phase */
4345b8848d1SDavid Howells 	RXRPC_CALL_CLIENT_FINAL_ACK,	/* - client sending final ACK phase */
43500e90712SDavid Howells 	RXRPC_CALL_SERVER_PREALLOC,	/* - service preallocation */
4365b8848d1SDavid Howells 	RXRPC_CALL_SERVER_SECURING,	/* - server securing request connection */
4375b8848d1SDavid Howells 	RXRPC_CALL_SERVER_ACCEPTING,	/* - server accepting request */
4385b8848d1SDavid Howells 	RXRPC_CALL_SERVER_RECV_REQUEST,	/* - server receiving request */
4395b8848d1SDavid Howells 	RXRPC_CALL_SERVER_ACK_REQUEST,	/* - server pending ACK of request */
4405b8848d1SDavid Howells 	RXRPC_CALL_SERVER_SEND_REPLY,	/* - server sending reply */
4415b8848d1SDavid Howells 	RXRPC_CALL_SERVER_AWAIT_ACK,	/* - server awaiting final ACK */
442f5c17aaeSDavid Howells 	RXRPC_CALL_COMPLETE,		/* - call complete */
443f5c17aaeSDavid Howells 	NR__RXRPC_CALL_STATES
444f5c17aaeSDavid Howells };
445f5c17aaeSDavid Howells 
446f5c17aaeSDavid Howells /*
447f5c17aaeSDavid Howells  * Call completion condition (state == RXRPC_CALL_COMPLETE).
448f5c17aaeSDavid Howells  */
449f5c17aaeSDavid Howells enum rxrpc_call_completion {
450f5c17aaeSDavid Howells 	RXRPC_CALL_SUCCEEDED,		/* - Normal termination */
4515b8848d1SDavid Howells 	RXRPC_CALL_SERVER_BUSY,		/* - call rejected by busy server */
4525b8848d1SDavid Howells 	RXRPC_CALL_REMOTELY_ABORTED,	/* - call aborted by peer */
4535b8848d1SDavid Howells 	RXRPC_CALL_LOCALLY_ABORTED,	/* - call aborted locally on error or close */
454f5c17aaeSDavid Howells 	RXRPC_CALL_LOCAL_ERROR,		/* - call failed due to local error */
4555b8848d1SDavid Howells 	RXRPC_CALL_NETWORK_ERROR,	/* - call terminated by network error */
456f5c17aaeSDavid Howells 	NR__RXRPC_CALL_COMPLETIONS
4575b8848d1SDavid Howells };
4585b8848d1SDavid Howells 
4595b8848d1SDavid Howells /*
46017926a79SDavid Howells  * RxRPC call definition
46117926a79SDavid Howells  * - matched by { connection, call_id }
46217926a79SDavid Howells  */
46317926a79SDavid Howells struct rxrpc_call {
464dee46364SDavid Howells 	struct rcu_head		rcu;
46517926a79SDavid Howells 	struct rxrpc_connection	*conn;		/* connection carrying call */
466df5d8bf7SDavid Howells 	struct rxrpc_peer	*peer;		/* Peer record for remote address */
4678d94aa38SDavid Howells 	struct rxrpc_sock __rcu	*socket;	/* socket responsible */
46817926a79SDavid Howells 	struct timer_list	lifetimer;	/* lifetime remaining on call */
46917926a79SDavid Howells 	struct timer_list	ack_timer;	/* ACK generation timer */
47017926a79SDavid Howells 	struct timer_list	resend_timer;	/* Tx resend timer */
47117926a79SDavid Howells 	struct work_struct	processor;	/* packet processor and ACK generator */
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 */
47617926a79SDavid Howells 	struct list_head	accept_link;	/* calls awaiting acceptance */
47717926a79SDavid Howells 	struct rb_node		sock_node;	/* node in socket call tree */
47817926a79SDavid Howells 	struct sk_buff_head	rx_queue;	/* received packets */
47917926a79SDavid Howells 	struct sk_buff_head	rx_oos_queue;	/* packets received out of sequence */
480d001648eSDavid Howells 	struct sk_buff_head	knlrecv_queue;	/* Queue for kernel_recv [TODO: replace this] */
48117926a79SDavid Howells 	struct sk_buff		*tx_pending;	/* Tx socket buffer being filled */
48245025bceSDavid Howells 	wait_queue_head_t	waitq;		/* Wait queue for channel or Tx */
483a263629dSHerbert Xu 	__be32			crypto_buf[2];	/* Temporary packet crypto buffer */
48417926a79SDavid Howells 	unsigned long		user_call_ID;	/* user-defined call ID */
48517926a79SDavid Howells 	unsigned long		creation_jif;	/* time of call creation */
48617926a79SDavid Howells 	unsigned long		flags;
48717926a79SDavid Howells 	unsigned long		events;
48817926a79SDavid Howells 	spinlock_t		lock;
48917926a79SDavid Howells 	rwlock_t		state_lock;	/* lock for state transition */
490f5c17aaeSDavid Howells 	u32			abort_code;	/* Local/remote abort code */
491f5c17aaeSDavid Howells 	int			error;		/* Local error incurred */
492cf13258fSDavid Howells 	enum rxrpc_call_state	state;		/* current state of call */
493cf13258fSDavid Howells 	enum rxrpc_call_completion completion;	/* Call completion condition */
49417926a79SDavid Howells 	atomic_t		usage;
49517926a79SDavid Howells 	atomic_t		sequence;	/* Tx data packet sequence counter */
496dabe5a79SDavid Howells 	u16			service_id;	/* service ID */
497278ac0cdSDavid Howells 	u8			security_ix;	/* Security type */
498dabe5a79SDavid Howells 	u32			call_id;	/* call ID on connection  */
499dabe5a79SDavid Howells 	u32			cid;		/* connection ID plus channel index */
500dabe5a79SDavid Howells 	int			debug_id;	/* debug ID for printks */
50117926a79SDavid Howells 
50217926a79SDavid Howells 	/* transmission-phase ACK management */
5034e36a95eSDavid Howells 	u8			acks_head;	/* offset into window of first entry */
5044e36a95eSDavid Howells 	u8			acks_tail;	/* offset into window of last entry */
5054e36a95eSDavid Howells 	u8			acks_winsz;	/* size of un-ACK'd window */
5064e36a95eSDavid Howells 	u8			acks_unacked;	/* lowest unacked packet in last ACK received */
50717926a79SDavid Howells 	int			acks_latest;	/* serial number of latest ACK received */
50817926a79SDavid Howells 	rxrpc_seq_t		acks_hard;	/* highest definitively ACK'd msg seq */
50917926a79SDavid Howells 	unsigned long		*acks_window;	/* sent packet window
51017926a79SDavid Howells 						 * - elements are pointers with LSB set if ACK'd
51117926a79SDavid Howells 						 */
51217926a79SDavid Howells 
51317926a79SDavid Howells 	/* receive-phase ACK management */
51417926a79SDavid Howells 	rxrpc_seq_t		rx_data_expect;	/* next data seq ID expected to be received */
51517926a79SDavid Howells 	rxrpc_seq_t		rx_data_post;	/* next data seq ID expected to be posted */
51617926a79SDavid Howells 	rxrpc_seq_t		rx_data_recv;	/* last data seq ID encountered by recvmsg */
51717926a79SDavid Howells 	rxrpc_seq_t		rx_data_eaten;	/* last data seq ID consumed by recvmsg */
51817926a79SDavid Howells 	rxrpc_seq_t		rx_first_oos;	/* first packet in rx_oos_queue (or 0) */
51917926a79SDavid Howells 	rxrpc_seq_t		ackr_win_top;	/* top of ACK window (rx_data_eaten is bottom) */
5200d12f8a4SDavid Howells 	rxrpc_seq_t		ackr_prev_seq;	/* previous sequence number received */
5214e36a95eSDavid Howells 	u8			ackr_reason;	/* reason to ACK */
522563ea7d5SDavid Howells 	u16			ackr_skew;	/* skew on packet being ACK'd */
5230d12f8a4SDavid Howells 	rxrpc_serial_t		ackr_serial;	/* serial of packet being ACK'd */
52417926a79SDavid Howells 	atomic_t		ackr_not_idle;	/* number of packets in Rx queue */
52517926a79SDavid Howells 
52617926a79SDavid Howells 	/* received packet records, 1 bit per record */
52717926a79SDavid Howells #define RXRPC_ACKR_WINDOW_ASZ DIV_ROUND_UP(RXRPC_MAXACKS, BITS_PER_LONG)
52817926a79SDavid Howells 	unsigned long		ackr_window[RXRPC_ACKR_WINDOW_ASZ + 1];
52917926a79SDavid Howells };
53017926a79SDavid Howells 
531fff72429SDavid Howells enum rxrpc_call_trace {
532fff72429SDavid Howells 	rxrpc_call_new_client,
533fff72429SDavid Howells 	rxrpc_call_new_service,
534fff72429SDavid Howells 	rxrpc_call_queued,
535fff72429SDavid Howells 	rxrpc_call_queued_ref,
536fff72429SDavid Howells 	rxrpc_call_seen,
537fff72429SDavid Howells 	rxrpc_call_got,
538fff72429SDavid Howells 	rxrpc_call_got_skb,
539fff72429SDavid Howells 	rxrpc_call_got_userid,
540fff72429SDavid Howells 	rxrpc_call_put,
541fff72429SDavid Howells 	rxrpc_call_put_skb,
542fff72429SDavid Howells 	rxrpc_call_put_userid,
543fff72429SDavid Howells 	rxrpc_call_put_noqueue,
544fff72429SDavid Howells 	rxrpc_call__nr_trace
545fff72429SDavid Howells };
546fff72429SDavid Howells 
547fff72429SDavid Howells extern const char rxrpc_call_traces[rxrpc_call__nr_trace][4];
548fff72429SDavid Howells 
549df844fd4SDavid Howells #include <trace/events/rxrpc.h>
550df844fd4SDavid Howells 
55117926a79SDavid Howells /*
552651350d1SDavid Howells  * af_rxrpc.c
55317926a79SDavid Howells  */
554651350d1SDavid Howells extern atomic_t rxrpc_n_skbs;
5550d12f8a4SDavid Howells extern u32 rxrpc_epoch;
556651350d1SDavid Howells extern atomic_t rxrpc_debug_id;
557651350d1SDavid Howells extern struct workqueue_struct *rxrpc_workqueue;
55817926a79SDavid Howells 
55917926a79SDavid Howells /*
5600d81a51aSDavid Howells  * call_accept.c
56117926a79SDavid Howells  */
56200e90712SDavid Howells int rxrpc_service_prealloc(struct rxrpc_sock *, gfp_t);
56300e90712SDavid Howells void rxrpc_discard_prealloc(struct rxrpc_sock *);
5644f95dd78SDavid Howells void rxrpc_accept_incoming_calls(struct rxrpc_local *);
565d001648eSDavid Howells struct rxrpc_call *rxrpc_accept_call(struct rxrpc_sock *, unsigned long,
566d001648eSDavid Howells 				     rxrpc_notify_rx_t);
567c1b1203dSJoe Perches int rxrpc_reject_call(struct rxrpc_sock *);
56817926a79SDavid Howells 
56917926a79SDavid Howells /*
5700d81a51aSDavid Howells  * call_event.c
57117926a79SDavid Howells  */
572563ea7d5SDavid Howells void __rxrpc_propose_ACK(struct rxrpc_call *, u8, u16, u32, bool);
573563ea7d5SDavid Howells void rxrpc_propose_ACK(struct rxrpc_call *, u8, u16, u32, bool);
574c1b1203dSJoe Perches void rxrpc_process_call(struct work_struct *);
57517926a79SDavid Howells 
57617926a79SDavid Howells /*
5770d81a51aSDavid Howells  * call_object.c
57817926a79SDavid Howells  */
579f5c17aaeSDavid Howells extern const char *const rxrpc_call_states[];
580f5c17aaeSDavid Howells extern const char *const rxrpc_call_completions[];
581dad8aff7SDavid Howells extern unsigned int rxrpc_max_call_lifetime;
58217926a79SDavid Howells extern struct kmem_cache *rxrpc_call_jar;
58317926a79SDavid Howells extern struct list_head rxrpc_calls;
58417926a79SDavid Howells extern rwlock_t rxrpc_call_lock;
58517926a79SDavid Howells 
5862341e077SDavid Howells struct rxrpc_call *rxrpc_find_call_by_user_ID(struct rxrpc_sock *, unsigned long);
58700e90712SDavid Howells struct rxrpc_call *rxrpc_alloc_call(gfp_t);
5882341e077SDavid Howells struct rxrpc_call *rxrpc_new_client_call(struct rxrpc_sock *,
58919ffa01cSDavid Howells 					 struct rxrpc_conn_parameters *,
590999b69f8SDavid Howells 					 struct sockaddr_rxrpc *,
5912341e077SDavid Howells 					 unsigned long, gfp_t);
592c1b1203dSJoe Perches struct rxrpc_call *rxrpc_incoming_call(struct rxrpc_sock *,
59317926a79SDavid Howells 				       struct rxrpc_connection *,
59442886ffeSDavid Howells 				       struct sk_buff *);
5958d94aa38SDavid Howells void rxrpc_release_call(struct rxrpc_sock *, struct rxrpc_call *);
596c1b1203dSJoe Perches void rxrpc_release_calls_on_socket(struct rxrpc_sock *);
5978d94aa38SDavid Howells bool __rxrpc_queue_call(struct rxrpc_call *);
5988d94aa38SDavid Howells bool rxrpc_queue_call(struct rxrpc_call *);
599e34d4234SDavid Howells void rxrpc_see_call(struct rxrpc_call *);
600fff72429SDavid Howells void rxrpc_get_call(struct rxrpc_call *, enum rxrpc_call_trace);
601fff72429SDavid Howells void rxrpc_put_call(struct rxrpc_call *, enum rxrpc_call_trace);
602e34d4234SDavid Howells void rxrpc_get_call_for_skb(struct rxrpc_call *, struct sk_buff *);
603e34d4234SDavid Howells void rxrpc_put_call_for_skb(struct rxrpc_call *, struct sk_buff *);
60400e90712SDavid Howells void rxrpc_cleanup_call(struct rxrpc_call *);
605c1b1203dSJoe Perches void __exit rxrpc_destroy_all_calls(void);
60617926a79SDavid Howells 
607dabe5a79SDavid Howells static inline bool rxrpc_is_service_call(const struct rxrpc_call *call)
608dabe5a79SDavid Howells {
609dabe5a79SDavid Howells 	return test_bit(RXRPC_CALL_IS_SERVICE, &call->flags);
610dabe5a79SDavid Howells }
611dabe5a79SDavid Howells 
612dabe5a79SDavid Howells static inline bool rxrpc_is_client_call(const struct rxrpc_call *call)
613dabe5a79SDavid Howells {
614dabe5a79SDavid Howells 	return !rxrpc_is_service_call(call);
615dabe5a79SDavid Howells }
616dabe5a79SDavid Howells 
61717926a79SDavid Howells /*
618f5c17aaeSDavid Howells  * Transition a call to the complete state.
619f5c17aaeSDavid Howells  */
620f5c17aaeSDavid Howells static inline bool __rxrpc_set_call_completion(struct rxrpc_call *call,
621f5c17aaeSDavid Howells 					       enum rxrpc_call_completion compl,
622f5c17aaeSDavid Howells 					       u32 abort_code,
623f5c17aaeSDavid Howells 					       int error)
624f5c17aaeSDavid Howells {
625f5c17aaeSDavid Howells 	if (call->state < RXRPC_CALL_COMPLETE) {
626f5c17aaeSDavid Howells 		call->abort_code = abort_code;
627f5c17aaeSDavid Howells 		call->error = error;
628f5c17aaeSDavid Howells 		call->completion = compl,
629f5c17aaeSDavid Howells 		call->state = RXRPC_CALL_COMPLETE;
630f5c17aaeSDavid Howells 		return true;
631f5c17aaeSDavid Howells 	}
632f5c17aaeSDavid Howells 	return false;
633f5c17aaeSDavid Howells }
634f5c17aaeSDavid Howells 
635f5c17aaeSDavid Howells static inline bool rxrpc_set_call_completion(struct rxrpc_call *call,
636f5c17aaeSDavid Howells 					     enum rxrpc_call_completion compl,
637f5c17aaeSDavid Howells 					     u32 abort_code,
638f5c17aaeSDavid Howells 					     int error)
639f5c17aaeSDavid Howells {
640e8d6bbb0SDavid Howells 	bool ret;
641f5c17aaeSDavid Howells 
642f5c17aaeSDavid Howells 	write_lock_bh(&call->state_lock);
643f5c17aaeSDavid Howells 	ret = __rxrpc_set_call_completion(call, compl, abort_code, error);
644f5c17aaeSDavid Howells 	write_unlock_bh(&call->state_lock);
645f5c17aaeSDavid Howells 	return ret;
646f5c17aaeSDavid Howells }
647f5c17aaeSDavid Howells 
648f5c17aaeSDavid Howells /*
649f5c17aaeSDavid Howells  * Record that a call successfully completed.
650f5c17aaeSDavid Howells  */
651e8d6bbb0SDavid Howells static inline bool __rxrpc_call_completed(struct rxrpc_call *call)
652f5c17aaeSDavid Howells {
653e8d6bbb0SDavid Howells 	return __rxrpc_set_call_completion(call, RXRPC_CALL_SUCCEEDED, 0, 0);
654f5c17aaeSDavid Howells }
655f5c17aaeSDavid Howells 
656e8d6bbb0SDavid Howells static inline bool rxrpc_call_completed(struct rxrpc_call *call)
657f5c17aaeSDavid Howells {
658e8d6bbb0SDavid Howells 	bool ret;
659e8d6bbb0SDavid Howells 
660f5c17aaeSDavid Howells 	write_lock_bh(&call->state_lock);
661e8d6bbb0SDavid Howells 	ret = __rxrpc_call_completed(call);
662f5c17aaeSDavid Howells 	write_unlock_bh(&call->state_lock);
663e8d6bbb0SDavid Howells 	return ret;
664f5c17aaeSDavid Howells }
665f5c17aaeSDavid Howells 
666f5c17aaeSDavid Howells /*
667f5c17aaeSDavid Howells  * Record that a call is locally aborted.
668f5c17aaeSDavid Howells  */
6695a42976dSDavid Howells static inline bool __rxrpc_abort_call(const char *why, struct rxrpc_call *call,
6705a42976dSDavid Howells 				      rxrpc_seq_t seq,
671f5c17aaeSDavid Howells 				      u32 abort_code, int error)
672f5c17aaeSDavid Howells {
6735a42976dSDavid Howells 	trace_rxrpc_abort(why, call->cid, call->call_id, seq,
6745a42976dSDavid Howells 			  abort_code, error);
675f5c17aaeSDavid Howells 	if (__rxrpc_set_call_completion(call,
676f5c17aaeSDavid Howells 					RXRPC_CALL_LOCALLY_ABORTED,
677f5c17aaeSDavid Howells 					abort_code, error)) {
678f5c17aaeSDavid Howells 		set_bit(RXRPC_CALL_EV_ABORT, &call->events);
679f5c17aaeSDavid Howells 		return true;
680f5c17aaeSDavid Howells 	}
681f5c17aaeSDavid Howells 	return false;
682f5c17aaeSDavid Howells }
683f5c17aaeSDavid Howells 
6845a42976dSDavid Howells static inline bool rxrpc_abort_call(const char *why, struct rxrpc_call *call,
6855a42976dSDavid Howells 				    rxrpc_seq_t seq, u32 abort_code, int error)
686f5c17aaeSDavid Howells {
687f5c17aaeSDavid Howells 	bool ret;
688f5c17aaeSDavid Howells 
689f5c17aaeSDavid Howells 	write_lock_bh(&call->state_lock);
6905a42976dSDavid Howells 	ret = __rxrpc_abort_call(why, call, seq, abort_code, error);
691f5c17aaeSDavid Howells 	write_unlock_bh(&call->state_lock);
692f5c17aaeSDavid Howells 	return ret;
693f5c17aaeSDavid Howells }
694f5c17aaeSDavid Howells 
695f5c17aaeSDavid Howells /*
6964a3388c8SDavid Howells  * conn_client.c
6974a3388c8SDavid Howells  */
69845025bceSDavid Howells extern unsigned int rxrpc_max_client_connections;
69945025bceSDavid Howells extern unsigned int rxrpc_reap_client_connections;
70045025bceSDavid Howells extern unsigned int rxrpc_conn_idle_client_expiry;
70145025bceSDavid Howells extern unsigned int rxrpc_conn_idle_client_fast_expiry;
7024a3388c8SDavid Howells extern struct idr rxrpc_client_conn_ids;
7034a3388c8SDavid Howells 
704eb9b9d22SDavid Howells void rxrpc_destroy_client_conn_ids(void);
705c6d2b8d7SDavid Howells int rxrpc_connect_call(struct rxrpc_call *, struct rxrpc_conn_parameters *,
706c6d2b8d7SDavid Howells 		       struct sockaddr_rxrpc *, gfp_t);
70745025bceSDavid Howells void rxrpc_expose_client_call(struct rxrpc_call *);
70845025bceSDavid Howells void rxrpc_disconnect_client_call(struct rxrpc_call *);
70945025bceSDavid Howells void rxrpc_put_client_conn(struct rxrpc_connection *);
71045025bceSDavid Howells void __exit rxrpc_destroy_all_client_connections(void);
7114a3388c8SDavid Howells 
7124a3388c8SDavid Howells /*
7130d81a51aSDavid Howells  * conn_event.c
7140d81a51aSDavid Howells  */
7150d81a51aSDavid Howells void rxrpc_process_connection(struct work_struct *);
7160d81a51aSDavid Howells void rxrpc_reject_packet(struct rxrpc_local *, struct sk_buff *);
7174f95dd78SDavid Howells void rxrpc_reject_packets(struct rxrpc_local *);
7180d81a51aSDavid Howells 
7190d81a51aSDavid Howells /*
7200d81a51aSDavid Howells  * conn_object.c
72117926a79SDavid Howells  */
722dad8aff7SDavid Howells extern unsigned int rxrpc_connection_expiry;
72317926a79SDavid Howells extern struct list_head rxrpc_connections;
7244d028b2cSDavid Howells extern struct list_head rxrpc_connection_proc_list;
72517926a79SDavid Howells extern rwlock_t rxrpc_connection_lock;
72617926a79SDavid Howells 
7278496af50SDavid Howells int rxrpc_extract_addr_from_skb(struct sockaddr_rxrpc *, struct sk_buff *);
728c6d2b8d7SDavid Howells struct rxrpc_connection *rxrpc_alloc_connection(gfp_t);
7298496af50SDavid Howells struct rxrpc_connection *rxrpc_find_connection_rcu(struct rxrpc_local *,
730aa390bbeSDavid Howells 						   struct sk_buff *);
73145025bceSDavid Howells void __rxrpc_disconnect_call(struct rxrpc_connection *, struct rxrpc_call *);
732999b69f8SDavid Howells void rxrpc_disconnect_call(struct rxrpc_call *);
73345025bceSDavid Howells void rxrpc_kill_connection(struct rxrpc_connection *);
734f51b4480SDavid Howells void __rxrpc_put_connection(struct rxrpc_connection *);
735c1b1203dSJoe Perches void __exit rxrpc_destroy_all_connections(void);
73617926a79SDavid Howells 
73719ffa01cSDavid Howells static inline bool rxrpc_conn_is_client(const struct rxrpc_connection *conn)
73819ffa01cSDavid Howells {
73919ffa01cSDavid Howells 	return conn->out_clientflag;
74019ffa01cSDavid Howells }
74119ffa01cSDavid Howells 
74219ffa01cSDavid Howells static inline bool rxrpc_conn_is_service(const struct rxrpc_connection *conn)
74319ffa01cSDavid Howells {
744e8d70ce1SDavid Howells 	return !rxrpc_conn_is_client(conn);
74519ffa01cSDavid Howells }
74619ffa01cSDavid Howells 
7475627cc8bSDavid Howells static inline void rxrpc_get_connection(struct rxrpc_connection *conn)
7485627cc8bSDavid Howells {
7495627cc8bSDavid Howells 	atomic_inc(&conn->usage);
7505627cc8bSDavid Howells }
7515627cc8bSDavid Howells 
7522c4579e4SDavid Howells static inline
7532c4579e4SDavid Howells struct rxrpc_connection *rxrpc_get_connection_maybe(struct rxrpc_connection *conn)
7542c4579e4SDavid Howells {
7552c4579e4SDavid Howells 	return atomic_inc_not_zero(&conn->usage) ? conn : NULL;
7562c4579e4SDavid Howells }
7575acbee46SDavid Howells 
758f51b4480SDavid Howells static inline void rxrpc_put_connection(struct rxrpc_connection *conn)
759f51b4480SDavid Howells {
76045025bceSDavid Howells 	if (!conn)
76145025bceSDavid Howells 		return;
76245025bceSDavid Howells 
76345025bceSDavid Howells 	if (rxrpc_conn_is_client(conn)) {
76445025bceSDavid Howells 		if (atomic_dec_and_test(&conn->usage))
76545025bceSDavid Howells 			rxrpc_put_client_conn(conn);
76645025bceSDavid Howells 	} else {
76745025bceSDavid Howells 		if (atomic_dec_return(&conn->usage) == 1)
768f51b4480SDavid Howells 			__rxrpc_put_connection(conn);
769f51b4480SDavid Howells 	}
77045025bceSDavid Howells }
771f51b4480SDavid Howells 
7728496af50SDavid Howells static inline bool rxrpc_queue_conn(struct rxrpc_connection *conn)
7735acbee46SDavid Howells {
7748496af50SDavid Howells 	if (!rxrpc_get_connection_maybe(conn))
7758496af50SDavid Howells 		return false;
7768496af50SDavid Howells 	if (!rxrpc_queue_work(&conn->processor))
7772c4579e4SDavid Howells 		rxrpc_put_connection(conn);
7788496af50SDavid Howells 	return true;
7795acbee46SDavid Howells }
7805acbee46SDavid Howells 
78117926a79SDavid Howells /*
7827877a4a4SDavid Howells  * conn_service.c
7837877a4a4SDavid Howells  */
7848496af50SDavid Howells struct rxrpc_connection *rxrpc_find_service_conn_rcu(struct rxrpc_peer *,
7858496af50SDavid Howells 						     struct sk_buff *);
7867877a4a4SDavid Howells struct rxrpc_connection *rxrpc_incoming_connection(struct rxrpc_local *,
787d991b4a3SDavid Howells 						   struct sockaddr_rxrpc *,
7887877a4a4SDavid Howells 						   struct sk_buff *);
78900e90712SDavid Howells struct rxrpc_connection *rxrpc_prealloc_service_connection(gfp_t);
790001c1122SDavid Howells void rxrpc_unpublish_service_conn(struct rxrpc_connection *);
7917877a4a4SDavid Howells 
7927877a4a4SDavid Howells /*
7930d81a51aSDavid Howells  * input.c
79417926a79SDavid Howells  */
795676d2369SDavid S. Miller void rxrpc_data_ready(struct sock *);
796c1b1203dSJoe Perches int rxrpc_queue_rcv_skb(struct rxrpc_call *, struct sk_buff *, bool, bool);
797c1b1203dSJoe Perches void rxrpc_fast_process_packet(struct rxrpc_call *, struct sk_buff *);
79817926a79SDavid Howells 
79917926a79SDavid Howells /*
8000d81a51aSDavid Howells  * insecure.c
80117926a79SDavid Howells  */
8020d81a51aSDavid Howells extern const struct rxrpc_security rxrpc_no_security;
80317926a79SDavid Howells 
80417926a79SDavid Howells /*
8050d81a51aSDavid Howells  * key.c
80617926a79SDavid Howells  */
80717926a79SDavid Howells extern struct key_type key_type_rxrpc;
80817926a79SDavid Howells extern struct key_type key_type_rxrpc_s;
80917926a79SDavid Howells 
810c1b1203dSJoe Perches int rxrpc_request_key(struct rxrpc_sock *, char __user *, int);
811c1b1203dSJoe Perches int rxrpc_server_keyring(struct rxrpc_sock *, char __user *, int);
812c1b1203dSJoe Perches int rxrpc_get_server_data_key(struct rxrpc_connection *, const void *, time_t,
813c1b1203dSJoe Perches 			      u32);
81417926a79SDavid Howells 
81517926a79SDavid Howells /*
81687563616SDavid Howells  * local_event.c
81787563616SDavid Howells  */
8184f95dd78SDavid Howells extern void rxrpc_process_local_events(struct rxrpc_local *);
81987563616SDavid Howells 
82087563616SDavid Howells /*
8210d81a51aSDavid Howells  * local_object.c
82217926a79SDavid Howells  */
8234f95dd78SDavid Howells struct rxrpc_local *rxrpc_lookup_local(const struct sockaddr_rxrpc *);
8244f95dd78SDavid Howells void __rxrpc_put_local(struct rxrpc_local *);
8250d81a51aSDavid Howells void __exit rxrpc_destroy_all_locals(void);
826e0e4d82fSDavid Howells 
8274f95dd78SDavid Howells static inline void rxrpc_get_local(struct rxrpc_local *local)
8284f95dd78SDavid Howells {
8294f95dd78SDavid Howells 	atomic_inc(&local->usage);
8304f95dd78SDavid Howells }
8314f95dd78SDavid Howells 
8324f95dd78SDavid Howells static inline
8334f95dd78SDavid Howells struct rxrpc_local *rxrpc_get_local_maybe(struct rxrpc_local *local)
8344f95dd78SDavid Howells {
8354f95dd78SDavid Howells 	return atomic_inc_not_zero(&local->usage) ? local : NULL;
8364f95dd78SDavid Howells }
8374f95dd78SDavid Howells 
8384f95dd78SDavid Howells static inline void rxrpc_put_local(struct rxrpc_local *local)
8394f95dd78SDavid Howells {
8405627cc8bSDavid Howells 	if (local && atomic_dec_and_test(&local->usage))
8414f95dd78SDavid Howells 		__rxrpc_put_local(local);
8424f95dd78SDavid Howells }
8434f95dd78SDavid Howells 
8445acbee46SDavid Howells static inline void rxrpc_queue_local(struct rxrpc_local *local)
8455acbee46SDavid Howells {
8465acbee46SDavid Howells 	rxrpc_queue_work(&local->processor);
8475acbee46SDavid Howells }
8485acbee46SDavid Howells 
849e0e4d82fSDavid Howells /*
8508e688d9cSDavid Howells  * misc.c
8518e688d9cSDavid Howells  */
8520e119b41SDavid Howells extern unsigned int rxrpc_max_backlog __read_mostly;
8538e688d9cSDavid Howells extern unsigned int rxrpc_requested_ack_delay;
8548e688d9cSDavid Howells extern unsigned int rxrpc_soft_ack_delay;
8558e688d9cSDavid Howells extern unsigned int rxrpc_idle_ack_delay;
8568e688d9cSDavid Howells extern unsigned int rxrpc_rx_window_size;
8578e688d9cSDavid Howells extern unsigned int rxrpc_rx_mtu;
8588e688d9cSDavid Howells extern unsigned int rxrpc_rx_jumbo_max;
8590b58b8a1SDavid Howells extern unsigned int rxrpc_resend_timeout;
8608e688d9cSDavid Howells 
8615b3e87f1SDavid Howells extern const char *const rxrpc_pkts[];
8628e688d9cSDavid Howells extern const s8 rxrpc_ack_priority[];
8638e688d9cSDavid Howells 
8648e688d9cSDavid Howells extern const char *rxrpc_acks(u8 reason);
8658e688d9cSDavid Howells 
8668e688d9cSDavid Howells /*
8670d81a51aSDavid Howells  * output.c
8680d81a51aSDavid Howells  */
8698d94aa38SDavid Howells int rxrpc_send_call_packet(struct rxrpc_call *, u8);
870985a5c82SDavid Howells int rxrpc_send_data_packet(struct rxrpc_connection *, struct sk_buff *);
8710d81a51aSDavid Howells 
8720d81a51aSDavid Howells /*
873abe89ef0SDavid Howells  * peer_event.c
8740d81a51aSDavid Howells  */
875abe89ef0SDavid Howells void rxrpc_error_report(struct sock *);
876f66d7490SDavid Howells void rxrpc_peer_error_distributor(struct work_struct *);
8770d81a51aSDavid Howells 
8780d81a51aSDavid Howells /*
8790d81a51aSDavid Howells  * peer_object.c
8800d81a51aSDavid Howells  */
881be6e6707SDavid Howells struct rxrpc_peer *rxrpc_lookup_peer_rcu(struct rxrpc_local *,
882be6e6707SDavid Howells 					 const struct sockaddr_rxrpc *);
883be6e6707SDavid Howells struct rxrpc_peer *rxrpc_lookup_peer(struct rxrpc_local *,
884be6e6707SDavid Howells 				     struct sockaddr_rxrpc *, gfp_t);
885be6e6707SDavid Howells struct rxrpc_peer *rxrpc_alloc_peer(struct rxrpc_local *, gfp_t);
886be6e6707SDavid Howells 
887df5d8bf7SDavid Howells static inline struct rxrpc_peer *rxrpc_get_peer(struct rxrpc_peer *peer)
888be6e6707SDavid Howells {
889be6e6707SDavid Howells 	atomic_inc(&peer->usage);
890df5d8bf7SDavid Howells 	return peer;
891be6e6707SDavid Howells }
892be6e6707SDavid Howells 
893be6e6707SDavid Howells static inline
894be6e6707SDavid Howells struct rxrpc_peer *rxrpc_get_peer_maybe(struct rxrpc_peer *peer)
895be6e6707SDavid Howells {
896be6e6707SDavid Howells 	return atomic_inc_not_zero(&peer->usage) ? peer : NULL;
897be6e6707SDavid Howells }
898be6e6707SDavid Howells 
899be6e6707SDavid Howells extern void __rxrpc_put_peer(struct rxrpc_peer *peer);
900be6e6707SDavid Howells static inline void rxrpc_put_peer(struct rxrpc_peer *peer)
901be6e6707SDavid Howells {
9025627cc8bSDavid Howells 	if (peer && atomic_dec_and_test(&peer->usage))
903be6e6707SDavid Howells 		__rxrpc_put_peer(peer);
904be6e6707SDavid Howells }
9050d81a51aSDavid Howells 
9060d81a51aSDavid Howells /*
9070d81a51aSDavid Howells  * proc.c
9080d81a51aSDavid Howells  */
9090d81a51aSDavid Howells extern const struct file_operations rxrpc_call_seq_fops;
9100d81a51aSDavid Howells extern const struct file_operations rxrpc_connection_seq_fops;
9110d81a51aSDavid Howells 
9120d81a51aSDavid Howells /*
9130d81a51aSDavid Howells  * recvmsg.c
9140d81a51aSDavid Howells  */
9150d81a51aSDavid Howells int rxrpc_recvmsg(struct socket *, struct msghdr *, size_t, int);
9160d81a51aSDavid Howells 
9170d81a51aSDavid Howells /*
918648af7fcSDavid Howells  * rxkad.c
919648af7fcSDavid Howells  */
920648af7fcSDavid Howells #ifdef CONFIG_RXKAD
921648af7fcSDavid Howells extern const struct rxrpc_security rxkad;
922648af7fcSDavid Howells #endif
923648af7fcSDavid Howells 
924648af7fcSDavid Howells /*
9250d81a51aSDavid Howells  * security.c
9260d81a51aSDavid Howells  */
9270d81a51aSDavid Howells int __init rxrpc_init_security(void);
9280d81a51aSDavid Howells void rxrpc_exit_security(void);
9290d81a51aSDavid Howells int rxrpc_init_client_conn_security(struct rxrpc_connection *);
9300d81a51aSDavid Howells int rxrpc_init_server_conn_security(struct rxrpc_connection *);
9310d81a51aSDavid Howells 
9320d81a51aSDavid Howells /*
9330b58b8a1SDavid Howells  * sendmsg.c
9340b58b8a1SDavid Howells  */
9350b58b8a1SDavid Howells int rxrpc_do_sendmsg(struct rxrpc_sock *, struct msghdr *, size_t);
9360b58b8a1SDavid Howells 
9370b58b8a1SDavid Howells /*
9380d81a51aSDavid Howells  * skbuff.c
9390d81a51aSDavid Howells  */
940d001648eSDavid Howells void rxrpc_kernel_data_consumed(struct rxrpc_call *, struct sk_buff *);
9410d81a51aSDavid Howells void rxrpc_packet_destructor(struct sk_buff *);
942df844fd4SDavid Howells void rxrpc_new_skb(struct sk_buff *);
943df844fd4SDavid Howells void rxrpc_see_skb(struct sk_buff *);
944df844fd4SDavid Howells void rxrpc_get_skb(struct sk_buff *);
945df844fd4SDavid Howells void rxrpc_free_skb(struct sk_buff *);
946df844fd4SDavid Howells void rxrpc_purge_queue(struct sk_buff_head *);
9470d81a51aSDavid Howells 
9480d81a51aSDavid Howells /*
9495873c083SDavid Howells  * sysctl.c
9505873c083SDavid Howells  */
9515873c083SDavid Howells #ifdef CONFIG_SYSCTL
9525873c083SDavid Howells extern int __init rxrpc_sysctl_init(void);
9535873c083SDavid Howells extern void rxrpc_sysctl_exit(void);
9545873c083SDavid Howells #else
9555873c083SDavid Howells static inline int __init rxrpc_sysctl_init(void) { return 0; }
9565873c083SDavid Howells static inline void rxrpc_sysctl_exit(void) {}
9575873c083SDavid Howells #endif
9585873c083SDavid Howells 
9595873c083SDavid Howells /*
960be6e6707SDavid Howells  * utils.c
961be6e6707SDavid Howells  */
962d991b4a3SDavid Howells int rxrpc_extract_addr_from_skb(struct sockaddr_rxrpc *, struct sk_buff *);
963be6e6707SDavid Howells 
964be6e6707SDavid Howells /*
96517926a79SDavid Howells  * debug tracing
96617926a79SDavid Howells  */
96795c96174SEric Dumazet extern unsigned int rxrpc_debug;
96817926a79SDavid Howells 
96917926a79SDavid Howells #define dbgprintk(FMT,...) \
9709f389f4bSSven Schnelle 	printk("[%-6.6s] "FMT"\n", current->comm ,##__VA_ARGS__)
97117926a79SDavid Howells 
9720dc47877SHarvey Harrison #define kenter(FMT,...)	dbgprintk("==> %s("FMT")",__func__ ,##__VA_ARGS__)
9730dc47877SHarvey Harrison #define kleave(FMT,...)	dbgprintk("<== %s()"FMT"",__func__ ,##__VA_ARGS__)
97417926a79SDavid Howells #define kdebug(FMT,...)	dbgprintk("    "FMT ,##__VA_ARGS__)
97517926a79SDavid Howells #define kproto(FMT,...)	dbgprintk("### "FMT ,##__VA_ARGS__)
97617926a79SDavid Howells #define knet(FMT,...)	dbgprintk("@@@ "FMT ,##__VA_ARGS__)
97717926a79SDavid Howells 
97817926a79SDavid Howells 
97917926a79SDavid Howells #if defined(__KDEBUG)
98017926a79SDavid Howells #define _enter(FMT,...)	kenter(FMT,##__VA_ARGS__)
98117926a79SDavid Howells #define _leave(FMT,...)	kleave(FMT,##__VA_ARGS__)
98217926a79SDavid Howells #define _debug(FMT,...)	kdebug(FMT,##__VA_ARGS__)
98317926a79SDavid Howells #define _proto(FMT,...)	kproto(FMT,##__VA_ARGS__)
98417926a79SDavid Howells #define _net(FMT,...)	knet(FMT,##__VA_ARGS__)
98517926a79SDavid Howells 
98617926a79SDavid Howells #elif defined(CONFIG_AF_RXRPC_DEBUG)
98717926a79SDavid Howells #define RXRPC_DEBUG_KENTER	0x01
98817926a79SDavid Howells #define RXRPC_DEBUG_KLEAVE	0x02
98917926a79SDavid Howells #define RXRPC_DEBUG_KDEBUG	0x04
99017926a79SDavid Howells #define RXRPC_DEBUG_KPROTO	0x08
99117926a79SDavid Howells #define RXRPC_DEBUG_KNET	0x10
99217926a79SDavid Howells 
99317926a79SDavid Howells #define _enter(FMT,...)					\
99417926a79SDavid Howells do {							\
99517926a79SDavid Howells 	if (unlikely(rxrpc_debug & RXRPC_DEBUG_KENTER))	\
99617926a79SDavid Howells 		kenter(FMT,##__VA_ARGS__);		\
99717926a79SDavid Howells } while (0)
99817926a79SDavid Howells 
99917926a79SDavid Howells #define _leave(FMT,...)					\
100017926a79SDavid Howells do {							\
100117926a79SDavid Howells 	if (unlikely(rxrpc_debug & RXRPC_DEBUG_KLEAVE))	\
100217926a79SDavid Howells 		kleave(FMT,##__VA_ARGS__);		\
100317926a79SDavid Howells } while (0)
100417926a79SDavid Howells 
100517926a79SDavid Howells #define _debug(FMT,...)					\
100617926a79SDavid Howells do {							\
100717926a79SDavid Howells 	if (unlikely(rxrpc_debug & RXRPC_DEBUG_KDEBUG))	\
100817926a79SDavid Howells 		kdebug(FMT,##__VA_ARGS__);		\
100917926a79SDavid Howells } while (0)
101017926a79SDavid Howells 
101117926a79SDavid Howells #define _proto(FMT,...)					\
101217926a79SDavid Howells do {							\
101317926a79SDavid Howells 	if (unlikely(rxrpc_debug & RXRPC_DEBUG_KPROTO))	\
101417926a79SDavid Howells 		kproto(FMT,##__VA_ARGS__);		\
101517926a79SDavid Howells } while (0)
101617926a79SDavid Howells 
101717926a79SDavid Howells #define _net(FMT,...)					\
101817926a79SDavid Howells do {							\
101917926a79SDavid Howells 	if (unlikely(rxrpc_debug & RXRPC_DEBUG_KNET))	\
102017926a79SDavid Howells 		knet(FMT,##__VA_ARGS__);		\
102117926a79SDavid Howells } while (0)
102217926a79SDavid Howells 
102317926a79SDavid Howells #else
102412fdff3fSDavid Howells #define _enter(FMT,...)	no_printk("==> %s("FMT")",__func__ ,##__VA_ARGS__)
102512fdff3fSDavid Howells #define _leave(FMT,...)	no_printk("<== %s()"FMT"",__func__ ,##__VA_ARGS__)
102612fdff3fSDavid Howells #define _debug(FMT,...)	no_printk("    "FMT ,##__VA_ARGS__)
102712fdff3fSDavid Howells #define _proto(FMT,...)	no_printk("### "FMT ,##__VA_ARGS__)
102812fdff3fSDavid Howells #define _net(FMT,...)	no_printk("@@@ "FMT ,##__VA_ARGS__)
102917926a79SDavid Howells #endif
103017926a79SDavid Howells 
103117926a79SDavid Howells /*
103217926a79SDavid Howells  * debug assertion checking
103317926a79SDavid Howells  */
103417926a79SDavid Howells #if 1 // defined(__KDEBUGALL)
103517926a79SDavid Howells 
103617926a79SDavid Howells #define ASSERT(X)						\
103717926a79SDavid Howells do {								\
103817926a79SDavid Howells 	if (unlikely(!(X))) {					\
10399b6d5398SJoe Perches 		pr_err("Assertion failed\n");			\
104017926a79SDavid Howells 		BUG();						\
104117926a79SDavid Howells 	}							\
104217926a79SDavid Howells } while (0)
104317926a79SDavid Howells 
104417926a79SDavid Howells #define ASSERTCMP(X, OP, Y)						\
104517926a79SDavid Howells do {									\
1046cf13258fSDavid Howells 	__typeof__(X) _x = (X);						\
1047cf13258fSDavid Howells 	__typeof__(Y) _y = (__typeof__(X))(Y);				\
10489b6d5398SJoe Perches 	if (unlikely(!(_x OP _y))) {					\
10499b6d5398SJoe Perches 		pr_err("Assertion failed - %lu(0x%lx) %s %lu(0x%lx) is false\n", \
1050cf13258fSDavid Howells 		       (unsigned long)_x, (unsigned long)_x, #OP,	\
1051cf13258fSDavid Howells 		       (unsigned long)_y, (unsigned long)_y);		\
105217926a79SDavid Howells 		BUG();							\
105317926a79SDavid Howells 	}								\
105417926a79SDavid Howells } while (0)
105517926a79SDavid Howells 
105617926a79SDavid Howells #define ASSERTIF(C, X)						\
105717926a79SDavid Howells do {								\
105817926a79SDavid Howells 	if (unlikely((C) && !(X))) {				\
10599b6d5398SJoe Perches 		pr_err("Assertion failed\n");			\
106017926a79SDavid Howells 		BUG();						\
106117926a79SDavid Howells 	}							\
106217926a79SDavid Howells } while (0)
106317926a79SDavid Howells 
106417926a79SDavid Howells #define ASSERTIFCMP(C, X, OP, Y)					\
106517926a79SDavid Howells do {									\
1066cf13258fSDavid Howells 	__typeof__(X) _x = (X);						\
1067cf13258fSDavid Howells 	__typeof__(Y) _y = (__typeof__(X))(Y);				\
10689b6d5398SJoe Perches 	if (unlikely((C) && !(_x OP _y))) {				\
10699b6d5398SJoe Perches 		pr_err("Assertion failed - %lu(0x%lx) %s %lu(0x%lx) is false\n", \
1070cf13258fSDavid Howells 		       (unsigned long)_x, (unsigned long)_x, #OP,	\
1071cf13258fSDavid Howells 		       (unsigned long)_y, (unsigned long)_y);		\
107217926a79SDavid Howells 		BUG();							\
107317926a79SDavid Howells 	}								\
107417926a79SDavid Howells } while (0)
107517926a79SDavid Howells 
107617926a79SDavid Howells #else
107717926a79SDavid Howells 
107817926a79SDavid Howells #define ASSERT(X)				\
107917926a79SDavid Howells do {						\
108017926a79SDavid Howells } while (0)
108117926a79SDavid Howells 
108217926a79SDavid Howells #define ASSERTCMP(X, OP, Y)			\
108317926a79SDavid Howells do {						\
108417926a79SDavid Howells } while (0)
108517926a79SDavid Howells 
108617926a79SDavid Howells #define ASSERTIF(C, X)				\
108717926a79SDavid Howells do {						\
108817926a79SDavid Howells } while (0)
108917926a79SDavid Howells 
109017926a79SDavid Howells #define ASSERTIFCMP(C, X, OP, Y)		\
109117926a79SDavid Howells do {						\
109217926a79SDavid Howells } while (0)
109317926a79SDavid Howells 
109417926a79SDavid Howells #endif /* __KDEBUGALL */
1095