rxrpc: Trim line-terminal whitespace
[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
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
24struct 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 */
41enum {
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 */
53struct 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 */
81struct 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 */
102struct 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
117enum 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 */
127struct 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 */
174struct 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 */
199struct 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 */
226struct 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 */
247struct 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 */
266struct 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 */
321enum 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 */
336enum 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 */
359enum 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 */
383struct 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 */
461static 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 475extern atomic_t rxrpc_n_skbs;
0d12f8a4 476extern u32 rxrpc_epoch;
651350d1
DH
477extern atomic_t rxrpc_debug_id;
478extern struct workqueue_struct *rxrpc_workqueue;
17926a79 479
2341e077
DH
480extern struct rxrpc_transport *rxrpc_name_to_transport(struct rxrpc_sock *,
481 struct sockaddr *,
482 int, int, gfp_t);
483
17926a79
DH
484/*
485 * ar-accept.c
486 */
c1b1203d
JP
487void rxrpc_accept_incoming_calls(struct work_struct *);
488struct rxrpc_call *rxrpc_accept_call(struct rxrpc_sock *, unsigned long);
489int rxrpc_reject_call(struct rxrpc_sock *);
17926a79
DH
490
491/*
492 * ar-ack.c
493 */
0d12f8a4
DH
494void __rxrpc_propose_ACK(struct rxrpc_call *, u8, u32, bool);
495void rxrpc_propose_ACK(struct rxrpc_call *, u8, u32, bool);
c1b1203d 496void rxrpc_process_call(struct work_struct *);
17926a79
DH
497
498/*
499 * ar-call.c
500 */
dad8aff7
DH
501extern unsigned int rxrpc_max_call_lifetime;
502extern unsigned int rxrpc_dead_call_expiry;
17926a79
DH
503extern struct kmem_cache *rxrpc_call_jar;
504extern struct list_head rxrpc_calls;
505extern rwlock_t rxrpc_call_lock;
506
0d12f8a4
DH
507struct rxrpc_call *rxrpc_find_call_hash(struct rxrpc_host_header *,
508 void *, sa_family_t, const void *);
2341e077
DH
509struct rxrpc_call *rxrpc_find_call_by_user_ID(struct rxrpc_sock *, unsigned long);
510struct 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
514struct rxrpc_call *rxrpc_incoming_call(struct rxrpc_sock *,
515 struct rxrpc_connection *,
843099ca 516 struct rxrpc_host_header *);
c1b1203d
JP
517void rxrpc_release_call(struct rxrpc_call *);
518void rxrpc_release_calls_on_socket(struct rxrpc_sock *);
519void __rxrpc_put_call(struct rxrpc_call *);
520void __exit rxrpc_destroy_all_calls(void);
17926a79
DH
521
522/*
523 * ar-connection.c
524 */
dad8aff7 525extern unsigned int rxrpc_connection_expiry;
17926a79
DH
526extern struct list_head rxrpc_connections;
527extern rwlock_t rxrpc_connection_lock;
528
c1b1203d
JP
529struct rxrpc_conn_bundle *rxrpc_get_bundle(struct rxrpc_sock *,
530 struct rxrpc_transport *,
0d12f8a4 531 struct key *, u16, gfp_t);
c1b1203d
JP
532void rxrpc_put_bundle(struct rxrpc_transport *, struct rxrpc_conn_bundle *);
533int rxrpc_connect_call(struct rxrpc_sock *, struct rxrpc_transport *,
534 struct rxrpc_conn_bundle *, struct rxrpc_call *, gfp_t);
535void rxrpc_put_connection(struct rxrpc_connection *);
536void __exit rxrpc_destroy_all_connections(void);
537struct rxrpc_connection *rxrpc_find_connection(struct rxrpc_transport *,
0d12f8a4 538 struct rxrpc_host_header *);
17926a79 539extern struct rxrpc_connection *
843099ca 540rxrpc_incoming_connection(struct rxrpc_transport *, struct rxrpc_host_header *);
17926a79
DH
541
542/*
543 * ar-connevent.c
544 */
c1b1203d
JP
545void rxrpc_process_connection(struct work_struct *);
546void rxrpc_reject_packet(struct rxrpc_local *, struct sk_buff *);
547void rxrpc_reject_packets(struct work_struct *);
17926a79
DH
548
549/*
550 * ar-error.c
551 */
c1b1203d
JP
552void rxrpc_UDP_error_report(struct sock *);
553void rxrpc_UDP_error_handler(struct work_struct *);
17926a79
DH
554
555/*
556 * ar-input.c
557 */
676d2369 558void rxrpc_data_ready(struct sock *);
c1b1203d
JP
559int rxrpc_queue_rcv_skb(struct rxrpc_call *, struct sk_buff *, bool, bool);
560void rxrpc_fast_process_packet(struct rxrpc_call *, struct sk_buff *);
17926a79
DH
561
562/*
563 * ar-local.c
564 */
565extern rwlock_t rxrpc_local_lock;
5873c083 566
c1b1203d
JP
567struct rxrpc_local *rxrpc_lookup_local(struct sockaddr_rxrpc *);
568void rxrpc_put_local(struct rxrpc_local *);
569void __exit rxrpc_destroy_all_locals(void);
17926a79
DH
570
571/*
572 * ar-key.c
573 */
574extern struct key_type key_type_rxrpc;
575extern struct key_type key_type_rxrpc_s;
576
c1b1203d
JP
577int rxrpc_request_key(struct rxrpc_sock *, char __user *, int);
578int rxrpc_server_keyring(struct rxrpc_sock *, char __user *, int);
579int rxrpc_get_server_data_key(struct rxrpc_connection *, const void *, time_t,
580 u32);
17926a79
DH
581
582/*
583 * ar-output.c
584 */
dad8aff7 585extern unsigned int rxrpc_resend_timeout;
17926a79 586
c1b1203d 587int rxrpc_send_packet(struct rxrpc_transport *, struct sk_buff *);
2341e077 588int rxrpc_do_sendmsg(struct rxrpc_sock *, struct msghdr *, size_t);
17926a79
DH
589
590/*
591 * ar-peer.c
592 */
c1b1203d
JP
593struct rxrpc_peer *rxrpc_get_peer(struct sockaddr_rxrpc *, gfp_t);
594void rxrpc_put_peer(struct rxrpc_peer *);
595struct rxrpc_peer *rxrpc_find_peer(struct rxrpc_local *, __be32, __be16);
596void __exit rxrpc_destroy_all_peers(void);
17926a79
DH
597
598/*
599 * ar-proc.c
600 */
036c2e27
JE
601extern const char *const rxrpc_call_states[];
602extern const struct file_operations rxrpc_call_seq_fops;
603extern const struct file_operations rxrpc_connection_seq_fops;
17926a79
DH
604
605/*
606 * ar-recvmsg.c
607 */
c1b1203d 608void rxrpc_remove_user_ID(struct rxrpc_sock *, struct rxrpc_call *);
1b784140 609int rxrpc_recvmsg(struct socket *, struct msghdr *, size_t, int);
17926a79
DH
610
611/*
612 * ar-security.c
613 */
648af7fc
DH
614int __init rxrpc_init_security(void);
615void rxrpc_exit_security(void);
c1b1203d
JP
616int rxrpc_init_client_conn_security(struct rxrpc_connection *);
617int rxrpc_init_server_conn_security(struct rxrpc_connection *);
17926a79
DH
618
619/*
620 * ar-skbuff.c
621 */
c1b1203d 622void rxrpc_packet_destructor(struct sk_buff *);
17926a79
DH
623
624/*
625 * ar-transport.c
626 */
dad8aff7 627extern unsigned int rxrpc_transport_expiry;
5873c083 628
c1b1203d
JP
629struct rxrpc_transport *rxrpc_get_transport(struct rxrpc_local *,
630 struct rxrpc_peer *, gfp_t);
631void rxrpc_put_transport(struct rxrpc_transport *);
632void __exit rxrpc_destroy_all_transports(void);
633struct rxrpc_transport *rxrpc_find_transport(struct rxrpc_local *,
634 struct rxrpc_peer *);
17926a79 635
e0e4d82f
DH
636/*
637 * insecure.c
638 */
639extern const struct rxrpc_security rxrpc_no_security;
640
8e688d9c
DH
641/*
642 * misc.c
643 */
644extern unsigned int rxrpc_requested_ack_delay;
645extern unsigned int rxrpc_soft_ack_delay;
646extern unsigned int rxrpc_idle_ack_delay;
647extern unsigned int rxrpc_rx_window_size;
648extern unsigned int rxrpc_rx_mtu;
649extern unsigned int rxrpc_rx_jumbo_max;
650
5b3e87f1 651extern const char *const rxrpc_pkts[];
8e688d9c
DH
652extern const s8 rxrpc_ack_priority[];
653
654extern const char *rxrpc_acks(u8 reason);
655
648af7fc
DH
656/*
657 * rxkad.c
658 */
659#ifdef CONFIG_RXKAD
660extern const struct rxrpc_security rxkad;
661#endif
662
5873c083
DH
663/*
664 * sysctl.c
665 */
666#ifdef CONFIG_SYSCTL
667extern int __init rxrpc_sysctl_init(void);
668extern void rxrpc_sysctl_exit(void);
669#else
670static inline int __init rxrpc_sysctl_init(void) { return 0; }
671static inline void rxrpc_sysctl_exit(void) {}
672#endif
673
17926a79
DH
674/*
675 * debug tracing
676 */
95c96174 677extern unsigned int rxrpc_debug;
17926a79
DH
678
679#define dbgprintk(FMT,...) \
9f389f4b 680 printk("[%-6.6s] "FMT"\n", current->comm ,##__VA_ARGS__)
17926a79 681
0dc47877
HH
682#define kenter(FMT,...) dbgprintk("==> %s("FMT")",__func__ ,##__VA_ARGS__)
683#define kleave(FMT,...) dbgprintk("<== %s()"FMT"",__func__ ,##__VA_ARGS__)
17926a79
DH
684#define kdebug(FMT,...) dbgprintk(" "FMT ,##__VA_ARGS__)
685#define kproto(FMT,...) dbgprintk("### "FMT ,##__VA_ARGS__)
686#define knet(FMT,...) dbgprintk("@@@ "FMT ,##__VA_ARGS__)
687
688
689#if defined(__KDEBUG)
690#define _enter(FMT,...) kenter(FMT,##__VA_ARGS__)
691#define _leave(FMT,...) kleave(FMT,##__VA_ARGS__)
692#define _debug(FMT,...) kdebug(FMT,##__VA_ARGS__)
693#define _proto(FMT,...) kproto(FMT,##__VA_ARGS__)
694#define _net(FMT,...) knet(FMT,##__VA_ARGS__)
695
696#elif defined(CONFIG_AF_RXRPC_DEBUG)
697#define RXRPC_DEBUG_KENTER 0x01
698#define RXRPC_DEBUG_KLEAVE 0x02
699#define RXRPC_DEBUG_KDEBUG 0x04
700#define RXRPC_DEBUG_KPROTO 0x08
701#define RXRPC_DEBUG_KNET 0x10
702
703#define _enter(FMT,...) \
704do { \
705 if (unlikely(rxrpc_debug & RXRPC_DEBUG_KENTER)) \
706 kenter(FMT,##__VA_ARGS__); \
707} while (0)
708
709#define _leave(FMT,...) \
710do { \
711 if (unlikely(rxrpc_debug & RXRPC_DEBUG_KLEAVE)) \
712 kleave(FMT,##__VA_ARGS__); \
713} while (0)
714
715#define _debug(FMT,...) \
716do { \
717 if (unlikely(rxrpc_debug & RXRPC_DEBUG_KDEBUG)) \
718 kdebug(FMT,##__VA_ARGS__); \
719} while (0)
720
721#define _proto(FMT,...) \
722do { \
723 if (unlikely(rxrpc_debug & RXRPC_DEBUG_KPROTO)) \
724 kproto(FMT,##__VA_ARGS__); \
725} while (0)
726
727#define _net(FMT,...) \
728do { \
729 if (unlikely(rxrpc_debug & RXRPC_DEBUG_KNET)) \
730 knet(FMT,##__VA_ARGS__); \
731} while (0)
732
733#else
12fdff3f
DH
734#define _enter(FMT,...) no_printk("==> %s("FMT")",__func__ ,##__VA_ARGS__)
735#define _leave(FMT,...) no_printk("<== %s()"FMT"",__func__ ,##__VA_ARGS__)
736#define _debug(FMT,...) no_printk(" "FMT ,##__VA_ARGS__)
737#define _proto(FMT,...) no_printk("### "FMT ,##__VA_ARGS__)
738#define _net(FMT,...) no_printk("@@@ "FMT ,##__VA_ARGS__)
17926a79
DH
739#endif
740
741/*
742 * debug assertion checking
743 */
744#if 1 // defined(__KDEBUGALL)
745
746#define ASSERT(X) \
747do { \
748 if (unlikely(!(X))) { \
9b6d5398 749 pr_err("Assertion failed\n"); \
17926a79
DH
750 BUG(); \
751 } \
b4f1342f 752} while (0)
17926a79
DH
753
754#define ASSERTCMP(X, OP, Y) \
755do { \
9b6d5398
JP
756 unsigned long _x = (unsigned long)(X); \
757 unsigned long _y = (unsigned long)(Y); \
758 if (unlikely(!(_x OP _y))) { \
759 pr_err("Assertion failed - %lu(0x%lx) %s %lu(0x%lx) is false\n", \
760 _x, _x, #OP, _y, _y); \
17926a79
DH
761 BUG(); \
762 } \
b4f1342f 763} while (0)
17926a79
DH
764
765#define ASSERTIF(C, X) \
766do { \
767 if (unlikely((C) && !(X))) { \
9b6d5398 768 pr_err("Assertion failed\n"); \
17926a79
DH
769 BUG(); \
770 } \
b4f1342f 771} while (0)
17926a79
DH
772
773#define ASSERTIFCMP(C, X, OP, Y) \
774do { \
9b6d5398
JP
775 unsigned long _x = (unsigned long)(X); \
776 unsigned long _y = (unsigned long)(Y); \
777 if (unlikely((C) && !(_x OP _y))) { \
778 pr_err("Assertion failed - %lu(0x%lx) %s %lu(0x%lx) is false\n", \
779 _x, _x, #OP, _y, _y); \
17926a79
DH
780 BUG(); \
781 } \
b4f1342f 782} while (0)
17926a79
DH
783
784#else
785
786#define ASSERT(X) \
787do { \
b4f1342f 788} while (0)
17926a79
DH
789
790#define ASSERTCMP(X, OP, Y) \
791do { \
b4f1342f 792} while (0)
17926a79
DH
793
794#define ASSERTIF(C, X) \
795do { \
b4f1342f 796} while (0)
17926a79
DH
797
798#define ASSERTIFCMP(C, X, OP, Y) \
799do { \
b4f1342f 800} while (0)
17926a79
DH
801
802#endif /* __KDEBUGALL */
803
804/*
805 * socket buffer accounting / leak finding
806 */
807static inline void __rxrpc_new_skb(struct sk_buff *skb, const char *fn)
808{
809 //_net("new skb %p %s [%d]", skb, fn, atomic_read(&rxrpc_n_skbs));
810 //atomic_inc(&rxrpc_n_skbs);
811}
812
813#define rxrpc_new_skb(skb) __rxrpc_new_skb((skb), __func__)
814
815static inline void __rxrpc_kill_skb(struct sk_buff *skb, const char *fn)
816{
817 //_net("kill skb %p %s [%d]", skb, fn, atomic_read(&rxrpc_n_skbs));
818 //atomic_dec(&rxrpc_n_skbs);
819}
820
821#define rxrpc_kill_skb(skb) __rxrpc_kill_skb((skb), __func__)
822
823static inline void __rxrpc_free_skb(struct sk_buff *skb, const char *fn)
824{
825 if (skb) {
826 CHECK_SLAB_OKAY(&skb->users);
827 //_net("free skb %p %s [%d]",
828 // skb, fn, atomic_read(&rxrpc_n_skbs));
829 //atomic_dec(&rxrpc_n_skbs);
830 kfree_skb(skb);
831 }
832}
833
834#define rxrpc_free_skb(skb) __rxrpc_free_skb((skb), __func__)
835
836static inline void rxrpc_purge_queue(struct sk_buff_head *list)
837{
838 struct sk_buff *skb;
839 while ((skb = skb_dequeue((list))) != NULL)
840 rxrpc_free_skb(skb);
841}
842
17926a79
DH
843static inline void __rxrpc_get_local(struct rxrpc_local *local, const char *f)
844{
845 CHECK_SLAB_OKAY(&local->usage);
846 if (atomic_inc_return(&local->usage) == 1)
847 printk("resurrected (%s)\n", f);
848}
849
850#define rxrpc_get_local(LOCAL) __rxrpc_get_local((LOCAL), __func__)
851
852#define rxrpc_get_call(CALL) \
853do { \
854 CHECK_SLAB_OKAY(&(CALL)->usage); \
855 if (atomic_inc_return(&(CALL)->usage) == 1) \
856 BUG(); \
b4f1342f 857} while (0)
17926a79
DH
858
859#define rxrpc_put_call(CALL) \
860do { \
861 __rxrpc_put_call(CALL); \
b4f1342f 862} while (0)