xref: /openbmc/linux/net/rxrpc/ar-internal.h (revision d001648e)
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 
38651350d1SDavid Howells #define rxrpc_queue_call(CALL)	rxrpc_queue_work(&(CALL)->processor)
3917926a79SDavid Howells 
40cc8feb8eSDavid Howells struct rxrpc_connection;
41cc8feb8eSDavid Howells 
4217926a79SDavid Howells /*
43d001648eSDavid Howells  * Mark applied to socket buffers.
44d001648eSDavid Howells  */
45d001648eSDavid Howells enum rxrpc_skb_mark {
46d001648eSDavid Howells 	RXRPC_SKB_MARK_DATA,		/* data message */
47d001648eSDavid Howells 	RXRPC_SKB_MARK_FINAL_ACK,	/* final ACK received message */
48d001648eSDavid Howells 	RXRPC_SKB_MARK_BUSY,		/* server busy message */
49d001648eSDavid Howells 	RXRPC_SKB_MARK_REMOTE_ABORT,	/* remote abort message */
50d001648eSDavid Howells 	RXRPC_SKB_MARK_LOCAL_ABORT,	/* local abort message */
51d001648eSDavid Howells 	RXRPC_SKB_MARK_NET_ERROR,	/* network error message */
52d001648eSDavid Howells 	RXRPC_SKB_MARK_LOCAL_ERROR,	/* local error message */
53d001648eSDavid Howells 	RXRPC_SKB_MARK_NEW_CALL,	/* local error message */
54d001648eSDavid Howells };
55d001648eSDavid Howells 
56d001648eSDavid Howells /*
5717926a79SDavid Howells  * sk_state for RxRPC sockets
5817926a79SDavid Howells  */
5917926a79SDavid Howells enum {
602341e077SDavid Howells 	RXRPC_UNBOUND = 0,
612341e077SDavid Howells 	RXRPC_CLIENT_UNBOUND,		/* Unbound socket used as client */
6217926a79SDavid Howells 	RXRPC_CLIENT_BOUND,		/* client local address bound */
6317926a79SDavid Howells 	RXRPC_SERVER_BOUND,		/* server local address bound */
6417926a79SDavid Howells 	RXRPC_SERVER_LISTENING,		/* server listening for connections */
6517926a79SDavid Howells 	RXRPC_CLOSE,			/* socket is being closed */
6617926a79SDavid Howells };
6717926a79SDavid Howells 
6817926a79SDavid Howells /*
6917926a79SDavid Howells  * RxRPC socket definition
7017926a79SDavid Howells  */
7117926a79SDavid Howells struct rxrpc_sock {
7217926a79SDavid Howells 	/* WARNING: sk has to be the first member */
7317926a79SDavid Howells 	struct sock		sk;
74d001648eSDavid Howells 	rxrpc_notify_new_call_t	notify_new_call; /* Func to notify of new call */
7517926a79SDavid Howells 	struct rxrpc_local	*local;		/* local endpoint */
7617926a79SDavid Howells 	struct list_head	listen_link;	/* link in the local endpoint's listen list */
7717926a79SDavid Howells 	struct list_head	secureq;	/* calls awaiting connection security clearance */
7817926a79SDavid Howells 	struct list_head	acceptq;	/* calls awaiting acceptance */
7917926a79SDavid Howells 	struct key		*key;		/* security for this socket */
8017926a79SDavid Howells 	struct key		*securities;	/* list of server security descriptors */
8117926a79SDavid Howells 	struct rb_root		calls;		/* outstanding calls on this socket */
8217926a79SDavid Howells 	unsigned long		flags;
832341e077SDavid Howells #define RXRPC_SOCK_CONNECTED		0	/* connect_srx is set */
8417926a79SDavid Howells 	rwlock_t		call_lock;	/* lock for calls */
8517926a79SDavid Howells 	u32			min_sec_level;	/* minimum security level */
8617926a79SDavid Howells #define RXRPC_SECURITY_MAX	RXRPC_SECURITY_ENCRYPT
87cc8feb8eSDavid Howells 	bool			exclusive;	/* Exclusive connection for a client socket */
88cc8feb8eSDavid Howells 	sa_family_t		family;		/* Protocol family created with */
8917926a79SDavid Howells 	struct sockaddr_rxrpc	srx;		/* local address */
902341e077SDavid Howells 	struct sockaddr_rxrpc	connect_srx;	/* Default client address from connect() */
9117926a79SDavid Howells };
9217926a79SDavid Howells 
9317926a79SDavid Howells #define rxrpc_sk(__sk) container_of((__sk), struct rxrpc_sock, sk)
9417926a79SDavid Howells 
9517926a79SDavid Howells /*
960d12f8a4SDavid Howells  * CPU-byteorder normalised Rx packet header.
970d12f8a4SDavid Howells  */
980d12f8a4SDavid Howells struct rxrpc_host_header {
990d12f8a4SDavid Howells 	u32		epoch;		/* client boot timestamp */
1000d12f8a4SDavid Howells 	u32		cid;		/* connection and channel ID */
1010d12f8a4SDavid Howells 	u32		callNumber;	/* call ID (0 for connection-level packets) */
1020d12f8a4SDavid Howells 	u32		seq;		/* sequence number of pkt in call stream */
1030d12f8a4SDavid Howells 	u32		serial;		/* serial number of pkt sent to network */
1040d12f8a4SDavid Howells 	u8		type;		/* packet type */
1050d12f8a4SDavid Howells 	u8		flags;		/* packet flags */
1060d12f8a4SDavid Howells 	u8		userStatus;	/* app-layer defined status */
1070d12f8a4SDavid Howells 	u8		securityIndex;	/* security protocol ID */
1080d12f8a4SDavid Howells 	union {
1090d12f8a4SDavid Howells 		u16	_rsvd;		/* reserved */
1100d12f8a4SDavid Howells 		u16	cksum;		/* kerberos security checksum */
1110d12f8a4SDavid Howells 	};
1120d12f8a4SDavid Howells 	u16		serviceId;	/* service ID */
1130d12f8a4SDavid Howells } __packed;
1140d12f8a4SDavid Howells 
1150d12f8a4SDavid Howells /*
11617926a79SDavid Howells  * RxRPC socket buffer private variables
11717926a79SDavid Howells  * - max 48 bytes (struct sk_buff::cb)
11817926a79SDavid Howells  */
11917926a79SDavid Howells struct rxrpc_skb_priv {
12017926a79SDavid Howells 	struct rxrpc_call	*call;		/* call with which associated */
12117926a79SDavid Howells 	unsigned long		resend_at;	/* time in jiffies at which to resend */
12217926a79SDavid Howells 	union {
12395c96174SEric Dumazet 		unsigned int	offset;		/* offset into buffer of next read */
12417926a79SDavid Howells 		int		remain;		/* amount of space remaining for next write */
12517926a79SDavid Howells 		u32		error;		/* network error code */
12617926a79SDavid Howells 		bool		need_resend;	/* T if needs resending */
12717926a79SDavid Howells 	};
12817926a79SDavid Howells 
1290d12f8a4SDavid Howells 	struct rxrpc_host_header hdr;		/* RxRPC packet header from this packet */
13017926a79SDavid Howells };
13117926a79SDavid Howells 
13217926a79SDavid Howells #define rxrpc_skb(__skb) ((struct rxrpc_skb_priv *) &(__skb)->cb)
13317926a79SDavid Howells 
13417926a79SDavid Howells enum rxrpc_command {
13517926a79SDavid Howells 	RXRPC_CMD_SEND_DATA,		/* send data message */
13617926a79SDavid Howells 	RXRPC_CMD_SEND_ABORT,		/* request abort generation */
13717926a79SDavid Howells 	RXRPC_CMD_ACCEPT,		/* [server] accept incoming call */
13817926a79SDavid Howells 	RXRPC_CMD_REJECT_BUSY,		/* [server] reject a call as busy */
13917926a79SDavid Howells };
14017926a79SDavid Howells 
14117926a79SDavid Howells /*
14217926a79SDavid Howells  * RxRPC security module interface
14317926a79SDavid Howells  */
14417926a79SDavid Howells struct rxrpc_security {
14517926a79SDavid Howells 	const char		*name;		/* name of this service */
14617926a79SDavid Howells 	u8			security_index;	/* security type provided */
14717926a79SDavid Howells 
148648af7fcSDavid Howells 	/* Initialise a security service */
149648af7fcSDavid Howells 	int (*init)(void);
150648af7fcSDavid Howells 
151648af7fcSDavid Howells 	/* Clean up a security service */
152648af7fcSDavid Howells 	void (*exit)(void);
153648af7fcSDavid Howells 
15417926a79SDavid Howells 	/* initialise a connection's security */
15517926a79SDavid Howells 	int (*init_connection_security)(struct rxrpc_connection *);
15617926a79SDavid Howells 
15717926a79SDavid Howells 	/* prime a connection's packet security */
158a263629dSHerbert Xu 	int (*prime_packet_security)(struct rxrpc_connection *);
15917926a79SDavid Howells 
16017926a79SDavid Howells 	/* impose security on a packet */
161a263629dSHerbert Xu 	int (*secure_packet)(struct rxrpc_call *,
16217926a79SDavid Howells 			     struct sk_buff *,
16317926a79SDavid Howells 			     size_t,
16417926a79SDavid Howells 			     void *);
16517926a79SDavid Howells 
16617926a79SDavid Howells 	/* verify the security on a received packet */
167a263629dSHerbert Xu 	int (*verify_packet)(struct rxrpc_call *, struct sk_buff *, u32 *);
16817926a79SDavid Howells 
16917926a79SDavid Howells 	/* issue a challenge */
17017926a79SDavid Howells 	int (*issue_challenge)(struct rxrpc_connection *);
17117926a79SDavid Howells 
17217926a79SDavid Howells 	/* respond to a challenge */
17317926a79SDavid Howells 	int (*respond_to_challenge)(struct rxrpc_connection *,
17417926a79SDavid Howells 				    struct sk_buff *,
17517926a79SDavid Howells 				    u32 *);
17617926a79SDavid Howells 
17717926a79SDavid Howells 	/* verify a response */
17817926a79SDavid Howells 	int (*verify_response)(struct rxrpc_connection *,
17917926a79SDavid Howells 			       struct sk_buff *,
18017926a79SDavid Howells 			       u32 *);
18117926a79SDavid Howells 
18217926a79SDavid Howells 	/* clear connection security */
18317926a79SDavid Howells 	void (*clear)(struct rxrpc_connection *);
18417926a79SDavid Howells };
18517926a79SDavid Howells 
18617926a79SDavid Howells /*
1874f95dd78SDavid Howells  * RxRPC local transport endpoint description
1884f95dd78SDavid Howells  * - owned by a single AF_RXRPC socket
1894f95dd78SDavid Howells  * - pointed to by transport socket struct sk_user_data
19017926a79SDavid Howells  */
19117926a79SDavid Howells struct rxrpc_local {
1924f95dd78SDavid Howells 	struct rcu_head		rcu;
1934f95dd78SDavid Howells 	atomic_t		usage;
1944f95dd78SDavid Howells 	struct list_head	link;
19517926a79SDavid Howells 	struct socket		*socket;	/* my UDP socket */
1964f95dd78SDavid Howells 	struct work_struct	processor;
19717926a79SDavid Howells 	struct list_head	services;	/* services listening on this endpoint */
19817926a79SDavid Howells 	struct rw_semaphore	defrag_sem;	/* control re-enablement of IP DF bit */
19917926a79SDavid Howells 	struct sk_buff_head	accept_queue;	/* incoming calls awaiting acceptance */
20017926a79SDavid Howells 	struct sk_buff_head	reject_queue;	/* packets awaiting rejection */
20144ba0698SDavid Howells 	struct sk_buff_head	event_queue;	/* endpoint event packets awaiting processing */
202999b69f8SDavid Howells 	struct rb_root		client_conns;	/* Client connections by socket params */
203999b69f8SDavid Howells 	spinlock_t		client_conns_lock; /* Lock for client_conns */
20417926a79SDavid Howells 	spinlock_t		lock;		/* access lock */
20517926a79SDavid Howells 	rwlock_t		services_lock;	/* lock for services list */
20617926a79SDavid Howells 	int			debug_id;	/* debug ID for printks */
2074f95dd78SDavid Howells 	bool			dead;
20817926a79SDavid Howells 	struct sockaddr_rxrpc	srx;		/* local address */
20917926a79SDavid Howells };
21017926a79SDavid Howells 
21117926a79SDavid Howells /*
21217926a79SDavid Howells  * RxRPC remote transport endpoint definition
213be6e6707SDavid Howells  * - matched by local endpoint, remote port, address and protocol type
21417926a79SDavid Howells  */
21517926a79SDavid Howells struct rxrpc_peer {
216be6e6707SDavid Howells 	struct rcu_head		rcu;		/* This must be first */
217be6e6707SDavid Howells 	atomic_t		usage;
218be6e6707SDavid Howells 	unsigned long		hash_key;
219be6e6707SDavid Howells 	struct hlist_node	hash_link;
220be6e6707SDavid Howells 	struct rxrpc_local	*local;
221f66d7490SDavid Howells 	struct hlist_head	error_targets;	/* targets for net error distribution */
222f66d7490SDavid Howells 	struct work_struct	error_distributor;
223aa390bbeSDavid Howells 	struct rb_root		service_conns;	/* Service connections */
2248496af50SDavid Howells 	seqlock_t		service_conn_lock;
22517926a79SDavid Howells 	spinlock_t		lock;		/* access lock */
22695c96174SEric Dumazet 	unsigned int		if_mtu;		/* interface MTU for this peer */
22795c96174SEric Dumazet 	unsigned int		mtu;		/* network MTU for this peer */
22895c96174SEric Dumazet 	unsigned int		maxdata;	/* data size (MTU - hdrsize) */
22917926a79SDavid Howells 	unsigned short		hdrsize;	/* header size (IP + UDP + RxRPC) */
23017926a79SDavid Howells 	int			debug_id;	/* debug ID for printks */
231f66d7490SDavid Howells 	int			error_report;	/* Net (+0) or local (+1000000) to distribute */
232f66d7490SDavid Howells #define RXRPC_LOCAL_ERROR_OFFSET 1000000
23317926a79SDavid Howells 	struct sockaddr_rxrpc	srx;		/* remote address */
23417926a79SDavid Howells 
23517926a79SDavid Howells 	/* calculated RTT cache */
23617926a79SDavid Howells #define RXRPC_RTT_CACHE_SIZE 32
23717926a79SDavid Howells 	suseconds_t		rtt;		/* current RTT estimate (in uS) */
23895c96174SEric Dumazet 	unsigned int		rtt_point;	/* next entry at which to insert */
23995c96174SEric Dumazet 	unsigned int		rtt_usage;	/* amount of cache actually used */
24017926a79SDavid Howells 	suseconds_t		rtt_cache[RXRPC_RTT_CACHE_SIZE]; /* calculated RTT cache */
24117926a79SDavid Howells };
24217926a79SDavid Howells 
24317926a79SDavid Howells /*
24419ffa01cSDavid Howells  * Keys for matching a connection.
24519ffa01cSDavid Howells  */
24619ffa01cSDavid Howells struct rxrpc_conn_proto {
247e8d70ce1SDavid Howells 	union {
248e8d70ce1SDavid Howells 		struct {
24919ffa01cSDavid Howells 			u32	epoch;		/* epoch of this connection */
25019ffa01cSDavid Howells 			u32	cid;		/* connection ID */
251e8d70ce1SDavid Howells 		};
252e8d70ce1SDavid Howells 		u64		index_key;
25319ffa01cSDavid Howells 	};
25419ffa01cSDavid Howells };
25519ffa01cSDavid Howells 
25619ffa01cSDavid Howells struct rxrpc_conn_parameters {
25719ffa01cSDavid Howells 	struct rxrpc_local	*local;		/* Representation of local endpoint */
25819ffa01cSDavid Howells 	struct rxrpc_peer	*peer;		/* Remote endpoint */
25919ffa01cSDavid Howells 	struct key		*key;		/* Security details */
26019ffa01cSDavid Howells 	bool			exclusive;	/* T if conn is exclusive */
26119ffa01cSDavid Howells 	u16			service_id;	/* Service ID for this connection */
26219ffa01cSDavid Howells 	u32			security_level;	/* Security level selected */
26319ffa01cSDavid Howells };
26419ffa01cSDavid Howells 
26519ffa01cSDavid Howells /*
266bba304dbSDavid Howells  * Bits in the connection flags.
267bba304dbSDavid Howells  */
268bba304dbSDavid Howells enum rxrpc_conn_flag {
269bba304dbSDavid Howells 	RXRPC_CONN_HAS_IDR,		/* Has a client conn ID assigned */
270001c1122SDavid Howells 	RXRPC_CONN_IN_SERVICE_CONNS,	/* Conn is in peer->service_conns */
271001c1122SDavid Howells 	RXRPC_CONN_IN_CLIENT_CONNS,	/* Conn is in local->client_conns */
27245025bceSDavid Howells 	RXRPC_CONN_EXPOSED,		/* Conn has extra ref for exposure */
27345025bceSDavid Howells 	RXRPC_CONN_DONT_REUSE,		/* Don't reuse this connection */
27445025bceSDavid Howells 	RXRPC_CONN_COUNTED,		/* Counted by rxrpc_nr_client_conns */
275bba304dbSDavid Howells };
276bba304dbSDavid Howells 
277bba304dbSDavid Howells /*
278bba304dbSDavid Howells  * Events that can be raised upon a connection.
279bba304dbSDavid Howells  */
280bba304dbSDavid Howells enum rxrpc_conn_event {
281bba304dbSDavid Howells 	RXRPC_CONN_EV_CHALLENGE,	/* Send challenge packet */
282bba304dbSDavid Howells };
283bba304dbSDavid Howells 
284bba304dbSDavid Howells /*
28545025bceSDavid Howells  * The connection cache state.
28645025bceSDavid Howells  */
28745025bceSDavid Howells enum rxrpc_conn_cache_state {
28845025bceSDavid Howells 	RXRPC_CONN_CLIENT_INACTIVE,	/* Conn is not yet listed */
28945025bceSDavid Howells 	RXRPC_CONN_CLIENT_WAITING,	/* Conn is on wait list, waiting for capacity */
29045025bceSDavid Howells 	RXRPC_CONN_CLIENT_ACTIVE,	/* Conn is on active list, doing calls */
29145025bceSDavid Howells 	RXRPC_CONN_CLIENT_CULLED,	/* Conn is culled and delisted, doing calls */
29245025bceSDavid Howells 	RXRPC_CONN_CLIENT_IDLE,		/* Conn is on idle list, doing mostly nothing */
29345025bceSDavid Howells };
29445025bceSDavid Howells 
29545025bceSDavid Howells /*
296bba304dbSDavid Howells  * The connection protocol state.
297bba304dbSDavid Howells  */
298bba304dbSDavid Howells enum rxrpc_conn_proto_state {
299bba304dbSDavid Howells 	RXRPC_CONN_UNUSED,		/* Connection not yet attempted */
300bba304dbSDavid Howells 	RXRPC_CONN_CLIENT,		/* Client connection */
301bba304dbSDavid Howells 	RXRPC_CONN_SERVICE_UNSECURED,	/* Service unsecured connection */
302bba304dbSDavid Howells 	RXRPC_CONN_SERVICE_CHALLENGING,	/* Service challenging for security */
303bba304dbSDavid Howells 	RXRPC_CONN_SERVICE,		/* Service secured connection */
304bba304dbSDavid Howells 	RXRPC_CONN_REMOTELY_ABORTED,	/* Conn aborted by peer */
305bba304dbSDavid Howells 	RXRPC_CONN_LOCALLY_ABORTED,	/* Conn aborted locally */
306bba304dbSDavid Howells 	RXRPC_CONN__NR_STATES
307bba304dbSDavid Howells };
308bba304dbSDavid Howells 
309bba304dbSDavid Howells /*
31017926a79SDavid Howells  * RxRPC connection definition
311aa390bbeSDavid Howells  * - matched by { local, peer, epoch, conn_id, direction }
31217926a79SDavid Howells  * - each connection can only handle four simultaneous calls
31317926a79SDavid Howells  */
31417926a79SDavid Howells struct rxrpc_connection {
31519ffa01cSDavid Howells 	struct rxrpc_conn_proto	proto;
31619ffa01cSDavid Howells 	struct rxrpc_conn_parameters params;
31719ffa01cSDavid Howells 
31845025bceSDavid Howells 	atomic_t		usage;
31945025bceSDavid Howells 	struct rcu_head		rcu;
32045025bceSDavid Howells 	struct list_head	cache_link;
321a1399f8bSDavid Howells 
32245025bceSDavid Howells 	spinlock_t		channel_lock;
32345025bceSDavid Howells 	unsigned char		active_chans;	/* Mask of active channels */
32445025bceSDavid Howells #define RXRPC_ACTIVE_CHANS_MASK	((1 << RXRPC_MAXCALLS) - 1)
32545025bceSDavid Howells 	struct list_head	waiting_calls;	/* Calls waiting for channels */
326a1399f8bSDavid Howells 	struct rxrpc_channel {
327a1399f8bSDavid Howells 		struct rxrpc_call __rcu	*call;		/* Active call */
328a1399f8bSDavid Howells 		u32			call_id;	/* ID of current call */
329a1399f8bSDavid Howells 		u32			call_counter;	/* Call ID counter */
330a1399f8bSDavid Howells 		u32			last_call;	/* ID of last call */
33118bfeba5SDavid Howells 		u8			last_type;	/* Type of last packet */
33218bfeba5SDavid Howells 		u16			last_service_id;
33318bfeba5SDavid Howells 		union {
33418bfeba5SDavid Howells 			u32		last_seq;
33518bfeba5SDavid Howells 			u32		last_abort;
33618bfeba5SDavid Howells 		};
337a1399f8bSDavid Howells 	} channels[RXRPC_MAXCALLS];
338999b69f8SDavid Howells 
33917926a79SDavid Howells 	struct work_struct	processor;	/* connection event processor */
340999b69f8SDavid Howells 	union {
341999b69f8SDavid Howells 		struct rb_node	client_node;	/* Node in local->client_conns */
342aa390bbeSDavid Howells 		struct rb_node	service_node;	/* Node in peer->service_conns */
343999b69f8SDavid Howells 	};
3444d028b2cSDavid Howells 	struct list_head	proc_link;	/* link in procfs list */
34517926a79SDavid Howells 	struct list_head	link;		/* link in master connection list */
34617926a79SDavid Howells 	struct sk_buff_head	rx_queue;	/* received conn-level packets */
347648af7fcSDavid Howells 	const struct rxrpc_security *security;	/* applied security module */
34817926a79SDavid Howells 	struct key		*server_key;	/* security for this service */
3491afe593bSHerbert Xu 	struct crypto_skcipher	*cipher;	/* encryption handle */
35017926a79SDavid Howells 	struct rxrpc_crypt	csum_iv;	/* packet checksum base */
3514a3388c8SDavid Howells 	unsigned long		flags;
35217926a79SDavid Howells 	unsigned long		events;
353f51b4480SDavid Howells 	unsigned long		idle_timestamp;	/* Time at which last became idle */
35417926a79SDavid Howells 	spinlock_t		state_lock;	/* state-change lock */
35545025bceSDavid Howells 	enum rxrpc_conn_cache_state cache_state : 8;
356bba304dbSDavid Howells 	enum rxrpc_conn_proto_state state : 8;	/* current state of connection */
357dc44b3a0SDavid Howells 	u32			local_abort;	/* local abort code */
358dc44b3a0SDavid Howells 	u32			remote_abort;	/* remote abort code */
35917926a79SDavid Howells 	int			debug_id;	/* debug ID for printks */
36017926a79SDavid Howells 	atomic_t		serial;		/* packet serial number counter */
361563ea7d5SDavid Howells 	unsigned int		hi_serial;	/* highest serial number received */
36217926a79SDavid Howells 	u8			size_align;	/* data size alignment (for security) */
36317926a79SDavid Howells 	u8			header_size;	/* rxrpc + security header size */
36417926a79SDavid Howells 	u8			security_size;	/* security header size */
36517926a79SDavid Howells 	u32			security_nonce;	/* response re-use preventer */
36617926a79SDavid Howells 	u8			security_ix;	/* security type */
36717926a79SDavid Howells 	u8			out_clientflag;	/* RXRPC_CLIENT_INITIATED if we are client */
36817926a79SDavid Howells };
36917926a79SDavid Howells 
37017926a79SDavid Howells /*
3715b8848d1SDavid Howells  * Flags in call->flags.
3725b8848d1SDavid Howells  */
3735b8848d1SDavid Howells enum rxrpc_call_flag {
3745b8848d1SDavid Howells 	RXRPC_CALL_RELEASED,		/* call has been released - no more message to userspace */
3755b8848d1SDavid Howells 	RXRPC_CALL_TERMINAL_MSG,	/* call has given the socket its final message */
3765b8848d1SDavid Howells 	RXRPC_CALL_RCVD_LAST,		/* all packets received */
3775b8848d1SDavid Howells 	RXRPC_CALL_RUN_RTIMER,		/* Tx resend timer started */
3785b8848d1SDavid Howells 	RXRPC_CALL_TX_SOFT_ACK,		/* sent some soft ACKs */
3795b8848d1SDavid Howells 	RXRPC_CALL_INIT_ACCEPT,		/* acceptance was initiated */
3805b8848d1SDavid Howells 	RXRPC_CALL_HAS_USERID,		/* has a user ID attached */
3815b8848d1SDavid Howells 	RXRPC_CALL_EXPECT_OOS,		/* expect out of sequence packets */
382dabe5a79SDavid Howells 	RXRPC_CALL_IS_SERVICE,		/* Call is service call */
38345025bceSDavid Howells 	RXRPC_CALL_EXPOSED,		/* The call was exposed to the world */
384d001648eSDavid Howells 	RXRPC_CALL_RX_NO_MORE,		/* Don't indicate MSG_MORE from recvmsg() */
3855b8848d1SDavid Howells };
3865b8848d1SDavid Howells 
3875b8848d1SDavid Howells /*
3885b8848d1SDavid Howells  * Events that can be raised on a call.
3895b8848d1SDavid Howells  */
3905b8848d1SDavid Howells enum rxrpc_call_event {
3914c198ad1SDavid Howells 	RXRPC_CALL_EV_RCVD_ACKALL,	/* ACKALL or reply received */
3924c198ad1SDavid Howells 	RXRPC_CALL_EV_RCVD_BUSY,	/* busy packet received */
3934c198ad1SDavid Howells 	RXRPC_CALL_EV_RCVD_ABORT,	/* abort packet received */
3944c198ad1SDavid Howells 	RXRPC_CALL_EV_RCVD_ERROR,	/* network error received */
3954c198ad1SDavid Howells 	RXRPC_CALL_EV_ACK_FINAL,	/* need to generate final ACK (and release call) */
3964c198ad1SDavid Howells 	RXRPC_CALL_EV_ACK,		/* need to generate ACK */
3974c198ad1SDavid Howells 	RXRPC_CALL_EV_REJECT_BUSY,	/* need to generate busy message */
3984c198ad1SDavid Howells 	RXRPC_CALL_EV_ABORT,		/* need to generate abort */
3994c198ad1SDavid Howells 	RXRPC_CALL_EV_CONN_ABORT,	/* local connection abort generated */
4004c198ad1SDavid Howells 	RXRPC_CALL_EV_RESEND_TIMER,	/* Tx resend timer expired */
4014c198ad1SDavid Howells 	RXRPC_CALL_EV_RESEND,		/* Tx resend required */
4024c198ad1SDavid Howells 	RXRPC_CALL_EV_DRAIN_RX_OOS,	/* drain the Rx out of sequence queue */
4034c198ad1SDavid Howells 	RXRPC_CALL_EV_LIFE_TIMER,	/* call's lifetimer ran out */
4044c198ad1SDavid Howells 	RXRPC_CALL_EV_ACCEPTED,		/* incoming call accepted by userspace app */
4054c198ad1SDavid Howells 	RXRPC_CALL_EV_SECURED,		/* incoming call's connection is now secure */
4064c198ad1SDavid Howells 	RXRPC_CALL_EV_POST_ACCEPT,	/* need to post an "accept?" message to the app */
4074c198ad1SDavid Howells 	RXRPC_CALL_EV_RELEASE,		/* need to release the call's resources */
4085b8848d1SDavid Howells };
4095b8848d1SDavid Howells 
4105b8848d1SDavid Howells /*
4115b8848d1SDavid Howells  * The states that a call can be in.
4125b8848d1SDavid Howells  */
4135b8848d1SDavid Howells enum rxrpc_call_state {
414999b69f8SDavid Howells 	RXRPC_CALL_UNINITIALISED,
415999b69f8SDavid Howells 	RXRPC_CALL_CLIENT_AWAIT_CONN,	/* - client waiting for connection to become available */
4165b8848d1SDavid Howells 	RXRPC_CALL_CLIENT_SEND_REQUEST,	/* - client sending request phase */
4175b8848d1SDavid Howells 	RXRPC_CALL_CLIENT_AWAIT_REPLY,	/* - client awaiting reply */
4185b8848d1SDavid Howells 	RXRPC_CALL_CLIENT_RECV_REPLY,	/* - client receiving reply phase */
4195b8848d1SDavid Howells 	RXRPC_CALL_CLIENT_FINAL_ACK,	/* - client sending final ACK phase */
4205b8848d1SDavid Howells 	RXRPC_CALL_SERVER_SECURING,	/* - server securing request connection */
4215b8848d1SDavid Howells 	RXRPC_CALL_SERVER_ACCEPTING,	/* - server accepting request */
4225b8848d1SDavid Howells 	RXRPC_CALL_SERVER_RECV_REQUEST,	/* - server receiving request */
4235b8848d1SDavid Howells 	RXRPC_CALL_SERVER_ACK_REQUEST,	/* - server pending ACK of request */
4245b8848d1SDavid Howells 	RXRPC_CALL_SERVER_SEND_REPLY,	/* - server sending reply */
4255b8848d1SDavid Howells 	RXRPC_CALL_SERVER_AWAIT_ACK,	/* - server awaiting final ACK */
426f5c17aaeSDavid Howells 	RXRPC_CALL_COMPLETE,		/* - call complete */
427f5c17aaeSDavid Howells 	RXRPC_CALL_DEAD,		/* - call is dead */
428f5c17aaeSDavid Howells 	NR__RXRPC_CALL_STATES
429f5c17aaeSDavid Howells };
430f5c17aaeSDavid Howells 
431f5c17aaeSDavid Howells /*
432f5c17aaeSDavid Howells  * Call completion condition (state == RXRPC_CALL_COMPLETE).
433f5c17aaeSDavid Howells  */
434f5c17aaeSDavid Howells enum rxrpc_call_completion {
435f5c17aaeSDavid Howells 	RXRPC_CALL_SUCCEEDED,		/* - Normal termination */
4365b8848d1SDavid Howells 	RXRPC_CALL_SERVER_BUSY,		/* - call rejected by busy server */
4375b8848d1SDavid Howells 	RXRPC_CALL_REMOTELY_ABORTED,	/* - call aborted by peer */
4385b8848d1SDavid Howells 	RXRPC_CALL_LOCALLY_ABORTED,	/* - call aborted locally on error or close */
439f5c17aaeSDavid Howells 	RXRPC_CALL_LOCAL_ERROR,		/* - call failed due to local error */
4405b8848d1SDavid Howells 	RXRPC_CALL_NETWORK_ERROR,	/* - call terminated by network error */
441f5c17aaeSDavid Howells 	NR__RXRPC_CALL_COMPLETIONS
4425b8848d1SDavid Howells };
4435b8848d1SDavid Howells 
4445b8848d1SDavid Howells /*
44517926a79SDavid Howells  * RxRPC call definition
44617926a79SDavid Howells  * - matched by { connection, call_id }
44717926a79SDavid Howells  */
44817926a79SDavid Howells struct rxrpc_call {
449dee46364SDavid Howells 	struct rcu_head		rcu;
45017926a79SDavid Howells 	struct rxrpc_connection	*conn;		/* connection carrying call */
451df5d8bf7SDavid Howells 	struct rxrpc_peer	*peer;		/* Peer record for remote address */
45217926a79SDavid Howells 	struct rxrpc_sock	*socket;	/* socket responsible */
45317926a79SDavid Howells 	struct timer_list	lifetimer;	/* lifetime remaining on call */
45417926a79SDavid Howells 	struct timer_list	deadspan;	/* reap timer for re-ACK'ing, etc  */
45517926a79SDavid Howells 	struct timer_list	ack_timer;	/* ACK generation timer */
45617926a79SDavid Howells 	struct timer_list	resend_timer;	/* Tx resend timer */
45717926a79SDavid Howells 	struct work_struct	destroyer;	/* call destroyer */
45817926a79SDavid Howells 	struct work_struct	processor;	/* packet processor and ACK generator */
459d001648eSDavid Howells 	rxrpc_notify_rx_t	notify_rx;	/* kernel service Rx notification function */
46017926a79SDavid Howells 	struct list_head	link;		/* link in master call list */
46145025bceSDavid Howells 	struct list_head	chan_wait_link;	/* Link in conn->waiting_calls */
462f66d7490SDavid Howells 	struct hlist_node	error_link;	/* link in error distribution list */
46317926a79SDavid Howells 	struct list_head	accept_link;	/* calls awaiting acceptance */
46417926a79SDavid Howells 	struct rb_node		sock_node;	/* node in socket call tree */
46517926a79SDavid Howells 	struct sk_buff_head	rx_queue;	/* received packets */
46617926a79SDavid Howells 	struct sk_buff_head	rx_oos_queue;	/* packets received out of sequence */
467d001648eSDavid Howells 	struct sk_buff_head	knlrecv_queue;	/* Queue for kernel_recv [TODO: replace this] */
46817926a79SDavid Howells 	struct sk_buff		*tx_pending;	/* Tx socket buffer being filled */
46945025bceSDavid Howells 	wait_queue_head_t	waitq;		/* Wait queue for channel or Tx */
470a263629dSHerbert Xu 	__be32			crypto_buf[2];	/* Temporary packet crypto buffer */
47117926a79SDavid Howells 	unsigned long		user_call_ID;	/* user-defined call ID */
47217926a79SDavid Howells 	unsigned long		creation_jif;	/* time of call creation */
47317926a79SDavid Howells 	unsigned long		flags;
47417926a79SDavid Howells 	unsigned long		events;
47517926a79SDavid Howells 	spinlock_t		lock;
47617926a79SDavid Howells 	rwlock_t		state_lock;	/* lock for state transition */
477f5c17aaeSDavid Howells 	u32			abort_code;	/* Local/remote abort code */
478f5c17aaeSDavid Howells 	int			error;		/* Local error incurred */
479f5c17aaeSDavid Howells 	enum rxrpc_call_state	state : 8;	/* current state of call */
480f5c17aaeSDavid Howells 	enum rxrpc_call_completion completion : 8; /* Call completion condition */
48117926a79SDavid Howells 	atomic_t		usage;
482372ee163SDavid Howells 	atomic_t		skb_count;	/* Outstanding packets on this call */
48317926a79SDavid Howells 	atomic_t		sequence;	/* Tx data packet sequence counter */
484dabe5a79SDavid Howells 	u16			service_id;	/* service ID */
485dabe5a79SDavid Howells 	u32			call_id;	/* call ID on connection  */
486dabe5a79SDavid Howells 	u32			cid;		/* connection ID plus channel index */
487dabe5a79SDavid Howells 	int			debug_id;	/* debug ID for printks */
48817926a79SDavid Howells 
48917926a79SDavid Howells 	/* transmission-phase ACK management */
4904e36a95eSDavid Howells 	u8			acks_head;	/* offset into window of first entry */
4914e36a95eSDavid Howells 	u8			acks_tail;	/* offset into window of last entry */
4924e36a95eSDavid Howells 	u8			acks_winsz;	/* size of un-ACK'd window */
4934e36a95eSDavid Howells 	u8			acks_unacked;	/* lowest unacked packet in last ACK received */
49417926a79SDavid Howells 	int			acks_latest;	/* serial number of latest ACK received */
49517926a79SDavid Howells 	rxrpc_seq_t		acks_hard;	/* highest definitively ACK'd msg seq */
49617926a79SDavid Howells 	unsigned long		*acks_window;	/* sent packet window
49717926a79SDavid Howells 						 * - elements are pointers with LSB set if ACK'd
49817926a79SDavid Howells 						 */
49917926a79SDavid Howells 
50017926a79SDavid Howells 	/* receive-phase ACK management */
50117926a79SDavid Howells 	rxrpc_seq_t		rx_data_expect;	/* next data seq ID expected to be received */
50217926a79SDavid Howells 	rxrpc_seq_t		rx_data_post;	/* next data seq ID expected to be posted */
50317926a79SDavid Howells 	rxrpc_seq_t		rx_data_recv;	/* last data seq ID encountered by recvmsg */
50417926a79SDavid Howells 	rxrpc_seq_t		rx_data_eaten;	/* last data seq ID consumed by recvmsg */
50517926a79SDavid Howells 	rxrpc_seq_t		rx_first_oos;	/* first packet in rx_oos_queue (or 0) */
50617926a79SDavid Howells 	rxrpc_seq_t		ackr_win_top;	/* top of ACK window (rx_data_eaten is bottom) */
5070d12f8a4SDavid Howells 	rxrpc_seq_t		ackr_prev_seq;	/* previous sequence number received */
5084e36a95eSDavid Howells 	u8			ackr_reason;	/* reason to ACK */
509563ea7d5SDavid Howells 	u16			ackr_skew;	/* skew on packet being ACK'd */
5100d12f8a4SDavid Howells 	rxrpc_serial_t		ackr_serial;	/* serial of packet being ACK'd */
51117926a79SDavid Howells 	atomic_t		ackr_not_idle;	/* number of packets in Rx queue */
51217926a79SDavid Howells 
51317926a79SDavid Howells 	/* received packet records, 1 bit per record */
51417926a79SDavid Howells #define RXRPC_ACKR_WINDOW_ASZ DIV_ROUND_UP(RXRPC_MAXACKS, BITS_PER_LONG)
51517926a79SDavid Howells 	unsigned long		ackr_window[RXRPC_ACKR_WINDOW_ASZ + 1];
51617926a79SDavid Howells };
51717926a79SDavid Howells 
518df844fd4SDavid Howells #include <trace/events/rxrpc.h>
519df844fd4SDavid Howells 
52017926a79SDavid Howells /*
521651350d1SDavid Howells  * af_rxrpc.c
52217926a79SDavid Howells  */
523651350d1SDavid Howells extern atomic_t rxrpc_n_skbs;
5240d12f8a4SDavid Howells extern u32 rxrpc_epoch;
525651350d1SDavid Howells extern atomic_t rxrpc_debug_id;
526651350d1SDavid Howells extern struct workqueue_struct *rxrpc_workqueue;
52717926a79SDavid Howells 
52817926a79SDavid Howells /*
5290d81a51aSDavid Howells  * call_accept.c
53017926a79SDavid Howells  */
5314f95dd78SDavid Howells void rxrpc_accept_incoming_calls(struct rxrpc_local *);
532d001648eSDavid Howells struct rxrpc_call *rxrpc_accept_call(struct rxrpc_sock *, unsigned long,
533d001648eSDavid Howells 				     rxrpc_notify_rx_t);
534c1b1203dSJoe Perches int rxrpc_reject_call(struct rxrpc_sock *);
53517926a79SDavid Howells 
53617926a79SDavid Howells /*
5370d81a51aSDavid Howells  * call_event.c
53817926a79SDavid Howells  */
539563ea7d5SDavid Howells void __rxrpc_propose_ACK(struct rxrpc_call *, u8, u16, u32, bool);
540563ea7d5SDavid Howells void rxrpc_propose_ACK(struct rxrpc_call *, u8, u16, u32, bool);
541c1b1203dSJoe Perches void rxrpc_process_call(struct work_struct *);
54217926a79SDavid Howells 
54317926a79SDavid Howells /*
5440d81a51aSDavid Howells  * call_object.c
54517926a79SDavid Howells  */
546f5c17aaeSDavid Howells extern const char *const rxrpc_call_states[];
547f5c17aaeSDavid Howells extern const char *const rxrpc_call_completions[];
548dad8aff7SDavid Howells extern unsigned int rxrpc_max_call_lifetime;
549dad8aff7SDavid Howells extern unsigned int rxrpc_dead_call_expiry;
55017926a79SDavid Howells extern struct kmem_cache *rxrpc_call_jar;
55117926a79SDavid Howells extern struct list_head rxrpc_calls;
55217926a79SDavid Howells extern rwlock_t rxrpc_call_lock;
55317926a79SDavid Howells 
5542341e077SDavid Howells struct rxrpc_call *rxrpc_find_call_by_user_ID(struct rxrpc_sock *, unsigned long);
5552341e077SDavid Howells struct rxrpc_call *rxrpc_new_client_call(struct rxrpc_sock *,
55619ffa01cSDavid Howells 					 struct rxrpc_conn_parameters *,
557999b69f8SDavid Howells 					 struct sockaddr_rxrpc *,
5582341e077SDavid Howells 					 unsigned long, gfp_t);
559c1b1203dSJoe Perches struct rxrpc_call *rxrpc_incoming_call(struct rxrpc_sock *,
56017926a79SDavid Howells 				       struct rxrpc_connection *,
56142886ffeSDavid Howells 				       struct sk_buff *);
562c1b1203dSJoe Perches void rxrpc_release_call(struct rxrpc_call *);
563c1b1203dSJoe Perches void rxrpc_release_calls_on_socket(struct rxrpc_sock *);
564e34d4234SDavid Howells void rxrpc_see_call(struct rxrpc_call *);
565e34d4234SDavid Howells void rxrpc_get_call(struct rxrpc_call *);
566e34d4234SDavid Howells void rxrpc_put_call(struct rxrpc_call *);
567e34d4234SDavid Howells void rxrpc_get_call_for_skb(struct rxrpc_call *, struct sk_buff *);
568e34d4234SDavid Howells void rxrpc_put_call_for_skb(struct rxrpc_call *, struct sk_buff *);
569c1b1203dSJoe Perches void __exit rxrpc_destroy_all_calls(void);
57017926a79SDavid Howells 
571dabe5a79SDavid Howells static inline bool rxrpc_is_service_call(const struct rxrpc_call *call)
572dabe5a79SDavid Howells {
573dabe5a79SDavid Howells 	return test_bit(RXRPC_CALL_IS_SERVICE, &call->flags);
574dabe5a79SDavid Howells }
575dabe5a79SDavid Howells 
576dabe5a79SDavid Howells static inline bool rxrpc_is_client_call(const struct rxrpc_call *call)
577dabe5a79SDavid Howells {
578dabe5a79SDavid Howells 	return !rxrpc_is_service_call(call);
579dabe5a79SDavid Howells }
580dabe5a79SDavid Howells 
58117926a79SDavid Howells /*
582f5c17aaeSDavid Howells  * Transition a call to the complete state.
583f5c17aaeSDavid Howells  */
584f5c17aaeSDavid Howells static inline bool __rxrpc_set_call_completion(struct rxrpc_call *call,
585f5c17aaeSDavid Howells 					       enum rxrpc_call_completion compl,
586f5c17aaeSDavid Howells 					       u32 abort_code,
587f5c17aaeSDavid Howells 					       int error)
588f5c17aaeSDavid Howells {
589f5c17aaeSDavid Howells 	if (call->state < RXRPC_CALL_COMPLETE) {
590f5c17aaeSDavid Howells 		call->abort_code = abort_code;
591f5c17aaeSDavid Howells 		call->error = error;
592f5c17aaeSDavid Howells 		call->completion = compl,
593f5c17aaeSDavid Howells 		call->state = RXRPC_CALL_COMPLETE;
594f5c17aaeSDavid Howells 		return true;
595f5c17aaeSDavid Howells 	}
596f5c17aaeSDavid Howells 	return false;
597f5c17aaeSDavid Howells }
598f5c17aaeSDavid Howells 
599f5c17aaeSDavid Howells static inline bool rxrpc_set_call_completion(struct rxrpc_call *call,
600f5c17aaeSDavid Howells 					     enum rxrpc_call_completion compl,
601f5c17aaeSDavid Howells 					     u32 abort_code,
602f5c17aaeSDavid Howells 					     int error)
603f5c17aaeSDavid Howells {
604f5c17aaeSDavid Howells 	int ret;
605f5c17aaeSDavid Howells 
606f5c17aaeSDavid Howells 	write_lock_bh(&call->state_lock);
607f5c17aaeSDavid Howells 	ret = __rxrpc_set_call_completion(call, compl, abort_code, error);
608f5c17aaeSDavid Howells 	write_unlock_bh(&call->state_lock);
609f5c17aaeSDavid Howells 	return ret;
610f5c17aaeSDavid Howells }
611f5c17aaeSDavid Howells 
612f5c17aaeSDavid Howells /*
613f5c17aaeSDavid Howells  * Record that a call successfully completed.
614f5c17aaeSDavid Howells  */
615f5c17aaeSDavid Howells static inline void __rxrpc_call_completed(struct rxrpc_call *call)
616f5c17aaeSDavid Howells {
617f5c17aaeSDavid Howells 	__rxrpc_set_call_completion(call, RXRPC_CALL_SUCCEEDED, 0, 0);
618f5c17aaeSDavid Howells }
619f5c17aaeSDavid Howells 
620f5c17aaeSDavid Howells static inline void rxrpc_call_completed(struct rxrpc_call *call)
621f5c17aaeSDavid Howells {
622f5c17aaeSDavid Howells 	write_lock_bh(&call->state_lock);
623f5c17aaeSDavid Howells 	__rxrpc_call_completed(call);
624f5c17aaeSDavid Howells 	write_unlock_bh(&call->state_lock);
625f5c17aaeSDavid Howells }
626f5c17aaeSDavid Howells 
627f5c17aaeSDavid Howells /*
628f5c17aaeSDavid Howells  * Record that a call is locally aborted.
629f5c17aaeSDavid Howells  */
630f5c17aaeSDavid Howells static inline bool __rxrpc_abort_call(struct rxrpc_call *call,
631f5c17aaeSDavid Howells 				      u32 abort_code, int error)
632f5c17aaeSDavid Howells {
633f5c17aaeSDavid Howells 	if (__rxrpc_set_call_completion(call,
634f5c17aaeSDavid Howells 					RXRPC_CALL_LOCALLY_ABORTED,
635f5c17aaeSDavid Howells 					abort_code, error)) {
636f5c17aaeSDavid Howells 		set_bit(RXRPC_CALL_EV_ABORT, &call->events);
637f5c17aaeSDavid Howells 		return true;
638f5c17aaeSDavid Howells 	}
639f5c17aaeSDavid Howells 	return false;
640f5c17aaeSDavid Howells }
641f5c17aaeSDavid Howells 
642f5c17aaeSDavid Howells static inline bool rxrpc_abort_call(struct rxrpc_call *call,
643f5c17aaeSDavid Howells 				    u32 abort_code, int error)
644f5c17aaeSDavid Howells {
645f5c17aaeSDavid Howells 	bool ret;
646f5c17aaeSDavid Howells 
647f5c17aaeSDavid Howells 	write_lock_bh(&call->state_lock);
648f5c17aaeSDavid Howells 	ret = __rxrpc_abort_call(call, abort_code, error);
649f5c17aaeSDavid Howells 	write_unlock_bh(&call->state_lock);
650f5c17aaeSDavid Howells 	return ret;
651f5c17aaeSDavid Howells }
652f5c17aaeSDavid Howells 
653f5c17aaeSDavid Howells /*
6544a3388c8SDavid Howells  * conn_client.c
6554a3388c8SDavid Howells  */
65645025bceSDavid Howells extern unsigned int rxrpc_max_client_connections;
65745025bceSDavid Howells extern unsigned int rxrpc_reap_client_connections;
65845025bceSDavid Howells extern unsigned int rxrpc_conn_idle_client_expiry;
65945025bceSDavid Howells extern unsigned int rxrpc_conn_idle_client_fast_expiry;
6604a3388c8SDavid Howells extern struct idr rxrpc_client_conn_ids;
6614a3388c8SDavid Howells 
662eb9b9d22SDavid Howells void rxrpc_destroy_client_conn_ids(void);
663c6d2b8d7SDavid Howells int rxrpc_connect_call(struct rxrpc_call *, struct rxrpc_conn_parameters *,
664c6d2b8d7SDavid Howells 		       struct sockaddr_rxrpc *, gfp_t);
66545025bceSDavid Howells void rxrpc_expose_client_call(struct rxrpc_call *);
66645025bceSDavid Howells void rxrpc_disconnect_client_call(struct rxrpc_call *);
66745025bceSDavid Howells void rxrpc_put_client_conn(struct rxrpc_connection *);
66845025bceSDavid Howells void __exit rxrpc_destroy_all_client_connections(void);
6694a3388c8SDavid Howells 
6704a3388c8SDavid Howells /*
6710d81a51aSDavid Howells  * conn_event.c
6720d81a51aSDavid Howells  */
6730d81a51aSDavid Howells void rxrpc_process_connection(struct work_struct *);
6740d81a51aSDavid Howells void rxrpc_reject_packet(struct rxrpc_local *, struct sk_buff *);
6754f95dd78SDavid Howells void rxrpc_reject_packets(struct rxrpc_local *);
6760d81a51aSDavid Howells 
6770d81a51aSDavid Howells /*
6780d81a51aSDavid Howells  * conn_object.c
67917926a79SDavid Howells  */
680dad8aff7SDavid Howells extern unsigned int rxrpc_connection_expiry;
68117926a79SDavid Howells extern struct list_head rxrpc_connections;
6824d028b2cSDavid Howells extern struct list_head rxrpc_connection_proc_list;
68317926a79SDavid Howells extern rwlock_t rxrpc_connection_lock;
68417926a79SDavid Howells 
6858496af50SDavid Howells int rxrpc_extract_addr_from_skb(struct sockaddr_rxrpc *, struct sk_buff *);
686c6d2b8d7SDavid Howells struct rxrpc_connection *rxrpc_alloc_connection(gfp_t);
6878496af50SDavid Howells struct rxrpc_connection *rxrpc_find_connection_rcu(struct rxrpc_local *,
688aa390bbeSDavid Howells 						   struct sk_buff *);
68945025bceSDavid Howells void __rxrpc_disconnect_call(struct rxrpc_connection *, struct rxrpc_call *);
690999b69f8SDavid Howells void rxrpc_disconnect_call(struct rxrpc_call *);
69145025bceSDavid Howells void rxrpc_kill_connection(struct rxrpc_connection *);
692f51b4480SDavid Howells void __rxrpc_put_connection(struct rxrpc_connection *);
693c1b1203dSJoe Perches void __exit rxrpc_destroy_all_connections(void);
69417926a79SDavid Howells 
69519ffa01cSDavid Howells static inline bool rxrpc_conn_is_client(const struct rxrpc_connection *conn)
69619ffa01cSDavid Howells {
69719ffa01cSDavid Howells 	return conn->out_clientflag;
69819ffa01cSDavid Howells }
69919ffa01cSDavid Howells 
70019ffa01cSDavid Howells static inline bool rxrpc_conn_is_service(const struct rxrpc_connection *conn)
70119ffa01cSDavid Howells {
702e8d70ce1SDavid Howells 	return !rxrpc_conn_is_client(conn);
70319ffa01cSDavid Howells }
70419ffa01cSDavid Howells 
7055627cc8bSDavid Howells static inline void rxrpc_get_connection(struct rxrpc_connection *conn)
7065627cc8bSDavid Howells {
7075627cc8bSDavid Howells 	atomic_inc(&conn->usage);
7085627cc8bSDavid Howells }
7095627cc8bSDavid Howells 
7102c4579e4SDavid Howells static inline
7112c4579e4SDavid Howells struct rxrpc_connection *rxrpc_get_connection_maybe(struct rxrpc_connection *conn)
7122c4579e4SDavid Howells {
7132c4579e4SDavid Howells 	return atomic_inc_not_zero(&conn->usage) ? conn : NULL;
7142c4579e4SDavid Howells }
7155acbee46SDavid Howells 
716f51b4480SDavid Howells static inline void rxrpc_put_connection(struct rxrpc_connection *conn)
717f51b4480SDavid Howells {
71845025bceSDavid Howells 	if (!conn)
71945025bceSDavid Howells 		return;
72045025bceSDavid Howells 
72145025bceSDavid Howells 	if (rxrpc_conn_is_client(conn)) {
72245025bceSDavid Howells 		if (atomic_dec_and_test(&conn->usage))
72345025bceSDavid Howells 			rxrpc_put_client_conn(conn);
72445025bceSDavid Howells 	} else {
72545025bceSDavid Howells 		if (atomic_dec_return(&conn->usage) == 1)
726f51b4480SDavid Howells 			__rxrpc_put_connection(conn);
727f51b4480SDavid Howells 	}
72845025bceSDavid Howells }
729f51b4480SDavid Howells 
730f51b4480SDavid Howells 
7318496af50SDavid Howells static inline bool rxrpc_queue_conn(struct rxrpc_connection *conn)
7325acbee46SDavid Howells {
7338496af50SDavid Howells 	if (!rxrpc_get_connection_maybe(conn))
7348496af50SDavid Howells 		return false;
7358496af50SDavid Howells 	if (!rxrpc_queue_work(&conn->processor))
7362c4579e4SDavid Howells 		rxrpc_put_connection(conn);
7378496af50SDavid Howells 	return true;
7385acbee46SDavid Howells }
7395acbee46SDavid Howells 
74017926a79SDavid Howells /*
7417877a4a4SDavid Howells  * conn_service.c
7427877a4a4SDavid Howells  */
7438496af50SDavid Howells struct rxrpc_connection *rxrpc_find_service_conn_rcu(struct rxrpc_peer *,
7448496af50SDavid Howells 						     struct sk_buff *);
7457877a4a4SDavid Howells struct rxrpc_connection *rxrpc_incoming_connection(struct rxrpc_local *,
746d991b4a3SDavid Howells 						   struct sockaddr_rxrpc *,
7477877a4a4SDavid Howells 						   struct sk_buff *);
748001c1122SDavid Howells void rxrpc_unpublish_service_conn(struct rxrpc_connection *);
7497877a4a4SDavid Howells 
7507877a4a4SDavid Howells /*
7510d81a51aSDavid Howells  * input.c
75217926a79SDavid Howells  */
753676d2369SDavid S. Miller void rxrpc_data_ready(struct sock *);
754c1b1203dSJoe Perches int rxrpc_queue_rcv_skb(struct rxrpc_call *, struct sk_buff *, bool, bool);
755c1b1203dSJoe Perches void rxrpc_fast_process_packet(struct rxrpc_call *, struct sk_buff *);
75617926a79SDavid Howells 
75717926a79SDavid Howells /*
7580d81a51aSDavid Howells  * insecure.c
75917926a79SDavid Howells  */
7600d81a51aSDavid Howells extern const struct rxrpc_security rxrpc_no_security;
76117926a79SDavid Howells 
76217926a79SDavid Howells /*
7630d81a51aSDavid Howells  * key.c
76417926a79SDavid Howells  */
76517926a79SDavid Howells extern struct key_type key_type_rxrpc;
76617926a79SDavid Howells extern struct key_type key_type_rxrpc_s;
76717926a79SDavid Howells 
768c1b1203dSJoe Perches int rxrpc_request_key(struct rxrpc_sock *, char __user *, int);
769c1b1203dSJoe Perches int rxrpc_server_keyring(struct rxrpc_sock *, char __user *, int);
770c1b1203dSJoe Perches int rxrpc_get_server_data_key(struct rxrpc_connection *, const void *, time_t,
771c1b1203dSJoe Perches 			      u32);
77217926a79SDavid Howells 
77317926a79SDavid Howells /*
77487563616SDavid Howells  * local_event.c
77587563616SDavid Howells  */
7764f95dd78SDavid Howells extern void rxrpc_process_local_events(struct rxrpc_local *);
77787563616SDavid Howells 
77887563616SDavid Howells /*
7790d81a51aSDavid Howells  * local_object.c
78017926a79SDavid Howells  */
7814f95dd78SDavid Howells struct rxrpc_local *rxrpc_lookup_local(const struct sockaddr_rxrpc *);
7824f95dd78SDavid Howells void __rxrpc_put_local(struct rxrpc_local *);
7830d81a51aSDavid Howells void __exit rxrpc_destroy_all_locals(void);
784e0e4d82fSDavid Howells 
7854f95dd78SDavid Howells static inline void rxrpc_get_local(struct rxrpc_local *local)
7864f95dd78SDavid Howells {
7874f95dd78SDavid Howells 	atomic_inc(&local->usage);
7884f95dd78SDavid Howells }
7894f95dd78SDavid Howells 
7904f95dd78SDavid Howells static inline
7914f95dd78SDavid Howells struct rxrpc_local *rxrpc_get_local_maybe(struct rxrpc_local *local)
7924f95dd78SDavid Howells {
7934f95dd78SDavid Howells 	return atomic_inc_not_zero(&local->usage) ? local : NULL;
7944f95dd78SDavid Howells }
7954f95dd78SDavid Howells 
7964f95dd78SDavid Howells static inline void rxrpc_put_local(struct rxrpc_local *local)
7974f95dd78SDavid Howells {
7985627cc8bSDavid Howells 	if (local && atomic_dec_and_test(&local->usage))
7994f95dd78SDavid Howells 		__rxrpc_put_local(local);
8004f95dd78SDavid Howells }
8014f95dd78SDavid Howells 
8025acbee46SDavid Howells static inline void rxrpc_queue_local(struct rxrpc_local *local)
8035acbee46SDavid Howells {
8045acbee46SDavid Howells 	rxrpc_queue_work(&local->processor);
8055acbee46SDavid Howells }
8065acbee46SDavid Howells 
807e0e4d82fSDavid Howells /*
8088e688d9cSDavid Howells  * misc.c
8098e688d9cSDavid Howells  */
8100e119b41SDavid Howells extern unsigned int rxrpc_max_backlog __read_mostly;
8118e688d9cSDavid Howells extern unsigned int rxrpc_requested_ack_delay;
8128e688d9cSDavid Howells extern unsigned int rxrpc_soft_ack_delay;
8138e688d9cSDavid Howells extern unsigned int rxrpc_idle_ack_delay;
8148e688d9cSDavid Howells extern unsigned int rxrpc_rx_window_size;
8158e688d9cSDavid Howells extern unsigned int rxrpc_rx_mtu;
8168e688d9cSDavid Howells extern unsigned int rxrpc_rx_jumbo_max;
8178e688d9cSDavid Howells 
8185b3e87f1SDavid Howells extern const char *const rxrpc_pkts[];
8198e688d9cSDavid Howells extern const s8 rxrpc_ack_priority[];
8208e688d9cSDavid Howells 
8218e688d9cSDavid Howells extern const char *rxrpc_acks(u8 reason);
8228e688d9cSDavid Howells 
8238e688d9cSDavid Howells /*
8240d81a51aSDavid Howells  * output.c
8250d81a51aSDavid Howells  */
8260d81a51aSDavid Howells extern unsigned int rxrpc_resend_timeout;
8270d81a51aSDavid Howells 
828985a5c82SDavid Howells int rxrpc_send_data_packet(struct rxrpc_connection *, struct sk_buff *);
8290d81a51aSDavid Howells int rxrpc_do_sendmsg(struct rxrpc_sock *, struct msghdr *, size_t);
8300d81a51aSDavid Howells 
8310d81a51aSDavid Howells /*
832abe89ef0SDavid Howells  * peer_event.c
8330d81a51aSDavid Howells  */
834abe89ef0SDavid Howells void rxrpc_error_report(struct sock *);
835f66d7490SDavid Howells void rxrpc_peer_error_distributor(struct work_struct *);
8360d81a51aSDavid Howells 
8370d81a51aSDavid Howells /*
8380d81a51aSDavid Howells  * peer_object.c
8390d81a51aSDavid Howells  */
840be6e6707SDavid Howells struct rxrpc_peer *rxrpc_lookup_peer_rcu(struct rxrpc_local *,
841be6e6707SDavid Howells 					 const struct sockaddr_rxrpc *);
842be6e6707SDavid Howells struct rxrpc_peer *rxrpc_lookup_peer(struct rxrpc_local *,
843be6e6707SDavid Howells 				     struct sockaddr_rxrpc *, gfp_t);
844be6e6707SDavid Howells struct rxrpc_peer *rxrpc_alloc_peer(struct rxrpc_local *, gfp_t);
845be6e6707SDavid Howells 
846df5d8bf7SDavid Howells static inline struct rxrpc_peer *rxrpc_get_peer(struct rxrpc_peer *peer)
847be6e6707SDavid Howells {
848be6e6707SDavid Howells 	atomic_inc(&peer->usage);
849df5d8bf7SDavid Howells 	return peer;
850be6e6707SDavid Howells }
851be6e6707SDavid Howells 
852be6e6707SDavid Howells static inline
853be6e6707SDavid Howells struct rxrpc_peer *rxrpc_get_peer_maybe(struct rxrpc_peer *peer)
854be6e6707SDavid Howells {
855be6e6707SDavid Howells 	return atomic_inc_not_zero(&peer->usage) ? peer : NULL;
856be6e6707SDavid Howells }
857be6e6707SDavid Howells 
858be6e6707SDavid Howells extern void __rxrpc_put_peer(struct rxrpc_peer *peer);
859be6e6707SDavid Howells static inline void rxrpc_put_peer(struct rxrpc_peer *peer)
860be6e6707SDavid Howells {
8615627cc8bSDavid Howells 	if (peer && atomic_dec_and_test(&peer->usage))
862be6e6707SDavid Howells 		__rxrpc_put_peer(peer);
863be6e6707SDavid Howells }
8640d81a51aSDavid Howells 
8650d81a51aSDavid Howells /*
8660d81a51aSDavid Howells  * proc.c
8670d81a51aSDavid Howells  */
8680d81a51aSDavid Howells extern const struct file_operations rxrpc_call_seq_fops;
8690d81a51aSDavid Howells extern const struct file_operations rxrpc_connection_seq_fops;
8700d81a51aSDavid Howells 
8710d81a51aSDavid Howells /*
8720d81a51aSDavid Howells  * recvmsg.c
8730d81a51aSDavid Howells  */
8740d81a51aSDavid Howells void rxrpc_remove_user_ID(struct rxrpc_sock *, struct rxrpc_call *);
8750d81a51aSDavid Howells int rxrpc_recvmsg(struct socket *, struct msghdr *, size_t, int);
8760d81a51aSDavid Howells 
8770d81a51aSDavid Howells /*
878648af7fcSDavid Howells  * rxkad.c
879648af7fcSDavid Howells  */
880648af7fcSDavid Howells #ifdef CONFIG_RXKAD
881648af7fcSDavid Howells extern const struct rxrpc_security rxkad;
882648af7fcSDavid Howells #endif
883648af7fcSDavid Howells 
884648af7fcSDavid Howells /*
8850d81a51aSDavid Howells  * security.c
8860d81a51aSDavid Howells  */
8870d81a51aSDavid Howells int __init rxrpc_init_security(void);
8880d81a51aSDavid Howells void rxrpc_exit_security(void);
8890d81a51aSDavid Howells int rxrpc_init_client_conn_security(struct rxrpc_connection *);
8900d81a51aSDavid Howells int rxrpc_init_server_conn_security(struct rxrpc_connection *);
8910d81a51aSDavid Howells 
8920d81a51aSDavid Howells /*
8930d81a51aSDavid Howells  * skbuff.c
8940d81a51aSDavid Howells  */
895d001648eSDavid Howells void rxrpc_kernel_data_consumed(struct rxrpc_call *, struct sk_buff *);
8960d81a51aSDavid Howells void rxrpc_packet_destructor(struct sk_buff *);
897df844fd4SDavid Howells void rxrpc_new_skb(struct sk_buff *);
898df844fd4SDavid Howells void rxrpc_see_skb(struct sk_buff *);
899df844fd4SDavid Howells void rxrpc_get_skb(struct sk_buff *);
900df844fd4SDavid Howells void rxrpc_free_skb(struct sk_buff *);
901df844fd4SDavid Howells void rxrpc_purge_queue(struct sk_buff_head *);
9020d81a51aSDavid Howells 
9030d81a51aSDavid Howells /*
9045873c083SDavid Howells  * sysctl.c
9055873c083SDavid Howells  */
9065873c083SDavid Howells #ifdef CONFIG_SYSCTL
9075873c083SDavid Howells extern int __init rxrpc_sysctl_init(void);
9085873c083SDavid Howells extern void rxrpc_sysctl_exit(void);
9095873c083SDavid Howells #else
9105873c083SDavid Howells static inline int __init rxrpc_sysctl_init(void) { return 0; }
9115873c083SDavid Howells static inline void rxrpc_sysctl_exit(void) {}
9125873c083SDavid Howells #endif
9135873c083SDavid Howells 
9145873c083SDavid Howells /*
915be6e6707SDavid Howells  * utils.c
916be6e6707SDavid Howells  */
917d991b4a3SDavid Howells int rxrpc_extract_addr_from_skb(struct sockaddr_rxrpc *, struct sk_buff *);
918be6e6707SDavid Howells 
919be6e6707SDavid Howells /*
92017926a79SDavid Howells  * debug tracing
92117926a79SDavid Howells  */
92295c96174SEric Dumazet extern unsigned int rxrpc_debug;
92317926a79SDavid Howells 
92417926a79SDavid Howells #define dbgprintk(FMT,...) \
9259f389f4bSSven Schnelle 	printk("[%-6.6s] "FMT"\n", current->comm ,##__VA_ARGS__)
92617926a79SDavid Howells 
9270dc47877SHarvey Harrison #define kenter(FMT,...)	dbgprintk("==> %s("FMT")",__func__ ,##__VA_ARGS__)
9280dc47877SHarvey Harrison #define kleave(FMT,...)	dbgprintk("<== %s()"FMT"",__func__ ,##__VA_ARGS__)
92917926a79SDavid Howells #define kdebug(FMT,...)	dbgprintk("    "FMT ,##__VA_ARGS__)
93017926a79SDavid Howells #define kproto(FMT,...)	dbgprintk("### "FMT ,##__VA_ARGS__)
93117926a79SDavid Howells #define knet(FMT,...)	dbgprintk("@@@ "FMT ,##__VA_ARGS__)
93217926a79SDavid Howells 
93317926a79SDavid Howells 
93417926a79SDavid Howells #if defined(__KDEBUG)
93517926a79SDavid Howells #define _enter(FMT,...)	kenter(FMT,##__VA_ARGS__)
93617926a79SDavid Howells #define _leave(FMT,...)	kleave(FMT,##__VA_ARGS__)
93717926a79SDavid Howells #define _debug(FMT,...)	kdebug(FMT,##__VA_ARGS__)
93817926a79SDavid Howells #define _proto(FMT,...)	kproto(FMT,##__VA_ARGS__)
93917926a79SDavid Howells #define _net(FMT,...)	knet(FMT,##__VA_ARGS__)
94017926a79SDavid Howells 
94117926a79SDavid Howells #elif defined(CONFIG_AF_RXRPC_DEBUG)
94217926a79SDavid Howells #define RXRPC_DEBUG_KENTER	0x01
94317926a79SDavid Howells #define RXRPC_DEBUG_KLEAVE	0x02
94417926a79SDavid Howells #define RXRPC_DEBUG_KDEBUG	0x04
94517926a79SDavid Howells #define RXRPC_DEBUG_KPROTO	0x08
94617926a79SDavid Howells #define RXRPC_DEBUG_KNET	0x10
94717926a79SDavid Howells 
94817926a79SDavid Howells #define _enter(FMT,...)					\
94917926a79SDavid Howells do {							\
95017926a79SDavid Howells 	if (unlikely(rxrpc_debug & RXRPC_DEBUG_KENTER))	\
95117926a79SDavid Howells 		kenter(FMT,##__VA_ARGS__);		\
95217926a79SDavid Howells } while (0)
95317926a79SDavid Howells 
95417926a79SDavid Howells #define _leave(FMT,...)					\
95517926a79SDavid Howells do {							\
95617926a79SDavid Howells 	if (unlikely(rxrpc_debug & RXRPC_DEBUG_KLEAVE))	\
95717926a79SDavid Howells 		kleave(FMT,##__VA_ARGS__);		\
95817926a79SDavid Howells } while (0)
95917926a79SDavid Howells 
96017926a79SDavid Howells #define _debug(FMT,...)					\
96117926a79SDavid Howells do {							\
96217926a79SDavid Howells 	if (unlikely(rxrpc_debug & RXRPC_DEBUG_KDEBUG))	\
96317926a79SDavid Howells 		kdebug(FMT,##__VA_ARGS__);		\
96417926a79SDavid Howells } while (0)
96517926a79SDavid Howells 
96617926a79SDavid Howells #define _proto(FMT,...)					\
96717926a79SDavid Howells do {							\
96817926a79SDavid Howells 	if (unlikely(rxrpc_debug & RXRPC_DEBUG_KPROTO))	\
96917926a79SDavid Howells 		kproto(FMT,##__VA_ARGS__);		\
97017926a79SDavid Howells } while (0)
97117926a79SDavid Howells 
97217926a79SDavid Howells #define _net(FMT,...)					\
97317926a79SDavid Howells do {							\
97417926a79SDavid Howells 	if (unlikely(rxrpc_debug & RXRPC_DEBUG_KNET))	\
97517926a79SDavid Howells 		knet(FMT,##__VA_ARGS__);		\
97617926a79SDavid Howells } while (0)
97717926a79SDavid Howells 
97817926a79SDavid Howells #else
97912fdff3fSDavid Howells #define _enter(FMT,...)	no_printk("==> %s("FMT")",__func__ ,##__VA_ARGS__)
98012fdff3fSDavid Howells #define _leave(FMT,...)	no_printk("<== %s()"FMT"",__func__ ,##__VA_ARGS__)
98112fdff3fSDavid Howells #define _debug(FMT,...)	no_printk("    "FMT ,##__VA_ARGS__)
98212fdff3fSDavid Howells #define _proto(FMT,...)	no_printk("### "FMT ,##__VA_ARGS__)
98312fdff3fSDavid Howells #define _net(FMT,...)	no_printk("@@@ "FMT ,##__VA_ARGS__)
98417926a79SDavid Howells #endif
98517926a79SDavid Howells 
98617926a79SDavid Howells /*
98717926a79SDavid Howells  * debug assertion checking
98817926a79SDavid Howells  */
98917926a79SDavid Howells #if 1 // defined(__KDEBUGALL)
99017926a79SDavid Howells 
99117926a79SDavid Howells #define ASSERT(X)						\
99217926a79SDavid Howells do {								\
99317926a79SDavid Howells 	if (unlikely(!(X))) {					\
9949b6d5398SJoe Perches 		pr_err("Assertion failed\n");			\
99517926a79SDavid Howells 		BUG();						\
99617926a79SDavid Howells 	}							\
99717926a79SDavid Howells } while (0)
99817926a79SDavid Howells 
99917926a79SDavid Howells #define ASSERTCMP(X, OP, Y)						\
100017926a79SDavid Howells do {									\
10019b6d5398SJoe Perches 	unsigned long _x = (unsigned long)(X);				\
10029b6d5398SJoe Perches 	unsigned long _y = (unsigned long)(Y);				\
10039b6d5398SJoe Perches 	if (unlikely(!(_x OP _y))) {					\
10049b6d5398SJoe Perches 		pr_err("Assertion failed - %lu(0x%lx) %s %lu(0x%lx) is false\n",			\
10059b6d5398SJoe Perches 		       _x, _x, #OP, _y, _y);				\
100617926a79SDavid Howells 		BUG();							\
100717926a79SDavid Howells 	}								\
100817926a79SDavid Howells } while (0)
100917926a79SDavid Howells 
101017926a79SDavid Howells #define ASSERTIF(C, X)						\
101117926a79SDavid Howells do {								\
101217926a79SDavid Howells 	if (unlikely((C) && !(X))) {				\
10139b6d5398SJoe Perches 		pr_err("Assertion failed\n");			\
101417926a79SDavid Howells 		BUG();						\
101517926a79SDavid Howells 	}							\
101617926a79SDavid Howells } while (0)
101717926a79SDavid Howells 
101817926a79SDavid Howells #define ASSERTIFCMP(C, X, OP, Y)					\
101917926a79SDavid Howells do {									\
10209b6d5398SJoe Perches 	unsigned long _x = (unsigned long)(X);				\
10219b6d5398SJoe Perches 	unsigned long _y = (unsigned long)(Y);				\
10229b6d5398SJoe Perches 	if (unlikely((C) && !(_x OP _y))) {				\
10239b6d5398SJoe Perches 		pr_err("Assertion failed - %lu(0x%lx) %s %lu(0x%lx) is false\n", \
10249b6d5398SJoe Perches 		       _x, _x, #OP, _y, _y);				\
102517926a79SDavid Howells 		BUG();							\
102617926a79SDavid Howells 	}								\
102717926a79SDavid Howells } while (0)
102817926a79SDavid Howells 
102917926a79SDavid Howells #else
103017926a79SDavid Howells 
103117926a79SDavid Howells #define ASSERT(X)				\
103217926a79SDavid Howells do {						\
103317926a79SDavid Howells } while (0)
103417926a79SDavid Howells 
103517926a79SDavid Howells #define ASSERTCMP(X, OP, Y)			\
103617926a79SDavid Howells do {						\
103717926a79SDavid Howells } while (0)
103817926a79SDavid Howells 
103917926a79SDavid Howells #define ASSERTIF(C, X)				\
104017926a79SDavid Howells do {						\
104117926a79SDavid Howells } while (0)
104217926a79SDavid Howells 
104317926a79SDavid Howells #define ASSERTIFCMP(C, X, OP, Y)		\
104417926a79SDavid Howells do {						\
104517926a79SDavid Howells } while (0)
104617926a79SDavid Howells 
104717926a79SDavid Howells #endif /* __KDEBUGALL */
1048