xref: /openbmc/linux/net/rxrpc/ar-internal.h (revision 2baec2c3)
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 <linux/atomic.h>
13 #include <linux/seqlock.h>
14 #include <net/net_namespace.h>
15 #include <net/netns/generic.h>
16 #include <net/sock.h>
17 #include <net/af_rxrpc.h>
18 #include <rxrpc/packet.h>
19 
20 #if 0
21 #define CHECK_SLAB_OKAY(X)				     \
22 	BUG_ON(atomic_read((X)) >> (sizeof(atomic_t) - 2) == \
23 	       (POISON_FREE << 8 | POISON_FREE))
24 #else
25 #define CHECK_SLAB_OKAY(X) do {} while (0)
26 #endif
27 
28 #define FCRYPT_BSIZE 8
29 struct rxrpc_crypt {
30 	union {
31 		u8	x[FCRYPT_BSIZE];
32 		__be32	n[2];
33 	};
34 } __attribute__((aligned(8)));
35 
36 #define rxrpc_queue_work(WS)	queue_work(rxrpc_workqueue, (WS))
37 #define rxrpc_queue_delayed_work(WS,D)	\
38 	queue_delayed_work(rxrpc_workqueue, (WS), (D))
39 
40 struct rxrpc_connection;
41 
42 /*
43  * Mark applied to socket buffers.
44  */
45 enum rxrpc_skb_mark {
46 	RXRPC_SKB_MARK_DATA,		/* data message */
47 	RXRPC_SKB_MARK_FINAL_ACK,	/* final ACK received message */
48 	RXRPC_SKB_MARK_BUSY,		/* server busy message */
49 	RXRPC_SKB_MARK_REMOTE_ABORT,	/* remote abort message */
50 	RXRPC_SKB_MARK_LOCAL_ABORT,	/* local abort message */
51 	RXRPC_SKB_MARK_NET_ERROR,	/* network error message */
52 	RXRPC_SKB_MARK_LOCAL_ERROR,	/* local error message */
53 	RXRPC_SKB_MARK_NEW_CALL,	/* local error message */
54 };
55 
56 /*
57  * sk_state for RxRPC sockets
58  */
59 enum {
60 	RXRPC_UNBOUND = 0,
61 	RXRPC_CLIENT_UNBOUND,		/* Unbound socket used as client */
62 	RXRPC_CLIENT_BOUND,		/* client local address bound */
63 	RXRPC_SERVER_BOUND,		/* server local address bound */
64 	RXRPC_SERVER_LISTENING,		/* server listening for connections */
65 	RXRPC_SERVER_LISTEN_DISABLED,	/* server listening disabled */
66 	RXRPC_CLOSE,			/* socket is being closed */
67 };
68 
69 /*
70  * Per-network namespace data.
71  */
72 struct rxrpc_net {
73 	struct proc_dir_entry	*proc_net;	/* Subdir in /proc/net */
74 	u32			epoch;		/* Local epoch for detecting local-end reset */
75 	struct list_head	calls;		/* List of calls active in this namespace */
76 	rwlock_t		call_lock;	/* Lock for ->calls */
77 
78 	struct list_head	conn_proc_list;	/* List of conns in this namespace for proc */
79 	struct list_head	service_conns;	/* Service conns in this namespace */
80 	rwlock_t		conn_lock;	/* Lock for ->conn_proc_list, ->service_conns */
81 	struct delayed_work	service_conn_reaper;
82 
83 	unsigned int		nr_client_conns;
84 	unsigned int		nr_active_client_conns;
85 	bool			kill_all_client_conns;
86 	spinlock_t		client_conn_cache_lock; /* Lock for ->*_client_conns */
87 	spinlock_t		client_conn_discard_lock; /* Prevent multiple discarders */
88 	struct list_head	waiting_client_conns;
89 	struct list_head	active_client_conns;
90 	struct list_head	idle_client_conns;
91 	struct delayed_work	client_conn_reaper;
92 
93 	struct list_head	local_endpoints;
94 	struct mutex		local_mutex;	/* Lock for ->local_endpoints */
95 
96 	spinlock_t		peer_hash_lock;	/* Lock for ->peer_hash */
97 	DECLARE_HASHTABLE	(peer_hash, 10);
98 };
99 
100 /*
101  * Service backlog preallocation.
102  *
103  * This contains circular buffers of preallocated peers, connections and calls
104  * for incoming service calls and their head and tail pointers.  This allows
105  * calls to be set up in the data_ready handler, thereby avoiding the need to
106  * shuffle packets around so much.
107  */
108 struct rxrpc_backlog {
109 	unsigned short		peer_backlog_head;
110 	unsigned short		peer_backlog_tail;
111 	unsigned short		conn_backlog_head;
112 	unsigned short		conn_backlog_tail;
113 	unsigned short		call_backlog_head;
114 	unsigned short		call_backlog_tail;
115 #define RXRPC_BACKLOG_MAX	32
116 	struct rxrpc_peer	*peer_backlog[RXRPC_BACKLOG_MAX];
117 	struct rxrpc_connection	*conn_backlog[RXRPC_BACKLOG_MAX];
118 	struct rxrpc_call	*call_backlog[RXRPC_BACKLOG_MAX];
119 };
120 
121 /*
122  * RxRPC socket definition
123  */
124 struct rxrpc_sock {
125 	/* WARNING: sk has to be the first member */
126 	struct sock		sk;
127 	rxrpc_notify_new_call_t	notify_new_call; /* Func to notify of new call */
128 	rxrpc_discard_new_call_t discard_new_call; /* Func to discard a new call */
129 	struct rxrpc_local	*local;		/* local endpoint */
130 	struct rxrpc_backlog	*backlog;	/* Preallocation for services */
131 	spinlock_t		incoming_lock;	/* Incoming call vs service shutdown lock */
132 	struct list_head	sock_calls;	/* List of calls owned by this socket */
133 	struct list_head	to_be_accepted;	/* calls awaiting acceptance */
134 	struct list_head	recvmsg_q;	/* Calls awaiting recvmsg's attention  */
135 	rwlock_t		recvmsg_lock;	/* Lock for recvmsg_q */
136 	struct key		*key;		/* security for this socket */
137 	struct key		*securities;	/* list of server security descriptors */
138 	struct rb_root		calls;		/* User ID -> call mapping */
139 	unsigned long		flags;
140 #define RXRPC_SOCK_CONNECTED		0	/* connect_srx is set */
141 	rwlock_t		call_lock;	/* lock for calls */
142 	u32			min_sec_level;	/* minimum security level */
143 #define RXRPC_SECURITY_MAX	RXRPC_SECURITY_ENCRYPT
144 	bool			exclusive;	/* Exclusive connection for a client socket */
145 	sa_family_t		family;		/* Protocol family created with */
146 	struct sockaddr_rxrpc	srx;		/* local address */
147 	struct sockaddr_rxrpc	connect_srx;	/* Default client address from connect() */
148 };
149 
150 #define rxrpc_sk(__sk) container_of((__sk), struct rxrpc_sock, sk)
151 
152 /*
153  * CPU-byteorder normalised Rx packet header.
154  */
155 struct rxrpc_host_header {
156 	u32		epoch;		/* client boot timestamp */
157 	u32		cid;		/* connection and channel ID */
158 	u32		callNumber;	/* call ID (0 for connection-level packets) */
159 	u32		seq;		/* sequence number of pkt in call stream */
160 	u32		serial;		/* serial number of pkt sent to network */
161 	u8		type;		/* packet type */
162 	u8		flags;		/* packet flags */
163 	u8		userStatus;	/* app-layer defined status */
164 	u8		securityIndex;	/* security protocol ID */
165 	union {
166 		u16	_rsvd;		/* reserved */
167 		u16	cksum;		/* kerberos security checksum */
168 	};
169 	u16		serviceId;	/* service ID */
170 } __packed;
171 
172 /*
173  * RxRPC socket buffer private variables
174  * - max 48 bytes (struct sk_buff::cb)
175  */
176 struct rxrpc_skb_priv {
177 	union {
178 		u8		nr_jumbo;	/* Number of jumbo subpackets */
179 	};
180 	union {
181 		int		remain;		/* amount of space remaining for next write */
182 	};
183 
184 	struct rxrpc_host_header hdr;		/* RxRPC packet header from this packet */
185 };
186 
187 #define rxrpc_skb(__skb) ((struct rxrpc_skb_priv *) &(__skb)->cb)
188 
189 /*
190  * RxRPC security module interface
191  */
192 struct rxrpc_security {
193 	const char		*name;		/* name of this service */
194 	u8			security_index;	/* security type provided */
195 
196 	/* Initialise a security service */
197 	int (*init)(void);
198 
199 	/* Clean up a security service */
200 	void (*exit)(void);
201 
202 	/* initialise a connection's security */
203 	int (*init_connection_security)(struct rxrpc_connection *);
204 
205 	/* prime a connection's packet security */
206 	int (*prime_packet_security)(struct rxrpc_connection *);
207 
208 	/* impose security on a packet */
209 	int (*secure_packet)(struct rxrpc_call *,
210 			     struct sk_buff *,
211 			     size_t,
212 			     void *);
213 
214 	/* verify the security on a received packet */
215 	int (*verify_packet)(struct rxrpc_call *, struct sk_buff *,
216 			     unsigned int, unsigned int, rxrpc_seq_t, u16);
217 
218 	/* Locate the data in a received packet that has been verified. */
219 	void (*locate_data)(struct rxrpc_call *, struct sk_buff *,
220 			    unsigned int *, unsigned int *);
221 
222 	/* issue a challenge */
223 	int (*issue_challenge)(struct rxrpc_connection *);
224 
225 	/* respond to a challenge */
226 	int (*respond_to_challenge)(struct rxrpc_connection *,
227 				    struct sk_buff *,
228 				    u32 *);
229 
230 	/* verify a response */
231 	int (*verify_response)(struct rxrpc_connection *,
232 			       struct sk_buff *,
233 			       u32 *);
234 
235 	/* clear connection security */
236 	void (*clear)(struct rxrpc_connection *);
237 };
238 
239 /*
240  * RxRPC local transport endpoint description
241  * - owned by a single AF_RXRPC socket
242  * - pointed to by transport socket struct sk_user_data
243  */
244 struct rxrpc_local {
245 	struct rcu_head		rcu;
246 	atomic_t		usage;
247 	struct rxrpc_net	*rxnet;		/* The network ns in which this resides */
248 	struct list_head	link;
249 	struct socket		*socket;	/* my UDP socket */
250 	struct work_struct	processor;
251 	struct rxrpc_sock __rcu	*service;	/* Service(s) listening on this endpoint */
252 	struct rw_semaphore	defrag_sem;	/* control re-enablement of IP DF bit */
253 	struct sk_buff_head	reject_queue;	/* packets awaiting rejection */
254 	struct sk_buff_head	event_queue;	/* endpoint event packets awaiting processing */
255 	struct rb_root		client_conns;	/* Client connections by socket params */
256 	spinlock_t		client_conns_lock; /* Lock for client_conns */
257 	spinlock_t		lock;		/* access lock */
258 	rwlock_t		services_lock;	/* lock for services list */
259 	int			debug_id;	/* debug ID for printks */
260 	bool			dead;
261 	struct sockaddr_rxrpc	srx;		/* local address */
262 };
263 
264 /*
265  * RxRPC remote transport endpoint definition
266  * - matched by local endpoint, remote port, address and protocol type
267  */
268 struct rxrpc_peer {
269 	struct rcu_head		rcu;		/* This must be first */
270 	atomic_t		usage;
271 	unsigned long		hash_key;
272 	struct hlist_node	hash_link;
273 	struct rxrpc_local	*local;
274 	struct hlist_head	error_targets;	/* targets for net error distribution */
275 	struct work_struct	error_distributor;
276 	struct rb_root		service_conns;	/* Service connections */
277 	seqlock_t		service_conn_lock;
278 	spinlock_t		lock;		/* access lock */
279 	unsigned int		if_mtu;		/* interface MTU for this peer */
280 	unsigned int		mtu;		/* network MTU for this peer */
281 	unsigned int		maxdata;	/* data size (MTU - hdrsize) */
282 	unsigned short		hdrsize;	/* header size (IP + UDP + RxRPC) */
283 	int			debug_id;	/* debug ID for printks */
284 	int			error_report;	/* Net (+0) or local (+1000000) to distribute */
285 #define RXRPC_LOCAL_ERROR_OFFSET 1000000
286 	struct sockaddr_rxrpc	srx;		/* remote address */
287 
288 	/* calculated RTT cache */
289 #define RXRPC_RTT_CACHE_SIZE 32
290 	ktime_t			rtt_last_req;	/* Time of last RTT request */
291 	u64			rtt;		/* Current RTT estimate (in nS) */
292 	u64			rtt_sum;	/* Sum of cache contents */
293 	u64			rtt_cache[RXRPC_RTT_CACHE_SIZE]; /* Determined RTT cache */
294 	u8			rtt_cursor;	/* next entry at which to insert */
295 	u8			rtt_usage;	/* amount of cache actually used */
296 };
297 
298 /*
299  * Keys for matching a connection.
300  */
301 struct rxrpc_conn_proto {
302 	union {
303 		struct {
304 			u32	epoch;		/* epoch of this connection */
305 			u32	cid;		/* connection ID */
306 		};
307 		u64		index_key;
308 	};
309 };
310 
311 struct rxrpc_conn_parameters {
312 	struct rxrpc_local	*local;		/* Representation of local endpoint */
313 	struct rxrpc_peer	*peer;		/* Remote endpoint */
314 	struct key		*key;		/* Security details */
315 	bool			exclusive;	/* T if conn is exclusive */
316 	u16			service_id;	/* Service ID for this connection */
317 	u32			security_level;	/* Security level selected */
318 };
319 
320 /*
321  * Bits in the connection flags.
322  */
323 enum rxrpc_conn_flag {
324 	RXRPC_CONN_HAS_IDR,		/* Has a client conn ID assigned */
325 	RXRPC_CONN_IN_SERVICE_CONNS,	/* Conn is in peer->service_conns */
326 	RXRPC_CONN_IN_CLIENT_CONNS,	/* Conn is in local->client_conns */
327 	RXRPC_CONN_EXPOSED,		/* Conn has extra ref for exposure */
328 	RXRPC_CONN_DONT_REUSE,		/* Don't reuse this connection */
329 	RXRPC_CONN_COUNTED,		/* Counted by rxrpc_nr_client_conns */
330 };
331 
332 /*
333  * Events that can be raised upon a connection.
334  */
335 enum rxrpc_conn_event {
336 	RXRPC_CONN_EV_CHALLENGE,	/* Send challenge packet */
337 };
338 
339 /*
340  * The connection cache state.
341  */
342 enum rxrpc_conn_cache_state {
343 	RXRPC_CONN_CLIENT_INACTIVE,	/* Conn is not yet listed */
344 	RXRPC_CONN_CLIENT_WAITING,	/* Conn is on wait list, waiting for capacity */
345 	RXRPC_CONN_CLIENT_ACTIVE,	/* Conn is on active list, doing calls */
346 	RXRPC_CONN_CLIENT_CULLED,	/* Conn is culled and delisted, doing calls */
347 	RXRPC_CONN_CLIENT_IDLE,		/* Conn is on idle list, doing mostly nothing */
348 	RXRPC_CONN__NR_CACHE_STATES
349 };
350 
351 /*
352  * The connection protocol state.
353  */
354 enum rxrpc_conn_proto_state {
355 	RXRPC_CONN_UNUSED,		/* Connection not yet attempted */
356 	RXRPC_CONN_CLIENT,		/* Client connection */
357 	RXRPC_CONN_SERVICE_PREALLOC,	/* Service connection preallocation */
358 	RXRPC_CONN_SERVICE_UNSECURED,	/* Service unsecured connection */
359 	RXRPC_CONN_SERVICE_CHALLENGING,	/* Service challenging for security */
360 	RXRPC_CONN_SERVICE,		/* Service secured connection */
361 	RXRPC_CONN_REMOTELY_ABORTED,	/* Conn aborted by peer */
362 	RXRPC_CONN_LOCALLY_ABORTED,	/* Conn aborted locally */
363 	RXRPC_CONN__NR_STATES
364 };
365 
366 /*
367  * RxRPC connection definition
368  * - matched by { local, peer, epoch, conn_id, direction }
369  * - each connection can only handle four simultaneous calls
370  */
371 struct rxrpc_connection {
372 	struct rxrpc_conn_proto	proto;
373 	struct rxrpc_conn_parameters params;
374 
375 	atomic_t		usage;
376 	struct rcu_head		rcu;
377 	struct list_head	cache_link;
378 
379 	spinlock_t		channel_lock;
380 	unsigned char		active_chans;	/* Mask of active channels */
381 #define RXRPC_ACTIVE_CHANS_MASK	((1 << RXRPC_MAXCALLS) - 1)
382 	struct list_head	waiting_calls;	/* Calls waiting for channels */
383 	struct rxrpc_channel {
384 		struct rxrpc_call __rcu	*call;		/* Active call */
385 		u32			call_id;	/* ID of current call */
386 		u32			call_counter;	/* Call ID counter */
387 		u32			last_call;	/* ID of last call */
388 		u8			last_type;	/* Type of last packet */
389 		u16			last_service_id;
390 		union {
391 			u32		last_seq;
392 			u32		last_abort;
393 		};
394 	} channels[RXRPC_MAXCALLS];
395 
396 	struct work_struct	processor;	/* connection event processor */
397 	union {
398 		struct rb_node	client_node;	/* Node in local->client_conns */
399 		struct rb_node	service_node;	/* Node in peer->service_conns */
400 	};
401 	struct list_head	proc_link;	/* link in procfs list */
402 	struct list_head	link;		/* link in master connection list */
403 	struct sk_buff_head	rx_queue;	/* received conn-level packets */
404 	const struct rxrpc_security *security;	/* applied security module */
405 	struct key		*server_key;	/* security for this service */
406 	struct crypto_skcipher	*cipher;	/* encryption handle */
407 	struct rxrpc_crypt	csum_iv;	/* packet checksum base */
408 	unsigned long		flags;
409 	unsigned long		events;
410 	unsigned long		idle_timestamp;	/* Time at which last became idle */
411 	spinlock_t		state_lock;	/* state-change lock */
412 	enum rxrpc_conn_cache_state cache_state;
413 	enum rxrpc_conn_proto_state state;	/* current state of connection */
414 	u32			local_abort;	/* local abort code */
415 	u32			remote_abort;	/* remote abort code */
416 	int			debug_id;	/* debug ID for printks */
417 	atomic_t		serial;		/* packet serial number counter */
418 	unsigned int		hi_serial;	/* highest serial number received */
419 	u32			security_nonce;	/* response re-use preventer */
420 	u8			size_align;	/* data size alignment (for security) */
421 	u8			security_size;	/* security header size */
422 	u8			security_ix;	/* security type */
423 	u8			out_clientflag;	/* RXRPC_CLIENT_INITIATED if we are client */
424 };
425 
426 /*
427  * Flags in call->flags.
428  */
429 enum rxrpc_call_flag {
430 	RXRPC_CALL_RELEASED,		/* call has been released - no more message to userspace */
431 	RXRPC_CALL_HAS_USERID,		/* has a user ID attached */
432 	RXRPC_CALL_IS_SERVICE,		/* Call is service call */
433 	RXRPC_CALL_EXPOSED,		/* The call was exposed to the world */
434 	RXRPC_CALL_RX_LAST,		/* Received the last packet (at rxtx_top) */
435 	RXRPC_CALL_TX_LAST,		/* Last packet in Tx buffer (at rxtx_top) */
436 	RXRPC_CALL_SEND_PING,		/* A ping will need to be sent */
437 	RXRPC_CALL_PINGING,		/* Ping in process */
438 	RXRPC_CALL_RETRANS_TIMEOUT,	/* Retransmission due to timeout occurred */
439 };
440 
441 /*
442  * Events that can be raised on a call.
443  */
444 enum rxrpc_call_event {
445 	RXRPC_CALL_EV_ACK,		/* need to generate ACK */
446 	RXRPC_CALL_EV_ABORT,		/* need to generate abort */
447 	RXRPC_CALL_EV_TIMER,		/* Timer expired */
448 	RXRPC_CALL_EV_RESEND,		/* Tx resend required */
449 	RXRPC_CALL_EV_PING,		/* Ping send required */
450 };
451 
452 /*
453  * The states that a call can be in.
454  */
455 enum rxrpc_call_state {
456 	RXRPC_CALL_UNINITIALISED,
457 	RXRPC_CALL_CLIENT_AWAIT_CONN,	/* - client waiting for connection to become available */
458 	RXRPC_CALL_CLIENT_SEND_REQUEST,	/* - client sending request phase */
459 	RXRPC_CALL_CLIENT_AWAIT_REPLY,	/* - client awaiting reply */
460 	RXRPC_CALL_CLIENT_RECV_REPLY,	/* - client receiving reply phase */
461 	RXRPC_CALL_SERVER_PREALLOC,	/* - service preallocation */
462 	RXRPC_CALL_SERVER_SECURING,	/* - server securing request connection */
463 	RXRPC_CALL_SERVER_ACCEPTING,	/* - server accepting request */
464 	RXRPC_CALL_SERVER_RECV_REQUEST,	/* - server receiving request */
465 	RXRPC_CALL_SERVER_ACK_REQUEST,	/* - server pending ACK of request */
466 	RXRPC_CALL_SERVER_SEND_REPLY,	/* - server sending reply */
467 	RXRPC_CALL_SERVER_AWAIT_ACK,	/* - server awaiting final ACK */
468 	RXRPC_CALL_COMPLETE,		/* - call complete */
469 	NR__RXRPC_CALL_STATES
470 };
471 
472 /*
473  * Call completion condition (state == RXRPC_CALL_COMPLETE).
474  */
475 enum rxrpc_call_completion {
476 	RXRPC_CALL_SUCCEEDED,		/* - Normal termination */
477 	RXRPC_CALL_REMOTELY_ABORTED,	/* - call aborted by peer */
478 	RXRPC_CALL_LOCALLY_ABORTED,	/* - call aborted locally on error or close */
479 	RXRPC_CALL_LOCAL_ERROR,		/* - call failed due to local error */
480 	RXRPC_CALL_NETWORK_ERROR,	/* - call terminated by network error */
481 	NR__RXRPC_CALL_COMPLETIONS
482 };
483 
484 /*
485  * Call Tx congestion management modes.
486  */
487 enum rxrpc_congest_mode {
488 	RXRPC_CALL_SLOW_START,
489 	RXRPC_CALL_CONGEST_AVOIDANCE,
490 	RXRPC_CALL_PACKET_LOSS,
491 	RXRPC_CALL_FAST_RETRANSMIT,
492 	NR__RXRPC_CONGEST_MODES
493 };
494 
495 /*
496  * RxRPC call definition
497  * - matched by { connection, call_id }
498  */
499 struct rxrpc_call {
500 	struct rcu_head		rcu;
501 	struct rxrpc_connection	*conn;		/* connection carrying call */
502 	struct rxrpc_peer	*peer;		/* Peer record for remote address */
503 	struct rxrpc_sock __rcu	*socket;	/* socket responsible */
504 	struct mutex		user_mutex;	/* User access mutex */
505 	ktime_t			ack_at;		/* When deferred ACK needs to happen */
506 	ktime_t			resend_at;	/* When next resend needs to happen */
507 	ktime_t			ping_at;	/* When next to send a ping */
508 	ktime_t			expire_at;	/* When the call times out */
509 	struct timer_list	timer;		/* Combined event timer */
510 	struct work_struct	processor;	/* Event processor */
511 	rxrpc_notify_rx_t	notify_rx;	/* kernel service Rx notification function */
512 	struct list_head	link;		/* link in master call list */
513 	struct list_head	chan_wait_link;	/* Link in conn->waiting_calls */
514 	struct hlist_node	error_link;	/* link in error distribution list */
515 	struct list_head	accept_link;	/* Link in rx->acceptq */
516 	struct list_head	recvmsg_link;	/* Link in rx->recvmsg_q */
517 	struct list_head	sock_link;	/* Link in rx->sock_calls */
518 	struct rb_node		sock_node;	/* Node in rx->calls */
519 	struct sk_buff		*tx_pending;	/* Tx socket buffer being filled */
520 	wait_queue_head_t	waitq;		/* Wait queue for channel or Tx */
521 	__be32			crypto_buf[2];	/* Temporary packet crypto buffer */
522 	unsigned long		user_call_ID;	/* user-defined call ID */
523 	unsigned long		flags;
524 	unsigned long		events;
525 	spinlock_t		lock;
526 	rwlock_t		state_lock;	/* lock for state transition */
527 	u32			abort_code;	/* Local/remote abort code */
528 	int			error;		/* Local error incurred */
529 	enum rxrpc_call_state	state;		/* current state of call */
530 	enum rxrpc_call_completion completion;	/* Call completion condition */
531 	atomic_t		usage;
532 	u16			service_id;	/* service ID */
533 	u8			security_ix;	/* Security type */
534 	u32			call_id;	/* call ID on connection  */
535 	u32			cid;		/* connection ID plus channel index */
536 	int			debug_id;	/* debug ID for printks */
537 	unsigned short		rx_pkt_offset;	/* Current recvmsg packet offset */
538 	unsigned short		rx_pkt_len;	/* Current recvmsg packet len */
539 
540 	/* Rx/Tx circular buffer, depending on phase.
541 	 *
542 	 * In the Rx phase, packets are annotated with 0 or the number of the
543 	 * segment of a jumbo packet each buffer refers to.  There can be up to
544 	 * 47 segments in a maximum-size UDP packet.
545 	 *
546 	 * In the Tx phase, packets are annotated with which buffers have been
547 	 * acked.
548 	 */
549 #define RXRPC_RXTX_BUFF_SIZE	64
550 #define RXRPC_RXTX_BUFF_MASK	(RXRPC_RXTX_BUFF_SIZE - 1)
551 #define RXRPC_INIT_RX_WINDOW_SIZE 32
552 	struct sk_buff		**rxtx_buffer;
553 	u8			*rxtx_annotations;
554 #define RXRPC_TX_ANNO_ACK	0
555 #define RXRPC_TX_ANNO_UNACK	1
556 #define RXRPC_TX_ANNO_NAK	2
557 #define RXRPC_TX_ANNO_RETRANS	3
558 #define RXRPC_TX_ANNO_MASK	0x03
559 #define RXRPC_TX_ANNO_LAST	0x04
560 #define RXRPC_TX_ANNO_RESENT	0x08
561 
562 #define RXRPC_RX_ANNO_JUMBO	0x3f		/* Jumbo subpacket number + 1 if not zero */
563 #define RXRPC_RX_ANNO_JLAST	0x40		/* Set if last element of a jumbo packet */
564 #define RXRPC_RX_ANNO_VERIFIED	0x80		/* Set if verified and decrypted */
565 	rxrpc_seq_t		tx_hard_ack;	/* Dead slot in buffer; the first transmitted but
566 						 * not hard-ACK'd packet follows this.
567 						 */
568 	rxrpc_seq_t		tx_top;		/* Highest Tx slot allocated. */
569 
570 	/* TCP-style slow-start congestion control [RFC5681].  Since the SMSS
571 	 * is fixed, we keep these numbers in terms of segments (ie. DATA
572 	 * packets) rather than bytes.
573 	 */
574 #define RXRPC_TX_SMSS		RXRPC_JUMBO_DATALEN
575 	u8			cong_cwnd;	/* Congestion window size */
576 	u8			cong_extra;	/* Extra to send for congestion management */
577 	u8			cong_ssthresh;	/* Slow-start threshold */
578 	enum rxrpc_congest_mode	cong_mode:8;	/* Congestion management mode */
579 	u8			cong_dup_acks;	/* Count of ACKs showing missing packets */
580 	u8			cong_cumul_acks; /* Cumulative ACK count */
581 	ktime_t			cong_tstamp;	/* Last time cwnd was changed */
582 
583 	rxrpc_seq_t		rx_hard_ack;	/* Dead slot in buffer; the first received but not
584 						 * consumed packet follows this.
585 						 */
586 	rxrpc_seq_t		rx_top;		/* Highest Rx slot allocated. */
587 	rxrpc_seq_t		rx_expect_next;	/* Expected next packet sequence number */
588 	u8			rx_winsize;	/* Size of Rx window */
589 	u8			tx_winsize;	/* Maximum size of Tx window */
590 	bool			tx_phase;	/* T if transmission phase, F if receive phase */
591 	u8			nr_jumbo_bad;	/* Number of jumbo dups/exceeds-windows */
592 
593 	/* receive-phase ACK management */
594 	u8			ackr_reason;	/* reason to ACK */
595 	u16			ackr_skew;	/* skew on packet being ACK'd */
596 	rxrpc_serial_t		ackr_serial;	/* serial of packet being ACK'd */
597 	rxrpc_seq_t		ackr_prev_seq;	/* previous sequence number received */
598 	rxrpc_seq_t		ackr_consumed;	/* Highest packet shown consumed */
599 	rxrpc_seq_t		ackr_seen;	/* Highest packet shown seen */
600 
601 	/* ping management */
602 	rxrpc_serial_t		ping_serial;	/* Last ping sent */
603 	ktime_t			ping_time;	/* Time last ping sent */
604 
605 	/* transmission-phase ACK management */
606 	ktime_t			acks_latest_ts;	/* Timestamp of latest ACK received */
607 	rxrpc_serial_t		acks_latest;	/* serial number of latest ACK received */
608 	rxrpc_seq_t		acks_lowest_nak; /* Lowest NACK in the buffer (or ==tx_hard_ack) */
609 };
610 
611 /*
612  * Summary of a new ACK and the changes it made to the Tx buffer packet states.
613  */
614 struct rxrpc_ack_summary {
615 	u8			ack_reason;
616 	u8			nr_acks;		/* Number of ACKs in packet */
617 	u8			nr_nacks;		/* Number of NACKs in packet */
618 	u8			nr_new_acks;		/* Number of new ACKs in packet */
619 	u8			nr_new_nacks;		/* Number of new NACKs in packet */
620 	u8			nr_rot_new_acks;	/* Number of rotated new ACKs */
621 	bool			new_low_nack;		/* T if new low NACK found */
622 	bool			retrans_timeo;		/* T if reTx due to timeout happened */
623 	u8			flight_size;		/* Number of unreceived transmissions */
624 	/* Place to stash values for tracing */
625 	enum rxrpc_congest_mode	mode:8;
626 	u8			cwnd;
627 	u8			ssthresh;
628 	u8			dup_acks;
629 	u8			cumulative_acks;
630 };
631 
632 #include <trace/events/rxrpc.h>
633 
634 /*
635  * af_rxrpc.c
636  */
637 extern atomic_t rxrpc_n_tx_skbs, rxrpc_n_rx_skbs;
638 extern atomic_t rxrpc_debug_id;
639 extern struct workqueue_struct *rxrpc_workqueue;
640 
641 /*
642  * call_accept.c
643  */
644 int rxrpc_service_prealloc(struct rxrpc_sock *, gfp_t);
645 void rxrpc_discard_prealloc(struct rxrpc_sock *);
646 struct rxrpc_call *rxrpc_new_incoming_call(struct rxrpc_local *,
647 					   struct rxrpc_connection *,
648 					   struct sk_buff *);
649 void rxrpc_accept_incoming_calls(struct rxrpc_local *);
650 struct rxrpc_call *rxrpc_accept_call(struct rxrpc_sock *, unsigned long,
651 				     rxrpc_notify_rx_t);
652 int rxrpc_reject_call(struct rxrpc_sock *);
653 
654 /*
655  * call_event.c
656  */
657 void __rxrpc_set_timer(struct rxrpc_call *, enum rxrpc_timer_trace, ktime_t);
658 void rxrpc_set_timer(struct rxrpc_call *, enum rxrpc_timer_trace, ktime_t);
659 void rxrpc_propose_ACK(struct rxrpc_call *, u8, u16, u32, bool, bool,
660 		       enum rxrpc_propose_ack_trace);
661 void rxrpc_process_call(struct work_struct *);
662 
663 /*
664  * call_object.c
665  */
666 extern const char *const rxrpc_call_states[];
667 extern const char *const rxrpc_call_completions[];
668 extern unsigned int rxrpc_max_call_lifetime;
669 extern struct kmem_cache *rxrpc_call_jar;
670 
671 struct rxrpc_call *rxrpc_find_call_by_user_ID(struct rxrpc_sock *, unsigned long);
672 struct rxrpc_call *rxrpc_alloc_call(gfp_t);
673 struct rxrpc_call *rxrpc_new_client_call(struct rxrpc_sock *,
674 					 struct rxrpc_conn_parameters *,
675 					 struct sockaddr_rxrpc *,
676 					 unsigned long, gfp_t);
677 void rxrpc_incoming_call(struct rxrpc_sock *, struct rxrpc_call *,
678 			 struct sk_buff *);
679 void rxrpc_release_call(struct rxrpc_sock *, struct rxrpc_call *);
680 void rxrpc_release_calls_on_socket(struct rxrpc_sock *);
681 bool __rxrpc_queue_call(struct rxrpc_call *);
682 bool rxrpc_queue_call(struct rxrpc_call *);
683 void rxrpc_see_call(struct rxrpc_call *);
684 void rxrpc_get_call(struct rxrpc_call *, enum rxrpc_call_trace);
685 void rxrpc_put_call(struct rxrpc_call *, enum rxrpc_call_trace);
686 void rxrpc_cleanup_call(struct rxrpc_call *);
687 void rxrpc_destroy_all_calls(struct rxrpc_net *);
688 
689 static inline bool rxrpc_is_service_call(const struct rxrpc_call *call)
690 {
691 	return test_bit(RXRPC_CALL_IS_SERVICE, &call->flags);
692 }
693 
694 static inline bool rxrpc_is_client_call(const struct rxrpc_call *call)
695 {
696 	return !rxrpc_is_service_call(call);
697 }
698 
699 /*
700  * Transition a call to the complete state.
701  */
702 static inline bool __rxrpc_set_call_completion(struct rxrpc_call *call,
703 					       enum rxrpc_call_completion compl,
704 					       u32 abort_code,
705 					       int error)
706 {
707 	if (call->state < RXRPC_CALL_COMPLETE) {
708 		call->abort_code = abort_code;
709 		call->error = error;
710 		call->completion = compl,
711 		call->state = RXRPC_CALL_COMPLETE;
712 		wake_up(&call->waitq);
713 		return true;
714 	}
715 	return false;
716 }
717 
718 static inline bool rxrpc_set_call_completion(struct rxrpc_call *call,
719 					     enum rxrpc_call_completion compl,
720 					     u32 abort_code,
721 					     int error)
722 {
723 	bool ret;
724 
725 	write_lock_bh(&call->state_lock);
726 	ret = __rxrpc_set_call_completion(call, compl, abort_code, error);
727 	write_unlock_bh(&call->state_lock);
728 	return ret;
729 }
730 
731 /*
732  * Record that a call successfully completed.
733  */
734 static inline bool __rxrpc_call_completed(struct rxrpc_call *call)
735 {
736 	return __rxrpc_set_call_completion(call, RXRPC_CALL_SUCCEEDED, 0, 0);
737 }
738 
739 static inline bool rxrpc_call_completed(struct rxrpc_call *call)
740 {
741 	bool ret;
742 
743 	write_lock_bh(&call->state_lock);
744 	ret = __rxrpc_call_completed(call);
745 	write_unlock_bh(&call->state_lock);
746 	return ret;
747 }
748 
749 /*
750  * Record that a call is locally aborted.
751  */
752 static inline bool __rxrpc_abort_call(const char *why, struct rxrpc_call *call,
753 				      rxrpc_seq_t seq,
754 				      u32 abort_code, int error)
755 {
756 	trace_rxrpc_abort(why, call->cid, call->call_id, seq,
757 			  abort_code, error);
758 	return __rxrpc_set_call_completion(call, RXRPC_CALL_LOCALLY_ABORTED,
759 					   abort_code, error);
760 }
761 
762 static inline bool rxrpc_abort_call(const char *why, struct rxrpc_call *call,
763 				    rxrpc_seq_t seq, u32 abort_code, int error)
764 {
765 	bool ret;
766 
767 	write_lock_bh(&call->state_lock);
768 	ret = __rxrpc_abort_call(why, call, seq, abort_code, error);
769 	write_unlock_bh(&call->state_lock);
770 	return ret;
771 }
772 
773 /*
774  * Abort a call due to a protocol error.
775  */
776 static inline bool __rxrpc_abort_eproto(struct rxrpc_call *call,
777 					struct sk_buff *skb,
778 					const char *eproto_why,
779 					const char *why,
780 					u32 abort_code)
781 {
782 	struct rxrpc_skb_priv *sp = rxrpc_skb(skb);
783 
784 	trace_rxrpc_rx_eproto(call, sp->hdr.serial, eproto_why);
785 	return rxrpc_abort_call(why, call, sp->hdr.seq, abort_code, -EPROTO);
786 }
787 
788 #define rxrpc_abort_eproto(call, skb, eproto_why, abort_why, abort_code) \
789 	__rxrpc_abort_eproto((call), (skb), tracepoint_string(eproto_why), \
790 			     (abort_why), (abort_code))
791 
792 /*
793  * conn_client.c
794  */
795 extern unsigned int rxrpc_max_client_connections;
796 extern unsigned int rxrpc_reap_client_connections;
797 extern unsigned int rxrpc_conn_idle_client_expiry;
798 extern unsigned int rxrpc_conn_idle_client_fast_expiry;
799 extern struct idr rxrpc_client_conn_ids;
800 
801 void rxrpc_destroy_client_conn_ids(void);
802 int rxrpc_connect_call(struct rxrpc_call *, struct rxrpc_conn_parameters *,
803 		       struct sockaddr_rxrpc *, gfp_t);
804 void rxrpc_expose_client_call(struct rxrpc_call *);
805 void rxrpc_disconnect_client_call(struct rxrpc_call *);
806 void rxrpc_put_client_conn(struct rxrpc_connection *);
807 void rxrpc_discard_expired_client_conns(struct work_struct *);
808 void rxrpc_destroy_all_client_connections(struct rxrpc_net *);
809 
810 /*
811  * conn_event.c
812  */
813 void rxrpc_process_connection(struct work_struct *);
814 
815 /*
816  * conn_object.c
817  */
818 extern unsigned int rxrpc_connection_expiry;
819 
820 int rxrpc_extract_addr_from_skb(struct sockaddr_rxrpc *, struct sk_buff *);
821 struct rxrpc_connection *rxrpc_alloc_connection(gfp_t);
822 struct rxrpc_connection *rxrpc_find_connection_rcu(struct rxrpc_local *,
823 						   struct sk_buff *);
824 void __rxrpc_disconnect_call(struct rxrpc_connection *, struct rxrpc_call *);
825 void rxrpc_disconnect_call(struct rxrpc_call *);
826 void rxrpc_kill_connection(struct rxrpc_connection *);
827 bool rxrpc_queue_conn(struct rxrpc_connection *);
828 void rxrpc_see_connection(struct rxrpc_connection *);
829 void rxrpc_get_connection(struct rxrpc_connection *);
830 struct rxrpc_connection *rxrpc_get_connection_maybe(struct rxrpc_connection *);
831 void rxrpc_put_service_conn(struct rxrpc_connection *);
832 void rxrpc_service_connection_reaper(struct work_struct *);
833 void rxrpc_destroy_all_connections(struct rxrpc_net *);
834 
835 static inline bool rxrpc_conn_is_client(const struct rxrpc_connection *conn)
836 {
837 	return conn->out_clientflag;
838 }
839 
840 static inline bool rxrpc_conn_is_service(const struct rxrpc_connection *conn)
841 {
842 	return !rxrpc_conn_is_client(conn);
843 }
844 
845 static inline void rxrpc_put_connection(struct rxrpc_connection *conn)
846 {
847 	if (!conn)
848 		return;
849 
850 	if (rxrpc_conn_is_client(conn))
851 		rxrpc_put_client_conn(conn);
852 	else
853 		rxrpc_put_service_conn(conn);
854 }
855 
856 /*
857  * conn_service.c
858  */
859 struct rxrpc_connection *rxrpc_find_service_conn_rcu(struct rxrpc_peer *,
860 						     struct sk_buff *);
861 struct rxrpc_connection *rxrpc_prealloc_service_connection(struct rxrpc_net *, gfp_t);
862 void rxrpc_new_incoming_connection(struct rxrpc_connection *, struct sk_buff *);
863 void rxrpc_unpublish_service_conn(struct rxrpc_connection *);
864 
865 /*
866  * input.c
867  */
868 void rxrpc_data_ready(struct sock *);
869 
870 /*
871  * insecure.c
872  */
873 extern const struct rxrpc_security rxrpc_no_security;
874 
875 /*
876  * key.c
877  */
878 extern struct key_type key_type_rxrpc;
879 extern struct key_type key_type_rxrpc_s;
880 
881 int rxrpc_request_key(struct rxrpc_sock *, char __user *, int);
882 int rxrpc_server_keyring(struct rxrpc_sock *, char __user *, int);
883 int rxrpc_get_server_data_key(struct rxrpc_connection *, const void *, time_t,
884 			      u32);
885 
886 /*
887  * local_event.c
888  */
889 extern void rxrpc_process_local_events(struct rxrpc_local *);
890 
891 /*
892  * local_object.c
893  */
894 struct rxrpc_local *rxrpc_lookup_local(struct net *, const struct sockaddr_rxrpc *);
895 void __rxrpc_put_local(struct rxrpc_local *);
896 void rxrpc_destroy_all_locals(struct rxrpc_net *);
897 
898 static inline void rxrpc_get_local(struct rxrpc_local *local)
899 {
900 	atomic_inc(&local->usage);
901 }
902 
903 static inline
904 struct rxrpc_local *rxrpc_get_local_maybe(struct rxrpc_local *local)
905 {
906 	return atomic_inc_not_zero(&local->usage) ? local : NULL;
907 }
908 
909 static inline void rxrpc_put_local(struct rxrpc_local *local)
910 {
911 	if (local && atomic_dec_and_test(&local->usage))
912 		__rxrpc_put_local(local);
913 }
914 
915 static inline void rxrpc_queue_local(struct rxrpc_local *local)
916 {
917 	rxrpc_queue_work(&local->processor);
918 }
919 
920 /*
921  * misc.c
922  */
923 extern unsigned int rxrpc_max_backlog __read_mostly;
924 extern unsigned int rxrpc_requested_ack_delay;
925 extern unsigned int rxrpc_soft_ack_delay;
926 extern unsigned int rxrpc_idle_ack_delay;
927 extern unsigned int rxrpc_rx_window_size;
928 extern unsigned int rxrpc_rx_mtu;
929 extern unsigned int rxrpc_rx_jumbo_max;
930 extern unsigned int rxrpc_resend_timeout;
931 
932 extern const s8 rxrpc_ack_priority[];
933 
934 /*
935  * net_ns.c
936  */
937 extern unsigned int rxrpc_net_id;
938 extern struct pernet_operations rxrpc_net_ops;
939 
940 static inline struct rxrpc_net *rxrpc_net(struct net *net)
941 {
942 	return net_generic(net, rxrpc_net_id);
943 }
944 
945 /*
946  * output.c
947  */
948 int rxrpc_send_ack_packet(struct rxrpc_call *, bool);
949 int rxrpc_send_abort_packet(struct rxrpc_call *);
950 int rxrpc_send_data_packet(struct rxrpc_call *, struct sk_buff *, bool);
951 void rxrpc_reject_packets(struct rxrpc_local *);
952 
953 /*
954  * peer_event.c
955  */
956 void rxrpc_error_report(struct sock *);
957 void rxrpc_peer_error_distributor(struct work_struct *);
958 void rxrpc_peer_add_rtt(struct rxrpc_call *, enum rxrpc_rtt_rx_trace,
959 			rxrpc_serial_t, rxrpc_serial_t, ktime_t, ktime_t);
960 
961 /*
962  * peer_object.c
963  */
964 struct rxrpc_peer *rxrpc_lookup_peer_rcu(struct rxrpc_local *,
965 					 const struct sockaddr_rxrpc *);
966 struct rxrpc_peer *rxrpc_lookup_peer(struct rxrpc_local *,
967 				     struct sockaddr_rxrpc *, gfp_t);
968 struct rxrpc_peer *rxrpc_alloc_peer(struct rxrpc_local *, gfp_t);
969 struct rxrpc_peer *rxrpc_lookup_incoming_peer(struct rxrpc_local *,
970 					      struct rxrpc_peer *);
971 
972 static inline struct rxrpc_peer *rxrpc_get_peer(struct rxrpc_peer *peer)
973 {
974 	atomic_inc(&peer->usage);
975 	return peer;
976 }
977 
978 static inline
979 struct rxrpc_peer *rxrpc_get_peer_maybe(struct rxrpc_peer *peer)
980 {
981 	return atomic_inc_not_zero(&peer->usage) ? peer : NULL;
982 }
983 
984 extern void __rxrpc_put_peer(struct rxrpc_peer *peer);
985 static inline void rxrpc_put_peer(struct rxrpc_peer *peer)
986 {
987 	if (peer && atomic_dec_and_test(&peer->usage))
988 		__rxrpc_put_peer(peer);
989 }
990 
991 /*
992  * proc.c
993  */
994 extern const struct file_operations rxrpc_call_seq_fops;
995 extern const struct file_operations rxrpc_connection_seq_fops;
996 
997 /*
998  * recvmsg.c
999  */
1000 void rxrpc_notify_socket(struct rxrpc_call *);
1001 int rxrpc_recvmsg(struct socket *, struct msghdr *, size_t, int);
1002 
1003 /*
1004  * rxkad.c
1005  */
1006 #ifdef CONFIG_RXKAD
1007 extern const struct rxrpc_security rxkad;
1008 #endif
1009 
1010 /*
1011  * security.c
1012  */
1013 int __init rxrpc_init_security(void);
1014 void rxrpc_exit_security(void);
1015 int rxrpc_init_client_conn_security(struct rxrpc_connection *);
1016 int rxrpc_init_server_conn_security(struct rxrpc_connection *);
1017 
1018 /*
1019  * sendmsg.c
1020  */
1021 int rxrpc_do_sendmsg(struct rxrpc_sock *, struct msghdr *, size_t);
1022 
1023 /*
1024  * skbuff.c
1025  */
1026 void rxrpc_kernel_data_consumed(struct rxrpc_call *, struct sk_buff *);
1027 void rxrpc_packet_destructor(struct sk_buff *);
1028 void rxrpc_new_skb(struct sk_buff *, enum rxrpc_skb_trace);
1029 void rxrpc_see_skb(struct sk_buff *, enum rxrpc_skb_trace);
1030 void rxrpc_get_skb(struct sk_buff *, enum rxrpc_skb_trace);
1031 void rxrpc_free_skb(struct sk_buff *, enum rxrpc_skb_trace);
1032 void rxrpc_lose_skb(struct sk_buff *, enum rxrpc_skb_trace);
1033 void rxrpc_purge_queue(struct sk_buff_head *);
1034 
1035 /*
1036  * sysctl.c
1037  */
1038 #ifdef CONFIG_SYSCTL
1039 extern int __init rxrpc_sysctl_init(void);
1040 extern void rxrpc_sysctl_exit(void);
1041 #else
1042 static inline int __init rxrpc_sysctl_init(void) { return 0; }
1043 static inline void rxrpc_sysctl_exit(void) {}
1044 #endif
1045 
1046 /*
1047  * utils.c
1048  */
1049 int rxrpc_extract_addr_from_skb(struct sockaddr_rxrpc *, struct sk_buff *);
1050 
1051 static inline bool before(u32 seq1, u32 seq2)
1052 {
1053         return (s32)(seq1 - seq2) < 0;
1054 }
1055 static inline bool before_eq(u32 seq1, u32 seq2)
1056 {
1057         return (s32)(seq1 - seq2) <= 0;
1058 }
1059 static inline bool after(u32 seq1, u32 seq2)
1060 {
1061         return (s32)(seq1 - seq2) > 0;
1062 }
1063 static inline bool after_eq(u32 seq1, u32 seq2)
1064 {
1065         return (s32)(seq1 - seq2) >= 0;
1066 }
1067 
1068 /*
1069  * debug tracing
1070  */
1071 extern unsigned int rxrpc_debug;
1072 
1073 #define dbgprintk(FMT,...) \
1074 	printk("[%-6.6s] "FMT"\n", current->comm ,##__VA_ARGS__)
1075 
1076 #define kenter(FMT,...)	dbgprintk("==> %s("FMT")",__func__ ,##__VA_ARGS__)
1077 #define kleave(FMT,...)	dbgprintk("<== %s()"FMT"",__func__ ,##__VA_ARGS__)
1078 #define kdebug(FMT,...)	dbgprintk("    "FMT ,##__VA_ARGS__)
1079 #define kproto(FMT,...)	dbgprintk("### "FMT ,##__VA_ARGS__)
1080 #define knet(FMT,...)	dbgprintk("@@@ "FMT ,##__VA_ARGS__)
1081 
1082 
1083 #if defined(__KDEBUG)
1084 #define _enter(FMT,...)	kenter(FMT,##__VA_ARGS__)
1085 #define _leave(FMT,...)	kleave(FMT,##__VA_ARGS__)
1086 #define _debug(FMT,...)	kdebug(FMT,##__VA_ARGS__)
1087 #define _proto(FMT,...)	kproto(FMT,##__VA_ARGS__)
1088 #define _net(FMT,...)	knet(FMT,##__VA_ARGS__)
1089 
1090 #elif defined(CONFIG_AF_RXRPC_DEBUG)
1091 #define RXRPC_DEBUG_KENTER	0x01
1092 #define RXRPC_DEBUG_KLEAVE	0x02
1093 #define RXRPC_DEBUG_KDEBUG	0x04
1094 #define RXRPC_DEBUG_KPROTO	0x08
1095 #define RXRPC_DEBUG_KNET	0x10
1096 
1097 #define _enter(FMT,...)					\
1098 do {							\
1099 	if (unlikely(rxrpc_debug & RXRPC_DEBUG_KENTER))	\
1100 		kenter(FMT,##__VA_ARGS__);		\
1101 } while (0)
1102 
1103 #define _leave(FMT,...)					\
1104 do {							\
1105 	if (unlikely(rxrpc_debug & RXRPC_DEBUG_KLEAVE))	\
1106 		kleave(FMT,##__VA_ARGS__);		\
1107 } while (0)
1108 
1109 #define _debug(FMT,...)					\
1110 do {							\
1111 	if (unlikely(rxrpc_debug & RXRPC_DEBUG_KDEBUG))	\
1112 		kdebug(FMT,##__VA_ARGS__);		\
1113 } while (0)
1114 
1115 #define _proto(FMT,...)					\
1116 do {							\
1117 	if (unlikely(rxrpc_debug & RXRPC_DEBUG_KPROTO))	\
1118 		kproto(FMT,##__VA_ARGS__);		\
1119 } while (0)
1120 
1121 #define _net(FMT,...)					\
1122 do {							\
1123 	if (unlikely(rxrpc_debug & RXRPC_DEBUG_KNET))	\
1124 		knet(FMT,##__VA_ARGS__);		\
1125 } while (0)
1126 
1127 #else
1128 #define _enter(FMT,...)	no_printk("==> %s("FMT")",__func__ ,##__VA_ARGS__)
1129 #define _leave(FMT,...)	no_printk("<== %s()"FMT"",__func__ ,##__VA_ARGS__)
1130 #define _debug(FMT,...)	no_printk("    "FMT ,##__VA_ARGS__)
1131 #define _proto(FMT,...)	no_printk("### "FMT ,##__VA_ARGS__)
1132 #define _net(FMT,...)	no_printk("@@@ "FMT ,##__VA_ARGS__)
1133 #endif
1134 
1135 /*
1136  * debug assertion checking
1137  */
1138 #if 1 // defined(__KDEBUGALL)
1139 
1140 #define ASSERT(X)						\
1141 do {								\
1142 	if (unlikely(!(X))) {					\
1143 		pr_err("Assertion failed\n");			\
1144 		BUG();						\
1145 	}							\
1146 } while (0)
1147 
1148 #define ASSERTCMP(X, OP, Y)						\
1149 do {									\
1150 	__typeof__(X) _x = (X);						\
1151 	__typeof__(Y) _y = (__typeof__(X))(Y);				\
1152 	if (unlikely(!(_x OP _y))) {					\
1153 		pr_err("Assertion failed - %lu(0x%lx) %s %lu(0x%lx) is false\n", \
1154 		       (unsigned long)_x, (unsigned long)_x, #OP,	\
1155 		       (unsigned long)_y, (unsigned long)_y);		\
1156 		BUG();							\
1157 	}								\
1158 } while (0)
1159 
1160 #define ASSERTIF(C, X)						\
1161 do {								\
1162 	if (unlikely((C) && !(X))) {				\
1163 		pr_err("Assertion failed\n");			\
1164 		BUG();						\
1165 	}							\
1166 } while (0)
1167 
1168 #define ASSERTIFCMP(C, X, OP, Y)					\
1169 do {									\
1170 	__typeof__(X) _x = (X);						\
1171 	__typeof__(Y) _y = (__typeof__(X))(Y);				\
1172 	if (unlikely((C) && !(_x OP _y))) {				\
1173 		pr_err("Assertion failed - %lu(0x%lx) %s %lu(0x%lx) is false\n", \
1174 		       (unsigned long)_x, (unsigned long)_x, #OP,	\
1175 		       (unsigned long)_y, (unsigned long)_y);		\
1176 		BUG();							\
1177 	}								\
1178 } while (0)
1179 
1180 #else
1181 
1182 #define ASSERT(X)				\
1183 do {						\
1184 } while (0)
1185 
1186 #define ASSERTCMP(X, OP, Y)			\
1187 do {						\
1188 } while (0)
1189 
1190 #define ASSERTIF(C, X)				\
1191 do {						\
1192 } while (0)
1193 
1194 #define ASSERTIFCMP(C, X, OP, Y)		\
1195 do {						\
1196 } while (0)
1197 
1198 #endif /* __KDEBUGALL */
1199