xref: /openbmc/linux/net/rxrpc/ar-internal.h (revision 648af7fc)
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 #define FCRYPT_BSIZE 8
2317926a79SDavid Howells struct rxrpc_crypt {
2417926a79SDavid Howells 	union {
2517926a79SDavid Howells 		u8	x[FCRYPT_BSIZE];
2691e916cfSAl Viro 		__be32	n[2];
2717926a79SDavid Howells 	};
2817926a79SDavid Howells } __attribute__((aligned(8)));
2917926a79SDavid Howells 
30651350d1SDavid Howells #define rxrpc_queue_work(WS)	queue_work(rxrpc_workqueue, (WS))
31651350d1SDavid Howells #define rxrpc_queue_delayed_work(WS,D)	\
32651350d1SDavid Howells 	queue_delayed_work(rxrpc_workqueue, (WS), (D))
33651350d1SDavid Howells 
34651350d1SDavid Howells #define rxrpc_queue_call(CALL)	rxrpc_queue_work(&(CALL)->processor)
35651350d1SDavid Howells #define rxrpc_queue_conn(CONN)	rxrpc_queue_work(&(CONN)->processor)
3617926a79SDavid Howells 
3717926a79SDavid Howells /*
3817926a79SDavid Howells  * sk_state for RxRPC sockets
3917926a79SDavid Howells  */
4017926a79SDavid Howells enum {
4117926a79SDavid Howells 	RXRPC_UNCONNECTED = 0,
4217926a79SDavid Howells 	RXRPC_CLIENT_BOUND,		/* client local address bound */
4317926a79SDavid Howells 	RXRPC_CLIENT_CONNECTED,		/* client is connected */
4417926a79SDavid Howells 	RXRPC_SERVER_BOUND,		/* server local address bound */
4517926a79SDavid Howells 	RXRPC_SERVER_LISTENING,		/* server listening for connections */
4617926a79SDavid Howells 	RXRPC_CLOSE,			/* socket is being closed */
4717926a79SDavid Howells };
4817926a79SDavid Howells 
4917926a79SDavid Howells /*
5017926a79SDavid Howells  * RxRPC socket definition
5117926a79SDavid Howells  */
5217926a79SDavid Howells struct rxrpc_sock {
5317926a79SDavid Howells 	/* WARNING: sk has to be the first member */
5417926a79SDavid Howells 	struct sock		sk;
55651350d1SDavid Howells 	rxrpc_interceptor_t	interceptor;	/* kernel service Rx interceptor function */
5617926a79SDavid Howells 	struct rxrpc_local	*local;		/* local endpoint */
5717926a79SDavid Howells 	struct rxrpc_transport	*trans;		/* transport handler */
5817926a79SDavid Howells 	struct rxrpc_conn_bundle *bundle;	/* virtual connection bundle */
5917926a79SDavid Howells 	struct rxrpc_connection	*conn;		/* exclusive virtual connection */
6017926a79SDavid Howells 	struct list_head	listen_link;	/* link in the local endpoint's listen list */
6117926a79SDavid Howells 	struct list_head	secureq;	/* calls awaiting connection security clearance */
6217926a79SDavid Howells 	struct list_head	acceptq;	/* calls awaiting acceptance */
6317926a79SDavid Howells 	struct key		*key;		/* security for this socket */
6417926a79SDavid Howells 	struct key		*securities;	/* list of server security descriptors */
6517926a79SDavid Howells 	struct rb_root		calls;		/* outstanding calls on this socket */
6617926a79SDavid Howells 	unsigned long		flags;
6717926a79SDavid Howells #define RXRPC_SOCK_EXCLUSIVE_CONN	1	/* exclusive connection for a client socket */
6817926a79SDavid Howells 	rwlock_t		call_lock;	/* lock for calls */
6917926a79SDavid Howells 	u32			min_sec_level;	/* minimum security level */
7017926a79SDavid Howells #define RXRPC_SECURITY_MAX	RXRPC_SECURITY_ENCRYPT
7117926a79SDavid Howells 	struct sockaddr_rxrpc	srx;		/* local address */
7217926a79SDavid Howells 	sa_family_t		proto;		/* protocol created with */
7317926a79SDavid Howells };
7417926a79SDavid Howells 
7517926a79SDavid Howells #define rxrpc_sk(__sk) container_of((__sk), struct rxrpc_sock, sk)
7617926a79SDavid Howells 
7717926a79SDavid Howells /*
780d12f8a4SDavid Howells  * CPU-byteorder normalised Rx packet header.
790d12f8a4SDavid Howells  */
800d12f8a4SDavid Howells struct rxrpc_host_header {
810d12f8a4SDavid Howells 	u32		epoch;		/* client boot timestamp */
820d12f8a4SDavid Howells 	u32		cid;		/* connection and channel ID */
830d12f8a4SDavid Howells 	u32		callNumber;	/* call ID (0 for connection-level packets) */
840d12f8a4SDavid Howells 	u32		seq;		/* sequence number of pkt in call stream */
850d12f8a4SDavid Howells 	u32		serial;		/* serial number of pkt sent to network */
860d12f8a4SDavid Howells 	u8		type;		/* packet type */
870d12f8a4SDavid Howells 	u8		flags;		/* packet flags */
880d12f8a4SDavid Howells 	u8		userStatus;	/* app-layer defined status */
890d12f8a4SDavid Howells 	u8		securityIndex;	/* security protocol ID */
900d12f8a4SDavid Howells 	union {
910d12f8a4SDavid Howells 		u16	_rsvd;		/* reserved */
920d12f8a4SDavid Howells 		u16	cksum;		/* kerberos security checksum */
930d12f8a4SDavid Howells 	};
940d12f8a4SDavid Howells 	u16		serviceId;	/* service ID */
950d12f8a4SDavid Howells } __packed;
960d12f8a4SDavid Howells 
970d12f8a4SDavid Howells /*
9817926a79SDavid Howells  * RxRPC socket buffer private variables
9917926a79SDavid Howells  * - max 48 bytes (struct sk_buff::cb)
10017926a79SDavid Howells  */
10117926a79SDavid Howells struct rxrpc_skb_priv {
10217926a79SDavid Howells 	struct rxrpc_call	*call;		/* call with which associated */
10317926a79SDavid Howells 	unsigned long		resend_at;	/* time in jiffies at which to resend */
10417926a79SDavid Howells 	union {
10595c96174SEric Dumazet 		unsigned int	offset;		/* offset into buffer of next read */
10617926a79SDavid Howells 		int		remain;		/* amount of space remaining for next write */
10717926a79SDavid Howells 		u32		error;		/* network error code */
10817926a79SDavid Howells 		bool		need_resend;	/* T if needs resending */
10917926a79SDavid Howells 	};
11017926a79SDavid Howells 
1110d12f8a4SDavid Howells 	struct rxrpc_host_header hdr;		/* RxRPC packet header from this packet */
11217926a79SDavid Howells };
11317926a79SDavid Howells 
11417926a79SDavid Howells #define rxrpc_skb(__skb) ((struct rxrpc_skb_priv *) &(__skb)->cb)
11517926a79SDavid Howells 
11617926a79SDavid Howells enum rxrpc_command {
11717926a79SDavid Howells 	RXRPC_CMD_SEND_DATA,		/* send data message */
11817926a79SDavid Howells 	RXRPC_CMD_SEND_ABORT,		/* request abort generation */
11917926a79SDavid Howells 	RXRPC_CMD_ACCEPT,		/* [server] accept incoming call */
12017926a79SDavid Howells 	RXRPC_CMD_REJECT_BUSY,		/* [server] reject a call as busy */
12117926a79SDavid Howells };
12217926a79SDavid Howells 
12317926a79SDavid Howells /*
12417926a79SDavid Howells  * RxRPC security module interface
12517926a79SDavid Howells  */
12617926a79SDavid Howells struct rxrpc_security {
12717926a79SDavid Howells 	const char		*name;		/* name of this service */
12817926a79SDavid Howells 	u8			security_index;	/* security type provided */
12917926a79SDavid Howells 
130648af7fcSDavid Howells 	/* Initialise a security service */
131648af7fcSDavid Howells 	int (*init)(void);
132648af7fcSDavid Howells 
133648af7fcSDavid Howells 	/* Clean up a security service */
134648af7fcSDavid Howells 	void (*exit)(void);
135648af7fcSDavid Howells 
13617926a79SDavid Howells 	/* initialise a connection's security */
13717926a79SDavid Howells 	int (*init_connection_security)(struct rxrpc_connection *);
13817926a79SDavid Howells 
13917926a79SDavid Howells 	/* prime a connection's packet security */
14017926a79SDavid Howells 	void (*prime_packet_security)(struct rxrpc_connection *);
14117926a79SDavid Howells 
14217926a79SDavid Howells 	/* impose security on a packet */
14317926a79SDavid Howells 	int (*secure_packet)(const struct rxrpc_call *,
14417926a79SDavid Howells 			     struct sk_buff *,
14517926a79SDavid Howells 			     size_t,
14617926a79SDavid Howells 			     void *);
14717926a79SDavid Howells 
14817926a79SDavid Howells 	/* verify the security on a received packet */
14917926a79SDavid Howells 	int (*verify_packet)(const struct rxrpc_call *, struct sk_buff *,
15017926a79SDavid Howells 			     u32 *);
15117926a79SDavid Howells 
15217926a79SDavid Howells 	/* issue a challenge */
15317926a79SDavid Howells 	int (*issue_challenge)(struct rxrpc_connection *);
15417926a79SDavid Howells 
15517926a79SDavid Howells 	/* respond to a challenge */
15617926a79SDavid Howells 	int (*respond_to_challenge)(struct rxrpc_connection *,
15717926a79SDavid Howells 				    struct sk_buff *,
15817926a79SDavid Howells 				    u32 *);
15917926a79SDavid Howells 
16017926a79SDavid Howells 	/* verify a response */
16117926a79SDavid Howells 	int (*verify_response)(struct rxrpc_connection *,
16217926a79SDavid Howells 			       struct sk_buff *,
16317926a79SDavid Howells 			       u32 *);
16417926a79SDavid Howells 
16517926a79SDavid Howells 	/* clear connection security */
16617926a79SDavid Howells 	void (*clear)(struct rxrpc_connection *);
16717926a79SDavid Howells };
16817926a79SDavid Howells 
16917926a79SDavid Howells /*
17017926a79SDavid Howells  * RxRPC local transport endpoint definition
17117926a79SDavid Howells  * - matched by local port, address and protocol type
17217926a79SDavid Howells  */
17317926a79SDavid Howells struct rxrpc_local {
17417926a79SDavid Howells 	struct socket		*socket;	/* my UDP socket */
17517926a79SDavid Howells 	struct work_struct	destroyer;	/* endpoint destroyer */
17617926a79SDavid Howells 	struct work_struct	acceptor;	/* incoming call processor */
17717926a79SDavid Howells 	struct work_struct	rejecter;	/* packet reject writer */
17844ba0698SDavid Howells 	struct work_struct	event_processor; /* endpoint event processor */
17917926a79SDavid Howells 	struct list_head	services;	/* services listening on this endpoint */
18017926a79SDavid Howells 	struct list_head	link;		/* link in endpoint list */
18117926a79SDavid Howells 	struct rw_semaphore	defrag_sem;	/* control re-enablement of IP DF bit */
18217926a79SDavid Howells 	struct sk_buff_head	accept_queue;	/* incoming calls awaiting acceptance */
18317926a79SDavid Howells 	struct sk_buff_head	reject_queue;	/* packets awaiting rejection */
18444ba0698SDavid Howells 	struct sk_buff_head	event_queue;	/* endpoint event packets awaiting processing */
18517926a79SDavid Howells 	spinlock_t		lock;		/* access lock */
18617926a79SDavid Howells 	rwlock_t		services_lock;	/* lock for services list */
18717926a79SDavid Howells 	atomic_t		usage;
18817926a79SDavid Howells 	int			debug_id;	/* debug ID for printks */
18917926a79SDavid Howells 	volatile char		error_rcvd;	/* T if received ICMP error outstanding */
19017926a79SDavid Howells 	struct sockaddr_rxrpc	srx;		/* local address */
19117926a79SDavid Howells };
19217926a79SDavid Howells 
19317926a79SDavid Howells /*
19417926a79SDavid Howells  * RxRPC remote transport endpoint definition
19517926a79SDavid Howells  * - matched by remote port, address and protocol type
19617926a79SDavid Howells  * - holds the connection ID counter for connections between the two endpoints
19717926a79SDavid Howells  */
19817926a79SDavid Howells struct rxrpc_peer {
19917926a79SDavid Howells 	struct work_struct	destroyer;	/* peer destroyer */
20017926a79SDavid Howells 	struct list_head	link;		/* link in master peer list */
20117926a79SDavid Howells 	struct list_head	error_targets;	/* targets for net error distribution */
20217926a79SDavid Howells 	spinlock_t		lock;		/* access lock */
20317926a79SDavid Howells 	atomic_t		usage;
20495c96174SEric Dumazet 	unsigned int		if_mtu;		/* interface MTU for this peer */
20595c96174SEric Dumazet 	unsigned int		mtu;		/* network MTU for this peer */
20695c96174SEric Dumazet 	unsigned int		maxdata;	/* data size (MTU - hdrsize) */
20717926a79SDavid Howells 	unsigned short		hdrsize;	/* header size (IP + UDP + RxRPC) */
20817926a79SDavid Howells 	int			debug_id;	/* debug ID for printks */
20917926a79SDavid Howells 	int			net_error;	/* network error distributed */
21017926a79SDavid Howells 	struct sockaddr_rxrpc	srx;		/* remote address */
21117926a79SDavid Howells 
21217926a79SDavid Howells 	/* calculated RTT cache */
21317926a79SDavid Howells #define RXRPC_RTT_CACHE_SIZE 32
21417926a79SDavid Howells 	suseconds_t		rtt;		/* current RTT estimate (in uS) */
21595c96174SEric Dumazet 	unsigned int		rtt_point;	/* next entry at which to insert */
21695c96174SEric Dumazet 	unsigned int		rtt_usage;	/* amount of cache actually used */
21717926a79SDavid Howells 	suseconds_t		rtt_cache[RXRPC_RTT_CACHE_SIZE]; /* calculated RTT cache */
21817926a79SDavid Howells };
21917926a79SDavid Howells 
22017926a79SDavid Howells /*
22117926a79SDavid Howells  * RxRPC point-to-point transport / connection manager definition
22217926a79SDavid Howells  * - handles a bundle of connections between two endpoints
22317926a79SDavid Howells  * - matched by { local, peer }
22417926a79SDavid Howells  */
22517926a79SDavid Howells struct rxrpc_transport {
22617926a79SDavid Howells 	struct rxrpc_local	*local;		/* local transport endpoint */
22717926a79SDavid Howells 	struct rxrpc_peer	*peer;		/* remote transport endpoint */
22817926a79SDavid Howells 	struct work_struct	error_handler;	/* network error distributor */
22917926a79SDavid Howells 	struct rb_root		bundles;	/* client connection bundles on this transport */
23017926a79SDavid Howells 	struct rb_root		client_conns;	/* client connections on this transport */
23117926a79SDavid Howells 	struct rb_root		server_conns;	/* server connections on this transport */
23217926a79SDavid Howells 	struct list_head	link;		/* link in master session list */
23317926a79SDavid Howells 	struct sk_buff_head	error_queue;	/* error packets awaiting processing */
23422a3f9a2SKsenija Stanojevic 	unsigned long		put_time;	/* time at which to reap */
23517926a79SDavid Howells 	spinlock_t		client_lock;	/* client connection allocation lock */
23617926a79SDavid Howells 	rwlock_t		conn_lock;	/* lock for active/dead connections */
23717926a79SDavid Howells 	atomic_t		usage;
23817926a79SDavid Howells 	int			debug_id;	/* debug ID for printks */
23917926a79SDavid Howells 	unsigned int		conn_idcounter;	/* connection ID counter (client) */
24017926a79SDavid Howells };
24117926a79SDavid Howells 
24217926a79SDavid Howells /*
24317926a79SDavid Howells  * RxRPC client connection bundle
24417926a79SDavid Howells  * - matched by { transport, service_id, key }
24517926a79SDavid Howells  */
24617926a79SDavid Howells struct rxrpc_conn_bundle {
24717926a79SDavid Howells 	struct rb_node		node;		/* node in transport's lookup tree */
24817926a79SDavid Howells 	struct list_head	unused_conns;	/* unused connections in this bundle */
24917926a79SDavid Howells 	struct list_head	avail_conns;	/* available connections in this bundle */
25017926a79SDavid Howells 	struct list_head	busy_conns;	/* busy connections in this bundle */
25117926a79SDavid Howells 	struct key		*key;		/* security for this bundle */
25217926a79SDavid Howells 	wait_queue_head_t	chanwait;	/* wait for channel to become available */
25317926a79SDavid Howells 	atomic_t		usage;
25417926a79SDavid Howells 	int			debug_id;	/* debug ID for printks */
25517926a79SDavid Howells 	unsigned short		num_conns;	/* number of connections in this bundle */
2560d12f8a4SDavid Howells 	u16			service_id;	/* Service ID for this bundle */
2574e36a95eSDavid Howells 	u8			security_ix;	/* security type */
25817926a79SDavid Howells };
25917926a79SDavid Howells 
26017926a79SDavid Howells /*
26117926a79SDavid Howells  * RxRPC connection definition
26217926a79SDavid Howells  * - matched by { transport, service_id, conn_id, direction, key }
26317926a79SDavid Howells  * - each connection can only handle four simultaneous calls
26417926a79SDavid Howells  */
26517926a79SDavid Howells struct rxrpc_connection {
26617926a79SDavid Howells 	struct rxrpc_transport	*trans;		/* transport session */
26717926a79SDavid Howells 	struct rxrpc_conn_bundle *bundle;	/* connection bundle (client) */
26817926a79SDavid Howells 	struct work_struct	processor;	/* connection event processor */
26917926a79SDavid Howells 	struct rb_node		node;		/* node in transport's lookup tree */
27017926a79SDavid Howells 	struct list_head	link;		/* link in master connection list */
27117926a79SDavid Howells 	struct list_head	bundle_link;	/* link in bundle */
27217926a79SDavid Howells 	struct rb_root		calls;		/* calls on this connection */
27317926a79SDavid Howells 	struct sk_buff_head	rx_queue;	/* received conn-level packets */
27417926a79SDavid Howells 	struct rxrpc_call	*channels[RXRPC_MAXCALLS]; /* channels (active calls) */
275648af7fcSDavid Howells 	const struct rxrpc_security *security;	/* applied security module */
27617926a79SDavid Howells 	struct key		*key;		/* security for this connection (client) */
27717926a79SDavid Howells 	struct key		*server_key;	/* security for this service */
2781afe593bSHerbert Xu 	struct crypto_skcipher	*cipher;	/* encryption handle */
27917926a79SDavid Howells 	struct rxrpc_crypt	csum_iv;	/* packet checksum base */
28017926a79SDavid Howells 	unsigned long		events;
28117926a79SDavid Howells #define RXRPC_CONN_CHALLENGE	0		/* send challenge packet */
28222a3f9a2SKsenija Stanojevic 	unsigned long		put_time;	/* time at which to reap */
28317926a79SDavid Howells 	rwlock_t		lock;		/* access lock */
28417926a79SDavid Howells 	spinlock_t		state_lock;	/* state-change lock */
28517926a79SDavid Howells 	atomic_t		usage;
28617926a79SDavid Howells 	enum {					/* current state of connection */
28717926a79SDavid Howells 		RXRPC_CONN_UNUSED,		/* - connection not yet attempted */
28817926a79SDavid Howells 		RXRPC_CONN_CLIENT,		/* - client connection */
28917926a79SDavid Howells 		RXRPC_CONN_SERVER_UNSECURED,	/* - server unsecured connection */
29017926a79SDavid Howells 		RXRPC_CONN_SERVER_CHALLENGING,	/* - server challenging for security */
29117926a79SDavid Howells 		RXRPC_CONN_SERVER,		/* - server secured connection */
29217926a79SDavid Howells 		RXRPC_CONN_REMOTELY_ABORTED,	/* - conn aborted by peer */
29317926a79SDavid Howells 		RXRPC_CONN_LOCALLY_ABORTED,	/* - conn aborted locally */
29417926a79SDavid Howells 		RXRPC_CONN_NETWORK_ERROR,	/* - conn terminated by network error */
29517926a79SDavid Howells 	} state;
296dc44b3a0SDavid Howells 	u32			local_abort;	/* local abort code */
297dc44b3a0SDavid Howells 	u32			remote_abort;	/* remote abort code */
298dc44b3a0SDavid Howells 	int			error;		/* local error incurred */
29917926a79SDavid Howells 	int			debug_id;	/* debug ID for printks */
30095c96174SEric Dumazet 	unsigned int		call_counter;	/* call ID counter */
30117926a79SDavid Howells 	atomic_t		serial;		/* packet serial number counter */
30217926a79SDavid Howells 	atomic_t		hi_serial;	/* highest serial number received */
30317926a79SDavid Howells 	u8			avail_calls;	/* number of calls available */
30417926a79SDavid Howells 	u8			size_align;	/* data size alignment (for security) */
30517926a79SDavid Howells 	u8			header_size;	/* rxrpc + security header size */
30617926a79SDavid Howells 	u8			security_size;	/* security header size */
30717926a79SDavid Howells 	u32			security_level;	/* security level negotiated */
30817926a79SDavid Howells 	u32			security_nonce;	/* response re-use preventer */
3090d12f8a4SDavid Howells 	u32			epoch;		/* epoch of this connection */
3100d12f8a4SDavid Howells 	u32			cid;		/* connection ID */
3110d12f8a4SDavid Howells 	u16			service_id;	/* service ID for this connection */
31217926a79SDavid Howells 	u8			security_ix;	/* security type */
31317926a79SDavid Howells 	u8			in_clientflag;	/* RXRPC_CLIENT_INITIATED if we are server */
31417926a79SDavid Howells 	u8			out_clientflag;	/* RXRPC_CLIENT_INITIATED if we are client */
31517926a79SDavid Howells };
31617926a79SDavid Howells 
31717926a79SDavid Howells /*
3185b8848d1SDavid Howells  * Flags in call->flags.
3195b8848d1SDavid Howells  */
3205b8848d1SDavid Howells enum rxrpc_call_flag {
3215b8848d1SDavid Howells 	RXRPC_CALL_RELEASED,		/* call has been released - no more message to userspace */
3225b8848d1SDavid Howells 	RXRPC_CALL_TERMINAL_MSG,	/* call has given the socket its final message */
3235b8848d1SDavid Howells 	RXRPC_CALL_RCVD_LAST,		/* all packets received */
3245b8848d1SDavid Howells 	RXRPC_CALL_RUN_RTIMER,		/* Tx resend timer started */
3255b8848d1SDavid Howells 	RXRPC_CALL_TX_SOFT_ACK,		/* sent some soft ACKs */
3265b8848d1SDavid Howells 	RXRPC_CALL_PROC_BUSY,		/* the processor is busy */
3275b8848d1SDavid Howells 	RXRPC_CALL_INIT_ACCEPT,		/* acceptance was initiated */
3285b8848d1SDavid Howells 	RXRPC_CALL_HAS_USERID,		/* has a user ID attached */
3295b8848d1SDavid Howells 	RXRPC_CALL_EXPECT_OOS,		/* expect out of sequence packets */
3305b8848d1SDavid Howells };
3315b8848d1SDavid Howells 
3325b8848d1SDavid Howells /*
3335b8848d1SDavid Howells  * Events that can be raised on a call.
3345b8848d1SDavid Howells  */
3355b8848d1SDavid Howells enum rxrpc_call_event {
3364c198ad1SDavid Howells 	RXRPC_CALL_EV_RCVD_ACKALL,	/* ACKALL or reply received */
3374c198ad1SDavid Howells 	RXRPC_CALL_EV_RCVD_BUSY,	/* busy packet received */
3384c198ad1SDavid Howells 	RXRPC_CALL_EV_RCVD_ABORT,	/* abort packet received */
3394c198ad1SDavid Howells 	RXRPC_CALL_EV_RCVD_ERROR,	/* network error received */
3404c198ad1SDavid Howells 	RXRPC_CALL_EV_ACK_FINAL,	/* need to generate final ACK (and release call) */
3414c198ad1SDavid Howells 	RXRPC_CALL_EV_ACK,		/* need to generate ACK */
3424c198ad1SDavid Howells 	RXRPC_CALL_EV_REJECT_BUSY,	/* need to generate busy message */
3434c198ad1SDavid Howells 	RXRPC_CALL_EV_ABORT,		/* need to generate abort */
3444c198ad1SDavid Howells 	RXRPC_CALL_EV_CONN_ABORT,	/* local connection abort generated */
3454c198ad1SDavid Howells 	RXRPC_CALL_EV_RESEND_TIMER,	/* Tx resend timer expired */
3464c198ad1SDavid Howells 	RXRPC_CALL_EV_RESEND,		/* Tx resend required */
3474c198ad1SDavid Howells 	RXRPC_CALL_EV_DRAIN_RX_OOS,	/* drain the Rx out of sequence queue */
3484c198ad1SDavid Howells 	RXRPC_CALL_EV_LIFE_TIMER,	/* call's lifetimer ran out */
3494c198ad1SDavid Howells 	RXRPC_CALL_EV_ACCEPTED,		/* incoming call accepted by userspace app */
3504c198ad1SDavid Howells 	RXRPC_CALL_EV_SECURED,		/* incoming call's connection is now secure */
3514c198ad1SDavid Howells 	RXRPC_CALL_EV_POST_ACCEPT,	/* need to post an "accept?" message to the app */
3524c198ad1SDavid Howells 	RXRPC_CALL_EV_RELEASE,		/* need to release the call's resources */
3535b8848d1SDavid Howells };
3545b8848d1SDavid Howells 
3555b8848d1SDavid Howells /*
3565b8848d1SDavid Howells  * The states that a call can be in.
3575b8848d1SDavid Howells  */
3585b8848d1SDavid Howells enum rxrpc_call_state {
3595b8848d1SDavid Howells 	RXRPC_CALL_CLIENT_SEND_REQUEST,	/* - client sending request phase */
3605b8848d1SDavid Howells 	RXRPC_CALL_CLIENT_AWAIT_REPLY,	/* - client awaiting reply */
3615b8848d1SDavid Howells 	RXRPC_CALL_CLIENT_RECV_REPLY,	/* - client receiving reply phase */
3625b8848d1SDavid Howells 	RXRPC_CALL_CLIENT_FINAL_ACK,	/* - client sending final ACK phase */
3635b8848d1SDavid Howells 	RXRPC_CALL_SERVER_SECURING,	/* - server securing request connection */
3645b8848d1SDavid Howells 	RXRPC_CALL_SERVER_ACCEPTING,	/* - server accepting request */
3655b8848d1SDavid Howells 	RXRPC_CALL_SERVER_RECV_REQUEST,	/* - server receiving request */
3665b8848d1SDavid Howells 	RXRPC_CALL_SERVER_ACK_REQUEST,	/* - server pending ACK of request */
3675b8848d1SDavid Howells 	RXRPC_CALL_SERVER_SEND_REPLY,	/* - server sending reply */
3685b8848d1SDavid Howells 	RXRPC_CALL_SERVER_AWAIT_ACK,	/* - server awaiting final ACK */
3695b8848d1SDavid Howells 	RXRPC_CALL_COMPLETE,		/* - call completed */
3705b8848d1SDavid Howells 	RXRPC_CALL_SERVER_BUSY,		/* - call rejected by busy server */
3715b8848d1SDavid Howells 	RXRPC_CALL_REMOTELY_ABORTED,	/* - call aborted by peer */
3725b8848d1SDavid Howells 	RXRPC_CALL_LOCALLY_ABORTED,	/* - call aborted locally on error or close */
3735b8848d1SDavid Howells 	RXRPC_CALL_NETWORK_ERROR,	/* - call terminated by network error */
3745b8848d1SDavid Howells 	RXRPC_CALL_DEAD,		/* - call is dead */
3755b8848d1SDavid Howells 	NR__RXRPC_CALL_STATES
3765b8848d1SDavid Howells };
3775b8848d1SDavid Howells 
3785b8848d1SDavid Howells /*
37917926a79SDavid Howells  * RxRPC call definition
38017926a79SDavid Howells  * - matched by { connection, call_id }
38117926a79SDavid Howells  */
38217926a79SDavid Howells struct rxrpc_call {
38317926a79SDavid Howells 	struct rxrpc_connection	*conn;		/* connection carrying call */
38417926a79SDavid Howells 	struct rxrpc_sock	*socket;	/* socket responsible */
38517926a79SDavid Howells 	struct timer_list	lifetimer;	/* lifetime remaining on call */
38617926a79SDavid Howells 	struct timer_list	deadspan;	/* reap timer for re-ACK'ing, etc  */
38717926a79SDavid Howells 	struct timer_list	ack_timer;	/* ACK generation timer */
38817926a79SDavid Howells 	struct timer_list	resend_timer;	/* Tx resend timer */
38917926a79SDavid Howells 	struct work_struct	destroyer;	/* call destroyer */
39017926a79SDavid Howells 	struct work_struct	processor;	/* packet processor and ACK generator */
39117926a79SDavid Howells 	struct list_head	link;		/* link in master call list */
39217926a79SDavid Howells 	struct list_head	error_link;	/* link in error distribution list */
39317926a79SDavid Howells 	struct list_head	accept_link;	/* calls awaiting acceptance */
39417926a79SDavid Howells 	struct rb_node		sock_node;	/* node in socket call tree */
39517926a79SDavid Howells 	struct rb_node		conn_node;	/* node in connection call tree */
39617926a79SDavid Howells 	struct sk_buff_head	rx_queue;	/* received packets */
39717926a79SDavid Howells 	struct sk_buff_head	rx_oos_queue;	/* packets received out of sequence */
39817926a79SDavid Howells 	struct sk_buff		*tx_pending;	/* Tx socket buffer being filled */
39917926a79SDavid Howells 	wait_queue_head_t	tx_waitq;	/* wait for Tx window space to become available */
40017926a79SDavid Howells 	unsigned long		user_call_ID;	/* user-defined call ID */
40117926a79SDavid Howells 	unsigned long		creation_jif;	/* time of call creation */
40217926a79SDavid Howells 	unsigned long		flags;
40317926a79SDavid Howells 	unsigned long		events;
40417926a79SDavid Howells 	spinlock_t		lock;
40517926a79SDavid Howells 	rwlock_t		state_lock;	/* lock for state transition */
40617926a79SDavid Howells 	atomic_t		usage;
40717926a79SDavid Howells 	atomic_t		sequence;	/* Tx data packet sequence counter */
408dc44b3a0SDavid Howells 	u32			local_abort;	/* local abort code */
409dc44b3a0SDavid Howells 	u32			remote_abort;	/* remote abort code */
410dc44b3a0SDavid Howells 	int			error;		/* local error incurred */
4115b8848d1SDavid Howells 	enum rxrpc_call_state	state : 8;	/* current state of call */
41217926a79SDavid Howells 	int			debug_id;	/* debug ID for printks */
41317926a79SDavid Howells 	u8			channel;	/* connection channel occupied by this call */
41417926a79SDavid Howells 
41517926a79SDavid Howells 	/* transmission-phase ACK management */
4164e36a95eSDavid Howells 	u8			acks_head;	/* offset into window of first entry */
4174e36a95eSDavid Howells 	u8			acks_tail;	/* offset into window of last entry */
4184e36a95eSDavid Howells 	u8			acks_winsz;	/* size of un-ACK'd window */
4194e36a95eSDavid Howells 	u8			acks_unacked;	/* lowest unacked packet in last ACK received */
42017926a79SDavid Howells 	int			acks_latest;	/* serial number of latest ACK received */
42117926a79SDavid Howells 	rxrpc_seq_t		acks_hard;	/* highest definitively ACK'd msg seq */
42217926a79SDavid Howells 	unsigned long		*acks_window;	/* sent packet window
42317926a79SDavid Howells 						 * - elements are pointers with LSB set if ACK'd
42417926a79SDavid Howells 						 */
42517926a79SDavid Howells 
42617926a79SDavid Howells 	/* receive-phase ACK management */
42717926a79SDavid Howells 	rxrpc_seq_t		rx_data_expect;	/* next data seq ID expected to be received */
42817926a79SDavid Howells 	rxrpc_seq_t		rx_data_post;	/* next data seq ID expected to be posted */
42917926a79SDavid Howells 	rxrpc_seq_t		rx_data_recv;	/* last data seq ID encountered by recvmsg */
43017926a79SDavid Howells 	rxrpc_seq_t		rx_data_eaten;	/* last data seq ID consumed by recvmsg */
43117926a79SDavid Howells 	rxrpc_seq_t		rx_first_oos;	/* first packet in rx_oos_queue (or 0) */
43217926a79SDavid Howells 	rxrpc_seq_t		ackr_win_top;	/* top of ACK window (rx_data_eaten is bottom) */
4330d12f8a4SDavid Howells 	rxrpc_seq_t		ackr_prev_seq;	/* previous sequence number received */
4344e36a95eSDavid Howells 	u8			ackr_reason;	/* reason to ACK */
4350d12f8a4SDavid Howells 	rxrpc_serial_t		ackr_serial;	/* serial of packet being ACK'd */
43617926a79SDavid Howells 	atomic_t		ackr_not_idle;	/* number of packets in Rx queue */
43717926a79SDavid Howells 
43817926a79SDavid Howells 	/* received packet records, 1 bit per record */
43917926a79SDavid Howells #define RXRPC_ACKR_WINDOW_ASZ DIV_ROUND_UP(RXRPC_MAXACKS, BITS_PER_LONG)
44017926a79SDavid Howells 	unsigned long		ackr_window[RXRPC_ACKR_WINDOW_ASZ + 1];
44117926a79SDavid Howells 
4427727640cSTim Smith 	struct hlist_node	hash_node;
4437727640cSTim Smith 	unsigned long		hash_key;	/* Full hash key */
4447727640cSTim Smith 	u8			in_clientflag;	/* Copy of conn->in_clientflag for hashing */
4457727640cSTim Smith 	struct rxrpc_local	*local;		/* Local endpoint. Used for hashing. */
4467727640cSTim Smith 	sa_family_t		proto;		/* Frame protocol */
4470d12f8a4SDavid Howells 	u32			call_id;	/* call ID on connection  */
4480d12f8a4SDavid Howells 	u32			cid;		/* connection ID plus channel index */
4490d12f8a4SDavid Howells 	u32			epoch;		/* epoch of this connection */
4500d12f8a4SDavid Howells 	u16			service_id;	/* service ID */
4517727640cSTim Smith 	union {					/* Peer IP address for hashing */
4527727640cSTim Smith 		__be32	ipv4_addr;
4537727640cSTim Smith 		__u8	ipv6_addr[16];		/* Anticipates eventual IPv6 support */
4547727640cSTim Smith 	} peer_ip;
45517926a79SDavid Howells };
45617926a79SDavid Howells 
45717926a79SDavid Howells /*
45817926a79SDavid Howells  * locally abort an RxRPC call
45917926a79SDavid Howells  */
46017926a79SDavid Howells static inline void rxrpc_abort_call(struct rxrpc_call *call, u32 abort_code)
46117926a79SDavid Howells {
46217926a79SDavid Howells 	write_lock_bh(&call->state_lock);
46317926a79SDavid Howells 	if (call->state < RXRPC_CALL_COMPLETE) {
464dc44b3a0SDavid Howells 		call->local_abort = abort_code;
46517926a79SDavid Howells 		call->state = RXRPC_CALL_LOCALLY_ABORTED;
4664c198ad1SDavid Howells 		set_bit(RXRPC_CALL_EV_ABORT, &call->events);
46717926a79SDavid Howells 	}
46817926a79SDavid Howells 	write_unlock_bh(&call->state_lock);
46917926a79SDavid Howells }
47017926a79SDavid Howells 
47117926a79SDavid Howells /*
472651350d1SDavid Howells  * af_rxrpc.c
47317926a79SDavid Howells  */
474651350d1SDavid Howells extern atomic_t rxrpc_n_skbs;
4750d12f8a4SDavid Howells extern u32 rxrpc_epoch;
476651350d1SDavid Howells extern atomic_t rxrpc_debug_id;
477651350d1SDavid Howells extern struct workqueue_struct *rxrpc_workqueue;
47817926a79SDavid Howells 
47917926a79SDavid Howells /*
48017926a79SDavid Howells  * ar-accept.c
48117926a79SDavid Howells  */
482c1b1203dSJoe Perches void rxrpc_accept_incoming_calls(struct work_struct *);
483c1b1203dSJoe Perches struct rxrpc_call *rxrpc_accept_call(struct rxrpc_sock *, unsigned long);
484c1b1203dSJoe Perches int rxrpc_reject_call(struct rxrpc_sock *);
48517926a79SDavid Howells 
48617926a79SDavid Howells /*
48717926a79SDavid Howells  * ar-ack.c
48817926a79SDavid Howells  */
4890d12f8a4SDavid Howells void __rxrpc_propose_ACK(struct rxrpc_call *, u8, u32, bool);
4900d12f8a4SDavid Howells void rxrpc_propose_ACK(struct rxrpc_call *, u8, u32, bool);
491c1b1203dSJoe Perches void rxrpc_process_call(struct work_struct *);
49217926a79SDavid Howells 
49317926a79SDavid Howells /*
49417926a79SDavid Howells  * ar-call.c
49517926a79SDavid Howells  */
496dad8aff7SDavid Howells extern unsigned int rxrpc_max_call_lifetime;
497dad8aff7SDavid Howells extern unsigned int rxrpc_dead_call_expiry;
49817926a79SDavid Howells extern struct kmem_cache *rxrpc_call_jar;
49917926a79SDavid Howells extern struct list_head rxrpc_calls;
50017926a79SDavid Howells extern rwlock_t rxrpc_call_lock;
50117926a79SDavid Howells 
5020d12f8a4SDavid Howells struct rxrpc_call *rxrpc_find_call_hash(struct rxrpc_host_header *,
5030d12f8a4SDavid Howells 					void *, sa_family_t, const void *);
504c1b1203dSJoe Perches struct rxrpc_call *rxrpc_get_client_call(struct rxrpc_sock *,
50517926a79SDavid Howells 					 struct rxrpc_transport *,
50617926a79SDavid Howells 					 struct rxrpc_conn_bundle *,
50717926a79SDavid Howells 					 unsigned long, int, gfp_t);
508c1b1203dSJoe Perches struct rxrpc_call *rxrpc_incoming_call(struct rxrpc_sock *,
50917926a79SDavid Howells 				       struct rxrpc_connection *,
510843099caSDavid Howells 				       struct rxrpc_host_header *);
511c1b1203dSJoe Perches struct rxrpc_call *rxrpc_find_server_call(struct rxrpc_sock *, unsigned long);
512c1b1203dSJoe Perches void rxrpc_release_call(struct rxrpc_call *);
513c1b1203dSJoe Perches void rxrpc_release_calls_on_socket(struct rxrpc_sock *);
514c1b1203dSJoe Perches void __rxrpc_put_call(struct rxrpc_call *);
515c1b1203dSJoe Perches void __exit rxrpc_destroy_all_calls(void);
51617926a79SDavid Howells 
51717926a79SDavid Howells /*
51817926a79SDavid Howells  * ar-connection.c
51917926a79SDavid Howells  */
520dad8aff7SDavid Howells extern unsigned int rxrpc_connection_expiry;
52117926a79SDavid Howells extern struct list_head rxrpc_connections;
52217926a79SDavid Howells extern rwlock_t rxrpc_connection_lock;
52317926a79SDavid Howells 
524c1b1203dSJoe Perches struct rxrpc_conn_bundle *rxrpc_get_bundle(struct rxrpc_sock *,
52517926a79SDavid Howells 					   struct rxrpc_transport *,
5260d12f8a4SDavid Howells 					   struct key *, u16, gfp_t);
527c1b1203dSJoe Perches void rxrpc_put_bundle(struct rxrpc_transport *, struct rxrpc_conn_bundle *);
528c1b1203dSJoe Perches int rxrpc_connect_call(struct rxrpc_sock *, struct rxrpc_transport *,
529c1b1203dSJoe Perches 		       struct rxrpc_conn_bundle *, struct rxrpc_call *, gfp_t);
530c1b1203dSJoe Perches void rxrpc_put_connection(struct rxrpc_connection *);
531c1b1203dSJoe Perches void __exit rxrpc_destroy_all_connections(void);
532c1b1203dSJoe Perches struct rxrpc_connection *rxrpc_find_connection(struct rxrpc_transport *,
5330d12f8a4SDavid Howells 					       struct rxrpc_host_header *);
53417926a79SDavid Howells extern struct rxrpc_connection *
535843099caSDavid Howells rxrpc_incoming_connection(struct rxrpc_transport *, struct rxrpc_host_header *);
53617926a79SDavid Howells 
53717926a79SDavid Howells /*
53817926a79SDavid Howells  * ar-connevent.c
53917926a79SDavid Howells  */
540c1b1203dSJoe Perches void rxrpc_process_connection(struct work_struct *);
541c1b1203dSJoe Perches void rxrpc_reject_packet(struct rxrpc_local *, struct sk_buff *);
542c1b1203dSJoe Perches void rxrpc_reject_packets(struct work_struct *);
54317926a79SDavid Howells 
54417926a79SDavid Howells /*
54517926a79SDavid Howells  * ar-error.c
54617926a79SDavid Howells  */
547c1b1203dSJoe Perches void rxrpc_UDP_error_report(struct sock *);
548c1b1203dSJoe Perches void rxrpc_UDP_error_handler(struct work_struct *);
54917926a79SDavid Howells 
55017926a79SDavid Howells /*
55117926a79SDavid Howells  * ar-input.c
55217926a79SDavid Howells  */
553676d2369SDavid S. Miller void rxrpc_data_ready(struct sock *);
554c1b1203dSJoe Perches int rxrpc_queue_rcv_skb(struct rxrpc_call *, struct sk_buff *, bool, bool);
555c1b1203dSJoe Perches void rxrpc_fast_process_packet(struct rxrpc_call *, struct sk_buff *);
55617926a79SDavid Howells 
55717926a79SDavid Howells /*
55817926a79SDavid Howells  * ar-local.c
55917926a79SDavid Howells  */
56017926a79SDavid Howells extern rwlock_t rxrpc_local_lock;
5615873c083SDavid Howells 
562c1b1203dSJoe Perches struct rxrpc_local *rxrpc_lookup_local(struct sockaddr_rxrpc *);
563c1b1203dSJoe Perches void rxrpc_put_local(struct rxrpc_local *);
564c1b1203dSJoe Perches void __exit rxrpc_destroy_all_locals(void);
56517926a79SDavid Howells 
56617926a79SDavid Howells /*
56717926a79SDavid Howells  * ar-key.c
56817926a79SDavid Howells  */
56917926a79SDavid Howells extern struct key_type key_type_rxrpc;
57017926a79SDavid Howells extern struct key_type key_type_rxrpc_s;
57117926a79SDavid Howells 
572c1b1203dSJoe Perches int rxrpc_request_key(struct rxrpc_sock *, char __user *, int);
573c1b1203dSJoe Perches int rxrpc_server_keyring(struct rxrpc_sock *, char __user *, int);
574c1b1203dSJoe Perches int rxrpc_get_server_data_key(struct rxrpc_connection *, const void *, time_t,
575c1b1203dSJoe Perches 			      u32);
57617926a79SDavid Howells 
57717926a79SDavid Howells /*
57817926a79SDavid Howells  * ar-output.c
57917926a79SDavid Howells  */
580dad8aff7SDavid Howells extern unsigned int rxrpc_resend_timeout;
58117926a79SDavid Howells 
582c1b1203dSJoe Perches int rxrpc_send_packet(struct rxrpc_transport *, struct sk_buff *);
5831b784140SYing Xue int rxrpc_client_sendmsg(struct rxrpc_sock *, struct rxrpc_transport *,
5841b784140SYing Xue 			 struct msghdr *, size_t);
5851b784140SYing Xue int rxrpc_server_sendmsg(struct rxrpc_sock *, struct msghdr *, size_t);
58617926a79SDavid Howells 
58717926a79SDavid Howells /*
58817926a79SDavid Howells  * ar-peer.c
58917926a79SDavid Howells  */
590c1b1203dSJoe Perches struct rxrpc_peer *rxrpc_get_peer(struct sockaddr_rxrpc *, gfp_t);
591c1b1203dSJoe Perches void rxrpc_put_peer(struct rxrpc_peer *);
592c1b1203dSJoe Perches struct rxrpc_peer *rxrpc_find_peer(struct rxrpc_local *, __be32, __be16);
593c1b1203dSJoe Perches void __exit rxrpc_destroy_all_peers(void);
59417926a79SDavid Howells 
59517926a79SDavid Howells /*
59617926a79SDavid Howells  * ar-proc.c
59717926a79SDavid Howells  */
598036c2e27SJan Engelhardt extern const char *const rxrpc_call_states[];
599036c2e27SJan Engelhardt extern const struct file_operations rxrpc_call_seq_fops;
600036c2e27SJan Engelhardt extern const struct file_operations rxrpc_connection_seq_fops;
60117926a79SDavid Howells 
60217926a79SDavid Howells /*
60317926a79SDavid Howells  * ar-recvmsg.c
60417926a79SDavid Howells  */
605c1b1203dSJoe Perches void rxrpc_remove_user_ID(struct rxrpc_sock *, struct rxrpc_call *);
6061b784140SYing Xue int rxrpc_recvmsg(struct socket *, struct msghdr *, size_t, int);
60717926a79SDavid Howells 
60817926a79SDavid Howells /*
60917926a79SDavid Howells  * ar-security.c
61017926a79SDavid Howells  */
611648af7fcSDavid Howells int __init rxrpc_init_security(void);
612648af7fcSDavid Howells void rxrpc_exit_security(void);
613c1b1203dSJoe Perches int rxrpc_init_client_conn_security(struct rxrpc_connection *);
614c1b1203dSJoe Perches int rxrpc_init_server_conn_security(struct rxrpc_connection *);
615c1b1203dSJoe Perches int rxrpc_secure_packet(const struct rxrpc_call *, struct sk_buff *, size_t,
616c1b1203dSJoe Perches 			void *);
617c1b1203dSJoe Perches int rxrpc_verify_packet(const struct rxrpc_call *, struct sk_buff *, u32 *);
618c1b1203dSJoe Perches void rxrpc_clear_conn_security(struct rxrpc_connection *);
61917926a79SDavid Howells 
62017926a79SDavid Howells /*
62117926a79SDavid Howells  * ar-skbuff.c
62217926a79SDavid Howells  */
623c1b1203dSJoe Perches void rxrpc_packet_destructor(struct sk_buff *);
62417926a79SDavid Howells 
62517926a79SDavid Howells /*
62617926a79SDavid Howells  * ar-transport.c
62717926a79SDavid Howells  */
628dad8aff7SDavid Howells extern unsigned int rxrpc_transport_expiry;
6295873c083SDavid Howells 
630c1b1203dSJoe Perches struct rxrpc_transport *rxrpc_get_transport(struct rxrpc_local *,
631c1b1203dSJoe Perches 					    struct rxrpc_peer *, gfp_t);
632c1b1203dSJoe Perches void rxrpc_put_transport(struct rxrpc_transport *);
633c1b1203dSJoe Perches void __exit rxrpc_destroy_all_transports(void);
634c1b1203dSJoe Perches struct rxrpc_transport *rxrpc_find_transport(struct rxrpc_local *,
63517926a79SDavid Howells 					     struct rxrpc_peer *);
63617926a79SDavid Howells 
63717926a79SDavid Howells /*
6388e688d9cSDavid Howells  * misc.c
6398e688d9cSDavid Howells  */
6408e688d9cSDavid Howells extern unsigned int rxrpc_requested_ack_delay;
6418e688d9cSDavid Howells extern unsigned int rxrpc_soft_ack_delay;
6428e688d9cSDavid Howells extern unsigned int rxrpc_idle_ack_delay;
6438e688d9cSDavid Howells extern unsigned int rxrpc_rx_window_size;
6448e688d9cSDavid Howells extern unsigned int rxrpc_rx_mtu;
6458e688d9cSDavid Howells extern unsigned int rxrpc_rx_jumbo_max;
6468e688d9cSDavid Howells 
6475b3e87f1SDavid Howells extern const char *const rxrpc_pkts[];
6488e688d9cSDavid Howells extern const s8 rxrpc_ack_priority[];
6498e688d9cSDavid Howells 
6508e688d9cSDavid Howells extern const char *rxrpc_acks(u8 reason);
6518e688d9cSDavid Howells 
6528e688d9cSDavid Howells /*
653648af7fcSDavid Howells  * rxkad.c
654648af7fcSDavid Howells  */
655648af7fcSDavid Howells #ifdef CONFIG_RXKAD
656648af7fcSDavid Howells extern const struct rxrpc_security rxkad;
657648af7fcSDavid Howells #endif
658648af7fcSDavid Howells 
659648af7fcSDavid Howells /*
6605873c083SDavid Howells  * sysctl.c
6615873c083SDavid Howells  */
6625873c083SDavid Howells #ifdef CONFIG_SYSCTL
6635873c083SDavid Howells extern int __init rxrpc_sysctl_init(void);
6645873c083SDavid Howells extern void rxrpc_sysctl_exit(void);
6655873c083SDavid Howells #else
6665873c083SDavid Howells static inline int __init rxrpc_sysctl_init(void) { return 0; }
6675873c083SDavid Howells static inline void rxrpc_sysctl_exit(void) {}
6685873c083SDavid Howells #endif
6695873c083SDavid Howells 
6705873c083SDavid Howells /*
67117926a79SDavid Howells  * debug tracing
67217926a79SDavid Howells  */
67395c96174SEric Dumazet extern unsigned int rxrpc_debug;
67417926a79SDavid Howells 
67517926a79SDavid Howells #define dbgprintk(FMT,...) \
6769f389f4bSSven Schnelle 	printk("[%-6.6s] "FMT"\n", current->comm ,##__VA_ARGS__)
67717926a79SDavid Howells 
6780dc47877SHarvey Harrison #define kenter(FMT,...)	dbgprintk("==> %s("FMT")",__func__ ,##__VA_ARGS__)
6790dc47877SHarvey Harrison #define kleave(FMT,...)	dbgprintk("<== %s()"FMT"",__func__ ,##__VA_ARGS__)
68017926a79SDavid Howells #define kdebug(FMT,...)	dbgprintk("    "FMT ,##__VA_ARGS__)
68117926a79SDavid Howells #define kproto(FMT,...)	dbgprintk("### "FMT ,##__VA_ARGS__)
68217926a79SDavid Howells #define knet(FMT,...)	dbgprintk("@@@ "FMT ,##__VA_ARGS__)
68317926a79SDavid Howells 
68417926a79SDavid Howells 
68517926a79SDavid Howells #if defined(__KDEBUG)
68617926a79SDavid Howells #define _enter(FMT,...)	kenter(FMT,##__VA_ARGS__)
68717926a79SDavid Howells #define _leave(FMT,...)	kleave(FMT,##__VA_ARGS__)
68817926a79SDavid Howells #define _debug(FMT,...)	kdebug(FMT,##__VA_ARGS__)
68917926a79SDavid Howells #define _proto(FMT,...)	kproto(FMT,##__VA_ARGS__)
69017926a79SDavid Howells #define _net(FMT,...)	knet(FMT,##__VA_ARGS__)
69117926a79SDavid Howells 
69217926a79SDavid Howells #elif defined(CONFIG_AF_RXRPC_DEBUG)
69317926a79SDavid Howells #define RXRPC_DEBUG_KENTER	0x01
69417926a79SDavid Howells #define RXRPC_DEBUG_KLEAVE	0x02
69517926a79SDavid Howells #define RXRPC_DEBUG_KDEBUG	0x04
69617926a79SDavid Howells #define RXRPC_DEBUG_KPROTO	0x08
69717926a79SDavid Howells #define RXRPC_DEBUG_KNET	0x10
69817926a79SDavid Howells 
69917926a79SDavid Howells #define _enter(FMT,...)					\
70017926a79SDavid Howells do {							\
70117926a79SDavid Howells 	if (unlikely(rxrpc_debug & RXRPC_DEBUG_KENTER))	\
70217926a79SDavid Howells 		kenter(FMT,##__VA_ARGS__);		\
70317926a79SDavid Howells } while (0)
70417926a79SDavid Howells 
70517926a79SDavid Howells #define _leave(FMT,...)					\
70617926a79SDavid Howells do {							\
70717926a79SDavid Howells 	if (unlikely(rxrpc_debug & RXRPC_DEBUG_KLEAVE))	\
70817926a79SDavid Howells 		kleave(FMT,##__VA_ARGS__);		\
70917926a79SDavid Howells } while (0)
71017926a79SDavid Howells 
71117926a79SDavid Howells #define _debug(FMT,...)					\
71217926a79SDavid Howells do {							\
71317926a79SDavid Howells 	if (unlikely(rxrpc_debug & RXRPC_DEBUG_KDEBUG))	\
71417926a79SDavid Howells 		kdebug(FMT,##__VA_ARGS__);		\
71517926a79SDavid Howells } while (0)
71617926a79SDavid Howells 
71717926a79SDavid Howells #define _proto(FMT,...)					\
71817926a79SDavid Howells do {							\
71917926a79SDavid Howells 	if (unlikely(rxrpc_debug & RXRPC_DEBUG_KPROTO))	\
72017926a79SDavid Howells 		kproto(FMT,##__VA_ARGS__);		\
72117926a79SDavid Howells } while (0)
72217926a79SDavid Howells 
72317926a79SDavid Howells #define _net(FMT,...)					\
72417926a79SDavid Howells do {							\
72517926a79SDavid Howells 	if (unlikely(rxrpc_debug & RXRPC_DEBUG_KNET))	\
72617926a79SDavid Howells 		knet(FMT,##__VA_ARGS__);		\
72717926a79SDavid Howells } while (0)
72817926a79SDavid Howells 
72917926a79SDavid Howells #else
73012fdff3fSDavid Howells #define _enter(FMT,...)	no_printk("==> %s("FMT")",__func__ ,##__VA_ARGS__)
73112fdff3fSDavid Howells #define _leave(FMT,...)	no_printk("<== %s()"FMT"",__func__ ,##__VA_ARGS__)
73212fdff3fSDavid Howells #define _debug(FMT,...)	no_printk("    "FMT ,##__VA_ARGS__)
73312fdff3fSDavid Howells #define _proto(FMT,...)	no_printk("### "FMT ,##__VA_ARGS__)
73412fdff3fSDavid Howells #define _net(FMT,...)	no_printk("@@@ "FMT ,##__VA_ARGS__)
73517926a79SDavid Howells #endif
73617926a79SDavid Howells 
73717926a79SDavid Howells /*
73817926a79SDavid Howells  * debug assertion checking
73917926a79SDavid Howells  */
74017926a79SDavid Howells #if 1 // defined(__KDEBUGALL)
74117926a79SDavid Howells 
74217926a79SDavid Howells #define ASSERT(X)						\
74317926a79SDavid Howells do {								\
74417926a79SDavid Howells 	if (unlikely(!(X))) {					\
74517926a79SDavid Howells 		printk(KERN_ERR "\n");				\
74617926a79SDavid Howells 		printk(KERN_ERR "RxRPC: Assertion failed\n");	\
74717926a79SDavid Howells 		BUG();						\
74817926a79SDavid Howells 	}							\
74917926a79SDavid Howells } while (0)
75017926a79SDavid Howells 
75117926a79SDavid Howells #define ASSERTCMP(X, OP, Y)						\
75217926a79SDavid Howells do {									\
75317926a79SDavid Howells 	if (unlikely(!((X) OP (Y)))) {					\
75417926a79SDavid Howells 		printk(KERN_ERR "\n");					\
75517926a79SDavid Howells 		printk(KERN_ERR "RxRPC: Assertion failed\n");		\
75617926a79SDavid Howells 		printk(KERN_ERR "%lu " #OP " %lu is false\n",		\
75717926a79SDavid Howells 		       (unsigned long)(X), (unsigned long)(Y));		\
75817926a79SDavid Howells 		printk(KERN_ERR "0x%lx " #OP " 0x%lx is false\n",	\
75917926a79SDavid Howells 		       (unsigned long)(X), (unsigned long)(Y));		\
76017926a79SDavid Howells 		BUG();							\
76117926a79SDavid Howells 	}								\
76217926a79SDavid Howells } while (0)
76317926a79SDavid Howells 
76417926a79SDavid Howells #define ASSERTIF(C, X)						\
76517926a79SDavid Howells do {								\
76617926a79SDavid Howells 	if (unlikely((C) && !(X))) {				\
76717926a79SDavid Howells 		printk(KERN_ERR "\n");				\
76817926a79SDavid Howells 		printk(KERN_ERR "RxRPC: Assertion failed\n");	\
76917926a79SDavid Howells 		BUG();						\
77017926a79SDavid Howells 	}							\
77117926a79SDavid Howells } while (0)
77217926a79SDavid Howells 
77317926a79SDavid Howells #define ASSERTIFCMP(C, X, OP, Y)					\
77417926a79SDavid Howells do {									\
77517926a79SDavid Howells 	if (unlikely((C) && !((X) OP (Y)))) {				\
77617926a79SDavid Howells 		printk(KERN_ERR "\n");					\
77717926a79SDavid Howells 		printk(KERN_ERR "RxRPC: Assertion failed\n");		\
77817926a79SDavid Howells 		printk(KERN_ERR "%lu " #OP " %lu is false\n",		\
77917926a79SDavid Howells 		       (unsigned long)(X), (unsigned long)(Y));		\
78017926a79SDavid Howells 		printk(KERN_ERR "0x%lx " #OP " 0x%lx is false\n",	\
78117926a79SDavid Howells 		       (unsigned long)(X), (unsigned long)(Y));		\
78217926a79SDavid Howells 		BUG();							\
78317926a79SDavid Howells 	}								\
78417926a79SDavid Howells } while (0)
78517926a79SDavid Howells 
78617926a79SDavid Howells #else
78717926a79SDavid Howells 
78817926a79SDavid Howells #define ASSERT(X)				\
78917926a79SDavid Howells do {						\
79017926a79SDavid Howells } while (0)
79117926a79SDavid Howells 
79217926a79SDavid Howells #define ASSERTCMP(X, OP, Y)			\
79317926a79SDavid Howells do {						\
79417926a79SDavid Howells } while (0)
79517926a79SDavid Howells 
79617926a79SDavid Howells #define ASSERTIF(C, X)				\
79717926a79SDavid Howells do {						\
79817926a79SDavid Howells } while (0)
79917926a79SDavid Howells 
80017926a79SDavid Howells #define ASSERTIFCMP(C, X, OP, Y)		\
80117926a79SDavid Howells do {						\
80217926a79SDavid Howells } while (0)
80317926a79SDavid Howells 
80417926a79SDavid Howells #endif /* __KDEBUGALL */
80517926a79SDavid Howells 
80617926a79SDavid Howells /*
80717926a79SDavid Howells  * socket buffer accounting / leak finding
80817926a79SDavid Howells  */
80917926a79SDavid Howells static inline void __rxrpc_new_skb(struct sk_buff *skb, const char *fn)
81017926a79SDavid Howells {
81117926a79SDavid Howells 	//_net("new skb %p %s [%d]", skb, fn, atomic_read(&rxrpc_n_skbs));
81217926a79SDavid Howells 	//atomic_inc(&rxrpc_n_skbs);
81317926a79SDavid Howells }
81417926a79SDavid Howells 
81517926a79SDavid Howells #define rxrpc_new_skb(skb) __rxrpc_new_skb((skb), __func__)
81617926a79SDavid Howells 
81717926a79SDavid Howells static inline void __rxrpc_kill_skb(struct sk_buff *skb, const char *fn)
81817926a79SDavid Howells {
81917926a79SDavid Howells 	//_net("kill skb %p %s [%d]", skb, fn, atomic_read(&rxrpc_n_skbs));
82017926a79SDavid Howells 	//atomic_dec(&rxrpc_n_skbs);
82117926a79SDavid Howells }
82217926a79SDavid Howells 
82317926a79SDavid Howells #define rxrpc_kill_skb(skb) __rxrpc_kill_skb((skb), __func__)
82417926a79SDavid Howells 
82517926a79SDavid Howells static inline void __rxrpc_free_skb(struct sk_buff *skb, const char *fn)
82617926a79SDavid Howells {
82717926a79SDavid Howells 	if (skb) {
82817926a79SDavid Howells 		CHECK_SLAB_OKAY(&skb->users);
82917926a79SDavid Howells 		//_net("free skb %p %s [%d]",
83017926a79SDavid Howells 		//     skb, fn, atomic_read(&rxrpc_n_skbs));
83117926a79SDavid Howells 		//atomic_dec(&rxrpc_n_skbs);
83217926a79SDavid Howells 		kfree_skb(skb);
83317926a79SDavid Howells 	}
83417926a79SDavid Howells }
83517926a79SDavid Howells 
83617926a79SDavid Howells #define rxrpc_free_skb(skb) __rxrpc_free_skb((skb), __func__)
83717926a79SDavid Howells 
83817926a79SDavid Howells static inline void rxrpc_purge_queue(struct sk_buff_head *list)
83917926a79SDavid Howells {
84017926a79SDavid Howells 	struct sk_buff *skb;
84117926a79SDavid Howells 	while ((skb = skb_dequeue((list))) != NULL)
84217926a79SDavid Howells 		rxrpc_free_skb(skb);
84317926a79SDavid Howells }
84417926a79SDavid Howells 
84517926a79SDavid Howells static inline void __rxrpc_get_local(struct rxrpc_local *local, const char *f)
84617926a79SDavid Howells {
84717926a79SDavid Howells 	CHECK_SLAB_OKAY(&local->usage);
84817926a79SDavid Howells 	if (atomic_inc_return(&local->usage) == 1)
84917926a79SDavid Howells 		printk("resurrected (%s)\n", f);
85017926a79SDavid Howells }
85117926a79SDavid Howells 
85217926a79SDavid Howells #define rxrpc_get_local(LOCAL) __rxrpc_get_local((LOCAL), __func__)
85317926a79SDavid Howells 
85417926a79SDavid Howells #define rxrpc_get_call(CALL)				\
85517926a79SDavid Howells do {							\
85617926a79SDavid Howells 	CHECK_SLAB_OKAY(&(CALL)->usage);		\
85717926a79SDavid Howells 	if (atomic_inc_return(&(CALL)->usage) == 1)	\
85817926a79SDavid Howells 		BUG();					\
85917926a79SDavid Howells } while (0)
86017926a79SDavid Howells 
86117926a79SDavid Howells #define rxrpc_put_call(CALL)				\
86217926a79SDavid Howells do {							\
86317926a79SDavid Howells 	__rxrpc_put_call(CALL);				\
86417926a79SDavid Howells } while (0)
865