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