Blame view

net/rxrpc/ar-internal.h 41.7 KB
2874c5fd2   Thomas Gleixner   treewide: Replace...
1
  /* SPDX-License-Identifier: GPL-2.0-or-later */
17926a793   David Howells   [AF_RXRPC]: Provi...
2
3
4
5
  /* AF_RXRPC internal definitions
   *
   * Copyright (C) 2007 Red Hat, Inc. All Rights Reserved.
   * Written by David Howells (dhowells@redhat.com)
17926a793   David Howells   [AF_RXRPC]: Provi...
6
   */
be6e6707f   David Howells   rxrpc: Rework pee...
7
  #include <linux/atomic.h>
8496af50e   David Howells   rxrpc: Use RCU to...
8
  #include <linux/seqlock.h>
c410bf019   David Howells   rxrpc: Fix the ex...
9
  #include <linux/win_minmax.h>
2baec2c3f   David Howells   rxrpc: Support ne...
10
11
  #include <net/net_namespace.h>
  #include <net/netns/generic.h>
e0e4d82f3   David Howells   rxrpc: Create a n...
12
  #include <net/sock.h>
be6e6707f   David Howells   rxrpc: Rework pee...
13
  #include <net/af_rxrpc.h>
ddc6c70f0   David Howells   rxrpc: Move the p...
14
  #include "protocol.h"
17926a793   David Howells   [AF_RXRPC]: Provi...
15
16
17
18
19
20
  
  #if 0
  #define CHECK_SLAB_OKAY(X)				     \
  	BUG_ON(atomic_read((X)) >> (sizeof(atomic_t) - 2) == \
  	       (POISON_FREE << 8 | POISON_FREE))
  #else
b4f1342f9   David Howells   rxrpc: Adjust som...
21
  #define CHECK_SLAB_OKAY(X) do {} while (0)
17926a793   David Howells   [AF_RXRPC]: Provi...
22
  #endif
17926a793   David Howells   [AF_RXRPC]: Provi...
23
24
25
26
  #define FCRYPT_BSIZE 8
  struct rxrpc_crypt {
  	union {
  		u8	x[FCRYPT_BSIZE];
91e916cff   Al Viro   net/rxrpc trivial...
27
  		__be32	n[2];
17926a793   David Howells   [AF_RXRPC]: Provi...
28
29
  	};
  } __attribute__((aligned(8)));
651350d10   David Howells   [AF_RXRPC]: Add a...
30
31
32
  #define rxrpc_queue_work(WS)	queue_work(rxrpc_workqueue, (WS))
  #define rxrpc_queue_delayed_work(WS,D)	\
  	queue_delayed_work(rxrpc_workqueue, (WS), (D))
cc8feb8ed   David Howells   rxrpc: Fix exclus...
33
  struct rxrpc_connection;
17926a793   David Howells   [AF_RXRPC]: Provi...
34
  /*
ece64fec1   David Howells   rxrpc: Emit BUSY ...
35
36
   * Mark applied to socket buffers in skb->mark.  skb->priority is used
   * to pass supplementary information.
d001648ec   David Howells   rxrpc: Don't expo...
37
38
   */
  enum rxrpc_skb_mark {
ece64fec1   David Howells   rxrpc: Emit BUSY ...
39
40
  	RXRPC_SKB_MARK_REJECT_BUSY,	/* Reject with BUSY */
  	RXRPC_SKB_MARK_REJECT_ABORT,	/* Reject with ABORT (code in skb->priority) */
d001648ec   David Howells   rxrpc: Don't expo...
41
42
43
  };
  
  /*
17926a793   David Howells   [AF_RXRPC]: Provi...
44
45
46
   * sk_state for RxRPC sockets
   */
  enum {
2341e0775   David Howells   rxrpc: Simplify c...
47
48
  	RXRPC_UNBOUND = 0,
  	RXRPC_CLIENT_UNBOUND,		/* Unbound socket used as client */
17926a793   David Howells   [AF_RXRPC]: Provi...
49
  	RXRPC_CLIENT_BOUND,		/* client local address bound */
17926a793   David Howells   [AF_RXRPC]: Provi...
50
  	RXRPC_SERVER_BOUND,		/* server local address bound */
28036f448   David Howells   rxrpc: Permit mul...
51
  	RXRPC_SERVER_BOUND2,		/* second server local address bound */
17926a793   David Howells   [AF_RXRPC]: Provi...
52
  	RXRPC_SERVER_LISTENING,		/* server listening for connections */
210f03531   David Howells   rxrpc: Allow list...
53
  	RXRPC_SERVER_LISTEN_DISABLED,	/* server listening disabled */
17926a793   David Howells   [AF_RXRPC]: Provi...
54
55
56
57
  	RXRPC_CLOSE,			/* socket is being closed */
  };
  
  /*
2baec2c3f   David Howells   rxrpc: Support ne...
58
59
60
61
62
63
64
   * Per-network namespace data.
   */
  struct rxrpc_net {
  	struct proc_dir_entry	*proc_net;	/* Subdir in /proc/net */
  	u32			epoch;		/* Local epoch for detecting local-end reset */
  	struct list_head	calls;		/* List of calls active in this namespace */
  	rwlock_t		call_lock;	/* Lock for ->calls */
d3be4d244   David Howells   rxrpc: Fix potent...
65
  	atomic_t		nr_calls;	/* Count of allocated calls */
2baec2c3f   David Howells   rxrpc: Support ne...
66

31f5f9a16   David Howells   rxrpc: Fix appare...
67
  	atomic_t		nr_conns;
2baec2c3f   David Howells   rxrpc: Support ne...
68
69
70
  	struct list_head	conn_proc_list;	/* List of conns in this namespace for proc */
  	struct list_head	service_conns;	/* Service conns in this namespace */
  	rwlock_t		conn_lock;	/* Lock for ->conn_proc_list, ->service_conns */
3d18cbb7f   David Howells   rxrpc: Fix conn e...
71
72
  	struct work_struct	service_conn_reaper;
  	struct timer_list	service_conn_reap_timer;
2baec2c3f   David Howells   rxrpc: Support ne...
73

f859ab618   David Howells   rxrpc: Fix servic...
74
  	bool			live;
245500d85   David Howells   rxrpc: Rewrite th...
75
76
77
  
  	bool			kill_all_client_conns;
  	atomic_t		nr_client_conns;
2baec2c3f   David Howells   rxrpc: Support ne...
78
79
  	spinlock_t		client_conn_cache_lock; /* Lock for ->*_client_conns */
  	spinlock_t		client_conn_discard_lock; /* Prevent multiple discarders */
2baec2c3f   David Howells   rxrpc: Support ne...
80
  	struct list_head	idle_client_conns;
3d18cbb7f   David Howells   rxrpc: Fix conn e...
81
82
  	struct work_struct	client_conn_reaper;
  	struct timer_list	client_conn_reap_timer;
2baec2c3f   David Howells   rxrpc: Support ne...
83
84
85
  
  	struct list_head	local_endpoints;
  	struct mutex		local_mutex;	/* Lock for ->local_endpoints */
2baec2c3f   David Howells   rxrpc: Support ne...
86
  	DECLARE_HASHTABLE	(peer_hash, 10);
ace45bec6   David Howells   rxrpc: Fix firewa...
87
88
89
90
  	spinlock_t		peer_hash_lock;	/* Lock for ->peer_hash */
  
  #define RXRPC_KEEPALIVE_TIME 20 /* NAT keepalive time in seconds */
  	u8			peer_keepalive_cursor;
330bdcfad   David Howells   rxrpc: Fix the ke...
91
92
93
  	time64_t		peer_keepalive_base;
  	struct list_head	peer_keepalive[32];
  	struct list_head	peer_keepalive_new;
ace45bec6   David Howells   rxrpc: Fix firewa...
94
95
  	struct timer_list	peer_keepalive_timer;
  	struct work_struct	peer_keepalive_work;
2baec2c3f   David Howells   rxrpc: Support ne...
96
97
98
  };
  
  /*
00e907127   David Howells   rxrpc: Preallocat...
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
   * Service backlog preallocation.
   *
   * This contains circular buffers of preallocated peers, connections and calls
   * for incoming service calls and their head and tail pointers.  This allows
   * calls to be set up in the data_ready handler, thereby avoiding the need to
   * shuffle packets around so much.
   */
  struct rxrpc_backlog {
  	unsigned short		peer_backlog_head;
  	unsigned short		peer_backlog_tail;
  	unsigned short		conn_backlog_head;
  	unsigned short		conn_backlog_tail;
  	unsigned short		call_backlog_head;
  	unsigned short		call_backlog_tail;
  #define RXRPC_BACKLOG_MAX	32
  	struct rxrpc_peer	*peer_backlog[RXRPC_BACKLOG_MAX];
  	struct rxrpc_connection	*conn_backlog[RXRPC_BACKLOG_MAX];
  	struct rxrpc_call	*call_backlog[RXRPC_BACKLOG_MAX];
  };
  
  /*
17926a793   David Howells   [AF_RXRPC]: Provi...
120
121
122
123
124
   * RxRPC socket definition
   */
  struct rxrpc_sock {
  	/* WARNING: sk has to be the first member */
  	struct sock		sk;
d001648ec   David Howells   rxrpc: Don't expo...
125
  	rxrpc_notify_new_call_t	notify_new_call; /* Func to notify of new call */
00e907127   David Howells   rxrpc: Preallocat...
126
  	rxrpc_discard_new_call_t discard_new_call; /* Func to discard a new call */
17926a793   David Howells   [AF_RXRPC]: Provi...
127
  	struct rxrpc_local	*local;		/* local endpoint */
00e907127   David Howells   rxrpc: Preallocat...
128
  	struct rxrpc_backlog	*backlog;	/* Preallocation for services */
248f219cb   David Howells   rxrpc: Rewrite th...
129
130
131
132
133
  	spinlock_t		incoming_lock;	/* Incoming call vs service shutdown lock */
  	struct list_head	sock_calls;	/* List of calls owned by this socket */
  	struct list_head	to_be_accepted;	/* calls awaiting acceptance */
  	struct list_head	recvmsg_q;	/* Calls awaiting recvmsg's attention  */
  	rwlock_t		recvmsg_lock;	/* Lock for recvmsg_q */
17926a793   David Howells   [AF_RXRPC]: Provi...
134
135
  	struct key		*key;		/* security for this socket */
  	struct key		*securities;	/* list of server security descriptors */
00e907127   David Howells   rxrpc: Preallocat...
136
  	struct rb_root		calls;		/* User ID -> call mapping */
17926a793   David Howells   [AF_RXRPC]: Provi...
137
  	unsigned long		flags;
2341e0775   David Howells   rxrpc: Simplify c...
138
  #define RXRPC_SOCK_CONNECTED		0	/* connect_srx is set */
17926a793   David Howells   [AF_RXRPC]: Provi...
139
140
141
  	rwlock_t		call_lock;	/* lock for calls */
  	u32			min_sec_level;	/* minimum security level */
  #define RXRPC_SECURITY_MAX	RXRPC_SECURITY_ENCRYPT
cc8feb8ed   David Howells   rxrpc: Fix exclus...
142
  	bool			exclusive;	/* Exclusive connection for a client socket */
28036f448   David Howells   rxrpc: Permit mul...
143
  	u16			second_service;	/* Additional service bound to the endpoint */
4722974d9   David Howells   rxrpc: Implement ...
144
145
146
147
148
  	struct {
  		/* Service upgrade information */
  		u16		from;		/* Service ID to upgrade (if not 0) */
  		u16		to;		/* service ID to upgrade to */
  	} service_upgrade;
cc8feb8ed   David Howells   rxrpc: Fix exclus...
149
  	sa_family_t		family;		/* Protocol family created with */
4722974d9   David Howells   rxrpc: Implement ...
150
  	struct sockaddr_rxrpc	srx;		/* Primary Service/local addresses */
2341e0775   David Howells   rxrpc: Simplify c...
151
  	struct sockaddr_rxrpc	connect_srx;	/* Default client address from connect() */
17926a793   David Howells   [AF_RXRPC]: Provi...
152
153
154
155
156
  };
  
  #define rxrpc_sk(__sk) container_of((__sk), struct rxrpc_sock, sk)
  
  /*
0d12f8a40   David Howells   rxrpc: Keep the s...
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
   * CPU-byteorder normalised Rx packet header.
   */
  struct rxrpc_host_header {
  	u32		epoch;		/* client boot timestamp */
  	u32		cid;		/* connection and channel ID */
  	u32		callNumber;	/* call ID (0 for connection-level packets) */
  	u32		seq;		/* sequence number of pkt in call stream */
  	u32		serial;		/* serial number of pkt sent to network */
  	u8		type;		/* packet type */
  	u8		flags;		/* packet flags */
  	u8		userStatus;	/* app-layer defined status */
  	u8		securityIndex;	/* security protocol ID */
  	union {
  		u16	_rsvd;		/* reserved */
  		u16	cksum;		/* kerberos security checksum */
  	};
  	u16		serviceId;	/* service ID */
  } __packed;
  
  /*
17926a793   David Howells   [AF_RXRPC]: Provi...
177
178
179
180
   * RxRPC socket buffer private variables
   * - max 48 bytes (struct sk_buff::cb)
   */
  struct rxrpc_skb_priv {
987db9f7c   David Howells   rxrpc: Use the tx...
181
  	atomic_t	nr_ring_pins;		/* Number of rxtx ring pins */
c3c9e3df4   David Howells   rxrpc: Improve ju...
182
183
184
  	u8		nr_subpackets;		/* Number of subpackets */
  	u8		rx_flags;		/* Received packet flags */
  #define RXRPC_SKB_INCL_LAST	0x01		/* - Includes last packet */
b311e6842   David Howells   rxrpc: Add a priv...
185
  #define RXRPC_SKB_TX_BUFFER	0x02		/* - Is transmit buffer */
17926a793   David Howells   [AF_RXRPC]: Provi...
186
  	union {
17926a793   David Howells   [AF_RXRPC]: Provi...
187
  		int		remain;		/* amount of space remaining for next write */
c3c9e3df4   David Howells   rxrpc: Improve ju...
188
189
190
191
  
  		/* List of requested ACKs on subpackets */
  		unsigned long	rx_req_ack[(RXRPC_MAX_NR_JUMBO + BITS_PER_LONG - 1) /
  					   BITS_PER_LONG];
17926a793   David Howells   [AF_RXRPC]: Provi...
192
  	};
0d12f8a40   David Howells   rxrpc: Keep the s...
193
  	struct rxrpc_host_header hdr;		/* RxRPC packet header from this packet */
17926a793   David Howells   [AF_RXRPC]: Provi...
194
195
196
  };
  
  #define rxrpc_skb(__skb) ((struct rxrpc_skb_priv *) &(__skb)->cb)
