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