0001
0002
0003
0004
0005
0006
0007
0008 #include <linux/atomic.h>
0009 #include <linux/seqlock.h>
0010 #include <linux/win_minmax.h>
0011 #include <net/net_namespace.h>
0012 #include <net/netns/generic.h>
0013 #include <net/sock.h>
0014 #include <net/af_rxrpc.h>
0015 #include <keys/rxrpc-type.h>
0016 #include "protocol.h"
0017
0018 #define FCRYPT_BSIZE 8
0019 struct rxrpc_crypt {
0020 union {
0021 u8 x[FCRYPT_BSIZE];
0022 __be32 n[2];
0023 };
0024 } __attribute__((aligned(8)));
0025
0026 #define rxrpc_queue_work(WS) queue_work(rxrpc_workqueue, (WS))
0027 #define rxrpc_queue_delayed_work(WS,D) \
0028 queue_delayed_work(rxrpc_workqueue, (WS), (D))
0029
0030 struct key_preparsed_payload;
0031 struct rxrpc_connection;
0032
0033
0034
0035
0036
0037 enum rxrpc_skb_mark {
0038 RXRPC_SKB_MARK_REJECT_BUSY,
0039 RXRPC_SKB_MARK_REJECT_ABORT,
0040 };
0041
0042
0043
0044
0045 enum {
0046 RXRPC_UNBOUND = 0,
0047 RXRPC_CLIENT_UNBOUND,
0048 RXRPC_CLIENT_BOUND,
0049 RXRPC_SERVER_BOUND,
0050 RXRPC_SERVER_BOUND2,
0051 RXRPC_SERVER_LISTENING,
0052 RXRPC_SERVER_LISTEN_DISABLED,
0053 RXRPC_CLOSE,
0054 };
0055
0056
0057
0058
0059 struct rxrpc_net {
0060 struct proc_dir_entry *proc_net;
0061 u32 epoch;
0062 struct list_head calls;
0063 spinlock_t call_lock;
0064 atomic_t nr_calls;
0065
0066 atomic_t nr_conns;
0067 struct list_head conn_proc_list;
0068 struct list_head service_conns;
0069 rwlock_t conn_lock;
0070 struct work_struct service_conn_reaper;
0071 struct timer_list service_conn_reap_timer;
0072
0073 bool live;
0074
0075 bool kill_all_client_conns;
0076 atomic_t nr_client_conns;
0077 spinlock_t client_conn_cache_lock;
0078 spinlock_t client_conn_discard_lock;
0079 struct list_head idle_client_conns;
0080 struct work_struct client_conn_reaper;
0081 struct timer_list client_conn_reap_timer;
0082
0083 struct hlist_head local_endpoints;
0084 struct mutex local_mutex;
0085
0086 DECLARE_HASHTABLE (peer_hash, 10);
0087 spinlock_t peer_hash_lock;
0088
0089 #define RXRPC_KEEPALIVE_TIME 20
0090 u8 peer_keepalive_cursor;
0091 time64_t peer_keepalive_base;
0092 struct list_head peer_keepalive[32];
0093 struct list_head peer_keepalive_new;
0094 struct timer_list peer_keepalive_timer;
0095 struct work_struct peer_keepalive_work;
0096 };
0097
0098
0099
0100
0101
0102
0103
0104
0105
0106 struct rxrpc_backlog {
0107 unsigned short peer_backlog_head;
0108 unsigned short peer_backlog_tail;
0109 unsigned short conn_backlog_head;
0110 unsigned short conn_backlog_tail;
0111 unsigned short call_backlog_head;
0112 unsigned short call_backlog_tail;
0113 #define RXRPC_BACKLOG_MAX 32
0114 struct rxrpc_peer *peer_backlog[RXRPC_BACKLOG_MAX];
0115 struct rxrpc_connection *conn_backlog[RXRPC_BACKLOG_MAX];
0116 struct rxrpc_call *call_backlog[RXRPC_BACKLOG_MAX];
0117 };
0118
0119
0120
0121
0122 struct rxrpc_sock {
0123
0124 struct sock sk;
0125 rxrpc_notify_new_call_t notify_new_call;
0126 rxrpc_discard_new_call_t discard_new_call;
0127 struct rxrpc_local *local;
0128 struct rxrpc_backlog *backlog;
0129 spinlock_t incoming_lock;
0130 struct list_head sock_calls;
0131 struct list_head to_be_accepted;
0132 struct list_head recvmsg_q;
0133 rwlock_t recvmsg_lock;
0134 struct key *key;
0135 struct key *securities;
0136 struct rb_root calls;
0137 unsigned long flags;
0138 #define RXRPC_SOCK_CONNECTED 0
0139 rwlock_t call_lock;
0140 u32 min_sec_level;
0141 #define RXRPC_SECURITY_MAX RXRPC_SECURITY_ENCRYPT
0142 bool exclusive;
0143 u16 second_service;
0144 struct {
0145
0146 u16 from;
0147 u16 to;
0148 } service_upgrade;
0149 sa_family_t family;
0150 struct sockaddr_rxrpc srx;
0151 struct sockaddr_rxrpc connect_srx;
0152 };
0153
0154 #define rxrpc_sk(__sk) container_of((__sk), struct rxrpc_sock, sk)
0155
0156
0157
0158
0159 struct rxrpc_host_header {
0160 u32 epoch;
0161 u32 cid;
0162 u32 callNumber;
0163 u32 seq;
0164 u32 serial;
0165 u8 type;
0166 u8 flags;
0167 u8 userStatus;
0168 u8 securityIndex;
0169 union {
0170 u16 _rsvd;
0171 u16 cksum;
0172 };
0173 u16 serviceId;
0174 } __packed;
0175
0176
0177
0178
0179
0180 struct rxrpc_skb_priv {
0181 atomic_t nr_ring_pins;
0182 u8 nr_subpackets;
0183 u8 rx_flags;
0184 #define RXRPC_SKB_INCL_LAST 0x01
0185 #define RXRPC_SKB_TX_BUFFER 0x02
0186 union {
0187 int remain;
0188
0189
0190 unsigned long rx_req_ack[(RXRPC_MAX_NR_JUMBO + BITS_PER_LONG - 1) /
0191 BITS_PER_LONG];
0192 };
0193
0194 struct rxrpc_host_header hdr;
0195 };
0196
0197 #define rxrpc_skb(__skb) ((struct rxrpc_skb_priv *) &(__skb)->cb)
0198
0199
0200
0201
0202 struct rxrpc_security {
0203 const char *name;
0204 u8 security_index;
0205 u32 no_key_abort;
0206
0207
0208 int (*init)(void);
0209
0210
0211 void (*exit)(void);
0212
0213
0214 int (*preparse_server_key)(struct key_preparsed_payload *);
0215
0216
0217 void (*free_preparse_server_key)(struct key_preparsed_payload *);
0218
0219
0220 void (*destroy_server_key)(struct key *);
0221
0222
0223 void (*describe_server_key)(const struct key *, struct seq_file *);
0224
0225
0226 int (*init_connection_security)(struct rxrpc_connection *,
0227 struct rxrpc_key_token *);
0228
0229
0230
0231
0232 int (*how_much_data)(struct rxrpc_call *, size_t,
0233 size_t *, size_t *, size_t *);
0234
0235
0236 int (*secure_packet)(struct rxrpc_call *, struct sk_buff *, size_t);
0237
0238
0239 int (*verify_packet)(struct rxrpc_call *, struct sk_buff *,
0240 unsigned int, unsigned int, rxrpc_seq_t, u16);
0241
0242
0243 void (*free_call_crypto)(struct rxrpc_call *);
0244
0245
0246 void (*locate_data)(struct rxrpc_call *, struct sk_buff *,
0247 unsigned int *, unsigned int *);
0248
0249
0250 int (*issue_challenge)(struct rxrpc_connection *);
0251
0252
0253 int (*respond_to_challenge)(struct rxrpc_connection *,
0254 struct sk_buff *,
0255 u32 *);
0256
0257
0258 int (*verify_response)(struct rxrpc_connection *,
0259 struct sk_buff *,
0260 u32 *);
0261
0262
0263 void (*clear)(struct rxrpc_connection *);
0264 };
0265
0266
0267
0268
0269
0270
0271 struct rxrpc_local {
0272 struct rcu_head rcu;
0273 atomic_t active_users;
0274 refcount_t ref;
0275 struct rxrpc_net *rxnet;
0276 struct hlist_node link;
0277 struct socket *socket;
0278 struct work_struct processor;
0279 struct rxrpc_sock __rcu *service;
0280 struct rw_semaphore defrag_sem;
0281 struct sk_buff_head reject_queue;
0282 struct sk_buff_head event_queue;
0283 struct rb_root client_bundles;
0284 spinlock_t client_bundles_lock;
0285 spinlock_t lock;
0286 rwlock_t services_lock;
0287 int debug_id;
0288 bool dead;
0289 bool service_closed;
0290 struct sockaddr_rxrpc srx;
0291 };
0292
0293
0294
0295
0296
0297 struct rxrpc_peer {
0298 struct rcu_head rcu;
0299 refcount_t ref;
0300 unsigned long hash_key;
0301 struct hlist_node hash_link;
0302 struct rxrpc_local *local;
0303 struct hlist_head error_targets;
0304 struct rb_root service_conns;
0305 struct list_head keepalive_link;
0306 time64_t last_tx_at;
0307 seqlock_t service_conn_lock;
0308 spinlock_t lock;
0309 unsigned int if_mtu;
0310 unsigned int mtu;
0311 unsigned int maxdata;
0312 unsigned short hdrsize;
0313 int debug_id;
0314 struct sockaddr_rxrpc srx;
0315
0316
0317 #define RXRPC_RTT_CACHE_SIZE 32
0318 spinlock_t rtt_input_lock;
0319 ktime_t rtt_last_req;
0320 unsigned int rtt_count;
0321
0322 u32 srtt_us;
0323 u32 mdev_us;
0324 u32 mdev_max_us;
0325 u32 rttvar_us;
0326 u32 rto_j;
0327 u8 backoff;
0328
0329 u8 cong_cwnd;
0330 };
0331
0332
0333
0334
0335 struct rxrpc_conn_proto {
0336 union {
0337 struct {
0338 u32 epoch;
0339 u32 cid;
0340 };
0341 u64 index_key;
0342 };
0343 };
0344
0345 struct rxrpc_conn_parameters {
0346 struct rxrpc_local *local;
0347 struct rxrpc_peer *peer;
0348 struct key *key;
0349 bool exclusive;
0350 bool upgrade;
0351 u16 service_id;
0352 u32 security_level;
0353 };
0354
0355
0356
0357
0358 enum rxrpc_conn_flag {
0359 RXRPC_CONN_HAS_IDR,
0360 RXRPC_CONN_IN_SERVICE_CONNS,
0361 RXRPC_CONN_DONT_REUSE,
0362 RXRPC_CONN_PROBING_FOR_UPGRADE,
0363 RXRPC_CONN_FINAL_ACK_0,
0364 RXRPC_CONN_FINAL_ACK_1,
0365 RXRPC_CONN_FINAL_ACK_2,
0366 RXRPC_CONN_FINAL_ACK_3,
0367 };
0368
0369 #define RXRPC_CONN_FINAL_ACK_MASK ((1UL << RXRPC_CONN_FINAL_ACK_0) | \
0370 (1UL << RXRPC_CONN_FINAL_ACK_1) | \
0371 (1UL << RXRPC_CONN_FINAL_ACK_2) | \
0372 (1UL << RXRPC_CONN_FINAL_ACK_3))
0373
0374
0375
0376
0377 enum rxrpc_conn_event {
0378 RXRPC_CONN_EV_CHALLENGE,
0379 };
0380
0381
0382
0383
0384 enum rxrpc_conn_proto_state {
0385 RXRPC_CONN_UNUSED,
0386 RXRPC_CONN_CLIENT,
0387 RXRPC_CONN_SERVICE_PREALLOC,
0388 RXRPC_CONN_SERVICE_UNSECURED,
0389 RXRPC_CONN_SERVICE_CHALLENGING,
0390 RXRPC_CONN_SERVICE,
0391 RXRPC_CONN_REMOTELY_ABORTED,
0392 RXRPC_CONN_LOCALLY_ABORTED,
0393 RXRPC_CONN__NR_STATES
0394 };
0395
0396
0397
0398
0399 struct rxrpc_bundle {
0400 struct rxrpc_conn_parameters params;
0401 refcount_t ref;
0402 unsigned int debug_id;
0403 bool try_upgrade;
0404 bool alloc_conn;
0405 short alloc_error;
0406 spinlock_t channel_lock;
0407 struct rb_node local_node;
0408 struct list_head waiting_calls;
0409 unsigned long avail_chans;
0410 struct rxrpc_connection *conns[4];
0411 };
0412
0413
0414
0415
0416
0417
0418 struct rxrpc_connection {
0419 struct rxrpc_conn_proto proto;
0420 struct rxrpc_conn_parameters params;
0421
0422 refcount_t ref;
0423 struct rcu_head rcu;
0424 struct list_head cache_link;
0425
0426 unsigned char act_chans;
0427 struct rxrpc_channel {
0428 unsigned long final_ack_at;
0429 struct rxrpc_call __rcu *call;
0430 unsigned int call_debug_id;
0431 u32 call_id;
0432 u32 call_counter;
0433 u32 last_call;
0434 u8 last_type;
0435 union {
0436 u32 last_seq;
0437 u32 last_abort;
0438 };
0439 } channels[RXRPC_MAXCALLS];
0440
0441 struct timer_list timer;
0442 struct work_struct processor;
0443 struct rxrpc_bundle *bundle;
0444 struct rb_node service_node;
0445 struct list_head proc_link;
0446 struct list_head link;
0447 struct sk_buff_head rx_queue;
0448
0449 const struct rxrpc_security *security;
0450 union {
0451 struct {
0452 struct crypto_sync_skcipher *cipher;
0453 struct rxrpc_crypt csum_iv;
0454 u32 nonce;
0455 } rxkad;
0456 };
0457 unsigned long flags;
0458 unsigned long events;
0459 unsigned long idle_timestamp;
0460 spinlock_t state_lock;
0461 enum rxrpc_conn_proto_state state;
0462 u32 abort_code;
0463 int debug_id;
0464 atomic_t serial;
0465 unsigned int hi_serial;
0466 u32 service_id;
0467 u8 security_ix;
0468 u8 out_clientflag;
0469 u8 bundle_shift;
0470 short error;
0471 };
0472
0473 static inline bool rxrpc_to_server(const struct rxrpc_skb_priv *sp)
0474 {
0475 return sp->hdr.flags & RXRPC_CLIENT_INITIATED;
0476 }
0477
0478 static inline bool rxrpc_to_client(const struct rxrpc_skb_priv *sp)
0479 {
0480 return !rxrpc_to_server(sp);
0481 }
0482
0483
0484
0485
0486 enum rxrpc_call_flag {
0487 RXRPC_CALL_RELEASED,
0488 RXRPC_CALL_HAS_USERID,
0489 RXRPC_CALL_IS_SERVICE,
0490 RXRPC_CALL_EXPOSED,
0491 RXRPC_CALL_RX_LAST,
0492 RXRPC_CALL_TX_LAST,
0493 RXRPC_CALL_SEND_PING,
0494 RXRPC_CALL_RETRANS_TIMEOUT,
0495 RXRPC_CALL_BEGAN_RX_TIMER,
0496 RXRPC_CALL_RX_HEARD,
0497 RXRPC_CALL_RX_UNDERRUN,
0498 RXRPC_CALL_DISCONNECTED,
0499 RXRPC_CALL_KERNEL,
0500 RXRPC_CALL_UPGRADE,
0501 };
0502
0503
0504
0505
0506 enum rxrpc_call_event {
0507 RXRPC_CALL_EV_ACK,
0508 RXRPC_CALL_EV_ABORT,
0509 RXRPC_CALL_EV_RESEND,
0510 RXRPC_CALL_EV_PING,
0511 RXRPC_CALL_EV_EXPIRED,
0512 RXRPC_CALL_EV_ACK_LOST,
0513 };
0514
0515
0516
0517
0518 enum rxrpc_call_state {
0519 RXRPC_CALL_UNINITIALISED,
0520 RXRPC_CALL_CLIENT_AWAIT_CONN,
0521 RXRPC_CALL_CLIENT_SEND_REQUEST,
0522 RXRPC_CALL_CLIENT_AWAIT_REPLY,
0523 RXRPC_CALL_CLIENT_RECV_REPLY,
0524 RXRPC_CALL_SERVER_PREALLOC,
0525 RXRPC_CALL_SERVER_SECURING,
0526 RXRPC_CALL_SERVER_RECV_REQUEST,
0527 RXRPC_CALL_SERVER_ACK_REQUEST,
0528 RXRPC_CALL_SERVER_SEND_REPLY,
0529 RXRPC_CALL_SERVER_AWAIT_ACK,
0530 RXRPC_CALL_COMPLETE,
0531 NR__RXRPC_CALL_STATES
0532 };
0533
0534
0535
0536
0537 enum rxrpc_call_completion {
0538 RXRPC_CALL_SUCCEEDED,
0539 RXRPC_CALL_REMOTELY_ABORTED,
0540 RXRPC_CALL_LOCALLY_ABORTED,
0541 RXRPC_CALL_LOCAL_ERROR,
0542 RXRPC_CALL_NETWORK_ERROR,
0543 NR__RXRPC_CALL_COMPLETIONS
0544 };
0545
0546
0547
0548
0549 enum rxrpc_congest_mode {
0550 RXRPC_CALL_SLOW_START,
0551 RXRPC_CALL_CONGEST_AVOIDANCE,
0552 RXRPC_CALL_PACKET_LOSS,
0553 RXRPC_CALL_FAST_RETRANSMIT,
0554 NR__RXRPC_CONGEST_MODES
0555 };
0556
0557
0558
0559
0560
0561 struct rxrpc_call {
0562 struct rcu_head rcu;
0563 struct rxrpc_connection *conn;
0564 struct rxrpc_peer *peer;
0565 struct rxrpc_sock __rcu *socket;
0566 struct rxrpc_net *rxnet;
0567 const struct rxrpc_security *security;
0568 struct mutex user_mutex;
0569 unsigned long ack_at;
0570 unsigned long ack_lost_at;
0571 unsigned long resend_at;
0572 unsigned long ping_at;
0573 unsigned long keepalive_at;
0574 unsigned long expect_rx_by;
0575 unsigned long expect_req_by;
0576 unsigned long expect_term_by;
0577 u32 next_rx_timo;
0578 u32 next_req_timo;
0579 struct skcipher_request *cipher_req;
0580 struct timer_list timer;
0581 struct work_struct processor;
0582 rxrpc_notify_rx_t notify_rx;
0583 struct list_head link;
0584 struct list_head chan_wait_link;
0585 struct hlist_node error_link;
0586 struct list_head accept_link;
0587 struct list_head recvmsg_link;
0588 struct list_head sock_link;
0589 struct rb_node sock_node;
0590 struct sk_buff *tx_pending;
0591 wait_queue_head_t waitq;
0592 s64 tx_total_len;
0593 __be32 crypto_buf[2];
0594 unsigned long user_call_ID;
0595 unsigned long flags;
0596 unsigned long events;
0597 spinlock_t lock;
0598 spinlock_t notify_lock;
0599 rwlock_t state_lock;
0600 u32 abort_code;
0601 int error;
0602 enum rxrpc_call_state state;
0603 enum rxrpc_call_completion completion;
0604 refcount_t ref;
0605 u16 service_id;
0606 u8 security_ix;
0607 enum rxrpc_interruptibility interruptibility;
0608 u32 call_id;
0609 u32 cid;
0610 int debug_id;
0611 unsigned short rx_pkt_offset;
0612 unsigned short rx_pkt_len;
0613 bool rx_pkt_last;
0614
0615
0616
0617
0618
0619
0620
0621
0622
0623
0624 #define RXRPC_RXTX_BUFF_SIZE 64
0625 #define RXRPC_RXTX_BUFF_MASK (RXRPC_RXTX_BUFF_SIZE - 1)
0626 #define RXRPC_INIT_RX_WINDOW_SIZE 63
0627 struct sk_buff **rxtx_buffer;
0628 u8 *rxtx_annotations;
0629 #define RXRPC_TX_ANNO_ACK 0
0630 #define RXRPC_TX_ANNO_UNACK 1
0631 #define RXRPC_TX_ANNO_NAK 2
0632 #define RXRPC_TX_ANNO_RETRANS 3
0633 #define RXRPC_TX_ANNO_MASK 0x03
0634 #define RXRPC_TX_ANNO_LAST 0x04
0635 #define RXRPC_TX_ANNO_RESENT 0x08
0636
0637 #define RXRPC_RX_ANNO_SUBPACKET 0x3f
0638 #define RXRPC_RX_ANNO_VERIFIED 0x80
0639 rxrpc_seq_t tx_hard_ack;
0640
0641
0642 rxrpc_seq_t tx_top;
0643 u16 tx_backoff;
0644
0645
0646
0647
0648
0649 #define RXRPC_TX_SMSS RXRPC_JUMBO_DATALEN
0650 u8 cong_cwnd;
0651 u8 cong_extra;
0652 u8 cong_ssthresh;
0653 enum rxrpc_congest_mode cong_mode:8;
0654 u8 cong_dup_acks;
0655 u8 cong_cumul_acks;
0656 ktime_t cong_tstamp;
0657
0658 rxrpc_seq_t rx_hard_ack;
0659
0660
0661 rxrpc_seq_t rx_top;
0662 rxrpc_seq_t rx_expect_next;
0663 rxrpc_serial_t rx_serial;
0664 u8 rx_winsize;
0665 u8 tx_winsize;
0666 bool tx_phase;
0667 u8 nr_jumbo_bad;
0668
0669 spinlock_t input_lock;
0670
0671
0672 u8 ackr_reason;
0673 rxrpc_serial_t ackr_serial;
0674 rxrpc_seq_t ackr_highest_seq;
0675 atomic_t ackr_nr_unacked;
0676 atomic_t ackr_nr_consumed;
0677
0678
0679 rxrpc_serial_t rtt_serial[4];
0680 ktime_t rtt_sent_at[4];
0681 unsigned long rtt_avail;
0682
0683 #define RXRPC_CALL_RTT_AVAIL_MASK 0xf
0684 #define RXRPC_CALL_RTT_PEND_SHIFT 8
0685
0686
0687 ktime_t acks_latest_ts;
0688 rxrpc_seq_t acks_first_seq;
0689 rxrpc_seq_t acks_prev_seq;
0690 rxrpc_seq_t acks_lowest_nak;
0691 rxrpc_seq_t acks_lost_top;
0692 rxrpc_serial_t acks_lost_ping;
0693 };
0694
0695
0696
0697
0698 struct rxrpc_ack_summary {
0699 u8 ack_reason;
0700 u8 nr_acks;
0701 u8 nr_nacks;
0702 u8 nr_new_acks;
0703 u8 nr_new_nacks;
0704 u8 nr_rot_new_acks;
0705 bool new_low_nack;
0706 bool retrans_timeo;
0707 u8 flight_size;
0708
0709 enum rxrpc_congest_mode mode:8;
0710 u8 cwnd;
0711 u8 ssthresh;
0712 u8 dup_acks;
0713 u8 cumulative_acks;
0714 };
0715
0716
0717
0718
0719 enum rxrpc_command {
0720 RXRPC_CMD_SEND_DATA,
0721 RXRPC_CMD_SEND_ABORT,
0722 RXRPC_CMD_REJECT_BUSY,
0723 RXRPC_CMD_CHARGE_ACCEPT,
0724 };
0725
0726 struct rxrpc_call_params {
0727 s64 tx_total_len;
0728 unsigned long user_call_ID;
0729 struct {
0730 u32 hard;
0731 u32 idle;
0732 u32 normal;
0733 } timeouts;
0734 u8 nr_timeouts;
0735 bool kernel;
0736 enum rxrpc_interruptibility interruptibility;
0737 };
0738
0739 struct rxrpc_send_params {
0740 struct rxrpc_call_params call;
0741 u32 abort_code;
0742 enum rxrpc_command command : 8;
0743 bool exclusive;
0744 bool upgrade;
0745 };
0746
0747 #include <trace/events/rxrpc.h>
0748
0749
0750
0751
0752 extern atomic_t rxrpc_n_tx_skbs, rxrpc_n_rx_skbs;
0753 extern struct workqueue_struct *rxrpc_workqueue;
0754
0755
0756
0757
0758 int rxrpc_service_prealloc(struct rxrpc_sock *, gfp_t);
0759 void rxrpc_discard_prealloc(struct rxrpc_sock *);
0760 struct rxrpc_call *rxrpc_new_incoming_call(struct rxrpc_local *,
0761 struct rxrpc_sock *,
0762 struct sk_buff *);
0763 void rxrpc_accept_incoming_calls(struct rxrpc_local *);
0764 int rxrpc_user_charge_accept(struct rxrpc_sock *, unsigned long);
0765
0766
0767
0768
0769 void rxrpc_propose_ACK(struct rxrpc_call *, u8, u32, bool, bool,
0770 enum rxrpc_propose_ack_trace);
0771 void rxrpc_process_call(struct work_struct *);
0772
0773 void rxrpc_reduce_call_timer(struct rxrpc_call *call,
0774 unsigned long expire_at,
0775 unsigned long now,
0776 enum rxrpc_timer_trace why);
0777
0778 void rxrpc_delete_call_timer(struct rxrpc_call *call);
0779
0780
0781
0782
0783 extern const char *const rxrpc_call_states[];
0784 extern const char *const rxrpc_call_completions[];
0785 extern unsigned int rxrpc_max_call_lifetime;
0786 extern struct kmem_cache *rxrpc_call_jar;
0787
0788 struct rxrpc_call *rxrpc_find_call_by_user_ID(struct rxrpc_sock *, unsigned long);
0789 struct rxrpc_call *rxrpc_alloc_call(struct rxrpc_sock *, gfp_t, unsigned int);
0790 struct rxrpc_call *rxrpc_new_client_call(struct rxrpc_sock *,
0791 struct rxrpc_conn_parameters *,
0792 struct sockaddr_rxrpc *,
0793 struct rxrpc_call_params *, gfp_t,
0794 unsigned int);
0795 void rxrpc_incoming_call(struct rxrpc_sock *, struct rxrpc_call *,
0796 struct sk_buff *);
0797 void rxrpc_release_call(struct rxrpc_sock *, struct rxrpc_call *);
0798 void rxrpc_release_calls_on_socket(struct rxrpc_sock *);
0799 bool __rxrpc_queue_call(struct rxrpc_call *);
0800 bool rxrpc_queue_call(struct rxrpc_call *);
0801 void rxrpc_see_call(struct rxrpc_call *);
0802 bool rxrpc_try_get_call(struct rxrpc_call *call, enum rxrpc_call_trace op);
0803 void rxrpc_get_call(struct rxrpc_call *, enum rxrpc_call_trace);
0804 void rxrpc_put_call(struct rxrpc_call *, enum rxrpc_call_trace);
0805 void rxrpc_cleanup_call(struct rxrpc_call *);
0806 void rxrpc_destroy_all_calls(struct rxrpc_net *);
0807
0808 static inline bool rxrpc_is_service_call(const struct rxrpc_call *call)
0809 {
0810 return test_bit(RXRPC_CALL_IS_SERVICE, &call->flags);
0811 }
0812
0813 static inline bool rxrpc_is_client_call(const struct rxrpc_call *call)
0814 {
0815 return !rxrpc_is_service_call(call);
0816 }
0817
0818
0819
0820
0821 extern unsigned int rxrpc_reap_client_connections;
0822 extern unsigned long rxrpc_conn_idle_client_expiry;
0823 extern unsigned long rxrpc_conn_idle_client_fast_expiry;
0824 extern struct idr rxrpc_client_conn_ids;
0825
0826 void rxrpc_destroy_client_conn_ids(void);
0827 struct rxrpc_bundle *rxrpc_get_bundle(struct rxrpc_bundle *);
0828 void rxrpc_put_bundle(struct rxrpc_bundle *);
0829 int rxrpc_connect_call(struct rxrpc_sock *, struct rxrpc_call *,
0830 struct rxrpc_conn_parameters *, struct sockaddr_rxrpc *,
0831 gfp_t);
0832 void rxrpc_expose_client_call(struct rxrpc_call *);
0833 void rxrpc_disconnect_client_call(struct rxrpc_bundle *, struct rxrpc_call *);
0834 void rxrpc_put_client_conn(struct rxrpc_connection *);
0835 void rxrpc_discard_expired_client_conns(struct work_struct *);
0836 void rxrpc_destroy_all_client_connections(struct rxrpc_net *);
0837 void rxrpc_clean_up_local_conns(struct rxrpc_local *);
0838
0839
0840
0841
0842 void rxrpc_process_connection(struct work_struct *);
0843 void rxrpc_process_delayed_final_acks(struct rxrpc_connection *, bool);
0844
0845
0846
0847
0848 extern unsigned int rxrpc_connection_expiry;
0849 extern unsigned int rxrpc_closed_conn_expiry;
0850
0851 struct rxrpc_connection *rxrpc_alloc_connection(gfp_t);
0852 struct rxrpc_connection *rxrpc_find_connection_rcu(struct rxrpc_local *,
0853 struct sk_buff *,
0854 struct rxrpc_peer **);
0855 void __rxrpc_disconnect_call(struct rxrpc_connection *, struct rxrpc_call *);
0856 void rxrpc_disconnect_call(struct rxrpc_call *);
0857 void rxrpc_kill_connection(struct rxrpc_connection *);
0858 bool rxrpc_queue_conn(struct rxrpc_connection *);
0859 void rxrpc_see_connection(struct rxrpc_connection *);
0860 struct rxrpc_connection *rxrpc_get_connection(struct rxrpc_connection *);
0861 struct rxrpc_connection *rxrpc_get_connection_maybe(struct rxrpc_connection *);
0862 void rxrpc_put_service_conn(struct rxrpc_connection *);
0863 void rxrpc_service_connection_reaper(struct work_struct *);
0864 void rxrpc_destroy_all_connections(struct rxrpc_net *);
0865
0866 static inline bool rxrpc_conn_is_client(const struct rxrpc_connection *conn)
0867 {
0868 return conn->out_clientflag;
0869 }
0870
0871 static inline bool rxrpc_conn_is_service(const struct rxrpc_connection *conn)
0872 {
0873 return !rxrpc_conn_is_client(conn);
0874 }
0875
0876 static inline void rxrpc_put_connection(struct rxrpc_connection *conn)
0877 {
0878 if (!conn)
0879 return;
0880
0881 if (rxrpc_conn_is_client(conn))
0882 rxrpc_put_client_conn(conn);
0883 else
0884 rxrpc_put_service_conn(conn);
0885 }
0886
0887 static inline void rxrpc_reduce_conn_timer(struct rxrpc_connection *conn,
0888 unsigned long expire_at)
0889 {
0890 timer_reduce(&conn->timer, expire_at);
0891 }
0892
0893
0894
0895
0896 struct rxrpc_connection *rxrpc_find_service_conn_rcu(struct rxrpc_peer *,
0897 struct sk_buff *);
0898 struct rxrpc_connection *rxrpc_prealloc_service_connection(struct rxrpc_net *, gfp_t);
0899 void rxrpc_new_incoming_connection(struct rxrpc_sock *, struct rxrpc_connection *,
0900 const struct rxrpc_security *, struct sk_buff *);
0901 void rxrpc_unpublish_service_conn(struct rxrpc_connection *);
0902
0903
0904
0905
0906 int rxrpc_input_packet(struct sock *, struct sk_buff *);
0907
0908
0909
0910
0911 extern const struct rxrpc_security rxrpc_no_security;
0912
0913
0914
0915
0916 extern struct key_type key_type_rxrpc;
0917
0918 int rxrpc_request_key(struct rxrpc_sock *, sockptr_t , int);
0919 int rxrpc_get_server_data_key(struct rxrpc_connection *, const void *, time64_t,
0920 u32);
0921
0922
0923
0924
0925 extern void rxrpc_process_local_events(struct rxrpc_local *);
0926
0927
0928
0929
0930 struct rxrpc_local *rxrpc_lookup_local(struct net *, const struct sockaddr_rxrpc *);
0931 struct rxrpc_local *rxrpc_get_local(struct rxrpc_local *);
0932 struct rxrpc_local *rxrpc_get_local_maybe(struct rxrpc_local *);
0933 void rxrpc_put_local(struct rxrpc_local *);
0934 struct rxrpc_local *rxrpc_use_local(struct rxrpc_local *);
0935 void rxrpc_unuse_local(struct rxrpc_local *);
0936 void rxrpc_queue_local(struct rxrpc_local *);
0937 void rxrpc_destroy_all_locals(struct rxrpc_net *);
0938
0939 static inline bool __rxrpc_unuse_local(struct rxrpc_local *local)
0940 {
0941 return atomic_dec_return(&local->active_users) == 0;
0942 }
0943
0944 static inline bool __rxrpc_use_local(struct rxrpc_local *local)
0945 {
0946 return atomic_fetch_add_unless(&local->active_users, 1, 0) != 0;
0947 }
0948
0949
0950
0951
0952 extern unsigned int rxrpc_max_backlog __read_mostly;
0953 extern unsigned long rxrpc_requested_ack_delay;
0954 extern unsigned long rxrpc_soft_ack_delay;
0955 extern unsigned long rxrpc_idle_ack_delay;
0956 extern unsigned int rxrpc_rx_window_size;
0957 extern unsigned int rxrpc_rx_mtu;
0958 extern unsigned int rxrpc_rx_jumbo_max;
0959
0960 extern const s8 rxrpc_ack_priority[];
0961
0962
0963
0964
0965 extern unsigned int rxrpc_net_id;
0966 extern struct pernet_operations rxrpc_net_ops;
0967
0968 static inline struct rxrpc_net *rxrpc_net(struct net *net)
0969 {
0970 return net_generic(net, rxrpc_net_id);
0971 }
0972
0973
0974
0975
0976 int rxrpc_send_ack_packet(struct rxrpc_call *, bool, rxrpc_serial_t *);
0977 int rxrpc_send_abort_packet(struct rxrpc_call *);
0978 int rxrpc_send_data_packet(struct rxrpc_call *, struct sk_buff *, bool);
0979 void rxrpc_reject_packets(struct rxrpc_local *);
0980 void rxrpc_send_keepalive(struct rxrpc_peer *);
0981
0982
0983
0984
0985 void rxrpc_encap_err_rcv(struct sock *sk, struct sk_buff *skb, unsigned int udp_offset);
0986 void rxrpc_error_report(struct sock *);
0987 void rxrpc_peer_keepalive_worker(struct work_struct *);
0988
0989
0990
0991
0992 struct rxrpc_peer *rxrpc_lookup_peer_rcu(struct rxrpc_local *,
0993 const struct sockaddr_rxrpc *);
0994 struct rxrpc_peer *rxrpc_lookup_peer(struct rxrpc_sock *, struct rxrpc_local *,
0995 struct sockaddr_rxrpc *, gfp_t);
0996 struct rxrpc_peer *rxrpc_alloc_peer(struct rxrpc_local *, gfp_t);
0997 void rxrpc_new_incoming_peer(struct rxrpc_sock *, struct rxrpc_local *,
0998 struct rxrpc_peer *);
0999 void rxrpc_destroy_all_peers(struct rxrpc_net *);
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 *);
1003 void rxrpc_put_peer_locked(struct rxrpc_peer *);
1004
1005
1006
1007
1008 extern const struct seq_operations rxrpc_call_seq_ops;
1009 extern const struct seq_operations rxrpc_connection_seq_ops;
1010 extern const struct seq_operations rxrpc_peer_seq_ops;
1011 extern const struct seq_operations rxrpc_local_seq_ops;
1012
1013
1014
1015
1016 void rxrpc_notify_socket(struct rxrpc_call *);
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);
1023 int rxrpc_recvmsg(struct socket *, struct msghdr *, size_t, int);
1024
1025
1026
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
1044
1045
1046
1047 void rxrpc_peer_add_rtt(struct rxrpc_call *, enum rxrpc_rtt_rx_trace, int,
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
1052
1053
1054
1055 #ifdef CONFIG_RXKAD
1056 extern const struct rxrpc_security rxkad;
1057 #endif
1058
1059
1060
1061
1062 int __init rxrpc_init_security(void);
1063 const struct rxrpc_security *rxrpc_security_lookup(u8);
1064 void rxrpc_exit_security(void);
1065 int rxrpc_init_client_conn_security(struct rxrpc_connection *);
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);
1070
1071
1072
1073
1074 int rxrpc_do_sendmsg(struct rxrpc_sock *, struct msghdr *, size_t);
1075
1076
1077
1078
1079 extern struct key_type key_type_rxrpc_s;
1080
1081 int rxrpc_server_keyring(struct rxrpc_sock *, sockptr_t, int);
1082
1083
1084
1085
1086 void rxrpc_kernel_data_consumed(struct rxrpc_call *, struct sk_buff *);
1087 void rxrpc_packet_destructor(struct sk_buff *);
1088 void rxrpc_new_skb(struct sk_buff *, enum rxrpc_skb_trace);
1089 void rxrpc_see_skb(struct sk_buff *, enum rxrpc_skb_trace);
1090 void rxrpc_eaten_skb(struct sk_buff *, enum rxrpc_skb_trace);
1091 void rxrpc_get_skb(struct sk_buff *, enum rxrpc_skb_trace);
1092 void rxrpc_free_skb(struct sk_buff *, enum rxrpc_skb_trace);
1093 void rxrpc_purge_queue(struct sk_buff_head *);
1094
1095
1096
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
1106
1107
1108
1109 int rxrpc_extract_addr_from_skb(struct sockaddr_rxrpc *, struct sk_buff *);
1110
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
1128
1129
1130
1131 extern unsigned int rxrpc_debug;
1132
1133 #define dbgprintk(FMT,...) \
1134 printk("[%-6.6s] "FMT"\n", current->comm ,##__VA_ARGS__)
1135
1136 #define kenter(FMT,...) dbgprintk("==> %s("FMT")",__func__ ,##__VA_ARGS__)
1137 #define kleave(FMT,...) dbgprintk("<== %s()"FMT"",__func__ ,##__VA_ARGS__)
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
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__)
1193 #endif
1194
1195
1196
1197
1198 #if 1
1199
1200 #define ASSERT(X) \
1201 do { \
1202 if (unlikely(!(X))) { \
1203 pr_err("Assertion failed\n"); \
1204 BUG(); \
1205 } \
1206 } while (0)
1207
1208 #define ASSERTCMP(X, OP, Y) \
1209 do { \
1210 __typeof__(X) _x = (X); \
1211 __typeof__(Y) _y = (__typeof__(X))(Y); \
1212 if (unlikely(!(_x OP _y))) { \
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); \
1216 BUG(); \
1217 } \
1218 } while (0)
1219
1220 #define ASSERTIF(C, X) \
1221 do { \
1222 if (unlikely((C) && !(X))) { \
1223 pr_err("Assertion failed\n"); \
1224 BUG(); \
1225 } \
1226 } while (0)
1227
1228 #define ASSERTIFCMP(C, X, OP, Y) \
1229 do { \
1230 __typeof__(X) _x = (X); \
1231 __typeof__(Y) _y = (__typeof__(X))(Y); \
1232 if (unlikely((C) && !(_x OP _y))) { \
1233 pr_err("Assertion failed - %lu(0x%lx) %s %lu(0x%lx) is false\n", \
1234 (unsigned long)_x, (unsigned long)_x, #OP, \
1235 (unsigned long)_y, (unsigned long)_y); \
1236 BUG(); \
1237 } \
1238 } while (0)
1239
1240 #else
1241
1242 #define ASSERT(X) \
1243 do { \
1244 } while (0)
1245
1246 #define ASSERTCMP(X, OP, Y) \
1247 do { \
1248 } while (0)
1249
1250 #define ASSERTIF(C, X) \
1251 do { \
1252 } while (0)
1253
1254 #define ASSERTIFCMP(C, X, OP, Y) \
1255 do { \
1256 } while (0)
1257
1258 #endif