1 /* AF_RXRPC internal definitions
3 * Copyright (C) 2007 Red Hat, Inc. All Rights Reserved.
4 * Written by David Howells (dhowells@redhat.com)
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.
12 #include <linux/atomic.h>
13 #include <linux/seqlock.h>
14 #include <net/net_namespace.h>
15 #include <net/netns/generic.h>
17 #include <net/af_rxrpc.h>
18 #include <rxrpc/packet.h>
21 #define CHECK_SLAB_OKAY(X) \
22 BUG_ON(atomic_read((X)) >> (sizeof(atomic_t) - 2) == \
23 (POISON_FREE << 8 | POISON_FREE))
25 #define CHECK_SLAB_OKAY(X) do {} while (0)
28 #define FCRYPT_BSIZE 8
34 } __attribute__((aligned(8)));
36 #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))
40 struct rxrpc_connection;
43 * Mark applied to socket buffers.
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 */
57 * sk_state for RxRPC sockets
61 RXRPC_CLIENT_UNBOUND, /* Unbound socket used as client */
62 RXRPC_CLIENT_BOUND, /* client local address bound */
63 RXRPC_SERVER_BOUND, /* server local address bound */
64 RXRPC_SERVER_LISTENING, /* server listening for connections */
65 RXRPC_SERVER_LISTEN_DISABLED, /* server listening disabled */
66 RXRPC_CLOSE, /* socket is being closed */
70 * Per-network namespace data.
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 */
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;
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;
93 struct list_head local_endpoints;
94 struct mutex local_mutex; /* Lock for ->local_endpoints */
96 spinlock_t peer_hash_lock; /* Lock for ->peer_hash */
97 DECLARE_HASHTABLE (peer_hash, 10);
101 * Service backlog preallocation.
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.
108 struct 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];
122 * RxRPC socket definition
125 /* WARNING: sk has to be the first member */
127 rxrpc_notify_new_call_t notify_new_call; /* Func to notify of new call */
128 rxrpc_discard_new_call_t discard_new_call; /* Func to discard a new call */
129 struct rxrpc_local *local; /* local endpoint */
130 struct rxrpc_backlog *backlog; /* Preallocation for services */
131 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 */
136 struct key *key; /* security for this socket */
137 struct key *securities; /* list of server security descriptors */
138 struct rb_root calls; /* User ID -> call mapping */
140 #define RXRPC_SOCK_CONNECTED 0 /* connect_srx is set */
141 rwlock_t call_lock; /* lock for calls */
142 u32 min_sec_level; /* minimum security level */
143 #define RXRPC_SECURITY_MAX RXRPC_SECURITY_ENCRYPT
144 bool exclusive; /* Exclusive connection for a client socket */
145 sa_family_t family; /* Protocol family created with */
146 struct sockaddr_rxrpc srx; /* local address */
147 struct sockaddr_rxrpc connect_srx; /* Default client address from connect() */
150 #define rxrpc_sk(__sk) container_of((__sk), struct rxrpc_sock, sk)
153 * CPU-byteorder normalised Rx packet header.
155 struct 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 */
166 u16 _rsvd; /* reserved */
167 u16 cksum; /* kerberos security checksum */
169 u16 serviceId; /* service ID */
173 * RxRPC socket buffer private variables
174 * - max 48 bytes (struct sk_buff::cb)
176 struct rxrpc_skb_priv {
178 u8 nr_jumbo; /* Number of jumbo subpackets */
181 int remain; /* amount of space remaining for next write */
184 struct rxrpc_host_header hdr; /* RxRPC packet header from this packet */
187 #define rxrpc_skb(__skb) ((struct rxrpc_skb_priv *) &(__skb)->cb)
190 * RxRPC security module interface
192 struct rxrpc_security {
193 const char *name; /* name of this service */
194 u8 security_index; /* security type provided */
196 /* Initialise a security service */
199 /* Clean up a security service */
202 /* initialise a connection's security */
203 int (*init_connection_security)(struct rxrpc_connection *);
205 /* prime a connection's packet security */
206 int (*prime_packet_security)(struct rxrpc_connection *);
208 /* impose security on a packet */
209 int (*secure_packet)(struct rxrpc_call *,
214 /* verify the security on a received packet */
215 int (*verify_packet)(struct rxrpc_call *, struct sk_buff *,
216 unsigned int, unsigned int, rxrpc_seq_t, u16);
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 *);
222 /* issue a challenge */
223 int (*issue_challenge)(struct rxrpc_connection *);
225 /* respond to a challenge */
226 int (*respond_to_challenge)(struct rxrpc_connection *,
230 /* verify a response */
231 int (*verify_response)(struct rxrpc_connection *,
235 /* clear connection security */
236 void (*clear)(struct rxrpc_connection *);
240 * RxRPC local transport endpoint description
241 * - owned by a single AF_RXRPC socket
242 * - pointed to by transport socket struct sk_user_data
247 struct rxrpc_net *rxnet; /* The network ns in which this resides */
248 struct list_head link;
249 struct socket *socket; /* my UDP socket */
250 struct work_struct processor;
251 struct rxrpc_sock __rcu *service; /* Service(s) listening on this endpoint */
252 struct rw_semaphore defrag_sem; /* control re-enablement of IP DF bit */
253 struct sk_buff_head reject_queue; /* packets awaiting rejection */
254 struct sk_buff_head event_queue; /* endpoint event packets awaiting processing */
255 struct rb_root client_conns; /* Client connections by socket params */
256 spinlock_t client_conns_lock; /* Lock for client_conns */
257 spinlock_t lock; /* access lock */
258 rwlock_t services_lock; /* lock for services list */
259 int debug_id; /* debug ID for printks */
261 struct sockaddr_rxrpc srx; /* local address */
265 * RxRPC remote transport endpoint definition
266 * - matched by local endpoint, remote port, address and protocol type
269 struct rcu_head rcu; /* This must be first */
271 unsigned long hash_key;
272 struct hlist_node hash_link;
273 struct rxrpc_local *local;
274 struct hlist_head error_targets; /* targets for net error distribution */
275 struct work_struct error_distributor;
276 struct rb_root service_conns; /* Service connections */
277 seqlock_t service_conn_lock;
278 spinlock_t lock; /* access lock */
279 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) */
282 unsigned short hdrsize; /* header size (IP + UDP + RxRPC) */
283 int debug_id; /* debug ID for printks */
284 int error_report; /* Net (+0) or local (+1000000) to distribute */
285 #define RXRPC_LOCAL_ERROR_OFFSET 1000000
286 struct sockaddr_rxrpc srx; /* remote address */
288 /* calculated RTT cache */
289 #define RXRPC_RTT_CACHE_SIZE 32
290 ktime_t rtt_last_req; /* Time of last RTT request */
291 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 */
299 * Keys for matching a connection.
301 struct rxrpc_conn_proto {
304 u32 epoch; /* epoch of this connection */
305 u32 cid; /* connection ID */
311 struct 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 */
321 * Bits in the connection flags.
323 enum rxrpc_conn_flag {
324 RXRPC_CONN_HAS_IDR, /* Has a client conn ID assigned */
325 RXRPC_CONN_IN_SERVICE_CONNS, /* Conn is in peer->service_conns */
326 RXRPC_CONN_IN_CLIENT_CONNS, /* Conn is in local->client_conns */
327 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 */
333 * Events that can be raised upon a connection.
335 enum rxrpc_conn_event {
336 RXRPC_CONN_EV_CHALLENGE, /* Send challenge packet */
340 * The connection cache state.
342 enum 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 */
348 RXRPC_CONN__NR_CACHE_STATES
352 * The connection protocol state.
354 enum rxrpc_conn_proto_state {
355 RXRPC_CONN_UNUSED, /* Connection not yet attempted */
356 RXRPC_CONN_CLIENT, /* Client connection */
357 RXRPC_CONN_SERVICE_PREALLOC, /* Service connection preallocation */
358 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 */
363 RXRPC_CONN__NR_STATES
367 * RxRPC connection definition
368 * - matched by { local, peer, epoch, conn_id, direction }
369 * - each connection can only handle four simultaneous calls
371 struct rxrpc_connection {
372 struct rxrpc_conn_proto proto;
373 struct rxrpc_conn_parameters params;
377 struct list_head cache_link;
379 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 */
383 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 */
388 u8 last_type; /* Type of last packet */
393 } channels[RXRPC_MAXCALLS];
395 struct work_struct processor; /* connection event processor */
397 struct rb_node client_node; /* Node in local->client_conns */
398 struct rb_node service_node; /* Node in peer->service_conns */
400 struct list_head proc_link; /* link in procfs list */
401 struct list_head link; /* link in master connection list */
402 struct sk_buff_head rx_queue; /* received conn-level packets */
403 const struct rxrpc_security *security; /* applied security module */
404 struct key *server_key; /* security for this service */
405 struct crypto_skcipher *cipher; /* encryption handle */
406 struct rxrpc_crypt csum_iv; /* packet checksum base */
408 unsigned long events;
409 unsigned long idle_timestamp; /* Time at which last became idle */
410 spinlock_t state_lock; /* state-change lock */
411 enum rxrpc_conn_cache_state cache_state;
412 enum rxrpc_conn_proto_state state; /* current state of connection */
413 u32 local_abort; /* local abort code */
414 u32 remote_abort; /* remote abort code */
415 int debug_id; /* debug ID for printks */
416 atomic_t serial; /* packet serial number counter */
417 unsigned int hi_serial; /* highest serial number received */
418 u32 security_nonce; /* response re-use preventer */
419 u16 service_id; /* Service ID, possibly upgraded */
420 u8 size_align; /* data size alignment (for security) */
421 u8 security_size; /* security header size */
422 u8 security_ix; /* security type */
423 u8 out_clientflag; /* RXRPC_CLIENT_INITIATED if we are client */
427 * Flags in call->flags.
429 enum rxrpc_call_flag {
430 RXRPC_CALL_RELEASED, /* call has been released - no more message to userspace */
431 RXRPC_CALL_HAS_USERID, /* has a user ID attached */
432 RXRPC_CALL_IS_SERVICE, /* Call is service call */
433 RXRPC_CALL_EXPOSED, /* The call was exposed to the world */
434 RXRPC_CALL_RX_LAST, /* Received the last packet (at rxtx_top) */
435 RXRPC_CALL_TX_LAST, /* Last packet in Tx buffer (at rxtx_top) */
436 RXRPC_CALL_SEND_PING, /* A ping will need to be sent */
437 RXRPC_CALL_PINGING, /* Ping in process */
438 RXRPC_CALL_RETRANS_TIMEOUT, /* Retransmission due to timeout occurred */
442 * Events that can be raised on a call.
444 enum rxrpc_call_event {
445 RXRPC_CALL_EV_ACK, /* need to generate ACK */
446 RXRPC_CALL_EV_ABORT, /* need to generate abort */
447 RXRPC_CALL_EV_TIMER, /* Timer expired */
448 RXRPC_CALL_EV_RESEND, /* Tx resend required */
449 RXRPC_CALL_EV_PING, /* Ping send required */
453 * The states that a call can be in.
455 enum rxrpc_call_state {
456 RXRPC_CALL_UNINITIALISED,
457 RXRPC_CALL_CLIENT_AWAIT_CONN, /* - client waiting for connection to become available */
458 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 */
461 RXRPC_CALL_SERVER_PREALLOC, /* - service preallocation */
462 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 */
468 RXRPC_CALL_COMPLETE, /* - call complete */
469 NR__RXRPC_CALL_STATES
473 * Call completion condition (state == RXRPC_CALL_COMPLETE).
475 enum rxrpc_call_completion {
476 RXRPC_CALL_SUCCEEDED, /* - Normal termination */
477 RXRPC_CALL_REMOTELY_ABORTED, /* - call aborted by peer */
478 RXRPC_CALL_LOCALLY_ABORTED, /* - call aborted locally on error or close */
479 RXRPC_CALL_LOCAL_ERROR, /* - call failed due to local error */
480 RXRPC_CALL_NETWORK_ERROR, /* - call terminated by network error */
481 NR__RXRPC_CALL_COMPLETIONS
485 * Call Tx congestion management modes.
487 enum 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
496 * RxRPC call definition
497 * - matched by { connection, call_id }
501 struct rxrpc_connection *conn; /* connection carrying call */
502 struct rxrpc_peer *peer; /* Peer record for remote address */
503 struct rxrpc_sock __rcu *socket; /* socket responsible */
504 struct mutex user_mutex; /* User access mutex */
505 ktime_t ack_at; /* When deferred ACK needs to happen */
506 ktime_t resend_at; /* When next resend needs to happen */
507 ktime_t ping_at; /* When next to send a ping */
508 ktime_t expire_at; /* When the call times out */
509 struct timer_list timer; /* Combined event timer */
510 struct work_struct processor; /* Event processor */
511 rxrpc_notify_rx_t notify_rx; /* kernel service Rx notification function */
512 struct list_head link; /* link in master call list */
513 struct list_head chan_wait_link; /* Link in conn->waiting_calls */
514 struct hlist_node error_link; /* link in error distribution list */
515 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 */
519 struct sk_buff *tx_pending; /* Tx socket buffer being filled */
520 wait_queue_head_t waitq; /* Wait queue for channel or Tx */
521 __be32 crypto_buf[2]; /* Temporary packet crypto buffer */
522 unsigned long user_call_ID; /* user-defined call ID */
524 unsigned long events;
526 rwlock_t state_lock; /* lock for state transition */
527 u32 abort_code; /* Local/remote abort code */
528 int error; /* Local error incurred */
529 enum rxrpc_call_state state; /* current state of call */
530 enum rxrpc_call_completion completion; /* Call completion condition */
532 u16 service_id; /* service ID */
533 u8 security_ix; /* Security type */
534 u32 call_id; /* call ID on connection */
535 u32 cid; /* connection ID plus channel index */
536 int debug_id; /* debug ID for printks */
537 unsigned short rx_pkt_offset; /* Current recvmsg packet offset */
538 unsigned short rx_pkt_len; /* Current recvmsg packet len */
540 /* Rx/Tx circular buffer, depending on phase.
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.
546 * In the Tx phase, packets are annotated with which buffers have been
549 #define RXRPC_RXTX_BUFF_SIZE 64
550 #define RXRPC_RXTX_BUFF_MASK (RXRPC_RXTX_BUFF_SIZE - 1)
551 #define RXRPC_INIT_RX_WINDOW_SIZE 32
552 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
558 #define RXRPC_TX_ANNO_MASK 0x03
559 #define RXRPC_TX_ANNO_LAST 0x04
560 #define RXRPC_TX_ANNO_RESENT 0x08
562 #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.
568 rxrpc_seq_t tx_top; /* Highest Tx slot allocated. */
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.
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 */
583 rxrpc_seq_t rx_hard_ack; /* Dead slot in buffer; the first received but not
584 * consumed packet follows this.
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 */
590 bool tx_phase; /* T if transmission phase, F if receive phase */
591 u8 nr_jumbo_bad; /* Number of jumbo dups/exceeds-windows */
593 /* receive-phase ACK management */
594 u8 ackr_reason; /* reason to ACK */
595 u16 ackr_skew; /* skew on packet being ACK'd */
596 rxrpc_serial_t ackr_serial; /* serial of packet being ACK'd */
597 rxrpc_seq_t ackr_prev_seq; /* previous sequence number received */
598 rxrpc_seq_t ackr_consumed; /* Highest packet shown consumed */
599 rxrpc_seq_t ackr_seen; /* Highest packet shown seen */
601 /* ping management */
602 rxrpc_serial_t ping_serial; /* Last ping sent */
603 ktime_t ping_time; /* Time last ping sent */
605 /* transmission-phase ACK management */
606 ktime_t acks_latest_ts; /* Timestamp of latest ACK received */
607 rxrpc_serial_t acks_latest; /* serial number of latest ACK received */
608 rxrpc_seq_t acks_lowest_nak; /* Lowest NACK in the buffer (or ==tx_hard_ack) */
612 * Summary of a new ACK and the changes it made to the Tx buffer packet states.
614 struct rxrpc_ack_summary {
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 */
622 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;
632 #include <trace/events/rxrpc.h>
637 extern atomic_t rxrpc_n_tx_skbs, rxrpc_n_rx_skbs;
638 extern atomic_t rxrpc_debug_id;
639 extern struct workqueue_struct *rxrpc_workqueue;
644 int rxrpc_service_prealloc(struct rxrpc_sock *, gfp_t);
645 void rxrpc_discard_prealloc(struct rxrpc_sock *);
646 struct rxrpc_call *rxrpc_new_incoming_call(struct rxrpc_local *,
647 struct rxrpc_connection *,
649 void rxrpc_accept_incoming_calls(struct rxrpc_local *);
650 struct rxrpc_call *rxrpc_accept_call(struct rxrpc_sock *, unsigned long,
652 int rxrpc_reject_call(struct rxrpc_sock *);
657 void __rxrpc_set_timer(struct rxrpc_call *, enum rxrpc_timer_trace, ktime_t);
658 void rxrpc_set_timer(struct rxrpc_call *, enum rxrpc_timer_trace, ktime_t);
659 void rxrpc_propose_ACK(struct rxrpc_call *, u8, u16, u32, bool, bool,
660 enum rxrpc_propose_ack_trace);
661 void rxrpc_process_call(struct work_struct *);
666 extern const char *const rxrpc_call_states[];
667 extern const char *const rxrpc_call_completions[];
668 extern unsigned int rxrpc_max_call_lifetime;
669 extern struct kmem_cache *rxrpc_call_jar;
671 struct rxrpc_call *rxrpc_find_call_by_user_ID(struct rxrpc_sock *, unsigned long);
672 struct rxrpc_call *rxrpc_alloc_call(gfp_t);
673 struct rxrpc_call *rxrpc_new_client_call(struct rxrpc_sock *,
674 struct rxrpc_conn_parameters *,
675 struct sockaddr_rxrpc *,
676 unsigned long, gfp_t);
677 void rxrpc_incoming_call(struct rxrpc_sock *, struct rxrpc_call *,
679 void rxrpc_release_call(struct rxrpc_sock *, struct rxrpc_call *);
680 void rxrpc_release_calls_on_socket(struct rxrpc_sock *);
681 bool __rxrpc_queue_call(struct rxrpc_call *);
682 bool rxrpc_queue_call(struct rxrpc_call *);
683 void rxrpc_see_call(struct rxrpc_call *);
684 void rxrpc_get_call(struct rxrpc_call *, enum rxrpc_call_trace);
685 void rxrpc_put_call(struct rxrpc_call *, enum rxrpc_call_trace);
686 void rxrpc_cleanup_call(struct rxrpc_call *);
687 void rxrpc_destroy_all_calls(struct rxrpc_net *);
689 static inline bool rxrpc_is_service_call(const struct rxrpc_call *call)
691 return test_bit(RXRPC_CALL_IS_SERVICE, &call->flags);
694 static inline bool rxrpc_is_client_call(const struct rxrpc_call *call)
696 return !rxrpc_is_service_call(call);
700 * Transition a call to the complete state.
702 static inline bool __rxrpc_set_call_completion(struct rxrpc_call *call,
703 enum rxrpc_call_completion compl,
707 if (call->state < RXRPC_CALL_COMPLETE) {
708 call->abort_code = abort_code;
710 call->completion = compl,
711 call->state = RXRPC_CALL_COMPLETE;
712 wake_up(&call->waitq);
718 static inline bool rxrpc_set_call_completion(struct rxrpc_call *call,
719 enum rxrpc_call_completion compl,
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);
732 * Record that a call successfully completed.
734 static inline bool __rxrpc_call_completed(struct rxrpc_call *call)
736 return __rxrpc_set_call_completion(call, RXRPC_CALL_SUCCEEDED, 0, 0);
739 static inline bool rxrpc_call_completed(struct rxrpc_call *call)
743 write_lock_bh(&call->state_lock);
744 ret = __rxrpc_call_completed(call);
745 write_unlock_bh(&call->state_lock);
750 * Record that a call is locally aborted.
752 static inline bool __rxrpc_abort_call(const char *why, struct rxrpc_call *call,
754 u32 abort_code, int error)
756 trace_rxrpc_abort(why, call->cid, call->call_id, seq,
758 return __rxrpc_set_call_completion(call, RXRPC_CALL_LOCALLY_ABORTED,
762 static inline bool rxrpc_abort_call(const char *why, struct rxrpc_call *call,
763 rxrpc_seq_t seq, u32 abort_code, int error)
767 write_lock_bh(&call->state_lock);
768 ret = __rxrpc_abort_call(why, call, seq, abort_code, error);
769 write_unlock_bh(&call->state_lock);
774 * Abort a call due to a protocol error.
776 static inline bool __rxrpc_abort_eproto(struct rxrpc_call *call,
778 const char *eproto_why,
782 struct rxrpc_skb_priv *sp = rxrpc_skb(skb);
784 trace_rxrpc_rx_eproto(call, sp->hdr.serial, eproto_why);
785 return rxrpc_abort_call(why, call, sp->hdr.seq, abort_code, -EPROTO);
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))
795 extern unsigned int rxrpc_max_client_connections;
796 extern unsigned int rxrpc_reap_client_connections;
797 extern unsigned int rxrpc_conn_idle_client_expiry;
798 extern unsigned int rxrpc_conn_idle_client_fast_expiry;
799 extern struct idr rxrpc_client_conn_ids;
801 void rxrpc_destroy_client_conn_ids(void);
802 int rxrpc_connect_call(struct rxrpc_call *, struct rxrpc_conn_parameters *,
803 struct sockaddr_rxrpc *, gfp_t);
804 void rxrpc_expose_client_call(struct rxrpc_call *);
805 void rxrpc_disconnect_client_call(struct rxrpc_call *);
806 void rxrpc_put_client_conn(struct rxrpc_connection *);
807 void rxrpc_discard_expired_client_conns(struct work_struct *);
808 void rxrpc_destroy_all_client_connections(struct rxrpc_net *);
813 void rxrpc_process_connection(struct work_struct *);
818 extern unsigned int rxrpc_connection_expiry;
820 int rxrpc_extract_addr_from_skb(struct sockaddr_rxrpc *, struct sk_buff *);
821 struct rxrpc_connection *rxrpc_alloc_connection(gfp_t);
822 struct rxrpc_connection *rxrpc_find_connection_rcu(struct rxrpc_local *,
824 void __rxrpc_disconnect_call(struct rxrpc_connection *, struct rxrpc_call *);
825 void rxrpc_disconnect_call(struct rxrpc_call *);
826 void rxrpc_kill_connection(struct rxrpc_connection *);
827 bool rxrpc_queue_conn(struct rxrpc_connection *);
828 void rxrpc_see_connection(struct rxrpc_connection *);
829 void rxrpc_get_connection(struct rxrpc_connection *);
830 struct rxrpc_connection *rxrpc_get_connection_maybe(struct rxrpc_connection *);
831 void rxrpc_put_service_conn(struct rxrpc_connection *);
832 void rxrpc_service_connection_reaper(struct work_struct *);
833 void rxrpc_destroy_all_connections(struct rxrpc_net *);
835 static inline bool rxrpc_conn_is_client(const struct rxrpc_connection *conn)
837 return conn->out_clientflag;
840 static inline bool rxrpc_conn_is_service(const struct rxrpc_connection *conn)
842 return !rxrpc_conn_is_client(conn);
845 static inline void rxrpc_put_connection(struct rxrpc_connection *conn)
850 if (rxrpc_conn_is_client(conn))
851 rxrpc_put_client_conn(conn);
853 rxrpc_put_service_conn(conn);
859 struct rxrpc_connection *rxrpc_find_service_conn_rcu(struct rxrpc_peer *,
861 struct rxrpc_connection *rxrpc_prealloc_service_connection(struct rxrpc_net *, gfp_t);
862 void rxrpc_new_incoming_connection(struct rxrpc_connection *, struct sk_buff *);
863 void rxrpc_unpublish_service_conn(struct rxrpc_connection *);
868 void rxrpc_data_ready(struct sock *);
873 extern const struct rxrpc_security rxrpc_no_security;
878 extern struct key_type key_type_rxrpc;
879 extern struct key_type key_type_rxrpc_s;
881 int rxrpc_request_key(struct rxrpc_sock *, char __user *, int);
882 int rxrpc_server_keyring(struct rxrpc_sock *, char __user *, int);
883 int rxrpc_get_server_data_key(struct rxrpc_connection *, const void *, time_t,
889 extern void rxrpc_process_local_events(struct rxrpc_local *);
894 struct rxrpc_local *rxrpc_lookup_local(struct net *, const struct sockaddr_rxrpc *);
895 void __rxrpc_put_local(struct rxrpc_local *);
896 void rxrpc_destroy_all_locals(struct rxrpc_net *);
898 static inline void rxrpc_get_local(struct rxrpc_local *local)
900 atomic_inc(&local->usage);
904 struct rxrpc_local *rxrpc_get_local_maybe(struct rxrpc_local *local)
906 return atomic_inc_not_zero(&local->usage) ? local : NULL;
909 static inline void rxrpc_put_local(struct rxrpc_local *local)
911 if (local && atomic_dec_and_test(&local->usage))
912 __rxrpc_put_local(local);
915 static inline void rxrpc_queue_local(struct rxrpc_local *local)
917 rxrpc_queue_work(&local->processor);
923 extern unsigned int rxrpc_max_backlog __read_mostly;
924 extern unsigned int rxrpc_requested_ack_delay;
925 extern unsigned int rxrpc_soft_ack_delay;
926 extern unsigned int rxrpc_idle_ack_delay;
927 extern unsigned int rxrpc_rx_window_size;
928 extern unsigned int rxrpc_rx_mtu;
929 extern unsigned int rxrpc_rx_jumbo_max;
930 extern unsigned int rxrpc_resend_timeout;
932 extern const s8 rxrpc_ack_priority[];
937 extern unsigned int rxrpc_net_id;
938 extern struct pernet_operations rxrpc_net_ops;
940 static inline struct rxrpc_net *rxrpc_net(struct net *net)
942 return net_generic(net, rxrpc_net_id);
948 int rxrpc_send_ack_packet(struct rxrpc_call *, bool);
949 int rxrpc_send_abort_packet(struct rxrpc_call *);
950 int rxrpc_send_data_packet(struct rxrpc_call *, struct sk_buff *, bool);
951 void rxrpc_reject_packets(struct rxrpc_local *);
956 void rxrpc_error_report(struct sock *);
957 void rxrpc_peer_error_distributor(struct work_struct *);
958 void rxrpc_peer_add_rtt(struct rxrpc_call *, enum rxrpc_rtt_rx_trace,
959 rxrpc_serial_t, rxrpc_serial_t, ktime_t, ktime_t);
964 struct rxrpc_peer *rxrpc_lookup_peer_rcu(struct rxrpc_local *,
965 const struct sockaddr_rxrpc *);
966 struct rxrpc_peer *rxrpc_lookup_peer(struct rxrpc_local *,
967 struct sockaddr_rxrpc *, gfp_t);
968 struct rxrpc_peer *rxrpc_alloc_peer(struct rxrpc_local *, gfp_t);
969 struct rxrpc_peer *rxrpc_lookup_incoming_peer(struct rxrpc_local *,
970 struct rxrpc_peer *);
972 static inline struct rxrpc_peer *rxrpc_get_peer(struct rxrpc_peer *peer)
974 atomic_inc(&peer->usage);
979 struct rxrpc_peer *rxrpc_get_peer_maybe(struct rxrpc_peer *peer)
981 return atomic_inc_not_zero(&peer->usage) ? peer : NULL;
984 extern void __rxrpc_put_peer(struct rxrpc_peer *peer);
985 static inline void rxrpc_put_peer(struct rxrpc_peer *peer)
987 if (peer && atomic_dec_and_test(&peer->usage))
988 __rxrpc_put_peer(peer);
994 extern const struct file_operations rxrpc_call_seq_fops;
995 extern const struct file_operations rxrpc_connection_seq_fops;
1000 void rxrpc_notify_socket(struct rxrpc_call *);
1001 int rxrpc_recvmsg(struct socket *, struct msghdr *, size_t, int);
1007 extern const struct rxrpc_security rxkad;
1013 int __init rxrpc_init_security(void);
1014 void rxrpc_exit_security(void);
1015 int rxrpc_init_client_conn_security(struct rxrpc_connection *);
1016 int rxrpc_init_server_conn_security(struct rxrpc_connection *);
1021 int rxrpc_do_sendmsg(struct rxrpc_sock *, struct msghdr *, size_t);
1026 void rxrpc_kernel_data_consumed(struct rxrpc_call *, struct sk_buff *);
1027 void rxrpc_packet_destructor(struct sk_buff *);
1028 void rxrpc_new_skb(struct sk_buff *, enum rxrpc_skb_trace);
1029 void rxrpc_see_skb(struct sk_buff *, enum rxrpc_skb_trace);
1030 void rxrpc_get_skb(struct sk_buff *, enum rxrpc_skb_trace);
1031 void rxrpc_free_skb(struct sk_buff *, enum rxrpc_skb_trace);
1032 void rxrpc_lose_skb(struct sk_buff *, enum rxrpc_skb_trace);
1033 void rxrpc_purge_queue(struct sk_buff_head *);
1038 #ifdef CONFIG_SYSCTL
1039 extern int __init rxrpc_sysctl_init(void);
1040 extern void rxrpc_sysctl_exit(void);
1042 static inline int __init rxrpc_sysctl_init(void) { return 0; }
1043 static inline void rxrpc_sysctl_exit(void) {}
1049 int rxrpc_extract_addr_from_skb(struct sockaddr_rxrpc *, struct sk_buff *);
1051 static inline bool before(u32 seq1, u32 seq2)
1053 return (s32)(seq1 - seq2) < 0;
1055 static inline bool before_eq(u32 seq1, u32 seq2)
1057 return (s32)(seq1 - seq2) <= 0;
1059 static inline bool after(u32 seq1, u32 seq2)
1061 return (s32)(seq1 - seq2) > 0;
1063 static inline bool after_eq(u32 seq1, u32 seq2)
1065 return (s32)(seq1 - seq2) >= 0;
1071 extern unsigned int rxrpc_debug;
1073 #define dbgprintk(FMT,...) \
1074 printk("[%-6.6s] "FMT"\n", current->comm ,##__VA_ARGS__)
1076 #define kenter(FMT,...) dbgprintk("==> %s("FMT")",__func__ ,##__VA_ARGS__)
1077 #define kleave(FMT,...) dbgprintk("<== %s()"FMT"",__func__ ,##__VA_ARGS__)
1078 #define kdebug(FMT,...) dbgprintk(" "FMT ,##__VA_ARGS__)
1079 #define kproto(FMT,...) dbgprintk("### "FMT ,##__VA_ARGS__)
1080 #define knet(FMT,...) dbgprintk("@@@ "FMT ,##__VA_ARGS__)
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__)
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
1097 #define _enter(FMT,...) \
1099 if (unlikely(rxrpc_debug & RXRPC_DEBUG_KENTER)) \
1100 kenter(FMT,##__VA_ARGS__); \
1103 #define _leave(FMT,...) \
1105 if (unlikely(rxrpc_debug & RXRPC_DEBUG_KLEAVE)) \
1106 kleave(FMT,##__VA_ARGS__); \
1109 #define _debug(FMT,...) \
1111 if (unlikely(rxrpc_debug & RXRPC_DEBUG_KDEBUG)) \
1112 kdebug(FMT,##__VA_ARGS__); \
1115 #define _proto(FMT,...) \
1117 if (unlikely(rxrpc_debug & RXRPC_DEBUG_KPROTO)) \
1118 kproto(FMT,##__VA_ARGS__); \
1121 #define _net(FMT,...) \
1123 if (unlikely(rxrpc_debug & RXRPC_DEBUG_KNET)) \
1124 knet(FMT,##__VA_ARGS__); \
1128 #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__)
1136 * debug assertion checking
1138 #if 1 // defined(__KDEBUGALL)
1142 if (unlikely(!(X))) { \
1143 pr_err("Assertion failed\n"); \
1148 #define ASSERTCMP(X, OP, Y) \
1150 __typeof__(X) _x = (X); \
1151 __typeof__(Y) _y = (__typeof__(X))(Y); \
1152 if (unlikely(!(_x OP _y))) { \
1153 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); \
1160 #define ASSERTIF(C, X) \
1162 if (unlikely((C) && !(X))) { \
1163 pr_err("Assertion failed\n"); \
1168 #define ASSERTIFCMP(C, X, OP, Y) \
1170 __typeof__(X) _x = (X); \
1171 __typeof__(Y) _y = (__typeof__(X))(Y); \
1172 if (unlikely((C) && !(_x OP _y))) { \
1173 pr_err("Assertion failed - %lu(0x%lx) %s %lu(0x%lx) is false\n", \
1174 (unsigned long)_x, (unsigned long)_x, #OP, \
1175 (unsigned long)_y, (unsigned long)_y); \
1186 #define ASSERTCMP(X, OP, Y) \
1190 #define ASSERTIF(C, X) \
1194 #define ASSERTIFCMP(C, X, OP, Y) \
1198 #endif /* __KDEBUGALL */