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