17926a793   David Howells   [AF_RXRPC]: Provi...
197
198
199
200
  /*
   * RxRPC security module interface
   */
  struct rxrpc_security {
17926a793   David Howells   [AF_RXRPC]: Provi...
201
202
  	const char		*name;		/* name of this service */
  	u8			security_index;	/* security type provided */
063c60d39   David Howells   rxrpc: Fix missin...
203
  	u32			no_key_abort;	/* Abort code indicating no key */
17926a793   David Howells   [AF_RXRPC]: Provi...
204

648af7fca   David Howells   rxrpc: Absorb the...
205
206
207
208
209
  	/* Initialise a security service */
  	int (*init)(void);
  
  	/* Clean up a security service */
  	void (*exit)(void);
17926a793   David Howells   [AF_RXRPC]: Provi...
210
211
212
213
  	/* initialise a connection's security */
  	int (*init_connection_security)(struct rxrpc_connection *);
  
  	/* prime a connection's packet security */
a263629da   Herbert Xu   rxrpc: Avoid usin...
214
  	int (*prime_packet_security)(struct rxrpc_connection *);
17926a793   David Howells   [AF_RXRPC]: Provi...
215
216
  
  	/* impose security on a packet */
a263629da   Herbert Xu   rxrpc: Avoid usin...
217
  	int (*secure_packet)(struct rxrpc_call *,
17926a793   David Howells   [AF_RXRPC]: Provi...
218
219
220
221
222
  			     struct sk_buff *,
  			     size_t,
  			     void *);
  
  	/* verify the security on a received packet */
5a42976d4   David Howells   rxrpc: Add tracep...
223
  	int (*verify_packet)(struct rxrpc_call *, struct sk_buff *,
248f219cb   David Howells   rxrpc: Rewrite th...
224
  			     unsigned int, unsigned int, rxrpc_seq_t, u16);
1db88c534   David Howells   rxrpc: Fix -Wfram...
225
226
  	/* Free crypto request on a call */
  	void (*free_call_crypto)(struct rxrpc_call *);
248f219cb   David Howells   rxrpc: Rewrite th...
227
228
229
  	/* Locate the data in a received packet that has been verified. */
  	void (*locate_data)(struct rxrpc_call *, struct sk_buff *,
  			    unsigned int *, unsigned int *);
17926a793   David Howells   [AF_RXRPC]: Provi...
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
  
  	/* issue a challenge */
  	int (*issue_challenge)(struct rxrpc_connection *);
  
  	/* respond to a challenge */
  	int (*respond_to_challenge)(struct rxrpc_connection *,
  				    struct sk_buff *,
  				    u32 *);
  
  	/* verify a response */
  	int (*verify_response)(struct rxrpc_connection *,
  			       struct sk_buff *,
  			       u32 *);
  
  	/* clear connection security */
  	void (*clear)(struct rxrpc_connection *);
  };
  
  /*
4f95dd78a   David Howells   rxrpc: Rework loc...
249
250
251
   * RxRPC local transport endpoint description
   * - owned by a single AF_RXRPC socket
   * - pointed to by transport socket struct sk_user_data
17926a793   David Howells   [AF_RXRPC]: Provi...
252
253
   */
  struct rxrpc_local {
4f95dd78a   David Howells   rxrpc: Rework loc...
254
  	struct rcu_head		rcu;
730c5fd42   David Howells   rxrpc: Fix local ...
255
256
  	atomic_t		active_users;	/* Number of users of the local endpoint */
  	atomic_t		usage;		/* Number of references to the structure */
2baec2c3f   David Howells   rxrpc: Support ne...
257
  	struct rxrpc_net	*rxnet;		/* The network ns in which this resides */
4f95dd78a   David Howells   rxrpc: Rework loc...
258
  	struct list_head	link;
17926a793   David Howells   [AF_RXRPC]: Provi...
259
  	struct socket		*socket;	/* my UDP socket */
4f95dd78a   David Howells   rxrpc: Rework loc...
260
  	struct work_struct	processor;
1e9e5c952   David Howells   rxrpc: Reduce the...
261
  	struct rxrpc_sock __rcu	*service;	/* Service(s) listening on this endpoint */
17926a793   David Howells   [AF_RXRPC]: Provi...
262
  	struct rw_semaphore	defrag_sem;	/* control re-enablement of IP DF bit */
17926a793   David Howells   [AF_RXRPC]: Provi...
263
  	struct sk_buff_head	reject_queue;	/* packets awaiting rejection */
44ba06987   David Howells   RxRPC: Handle VER...
264
  	struct sk_buff_head	event_queue;	/* endpoint event packets awaiting processing */
245500d85   David Howells   rxrpc: Rewrite th...
265
266
  	struct rb_root		client_bundles;	/* Client connection bundles by socket params */
  	spinlock_t		client_bundles_lock; /* Lock for client_bundles */
17926a793   David Howells   [AF_RXRPC]: Provi...
267
268
  	spinlock_t		lock;		/* access lock */
  	rwlock_t		services_lock;	/* lock for services list */
17926a793   David Howells   [AF_RXRPC]: Provi...
269
  	int			debug_id;	/* debug ID for printks */
4f95dd78a   David Howells   rxrpc: Rework loc...
270
  	bool			dead;
f859ab618   David Howells   rxrpc: Fix servic...
271
  	bool			service_closed;	/* Service socket closed */
17926a793   David Howells   [AF_RXRPC]: Provi...
272
273
274
275
276
  	struct sockaddr_rxrpc	srx;		/* local address */
  };
  
  /*
   * RxRPC remote transport endpoint definition
be6e6707f   David Howells   rxrpc: Rework pee...
277
   * - matched by local endpoint, remote port, address and protocol type
17926a793   David Howells   [AF_RXRPC]: Provi...
278
279
   */
  struct rxrpc_peer {
be6e6707f   David Howells   rxrpc: Rework pee...
280
281
282
283
284
  	struct rcu_head		rcu;		/* This must be first */
  	atomic_t		usage;
  	unsigned long		hash_key;
  	struct hlist_node	hash_link;
  	struct rxrpc_local	*local;
f66d74901   David Howells   rxrpc: Use the pe...
285
  	struct hlist_head	error_targets;	/* targets for net error distribution */
aa390bbe2   David Howells   rxrpc: Kill off t...
286
  	struct rb_root		service_conns;	/* Service connections */
330bdcfad   David Howells   rxrpc: Fix the ke...
287
  	struct list_head	keepalive_link;	/* Link in net->peer_keepalive[] */
ace45bec6   David Howells   rxrpc: Fix firewa...
288
  	time64_t		last_tx_at;	/* Last time packet sent here */
8496af50e   David Howells   rxrpc: Use RCU to...
289
  	seqlock_t		service_conn_lock;
17926a793   David Howells   [AF_RXRPC]: Provi...
290
  	spinlock_t		lock;		/* access lock */
95c961747   Eric Dumazet   net: cleanup unsi...
291
292
293
  	unsigned int		if_mtu;		/* interface MTU for this peer */
  	unsigned int		mtu;		/* network MTU for this peer */
  	unsigned int		maxdata;	/* data size (MTU - hdrsize) */
17926a793   David Howells   [AF_RXRPC]: Provi...
294
295
  	unsigned short		hdrsize;	/* header size (IP + UDP + RxRPC) */
  	int			debug_id;	/* debug ID for printks */
17926a793   David Howells   [AF_RXRPC]: Provi...
296
297
298
299
  	struct sockaddr_rxrpc	srx;		/* remote address */
  
  	/* calculated RTT cache */
  #define RXRPC_RTT_CACHE_SIZE 32
c1e15b494   David Howells   rxrpc: Fix the pa...
300
  	spinlock_t		rtt_input_lock;	/* RTT lock for input routine */
0d4b103c0   David Howells   rxrpc: Reduce the...
301
  	ktime_t			rtt_last_req;	/* Time of last RTT request */
c410bf019   David Howells   rxrpc: Fix the ex...
302
303
304
305
306
307
308
309
  	unsigned int		rtt_count;	/* Number of samples we've got */
  
  	u32			srtt_us;	/* smoothed round trip time << 3 in usecs */
  	u32			mdev_us;	/* medium deviation			*/
  	u32			mdev_max_us;	/* maximal mdev for the last rtt period	*/
  	u32			rttvar_us;	/* smoothed mdev_max			*/
  	u32			rto_j;		/* Retransmission timeout in jiffies */
  	u8			backoff;	/* Backoff timeout */
f7aec129a   David Howells   rxrpc: Cache the ...
310
311
  
  	u8			cong_cwnd;	/* Congestion window size */
17926a793   David Howells   [AF_RXRPC]: Provi...
312
313
314
  };
  
  /*
19ffa01c9   David Howells   rxrpc: Use struct...
315
316
317
   * Keys for matching a connection.
   */
  struct rxrpc_conn_proto {
e8d70ce17   David Howells   rxrpc: Prune the ...
318
319
320
321
322
323
  	union {
  		struct {
  			u32	epoch;		/* epoch of this connection */
  			u32	cid;		/* connection ID */
  		};
  		u64		index_key;
19ffa01c9   David Howells   rxrpc: Use struct...
324
325
326
327
328
329
330
331
  	};
  };
  
  struct rxrpc_conn_parameters {
  	struct rxrpc_local	*local;		/* Representation of local endpoint */
  	struct rxrpc_peer	*peer;		/* Remote endpoint */
  	struct key		*key;		/* Security details */
  	bool			exclusive;	/* T if conn is exclusive */
4e255721d   David Howells   rxrpc: Add servic...
332
  	bool			upgrade;	/* T if service ID can be upgraded */
19ffa01c9   David Howells   rxrpc: Use struct...
333
334
335
336
337
  	u16			service_id;	/* Service ID for this connection */
  	u32			security_level;	/* Security level selected */
  };
  
  /*
bba304db3   David Howells   rxrpc: Turn conne...
338
339
340
341
   * Bits in the connection flags.
   */
  enum rxrpc_conn_flag {
  	RXRPC_CONN_HAS_IDR,		/* Has a client conn ID assigned */
001c11224   David Howells   rxrpc: Maintain a...
342
  	RXRPC_CONN_IN_SERVICE_CONNS,	/* Conn is in peer->service_conns */
45025bcee   David Howells   rxrpc: Improve ma...
343
  	RXRPC_CONN_DONT_REUSE,		/* Don't reuse this connection */
4e255721d   David Howells   rxrpc: Add servic...
344
  	RXRPC_CONN_PROBING_FOR_UPGRADE,	/* Probing for service upgrade */
3136ef49a   David Howells   rxrpc: Delay term...
345
346
347
348
  	RXRPC_CONN_FINAL_ACK_0,		/* Need final ACK for channel 0 */
  	RXRPC_CONN_FINAL_ACK_1,		/* Need final ACK for channel 1 */
  	RXRPC_CONN_FINAL_ACK_2,		/* Need final ACK for channel 2 */
  	RXRPC_CONN_FINAL_ACK_3,		/* Need final ACK for channel 3 */
bba304db3   David Howells   rxrpc: Turn conne...
349
  };
