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