1
2
3
4
5
6
7
8#include <linux/atomic.h>
9#include <linux/seqlock.h>
10#include <linux/win_minmax.h>
11#include <net/net_namespace.h>
12#include <net/netns/generic.h>
13#include <net/sock.h>
14#include <net/af_rxrpc.h>
15#include <keys/rxrpc-type.h>
16#include "protocol.h"
17
18#if 0
19#define CHECK_SLAB_OKAY(X) \
20 BUG_ON(atomic_read((X)) >> (sizeof(atomic_t) - 2) == \
21 (POISON_FREE << 8 | POISON_FREE))
22#else
23#define CHECK_SLAB_OKAY(X) do {} while (0)
24#endif
25
26#define FCRYPT_BSIZE 8
27struct rxrpc_crypt {
28 union {
29 u8 x[FCRYPT_BSIZE];
30 __be32 n[2];
31 };
32} __attribute__((aligned(8)));
33
34#define rxrpc_queue_work(WS) queue_work(rxrpc_workqueue, (WS))
35#define rxrpc_queue_delayed_work(WS,D) \
36 queue_delayed_work(rxrpc_workqueue, (WS), (D))
37
38struct key_preparsed_payload;
39struct rxrpc_connection;
40
41
42
43
44
45enum rxrpc_skb_mark {
46 RXRPC_SKB_MARK_REJECT_BUSY,
47 RXRPC_SKB_MARK_REJECT_ABORT,
48};
49
50
51
52
53enum {
54 RXRPC_UNBOUND = 0,
55 RXRPC_CLIENT_UNBOUND,
56 RXRPC_CLIENT_BOUND,
57 RXRPC_SERVER_BOUND,
58 RXRPC_SERVER_BOUND2,
59 RXRPC_SERVER_LISTENING,
60 RXRPC_SERVER_LISTEN_DISABLED,
61 RXRPC_CLOSE,
62};
63
64
65
66
67struct rxrpc_net {
68 struct proc_dir_entry *proc_net;
69 u32 epoch;
70 struct list_head calls;
71 rwlock_t call_lock;
72 atomic_t nr_calls;
73
74 atomic_t nr_conns;
75 struct list_head conn_proc_list;
76 struct list_head service_conns;
77 rwlock_t conn_lock;
78 struct work_struct service_conn_reaper;
79 struct timer_list service_conn_reap_timer;
80
81 bool live;
82
83 bool kill_all_client_conns;
84 atomic_t nr_client_conns;
85 spinlock_t client_conn_cache_lock;
86 spinlock_t client_conn_discard_lock;
87 struct list_head idle_client_conns;
88 struct work_struct client_conn_reaper;
89 struct timer_list client_conn_reap_timer;
90
91 struct list_head local_endpoints;
92 struct mutex local_mutex;
93
94 DECLARE_HASHTABLE (peer_hash, 10);
95 spinlock_t peer_hash_lock;
96
97#define RXRPC_KEEPALIVE_TIME 20
98 u8 peer_keepalive_cursor;
99 time64_t peer_keepalive_base;
100 struct list_head peer_keepalive[32];
101 struct list_head peer_keepalive_new;
102 struct timer_list peer_keepalive_timer;
103 struct work_struct peer_keepalive_work;
104};
105
106
107
108
109
110
111
112
113
114struct rxrpc_backlog {
115 unsigned short peer_backlog_head;
116 unsigned short peer_backlog_tail;
117 unsigned short conn_backlog_head;
118 unsigned short conn_backlog_tail;
119 unsigned short call_backlog_head;
120 unsigned short call_backlog_tail;
121#define RXRPC_BACKLOG_MAX 32
122 struct rxrpc_peer *peer_backlog[RXRPC_BACKLOG_MAX];
123 struct rxrpc_connection *conn_backlog[RXRPC_BACKLOG_MAX];
124 struct rxrpc_call *call_backlog[RXRPC_BACKLOG_MAX];
125};
126
127
128
129
130struct rxrpc_sock {
131
132 struct sock sk;
133 rxrpc_notify_new_call_t notify_new_call;
134 rxrpc_discard_new_call_t discard_new_call;
135 struct rxrpc_local *local;
136 struct rxrpc_backlog *backlog;
137 spinlock_t incoming_lock;
138 struct list_head sock_calls;
139 struct list_head to_be_accepted;
140 struct list_head recvmsg_q;
141 rwlock_t recvmsg_lock;
142 struct key *key;
143 struct key *securities;
144 struct rb_root calls;
145 unsigned long flags;
146#define RXRPC_SOCK_CONNECTED 0
147 rwlock_t call_lock;
148 u32 min_sec_level;
149#define RXRPC_SECURITY_MAX RXRPC_SECURITY_ENCRYPT
150 bool exclusive;
151 u16 second_service;
152 struct {
153
154 u16 from;
155 u16 to;
156 } service_upgrade;
157 sa_family_t family;
158 struct sockaddr_rxrpc srx;
159 struct sockaddr_rxrpc connect_srx;
160};
161
162#define rxrpc_sk(__sk) container_of((__sk), struct rxrpc_sock, sk)
163
164
165
166
167struct rxrpc_host_header {
168 u32 epoch;
169 u32 cid;
170 u32 callNumber;
171 u32 seq;
172 u32 serial;
173 u8 type;
174 u8 flags;
175 u8 userStatus;
176 u8 securityIndex;
177 union {
178 u16 _rsvd;
179 u16 cksum;
180 };
181 u16 serviceId;
182} __packed;
183
184
185
186
187
188struct rxrpc_skb_priv {
189 atomic_t nr_ring_pins;
190 u8 nr_subpackets;
191 u8 rx_flags;
192#define RXRPC_SKB_INCL_LAST 0x01
193#define RXRPC_SKB_TX_BUFFER 0x02
194 union {
195 int remain;
196
197
198 unsigned long rx_req_ack[(RXRPC_MAX_NR_JUMBO + BITS_PER_LONG - 1) /
199 BITS_PER_LONG];
200 };
201
202 struct rxrpc_host_header hdr;
203};
204
205#define rxrpc_skb(__skb) ((struct rxrpc_skb_priv *) &(__skb)->cb)
206
207
208
209
210struct rxrpc_security {
211 const char *name;
212 u8 security_index;
213 u32 no_key_abort;
214
215
216 int (*init)(void);
217
218
219 void (*exit)(void);
220
221
222 int (*preparse_server_key)(struct key_preparsed_payload *);
223
224
225 void (*free_preparse_server_key)(struct key_preparsed_payload *);
226
227
228 void (*destroy_server_key)(struct key *);
229
230
231 void (*describe_server_key)(const struct key *, struct seq_file *);
232
233
234 int (*init_connection_security)(struct rxrpc_connection *,
235 struct rxrpc_key_token *);
236
237
238
239
240 int (*how_much_data)(struct rxrpc_call *, size_t,
241 size_t *, size_t *, size_t *);
242
243
244 int (*secure_packet)(struct rxrpc_call *, struct sk_buff *, size_t);
245
246
247 int (*verify_packet)(struct rxrpc_call *, struct sk_buff *,
248 unsigned int, unsigned int, rxrpc_seq_t, u16);
249
250
251 void (*free_call_crypto)(struct rxrpc_call *);
252
253
254 void (*locate_data)(struct rxrpc_call *, struct sk_buff *,
255 unsigned int *, unsigned int *);
256
257
258 int (*issue_challenge)(struct rxrpc_connection *);
259
260
261 int (*respond_to_challenge)(struct rxrpc_connection *,
262 struct sk_buff *,
263 u32 *);
264
265
266 int (*verify_response)(struct rxrpc_connection *,
267 struct sk_buff *,
268 u32 *);
269
270
271 void (*clear)(struct rxrpc_connection *);
272};
273
274
275
276
277
278
279struct rxrpc_local {
280 struct rcu_head rcu;
281 atomic_t active_users;
282 atomic_t usage;
283 struct rxrpc_net *rxnet;
284 struct list_head link;
285 struct socket *socket;
286 struct work_struct processor;
287 struct rxrpc_sock __rcu *service;
288 struct rw_semaphore defrag_sem;
289 struct sk_buff_head reject_queue;
290 struct sk_buff_head event_queue;
291 struct rb_root client_bundles;
292 spinlock_t client_bundles_lock;
293 spinlock_t lock;
294 rwlock_t services_lock;
295 int debug_id;
296 bool dead;
297 bool service_closed;
298 struct sockaddr_rxrpc srx;
299};
300
301
302
303
304
305struct rxrpc_peer {
306 struct rcu_head rcu;
307 atomic_t usage;
308 unsigned long hash_key;
309 struct hlist_node hash_link;
310 struct rxrpc_local *local;
311 struct hlist_head error_targets;
312 struct rb_root service_conns;
313 struct list_head keepalive_link;
314 time64_t last_tx_at;
315 seqlock_t service_conn_lock;
316 spinlock_t lock;
317 unsigned int if_mtu;
318 unsigned int mtu;
319 unsigned int maxdata;
320 unsigned short hdrsize;
321 int debug_id;
322 struct sockaddr_rxrpc srx;
323
324
325#define RXRPC_RTT_CACHE_SIZE 32
326 spinlock_t rtt_input_lock;
327 ktime_t rtt_last_req;
328 unsigned int rtt_count;
329
330 u32 srtt_us;
331 u32 mdev_us;
332 u32 mdev_max_us;
333 u32 rttvar_us;
334 u32 rto_j;
335 u8 backoff;
336
337 u8 cong_cwnd;
338};
339
340
341
342
343struct rxrpc_conn_proto {
344 union {
345 struct {
346 u32 epoch;
347 u32 cid;
348 };
349 u64 index_key;
350 };
351};
352
353struct rxrpc_conn_parameters {
354 struct rxrpc_local *local;
355 struct rxrpc_peer *peer;
356 struct key *key;
357 bool exclusive;
358 bool upgrade;
359 u16 service_id;
360 u32 security_level;
361};
362
363
364
365
366enum rxrpc_conn_flag {
367 RXRPC_CONN_HAS_IDR,
368 RXRPC_CONN_IN_SERVICE_CONNS,
369 RXRPC_CONN_DONT_REUSE,
370 RXRPC_CONN_PROBING_FOR_UPGRADE,
371 RXRPC_CONN_FINAL_ACK_0,
372 RXRPC_CONN_FINAL_ACK_1,
373 RXRPC_CONN_FINAL_ACK_2,
374 RXRPC_CONN_FINAL_ACK_3,
375};
376
377#define RXRPC_CONN_FINAL_ACK_MASK ((1UL << RXRPC_CONN_FINAL_ACK_0) | \
378 (1UL << RXRPC_CONN_FINAL_ACK_1) | \
379 (1UL << RXRPC_CONN_FINAL_ACK_2) | \
380 (1UL << RXRPC_CONN_FINAL_ACK_3))
381
382
383
384
385enum rxrpc_conn_event {
386 RXRPC_CONN_EV_CHALLENGE,
387};
388
389
390
391
392enum rxrpc_conn_proto_state {
393 RXRPC_CONN_UNUSED,
394 RXRPC_CONN_CLIENT,
395 RXRPC_CONN_SERVICE_PREALLOC,
396 RXRPC_CONN_SERVICE_UNSECURED,
397 RXRPC_CONN_SERVICE_CHALLENGING,
398 RXRPC_CONN_SERVICE,
399 RXRPC_CONN_REMOTELY_ABORTED,
400 RXRPC_CONN_LOCALLY_ABORTED,
401 RXRPC_CONN__NR_STATES
402};
403
404
405
406
407struct rxrpc_bundle {
408 struct rxrpc_conn_parameters params;
409 atomic_t usage;
410 unsigned int debug_id;
411 bool try_upgrade;
412 bool alloc_conn;
413 short alloc_error;
414 spinlock_t channel_lock;
415 struct rb_node local_node;
416 struct list_head waiting_calls;
417 unsigned long avail_chans;
418 struct rxrpc_connection *conns[4];
419};
420
421
422
423
424
425
426struct rxrpc_connection {
427 struct rxrpc_conn_proto proto;
428 struct rxrpc_conn_parameters params;
429
430 atomic_t usage;
431 struct rcu_head rcu;
432 struct list_head cache_link;
433
434 unsigned char act_chans;
435 struct rxrpc_channel {
436 unsigned long final_ack_at;
437 struct rxrpc_call __rcu *call;
438 unsigned int call_debug_id;
439 u32 call_id;
440 u32 call_counter;
441 u32 last_call;
442 u8 last_type;
443 union {
444 u32 last_seq;
445 u32 last_abort;
446 };
447 } channels[RXRPC_MAXCALLS];
448
449 struct timer_list timer;
450 struct work_struct processor;
451 struct rxrpc_bundle *bundle;
452 struct rb_node service_node;
453 struct list_head proc_link;
454 struct list_head link;
455 struct sk_buff_head rx_queue;
456
457 const struct rxrpc_security *security;
458 union {
459 struct {
460 struct crypto_sync_skcipher *cipher;
461 struct rxrpc_crypt csum_iv;
462 u32 nonce;
463 } rxkad;
464 };
465 unsigned long flags;
466 unsigned long events;
467 unsigned long idle_timestamp;
468 spinlock_t state_lock;
469 enum rxrpc_conn_proto_state state;
470 u32 abort_code;
471 int debug_id;
472 atomic_t serial;
473 unsigned int hi_serial;
474 u32 service_id;
475 u8 security_ix;
476 u8 out_clientflag;
477 u8 bundle_shift;
478 short error;
479};
480
481static inline bool rxrpc_to_server(const struct rxrpc_skb_priv *sp)
482{
483 return sp->hdr.flags & RXRPC_CLIENT_INITIATED;
484}
485
486static inline bool rxrpc_to_client(const struct rxrpc_skb_priv *sp)
487{
488 return !rxrpc_to_server(sp);
489}
490
491
492
493
494enum rxrpc_call_flag {
495 RXRPC_CALL_RELEASED,
496 RXRPC_CALL_HAS_USERID,
497 RXRPC_CALL_IS_SERVICE,
498 RXRPC_CALL_EXPOSED,
499 RXRPC_CALL_RX_LAST,
500 RXRPC_CALL_TX_LAST,
501 RXRPC_CALL_SEND_PING,
502 RXRPC_CALL_RETRANS_TIMEOUT,
503 RXRPC_CALL_BEGAN_RX_TIMER,
504 RXRPC_CALL_RX_HEARD,
505 RXRPC_CALL_RX_UNDERRUN,
506 RXRPC_CALL_DISCONNECTED,
507 RXRPC_CALL_KERNEL,
508 RXRPC_CALL_UPGRADE,
509};
510
511
512
513
514enum rxrpc_call_event {
515 RXRPC_CALL_EV_ACK,
516 RXRPC_CALL_EV_ABORT,
517 RXRPC_CALL_EV_RESEND,
518 RXRPC_CALL_EV_PING,
519 RXRPC_CALL_EV_EXPIRED,
520 RXRPC_CALL_EV_ACK_LOST,
521};
522
523
524
525
526enum rxrpc_call_state {
527 RXRPC_CALL_UNINITIALISED,
528 RXRPC_CALL_CLIENT_AWAIT_CONN,
529 RXRPC_CALL_CLIENT_SEND_REQUEST,
530 RXRPC_CALL_CLIENT_AWAIT_REPLY,
531 RXRPC_CALL_CLIENT_RECV_REPLY,
532 RXRPC_CALL_SERVER_PREALLOC,
533 RXRPC_CALL_SERVER_SECURING,
534 RXRPC_CALL_SERVER_RECV_REQUEST,
535 RXRPC_CALL_SERVER_ACK_REQUEST,
536 RXRPC_CALL_SERVER_SEND_REPLY,
537 RXRPC_CALL_SERVER_AWAIT_ACK,
538 RXRPC_CALL_COMPLETE,
539 NR__RXRPC_CALL_STATES
540};
541
542
543
544
545enum rxrpc_call_completion {
546 RXRPC_CALL_SUCCEEDED,
547 RXRPC_CALL_REMOTELY_ABORTED,
548 RXRPC_CALL_LOCALLY_ABORTED,
549 RXRPC_CALL_LOCAL_ERROR,
550 RXRPC_CALL_NETWORK_ERROR,
551 NR__RXRPC_CALL_COMPLETIONS
552};
553
554
555
556
557enum rxrpc_congest_mode {
558 RXRPC_CALL_SLOW_START,
559 RXRPC_CALL_CONGEST_AVOIDANCE,
560 RXRPC_CALL_PACKET_LOSS,
561 RXRPC_CALL_FAST_RETRANSMIT,
562 NR__RXRPC_CONGEST_MODES
563};
564
565
566
567
568
569struct rxrpc_call {
570 struct rcu_head rcu;
571 struct rxrpc_connection *conn;
572 struct rxrpc_peer *peer;
573 struct rxrpc_sock __rcu *socket;
574 struct rxrpc_net *rxnet;
575 const struct rxrpc_security *security;
576 struct mutex user_mutex;
577 unsigned long ack_at;
578 unsigned long ack_lost_at;
579 unsigned long resend_at;
580 unsigned long ping_at;
581 unsigned long keepalive_at;
582 unsigned long expect_rx_by;
583 unsigned long expect_req_by;
584 unsigned long expect_term_by;
585 u32 next_rx_timo;
586 u32 next_req_timo;
587 struct skcipher_request *cipher_req;
588 struct timer_list timer;
589 struct work_struct processor;
590 rxrpc_notify_rx_t notify_rx;
591 struct list_head link;
592 struct list_head chan_wait_link;
593 struct hlist_node error_link;
594 struct list_head accept_link;
595 struct list_head recvmsg_link;
596 struct list_head sock_link;
597 struct rb_node sock_node;
598 struct sk_buff *tx_pending;
599 wait_queue_head_t waitq;
600 s64 tx_total_len;
601 __be32 crypto_buf[2];
602 unsigned long user_call_ID;
603 unsigned long flags;
604 unsigned long events;
605 spinlock_t lock;
606 spinlock_t notify_lock;
607 rwlock_t state_lock;
608 u32 abort_code;
609 int error;
610 enum rxrpc_call_state state;
611 enum rxrpc_call_completion completion;
612 atomic_t usage;
613 u16 service_id;
614 u8 security_ix;
615 enum rxrpc_interruptibility interruptibility;
616 u32 call_id;
617 u32 cid;
618 int debug_id;
619 unsigned short rx_pkt_offset;
620 unsigned short rx_pkt_len;
621 bool rx_pkt_last;
622
623
624
625
626
627
628
629
630
631
632#define RXRPC_RXTX_BUFF_SIZE 64
633#define RXRPC_RXTX_BUFF_MASK (RXRPC_RXTX_BUFF_SIZE - 1)
634#define RXRPC_INIT_RX_WINDOW_SIZE 63
635 struct sk_buff **rxtx_buffer;
636 u8 *rxtx_annotations;
637#define RXRPC_TX_ANNO_ACK 0
638#define RXRPC_TX_ANNO_UNACK 1
639#define RXRPC_TX_ANNO_NAK 2
640#define RXRPC_TX_ANNO_RETRANS 3
641#define RXRPC_TX_ANNO_MASK 0x03
642#define RXRPC_TX_ANNO_LAST 0x04
643#define RXRPC_TX_ANNO_RESENT 0x08
644
645#define RXRPC_RX_ANNO_SUBPACKET 0x3f
646#define RXRPC_RX_ANNO_VERIFIED 0x80
647 rxrpc_seq_t tx_hard_ack;
648
649
650 rxrpc_seq_t tx_top;
651 u16 tx_backoff;
652
653
654
655
656
657#define RXRPC_TX_SMSS RXRPC_JUMBO_DATALEN
658 u8 cong_cwnd;
659 u8 cong_extra;
660 u8 cong_ssthresh;
661 enum rxrpc_congest_mode cong_mode:8;
662 u8 cong_dup_acks;
663 u8 cong_cumul_acks;
664 ktime_t cong_tstamp;
665
666 rxrpc_seq_t rx_hard_ack;
667
668
669 rxrpc_seq_t rx_top;
670 rxrpc_seq_t rx_expect_next;
671 rxrpc_serial_t rx_serial;
672 u8 rx_winsize;
673 u8 tx_winsize;
674 bool tx_phase;
675 u8 nr_jumbo_bad;
676
677 spinlock_t input_lock;
678
679
680 u8 ackr_reason;
681 rxrpc_serial_t ackr_serial;
682 rxrpc_serial_t ackr_first_seq;
683 rxrpc_seq_t ackr_prev_seq;
684 rxrpc_seq_t ackr_consumed;
685 rxrpc_seq_t ackr_seen;
686
687
688 rxrpc_serial_t rtt_serial[4];
689 ktime_t rtt_sent_at[4];
690 unsigned long rtt_avail;
691
692#define RXRPC_CALL_RTT_AVAIL_MASK 0xf
693#define RXRPC_CALL_RTT_PEND_SHIFT 8
694
695
696 ktime_t acks_latest_ts;
697 rxrpc_seq_t acks_lowest_nak;
698 rxrpc_seq_t acks_lost_top;
699 rxrpc_serial_t acks_lost_ping;
700};
701
702
703
704
705struct rxrpc_ack_summary {
706 u8 ack_reason;
707 u8 nr_acks;
708 u8 nr_nacks;
709 u8 nr_new_acks;
710 u8 nr_new_nacks;
711 u8 nr_rot_new_acks;
712 bool new_low_nack;
713 bool retrans_timeo;
714 u8 flight_size;
715
716 enum rxrpc_congest_mode mode:8;
717 u8 cwnd;
718 u8 ssthresh;
719 u8 dup_acks;
720 u8 cumulative_acks;
721};
722
723
724
725
726enum rxrpc_command {
727 RXRPC_CMD_SEND_DATA,
728 RXRPC_CMD_SEND_ABORT,
729 RXRPC_CMD_REJECT_BUSY,
730 RXRPC_CMD_CHARGE_ACCEPT,
731};
732
733struct rxrpc_call_params {
734 s64 tx_total_len;
735 unsigned long user_call_ID;
736 struct {
737 u32 hard;
738 u32 idle;
739 u32 normal;
740 } timeouts;
741 u8 nr_timeouts;
742 bool kernel;
743 enum rxrpc_interruptibility interruptibility;
744};
745
746struct rxrpc_send_params {
747 struct rxrpc_call_params call;
748 u32 abort_code;
749 enum rxrpc_command command : 8;
750 bool exclusive;
751 bool upgrade;
752};
753
754#include <trace/events/rxrpc.h>
755
756
757
758
759extern atomic_t rxrpc_n_tx_skbs, rxrpc_n_rx_skbs;
760extern struct workqueue_struct *rxrpc_workqueue;
761
762
763
764
765int rxrpc_service_prealloc(struct rxrpc_sock *, gfp_t);
766void rxrpc_discard_prealloc(struct rxrpc_sock *);
767struct rxrpc_call *rxrpc_new_incoming_call(struct rxrpc_local *,
768 struct rxrpc_sock *,
769 struct sk_buff *);
770void rxrpc_accept_incoming_calls(struct rxrpc_local *);
771int rxrpc_user_charge_accept(struct rxrpc_sock *, unsigned long);
772
773
774
775
776void rxrpc_propose_ACK(struct rxrpc_call *, u8, u32, bool, bool,
777 enum rxrpc_propose_ack_trace);
778void rxrpc_process_call(struct work_struct *);
779
780static inline void rxrpc_reduce_call_timer(struct rxrpc_call *call,
781 unsigned long expire_at,
782 unsigned long now,
783 enum rxrpc_timer_trace why)
784{
785 trace_rxrpc_timer(call, why, now);
786 timer_reduce(&call->timer, expire_at);
787}
788
789
790
791
792extern const char *const rxrpc_call_states[];
793extern const char *const rxrpc_call_completions[];
794extern unsigned int rxrpc_max_call_lifetime;
795extern struct kmem_cache *rxrpc_call_jar;
796
797struct rxrpc_call *rxrpc_find_call_by_user_ID(struct rxrpc_sock *, unsigned long);
798struct rxrpc_call *rxrpc_alloc_call(struct rxrpc_sock *, gfp_t, unsigned int);
799struct rxrpc_call *rxrpc_new_client_call(struct rxrpc_sock *,
800 struct rxrpc_conn_parameters *,
801 struct sockaddr_rxrpc *,
802 struct rxrpc_call_params *, gfp_t,
803 unsigned int);
804void rxrpc_incoming_call(struct rxrpc_sock *, struct rxrpc_call *,
805 struct sk_buff *);
806void rxrpc_release_call(struct rxrpc_sock *, struct rxrpc_call *);
807void rxrpc_release_calls_on_socket(struct rxrpc_sock *);
808bool __rxrpc_queue_call(struct rxrpc_call *);
809bool rxrpc_queue_call(struct rxrpc_call *);
810void rxrpc_see_call(struct rxrpc_call *);
811void rxrpc_get_call(struct rxrpc_call *, enum rxrpc_call_trace);
812void rxrpc_put_call(struct rxrpc_call *, enum rxrpc_call_trace);
813void rxrpc_cleanup_call(struct rxrpc_call *);
814void rxrpc_destroy_all_calls(struct rxrpc_net *);
815
816static inline bool rxrpc_is_service_call(const struct rxrpc_call *call)
817{
818 return test_bit(RXRPC_CALL_IS_SERVICE, &call->flags);
819}
820
821static inline bool rxrpc_is_client_call(const struct rxrpc_call *call)
822{
823 return !rxrpc_is_service_call(call);
824}
825
826
827
828
829extern unsigned int rxrpc_reap_client_connections;
830extern unsigned long rxrpc_conn_idle_client_expiry;
831extern unsigned long rxrpc_conn_idle_client_fast_expiry;
832extern struct idr rxrpc_client_conn_ids;
833
834void rxrpc_destroy_client_conn_ids(void);
835struct rxrpc_bundle *rxrpc_get_bundle(struct rxrpc_bundle *);
836void rxrpc_put_bundle(struct rxrpc_bundle *);
837int rxrpc_connect_call(struct rxrpc_sock *, struct rxrpc_call *,
838 struct rxrpc_conn_parameters *, struct sockaddr_rxrpc *,
839 gfp_t);
840void rxrpc_expose_client_call(struct rxrpc_call *);
841void rxrpc_disconnect_client_call(struct rxrpc_bundle *, struct rxrpc_call *);
842void rxrpc_put_client_conn(struct rxrpc_connection *);
843void rxrpc_discard_expired_client_conns(struct work_struct *);
844void rxrpc_destroy_all_client_connections(struct rxrpc_net *);
845void rxrpc_clean_up_local_conns(struct rxrpc_local *);
846
847
848
849
850void rxrpc_process_connection(struct work_struct *);
851void rxrpc_process_delayed_final_acks(struct rxrpc_connection *, bool);
852
853
854
855
856extern unsigned int rxrpc_connection_expiry;
857extern unsigned int rxrpc_closed_conn_expiry;
858
859struct rxrpc_connection *rxrpc_alloc_connection(gfp_t);
860struct rxrpc_connection *rxrpc_find_connection_rcu(struct rxrpc_local *,
861 struct sk_buff *,
862 struct rxrpc_peer **);
863void __rxrpc_disconnect_call(struct rxrpc_connection *, struct rxrpc_call *);
864void rxrpc_disconnect_call(struct rxrpc_call *);
865void rxrpc_kill_connection(struct rxrpc_connection *);
866bool rxrpc_queue_conn(struct rxrpc_connection *);
867void rxrpc_see_connection(struct rxrpc_connection *);
868struct rxrpc_connection *rxrpc_get_connection(struct rxrpc_connection *);
869struct rxrpc_connection *rxrpc_get_connection_maybe(struct rxrpc_connection *);
870void rxrpc_put_service_conn(struct rxrpc_connection *);
871void rxrpc_service_connection_reaper(struct work_struct *);
872void rxrpc_destroy_all_connections(struct rxrpc_net *);
873
874static inline bool rxrpc_conn_is_client(const struct rxrpc_connection *conn)
875{
876 return conn->out_clientflag;
877}
878
879static inline bool rxrpc_conn_is_service(const struct rxrpc_connection *conn)
880{
881 return !rxrpc_conn_is_client(conn);
882}
883
884static inline void rxrpc_put_connection(struct rxrpc_connection *conn)
885{
886 if (!conn)
887 return;
888
889 if (rxrpc_conn_is_client(conn))
890 rxrpc_put_client_conn(conn);
891 else
892 rxrpc_put_service_conn(conn);
893}
894
895static inline void rxrpc_reduce_conn_timer(struct rxrpc_connection *conn,
896 unsigned long expire_at)
897{
898 timer_reduce(&conn->timer, expire_at);
899}
900
901
902
903
904struct rxrpc_connection *rxrpc_find_service_conn_rcu(struct rxrpc_peer *,
905 struct sk_buff *);
906struct rxrpc_connection *rxrpc_prealloc_service_connection(struct rxrpc_net *, gfp_t);
907void rxrpc_new_incoming_connection(struct rxrpc_sock *, struct rxrpc_connection *,
908 const struct rxrpc_security *, struct sk_buff *);
909void rxrpc_unpublish_service_conn(struct rxrpc_connection *);
910
911
912
913
914int rxrpc_input_packet(struct sock *, struct sk_buff *);
915
916
917
918
919extern const struct rxrpc_security rxrpc_no_security;
920
921
922
923
924extern struct key_type key_type_rxrpc;
925
926int rxrpc_request_key(struct rxrpc_sock *, sockptr_t , int);
927int rxrpc_get_server_data_key(struct rxrpc_connection *, const void *, time64_t,
928 u32);
929
930
931
932
933extern void rxrpc_process_local_events(struct rxrpc_local *);
934
935
936
937
938struct rxrpc_local *rxrpc_lookup_local(struct net *, const struct sockaddr_rxrpc *);
939struct rxrpc_local *rxrpc_get_local(struct rxrpc_local *);
940struct rxrpc_local *rxrpc_get_local_maybe(struct rxrpc_local *);
941void rxrpc_put_local(struct rxrpc_local *);
942struct rxrpc_local *rxrpc_use_local(struct rxrpc_local *);
943void rxrpc_unuse_local(struct rxrpc_local *);
944void rxrpc_queue_local(struct rxrpc_local *);
945void rxrpc_destroy_all_locals(struct rxrpc_net *);
946
947static inline bool __rxrpc_unuse_local(struct rxrpc_local *local)
948{
949 return atomic_dec_return(&local->active_users) == 0;
950}
951
952static inline bool __rxrpc_use_local(struct rxrpc_local *local)
953{
954 return atomic_fetch_add_unless(&local->active_users, 1, 0) != 0;
955}
956
957
958
959
960extern unsigned int rxrpc_max_backlog __read_mostly;
961extern unsigned long rxrpc_requested_ack_delay;
962extern unsigned long rxrpc_soft_ack_delay;
963extern unsigned long rxrpc_idle_ack_delay;
964extern unsigned int rxrpc_rx_window_size;
965extern unsigned int rxrpc_rx_mtu;
966extern unsigned int rxrpc_rx_jumbo_max;
967
968extern const s8 rxrpc_ack_priority[];
969
970
971
972
973extern unsigned int rxrpc_net_id;
974extern struct pernet_operations rxrpc_net_ops;
975
976static inline struct rxrpc_net *rxrpc_net(struct net *net)
977{
978 return net_generic(net, rxrpc_net_id);
979}
980
981
982
983
984int rxrpc_send_ack_packet(struct rxrpc_call *, bool, rxrpc_serial_t *);
985int rxrpc_send_abort_packet(struct rxrpc_call *);
986int rxrpc_send_data_packet(struct rxrpc_call *, struct sk_buff *, bool);
987void rxrpc_reject_packets(struct rxrpc_local *);
988void rxrpc_send_keepalive(struct rxrpc_peer *);
989
990
991
992
993void rxrpc_error_report(struct sock *);
994void rxrpc_peer_keepalive_worker(struct work_struct *);
995
996
997
998
999struct rxrpc_peer *rxrpc_lookup_peer_rcu(struct rxrpc_local *,
1000 const struct sockaddr_rxrpc *);
1001struct rxrpc_peer *rxrpc_lookup_peer(struct rxrpc_sock *, struct rxrpc_local *,
1002 struct sockaddr_rxrpc *, gfp_t);
1003struct rxrpc_peer *rxrpc_alloc_peer(struct rxrpc_local *, gfp_t);
1004void rxrpc_new_incoming_peer(struct rxrpc_sock *, struct rxrpc_local *,
1005 struct rxrpc_peer *);
1006void rxrpc_destroy_all_peers(struct rxrpc_net *);
1007struct rxrpc_peer *rxrpc_get_peer(struct rxrpc_peer *);
1008struct rxrpc_peer *rxrpc_get_peer_maybe(struct rxrpc_peer *);
1009void rxrpc_put_peer(struct rxrpc_peer *);
1010void rxrpc_put_peer_locked(struct rxrpc_peer *);
1011
1012
1013
1014
1015extern const struct seq_operations rxrpc_call_seq_ops;
1016extern const struct seq_operations rxrpc_connection_seq_ops;
1017extern const struct seq_operations rxrpc_peer_seq_ops;
1018
1019
1020
1021
1022void rxrpc_notify_socket(struct rxrpc_call *);
1023bool __rxrpc_set_call_completion(struct rxrpc_call *, enum rxrpc_call_completion, u32, int);
1024bool rxrpc_set_call_completion(struct rxrpc_call *, enum rxrpc_call_completion, u32, int);
1025bool __rxrpc_call_completed(struct rxrpc_call *);
1026bool rxrpc_call_completed(struct rxrpc_call *);
1027bool __rxrpc_abort_call(const char *, struct rxrpc_call *, rxrpc_seq_t, u32, int);
1028bool rxrpc_abort_call(const char *, struct rxrpc_call *, rxrpc_seq_t, u32, int);
1029int rxrpc_recvmsg(struct socket *, struct msghdr *, size_t, int);
1030
1031
1032
1033
1034static inline bool __rxrpc_abort_eproto(struct rxrpc_call *call,
1035 struct sk_buff *skb,
1036 const char *eproto_why,
1037 const char *why,
1038 u32 abort_code)
1039{
1040 struct rxrpc_skb_priv *sp = rxrpc_skb(skb);
1041
1042 trace_rxrpc_rx_eproto(call, sp->hdr.serial, eproto_why);
1043 return rxrpc_abort_call(why, call, sp->hdr.seq, abort_code, -EPROTO);
1044}
1045
1046#define rxrpc_abort_eproto(call, skb, eproto_why, abort_why, abort_code) \
1047 __rxrpc_abort_eproto((call), (skb), tracepoint_string(eproto_why), \
1048 (abort_why), (abort_code))
1049
1050
1051
1052
1053void rxrpc_peer_add_rtt(struct rxrpc_call *, enum rxrpc_rtt_rx_trace, int,
1054 rxrpc_serial_t, rxrpc_serial_t, ktime_t, ktime_t);
1055unsigned long rxrpc_get_rto_backoff(struct rxrpc_peer *, bool);
1056void rxrpc_peer_init_rtt(struct rxrpc_peer *);
1057
1058
1059
1060
1061#ifdef CONFIG_RXKAD
1062extern const struct rxrpc_security rxkad;
1063#endif
1064
1065
1066
1067
1068int __init rxrpc_init_security(void);
1069const struct rxrpc_security *rxrpc_security_lookup(u8);
1070void rxrpc_exit_security(void);
1071int rxrpc_init_client_conn_security(struct rxrpc_connection *);
1072const struct rxrpc_security *rxrpc_get_incoming_security(struct rxrpc_sock *,
1073 struct sk_buff *);
1074struct key *rxrpc_look_up_server_security(struct rxrpc_connection *,
1075 struct sk_buff *, u32, u32);
1076
1077
1078
1079
1080int rxrpc_do_sendmsg(struct rxrpc_sock *, struct msghdr *, size_t);
1081
1082
1083
1084
1085extern struct key_type key_type_rxrpc_s;
1086
1087int rxrpc_server_keyring(struct rxrpc_sock *, sockptr_t, int);
1088
1089
1090
1091
1092void rxrpc_kernel_data_consumed(struct rxrpc_call *, struct sk_buff *);
1093void rxrpc_packet_destructor(struct sk_buff *);
1094void rxrpc_new_skb(struct sk_buff *, enum rxrpc_skb_trace);
1095void rxrpc_see_skb(struct sk_buff *, enum rxrpc_skb_trace);
1096void rxrpc_eaten_skb(struct sk_buff *, enum rxrpc_skb_trace);
1097void rxrpc_get_skb(struct sk_buff *, enum rxrpc_skb_trace);
1098void rxrpc_free_skb(struct sk_buff *, enum rxrpc_skb_trace);
1099void rxrpc_purge_queue(struct sk_buff_head *);
1100
1101
1102
1103
1104#ifdef CONFIG_SYSCTL
1105extern int __init rxrpc_sysctl_init(void);
1106extern void rxrpc_sysctl_exit(void);
1107#else
1108static inline int __init rxrpc_sysctl_init(void) { return 0; }
1109static inline void rxrpc_sysctl_exit(void) {}
1110#endif
1111
1112
1113
1114
1115int rxrpc_extract_addr_from_skb(struct sockaddr_rxrpc *, struct sk_buff *);
1116
1117static inline bool before(u32 seq1, u32 seq2)
1118{
1119 return (s32)(seq1 - seq2) < 0;
1120}
1121static inline bool before_eq(u32 seq1, u32 seq2)
1122{
1123 return (s32)(seq1 - seq2) <= 0;
1124}
1125static inline bool after(u32 seq1, u32 seq2)
1126{
1127 return (s32)(seq1 - seq2) > 0;
1128}
1129static inline bool after_eq(u32 seq1, u32 seq2)
1130{
1131 return (s32)(seq1 - seq2) >= 0;
1132}
1133
1134
1135
1136
1137extern unsigned int rxrpc_debug;
1138
1139#define dbgprintk(FMT,...) \
1140 printk("[%-6.6s] "FMT"\n", current->comm ,##__VA_ARGS__)
1141
1142#define kenter(FMT,...) dbgprintk("==> %s("FMT")",__func__ ,##__VA_ARGS__)
1143#define kleave(FMT,...) dbgprintk("<== %s()"FMT"",__func__ ,##__VA_ARGS__)
1144#define kdebug(FMT,...) dbgprintk(" "FMT ,##__VA_ARGS__)
1145#define kproto(FMT,...) dbgprintk("### "FMT ,##__VA_ARGS__)
1146#define knet(FMT,...) dbgprintk("@@@ "FMT ,##__VA_ARGS__)
1147
1148
1149#if defined(__KDEBUG)
1150#define _enter(FMT,...) kenter(FMT,##__VA_ARGS__)
1151#define _leave(FMT,...) kleave(FMT,##__VA_ARGS__)
1152#define _debug(FMT,...) kdebug(FMT,##__VA_ARGS__)
1153#define _proto(FMT,...) kproto(FMT,##__VA_ARGS__)
1154#define _net(FMT,...) knet(FMT,##__VA_ARGS__)
1155
1156#elif defined(CONFIG_AF_RXRPC_DEBUG)
1157#define RXRPC_DEBUG_KENTER 0x01
1158#define RXRPC_DEBUG_KLEAVE 0x02
1159#define RXRPC_DEBUG_KDEBUG 0x04
1160#define RXRPC_DEBUG_KPROTO 0x08
1161#define RXRPC_DEBUG_KNET 0x10
1162
1163#define _enter(FMT,...) \
1164do { \
1165 if (unlikely(rxrpc_debug & RXRPC_DEBUG_KENTER)) \
1166 kenter(FMT,##__VA_ARGS__); \
1167} while (0)
1168
1169#define _leave(FMT,...) \
1170do { \
1171 if (unlikely(rxrpc_debug & RXRPC_DEBUG_KLEAVE)) \
1172 kleave(FMT,##__VA_ARGS__); \
1173} while (0)
1174
1175#define _debug(FMT,...) \
1176do { \
1177 if (unlikely(rxrpc_debug & RXRPC_DEBUG_KDEBUG)) \
1178 kdebug(FMT,##__VA_ARGS__); \
1179} while (0)
1180
1181#define _proto(FMT,...) \
1182do { \
1183 if (unlikely(rxrpc_debug & RXRPC_DEBUG_KPROTO)) \
1184 kproto(FMT,##__VA_ARGS__); \
1185} while (0)
1186
1187#define _net(FMT,...) \
1188do { \
1189 if (unlikely(rxrpc_debug & RXRPC_DEBUG_KNET)) \
1190 knet(FMT,##__VA_ARGS__); \
1191} while (0)
1192
1193#else
1194#define _enter(FMT,...) no_printk("==> %s("FMT")",__func__ ,##__VA_ARGS__)
1195#define _leave(FMT,...) no_printk("<== %s()"FMT"",__func__ ,##__VA_ARGS__)
1196#define _debug(FMT,...) no_printk(" "FMT ,##__VA_ARGS__)
1197#define _proto(FMT,...) no_printk("### "FMT ,##__VA_ARGS__)
1198#define _net(FMT,...) no_printk("@@@ "FMT ,##__VA_ARGS__)
1199#endif
1200
1201
1202
1203
1204#if 1
1205
1206#define ASSERT(X) \
1207do { \
1208 if (unlikely(!(X))) { \
1209 pr_err("Assertion failed\n"); \
1210 BUG(); \
1211 } \
1212} while (0)
1213
1214#define ASSERTCMP(X, OP, Y) \
1215do { \
1216 __typeof__(X) _x = (X); \
1217 __typeof__(Y) _y = (__typeof__(X))(Y); \
1218 if (unlikely(!(_x OP _y))) { \
1219 pr_err("Assertion failed - %lu(0x%lx) %s %lu(0x%lx) is false\n", \
1220 (unsigned long)_x, (unsigned long)_x, #OP, \
1221 (unsigned long)_y, (unsigned long)_y); \
1222 BUG(); \
1223 } \
1224} while (0)
1225
1226#define ASSERTIF(C, X) \
1227do { \
1228 if (unlikely((C) && !(X))) { \
1229 pr_err("Assertion failed\n"); \
1230 BUG(); \
1231 } \
1232} while (0)
1233
1234#define ASSERTIFCMP(C, X, OP, Y) \
1235do { \
1236 __typeof__(X) _x = (X); \
1237 __typeof__(Y) _y = (__typeof__(X))(Y); \
1238 if (unlikely((C) && !(_x OP _y))) { \
1239 pr_err("Assertion failed - %lu(0x%lx) %s %lu(0x%lx) is false\n", \
1240 (unsigned long)_x, (unsigned long)_x, #OP, \
1241 (unsigned long)_y, (unsigned long)_y); \
1242 BUG(); \
1243 } \
1244} while (0)
1245
1246#else
1247
1248#define ASSERT(X) \
1249do { \
1250} while (0)
1251
1252#define ASSERTCMP(X, OP, Y) \
1253do { \
1254} while (0)
1255
1256#define ASSERTIF(C, X) \
1257do { \
1258} while (0)
1259
1260#define ASSERTIFCMP(C, X, OP, Y) \
1261do { \
1262} while (0)
1263
1264#endif
1265