3136ef49a   David Howells   rxrpc: Delay term...
350
351
352
353
  #define RXRPC_CONN_FINAL_ACK_MASK ((1UL << RXRPC_CONN_FINAL_ACK_0) |	\
  				   (1UL << RXRPC_CONN_FINAL_ACK_1) |	\
  				   (1UL << RXRPC_CONN_FINAL_ACK_2) |	\
  				   (1UL << RXRPC_CONN_FINAL_ACK_3))
bba304db3   David Howells   rxrpc: Turn conne...
354
355
356
357
358
359
360
361
362
363
364
365
366
  /*
   * Events that can be raised upon a connection.
   */
  enum rxrpc_conn_event {
  	RXRPC_CONN_EV_CHALLENGE,	/* Send challenge packet */
  };
  
  /*
   * The connection protocol state.
   */
  enum rxrpc_conn_proto_state {
  	RXRPC_CONN_UNUSED,		/* Connection not yet attempted */
  	RXRPC_CONN_CLIENT,		/* Client connection */
00e907127   David Howells   rxrpc: Preallocat...
367
  	RXRPC_CONN_SERVICE_PREALLOC,	/* Service connection preallocation */
bba304db3   David Howells   rxrpc: Turn conne...
368
369
370
371
372
  	RXRPC_CONN_SERVICE_UNSECURED,	/* Service unsecured connection */
  	RXRPC_CONN_SERVICE_CHALLENGING,	/* Service challenging for security */
  	RXRPC_CONN_SERVICE,		/* Service secured connection */
  	RXRPC_CONN_REMOTELY_ABORTED,	/* Conn aborted by peer */
  	RXRPC_CONN_LOCALLY_ABORTED,	/* Conn aborted locally */
bba304db3   David Howells   rxrpc: Turn conne...
373
374
375
376
  	RXRPC_CONN__NR_STATES
  };
  
  /*
245500d85   David Howells   rxrpc: Rewrite th...
377
378
379
380
381
382
383
384
   * RxRPC client connection bundle.
   */
  struct rxrpc_bundle {
  	struct rxrpc_conn_parameters params;
  	atomic_t		usage;
  	unsigned int		debug_id;
  	bool			try_upgrade;	/* True if the bundle is attempting upgrade */
  	bool			alloc_conn;	/* True if someone's getting a conn */
8806245a3   David Howells   rxrpc: Fix rxrpc_...
385
  	short			alloc_error;	/* Error from last conn allocation */
245500d85   David Howells   rxrpc: Rewrite th...
386
387
388
389
390
391
392
393
  	spinlock_t		channel_lock;
  	struct rb_node		local_node;	/* Node in local->client_conns */
  	struct list_head	waiting_calls;	/* Calls waiting for channels */
  	unsigned long		avail_chans;	/* Mask of available channels */
  	struct rxrpc_connection	*conns[4];	/* The connections in the bundle (max 4) */
  };
  
  /*
17926a793   David Howells   [AF_RXRPC]: Provi...
394
   * RxRPC connection definition
aa390bbe2   David Howells   rxrpc: Kill off t...
395
   * - matched by { local, peer, epoch, conn_id, direction }
17926a793   David Howells   [AF_RXRPC]: Provi...
396
397
398
   * - each connection can only handle four simultaneous calls
   */
  struct rxrpc_connection {
19ffa01c9   David Howells   rxrpc: Use struct...
399
400
  	struct rxrpc_conn_proto	proto;
  	struct rxrpc_conn_parameters params;
45025bcee   David Howells   rxrpc: Improve ma...
401
402
403
  	atomic_t		usage;
  	struct rcu_head		rcu;
  	struct list_head	cache_link;
a1399f8bb   David Howells   rxrpc: Call chann...
404

245500d85   David Howells   rxrpc: Rewrite th...
405
  	unsigned char		act_chans;	/* Mask of active channels */
a1399f8bb   David Howells   rxrpc: Call chann...
406
  	struct rxrpc_channel {
3136ef49a   David Howells   rxrpc: Delay term...
407
  		unsigned long		final_ack_at;	/* Time at which to issue final ACK */
a1399f8bb   David Howells   rxrpc: Call chann...
408
  		struct rxrpc_call __rcu	*call;		/* Active call */
4764c0da6   David Howells   rxrpc: Trace pack...
409
  		unsigned int		call_debug_id;	/* call->debug_id */
a1399f8bb   David Howells   rxrpc: Call chann...
410
411
412
  		u32			call_id;	/* ID of current call */
  		u32			call_counter;	/* Call ID counter */
  		u32			last_call;	/* ID of last call */
18bfeba50   David Howells   rxrpc: Perform te...
413
  		u8			last_type;	/* Type of last packet */
18bfeba50   David Howells   rxrpc: Perform te...
414
415
416
417
  		union {
  			u32		last_seq;
  			u32		last_abort;
  		};
a1399f8bb   David Howells   rxrpc: Call chann...
418
  	} channels[RXRPC_MAXCALLS];
999b69f89   David Howells   rxrpc: Kill the c...
419

3136ef49a   David Howells   rxrpc: Delay term...
420
  	struct timer_list	timer;		/* Conn event timer */
17926a793   David Howells   [AF_RXRPC]: Provi...
421
  	struct work_struct	processor;	/* connection event processor */
245500d85   David Howells   rxrpc: Rewrite th...
422
423
  	struct rxrpc_bundle	*bundle;	/* Client connection bundle */
  	struct rb_node		service_node;	/* Node in peer->service_conns */
4d028b2c8   David Howells   rxrpc: Dup the ma...
424
  	struct list_head	proc_link;	/* link in procfs list */
17926a793   David Howells   [AF_RXRPC]: Provi...
425
  	struct list_head	link;		/* link in master connection list */
17926a793   David Howells   [AF_RXRPC]: Provi...
426
  	struct sk_buff_head	rx_queue;	/* received conn-level packets */
648af7fca   David Howells   rxrpc: Absorb the...
427
  	const struct rxrpc_security *security;	/* applied security module */
17926a793   David Howells   [AF_RXRPC]: Provi...
428
  	struct key		*server_key;	/* security for this service */
69d826fa5   Kees Cook   rxrpc: Remove VLA...
429
  	struct crypto_sync_skcipher *cipher;	/* encryption handle */
17926a793   David Howells   [AF_RXRPC]: Provi...
430
  	struct rxrpc_crypt	csum_iv;	/* packet checksum base */
4a3388c80   David Howells   rxrpc: Use IDR to...
431
  	unsigned long		flags;
17926a793   David Howells   [AF_RXRPC]: Provi...
432
  	unsigned long		events;
f51b44800   David Howells   rxrpc: Set connec...
433
  	unsigned long		idle_timestamp;	/* Time at which last became idle */
17926a793   David Howells   [AF_RXRPC]: Provi...
434
  	spinlock_t		state_lock;	/* state-change lock */
cf13258fd   David Howells   rxrpc: Fix ASSERT...
435
  	enum rxrpc_conn_proto_state state;	/* current state of connection */
647530924   David Howells   rxrpc: Fix connec...
436
  	u32			abort_code;	/* Abort code of connection abort */
17926a793   David Howells   [AF_RXRPC]: Provi...
437
  	int			debug_id;	/* debug ID for printks */
17926a793   David Howells   [AF_RXRPC]: Provi...
438
  	atomic_t		serial;		/* packet serial number counter */
563ea7d5d   David Howells   rxrpc: Calculate ...
439
  	unsigned int		hi_serial;	/* highest serial number received */
5a924b895   David Howells   rxrpc: Don't stor...
440
  	u32			security_nonce;	/* response re-use preventer */
c1e15b494   David Howells   rxrpc: Fix the pa...
441
  	u32			service_id;	/* Service ID, possibly upgraded */
17926a793   David Howells   [AF_RXRPC]: Provi...
442
  	u8			size_align;	/* data size alignment (for security) */
17926a793   David Howells   [AF_RXRPC]: Provi...
443
  	u8			security_size;	/* security header size */
17926a793   David Howells   [AF_RXRPC]: Provi...
444
  	u8			security_ix;	/* security type */
17926a793   David Howells   [AF_RXRPC]: Provi...
445
  	u8			out_clientflag;	/* RXRPC_CLIENT_INITIATED if we are client */
245500d85   David Howells   rxrpc: Rewrite th...
446
  	u8			bundle_shift;	/* Index into bundle->avail_chans */
647530924   David Howells   rxrpc: Fix connec...
447
  	short			error;		/* Local error code */
17926a793   David Howells   [AF_RXRPC]: Provi...
448
  };
dc71db34e   David Howells   rxrpc: Fix checks...
449
450
451
452
453
454
455
456
457
  static inline bool rxrpc_to_server(const struct rxrpc_skb_priv *sp)
  {
  	return sp->hdr.flags & RXRPC_CLIENT_INITIATED;
  }
  
  static inline bool rxrpc_to_client(const struct rxrpc_skb_priv *sp)
  {
  	return !rxrpc_to_server(sp);
  }
