blob: de98a49adb359470dd926607f707117972f5186f [file] [log] [blame]
David Howells17926a72007-04-26 15:48:28 -07001/* 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
David Howellsbe6e6702016-04-04 14:00:32 +010012#include <linux/atomic.h>
David Howells8496af52016-07-01 07:51:50 +010013#include <linux/seqlock.h>
David Howells2baec2c2017-05-24 17:02:32 +010014#include <net/net_namespace.h>
15#include <net/netns/generic.h>
David Howellse0e4d822016-04-07 17:23:58 +010016#include <net/sock.h>
David Howellsbe6e6702016-04-04 14:00:32 +010017#include <net/af_rxrpc.h>
David Howells17926a72007-04-26 15:48:28 -070018#include <rxrpc/packet.h>
19
20#if 0
21#define CHECK_SLAB_OKAY(X) \
22 BUG_ON(atomic_read((X)) >> (sizeof(atomic_t) - 2) == \
23 (POISON_FREE << 8 | POISON_FREE))
24#else
David Howellsb4f13422016-03-04 15:56:19 +000025#define CHECK_SLAB_OKAY(X) do {} while (0)
David Howells17926a72007-04-26 15:48:28 -070026#endif
27
David Howells17926a72007-04-26 15:48:28 -070028#define FCRYPT_BSIZE 8
29struct rxrpc_crypt {
30 union {
31 u8 x[FCRYPT_BSIZE];
Al Viro91e916c2008-03-29 03:08:38 +000032 __be32 n[2];
David Howells17926a72007-04-26 15:48:28 -070033 };
34} __attribute__((aligned(8)));
35
David Howells651350d2007-04-26 15:50:17 -070036#define rxrpc_queue_work(WS) queue_work(rxrpc_workqueue, (WS))
37#define rxrpc_queue_delayed_work(WS,D) \
38 queue_delayed_work(rxrpc_workqueue, (WS), (D))
39
David Howellscc8feb82016-04-04 14:00:37 +010040struct rxrpc_connection;
41
David Howells17926a72007-04-26 15:48:28 -070042/*
David Howellsd0016482016-08-30 20:42:14 +010043 * Mark applied to socket buffers.
44 */
45enum rxrpc_skb_mark {
46 RXRPC_SKB_MARK_DATA, /* data message */
47 RXRPC_SKB_MARK_FINAL_ACK, /* final ACK received message */
48 RXRPC_SKB_MARK_BUSY, /* server busy message */
49 RXRPC_SKB_MARK_REMOTE_ABORT, /* remote abort message */
50 RXRPC_SKB_MARK_LOCAL_ABORT, /* local abort message */
51 RXRPC_SKB_MARK_NET_ERROR, /* network error message */
52 RXRPC_SKB_MARK_LOCAL_ERROR, /* local error message */
53 RXRPC_SKB_MARK_NEW_CALL, /* local error message */
54};
55
56/*
David Howells17926a72007-04-26 15:48:28 -070057 * sk_state for RxRPC sockets
58 */
59enum {
David Howells2341e072016-06-09 23:02:51 +010060 RXRPC_UNBOUND = 0,
61 RXRPC_CLIENT_UNBOUND, /* Unbound socket used as client */
David Howells17926a72007-04-26 15:48:28 -070062 RXRPC_CLIENT_BOUND, /* client local address bound */
David Howells17926a72007-04-26 15:48:28 -070063 RXRPC_SERVER_BOUND, /* server local address bound */
64 RXRPC_SERVER_LISTENING, /* server listening for connections */
David Howells210f0352017-01-05 10:38:36 +000065 RXRPC_SERVER_LISTEN_DISABLED, /* server listening disabled */
David Howells17926a72007-04-26 15:48:28 -070066 RXRPC_CLOSE, /* socket is being closed */
67};
68
69/*
David Howells2baec2c2017-05-24 17:02:32 +010070 * Per-network namespace data.
71 */
72struct rxrpc_net {
73 struct proc_dir_entry *proc_net; /* Subdir in /proc/net */
74 u32 epoch; /* Local epoch for detecting local-end reset */
75 struct list_head calls; /* List of calls active in this namespace */
76 rwlock_t call_lock; /* Lock for ->calls */
77
78 struct list_head conn_proc_list; /* List of conns in this namespace for proc */
79 struct list_head service_conns; /* Service conns in this namespace */
80 rwlock_t conn_lock; /* Lock for ->conn_proc_list, ->service_conns */
81 struct delayed_work service_conn_reaper;
82
83 unsigned int nr_client_conns;
84 unsigned int nr_active_client_conns;
85 bool kill_all_client_conns;
86 spinlock_t client_conn_cache_lock; /* Lock for ->*_client_conns */
87 spinlock_t client_conn_discard_lock; /* Prevent multiple discarders */
88 struct list_head waiting_client_conns;
89 struct list_head active_client_conns;
90 struct list_head idle_client_conns;
91 struct delayed_work client_conn_reaper;
92
93 struct list_head local_endpoints;
94 struct mutex local_mutex; /* Lock for ->local_endpoints */
95
96 spinlock_t peer_hash_lock; /* Lock for ->peer_hash */
97 DECLARE_HASHTABLE (peer_hash, 10);
98};
99
100/*
David Howells00e90712016-09-08 11:10:12 +0100101 * Service backlog preallocation.
102 *
103 * This contains circular buffers of preallocated peers, connections and calls
104 * for incoming service calls and their head and tail pointers. This allows
105 * calls to be set up in the data_ready handler, thereby avoiding the need to
106 * shuffle packets around so much.
107 */
108struct rxrpc_backlog {
109 unsigned short peer_backlog_head;
110 unsigned short peer_backlog_tail;
111 unsigned short conn_backlog_head;
112 unsigned short conn_backlog_tail;
113 unsigned short call_backlog_head;
114 unsigned short call_backlog_tail;
115#define RXRPC_BACKLOG_MAX 32
116 struct rxrpc_peer *peer_backlog[RXRPC_BACKLOG_MAX];
117 struct rxrpc_connection *conn_backlog[RXRPC_BACKLOG_MAX];
118 struct rxrpc_call *call_backlog[RXRPC_BACKLOG_MAX];
119};
120
121/*
David Howells17926a72007-04-26 15:48:28 -0700122 * RxRPC socket definition
123 */
124struct rxrpc_sock {
125 /* WARNING: sk has to be the first member */
126 struct sock sk;
David Howellsd0016482016-08-30 20:42:14 +0100127 rxrpc_notify_new_call_t notify_new_call; /* Func to notify of new call */
David Howells00e90712016-09-08 11:10:12 +0100128 rxrpc_discard_new_call_t discard_new_call; /* Func to discard a new call */
David Howells17926a72007-04-26 15:48:28 -0700129 struct rxrpc_local *local; /* local endpoint */
David Howells00e90712016-09-08 11:10:12 +0100130 struct rxrpc_backlog *backlog; /* Preallocation for services */
David Howells248f2192016-09-08 11:10:12 +0100131 spinlock_t incoming_lock; /* Incoming call vs service shutdown lock */
132 struct list_head sock_calls; /* List of calls owned by this socket */
133 struct list_head to_be_accepted; /* calls awaiting acceptance */
134 struct list_head recvmsg_q; /* Calls awaiting recvmsg's attention */
135 rwlock_t recvmsg_lock; /* Lock for recvmsg_q */
David Howells17926a72007-04-26 15:48:28 -0700136 struct key *key; /* security for this socket */
137 struct key *securities; /* list of server security descriptors */
David Howells00e90712016-09-08 11:10:12 +0100138 struct rb_root calls; /* User ID -> call mapping */
David Howells17926a72007-04-26 15:48:28 -0700139 unsigned long flags;
David Howells2341e072016-06-09 23:02:51 +0100140#define RXRPC_SOCK_CONNECTED 0 /* connect_srx is set */
David Howells17926a72007-04-26 15:48:28 -0700141 rwlock_t call_lock; /* lock for calls */
142 u32 min_sec_level; /* minimum security level */
143#define RXRPC_SECURITY_MAX RXRPC_SECURITY_ENCRYPT
David Howellscc8feb82016-04-04 14:00:37 +0100144 bool exclusive; /* Exclusive connection for a client socket */
145 sa_family_t family; /* Protocol family created with */
David Howells17926a72007-04-26 15:48:28 -0700146 struct sockaddr_rxrpc srx; /* local address */
David Howells2341e072016-06-09 23:02:51 +0100147 struct sockaddr_rxrpc connect_srx; /* Default client address from connect() */
David Howells17926a72007-04-26 15:48:28 -0700148};
149
150#define rxrpc_sk(__sk) container_of((__sk), struct rxrpc_sock, sk)
151
152/*
David Howells0d12f8a2016-03-04 15:53:46 +0000153 * CPU-byteorder normalised Rx packet header.
154 */
155struct rxrpc_host_header {
156 u32 epoch; /* client boot timestamp */
157 u32 cid; /* connection and channel ID */
158 u32 callNumber; /* call ID (0 for connection-level packets) */
159 u32 seq; /* sequence number of pkt in call stream */
160 u32 serial; /* serial number of pkt sent to network */
161 u8 type; /* packet type */
162 u8 flags; /* packet flags */
163 u8 userStatus; /* app-layer defined status */
164 u8 securityIndex; /* security protocol ID */
165 union {
166 u16 _rsvd; /* reserved */
167 u16 cksum; /* kerberos security checksum */
168 };
169 u16 serviceId; /* service ID */
170} __packed;
171
172/*
David Howells17926a72007-04-26 15:48:28 -0700173 * RxRPC socket buffer private variables
174 * - max 48 bytes (struct sk_buff::cb)
175 */
176struct rxrpc_skb_priv {
David Howells248f2192016-09-08 11:10:12 +0100177 union {
David Howells50235c42016-09-22 00:29:31 +0100178 u8 nr_jumbo; /* Number of jumbo subpackets */
David Howells248f2192016-09-08 11:10:12 +0100179 };
David Howells17926a72007-04-26 15:48:28 -0700180 union {
David Howells17926a72007-04-26 15:48:28 -0700181 int remain; /* amount of space remaining for next write */
David Howells17926a72007-04-26 15:48:28 -0700182 };
183
David Howells0d12f8a2016-03-04 15:53:46 +0000184 struct rxrpc_host_header hdr; /* RxRPC packet header from this packet */
David Howells17926a72007-04-26 15:48:28 -0700185};
186
187#define rxrpc_skb(__skb) ((struct rxrpc_skb_priv *) &(__skb)->cb)
188
David Howells17926a72007-04-26 15:48:28 -0700189/*
190 * RxRPC security module interface
191 */
192struct rxrpc_security {
David Howells17926a72007-04-26 15:48:28 -0700193 const char *name; /* name of this service */
194 u8 security_index; /* security type provided */
195
David Howells648af7f2016-04-07 17:23:51 +0100196 /* Initialise a security service */
197 int (*init)(void);
198
199 /* Clean up a security service */
200 void (*exit)(void);
201
David Howells17926a72007-04-26 15:48:28 -0700202 /* initialise a connection's security */
203 int (*init_connection_security)(struct rxrpc_connection *);
204
205 /* prime a connection's packet security */
Herbert Xua2636292016-06-26 14:55:24 -0700206 int (*prime_packet_security)(struct rxrpc_connection *);
David Howells17926a72007-04-26 15:48:28 -0700207
208 /* impose security on a packet */
Herbert Xua2636292016-06-26 14:55:24 -0700209 int (*secure_packet)(struct rxrpc_call *,
David Howells17926a72007-04-26 15:48:28 -0700210 struct sk_buff *,
211 size_t,
212 void *);
213
214 /* verify the security on a received packet */
David Howells5a429762016-09-06 22:19:51 +0100215 int (*verify_packet)(struct rxrpc_call *, struct sk_buff *,
David Howells248f2192016-09-08 11:10:12 +0100216 unsigned int, unsigned int, rxrpc_seq_t, u16);
217
218 /* Locate the data in a received packet that has been verified. */
219 void (*locate_data)(struct rxrpc_call *, struct sk_buff *,
220 unsigned int *, unsigned int *);
David Howells17926a72007-04-26 15:48:28 -0700221
222 /* issue a challenge */
223 int (*issue_challenge)(struct rxrpc_connection *);
224
225 /* respond to a challenge */
226 int (*respond_to_challenge)(struct rxrpc_connection *,
227 struct sk_buff *,
228 u32 *);
229
230 /* verify a response */
231 int (*verify_response)(struct rxrpc_connection *,
232 struct sk_buff *,
233 u32 *);
234
235 /* clear connection security */
236 void (*clear)(struct rxrpc_connection *);
237};
238
239/*
David Howells4f95dd72016-04-04 14:00:35 +0100240 * RxRPC local transport endpoint description
241 * - owned by a single AF_RXRPC socket
242 * - pointed to by transport socket struct sk_user_data
David Howells17926a72007-04-26 15:48:28 -0700243 */
244struct rxrpc_local {
David Howells4f95dd72016-04-04 14:00:35 +0100245 struct rcu_head rcu;
246 atomic_t usage;
David Howells2baec2c2017-05-24 17:02:32 +0100247 struct rxrpc_net *rxnet; /* The network ns in which this resides */
David Howells4f95dd72016-04-04 14:00:35 +0100248 struct list_head link;
David Howells17926a72007-04-26 15:48:28 -0700249 struct socket *socket; /* my UDP socket */
David Howells4f95dd72016-04-04 14:00:35 +0100250 struct work_struct processor;
David Howells1e9e5c92016-09-29 22:37:15 +0100251 struct rxrpc_sock __rcu *service; /* Service(s) listening on this endpoint */
David Howells17926a72007-04-26 15:48:28 -0700252 struct rw_semaphore defrag_sem; /* control re-enablement of IP DF bit */
David Howells17926a72007-04-26 15:48:28 -0700253 struct sk_buff_head reject_queue; /* packets awaiting rejection */
David Howells44ba0692015-04-01 16:31:26 +0100254 struct sk_buff_head event_queue; /* endpoint event packets awaiting processing */
David Howells999b69f2016-06-17 15:42:35 +0100255 struct rb_root client_conns; /* Client connections by socket params */
256 spinlock_t client_conns_lock; /* Lock for client_conns */
David Howells17926a72007-04-26 15:48:28 -0700257 spinlock_t lock; /* access lock */
258 rwlock_t services_lock; /* lock for services list */
David Howells17926a72007-04-26 15:48:28 -0700259 int debug_id; /* debug ID for printks */
David Howells4f95dd72016-04-04 14:00:35 +0100260 bool dead;
David Howells17926a72007-04-26 15:48:28 -0700261 struct sockaddr_rxrpc srx; /* local address */
262};
263
264/*
265 * RxRPC remote transport endpoint definition
David Howellsbe6e6702016-04-04 14:00:32 +0100266 * - matched by local endpoint, remote port, address and protocol type
David Howells17926a72007-04-26 15:48:28 -0700267 */
268struct rxrpc_peer {
David Howellsbe6e6702016-04-04 14:00:32 +0100269 struct rcu_head rcu; /* This must be first */
270 atomic_t usage;
271 unsigned long hash_key;
272 struct hlist_node hash_link;
273 struct rxrpc_local *local;
David Howellsf66d7492016-04-04 14:00:34 +0100274 struct hlist_head error_targets; /* targets for net error distribution */
275 struct work_struct error_distributor;
David Howellsaa390bb2016-06-17 10:06:56 +0100276 struct rb_root service_conns; /* Service connections */
David Howells8496af52016-07-01 07:51:50 +0100277 seqlock_t service_conn_lock;
David Howells17926a72007-04-26 15:48:28 -0700278 spinlock_t lock; /* access lock */
Eric Dumazet95c96172012-04-15 05:58:06 +0000279 unsigned int if_mtu; /* interface MTU for this peer */
280 unsigned int mtu; /* network MTU for this peer */
281 unsigned int maxdata; /* data size (MTU - hdrsize) */
David Howells17926a72007-04-26 15:48:28 -0700282 unsigned short hdrsize; /* header size (IP + UDP + RxRPC) */
283 int debug_id; /* debug ID for printks */
David Howellsf66d7492016-04-04 14:00:34 +0100284 int error_report; /* Net (+0) or local (+1000000) to distribute */
285#define RXRPC_LOCAL_ERROR_OFFSET 1000000
David Howells17926a72007-04-26 15:48:28 -0700286 struct sockaddr_rxrpc srx; /* remote address */
287
288 /* calculated RTT cache */
289#define RXRPC_RTT_CACHE_SIZE 32
David Howells0d4b1032016-09-22 00:29:31 +0100290 ktime_t rtt_last_req; /* Time of last RTT request */
David Howellscf1a6472016-09-22 00:41:53 +0100291 u64 rtt; /* Current RTT estimate (in nS) */
292 u64 rtt_sum; /* Sum of cache contents */
293 u64 rtt_cache[RXRPC_RTT_CACHE_SIZE]; /* Determined RTT cache */
294 u8 rtt_cursor; /* next entry at which to insert */
295 u8 rtt_usage; /* amount of cache actually used */
David Howells17926a72007-04-26 15:48:28 -0700296};
297
298/*
David Howells19ffa012016-04-04 14:00:36 +0100299 * Keys for matching a connection.
300 */
301struct rxrpc_conn_proto {
David Howellse8d70ce2016-06-30 12:16:21 +0100302 union {
303 struct {
304 u32 epoch; /* epoch of this connection */
305 u32 cid; /* connection ID */
306 };
307 u64 index_key;
David Howells19ffa012016-04-04 14:00:36 +0100308 };
309};
310
311struct rxrpc_conn_parameters {
312 struct rxrpc_local *local; /* Representation of local endpoint */
313 struct rxrpc_peer *peer; /* Remote endpoint */
314 struct key *key; /* Security details */
315 bool exclusive; /* T if conn is exclusive */
316 u16 service_id; /* Service ID for this connection */
317 u32 security_level; /* Security level selected */
318};
319
320/*
David Howellsbba304d2016-06-27 10:32:02 +0100321 * Bits in the connection flags.
322 */
323enum rxrpc_conn_flag {
324 RXRPC_CONN_HAS_IDR, /* Has a client conn ID assigned */
David Howells001c1122016-06-30 10:45:22 +0100325 RXRPC_CONN_IN_SERVICE_CONNS, /* Conn is in peer->service_conns */
326 RXRPC_CONN_IN_CLIENT_CONNS, /* Conn is in local->client_conns */
David Howells45025bc2016-08-24 07:30:52 +0100327 RXRPC_CONN_EXPOSED, /* Conn has extra ref for exposure */
328 RXRPC_CONN_DONT_REUSE, /* Don't reuse this connection */
329 RXRPC_CONN_COUNTED, /* Counted by rxrpc_nr_client_conns */
David Howellsbba304d2016-06-27 10:32:02 +0100330};
331
332/*
333 * Events that can be raised upon a connection.
334 */
335enum rxrpc_conn_event {
336 RXRPC_CONN_EV_CHALLENGE, /* Send challenge packet */
337};
338
339/*
David Howells45025bc2016-08-24 07:30:52 +0100340 * The connection cache state.
341 */
342enum rxrpc_conn_cache_state {
343 RXRPC_CONN_CLIENT_INACTIVE, /* Conn is not yet listed */
344 RXRPC_CONN_CLIENT_WAITING, /* Conn is on wait list, waiting for capacity */
345 RXRPC_CONN_CLIENT_ACTIVE, /* Conn is on active list, doing calls */
346 RXRPC_CONN_CLIENT_CULLED, /* Conn is culled and delisted, doing calls */
347 RXRPC_CONN_CLIENT_IDLE, /* Conn is on idle list, doing mostly nothing */
David Howells363deea2016-09-17 10:49:14 +0100348 RXRPC_CONN__NR_CACHE_STATES
David Howells45025bc2016-08-24 07:30:52 +0100349};
350
351/*
David Howellsbba304d2016-06-27 10:32:02 +0100352 * The connection protocol state.
353 */
354enum rxrpc_conn_proto_state {
355 RXRPC_CONN_UNUSED, /* Connection not yet attempted */
356 RXRPC_CONN_CLIENT, /* Client connection */
David Howells00e90712016-09-08 11:10:12 +0100357 RXRPC_CONN_SERVICE_PREALLOC, /* Service connection preallocation */
David Howellsbba304d2016-06-27 10:32:02 +0100358 RXRPC_CONN_SERVICE_UNSECURED, /* Service unsecured connection */
359 RXRPC_CONN_SERVICE_CHALLENGING, /* Service challenging for security */
360 RXRPC_CONN_SERVICE, /* Service secured connection */
361 RXRPC_CONN_REMOTELY_ABORTED, /* Conn aborted by peer */
362 RXRPC_CONN_LOCALLY_ABORTED, /* Conn aborted locally */
David Howellsbba304d2016-06-27 10:32:02 +0100363 RXRPC_CONN__NR_STATES
364};
365
366/*
David Howells17926a72007-04-26 15:48:28 -0700367 * RxRPC connection definition
David Howellsaa390bb2016-06-17 10:06:56 +0100368 * - matched by { local, peer, epoch, conn_id, direction }
David Howells17926a72007-04-26 15:48:28 -0700369 * - each connection can only handle four simultaneous calls
370 */
371struct rxrpc_connection {
David Howells19ffa012016-04-04 14:00:36 +0100372 struct rxrpc_conn_proto proto;
373 struct rxrpc_conn_parameters params;
374
David Howells45025bc2016-08-24 07:30:52 +0100375 atomic_t usage;
376 struct rcu_head rcu;
377 struct list_head cache_link;
David Howellsa1399f82016-06-27 14:39:44 +0100378
David Howells45025bc2016-08-24 07:30:52 +0100379 spinlock_t channel_lock;
380 unsigned char active_chans; /* Mask of active channels */
381#define RXRPC_ACTIVE_CHANS_MASK ((1 << RXRPC_MAXCALLS) - 1)
382 struct list_head waiting_calls; /* Calls waiting for channels */
David Howellsa1399f82016-06-27 14:39:44 +0100383 struct rxrpc_channel {
384 struct rxrpc_call __rcu *call; /* Active call */
385 u32 call_id; /* ID of current call */
386 u32 call_counter; /* Call ID counter */
387 u32 last_call; /* ID of last call */
David Howells18bfeba2016-08-23 15:27:25 +0100388 u8 last_type; /* Type of last packet */
David Howells18bfeba2016-08-23 15:27:25 +0100389 union {
390 u32 last_seq;
391 u32 last_abort;
392 };
David Howellsa1399f82016-06-27 14:39:44 +0100393 } channels[RXRPC_MAXCALLS];
David Howells999b69f2016-06-17 15:42:35 +0100394
David Howells17926a72007-04-26 15:48:28 -0700395 struct work_struct processor; /* connection event processor */
David Howells999b69f2016-06-17 15:42:35 +0100396 union {
397 struct rb_node client_node; /* Node in local->client_conns */
David Howellsaa390bb2016-06-17 10:06:56 +0100398 struct rb_node service_node; /* Node in peer->service_conns */
David Howells999b69f2016-06-17 15:42:35 +0100399 };
David Howells4d028b22016-08-24 07:30:52 +0100400 struct list_head proc_link; /* link in procfs list */
David Howells17926a72007-04-26 15:48:28 -0700401 struct list_head link; /* link in master connection list */
David Howells17926a72007-04-26 15:48:28 -0700402 struct sk_buff_head rx_queue; /* received conn-level packets */
David Howells648af7f2016-04-07 17:23:51 +0100403 const struct rxrpc_security *security; /* applied security module */
David Howells17926a72007-04-26 15:48:28 -0700404 struct key *server_key; /* security for this service */
Herbert Xu1afe5932016-01-24 21:19:01 +0800405 struct crypto_skcipher *cipher; /* encryption handle */
David Howells17926a72007-04-26 15:48:28 -0700406 struct rxrpc_crypt csum_iv; /* packet checksum base */
David Howells4a3388c2016-04-04 14:00:37 +0100407 unsigned long flags;
David Howells17926a72007-04-26 15:48:28 -0700408 unsigned long events;
David Howellsf51b4482016-08-23 15:27:24 +0100409 unsigned long idle_timestamp; /* Time at which last became idle */
David Howells17926a72007-04-26 15:48:28 -0700410 spinlock_t state_lock; /* state-change lock */
David Howellscf132582016-09-08 11:10:11 +0100411 enum rxrpc_conn_cache_state cache_state;
412 enum rxrpc_conn_proto_state state; /* current state of connection */
David Howellsdc44b3a2016-04-07 17:23:30 +0100413 u32 local_abort; /* local abort code */
414 u32 remote_abort; /* remote abort code */
David Howells17926a72007-04-26 15:48:28 -0700415 int debug_id; /* debug ID for printks */
David Howells17926a72007-04-26 15:48:28 -0700416 atomic_t serial; /* packet serial number counter */
David Howells563ea7d2016-08-23 15:27:25 +0100417 unsigned int hi_serial; /* highest serial number received */
David Howells17926a72007-04-26 15:48:28 -0700418 u32 security_nonce; /* response re-use preventer */
David Howells68d6d1a2017-06-05 14:30:49 +0100419 u16 service_id; /* Service ID, possibly upgraded */
David Howells5a924b82016-09-22 00:29:31 +0100420 u8 size_align; /* data size alignment (for security) */
421 u8 security_size; /* security header size */
David Howells17926a72007-04-26 15:48:28 -0700422 u8 security_ix; /* security type */
David Howells17926a72007-04-26 15:48:28 -0700423 u8 out_clientflag; /* RXRPC_CLIENT_INITIATED if we are client */
424};
425
426/*
David Howells5b8848d2016-03-04 15:53:46 +0000427 * Flags in call->flags.
428 */
429enum rxrpc_call_flag {
430 RXRPC_CALL_RELEASED, /* call has been released - no more message to userspace */
David Howells5b8848d2016-03-04 15:53:46 +0000431 RXRPC_CALL_HAS_USERID, /* has a user ID attached */
David Howellsdabe5a72016-08-23 15:27:24 +0100432 RXRPC_CALL_IS_SERVICE, /* Call is service call */
David Howells45025bc2016-08-24 07:30:52 +0100433 RXRPC_CALL_EXPOSED, /* The call was exposed to the world */
David Howells248f2192016-09-08 11:10:12 +0100434 RXRPC_CALL_RX_LAST, /* Received the last packet (at rxtx_top) */
435 RXRPC_CALL_TX_LAST, /* Last packet in Tx buffer (at rxtx_top) */
David Howellsa5af7e12016-10-06 08:11:49 +0100436 RXRPC_CALL_SEND_PING, /* A ping will need to be sent */
David Howells8e831342016-09-22 00:29:31 +0100437 RXRPC_CALL_PINGING, /* Ping in process */
David Howells57494342016-09-24 18:05:27 +0100438 RXRPC_CALL_RETRANS_TIMEOUT, /* Retransmission due to timeout occurred */
David Howells5b8848d2016-03-04 15:53:46 +0000439};
440
441/*
442 * Events that can be raised on a call.
443 */
444enum rxrpc_call_event {
David Howells4c198ad2016-03-04 15:53:46 +0000445 RXRPC_CALL_EV_ACK, /* need to generate ACK */
David Howells4c198ad2016-03-04 15:53:46 +0000446 RXRPC_CALL_EV_ABORT, /* need to generate abort */
David Howells248f2192016-09-08 11:10:12 +0100447 RXRPC_CALL_EV_TIMER, /* Timer expired */
David Howells4c198ad2016-03-04 15:53:46 +0000448 RXRPC_CALL_EV_RESEND, /* Tx resend required */
David Howellsa5af7e12016-10-06 08:11:49 +0100449 RXRPC_CALL_EV_PING, /* Ping send required */
David Howells5b8848d2016-03-04 15:53:46 +0000450};
451
452/*
453 * The states that a call can be in.
454 */
455enum rxrpc_call_state {
David Howells999b69f2016-06-17 15:42:35 +0100456 RXRPC_CALL_UNINITIALISED,
457 RXRPC_CALL_CLIENT_AWAIT_CONN, /* - client waiting for connection to become available */
David Howells5b8848d2016-03-04 15:53:46 +0000458 RXRPC_CALL_CLIENT_SEND_REQUEST, /* - client sending request phase */
459 RXRPC_CALL_CLIENT_AWAIT_REPLY, /* - client awaiting reply */
460 RXRPC_CALL_CLIENT_RECV_REPLY, /* - client receiving reply phase */
David Howells00e90712016-09-08 11:10:12 +0100461 RXRPC_CALL_SERVER_PREALLOC, /* - service preallocation */
David Howells5b8848d2016-03-04 15:53:46 +0000462 RXRPC_CALL_SERVER_SECURING, /* - server securing request connection */
463 RXRPC_CALL_SERVER_ACCEPTING, /* - server accepting request */
464 RXRPC_CALL_SERVER_RECV_REQUEST, /* - server receiving request */
465 RXRPC_CALL_SERVER_ACK_REQUEST, /* - server pending ACK of request */
466 RXRPC_CALL_SERVER_SEND_REPLY, /* - server sending reply */
467 RXRPC_CALL_SERVER_AWAIT_ACK, /* - server awaiting final ACK */
David Howellsf5c17aa2016-08-30 09:49:28 +0100468 RXRPC_CALL_COMPLETE, /* - call complete */
David Howellsf5c17aa2016-08-30 09:49:28 +0100469 NR__RXRPC_CALL_STATES
470};
471
472/*
473 * Call completion condition (state == RXRPC_CALL_COMPLETE).
474 */
475enum rxrpc_call_completion {
476 RXRPC_CALL_SUCCEEDED, /* - Normal termination */
David Howells5b8848d2016-03-04 15:53:46 +0000477 RXRPC_CALL_REMOTELY_ABORTED, /* - call aborted by peer */
478 RXRPC_CALL_LOCALLY_ABORTED, /* - call aborted locally on error or close */
David Howellsf5c17aa2016-08-30 09:49:28 +0100479 RXRPC_CALL_LOCAL_ERROR, /* - call failed due to local error */
David Howells5b8848d2016-03-04 15:53:46 +0000480 RXRPC_CALL_NETWORK_ERROR, /* - call terminated by network error */
David Howellsf5c17aa2016-08-30 09:49:28 +0100481 NR__RXRPC_CALL_COMPLETIONS
David Howells5b8848d2016-03-04 15:53:46 +0000482};
483
484/*
David Howells57494342016-09-24 18:05:27 +0100485 * Call Tx congestion management modes.
486 */
487enum rxrpc_congest_mode {
488 RXRPC_CALL_SLOW_START,
489 RXRPC_CALL_CONGEST_AVOIDANCE,
490 RXRPC_CALL_PACKET_LOSS,
491 RXRPC_CALL_FAST_RETRANSMIT,
492 NR__RXRPC_CONGEST_MODES
493};
494
495/*
David Howells17926a72007-04-26 15:48:28 -0700496 * RxRPC call definition
497 * - matched by { connection, call_id }
498 */
499struct rxrpc_call {
David Howellsdee46362016-06-27 17:11:19 +0100500 struct rcu_head rcu;
David Howells17926a72007-04-26 15:48:28 -0700501 struct rxrpc_connection *conn; /* connection carrying call */
David Howellsdf5d8bf2016-08-24 14:31:43 +0100502 struct rxrpc_peer *peer; /* Peer record for remote address */
David Howells8d94aa32016-09-07 09:19:31 +0100503 struct rxrpc_sock __rcu *socket; /* socket responsible */
David Howells540b1c42017-02-27 15:43:06 +0000504 struct mutex user_mutex; /* User access mutex */
David Howellsdf0adc72016-09-26 22:12:49 +0100505 ktime_t ack_at; /* When deferred ACK needs to happen */
506 ktime_t resend_at; /* When next resend needs to happen */
David Howellsa5af7e12016-10-06 08:11:49 +0100507 ktime_t ping_at; /* When next to send a ping */
David Howellsdf0adc72016-09-26 22:12:49 +0100508 ktime_t expire_at; /* When the call times out */
David Howells248f2192016-09-08 11:10:12 +0100509 struct timer_list timer; /* Combined event timer */
510 struct work_struct processor; /* Event processor */
David Howellsd0016482016-08-30 20:42:14 +0100511 rxrpc_notify_rx_t notify_rx; /* kernel service Rx notification function */
David Howells17926a72007-04-26 15:48:28 -0700512 struct list_head link; /* link in master call list */
David Howells45025bc2016-08-24 07:30:52 +0100513 struct list_head chan_wait_link; /* Link in conn->waiting_calls */
David Howellsf66d7492016-04-04 14:00:34 +0100514 struct hlist_node error_link; /* link in error distribution list */
David Howells248f2192016-09-08 11:10:12 +0100515 struct list_head accept_link; /* Link in rx->acceptq */
516 struct list_head recvmsg_link; /* Link in rx->recvmsg_q */
517 struct list_head sock_link; /* Link in rx->sock_calls */
518 struct rb_node sock_node; /* Node in rx->calls */
David Howells17926a72007-04-26 15:48:28 -0700519 struct sk_buff *tx_pending; /* Tx socket buffer being filled */
David Howells45025bc2016-08-24 07:30:52 +0100520 wait_queue_head_t waitq; /* Wait queue for channel or Tx */
Herbert Xua2636292016-06-26 14:55:24 -0700521 __be32 crypto_buf[2]; /* Temporary packet crypto buffer */
David Howells17926a72007-04-26 15:48:28 -0700522 unsigned long user_call_ID; /* user-defined call ID */
David Howells17926a72007-04-26 15:48:28 -0700523 unsigned long flags;
David Howells17926a72007-04-26 15:48:28 -0700524 unsigned long events;
David Howells17926a72007-04-26 15:48:28 -0700525 spinlock_t lock;
526 rwlock_t state_lock; /* lock for state transition */
David Howellsf5c17aa2016-08-30 09:49:28 +0100527 u32 abort_code; /* Local/remote abort code */
528 int error; /* Local error incurred */
David Howellscf132582016-09-08 11:10:11 +0100529 enum rxrpc_call_state state; /* current state of call */
530 enum rxrpc_call_completion completion; /* Call completion condition */
David Howells17926a72007-04-26 15:48:28 -0700531 atomic_t usage;
David Howellsdabe5a72016-08-23 15:27:24 +0100532 u16 service_id; /* service ID */
David Howells278ac0c2016-09-07 15:19:25 +0100533 u8 security_ix; /* Security type */
David Howellsdabe5a72016-08-23 15:27:24 +0100534 u32 call_id; /* call ID on connection */
535 u32 cid; /* connection ID plus channel index */
536 int debug_id; /* debug ID for printks */
David Howells8e831342016-09-22 00:29:31 +0100537 unsigned short rx_pkt_offset; /* Current recvmsg packet offset */
538 unsigned short rx_pkt_len; /* Current recvmsg packet len */
David Howells17926a72007-04-26 15:48:28 -0700539
David Howells248f2192016-09-08 11:10:12 +0100540 /* Rx/Tx circular buffer, depending on phase.
541 *
542 * In the Rx phase, packets are annotated with 0 or the number of the
543 * segment of a jumbo packet each buffer refers to. There can be up to
544 * 47 segments in a maximum-size UDP packet.
545 *
546 * In the Tx phase, packets are annotated with which buffers have been
547 * acked.
548 */
549#define RXRPC_RXTX_BUFF_SIZE 64
550#define RXRPC_RXTX_BUFF_MASK (RXRPC_RXTX_BUFF_SIZE - 1)
David Howells75e42122016-09-13 22:36:22 +0100551#define RXRPC_INIT_RX_WINDOW_SIZE 32
David Howells248f2192016-09-08 11:10:12 +0100552 struct sk_buff **rxtx_buffer;
553 u8 *rxtx_annotations;
554#define RXRPC_TX_ANNO_ACK 0
555#define RXRPC_TX_ANNO_UNACK 1
556#define RXRPC_TX_ANNO_NAK 2
557#define RXRPC_TX_ANNO_RETRANS 3
David Howellsf07373e2016-09-22 00:29:32 +0100558#define RXRPC_TX_ANNO_MASK 0x03
David Howells70790db2016-09-23 12:39:22 +0100559#define RXRPC_TX_ANNO_LAST 0x04
560#define RXRPC_TX_ANNO_RESENT 0x08
561
David Howells248f2192016-09-08 11:10:12 +0100562#define RXRPC_RX_ANNO_JUMBO 0x3f /* Jumbo subpacket number + 1 if not zero */
563#define RXRPC_RX_ANNO_JLAST 0x40 /* Set if last element of a jumbo packet */
564#define RXRPC_RX_ANNO_VERIFIED 0x80 /* Set if verified and decrypted */
565 rxrpc_seq_t tx_hard_ack; /* Dead slot in buffer; the first transmitted but
566 * not hard-ACK'd packet follows this.
David Howells17926a72007-04-26 15:48:28 -0700567 */
David Howells248f2192016-09-08 11:10:12 +0100568 rxrpc_seq_t tx_top; /* Highest Tx slot allocated. */
David Howells57494342016-09-24 18:05:27 +0100569
570 /* TCP-style slow-start congestion control [RFC5681]. Since the SMSS
571 * is fixed, we keep these numbers in terms of segments (ie. DATA
572 * packets) rather than bytes.
573 */
574#define RXRPC_TX_SMSS RXRPC_JUMBO_DATALEN
575 u8 cong_cwnd; /* Congestion window size */
576 u8 cong_extra; /* Extra to send for congestion management */
577 u8 cong_ssthresh; /* Slow-start threshold */
578 enum rxrpc_congest_mode cong_mode:8; /* Congestion management mode */
579 u8 cong_dup_acks; /* Count of ACKs showing missing packets */
580 u8 cong_cumul_acks; /* Cumulative ACK count */
581 ktime_t cong_tstamp; /* Last time cwnd was changed */
582
David Howells248f2192016-09-08 11:10:12 +0100583 rxrpc_seq_t rx_hard_ack; /* Dead slot in buffer; the first received but not
584 * consumed packet follows this.
585 */
586 rxrpc_seq_t rx_top; /* Highest Rx slot allocated. */
587 rxrpc_seq_t rx_expect_next; /* Expected next packet sequence number */
588 u8 rx_winsize; /* Size of Rx window */
589 u8 tx_winsize; /* Maximum size of Tx window */
David Howells71f3ca42016-09-17 10:49:14 +0100590 bool tx_phase; /* T if transmission phase, F if receive phase */
David Howells75e42122016-09-13 22:36:22 +0100591 u8 nr_jumbo_bad; /* Number of jumbo dups/exceeds-windows */
David Howells17926a72007-04-26 15:48:28 -0700592
593 /* receive-phase ACK management */
David Howells4e36a952009-09-16 00:01:13 -0700594 u8 ackr_reason; /* reason to ACK */
David Howells563ea7d2016-08-23 15:27:25 +0100595 u16 ackr_skew; /* skew on packet being ACK'd */
David Howells0d12f8a2016-03-04 15:53:46 +0000596 rxrpc_serial_t ackr_serial; /* serial of packet being ACK'd */
David Howells248f2192016-09-08 11:10:12 +0100597 rxrpc_seq_t ackr_prev_seq; /* previous sequence number received */
David Howells805b21b2016-09-24 18:05:26 +0100598 rxrpc_seq_t ackr_consumed; /* Highest packet shown consumed */
599 rxrpc_seq_t ackr_seen; /* Highest packet shown seen */
David Howellsa5af7e12016-10-06 08:11:49 +0100600
601 /* ping management */
602 rxrpc_serial_t ping_serial; /* Last ping sent */
603 ktime_t ping_time; /* Time last ping sent */
David Howells17926a72007-04-26 15:48:28 -0700604
David Howells248f2192016-09-08 11:10:12 +0100605 /* transmission-phase ACK management */
David Howells57494342016-09-24 18:05:27 +0100606 ktime_t acks_latest_ts; /* Timestamp of latest ACK received */
David Howells248f2192016-09-08 11:10:12 +0100607 rxrpc_serial_t acks_latest; /* serial number of latest ACK received */
David Howells31a1b982016-09-24 18:05:26 +0100608 rxrpc_seq_t acks_lowest_nak; /* Lowest NACK in the buffer (or ==tx_hard_ack) */
609};
610
611/*
David Howells57494342016-09-24 18:05:27 +0100612 * Summary of a new ACK and the changes it made to the Tx buffer packet states.
David Howells31a1b982016-09-24 18:05:26 +0100613 */
614struct rxrpc_ack_summary {
615 u8 ack_reason;
616 u8 nr_acks; /* Number of ACKs in packet */
617 u8 nr_nacks; /* Number of NACKs in packet */
618 u8 nr_new_acks; /* Number of new ACKs in packet */
619 u8 nr_new_nacks; /* Number of new NACKs in packet */
620 u8 nr_rot_new_acks; /* Number of rotated new ACKs */
621 bool new_low_nack; /* T if new low NACK found */
David Howells57494342016-09-24 18:05:27 +0100622 bool retrans_timeo; /* T if reTx due to timeout happened */
623 u8 flight_size; /* Number of unreceived transmissions */
624 /* Place to stash values for tracing */
625 enum rxrpc_congest_mode mode:8;
626 u8 cwnd;
627 u8 ssthresh;
628 u8 dup_acks;
629 u8 cumulative_acks;
David Howells17926a72007-04-26 15:48:28 -0700630};
631
David Howellsdf844fd2016-08-23 15:27:24 +0100632#include <trace/events/rxrpc.h>
633
David Howells17926a72007-04-26 15:48:28 -0700634/*
David Howells651350d2007-04-26 15:50:17 -0700635 * af_rxrpc.c
David Howells17926a72007-04-26 15:48:28 -0700636 */
David Howells71f3ca42016-09-17 10:49:14 +0100637extern atomic_t rxrpc_n_tx_skbs, rxrpc_n_rx_skbs;
David Howells651350d2007-04-26 15:50:17 -0700638extern atomic_t rxrpc_debug_id;
639extern struct workqueue_struct *rxrpc_workqueue;
David Howells17926a72007-04-26 15:48:28 -0700640
641/*
David Howells0d81a512016-06-13 13:30:30 +0100642 * call_accept.c
David Howells17926a72007-04-26 15:48:28 -0700643 */
David Howells00e90712016-09-08 11:10:12 +0100644int rxrpc_service_prealloc(struct rxrpc_sock *, gfp_t);
645void rxrpc_discard_prealloc(struct rxrpc_sock *);
David Howells248f2192016-09-08 11:10:12 +0100646struct rxrpc_call *rxrpc_new_incoming_call(struct rxrpc_local *,
647 struct rxrpc_connection *,
648 struct sk_buff *);
David Howells4f95dd72016-04-04 14:00:35 +0100649void rxrpc_accept_incoming_calls(struct rxrpc_local *);
David Howellsd0016482016-08-30 20:42:14 +0100650struct rxrpc_call *rxrpc_accept_call(struct rxrpc_sock *, unsigned long,
651 rxrpc_notify_rx_t);
Joe Perchesc1b12032013-10-18 13:48:25 -0700652int rxrpc_reject_call(struct rxrpc_sock *);
David Howells17926a72007-04-26 15:48:28 -0700653
654/*
David Howells0d81a512016-06-13 13:30:30 +0100655 * call_event.c
David Howells17926a72007-04-26 15:48:28 -0700656 */
David Howells9749fd22016-10-06 08:11:50 +0100657void __rxrpc_set_timer(struct rxrpc_call *, enum rxrpc_timer_trace, ktime_t);
David Howellsdf0adc72016-09-26 22:12:49 +0100658void rxrpc_set_timer(struct rxrpc_call *, enum rxrpc_timer_trace, ktime_t);
David Howells9c7ad432016-09-23 13:50:40 +0100659void rxrpc_propose_ACK(struct rxrpc_call *, u8, u16, u32, bool, bool,
660 enum rxrpc_propose_ack_trace);
Joe Perchesc1b12032013-10-18 13:48:25 -0700661void rxrpc_process_call(struct work_struct *);
David Howells17926a72007-04-26 15:48:28 -0700662
663/*
David Howells0d81a512016-06-13 13:30:30 +0100664 * call_object.c
David Howells17926a72007-04-26 15:48:28 -0700665 */
David Howellsf5c17aa2016-08-30 09:49:28 +0100666extern const char *const rxrpc_call_states[];
667extern const char *const rxrpc_call_completions[];
David Howellsdad8aff2016-03-09 23:22:56 +0000668extern unsigned int rxrpc_max_call_lifetime;
David Howells17926a72007-04-26 15:48:28 -0700669extern struct kmem_cache *rxrpc_call_jar;
David Howells17926a72007-04-26 15:48:28 -0700670
David Howells2341e072016-06-09 23:02:51 +0100671struct rxrpc_call *rxrpc_find_call_by_user_ID(struct rxrpc_sock *, unsigned long);
David Howells00e90712016-09-08 11:10:12 +0100672struct rxrpc_call *rxrpc_alloc_call(gfp_t);
David Howells2341e072016-06-09 23:02:51 +0100673struct rxrpc_call *rxrpc_new_client_call(struct rxrpc_sock *,
David Howells19ffa012016-04-04 14:00:36 +0100674 struct rxrpc_conn_parameters *,
David Howells999b69f2016-06-17 15:42:35 +0100675 struct sockaddr_rxrpc *,
David Howells2341e072016-06-09 23:02:51 +0100676 unsigned long, gfp_t);
David Howells248f2192016-09-08 11:10:12 +0100677void rxrpc_incoming_call(struct rxrpc_sock *, struct rxrpc_call *,
678 struct sk_buff *);
David Howells8d94aa32016-09-07 09:19:31 +0100679void rxrpc_release_call(struct rxrpc_sock *, struct rxrpc_call *);
Joe Perchesc1b12032013-10-18 13:48:25 -0700680void rxrpc_release_calls_on_socket(struct rxrpc_sock *);
David Howells8d94aa32016-09-07 09:19:31 +0100681bool __rxrpc_queue_call(struct rxrpc_call *);
682bool rxrpc_queue_call(struct rxrpc_call *);
David Howellse34d4232016-08-30 09:49:29 +0100683void rxrpc_see_call(struct rxrpc_call *);
David Howellsfff724292016-09-07 14:34:21 +0100684void rxrpc_get_call(struct rxrpc_call *, enum rxrpc_call_trace);
685void rxrpc_put_call(struct rxrpc_call *, enum rxrpc_call_trace);
David Howells00e90712016-09-08 11:10:12 +0100686void rxrpc_cleanup_call(struct rxrpc_call *);
David Howells2baec2c2017-05-24 17:02:32 +0100687void rxrpc_destroy_all_calls(struct rxrpc_net *);
David Howells17926a72007-04-26 15:48:28 -0700688
David Howellsdabe5a72016-08-23 15:27:24 +0100689static inline bool rxrpc_is_service_call(const struct rxrpc_call *call)
690{
691 return test_bit(RXRPC_CALL_IS_SERVICE, &call->flags);
692}
693
694static inline bool rxrpc_is_client_call(const struct rxrpc_call *call)
695{
696 return !rxrpc_is_service_call(call);
697}
698
David Howells17926a72007-04-26 15:48:28 -0700699/*
David Howellsf5c17aa2016-08-30 09:49:28 +0100700 * Transition a call to the complete state.
701 */
702static inline bool __rxrpc_set_call_completion(struct rxrpc_call *call,
703 enum rxrpc_call_completion compl,
704 u32 abort_code,
705 int error)
706{
707 if (call->state < RXRPC_CALL_COMPLETE) {
708 call->abort_code = abort_code;
709 call->error = error;
710 call->completion = compl,
711 call->state = RXRPC_CALL_COMPLETE;
David Howellsc0d058c2016-09-23 12:39:23 +0100712 wake_up(&call->waitq);
David Howellsf5c17aa2016-08-30 09:49:28 +0100713 return true;
714 }
715 return false;
716}
717
718static inline bool rxrpc_set_call_completion(struct rxrpc_call *call,
719 enum rxrpc_call_completion compl,
720 u32 abort_code,
721 int error)
722{
David Howellse8d6bbb2016-09-07 16:34:12 +0100723 bool ret;
David Howellsf5c17aa2016-08-30 09:49:28 +0100724
725 write_lock_bh(&call->state_lock);
726 ret = __rxrpc_set_call_completion(call, compl, abort_code, error);
727 write_unlock_bh(&call->state_lock);
728 return ret;
729}
730
731/*
732 * Record that a call successfully completed.
733 */
David Howellse8d6bbb2016-09-07 16:34:12 +0100734static inline bool __rxrpc_call_completed(struct rxrpc_call *call)
David Howellsf5c17aa2016-08-30 09:49:28 +0100735{
David Howellse8d6bbb2016-09-07 16:34:12 +0100736 return __rxrpc_set_call_completion(call, RXRPC_CALL_SUCCEEDED, 0, 0);
David Howellsf5c17aa2016-08-30 09:49:28 +0100737}
738
David Howellse8d6bbb2016-09-07 16:34:12 +0100739static inline bool rxrpc_call_completed(struct rxrpc_call *call)
David Howellsf5c17aa2016-08-30 09:49:28 +0100740{
David Howellse8d6bbb2016-09-07 16:34:12 +0100741 bool ret;
742
David Howellsf5c17aa2016-08-30 09:49:28 +0100743 write_lock_bh(&call->state_lock);
David Howellse8d6bbb2016-09-07 16:34:12 +0100744 ret = __rxrpc_call_completed(call);
David Howellsf5c17aa2016-08-30 09:49:28 +0100745 write_unlock_bh(&call->state_lock);
David Howellse8d6bbb2016-09-07 16:34:12 +0100746 return ret;
David Howellsf5c17aa2016-08-30 09:49:28 +0100747}
748
749/*
750 * Record that a call is locally aborted.
751 */
David Howells5a429762016-09-06 22:19:51 +0100752static inline bool __rxrpc_abort_call(const char *why, struct rxrpc_call *call,
753 rxrpc_seq_t seq,
David Howellsf5c17aa2016-08-30 09:49:28 +0100754 u32 abort_code, int error)
755{
David Howells5a429762016-09-06 22:19:51 +0100756 trace_rxrpc_abort(why, call->cid, call->call_id, seq,
757 abort_code, error);
David Howells248f2192016-09-08 11:10:12 +0100758 return __rxrpc_set_call_completion(call, RXRPC_CALL_LOCALLY_ABORTED,
759 abort_code, error);
David Howellsf5c17aa2016-08-30 09:49:28 +0100760}
761
David Howells5a429762016-09-06 22:19:51 +0100762static inline bool rxrpc_abort_call(const char *why, struct rxrpc_call *call,
763 rxrpc_seq_t seq, u32 abort_code, int error)
David Howellsf5c17aa2016-08-30 09:49:28 +0100764{
765 bool ret;
766
767 write_lock_bh(&call->state_lock);
David Howells5a429762016-09-06 22:19:51 +0100768 ret = __rxrpc_abort_call(why, call, seq, abort_code, error);
David Howellsf5c17aa2016-08-30 09:49:28 +0100769 write_unlock_bh(&call->state_lock);
770 return ret;
771}
772
773/*
David Howellsfb46f6e2017-04-06 10:12:00 +0100774 * Abort a call due to a protocol error.
775 */
776static inline bool __rxrpc_abort_eproto(struct rxrpc_call *call,
777 struct sk_buff *skb,
778 const char *eproto_why,
779 const char *why,
780 u32 abort_code)
781{
782 struct rxrpc_skb_priv *sp = rxrpc_skb(skb);
783
784 trace_rxrpc_rx_eproto(call, sp->hdr.serial, eproto_why);
785 return rxrpc_abort_call(why, call, sp->hdr.seq, abort_code, -EPROTO);
786}
787
788#define rxrpc_abort_eproto(call, skb, eproto_why, abort_why, abort_code) \
789 __rxrpc_abort_eproto((call), (skb), tracepoint_string(eproto_why), \
790 (abort_why), (abort_code))
791
792/*
David Howells4a3388c2016-04-04 14:00:37 +0100793 * conn_client.c
794 */
David Howells45025bc2016-08-24 07:30:52 +0100795extern unsigned int rxrpc_max_client_connections;
796extern unsigned int rxrpc_reap_client_connections;
797extern unsigned int rxrpc_conn_idle_client_expiry;
798extern unsigned int rxrpc_conn_idle_client_fast_expiry;
David Howells4a3388c2016-04-04 14:00:37 +0100799extern struct idr rxrpc_client_conn_ids;
800
David Howellseb9b9d22016-06-27 10:32:02 +0100801void rxrpc_destroy_client_conn_ids(void);
David Howellsc6d2b8d2016-04-04 14:00:40 +0100802int rxrpc_connect_call(struct rxrpc_call *, struct rxrpc_conn_parameters *,
803 struct sockaddr_rxrpc *, gfp_t);
David Howells45025bc2016-08-24 07:30:52 +0100804void rxrpc_expose_client_call(struct rxrpc_call *);
805void rxrpc_disconnect_client_call(struct rxrpc_call *);
806void rxrpc_put_client_conn(struct rxrpc_connection *);
David Howells2baec2c2017-05-24 17:02:32 +0100807void rxrpc_discard_expired_client_conns(struct work_struct *);
808void rxrpc_destroy_all_client_connections(struct rxrpc_net *);
David Howells4a3388c2016-04-04 14:00:37 +0100809
810/*
David Howells0d81a512016-06-13 13:30:30 +0100811 * conn_event.c
812 */
813void rxrpc_process_connection(struct work_struct *);
David Howells0d81a512016-06-13 13:30:30 +0100814
815/*
816 * conn_object.c
David Howells17926a72007-04-26 15:48:28 -0700817 */
David Howellsdad8aff2016-03-09 23:22:56 +0000818extern unsigned int rxrpc_connection_expiry;
David Howells17926a72007-04-26 15:48:28 -0700819
David Howells8496af52016-07-01 07:51:50 +0100820int rxrpc_extract_addr_from_skb(struct sockaddr_rxrpc *, struct sk_buff *);
David Howellsc6d2b8d2016-04-04 14:00:40 +0100821struct rxrpc_connection *rxrpc_alloc_connection(gfp_t);
David Howells8496af52016-07-01 07:51:50 +0100822struct rxrpc_connection *rxrpc_find_connection_rcu(struct rxrpc_local *,
823 struct sk_buff *);
David Howells45025bc2016-08-24 07:30:52 +0100824void __rxrpc_disconnect_call(struct rxrpc_connection *, struct rxrpc_call *);
David Howells999b69f2016-06-17 15:42:35 +0100825void rxrpc_disconnect_call(struct rxrpc_call *);
David Howells45025bc2016-08-24 07:30:52 +0100826void rxrpc_kill_connection(struct rxrpc_connection *);
David Howells363deea2016-09-17 10:49:14 +0100827bool rxrpc_queue_conn(struct rxrpc_connection *);
828void rxrpc_see_connection(struct rxrpc_connection *);
829void rxrpc_get_connection(struct rxrpc_connection *);
830struct rxrpc_connection *rxrpc_get_connection_maybe(struct rxrpc_connection *);
831void rxrpc_put_service_conn(struct rxrpc_connection *);
David Howells2baec2c2017-05-24 17:02:32 +0100832void rxrpc_service_connection_reaper(struct work_struct *);
833void rxrpc_destroy_all_connections(struct rxrpc_net *);
David Howells17926a72007-04-26 15:48:28 -0700834
David Howells19ffa012016-04-04 14:00:36 +0100835static inline bool rxrpc_conn_is_client(const struct rxrpc_connection *conn)
836{
837 return conn->out_clientflag;
838}
839
840static inline bool rxrpc_conn_is_service(const struct rxrpc_connection *conn)
841{
David Howellse8d70ce2016-06-30 12:16:21 +0100842 return !rxrpc_conn_is_client(conn);
David Howells19ffa012016-04-04 14:00:36 +0100843}
844
David Howellsf51b4482016-08-23 15:27:24 +0100845static inline void rxrpc_put_connection(struct rxrpc_connection *conn)
846{
David Howells45025bc2016-08-24 07:30:52 +0100847 if (!conn)
848 return;
849
David Howells363deea2016-09-17 10:49:14 +0100850 if (rxrpc_conn_is_client(conn))
851 rxrpc_put_client_conn(conn);
852 else
853 rxrpc_put_service_conn(conn);
David Howells5acbee42016-06-27 10:32:02 +0100854}
855
David Howells17926a72007-04-26 15:48:28 -0700856/*
David Howells7877a4a2016-04-04 14:00:40 +0100857 * conn_service.c
858 */
David Howells8496af52016-07-01 07:51:50 +0100859struct rxrpc_connection *rxrpc_find_service_conn_rcu(struct rxrpc_peer *,
860 struct sk_buff *);
David Howells2baec2c2017-05-24 17:02:32 +0100861struct rxrpc_connection *rxrpc_prealloc_service_connection(struct rxrpc_net *, gfp_t);
David Howells248f2192016-09-08 11:10:12 +0100862void rxrpc_new_incoming_connection(struct rxrpc_connection *, struct sk_buff *);
David Howells001c1122016-06-30 10:45:22 +0100863void rxrpc_unpublish_service_conn(struct rxrpc_connection *);
David Howells7877a4a2016-04-04 14:00:40 +0100864
865/*
David Howells0d81a512016-06-13 13:30:30 +0100866 * input.c
David Howells17926a72007-04-26 15:48:28 -0700867 */
David S. Miller676d2362014-04-11 16:15:36 -0400868void rxrpc_data_ready(struct sock *);
David Howells17926a72007-04-26 15:48:28 -0700869
870/*
David Howells0d81a512016-06-13 13:30:30 +0100871 * insecure.c
David Howells17926a72007-04-26 15:48:28 -0700872 */
David Howells0d81a512016-06-13 13:30:30 +0100873extern const struct rxrpc_security rxrpc_no_security;
David Howells17926a72007-04-26 15:48:28 -0700874
875/*
David Howells0d81a512016-06-13 13:30:30 +0100876 * key.c
David Howells17926a72007-04-26 15:48:28 -0700877 */
878extern struct key_type key_type_rxrpc;
879extern struct key_type key_type_rxrpc_s;
880
Joe Perchesc1b12032013-10-18 13:48:25 -0700881int rxrpc_request_key(struct rxrpc_sock *, char __user *, int);
882int rxrpc_server_keyring(struct rxrpc_sock *, char __user *, int);
883int rxrpc_get_server_data_key(struct rxrpc_connection *, const void *, time_t,
884 u32);
David Howells17926a72007-04-26 15:48:28 -0700885
886/*
David Howells87563612016-04-04 14:00:34 +0100887 * local_event.c
888 */
David Howells4f95dd72016-04-04 14:00:35 +0100889extern void rxrpc_process_local_events(struct rxrpc_local *);
David Howells87563612016-04-04 14:00:34 +0100890
891/*
David Howells0d81a512016-06-13 13:30:30 +0100892 * local_object.c
David Howells17926a72007-04-26 15:48:28 -0700893 */
David Howells2baec2c2017-05-24 17:02:32 +0100894struct rxrpc_local *rxrpc_lookup_local(struct net *, const struct sockaddr_rxrpc *);
David Howells4f95dd72016-04-04 14:00:35 +0100895void __rxrpc_put_local(struct rxrpc_local *);
David Howells2baec2c2017-05-24 17:02:32 +0100896void rxrpc_destroy_all_locals(struct rxrpc_net *);
David Howellse0e4d822016-04-07 17:23:58 +0100897
David Howells4f95dd72016-04-04 14:00:35 +0100898static inline void rxrpc_get_local(struct rxrpc_local *local)
899{
900 atomic_inc(&local->usage);
901}
902
903static inline
904struct rxrpc_local *rxrpc_get_local_maybe(struct rxrpc_local *local)
905{
906 return atomic_inc_not_zero(&local->usage) ? local : NULL;
907}
908
909static inline void rxrpc_put_local(struct rxrpc_local *local)
910{
David Howells5627cc82016-04-04 14:00:38 +0100911 if (local && atomic_dec_and_test(&local->usage))
David Howells4f95dd72016-04-04 14:00:35 +0100912 __rxrpc_put_local(local);
913}
914
David Howells5acbee42016-06-27 10:32:02 +0100915static inline void rxrpc_queue_local(struct rxrpc_local *local)
916{
917 rxrpc_queue_work(&local->processor);
918}
919
David Howellse0e4d822016-04-07 17:23:58 +0100920/*
David Howells8e688d92016-04-07 17:23:16 +0100921 * misc.c
922 */
David Howells0e119b42016-06-10 22:30:37 +0100923extern unsigned int rxrpc_max_backlog __read_mostly;
David Howells8e688d92016-04-07 17:23:16 +0100924extern unsigned int rxrpc_requested_ack_delay;
925extern unsigned int rxrpc_soft_ack_delay;
926extern unsigned int rxrpc_idle_ack_delay;
927extern unsigned int rxrpc_rx_window_size;
928extern unsigned int rxrpc_rx_mtu;
929extern unsigned int rxrpc_rx_jumbo_max;
David Howells0b58b8a2016-09-02 22:39:45 +0100930extern unsigned int rxrpc_resend_timeout;
David Howells8e688d92016-04-07 17:23:16 +0100931
David Howells8e688d92016-04-07 17:23:16 +0100932extern const s8 rxrpc_ack_priority[];
933
David Howells8e688d92016-04-07 17:23:16 +0100934/*
David Howells2baec2c2017-05-24 17:02:32 +0100935 * net_ns.c
936 */
937extern unsigned int rxrpc_net_id;
938extern struct pernet_operations rxrpc_net_ops;
939
940static inline struct rxrpc_net *rxrpc_net(struct net *net)
941{
942 return net_generic(net, rxrpc_net_id);
943}
944
945/*
David Howells0d81a512016-06-13 13:30:30 +0100946 * output.c
947 */
David Howellsa5af7e12016-10-06 08:11:49 +0100948int rxrpc_send_ack_packet(struct rxrpc_call *, bool);
David Howells26cb02a2016-10-06 08:11:49 +0100949int rxrpc_send_abort_packet(struct rxrpc_call *);
David Howellsa1767072016-09-29 22:37:15 +0100950int rxrpc_send_data_packet(struct rxrpc_call *, struct sk_buff *, bool);
David Howells248f2192016-09-08 11:10:12 +0100951void rxrpc_reject_packets(struct rxrpc_local *);
David Howells0d81a512016-06-13 13:30:30 +0100952
953/*
David Howellsabe89ef2016-04-04 14:00:32 +0100954 * peer_event.c
David Howells0d81a512016-06-13 13:30:30 +0100955 */
David Howellsabe89ef2016-04-04 14:00:32 +0100956void rxrpc_error_report(struct sock *);
David Howellsf66d7492016-04-04 14:00:34 +0100957void rxrpc_peer_error_distributor(struct work_struct *);
David Howellscf1a6472016-09-22 00:41:53 +0100958void rxrpc_peer_add_rtt(struct rxrpc_call *, enum rxrpc_rtt_rx_trace,
959 rxrpc_serial_t, rxrpc_serial_t, ktime_t, ktime_t);
David Howells0d81a512016-06-13 13:30:30 +0100960
961/*
962 * peer_object.c
963 */
David Howellsbe6e6702016-04-04 14:00:32 +0100964struct rxrpc_peer *rxrpc_lookup_peer_rcu(struct rxrpc_local *,
965 const struct sockaddr_rxrpc *);
966struct rxrpc_peer *rxrpc_lookup_peer(struct rxrpc_local *,
967 struct sockaddr_rxrpc *, gfp_t);
968struct rxrpc_peer *rxrpc_alloc_peer(struct rxrpc_local *, gfp_t);
David Howells248f2192016-09-08 11:10:12 +0100969struct rxrpc_peer *rxrpc_lookup_incoming_peer(struct rxrpc_local *,
970 struct rxrpc_peer *);
David Howellsbe6e6702016-04-04 14:00:32 +0100971
David Howellsdf5d8bf2016-08-24 14:31:43 +0100972static inline struct rxrpc_peer *rxrpc_get_peer(struct rxrpc_peer *peer)
David Howellsbe6e6702016-04-04 14:00:32 +0100973{
974 atomic_inc(&peer->usage);
David Howellsdf5d8bf2016-08-24 14:31:43 +0100975 return peer;
David Howellsbe6e6702016-04-04 14:00:32 +0100976}
977
978static inline
979struct rxrpc_peer *rxrpc_get_peer_maybe(struct rxrpc_peer *peer)
980{
981 return atomic_inc_not_zero(&peer->usage) ? peer : NULL;
982}
983
984extern void __rxrpc_put_peer(struct rxrpc_peer *peer);
985static inline void rxrpc_put_peer(struct rxrpc_peer *peer)
986{
David Howells5627cc82016-04-04 14:00:38 +0100987 if (peer && atomic_dec_and_test(&peer->usage))
David Howellsbe6e6702016-04-04 14:00:32 +0100988 __rxrpc_put_peer(peer);
989}
David Howells0d81a512016-06-13 13:30:30 +0100990
991/*
992 * proc.c
993 */
David Howells0d81a512016-06-13 13:30:30 +0100994extern const struct file_operations rxrpc_call_seq_fops;
995extern const struct file_operations rxrpc_connection_seq_fops;
996
997/*
998 * recvmsg.c
999 */
David Howells248f2192016-09-08 11:10:12 +01001000void rxrpc_notify_socket(struct rxrpc_call *);
David Howells0d81a512016-06-13 13:30:30 +01001001int rxrpc_recvmsg(struct socket *, struct msghdr *, size_t, int);
1002
1003/*
David Howells648af7f2016-04-07 17:23:51 +01001004 * rxkad.c
1005 */
1006#ifdef CONFIG_RXKAD
1007extern const struct rxrpc_security rxkad;
1008#endif
1009
1010/*
David Howells0d81a512016-06-13 13:30:30 +01001011 * security.c
1012 */
1013int __init rxrpc_init_security(void);
1014void rxrpc_exit_security(void);
1015int rxrpc_init_client_conn_security(struct rxrpc_connection *);
1016int rxrpc_init_server_conn_security(struct rxrpc_connection *);
David Howells71a17de2016-09-07 14:43:39 +01001017
David Howells0b58b8a2016-09-02 22:39:45 +01001018/*
1019 * sendmsg.c
1020 */
1021int rxrpc_do_sendmsg(struct rxrpc_sock *, struct msghdr *, size_t);
David Howells0d81a512016-06-13 13:30:30 +01001022
1023/*
1024 * skbuff.c
1025 */
David Howellsd0016482016-08-30 20:42:14 +01001026void rxrpc_kernel_data_consumed(struct rxrpc_call *, struct sk_buff *);
David Howells0d81a512016-06-13 13:30:30 +01001027void rxrpc_packet_destructor(struct sk_buff *);
David Howells71f3ca42016-09-17 10:49:14 +01001028void rxrpc_new_skb(struct sk_buff *, enum rxrpc_skb_trace);
1029void rxrpc_see_skb(struct sk_buff *, enum rxrpc_skb_trace);
1030void rxrpc_get_skb(struct sk_buff *, enum rxrpc_skb_trace);
1031void rxrpc_free_skb(struct sk_buff *, enum rxrpc_skb_trace);
1032void rxrpc_lose_skb(struct sk_buff *, enum rxrpc_skb_trace);
David Howellsdf844fd2016-08-23 15:27:24 +01001033void rxrpc_purge_queue(struct sk_buff_head *);
David Howells0d81a512016-06-13 13:30:30 +01001034
1035/*
David Howells5873c082014-02-07 18:58:44 +00001036 * sysctl.c
1037 */
1038#ifdef CONFIG_SYSCTL
1039extern int __init rxrpc_sysctl_init(void);
1040extern void rxrpc_sysctl_exit(void);
1041#else
1042static inline int __init rxrpc_sysctl_init(void) { return 0; }
1043static inline void rxrpc_sysctl_exit(void) {}
1044#endif
1045
1046/*
David Howellsbe6e6702016-04-04 14:00:32 +01001047 * utils.c
1048 */
David Howellsd991b4a2016-06-29 14:40:39 +01001049int rxrpc_extract_addr_from_skb(struct sockaddr_rxrpc *, struct sk_buff *);
David Howellsbe6e6702016-04-04 14:00:32 +01001050
David Howells248f2192016-09-08 11:10:12 +01001051static inline bool before(u32 seq1, u32 seq2)
1052{
1053 return (s32)(seq1 - seq2) < 0;
1054}
1055static inline bool before_eq(u32 seq1, u32 seq2)
1056{
1057 return (s32)(seq1 - seq2) <= 0;
1058}
1059static inline bool after(u32 seq1, u32 seq2)
1060{
1061 return (s32)(seq1 - seq2) > 0;
1062}
1063static inline bool after_eq(u32 seq1, u32 seq2)
1064{
1065 return (s32)(seq1 - seq2) >= 0;
1066}
1067
David Howellsbe6e6702016-04-04 14:00:32 +01001068/*
David Howells17926a72007-04-26 15:48:28 -07001069 * debug tracing
1070 */
Eric Dumazet95c96172012-04-15 05:58:06 +00001071extern unsigned int rxrpc_debug;
David Howells17926a72007-04-26 15:48:28 -07001072
1073#define dbgprintk(FMT,...) \
Sven Schnelle9f389f42008-04-03 10:45:30 +01001074 printk("[%-6.6s] "FMT"\n", current->comm ,##__VA_ARGS__)
David Howells17926a72007-04-26 15:48:28 -07001075
Harvey Harrison0dc47872008-03-05 20:47:47 -08001076#define kenter(FMT,...) dbgprintk("==> %s("FMT")",__func__ ,##__VA_ARGS__)
1077#define kleave(FMT,...) dbgprintk("<== %s()"FMT"",__func__ ,##__VA_ARGS__)
David Howells17926a72007-04-26 15:48:28 -07001078#define kdebug(FMT,...) dbgprintk(" "FMT ,##__VA_ARGS__)
1079#define kproto(FMT,...) dbgprintk("### "FMT ,##__VA_ARGS__)
1080#define knet(FMT,...) dbgprintk("@@@ "FMT ,##__VA_ARGS__)
1081
1082
1083#if defined(__KDEBUG)
1084#define _enter(FMT,...) kenter(FMT,##__VA_ARGS__)
1085#define _leave(FMT,...) kleave(FMT,##__VA_ARGS__)
1086#define _debug(FMT,...) kdebug(FMT,##__VA_ARGS__)
1087#define _proto(FMT,...) kproto(FMT,##__VA_ARGS__)
1088#define _net(FMT,...) knet(FMT,##__VA_ARGS__)
1089
1090#elif defined(CONFIG_AF_RXRPC_DEBUG)
1091#define RXRPC_DEBUG_KENTER 0x01
1092#define RXRPC_DEBUG_KLEAVE 0x02
1093#define RXRPC_DEBUG_KDEBUG 0x04
1094#define RXRPC_DEBUG_KPROTO 0x08
1095#define RXRPC_DEBUG_KNET 0x10
1096
1097#define _enter(FMT,...) \
1098do { \
1099 if (unlikely(rxrpc_debug & RXRPC_DEBUG_KENTER)) \
1100 kenter(FMT,##__VA_ARGS__); \
1101} while (0)
1102
1103#define _leave(FMT,...) \
1104do { \
1105 if (unlikely(rxrpc_debug & RXRPC_DEBUG_KLEAVE)) \
1106 kleave(FMT,##__VA_ARGS__); \
1107} while (0)
1108
1109#define _debug(FMT,...) \
1110do { \
1111 if (unlikely(rxrpc_debug & RXRPC_DEBUG_KDEBUG)) \
1112 kdebug(FMT,##__VA_ARGS__); \
1113} while (0)
1114
1115#define _proto(FMT,...) \
1116do { \
1117 if (unlikely(rxrpc_debug & RXRPC_DEBUG_KPROTO)) \
1118 kproto(FMT,##__VA_ARGS__); \
1119} while (0)
1120
1121#define _net(FMT,...) \
1122do { \
1123 if (unlikely(rxrpc_debug & RXRPC_DEBUG_KNET)) \
1124 knet(FMT,##__VA_ARGS__); \
1125} while (0)
1126
1127#else
David Howells12fdff32010-08-12 16:54:57 +01001128#define _enter(FMT,...) no_printk("==> %s("FMT")",__func__ ,##__VA_ARGS__)
1129#define _leave(FMT,...) no_printk("<== %s()"FMT"",__func__ ,##__VA_ARGS__)
1130#define _debug(FMT,...) no_printk(" "FMT ,##__VA_ARGS__)
1131#define _proto(FMT,...) no_printk("### "FMT ,##__VA_ARGS__)
1132#define _net(FMT,...) no_printk("@@@ "FMT ,##__VA_ARGS__)
David Howells17926a72007-04-26 15:48:28 -07001133#endif
1134
1135/*
1136 * debug assertion checking
1137 */
1138#if 1 // defined(__KDEBUGALL)
1139
1140#define ASSERT(X) \
1141do { \
1142 if (unlikely(!(X))) { \
Joe Perches9b6d5392016-06-02 12:08:52 -07001143 pr_err("Assertion failed\n"); \
David Howells17926a72007-04-26 15:48:28 -07001144 BUG(); \
1145 } \
David Howellsb4f13422016-03-04 15:56:19 +00001146} while (0)
David Howells17926a72007-04-26 15:48:28 -07001147
1148#define ASSERTCMP(X, OP, Y) \
1149do { \
David Howellscf132582016-09-08 11:10:11 +01001150 __typeof__(X) _x = (X); \
1151 __typeof__(Y) _y = (__typeof__(X))(Y); \
Joe Perches9b6d5392016-06-02 12:08:52 -07001152 if (unlikely(!(_x OP _y))) { \
David Howellscf132582016-09-08 11:10:11 +01001153 pr_err("Assertion failed - %lu(0x%lx) %s %lu(0x%lx) is false\n", \
1154 (unsigned long)_x, (unsigned long)_x, #OP, \
1155 (unsigned long)_y, (unsigned long)_y); \
David Howells17926a72007-04-26 15:48:28 -07001156 BUG(); \
1157 } \
David Howellsb4f13422016-03-04 15:56:19 +00001158} while (0)
David Howells17926a72007-04-26 15:48:28 -07001159
1160#define ASSERTIF(C, X) \
1161do { \
1162 if (unlikely((C) && !(X))) { \
Joe Perches9b6d5392016-06-02 12:08:52 -07001163 pr_err("Assertion failed\n"); \
David Howells17926a72007-04-26 15:48:28 -07001164 BUG(); \
1165 } \
David Howellsb4f13422016-03-04 15:56:19 +00001166} while (0)
David Howells17926a72007-04-26 15:48:28 -07001167
1168#define ASSERTIFCMP(C, X, OP, Y) \
1169do { \
David Howellscf132582016-09-08 11:10:11 +01001170 __typeof__(X) _x = (X); \
1171 __typeof__(Y) _y = (__typeof__(X))(Y); \
Joe Perches9b6d5392016-06-02 12:08:52 -07001172 if (unlikely((C) && !(_x OP _y))) { \
1173 pr_err("Assertion failed - %lu(0x%lx) %s %lu(0x%lx) is false\n", \
David Howellscf132582016-09-08 11:10:11 +01001174 (unsigned long)_x, (unsigned long)_x, #OP, \
1175 (unsigned long)_y, (unsigned long)_y); \
David Howells17926a72007-04-26 15:48:28 -07001176 BUG(); \
1177 } \
David Howellsb4f13422016-03-04 15:56:19 +00001178} while (0)
David Howells17926a72007-04-26 15:48:28 -07001179
1180#else
1181
1182#define ASSERT(X) \
1183do { \
David Howellsb4f13422016-03-04 15:56:19 +00001184} while (0)
David Howells17926a72007-04-26 15:48:28 -07001185
1186#define ASSERTCMP(X, OP, Y) \
1187do { \
David Howellsb4f13422016-03-04 15:56:19 +00001188} while (0)
David Howells17926a72007-04-26 15:48:28 -07001189
1190#define ASSERTIF(C, X) \
1191do { \
David Howellsb4f13422016-03-04 15:56:19 +00001192} while (0)
David Howells17926a72007-04-26 15:48:28 -07001193
1194#define ASSERTIFCMP(C, X, OP, Y) \
1195do { \
David Howellsb4f13422016-03-04 15:56:19 +00001196} while (0)
David Howells17926a72007-04-26 15:48:28 -07001197
1198#endif /* __KDEBUGALL */