xref: /openbmc/linux/net/rxrpc/ar-internal.h (revision 4f95dd78)
117926a79SDavid Howells /* AF_RXRPC internal definitions
217926a79SDavid Howells  *
317926a79SDavid Howells  * Copyright (C) 2007 Red Hat, Inc. All Rights Reserved.
417926a79SDavid Howells  * Written by David Howells (dhowells@redhat.com)
517926a79SDavid Howells  *
617926a79SDavid Howells  * This program is free software; you can redistribute it and/or
717926a79SDavid Howells  * modify it under the terms of the GNU General Public License
817926a79SDavid Howells  * as published by the Free Software Foundation; either version
917926a79SDavid Howells  * 2 of the License, or (at your option) any later version.
1017926a79SDavid Howells  */
1117926a79SDavid Howells 
12be6e6707SDavid Howells #include <linux/atomic.h>
13e0e4d82fSDavid Howells #include <net/sock.h>
14be6e6707SDavid Howells #include <net/af_rxrpc.h>
1517926a79SDavid Howells #include <rxrpc/packet.h>
1617926a79SDavid Howells 
1717926a79SDavid Howells #if 0
1817926a79SDavid Howells #define CHECK_SLAB_OKAY(X)				     \
1917926a79SDavid Howells 	BUG_ON(atomic_read((X)) >> (sizeof(atomic_t) - 2) == \
2017926a79SDavid Howells 	       (POISON_FREE << 8 | POISON_FREE))
2117926a79SDavid Howells #else
2217926a79SDavid Howells #define CHECK_SLAB_OKAY(X) do {} while (0)
2317926a79SDavid Howells #endif
2417926a79SDavid Howells 
2517926a79SDavid Howells #define FCRYPT_BSIZE 8
2617926a79SDavid Howells struct rxrpc_crypt {
2717926a79SDavid Howells 	union {
2817926a79SDavid Howells 		u8	x[FCRYPT_BSIZE];
2991e916cfSAl Viro 		__be32	n[2];
3017926a79SDavid Howells 	};
3117926a79SDavid Howells } __attribute__((aligned(8)));
3217926a79SDavid Howells 
33651350d1SDavid Howells #define rxrpc_queue_work(WS)	queue_work(rxrpc_workqueue, (WS))
34651350d1SDavid Howells #define rxrpc_queue_delayed_work(WS,D)	\
35651350d1SDavid Howells 	queue_delayed_work(rxrpc_workqueue, (WS), (D))
36651350d1SDavid Howells 
37651350d1SDavid Howells #define rxrpc_queue_call(CALL)	rxrpc_queue_work(&(CALL)->processor)
38651350d1SDavid Howells #define rxrpc_queue_conn(CONN)	rxrpc_queue_work(&(CONN)->processor)
3917926a79SDavid Howells 
4017926a79SDavid Howells /*
4117926a79SDavid Howells  * sk_state for RxRPC sockets
4217926a79SDavid Howells  */
4317926a79SDavid Howells enum {
442341e077SDavid Howells 	RXRPC_UNBOUND = 0,
452341e077SDavid Howells 	RXRPC_CLIENT_UNBOUND,		/* Unbound socket used as client */
4617926a79SDavid Howells 	RXRPC_CLIENT_BOUND,		/* client local address bound */
4717926a79SDavid Howells 	RXRPC_SERVER_BOUND,		/* server local address bound */
4817926a79SDavid Howells 	RXRPC_SERVER_LISTENING,		/* server listening for connections */
4917926a79SDavid Howells 	RXRPC_CLOSE,			/* socket is being closed */
5017926a79SDavid Howells };
5117926a79SDavid Howells 
5217926a79SDavid Howells /*
5317926a79SDavid Howells  * RxRPC socket definition
5417926a79SDavid Howells  */
5517926a79SDavid Howells struct rxrpc_sock {
5617926a79SDavid Howells 	/* WARNING: sk has to be the first member */
5717926a79SDavid Howells 	struct sock		sk;
58651350d1SDavid Howells 	rxrpc_interceptor_t	interceptor;	/* kernel service Rx interceptor function */
5917926a79SDavid Howells 	struct rxrpc_local	*local;		/* local endpoint */
6017926a79SDavid Howells 	struct rxrpc_connection	*conn;		/* exclusive virtual connection */
6117926a79SDavid Howells 	struct list_head	listen_link;	/* link in the local endpoint's listen list */
6217926a79SDavid Howells 	struct list_head	secureq;	/* calls awaiting connection security clearance */
6317926a79SDavid Howells 	struct list_head	acceptq;	/* calls awaiting acceptance */
6417926a79SDavid Howells 	struct key		*key;		/* security for this socket */
6517926a79SDavid Howells 	struct key		*securities;	/* list of server security descriptors */
6617926a79SDavid Howells 	struct rb_root		calls;		/* outstanding calls on this socket */
6717926a79SDavid Howells 	unsigned long		flags;
682341e077SDavid Howells #define RXRPC_SOCK_CONNECTED		0	/* connect_srx is set */
6917926a79SDavid Howells #define RXRPC_SOCK_EXCLUSIVE_CONN	1	/* exclusive connection for a client socket */
7017926a79SDavid Howells 	rwlock_t		call_lock;	/* lock for calls */
7117926a79SDavid Howells 	u32			min_sec_level;	/* minimum security level */
7217926a79SDavid Howells #define RXRPC_SECURITY_MAX	RXRPC_SECURITY_ENCRYPT
7317926a79SDavid Howells 	struct sockaddr_rxrpc	srx;		/* local address */
742341e077SDavid Howells 	struct sockaddr_rxrpc	connect_srx;	/* Default client address from connect() */
7517926a79SDavid Howells 	sa_family_t		proto;		/* protocol created with */
7617926a79SDavid Howells };
7717926a79SDavid Howells 
7817926a79SDavid Howells #define rxrpc_sk(__sk) container_of((__sk), struct rxrpc_sock, sk)
7917926a79SDavid Howells 
8017926a79SDavid Howells /*
810d12f8a4SDavid Howells  * CPU-byteorder normalised Rx packet header.
820d12f8a4SDavid Howells  */
830d12f8a4SDavid Howells struct rxrpc_host_header {
840d12f8a4SDavid Howells 	u32		epoch;		/* client boot timestamp */
850d12f8a4SDavid Howells 	u32		cid;		/* connection and channel ID */
860d12f8a4SDavid Howells 	u32		callNumber;	/* call ID (0 for connection-level packets) */
870d12f8a4SDavid Howells 	u32		seq;		/* sequence number of pkt in call stream */
880d12f8a4SDavid Howells 	u32		serial;		/* serial number of pkt sent to network */
890d12f8a4SDavid Howells 	u8		type;		/* packet type */
900d12f8a4SDavid Howells 	u8		flags;		/* packet flags */
910d12f8a4SDavid Howells 	u8		userStatus;	/* app-layer defined status */
920d12f8a4SDavid Howells 	u8		securityIndex;	/* security protocol ID */
930d12f8a4SDavid Howells 	union {
940d12f8a4SDavid Howells 		u16	_rsvd;		/* reserved */
950d12f8a4SDavid Howells 		u16	cksum;		/* kerberos security checksum */
960d12f8a4SDavid Howells 	};
970d12f8a4SDavid Howells 	u16		serviceId;	/* service ID */
980d12f8a4SDavid Howells } __packed;
990d12f8a4SDavid Howells 
1000d12f8a4SDavid Howells /*
10117926a79SDavid Howells  * RxRPC socket buffer private variables
10217926a79SDavid Howells  * - max 48 bytes (struct sk_buff::cb)
10317926a79SDavid Howells  */
10417926a79SDavid Howells struct rxrpc_skb_priv {
10517926a79SDavid Howells 	struct rxrpc_call	*call;		/* call with which associated */
10617926a79SDavid Howells 	unsigned long		resend_at;	/* time in jiffies at which to resend */
10717926a79SDavid Howells 	union {
10895c96174SEric Dumazet 		unsigned int	offset;		/* offset into buffer of next read */
10917926a79SDavid Howells 		int		remain;		/* amount of space remaining for next write */
11017926a79SDavid Howells 		u32		error;		/* network error code */
11117926a79SDavid Howells 		bool		need_resend;	/* T if needs resending */
11217926a79SDavid Howells 	};
11317926a79SDavid Howells 
1140d12f8a4SDavid Howells 	struct rxrpc_host_header hdr;		/* RxRPC packet header from this packet */
11517926a79SDavid Howells };
11617926a79SDavid Howells 
11717926a79SDavid Howells #define rxrpc_skb(__skb) ((struct rxrpc_skb_priv *) &(__skb)->cb)
11817926a79SDavid Howells 
11917926a79SDavid Howells enum rxrpc_command {
12017926a79SDavid Howells 	RXRPC_CMD_SEND_DATA,		/* send data message */
12117926a79SDavid Howells 	RXRPC_CMD_SEND_ABORT,		/* request abort generation */
12217926a79SDavid Howells 	RXRPC_CMD_ACCEPT,		/* [server] accept incoming call */
12317926a79SDavid Howells 	RXRPC_CMD_REJECT_BUSY,		/* [server] reject a call as busy */
12417926a79SDavid Howells };
12517926a79SDavid Howells 
12617926a79SDavid Howells /*
12717926a79SDavid Howells  * RxRPC security module interface
12817926a79SDavid Howells  */
12917926a79SDavid Howells struct rxrpc_security {
13017926a79SDavid Howells 	const char		*name;		/* name of this service */
13117926a79SDavid Howells 	u8			security_index;	/* security type provided */
13217926a79SDavid Howells 
133648af7fcSDavid Howells 	/* Initialise a security service */
134648af7fcSDavid Howells 	int (*init)(void);
135648af7fcSDavid Howells 
136648af7fcSDavid Howells 	/* Clean up a security service */
137648af7fcSDavid Howells 	void (*exit)(void);
138648af7fcSDavid Howells 
13917926a79SDavid Howells 	/* initialise a connection's security */
14017926a79SDavid Howells 	int (*init_connection_security)(struct rxrpc_connection *);
14117926a79SDavid Howells 
14217926a79SDavid Howells 	/* prime a connection's packet security */
14317926a79SDavid Howells 	void (*prime_packet_security)(struct rxrpc_connection *);
14417926a79SDavid Howells 
14517926a79SDavid Howells 	/* impose security on a packet */
14617926a79SDavid Howells 	int (*secure_packet)(const struct rxrpc_call *,
14717926a79SDavid Howells 			     struct sk_buff *,
14817926a79SDavid Howells 			     size_t,
14917926a79SDavid Howells 			     void *);
15017926a79SDavid Howells 
15117926a79SDavid Howells 	/* verify the security on a received packet */
15217926a79SDavid Howells 	int (*verify_packet)(const struct rxrpc_call *, struct sk_buff *,
15317926a79SDavid Howells 			     u32 *);
15417926a79SDavid Howells 
15517926a79SDavid Howells 	/* issue a challenge */
15617926a79SDavid Howells 	int (*issue_challenge)(struct rxrpc_connection *);
15717926a79SDavid Howells 
15817926a79SDavid Howells 	/* respond to a challenge */
15917926a79SDavid Howells 	int (*respond_to_challenge)(struct rxrpc_connection *,
16017926a79SDavid Howells 				    struct sk_buff *,
16117926a79SDavid Howells 				    u32 *);
16217926a79SDavid Howells 
16317926a79SDavid Howells 	/* verify a response */
16417926a79SDavid Howells 	int (*verify_response)(struct rxrpc_connection *,
16517926a79SDavid Howells 			       struct sk_buff *,
16617926a79SDavid Howells 			       u32 *);
16717926a79SDavid Howells 
16817926a79SDavid Howells 	/* clear connection security */
16917926a79SDavid Howells 	void (*clear)(struct rxrpc_connection *);
17017926a79SDavid Howells };
17117926a79SDavid Howells 
17217926a79SDavid Howells /*
1734f95dd78SDavid Howells  * RxRPC local transport endpoint description
1744f95dd78SDavid Howells  * - owned by a single AF_RXRPC socket
1754f95dd78SDavid Howells  * - pointed to by transport socket struct sk_user_data
17617926a79SDavid Howells  */
17717926a79SDavid Howells struct rxrpc_local {
1784f95dd78SDavid Howells 	struct rcu_head		rcu;
1794f95dd78SDavid Howells 	atomic_t		usage;
1804f95dd78SDavid Howells 	struct list_head	link;
18117926a79SDavid Howells 	struct socket		*socket;	/* my UDP socket */
1824f95dd78SDavid Howells 	struct work_struct	processor;
18317926a79SDavid Howells 	struct list_head	services;	/* services listening on this endpoint */
18417926a79SDavid Howells 	struct rw_semaphore	defrag_sem;	/* control re-enablement of IP DF bit */
18517926a79SDavid Howells 	struct sk_buff_head	accept_queue;	/* incoming calls awaiting acceptance */
18617926a79SDavid Howells 	struct sk_buff_head	reject_queue;	/* packets awaiting rejection */
18744ba0698SDavid Howells 	struct sk_buff_head	event_queue;	/* endpoint event packets awaiting processing */
1884f95dd78SDavid Howells 	struct mutex		conn_lock;	/* Client connection creation lock */
18917926a79SDavid Howells 	spinlock_t		lock;		/* access lock */
19017926a79SDavid Howells 	rwlock_t		services_lock;	/* lock for services list */
19117926a79SDavid Howells 	int			debug_id;	/* debug ID for printks */
1924f95dd78SDavid Howells 	bool			dead;
19317926a79SDavid Howells 	struct sockaddr_rxrpc	srx;		/* local address */
19417926a79SDavid Howells };
19517926a79SDavid Howells 
19617926a79SDavid Howells /*
19717926a79SDavid Howells  * RxRPC remote transport endpoint definition
198be6e6707SDavid Howells  * - matched by local endpoint, remote port, address and protocol type
19917926a79SDavid Howells  */
20017926a79SDavid Howells struct rxrpc_peer {
201be6e6707SDavid Howells 	struct rcu_head		rcu;		/* This must be first */
202be6e6707SDavid Howells 	atomic_t		usage;
203be6e6707SDavid Howells 	unsigned long		hash_key;
204be6e6707SDavid Howells 	struct hlist_node	hash_link;
205be6e6707SDavid Howells 	struct rxrpc_local	*local;
206f66d7490SDavid Howells 	struct hlist_head	error_targets;	/* targets for net error distribution */
207f66d7490SDavid Howells 	struct work_struct	error_distributor;
20817926a79SDavid Howells 	spinlock_t		lock;		/* access lock */
20995c96174SEric Dumazet 	unsigned int		if_mtu;		/* interface MTU for this peer */
21095c96174SEric Dumazet 	unsigned int		mtu;		/* network MTU for this peer */
21195c96174SEric Dumazet 	unsigned int		maxdata;	/* data size (MTU - hdrsize) */
21217926a79SDavid Howells 	unsigned short		hdrsize;	/* header size (IP + UDP + RxRPC) */
21317926a79SDavid Howells 	int			debug_id;	/* debug ID for printks */
214f66d7490SDavid Howells 	int			error_report;	/* Net (+0) or local (+1000000) to distribute */
215f66d7490SDavid Howells #define RXRPC_LOCAL_ERROR_OFFSET 1000000
21617926a79SDavid Howells 	struct sockaddr_rxrpc	srx;		/* remote address */
21717926a79SDavid Howells 
21817926a79SDavid Howells 	/* calculated RTT cache */
21917926a79SDavid Howells #define RXRPC_RTT_CACHE_SIZE 32
22017926a79SDavid Howells 	suseconds_t		rtt;		/* current RTT estimate (in uS) */
22195c96174SEric Dumazet 	unsigned int		rtt_point;	/* next entry at which to insert */
22295c96174SEric Dumazet 	unsigned int		rtt_usage;	/* amount of cache actually used */
22317926a79SDavid Howells 	suseconds_t		rtt_cache[RXRPC_RTT_CACHE_SIZE]; /* calculated RTT cache */
22417926a79SDavid Howells };
22517926a79SDavid Howells 
22617926a79SDavid Howells /*
22717926a79SDavid Howells  * RxRPC point-to-point transport / connection manager definition
22817926a79SDavid Howells  * - handles a bundle of connections between two endpoints
22917926a79SDavid Howells  * - matched by { local, peer }
23017926a79SDavid Howells  */
23117926a79SDavid Howells struct rxrpc_transport {
23217926a79SDavid Howells 	struct rxrpc_local	*local;		/* local transport endpoint */
23317926a79SDavid Howells 	struct rxrpc_peer	*peer;		/* remote transport endpoint */
23417926a79SDavid Howells 	struct rb_root		bundles;	/* client connection bundles on this transport */
23517926a79SDavid Howells 	struct rb_root		client_conns;	/* client connections on this transport */
23617926a79SDavid Howells 	struct rb_root		server_conns;	/* server connections on this transport */
23717926a79SDavid Howells 	struct list_head	link;		/* link in master session list */
23822a3f9a2SKsenija Stanojevic 	unsigned long		put_time;	/* time at which to reap */
23917926a79SDavid Howells 	spinlock_t		client_lock;	/* client connection allocation lock */
24017926a79SDavid Howells 	rwlock_t		conn_lock;	/* lock for active/dead connections */
24117926a79SDavid Howells 	atomic_t		usage;
24217926a79SDavid Howells 	int			debug_id;	/* debug ID for printks */
24317926a79SDavid Howells 	unsigned int		conn_idcounter;	/* connection ID counter (client) */
24417926a79SDavid Howells };
24517926a79SDavid Howells 
24617926a79SDavid Howells /*
24717926a79SDavid Howells  * RxRPC client connection bundle
24817926a79SDavid Howells  * - matched by { transport, service_id, key }
24917926a79SDavid Howells  */
25017926a79SDavid Howells struct rxrpc_conn_bundle {
25117926a79SDavid Howells 	struct rb_node		node;		/* node in transport's lookup tree */
25217926a79SDavid Howells 	struct list_head	unused_conns;	/* unused connections in this bundle */
25317926a79SDavid Howells 	struct list_head	avail_conns;	/* available connections in this bundle */
25417926a79SDavid Howells 	struct list_head	busy_conns;	/* busy connections in this bundle */
25517926a79SDavid Howells 	struct key		*key;		/* security for this bundle */
25617926a79SDavid Howells 	wait_queue_head_t	chanwait;	/* wait for channel to become available */
25717926a79SDavid Howells 	atomic_t		usage;
25817926a79SDavid Howells 	int			debug_id;	/* debug ID for printks */
25917926a79SDavid Howells 	unsigned short		num_conns;	/* number of connections in this bundle */
2600d12f8a4SDavid Howells 	u16			service_id;	/* Service ID for this bundle */
2614e36a95eSDavid Howells 	u8			security_ix;	/* security type */
26217926a79SDavid Howells };
26317926a79SDavid Howells 
26417926a79SDavid Howells /*
26517926a79SDavid Howells  * RxRPC connection definition
26617926a79SDavid Howells  * - matched by { transport, service_id, conn_id, direction, key }
26717926a79SDavid Howells  * - each connection can only handle four simultaneous calls
26817926a79SDavid Howells  */
26917926a79SDavid Howells struct rxrpc_connection {
27017926a79SDavid Howells 	struct rxrpc_transport	*trans;		/* transport session */
27117926a79SDavid Howells 	struct rxrpc_conn_bundle *bundle;	/* connection bundle (client) */
27217926a79SDavid Howells 	struct work_struct	processor;	/* connection event processor */
27317926a79SDavid Howells 	struct rb_node		node;		/* node in transport's lookup tree */
27417926a79SDavid Howells 	struct list_head	link;		/* link in master connection list */
27517926a79SDavid Howells 	struct list_head	bundle_link;	/* link in bundle */
27617926a79SDavid Howells 	struct rb_root		calls;		/* calls on this connection */
27717926a79SDavid Howells 	struct sk_buff_head	rx_queue;	/* received conn-level packets */
27817926a79SDavid Howells 	struct rxrpc_call	*channels[RXRPC_MAXCALLS]; /* channels (active calls) */
279648af7fcSDavid Howells 	const struct rxrpc_security *security;	/* applied security module */
28017926a79SDavid Howells 	struct key		*key;		/* security for this connection (client) */
28117926a79SDavid Howells 	struct key		*server_key;	/* security for this service */
2821afe593bSHerbert Xu 	struct crypto_skcipher	*cipher;	/* encryption handle */
28317926a79SDavid Howells 	struct rxrpc_crypt	csum_iv;	/* packet checksum base */
28417926a79SDavid Howells 	unsigned long		events;
28517926a79SDavid Howells #define RXRPC_CONN_CHALLENGE	0		/* send challenge packet */
28622a3f9a2SKsenija Stanojevic 	unsigned long		put_time;	/* time at which to reap */
28717926a79SDavid Howells 	rwlock_t		lock;		/* access lock */
28817926a79SDavid Howells 	spinlock_t		state_lock;	/* state-change lock */
28917926a79SDavid Howells 	atomic_t		usage;
29017926a79SDavid Howells 	enum {					/* current state of connection */
29117926a79SDavid Howells 		RXRPC_CONN_UNUSED,		/* - connection not yet attempted */
29217926a79SDavid Howells 		RXRPC_CONN_CLIENT,		/* - client connection */
29317926a79SDavid Howells 		RXRPC_CONN_SERVER_UNSECURED,	/* - server unsecured connection */
29417926a79SDavid Howells 		RXRPC_CONN_SERVER_CHALLENGING,	/* - server challenging for security */
29517926a79SDavid Howells 		RXRPC_CONN_SERVER,		/* - server secured connection */
29617926a79SDavid Howells 		RXRPC_CONN_REMOTELY_ABORTED,	/* - conn aborted by peer */
29717926a79SDavid Howells 		RXRPC_CONN_LOCALLY_ABORTED,	/* - conn aborted locally */
29817926a79SDavid Howells 		RXRPC_CONN_NETWORK_ERROR,	/* - conn terminated by network error */
29917926a79SDavid Howells 	} state;
300dc44b3a0SDavid Howells 	u32			local_abort;	/* local abort code */
301dc44b3a0SDavid Howells 	u32			remote_abort;	/* remote abort code */
302dc44b3a0SDavid Howells 	int			error;		/* local error incurred */
30317926a79SDavid Howells 	int			debug_id;	/* debug ID for printks */
30495c96174SEric Dumazet 	unsigned int		call_counter;	/* call ID counter */
30517926a79SDavid Howells 	atomic_t		serial;		/* packet serial number counter */
30617926a79SDavid Howells 	atomic_t		hi_serial;	/* highest serial number received */
30717926a79SDavid Howells 	u8			avail_calls;	/* number of calls available */
30817926a79SDavid Howells 	u8			size_align;	/* data size alignment (for security) */
30917926a79SDavid Howells 	u8			header_size;	/* rxrpc + security header size */
31017926a79SDavid Howells 	u8			security_size;	/* security header size */
31117926a79SDavid Howells 	u32			security_level;	/* security level negotiated */
31217926a79SDavid Howells 	u32			security_nonce;	/* response re-use preventer */
3130d12f8a4SDavid Howells 	u32			epoch;		/* epoch of this connection */
3140d12f8a4SDavid Howells 	u32			cid;		/* connection ID */
3150d12f8a4SDavid Howells 	u16			service_id;	/* service ID for this connection */
31617926a79SDavid Howells 	u8			security_ix;	/* security type */
31717926a79SDavid Howells 	u8			in_clientflag;	/* RXRPC_CLIENT_INITIATED if we are server */
31817926a79SDavid Howells 	u8			out_clientflag;	/* RXRPC_CLIENT_INITIATED if we are client */
31917926a79SDavid Howells };
32017926a79SDavid Howells 
32117926a79SDavid Howells /*
3225b8848d1SDavid Howells  * Flags in call->flags.
3235b8848d1SDavid Howells  */
3245b8848d1SDavid Howells enum rxrpc_call_flag {
3255b8848d1SDavid Howells 	RXRPC_CALL_RELEASED,		/* call has been released - no more message to userspace */
3265b8848d1SDavid Howells 	RXRPC_CALL_TERMINAL_MSG,	/* call has given the socket its final message */
3275b8848d1SDavid Howells 	RXRPC_CALL_RCVD_LAST,		/* all packets received */
3285b8848d1SDavid Howells 	RXRPC_CALL_RUN_RTIMER,		/* Tx resend timer started */
3295b8848d1SDavid Howells 	RXRPC_CALL_TX_SOFT_ACK,		/* sent some soft ACKs */
3305b8848d1SDavid Howells 	RXRPC_CALL_PROC_BUSY,		/* the processor is busy */
3315b8848d1SDavid Howells 	RXRPC_CALL_INIT_ACCEPT,		/* acceptance was initiated */
3325b8848d1SDavid Howells 	RXRPC_CALL_HAS_USERID,		/* has a user ID attached */
3335b8848d1SDavid Howells 	RXRPC_CALL_EXPECT_OOS,		/* expect out of sequence packets */
3345b8848d1SDavid Howells };
3355b8848d1SDavid Howells 
3365b8848d1SDavid Howells /*
3375b8848d1SDavid Howells  * Events that can be raised on a call.
3385b8848d1SDavid Howells  */
3395b8848d1SDavid Howells enum rxrpc_call_event {
3404c198ad1SDavid Howells 	RXRPC_CALL_EV_RCVD_ACKALL,	/* ACKALL or reply received */
3414c198ad1SDavid Howells 	RXRPC_CALL_EV_RCVD_BUSY,	/* busy packet received */
3424c198ad1SDavid Howells 	RXRPC_CALL_EV_RCVD_ABORT,	/* abort packet received */
3434c198ad1SDavid Howells 	RXRPC_CALL_EV_RCVD_ERROR,	/* network error received */
3444c198ad1SDavid Howells 	RXRPC_CALL_EV_ACK_FINAL,	/* need to generate final ACK (and release call) */
3454c198ad1SDavid Howells 	RXRPC_CALL_EV_ACK,		/* need to generate ACK */
3464c198ad1SDavid Howells 	RXRPC_CALL_EV_REJECT_BUSY,	/* need to generate busy message */
3474c198ad1SDavid Howells 	RXRPC_CALL_EV_ABORT,		/* need to generate abort */
3484c198ad1SDavid Howells 	RXRPC_CALL_EV_CONN_ABORT,	/* local connection abort generated */
3494c198ad1SDavid Howells 	RXRPC_CALL_EV_RESEND_TIMER,	/* Tx resend timer expired */
3504c198ad1SDavid Howells 	RXRPC_CALL_EV_RESEND,		/* Tx resend required */
3514c198ad1SDavid Howells 	RXRPC_CALL_EV_DRAIN_RX_OOS,	/* drain the Rx out of sequence queue */
3524c198ad1SDavid Howells 	RXRPC_CALL_EV_LIFE_TIMER,	/* call's lifetimer ran out */
3534c198ad1SDavid Howells 	RXRPC_CALL_EV_ACCEPTED,		/* incoming call accepted by userspace app */
3544c198ad1SDavid Howells 	RXRPC_CALL_EV_SECURED,		/* incoming call's connection is now secure */
3554c198ad1SDavid Howells 	RXRPC_CALL_EV_POST_ACCEPT,	/* need to post an "accept?" message to the app */
3564c198ad1SDavid Howells 	RXRPC_CALL_EV_RELEASE,		/* need to release the call's resources */
3575b8848d1SDavid Howells };
3585b8848d1SDavid Howells 
3595b8848d1SDavid Howells /*
3605b8848d1SDavid Howells  * The states that a call can be in.
3615b8848d1SDavid Howells  */
3625b8848d1SDavid Howells enum rxrpc_call_state {
3635b8848d1SDavid Howells 	RXRPC_CALL_CLIENT_SEND_REQUEST,	/* - client sending request phase */
3645b8848d1SDavid Howells 	RXRPC_CALL_CLIENT_AWAIT_REPLY,	/* - client awaiting reply */
3655b8848d1SDavid Howells 	RXRPC_CALL_CLIENT_RECV_REPLY,	/* - client receiving reply phase */
3665b8848d1SDavid Howells 	RXRPC_CALL_CLIENT_FINAL_ACK,	/* - client sending final ACK phase */
3675b8848d1SDavid Howells 	RXRPC_CALL_SERVER_SECURING,	/* - server securing request connection */
3685b8848d1SDavid Howells 	RXRPC_CALL_SERVER_ACCEPTING,	/* - server accepting request */
3695b8848d1SDavid Howells 	RXRPC_CALL_SERVER_RECV_REQUEST,	/* - server receiving request */
3705b8848d1SDavid Howells 	RXRPC_CALL_SERVER_ACK_REQUEST,	/* - server pending ACK of request */
3715b8848d1SDavid Howells 	RXRPC_CALL_SERVER_SEND_REPLY,	/* - server sending reply */
3725b8848d1SDavid Howells 	RXRPC_CALL_SERVER_AWAIT_ACK,	/* - server awaiting final ACK */
3735b8848d1SDavid Howells 	RXRPC_CALL_COMPLETE,		/* - call completed */
3745b8848d1SDavid Howells 	RXRPC_CALL_SERVER_BUSY,		/* - call rejected by busy server */
3755b8848d1SDavid Howells 	RXRPC_CALL_REMOTELY_ABORTED,	/* - call aborted by peer */
3765b8848d1SDavid Howells 	RXRPC_CALL_LOCALLY_ABORTED,	/* - call aborted locally on error or close */
3775b8848d1SDavid Howells 	RXRPC_CALL_NETWORK_ERROR,	/* - call terminated by network error */
3785b8848d1SDavid Howells 	RXRPC_CALL_DEAD,		/* - call is dead */
3795b8848d1SDavid Howells 	NR__RXRPC_CALL_STATES
3805b8848d1SDavid Howells };
3815b8848d1SDavid Howells 
3825b8848d1SDavid Howells /*
38317926a79SDavid Howells  * RxRPC call definition
38417926a79SDavid Howells  * - matched by { connection, call_id }
38517926a79SDavid Howells  */
38617926a79SDavid Howells struct rxrpc_call {
38717926a79SDavid Howells 	struct rxrpc_connection	*conn;		/* connection carrying call */
38817926a79SDavid Howells 	struct rxrpc_sock	*socket;	/* socket responsible */
38917926a79SDavid Howells 	struct timer_list	lifetimer;	/* lifetime remaining on call */
39017926a79SDavid Howells 	struct timer_list	deadspan;	/* reap timer for re-ACK'ing, etc  */
39117926a79SDavid Howells 	struct timer_list	ack_timer;	/* ACK generation timer */
39217926a79SDavid Howells 	struct timer_list	resend_timer;	/* Tx resend timer */
39317926a79SDavid Howells 	struct work_struct	destroyer;	/* call destroyer */
39417926a79SDavid Howells 	struct work_struct	processor;	/* packet processor and ACK generator */
39517926a79SDavid Howells 	struct list_head	link;		/* link in master call list */
396f66d7490SDavid Howells 	struct hlist_node	error_link;	/* link in error distribution list */
39717926a79SDavid Howells 	struct list_head	accept_link;	/* calls awaiting acceptance */
39817926a79SDavid Howells 	struct rb_node		sock_node;	/* node in socket call tree */
39917926a79SDavid Howells 	struct rb_node		conn_node;	/* node in connection call tree */
40017926a79SDavid Howells 	struct sk_buff_head	rx_queue;	/* received packets */
40117926a79SDavid Howells 	struct sk_buff_head	rx_oos_queue;	/* packets received out of sequence */
40217926a79SDavid Howells 	struct sk_buff		*tx_pending;	/* Tx socket buffer being filled */
40317926a79SDavid Howells 	wait_queue_head_t	tx_waitq;	/* wait for Tx window space to become available */
40417926a79SDavid Howells 	unsigned long		user_call_ID;	/* user-defined call ID */
40517926a79SDavid Howells 	unsigned long		creation_jif;	/* time of call creation */
40617926a79SDavid Howells 	unsigned long		flags;
40717926a79SDavid Howells 	unsigned long		events;
40817926a79SDavid Howells 	spinlock_t		lock;
40917926a79SDavid Howells 	rwlock_t		state_lock;	/* lock for state transition */
41017926a79SDavid Howells 	atomic_t		usage;
41117926a79SDavid Howells 	atomic_t		sequence;	/* Tx data packet sequence counter */
412dc44b3a0SDavid Howells 	u32			local_abort;	/* local abort code */
413dc44b3a0SDavid Howells 	u32			remote_abort;	/* remote abort code */
414f66d7490SDavid Howells 	int			error_report;	/* Network error (ICMP/local transport) */
415f66d7490SDavid Howells 	int			error;		/* Local error incurred */
4165b8848d1SDavid Howells 	enum rxrpc_call_state	state : 8;	/* current state of call */
41717926a79SDavid Howells 	int			debug_id;	/* debug ID for printks */
41817926a79SDavid Howells 	u8			channel;	/* connection channel occupied by this call */
41917926a79SDavid Howells 
42017926a79SDavid Howells 	/* transmission-phase ACK management */
4214e36a95eSDavid Howells 	u8			acks_head;	/* offset into window of first entry */
4224e36a95eSDavid Howells 	u8			acks_tail;	/* offset into window of last entry */
4234e36a95eSDavid Howells 	u8			acks_winsz;	/* size of un-ACK'd window */
4244e36a95eSDavid Howells 	u8			acks_unacked;	/* lowest unacked packet in last ACK received */
42517926a79SDavid Howells 	int			acks_latest;	/* serial number of latest ACK received */
42617926a79SDavid Howells 	rxrpc_seq_t		acks_hard;	/* highest definitively ACK'd msg seq */
42717926a79SDavid Howells 	unsigned long		*acks_window;	/* sent packet window
42817926a79SDavid Howells 						 * - elements are pointers with LSB set if ACK'd
42917926a79SDavid Howells 						 */
43017926a79SDavid Howells 
43117926a79SDavid Howells 	/* receive-phase ACK management */
43217926a79SDavid Howells 	rxrpc_seq_t		rx_data_expect;	/* next data seq ID expected to be received */
43317926a79SDavid Howells 	rxrpc_seq_t		rx_data_post;	/* next data seq ID expected to be posted */
43417926a79SDavid Howells 	rxrpc_seq_t		rx_data_recv;	/* last data seq ID encountered by recvmsg */
43517926a79SDavid Howells 	rxrpc_seq_t		rx_data_eaten;	/* last data seq ID consumed by recvmsg */
43617926a79SDavid Howells 	rxrpc_seq_t		rx_first_oos;	/* first packet in rx_oos_queue (or 0) */
43717926a79SDavid Howells 	rxrpc_seq_t		ackr_win_top;	/* top of ACK window (rx_data_eaten is bottom) */
4380d12f8a4SDavid Howells 	rxrpc_seq_t		ackr_prev_seq;	/* previous sequence number received */
4394e36a95eSDavid Howells 	u8			ackr_reason;	/* reason to ACK */
4400d12f8a4SDavid Howells 	rxrpc_serial_t		ackr_serial;	/* serial of packet being ACK'd */
44117926a79SDavid Howells 	atomic_t		ackr_not_idle;	/* number of packets in Rx queue */
44217926a79SDavid Howells 
44317926a79SDavid Howells 	/* received packet records, 1 bit per record */
44417926a79SDavid Howells #define RXRPC_ACKR_WINDOW_ASZ DIV_ROUND_UP(RXRPC_MAXACKS, BITS_PER_LONG)
44517926a79SDavid Howells 	unsigned long		ackr_window[RXRPC_ACKR_WINDOW_ASZ + 1];
44617926a79SDavid Howells 
4477727640cSTim Smith 	struct hlist_node	hash_node;
4487727640cSTim Smith 	unsigned long		hash_key;	/* Full hash key */
4497727640cSTim Smith 	u8			in_clientflag;	/* Copy of conn->in_clientflag for hashing */
4507727640cSTim Smith 	struct rxrpc_local	*local;		/* Local endpoint. Used for hashing. */
4517727640cSTim Smith 	sa_family_t		proto;		/* Frame protocol */
4520d12f8a4SDavid Howells 	u32			call_id;	/* call ID on connection  */
4530d12f8a4SDavid Howells 	u32			cid;		/* connection ID plus channel index */
4540d12f8a4SDavid Howells 	u32			epoch;		/* epoch of this connection */
4550d12f8a4SDavid Howells 	u16			service_id;	/* service ID */
4567727640cSTim Smith 	union {					/* Peer IP address for hashing */
4577727640cSTim Smith 		__be32	ipv4_addr;
4587727640cSTim Smith 		__u8	ipv6_addr[16];		/* Anticipates eventual IPv6 support */
4597727640cSTim Smith 	} peer_ip;
46017926a79SDavid Howells };
46117926a79SDavid Howells 
46217926a79SDavid Howells /*
46317926a79SDavid Howells  * locally abort an RxRPC call
46417926a79SDavid Howells  */
46517926a79SDavid Howells static inline void rxrpc_abort_call(struct rxrpc_call *call, u32 abort_code)
46617926a79SDavid Howells {
46717926a79SDavid Howells 	write_lock_bh(&call->state_lock);
46817926a79SDavid Howells 	if (call->state < RXRPC_CALL_COMPLETE) {
469dc44b3a0SDavid Howells 		call->local_abort = abort_code;
47017926a79SDavid Howells 		call->state = RXRPC_CALL_LOCALLY_ABORTED;
4714c198ad1SDavid Howells 		set_bit(RXRPC_CALL_EV_ABORT, &call->events);
47217926a79SDavid Howells 	}
47317926a79SDavid Howells 	write_unlock_bh(&call->state_lock);
47417926a79SDavid Howells }
47517926a79SDavid Howells 
47617926a79SDavid Howells /*
477651350d1SDavid Howells  * af_rxrpc.c
47817926a79SDavid Howells  */
479651350d1SDavid Howells extern atomic_t rxrpc_n_skbs;
4800d12f8a4SDavid Howells extern u32 rxrpc_epoch;
481651350d1SDavid Howells extern atomic_t rxrpc_debug_id;
482651350d1SDavid Howells extern struct workqueue_struct *rxrpc_workqueue;
48317926a79SDavid Howells 
4842341e077SDavid Howells extern struct rxrpc_transport *rxrpc_name_to_transport(struct rxrpc_sock *,
4852341e077SDavid Howells 						       struct sockaddr *,
4862341e077SDavid Howells 						       int, int, gfp_t);
4872341e077SDavid Howells 
48817926a79SDavid Howells /*
4890d81a51aSDavid Howells  * call_accept.c
49017926a79SDavid Howells  */
4914f95dd78SDavid Howells void rxrpc_accept_incoming_calls(struct rxrpc_local *);
492c1b1203dSJoe Perches struct rxrpc_call *rxrpc_accept_call(struct rxrpc_sock *, unsigned long);
493c1b1203dSJoe Perches int rxrpc_reject_call(struct rxrpc_sock *);
49417926a79SDavid Howells 
49517926a79SDavid Howells /*
4960d81a51aSDavid Howells  * call_event.c
49717926a79SDavid Howells  */
4980d12f8a4SDavid Howells void __rxrpc_propose_ACK(struct rxrpc_call *, u8, u32, bool);
4990d12f8a4SDavid Howells void rxrpc_propose_ACK(struct rxrpc_call *, u8, u32, bool);
500c1b1203dSJoe Perches void rxrpc_process_call(struct work_struct *);
50117926a79SDavid Howells 
50217926a79SDavid Howells /*
5030d81a51aSDavid Howells  * call_object.c
50417926a79SDavid Howells  */
505dad8aff7SDavid Howells extern unsigned int rxrpc_max_call_lifetime;
506dad8aff7SDavid Howells extern unsigned int rxrpc_dead_call_expiry;
50717926a79SDavid Howells extern struct kmem_cache *rxrpc_call_jar;
50817926a79SDavid Howells extern struct list_head rxrpc_calls;
50917926a79SDavid Howells extern rwlock_t rxrpc_call_lock;
51017926a79SDavid Howells 
5110d12f8a4SDavid Howells struct rxrpc_call *rxrpc_find_call_hash(struct rxrpc_host_header *,
5120d12f8a4SDavid Howells 					void *, sa_family_t, const void *);
5132341e077SDavid Howells struct rxrpc_call *rxrpc_find_call_by_user_ID(struct rxrpc_sock *, unsigned long);
5142341e077SDavid Howells struct rxrpc_call *rxrpc_new_client_call(struct rxrpc_sock *,
51517926a79SDavid Howells 					 struct rxrpc_transport *,
51617926a79SDavid Howells 					 struct rxrpc_conn_bundle *,
5172341e077SDavid Howells 					 unsigned long, gfp_t);
518c1b1203dSJoe Perches struct rxrpc_call *rxrpc_incoming_call(struct rxrpc_sock *,
51917926a79SDavid Howells 				       struct rxrpc_connection *,
520843099caSDavid Howells 				       struct rxrpc_host_header *);
521c1b1203dSJoe Perches void rxrpc_release_call(struct rxrpc_call *);
522c1b1203dSJoe Perches void rxrpc_release_calls_on_socket(struct rxrpc_sock *);
523c1b1203dSJoe Perches void __rxrpc_put_call(struct rxrpc_call *);
524c1b1203dSJoe Perches void __exit rxrpc_destroy_all_calls(void);
52517926a79SDavid Howells 
52617926a79SDavid Howells /*
5270d81a51aSDavid Howells  * conn_event.c
5280d81a51aSDavid Howells  */
5290d81a51aSDavid Howells void rxrpc_process_connection(struct work_struct *);
5300d81a51aSDavid Howells void rxrpc_reject_packet(struct rxrpc_local *, struct sk_buff *);
5314f95dd78SDavid Howells void rxrpc_reject_packets(struct rxrpc_local *);
5320d81a51aSDavid Howells 
5330d81a51aSDavid Howells /*
5340d81a51aSDavid Howells  * conn_object.c
53517926a79SDavid Howells  */
536dad8aff7SDavid Howells extern unsigned int rxrpc_connection_expiry;
53717926a79SDavid Howells extern struct list_head rxrpc_connections;
53817926a79SDavid Howells extern rwlock_t rxrpc_connection_lock;
53917926a79SDavid Howells 
540c1b1203dSJoe Perches struct rxrpc_conn_bundle *rxrpc_get_bundle(struct rxrpc_sock *,
54117926a79SDavid Howells 					   struct rxrpc_transport *,
5420d12f8a4SDavid Howells 					   struct key *, u16, gfp_t);
543c1b1203dSJoe Perches void rxrpc_put_bundle(struct rxrpc_transport *, struct rxrpc_conn_bundle *);
544c1b1203dSJoe Perches int rxrpc_connect_call(struct rxrpc_sock *, struct rxrpc_transport *,
545c1b1203dSJoe Perches 		       struct rxrpc_conn_bundle *, struct rxrpc_call *, gfp_t);
546c1b1203dSJoe Perches void rxrpc_put_connection(struct rxrpc_connection *);
547c1b1203dSJoe Perches void __exit rxrpc_destroy_all_connections(void);
548c1b1203dSJoe Perches struct rxrpc_connection *rxrpc_find_connection(struct rxrpc_transport *,
5490d12f8a4SDavid Howells 					       struct rxrpc_host_header *);
55017926a79SDavid Howells extern struct rxrpc_connection *
551843099caSDavid Howells rxrpc_incoming_connection(struct rxrpc_transport *, struct rxrpc_host_header *);
55217926a79SDavid Howells 
55317926a79SDavid Howells /*
5540d81a51aSDavid Howells  * input.c
55517926a79SDavid Howells  */
556676d2369SDavid S. Miller void rxrpc_data_ready(struct sock *);
557c1b1203dSJoe Perches int rxrpc_queue_rcv_skb(struct rxrpc_call *, struct sk_buff *, bool, bool);
558c1b1203dSJoe Perches void rxrpc_fast_process_packet(struct rxrpc_call *, struct sk_buff *);
55917926a79SDavid Howells 
56017926a79SDavid Howells /*
5610d81a51aSDavid Howells  * insecure.c
56217926a79SDavid Howells  */
5630d81a51aSDavid Howells extern const struct rxrpc_security rxrpc_no_security;
56417926a79SDavid Howells 
56517926a79SDavid Howells /*
5660d81a51aSDavid Howells  * key.c
56717926a79SDavid Howells  */
56817926a79SDavid Howells extern struct key_type key_type_rxrpc;
56917926a79SDavid Howells extern struct key_type key_type_rxrpc_s;
57017926a79SDavid Howells 
571c1b1203dSJoe Perches int rxrpc_request_key(struct rxrpc_sock *, char __user *, int);
572c1b1203dSJoe Perches int rxrpc_server_keyring(struct rxrpc_sock *, char __user *, int);
573c1b1203dSJoe Perches int rxrpc_get_server_data_key(struct rxrpc_connection *, const void *, time_t,
574c1b1203dSJoe Perches 			      u32);
57517926a79SDavid Howells 
57617926a79SDavid Howells /*
57787563616SDavid Howells  * local_event.c
57887563616SDavid Howells  */
5794f95dd78SDavid Howells extern void rxrpc_process_local_events(struct rxrpc_local *);
58087563616SDavid Howells 
58187563616SDavid Howells /*
5820d81a51aSDavid Howells  * local_object.c
58317926a79SDavid Howells  */
5844f95dd78SDavid Howells struct rxrpc_local *rxrpc_lookup_local(const struct sockaddr_rxrpc *);
5854f95dd78SDavid Howells void __rxrpc_put_local(struct rxrpc_local *);
5860d81a51aSDavid Howells void __exit rxrpc_destroy_all_locals(void);
587e0e4d82fSDavid Howells 
5884f95dd78SDavid Howells static inline void rxrpc_get_local(struct rxrpc_local *local)
5894f95dd78SDavid Howells {
5904f95dd78SDavid Howells 	atomic_inc(&local->usage);
5914f95dd78SDavid Howells }
5924f95dd78SDavid Howells 
5934f95dd78SDavid Howells static inline
5944f95dd78SDavid Howells struct rxrpc_local *rxrpc_get_local_maybe(struct rxrpc_local *local)
5954f95dd78SDavid Howells {
5964f95dd78SDavid Howells 	return atomic_inc_not_zero(&local->usage) ? local : NULL;
5974f95dd78SDavid Howells }
5984f95dd78SDavid Howells 
5994f95dd78SDavid Howells static inline void rxrpc_put_local(struct rxrpc_local *local)
6004f95dd78SDavid Howells {
6014f95dd78SDavid Howells 	if (atomic_dec_and_test(&local->usage))
6024f95dd78SDavid Howells 		__rxrpc_put_local(local);
6034f95dd78SDavid Howells }
6044f95dd78SDavid Howells 
605e0e4d82fSDavid Howells /*
6068e688d9cSDavid Howells  * misc.c
6078e688d9cSDavid Howells  */
6080e119b41SDavid Howells extern unsigned int rxrpc_max_backlog __read_mostly;
6098e688d9cSDavid Howells extern unsigned int rxrpc_requested_ack_delay;
6108e688d9cSDavid Howells extern unsigned int rxrpc_soft_ack_delay;
6118e688d9cSDavid Howells extern unsigned int rxrpc_idle_ack_delay;
6128e688d9cSDavid Howells extern unsigned int rxrpc_rx_window_size;
6138e688d9cSDavid Howells extern unsigned int rxrpc_rx_mtu;
6148e688d9cSDavid Howells extern unsigned int rxrpc_rx_jumbo_max;
6158e688d9cSDavid Howells 
6165b3e87f1SDavid Howells extern const char *const rxrpc_pkts[];
6178e688d9cSDavid Howells extern const s8 rxrpc_ack_priority[];
6188e688d9cSDavid Howells 
6198e688d9cSDavid Howells extern const char *rxrpc_acks(u8 reason);
6208e688d9cSDavid Howells 
6218e688d9cSDavid Howells /*
6220d81a51aSDavid Howells  * output.c
6230d81a51aSDavid Howells  */
6240d81a51aSDavid Howells extern unsigned int rxrpc_resend_timeout;
6250d81a51aSDavid Howells 
6260d81a51aSDavid Howells int rxrpc_send_packet(struct rxrpc_transport *, struct sk_buff *);
6270d81a51aSDavid Howells int rxrpc_do_sendmsg(struct rxrpc_sock *, struct msghdr *, size_t);
6280d81a51aSDavid Howells 
6290d81a51aSDavid Howells /*
630abe89ef0SDavid Howells  * peer_event.c
6310d81a51aSDavid Howells  */
632abe89ef0SDavid Howells void rxrpc_error_report(struct sock *);
633f66d7490SDavid Howells void rxrpc_peer_error_distributor(struct work_struct *);
6340d81a51aSDavid Howells 
6350d81a51aSDavid Howells /*
6360d81a51aSDavid Howells  * peer_object.c
6370d81a51aSDavid Howells  */
638be6e6707SDavid Howells struct rxrpc_peer *rxrpc_lookup_peer_rcu(struct rxrpc_local *,
639be6e6707SDavid Howells 					 const struct sockaddr_rxrpc *);
640be6e6707SDavid Howells struct rxrpc_peer *rxrpc_lookup_peer(struct rxrpc_local *,
641be6e6707SDavid Howells 				     struct sockaddr_rxrpc *, gfp_t);
642be6e6707SDavid Howells struct rxrpc_peer *rxrpc_alloc_peer(struct rxrpc_local *, gfp_t);
643be6e6707SDavid Howells 
644be6e6707SDavid Howells static inline void rxrpc_get_peer(struct rxrpc_peer *peer)
645be6e6707SDavid Howells {
646be6e6707SDavid Howells 	atomic_inc(&peer->usage);
647be6e6707SDavid Howells }
648be6e6707SDavid Howells 
649be6e6707SDavid Howells static inline
650be6e6707SDavid Howells struct rxrpc_peer *rxrpc_get_peer_maybe(struct rxrpc_peer *peer)
651be6e6707SDavid Howells {
652be6e6707SDavid Howells 	return atomic_inc_not_zero(&peer->usage) ? peer : NULL;
653be6e6707SDavid Howells }
654be6e6707SDavid Howells 
655be6e6707SDavid Howells extern void __rxrpc_put_peer(struct rxrpc_peer *peer);
656be6e6707SDavid Howells static inline void rxrpc_put_peer(struct rxrpc_peer *peer)
657be6e6707SDavid Howells {
658be6e6707SDavid Howells 	if (atomic_dec_and_test(&peer->usage))
659be6e6707SDavid Howells 		__rxrpc_put_peer(peer);
660be6e6707SDavid Howells }
6610d81a51aSDavid Howells 
6620d81a51aSDavid Howells /*
6630d81a51aSDavid Howells  * proc.c
6640d81a51aSDavid Howells  */
6650d81a51aSDavid Howells extern const char *const rxrpc_call_states[];
6660d81a51aSDavid Howells extern const struct file_operations rxrpc_call_seq_fops;
6670d81a51aSDavid Howells extern const struct file_operations rxrpc_connection_seq_fops;
6680d81a51aSDavid Howells 
6690d81a51aSDavid Howells /*
6700d81a51aSDavid Howells  * recvmsg.c
6710d81a51aSDavid Howells  */
6720d81a51aSDavid Howells void rxrpc_remove_user_ID(struct rxrpc_sock *, struct rxrpc_call *);
6730d81a51aSDavid Howells int rxrpc_recvmsg(struct socket *, struct msghdr *, size_t, int);
6740d81a51aSDavid Howells 
6750d81a51aSDavid Howells /*
676648af7fcSDavid Howells  * rxkad.c
677648af7fcSDavid Howells  */
678648af7fcSDavid Howells #ifdef CONFIG_RXKAD
679648af7fcSDavid Howells extern const struct rxrpc_security rxkad;
680648af7fcSDavid Howells #endif
681648af7fcSDavid Howells 
682648af7fcSDavid Howells /*
6830d81a51aSDavid Howells  * security.c
6840d81a51aSDavid Howells  */
6850d81a51aSDavid Howells int __init rxrpc_init_security(void);
6860d81a51aSDavid Howells void rxrpc_exit_security(void);
6870d81a51aSDavid Howells int rxrpc_init_client_conn_security(struct rxrpc_connection *);
6880d81a51aSDavid Howells int rxrpc_init_server_conn_security(struct rxrpc_connection *);
6890d81a51aSDavid Howells 
6900d81a51aSDavid Howells /*
6910d81a51aSDavid Howells  * skbuff.c
6920d81a51aSDavid Howells  */
6930d81a51aSDavid Howells void rxrpc_packet_destructor(struct sk_buff *);
6940d81a51aSDavid Howells 
6950d81a51aSDavid Howells /*
6965873c083SDavid Howells  * sysctl.c
6975873c083SDavid Howells  */
6985873c083SDavid Howells #ifdef CONFIG_SYSCTL
6995873c083SDavid Howells extern int __init rxrpc_sysctl_init(void);
7005873c083SDavid Howells extern void rxrpc_sysctl_exit(void);
7015873c083SDavid Howells #else
7025873c083SDavid Howells static inline int __init rxrpc_sysctl_init(void) { return 0; }
7035873c083SDavid Howells static inline void rxrpc_sysctl_exit(void) {}
7045873c083SDavid Howells #endif
7055873c083SDavid Howells 
7065873c083SDavid Howells /*
7070d81a51aSDavid Howells  * transport.c
7080d81a51aSDavid Howells  */
7090d81a51aSDavid Howells extern unsigned int rxrpc_transport_expiry;
7100d81a51aSDavid Howells 
7110d81a51aSDavid Howells struct rxrpc_transport *rxrpc_get_transport(struct rxrpc_local *,
7120d81a51aSDavid Howells 					    struct rxrpc_peer *, gfp_t);
7130d81a51aSDavid Howells void rxrpc_put_transport(struct rxrpc_transport *);
7140d81a51aSDavid Howells void __exit rxrpc_destroy_all_transports(void);
7150d81a51aSDavid Howells struct rxrpc_transport *rxrpc_find_transport(struct rxrpc_local *,
7160d81a51aSDavid Howells 					     struct rxrpc_peer *);
7170d81a51aSDavid Howells 
7180d81a51aSDavid Howells /*
719be6e6707SDavid Howells  * utils.c
720be6e6707SDavid Howells  */
721be6e6707SDavid Howells void rxrpc_get_addr_from_skb(struct rxrpc_local *, const struct sk_buff *,
722be6e6707SDavid Howells 			     struct sockaddr_rxrpc *);
723be6e6707SDavid Howells 
724be6e6707SDavid Howells /*
72517926a79SDavid Howells  * debug tracing
72617926a79SDavid Howells  */
72795c96174SEric Dumazet extern unsigned int rxrpc_debug;
72817926a79SDavid Howells 
72917926a79SDavid Howells #define dbgprintk(FMT,...) \
7309f389f4bSSven Schnelle 	printk("[%-6.6s] "FMT"\n", current->comm ,##__VA_ARGS__)
73117926a79SDavid Howells 
7320dc47877SHarvey Harrison #define kenter(FMT,...)	dbgprintk("==> %s("FMT")",__func__ ,##__VA_ARGS__)
7330dc47877SHarvey Harrison #define kleave(FMT,...)	dbgprintk("<== %s()"FMT"",__func__ ,##__VA_ARGS__)
73417926a79SDavid Howells #define kdebug(FMT,...)	dbgprintk("    "FMT ,##__VA_ARGS__)
73517926a79SDavid Howells #define kproto(FMT,...)	dbgprintk("### "FMT ,##__VA_ARGS__)
73617926a79SDavid Howells #define knet(FMT,...)	dbgprintk("@@@ "FMT ,##__VA_ARGS__)
73717926a79SDavid Howells 
73817926a79SDavid Howells 
73917926a79SDavid Howells #if defined(__KDEBUG)
74017926a79SDavid Howells #define _enter(FMT,...)	kenter(FMT,##__VA_ARGS__)
74117926a79SDavid Howells #define _leave(FMT,...)	kleave(FMT,##__VA_ARGS__)
74217926a79SDavid Howells #define _debug(FMT,...)	kdebug(FMT,##__VA_ARGS__)
74317926a79SDavid Howells #define _proto(FMT,...)	kproto(FMT,##__VA_ARGS__)
74417926a79SDavid Howells #define _net(FMT,...)	knet(FMT,##__VA_ARGS__)
74517926a79SDavid Howells 
74617926a79SDavid Howells #elif defined(CONFIG_AF_RXRPC_DEBUG)
74717926a79SDavid Howells #define RXRPC_DEBUG_KENTER	0x01
74817926a79SDavid Howells #define RXRPC_DEBUG_KLEAVE	0x02
74917926a79SDavid Howells #define RXRPC_DEBUG_KDEBUG	0x04
75017926a79SDavid Howells #define RXRPC_DEBUG_KPROTO	0x08
75117926a79SDavid Howells #define RXRPC_DEBUG_KNET	0x10
75217926a79SDavid Howells 
75317926a79SDavid Howells #define _enter(FMT,...)					\
75417926a79SDavid Howells do {							\
75517926a79SDavid Howells 	if (unlikely(rxrpc_debug & RXRPC_DEBUG_KENTER))	\
75617926a79SDavid Howells 		kenter(FMT,##__VA_ARGS__);		\
75717926a79SDavid Howells } while (0)
75817926a79SDavid Howells 
75917926a79SDavid Howells #define _leave(FMT,...)					\
76017926a79SDavid Howells do {							\
76117926a79SDavid Howells 	if (unlikely(rxrpc_debug & RXRPC_DEBUG_KLEAVE))	\
76217926a79SDavid Howells 		kleave(FMT,##__VA_ARGS__);		\
76317926a79SDavid Howells } while (0)
76417926a79SDavid Howells 
76517926a79SDavid Howells #define _debug(FMT,...)					\
76617926a79SDavid Howells do {							\
76717926a79SDavid Howells 	if (unlikely(rxrpc_debug & RXRPC_DEBUG_KDEBUG))	\
76817926a79SDavid Howells 		kdebug(FMT,##__VA_ARGS__);		\
76917926a79SDavid Howells } while (0)
77017926a79SDavid Howells 
77117926a79SDavid Howells #define _proto(FMT,...)					\
77217926a79SDavid Howells do {							\
77317926a79SDavid Howells 	if (unlikely(rxrpc_debug & RXRPC_DEBUG_KPROTO))	\
77417926a79SDavid Howells 		kproto(FMT,##__VA_ARGS__);		\
77517926a79SDavid Howells } while (0)
77617926a79SDavid Howells 
77717926a79SDavid Howells #define _net(FMT,...)					\
77817926a79SDavid Howells do {							\
77917926a79SDavid Howells 	if (unlikely(rxrpc_debug & RXRPC_DEBUG_KNET))	\
78017926a79SDavid Howells 		knet(FMT,##__VA_ARGS__);		\
78117926a79SDavid Howells } while (0)
78217926a79SDavid Howells 
78317926a79SDavid Howells #else
78412fdff3fSDavid Howells #define _enter(FMT,...)	no_printk("==> %s("FMT")",__func__ ,##__VA_ARGS__)
78512fdff3fSDavid Howells #define _leave(FMT,...)	no_printk("<== %s()"FMT"",__func__ ,##__VA_ARGS__)
78612fdff3fSDavid Howells #define _debug(FMT,...)	no_printk("    "FMT ,##__VA_ARGS__)
78712fdff3fSDavid Howells #define _proto(FMT,...)	no_printk("### "FMT ,##__VA_ARGS__)
78812fdff3fSDavid Howells #define _net(FMT,...)	no_printk("@@@ "FMT ,##__VA_ARGS__)
78917926a79SDavid Howells #endif
79017926a79SDavid Howells 
79117926a79SDavid Howells /*
79217926a79SDavid Howells  * debug assertion checking
79317926a79SDavid Howells  */
79417926a79SDavid Howells #if 1 // defined(__KDEBUGALL)
79517926a79SDavid Howells 
79617926a79SDavid Howells #define ASSERT(X)						\
79717926a79SDavid Howells do {								\
79817926a79SDavid Howells 	if (unlikely(!(X))) {					\
7999b6d5398SJoe Perches 		pr_err("Assertion failed\n");			\
80017926a79SDavid Howells 		BUG();						\
80117926a79SDavid Howells 	}							\
80217926a79SDavid Howells } while (0)
80317926a79SDavid Howells 
80417926a79SDavid Howells #define ASSERTCMP(X, OP, Y)						\
80517926a79SDavid Howells do {									\
8069b6d5398SJoe Perches 	unsigned long _x = (unsigned long)(X);				\
8079b6d5398SJoe Perches 	unsigned long _y = (unsigned long)(Y);				\
8089b6d5398SJoe Perches 	if (unlikely(!(_x OP _y))) {					\
8099b6d5398SJoe Perches 		pr_err("Assertion failed - %lu(0x%lx) %s %lu(0x%lx) is false\n",			\
8109b6d5398SJoe Perches 		       _x, _x, #OP, _y, _y);				\
81117926a79SDavid Howells 		BUG();							\
81217926a79SDavid Howells 	}								\
81317926a79SDavid Howells } while (0)
81417926a79SDavid Howells 
81517926a79SDavid Howells #define ASSERTIF(C, X)						\
81617926a79SDavid Howells do {								\
81717926a79SDavid Howells 	if (unlikely((C) && !(X))) {				\
8189b6d5398SJoe Perches 		pr_err("Assertion failed\n");			\
81917926a79SDavid Howells 		BUG();						\
82017926a79SDavid Howells 	}							\
82117926a79SDavid Howells } while (0)
82217926a79SDavid Howells 
82317926a79SDavid Howells #define ASSERTIFCMP(C, X, OP, Y)					\
82417926a79SDavid Howells do {									\
8259b6d5398SJoe Perches 	unsigned long _x = (unsigned long)(X);				\
8269b6d5398SJoe Perches 	unsigned long _y = (unsigned long)(Y);				\
8279b6d5398SJoe Perches 	if (unlikely((C) && !(_x OP _y))) {				\
8289b6d5398SJoe Perches 		pr_err("Assertion failed - %lu(0x%lx) %s %lu(0x%lx) is false\n", \
8299b6d5398SJoe Perches 		       _x, _x, #OP, _y, _y);				\
83017926a79SDavid Howells 		BUG();							\
83117926a79SDavid Howells 	}								\
83217926a79SDavid Howells } while (0)
83317926a79SDavid Howells 
83417926a79SDavid Howells #else
83517926a79SDavid Howells 
83617926a79SDavid Howells #define ASSERT(X)				\
83717926a79SDavid Howells do {						\
83817926a79SDavid Howells } while (0)
83917926a79SDavid Howells 
84017926a79SDavid Howells #define ASSERTCMP(X, OP, Y)			\
84117926a79SDavid Howells do {						\
84217926a79SDavid Howells } while (0)
84317926a79SDavid Howells 
84417926a79SDavid Howells #define ASSERTIF(C, X)				\
84517926a79SDavid Howells do {						\
84617926a79SDavid Howells } while (0)
84717926a79SDavid Howells 
84817926a79SDavid Howells #define ASSERTIFCMP(C, X, OP, Y)		\
84917926a79SDavid Howells do {						\
85017926a79SDavid Howells } while (0)
85117926a79SDavid Howells 
85217926a79SDavid Howells #endif /* __KDEBUGALL */
85317926a79SDavid Howells 
85417926a79SDavid Howells /*
85517926a79SDavid Howells  * socket buffer accounting / leak finding
85617926a79SDavid Howells  */
85717926a79SDavid Howells static inline void __rxrpc_new_skb(struct sk_buff *skb, const char *fn)
85817926a79SDavid Howells {
85917926a79SDavid Howells 	//_net("new skb %p %s [%d]", skb, fn, atomic_read(&rxrpc_n_skbs));
86017926a79SDavid Howells 	//atomic_inc(&rxrpc_n_skbs);
86117926a79SDavid Howells }
86217926a79SDavid Howells 
86317926a79SDavid Howells #define rxrpc_new_skb(skb) __rxrpc_new_skb((skb), __func__)
86417926a79SDavid Howells 
86517926a79SDavid Howells static inline void __rxrpc_kill_skb(struct sk_buff *skb, const char *fn)
86617926a79SDavid Howells {
86717926a79SDavid Howells 	//_net("kill skb %p %s [%d]", skb, fn, atomic_read(&rxrpc_n_skbs));
86817926a79SDavid Howells 	//atomic_dec(&rxrpc_n_skbs);
86917926a79SDavid Howells }
87017926a79SDavid Howells 
87117926a79SDavid Howells #define rxrpc_kill_skb(skb) __rxrpc_kill_skb((skb), __func__)
87217926a79SDavid Howells 
87317926a79SDavid Howells static inline void __rxrpc_free_skb(struct sk_buff *skb, const char *fn)
87417926a79SDavid Howells {
87517926a79SDavid Howells 	if (skb) {
87617926a79SDavid Howells 		CHECK_SLAB_OKAY(&skb->users);
87717926a79SDavid Howells 		//_net("free skb %p %s [%d]",
87817926a79SDavid Howells 		//     skb, fn, atomic_read(&rxrpc_n_skbs));
87917926a79SDavid Howells 		//atomic_dec(&rxrpc_n_skbs);
88017926a79SDavid Howells 		kfree_skb(skb);
88117926a79SDavid Howells 	}
88217926a79SDavid Howells }
88317926a79SDavid Howells 
88417926a79SDavid Howells #define rxrpc_free_skb(skb) __rxrpc_free_skb((skb), __func__)
88517926a79SDavid Howells 
88617926a79SDavid Howells static inline void rxrpc_purge_queue(struct sk_buff_head *list)
88717926a79SDavid Howells {
88817926a79SDavid Howells 	struct sk_buff *skb;
88917926a79SDavid Howells 	while ((skb = skb_dequeue((list))) != NULL)
89017926a79SDavid Howells 		rxrpc_free_skb(skb);
89117926a79SDavid Howells }
89217926a79SDavid Howells 
89317926a79SDavid Howells #define rxrpc_get_call(CALL)				\
89417926a79SDavid Howells do {							\
89517926a79SDavid Howells 	CHECK_SLAB_OKAY(&(CALL)->usage);		\
89617926a79SDavid Howells 	if (atomic_inc_return(&(CALL)->usage) == 1)	\
89717926a79SDavid Howells 		BUG();					\
89817926a79SDavid Howells } while (0)
89917926a79SDavid Howells 
90017926a79SDavid Howells #define rxrpc_put_call(CALL)				\
90117926a79SDavid Howells do {							\
90217926a79SDavid Howells 	__rxrpc_put_call(CALL);				\
90317926a79SDavid Howells } while (0)
904