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