17926a793   David Howells   [AF_RXRPC]: Provi...
458
  /*
5b8848d14   David Howells   rxrpc: Convert ca...
459
460
461
462
   * Flags in call->flags.
   */
  enum rxrpc_call_flag {
  	RXRPC_CALL_RELEASED,		/* call has been released - no more message to userspace */
5b8848d14   David Howells   rxrpc: Convert ca...
463
  	RXRPC_CALL_HAS_USERID,		/* has a user ID attached */
dabe5a790   David Howells   rxrpc: Tidy up th...
464
  	RXRPC_CALL_IS_SERVICE,		/* Call is service call */
45025bcee   David Howells   rxrpc: Improve ma...
465
  	RXRPC_CALL_EXPOSED,		/* The call was exposed to the world */
248f219cb   David Howells   rxrpc: Rewrite th...
466
467
  	RXRPC_CALL_RX_LAST,		/* Received the last packet (at rxtx_top) */
  	RXRPC_CALL_TX_LAST,		/* Last packet in Tx buffer (at rxtx_top) */
a5af7e1fc   David Howells   rxrpc: Fix loss o...
468
  	RXRPC_CALL_SEND_PING,		/* A ping will need to be sent */
57494343c   David Howells   rxrpc: Implement ...
469
  	RXRPC_CALL_RETRANS_TIMEOUT,	/* Retransmission due to timeout occurred */
c54e43d75   David Howells   rxrpc: Fix missin...
470
  	RXRPC_CALL_BEGAN_RX_TIMER,	/* We began the expect_rx_by timer */
1a025028d   David Howells   rxrpc: Fix handli...
471
  	RXRPC_CALL_RX_HEARD,		/* The peer responded at least once to this call */
d0b35a420   David Howells   rxrpc: Transmit m...
472
  	RXRPC_CALL_RX_UNDERRUN,		/* Got data underrun */
5273a191d   David Howells   rxrpc: Fix NULL p...
473
  	RXRPC_CALL_DISCONNECTED,	/* The call has been disconnected */
b7a7d6740   David Howells   rxrpc: Impose a m...
474
  	RXRPC_CALL_KERNEL,		/* The call was made by the kernel */
245500d85   David Howells   rxrpc: Rewrite th...
475
  	RXRPC_CALL_UPGRADE,		/* Service upgrade was requested for the call */
5b8848d14   David Howells   rxrpc: Convert ca...
476
477
478
479
480
481
  };
  
  /*
   * Events that can be raised on a call.
   */
  enum rxrpc_call_event {
4c198ad17   David Howells   rxrpc: Rename cal...
482
  	RXRPC_CALL_EV_ACK,		/* need to generate ACK */
4c198ad17   David Howells   rxrpc: Rename cal...
483
  	RXRPC_CALL_EV_ABORT,		/* need to generate abort */
4c198ad17   David Howells   rxrpc: Rename cal...
484
  	RXRPC_CALL_EV_RESEND,		/* Tx resend required */
a5af7e1fc   David Howells   rxrpc: Fix loss o...
485
  	RXRPC_CALL_EV_PING,		/* Ping send required */
a158bdd32   David Howells   rxrpc: Fix call t...
486
  	RXRPC_CALL_EV_EXPIRED,		/* Expiry occurred */
bd1fdf8cf   David Howells   rxrpc: Add a time...
487
  	RXRPC_CALL_EV_ACK_LOST,		/* ACK may be lost, send ping */
5b8848d14   David Howells   rxrpc: Convert ca...
488
489
490
491
492
493
  };
  
  /*
   * The states that a call can be in.
   */
  enum rxrpc_call_state {
999b69f89   David Howells   rxrpc: Kill the c...
494
495
  	RXRPC_CALL_UNINITIALISED,
  	RXRPC_CALL_CLIENT_AWAIT_CONN,	/* - client waiting for connection to become available */
5b8848d14   David Howells   rxrpc: Convert ca...
496
497
498
  	RXRPC_CALL_CLIENT_SEND_REQUEST,	/* - client sending request phase */
  	RXRPC_CALL_CLIENT_AWAIT_REPLY,	/* - client awaiting reply */
  	RXRPC_CALL_CLIENT_RECV_REPLY,	/* - client receiving reply phase */
00e907127   David Howells   rxrpc: Preallocat...
499
  	RXRPC_CALL_SERVER_PREALLOC,	/* - service preallocation */
5b8848d14   David Howells   rxrpc: Convert ca...
500
  	RXRPC_CALL_SERVER_SECURING,	/* - server securing request connection */
5b8848d14   David Howells   rxrpc: Convert ca...
501
502
503
504
  	RXRPC_CALL_SERVER_RECV_REQUEST,	/* - server receiving request */
  	RXRPC_CALL_SERVER_ACK_REQUEST,	/* - server pending ACK of request */
  	RXRPC_CALL_SERVER_SEND_REPLY,	/* - server sending reply */
  	RXRPC_CALL_SERVER_AWAIT_ACK,	/* - server awaiting final ACK */
f5c17aaeb   David Howells   rxrpc: Calls shou...
505
  	RXRPC_CALL_COMPLETE,		/* - call complete */
f5c17aaeb   David Howells   rxrpc: Calls shou...
506
507
508
509
  	NR__RXRPC_CALL_STATES
  };
  
  /*
e122d845a   David Howells   Revert "rxrpc: Al...
510
511
512
513
514
515
516
517
518
519
520
521
   * Call completion condition (state == RXRPC_CALL_COMPLETE).
   */
  enum rxrpc_call_completion {
  	RXRPC_CALL_SUCCEEDED,		/* - Normal termination */
  	RXRPC_CALL_REMOTELY_ABORTED,	/* - call aborted by peer */
  	RXRPC_CALL_LOCALLY_ABORTED,	/* - call aborted locally on error or close */
  	RXRPC_CALL_LOCAL_ERROR,		/* - call failed due to local error */
  	RXRPC_CALL_NETWORK_ERROR,	/* - call terminated by network error */
  	NR__RXRPC_CALL_COMPLETIONS
  };
  
  /*
57494343c   David Howells   rxrpc: Implement ...
522
523
524
525
526
527
528
529
530
531
532
   * Call Tx congestion management modes.
   */
  enum rxrpc_congest_mode {
  	RXRPC_CALL_SLOW_START,
  	RXRPC_CALL_CONGEST_AVOIDANCE,
  	RXRPC_CALL_PACKET_LOSS,
  	RXRPC_CALL_FAST_RETRANSMIT,
  	NR__RXRPC_CONGEST_MODES
  };
  
  /*
17926a793   David Howells   [AF_RXRPC]: Provi...
533
534
535
536
   * RxRPC call definition
   * - matched by { connection, call_id }
   */
  struct rxrpc_call {
dee46364c   David Howells   rxrpc: Add RCU de...
537
  	struct rcu_head		rcu;
17926a793   David Howells   [AF_RXRPC]: Provi...
538
  	struct rxrpc_connection	*conn;		/* connection carrying call */
df5d8bf70   David Howells   rxrpc: Make /proc...
539
  	struct rxrpc_peer	*peer;		/* Peer record for remote address */
8d94aa381   David Howells   rxrpc: Calls shou...
540
  	struct rxrpc_sock __rcu	*socket;	/* socket responsible */
d3be4d244   David Howells   rxrpc: Fix potent...
541
  	struct rxrpc_net	*rxnet;		/* Network namespace to which call belongs */
91fcfbe88   David Howells   rxrpc: Fix call c...
542
  	const struct rxrpc_security *security;	/* applied security module */
540b1c48c   David Howells   rxrpc: Fix deadlo...
543
  	struct mutex		user_mutex;	/* User access mutex */
a158bdd32   David Howells   rxrpc: Fix call t...
544
  	unsigned long		ack_at;		/* When deferred ACK needs to happen */
bd1fdf8cf   David Howells   rxrpc: Add a time...
545
  	unsigned long		ack_lost_at;	/* When ACK is figured as lost */
a158bdd32   David Howells   rxrpc: Fix call t...
546
547
  	unsigned long		resend_at;	/* When next resend needs to happen */
  	unsigned long		ping_at;	/* When next to send a ping */
415f44e43   David Howells   rxrpc: Add keepal...
548
  	unsigned long		keepalive_at;	/* When next to send a keepalive ping */
a158bdd32   David Howells   rxrpc: Fix call t...
549
550
551
552
553
  	unsigned long		expect_rx_by;	/* When we expect to get a packet by */
  	unsigned long		expect_req_by;	/* When we expect to get a request DATA packet by */
  	unsigned long		expect_term_by;	/* When we expect call termination by */
  	u32			next_rx_timo;	/* Timeout for next Rx packet (jif) */
  	u32			next_req_timo;	/* Timeout for next Rx request packet (jif) */
1db88c534   David Howells   rxrpc: Fix -Wfram...
554
  	struct skcipher_request	*cipher_req;	/* Packet cipher request buffer */
248f219cb   David Howells   rxrpc: Rewrite th...
555
556
  	struct timer_list	timer;		/* Combined event timer */
  	struct work_struct	processor;	/* Event processor */
d001648ec   David Howells   rxrpc: Don't expo...
557
  	rxrpc_notify_rx_t	notify_rx;	/* kernel service Rx notification function */
17926a793   David Howells   [AF_RXRPC]: Provi...
558
  	struct list_head	link;		/* link in master call list */
245500d85   David Howells   rxrpc: Rewrite th...
559
  	struct list_head	chan_wait_link;	/* Link in conn->bundle->waiting_calls */
f66d74901   David Howells   rxrpc: Use the pe...
560
  	struct hlist_node	error_link;	/* link in error distribution list */
248f219cb   David Howells   rxrpc: Rewrite th...
561
562
563
564
  	struct list_head	accept_link;	/* Link in rx->acceptq */
  	struct list_head	recvmsg_link;	/* Link in rx->recvmsg_q */
  	struct list_head	sock_link;	/* Link in rx->sock_calls */
  	struct rb_node		sock_node;	/* Node in rx->calls */
17926a793   David Howells   [AF_RXRPC]: Provi...
565
  	struct sk_buff		*tx_pending;	/* Tx socket buffer being filled */
45025bcee   David Howells   rxrpc: Improve ma...
566
  	wait_queue_head_t	waitq;		/* Wait queue for channel or Tx */
e754eba68   David Howells   rxrpc: Provide a ...
567
  	s64			tx_total_len;	/* Total length left to be transmitted (or -1) */
a263629da   Herbert Xu   rxrpc: Avoid usin...
568
  	__be32			crypto_buf[2];	/* Temporary packet crypto buffer */
17926a793   David Howells   [AF_RXRPC]: Provi...
569
  	unsigned long		user_call_ID;	/* user-defined call ID */
17926a793   David Howells   [AF_RXRPC]: Provi...
570
  	unsigned long		flags;
17926a793   David Howells   [AF_RXRPC]: Provi...
571
  	unsigned long		events;
17926a793   David Howells   [AF_RXRPC]: Provi...
572
  	spinlock_t		lock;
20acbd9a7   David Howells   rxrpc: Lock aroun...
573
  	spinlock_t		notify_lock;	/* Kernel notification lock */
17926a793   David Howells   [AF_RXRPC]: Provi...
574
  	rwlock_t		state_lock;	/* lock for state transition */
f5c17aaeb   David Howells   rxrpc: Calls shou...
575
576
  	u32			abort_code;	/* Local/remote abort code */
  	int			error;		/* Local error incurred */
cf13258fd   David Howells   rxrpc: Fix ASSERT...
577
578
  	enum rxrpc_call_state	state;		/* current state of call */
  	enum rxrpc_call_completion completion;	/* Call completion condition */
17926a793   David Howells   [AF_RXRPC]: Provi...
579
  	atomic_t		usage;
dabe5a790   David Howells   rxrpc: Tidy up th...
580
  	u16			service_id;	/* service ID */
278ac0cdd   David Howells   rxrpc: Cache the ...
581
  	u8			security_ix;	/* Security type */
e138aa7d3   David Howells   rxrpc: Fix call i...
582
  	enum rxrpc_interruptibility interruptibility; /* At what point call may be interrupted */
dabe5a790   David Howells   rxrpc: Tidy up th...
583
584
585
  	u32			call_id;	/* call ID on connection  */
  	u32			cid;		/* connection ID plus channel index */
  	int			debug_id;	/* debug ID for printks */
8e83134db   David Howells   rxrpc: Send pings...
586
587
  	unsigned short		rx_pkt_offset;	/* Current recvmsg packet offset */
  	unsigned short		rx_pkt_len;	/* Current recvmsg packet len */
f9c32435a   David Howells   rxrpc: Fix handli...
588
  	bool			rx_pkt_last;	/* Current recvmsg packet is last */
17926a793   David Howells   [AF_RXRPC]: Provi...
589

248f219cb   David Howells   rxrpc: Rewrite th...
590
591
592
593
594
595
596
597
598
599
600
  	/* Rx/Tx circular buffer, depending on phase.
  	 *
  	 * In the Rx phase, packets are annotated with 0 or the number of the
  	 * segment of a jumbo packet each buffer refers to.  There can be up to
  	 * 47 segments in a maximum-size UDP packet.
  	 *
  	 * In the Tx phase, packets are annotated with which buffers have been
  	 * acked.
  	 */
  #define RXRPC_RXTX_BUFF_SIZE	64
  #define RXRPC_RXTX_BUFF_MASK	(RXRPC_RXTX_BUFF_SIZE - 1)
4075295ab   David Howells   rxrpc: Increase t...
601
  #define RXRPC_INIT_RX_WINDOW_SIZE 63
248f219cb   David Howells   rxrpc: Rewrite th...
602
603
604
605
606
607
  	struct sk_buff		**rxtx_buffer;
  	u8			*rxtx_annotations;
  #define RXRPC_TX_ANNO_ACK	0
  #define RXRPC_TX_ANNO_UNACK	1
  #define RXRPC_TX_ANNO_NAK	2
  #define RXRPC_TX_ANNO_RETRANS	3
f07373ead   David Howells   rxrpc: Add re-sen...
608
  #define RXRPC_TX_ANNO_MASK	0x03
70790dbe3   David Howells   rxrpc: Pass the l...
609
610
  #define RXRPC_TX_ANNO_LAST	0x04
  #define RXRPC_TX_ANNO_RESENT	0x08
e2de6c404   David Howells   rxrpc: Use info i...
611
  #define RXRPC_RX_ANNO_SUBPACKET	0x3f		/* Subpacket number in jumbogram */
248f219cb   David Howells   rxrpc: Rewrite th...
612
613
614
615
616
  #define RXRPC_RX_ANNO_VERIFIED	0x80		/* Set if verified and decrypted */
  	rxrpc_seq_t		tx_hard_ack;	/* Dead slot in buffer; the first transmitted but
  						 * not hard-ACK'd packet follows this.
  						 */
  	rxrpc_seq_t		tx_top;		/* Highest Tx slot allocated. */
c7e86acfc   David Howells   rxrpc: Fix lockup...
617
  	u16			tx_backoff;	/* Delay to insert due to Tx failure */
57494343c   David Howells   rxrpc: Implement ...
618
619
620
621
622
623
624
625
626
627
628
629
630
  
  	/* TCP-style slow-start congestion control [RFC5681].  Since the SMSS
  	 * is fixed, we keep these numbers in terms of segments (ie. DATA
  	 * packets) rather than bytes.
  	 */
  #define RXRPC_TX_SMSS		RXRPC_JUMBO_DATALEN
  	u8			cong_cwnd;	/* Congestion window size */
  	u8			cong_extra;	/* Extra to send for congestion management */
  	u8			cong_ssthresh;	/* Slow-start threshold */
  	enum rxrpc_congest_mode	cong_mode:8;	/* Congestion management mode */
  	u8			cong_dup_acks;	/* Count of ACKs showing missing packets */
  	u8			cong_cumul_acks; /* Cumulative ACK count */
  	ktime_t			cong_tstamp;	/* Last time cwnd was changed */
248f219cb   David Howells   rxrpc: Rewrite th...
631
632
  	rxrpc_seq_t		rx_hard_ack;	/* Dead slot in buffer; the first received but not
  						 * consumed packet follows this.
17926a793   David Howells   [AF_RXRPC]: Provi...
633
  						 */
248f219cb   David Howells   rxrpc: Rewrite th...
634
635
  	rxrpc_seq_t		rx_top;		/* Highest Rx slot allocated. */
  	rxrpc_seq_t		rx_expect_next;	/* Expected next packet sequence number */
1a025028d   David Howells   rxrpc: Fix handli...
636
  	rxrpc_serial_t		rx_serial;	/* Highest serial received for this call */
248f219cb   David Howells   rxrpc: Rewrite th...
637
638
  	u8			rx_winsize;	/* Size of Rx window */
  	u8			tx_winsize;	/* Maximum size of Tx window */
71f3ca408   David Howells   rxrpc: Improve sk...
639
  	bool			tx_phase;	/* T if transmission phase, F if receive phase */
75e421263   David Howells   rxrpc: Correctly ...
640
  	u8			nr_jumbo_bad;	/* Number of jumbo dups/exceeds-windows */
17926a793   David Howells   [AF_RXRPC]: Provi...
641

c1e15b494   David Howells   rxrpc: Fix the pa...
642
  	spinlock_t		input_lock;	/* Lock for packet input to this call */
17926a793   David Howells   [AF_RXRPC]: Provi...
643
  	/* receive-phase ACK management */
4e36a95e5   David Howells   RxRPC: Use uX/sX ...
644
  	u8			ackr_reason;	/* reason to ACK */
0d12f8a40   David Howells   rxrpc: Keep the s...
645
  	rxrpc_serial_t		ackr_serial;	/* serial of packet being ACK'd */
1a2391c30   Jeffrey Altman   rxrpc: Fix detect...
646
  	rxrpc_serial_t		ackr_first_seq;	/* first sequence number received */
248f219cb   David Howells   rxrpc: Rewrite th...
647
  	rxrpc_seq_t		ackr_prev_seq;	/* previous sequence number received */
805b21b92   David Howells   rxrpc: Send an AC...
648
649
  	rxrpc_seq_t		ackr_consumed;	/* Highest packet shown consumed */
  	rxrpc_seq_t		ackr_seen;	/* Highest packet shown seen */
a5af7e1fc   David Howells   rxrpc: Fix loss o...
650

4700c4d80   David Howells   rxrpc: Fix loss o...
651
652
653
654
655
656
657
  	/* RTT management */
  	rxrpc_serial_t		rtt_serial[4];	/* Serial number of DATA or PING sent */
  	ktime_t			rtt_sent_at[4];	/* Time packet sent */
  	unsigned long		rtt_avail;	/* Mask of available slots in bits 0-3,
  						 * Mask of pending samples in 8-11 */
  #define RXRPC_CALL_RTT_AVAIL_MASK	0xf
  #define RXRPC_CALL_RTT_PEND_SHIFT	8
17926a793   David Howells   [AF_RXRPC]: Provi...
658

248f219cb   David Howells   rxrpc: Rewrite th...
659
  	/* transmission-phase ACK management */
57494343c   David Howells   rxrpc: Implement ...
660
  	ktime_t			acks_latest_ts;	/* Timestamp of latest ACK received */
31a1b9895   David Howells   rxrpc: Generate a...
661
  	rxrpc_seq_t		acks_lowest_nak; /* Lowest NACK in the buffer (or ==tx_hard_ack) */
bd1fdf8cf   David Howells   rxrpc: Add a time...
662
663
  	rxrpc_seq_t		acks_lost_top;	/* tx_top at the time lost-ack ping sent */
  	rxrpc_serial_t		acks_lost_ping;	/* Serial number of probe ACK */
31a1b9895   David Howells   rxrpc: Generate a...
664
665
666
  };
  
  /*
57494343c   David Howells   rxrpc: Implement ...
667
   * Summary of a new ACK and the changes it made to the Tx buffer packet states.
31a1b9895   David Howells   rxrpc: Generate a...
668
669
670
671
672
673
674
675
676
   */
  struct rxrpc_ack_summary {
  	u8			ack_reason;
  	u8			nr_acks;		/* Number of ACKs in packet */
  	u8			nr_nacks;		/* Number of NACKs in packet */
  	u8			nr_new_acks;		/* Number of new ACKs in packet */
  	u8			nr_new_nacks;		/* Number of new NACKs in packet */
  	u8			nr_rot_new_acks;	/* Number of rotated new ACKs */
  	bool			new_low_nack;		/* T if new low NACK found */
57494343c   David Howells   rxrpc: Implement ...
677
678
679
680
681
682
683
684
  	bool			retrans_timeo;		/* T if reTx due to timeout happened */
  	u8			flight_size;		/* Number of unreceived transmissions */
  	/* Place to stash values for tracing */
  	enum rxrpc_congest_mode	mode:8;
  	u8			cwnd;
  	u8			ssthresh;
  	u8			dup_acks;
  	u8			cumulative_acks;
17926a793   David Howells   [AF_RXRPC]: Provi...
685
  };
