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