xref: /openbmc/linux/net/rxrpc/ar-internal.h (revision 651350d1)
1 /* AF_RXRPC internal definitions
2  *
3  * Copyright (C) 2007 Red Hat, Inc. All Rights Reserved.
4  * Written by David Howells (dhowells@redhat.com)
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * as published by the Free Software Foundation; either version
9  * 2 of the License, or (at your option) any later version.
10  */
11 
12 #include <rxrpc/packet.h>
13 
14 #if 0
15 #define CHECK_SLAB_OKAY(X)				     \
16 	BUG_ON(atomic_read((X)) >> (sizeof(atomic_t) - 2) == \
17 	       (POISON_FREE << 8 | POISON_FREE))
18 #else
19 #define CHECK_SLAB_OKAY(X) do {} while(0)
20 #endif
21 
22 #define FCRYPT_BSIZE 8
23 struct rxrpc_crypt {
24 	union {
25 		u8	x[FCRYPT_BSIZE];
26 		u32	n[2];
27 	};
28 } __attribute__((aligned(8)));
29 
30 #define rxrpc_queue_work(WS)	queue_work(rxrpc_workqueue, (WS))
31 #define rxrpc_queue_delayed_work(WS,D)	\
32 	queue_delayed_work(rxrpc_workqueue, (WS), (D))
33 
34 #define rxrpc_queue_call(CALL)	rxrpc_queue_work(&(CALL)->processor)
35 #define rxrpc_queue_conn(CONN)	rxrpc_queue_work(&(CONN)->processor)
36 
37 /*
38  * sk_state for RxRPC sockets
39  */
40 enum {
41 	RXRPC_UNCONNECTED = 0,
42 	RXRPC_CLIENT_BOUND,		/* client local address bound */
43 	RXRPC_CLIENT_CONNECTED,		/* client is connected */
44 	RXRPC_SERVER_BOUND,		/* server local address bound */
45 	RXRPC_SERVER_LISTENING,		/* server listening for connections */
46 	RXRPC_CLOSE,			/* socket is being closed */
47 };
48 
49 /*
50  * RxRPC socket definition
51  */
52 struct rxrpc_sock {
53 	/* WARNING: sk has to be the first member */
54 	struct sock		sk;
55 	rxrpc_interceptor_t	interceptor;	/* kernel service Rx interceptor function */
56 	struct rxrpc_local	*local;		/* local endpoint */
57 	struct rxrpc_transport	*trans;		/* transport handler */
58 	struct rxrpc_conn_bundle *bundle;	/* virtual connection bundle */
59 	struct rxrpc_connection	*conn;		/* exclusive virtual connection */
60 	struct list_head	listen_link;	/* link in the local endpoint's listen list */
61 	struct list_head	secureq;	/* calls awaiting connection security clearance */
62 	struct list_head	acceptq;	/* calls awaiting acceptance */
63 	struct key		*key;		/* security for this socket */
64 	struct key		*securities;	/* list of server security descriptors */
65 	struct rb_root		calls;		/* outstanding calls on this socket */
66 	unsigned long		flags;
67 #define RXRPC_SOCK_EXCLUSIVE_CONN	1	/* exclusive connection for a client socket */
68 	rwlock_t		call_lock;	/* lock for calls */
69 	u32			min_sec_level;	/* minimum security level */
70 #define RXRPC_SECURITY_MAX	RXRPC_SECURITY_ENCRYPT
71 	struct sockaddr_rxrpc	srx;		/* local address */
72 	sa_family_t		proto;		/* protocol created with */
73 	__be16			service_id;	/* service ID of local/remote service */
74 };
75 
76 #define rxrpc_sk(__sk) container_of((__sk), struct rxrpc_sock, sk)
77 
78 /*
79  * RxRPC socket buffer private variables
80  * - max 48 bytes (struct sk_buff::cb)
81  */
82 struct rxrpc_skb_priv {
83 	struct rxrpc_call	*call;		/* call with which associated */
84 	unsigned long		resend_at;	/* time in jiffies at which to resend */
85 	union {
86 		unsigned	offset;		/* offset into buffer of next read */
87 		int		remain;		/* amount of space remaining for next write */
88 		u32		error;		/* network error code */
89 		bool		need_resend;	/* T if needs resending */
90 	};
91 
92 	struct rxrpc_header	hdr;		/* RxRPC packet header from this packet */
93 };
94 
95 #define rxrpc_skb(__skb) ((struct rxrpc_skb_priv *) &(__skb)->cb)
96 
97 enum rxrpc_command {
98 	RXRPC_CMD_SEND_DATA,		/* send data message */
99 	RXRPC_CMD_SEND_ABORT,		/* request abort generation */
100 	RXRPC_CMD_ACCEPT,		/* [server] accept incoming call */
101 	RXRPC_CMD_REJECT_BUSY,		/* [server] reject a call as busy */
102 };
103 
104 /*
105  * RxRPC security module interface
106  */
107 struct rxrpc_security {
108 	struct module		*owner;		/* providing module */
109 	struct list_head	link;		/* link in master list */
110 	const char		*name;		/* name of this service */
111 	u8			security_index;	/* security type provided */
112 
113 	/* initialise a connection's security */
114 	int (*init_connection_security)(struct rxrpc_connection *);
115 
116 	/* prime a connection's packet security */
117 	void (*prime_packet_security)(struct rxrpc_connection *);
118 
119 	/* impose security on a packet */
120 	int (*secure_packet)(const struct rxrpc_call *,
121 			     struct sk_buff *,
122 			     size_t,
123 			     void *);
124 
125 	/* verify the security on a received packet */
126 	int (*verify_packet)(const struct rxrpc_call *, struct sk_buff *,
127 			     u32 *);
128 
129 	/* issue a challenge */
130 	int (*issue_challenge)(struct rxrpc_connection *);
131 
132 	/* respond to a challenge */
133 	int (*respond_to_challenge)(struct rxrpc_connection *,
134 				    struct sk_buff *,
135 				    u32 *);
136 
137 	/* verify a response */
138 	int (*verify_response)(struct rxrpc_connection *,
139 			       struct sk_buff *,
140 			       u32 *);
141 
142 	/* clear connection security */
143 	void (*clear)(struct rxrpc_connection *);
144 };
145 
146 /*
147  * RxRPC local transport endpoint definition
148  * - matched by local port, address and protocol type
149  */
150 struct rxrpc_local {
151 	struct socket		*socket;	/* my UDP socket */
152 	struct work_struct	destroyer;	/* endpoint destroyer */
153 	struct work_struct	acceptor;	/* incoming call processor */
154 	struct work_struct	rejecter;	/* packet reject writer */
155 	struct list_head	services;	/* services listening on this endpoint */
156 	struct list_head	link;		/* link in endpoint list */
157 	struct rw_semaphore	defrag_sem;	/* control re-enablement of IP DF bit */
158 	struct sk_buff_head	accept_queue;	/* incoming calls awaiting acceptance */
159 	struct sk_buff_head	reject_queue;	/* packets awaiting rejection */
160 	spinlock_t		lock;		/* access lock */
161 	rwlock_t		services_lock;	/* lock for services list */
162 	atomic_t		usage;
163 	int			debug_id;	/* debug ID for printks */
164 	volatile char		error_rcvd;	/* T if received ICMP error outstanding */
165 	struct sockaddr_rxrpc	srx;		/* local address */
166 };
167 
168 /*
169  * RxRPC remote transport endpoint definition
170  * - matched by remote port, address and protocol type
171  * - holds the connection ID counter for connections between the two endpoints
172  */
173 struct rxrpc_peer {
174 	struct work_struct	destroyer;	/* peer destroyer */
175 	struct list_head	link;		/* link in master peer list */
176 	struct list_head	error_targets;	/* targets for net error distribution */
177 	spinlock_t		lock;		/* access lock */
178 	atomic_t		usage;
179 	unsigned		if_mtu;		/* interface MTU for this peer */
180 	unsigned		mtu;		/* network MTU for this peer */
181 	unsigned		maxdata;	/* data size (MTU - hdrsize) */
182 	unsigned short		hdrsize;	/* header size (IP + UDP + RxRPC) */
183 	int			debug_id;	/* debug ID for printks */
184 	int			net_error;	/* network error distributed */
185 	struct sockaddr_rxrpc	srx;		/* remote address */
186 
187 	/* calculated RTT cache */
188 #define RXRPC_RTT_CACHE_SIZE 32
189 	suseconds_t		rtt;		/* current RTT estimate (in uS) */
190 	unsigned		rtt_point;	/* next entry at which to insert */
191 	unsigned		rtt_usage;	/* amount of cache actually used */
192 	suseconds_t		rtt_cache[RXRPC_RTT_CACHE_SIZE]; /* calculated RTT cache */
193 };
194 
195 /*
196  * RxRPC point-to-point transport / connection manager definition
197  * - handles a bundle of connections between two endpoints
198  * - matched by { local, peer }
199  */
200 struct rxrpc_transport {
201 	struct rxrpc_local	*local;		/* local transport endpoint */
202 	struct rxrpc_peer	*peer;		/* remote transport endpoint */
203 	struct work_struct	error_handler;	/* network error distributor */
204 	struct rb_root		bundles;	/* client connection bundles on this transport */
205 	struct rb_root		client_conns;	/* client connections on this transport */
206 	struct rb_root		server_conns;	/* server connections on this transport */
207 	struct list_head	link;		/* link in master session list */
208 	struct sk_buff_head	error_queue;	/* error packets awaiting processing */
209 	time_t			put_time;	/* time at which to reap */
210 	spinlock_t		client_lock;	/* client connection allocation lock */
211 	rwlock_t		conn_lock;	/* lock for active/dead connections */
212 	atomic_t		usage;
213 	int			debug_id;	/* debug ID for printks */
214 	unsigned int		conn_idcounter;	/* connection ID counter (client) */
215 };
216 
217 /*
218  * RxRPC client connection bundle
219  * - matched by { transport, service_id, key }
220  */
221 struct rxrpc_conn_bundle {
222 	struct rb_node		node;		/* node in transport's lookup tree */
223 	struct list_head	unused_conns;	/* unused connections in this bundle */
224 	struct list_head	avail_conns;	/* available connections in this bundle */
225 	struct list_head	busy_conns;	/* busy connections in this bundle */
226 	struct key		*key;		/* security for this bundle */
227 	wait_queue_head_t	chanwait;	/* wait for channel to become available */
228 	atomic_t		usage;
229 	int			debug_id;	/* debug ID for printks */
230 	unsigned short		num_conns;	/* number of connections in this bundle */
231 	__be16			service_id;	/* service ID */
232 	uint8_t			security_ix;	/* security type */
233 };
234 
235 /*
236  * RxRPC connection definition
237  * - matched by { transport, service_id, conn_id, direction, key }
238  * - each connection can only handle four simultaneous calls
239  */
240 struct rxrpc_connection {
241 	struct rxrpc_transport	*trans;		/* transport session */
242 	struct rxrpc_conn_bundle *bundle;	/* connection bundle (client) */
243 	struct work_struct	processor;	/* connection event processor */
244 	struct rb_node		node;		/* node in transport's lookup tree */
245 	struct list_head	link;		/* link in master connection list */
246 	struct list_head	bundle_link;	/* link in bundle */
247 	struct rb_root		calls;		/* calls on this connection */
248 	struct sk_buff_head	rx_queue;	/* received conn-level packets */
249 	struct rxrpc_call	*channels[RXRPC_MAXCALLS]; /* channels (active calls) */
250 	struct rxrpc_security	*security;	/* applied security module */
251 	struct key		*key;		/* security for this connection (client) */
252 	struct key		*server_key;	/* security for this service */
253 	struct crypto_blkcipher	*cipher;	/* encryption handle */
254 	struct rxrpc_crypt	csum_iv;	/* packet checksum base */
255 	unsigned long		events;
256 #define RXRPC_CONN_CHALLENGE	0		/* send challenge packet */
257 	time_t			put_time;	/* time at which to reap */
258 	rwlock_t		lock;		/* access lock */
259 	spinlock_t		state_lock;	/* state-change lock */
260 	atomic_t		usage;
261 	u32			real_conn_id;	/* connection ID (host-endian) */
262 	enum {					/* current state of connection */
263 		RXRPC_CONN_UNUSED,		/* - connection not yet attempted */
264 		RXRPC_CONN_CLIENT,		/* - client connection */
265 		RXRPC_CONN_SERVER_UNSECURED,	/* - server unsecured connection */
266 		RXRPC_CONN_SERVER_CHALLENGING,	/* - server challenging for security */
267 		RXRPC_CONN_SERVER,		/* - server secured connection */
268 		RXRPC_CONN_REMOTELY_ABORTED,	/* - conn aborted by peer */
269 		RXRPC_CONN_LOCALLY_ABORTED,	/* - conn aborted locally */
270 		RXRPC_CONN_NETWORK_ERROR,	/* - conn terminated by network error */
271 	} state;
272 	int			error;		/* error code for local abort */
273 	int			debug_id;	/* debug ID for printks */
274 	unsigned		call_counter;	/* call ID counter */
275 	atomic_t		serial;		/* packet serial number counter */
276 	atomic_t		hi_serial;	/* highest serial number received */
277 	u8			avail_calls;	/* number of calls available */
278 	u8			size_align;	/* data size alignment (for security) */
279 	u8			header_size;	/* rxrpc + security header size */
280 	u8			security_size;	/* security header size */
281 	u32			security_level;	/* security level negotiated */
282 	u32			security_nonce;	/* response re-use preventer */
283 
284 	/* the following are all in net order */
285 	__be32			epoch;		/* epoch of this connection */
286 	__be32			cid;		/* connection ID */
287 	__be16			service_id;	/* service ID */
288 	u8			security_ix;	/* security type */
289 	u8			in_clientflag;	/* RXRPC_CLIENT_INITIATED if we are server */
290 	u8			out_clientflag;	/* RXRPC_CLIENT_INITIATED if we are client */
291 };
292 
293 /*
294  * RxRPC call definition
295  * - matched by { connection, call_id }
296  */
297 struct rxrpc_call {
298 	struct rxrpc_connection	*conn;		/* connection carrying call */
299 	struct rxrpc_sock	*socket;	/* socket responsible */
300 	struct timer_list	lifetimer;	/* lifetime remaining on call */
301 	struct timer_list	deadspan;	/* reap timer for re-ACK'ing, etc  */
302 	struct timer_list	ack_timer;	/* ACK generation timer */
303 	struct timer_list	resend_timer;	/* Tx resend timer */
304 	struct work_struct	destroyer;	/* call destroyer */
305 	struct work_struct	processor;	/* packet processor and ACK generator */
306 	struct list_head	link;		/* link in master call list */
307 	struct list_head	error_link;	/* link in error distribution list */
308 	struct list_head	accept_link;	/* calls awaiting acceptance */
309 	struct rb_node		sock_node;	/* node in socket call tree */
310 	struct rb_node		conn_node;	/* node in connection call tree */
311 	struct sk_buff_head	rx_queue;	/* received packets */
312 	struct sk_buff_head	rx_oos_queue;	/* packets received out of sequence */
313 	struct sk_buff		*tx_pending;	/* Tx socket buffer being filled */
314 	wait_queue_head_t	tx_waitq;	/* wait for Tx window space to become available */
315 	unsigned long		user_call_ID;	/* user-defined call ID */
316 	unsigned long		creation_jif;	/* time of call creation */
317 	unsigned long		flags;
318 #define RXRPC_CALL_RELEASED	0	/* call has been released - no more message to userspace */
319 #define RXRPC_CALL_TERMINAL_MSG	1	/* call has given the socket its final message */
320 #define RXRPC_CALL_RCVD_LAST	2	/* all packets received */
321 #define RXRPC_CALL_RUN_RTIMER	3	/* Tx resend timer started */
322 #define RXRPC_CALL_TX_SOFT_ACK	4	/* sent some soft ACKs */
323 #define RXRPC_CALL_PROC_BUSY	5	/* the processor is busy */
324 #define RXRPC_CALL_INIT_ACCEPT	6	/* acceptance was initiated */
325 #define RXRPC_CALL_HAS_USERID	7	/* has a user ID attached */
326 #define RXRPC_CALL_EXPECT_OOS	8	/* expect out of sequence packets */
327 	unsigned long		events;
328 #define RXRPC_CALL_RCVD_ACKALL	0	/* ACKALL or reply received */
329 #define RXRPC_CALL_RCVD_BUSY	1	/* busy packet received */
330 #define RXRPC_CALL_RCVD_ABORT	2	/* abort packet received */
331 #define RXRPC_CALL_RCVD_ERROR	3	/* network error received */
332 #define RXRPC_CALL_ACK_FINAL	4	/* need to generate final ACK (and release call) */
333 #define RXRPC_CALL_ACK		5	/* need to generate ACK */
334 #define RXRPC_CALL_REJECT_BUSY	6	/* need to generate busy message */
335 #define RXRPC_CALL_ABORT	7	/* need to generate abort */
336 #define RXRPC_CALL_CONN_ABORT	8	/* local connection abort generated */
337 #define RXRPC_CALL_RESEND_TIMER	9	/* Tx resend timer expired */
338 #define RXRPC_CALL_RESEND	10	/* Tx resend required */
339 #define RXRPC_CALL_DRAIN_RX_OOS	11	/* drain the Rx out of sequence queue */
340 #define RXRPC_CALL_LIFE_TIMER	12	/* call's lifetimer ran out */
341 #define RXRPC_CALL_ACCEPTED	13	/* incoming call accepted by userspace app */
342 #define RXRPC_CALL_SECURED	14	/* incoming call's connection is now secure */
343 #define RXRPC_CALL_POST_ACCEPT	15	/* need to post an "accept?" message to the app */
344 #define RXRPC_CALL_RELEASE	16	/* need to release the call's resources */
345 
346 	spinlock_t		lock;
347 	rwlock_t		state_lock;	/* lock for state transition */
348 	atomic_t		usage;
349 	atomic_t		sequence;	/* Tx data packet sequence counter */
350 	u32			abort_code;	/* local/remote abort code */
351 	enum {					/* current state of call */
352 		RXRPC_CALL_CLIENT_SEND_REQUEST,	/* - client sending request phase */
353 		RXRPC_CALL_CLIENT_AWAIT_REPLY,	/* - client awaiting reply */
354 		RXRPC_CALL_CLIENT_RECV_REPLY,	/* - client receiving reply phase */
355 		RXRPC_CALL_CLIENT_FINAL_ACK,	/* - client sending final ACK phase */
356 		RXRPC_CALL_SERVER_SECURING,	/* - server securing request connection */
357 		RXRPC_CALL_SERVER_ACCEPTING,	/* - server accepting request */
358 		RXRPC_CALL_SERVER_RECV_REQUEST,	/* - server receiving request */
359 		RXRPC_CALL_SERVER_ACK_REQUEST,	/* - server pending ACK of request */
360 		RXRPC_CALL_SERVER_SEND_REPLY,	/* - server sending reply */
361 		RXRPC_CALL_SERVER_AWAIT_ACK,	/* - server awaiting final ACK */
362 		RXRPC_CALL_COMPLETE,		/* - call completed */
363 		RXRPC_CALL_SERVER_BUSY,		/* - call rejected by busy server */
364 		RXRPC_CALL_REMOTELY_ABORTED,	/* - call aborted by peer */
365 		RXRPC_CALL_LOCALLY_ABORTED,	/* - call aborted locally on error or close */
366 		RXRPC_CALL_NETWORK_ERROR,	/* - call terminated by network error */
367 		RXRPC_CALL_DEAD,		/* - call is dead */
368 	} state;
369 	int			debug_id;	/* debug ID for printks */
370 	u8			channel;	/* connection channel occupied by this call */
371 
372 	/* transmission-phase ACK management */
373 	uint8_t			acks_head;	/* offset into window of first entry */
374 	uint8_t			acks_tail;	/* offset into window of last entry */
375 	uint8_t			acks_winsz;	/* size of un-ACK'd window */
376 	uint8_t			acks_unacked;	/* lowest unacked packet in last ACK received */
377 	int			acks_latest;	/* serial number of latest ACK received */
378 	rxrpc_seq_t		acks_hard;	/* highest definitively ACK'd msg seq */
379 	unsigned long		*acks_window;	/* sent packet window
380 						 * - elements are pointers with LSB set if ACK'd
381 						 */
382 
383 	/* receive-phase ACK management */
384 	rxrpc_seq_t		rx_data_expect;	/* next data seq ID expected to be received */
385 	rxrpc_seq_t		rx_data_post;	/* next data seq ID expected to be posted */
386 	rxrpc_seq_t		rx_data_recv;	/* last data seq ID encountered by recvmsg */
387 	rxrpc_seq_t		rx_data_eaten;	/* last data seq ID consumed by recvmsg */
388 	rxrpc_seq_t		rx_first_oos;	/* first packet in rx_oos_queue (or 0) */
389 	rxrpc_seq_t		ackr_win_top;	/* top of ACK window (rx_data_eaten is bottom) */
390 	rxrpc_seq_net_t		ackr_prev_seq;	/* previous sequence number received */
391 	uint8_t			ackr_reason;	/* reason to ACK */
392 	__be32			ackr_serial;	/* serial of packet being ACK'd */
393 	atomic_t		ackr_not_idle;	/* number of packets in Rx queue */
394 
395 	/* received packet records, 1 bit per record */
396 #define RXRPC_ACKR_WINDOW_ASZ DIV_ROUND_UP(RXRPC_MAXACKS, BITS_PER_LONG)
397 	unsigned long		ackr_window[RXRPC_ACKR_WINDOW_ASZ + 1];
398 
399 	/* the following should all be in net order */
400 	__be32			cid;		/* connection ID + channel index  */
401 	__be32			call_id;	/* call ID on connection  */
402 };
403 
404 /*
405  * RxRPC key for Kerberos (type-2 security)
406  */
407 struct rxkad_key {
408 	u16	security_index;		/* RxRPC header security index */
409 	u16	ticket_len;		/* length of ticket[] */
410 	u32	expiry;			/* time at which expires */
411 	u32	kvno;			/* key version number */
412 	u8	session_key[8];		/* DES session key */
413 	u8	ticket[0];		/* the encrypted ticket */
414 };
415 
416 struct rxrpc_key_payload {
417 	struct rxkad_key k;
418 };
419 
420 /*
421  * locally abort an RxRPC call
422  */
423 static inline void rxrpc_abort_call(struct rxrpc_call *call, u32 abort_code)
424 {
425 	write_lock_bh(&call->state_lock);
426 	if (call->state < RXRPC_CALL_COMPLETE) {
427 		call->abort_code = abort_code;
428 		call->state = RXRPC_CALL_LOCALLY_ABORTED;
429 		set_bit(RXRPC_CALL_ABORT, &call->events);
430 	}
431 	write_unlock_bh(&call->state_lock);
432 }
433 
434 /*
435  * af_rxrpc.c
436  */
437 extern atomic_t rxrpc_n_skbs;
438 extern __be32 rxrpc_epoch;
439 extern atomic_t rxrpc_debug_id;
440 extern struct workqueue_struct *rxrpc_workqueue;
441 
442 /*
443  * ar-accept.c
444  */
445 extern void rxrpc_accept_incoming_calls(struct work_struct *);
446 extern struct rxrpc_call *rxrpc_accept_call(struct rxrpc_sock *,
447 					    unsigned long);
448 extern int rxrpc_reject_call(struct rxrpc_sock *);
449 
450 /*
451  * ar-ack.c
452  */
453 extern void __rxrpc_propose_ACK(struct rxrpc_call *, uint8_t, __be32, bool);
454 extern void rxrpc_propose_ACK(struct rxrpc_call *, uint8_t, __be32, bool);
455 extern void rxrpc_process_call(struct work_struct *);
456 
457 /*
458  * ar-call.c
459  */
460 extern struct kmem_cache *rxrpc_call_jar;
461 extern struct list_head rxrpc_calls;
462 extern rwlock_t rxrpc_call_lock;
463 
464 extern struct rxrpc_call *rxrpc_get_client_call(struct rxrpc_sock *,
465 						struct rxrpc_transport *,
466 						struct rxrpc_conn_bundle *,
467 						unsigned long, int, gfp_t);
468 extern struct rxrpc_call *rxrpc_incoming_call(struct rxrpc_sock *,
469 					      struct rxrpc_connection *,
470 					      struct rxrpc_header *, gfp_t);
471 extern struct rxrpc_call *rxrpc_find_server_call(struct rxrpc_sock *,
472 						 unsigned long);
473 extern void rxrpc_release_call(struct rxrpc_call *);
474 extern void rxrpc_release_calls_on_socket(struct rxrpc_sock *);
475 extern void __rxrpc_put_call(struct rxrpc_call *);
476 extern void __exit rxrpc_destroy_all_calls(void);
477 
478 /*
479  * ar-connection.c
480  */
481 extern struct list_head rxrpc_connections;
482 extern rwlock_t rxrpc_connection_lock;
483 
484 extern struct rxrpc_conn_bundle *rxrpc_get_bundle(struct rxrpc_sock *,
485 						  struct rxrpc_transport *,
486 						  struct key *,
487 						  __be16, gfp_t);
488 extern void rxrpc_put_bundle(struct rxrpc_transport *,
489 			     struct rxrpc_conn_bundle *);
490 extern int rxrpc_connect_call(struct rxrpc_sock *, struct rxrpc_transport *,
491 			      struct rxrpc_conn_bundle *, struct rxrpc_call *,
492 			      gfp_t);
493 extern void rxrpc_put_connection(struct rxrpc_connection *);
494 extern void __exit rxrpc_destroy_all_connections(void);
495 extern struct rxrpc_connection *rxrpc_find_connection(struct rxrpc_transport *,
496 						      struct rxrpc_header *);
497 extern struct rxrpc_connection *
498 rxrpc_incoming_connection(struct rxrpc_transport *, struct rxrpc_header *,
499 			  gfp_t);
500 
501 /*
502  * ar-connevent.c
503  */
504 extern void rxrpc_process_connection(struct work_struct *);
505 extern void rxrpc_reject_packet(struct rxrpc_local *, struct sk_buff *);
506 extern void rxrpc_reject_packets(struct work_struct *);
507 
508 /*
509  * ar-error.c
510  */
511 extern void rxrpc_UDP_error_report(struct sock *);
512 extern void rxrpc_UDP_error_handler(struct work_struct *);
513 
514 /*
515  * ar-input.c
516  */
517 extern unsigned long rxrpc_ack_timeout;
518 extern const char *rxrpc_pkts[];
519 
520 extern void rxrpc_data_ready(struct sock *, int);
521 extern int rxrpc_queue_rcv_skb(struct rxrpc_call *, struct sk_buff *, bool,
522 			       bool);
523 extern void rxrpc_fast_process_packet(struct rxrpc_call *, struct sk_buff *);
524 
525 /*
526  * ar-local.c
527  */
528 extern rwlock_t rxrpc_local_lock;
529 extern struct rxrpc_local *rxrpc_lookup_local(struct sockaddr_rxrpc *);
530 extern void rxrpc_put_local(struct rxrpc_local *);
531 extern void __exit rxrpc_destroy_all_locals(void);
532 
533 /*
534  * ar-key.c
535  */
536 extern struct key_type key_type_rxrpc;
537 extern struct key_type key_type_rxrpc_s;
538 
539 extern int rxrpc_request_key(struct rxrpc_sock *, char __user *, int);
540 extern int rxrpc_server_keyring(struct rxrpc_sock *, char __user *, int);
541 extern int rxrpc_get_server_data_key(struct rxrpc_connection *, const void *,
542 				     time_t, u32);
543 
544 /*
545  * ar-output.c
546  */
547 extern int rxrpc_resend_timeout;
548 
549 extern int rxrpc_send_packet(struct rxrpc_transport *, struct sk_buff *);
550 extern int rxrpc_client_sendmsg(struct kiocb *, struct rxrpc_sock *,
551 				struct rxrpc_transport *, struct msghdr *,
552 				size_t);
553 extern int rxrpc_server_sendmsg(struct kiocb *, struct rxrpc_sock *,
554 				struct msghdr *, size_t);
555 
556 /*
557  * ar-peer.c
558  */
559 extern struct rxrpc_peer *rxrpc_get_peer(struct sockaddr_rxrpc *, gfp_t);
560 extern void rxrpc_put_peer(struct rxrpc_peer *);
561 extern struct rxrpc_peer *rxrpc_find_peer(struct rxrpc_local *,
562 					  __be32, __be16);
563 extern void __exit rxrpc_destroy_all_peers(void);
564 
565 /*
566  * ar-proc.c
567  */
568 extern const char *rxrpc_call_states[];
569 extern struct file_operations rxrpc_call_seq_fops;
570 extern struct file_operations rxrpc_connection_seq_fops;
571 
572 /*
573  * ar-recvmsg.c
574  */
575 extern void rxrpc_remove_user_ID(struct rxrpc_sock *, struct rxrpc_call *);
576 extern int rxrpc_recvmsg(struct kiocb *, struct socket *, struct msghdr *,
577 			 size_t, int);
578 
579 /*
580  * ar-security.c
581  */
582 extern int rxrpc_register_security(struct rxrpc_security *);
583 extern void rxrpc_unregister_security(struct rxrpc_security *);
584 extern int rxrpc_init_client_conn_security(struct rxrpc_connection *);
585 extern int rxrpc_init_server_conn_security(struct rxrpc_connection *);
586 extern int rxrpc_secure_packet(const struct rxrpc_call *, struct sk_buff *,
587 			       size_t, void *);
588 extern int rxrpc_verify_packet(const struct rxrpc_call *, struct sk_buff *,
589 			       u32 *);
590 extern void rxrpc_clear_conn_security(struct rxrpc_connection *);
591 
592 /*
593  * ar-skbuff.c
594  */
595 extern void rxrpc_packet_destructor(struct sk_buff *);
596 
597 /*
598  * ar-transport.c
599  */
600 extern struct rxrpc_transport *rxrpc_get_transport(struct rxrpc_local *,
601 						   struct rxrpc_peer *,
602 						   gfp_t);
603 extern void rxrpc_put_transport(struct rxrpc_transport *);
604 extern void __exit rxrpc_destroy_all_transports(void);
605 extern struct rxrpc_transport *rxrpc_find_transport(struct rxrpc_local *,
606 						    struct rxrpc_peer *);
607 
608 /*
609  * debug tracing
610  */
611 extern unsigned rxrpc_debug;
612 
613 #define dbgprintk(FMT,...) \
614 	printk("[%x%-6.6s] "FMT"\n", smp_processor_id(), current->comm ,##__VA_ARGS__)
615 
616 /* make sure we maintain the format strings, even when debugging is disabled */
617 static inline __attribute__((format(printf,1,2)))
618 void _dbprintk(const char *fmt, ...)
619 {
620 }
621 
622 #define kenter(FMT,...)	dbgprintk("==> %s("FMT")",__FUNCTION__ ,##__VA_ARGS__)
623 #define kleave(FMT,...)	dbgprintk("<== %s()"FMT"",__FUNCTION__ ,##__VA_ARGS__)
624 #define kdebug(FMT,...)	dbgprintk("    "FMT ,##__VA_ARGS__)
625 #define kproto(FMT,...)	dbgprintk("### "FMT ,##__VA_ARGS__)
626 #define knet(FMT,...)	dbgprintk("@@@ "FMT ,##__VA_ARGS__)
627 
628 
629 #if defined(__KDEBUG)
630 #define _enter(FMT,...)	kenter(FMT,##__VA_ARGS__)
631 #define _leave(FMT,...)	kleave(FMT,##__VA_ARGS__)
632 #define _debug(FMT,...)	kdebug(FMT,##__VA_ARGS__)
633 #define _proto(FMT,...)	kproto(FMT,##__VA_ARGS__)
634 #define _net(FMT,...)	knet(FMT,##__VA_ARGS__)
635 
636 #elif defined(CONFIG_AF_RXRPC_DEBUG)
637 #define RXRPC_DEBUG_KENTER	0x01
638 #define RXRPC_DEBUG_KLEAVE	0x02
639 #define RXRPC_DEBUG_KDEBUG	0x04
640 #define RXRPC_DEBUG_KPROTO	0x08
641 #define RXRPC_DEBUG_KNET	0x10
642 
643 #define _enter(FMT,...)					\
644 do {							\
645 	if (unlikely(rxrpc_debug & RXRPC_DEBUG_KENTER))	\
646 		kenter(FMT,##__VA_ARGS__);		\
647 } while (0)
648 
649 #define _leave(FMT,...)					\
650 do {							\
651 	if (unlikely(rxrpc_debug & RXRPC_DEBUG_KLEAVE))	\
652 		kleave(FMT,##__VA_ARGS__);		\
653 } while (0)
654 
655 #define _debug(FMT,...)					\
656 do {							\
657 	if (unlikely(rxrpc_debug & RXRPC_DEBUG_KDEBUG))	\
658 		kdebug(FMT,##__VA_ARGS__);		\
659 } while (0)
660 
661 #define _proto(FMT,...)					\
662 do {							\
663 	if (unlikely(rxrpc_debug & RXRPC_DEBUG_KPROTO))	\
664 		kproto(FMT,##__VA_ARGS__);		\
665 } while (0)
666 
667 #define _net(FMT,...)					\
668 do {							\
669 	if (unlikely(rxrpc_debug & RXRPC_DEBUG_KNET))	\
670 		knet(FMT,##__VA_ARGS__);		\
671 } while (0)
672 
673 #else
674 #define _enter(FMT,...)	_dbprintk("==> %s("FMT")",__FUNCTION__ ,##__VA_ARGS__)
675 #define _leave(FMT,...)	_dbprintk("<== %s()"FMT"",__FUNCTION__ ,##__VA_ARGS__)
676 #define _debug(FMT,...)	_dbprintk("    "FMT ,##__VA_ARGS__)
677 #define _proto(FMT,...)	_dbprintk("### "FMT ,##__VA_ARGS__)
678 #define _net(FMT,...)	_dbprintk("@@@ "FMT ,##__VA_ARGS__)
679 #endif
680 
681 /*
682  * debug assertion checking
683  */
684 #if 1 // defined(__KDEBUGALL)
685 
686 #define ASSERT(X)						\
687 do {								\
688 	if (unlikely(!(X))) {					\
689 		printk(KERN_ERR "\n");				\
690 		printk(KERN_ERR "RxRPC: Assertion failed\n");	\
691 		BUG();						\
692 	}							\
693 } while(0)
694 
695 #define ASSERTCMP(X, OP, Y)						\
696 do {									\
697 	if (unlikely(!((X) OP (Y)))) {					\
698 		printk(KERN_ERR "\n");					\
699 		printk(KERN_ERR "RxRPC: Assertion failed\n");		\
700 		printk(KERN_ERR "%lu " #OP " %lu is false\n",		\
701 		       (unsigned long)(X), (unsigned long)(Y));		\
702 		printk(KERN_ERR "0x%lx " #OP " 0x%lx is false\n",	\
703 		       (unsigned long)(X), (unsigned long)(Y));		\
704 		BUG();							\
705 	}								\
706 } while(0)
707 
708 #define ASSERTIF(C, X)						\
709 do {								\
710 	if (unlikely((C) && !(X))) {				\
711 		printk(KERN_ERR "\n");				\
712 		printk(KERN_ERR "RxRPC: Assertion failed\n");	\
713 		BUG();						\
714 	}							\
715 } while(0)
716 
717 #define ASSERTIFCMP(C, X, OP, Y)					\
718 do {									\
719 	if (unlikely((C) && !((X) OP (Y)))) {				\
720 		printk(KERN_ERR "\n");					\
721 		printk(KERN_ERR "RxRPC: Assertion failed\n");		\
722 		printk(KERN_ERR "%lu " #OP " %lu is false\n",		\
723 		       (unsigned long)(X), (unsigned long)(Y));		\
724 		printk(KERN_ERR "0x%lx " #OP " 0x%lx is false\n",	\
725 		       (unsigned long)(X), (unsigned long)(Y));		\
726 		BUG();							\
727 	}								\
728 } while(0)
729 
730 #else
731 
732 #define ASSERT(X)				\
733 do {						\
734 } while(0)
735 
736 #define ASSERTCMP(X, OP, Y)			\
737 do {						\
738 } while(0)
739 
740 #define ASSERTIF(C, X)				\
741 do {						\
742 } while(0)
743 
744 #define ASSERTIFCMP(C, X, OP, Y)		\
745 do {						\
746 } while(0)
747 
748 #endif /* __KDEBUGALL */
749 
750 /*
751  * socket buffer accounting / leak finding
752  */
753 static inline void __rxrpc_new_skb(struct sk_buff *skb, const char *fn)
754 {
755 	//_net("new skb %p %s [%d]", skb, fn, atomic_read(&rxrpc_n_skbs));
756 	//atomic_inc(&rxrpc_n_skbs);
757 }
758 
759 #define rxrpc_new_skb(skb) __rxrpc_new_skb((skb), __func__)
760 
761 static inline void __rxrpc_kill_skb(struct sk_buff *skb, const char *fn)
762 {
763 	//_net("kill skb %p %s [%d]", skb, fn, atomic_read(&rxrpc_n_skbs));
764 	//atomic_dec(&rxrpc_n_skbs);
765 }
766 
767 #define rxrpc_kill_skb(skb) __rxrpc_kill_skb((skb), __func__)
768 
769 static inline void __rxrpc_free_skb(struct sk_buff *skb, const char *fn)
770 {
771 	if (skb) {
772 		CHECK_SLAB_OKAY(&skb->users);
773 		//_net("free skb %p %s [%d]",
774 		//     skb, fn, atomic_read(&rxrpc_n_skbs));
775 		//atomic_dec(&rxrpc_n_skbs);
776 		kfree_skb(skb);
777 	}
778 }
779 
780 #define rxrpc_free_skb(skb) __rxrpc_free_skb((skb), __func__)
781 
782 static inline void rxrpc_purge_queue(struct sk_buff_head *list)
783 {
784 	struct sk_buff *skb;
785 	while ((skb = skb_dequeue((list))) != NULL)
786 		rxrpc_free_skb(skb);
787 }
788 
789 static inline void __rxrpc__atomic_inc(atomic_t *v)
790 {
791 	CHECK_SLAB_OKAY(v);
792 	atomic_inc(v);
793 }
794 
795 #define atomic_inc(v) __rxrpc__atomic_inc((v))
796 
797 static inline void __rxrpc__atomic_dec(atomic_t *v)
798 {
799 	CHECK_SLAB_OKAY(v);
800 	atomic_dec(v);
801 }
802 
803 #define atomic_dec(v) __rxrpc__atomic_dec((v))
804 
805 static inline int __rxrpc__atomic_dec_and_test(atomic_t *v)
806 {
807 	CHECK_SLAB_OKAY(v);
808 	return atomic_dec_and_test(v);
809 }
810 
811 #define atomic_dec_and_test(v) __rxrpc__atomic_dec_and_test((v))
812 
813 static inline void __rxrpc_get_local(struct rxrpc_local *local, const char *f)
814 {
815 	CHECK_SLAB_OKAY(&local->usage);
816 	if (atomic_inc_return(&local->usage) == 1)
817 		printk("resurrected (%s)\n", f);
818 }
819 
820 #define rxrpc_get_local(LOCAL) __rxrpc_get_local((LOCAL), __func__)
821 
822 #define rxrpc_get_call(CALL)				\
823 do {							\
824 	CHECK_SLAB_OKAY(&(CALL)->usage);		\
825 	if (atomic_inc_return(&(CALL)->usage) == 1)	\
826 		BUG();					\
827 } while(0)
828 
829 #define rxrpc_put_call(CALL)				\
830 do {							\
831 	__rxrpc_put_call(CALL);				\
832 } while(0)
833