481241789   David Howells   rxrpc: Split the ...
686
687
688
689
690
691
  /*
   * sendmsg() cmsg-specified parameters.
   */
  enum rxrpc_command {
  	RXRPC_CMD_SEND_DATA,		/* send data message */
  	RXRPC_CMD_SEND_ABORT,		/* request abort generation */
481241789   David Howells   rxrpc: Split the ...
692
  	RXRPC_CMD_REJECT_BUSY,		/* [server] reject a call as busy */
2d914c1bf   David Howells   rxrpc: Fix accept...
693
  	RXRPC_CMD_CHARGE_ACCEPT,	/* [server] charge accept preallocation */
481241789   David Howells   rxrpc: Split the ...
694
695
696
697
698
699
700
701
702
703
704
  };
  
  struct rxrpc_call_params {
  	s64			tx_total_len;	/* Total Tx data length (if send data) */
  	unsigned long		user_call_ID;	/* User's call ID */
  	struct {
  		u32		hard;		/* Maximum lifetime (sec) */
  		u32		idle;		/* Max time since last data packet (msec) */
  		u32		normal;		/* Max time since last call packet (msec) */
  	} timeouts;
  	u8			nr_timeouts;	/* Number of timeouts specified */
b7a7d6740   David Howells   rxrpc: Impose a m...
705
  	bool			kernel;		/* T if kernel is making the call */
e138aa7d3   David Howells   rxrpc: Fix call i...
706
  	enum rxrpc_interruptibility interruptibility; /* How is interruptible is the call? */
481241789   David Howells   rxrpc: Split the ...
707
708
709
710
711
712
713
714
715
  };
  
  struct rxrpc_send_params {
  	struct rxrpc_call_params call;
  	u32			abort_code;	/* Abort code to Tx (if abort) */
  	enum rxrpc_command	command : 8;	/* The command to implement */
  	bool			exclusive;	/* Shared or exclusive call */
  	bool			upgrade;	/* If the connection is upgradeable */
  };
df844fd46   David Howells   rxrpc: Use a trac...
716
  #include <trace/events/rxrpc.h>
17926a793   David Howells   [AF_RXRPC]: Provi...
717
  /*
651350d10   David Howells   [AF_RXRPC]: Add a...
718
   * af_rxrpc.c
17926a793   David Howells   [AF_RXRPC]: Provi...
719
   */
71f3ca408   David Howells   rxrpc: Improve sk...
720
  extern atomic_t rxrpc_n_tx_skbs, rxrpc_n_rx_skbs;
651350d10   David Howells   [AF_RXRPC]: Add a...
721
  extern struct workqueue_struct *rxrpc_workqueue;
17926a793   David Howells   [AF_RXRPC]: Provi...
722
723
  
  /*
0d81a51ab   David Howells   rxrpc: Update the...
724
   * call_accept.c
17926a793   David Howells   [AF_RXRPC]: Provi...
725
   */
00e907127   David Howells   rxrpc: Preallocat...
726
727
  int rxrpc_service_prealloc(struct rxrpc_sock *, gfp_t);
  void rxrpc_discard_prealloc(struct rxrpc_sock *);
248f219cb   David Howells   rxrpc: Rewrite th...
728
  struct rxrpc_call *rxrpc_new_incoming_call(struct rxrpc_local *,
0099dc589   David Howells   rxrpc: Make servi...
729
  					   struct rxrpc_sock *,
248f219cb   David Howells   rxrpc: Rewrite th...
730
  					   struct sk_buff *);
4f95dd78a   David Howells   rxrpc: Rework loc...
731
  void rxrpc_accept_incoming_calls(struct rxrpc_local *);
2d914c1bf   David Howells   rxrpc: Fix accept...
732
  int rxrpc_user_charge_accept(struct rxrpc_sock *, unsigned long);
