]>
Commit | Line | Data |
---|---|---|
2874c5fd | 1 | /* SPDX-License-Identifier: GPL-2.0-or-later */ |
17926a79 DH |
2 | /* AF_RXRPC internal definitions |
3 | * | |
4 | * Copyright (C) 2007 Red Hat, Inc. All Rights Reserved. | |
5 | * Written by David Howells (dhowells@redhat.com) | |
17926a79 DH |
6 | */ |
7 | ||
be6e6707 | 8 | #include <linux/atomic.h> |
8496af50 | 9 | #include <linux/seqlock.h> |
c410bf01 | 10 | #include <linux/win_minmax.h> |
2baec2c3 DH |
11 | #include <net/net_namespace.h> |
12 | #include <net/netns/generic.h> | |
e0e4d82f | 13 | #include <net/sock.h> |
be6e6707 | 14 | #include <net/af_rxrpc.h> |
41057ebd | 15 | #include <keys/rxrpc-type.h> |
ddc6c70f | 16 | #include "protocol.h" |
17926a79 | 17 | |
17926a79 DH |
18 | #define FCRYPT_BSIZE 8 |
19 | struct rxrpc_crypt { | |
20 | union { | |
21 | u8 x[FCRYPT_BSIZE]; | |
91e916cf | 22 | __be32 n[2]; |
17926a79 DH |
23 | }; |
24 | } __attribute__((aligned(8))); | |
25 | ||
651350d1 DH |
26 | #define rxrpc_queue_work(WS) queue_work(rxrpc_workqueue, (WS)) |
27 | #define rxrpc_queue_delayed_work(WS,D) \ | |
28 | queue_delayed_work(rxrpc_workqueue, (WS), (D)) | |
29 | ||
12da59fc | 30 | struct key_preparsed_payload; |
cc8feb8e DH |
31 | struct rxrpc_connection; |
32 | ||
d001648e | 33 | /* |
ece64fec DH |
34 | * Mark applied to socket buffers in skb->mark. skb->priority is used |
35 | * to pass supplementary information. | |
d001648e DH |
36 | */ |
37 | enum rxrpc_skb_mark { | |
ece64fec DH |
38 | RXRPC_SKB_MARK_REJECT_BUSY, /* Reject with BUSY */ |
39 | RXRPC_SKB_MARK_REJECT_ABORT, /* Reject with ABORT (code in skb->priority) */ | |
d001648e DH |
40 | }; |
41 | ||
17926a79 DH |
42 | /* |
43 | * sk_state for RxRPC sockets | |
44 | */ | |
45 | enum { | |
2341e077 DH |
46 | RXRPC_UNBOUND = 0, |
47 | RXRPC_CLIENT_UNBOUND, /* Unbound socket used as client */ | |
17926a79 | 48 | RXRPC_CLIENT_BOUND, /* client local address bound */ |
17926a79 | 49 | RXRPC_SERVER_BOUND, /* server local address bound */ |
28036f44 | 50 | RXRPC_SERVER_BOUND2, /* second server local address bound */ |
17926a79 | 51 | RXRPC_SERVER_LISTENING, /* server listening for connections */ |
210f0353 | 52 | RXRPC_SERVER_LISTEN_DISABLED, /* server listening disabled */ |
17926a79 DH |
53 | RXRPC_CLOSE, /* socket is being closed */ |
54 | }; | |
55 | ||
2baec2c3 DH |
56 | /* |
57 | * Per-network namespace data. | |
58 | */ | |
59 | struct rxrpc_net { | |
60 | struct proc_dir_entry *proc_net; /* Subdir in /proc/net */ | |
61 | u32 epoch; /* Local epoch for detecting local-end reset */ | |
62 | struct list_head calls; /* List of calls active in this namespace */ | |
ad25f5cb | 63 | spinlock_t call_lock; /* Lock for ->calls */ |
d3be4d24 | 64 | atomic_t nr_calls; /* Count of allocated calls */ |
2baec2c3 | 65 | |
31f5f9a1 | 66 | atomic_t nr_conns; |
2baec2c3 DH |
67 | struct list_head conn_proc_list; /* List of conns in this namespace for proc */ |
68 | struct list_head service_conns; /* Service conns in this namespace */ | |
69 | rwlock_t conn_lock; /* Lock for ->conn_proc_list, ->service_conns */ | |
3d18cbb7 DH |
70 | struct work_struct service_conn_reaper; |
71 | struct timer_list service_conn_reap_timer; | |
2baec2c3 | 72 | |
f859ab61 | 73 | bool live; |
245500d8 DH |
74 | |
75 | bool kill_all_client_conns; | |
76 | atomic_t nr_client_conns; | |
2baec2c3 DH |
77 | spinlock_t client_conn_cache_lock; /* Lock for ->*_client_conns */ |
78 | spinlock_t client_conn_discard_lock; /* Prevent multiple discarders */ | |
2baec2c3 | 79 | struct list_head idle_client_conns; |
3d18cbb7 DH |
80 | struct work_struct client_conn_reaper; |
81 | struct timer_list client_conn_reap_timer; | |
2baec2c3 | 82 | |
33912c26 | 83 | struct hlist_head local_endpoints; |
2baec2c3 DH |
84 | struct mutex local_mutex; /* Lock for ->local_endpoints */ |
85 | ||
2baec2c3 | 86 | DECLARE_HASHTABLE (peer_hash, 10); |
ace45bec DH |
87 | spinlock_t peer_hash_lock; /* Lock for ->peer_hash */ |
88 | ||
89 | #define RXRPC_KEEPALIVE_TIME 20 /* NAT keepalive time in seconds */ | |
90 | u8 peer_keepalive_cursor; | |
330bdcfa DH |
91 | time64_t peer_keepalive_base; |
92 | struct list_head peer_keepalive[32]; | |
93 | struct list_head peer_keepalive_new; | |
ace45bec DH |
94 | struct timer_list peer_keepalive_timer; |
95 | struct work_struct peer_keepalive_work; | |
2baec2c3 DH |
96 | }; |
97 | ||
00e90712 DH |
98 | /* |
99 | * Service backlog preallocation. | |
100 | * | |
101 | * This contains circular buffers of preallocated peers, connections and calls | |
102 | * for incoming service calls and their head and tail pointers. This allows | |
103 | * calls to be set up in the data_ready handler, thereby avoiding the need to | |
104 | * shuffle packets around so much. | |
105 | */ | |
106 | struct rxrpc_backlog { | |
107 | unsigned short peer_backlog_head; | |
108 | unsigned short peer_backlog_tail; | |
109 | unsigned short conn_backlog_head; | |
110 | unsigned short conn_backlog_tail; | |
111 | unsigned short call_backlog_head; | |
112 | unsigned short call_backlog_tail; | |
113 | #define RXRPC_BACKLOG_MAX 32 | |
114 | struct rxrpc_peer *peer_backlog[RXRPC_BACKLOG_MAX]; | |
115 | struct rxrpc_connection *conn_backlog[RXRPC_BACKLOG_MAX]; | |
116 | struct rxrpc_call *call_backlog[RXRPC_BACKLOG_MAX]; | |
117 | }; | |
118 | ||
17926a79 DH |
119 | /* |
120 | * RxRPC socket definition | |
121 | */ | |
122 | struct rxrpc_sock { | |
123 | /* WARNING: sk has to be the first member */ | |
124 | struct sock sk; | |
d001648e | 125 | rxrpc_notify_new_call_t notify_new_call; /* Func to notify of new call */ |
00e90712 | 126 | rxrpc_discard_new_call_t discard_new_call; /* Func to discard a new call */ |
17926a79 | 127 | struct rxrpc_local *local; /* local endpoint */ |
00e90712 | 128 | struct rxrpc_backlog *backlog; /* Preallocation for services */ |
248f219c DH |
129 | spinlock_t incoming_lock; /* Incoming call vs service shutdown lock */ |
130 | struct list_head sock_calls; /* List of calls owned by this socket */ | |
131 | struct list_head to_be_accepted; /* calls awaiting acceptance */ | |
132 | struct list_head recvmsg_q; /* Calls awaiting recvmsg's attention */ | |
133 | rwlock_t recvmsg_lock; /* Lock for recvmsg_q */ | |
17926a79 DH |
134 | struct key *key; /* security for this socket */ |
135 | struct key *securities; /* list of server security descriptors */ | |
00e90712 | 136 | struct rb_root calls; /* User ID -> call mapping */ |
17926a79 | 137 | unsigned long flags; |
2341e077 | 138 | #define RXRPC_SOCK_CONNECTED 0 /* connect_srx is set */ |
17926a79 DH |
139 | rwlock_t call_lock; /* lock for calls */ |
140 | u32 min_sec_level; /* minimum security level */ | |
141 | #define RXRPC_SECURITY_MAX RXRPC_SECURITY_ENCRYPT | |
cc8feb8e | 142 | bool exclusive; /* Exclusive connection for a client socket */ |
28036f44 | 143 | u16 second_service; /* Additional service bound to the endpoint */ |
4722974d DH |
144 | struct { |
145 | /* Service upgrade information */ | |
146 | u16 from; /* Service ID to upgrade (if not 0) */ | |
147 | u16 to; /* service ID to upgrade to */ | |
148 | } service_upgrade; | |
cc8feb8e | 149 | sa_family_t family; /* Protocol family created with */ |
4722974d | 150 | struct sockaddr_rxrpc srx; /* Primary Service/local addresses */ |
2341e077 | 151 | struct sockaddr_rxrpc connect_srx; /* Default client address from connect() */ |
17926a79 DH |
152 | }; |
153 | ||
154 | #define rxrpc_sk(__sk) container_of((__sk), struct rxrpc_sock, sk) | |
155 | ||
0d12f8a4 DH |
156 | /* |
157 | * CPU-byteorder normalised Rx packet header. | |
158 | */ | |
159 | struct rxrpc_host_header { | |
160 | u32 epoch; /* client boot timestamp */ | |
161 | u32 cid; /* connection and channel ID */ | |
162 | u32 callNumber; /* call ID (0 for connection-level packets) */ | |
163 | u32 seq; /* sequence number of pkt in call stream */ | |
164 | u32 serial; /* serial number of pkt sent to network */ | |
165 | u8 type; /* packet type */ | |
166 | u8 flags; /* packet flags */ | |
167 | u8 userStatus; /* app-layer defined status */ | |
168 | u8 securityIndex; /* security protocol ID */ | |
169 | union { | |
170 | u16 _rsvd; /* reserved */ | |
171 | u16 cksum; /* kerberos security checksum */ | |
172 | }; | |
173 | u16 serviceId; /* service ID */ | |
174 | } __packed; | |
175 | ||
17926a79 DH |
176 | /* |
177 | * RxRPC socket buffer private variables | |
178 | * - max 48 bytes (struct sk_buff::cb) | |
179 | */ | |
180 | struct rxrpc_skb_priv { | |
987db9f7 | 181 | atomic_t nr_ring_pins; /* Number of rxtx ring pins */ |
c3c9e3df DH |
182 | u8 nr_subpackets; /* Number of subpackets */ |
183 | u8 rx_flags; /* Received packet flags */ | |
184 | #define RXRPC_SKB_INCL_LAST 0x01 /* - Includes last packet */ | |
b311e684 | 185 | #define RXRPC_SKB_TX_BUFFER 0x02 /* - Is transmit buffer */ |
17926a79 | 186 | union { |
17926a79 | 187 | int remain; /* amount of space remaining for next write */ |
c3c9e3df DH |
188 | |
189 | /* List of requested ACKs on subpackets */ | |
190 | unsigned long rx_req_ack[(RXRPC_MAX_NR_JUMBO + BITS_PER_LONG - 1) / | |
191 | BITS_PER_LONG]; | |
17926a79 DH |
192 | }; |
193 | ||
0d12f8a4 | 194 | struct rxrpc_host_header hdr; /* RxRPC packet header from this packet */ |
17926a79 DH |
195 | }; |
196 | ||
197 | #define rxrpc_skb(__skb) ((struct rxrpc_skb_priv *) &(__skb)->cb) | |
198 | ||
17926a79 DH |
199 | /* |
200 | * RxRPC security module interface | |
201 | */ | |
202 | struct rxrpc_security { | |
17926a79 DH |
203 | const char *name; /* name of this service */ |
204 | u8 security_index; /* security type provided */ | |
063c60d3 | 205 | u32 no_key_abort; /* Abort code indicating no key */ |
17926a79 | 206 | |
648af7fc DH |
207 | /* Initialise a security service */ |
208 | int (*init)(void); | |
209 | ||
210 | /* Clean up a security service */ | |
211 | void (*exit)(void); | |
212 | ||
12da59fc DH |
213 | /* Parse the information from a server key */ |
214 | int (*preparse_server_key)(struct key_preparsed_payload *); | |
215 | ||
216 | /* Clean up the preparse buffer after parsing a server key */ | |
217 | void (*free_preparse_server_key)(struct key_preparsed_payload *); | |
218 | ||
219 | /* Destroy the payload of a server key */ | |
220 | void (*destroy_server_key)(struct key *); | |
221 | ||
d5953f65 DH |
222 | /* Describe a server key */ |
223 | void (*describe_server_key)(const struct key *, struct seq_file *); | |
224 | ||
17926a79 | 225 | /* initialise a connection's security */ |
41057ebd DH |
226 | int (*init_connection_security)(struct rxrpc_connection *, |
227 | struct rxrpc_key_token *); | |
17926a79 | 228 | |
d7d775b1 DH |
229 | /* Work out how much data we can store in a packet, given an estimate |
230 | * of the amount of data remaining. | |
231 | */ | |
232 | int (*how_much_data)(struct rxrpc_call *, size_t, | |
233 | size_t *, size_t *, size_t *); | |
17926a79 DH |
234 | |
235 | /* impose security on a packet */ | |
f4bdf3d6 | 236 | int (*secure_packet)(struct rxrpc_call *, struct sk_buff *, size_t); |
17926a79 DH |
237 | |
238 | /* verify the security on a received packet */ | |
5a42976d | 239 | int (*verify_packet)(struct rxrpc_call *, struct sk_buff *, |
248f219c DH |
240 | unsigned int, unsigned int, rxrpc_seq_t, u16); |
241 | ||
1db88c53 DH |
242 | /* Free crypto request on a call */ |
243 | void (*free_call_crypto)(struct rxrpc_call *); | |
244 | ||
248f219c DH |
245 | /* Locate the data in a received packet that has been verified. */ |
246 | void (*locate_data)(struct rxrpc_call *, struct sk_buff *, | |
247 | unsigned int *, unsigned int *); | |
17926a79 DH |
248 | |
249 | /* issue a challenge */ | |
250 | int (*issue_challenge)(struct rxrpc_connection *); | |
251 | ||
252 | /* respond to a challenge */ | |
253 | int (*respond_to_challenge)(struct rxrpc_connection *, | |
254 | struct sk_buff *, | |
255 | u32 *); | |
256 | ||
257 | /* verify a response */ | |
258 | int (*verify_response)(struct rxrpc_connection *, | |
259 | struct sk_buff *, | |
260 | u32 *); | |
261 | ||
262 | /* clear connection security */ | |
263 | void (*clear)(struct rxrpc_connection *); | |
264 | }; | |
265 | ||
266 | /* | |
4f95dd78 DH |
267 | * RxRPC local transport endpoint description |
268 | * - owned by a single AF_RXRPC socket | |
269 | * - pointed to by transport socket struct sk_user_data | |
17926a79 DH |
270 | */ |
271 | struct rxrpc_local { | |
4f95dd78 | 272 | struct rcu_head rcu; |
730c5fd4 | 273 | atomic_t active_users; /* Number of users of the local endpoint */ |
a0575429 | 274 | refcount_t ref; /* Number of references to the structure */ |
2baec2c3 | 275 | struct rxrpc_net *rxnet; /* The network ns in which this resides */ |
33912c26 | 276 | struct hlist_node link; |
17926a79 | 277 | struct socket *socket; /* my UDP socket */ |
4f95dd78 | 278 | struct work_struct processor; |
1e9e5c95 | 279 | struct rxrpc_sock __rcu *service; /* Service(s) listening on this endpoint */ |
17926a79 | 280 | struct rw_semaphore defrag_sem; /* control re-enablement of IP DF bit */ |
17926a79 | 281 | struct sk_buff_head reject_queue; /* packets awaiting rejection */ |
44ba0698 | 282 | struct sk_buff_head event_queue; /* endpoint event packets awaiting processing */ |
245500d8 DH |
283 | struct rb_root client_bundles; /* Client connection bundles by socket params */ |
284 | spinlock_t client_bundles_lock; /* Lock for client_bundles */ | |
17926a79 DH |
285 | spinlock_t lock; /* access lock */ |
286 | rwlock_t services_lock; /* lock for services list */ | |
17926a79 | 287 | int debug_id; /* debug ID for printks */ |
4f95dd78 | 288 | bool dead; |
f859ab61 | 289 | bool service_closed; /* Service socket closed */ |
17926a79 DH |
290 | struct sockaddr_rxrpc srx; /* local address */ |
291 | }; | |
292 | ||
293 | /* | |
294 | * RxRPC remote transport endpoint definition | |
be6e6707 | 295 | * - matched by local endpoint, remote port, address and protocol type |
17926a79 DH |
296 | */ |
297 | struct rxrpc_peer { | |
be6e6707 | 298 | struct rcu_head rcu; /* This must be first */ |
a0575429 | 299 | refcount_t ref; |
be6e6707 DH |
300 | unsigned long hash_key; |
301 | struct hlist_node hash_link; | |
302 | struct rxrpc_local *local; | |
f66d7490 | 303 | struct hlist_head error_targets; /* targets for net error distribution */ |
aa390bbe | 304 | struct rb_root service_conns; /* Service connections */ |
330bdcfa | 305 | struct list_head keepalive_link; /* Link in net->peer_keepalive[] */ |
ace45bec | 306 | time64_t last_tx_at; /* Last time packet sent here */ |
8496af50 | 307 | seqlock_t service_conn_lock; |
17926a79 | 308 | spinlock_t lock; /* access lock */ |
95c96174 ED |
309 | unsigned int if_mtu; /* interface MTU for this peer */ |
310 | unsigned int mtu; /* network MTU for this peer */ | |
311 | unsigned int maxdata; /* data size (MTU - hdrsize) */ | |
17926a79 DH |
312 | unsigned short hdrsize; /* header size (IP + UDP + RxRPC) */ |
313 | int debug_id; /* debug ID for printks */ | |
17926a79 DH |
314 | struct sockaddr_rxrpc srx; /* remote address */ |
315 | ||
316 | /* calculated RTT cache */ | |
317 | #define RXRPC_RTT_CACHE_SIZE 32 | |
c1e15b49 | 318 | spinlock_t rtt_input_lock; /* RTT lock for input routine */ |
0d4b103c | 319 | ktime_t rtt_last_req; /* Time of last RTT request */ |
c410bf01 DH |
320 | unsigned int rtt_count; /* Number of samples we've got */ |
321 | ||
322 | u32 srtt_us; /* smoothed round trip time << 3 in usecs */ | |
323 | u32 mdev_us; /* medium deviation */ | |
324 | u32 mdev_max_us; /* maximal mdev for the last rtt period */ | |
325 | u32 rttvar_us; /* smoothed mdev_max */ | |
326 | u32 rto_j; /* Retransmission timeout in jiffies */ | |
327 | u8 backoff; /* Backoff timeout */ | |
f7aec129 DH |
328 | |
329 | u8 cong_cwnd; /* Congestion window size */ | |
17926a79 DH |
330 | }; |
331 | ||
19ffa01c DH |
332 | /* |
333 | * Keys for matching a connection. | |
334 | */ | |
335 | struct rxrpc_conn_proto { | |
e8d70ce1 DH |
336 | union { |
337 | struct { | |
338 | u32 epoch; /* epoch of this connection */ | |
339 | u32 cid; /* connection ID */ | |
340 | }; | |
341 | u64 index_key; | |
19ffa01c DH |
342 | }; |
343 | }; | |
344 | ||
345 | struct rxrpc_conn_parameters { | |
346 | struct rxrpc_local *local; /* Representation of local endpoint */ | |
347 | struct rxrpc_peer *peer; /* Remote endpoint */ | |
348 | struct key *key; /* Security details */ | |
349 | bool exclusive; /* T if conn is exclusive */ | |
4e255721 | 350 | bool upgrade; /* T if service ID can be upgraded */ |
19ffa01c DH |
351 | u16 service_id; /* Service ID for this connection */ |
352 | u32 security_level; /* Security level selected */ | |
353 | }; | |
354 | ||
bba304db DH |
355 | /* |
356 | * Bits in the connection flags. | |
357 | */ | |
358 | enum rxrpc_conn_flag { | |
359 | RXRPC_CONN_HAS_IDR, /* Has a client conn ID assigned */ | |
001c1122 | 360 | RXRPC_CONN_IN_SERVICE_CONNS, /* Conn is in peer->service_conns */ |
45025bce | 361 | RXRPC_CONN_DONT_REUSE, /* Don't reuse this connection */ |
4e255721 | 362 | RXRPC_CONN_PROBING_FOR_UPGRADE, /* Probing for service upgrade */ |
3136ef49 DH |
363 | RXRPC_CONN_FINAL_ACK_0, /* Need final ACK for channel 0 */ |
364 | RXRPC_CONN_FINAL_ACK_1, /* Need final ACK for channel 1 */ | |
365 | RXRPC_CONN_FINAL_ACK_2, /* Need final ACK for channel 2 */ | |
366 | RXRPC_CONN_FINAL_ACK_3, /* Need final ACK for channel 3 */ | |
bba304db DH |
367 | }; |
368 | ||
3136ef49 DH |
369 | #define RXRPC_CONN_FINAL_ACK_MASK ((1UL << RXRPC_CONN_FINAL_ACK_0) | \ |
370 | (1UL << RXRPC_CONN_FINAL_ACK_1) | \ | |
371 | (1UL << RXRPC_CONN_FINAL_ACK_2) | \ | |
372 | (1UL << RXRPC_CONN_FINAL_ACK_3)) | |
373 | ||
bba304db DH |
374 | /* |
375 | * Events that can be raised upon a connection. | |
376 | */ | |
377 | enum rxrpc_conn_event { | |
378 | RXRPC_CONN_EV_CHALLENGE, /* Send challenge packet */ | |
379 | }; | |
380 | ||
381 | /* | |
382 | * The connection protocol state. | |
383 | */ | |
384 | enum rxrpc_conn_proto_state { | |
385 | RXRPC_CONN_UNUSED, /* Connection not yet attempted */ | |
386 | RXRPC_CONN_CLIENT, /* Client connection */ | |
00e90712 | 387 | RXRPC_CONN_SERVICE_PREALLOC, /* Service connection preallocation */ |
bba304db DH |
388 | RXRPC_CONN_SERVICE_UNSECURED, /* Service unsecured connection */ |
389 | RXRPC_CONN_SERVICE_CHALLENGING, /* Service challenging for security */ | |
390 | RXRPC_CONN_SERVICE, /* Service secured connection */ | |
391 | RXRPC_CONN_REMOTELY_ABORTED, /* Conn aborted by peer */ | |
392 | RXRPC_CONN_LOCALLY_ABORTED, /* Conn aborted locally */ | |
bba304db DH |
393 | RXRPC_CONN__NR_STATES |
394 | }; | |
395 | ||
245500d8 DH |
396 | /* |
397 | * RxRPC client connection bundle. | |
398 | */ | |
399 | struct rxrpc_bundle { | |
400 | struct rxrpc_conn_parameters params; | |
a0575429 | 401 | refcount_t ref; |
245500d8 DH |
402 | unsigned int debug_id; |
403 | bool try_upgrade; /* True if the bundle is attempting upgrade */ | |
404 | bool alloc_conn; /* True if someone's getting a conn */ | |
8806245a | 405 | short alloc_error; /* Error from last conn allocation */ |
245500d8 DH |
406 | spinlock_t channel_lock; |
407 | struct rb_node local_node; /* Node in local->client_conns */ | |
408 | struct list_head waiting_calls; /* Calls waiting for channels */ | |
409 | unsigned long avail_chans; /* Mask of available channels */ | |
410 | struct rxrpc_connection *conns[4]; /* The connections in the bundle (max 4) */ | |
411 | }; | |
412 | ||
17926a79 DH |
413 | /* |
414 | * RxRPC connection definition | |
aa390bbe | 415 | * - matched by { local, peer, epoch, conn_id, direction } |
17926a79 DH |
416 | * - each connection can only handle four simultaneous calls |
417 | */ | |
418 | struct rxrpc_connection { | |
19ffa01c DH |
419 | struct rxrpc_conn_proto proto; |
420 | struct rxrpc_conn_parameters params; | |
421 | ||
a0575429 | 422 | refcount_t ref; |
45025bce DH |
423 | struct rcu_head rcu; |
424 | struct list_head cache_link; | |
a1399f8b | 425 | |
245500d8 | 426 | unsigned char act_chans; /* Mask of active channels */ |
a1399f8b | 427 | struct rxrpc_channel { |
3136ef49 | 428 | unsigned long final_ack_at; /* Time at which to issue final ACK */ |
a1399f8b | 429 | struct rxrpc_call __rcu *call; /* Active call */ |
4764c0da | 430 | unsigned int call_debug_id; /* call->debug_id */ |
a1399f8b DH |
431 | u32 call_id; /* ID of current call */ |
432 | u32 call_counter; /* Call ID counter */ | |
433 | u32 last_call; /* ID of last call */ | |
18bfeba5 | 434 | u8 last_type; /* Type of last packet */ |
18bfeba5 DH |
435 | union { |
436 | u32 last_seq; | |
437 | u32 last_abort; | |
438 | }; | |
a1399f8b | 439 | } channels[RXRPC_MAXCALLS]; |
999b69f8 | 440 | |
3136ef49 | 441 | struct timer_list timer; /* Conn event timer */ |
17926a79 | 442 | struct work_struct processor; /* connection event processor */ |
245500d8 DH |
443 | struct rxrpc_bundle *bundle; /* Client connection bundle */ |
444 | struct rb_node service_node; /* Node in peer->service_conns */ | |
4d028b2c | 445 | struct list_head proc_link; /* link in procfs list */ |
17926a79 | 446 | struct list_head link; /* link in master connection list */ |
17926a79 | 447 | struct sk_buff_head rx_queue; /* received conn-level packets */ |
521bb304 | 448 | |
648af7fc | 449 | const struct rxrpc_security *security; /* applied security module */ |
521bb304 DH |
450 | union { |
451 | struct { | |
452 | struct crypto_sync_skcipher *cipher; /* encryption handle */ | |
453 | struct rxrpc_crypt csum_iv; /* packet checksum base */ | |
454 | u32 nonce; /* response re-use preventer */ | |
455 | } rxkad; | |
456 | }; | |
4a3388c8 | 457 | unsigned long flags; |
17926a79 | 458 | unsigned long events; |
f51b4480 | 459 | unsigned long idle_timestamp; /* Time at which last became idle */ |
17926a79 | 460 | spinlock_t state_lock; /* state-change lock */ |
cf13258f | 461 | enum rxrpc_conn_proto_state state; /* current state of connection */ |
64753092 | 462 | u32 abort_code; /* Abort code of connection abort */ |
17926a79 | 463 | int debug_id; /* debug ID for printks */ |
17926a79 | 464 | atomic_t serial; /* packet serial number counter */ |
563ea7d5 | 465 | unsigned int hi_serial; /* highest serial number received */ |
c1e15b49 | 466 | u32 service_id; /* Service ID, possibly upgraded */ |
17926a79 | 467 | u8 security_ix; /* security type */ |
17926a79 | 468 | u8 out_clientflag; /* RXRPC_CLIENT_INITIATED if we are client */ |
245500d8 | 469 | u8 bundle_shift; /* Index into bundle->avail_chans */ |
64753092 | 470 | short error; /* Local error code */ |
17926a79 DH |
471 | }; |
472 | ||
dc71db34 DH |
473 | static inline bool rxrpc_to_server(const struct rxrpc_skb_priv *sp) |
474 | { | |
475 | return sp->hdr.flags & RXRPC_CLIENT_INITIATED; | |
476 | } | |
477 | ||
478 | static inline bool rxrpc_to_client(const struct rxrpc_skb_priv *sp) | |
479 | { | |
480 | return !rxrpc_to_server(sp); | |
481 | } | |
482 | ||
5b8848d1 DH |
483 | /* |
484 | * Flags in call->flags. | |
485 | */ | |
486 | enum rxrpc_call_flag { | |
487 | RXRPC_CALL_RELEASED, /* call has been released - no more message to userspace */ | |
5b8848d1 | 488 | RXRPC_CALL_HAS_USERID, /* has a user ID attached */ |
dabe5a79 | 489 | RXRPC_CALL_IS_SERVICE, /* Call is service call */ |
45025bce | 490 | RXRPC_CALL_EXPOSED, /* The call was exposed to the world */ |
248f219c DH |
491 | RXRPC_CALL_RX_LAST, /* Received the last packet (at rxtx_top) */ |
492 | RXRPC_CALL_TX_LAST, /* Last packet in Tx buffer (at rxtx_top) */ | |
a5af7e1f | 493 | RXRPC_CALL_SEND_PING, /* A ping will need to be sent */ |
57494343 | 494 | RXRPC_CALL_RETRANS_TIMEOUT, /* Retransmission due to timeout occurred */ |
c54e43d7 | 495 | RXRPC_CALL_BEGAN_RX_TIMER, /* We began the expect_rx_by timer */ |
1a025028 | 496 | RXRPC_CALL_RX_HEARD, /* The peer responded at least once to this call */ |
d0b35a42 | 497 | RXRPC_CALL_RX_UNDERRUN, /* Got data underrun */ |
5273a191 | 498 | RXRPC_CALL_DISCONNECTED, /* The call has been disconnected */ |
b7a7d674 | 499 | RXRPC_CALL_KERNEL, /* The call was made by the kernel */ |
245500d8 | 500 | RXRPC_CALL_UPGRADE, /* Service upgrade was requested for the call */ |
5b8848d1 DH |
501 | }; |
502 | ||
503 | /* | |
504 | * Events that can be raised on a call. | |
505 | */ | |
506 | enum rxrpc_call_event { | |
4c198ad1 | 507 | RXRPC_CALL_EV_ACK, /* need to generate ACK */ |
4c198ad1 | 508 | RXRPC_CALL_EV_ABORT, /* need to generate abort */ |
4c198ad1 | 509 | RXRPC_CALL_EV_RESEND, /* Tx resend required */ |
a5af7e1f | 510 | RXRPC_CALL_EV_PING, /* Ping send required */ |
a158bdd3 | 511 | RXRPC_CALL_EV_EXPIRED, /* Expiry occurred */ |
bd1fdf8c | 512 | RXRPC_CALL_EV_ACK_LOST, /* ACK may be lost, send ping */ |
5b8848d1 DH |
513 | }; |
514 | ||
515 | /* | |
516 | * The states that a call can be in. | |
517 | */ | |
518 | enum rxrpc_call_state { | |
999b69f8 DH |
519 | RXRPC_CALL_UNINITIALISED, |
520 | RXRPC_CALL_CLIENT_AWAIT_CONN, /* - client waiting for connection to become available */ | |
5b8848d1 DH |
521 | RXRPC_CALL_CLIENT_SEND_REQUEST, /* - client sending request phase */ |
522 | RXRPC_CALL_CLIENT_AWAIT_REPLY, /* - client awaiting reply */ | |
523 | RXRPC_CALL_CLIENT_RECV_REPLY, /* - client receiving reply phase */ | |
00e90712 | 524 | RXRPC_CALL_SERVER_PREALLOC, /* - service preallocation */ |
5b8848d1 | 525 | RXRPC_CALL_SERVER_SECURING, /* - server securing request connection */ |
5b8848d1 DH |
526 | RXRPC_CALL_SERVER_RECV_REQUEST, /* - server receiving request */ |
527 | RXRPC_CALL_SERVER_ACK_REQUEST, /* - server pending ACK of request */ | |
528 | RXRPC_CALL_SERVER_SEND_REPLY, /* - server sending reply */ | |
529 | RXRPC_CALL_SERVER_AWAIT_ACK, /* - server awaiting final ACK */ | |
f5c17aae | 530 | RXRPC_CALL_COMPLETE, /* - call complete */ |
f5c17aae DH |
531 | NR__RXRPC_CALL_STATES |
532 | }; | |
533 | ||
e122d845 DH |
534 | /* |
535 | * Call completion condition (state == RXRPC_CALL_COMPLETE). | |
536 | */ | |
537 | enum rxrpc_call_completion { | |
538 | RXRPC_CALL_SUCCEEDED, /* - Normal termination */ | |
539 | RXRPC_CALL_REMOTELY_ABORTED, /* - call aborted by peer */ | |
540 | RXRPC_CALL_LOCALLY_ABORTED, /* - call aborted locally on error or close */ | |
541 | RXRPC_CALL_LOCAL_ERROR, /* - call failed due to local error */ | |
542 | RXRPC_CALL_NETWORK_ERROR, /* - call terminated by network error */ | |
543 | NR__RXRPC_CALL_COMPLETIONS | |
544 | }; | |
545 | ||
57494343 DH |
546 | /* |
547 | * Call Tx congestion management modes. | |
548 | */ | |
549 | enum rxrpc_congest_mode { | |
550 | RXRPC_CALL_SLOW_START, | |
551 | RXRPC_CALL_CONGEST_AVOIDANCE, | |
552 | RXRPC_CALL_PACKET_LOSS, | |
553 | RXRPC_CALL_FAST_RETRANSMIT, | |
554 | NR__RXRPC_CONGEST_MODES | |
555 | }; | |
556 | ||
17926a79 DH |
557 | /* |
558 | * RxRPC call definition | |
559 | * - matched by { connection, call_id } | |
560 | */ | |
561 | struct rxrpc_call { | |
dee46364 | 562 | struct rcu_head rcu; |
17926a79 | 563 | struct rxrpc_connection *conn; /* connection carrying call */ |
df5d8bf7 | 564 | struct rxrpc_peer *peer; /* Peer record for remote address */ |
8d94aa38 | 565 | struct rxrpc_sock __rcu *socket; /* socket responsible */ |
d3be4d24 | 566 | struct rxrpc_net *rxnet; /* Network namespace to which call belongs */ |
91fcfbe8 | 567 | const struct rxrpc_security *security; /* applied security module */ |
540b1c48 | 568 | struct mutex user_mutex; /* User access mutex */ |
a158bdd3 | 569 | unsigned long ack_at; /* When deferred ACK needs to happen */ |
bd1fdf8c | 570 | unsigned long ack_lost_at; /* When ACK is figured as lost */ |
a158bdd3 DH |
571 | unsigned long resend_at; /* When next resend needs to happen */ |
572 | unsigned long ping_at; /* When next to send a ping */ | |
415f44e4 | 573 | unsigned long keepalive_at; /* When next to send a keepalive ping */ |
a158bdd3 DH |
574 | unsigned long expect_rx_by; /* When we expect to get a packet by */ |
575 | unsigned long expect_req_by; /* When we expect to get a request DATA packet by */ | |
576 | unsigned long expect_term_by; /* When we expect call termination by */ | |
577 | u32 next_rx_timo; /* Timeout for next Rx packet (jif) */ | |
578 | u32 next_req_timo; /* Timeout for next Rx request packet (jif) */ | |
1db88c53 | 579 | struct skcipher_request *cipher_req; /* Packet cipher request buffer */ |
248f219c DH |
580 | struct timer_list timer; /* Combined event timer */ |
581 | struct work_struct processor; /* Event processor */ | |
d001648e | 582 | rxrpc_notify_rx_t notify_rx; /* kernel service Rx notification function */ |
17926a79 | 583 | struct list_head link; /* link in master call list */ |
245500d8 | 584 | struct list_head chan_wait_link; /* Link in conn->bundle->waiting_calls */ |
f66d7490 | 585 | struct hlist_node error_link; /* link in error distribution list */ |
248f219c DH |
586 | struct list_head accept_link; /* Link in rx->acceptq */ |
587 | struct list_head recvmsg_link; /* Link in rx->recvmsg_q */ | |
588 | struct list_head sock_link; /* Link in rx->sock_calls */ | |
589 | struct rb_node sock_node; /* Node in rx->calls */ | |
17926a79 | 590 | struct sk_buff *tx_pending; /* Tx socket buffer being filled */ |
45025bce | 591 | wait_queue_head_t waitq; /* Wait queue for channel or Tx */ |
e754eba6 | 592 | s64 tx_total_len; /* Total length left to be transmitted (or -1) */ |
a263629d | 593 | __be32 crypto_buf[2]; /* Temporary packet crypto buffer */ |
17926a79 | 594 | unsigned long user_call_ID; /* user-defined call ID */ |
17926a79 | 595 | unsigned long flags; |
17926a79 | 596 | unsigned long events; |
17926a79 | 597 | spinlock_t lock; |
20acbd9a | 598 | spinlock_t notify_lock; /* Kernel notification lock */ |
17926a79 | 599 | rwlock_t state_lock; /* lock for state transition */ |
f5c17aae DH |
600 | u32 abort_code; /* Local/remote abort code */ |
601 | int error; /* Local error incurred */ | |
cf13258f DH |
602 | enum rxrpc_call_state state; /* current state of call */ |
603 | enum rxrpc_call_completion completion; /* Call completion condition */ | |
a0575429 | 604 | refcount_t ref; |
dabe5a79 | 605 | u16 service_id; /* service ID */ |
278ac0cd | 606 | u8 security_ix; /* Security type */ |
e138aa7d | 607 | enum rxrpc_interruptibility interruptibility; /* At what point call may be interrupted */ |
dabe5a79 DH |
608 | u32 call_id; /* call ID on connection */ |
609 | u32 cid; /* connection ID plus channel index */ | |
610 | int debug_id; /* debug ID for printks */ | |
8e83134d DH |
611 | unsigned short rx_pkt_offset; /* Current recvmsg packet offset */ |
612 | unsigned short rx_pkt_len; /* Current recvmsg packet len */ | |
f9c32435 | 613 | bool rx_pkt_last; /* Current recvmsg packet is last */ |
17926a79 | 614 | |
248f219c DH |
615 | /* Rx/Tx circular buffer, depending on phase. |
616 | * | |
617 | * In the Rx phase, packets are annotated with 0 or the number of the | |
618 | * segment of a jumbo packet each buffer refers to. There can be up to | |
619 | * 47 segments in a maximum-size UDP packet. | |
620 | * | |
621 | * In the Tx phase, packets are annotated with which buffers have been | |
622 | * acked. | |
623 | */ | |
624 | #define RXRPC_RXTX_BUFF_SIZE 64 | |
625 | #define RXRPC_RXTX_BUFF_MASK (RXRPC_RXTX_BUFF_SIZE - 1) | |
4075295a | 626 | #define RXRPC_INIT_RX_WINDOW_SIZE 63 |
248f219c DH |
627 | struct sk_buff **rxtx_buffer; |
628 | u8 *rxtx_annotations; | |
629 | #define RXRPC_TX_ANNO_ACK 0 | |
630 | #define RXRPC_TX_ANNO_UNACK 1 | |
631 | #define RXRPC_TX_ANNO_NAK 2 | |
632 | #define RXRPC_TX_ANNO_RETRANS 3 | |
f07373ea | 633 | #define RXRPC_TX_ANNO_MASK 0x03 |
70790dbe DH |
634 | #define RXRPC_TX_ANNO_LAST 0x04 |
635 | #define RXRPC_TX_ANNO_RESENT 0x08 | |
636 | ||
e2de6c40 | 637 | #define RXRPC_RX_ANNO_SUBPACKET 0x3f /* Subpacket number in jumbogram */ |
248f219c DH |
638 | #define RXRPC_RX_ANNO_VERIFIED 0x80 /* Set if verified and decrypted */ |
639 | rxrpc_seq_t tx_hard_ack; /* Dead slot in buffer; the first transmitted but | |
640 | * not hard-ACK'd packet follows this. | |
641 | */ | |
642 | rxrpc_seq_t tx_top; /* Highest Tx slot allocated. */ | |
c7e86acf | 643 | u16 tx_backoff; /* Delay to insert due to Tx failure */ |
57494343 DH |
644 | |
645 | /* TCP-style slow-start congestion control [RFC5681]. Since the SMSS | |
646 | * is fixed, we keep these numbers in terms of segments (ie. DATA | |
647 | * packets) rather than bytes. | |
648 | */ | |
649 | #define RXRPC_TX_SMSS RXRPC_JUMBO_DATALEN | |
650 | u8 cong_cwnd; /* Congestion window size */ | |
651 | u8 cong_extra; /* Extra to send for congestion management */ | |
652 | u8 cong_ssthresh; /* Slow-start threshold */ | |
653 | enum rxrpc_congest_mode cong_mode:8; /* Congestion management mode */ | |
654 | u8 cong_dup_acks; /* Count of ACKs showing missing packets */ | |
655 | u8 cong_cumul_acks; /* Cumulative ACK count */ | |
656 | ktime_t cong_tstamp; /* Last time cwnd was changed */ | |
657 | ||
248f219c DH |
658 | rxrpc_seq_t rx_hard_ack; /* Dead slot in buffer; the first received but not |
659 | * consumed packet follows this. | |
17926a79 | 660 | */ |
248f219c DH |
661 | rxrpc_seq_t rx_top; /* Highest Rx slot allocated. */ |
662 | rxrpc_seq_t rx_expect_next; /* Expected next packet sequence number */ | |
1a025028 | 663 | rxrpc_serial_t rx_serial; /* Highest serial received for this call */ |
248f219c DH |
664 | u8 rx_winsize; /* Size of Rx window */ |
665 | u8 tx_winsize; /* Maximum size of Tx window */ | |
71f3ca40 | 666 | bool tx_phase; /* T if transmission phase, F if receive phase */ |
75e42126 | 667 | u8 nr_jumbo_bad; /* Number of jumbo dups/exceeds-windows */ |
17926a79 | 668 | |
c1e15b49 DH |
669 | spinlock_t input_lock; /* Lock for packet input to this call */ |
670 | ||
8940ba3c | 671 | /* Receive-phase ACK management (ACKs we send). */ |
4e36a95e | 672 | u8 ackr_reason; /* reason to ACK */ |
0d12f8a4 | 673 | rxrpc_serial_t ackr_serial; /* serial of packet being ACK'd */ |
81524b63 | 674 | rxrpc_seq_t ackr_highest_seq; /* Higest sequence number received */ |
9a3dedcf DH |
675 | atomic_t ackr_nr_unacked; /* Number of unacked packets */ |
676 | atomic_t ackr_nr_consumed; /* Number of packets needing hard ACK */ | |
a5af7e1f | 677 | |
4700c4d8 DH |
678 | /* RTT management */ |
679 | rxrpc_serial_t rtt_serial[4]; /* Serial number of DATA or PING sent */ | |
680 | ktime_t rtt_sent_at[4]; /* Time packet sent */ | |
681 | unsigned long rtt_avail; /* Mask of available slots in bits 0-3, | |
682 | * Mask of pending samples in 8-11 */ | |
683 | #define RXRPC_CALL_RTT_AVAIL_MASK 0xf | |
684 | #define RXRPC_CALL_RTT_PEND_SHIFT 8 | |
17926a79 | 685 | |
8940ba3c | 686 | /* Transmission-phase ACK management (ACKs we've received). */ |
57494343 | 687 | ktime_t acks_latest_ts; /* Timestamp of latest ACK received */ |
8940ba3c | 688 | rxrpc_seq_t acks_first_seq; /* first sequence number received */ |
81524b63 | 689 | rxrpc_seq_t acks_prev_seq; /* Highest previousPacket received */ |
31a1b989 | 690 | rxrpc_seq_t acks_lowest_nak; /* Lowest NACK in the buffer (or ==tx_hard_ack) */ |
bd1fdf8c DH |
691 | rxrpc_seq_t acks_lost_top; /* tx_top at the time lost-ack ping sent */ |
692 | rxrpc_serial_t acks_lost_ping; /* Serial number of probe ACK */ | |
31a1b989 DH |
693 | }; |
694 | ||
695 | /* | |
57494343 | 696 | * Summary of a new ACK and the changes it made to the Tx buffer packet states. |
31a1b989 DH |
697 | */ |
698 | struct rxrpc_ack_summary { | |
699 | u8 ack_reason; | |
700 | u8 nr_acks; /* Number of ACKs in packet */ | |
701 | u8 nr_nacks; /* Number of NACKs in packet */ | |
702 | u8 nr_new_acks; /* Number of new ACKs in packet */ | |
703 | u8 nr_new_nacks; /* Number of new NACKs in packet */ | |
704 | u8 nr_rot_new_acks; /* Number of rotated new ACKs */ | |
705 | bool new_low_nack; /* T if new low NACK found */ | |
57494343 DH |
706 | bool retrans_timeo; /* T if reTx due to timeout happened */ |
707 | u8 flight_size; /* Number of unreceived transmissions */ | |
708 | /* Place to stash values for tracing */ | |
709 | enum rxrpc_congest_mode mode:8; | |
710 | u8 cwnd; | |
711 | u8 ssthresh; | |
712 | u8 dup_acks; | |
713 | u8 cumulative_acks; | |
17926a79 DH |
714 | }; |
715 | ||
48124178 DH |
716 | /* |
717 | * sendmsg() cmsg-specified parameters. | |
718 | */ | |
719 | enum rxrpc_command { | |
720 | RXRPC_CMD_SEND_DATA, /* send data message */ | |
721 | RXRPC_CMD_SEND_ABORT, /* request abort generation */ | |
48124178 | 722 | RXRPC_CMD_REJECT_BUSY, /* [server] reject a call as busy */ |
2d914c1b | 723 | RXRPC_CMD_CHARGE_ACCEPT, /* [server] charge accept preallocation */ |
48124178 DH |
724 | }; |
725 | ||
726 | struct rxrpc_call_params { | |
727 | s64 tx_total_len; /* Total Tx data length (if send data) */ | |
728 | unsigned long user_call_ID; /* User's call ID */ | |
729 | struct { | |
730 | u32 hard; /* Maximum lifetime (sec) */ | |
731 | u32 idle; /* Max time since last data packet (msec) */ | |
732 | u32 normal; /* Max time since last call packet (msec) */ | |
733 | } timeouts; | |
734 | u8 nr_timeouts; /* Number of timeouts specified */ | |
b7a7d674 | 735 | bool kernel; /* T if kernel is making the call */ |
e138aa7d | 736 | enum rxrpc_interruptibility interruptibility; /* How is interruptible is the call? */ |
48124178 DH |
737 | }; |
738 | ||
739 | struct rxrpc_send_params { | |
740 | struct rxrpc_call_params call; | |
741 | u32 abort_code; /* Abort code to Tx (if abort) */ | |
742 | enum rxrpc_command command : 8; /* The command to implement */ | |
743 | bool exclusive; /* Shared or exclusive call */ | |
744 | bool upgrade; /* If the connection is upgradeable */ | |
745 | }; | |
746 | ||
df844fd4 DH |
747 | #include <trace/events/rxrpc.h> |
748 | ||
17926a79 | 749 | /* |
651350d1 | 750 | * af_rxrpc.c |
17926a79 | 751 | */ |
71f3ca40 | 752 | extern atomic_t rxrpc_n_tx_skbs, rxrpc_n_rx_skbs; |
651350d1 | 753 | extern struct workqueue_struct *rxrpc_workqueue; |
17926a79 DH |
754 | |
755 | /* | |
0d81a51a | 756 | * call_accept.c |
17926a79 | 757 | */ |
00e90712 DH |
758 | int rxrpc_service_prealloc(struct rxrpc_sock *, gfp_t); |
759 | void rxrpc_discard_prealloc(struct rxrpc_sock *); | |
248f219c | 760 | struct rxrpc_call *rxrpc_new_incoming_call(struct rxrpc_local *, |
0099dc58 | 761 | struct rxrpc_sock *, |
248f219c | 762 | struct sk_buff *); |
4f95dd78 | 763 | void rxrpc_accept_incoming_calls(struct rxrpc_local *); |
2d914c1b | 764 | int rxrpc_user_charge_accept(struct rxrpc_sock *, unsigned long); |
17926a79 DH |
765 | |
766 | /* | |
0d81a51a | 767 | * call_event.c |
17926a79 | 768 | */ |
e8c3af6b | 769 | void rxrpc_propose_ACK(struct rxrpc_call *, u8, u32, bool, bool, |
9c7ad434 | 770 | enum rxrpc_propose_ack_trace); |
c1b1203d | 771 | void rxrpc_process_call(struct work_struct *); |
17926a79 | 772 | |
4a7f62f9 DH |
773 | void rxrpc_reduce_call_timer(struct rxrpc_call *call, |
774 | unsigned long expire_at, | |
775 | unsigned long now, | |
776 | enum rxrpc_timer_trace why); | |
777 | ||
778 | void rxrpc_delete_call_timer(struct rxrpc_call *call); | |
a158bdd3 | 779 | |
17926a79 | 780 | /* |
0d81a51a | 781 | * call_object.c |
17926a79 | 782 | */ |
f5c17aae DH |
783 | extern const char *const rxrpc_call_states[]; |
784 | extern const char *const rxrpc_call_completions[]; | |
dad8aff7 | 785 | extern unsigned int rxrpc_max_call_lifetime; |
17926a79 | 786 | extern struct kmem_cache *rxrpc_call_jar; |
17926a79 | 787 | |
2341e077 | 788 | struct rxrpc_call *rxrpc_find_call_by_user_ID(struct rxrpc_sock *, unsigned long); |
a25e21f0 | 789 | struct rxrpc_call *rxrpc_alloc_call(struct rxrpc_sock *, gfp_t, unsigned int); |
2341e077 | 790 | struct rxrpc_call *rxrpc_new_client_call(struct rxrpc_sock *, |
19ffa01c | 791 | struct rxrpc_conn_parameters *, |
999b69f8 | 792 | struct sockaddr_rxrpc *, |
a25e21f0 DH |
793 | struct rxrpc_call_params *, gfp_t, |
794 | unsigned int); | |
248f219c DH |
795 | void rxrpc_incoming_call(struct rxrpc_sock *, struct rxrpc_call *, |
796 | struct sk_buff *); | |
8d94aa38 | 797 | void rxrpc_release_call(struct rxrpc_sock *, struct rxrpc_call *); |
c1b1203d | 798 | void rxrpc_release_calls_on_socket(struct rxrpc_sock *); |
8d94aa38 DH |
799 | bool __rxrpc_queue_call(struct rxrpc_call *); |
800 | bool rxrpc_queue_call(struct rxrpc_call *); | |
e34d4234 | 801 | void rxrpc_see_call(struct rxrpc_call *); |
4a7f62f9 | 802 | bool rxrpc_try_get_call(struct rxrpc_call *call, enum rxrpc_call_trace op); |
fff72429 DH |
803 | void rxrpc_get_call(struct rxrpc_call *, enum rxrpc_call_trace); |
804 | void rxrpc_put_call(struct rxrpc_call *, enum rxrpc_call_trace); | |
00e90712 | 805 | void rxrpc_cleanup_call(struct rxrpc_call *); |
2baec2c3 | 806 | void rxrpc_destroy_all_calls(struct rxrpc_net *); |
17926a79 | 807 | |
dabe5a79 DH |
808 | static inline bool rxrpc_is_service_call(const struct rxrpc_call *call) |
809 | { | |
810 | return test_bit(RXRPC_CALL_IS_SERVICE, &call->flags); | |
811 | } | |
812 | ||
813 | static inline bool rxrpc_is_client_call(const struct rxrpc_call *call) | |
814 | { | |
815 | return !rxrpc_is_service_call(call); | |
816 | } | |
817 | ||
4a3388c8 DH |
818 | /* |
819 | * conn_client.c | |
820 | */ | |
45025bce | 821 | extern unsigned int rxrpc_reap_client_connections; |
a158bdd3 DH |
822 | extern unsigned long rxrpc_conn_idle_client_expiry; |
823 | extern unsigned long rxrpc_conn_idle_client_fast_expiry; | |
4a3388c8 DH |
824 | extern struct idr rxrpc_client_conn_ids; |
825 | ||
eb9b9d22 | 826 | void rxrpc_destroy_client_conn_ids(void); |
245500d8 DH |
827 | struct rxrpc_bundle *rxrpc_get_bundle(struct rxrpc_bundle *); |
828 | void rxrpc_put_bundle(struct rxrpc_bundle *); | |
5e33a23b DH |
829 | int rxrpc_connect_call(struct rxrpc_sock *, struct rxrpc_call *, |
830 | struct rxrpc_conn_parameters *, struct sockaddr_rxrpc *, | |
831 | gfp_t); | |
45025bce | 832 | void rxrpc_expose_client_call(struct rxrpc_call *); |
245500d8 | 833 | void rxrpc_disconnect_client_call(struct rxrpc_bundle *, struct rxrpc_call *); |
45025bce | 834 | void rxrpc_put_client_conn(struct rxrpc_connection *); |
2baec2c3 DH |
835 | void rxrpc_discard_expired_client_conns(struct work_struct *); |
836 | void rxrpc_destroy_all_client_connections(struct rxrpc_net *); | |
d12040b6 | 837 | void rxrpc_clean_up_local_conns(struct rxrpc_local *); |
4a3388c8 | 838 | |
17926a79 | 839 | /* |
0d81a51a DH |
840 | * conn_event.c |
841 | */ | |
842 | void rxrpc_process_connection(struct work_struct *); | |
ddc7834a | 843 | void rxrpc_process_delayed_final_acks(struct rxrpc_connection *, bool); |
0d81a51a DH |
844 | |
845 | /* | |
846 | * conn_object.c | |
17926a79 | 847 | */ |
dad8aff7 | 848 | extern unsigned int rxrpc_connection_expiry; |
f859ab61 | 849 | extern unsigned int rxrpc_closed_conn_expiry; |
17926a79 | 850 | |
c6d2b8d7 | 851 | struct rxrpc_connection *rxrpc_alloc_connection(gfp_t); |
8496af50 | 852 | struct rxrpc_connection *rxrpc_find_connection_rcu(struct rxrpc_local *, |
0099dc58 DH |
853 | struct sk_buff *, |
854 | struct rxrpc_peer **); | |
45025bce | 855 | void __rxrpc_disconnect_call(struct rxrpc_connection *, struct rxrpc_call *); |
999b69f8 | 856 | void rxrpc_disconnect_call(struct rxrpc_call *); |
45025bce | 857 | void rxrpc_kill_connection(struct rxrpc_connection *); |
363deeab DH |
858 | bool rxrpc_queue_conn(struct rxrpc_connection *); |
859 | void rxrpc_see_connection(struct rxrpc_connection *); | |
245500d8 | 860 | struct rxrpc_connection *rxrpc_get_connection(struct rxrpc_connection *); |
363deeab DH |
861 | struct rxrpc_connection *rxrpc_get_connection_maybe(struct rxrpc_connection *); |
862 | void rxrpc_put_service_conn(struct rxrpc_connection *); | |
2baec2c3 DH |
863 | void rxrpc_service_connection_reaper(struct work_struct *); |
864 | void rxrpc_destroy_all_connections(struct rxrpc_net *); | |
17926a79 | 865 | |
19ffa01c DH |
866 | static inline bool rxrpc_conn_is_client(const struct rxrpc_connection *conn) |
867 | { | |
868 | return conn->out_clientflag; | |
869 | } | |
870 | ||
871 | static inline bool rxrpc_conn_is_service(const struct rxrpc_connection *conn) | |
872 | { | |
e8d70ce1 | 873 | return !rxrpc_conn_is_client(conn); |
19ffa01c DH |
874 | } |
875 | ||
f51b4480 DH |
876 | static inline void rxrpc_put_connection(struct rxrpc_connection *conn) |
877 | { | |
45025bce DH |
878 | if (!conn) |
879 | return; | |
880 | ||
363deeab DH |
881 | if (rxrpc_conn_is_client(conn)) |
882 | rxrpc_put_client_conn(conn); | |
883 | else | |
884 | rxrpc_put_service_conn(conn); | |
5acbee46 DH |
885 | } |
886 | ||
3136ef49 DH |
887 | static inline void rxrpc_reduce_conn_timer(struct rxrpc_connection *conn, |
888 | unsigned long expire_at) | |
889 | { | |
890 | timer_reduce(&conn->timer, expire_at); | |
891 | } | |
892 | ||
7877a4a4 DH |
893 | /* |
894 | * conn_service.c | |
895 | */ | |
8496af50 DH |
896 | struct rxrpc_connection *rxrpc_find_service_conn_rcu(struct rxrpc_peer *, |
897 | struct sk_buff *); | |
2baec2c3 | 898 | struct rxrpc_connection *rxrpc_prealloc_service_connection(struct rxrpc_net *, gfp_t); |
063c60d3 | 899 | void rxrpc_new_incoming_connection(struct rxrpc_sock *, struct rxrpc_connection *, |
ec832bd0 | 900 | const struct rxrpc_security *, struct sk_buff *); |
001c1122 | 901 | void rxrpc_unpublish_service_conn(struct rxrpc_connection *); |
7877a4a4 | 902 | |
17926a79 | 903 | /* |
0d81a51a | 904 | * input.c |
17926a79 | 905 | */ |
5271953c | 906 | int rxrpc_input_packet(struct sock *, struct sk_buff *); |
17926a79 DH |
907 | |
908 | /* | |
0d81a51a | 909 | * insecure.c |
17926a79 | 910 | */ |
0d81a51a | 911 | extern const struct rxrpc_security rxrpc_no_security; |
17926a79 DH |
912 | |
913 | /* | |
0d81a51a | 914 | * key.c |
17926a79 | 915 | */ |
0d81a51a | 916 | extern struct key_type key_type_rxrpc; |
0d81a51a | 917 | |
a7b75c5a | 918 | int rxrpc_request_key(struct rxrpc_sock *, sockptr_t , int); |
10674a03 | 919 | int rxrpc_get_server_data_key(struct rxrpc_connection *, const void *, time64_t, |
0d81a51a | 920 | u32); |
17926a79 | 921 | |
87563616 DH |
922 | /* |
923 | * local_event.c | |
924 | */ | |
4f95dd78 | 925 | extern void rxrpc_process_local_events(struct rxrpc_local *); |
87563616 | 926 | |
17926a79 | 927 | /* |
0d81a51a | 928 | * local_object.c |
17926a79 | 929 | */ |
2baec2c3 | 930 | struct rxrpc_local *rxrpc_lookup_local(struct net *, const struct sockaddr_rxrpc *); |
09d2bf59 DH |
931 | struct rxrpc_local *rxrpc_get_local(struct rxrpc_local *); |
932 | struct rxrpc_local *rxrpc_get_local_maybe(struct rxrpc_local *); | |
933 | void rxrpc_put_local(struct rxrpc_local *); | |
730c5fd4 DH |
934 | struct rxrpc_local *rxrpc_use_local(struct rxrpc_local *); |
935 | void rxrpc_unuse_local(struct rxrpc_local *); | |
09d2bf59 | 936 | void rxrpc_queue_local(struct rxrpc_local *); |
2baec2c3 | 937 | void rxrpc_destroy_all_locals(struct rxrpc_net *); |
17926a79 | 938 | |
04d36d74 DH |
939 | static inline bool __rxrpc_unuse_local(struct rxrpc_local *local) |
940 | { | |
941 | return atomic_dec_return(&local->active_users) == 0; | |
942 | } | |
943 | ||
944 | static inline bool __rxrpc_use_local(struct rxrpc_local *local) | |
945 | { | |
946 | return atomic_fetch_add_unless(&local->active_users, 1, 0) != 0; | |
947 | } | |
948 | ||
17926a79 | 949 | /* |
0d81a51a | 950 | * misc.c |
17926a79 | 951 | */ |
0d81a51a | 952 | extern unsigned int rxrpc_max_backlog __read_mostly; |
a158bdd3 DH |
953 | extern unsigned long rxrpc_requested_ack_delay; |
954 | extern unsigned long rxrpc_soft_ack_delay; | |
955 | extern unsigned long rxrpc_idle_ack_delay; | |
0d81a51a DH |
956 | extern unsigned int rxrpc_rx_window_size; |
957 | extern unsigned int rxrpc_rx_mtu; | |
958 | extern unsigned int rxrpc_rx_jumbo_max; | |
17926a79 | 959 | |
0d81a51a DH |
960 | extern const s8 rxrpc_ack_priority[]; |
961 | ||
2baec2c3 DH |
962 | /* |
963 | * net_ns.c | |
964 | */ | |
965 | extern unsigned int rxrpc_net_id; | |
966 | extern struct pernet_operations rxrpc_net_ops; | |
967 | ||
968 | static inline struct rxrpc_net *rxrpc_net(struct net *net) | |
969 | { | |
970 | return net_generic(net, rxrpc_net_id); | |
971 | } | |
972 | ||
17926a79 | 973 | /* |
0d81a51a | 974 | * output.c |
17926a79 | 975 | */ |
bd1fdf8c | 976 | int rxrpc_send_ack_packet(struct rxrpc_call *, bool, rxrpc_serial_t *); |
26cb02aa | 977 | int rxrpc_send_abort_packet(struct rxrpc_call *); |
a1767077 | 978 | int rxrpc_send_data_packet(struct rxrpc_call *, struct sk_buff *, bool); |
248f219c | 979 | void rxrpc_reject_packets(struct rxrpc_local *); |
ace45bec | 980 | void rxrpc_send_keepalive(struct rxrpc_peer *); |
17926a79 DH |
981 | |
982 | /* | |
abe89ef0 | 983 | * peer_event.c |
0d81a51a | 984 | */ |
ac56a0b4 | 985 | void rxrpc_encap_err_rcv(struct sock *sk, struct sk_buff *skb, unsigned int udp_offset); |
abe89ef0 | 986 | void rxrpc_error_report(struct sock *); |
ace45bec | 987 | void rxrpc_peer_keepalive_worker(struct work_struct *); |
0d81a51a DH |
988 | |
989 | /* | |
990 | * peer_object.c | |
17926a79 | 991 | */ |
be6e6707 DH |
992 | struct rxrpc_peer *rxrpc_lookup_peer_rcu(struct rxrpc_local *, |
993 | const struct sockaddr_rxrpc *); | |
5e33a23b | 994 | struct rxrpc_peer *rxrpc_lookup_peer(struct rxrpc_sock *, struct rxrpc_local *, |
be6e6707 DH |
995 | struct sockaddr_rxrpc *, gfp_t); |
996 | struct rxrpc_peer *rxrpc_alloc_peer(struct rxrpc_local *, gfp_t); | |
5e33a23b DH |
997 | void rxrpc_new_incoming_peer(struct rxrpc_sock *, struct rxrpc_local *, |
998 | struct rxrpc_peer *); | |
17226f12 | 999 | void rxrpc_destroy_all_peers(struct rxrpc_net *); |
1159d4b4 DH |
1000 | struct rxrpc_peer *rxrpc_get_peer(struct rxrpc_peer *); |
1001 | struct rxrpc_peer *rxrpc_get_peer_maybe(struct rxrpc_peer *); | |
1002 | void rxrpc_put_peer(struct rxrpc_peer *); | |
60034d3d | 1003 | void rxrpc_put_peer_locked(struct rxrpc_peer *); |
17926a79 DH |
1004 | |
1005 | /* | |
0d81a51a | 1006 | * proc.c |
17926a79 | 1007 | */ |
c3506372 CH |
1008 | extern const struct seq_operations rxrpc_call_seq_ops; |
1009 | extern const struct seq_operations rxrpc_connection_seq_ops; | |
bc0e7cf4 | 1010 | extern const struct seq_operations rxrpc_peer_seq_ops; |
33912c26 | 1011 | extern const struct seq_operations rxrpc_local_seq_ops; |
17926a79 DH |
1012 | |
1013 | /* | |
0d81a51a | 1014 | * recvmsg.c |
17926a79 | 1015 | */ |
248f219c | 1016 | void rxrpc_notify_socket(struct rxrpc_call *); |
3067bf8c DH |
1017 | bool __rxrpc_set_call_completion(struct rxrpc_call *, enum rxrpc_call_completion, u32, int); |
1018 | bool rxrpc_set_call_completion(struct rxrpc_call *, enum rxrpc_call_completion, u32, int); | |
1019 | bool __rxrpc_call_completed(struct rxrpc_call *); | |
1020 | bool rxrpc_call_completed(struct rxrpc_call *); | |
1021 | bool __rxrpc_abort_call(const char *, struct rxrpc_call *, rxrpc_seq_t, u32, int); | |
1022 | bool rxrpc_abort_call(const char *, struct rxrpc_call *, rxrpc_seq_t, u32, int); | |
1b784140 | 1023 | int rxrpc_recvmsg(struct socket *, struct msghdr *, size_t, int); |
17926a79 | 1024 | |
3067bf8c DH |
1025 | /* |
1026 | * Abort a call due to a protocol error. | |
1027 | */ | |
1028 | static inline bool __rxrpc_abort_eproto(struct rxrpc_call *call, | |
1029 | struct sk_buff *skb, | |
1030 | const char *eproto_why, | |
1031 | const char *why, | |
1032 | u32 abort_code) | |
1033 | { | |
1034 | struct rxrpc_skb_priv *sp = rxrpc_skb(skb); | |
1035 | ||
1036 | trace_rxrpc_rx_eproto(call, sp->hdr.serial, eproto_why); | |
1037 | return rxrpc_abort_call(why, call, sp->hdr.seq, abort_code, -EPROTO); | |
1038 | } | |
1039 | ||
1040 | #define rxrpc_abort_eproto(call, skb, eproto_why, abort_why, abort_code) \ | |
1041 | __rxrpc_abort_eproto((call), (skb), tracepoint_string(eproto_why), \ | |
1042 | (abort_why), (abort_code)) | |
1043 | ||
c410bf01 DH |
1044 | /* |
1045 | * rtt.c | |
1046 | */ | |
4700c4d8 | 1047 | void rxrpc_peer_add_rtt(struct rxrpc_call *, enum rxrpc_rtt_rx_trace, int, |
c410bf01 DH |
1048 | rxrpc_serial_t, rxrpc_serial_t, ktime_t, ktime_t); |
1049 | unsigned long rxrpc_get_rto_backoff(struct rxrpc_peer *, bool); | |
1050 | void rxrpc_peer_init_rtt(struct rxrpc_peer *); | |
1051 | ||
17926a79 | 1052 | /* |
0d81a51a DH |
1053 | * rxkad.c |
1054 | */ | |
1055 | #ifdef CONFIG_RXKAD | |
1056 | extern const struct rxrpc_security rxkad; | |
1057 | #endif | |
1058 | ||
1059 | /* | |
1060 | * security.c | |
17926a79 | 1061 | */ |
648af7fc | 1062 | int __init rxrpc_init_security(void); |
12da59fc | 1063 | const struct rxrpc_security *rxrpc_security_lookup(u8); |
648af7fc | 1064 | void rxrpc_exit_security(void); |
c1b1203d | 1065 | int rxrpc_init_client_conn_security(struct rxrpc_connection *); |
ec832bd0 DH |
1066 | const struct rxrpc_security *rxrpc_get_incoming_security(struct rxrpc_sock *, |
1067 | struct sk_buff *); | |
1068 | struct key *rxrpc_look_up_server_security(struct rxrpc_connection *, | |
1069 | struct sk_buff *, u32, u32); | |
71a17de3 | 1070 | |
0b58b8a1 DH |
1071 | /* |
1072 | * sendmsg.c | |
1073 | */ | |
1074 | int rxrpc_do_sendmsg(struct rxrpc_sock *, struct msghdr *, size_t); | |
17926a79 | 1075 | |
ca7fb100 DH |
1076 | /* |
1077 | * server_key.c | |
1078 | */ | |
1079 | extern struct key_type key_type_rxrpc_s; | |
1080 | ||
1081 | int rxrpc_server_keyring(struct rxrpc_sock *, sockptr_t, int); | |
1082 | ||
17926a79 | 1083 | /* |
0d81a51a | 1084 | * skbuff.c |
17926a79 | 1085 | */ |
d001648e | 1086 | void rxrpc_kernel_data_consumed(struct rxrpc_call *, struct sk_buff *); |
c1b1203d | 1087 | void rxrpc_packet_destructor(struct sk_buff *); |
71f3ca40 DH |
1088 | void rxrpc_new_skb(struct sk_buff *, enum rxrpc_skb_trace); |
1089 | void rxrpc_see_skb(struct sk_buff *, enum rxrpc_skb_trace); | |
d0d5c0cd | 1090 | void rxrpc_eaten_skb(struct sk_buff *, enum rxrpc_skb_trace); |
71f3ca40 DH |
1091 | void rxrpc_get_skb(struct sk_buff *, enum rxrpc_skb_trace); |
1092 | void rxrpc_free_skb(struct sk_buff *, enum rxrpc_skb_trace); | |
df844fd4 | 1093 | void rxrpc_purge_queue(struct sk_buff_head *); |
17926a79 | 1094 | |
5873c083 DH |
1095 | /* |
1096 | * sysctl.c | |
1097 | */ | |
1098 | #ifdef CONFIG_SYSCTL | |
1099 | extern int __init rxrpc_sysctl_init(void); | |
1100 | extern void rxrpc_sysctl_exit(void); | |
1101 | #else | |
1102 | static inline int __init rxrpc_sysctl_init(void) { return 0; } | |
1103 | static inline void rxrpc_sysctl_exit(void) {} | |
1104 | #endif | |
1105 | ||
be6e6707 DH |
1106 | /* |
1107 | * utils.c | |
1108 | */ | |
5a790b73 | 1109 | int rxrpc_extract_addr_from_skb(struct sockaddr_rxrpc *, struct sk_buff *); |
be6e6707 | 1110 | |
248f219c DH |
1111 | static inline bool before(u32 seq1, u32 seq2) |
1112 | { | |
1113 | return (s32)(seq1 - seq2) < 0; | |
1114 | } | |
1115 | static inline bool before_eq(u32 seq1, u32 seq2) | |
1116 | { | |
1117 | return (s32)(seq1 - seq2) <= 0; | |
1118 | } | |
1119 | static inline bool after(u32 seq1, u32 seq2) | |
1120 | { | |
1121 | return (s32)(seq1 - seq2) > 0; | |
1122 | } | |
1123 | static inline bool after_eq(u32 seq1, u32 seq2) | |
1124 | { | |
1125 | return (s32)(seq1 - seq2) >= 0; | |
1126 | } | |
1127 | ||
17926a79 DH |
1128 | /* |
1129 | * debug tracing | |
1130 | */ | |
95c96174 | 1131 | extern unsigned int rxrpc_debug; |
17926a79 DH |
1132 | |
1133 | #define dbgprintk(FMT,...) \ | |
9f389f4b | 1134 | printk("[%-6.6s] "FMT"\n", current->comm ,##__VA_ARGS__) |
17926a79 | 1135 | |
0dc47877 HH |
1136 | #define kenter(FMT,...) dbgprintk("==> %s("FMT")",__func__ ,##__VA_ARGS__) |
1137 | #define kleave(FMT,...) dbgprintk("<== %s()"FMT"",__func__ ,##__VA_ARGS__) | |
17926a79 DH |
1138 | #define kdebug(FMT,...) dbgprintk(" "FMT ,##__VA_ARGS__) |
1139 | #define kproto(FMT,...) dbgprintk("### "FMT ,##__VA_ARGS__) | |
1140 | #define knet(FMT,...) dbgprintk("@@@ "FMT ,##__VA_ARGS__) | |
1141 | ||
1142 | ||
1143 | #if defined(__KDEBUG) | |
1144 | #define _enter(FMT,...) kenter(FMT,##__VA_ARGS__) | |
1145 | #define _leave(FMT,...) kleave(FMT,##__VA_ARGS__) | |
1146 | #define _debug(FMT,...) kdebug(FMT,##__VA_ARGS__) | |
1147 | #define _proto(FMT,...) kproto(FMT,##__VA_ARGS__) | |
1148 | #define _net(FMT,...) knet(FMT,##__VA_ARGS__) | |
1149 | ||
1150 | #elif defined(CONFIG_AF_RXRPC_DEBUG) | |
1151 | #define RXRPC_DEBUG_KENTER 0x01 | |
1152 | #define RXRPC_DEBUG_KLEAVE 0x02 | |
1153 | #define RXRPC_DEBUG_KDEBUG 0x04 | |
1154 | #define RXRPC_DEBUG_KPROTO 0x08 | |
1155 | #define RXRPC_DEBUG_KNET 0x10 | |
1156 | ||
1157 | #define _enter(FMT,...) \ | |
1158 | do { \ | |
1159 | if (unlikely(rxrpc_debug & RXRPC_DEBUG_KENTER)) \ | |
1160 | kenter(FMT,##__VA_ARGS__); \ | |
1161 | } while (0) | |
1162 | ||
1163 | #define _leave(FMT,...) \ | |
1164 | do { \ | |
1165 | if (unlikely(rxrpc_debug & RXRPC_DEBUG_KLEAVE)) \ | |
1166 | kleave(FMT,##__VA_ARGS__); \ | |
1167 | } while (0) | |
1168 | ||
1169 | #define _debug(FMT,...) \ | |
1170 | do { \ | |
1171 | if (unlikely(rxrpc_debug & RXRPC_DEBUG_KDEBUG)) \ | |
1172 | kdebug(FMT,##__VA_ARGS__); \ | |
1173 | } while (0) | |
1174 | ||
1175 | #define _proto(FMT,...) \ | |
1176 | do { \ | |
1177 | if (unlikely(rxrpc_debug & RXRPC_DEBUG_KPROTO)) \ | |
1178 | kproto(FMT,##__VA_ARGS__); \ | |
1179 | } while (0) | |
1180 | ||
1181 | #define _net(FMT,...) \ | |
1182 | do { \ | |
1183 | if (unlikely(rxrpc_debug & RXRPC_DEBUG_KNET)) \ | |
1184 | knet(FMT,##__VA_ARGS__); \ | |
1185 | } while (0) | |
1186 | ||
1187 | #else | |
12fdff3f DH |
1188 | #define _enter(FMT,...) no_printk("==> %s("FMT")",__func__ ,##__VA_ARGS__) |
1189 | #define _leave(FMT,...) no_printk("<== %s()"FMT"",__func__ ,##__VA_ARGS__) | |
1190 | #define _debug(FMT,...) no_printk(" "FMT ,##__VA_ARGS__) | |
1191 | #define _proto(FMT,...) no_printk("### "FMT ,##__VA_ARGS__) | |
1192 | #define _net(FMT,...) no_printk("@@@ "FMT ,##__VA_ARGS__) | |
17926a79 DH |
1193 | #endif |
1194 | ||
1195 | /* | |
1196 | * debug assertion checking | |
1197 | */ | |
1198 | #if 1 // defined(__KDEBUGALL) | |
1199 | ||
1200 | #define ASSERT(X) \ | |
1201 | do { \ | |
1202 | if (unlikely(!(X))) { \ | |
9b6d5398 | 1203 | pr_err("Assertion failed\n"); \ |
17926a79 DH |
1204 | BUG(); \ |
1205 | } \ | |
b4f1342f | 1206 | } while (0) |
17926a79 DH |
1207 | |
1208 | #define ASSERTCMP(X, OP, Y) \ | |
1209 | do { \ | |
cf13258f DH |
1210 | __typeof__(X) _x = (X); \ |
1211 | __typeof__(Y) _y = (__typeof__(X))(Y); \ | |
9b6d5398 | 1212 | if (unlikely(!(_x OP _y))) { \ |
cf13258f DH |
1213 | pr_err("Assertion failed - %lu(0x%lx) %s %lu(0x%lx) is false\n", \ |
1214 | (unsigned long)_x, (unsigned long)_x, #OP, \ | |
1215 | (unsigned long)_y, (unsigned long)_y); \ | |
17926a79 DH |
1216 | BUG(); \ |
1217 | } \ | |
b4f1342f | 1218 | } while (0) |
17926a79 DH |
1219 | |
1220 | #define ASSERTIF(C, X) \ | |
1221 | do { \ | |
1222 | if (unlikely((C) && !(X))) { \ | |
9b6d5398 | 1223 | pr_err("Assertion failed\n"); \ |
17926a79 DH |
1224 | BUG(); \ |
1225 | } \ | |
b4f1342f | 1226 | } while (0) |
17926a79 DH |
1227 | |
1228 | #define ASSERTIFCMP(C, X, OP, Y) \ | |
1229 | do { \ | |
cf13258f DH |
1230 | __typeof__(X) _x = (X); \ |
1231 | __typeof__(Y) _y = (__typeof__(X))(Y); \ | |
9b6d5398 JP |
1232 | if (unlikely((C) && !(_x OP _y))) { \ |
1233 | pr_err("Assertion failed - %lu(0x%lx) %s %lu(0x%lx) is false\n", \ | |
cf13258f DH |
1234 | (unsigned long)_x, (unsigned long)_x, #OP, \ |
1235 | (unsigned long)_y, (unsigned long)_y); \ | |
17926a79 DH |
1236 | BUG(); \ |
1237 | } \ | |
b4f1342f | 1238 | } while (0) |
17926a79 DH |
1239 | |
1240 | #else | |
1241 | ||
1242 | #define ASSERT(X) \ | |
1243 | do { \ | |
b4f1342f | 1244 | } while (0) |
17926a79 DH |
1245 | |
1246 | #define ASSERTCMP(X, OP, Y) \ | |
1247 | do { \ | |
b4f1342f | 1248 | } while (0) |
17926a79 DH |
1249 | |
1250 | #define ASSERTIF(C, X) \ | |
1251 | do { \ | |
b4f1342f | 1252 | } while (0) |
17926a79 DH |
1253 | |
1254 | #define ASSERTIFCMP(C, X, OP, Y) \ | |
1255 | do { \ | |
b4f1342f | 1256 | } while (0) |
17926a79 DH |
1257 | |
1258 | #endif /* __KDEBUGALL */ |