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