17926a793   David Howells   [AF_RXRPC]: Provi...
733
734
  
  /*
0d81a51ab   David Howells   rxrpc: Update the...
735
   * call_event.c
17926a793   David Howells   [AF_RXRPC]: Provi...
736
   */
e8c3af6bb   David Howells   rxrpc: Don't both...
737
  void rxrpc_propose_ACK(struct rxrpc_call *, u8, u32, bool, bool,
9c7ad4344   David Howells   rxrpc: Add tracep...
738
  		       enum rxrpc_propose_ack_trace);
c1b1203d6   Joe Perches   net: misc: Remove...
739
  void rxrpc_process_call(struct work_struct *);
17926a793   David Howells   [AF_RXRPC]: Provi...
740

a158bdd32   David Howells   rxrpc: Fix call t...
741
742
743
744
745
746
747
748
  static inline void rxrpc_reduce_call_timer(struct rxrpc_call *call,
  					   unsigned long expire_at,
  					   unsigned long now,
  					   enum rxrpc_timer_trace why)
  {
  	trace_rxrpc_timer(call, why, now);
  	timer_reduce(&call->timer, expire_at);
  }
17926a793   David Howells   [AF_RXRPC]: Provi...
749
  /*
0d81a51ab   David Howells   rxrpc: Update the...
750
   * call_object.c
17926a793   David Howells   [AF_RXRPC]: Provi...
751
   */
f5c17aaeb   David Howells   rxrpc: Calls shou...
752
753
  extern const char *const rxrpc_call_states[];
  extern const char *const rxrpc_call_completions[];
dad8aff75   David Howells   rxrpc: Replace al...
754
  extern unsigned int rxrpc_max_call_lifetime;
17926a793   David Howells   [AF_RXRPC]: Provi...
755
  extern struct kmem_cache *rxrpc_call_jar;
17926a793   David Howells   [AF_RXRPC]: Provi...
756

2341e0775   David Howells   rxrpc: Simplify c...
757
  struct rxrpc_call *rxrpc_find_call_by_user_ID(struct rxrpc_sock *, unsigned long);
a25e21f0b   David Howells   rxrpc, afs: Use d...
758
  struct rxrpc_call *rxrpc_alloc_call(struct rxrpc_sock *, gfp_t, unsigned int);
2341e0775   David Howells   rxrpc: Simplify c...
759
  struct rxrpc_call *rxrpc_new_client_call(struct rxrpc_sock *,
19ffa01c9   David Howells   rxrpc: Use struct...
760
  					 struct rxrpc_conn_parameters *,
999b69f89   David Howells   rxrpc: Kill the c...
761
  					 struct sockaddr_rxrpc *,
a25e21f0b   David Howells   rxrpc, afs: Use d...
762
763
  					 struct rxrpc_call_params *, gfp_t,
  					 unsigned int);
248f219cb   David Howells   rxrpc: Rewrite th...
764
765
  void rxrpc_incoming_call(struct rxrpc_sock *, struct rxrpc_call *,
  			 struct sk_buff *);
8d94aa381   David Howells   rxrpc: Calls shou...
766
  void rxrpc_release_call(struct rxrpc_sock *, struct rxrpc_call *);
c1b1203d6   Joe Perches   net: misc: Remove...
767
  void rxrpc_release_calls_on_socket(struct rxrpc_sock *);
8d94aa381   David Howells   rxrpc: Calls shou...
768
769
  bool __rxrpc_queue_call(struct rxrpc_call *);
  bool rxrpc_queue_call(struct rxrpc_call *);
e34d4234b   David Howells   rxrpc: Trace rxrp...
770
  void rxrpc_see_call(struct rxrpc_call *);
fff72429c   David Howells   rxrpc: Improve th...
771
772
  void rxrpc_get_call(struct rxrpc_call *, enum rxrpc_call_trace);
  void rxrpc_put_call(struct rxrpc_call *, enum rxrpc_call_trace);
00e907127   David Howells   rxrpc: Preallocat...
773
  void rxrpc_cleanup_call(struct rxrpc_call *);
2baec2c3f   David Howells   rxrpc: Support ne...
774
  void rxrpc_destroy_all_calls(struct rxrpc_net *);
17926a793   David Howells   [AF_RXRPC]: Provi...
775

dabe5a790   David Howells   rxrpc: Tidy up th...
776
777
778
779
780
781
782
783
784
  static inline bool rxrpc_is_service_call(const struct rxrpc_call *call)
  {
  	return test_bit(RXRPC_CALL_IS_SERVICE, &call->flags);
  }
  
  static inline bool rxrpc_is_client_call(const struct rxrpc_call *call)
  {
  	return !rxrpc_is_service_call(call);
  }
17926a793   David Howells   [AF_RXRPC]: Provi...
785
  /*
4a3388c80   David Howells   rxrpc: Use IDR to...
786
787
   * conn_client.c
   */
45025bcee   David Howells   rxrpc: Improve ma...
788
  extern unsigned int rxrpc_reap_client_connections;
a158bdd32   David Howells   rxrpc: Fix call t...
789
790
  extern unsigned long rxrpc_conn_idle_client_expiry;
  extern unsigned long rxrpc_conn_idle_client_fast_expiry;
4a3388c80   David Howells   rxrpc: Use IDR to...
791
  extern struct idr rxrpc_client_conn_ids;
eb9b9d227   David Howells   rxrpc: Check that...
792
  void rxrpc_destroy_client_conn_ids(void);
245500d85   David Howells   rxrpc: Rewrite th...
793
794
  struct rxrpc_bundle *rxrpc_get_bundle(struct rxrpc_bundle *);
  void rxrpc_put_bundle(struct rxrpc_bundle *);
5e33a23ba   David Howells   rxrpc: Fix some m...
795
796
797
  int rxrpc_connect_call(struct rxrpc_sock *, struct rxrpc_call *,
  		       struct rxrpc_conn_parameters *, struct sockaddr_rxrpc *,
  		       gfp_t);
45025bcee   David Howells   rxrpc: Improve ma...
798
  void rxrpc_expose_client_call(struct rxrpc_call *);
245500d85   David Howells   rxrpc: Rewrite th...
799
  void rxrpc_disconnect_client_call(struct rxrpc_bundle *, struct rxrpc_call *);
45025bcee   David Howells   rxrpc: Improve ma...
800
  void rxrpc_put_client_conn(struct rxrpc_connection *);
2baec2c3f   David Howells   rxrpc: Support ne...
801
802
  void rxrpc_discard_expired_client_conns(struct work_struct *);
  void rxrpc_destroy_all_client_connections(struct rxrpc_net *);
d12040b69   David Howells   rxrpc: Fix lack o...
803
  void rxrpc_clean_up_local_conns(struct rxrpc_local *);
4a3388c80   David Howells   rxrpc: Use IDR to...
804
805
  
  /*
0d81a51ab   David Howells   rxrpc: Update the...
806
807
808
   * conn_event.c
   */
  void rxrpc_process_connection(struct work_struct *);
ddc7834af   David Howells   rxrpc: Fix loss o...
809
  void rxrpc_process_delayed_final_acks(struct rxrpc_connection *, bool);
0d81a51ab   David Howells   rxrpc: Update the...
810
811
812
  
  /*
   * conn_object.c
17926a793   David Howells   [AF_RXRPC]: Provi...
813
   */
dad8aff75   David Howells   rxrpc: Replace al...
814
  extern unsigned int rxrpc_connection_expiry;
f859ab618   David Howells   rxrpc: Fix servic...
815
  extern unsigned int rxrpc_closed_conn_expiry;
17926a793   David Howells   [AF_RXRPC]: Provi...
816

c6d2b8d76   David Howells   rxrpc: Split clie...
817
  struct rxrpc_connection *rxrpc_alloc_connection(gfp_t);
8496af50e   David Howells   rxrpc: Use RCU to...
818
  struct rxrpc_connection *rxrpc_find_connection_rcu(struct rxrpc_local *,
0099dc589   David Howells   rxrpc: Make servi...
819
820
  						   struct sk_buff *,
  						   struct rxrpc_peer **);
45025bcee   David Howells   rxrpc: Improve ma...
821
  void __rxrpc_disconnect_call(struct rxrpc_connection *, struct rxrpc_call *);
999b69f89   David Howells   rxrpc: Kill the c...
822
  void rxrpc_disconnect_call(struct rxrpc_call *);
45025bcee   David Howells   rxrpc: Improve ma...
823
  void rxrpc_kill_connection(struct rxrpc_connection *);
363deeab6   David Howells   rxrpc: Add connec...
824
825
  bool rxrpc_queue_conn(struct rxrpc_connection *);
  void rxrpc_see_connection(struct rxrpc_connection *);
245500d85   David Howells   rxrpc: Rewrite th...
826
  struct rxrpc_connection *rxrpc_get_connection(struct rxrpc_connection *);
363deeab6   David Howells   rxrpc: Add connec...
827
828
  struct rxrpc_connection *rxrpc_get_connection_maybe(struct rxrpc_connection *);
  void rxrpc_put_service_conn(struct rxrpc_connection *);
2baec2c3f   David Howells   rxrpc: Support ne...
829
830
  void rxrpc_service_connection_reaper(struct work_struct *);
  void rxrpc_destroy_all_connections(struct rxrpc_net *);
17926a793   David Howells   [AF_RXRPC]: Provi...
831

19ffa01c9   David Howells   rxrpc: Use struct...
832
833
834
835
836
837
838
  static inline bool rxrpc_conn_is_client(const struct rxrpc_connection *conn)
  {
  	return conn->out_clientflag;
  }
  
  static inline bool rxrpc_conn_is_service(const struct rxrpc_connection *conn)
  {
e8d70ce17   David Howells   rxrpc: Prune the ...
839
  	return !rxrpc_conn_is_client(conn);
19ffa01c9   David Howells   rxrpc: Use struct...
840
  }
f51b44800   David Howells   rxrpc: Set connec...
841
842
  static inline void rxrpc_put_connection(struct rxrpc_connection *conn)
  {
45025bcee   David Howells   rxrpc: Improve ma...
843
844
  	if (!conn)
  		return;
363deeab6   David Howells   rxrpc: Add connec...
845
846
847
848
  	if (rxrpc_conn_is_client(conn))
  		rxrpc_put_client_conn(conn);
  	else
  		rxrpc_put_service_conn(conn);
5acbee464   David Howells   rxrpc: Provide qu...
849
  }
3136ef49a   David Howells   rxrpc: Delay term...
850
851
852
853
854
  static inline void rxrpc_reduce_conn_timer(struct rxrpc_connection *conn,
  					   unsigned long expire_at)
  {
  	timer_reduce(&conn->timer, expire_at);
  }
17926a793   David Howells   [AF_RXRPC]: Provi...
855
  /*
7877a4a4b   David Howells   rxrpc: Split serv...
856
857
   * conn_service.c
   */
8496af50e   David Howells   rxrpc: Use RCU to...
858
859
  struct rxrpc_connection *rxrpc_find_service_conn_rcu(struct rxrpc_peer *,
  						     struct sk_buff *);
2baec2c3f   David Howells   rxrpc: Support ne...
860
  struct rxrpc_connection *rxrpc_prealloc_service_connection(struct rxrpc_net *, gfp_t);
063c60d39   David Howells   rxrpc: Fix missin...
861
862
863
  void rxrpc_new_incoming_connection(struct rxrpc_sock *, struct rxrpc_connection *,
  				   const struct rxrpc_security *, struct key *,
  				   struct sk_buff *);
001c11224   David Howells   rxrpc: Maintain a...
864
  void rxrpc_unpublish_service_conn(struct rxrpc_connection *);
7877a4a4b   David Howells   rxrpc: Split serv...
865
866
  
  /*
0d81a51ab   David Howells   rxrpc: Update the...
867
   * input.c
17926a793   David Howells   [AF_RXRPC]: Provi...
868
   */
