xref: /openbmc/linux/net/rxrpc/ar-internal.h (revision 17926a79)
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 
1217926a79SDavid Howells #include <rxrpc/packet.h>
1317926a79SDavid Howells 
1417926a79SDavid Howells #if 0
1517926a79SDavid Howells #define CHECK_SLAB_OKAY(X)				     \
1617926a79SDavid Howells 	BUG_ON(atomic_read((X)) >> (sizeof(atomic_t) - 2) == \
1717926a79SDavid Howells 	       (POISON_FREE << 8 | POISON_FREE))
1817926a79SDavid Howells #else
1917926a79SDavid Howells #define CHECK_SLAB_OKAY(X) do {} while(0)
2017926a79SDavid Howells #endif
2117926a79SDavid Howells 
2217926a79SDavid Howells extern atomic_t rxrpc_n_skbs;
2317926a79SDavid Howells 
2417926a79SDavid Howells #define FCRYPT_BSIZE 8
2517926a79SDavid Howells struct rxrpc_crypt {
2617926a79SDavid Howells 	union {
2717926a79SDavid Howells 		u8	x[FCRYPT_BSIZE];
2817926a79SDavid Howells 		u32	n[2];
2917926a79SDavid Howells 	};
3017926a79SDavid Howells } __attribute__((aligned(8)));
3117926a79SDavid Howells 
3217926a79SDavid Howells extern __be32 rxrpc_epoch;		/* local epoch for detecting local-end reset */
3317926a79SDavid Howells extern atomic_t rxrpc_debug_id;		/* current debugging ID */
3417926a79SDavid Howells 
3517926a79SDavid Howells /*
3617926a79SDavid Howells  * sk_state for RxRPC sockets
3717926a79SDavid Howells  */
3817926a79SDavid Howells enum {
3917926a79SDavid Howells 	RXRPC_UNCONNECTED = 0,
4017926a79SDavid Howells 	RXRPC_CLIENT_BOUND,		/* client local address bound */
4117926a79SDavid Howells 	RXRPC_CLIENT_CONNECTED,		/* client is connected */
4217926a79SDavid Howells 	RXRPC_SERVER_BOUND,		/* server local address bound */
4317926a79SDavid Howells 	RXRPC_SERVER_LISTENING,		/* server listening for connections */
4417926a79SDavid Howells 	RXRPC_CLOSE,			/* socket is being closed */
4517926a79SDavid Howells };
4617926a79SDavid Howells 
4717926a79SDavid Howells /*
4817926a79SDavid Howells  * RxRPC socket definition
4917926a79SDavid Howells  */
5017926a79SDavid Howells struct rxrpc_sock {
5117926a79SDavid Howells 	/* WARNING: sk has to be the first member */
5217926a79SDavid Howells 	struct sock		sk;
5317926a79SDavid Howells 	struct rxrpc_local	*local;		/* local endpoint */
5417926a79SDavid Howells 	struct rxrpc_transport	*trans;		/* transport handler */
5517926a79SDavid Howells 	struct rxrpc_conn_bundle *bundle;	/* virtual connection bundle */
5617926a79SDavid Howells 	struct rxrpc_connection	*conn;		/* exclusive virtual connection */
5717926a79SDavid Howells 	struct list_head	listen_link;	/* link in the local endpoint's listen list */
5817926a79SDavid Howells 	struct list_head	secureq;	/* calls awaiting connection security clearance */
5917926a79SDavid Howells 	struct list_head	acceptq;	/* calls awaiting acceptance */
6017926a79SDavid Howells 	struct key		*key;		/* security for this socket */
6117926a79SDavid Howells 	struct key		*securities;	/* list of server security descriptors */
6217926a79SDavid Howells 	struct rb_root		calls;		/* outstanding calls on this socket */
6317926a79SDavid Howells 	unsigned long		flags;
6417926a79SDavid Howells #define RXRPC_SOCK_EXCLUSIVE_CONN	1	/* exclusive connection for a client socket */
6517926a79SDavid Howells 	rwlock_t		call_lock;	/* lock for calls */
6617926a79SDavid Howells 	u32			min_sec_level;	/* minimum security level */
6717926a79SDavid Howells #define RXRPC_SECURITY_MAX	RXRPC_SECURITY_ENCRYPT
6817926a79SDavid Howells 	struct sockaddr_rxrpc	srx;		/* local address */
6917926a79SDavid Howells 	sa_family_t		proto;		/* protocol created with */
7017926a79SDavid Howells 	__be16			service_id;	/* service ID of local/remote service */
7117926a79SDavid Howells };
7217926a79SDavid Howells 
7317926a79SDavid Howells #define rxrpc_sk(__sk) container_of((__sk), struct rxrpc_sock, sk)
7417926a79SDavid Howells 
7517926a79SDavid Howells /*
7617926a79SDavid Howells  * RxRPC socket buffer private variables
7717926a79SDavid Howells  * - max 48 bytes (struct sk_buff::cb)
7817926a79SDavid Howells  */
7917926a79SDavid Howells struct rxrpc_skb_priv {
8017926a79SDavid Howells 	struct rxrpc_call	*call;		/* call with which associated */
8117926a79SDavid Howells 	unsigned long		resend_at;	/* time in jiffies at which to resend */
8217926a79SDavid Howells 	union {
8317926a79SDavid Howells 		unsigned	offset;		/* offset into buffer of next read */
8417926a79SDavid Howells 		int		remain;		/* amount of space remaining for next write */
8517926a79SDavid Howells 		u32		error;		/* network error code */
8617926a79SDavid Howells 		bool		need_resend;	/* T if needs resending */
8717926a79SDavid Howells 	};
8817926a79SDavid Howells 
8917926a79SDavid Howells 	struct rxrpc_header	hdr;		/* RxRPC packet header from this packet */
9017926a79SDavid Howells };
9117926a79SDavid Howells 
9217926a79SDavid Howells #define rxrpc_skb(__skb) ((struct rxrpc_skb_priv *) &(__skb)->cb)
9317926a79SDavid Howells 
9417926a79SDavid Howells enum {
9517926a79SDavid Howells 	RXRPC_SKB_MARK_DATA,		/* data message */
9617926a79SDavid Howells 	RXRPC_SKB_MARK_FINAL_ACK,	/* final ACK received message */
9717926a79SDavid Howells 	RXRPC_SKB_MARK_BUSY,		/* server busy message */
9817926a79SDavid Howells 	RXRPC_SKB_MARK_REMOTE_ABORT,	/* remote abort message */
9917926a79SDavid Howells 	RXRPC_SKB_MARK_NET_ERROR,	/* network error message */
10017926a79SDavid Howells 	RXRPC_SKB_MARK_LOCAL_ERROR,	/* local error message */
10117926a79SDavid Howells 	RXRPC_SKB_MARK_NEW_CALL,	/* local error message */
10217926a79SDavid Howells };
10317926a79SDavid Howells 
10417926a79SDavid Howells enum rxrpc_command {
10517926a79SDavid Howells 	RXRPC_CMD_SEND_DATA,		/* send data message */
10617926a79SDavid Howells 	RXRPC_CMD_SEND_ABORT,		/* request abort generation */
10717926a79SDavid Howells 	RXRPC_CMD_ACCEPT,		/* [server] accept incoming call */
10817926a79SDavid Howells 	RXRPC_CMD_REJECT_BUSY,		/* [server] reject a call as busy */
10917926a79SDavid Howells };
11017926a79SDavid Howells 
11117926a79SDavid Howells /*
11217926a79SDavid Howells  * RxRPC security module interface
11317926a79SDavid Howells  */
11417926a79SDavid Howells struct rxrpc_security {
11517926a79SDavid Howells 	struct module		*owner;		/* providing module */
11617926a79SDavid Howells 	struct list_head	link;		/* link in master list */
11717926a79SDavid Howells 	const char		*name;		/* name of this service */
11817926a79SDavid Howells 	u8			security_index;	/* security type provided */
11917926a79SDavid Howells 
12017926a79SDavid Howells 	/* initialise a connection's security */
12117926a79SDavid Howells 	int (*init_connection_security)(struct rxrpc_connection *);
12217926a79SDavid Howells 
12317926a79SDavid Howells 	/* prime a connection's packet security */
12417926a79SDavid Howells 	void (*prime_packet_security)(struct rxrpc_connection *);
12517926a79SDavid Howells 
12617926a79SDavid Howells 	/* impose security on a packet */
12717926a79SDavid Howells 	int (*secure_packet)(const struct rxrpc_call *,
12817926a79SDavid Howells 			     struct sk_buff *,
12917926a79SDavid Howells 			     size_t,
13017926a79SDavid Howells 			     void *);
13117926a79SDavid Howells 
13217926a79SDavid Howells 	/* verify the security on a received packet */
13317926a79SDavid Howells 	int (*verify_packet)(const struct rxrpc_call *, struct sk_buff *,
13417926a79SDavid Howells 			     u32 *);
13517926a79SDavid Howells 
13617926a79SDavid Howells 	/* issue a challenge */
13717926a79SDavid Howells 	int (*issue_challenge)(struct rxrpc_connection *);
13817926a79SDavid Howells 
13917926a79SDavid Howells 	/* respond to a challenge */
14017926a79SDavid Howells 	int (*respond_to_challenge)(struct rxrpc_connection *,
14117926a79SDavid Howells 				    struct sk_buff *,
14217926a79SDavid Howells 				    u32 *);
14317926a79SDavid Howells 
14417926a79SDavid Howells 	/* verify a response */
14517926a79SDavid Howells 	int (*verify_response)(struct rxrpc_connection *,
14617926a79SDavid Howells 			       struct sk_buff *,
14717926a79SDavid Howells 			       u32 *);
14817926a79SDavid Howells 
14917926a79SDavid Howells 	/* clear connection security */
15017926a79SDavid Howells 	void (*clear)(struct rxrpc_connection *);
15117926a79SDavid Howells };
15217926a79SDavid Howells 
15317926a79SDavid Howells /*
15417926a79SDavid Howells  * RxRPC local transport endpoint definition
15517926a79SDavid Howells  * - matched by local port, address and protocol type
15617926a79SDavid Howells  */
15717926a79SDavid Howells struct rxrpc_local {
15817926a79SDavid Howells 	struct socket		*socket;	/* my UDP socket */
15917926a79SDavid Howells 	struct work_struct	destroyer;	/* endpoint destroyer */
16017926a79SDavid Howells 	struct work_struct	acceptor;	/* incoming call processor */
16117926a79SDavid Howells 	struct work_struct	rejecter;	/* packet reject writer */
16217926a79SDavid Howells 	struct list_head	services;	/* services listening on this endpoint */
16317926a79SDavid Howells 	struct list_head	link;		/* link in endpoint list */
16417926a79SDavid Howells 	struct rw_semaphore	defrag_sem;	/* control re-enablement of IP DF bit */
16517926a79SDavid Howells 	struct sk_buff_head	accept_queue;	/* incoming calls awaiting acceptance */
16617926a79SDavid Howells 	struct sk_buff_head	reject_queue;	/* packets awaiting rejection */
16717926a79SDavid Howells 	spinlock_t		lock;		/* access lock */
16817926a79SDavid Howells 	rwlock_t		services_lock;	/* lock for services list */
16917926a79SDavid Howells 	atomic_t		usage;
17017926a79SDavid Howells 	int			debug_id;	/* debug ID for printks */
17117926a79SDavid Howells 	volatile char		error_rcvd;	/* T if received ICMP error outstanding */
17217926a79SDavid Howells 	struct sockaddr_rxrpc	srx;		/* local address */
17317926a79SDavid Howells };
17417926a79SDavid Howells 
17517926a79SDavid Howells /*
17617926a79SDavid Howells  * RxRPC remote transport endpoint definition
17717926a79SDavid Howells  * - matched by remote port, address and protocol type
17817926a79SDavid Howells  * - holds the connection ID counter for connections between the two endpoints
17917926a79SDavid Howells  */
18017926a79SDavid Howells struct rxrpc_peer {
18117926a79SDavid Howells 	struct work_struct	destroyer;	/* peer destroyer */
18217926a79SDavid Howells 	struct list_head	link;		/* link in master peer list */
18317926a79SDavid Howells 	struct list_head	error_targets;	/* targets for net error distribution */
18417926a79SDavid Howells 	spinlock_t		lock;		/* access lock */
18517926a79SDavid Howells 	atomic_t		usage;
18617926a79SDavid Howells 	unsigned		if_mtu;		/* interface MTU for this peer */
18717926a79SDavid Howells 	unsigned		mtu;		/* network MTU for this peer */
18817926a79SDavid Howells 	unsigned		maxdata;	/* data size (MTU - hdrsize) */
18917926a79SDavid Howells 	unsigned short		hdrsize;	/* header size (IP + UDP + RxRPC) */
19017926a79SDavid Howells 	int			debug_id;	/* debug ID for printks */
19117926a79SDavid Howells 	int			net_error;	/* network error distributed */
19217926a79SDavid Howells 	struct sockaddr_rxrpc	srx;		/* remote address */
19317926a79SDavid Howells 
19417926a79SDavid Howells 	/* calculated RTT cache */
19517926a79SDavid Howells #define RXRPC_RTT_CACHE_SIZE 32
19617926a79SDavid Howells 	suseconds_t		rtt;		/* current RTT estimate (in uS) */
19717926a79SDavid Howells 	unsigned		rtt_point;	/* next entry at which to insert */
19817926a79SDavid Howells 	unsigned		rtt_usage;	/* amount of cache actually used */
19917926a79SDavid Howells 	suseconds_t		rtt_cache[RXRPC_RTT_CACHE_SIZE]; /* calculated RTT cache */
20017926a79SDavid Howells };
20117926a79SDavid Howells 
20217926a79SDavid Howells /*
20317926a79SDavid Howells  * RxRPC point-to-point transport / connection manager definition
20417926a79SDavid Howells  * - handles a bundle of connections between two endpoints
20517926a79SDavid Howells  * - matched by { local, peer }
20617926a79SDavid Howells  */
20717926a79SDavid Howells struct rxrpc_transport {
20817926a79SDavid Howells 	struct rxrpc_local	*local;		/* local transport endpoint */
20917926a79SDavid Howells 	struct rxrpc_peer	*peer;		/* remote transport endpoint */
21017926a79SDavid Howells 	struct work_struct	error_handler;	/* network error distributor */
21117926a79SDavid Howells 	struct rb_root		bundles;	/* client connection bundles on this transport */
21217926a79SDavid Howells 	struct rb_root		client_conns;	/* client connections on this transport */
21317926a79SDavid Howells 	struct rb_root		server_conns;	/* server connections on this transport */
21417926a79SDavid Howells 	struct list_head	link;		/* link in master session list */
21517926a79SDavid Howells 	struct sk_buff_head	error_queue;	/* error packets awaiting processing */
21617926a79SDavid Howells 	time_t			put_time;	/* time at which to reap */
21717926a79SDavid Howells 	spinlock_t		client_lock;	/* client connection allocation lock */
21817926a79SDavid Howells 	rwlock_t		conn_lock;	/* lock for active/dead connections */
21917926a79SDavid Howells 	atomic_t		usage;
22017926a79SDavid Howells 	int			debug_id;	/* debug ID for printks */
22117926a79SDavid Howells 	unsigned int		conn_idcounter;	/* connection ID counter (client) */
22217926a79SDavid Howells };
22317926a79SDavid Howells 
22417926a79SDavid Howells /*
22517926a79SDavid Howells  * RxRPC client connection bundle
22617926a79SDavid Howells  * - matched by { transport, service_id, key }
22717926a79SDavid Howells  */
22817926a79SDavid Howells struct rxrpc_conn_bundle {
22917926a79SDavid Howells 	struct rb_node		node;		/* node in transport's lookup tree */
23017926a79SDavid Howells 	struct list_head	unused_conns;	/* unused connections in this bundle */
23117926a79SDavid Howells 	struct list_head	avail_conns;	/* available connections in this bundle */
23217926a79SDavid Howells 	struct list_head	busy_conns;	/* busy connections in this bundle */
23317926a79SDavid Howells 	struct key		*key;		/* security for this bundle */
23417926a79SDavid Howells 	wait_queue_head_t	chanwait;	/* wait for channel to become available */
23517926a79SDavid Howells 	atomic_t		usage;
23617926a79SDavid Howells 	int			debug_id;	/* debug ID for printks */
23717926a79SDavid Howells 	unsigned short		num_conns;	/* number of connections in this bundle */
23817926a79SDavid Howells 	__be16			service_id;	/* service ID */
23917926a79SDavid Howells 	uint8_t			security_ix;	/* security type */
24017926a79SDavid Howells };
24117926a79SDavid Howells 
24217926a79SDavid Howells /*
24317926a79SDavid Howells  * RxRPC connection definition
24417926a79SDavid Howells  * - matched by { transport, service_id, conn_id, direction, key }
24517926a79SDavid Howells  * - each connection can only handle four simultaneous calls
24617926a79SDavid Howells  */
24717926a79SDavid Howells struct rxrpc_connection {
24817926a79SDavid Howells 	struct rxrpc_transport	*trans;		/* transport session */
24917926a79SDavid Howells 	struct rxrpc_conn_bundle *bundle;	/* connection bundle (client) */
25017926a79SDavid Howells 	struct work_struct	processor;	/* connection event processor */
25117926a79SDavid Howells 	struct rb_node		node;		/* node in transport's lookup tree */
25217926a79SDavid Howells 	struct list_head	link;		/* link in master connection list */
25317926a79SDavid Howells 	struct list_head	bundle_link;	/* link in bundle */
25417926a79SDavid Howells 	struct rb_root		calls;		/* calls on this connection */
25517926a79SDavid Howells 	struct sk_buff_head	rx_queue;	/* received conn-level packets */
25617926a79SDavid Howells 	struct rxrpc_call	*channels[RXRPC_MAXCALLS]; /* channels (active calls) */
25717926a79SDavid Howells 	struct rxrpc_security	*security;	/* applied security module */
25817926a79SDavid Howells 	struct key		*key;		/* security for this connection (client) */
25917926a79SDavid Howells 	struct key		*server_key;	/* security for this service */
26017926a79SDavid Howells 	struct crypto_blkcipher	*cipher;	/* encryption handle */
26117926a79SDavid Howells 	struct rxrpc_crypt	csum_iv;	/* packet checksum base */
26217926a79SDavid Howells 	unsigned long		events;
26317926a79SDavid Howells #define RXRPC_CONN_CHALLENGE	0		/* send challenge packet */
26417926a79SDavid Howells 	time_t			put_time;	/* time at which to reap */
26517926a79SDavid Howells 	rwlock_t		lock;		/* access lock */
26617926a79SDavid Howells 	spinlock_t		state_lock;	/* state-change lock */
26717926a79SDavid Howells 	atomic_t		usage;
26817926a79SDavid Howells 	u32			real_conn_id;	/* connection ID (host-endian) */
26917926a79SDavid Howells 	enum {					/* current state of connection */
27017926a79SDavid Howells 		RXRPC_CONN_UNUSED,		/* - connection not yet attempted */
27117926a79SDavid Howells 		RXRPC_CONN_CLIENT,		/* - client connection */
27217926a79SDavid Howells 		RXRPC_CONN_SERVER_UNSECURED,	/* - server unsecured connection */
27317926a79SDavid Howells 		RXRPC_CONN_SERVER_CHALLENGING,	/* - server challenging for security */
27417926a79SDavid Howells 		RXRPC_CONN_SERVER,		/* - server secured connection */
27517926a79SDavid Howells 		RXRPC_CONN_REMOTELY_ABORTED,	/* - conn aborted by peer */
27617926a79SDavid Howells 		RXRPC_CONN_LOCALLY_ABORTED,	/* - conn aborted locally */
27717926a79SDavid Howells 		RXRPC_CONN_NETWORK_ERROR,	/* - conn terminated by network error */
27817926a79SDavid Howells 	} state;
27917926a79SDavid Howells 	int			error;		/* error code for local abort */
28017926a79SDavid Howells 	int			debug_id;	/* debug ID for printks */
28117926a79SDavid Howells 	unsigned		call_counter;	/* call ID counter */
28217926a79SDavid Howells 	atomic_t		serial;		/* packet serial number counter */
28317926a79SDavid Howells 	atomic_t		hi_serial;	/* highest serial number received */
28417926a79SDavid Howells 	u8			avail_calls;	/* number of calls available */
28517926a79SDavid Howells 	u8			size_align;	/* data size alignment (for security) */
28617926a79SDavid Howells 	u8			header_size;	/* rxrpc + security header size */
28717926a79SDavid Howells 	u8			security_size;	/* security header size */
28817926a79SDavid Howells 	u32			security_level;	/* security level negotiated */
28917926a79SDavid Howells 	u32			security_nonce;	/* response re-use preventer */
29017926a79SDavid Howells 
29117926a79SDavid Howells 	/* the following are all in net order */
29217926a79SDavid Howells 	__be32			epoch;		/* epoch of this connection */
29317926a79SDavid Howells 	__be32			cid;		/* connection ID */
29417926a79SDavid Howells 	__be16			service_id;	/* service ID */
29517926a79SDavid Howells 	u8			security_ix;	/* security type */
29617926a79SDavid Howells 	u8			in_clientflag;	/* RXRPC_CLIENT_INITIATED if we are server */
29717926a79SDavid Howells 	u8			out_clientflag;	/* RXRPC_CLIENT_INITIATED if we are client */
29817926a79SDavid Howells };
29917926a79SDavid Howells 
30017926a79SDavid Howells /*
30117926a79SDavid Howells  * RxRPC call definition
30217926a79SDavid Howells  * - matched by { connection, call_id }
30317926a79SDavid Howells  */
30417926a79SDavid Howells struct rxrpc_call {
30517926a79SDavid Howells 	struct rxrpc_connection	*conn;		/* connection carrying call */
30617926a79SDavid Howells 	struct rxrpc_sock	*socket;	/* socket responsible */
30717926a79SDavid Howells 	struct timer_list	lifetimer;	/* lifetime remaining on call */
30817926a79SDavid Howells 	struct timer_list	deadspan;	/* reap timer for re-ACK'ing, etc  */
30917926a79SDavid Howells 	struct timer_list	ack_timer;	/* ACK generation timer */
31017926a79SDavid Howells 	struct timer_list	resend_timer;	/* Tx resend timer */
31117926a79SDavid Howells 	struct work_struct	destroyer;	/* call destroyer */
31217926a79SDavid Howells 	struct work_struct	processor;	/* packet processor and ACK generator */
31317926a79SDavid Howells 	struct list_head	link;		/* link in master call list */
31417926a79SDavid Howells 	struct list_head	error_link;	/* link in error distribution list */
31517926a79SDavid Howells 	struct list_head	accept_link;	/* calls awaiting acceptance */
31617926a79SDavid Howells 	struct rb_node		sock_node;	/* node in socket call tree */
31717926a79SDavid Howells 	struct rb_node		conn_node;	/* node in connection call tree */
31817926a79SDavid Howells 	struct sk_buff_head	rx_queue;	/* received packets */
31917926a79SDavid Howells 	struct sk_buff_head	rx_oos_queue;	/* packets received out of sequence */
32017926a79SDavid Howells 	struct sk_buff		*tx_pending;	/* Tx socket buffer being filled */
32117926a79SDavid Howells 	wait_queue_head_t	tx_waitq;	/* wait for Tx window space to become available */
32217926a79SDavid Howells 	unsigned long		user_call_ID;	/* user-defined call ID */
32317926a79SDavid Howells 	unsigned long		creation_jif;	/* time of call creation */
32417926a79SDavid Howells 	unsigned long		flags;
32517926a79SDavid Howells #define RXRPC_CALL_RELEASED	0	/* call has been released - no more message to userspace */
32617926a79SDavid Howells #define RXRPC_CALL_TERMINAL_MSG	1	/* call has given the socket its final message */
32717926a79SDavid Howells #define RXRPC_CALL_RCVD_LAST	2	/* all packets received */
32817926a79SDavid Howells #define RXRPC_CALL_RUN_RTIMER	3	/* Tx resend timer started */
32917926a79SDavid Howells #define RXRPC_CALL_TX_SOFT_ACK	4	/* sent some soft ACKs */
33017926a79SDavid Howells #define RXRPC_CALL_PROC_BUSY	5	/* the processor is busy */
33117926a79SDavid Howells #define RXRPC_CALL_INIT_ACCEPT	6	/* acceptance was initiated */
33217926a79SDavid Howells #define RXRPC_CALL_HAS_USERID	7	/* has a user ID attached */
33317926a79SDavid Howells #define RXRPC_CALL_EXPECT_OOS	8	/* expect out of sequence packets */
33417926a79SDavid Howells 	unsigned long		events;
33517926a79SDavid Howells #define RXRPC_CALL_RCVD_ACKALL	0	/* ACKALL or reply received */
33617926a79SDavid Howells #define RXRPC_CALL_RCVD_BUSY	1	/* busy packet received */
33717926a79SDavid Howells #define RXRPC_CALL_RCVD_ABORT	2	/* abort packet received */
33817926a79SDavid Howells #define RXRPC_CALL_RCVD_ERROR	3	/* network error received */
33917926a79SDavid Howells #define RXRPC_CALL_ACK_FINAL	4	/* need to generate final ACK (and release call) */
34017926a79SDavid Howells #define RXRPC_CALL_ACK		5	/* need to generate ACK */
34117926a79SDavid Howells #define RXRPC_CALL_REJECT_BUSY	6	/* need to generate busy message */
34217926a79SDavid Howells #define RXRPC_CALL_ABORT	7	/* need to generate abort */
34317926a79SDavid Howells #define RXRPC_CALL_CONN_ABORT	8	/* local connection abort generated */
34417926a79SDavid Howells #define RXRPC_CALL_RESEND_TIMER	9	/* Tx resend timer expired */
34517926a79SDavid Howells #define RXRPC_CALL_RESEND	10	/* Tx resend required */
34617926a79SDavid Howells #define RXRPC_CALL_DRAIN_RX_OOS	11	/* drain the Rx out of sequence queue */
34717926a79SDavid Howells #define RXRPC_CALL_LIFE_TIMER	12	/* call's lifetimer ran out */
34817926a79SDavid Howells #define RXRPC_CALL_ACCEPTED	13	/* incoming call accepted by userspace app */
34917926a79SDavid Howells #define RXRPC_CALL_SECURED	14	/* incoming call's connection is now secure */
35017926a79SDavid Howells #define RXRPC_CALL_POST_ACCEPT	15	/* need to post an "accept?" message to the app */
35117926a79SDavid Howells #define RXRPC_CALL_RELEASE	16	/* need to release the call's resources */
35217926a79SDavid Howells 
35317926a79SDavid Howells 	spinlock_t		lock;
35417926a79SDavid Howells 	rwlock_t		state_lock;	/* lock for state transition */
35517926a79SDavid Howells 	atomic_t		usage;
35617926a79SDavid Howells 	atomic_t		sequence;	/* Tx data packet sequence counter */
35717926a79SDavid Howells 	u32			abort_code;	/* local/remote abort code */
35817926a79SDavid Howells 	enum {					/* current state of call */
35917926a79SDavid Howells 		RXRPC_CALL_CLIENT_SEND_REQUEST,	/* - client sending request phase */
36017926a79SDavid Howells 		RXRPC_CALL_CLIENT_AWAIT_REPLY,	/* - client awaiting reply */
36117926a79SDavid Howells 		RXRPC_CALL_CLIENT_RECV_REPLY,	/* - client receiving reply phase */
36217926a79SDavid Howells 		RXRPC_CALL_CLIENT_FINAL_ACK,	/* - client sending final ACK phase */
36317926a79SDavid Howells 		RXRPC_CALL_SERVER_SECURING,	/* - server securing request connection */
36417926a79SDavid Howells 		RXRPC_CALL_SERVER_ACCEPTING,	/* - server accepting request */
36517926a79SDavid Howells 		RXRPC_CALL_SERVER_RECV_REQUEST,	/* - server receiving request */
36617926a79SDavid Howells 		RXRPC_CALL_SERVER_ACK_REQUEST,	/* - server pending ACK of request */
36717926a79SDavid Howells 		RXRPC_CALL_SERVER_SEND_REPLY,	/* - server sending reply */
36817926a79SDavid Howells 		RXRPC_CALL_SERVER_AWAIT_ACK,	/* - server awaiting final ACK */
36917926a79SDavid Howells 		RXRPC_CALL_COMPLETE,		/* - call completed */
37017926a79SDavid Howells 		RXRPC_CALL_SERVER_BUSY,		/* - call rejected by busy server */
37117926a79SDavid Howells 		RXRPC_CALL_REMOTELY_ABORTED,	/* - call aborted by peer */
37217926a79SDavid Howells 		RXRPC_CALL_LOCALLY_ABORTED,	/* - call aborted locally on error or close */
37317926a79SDavid Howells 		RXRPC_CALL_NETWORK_ERROR,	/* - call terminated by network error */
37417926a79SDavid Howells 		RXRPC_CALL_DEAD,		/* - call is dead */
37517926a79SDavid Howells 	} state;
37617926a79SDavid Howells 	int			debug_id;	/* debug ID for printks */
37717926a79SDavid Howells 	u8			channel;	/* connection channel occupied by this call */
37817926a79SDavid Howells 
37917926a79SDavid Howells 	/* transmission-phase ACK management */
38017926a79SDavid Howells 	uint8_t			acks_head;	/* offset into window of first entry */
38117926a79SDavid Howells 	uint8_t			acks_tail;	/* offset into window of last entry */
38217926a79SDavid Howells 	uint8_t			acks_winsz;	/* size of un-ACK'd window */
38317926a79SDavid Howells 	uint8_t			acks_unacked;	/* lowest unacked packet in last ACK received */
38417926a79SDavid Howells 	int			acks_latest;	/* serial number of latest ACK received */
38517926a79SDavid Howells 	rxrpc_seq_t		acks_hard;	/* highest definitively ACK'd msg seq */
38617926a79SDavid Howells 	unsigned long		*acks_window;	/* sent packet window
38717926a79SDavid Howells 						 * - elements are pointers with LSB set if ACK'd
38817926a79SDavid Howells 						 */
38917926a79SDavid Howells 
39017926a79SDavid Howells 	/* receive-phase ACK management */
39117926a79SDavid Howells 	rxrpc_seq_t		rx_data_expect;	/* next data seq ID expected to be received */
39217926a79SDavid Howells 	rxrpc_seq_t		rx_data_post;	/* next data seq ID expected to be posted */
39317926a79SDavid Howells 	rxrpc_seq_t		rx_data_recv;	/* last data seq ID encountered by recvmsg */
39417926a79SDavid Howells 	rxrpc_seq_t		rx_data_eaten;	/* last data seq ID consumed by recvmsg */
39517926a79SDavid Howells 	rxrpc_seq_t		rx_first_oos;	/* first packet in rx_oos_queue (or 0) */
39617926a79SDavid Howells 	rxrpc_seq_t		ackr_win_top;	/* top of ACK window (rx_data_eaten is bottom) */
39717926a79SDavid Howells 	rxrpc_seq_net_t		ackr_prev_seq;	/* previous sequence number received */
39817926a79SDavid Howells 	uint8_t			ackr_reason;	/* reason to ACK */
39917926a79SDavid Howells 	__be32			ackr_serial;	/* serial of packet being ACK'd */
40017926a79SDavid Howells 	atomic_t		ackr_not_idle;	/* number of packets in Rx queue */
40117926a79SDavid Howells 
40217926a79SDavid Howells 	/* received packet records, 1 bit per record */
40317926a79SDavid Howells #define RXRPC_ACKR_WINDOW_ASZ DIV_ROUND_UP(RXRPC_MAXACKS, BITS_PER_LONG)
40417926a79SDavid Howells 	unsigned long		ackr_window[RXRPC_ACKR_WINDOW_ASZ + 1];
40517926a79SDavid Howells 
40617926a79SDavid Howells 	/* the following should all be in net order */
40717926a79SDavid Howells 	__be32			cid;		/* connection ID + channel index  */
40817926a79SDavid Howells 	__be32			call_id;	/* call ID on connection  */
40917926a79SDavid Howells };
41017926a79SDavid Howells 
41117926a79SDavid Howells /*
41217926a79SDavid Howells  * RxRPC key for Kerberos (type-2 security)
41317926a79SDavid Howells  */
41417926a79SDavid Howells struct rxkad_key {
41517926a79SDavid Howells 	u16	security_index;		/* RxRPC header security index */
41617926a79SDavid Howells 	u16	ticket_len;		/* length of ticket[] */
41717926a79SDavid Howells 	u32	expiry;			/* time at which expires */
41817926a79SDavid Howells 	u32	kvno;			/* key version number */
41917926a79SDavid Howells 	u8	session_key[8];		/* DES session key */
42017926a79SDavid Howells 	u8	ticket[0];		/* the encrypted ticket */
42117926a79SDavid Howells };
42217926a79SDavid Howells 
42317926a79SDavid Howells struct rxrpc_key_payload {
42417926a79SDavid Howells 	struct rxkad_key k;
42517926a79SDavid Howells };
42617926a79SDavid Howells 
42717926a79SDavid Howells /*
42817926a79SDavid Howells  * locally abort an RxRPC call
42917926a79SDavid Howells  */
43017926a79SDavid Howells static inline void rxrpc_abort_call(struct rxrpc_call *call, u32 abort_code)
43117926a79SDavid Howells {
43217926a79SDavid Howells 	write_lock_bh(&call->state_lock);
43317926a79SDavid Howells 	if (call->state < RXRPC_CALL_COMPLETE) {
43417926a79SDavid Howells 		call->abort_code = abort_code;
43517926a79SDavid Howells 		call->state = RXRPC_CALL_LOCALLY_ABORTED;
43617926a79SDavid Howells 		set_bit(RXRPC_CALL_ABORT, &call->events);
43717926a79SDavid Howells 	}
43817926a79SDavid Howells 	write_unlock_bh(&call->state_lock);
43917926a79SDavid Howells }
44017926a79SDavid Howells 
44117926a79SDavid Howells /*
44217926a79SDavid Howells  * put a packet up for transport-level abort
44317926a79SDavid Howells  */
44417926a79SDavid Howells static inline
44517926a79SDavid Howells void rxrpc_reject_packet(struct rxrpc_local *local, struct sk_buff *skb)
44617926a79SDavid Howells {
44717926a79SDavid Howells 	CHECK_SLAB_OKAY(&local->usage);
44817926a79SDavid Howells 	if (!atomic_inc_not_zero(&local->usage)) {
44917926a79SDavid Howells 		printk("resurrected on reject\n");
45017926a79SDavid Howells 		BUG();
45117926a79SDavid Howells 	}
45217926a79SDavid Howells 	skb_queue_tail(&local->reject_queue, skb);
45317926a79SDavid Howells 	schedule_work(&local->rejecter);
45417926a79SDavid Howells }
45517926a79SDavid Howells 
45617926a79SDavid Howells /*
45717926a79SDavid Howells  * ar-accept.c
45817926a79SDavid Howells  */
45917926a79SDavid Howells extern void rxrpc_accept_incoming_calls(struct work_struct *);
46017926a79SDavid Howells extern int rxrpc_accept_call(struct rxrpc_sock *, unsigned long);
46117926a79SDavid Howells 
46217926a79SDavid Howells /*
46317926a79SDavid Howells  * ar-ack.c
46417926a79SDavid Howells  */
46517926a79SDavid Howells extern void __rxrpc_propose_ACK(struct rxrpc_call *, uint8_t, __be32, bool);
46617926a79SDavid Howells extern void rxrpc_propose_ACK(struct rxrpc_call *, uint8_t, __be32, bool);
46717926a79SDavid Howells extern void rxrpc_process_call(struct work_struct *);
46817926a79SDavid Howells 
46917926a79SDavid Howells /*
47017926a79SDavid Howells  * ar-call.c
47117926a79SDavid Howells  */
47217926a79SDavid Howells extern struct kmem_cache *rxrpc_call_jar;
47317926a79SDavid Howells extern struct list_head rxrpc_calls;
47417926a79SDavid Howells extern rwlock_t rxrpc_call_lock;
47517926a79SDavid Howells 
47617926a79SDavid Howells extern struct rxrpc_call *rxrpc_get_client_call(struct rxrpc_sock *,
47717926a79SDavid Howells 						struct rxrpc_transport *,
47817926a79SDavid Howells 						struct rxrpc_conn_bundle *,
47917926a79SDavid Howells 						unsigned long, int, gfp_t);
48017926a79SDavid Howells extern struct rxrpc_call *rxrpc_incoming_call(struct rxrpc_sock *,
48117926a79SDavid Howells 					      struct rxrpc_connection *,
48217926a79SDavid Howells 					      struct rxrpc_header *, gfp_t);
48317926a79SDavid Howells extern struct rxrpc_call *rxrpc_find_server_call(struct rxrpc_sock *,
48417926a79SDavid Howells 						 unsigned long);
48517926a79SDavid Howells extern void rxrpc_release_call(struct rxrpc_call *);
48617926a79SDavid Howells extern void rxrpc_release_calls_on_socket(struct rxrpc_sock *);
48717926a79SDavid Howells extern void __rxrpc_put_call(struct rxrpc_call *);
48817926a79SDavid Howells extern void __exit rxrpc_destroy_all_calls(void);
48917926a79SDavid Howells 
49017926a79SDavid Howells /*
49117926a79SDavid Howells  * ar-connection.c
49217926a79SDavid Howells  */
49317926a79SDavid Howells extern struct list_head rxrpc_connections;
49417926a79SDavid Howells extern rwlock_t rxrpc_connection_lock;
49517926a79SDavid Howells 
49617926a79SDavid Howells extern struct rxrpc_conn_bundle *rxrpc_get_bundle(struct rxrpc_sock *,
49717926a79SDavid Howells 						  struct rxrpc_transport *,
49817926a79SDavid Howells 						  struct key *,
49917926a79SDavid Howells 						  __be16, gfp_t);
50017926a79SDavid Howells extern void rxrpc_put_bundle(struct rxrpc_transport *,
50117926a79SDavid Howells 			     struct rxrpc_conn_bundle *);
50217926a79SDavid Howells extern int rxrpc_connect_call(struct rxrpc_sock *, struct rxrpc_transport *,
50317926a79SDavid Howells 			      struct rxrpc_conn_bundle *, struct rxrpc_call *,
50417926a79SDavid Howells 			      gfp_t);
50517926a79SDavid Howells extern void rxrpc_put_connection(struct rxrpc_connection *);
50617926a79SDavid Howells extern void __exit rxrpc_destroy_all_connections(void);
50717926a79SDavid Howells extern struct rxrpc_connection *rxrpc_find_connection(struct rxrpc_transport *,
50817926a79SDavid Howells 						      struct rxrpc_header *);
50917926a79SDavid Howells extern struct rxrpc_connection *
51017926a79SDavid Howells rxrpc_incoming_connection(struct rxrpc_transport *, struct rxrpc_header *,
51117926a79SDavid Howells 			  gfp_t);
51217926a79SDavid Howells 
51317926a79SDavid Howells /*
51417926a79SDavid Howells  * ar-connevent.c
51517926a79SDavid Howells  */
51617926a79SDavid Howells extern void rxrpc_process_connection(struct work_struct *);
51717926a79SDavid Howells extern void rxrpc_reject_packets(struct work_struct *);
51817926a79SDavid Howells 
51917926a79SDavid Howells /*
52017926a79SDavid Howells  * ar-error.c
52117926a79SDavid Howells  */
52217926a79SDavid Howells extern void rxrpc_UDP_error_report(struct sock *);
52317926a79SDavid Howells extern void rxrpc_UDP_error_handler(struct work_struct *);
52417926a79SDavid Howells 
52517926a79SDavid Howells /*
52617926a79SDavid Howells  * ar-input.c
52717926a79SDavid Howells  */
52817926a79SDavid Howells extern unsigned long rxrpc_ack_timeout;
52917926a79SDavid Howells extern const char *rxrpc_pkts[];
53017926a79SDavid Howells 
53117926a79SDavid Howells extern void rxrpc_data_ready(struct sock *, int);
53217926a79SDavid Howells extern int rxrpc_queue_rcv_skb(struct rxrpc_call *, struct sk_buff *, bool,
53317926a79SDavid Howells 			       bool);
53417926a79SDavid Howells extern void rxrpc_fast_process_packet(struct rxrpc_call *, struct sk_buff *);
53517926a79SDavid Howells 
53617926a79SDavid Howells /*
53717926a79SDavid Howells  * ar-local.c
53817926a79SDavid Howells  */
53917926a79SDavid Howells extern rwlock_t rxrpc_local_lock;
54017926a79SDavid Howells extern struct rxrpc_local *rxrpc_lookup_local(struct sockaddr_rxrpc *);
54117926a79SDavid Howells extern void rxrpc_put_local(struct rxrpc_local *);
54217926a79SDavid Howells extern void __exit rxrpc_destroy_all_locals(void);
54317926a79SDavid Howells 
54417926a79SDavid Howells /*
54517926a79SDavid Howells  * ar-key.c
54617926a79SDavid Howells  */
54717926a79SDavid Howells extern struct key_type key_type_rxrpc;
54817926a79SDavid Howells extern struct key_type key_type_rxrpc_s;
54917926a79SDavid Howells 
55017926a79SDavid Howells extern int rxrpc_request_key(struct rxrpc_sock *, char __user *, int);
55117926a79SDavid Howells extern int rxrpc_server_keyring(struct rxrpc_sock *, char __user *, int);
55217926a79SDavid Howells extern int rxrpc_get_server_data_key(struct rxrpc_connection *, const void *,
55317926a79SDavid Howells 				     time_t, u32);
55417926a79SDavid Howells 
55517926a79SDavid Howells /*
55617926a79SDavid Howells  * ar-output.c
55717926a79SDavid Howells  */
55817926a79SDavid Howells extern int rxrpc_resend_timeout;
55917926a79SDavid Howells 
56017926a79SDavid Howells extern int rxrpc_send_packet(struct rxrpc_transport *, struct sk_buff *);
56117926a79SDavid Howells extern int rxrpc_client_sendmsg(struct kiocb *, struct rxrpc_sock *,
56217926a79SDavid Howells 				struct rxrpc_transport *, struct msghdr *,
56317926a79SDavid Howells 				size_t);
56417926a79SDavid Howells extern int rxrpc_server_sendmsg(struct kiocb *, struct rxrpc_sock *,
56517926a79SDavid Howells 				struct msghdr *, size_t);
56617926a79SDavid Howells 
56717926a79SDavid Howells /*
56817926a79SDavid Howells  * ar-peer.c
56917926a79SDavid Howells  */
57017926a79SDavid Howells extern struct rxrpc_peer *rxrpc_get_peer(struct sockaddr_rxrpc *, gfp_t);
57117926a79SDavid Howells extern void rxrpc_put_peer(struct rxrpc_peer *);
57217926a79SDavid Howells extern struct rxrpc_peer *rxrpc_find_peer(struct rxrpc_local *,
57317926a79SDavid Howells 					  __be32, __be16);
57417926a79SDavid Howells extern void __exit rxrpc_destroy_all_peers(void);
57517926a79SDavid Howells 
57617926a79SDavid Howells /*
57717926a79SDavid Howells  * ar-proc.c
57817926a79SDavid Howells  */
57917926a79SDavid Howells extern const char *rxrpc_call_states[];
58017926a79SDavid Howells extern struct file_operations rxrpc_call_seq_fops;
58117926a79SDavid Howells extern struct file_operations rxrpc_connection_seq_fops;
58217926a79SDavid Howells 
58317926a79SDavid Howells /*
58417926a79SDavid Howells  * ar-recvmsg.c
58517926a79SDavid Howells  */
58617926a79SDavid Howells extern int rxrpc_recvmsg(struct kiocb *, struct socket *, struct msghdr *,
58717926a79SDavid Howells 			 size_t, int);
58817926a79SDavid Howells 
58917926a79SDavid Howells /*
59017926a79SDavid Howells  * ar-security.c
59117926a79SDavid Howells  */
59217926a79SDavid Howells extern int rxrpc_register_security(struct rxrpc_security *);
59317926a79SDavid Howells extern void rxrpc_unregister_security(struct rxrpc_security *);
59417926a79SDavid Howells extern int rxrpc_init_client_conn_security(struct rxrpc_connection *);
59517926a79SDavid Howells extern int rxrpc_init_server_conn_security(struct rxrpc_connection *);
59617926a79SDavid Howells extern int rxrpc_secure_packet(const struct rxrpc_call *, struct sk_buff *,
59717926a79SDavid Howells 			       size_t, void *);
59817926a79SDavid Howells extern int rxrpc_verify_packet(const struct rxrpc_call *, struct sk_buff *,
59917926a79SDavid Howells 			       u32 *);
60017926a79SDavid Howells extern void rxrpc_clear_conn_security(struct rxrpc_connection *);
60117926a79SDavid Howells 
60217926a79SDavid Howells /*
60317926a79SDavid Howells  * ar-skbuff.c
60417926a79SDavid Howells  */
60517926a79SDavid Howells extern void rxrpc_packet_destructor(struct sk_buff *);
60617926a79SDavid Howells 
60717926a79SDavid Howells /*
60817926a79SDavid Howells  * ar-transport.c
60917926a79SDavid Howells  */
61017926a79SDavid Howells extern struct rxrpc_transport *rxrpc_get_transport(struct rxrpc_local *,
61117926a79SDavid Howells 						   struct rxrpc_peer *,
61217926a79SDavid Howells 						   gfp_t);
61317926a79SDavid Howells extern void rxrpc_put_transport(struct rxrpc_transport *);
61417926a79SDavid Howells extern void __exit rxrpc_destroy_all_transports(void);
61517926a79SDavid Howells extern struct rxrpc_transport *rxrpc_find_transport(struct rxrpc_local *,
61617926a79SDavid Howells 						    struct rxrpc_peer *);
61717926a79SDavid Howells 
61817926a79SDavid Howells /*
61917926a79SDavid Howells  * debug tracing
62017926a79SDavid Howells  */
62117926a79SDavid Howells extern unsigned rxrpc_debug;
62217926a79SDavid Howells 
62317926a79SDavid Howells #define dbgprintk(FMT,...) \
62417926a79SDavid Howells 	printk("[%x%-6.6s] "FMT"\n", smp_processor_id(), current->comm ,##__VA_ARGS__)
62517926a79SDavid Howells 
62617926a79SDavid Howells /* make sure we maintain the format strings, even when debugging is disabled */
62717926a79SDavid Howells static inline __attribute__((format(printf,1,2)))
62817926a79SDavid Howells void _dbprintk(const char *fmt, ...)
62917926a79SDavid Howells {
63017926a79SDavid Howells }
63117926a79SDavid Howells 
63217926a79SDavid Howells #define kenter(FMT,...)	dbgprintk("==> %s("FMT")",__FUNCTION__ ,##__VA_ARGS__)
63317926a79SDavid Howells #define kleave(FMT,...)	dbgprintk("<== %s()"FMT"",__FUNCTION__ ,##__VA_ARGS__)
63417926a79SDavid Howells #define kdebug(FMT,...)	dbgprintk("    "FMT ,##__VA_ARGS__)
63517926a79SDavid Howells #define kproto(FMT,...)	dbgprintk("### "FMT ,##__VA_ARGS__)
63617926a79SDavid Howells #define knet(FMT,...)	dbgprintk("@@@ "FMT ,##__VA_ARGS__)
63717926a79SDavid Howells 
63817926a79SDavid Howells 
63917926a79SDavid Howells #if defined(__KDEBUG)
64017926a79SDavid Howells #define _enter(FMT,...)	kenter(FMT,##__VA_ARGS__)
64117926a79SDavid Howells #define _leave(FMT,...)	kleave(FMT,##__VA_ARGS__)
64217926a79SDavid Howells #define _debug(FMT,...)	kdebug(FMT,##__VA_ARGS__)
64317926a79SDavid Howells #define _proto(FMT,...)	kproto(FMT,##__VA_ARGS__)
64417926a79SDavid Howells #define _net(FMT,...)	knet(FMT,##__VA_ARGS__)
64517926a79SDavid Howells 
64617926a79SDavid Howells #elif defined(CONFIG_AF_RXRPC_DEBUG)
64717926a79SDavid Howells #define RXRPC_DEBUG_KENTER	0x01
64817926a79SDavid Howells #define RXRPC_DEBUG_KLEAVE	0x02
64917926a79SDavid Howells #define RXRPC_DEBUG_KDEBUG	0x04
65017926a79SDavid Howells #define RXRPC_DEBUG_KPROTO	0x08
65117926a79SDavid Howells #define RXRPC_DEBUG_KNET	0x10
65217926a79SDavid Howells 
65317926a79SDavid Howells #define _enter(FMT,...)					\
65417926a79SDavid Howells do {							\
65517926a79SDavid Howells 	if (unlikely(rxrpc_debug & RXRPC_DEBUG_KENTER))	\
65617926a79SDavid Howells 		kenter(FMT,##__VA_ARGS__);		\
65717926a79SDavid Howells } while (0)
65817926a79SDavid Howells 
65917926a79SDavid Howells #define _leave(FMT,...)					\
66017926a79SDavid Howells do {							\
66117926a79SDavid Howells 	if (unlikely(rxrpc_debug & RXRPC_DEBUG_KLEAVE))	\
66217926a79SDavid Howells 		kleave(FMT,##__VA_ARGS__);		\
66317926a79SDavid Howells } while (0)
66417926a79SDavid Howells 
66517926a79SDavid Howells #define _debug(FMT,...)					\
66617926a79SDavid Howells do {							\
66717926a79SDavid Howells 	if (unlikely(rxrpc_debug & RXRPC_DEBUG_KDEBUG))	\
66817926a79SDavid Howells 		kdebug(FMT,##__VA_ARGS__);		\
66917926a79SDavid Howells } while (0)
67017926a79SDavid Howells 
67117926a79SDavid Howells #define _proto(FMT,...)					\
67217926a79SDavid Howells do {							\
67317926a79SDavid Howells 	if (unlikely(rxrpc_debug & RXRPC_DEBUG_KPROTO))	\
67417926a79SDavid Howells 		kproto(FMT,##__VA_ARGS__);		\
67517926a79SDavid Howells } while (0)
67617926a79SDavid Howells 
67717926a79SDavid Howells #define _net(FMT,...)					\
67817926a79SDavid Howells do {							\
67917926a79SDavid Howells 	if (unlikely(rxrpc_debug & RXRPC_DEBUG_KNET))	\
68017926a79SDavid Howells 		knet(FMT,##__VA_ARGS__);		\
68117926a79SDavid Howells } while (0)
68217926a79SDavid Howells 
68317926a79SDavid Howells #else
68417926a79SDavid Howells #define _enter(FMT,...)	_dbprintk("==> %s("FMT")",__FUNCTION__ ,##__VA_ARGS__)
68517926a79SDavid Howells #define _leave(FMT,...)	_dbprintk("<== %s()"FMT"",__FUNCTION__ ,##__VA_ARGS__)
68617926a79SDavid Howells #define _debug(FMT,...)	_dbprintk("    "FMT ,##__VA_ARGS__)
68717926a79SDavid Howells #define _proto(FMT,...)	_dbprintk("### "FMT ,##__VA_ARGS__)
68817926a79SDavid Howells #define _net(FMT,...)	_dbprintk("@@@ "FMT ,##__VA_ARGS__)
68917926a79SDavid Howells #endif
69017926a79SDavid Howells 
69117926a79SDavid Howells /*
69217926a79SDavid Howells  * debug assertion checking
69317926a79SDavid Howells  */
69417926a79SDavid Howells #if 1 // defined(__KDEBUGALL)
69517926a79SDavid Howells 
69617926a79SDavid Howells #define ASSERT(X)						\
69717926a79SDavid Howells do {								\
69817926a79SDavid Howells 	if (unlikely(!(X))) {					\
69917926a79SDavid Howells 		printk(KERN_ERR "\n");				\
70017926a79SDavid Howells 		printk(KERN_ERR "RxRPC: Assertion failed\n");	\
70117926a79SDavid Howells 		BUG();						\
70217926a79SDavid Howells 	}							\
70317926a79SDavid Howells } while(0)
70417926a79SDavid Howells 
70517926a79SDavid Howells #define ASSERTCMP(X, OP, Y)						\
70617926a79SDavid Howells do {									\
70717926a79SDavid Howells 	if (unlikely(!((X) OP (Y)))) {					\
70817926a79SDavid Howells 		printk(KERN_ERR "\n");					\
70917926a79SDavid Howells 		printk(KERN_ERR "RxRPC: Assertion failed\n");		\
71017926a79SDavid Howells 		printk(KERN_ERR "%lu " #OP " %lu is false\n",		\
71117926a79SDavid Howells 		       (unsigned long)(X), (unsigned long)(Y));		\
71217926a79SDavid Howells 		printk(KERN_ERR "0x%lx " #OP " 0x%lx is false\n",	\
71317926a79SDavid Howells 		       (unsigned long)(X), (unsigned long)(Y));		\
71417926a79SDavid Howells 		BUG();							\
71517926a79SDavid Howells 	}								\
71617926a79SDavid Howells } while(0)
71717926a79SDavid Howells 
71817926a79SDavid Howells #define ASSERTIF(C, X)						\
71917926a79SDavid Howells do {								\
72017926a79SDavid Howells 	if (unlikely((C) && !(X))) {				\
72117926a79SDavid Howells 		printk(KERN_ERR "\n");				\
72217926a79SDavid Howells 		printk(KERN_ERR "RxRPC: Assertion failed\n");	\
72317926a79SDavid Howells 		BUG();						\
72417926a79SDavid Howells 	}							\
72517926a79SDavid Howells } while(0)
72617926a79SDavid Howells 
72717926a79SDavid Howells #define ASSERTIFCMP(C, X, OP, Y)					\
72817926a79SDavid Howells do {									\
72917926a79SDavid Howells 	if (unlikely((C) && !((X) OP (Y)))) {				\
73017926a79SDavid Howells 		printk(KERN_ERR "\n");					\
73117926a79SDavid Howells 		printk(KERN_ERR "RxRPC: Assertion failed\n");		\
73217926a79SDavid Howells 		printk(KERN_ERR "%lu " #OP " %lu is false\n",		\
73317926a79SDavid Howells 		       (unsigned long)(X), (unsigned long)(Y));		\
73417926a79SDavid Howells 		printk(KERN_ERR "0x%lx " #OP " 0x%lx is false\n",	\
73517926a79SDavid Howells 		       (unsigned long)(X), (unsigned long)(Y));		\
73617926a79SDavid Howells 		BUG();							\
73717926a79SDavid Howells 	}								\
73817926a79SDavid Howells } while(0)
73917926a79SDavid Howells 
74017926a79SDavid Howells #else
74117926a79SDavid Howells 
74217926a79SDavid Howells #define ASSERT(X)				\
74317926a79SDavid Howells do {						\
74417926a79SDavid Howells } while(0)
74517926a79SDavid Howells 
74617926a79SDavid Howells #define ASSERTCMP(X, OP, Y)			\
74717926a79SDavid Howells do {						\
74817926a79SDavid Howells } while(0)
74917926a79SDavid Howells 
75017926a79SDavid Howells #define ASSERTIF(C, X)				\
75117926a79SDavid Howells do {						\
75217926a79SDavid Howells } while(0)
75317926a79SDavid Howells 
75417926a79SDavid Howells #define ASSERTIFCMP(C, X, OP, Y)		\
75517926a79SDavid Howells do {						\
75617926a79SDavid Howells } while(0)
75717926a79SDavid Howells 
75817926a79SDavid Howells #endif /* __KDEBUGALL */
75917926a79SDavid Howells 
76017926a79SDavid Howells /*
76117926a79SDavid Howells  * socket buffer accounting / leak finding
76217926a79SDavid Howells  */
76317926a79SDavid Howells static inline void __rxrpc_new_skb(struct sk_buff *skb, const char *fn)
76417926a79SDavid Howells {
76517926a79SDavid Howells 	//_net("new skb %p %s [%d]", skb, fn, atomic_read(&rxrpc_n_skbs));
76617926a79SDavid Howells 	//atomic_inc(&rxrpc_n_skbs);
76717926a79SDavid Howells }
76817926a79SDavid Howells 
76917926a79SDavid Howells #define rxrpc_new_skb(skb) __rxrpc_new_skb((skb), __func__)
77017926a79SDavid Howells 
77117926a79SDavid Howells static inline void __rxrpc_kill_skb(struct sk_buff *skb, const char *fn)
77217926a79SDavid Howells {
77317926a79SDavid Howells 	//_net("kill skb %p %s [%d]", skb, fn, atomic_read(&rxrpc_n_skbs));
77417926a79SDavid Howells 	//atomic_dec(&rxrpc_n_skbs);
77517926a79SDavid Howells }
77617926a79SDavid Howells 
77717926a79SDavid Howells #define rxrpc_kill_skb(skb) __rxrpc_kill_skb((skb), __func__)
77817926a79SDavid Howells 
77917926a79SDavid Howells static inline void __rxrpc_free_skb(struct sk_buff *skb, const char *fn)
78017926a79SDavid Howells {
78117926a79SDavid Howells 	if (skb) {
78217926a79SDavid Howells 		CHECK_SLAB_OKAY(&skb->users);
78317926a79SDavid Howells 		//_net("free skb %p %s [%d]",
78417926a79SDavid Howells 		//     skb, fn, atomic_read(&rxrpc_n_skbs));
78517926a79SDavid Howells 		//atomic_dec(&rxrpc_n_skbs);
78617926a79SDavid Howells 		kfree_skb(skb);
78717926a79SDavid Howells 	}
78817926a79SDavid Howells }
78917926a79SDavid Howells 
79017926a79SDavid Howells #define rxrpc_free_skb(skb) __rxrpc_free_skb((skb), __func__)
79117926a79SDavid Howells 
79217926a79SDavid Howells static inline void rxrpc_purge_queue(struct sk_buff_head *list)
79317926a79SDavid Howells {
79417926a79SDavid Howells 	struct sk_buff *skb;
79517926a79SDavid Howells 	while ((skb = skb_dequeue((list))) != NULL)
79617926a79SDavid Howells 		rxrpc_free_skb(skb);
79717926a79SDavid Howells }
79817926a79SDavid Howells 
79917926a79SDavid Howells static inline void __rxrpc__atomic_inc(atomic_t *v)
80017926a79SDavid Howells {
80117926a79SDavid Howells 	CHECK_SLAB_OKAY(v);
80217926a79SDavid Howells 	atomic_inc(v);
80317926a79SDavid Howells }
80417926a79SDavid Howells 
80517926a79SDavid Howells #define atomic_inc(v) __rxrpc__atomic_inc((v))
80617926a79SDavid Howells 
80717926a79SDavid Howells static inline void __rxrpc__atomic_dec(atomic_t *v)
80817926a79SDavid Howells {
80917926a79SDavid Howells 	CHECK_SLAB_OKAY(v);
81017926a79SDavid Howells 	atomic_dec(v);
81117926a79SDavid Howells }
81217926a79SDavid Howells 
81317926a79SDavid Howells #define atomic_dec(v) __rxrpc__atomic_dec((v))
81417926a79SDavid Howells 
81517926a79SDavid Howells static inline int __rxrpc__atomic_dec_and_test(atomic_t *v)
81617926a79SDavid Howells {
81717926a79SDavid Howells 	CHECK_SLAB_OKAY(v);
81817926a79SDavid Howells 	return atomic_dec_and_test(v);
81917926a79SDavid Howells }
82017926a79SDavid Howells 
82117926a79SDavid Howells #define atomic_dec_and_test(v) __rxrpc__atomic_dec_and_test((v))
82217926a79SDavid Howells 
82317926a79SDavid Howells static inline void __rxrpc_get_local(struct rxrpc_local *local, const char *f)
82417926a79SDavid Howells {
82517926a79SDavid Howells 	CHECK_SLAB_OKAY(&local->usage);
82617926a79SDavid Howells 	if (atomic_inc_return(&local->usage) == 1)
82717926a79SDavid Howells 		printk("resurrected (%s)\n", f);
82817926a79SDavid Howells }
82917926a79SDavid Howells 
83017926a79SDavid Howells #define rxrpc_get_local(LOCAL) __rxrpc_get_local((LOCAL), __func__)
83117926a79SDavid Howells 
83217926a79SDavid Howells #define rxrpc_get_call(CALL)				\
83317926a79SDavid Howells do {							\
83417926a79SDavid Howells 	CHECK_SLAB_OKAY(&(CALL)->usage);		\
83517926a79SDavid Howells 	if (atomic_inc_return(&(CALL)->usage) == 1)	\
83617926a79SDavid Howells 		BUG();					\
83717926a79SDavid Howells } while(0)
83817926a79SDavid Howells 
83917926a79SDavid Howells #define rxrpc_put_call(CALL)				\
84017926a79SDavid Howells do {							\
84117926a79SDavid Howells 	__rxrpc_put_call(CALL);				\
84217926a79SDavid Howells } while(0)
843