Merge branch 'core-urgent-for-linus' of git://git.kernel.org/pub/scm/linux/kernel...
[cascardo/linux.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 <net/sock.h>
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
20 #define CHECK_SLAB_OKAY(X) do {} while (0)
21 #endif
22
23 #define FCRYPT_BSIZE 8
24 struct rxrpc_crypt {
25         union {
26                 u8      x[FCRYPT_BSIZE];
27                 __be32  n[2];
28         };
29 } __attribute__((aligned(8)));
30
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)
37
38 /*
39  * sk_state for RxRPC sockets
40  */
41 enum {
42         RXRPC_UNCONNECTED = 0,
43         RXRPC_CLIENT_BOUND,             /* client local address bound */
44         RXRPC_CLIENT_CONNECTED,         /* client is connected */
45         RXRPC_SERVER_BOUND,             /* server local address bound */
46         RXRPC_SERVER_LISTENING,         /* server listening for connections */
47         RXRPC_CLOSE,                    /* socket is being closed */
48 };
49
50 /*
51  * RxRPC socket definition
52  */
53 struct rxrpc_sock {
54         /* WARNING: sk has to be the first member */
55         struct sock             sk;
56         rxrpc_interceptor_t     interceptor;    /* kernel service Rx interceptor function */
57         struct rxrpc_local      *local;         /* local endpoint */
58         struct rxrpc_transport  *trans;         /* transport handler */
59         struct rxrpc_conn_bundle *bundle;       /* virtual connection bundle */
60         struct rxrpc_connection *conn;          /* exclusive virtual connection */
61         struct list_head        listen_link;    /* link in the local endpoint's listen list */
62         struct list_head        secureq;        /* calls awaiting connection security clearance */
63         struct list_head        acceptq;        /* calls awaiting acceptance */
64         struct key              *key;           /* security for this socket */
65         struct key              *securities;    /* list of server security descriptors */
66         struct rb_root          calls;          /* outstanding calls on this socket */
67         unsigned long           flags;
68 #define RXRPC_SOCK_EXCLUSIVE_CONN       1       /* exclusive connection for a client socket */
69         rwlock_t                call_lock;      /* lock for calls */
70         u32                     min_sec_level;  /* minimum security level */
71 #define RXRPC_SECURITY_MAX      RXRPC_SECURITY_ENCRYPT
72         struct sockaddr_rxrpc   srx;            /* local address */
73         sa_family_t             proto;          /* protocol created with */
74 };
75
76 #define rxrpc_sk(__sk) container_of((__sk), struct rxrpc_sock, sk)
77
78 /*
79  * CPU-byteorder normalised Rx packet header.
80  */
81 struct rxrpc_host_header {
82         u32             epoch;          /* client boot timestamp */
83         u32             cid;            /* connection and channel ID */
84         u32             callNumber;     /* call ID (0 for connection-level packets) */
85         u32             seq;            /* sequence number of pkt in call stream */
86         u32             serial;         /* serial number of pkt sent to network */
87         u8              type;           /* packet type */
88         u8              flags;          /* packet flags */
89         u8              userStatus;     /* app-layer defined status */
90         u8              securityIndex;  /* security protocol ID */
91         union {
92                 u16     _rsvd;          /* reserved */
93                 u16     cksum;          /* kerberos security checksum */
94         };
95         u16             serviceId;      /* service ID */
96 } __packed;
97
98 /*
99  * RxRPC socket buffer private variables
100  * - max 48 bytes (struct sk_buff::cb)
101  */
102 struct rxrpc_skb_priv {
103         struct rxrpc_call       *call;          /* call with which associated */
104         unsigned long           resend_at;      /* time in jiffies at which to resend */
105         union {
106                 unsigned int    offset;         /* offset into buffer of next read */
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
112         struct rxrpc_host_header hdr;           /* RxRPC packet header from this packet */
113 };
114
115 #define rxrpc_skb(__skb) ((struct rxrpc_skb_priv *) &(__skb)->cb)
116
117 enum rxrpc_command {
118         RXRPC_CMD_SEND_DATA,            /* send data message */
119         RXRPC_CMD_SEND_ABORT,           /* request abort generation */
120         RXRPC_CMD_ACCEPT,               /* [server] accept incoming call */
121         RXRPC_CMD_REJECT_BUSY,          /* [server] reject a call as busy */
122 };
123
124 /*
125  * RxRPC security module interface
126  */
127 struct rxrpc_security {
128         const char              *name;          /* name of this service */
129         u8                      security_index; /* security type provided */
130
131         /* Initialise a security service */
132         int (*init)(void);
133
134         /* Clean up a security service */
135         void (*exit)(void);
136
137         /* initialise a connection's security */
138         int (*init_connection_security)(struct rxrpc_connection *);
139
140         /* prime a connection's packet security */
141         void (*prime_packet_security)(struct rxrpc_connection *);
142
143         /* impose security on a packet */
144         int (*secure_packet)(const struct rxrpc_call *,
145                              struct sk_buff *,
146                              size_t,
147                              void *);
148
149         /* verify the security on a received packet */
150         int (*verify_packet)(const struct rxrpc_call *, struct sk_buff *,
151                              u32 *);
152
153         /* issue a challenge */
154         int (*issue_challenge)(struct rxrpc_connection *);
155
156         /* respond to a challenge */
157         int (*respond_to_challenge)(struct rxrpc_connection *,
158                                     struct sk_buff *,
159                                     u32 *);
160
161         /* verify a response */
162         int (*verify_response)(struct rxrpc_connection *,
163                                struct sk_buff *,
164                                u32 *);
165
166         /* clear connection security */
167         void (*clear)(struct rxrpc_connection *);
168 };
169
170 /*
171  * RxRPC local transport endpoint definition
172  * - matched by local port, address and protocol type
173  */
174 struct rxrpc_local {
175         struct socket           *socket;        /* my UDP socket */
176         struct work_struct      destroyer;      /* endpoint destroyer */
177         struct work_struct      acceptor;       /* incoming call processor */
178         struct work_struct      rejecter;       /* packet reject writer */
179         struct work_struct      event_processor; /* endpoint event processor */
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 */
185         struct sk_buff_head     event_queue;    /* endpoint event packets awaiting processing */
186         spinlock_t              lock;           /* access lock */
187         rwlock_t                services_lock;  /* lock for services list */
188         atomic_t                usage;
189         int                     debug_id;       /* debug ID for printks */
190         volatile char           error_rcvd;     /* T if received ICMP error outstanding */
191         struct sockaddr_rxrpc   srx;            /* local address */
192 };
193
194 /*
195  * RxRPC remote transport endpoint definition
196  * - matched by remote port, address and protocol type
197  * - holds the connection ID counter for connections between the two endpoints
198  */
199 struct rxrpc_peer {
200         struct work_struct      destroyer;      /* peer destroyer */
201         struct list_head        link;           /* link in master peer list */
202         struct list_head        error_targets;  /* targets for net error distribution */
203         spinlock_t              lock;           /* access lock */
204         atomic_t                usage;
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) */
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) */
216         unsigned int            rtt_point;      /* next entry at which to insert */
217         unsigned int            rtt_usage;      /* amount of cache actually used */
218         suseconds_t             rtt_cache[RXRPC_RTT_CACHE_SIZE]; /* calculated RTT cache */
219 };
220
221 /*
222  * RxRPC point-to-point transport / connection manager definition
223  * - handles a bundle of connections between two endpoints
224  * - matched by { local, peer }
225  */
226 struct rxrpc_transport {
227         struct rxrpc_local      *local;         /* local transport endpoint */
228         struct rxrpc_peer       *peer;          /* remote transport endpoint */
229         struct work_struct      error_handler;  /* network error distributor */
230         struct rb_root          bundles;        /* client connection bundles on this transport */
231         struct rb_root          client_conns;   /* client connections on this transport */
232         struct rb_root          server_conns;   /* server connections on this transport */
233         struct list_head        link;           /* link in master session list */
234         struct sk_buff_head     error_queue;    /* error packets awaiting processing */
235         unsigned long           put_time;       /* time at which to reap */
236         spinlock_t              client_lock;    /* client connection allocation lock */
237         rwlock_t                conn_lock;      /* lock for active/dead connections */
238         atomic_t                usage;
239         int                     debug_id;       /* debug ID for printks */
240         unsigned int            conn_idcounter; /* connection ID counter (client) */
241 };
242
243 /*
244  * RxRPC client connection bundle
245  * - matched by { transport, service_id, key }
246  */
247 struct rxrpc_conn_bundle {
248         struct rb_node          node;           /* node in transport's lookup tree */
249         struct list_head        unused_conns;   /* unused connections in this bundle */
250         struct list_head        avail_conns;    /* available connections in this bundle */
251         struct list_head        busy_conns;     /* busy connections in this bundle */
252         struct key              *key;           /* security for this bundle */
253         wait_queue_head_t       chanwait;       /* wait for channel to become available */
254         atomic_t                usage;
255         int                     debug_id;       /* debug ID for printks */
256         unsigned short          num_conns;      /* number of connections in this bundle */
257         u16                     service_id;     /* Service ID for this bundle */
258         u8                      security_ix;    /* security type */
259 };
260
261 /*
262  * RxRPC connection definition
263  * - matched by { transport, service_id, conn_id, direction, key }
264  * - each connection can only handle four simultaneous calls
265  */
266 struct rxrpc_connection {
267         struct rxrpc_transport  *trans;         /* transport session */
268         struct rxrpc_conn_bundle *bundle;       /* connection bundle (client) */
269         struct work_struct      processor;      /* connection event processor */
270         struct rb_node          node;           /* node in transport's lookup tree */
271         struct list_head        link;           /* link in master connection list */
272         struct list_head        bundle_link;    /* link in bundle */
273         struct rb_root          calls;          /* calls on this connection */
274         struct sk_buff_head     rx_queue;       /* received conn-level packets */
275         struct rxrpc_call       *channels[RXRPC_MAXCALLS]; /* channels (active calls) */
276         const struct rxrpc_security *security;  /* applied security module */
277         struct key              *key;           /* security for this connection (client) */
278         struct key              *server_key;    /* security for this service */
279         struct crypto_skcipher  *cipher;        /* encryption handle */
280         struct rxrpc_crypt      csum_iv;        /* packet checksum base */
281         unsigned long           events;
282 #define RXRPC_CONN_CHALLENGE    0               /* send challenge packet */
283         unsigned long           put_time;       /* time at which to reap */
284         rwlock_t                lock;           /* access lock */
285         spinlock_t              state_lock;     /* state-change lock */
286         atomic_t                usage;
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;
297         u32                     local_abort;    /* local abort code */
298         u32                     remote_abort;   /* remote abort code */
299         int                     error;          /* local error incurred */
300         int                     debug_id;       /* debug ID for printks */
301         unsigned int            call_counter;   /* call ID counter */
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 */
310         u32                     epoch;          /* epoch of this connection */
311         u32                     cid;            /* connection ID */
312         u16                     service_id;     /* service ID for this connection */
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
318 /*
319  * Flags in call->flags.
320  */
321 enum rxrpc_call_flag {
322         RXRPC_CALL_RELEASED,            /* call has been released - no more message to userspace */
323         RXRPC_CALL_TERMINAL_MSG,        /* call has given the socket its final message */
324         RXRPC_CALL_RCVD_LAST,           /* all packets received */
325         RXRPC_CALL_RUN_RTIMER,          /* Tx resend timer started */
326         RXRPC_CALL_TX_SOFT_ACK,         /* sent some soft ACKs */
327         RXRPC_CALL_PROC_BUSY,           /* the processor is busy */
328         RXRPC_CALL_INIT_ACCEPT,         /* acceptance was initiated */
329         RXRPC_CALL_HAS_USERID,          /* has a user ID attached */
330         RXRPC_CALL_EXPECT_OOS,          /* expect out of sequence packets */
331 };
332
333 /*
334  * Events that can be raised on a call.
335  */
336 enum rxrpc_call_event {
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 */
354 };
355
356 /*
357  * The states that a call can be in.
358  */
359 enum rxrpc_call_state {
360         RXRPC_CALL_CLIENT_SEND_REQUEST, /* - client sending request phase */
361         RXRPC_CALL_CLIENT_AWAIT_REPLY,  /* - client awaiting reply */
362         RXRPC_CALL_CLIENT_RECV_REPLY,   /* - client receiving reply phase */
363         RXRPC_CALL_CLIENT_FINAL_ACK,    /* - client sending final ACK phase */
364         RXRPC_CALL_SERVER_SECURING,     /* - server securing request connection */
365         RXRPC_CALL_SERVER_ACCEPTING,    /* - server accepting request */
366         RXRPC_CALL_SERVER_RECV_REQUEST, /* - server receiving request */
367         RXRPC_CALL_SERVER_ACK_REQUEST,  /* - server pending ACK of request */
368         RXRPC_CALL_SERVER_SEND_REPLY,   /* - server sending reply */
369         RXRPC_CALL_SERVER_AWAIT_ACK,    /* - server awaiting final ACK */
370         RXRPC_CALL_COMPLETE,            /* - call completed */
371         RXRPC_CALL_SERVER_BUSY,         /* - call rejected by busy server */
372         RXRPC_CALL_REMOTELY_ABORTED,    /* - call aborted by peer */
373         RXRPC_CALL_LOCALLY_ABORTED,     /* - call aborted locally on error or close */
374         RXRPC_CALL_NETWORK_ERROR,       /* - call terminated by network error */
375         RXRPC_CALL_DEAD,                /* - call is dead */
376         NR__RXRPC_CALL_STATES
377 };
378
379 /*
380  * RxRPC call definition
381  * - matched by { connection, call_id }
382  */
383 struct rxrpc_call {
384         struct rxrpc_connection *conn;          /* connection carrying call */
385         struct rxrpc_sock       *socket;        /* socket responsible */
386         struct timer_list       lifetimer;      /* lifetime remaining on call */
387         struct timer_list       deadspan;       /* reap timer for re-ACK'ing, etc  */
388         struct timer_list       ack_timer;      /* ACK generation timer */
389         struct timer_list       resend_timer;   /* Tx resend timer */
390         struct work_struct      destroyer;      /* call destroyer */
391         struct work_struct      processor;      /* packet processor and ACK generator */
392         struct list_head        link;           /* link in master call list */
393         struct list_head        error_link;     /* link in error distribution list */
394         struct list_head        accept_link;    /* calls awaiting acceptance */
395         struct rb_node          sock_node;      /* node in socket call tree */
396         struct rb_node          conn_node;      /* node in connection call tree */
397         struct sk_buff_head     rx_queue;       /* received packets */
398         struct sk_buff_head     rx_oos_queue;   /* packets received out of sequence */
399         struct sk_buff          *tx_pending;    /* Tx socket buffer being filled */
400         wait_queue_head_t       tx_waitq;       /* wait for Tx window space to become available */
401         unsigned long           user_call_ID;   /* user-defined call ID */
402         unsigned long           creation_jif;   /* time of call creation */
403         unsigned long           flags;
404         unsigned long           events;
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 */
409         u32                     local_abort;    /* local abort code */
410         u32                     remote_abort;   /* remote abort code */
411         int                     error;          /* local error incurred */
412         enum rxrpc_call_state   state : 8;      /* current state of call */
413         int                     debug_id;       /* debug ID for printks */
414         u8                      channel;        /* connection channel occupied by this call */
415
416         /* transmission-phase ACK management */
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 */
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) */
434         rxrpc_seq_t             ackr_prev_seq;  /* previous sequence number received */
435         u8                      ackr_reason;    /* reason to ACK */
436         rxrpc_serial_t          ackr_serial;    /* serial of packet being ACK'd */
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
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 */
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 */
452         union {                                 /* Peer IP address for hashing */
453                 __be32  ipv4_addr;
454                 __u8    ipv6_addr[16];          /* Anticipates eventual IPv6 support */
455         } peer_ip;
456 };
457
458 /*
459  * locally abort an RxRPC call
460  */
461 static inline void rxrpc_abort_call(struct rxrpc_call *call, u32 abort_code)
462 {
463         write_lock_bh(&call->state_lock);
464         if (call->state < RXRPC_CALL_COMPLETE) {
465                 call->local_abort = abort_code;
466                 call->state = RXRPC_CALL_LOCALLY_ABORTED;
467                 set_bit(RXRPC_CALL_EV_ABORT, &call->events);
468         }
469         write_unlock_bh(&call->state_lock);
470 }
471
472 /*
473  * af_rxrpc.c
474  */
475 extern atomic_t rxrpc_n_skbs;
476 extern u32 rxrpc_epoch;
477 extern atomic_t rxrpc_debug_id;
478 extern struct workqueue_struct *rxrpc_workqueue;
479
480 /*
481  * ar-accept.c
482  */
483 void rxrpc_accept_incoming_calls(struct work_struct *);
484 struct rxrpc_call *rxrpc_accept_call(struct rxrpc_sock *, unsigned long);
485 int rxrpc_reject_call(struct rxrpc_sock *);
486
487 /*
488  * ar-ack.c
489  */
490 void __rxrpc_propose_ACK(struct rxrpc_call *, u8, u32, bool);
491 void rxrpc_propose_ACK(struct rxrpc_call *, u8, u32, bool);
492 void rxrpc_process_call(struct work_struct *);
493
494 /*
495  * ar-call.c
496  */
497 extern unsigned int rxrpc_max_call_lifetime;
498 extern unsigned int rxrpc_dead_call_expiry;
499 extern struct kmem_cache *rxrpc_call_jar;
500 extern struct list_head rxrpc_calls;
501 extern rwlock_t rxrpc_call_lock;
502
503 struct rxrpc_call *rxrpc_find_call_hash(struct rxrpc_host_header *,
504                                         void *, sa_family_t, const void *);
505 struct rxrpc_call *rxrpc_get_client_call(struct rxrpc_sock *,
506                                          struct rxrpc_transport *,
507                                          struct rxrpc_conn_bundle *,
508                                          unsigned long, int, gfp_t);
509 struct rxrpc_call *rxrpc_incoming_call(struct rxrpc_sock *,
510                                        struct rxrpc_connection *,
511                                        struct rxrpc_host_header *);
512 struct rxrpc_call *rxrpc_find_server_call(struct rxrpc_sock *, unsigned long);
513 void rxrpc_release_call(struct rxrpc_call *);
514 void rxrpc_release_calls_on_socket(struct rxrpc_sock *);
515 void __rxrpc_put_call(struct rxrpc_call *);
516 void __exit rxrpc_destroy_all_calls(void);
517
518 /*
519  * ar-connection.c
520  */
521 extern unsigned int rxrpc_connection_expiry;
522 extern struct list_head rxrpc_connections;
523 extern rwlock_t rxrpc_connection_lock;
524
525 struct rxrpc_conn_bundle *rxrpc_get_bundle(struct rxrpc_sock *,
526                                            struct rxrpc_transport *,
527                                            struct key *, u16, gfp_t);
528 void rxrpc_put_bundle(struct rxrpc_transport *, struct rxrpc_conn_bundle *);
529 int rxrpc_connect_call(struct rxrpc_sock *, struct rxrpc_transport *,
530                        struct rxrpc_conn_bundle *, struct rxrpc_call *, gfp_t);
531 void rxrpc_put_connection(struct rxrpc_connection *);
532 void __exit rxrpc_destroy_all_connections(void);
533 struct rxrpc_connection *rxrpc_find_connection(struct rxrpc_transport *,
534                                                struct rxrpc_host_header *);
535 extern struct rxrpc_connection *
536 rxrpc_incoming_connection(struct rxrpc_transport *, struct rxrpc_host_header *);
537
538 /*
539  * ar-connevent.c
540  */
541 void rxrpc_process_connection(struct work_struct *);
542 void rxrpc_reject_packet(struct rxrpc_local *, struct sk_buff *);
543 void rxrpc_reject_packets(struct work_struct *);
544
545 /*
546  * ar-error.c
547  */
548 void rxrpc_UDP_error_report(struct sock *);
549 void rxrpc_UDP_error_handler(struct work_struct *);
550
551 /*
552  * ar-input.c
553  */
554 void rxrpc_data_ready(struct sock *);
555 int rxrpc_queue_rcv_skb(struct rxrpc_call *, struct sk_buff *, bool, bool);
556 void rxrpc_fast_process_packet(struct rxrpc_call *, struct sk_buff *);
557
558 /*
559  * ar-local.c
560  */
561 extern rwlock_t rxrpc_local_lock;
562
563 struct rxrpc_local *rxrpc_lookup_local(struct sockaddr_rxrpc *);
564 void rxrpc_put_local(struct rxrpc_local *);
565 void __exit rxrpc_destroy_all_locals(void);
566
567 /*
568  * ar-key.c
569  */
570 extern struct key_type key_type_rxrpc;
571 extern struct key_type key_type_rxrpc_s;
572
573 int rxrpc_request_key(struct rxrpc_sock *, char __user *, int);
574 int rxrpc_server_keyring(struct rxrpc_sock *, char __user *, int);
575 int rxrpc_get_server_data_key(struct rxrpc_connection *, const void *, time_t,
576                               u32);
577
578 /*
579  * ar-output.c
580  */
581 extern unsigned int rxrpc_resend_timeout;
582
583 int rxrpc_send_packet(struct rxrpc_transport *, struct sk_buff *);
584 int rxrpc_client_sendmsg(struct rxrpc_sock *, struct rxrpc_transport *,
585                          struct msghdr *, size_t);
586 int rxrpc_server_sendmsg(struct rxrpc_sock *, struct msghdr *, size_t);
587
588 /*
589  * ar-peer.c
590  */
591 struct rxrpc_peer *rxrpc_get_peer(struct sockaddr_rxrpc *, gfp_t);
592 void rxrpc_put_peer(struct rxrpc_peer *);
593 struct rxrpc_peer *rxrpc_find_peer(struct rxrpc_local *, __be32, __be16);
594 void __exit rxrpc_destroy_all_peers(void);
595
596 /*
597  * ar-proc.c
598  */
599 extern const char *const rxrpc_call_states[];
600 extern const struct file_operations rxrpc_call_seq_fops;
601 extern const struct file_operations rxrpc_connection_seq_fops;
602
603 /*
604  * ar-recvmsg.c
605  */
606 void rxrpc_remove_user_ID(struct rxrpc_sock *, struct rxrpc_call *);
607 int rxrpc_recvmsg(struct socket *, struct msghdr *, size_t, int);
608
609 /*
610  * ar-security.c
611  */
612 int __init rxrpc_init_security(void);
613 void rxrpc_exit_security(void);
614 int rxrpc_init_client_conn_security(struct rxrpc_connection *);
615 int rxrpc_init_server_conn_security(struct rxrpc_connection *);
616
617 /*
618  * ar-skbuff.c
619  */
620 void rxrpc_packet_destructor(struct sk_buff *);
621
622 /*
623  * ar-transport.c
624  */
625 extern unsigned int rxrpc_transport_expiry;
626
627 struct rxrpc_transport *rxrpc_get_transport(struct rxrpc_local *,
628                                             struct rxrpc_peer *, gfp_t);
629 void rxrpc_put_transport(struct rxrpc_transport *);
630 void __exit rxrpc_destroy_all_transports(void);
631 struct rxrpc_transport *rxrpc_find_transport(struct rxrpc_local *,
632                                              struct rxrpc_peer *);
633
634 /*
635  * insecure.c
636  */
637 extern const struct rxrpc_security rxrpc_no_security;
638
639 /*
640  * misc.c
641  */
642 extern unsigned int rxrpc_requested_ack_delay;
643 extern unsigned int rxrpc_soft_ack_delay;
644 extern unsigned int rxrpc_idle_ack_delay;
645 extern unsigned int rxrpc_rx_window_size;
646 extern unsigned int rxrpc_rx_mtu;
647 extern unsigned int rxrpc_rx_jumbo_max;
648
649 extern const char *const rxrpc_pkts[];
650 extern const s8 rxrpc_ack_priority[];
651
652 extern const char *rxrpc_acks(u8 reason);
653
654 /*
655  * rxkad.c
656  */
657 #ifdef CONFIG_RXKAD
658 extern const struct rxrpc_security rxkad;
659 #endif
660
661 /*
662  * sysctl.c
663  */
664 #ifdef CONFIG_SYSCTL
665 extern int __init rxrpc_sysctl_init(void);
666 extern void rxrpc_sysctl_exit(void);
667 #else
668 static inline int __init rxrpc_sysctl_init(void) { return 0; }
669 static inline void rxrpc_sysctl_exit(void) {}
670 #endif
671
672 /*
673  * debug tracing
674  */
675 extern unsigned int rxrpc_debug;
676
677 #define dbgprintk(FMT,...) \
678         printk("[%-6.6s] "FMT"\n", current->comm ,##__VA_ARGS__)
679
680 #define kenter(FMT,...) dbgprintk("==> %s("FMT")",__func__ ,##__VA_ARGS__)
681 #define kleave(FMT,...) dbgprintk("<== %s()"FMT"",__func__ ,##__VA_ARGS__)
682 #define kdebug(FMT,...) dbgprintk("    "FMT ,##__VA_ARGS__)
683 #define kproto(FMT,...) dbgprintk("### "FMT ,##__VA_ARGS__)
684 #define knet(FMT,...)   dbgprintk("@@@ "FMT ,##__VA_ARGS__)
685
686
687 #if defined(__KDEBUG)
688 #define _enter(FMT,...) kenter(FMT,##__VA_ARGS__)
689 #define _leave(FMT,...) kleave(FMT,##__VA_ARGS__)
690 #define _debug(FMT,...) kdebug(FMT,##__VA_ARGS__)
691 #define _proto(FMT,...) kproto(FMT,##__VA_ARGS__)
692 #define _net(FMT,...)   knet(FMT,##__VA_ARGS__)
693
694 #elif defined(CONFIG_AF_RXRPC_DEBUG)
695 #define RXRPC_DEBUG_KENTER      0x01
696 #define RXRPC_DEBUG_KLEAVE      0x02
697 #define RXRPC_DEBUG_KDEBUG      0x04
698 #define RXRPC_DEBUG_KPROTO      0x08
699 #define RXRPC_DEBUG_KNET        0x10
700
701 #define _enter(FMT,...)                                 \
702 do {                                                    \
703         if (unlikely(rxrpc_debug & RXRPC_DEBUG_KENTER)) \
704                 kenter(FMT,##__VA_ARGS__);              \
705 } while (0)
706
707 #define _leave(FMT,...)                                 \
708 do {                                                    \
709         if (unlikely(rxrpc_debug & RXRPC_DEBUG_KLEAVE)) \
710                 kleave(FMT,##__VA_ARGS__);              \
711 } while (0)
712
713 #define _debug(FMT,...)                                 \
714 do {                                                    \
715         if (unlikely(rxrpc_debug & RXRPC_DEBUG_KDEBUG)) \
716                 kdebug(FMT,##__VA_ARGS__);              \
717 } while (0)
718
719 #define _proto(FMT,...)                                 \
720 do {                                                    \
721         if (unlikely(rxrpc_debug & RXRPC_DEBUG_KPROTO)) \
722                 kproto(FMT,##__VA_ARGS__);              \
723 } while (0)
724
725 #define _net(FMT,...)                                   \
726 do {                                                    \
727         if (unlikely(rxrpc_debug & RXRPC_DEBUG_KNET))   \
728                 knet(FMT,##__VA_ARGS__);                \
729 } while (0)
730
731 #else
732 #define _enter(FMT,...) no_printk("==> %s("FMT")",__func__ ,##__VA_ARGS__)
733 #define _leave(FMT,...) no_printk("<== %s()"FMT"",__func__ ,##__VA_ARGS__)
734 #define _debug(FMT,...) no_printk("    "FMT ,##__VA_ARGS__)
735 #define _proto(FMT,...) no_printk("### "FMT ,##__VA_ARGS__)
736 #define _net(FMT,...)   no_printk("@@@ "FMT ,##__VA_ARGS__)
737 #endif
738
739 /*
740  * debug assertion checking
741  */
742 #if 1 // defined(__KDEBUGALL)
743
744 #define ASSERT(X)                                               \
745 do {                                                            \
746         if (unlikely(!(X))) {                                   \
747                 printk(KERN_ERR "\n");                          \
748                 printk(KERN_ERR "RxRPC: Assertion failed\n");   \
749                 BUG();                                          \
750         }                                                       \
751 } while (0)
752
753 #define ASSERTCMP(X, OP, Y)                                             \
754 do {                                                                    \
755         if (unlikely(!((X) OP (Y)))) {                                  \
756                 printk(KERN_ERR "\n");                                  \
757                 printk(KERN_ERR "RxRPC: Assertion failed\n");           \
758                 printk(KERN_ERR "%lu " #OP " %lu is false\n",           \
759                        (unsigned long)(X), (unsigned long)(Y));         \
760                 printk(KERN_ERR "0x%lx " #OP " 0x%lx is false\n",       \
761                        (unsigned long)(X), (unsigned long)(Y));         \
762                 BUG();                                                  \
763         }                                                               \
764 } while (0)
765
766 #define ASSERTIF(C, X)                                          \
767 do {                                                            \
768         if (unlikely((C) && !(X))) {                            \
769                 printk(KERN_ERR "\n");                          \
770                 printk(KERN_ERR "RxRPC: Assertion failed\n");   \
771                 BUG();                                          \
772         }                                                       \
773 } while (0)
774
775 #define ASSERTIFCMP(C, X, OP, Y)                                        \
776 do {                                                                    \
777         if (unlikely((C) && !((X) OP (Y)))) {                           \
778                 printk(KERN_ERR "\n");                                  \
779                 printk(KERN_ERR "RxRPC: Assertion failed\n");           \
780                 printk(KERN_ERR "%lu " #OP " %lu is false\n",           \
781                        (unsigned long)(X), (unsigned long)(Y));         \
782                 printk(KERN_ERR "0x%lx " #OP " 0x%lx is false\n",       \
783                        (unsigned long)(X), (unsigned long)(Y));         \
784                 BUG();                                                  \
785         }                                                               \
786 } while (0)
787
788 #else
789
790 #define ASSERT(X)                               \
791 do {                                            \
792 } while (0)
793
794 #define ASSERTCMP(X, OP, Y)                     \
795 do {                                            \
796 } while (0)
797
798 #define ASSERTIF(C, X)                          \
799 do {                                            \
800 } while (0)
801
802 #define ASSERTIFCMP(C, X, OP, Y)                \
803 do {                                            \
804 } while (0)
805
806 #endif /* __KDEBUGALL */
807
808 /*
809  * socket buffer accounting / leak finding
810  */
811 static inline void __rxrpc_new_skb(struct sk_buff *skb, const char *fn)
812 {
813         //_net("new skb %p %s [%d]", skb, fn, atomic_read(&rxrpc_n_skbs));
814         //atomic_inc(&rxrpc_n_skbs);
815 }
816
817 #define rxrpc_new_skb(skb) __rxrpc_new_skb((skb), __func__)
818
819 static inline void __rxrpc_kill_skb(struct sk_buff *skb, const char *fn)
820 {
821         //_net("kill skb %p %s [%d]", skb, fn, atomic_read(&rxrpc_n_skbs));
822         //atomic_dec(&rxrpc_n_skbs);
823 }
824
825 #define rxrpc_kill_skb(skb) __rxrpc_kill_skb((skb), __func__)
826
827 static inline void __rxrpc_free_skb(struct sk_buff *skb, const char *fn)
828 {
829         if (skb) {
830                 CHECK_SLAB_OKAY(&skb->users);
831                 //_net("free skb %p %s [%d]",
832                 //     skb, fn, atomic_read(&rxrpc_n_skbs));
833                 //atomic_dec(&rxrpc_n_skbs);
834                 kfree_skb(skb);
835         }
836 }
837
838 #define rxrpc_free_skb(skb) __rxrpc_free_skb((skb), __func__)
839
840 static inline void rxrpc_purge_queue(struct sk_buff_head *list)
841 {
842         struct sk_buff *skb;
843         while ((skb = skb_dequeue((list))) != NULL)
844                 rxrpc_free_skb(skb);
845 }
846
847 static inline void __rxrpc_get_local(struct rxrpc_local *local, const char *f)
848 {
849         CHECK_SLAB_OKAY(&local->usage);
850         if (atomic_inc_return(&local->usage) == 1)
851                 printk("resurrected (%s)\n", f);
852 }
853
854 #define rxrpc_get_local(LOCAL) __rxrpc_get_local((LOCAL), __func__)
855
856 #define rxrpc_get_call(CALL)                            \
857 do {                                                    \
858         CHECK_SLAB_OKAY(&(CALL)->usage);                \
859         if (atomic_inc_return(&(CALL)->usage) == 1)     \
860                 BUG();                                  \
861 } while (0)
862
863 #define rxrpc_put_call(CALL)                            \
864 do {                                                    \
865         __rxrpc_put_call(CALL);                         \
866 } while (0)