5271953ca   David Howells   rxrpc: Use the UD...
869
  int rxrpc_input_packet(struct sock *, struct sk_buff *);
17926a793   David Howells   [AF_RXRPC]: Provi...
870
871
  
  /*
0d81a51ab   David Howells   rxrpc: Update the...
872
   * insecure.c
17926a793   David Howells   [AF_RXRPC]: Provi...
873
   */
0d81a51ab   David Howells   rxrpc: Update the...
874
  extern const struct rxrpc_security rxrpc_no_security;
17926a793   David Howells   [AF_RXRPC]: Provi...
875
876
  
  /*
0d81a51ab   David Howells   rxrpc: Update the...
877
   * key.c
17926a793   David Howells   [AF_RXRPC]: Provi...
878
   */
0d81a51ab   David Howells   rxrpc: Update the...
879
880
  extern struct key_type key_type_rxrpc;
  extern struct key_type key_type_rxrpc_s;
a7b75c5a8   Christoph Hellwig   net: pass a sockp...
881
882
  int rxrpc_request_key(struct rxrpc_sock *, sockptr_t , int);
  int rxrpc_server_keyring(struct rxrpc_sock *, sockptr_t, int);
10674a03c   Baolin Wang   net: rxrpc: Repla...
883
  int rxrpc_get_server_data_key(struct rxrpc_connection *, const void *, time64_t,
0d81a51ab   David Howells   rxrpc: Update the...
884
  			      u32);
17926a793   David Howells   [AF_RXRPC]: Provi...
885
886
  
  /*
875636163   David Howells   rxrpc: Separate l...
887
888
   * local_event.c
   */
4f95dd78a   David Howells   rxrpc: Rework loc...
889
  extern void rxrpc_process_local_events(struct rxrpc_local *);
875636163   David Howells   rxrpc: Separate l...
890
891
  
  /*
0d81a51ab   David Howells   rxrpc: Update the...
892
   * local_object.c
17926a793   David Howells   [AF_RXRPC]: Provi...
893
   */
2baec2c3f   David Howells   rxrpc: Support ne...
894
  struct rxrpc_local *rxrpc_lookup_local(struct net *, const struct sockaddr_rxrpc *);
09d2bf595   David Howells   rxrpc: Add a trac...
895
896
897
  struct rxrpc_local *rxrpc_get_local(struct rxrpc_local *);
  struct rxrpc_local *rxrpc_get_local_maybe(struct rxrpc_local *);
  void rxrpc_put_local(struct rxrpc_local *);
730c5fd42   David Howells   rxrpc: Fix local ...
898
899
  struct rxrpc_local *rxrpc_use_local(struct rxrpc_local *);
  void rxrpc_unuse_local(struct rxrpc_local *);
09d2bf595   David Howells   rxrpc: Add a trac...
900
  void rxrpc_queue_local(struct rxrpc_local *);
2baec2c3f   David Howells   rxrpc: Support ne...
901
  void rxrpc_destroy_all_locals(struct rxrpc_net *);
17926a793   David Howells   [AF_RXRPC]: Provi...
902

04d36d748   David Howells   rxrpc: Fix missin...
903
904
905
906
907
908
909
910
911
  static inline bool __rxrpc_unuse_local(struct rxrpc_local *local)
  {
  	return atomic_dec_return(&local->active_users) == 0;
  }
  
  static inline bool __rxrpc_use_local(struct rxrpc_local *local)
  {
  	return atomic_fetch_add_unless(&local->active_users, 1, 0) != 0;
  }
17926a793   David Howells   [AF_RXRPC]: Provi...
912
  /*
0d81a51ab   David Howells   rxrpc: Update the...
913
   * misc.c
17926a793   David Howells   [AF_RXRPC]: Provi...
914
   */
0d81a51ab   David Howells   rxrpc: Update the...
915
  extern unsigned int rxrpc_max_backlog __read_mostly;
a158bdd32   David Howells   rxrpc: Fix call t...
916
917
918
  extern unsigned long rxrpc_requested_ack_delay;
  extern unsigned long rxrpc_soft_ack_delay;
  extern unsigned long rxrpc_idle_ack_delay;
0d81a51ab   David Howells   rxrpc: Update the...
919
920
921
  extern unsigned int rxrpc_rx_window_size;
  extern unsigned int rxrpc_rx_mtu;
  extern unsigned int rxrpc_rx_jumbo_max;
17926a793   David Howells   [AF_RXRPC]: Provi...
922

0d81a51ab   David Howells   rxrpc: Update the...
923
  extern const s8 rxrpc_ack_priority[];
17926a793   David Howells   [AF_RXRPC]: Provi...
924
  /*
2baec2c3f   David Howells   rxrpc: Support ne...
925
926
927
928
929
930
931
932
933
934
935
   * net_ns.c
   */
  extern unsigned int rxrpc_net_id;
  extern struct pernet_operations rxrpc_net_ops;
  
  static inline struct rxrpc_net *rxrpc_net(struct net *net)
  {
  	return net_generic(net, rxrpc_net_id);
  }
  
  /*
0d81a51ab   David Howells   rxrpc: Update the...
936
   * output.c
17926a793   David Howells   [AF_RXRPC]: Provi...
937
   */
bd1fdf8cf   David Howells   rxrpc: Add a time...
938
  int rxrpc_send_ack_packet(struct rxrpc_call *, bool, rxrpc_serial_t *);
26cb02aa6   David Howells   rxrpc: Fix warnin...
939
  int rxrpc_send_abort_packet(struct rxrpc_call *);
a1767077b   David Howells   rxrpc: Make Tx lo...
940
  int rxrpc_send_data_packet(struct rxrpc_call *, struct sk_buff *, bool);
248f219cb   David Howells   rxrpc: Rewrite th...
941
  void rxrpc_reject_packets(struct rxrpc_local *);
ace45bec6   David Howells   rxrpc: Fix firewa...
942
  void rxrpc_send_keepalive(struct rxrpc_peer *);
17926a793   David Howells   [AF_RXRPC]: Provi...
943
944
  
  /*
abe89ef0e   David Howells   rxrpc: Rename rxr...
945
   * peer_event.c
0d81a51ab   David Howells   rxrpc: Update the...
946
   */
abe89ef0e   David Howells   rxrpc: Rename rxr...
947
  void rxrpc_error_report(struct sock *);
ace45bec6   David Howells   rxrpc: Fix firewa...
948
  void rxrpc_peer_keepalive_worker(struct work_struct *);
0d81a51ab   David Howells   rxrpc: Update the...
949
950
951
  
  /*
   * peer_object.c
17926a793   David Howells   [AF_RXRPC]: Provi...
952
   */
be6e6707f   David Howells   rxrpc: Rework pee...
953
954
  struct rxrpc_peer *rxrpc_lookup_peer_rcu(struct rxrpc_local *,
  					 const struct sockaddr_rxrpc *);
5e33a23ba   David Howells   rxrpc: Fix some m...
955
  struct rxrpc_peer *rxrpc_lookup_peer(struct rxrpc_sock *, struct rxrpc_local *,
be6e6707f   David Howells   rxrpc: Rework pee...
956
957
  				     struct sockaddr_rxrpc *, gfp_t);
  struct rxrpc_peer *rxrpc_alloc_peer(struct rxrpc_local *, gfp_t);
5e33a23ba   David Howells   rxrpc: Fix some m...
958
959
  void rxrpc_new_incoming_peer(struct rxrpc_sock *, struct rxrpc_local *,
  			     struct rxrpc_peer *);
17226f124   David Howells   rxrpc: Fix leak o...
960
  void rxrpc_destroy_all_peers(struct rxrpc_net *);
1159d4b49   David Howells   rxrpc: Add a trac...
961
962
963
  struct rxrpc_peer *rxrpc_get_peer(struct rxrpc_peer *);
  struct rxrpc_peer *rxrpc_get_peer_maybe(struct rxrpc_peer *);
  void rxrpc_put_peer(struct rxrpc_peer *);
60034d3d1   David Howells   rxrpc: Fix potent...
964
  void rxrpc_put_peer_locked(struct rxrpc_peer *);
17926a793   David Howells   [AF_RXRPC]: Provi...
965
966
  
  /*
0d81a51ab   David Howells   rxrpc: Update the...
967
   * proc.c
17926a793   David Howells   [AF_RXRPC]: Provi...
968
   */
c35063722   Christoph Hellwig   proc: introduce p...
969
970
  extern const struct seq_operations rxrpc_call_seq_ops;
  extern const struct seq_operations rxrpc_connection_seq_ops;
bc0e7cf43   David Howells   rxrpc: Add /proc/...
971
  extern const struct seq_operations rxrpc_peer_seq_ops;
17926a793   David Howells   [AF_RXRPC]: Provi...
972
973
  
  /*
0d81a51ab   David Howells   rxrpc: Update the...
974
   * recvmsg.c
17926a793   David Howells   [AF_RXRPC]: Provi...
975
   */
248f219cb   David Howells   rxrpc: Rewrite th...
976
  void rxrpc_notify_socket(struct rxrpc_call *);
3067bf8c5   David Howells   rxrpc: Move the c...
977
978
979
980
981
982
  bool __rxrpc_set_call_completion(struct rxrpc_call *, enum rxrpc_call_completion, u32, int);
  bool rxrpc_set_call_completion(struct rxrpc_call *, enum rxrpc_call_completion, u32, int);
  bool __rxrpc_call_completed(struct rxrpc_call *);
  bool rxrpc_call_completed(struct rxrpc_call *);
  bool __rxrpc_abort_call(const char *, struct rxrpc_call *, rxrpc_seq_t, u32, int);
  bool rxrpc_abort_call(const char *, struct rxrpc_call *, rxrpc_seq_t, u32, int);
1b7841404   Ying Xue   net: Remove iocb ...
983
  int rxrpc_recvmsg(struct socket *, struct msghdr *, size_t, int);
17926a793   David Howells   [AF_RXRPC]: Provi...
984
985
  
  /*
3067bf8c5   David Howells   rxrpc: Move the c...
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
   * Abort a call due to a protocol error.
   */
  static inline bool __rxrpc_abort_eproto(struct rxrpc_call *call,
  					struct sk_buff *skb,
  					const char *eproto_why,
  					const char *why,
  					u32 abort_code)
  {
  	struct rxrpc_skb_priv *sp = rxrpc_skb(skb);
  
  	trace_rxrpc_rx_eproto(call, sp->hdr.serial, eproto_why);
  	return rxrpc_abort_call(why, call, sp->hdr.seq, abort_code, -EPROTO);
  }
  
  #define rxrpc_abort_eproto(call, skb, eproto_why, abort_why, abort_code) \
  	__rxrpc_abort_eproto((call), (skb), tracepoint_string(eproto_why), \
  			     (abort_why), (abort_code))
  
  /*
c410bf019   David Howells   rxrpc: Fix the ex...
1005
1006
   * rtt.c
   */
4700c4d80   David Howells   rxrpc: Fix loss o...
1007
  void rxrpc_peer_add_rtt(struct rxrpc_call *, enum rxrpc_rtt_rx_trace, int,
c410bf019   David Howells   rxrpc: Fix the ex...
1008
1009
1010
1011
1012
  			rxrpc_serial_t, rxrpc_serial_t, ktime_t, ktime_t);
  unsigned long rxrpc_get_rto_backoff(struct rxrpc_peer *, bool);
  void rxrpc_peer_init_rtt(struct rxrpc_peer *);
  
  /*
0d81a51ab   David Howells   rxrpc: Update the...
1013
1014
1015
1016
1017
1018
1019
1020
   * rxkad.c
   */
  #ifdef CONFIG_RXKAD
  extern const struct rxrpc_security rxkad;
  #endif
  
  /*
   * security.c
17926a793   David Howells   [AF_RXRPC]: Provi...
1021
   */
648af7fca   David Howells   rxrpc: Absorb the...
1022
1023
  int __init rxrpc_init_security(void);
  void rxrpc_exit_security(void);
c1b1203d6   Joe Perches   net: misc: Remove...
1024
  int rxrpc_init_client_conn_security(struct rxrpc_connection *);
063c60d39   David Howells   rxrpc: Fix missin...
1025
1026
1027
  bool rxrpc_look_up_server_security(struct rxrpc_local *, struct rxrpc_sock *,
  				   const struct rxrpc_security **, struct key **,
  				   struct sk_buff *);
71a17de30   David Howells   rxrpc: Whitespace...
1028

0b58b8a18   David Howells   rxrpc: Split send...
1029
1030
1031
1032
  /*
   * sendmsg.c
   */
  int rxrpc_do_sendmsg(struct rxrpc_sock *, struct msghdr *, size_t);
17926a793   David Howells   [AF_RXRPC]: Provi...
1033
1034
  
  /*
0d81a51ab   David Howells   rxrpc: Update the...
1035
   * skbuff.c
17926a793   David Howells   [AF_RXRPC]: Provi...
1036
   */
d001648ec   David Howells   rxrpc: Don't expo...
1037
  void rxrpc_kernel_data_consumed(struct rxrpc_call *, struct sk_buff *);
c1b1203d6   Joe Perches   net: misc: Remove...
1038
  void rxrpc_packet_destructor(struct sk_buff *);
71f3ca408   David Howells   rxrpc: Improve sk...
1039
1040
  void rxrpc_new_skb(struct sk_buff *, enum rxrpc_skb_trace);
  void rxrpc_see_skb(struct sk_buff *, enum rxrpc_skb_trace);
d0d5c0cd1   David Howells   rxrpc: Use skb_un...
1041
  void rxrpc_eaten_skb(struct sk_buff *, enum rxrpc_skb_trace);
71f3ca408   David Howells   rxrpc: Improve sk...
1042
1043
  void rxrpc_get_skb(struct sk_buff *, enum rxrpc_skb_trace);
  void rxrpc_free_skb(struct sk_buff *, enum rxrpc_skb_trace);
df844fd46   David Howells   rxrpc: Use a trac...
1044
  void rxrpc_purge_queue(struct sk_buff_head *);
17926a793   David Howells   [AF_RXRPC]: Provi...
1045
1046
  
  /*
5873c0834   David Howells   af_rxrpc: Add sys...
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
   * sysctl.c
   */
  #ifdef CONFIG_SYSCTL
  extern int __init rxrpc_sysctl_init(void);
  extern void rxrpc_sysctl_exit(void);
  #else
  static inline int __init rxrpc_sysctl_init(void) { return 0; }
  static inline void rxrpc_sysctl_exit(void) {}
  #endif
  
  /*
be6e6707f   David Howells   rxrpc: Rework pee...
1058
1059
   * utils.c
   */
5a790b737   David Howells   rxrpc: Drop the l...
1060
  int rxrpc_extract_addr_from_skb(struct sockaddr_rxrpc *, struct sk_buff *);
be6e6707f   David Howells   rxrpc: Rework pee...
1061

248f219cb   David Howells   rxrpc: Rewrite th...
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
  static inline bool before(u32 seq1, u32 seq2)
  {
          return (s32)(seq1 - seq2) < 0;
  }
  static inline bool before_eq(u32 seq1, u32 seq2)
  {
          return (s32)(seq1 - seq2) <= 0;
  }
  static inline bool after(u32 seq1, u32 seq2)
  {
          return (s32)(seq1 - seq2) > 0;
  }
  static inline bool after_eq(u32 seq1, u32 seq2)
  {
          return (s32)(seq1 - seq2) >= 0;
  }
be6e6707f   David Howells   rxrpc: Rework pee...
1078
  /*
17926a793   David Howells   [AF_RXRPC]: Provi...
1079
1080
   * debug tracing
   */
95c961747   Eric Dumazet   net: cleanup unsi...
1081
  extern unsigned int rxrpc_debug;
17926a793   David Howells   [AF_RXRPC]: Provi...
1082
1083
  
  #define dbgprintk(FMT,...) \
9f389f4b2   Sven Schnelle   rxrpc: remove smp...
1084
1085
  	printk("[%-6.6s] "FMT"
  ", current->comm ,##__VA_ARGS__)
17926a793   David Howells   [AF_RXRPC]: Provi...
1086

0dc47877a   Harvey Harrison   net: replace rema...
1087
1088
  #define kenter(FMT,...)	dbgprintk("==> %s("FMT")",__func__ ,##__VA_ARGS__)
  #define kleave(FMT,...)	dbgprintk("<== %s()"FMT"",__func__ ,##__VA_ARGS__)
17926a793   David Howells   [AF_RXRPC]: Provi...
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
  #define kdebug(FMT,...)	dbgprintk("    "FMT ,##__VA_ARGS__)
  #define kproto(FMT,...)	dbgprintk("### "FMT ,##__VA_ARGS__)
  #define knet(FMT,...)	dbgprintk("@@@ "FMT ,##__VA_ARGS__)
  
  
  #if defined(__KDEBUG)
  #define _enter(FMT,...)	kenter(FMT,##__VA_ARGS__)
  #define _leave(FMT,...)	kleave(FMT,##__VA_ARGS__)
  #define _debug(FMT,...)	kdebug(FMT,##__VA_ARGS__)
  #define _proto(FMT,...)	kproto(FMT,##__VA_ARGS__)
  #define _net(FMT,...)	knet(FMT,##__VA_ARGS__)
  
  #elif defined(CONFIG_AF_RXRPC_DEBUG)
  #define RXRPC_DEBUG_KENTER	0x01
  #define RXRPC_DEBUG_KLEAVE	0x02
  #define RXRPC_DEBUG_KDEBUG	0x04
  #define RXRPC_DEBUG_KPROTO	0x08
  #define RXRPC_DEBUG_KNET	0x10
  
  #define _enter(FMT,...)					\
  do {							\
  	if (unlikely(rxrpc_debug & RXRPC_DEBUG_KENTER))	\
  		kenter(FMT,##__VA_ARGS__);		\
  } while (0)
  
  #define _leave(FMT,...)					\
  do {							\
  	if (unlikely(rxrpc_debug & RXRPC_DEBUG_KLEAVE))	\
  		kleave(FMT,##__VA_ARGS__);		\
  } while (0)
  
  #define _debug(FMT,...)					\
  do {							\
  	if (unlikely(rxrpc_debug & RXRPC_DEBUG_KDEBUG))	\
  		kdebug(FMT,##__VA_ARGS__);		\
  } while (0)
  
  #define _proto(FMT,...)					\
  do {							\
  	if (unlikely(rxrpc_debug & RXRPC_DEBUG_KPROTO))	\
  		kproto(FMT,##__VA_ARGS__);		\
  } while (0)
  
  #define _net(FMT,...)					\
  do {							\
  	if (unlikely(rxrpc_debug & RXRPC_DEBUG_KNET))	\
  		knet(FMT,##__VA_ARGS__);		\
  } while (0)
  
  #else
12fdff3fc   David Howells   Add a dummy print...
1139
1140
1141
1142
1143
  #define _enter(FMT,...)	no_printk("==> %s("FMT")",__func__ ,##__VA_ARGS__)
  #define _leave(FMT,...)	no_printk("<== %s()"FMT"",__func__ ,##__VA_ARGS__)
  #define _debug(FMT,...)	no_printk("    "FMT ,##__VA_ARGS__)
  #define _proto(FMT,...)	no_printk("### "FMT ,##__VA_ARGS__)
  #define _net(FMT,...)	no_printk("@@@ "FMT ,##__VA_ARGS__)
17926a793   David Howells   [AF_RXRPC]: Provi...
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
  #endif
  
  /*
   * debug assertion checking
   */
  #if 1 // defined(__KDEBUGALL)
  
  #define ASSERT(X)						\
  do {								\
  	if (unlikely(!(X))) {					\
9b6d53985   Joe Perches   rxrpc: Use pr_<le...
1154
1155
  		pr_err("Assertion failed
  ");			\
17926a793   David Howells   [AF_RXRPC]: Provi...
1156
1157
  		BUG();						\
  	}							\
b4f1342f9   David Howells   rxrpc: Adjust som...
1158
  } while (0)
17926a793   David Howells   [AF_RXRPC]: Provi...
1159
1160
1161
  
  #define ASSERTCMP(X, OP, Y)						\
  do {									\
cf13258fd   David Howells   rxrpc: Fix ASSERT...
1162
1163
  	__typeof__(X) _x = (X);						\
  	__typeof__(Y) _y = (__typeof__(X))(Y);				\
9b6d53985   Joe Perches   rxrpc: Use pr_<le...
1164
  	if (unlikely(!(_x OP _y))) {					\
cf13258fd   David Howells   rxrpc: Fix ASSERT...
1165
1166
1167
1168
  		pr_err("Assertion failed - %lu(0x%lx) %s %lu(0x%lx) is false
  ", \
  		       (unsigned long)_x, (unsigned long)_x, #OP,	\
  		       (unsigned long)_y, (unsigned long)_y);		\
17926a793   David Howells   [AF_RXRPC]: Provi...
1169
1170
  		BUG();							\
  	}								\
b4f1342f9   David Howells   rxrpc: Adjust som...
1171
  } while (0)
17926a793   David Howells   [AF_RXRPC]: Provi...
1172
1173
1174
1175
  
  #define ASSERTIF(C, X)						\
  do {								\
  	if (unlikely((C) && !(X))) {				\
9b6d53985   Joe Perches   rxrpc: Use pr_<le...
1176
1177
  		pr_err("Assertion failed
  ");			\
17926a793   David Howells   [AF_RXRPC]: Provi...
1178
1179
  		BUG();						\
  	}							\
b4f1342f9   David Howells   rxrpc: Adjust som...
1180
  } while (0)
17926a793   David Howells   [AF_RXRPC]: Provi...
1181
1182
1183
  
  #define ASSERTIFCMP(C, X, OP, Y)					\
  do {									\
cf13258fd   David Howells   rxrpc: Fix ASSERT...
1184
1185
  	__typeof__(X) _x = (X);						\
  	__typeof__(Y) _y = (__typeof__(X))(Y);				\
9b6d53985   Joe Perches   rxrpc: Use pr_<le...
1186
1187
1188
  	if (unlikely((C) && !(_x OP _y))) {				\
  		pr_err("Assertion failed - %lu(0x%lx) %s %lu(0x%lx) is false
  ", \
cf13258fd   David Howells   rxrpc: Fix ASSERT...
1189
1190
  		       (unsigned long)_x, (unsigned long)_x, #OP,	\
  		       (unsigned long)_y, (unsigned long)_y);		\
17926a793   David Howells   [AF_RXRPC]: Provi...
1191
1192
  		BUG();							\
  	}								\
b4f1342f9   David Howells   rxrpc: Adjust som...
1193
  } while (0)
17926a793   David Howells   [AF_RXRPC]: Provi...
1194
1195
1196
1197
1198
  
  #else
  
  #define ASSERT(X)				\
  do {						\
b4f1342f9   David Howells   rxrpc: Adjust som...
1199
  } while (0)
17926a793   David Howells   [AF_RXRPC]: Provi...
1200
1201
1202
  
  #define ASSERTCMP(X, OP, Y)			\
  do {						\
b4f1342f9   David Howells   rxrpc: Adjust som...
1203
  } while (0)
17926a793   David Howells   [AF_RXRPC]: Provi...
1204
1205
1206
  
  #define ASSERTIF(C, X)				\
  do {						\
b4f1342f9   David Howells   rxrpc: Adjust som...
1207
  } while (0)
17926a793   David Howells   [AF_RXRPC]: Provi...
1208
1209
1210
  
  #define ASSERTIFCMP(C, X, OP, Y)		\
  do {						\
b4f1342f9   David Howells   rxrpc: Adjust som...
1211
  } while (0)
17926a793   David Howells   [AF_RXRPC]: Provi...
1212
1213
  
  #endif /* __KDEBUGALL */