12874c5fdSThomas Gleixner /* SPDX-License-Identifier: GPL-2.0-or-later */ 217926a79SDavid Howells /* AF_RXRPC internal definitions 317926a79SDavid Howells * 417926a79SDavid Howells * Copyright (C) 2007 Red Hat, Inc. All Rights Reserved. 517926a79SDavid Howells * Written by David Howells (dhowells@redhat.com) 617926a79SDavid Howells */ 717926a79SDavid Howells 8be6e6707SDavid Howells #include <linux/atomic.h> 98496af50SDavid Howells #include <linux/seqlock.h> 10c410bf01SDavid Howells #include <linux/win_minmax.h> 112baec2c3SDavid Howells #include <net/net_namespace.h> 122baec2c3SDavid Howells #include <net/netns/generic.h> 13e0e4d82fSDavid Howells #include <net/sock.h> 14be6e6707SDavid Howells #include <net/af_rxrpc.h> 1541057ebdSDavid Howells #include <keys/rxrpc-type.h> 16ddc6c70fSDavid Howells #include "protocol.h" 1717926a79SDavid Howells 1817926a79SDavid Howells #define FCRYPT_BSIZE 8 1917926a79SDavid Howells struct rxrpc_crypt { 2017926a79SDavid Howells union { 2117926a79SDavid Howells u8 x[FCRYPT_BSIZE]; 2291e916cfSAl Viro __be32 n[2]; 2317926a79SDavid Howells }; 2417926a79SDavid Howells } __attribute__((aligned(8))); 2517926a79SDavid Howells 26651350d1SDavid Howells #define rxrpc_queue_work(WS) queue_work(rxrpc_workqueue, (WS)) 27651350d1SDavid Howells #define rxrpc_queue_delayed_work(WS,D) \ 28651350d1SDavid Howells queue_delayed_work(rxrpc_workqueue, (WS), (D)) 29651350d1SDavid Howells 3012da59fcSDavid Howells struct key_preparsed_payload; 31cc8feb8eSDavid Howells struct rxrpc_connection; 3202a19356SDavid Howells struct rxrpc_txbuf; 33cc8feb8eSDavid Howells 3417926a79SDavid Howells /* 35ece64fecSDavid Howells * Mark applied to socket buffers in skb->mark. skb->priority is used 36ece64fecSDavid Howells * to pass supplementary information. 37d001648eSDavid Howells */ 38d001648eSDavid Howells enum rxrpc_skb_mark { 39446b3e14SDavid Howells RXRPC_SKB_MARK_PACKET, /* Received packet */ 40ff734825SDavid Howells RXRPC_SKB_MARK_ERROR, /* Error notification */ 41ece64fecSDavid Howells RXRPC_SKB_MARK_REJECT_BUSY, /* Reject with BUSY */ 42ece64fecSDavid Howells RXRPC_SKB_MARK_REJECT_ABORT, /* Reject with ABORT (code in skb->priority) */ 43d001648eSDavid Howells }; 44d001648eSDavid Howells 45d001648eSDavid Howells /* 4617926a79SDavid Howells * sk_state for RxRPC sockets 4717926a79SDavid Howells */ 4817926a79SDavid Howells enum { 492341e077SDavid Howells RXRPC_UNBOUND = 0, 502341e077SDavid Howells RXRPC_CLIENT_UNBOUND, /* Unbound socket used as client */ 5117926a79SDavid Howells RXRPC_CLIENT_BOUND, /* client local address bound */ 5217926a79SDavid Howells RXRPC_SERVER_BOUND, /* server local address bound */ 5328036f44SDavid Howells RXRPC_SERVER_BOUND2, /* second server local address bound */ 5417926a79SDavid Howells RXRPC_SERVER_LISTENING, /* server listening for connections */ 55210f0353SDavid Howells RXRPC_SERVER_LISTEN_DISABLED, /* server listening disabled */ 5617926a79SDavid Howells RXRPC_CLOSE, /* socket is being closed */ 5717926a79SDavid Howells }; 5817926a79SDavid Howells 5917926a79SDavid Howells /* 602baec2c3SDavid Howells * Per-network namespace data. 612baec2c3SDavid Howells */ 622baec2c3SDavid Howells struct rxrpc_net { 632baec2c3SDavid Howells struct proc_dir_entry *proc_net; /* Subdir in /proc/net */ 642baec2c3SDavid Howells u32 epoch; /* Local epoch for detecting local-end reset */ 652baec2c3SDavid Howells struct list_head calls; /* List of calls active in this namespace */ 66ad25f5cbSDavid Howells spinlock_t call_lock; /* Lock for ->calls */ 67d3be4d24SDavid Howells atomic_t nr_calls; /* Count of allocated calls */ 682baec2c3SDavid Howells 6931f5f9a1SDavid Howells atomic_t nr_conns; 702baec2c3SDavid Howells struct list_head conn_proc_list; /* List of conns in this namespace for proc */ 712baec2c3SDavid Howells struct list_head service_conns; /* Service conns in this namespace */ 722baec2c3SDavid Howells rwlock_t conn_lock; /* Lock for ->conn_proc_list, ->service_conns */ 733d18cbb7SDavid Howells struct work_struct service_conn_reaper; 743d18cbb7SDavid Howells struct timer_list service_conn_reap_timer; 752baec2c3SDavid Howells 76f859ab61SDavid Howells bool live; 77245500d8SDavid Howells 78245500d8SDavid Howells bool kill_all_client_conns; 79245500d8SDavid Howells atomic_t nr_client_conns; 802baec2c3SDavid Howells spinlock_t client_conn_cache_lock; /* Lock for ->*_client_conns */ 813cec055cSDavid Howells struct mutex client_conn_discard_lock; /* Prevent multiple discarders */ 822baec2c3SDavid Howells struct list_head idle_client_conns; 833d18cbb7SDavid Howells struct work_struct client_conn_reaper; 843d18cbb7SDavid Howells struct timer_list client_conn_reap_timer; 852baec2c3SDavid Howells 8633912c26SDavid Howells struct hlist_head local_endpoints; 872baec2c3SDavid Howells struct mutex local_mutex; /* Lock for ->local_endpoints */ 882baec2c3SDavid Howells 892baec2c3SDavid Howells DECLARE_HASHTABLE (peer_hash, 10); 90ace45becSDavid Howells spinlock_t peer_hash_lock; /* Lock for ->peer_hash */ 91ace45becSDavid Howells 92ace45becSDavid Howells #define RXRPC_KEEPALIVE_TIME 20 /* NAT keepalive time in seconds */ 93ace45becSDavid Howells u8 peer_keepalive_cursor; 94330bdcfaSDavid Howells time64_t peer_keepalive_base; 95330bdcfaSDavid Howells struct list_head peer_keepalive[32]; 96330bdcfaSDavid Howells struct list_head peer_keepalive_new; 97ace45becSDavid Howells struct timer_list peer_keepalive_timer; 98ace45becSDavid Howells struct work_struct peer_keepalive_work; 99b0154246SDavid Howells 100b0154246SDavid Howells atomic_t stat_tx_data; 101b0154246SDavid Howells atomic_t stat_tx_data_retrans; 102b0154246SDavid Howells atomic_t stat_tx_data_send; 103b0154246SDavid Howells atomic_t stat_tx_data_send_frag; 10432cf8edbSDavid Howells atomic_t stat_tx_data_send_fail; 10532cf8edbSDavid Howells atomic_t stat_tx_data_underflow; 10632cf8edbSDavid Howells atomic_t stat_tx_data_cwnd_reset; 107b0154246SDavid Howells atomic_t stat_rx_data; 108b0154246SDavid Howells atomic_t stat_rx_data_reqack; 109b0154246SDavid Howells atomic_t stat_rx_data_jumbo; 110f2a676d1SDavid Howells 111f2a676d1SDavid Howells atomic_t stat_tx_ack_fill; 112f2a676d1SDavid Howells atomic_t stat_tx_ack_send; 113f2a676d1SDavid Howells atomic_t stat_tx_ack_skip; 114f2a676d1SDavid Howells atomic_t stat_tx_acks[256]; 115f2a676d1SDavid Howells atomic_t stat_rx_acks[256]; 116f7fa5242SDavid Howells 117f7fa5242SDavid Howells atomic_t stat_why_req_ack[8]; 118a275da62SDavid Howells 119a275da62SDavid Howells atomic_t stat_io_loop; 1202baec2c3SDavid Howells }; 1212baec2c3SDavid Howells 1222baec2c3SDavid Howells /* 12300e90712SDavid Howells * Service backlog preallocation. 12400e90712SDavid Howells * 12500e90712SDavid Howells * This contains circular buffers of preallocated peers, connections and calls 12600e90712SDavid Howells * for incoming service calls and their head and tail pointers. This allows 12700e90712SDavid Howells * calls to be set up in the data_ready handler, thereby avoiding the need to 12800e90712SDavid Howells * shuffle packets around so much. 12900e90712SDavid Howells */ 13000e90712SDavid Howells struct rxrpc_backlog { 13100e90712SDavid Howells unsigned short peer_backlog_head; 13200e90712SDavid Howells unsigned short peer_backlog_tail; 13300e90712SDavid Howells unsigned short conn_backlog_head; 13400e90712SDavid Howells unsigned short conn_backlog_tail; 13500e90712SDavid Howells unsigned short call_backlog_head; 13600e90712SDavid Howells unsigned short call_backlog_tail; 13700e90712SDavid Howells #define RXRPC_BACKLOG_MAX 32 13800e90712SDavid Howells struct rxrpc_peer *peer_backlog[RXRPC_BACKLOG_MAX]; 13900e90712SDavid Howells struct rxrpc_connection *conn_backlog[RXRPC_BACKLOG_MAX]; 14000e90712SDavid Howells struct rxrpc_call *call_backlog[RXRPC_BACKLOG_MAX]; 14100e90712SDavid Howells }; 14200e90712SDavid Howells 14300e90712SDavid Howells /* 14417926a79SDavid Howells * RxRPC socket definition 14517926a79SDavid Howells */ 14617926a79SDavid Howells struct rxrpc_sock { 14717926a79SDavid Howells /* WARNING: sk has to be the first member */ 14817926a79SDavid Howells struct sock sk; 149d001648eSDavid Howells rxrpc_notify_new_call_t notify_new_call; /* Func to notify of new call */ 15000e90712SDavid Howells rxrpc_discard_new_call_t discard_new_call; /* Func to discard a new call */ 15117926a79SDavid Howells struct rxrpc_local *local; /* local endpoint */ 15200e90712SDavid Howells struct rxrpc_backlog *backlog; /* Preallocation for services */ 153248f219cSDavid Howells spinlock_t incoming_lock; /* Incoming call vs service shutdown lock */ 154248f219cSDavid Howells struct list_head sock_calls; /* List of calls owned by this socket */ 155248f219cSDavid Howells struct list_head to_be_accepted; /* calls awaiting acceptance */ 156248f219cSDavid Howells struct list_head recvmsg_q; /* Calls awaiting recvmsg's attention */ 157248f219cSDavid Howells rwlock_t recvmsg_lock; /* Lock for recvmsg_q */ 15817926a79SDavid Howells struct key *key; /* security for this socket */ 15917926a79SDavid Howells struct key *securities; /* list of server security descriptors */ 16000e90712SDavid Howells struct rb_root calls; /* User ID -> call mapping */ 16117926a79SDavid Howells unsigned long flags; 1622341e077SDavid Howells #define RXRPC_SOCK_CONNECTED 0 /* connect_srx is set */ 16317926a79SDavid Howells rwlock_t call_lock; /* lock for calls */ 16417926a79SDavid Howells u32 min_sec_level; /* minimum security level */ 16517926a79SDavid Howells #define RXRPC_SECURITY_MAX RXRPC_SECURITY_ENCRYPT 166cc8feb8eSDavid Howells bool exclusive; /* Exclusive connection for a client socket */ 16728036f44SDavid Howells u16 second_service; /* Additional service bound to the endpoint */ 1684722974dSDavid Howells struct { 1694722974dSDavid Howells /* Service upgrade information */ 1704722974dSDavid Howells u16 from; /* Service ID to upgrade (if not 0) */ 1714722974dSDavid Howells u16 to; /* service ID to upgrade to */ 1724722974dSDavid Howells } service_upgrade; 173cc8feb8eSDavid Howells sa_family_t family; /* Protocol family created with */ 1744722974dSDavid Howells struct sockaddr_rxrpc srx; /* Primary Service/local addresses */ 1752341e077SDavid Howells struct sockaddr_rxrpc connect_srx; /* Default client address from connect() */ 17617926a79SDavid Howells }; 17717926a79SDavid Howells 17817926a79SDavid Howells #define rxrpc_sk(__sk) container_of((__sk), struct rxrpc_sock, sk) 17917926a79SDavid Howells 18017926a79SDavid Howells /* 1810d12f8a4SDavid Howells * CPU-byteorder normalised Rx packet header. 1820d12f8a4SDavid Howells */ 1830d12f8a4SDavid Howells struct rxrpc_host_header { 1840d12f8a4SDavid Howells u32 epoch; /* client boot timestamp */ 1850d12f8a4SDavid Howells u32 cid; /* connection and channel ID */ 1860d12f8a4SDavid Howells u32 callNumber; /* call ID (0 for connection-level packets) */ 1870d12f8a4SDavid Howells u32 seq; /* sequence number of pkt in call stream */ 1880d12f8a4SDavid Howells u32 serial; /* serial number of pkt sent to network */ 1890d12f8a4SDavid Howells u8 type; /* packet type */ 1900d12f8a4SDavid Howells u8 flags; /* packet flags */ 1910d12f8a4SDavid Howells u8 userStatus; /* app-layer defined status */ 1920d12f8a4SDavid Howells u8 securityIndex; /* security protocol ID */ 1930d12f8a4SDavid Howells union { 1940d12f8a4SDavid Howells u16 _rsvd; /* reserved */ 1950d12f8a4SDavid Howells u16 cksum; /* kerberos security checksum */ 1960d12f8a4SDavid Howells }; 1970d12f8a4SDavid Howells u16 serviceId; /* service ID */ 1980d12f8a4SDavid Howells } __packed; 1990d12f8a4SDavid Howells 2000d12f8a4SDavid Howells /* 20117926a79SDavid Howells * RxRPC socket buffer private variables 20217926a79SDavid Howells * - max 48 bytes (struct sk_buff::cb) 20317926a79SDavid Howells */ 20417926a79SDavid Howells struct rxrpc_skb_priv { 205*f2cce89aSDavid Howells struct rxrpc_connection *conn; /* Connection referred to (poke packet) */ 206d4d02d8bSDavid Howells u16 offset; /* Offset of data */ 207d4d02d8bSDavid Howells u16 len; /* Length of data */ 208d4d02d8bSDavid Howells u8 flags; 209d4d02d8bSDavid Howells #define RXRPC_RX_VERIFIED 0x01 21017926a79SDavid Howells 2110d12f8a4SDavid Howells struct rxrpc_host_header hdr; /* RxRPC packet header from this packet */ 21217926a79SDavid Howells }; 21317926a79SDavid Howells 21417926a79SDavid Howells #define rxrpc_skb(__skb) ((struct rxrpc_skb_priv *) &(__skb)->cb) 21517926a79SDavid Howells 21617926a79SDavid Howells /* 21717926a79SDavid Howells * RxRPC security module interface 21817926a79SDavid Howells */ 21917926a79SDavid Howells struct rxrpc_security { 22017926a79SDavid Howells const char *name; /* name of this service */ 22117926a79SDavid Howells u8 security_index; /* security type provided */ 222063c60d3SDavid Howells u32 no_key_abort; /* Abort code indicating no key */ 22317926a79SDavid Howells 224648af7fcSDavid Howells /* Initialise a security service */ 225648af7fcSDavid Howells int (*init)(void); 226648af7fcSDavid Howells 227648af7fcSDavid Howells /* Clean up a security service */ 228648af7fcSDavid Howells void (*exit)(void); 229648af7fcSDavid Howells 23012da59fcSDavid Howells /* Parse the information from a server key */ 23112da59fcSDavid Howells int (*preparse_server_key)(struct key_preparsed_payload *); 23212da59fcSDavid Howells 23312da59fcSDavid Howells /* Clean up the preparse buffer after parsing a server key */ 23412da59fcSDavid Howells void (*free_preparse_server_key)(struct key_preparsed_payload *); 23512da59fcSDavid Howells 23612da59fcSDavid Howells /* Destroy the payload of a server key */ 23712da59fcSDavid Howells void (*destroy_server_key)(struct key *); 23812da59fcSDavid Howells 239d5953f65SDavid Howells /* Describe a server key */ 240d5953f65SDavid Howells void (*describe_server_key)(const struct key *, struct seq_file *); 241d5953f65SDavid Howells 24217926a79SDavid Howells /* initialise a connection's security */ 24341057ebdSDavid Howells int (*init_connection_security)(struct rxrpc_connection *, 24441057ebdSDavid Howells struct rxrpc_key_token *); 24517926a79SDavid Howells 246d7d775b1SDavid Howells /* Work out how much data we can store in a packet, given an estimate 247d7d775b1SDavid Howells * of the amount of data remaining. 248d7d775b1SDavid Howells */ 249d7d775b1SDavid Howells int (*how_much_data)(struct rxrpc_call *, size_t, 250d7d775b1SDavid Howells size_t *, size_t *, size_t *); 25117926a79SDavid Howells 25217926a79SDavid Howells /* impose security on a packet */ 253a4ea4c47SDavid Howells int (*secure_packet)(struct rxrpc_call *, struct rxrpc_txbuf *); 25417926a79SDavid Howells 25517926a79SDavid Howells /* verify the security on a received packet */ 256d4d02d8bSDavid Howells int (*verify_packet)(struct rxrpc_call *, struct sk_buff *); 257248f219cSDavid Howells 2581db88c53SDavid Howells /* Free crypto request on a call */ 2591db88c53SDavid Howells void (*free_call_crypto)(struct rxrpc_call *); 2601db88c53SDavid Howells 26117926a79SDavid Howells /* issue a challenge */ 26217926a79SDavid Howells int (*issue_challenge)(struct rxrpc_connection *); 26317926a79SDavid Howells 26417926a79SDavid Howells /* respond to a challenge */ 26517926a79SDavid Howells int (*respond_to_challenge)(struct rxrpc_connection *, 26617926a79SDavid Howells struct sk_buff *, 26717926a79SDavid Howells u32 *); 26817926a79SDavid Howells 26917926a79SDavid Howells /* verify a response */ 27017926a79SDavid Howells int (*verify_response)(struct rxrpc_connection *, 27117926a79SDavid Howells struct sk_buff *, 27217926a79SDavid Howells u32 *); 27317926a79SDavid Howells 27417926a79SDavid Howells /* clear connection security */ 27517926a79SDavid Howells void (*clear)(struct rxrpc_connection *); 27617926a79SDavid Howells }; 27717926a79SDavid Howells 27817926a79SDavid Howells /* 2794f95dd78SDavid Howells * RxRPC local transport endpoint description 2804f95dd78SDavid Howells * - owned by a single AF_RXRPC socket 2814f95dd78SDavid Howells * - pointed to by transport socket struct sk_user_data 28217926a79SDavid Howells */ 28317926a79SDavid Howells struct rxrpc_local { 2844f95dd78SDavid Howells struct rcu_head rcu; 285730c5fd4SDavid Howells atomic_t active_users; /* Number of users of the local endpoint */ 286a0575429SDavid Howells refcount_t ref; /* Number of references to the structure */ 2878a758d98SDavid Howells struct net *net; /* The network namespace */ 2888a758d98SDavid Howells struct rxrpc_net *rxnet; /* Our bits in the network namespace */ 28933912c26SDavid Howells struct hlist_node link; 29017926a79SDavid Howells struct socket *socket; /* my UDP socket */ 291a275da62SDavid Howells struct task_struct *io_thread; 2928fbcc833SDavid Howells struct completion io_thread_ready; /* Indication that the I/O thread started */ 2931e9e5c95SDavid Howells struct rxrpc_sock __rcu *service; /* Service(s) listening on this endpoint */ 29417926a79SDavid Howells struct rw_semaphore defrag_sem; /* control re-enablement of IP DF bit */ 295a275da62SDavid Howells struct sk_buff_head rx_queue; /* Received packets */ 296*f2cce89aSDavid Howells struct list_head conn_attend_q; /* Conns requiring immediate attention */ 29715f661dcSDavid Howells struct list_head call_attend_q; /* Calls requiring immediate attention */ 298245500d8SDavid Howells struct rb_root client_bundles; /* Client connection bundles by socket params */ 299245500d8SDavid Howells spinlock_t client_bundles_lock; /* Lock for client_bundles */ 30017926a79SDavid Howells spinlock_t lock; /* access lock */ 30117926a79SDavid Howells rwlock_t services_lock; /* lock for services list */ 30217926a79SDavid Howells int debug_id; /* debug ID for printks */ 3034f95dd78SDavid Howells bool dead; 304f859ab61SDavid Howells bool service_closed; /* Service socket closed */ 30517926a79SDavid Howells struct sockaddr_rxrpc srx; /* local address */ 30617926a79SDavid Howells }; 30717926a79SDavid Howells 30817926a79SDavid Howells /* 30917926a79SDavid Howells * RxRPC remote transport endpoint definition 310be6e6707SDavid Howells * - matched by local endpoint, remote port, address and protocol type 31117926a79SDavid Howells */ 31217926a79SDavid Howells struct rxrpc_peer { 313be6e6707SDavid Howells struct rcu_head rcu; /* This must be first */ 314a0575429SDavid Howells refcount_t ref; 315be6e6707SDavid Howells unsigned long hash_key; 316be6e6707SDavid Howells struct hlist_node hash_link; 317be6e6707SDavid Howells struct rxrpc_local *local; 318f66d7490SDavid Howells struct hlist_head error_targets; /* targets for net error distribution */ 319aa390bbeSDavid Howells struct rb_root service_conns; /* Service connections */ 320330bdcfaSDavid Howells struct list_head keepalive_link; /* Link in net->peer_keepalive[] */ 321ace45becSDavid Howells time64_t last_tx_at; /* Last time packet sent here */ 3228496af50SDavid Howells seqlock_t service_conn_lock; 32317926a79SDavid Howells spinlock_t lock; /* access lock */ 32495c96174SEric Dumazet unsigned int if_mtu; /* interface MTU for this peer */ 32595c96174SEric Dumazet unsigned int mtu; /* network MTU for this peer */ 32695c96174SEric Dumazet unsigned int maxdata; /* data size (MTU - hdrsize) */ 32717926a79SDavid Howells unsigned short hdrsize; /* header size (IP + UDP + RxRPC) */ 32817926a79SDavid Howells int debug_id; /* debug ID for printks */ 32917926a79SDavid Howells struct sockaddr_rxrpc srx; /* remote address */ 33017926a79SDavid Howells 33117926a79SDavid Howells /* calculated RTT cache */ 33217926a79SDavid Howells #define RXRPC_RTT_CACHE_SIZE 32 333c1e15b49SDavid Howells spinlock_t rtt_input_lock; /* RTT lock for input routine */ 3340d4b103cSDavid Howells ktime_t rtt_last_req; /* Time of last RTT request */ 335c410bf01SDavid Howells unsigned int rtt_count; /* Number of samples we've got */ 336c410bf01SDavid Howells 337c410bf01SDavid Howells u32 srtt_us; /* smoothed round trip time << 3 in usecs */ 338c410bf01SDavid Howells u32 mdev_us; /* medium deviation */ 339c410bf01SDavid Howells u32 mdev_max_us; /* maximal mdev for the last rtt period */ 340c410bf01SDavid Howells u32 rttvar_us; /* smoothed mdev_max */ 341c410bf01SDavid Howells u32 rto_j; /* Retransmission timeout in jiffies */ 342c410bf01SDavid Howells u8 backoff; /* Backoff timeout */ 343f7aec129SDavid Howells 3441fc4fa2aSDavid Howells u8 cong_ssthresh; /* Congestion slow-start threshold */ 34517926a79SDavid Howells }; 34617926a79SDavid Howells 34717926a79SDavid Howells /* 34819ffa01cSDavid Howells * Keys for matching a connection. 34919ffa01cSDavid Howells */ 35019ffa01cSDavid Howells struct rxrpc_conn_proto { 351e8d70ce1SDavid Howells union { 352e8d70ce1SDavid Howells struct { 35319ffa01cSDavid Howells u32 epoch; /* epoch of this connection */ 35419ffa01cSDavid Howells u32 cid; /* connection ID */ 355e8d70ce1SDavid Howells }; 356e8d70ce1SDavid Howells u64 index_key; 35719ffa01cSDavid Howells }; 35819ffa01cSDavid Howells }; 35919ffa01cSDavid Howells 36019ffa01cSDavid Howells struct rxrpc_conn_parameters { 36119ffa01cSDavid Howells struct rxrpc_local *local; /* Representation of local endpoint */ 36219ffa01cSDavid Howells struct rxrpc_peer *peer; /* Remote endpoint */ 36319ffa01cSDavid Howells struct key *key; /* Security details */ 36419ffa01cSDavid Howells bool exclusive; /* T if conn is exclusive */ 3654e255721SDavid Howells bool upgrade; /* T if service ID can be upgraded */ 36619ffa01cSDavid Howells u16 service_id; /* Service ID for this connection */ 36719ffa01cSDavid Howells u32 security_level; /* Security level selected */ 36819ffa01cSDavid Howells }; 36919ffa01cSDavid Howells 37019ffa01cSDavid Howells /* 371bba304dbSDavid Howells * Bits in the connection flags. 372bba304dbSDavid Howells */ 373bba304dbSDavid Howells enum rxrpc_conn_flag { 374bba304dbSDavid Howells RXRPC_CONN_HAS_IDR, /* Has a client conn ID assigned */ 375001c1122SDavid Howells RXRPC_CONN_IN_SERVICE_CONNS, /* Conn is in peer->service_conns */ 37645025bceSDavid Howells RXRPC_CONN_DONT_REUSE, /* Don't reuse this connection */ 3774e255721SDavid Howells RXRPC_CONN_PROBING_FOR_UPGRADE, /* Probing for service upgrade */ 3783136ef49SDavid Howells RXRPC_CONN_FINAL_ACK_0, /* Need final ACK for channel 0 */ 3793136ef49SDavid Howells RXRPC_CONN_FINAL_ACK_1, /* Need final ACK for channel 1 */ 3803136ef49SDavid Howells RXRPC_CONN_FINAL_ACK_2, /* Need final ACK for channel 2 */ 3813136ef49SDavid Howells RXRPC_CONN_FINAL_ACK_3, /* Need final ACK for channel 3 */ 382bba304dbSDavid Howells }; 383bba304dbSDavid Howells 3843136ef49SDavid Howells #define RXRPC_CONN_FINAL_ACK_MASK ((1UL << RXRPC_CONN_FINAL_ACK_0) | \ 3853136ef49SDavid Howells (1UL << RXRPC_CONN_FINAL_ACK_1) | \ 3863136ef49SDavid Howells (1UL << RXRPC_CONN_FINAL_ACK_2) | \ 3873136ef49SDavid Howells (1UL << RXRPC_CONN_FINAL_ACK_3)) 3883136ef49SDavid Howells 389bba304dbSDavid Howells /* 390bba304dbSDavid Howells * Events that can be raised upon a connection. 391bba304dbSDavid Howells */ 392bba304dbSDavid Howells enum rxrpc_conn_event { 393bba304dbSDavid Howells RXRPC_CONN_EV_CHALLENGE, /* Send challenge packet */ 394bba304dbSDavid Howells }; 395bba304dbSDavid Howells 396bba304dbSDavid Howells /* 397bba304dbSDavid Howells * The connection protocol state. 398bba304dbSDavid Howells */ 399bba304dbSDavid Howells enum rxrpc_conn_proto_state { 400bba304dbSDavid Howells RXRPC_CONN_UNUSED, /* Connection not yet attempted */ 401bba304dbSDavid Howells RXRPC_CONN_CLIENT, /* Client connection */ 40200e90712SDavid Howells RXRPC_CONN_SERVICE_PREALLOC, /* Service connection preallocation */ 403bba304dbSDavid Howells RXRPC_CONN_SERVICE_UNSECURED, /* Service unsecured connection */ 404bba304dbSDavid Howells RXRPC_CONN_SERVICE_CHALLENGING, /* Service challenging for security */ 405bba304dbSDavid Howells RXRPC_CONN_SERVICE, /* Service secured connection */ 406bba304dbSDavid Howells RXRPC_CONN_REMOTELY_ABORTED, /* Conn aborted by peer */ 407bba304dbSDavid Howells RXRPC_CONN_LOCALLY_ABORTED, /* Conn aborted locally */ 408bba304dbSDavid Howells RXRPC_CONN__NR_STATES 409bba304dbSDavid Howells }; 410bba304dbSDavid Howells 411bba304dbSDavid Howells /* 412245500d8SDavid Howells * RxRPC client connection bundle. 413245500d8SDavid Howells */ 414245500d8SDavid Howells struct rxrpc_bundle { 4152cc80086SDavid Howells struct rxrpc_local *local; /* Representation of local endpoint */ 4162cc80086SDavid Howells struct rxrpc_peer *peer; /* Remote endpoint */ 4172cc80086SDavid Howells struct key *key; /* Security details */ 418a0575429SDavid Howells refcount_t ref; 4193bcd6c7eSDavid Howells atomic_t active; /* Number of active users */ 420245500d8SDavid Howells unsigned int debug_id; 4212cc80086SDavid Howells u32 security_level; /* Security level selected */ 4222cc80086SDavid Howells u16 service_id; /* Service ID for this connection */ 423245500d8SDavid Howells bool try_upgrade; /* True if the bundle is attempting upgrade */ 424245500d8SDavid Howells bool alloc_conn; /* True if someone's getting a conn */ 4252cc80086SDavid Howells bool exclusive; /* T if conn is exclusive */ 4262cc80086SDavid Howells bool upgrade; /* T if service ID can be upgraded */ 4278806245aSDavid Howells short alloc_error; /* Error from last conn allocation */ 428245500d8SDavid Howells spinlock_t channel_lock; 429245500d8SDavid Howells struct rb_node local_node; /* Node in local->client_conns */ 430245500d8SDavid Howells struct list_head waiting_calls; /* Calls waiting for channels */ 431245500d8SDavid Howells unsigned long avail_chans; /* Mask of available channels */ 432245500d8SDavid Howells struct rxrpc_connection *conns[4]; /* The connections in the bundle (max 4) */ 433245500d8SDavid Howells }; 434245500d8SDavid Howells 435245500d8SDavid Howells /* 43617926a79SDavid Howells * RxRPC connection definition 437aa390bbeSDavid Howells * - matched by { local, peer, epoch, conn_id, direction } 43817926a79SDavid Howells * - each connection can only handle four simultaneous calls 43917926a79SDavid Howells */ 44017926a79SDavid Howells struct rxrpc_connection { 44119ffa01cSDavid Howells struct rxrpc_conn_proto proto; 4422cc80086SDavid Howells struct rxrpc_local *local; /* Representation of local endpoint */ 4432cc80086SDavid Howells struct rxrpc_peer *peer; /* Remote endpoint */ 4443cec055cSDavid Howells struct rxrpc_net *rxnet; /* Network namespace to which call belongs */ 4452cc80086SDavid Howells struct key *key; /* Security details */ 446*f2cce89aSDavid Howells struct list_head attend_link; /* Link in local->conn_attend_q */ 44719ffa01cSDavid Howells 448a0575429SDavid Howells refcount_t ref; 4493cec055cSDavid Howells atomic_t active; /* Active count for service conns */ 45045025bceSDavid Howells struct rcu_head rcu; 45145025bceSDavid Howells struct list_head cache_link; 452a1399f8bSDavid Howells 453245500d8SDavid Howells unsigned char act_chans; /* Mask of active channels */ 454a1399f8bSDavid Howells struct rxrpc_channel { 4553136ef49SDavid Howells unsigned long final_ack_at; /* Time at which to issue final ACK */ 456a1399f8bSDavid Howells struct rxrpc_call __rcu *call; /* Active call */ 4574764c0daSDavid Howells unsigned int call_debug_id; /* call->debug_id */ 458a1399f8bSDavid Howells u32 call_id; /* ID of current call */ 459a1399f8bSDavid Howells u32 call_counter; /* Call ID counter */ 460a1399f8bSDavid Howells u32 last_call; /* ID of last call */ 46118bfeba5SDavid Howells u8 last_type; /* Type of last packet */ 46218bfeba5SDavid Howells union { 46318bfeba5SDavid Howells u32 last_seq; 46418bfeba5SDavid Howells u32 last_abort; 46518bfeba5SDavid Howells }; 466a1399f8bSDavid Howells } channels[RXRPC_MAXCALLS]; 467999b69f8SDavid Howells 4683136ef49SDavid Howells struct timer_list timer; /* Conn event timer */ 46917926a79SDavid Howells struct work_struct processor; /* connection event processor */ 4703cec055cSDavid Howells struct work_struct destructor; /* In-process-context destroyer */ 471245500d8SDavid Howells struct rxrpc_bundle *bundle; /* Client connection bundle */ 472aa390bbeSDavid Howells struct rb_node service_node; /* Node in peer->service_conns */ 4734d028b2cSDavid Howells struct list_head proc_link; /* link in procfs list */ 47417926a79SDavid Howells struct list_head link; /* link in master connection list */ 47517926a79SDavid Howells struct sk_buff_head rx_queue; /* received conn-level packets */ 476521bb304SDavid Howells 477648af7fcSDavid Howells const struct rxrpc_security *security; /* applied security module */ 478521bb304SDavid Howells union { 479521bb304SDavid Howells struct { 48069d826faSKees Cook struct crypto_sync_skcipher *cipher; /* encryption handle */ 48117926a79SDavid Howells struct rxrpc_crypt csum_iv; /* packet checksum base */ 482521bb304SDavid Howells u32 nonce; /* response re-use preventer */ 483521bb304SDavid Howells } rxkad; 484521bb304SDavid Howells }; 4854a3388c8SDavid Howells unsigned long flags; 48617926a79SDavid Howells unsigned long events; 487f51b4480SDavid Howells unsigned long idle_timestamp; /* Time at which last became idle */ 48817926a79SDavid Howells spinlock_t state_lock; /* state-change lock */ 489cf13258fSDavid Howells enum rxrpc_conn_proto_state state; /* current state of connection */ 49064753092SDavid Howells u32 abort_code; /* Abort code of connection abort */ 49117926a79SDavid Howells int debug_id; /* debug ID for printks */ 49217926a79SDavid Howells atomic_t serial; /* packet serial number counter */ 493563ea7d5SDavid Howells unsigned int hi_serial; /* highest serial number received */ 494c1e15b49SDavid Howells u32 service_id; /* Service ID, possibly upgraded */ 4952cc80086SDavid Howells u32 security_level; /* Security level selected */ 49617926a79SDavid Howells u8 security_ix; /* security type */ 49717926a79SDavid Howells u8 out_clientflag; /* RXRPC_CLIENT_INITIATED if we are client */ 498245500d8SDavid Howells u8 bundle_shift; /* Index into bundle->avail_chans */ 4992cc80086SDavid Howells bool exclusive; /* T if conn is exclusive */ 5002cc80086SDavid Howells bool upgrade; /* T if service ID can be upgraded */ 5012cc80086SDavid Howells u16 orig_service_id; /* Originally requested service ID */ 50264753092SDavid Howells short error; /* Local error code */ 50317926a79SDavid Howells }; 50417926a79SDavid Howells 505dc71db34SDavid Howells static inline bool rxrpc_to_server(const struct rxrpc_skb_priv *sp) 506dc71db34SDavid Howells { 507dc71db34SDavid Howells return sp->hdr.flags & RXRPC_CLIENT_INITIATED; 508dc71db34SDavid Howells } 509dc71db34SDavid Howells 510dc71db34SDavid Howells static inline bool rxrpc_to_client(const struct rxrpc_skb_priv *sp) 511dc71db34SDavid Howells { 512dc71db34SDavid Howells return !rxrpc_to_server(sp); 513dc71db34SDavid Howells } 514dc71db34SDavid Howells 51517926a79SDavid Howells /* 5165b8848d1SDavid Howells * Flags in call->flags. 5175b8848d1SDavid Howells */ 5185b8848d1SDavid Howells enum rxrpc_call_flag { 5195b8848d1SDavid Howells RXRPC_CALL_RELEASED, /* call has been released - no more message to userspace */ 5205b8848d1SDavid Howells RXRPC_CALL_HAS_USERID, /* has a user ID attached */ 521dabe5a79SDavid Howells RXRPC_CALL_IS_SERVICE, /* Call is service call */ 52245025bceSDavid Howells RXRPC_CALL_EXPOSED, /* The call was exposed to the world */ 523248f219cSDavid Howells RXRPC_CALL_RX_LAST, /* Received the last packet (at rxtx_top) */ 524248f219cSDavid Howells RXRPC_CALL_TX_LAST, /* Last packet in Tx buffer (at rxtx_top) */ 525a4ea4c47SDavid Howells RXRPC_CALL_TX_ALL_ACKED, /* Last packet has been hard-acked */ 526a5af7e1fSDavid Howells RXRPC_CALL_SEND_PING, /* A ping will need to be sent */ 52757494343SDavid Howells RXRPC_CALL_RETRANS_TIMEOUT, /* Retransmission due to timeout occurred */ 528c54e43d7SDavid Howells RXRPC_CALL_BEGAN_RX_TIMER, /* We began the expect_rx_by timer */ 5291a025028SDavid Howells RXRPC_CALL_RX_HEARD, /* The peer responded at least once to this call */ 5305273a191SDavid Howells RXRPC_CALL_DISCONNECTED, /* The call has been disconnected */ 531b7a7d674SDavid Howells RXRPC_CALL_KERNEL, /* The call was made by the kernel */ 532245500d8SDavid Howells RXRPC_CALL_UPGRADE, /* Service upgrade was requested for the call */ 533f3441d41SDavid Howells RXRPC_CALL_EXCLUSIVE, /* The call uses a once-only connection */ 5345e6ef4f1SDavid Howells RXRPC_CALL_RX_IS_IDLE, /* Reception is idle - send an ACK */ 5355b8848d1SDavid Howells }; 5365b8848d1SDavid Howells 5375b8848d1SDavid Howells /* 5385b8848d1SDavid Howells * Events that can be raised on a call. 5395b8848d1SDavid Howells */ 5405b8848d1SDavid Howells enum rxrpc_call_event { 541bd1fdf8cSDavid Howells RXRPC_CALL_EV_ACK_LOST, /* ACK may be lost, send ping */ 5425e6ef4f1SDavid Howells RXRPC_CALL_EV_INITIAL_PING, /* Send initial ping for a new service call */ 5435b8848d1SDavid Howells }; 5445b8848d1SDavid Howells 5455b8848d1SDavid Howells /* 5465b8848d1SDavid Howells * The states that a call can be in. 5475b8848d1SDavid Howells */ 5485b8848d1SDavid Howells enum rxrpc_call_state { 549999b69f8SDavid Howells RXRPC_CALL_UNINITIALISED, 550999b69f8SDavid Howells RXRPC_CALL_CLIENT_AWAIT_CONN, /* - client waiting for connection to become available */ 5515b8848d1SDavid Howells RXRPC_CALL_CLIENT_SEND_REQUEST, /* - client sending request phase */ 5525b8848d1SDavid Howells RXRPC_CALL_CLIENT_AWAIT_REPLY, /* - client awaiting reply */ 5535b8848d1SDavid Howells RXRPC_CALL_CLIENT_RECV_REPLY, /* - client receiving reply phase */ 55400e90712SDavid Howells RXRPC_CALL_SERVER_PREALLOC, /* - service preallocation */ 5555b8848d1SDavid Howells RXRPC_CALL_SERVER_SECURING, /* - server securing request connection */ 5565b8848d1SDavid Howells RXRPC_CALL_SERVER_RECV_REQUEST, /* - server receiving request */ 5575b8848d1SDavid Howells RXRPC_CALL_SERVER_ACK_REQUEST, /* - server pending ACK of request */ 5585b8848d1SDavid Howells RXRPC_CALL_SERVER_SEND_REPLY, /* - server sending reply */ 5595b8848d1SDavid Howells RXRPC_CALL_SERVER_AWAIT_ACK, /* - server awaiting final ACK */ 560f5c17aaeSDavid Howells RXRPC_CALL_COMPLETE, /* - call complete */ 561f5c17aaeSDavid Howells NR__RXRPC_CALL_STATES 562f5c17aaeSDavid Howells }; 563f5c17aaeSDavid Howells 564f5c17aaeSDavid Howells /* 565e122d845SDavid Howells * Call completion condition (state == RXRPC_CALL_COMPLETE). 566e122d845SDavid Howells */ 567e122d845SDavid Howells enum rxrpc_call_completion { 568e122d845SDavid Howells RXRPC_CALL_SUCCEEDED, /* - Normal termination */ 569e122d845SDavid Howells RXRPC_CALL_REMOTELY_ABORTED, /* - call aborted by peer */ 570e122d845SDavid Howells RXRPC_CALL_LOCALLY_ABORTED, /* - call aborted locally on error or close */ 571e122d845SDavid Howells RXRPC_CALL_LOCAL_ERROR, /* - call failed due to local error */ 572e122d845SDavid Howells RXRPC_CALL_NETWORK_ERROR, /* - call terminated by network error */ 573e122d845SDavid Howells NR__RXRPC_CALL_COMPLETIONS 574e122d845SDavid Howells }; 575e122d845SDavid Howells 576e122d845SDavid Howells /* 57757494343SDavid Howells * Call Tx congestion management modes. 57857494343SDavid Howells */ 57957494343SDavid Howells enum rxrpc_congest_mode { 58057494343SDavid Howells RXRPC_CALL_SLOW_START, 58157494343SDavid Howells RXRPC_CALL_CONGEST_AVOIDANCE, 58257494343SDavid Howells RXRPC_CALL_PACKET_LOSS, 58357494343SDavid Howells RXRPC_CALL_FAST_RETRANSMIT, 58457494343SDavid Howells NR__RXRPC_CONGEST_MODES 58557494343SDavid Howells }; 58657494343SDavid Howells 58757494343SDavid Howells /* 58817926a79SDavid Howells * RxRPC call definition 58917926a79SDavid Howells * - matched by { connection, call_id } 59017926a79SDavid Howells */ 59117926a79SDavid Howells struct rxrpc_call { 592dee46364SDavid Howells struct rcu_head rcu; 59317926a79SDavid Howells struct rxrpc_connection *conn; /* connection carrying call */ 594df5d8bf7SDavid Howells struct rxrpc_peer *peer; /* Peer record for remote address */ 595f3441d41SDavid Howells struct rxrpc_local *local; /* Representation of local endpoint */ 5968d94aa38SDavid Howells struct rxrpc_sock __rcu *socket; /* socket responsible */ 597d3be4d24SDavid Howells struct rxrpc_net *rxnet; /* Network namespace to which call belongs */ 598f3441d41SDavid Howells struct key *key; /* Security details */ 59991fcfbe8SDavid Howells const struct rxrpc_security *security; /* applied security module */ 600540b1c48SDavid Howells struct mutex user_mutex; /* User access mutex */ 601f3441d41SDavid Howells struct sockaddr_rxrpc dest_srx; /* Destination address */ 602530403d9SDavid Howells unsigned long delay_ack_at; /* When DELAY ACK needs to happen */ 603bd1fdf8cSDavid Howells unsigned long ack_lost_at; /* When ACK is figured as lost */ 604a158bdd3SDavid Howells unsigned long resend_at; /* When next resend needs to happen */ 605a158bdd3SDavid Howells unsigned long ping_at; /* When next to send a ping */ 606415f44e4SDavid Howells unsigned long keepalive_at; /* When next to send a keepalive ping */ 607a158bdd3SDavid Howells unsigned long expect_rx_by; /* When we expect to get a packet by */ 608a158bdd3SDavid Howells unsigned long expect_req_by; /* When we expect to get a request DATA packet by */ 609a158bdd3SDavid Howells unsigned long expect_term_by; /* When we expect call termination by */ 610a158bdd3SDavid Howells u32 next_rx_timo; /* Timeout for next Rx packet (jif) */ 611a158bdd3SDavid Howells u32 next_req_timo; /* Timeout for next Rx request packet (jif) */ 612248f219cSDavid Howells struct timer_list timer; /* Combined event timer */ 6133feda9d6SDavid Howells struct work_struct destroyer; /* In-process-context destroyer */ 614d001648eSDavid Howells rxrpc_notify_rx_t notify_rx; /* kernel service Rx notification function */ 61517926a79SDavid Howells struct list_head link; /* link in master call list */ 616245500d8SDavid Howells struct list_head chan_wait_link; /* Link in conn->bundle->waiting_calls */ 617f66d7490SDavid Howells struct hlist_node error_link; /* link in error distribution list */ 618248f219cSDavid Howells struct list_head accept_link; /* Link in rx->acceptq */ 619248f219cSDavid Howells struct list_head recvmsg_link; /* Link in rx->recvmsg_q */ 620248f219cSDavid Howells struct list_head sock_link; /* Link in rx->sock_calls */ 621248f219cSDavid Howells struct rb_node sock_node; /* Node in rx->calls */ 62215f661dcSDavid Howells struct list_head attend_link; /* Link in local->call_attend_q */ 623a4ea4c47SDavid Howells struct rxrpc_txbuf *tx_pending; /* Tx buffer being filled */ 62445025bceSDavid Howells wait_queue_head_t waitq; /* Wait queue for channel or Tx */ 625e754eba6SDavid Howells s64 tx_total_len; /* Total length left to be transmitted (or -1) */ 62617926a79SDavid Howells unsigned long user_call_ID; /* user-defined call ID */ 62717926a79SDavid Howells unsigned long flags; 62817926a79SDavid Howells unsigned long events; 62920acbd9aSDavid Howells spinlock_t notify_lock; /* Kernel notification lock */ 63017926a79SDavid Howells rwlock_t state_lock; /* lock for state transition */ 631a343b174SDavid Howells const char *send_abort_why; /* String indicating why the abort was sent */ 632a343b174SDavid Howells s32 send_abort; /* Abort code to be sent */ 633a343b174SDavid Howells short send_abort_err; /* Error to be associated with the abort */ 634a343b174SDavid Howells s32 abort_code; /* Local/remote abort code */ 635f5c17aaeSDavid Howells int error; /* Local error incurred */ 636cf13258fSDavid Howells enum rxrpc_call_state state; /* current state of call */ 637cf13258fSDavid Howells enum rxrpc_call_completion completion; /* Call completion condition */ 638a0575429SDavid Howells refcount_t ref; 639278ac0cdSDavid Howells u8 security_ix; /* Security type */ 640e138aa7dSDavid Howells enum rxrpc_interruptibility interruptibility; /* At what point call may be interrupted */ 641dabe5a79SDavid Howells u32 call_id; /* call ID on connection */ 642dabe5a79SDavid Howells u32 cid; /* connection ID plus channel index */ 643f3441d41SDavid Howells u32 security_level; /* Security level selected */ 644dabe5a79SDavid Howells int debug_id; /* debug ID for printks */ 6458e83134dSDavid Howells unsigned short rx_pkt_offset; /* Current recvmsg packet offset */ 6468e83134dSDavid Howells unsigned short rx_pkt_len; /* Current recvmsg packet len */ 64717926a79SDavid Howells 6485d7edbc9SDavid Howells /* Transmitted data tracking. */ 649a4ea4c47SDavid Howells spinlock_t tx_lock; /* Transmit queue lock */ 650cf37b598SDavid Howells struct list_head tx_sendmsg; /* Sendmsg prepared packets */ 651a4ea4c47SDavid Howells struct list_head tx_buffer; /* Buffer of transmissible packets */ 652a4ea4c47SDavid Howells rxrpc_seq_t tx_bottom; /* First packet in buffer */ 653a4ea4c47SDavid Howells rxrpc_seq_t tx_transmitted; /* Highest packet transmitted */ 654cf37b598SDavid Howells rxrpc_seq_t tx_prepared; /* Highest Tx slot prepared. */ 655248f219cSDavid Howells rxrpc_seq_t tx_top; /* Highest Tx slot allocated. */ 656c7e86acfSDavid Howells u16 tx_backoff; /* Delay to insert due to Tx failure */ 6575d7edbc9SDavid Howells u8 tx_winsize; /* Maximum size of Tx window */ 658a4ea4c47SDavid Howells #define RXRPC_TX_MAX_WINDOW 128 6591fc4fa2aSDavid Howells ktime_t tx_last_sent; /* Last time a transmission occurred */ 6605d7edbc9SDavid Howells 6615d7edbc9SDavid Howells /* Received data tracking */ 6625d7edbc9SDavid Howells struct sk_buff_head recvmsg_queue; /* Queue of packets ready for recvmsg() */ 6635d7edbc9SDavid Howells struct sk_buff_head rx_oos_queue; /* Queue of out of sequence packets */ 6645d7edbc9SDavid Howells 6655d7edbc9SDavid Howells rxrpc_seq_t rx_highest_seq; /* Higest sequence number received */ 6665d7edbc9SDavid Howells rxrpc_seq_t rx_consumed; /* Highest packet consumed */ 6675d7edbc9SDavid Howells rxrpc_serial_t rx_serial; /* Highest serial received for this call */ 6685d7edbc9SDavid Howells u8 rx_winsize; /* Size of Rx window */ 66957494343SDavid Howells 67057494343SDavid Howells /* TCP-style slow-start congestion control [RFC5681]. Since the SMSS 67157494343SDavid Howells * is fixed, we keep these numbers in terms of segments (ie. DATA 67257494343SDavid Howells * packets) rather than bytes. 67357494343SDavid Howells */ 67457494343SDavid Howells #define RXRPC_TX_SMSS RXRPC_JUMBO_DATALEN 6755086d9a9SDavid Howells #define RXRPC_MIN_CWND (RXRPC_TX_SMSS > 2190 ? 2 : RXRPC_TX_SMSS > 1095 ? 3 : 4) 67657494343SDavid Howells u8 cong_cwnd; /* Congestion window size */ 67757494343SDavid Howells u8 cong_extra; /* Extra to send for congestion management */ 67857494343SDavid Howells u8 cong_ssthresh; /* Slow-start threshold */ 67957494343SDavid Howells enum rxrpc_congest_mode cong_mode:8; /* Congestion management mode */ 68057494343SDavid Howells u8 cong_dup_acks; /* Count of ACKs showing missing packets */ 68157494343SDavid Howells u8 cong_cumul_acks; /* Cumulative ACK count */ 68257494343SDavid Howells ktime_t cong_tstamp; /* Last time cwnd was changed */ 68357494343SDavid Howells 6848940ba3cSDavid Howells /* Receive-phase ACK management (ACKs we send). */ 6854e36a95eSDavid Howells u8 ackr_reason; /* reason to ACK */ 6860d12f8a4SDavid Howells rxrpc_serial_t ackr_serial; /* serial of packet being ACK'd */ 6875d7edbc9SDavid Howells atomic64_t ackr_window; /* Base (in LSW) and top (in MSW) of SACK window */ 6889a3dedcfSDavid Howells atomic_t ackr_nr_unacked; /* Number of unacked packets */ 6899a3dedcfSDavid Howells atomic_t ackr_nr_consumed; /* Number of packets needing hard ACK */ 6905d7edbc9SDavid Howells struct { 6915d7edbc9SDavid Howells #define RXRPC_SACK_SIZE 256 6925d7edbc9SDavid Howells /* SACK table for soft-acked packets */ 6935d7edbc9SDavid Howells u8 ackr_sack_table[RXRPC_SACK_SIZE]; 6945d7edbc9SDavid Howells } __aligned(8); 695a5af7e1fSDavid Howells 6964700c4d8SDavid Howells /* RTT management */ 6974700c4d8SDavid Howells rxrpc_serial_t rtt_serial[4]; /* Serial number of DATA or PING sent */ 6984700c4d8SDavid Howells ktime_t rtt_sent_at[4]; /* Time packet sent */ 6994700c4d8SDavid Howells unsigned long rtt_avail; /* Mask of available slots in bits 0-3, 7004700c4d8SDavid Howells * Mask of pending samples in 8-11 */ 7014700c4d8SDavid Howells #define RXRPC_CALL_RTT_AVAIL_MASK 0xf 7024700c4d8SDavid Howells #define RXRPC_CALL_RTT_PEND_SHIFT 8 70317926a79SDavid Howells 7048940ba3cSDavid Howells /* Transmission-phase ACK management (ACKs we've received). */ 70557494343SDavid Howells ktime_t acks_latest_ts; /* Timestamp of latest ACK received */ 7068940ba3cSDavid Howells rxrpc_seq_t acks_first_seq; /* first sequence number received */ 70781524b63SDavid Howells rxrpc_seq_t acks_prev_seq; /* Highest previousPacket received */ 708a4ea4c47SDavid Howells rxrpc_seq_t acks_hard_ack; /* Latest hard-ack point */ 70931a1b989SDavid Howells rxrpc_seq_t acks_lowest_nak; /* Lowest NACK in the buffer (or ==tx_hard_ack) */ 710589a0c1eSDavid Howells rxrpc_serial_t acks_highest_serial; /* Highest serial number ACK'd */ 71131a1b989SDavid Howells }; 71231a1b989SDavid Howells 71331a1b989SDavid Howells /* 71457494343SDavid Howells * Summary of a new ACK and the changes it made to the Tx buffer packet states. 71531a1b989SDavid Howells */ 71631a1b989SDavid Howells struct rxrpc_ack_summary { 7171fc4fa2aSDavid Howells u16 nr_acks; /* Number of ACKs in packet */ 7181fc4fa2aSDavid Howells u16 nr_new_acks; /* Number of new ACKs in packet */ 7191fc4fa2aSDavid Howells u16 nr_rot_new_acks; /* Number of rotated new ACKs */ 72031a1b989SDavid Howells u8 ack_reason; 721d57a3a15SDavid Howells bool saw_nacks; /* Saw NACKs in packet */ 72231a1b989SDavid Howells bool new_low_nack; /* T if new low NACK found */ 72357494343SDavid Howells bool retrans_timeo; /* T if reTx due to timeout happened */ 72457494343SDavid Howells u8 flight_size; /* Number of unreceived transmissions */ 72557494343SDavid Howells /* Place to stash values for tracing */ 72657494343SDavid Howells enum rxrpc_congest_mode mode:8; 72757494343SDavid Howells u8 cwnd; 72857494343SDavid Howells u8 ssthresh; 72957494343SDavid Howells u8 dup_acks; 73057494343SDavid Howells u8 cumulative_acks; 73117926a79SDavid Howells }; 73217926a79SDavid Howells 73348124178SDavid Howells /* 73448124178SDavid Howells * sendmsg() cmsg-specified parameters. 73548124178SDavid Howells */ 73648124178SDavid Howells enum rxrpc_command { 73748124178SDavid Howells RXRPC_CMD_SEND_DATA, /* send data message */ 73848124178SDavid Howells RXRPC_CMD_SEND_ABORT, /* request abort generation */ 73948124178SDavid Howells RXRPC_CMD_REJECT_BUSY, /* [server] reject a call as busy */ 7402d914c1bSDavid Howells RXRPC_CMD_CHARGE_ACCEPT, /* [server] charge accept preallocation */ 74148124178SDavid Howells }; 74248124178SDavid Howells 74348124178SDavid Howells struct rxrpc_call_params { 74448124178SDavid Howells s64 tx_total_len; /* Total Tx data length (if send data) */ 74548124178SDavid Howells unsigned long user_call_ID; /* User's call ID */ 74648124178SDavid Howells struct { 74748124178SDavid Howells u32 hard; /* Maximum lifetime (sec) */ 74848124178SDavid Howells u32 idle; /* Max time since last data packet (msec) */ 74948124178SDavid Howells u32 normal; /* Max time since last call packet (msec) */ 75048124178SDavid Howells } timeouts; 75148124178SDavid Howells u8 nr_timeouts; /* Number of timeouts specified */ 752b7a7d674SDavid Howells bool kernel; /* T if kernel is making the call */ 753e138aa7dSDavid Howells enum rxrpc_interruptibility interruptibility; /* How is interruptible is the call? */ 75448124178SDavid Howells }; 75548124178SDavid Howells 75648124178SDavid Howells struct rxrpc_send_params { 75748124178SDavid Howells struct rxrpc_call_params call; 75848124178SDavid Howells u32 abort_code; /* Abort code to Tx (if abort) */ 75948124178SDavid Howells enum rxrpc_command command : 8; /* The command to implement */ 76048124178SDavid Howells bool exclusive; /* Shared or exclusive call */ 76148124178SDavid Howells bool upgrade; /* If the connection is upgradeable */ 76248124178SDavid Howells }; 76348124178SDavid Howells 76402a19356SDavid Howells /* 76502a19356SDavid Howells * Buffer of data to be output as a packet. 76602a19356SDavid Howells */ 76702a19356SDavid Howells struct rxrpc_txbuf { 76802a19356SDavid Howells struct rcu_head rcu; 769cf37b598SDavid Howells struct list_head call_link; /* Link in call->tx_sendmsg/tx_buffer */ 77002a19356SDavid Howells struct list_head tx_link; /* Link in live Enc queue or Tx queue */ 77102a19356SDavid Howells ktime_t last_sent; /* Time at which last transmitted */ 77202a19356SDavid Howells refcount_t ref; 77302a19356SDavid Howells rxrpc_seq_t seq; /* Sequence number of this packet */ 77402a19356SDavid Howells unsigned int call_debug_id; 77502a19356SDavid Howells unsigned int debug_id; 77602a19356SDavid Howells unsigned int len; /* Amount of data in buffer */ 77702a19356SDavid Howells unsigned int space; /* Remaining data space */ 77802a19356SDavid Howells unsigned int offset; /* Offset of fill point */ 77902a19356SDavid Howells unsigned long flags; 780d57a3a15SDavid Howells #define RXRPC_TXBUF_LAST 0 /* Set if last packet in Tx phase */ 781d57a3a15SDavid Howells #define RXRPC_TXBUF_RESENT 1 /* Set if has been resent */ 78272f0c6fbSDavid Howells u8 /*enum rxrpc_propose_ack_trace*/ ack_why; /* If ack, why */ 78302a19356SDavid Howells struct { 78402a19356SDavid Howells /* The packet for encrypting and DMA'ing. We align it such 78502a19356SDavid Howells * that data[] aligns correctly for any crypto blocksize. 78602a19356SDavid Howells */ 78702a19356SDavid Howells u8 pad[64 - sizeof(struct rxrpc_wire_header)]; 78802a19356SDavid Howells struct rxrpc_wire_header wire; /* Network-ready header */ 78972f0c6fbSDavid Howells union { 79002a19356SDavid Howells u8 data[RXRPC_JUMBO_DATALEN]; /* Data packet */ 79172f0c6fbSDavid Howells struct { 79272f0c6fbSDavid Howells struct rxrpc_ackpacket ack; 79372f0c6fbSDavid Howells u8 acks[0]; 79472f0c6fbSDavid Howells }; 79572f0c6fbSDavid Howells }; 79602a19356SDavid Howells } __aligned(64); 79702a19356SDavid Howells }; 79802a19356SDavid Howells 79902a19356SDavid Howells static inline bool rxrpc_sending_to_server(const struct rxrpc_txbuf *txb) 80002a19356SDavid Howells { 80102a19356SDavid Howells return txb->wire.flags & RXRPC_CLIENT_INITIATED; 80202a19356SDavid Howells } 80302a19356SDavid Howells 80402a19356SDavid Howells static inline bool rxrpc_sending_to_client(const struct rxrpc_txbuf *txb) 80502a19356SDavid Howells { 80602a19356SDavid Howells return !rxrpc_sending_to_server(txb); 80702a19356SDavid Howells } 80802a19356SDavid Howells 809df844fd4SDavid Howells #include <trace/events/rxrpc.h> 810df844fd4SDavid Howells 81117926a79SDavid Howells /* 812651350d1SDavid Howells * af_rxrpc.c 81317926a79SDavid Howells */ 814a4ea4c47SDavid Howells extern atomic_t rxrpc_n_rx_skbs; 815651350d1SDavid Howells extern struct workqueue_struct *rxrpc_workqueue; 81617926a79SDavid Howells 81717926a79SDavid Howells /* 8180d81a51aSDavid Howells * call_accept.c 81917926a79SDavid Howells */ 82000e90712SDavid Howells int rxrpc_service_prealloc(struct rxrpc_sock *, gfp_t); 82100e90712SDavid Howells void rxrpc_discard_prealloc(struct rxrpc_sock *); 82231d35a02SDavid Howells int rxrpc_new_incoming_call(struct rxrpc_local *, struct rxrpc_peer *, 8235e6ef4f1SDavid Howells struct rxrpc_connection *, struct sockaddr_rxrpc *, 824248f219cSDavid Howells struct sk_buff *); 8254f95dd78SDavid Howells void rxrpc_accept_incoming_calls(struct rxrpc_local *); 8262d914c1bSDavid Howells int rxrpc_user_charge_accept(struct rxrpc_sock *, unsigned long); 82717926a79SDavid Howells 82817926a79SDavid Howells /* 8290d81a51aSDavid Howells * call_event.c 83017926a79SDavid Howells */ 83172f0c6fbSDavid Howells void rxrpc_propose_ping(struct rxrpc_call *call, u32 serial, 83272f0c6fbSDavid Howells enum rxrpc_propose_ack_trace why); 83372f0c6fbSDavid Howells void rxrpc_send_ACK(struct rxrpc_call *, u8, rxrpc_serial_t, enum rxrpc_propose_ack_trace); 834530403d9SDavid Howells void rxrpc_propose_delay_ACK(struct rxrpc_call *, rxrpc_serial_t, 835530403d9SDavid Howells enum rxrpc_propose_ack_trace); 836a4ea4c47SDavid Howells void rxrpc_shrink_call_tx_buffer(struct rxrpc_call *); 8375e6ef4f1SDavid Howells void rxrpc_resend(struct rxrpc_call *call, struct sk_buff *ack_skb); 83817926a79SDavid Howells 8394a7f62f9SDavid Howells void rxrpc_reduce_call_timer(struct rxrpc_call *call, 840a158bdd3SDavid Howells unsigned long expire_at, 841a158bdd3SDavid Howells unsigned long now, 8424a7f62f9SDavid Howells enum rxrpc_timer_trace why); 8434a7f62f9SDavid Howells 8445e6ef4f1SDavid Howells void rxrpc_input_call_event(struct rxrpc_call *call, struct sk_buff *skb); 8455e6ef4f1SDavid Howells 84617926a79SDavid Howells /* 8470d81a51aSDavid Howells * call_object.c 84817926a79SDavid Howells */ 849f5c17aaeSDavid Howells extern const char *const rxrpc_call_states[]; 850f5c17aaeSDavid Howells extern const char *const rxrpc_call_completions[]; 85117926a79SDavid Howells extern struct kmem_cache *rxrpc_call_jar; 85217926a79SDavid Howells 85315f661dcSDavid Howells void rxrpc_poke_call(struct rxrpc_call *call, enum rxrpc_call_poke_trace what); 8542341e077SDavid Howells struct rxrpc_call *rxrpc_find_call_by_user_ID(struct rxrpc_sock *, unsigned long); 855a25e21f0SDavid Howells struct rxrpc_call *rxrpc_alloc_call(struct rxrpc_sock *, gfp_t, unsigned int); 8562341e077SDavid Howells struct rxrpc_call *rxrpc_new_client_call(struct rxrpc_sock *, 85719ffa01cSDavid Howells struct rxrpc_conn_parameters *, 858999b69f8SDavid Howells struct sockaddr_rxrpc *, 859a25e21f0SDavid Howells struct rxrpc_call_params *, gfp_t, 860a25e21f0SDavid Howells unsigned int); 861248f219cSDavid Howells void rxrpc_incoming_call(struct rxrpc_sock *, struct rxrpc_call *, 86242886ffeSDavid Howells struct sk_buff *); 8638d94aa38SDavid Howells void rxrpc_release_call(struct rxrpc_sock *, struct rxrpc_call *); 864c1b1203dSJoe Perches void rxrpc_release_calls_on_socket(struct rxrpc_sock *); 865cb0fc0c9SDavid Howells void rxrpc_see_call(struct rxrpc_call *, enum rxrpc_call_trace); 8665e6ef4f1SDavid Howells struct rxrpc_call *rxrpc_try_get_call(struct rxrpc_call *, enum rxrpc_call_trace); 867fff72429SDavid Howells void rxrpc_get_call(struct rxrpc_call *, enum rxrpc_call_trace); 868fff72429SDavid Howells void rxrpc_put_call(struct rxrpc_call *, enum rxrpc_call_trace); 86900e90712SDavid Howells void rxrpc_cleanup_call(struct rxrpc_call *); 8702baec2c3SDavid Howells void rxrpc_destroy_all_calls(struct rxrpc_net *); 87117926a79SDavid Howells 872dabe5a79SDavid Howells static inline bool rxrpc_is_service_call(const struct rxrpc_call *call) 873dabe5a79SDavid Howells { 874dabe5a79SDavid Howells return test_bit(RXRPC_CALL_IS_SERVICE, &call->flags); 875dabe5a79SDavid Howells } 876dabe5a79SDavid Howells 877dabe5a79SDavid Howells static inline bool rxrpc_is_client_call(const struct rxrpc_call *call) 878dabe5a79SDavid Howells { 879dabe5a79SDavid Howells return !rxrpc_is_service_call(call); 880dabe5a79SDavid Howells } 881dabe5a79SDavid Howells 88217926a79SDavid Howells /* 8834a3388c8SDavid Howells * conn_client.c 8844a3388c8SDavid Howells */ 88545025bceSDavid Howells extern unsigned int rxrpc_reap_client_connections; 886a158bdd3SDavid Howells extern unsigned long rxrpc_conn_idle_client_expiry; 887a158bdd3SDavid Howells extern unsigned long rxrpc_conn_idle_client_fast_expiry; 8884a3388c8SDavid Howells extern struct idr rxrpc_client_conn_ids; 8894a3388c8SDavid Howells 890eb9b9d22SDavid Howells void rxrpc_destroy_client_conn_ids(void); 891fa3492abSDavid Howells struct rxrpc_bundle *rxrpc_get_bundle(struct rxrpc_bundle *, enum rxrpc_bundle_trace); 892fa3492abSDavid Howells void rxrpc_put_bundle(struct rxrpc_bundle *, enum rxrpc_bundle_trace); 8935e33a23bSDavid Howells int rxrpc_connect_call(struct rxrpc_sock *, struct rxrpc_call *, 8945e33a23bSDavid Howells struct rxrpc_conn_parameters *, struct sockaddr_rxrpc *, 8955e33a23bSDavid Howells gfp_t); 89645025bceSDavid Howells void rxrpc_expose_client_call(struct rxrpc_call *); 897245500d8SDavid Howells void rxrpc_disconnect_client_call(struct rxrpc_bundle *, struct rxrpc_call *); 8987fa25105SDavid Howells void rxrpc_put_client_conn(struct rxrpc_connection *, enum rxrpc_conn_trace); 8992baec2c3SDavid Howells void rxrpc_discard_expired_client_conns(struct work_struct *); 9002baec2c3SDavid Howells void rxrpc_destroy_all_client_connections(struct rxrpc_net *); 901d12040b6SDavid Howells void rxrpc_clean_up_local_conns(struct rxrpc_local *); 9024a3388c8SDavid Howells 9034a3388c8SDavid Howells /* 9040d81a51aSDavid Howells * conn_event.c 9050d81a51aSDavid Howells */ 90630df927bSDavid Howells void rxrpc_conn_retransmit_call(struct rxrpc_connection *conn, struct sk_buff *skb, 90730df927bSDavid Howells unsigned int channel); 9080d81a51aSDavid Howells void rxrpc_process_connection(struct work_struct *); 909ddc7834aSDavid Howells void rxrpc_process_delayed_final_acks(struct rxrpc_connection *, bool); 9105e6ef4f1SDavid Howells int rxrpc_input_conn_packet(struct rxrpc_connection *conn, struct sk_buff *skb); 911*f2cce89aSDavid Howells void rxrpc_input_conn_event(struct rxrpc_connection *conn, struct sk_buff *skb); 9120d81a51aSDavid Howells 9130d81a51aSDavid Howells /* 9140d81a51aSDavid Howells * conn_object.c 91517926a79SDavid Howells */ 916dad8aff7SDavid Howells extern unsigned int rxrpc_connection_expiry; 917f859ab61SDavid Howells extern unsigned int rxrpc_closed_conn_expiry; 91817926a79SDavid Howells 919*f2cce89aSDavid Howells void rxrpc_poke_conn(struct rxrpc_connection *conn, enum rxrpc_conn_trace why); 9203cec055cSDavid Howells struct rxrpc_connection *rxrpc_alloc_connection(struct rxrpc_net *, gfp_t); 9215e6ef4f1SDavid Howells struct rxrpc_connection *rxrpc_find_client_connection_rcu(struct rxrpc_local *, 922393a2a20SDavid Howells struct sockaddr_rxrpc *, 9235e6ef4f1SDavid Howells struct sk_buff *); 92445025bceSDavid Howells void __rxrpc_disconnect_call(struct rxrpc_connection *, struct rxrpc_call *); 925999b69f8SDavid Howells void rxrpc_disconnect_call(struct rxrpc_call *); 9263cec055cSDavid Howells void rxrpc_kill_client_conn(struct rxrpc_connection *); 9273cec055cSDavid Howells void rxrpc_queue_conn(struct rxrpc_connection *, enum rxrpc_conn_trace); 9287fa25105SDavid Howells void rxrpc_see_connection(struct rxrpc_connection *, enum rxrpc_conn_trace); 9297fa25105SDavid Howells struct rxrpc_connection *rxrpc_get_connection(struct rxrpc_connection *, 9307fa25105SDavid Howells enum rxrpc_conn_trace); 9317fa25105SDavid Howells struct rxrpc_connection *rxrpc_get_connection_maybe(struct rxrpc_connection *, 9327fa25105SDavid Howells enum rxrpc_conn_trace); 9333cec055cSDavid Howells void rxrpc_put_connection(struct rxrpc_connection *, enum rxrpc_conn_trace); 9342baec2c3SDavid Howells void rxrpc_service_connection_reaper(struct work_struct *); 9352baec2c3SDavid Howells void rxrpc_destroy_all_connections(struct rxrpc_net *); 93617926a79SDavid Howells 93719ffa01cSDavid Howells static inline bool rxrpc_conn_is_client(const struct rxrpc_connection *conn) 93819ffa01cSDavid Howells { 93919ffa01cSDavid Howells return conn->out_clientflag; 94019ffa01cSDavid Howells } 94119ffa01cSDavid Howells 94219ffa01cSDavid Howells static inline bool rxrpc_conn_is_service(const struct rxrpc_connection *conn) 94319ffa01cSDavid Howells { 944e8d70ce1SDavid Howells return !rxrpc_conn_is_client(conn); 94519ffa01cSDavid Howells } 94619ffa01cSDavid Howells 9473136ef49SDavid Howells static inline void rxrpc_reduce_conn_timer(struct rxrpc_connection *conn, 9483136ef49SDavid Howells unsigned long expire_at) 9493136ef49SDavid Howells { 9503136ef49SDavid Howells timer_reduce(&conn->timer, expire_at); 9513136ef49SDavid Howells } 9523136ef49SDavid Howells 95317926a79SDavid Howells /* 9547877a4a4SDavid Howells * conn_service.c 9557877a4a4SDavid Howells */ 9568496af50SDavid Howells struct rxrpc_connection *rxrpc_find_service_conn_rcu(struct rxrpc_peer *, 9578496af50SDavid Howells struct sk_buff *); 9582baec2c3SDavid Howells struct rxrpc_connection *rxrpc_prealloc_service_connection(struct rxrpc_net *, gfp_t); 959063c60d3SDavid Howells void rxrpc_new_incoming_connection(struct rxrpc_sock *, struct rxrpc_connection *, 960ec832bd0SDavid Howells const struct rxrpc_security *, struct sk_buff *); 961001c1122SDavid Howells void rxrpc_unpublish_service_conn(struct rxrpc_connection *); 9627877a4a4SDavid Howells 9637877a4a4SDavid Howells /* 9640d81a51aSDavid Howells * input.c 96517926a79SDavid Howells */ 9665086d9a9SDavid Howells void rxrpc_congestion_degrade(struct rxrpc_call *); 9675e6ef4f1SDavid Howells void rxrpc_input_call_packet(struct rxrpc_call *, struct sk_buff *); 9685e6ef4f1SDavid Howells void rxrpc_implicit_end_call(struct rxrpc_call *, struct sk_buff *); 96996b2d69bSDavid Howells 97096b2d69bSDavid Howells /* 97196b2d69bSDavid Howells * io_thread.c 97296b2d69bSDavid Howells */ 973446b3e14SDavid Howells int rxrpc_encap_rcv(struct sock *, struct sk_buff *); 974ff734825SDavid Howells void rxrpc_error_report(struct sock *); 975a275da62SDavid Howells int rxrpc_io_thread(void *data); 976a275da62SDavid Howells static inline void rxrpc_wake_up_io_thread(struct rxrpc_local *local) 977a275da62SDavid Howells { 978a275da62SDavid Howells wake_up_process(local->io_thread); 979a275da62SDavid Howells } 98017926a79SDavid Howells 98117926a79SDavid Howells /* 9820d81a51aSDavid Howells * insecure.c 98317926a79SDavid Howells */ 9840d81a51aSDavid Howells extern const struct rxrpc_security rxrpc_no_security; 98517926a79SDavid Howells 98617926a79SDavid Howells /* 9870d81a51aSDavid Howells * key.c 98817926a79SDavid Howells */ 98917926a79SDavid Howells extern struct key_type key_type_rxrpc; 99017926a79SDavid Howells 991a7b75c5aSChristoph Hellwig int rxrpc_request_key(struct rxrpc_sock *, sockptr_t , int); 99210674a03SBaolin Wang int rxrpc_get_server_data_key(struct rxrpc_connection *, const void *, time64_t, 993c1b1203dSJoe Perches u32); 99417926a79SDavid Howells 99517926a79SDavid Howells /* 99687563616SDavid Howells * local_event.c 99787563616SDavid Howells */ 9985e6ef4f1SDavid Howells void rxrpc_send_version_request(struct rxrpc_local *local, 9995e6ef4f1SDavid Howells struct rxrpc_host_header *hdr, 10005e6ef4f1SDavid Howells struct sk_buff *skb); 100187563616SDavid Howells 100287563616SDavid Howells /* 10030d81a51aSDavid Howells * local_object.c 100417926a79SDavid Howells */ 10052baec2c3SDavid Howells struct rxrpc_local *rxrpc_lookup_local(struct net *, const struct sockaddr_rxrpc *); 10060fde882fSDavid Howells struct rxrpc_local *rxrpc_get_local(struct rxrpc_local *, enum rxrpc_local_trace); 10070fde882fSDavid Howells struct rxrpc_local *rxrpc_get_local_maybe(struct rxrpc_local *, enum rxrpc_local_trace); 10080fde882fSDavid Howells void rxrpc_put_local(struct rxrpc_local *, enum rxrpc_local_trace); 10090fde882fSDavid Howells struct rxrpc_local *rxrpc_use_local(struct rxrpc_local *, enum rxrpc_local_trace); 10100fde882fSDavid Howells void rxrpc_unuse_local(struct rxrpc_local *, enum rxrpc_local_trace); 1011a275da62SDavid Howells void rxrpc_destroy_local(struct rxrpc_local *local); 10122baec2c3SDavid Howells void rxrpc_destroy_all_locals(struct rxrpc_net *); 1013e0e4d82fSDavid Howells 10140fde882fSDavid Howells static inline bool __rxrpc_use_local(struct rxrpc_local *local, 10150fde882fSDavid Howells enum rxrpc_local_trace why) 101604d36d74SDavid Howells { 10170fde882fSDavid Howells int r, u; 10180fde882fSDavid Howells 10190fde882fSDavid Howells r = refcount_read(&local->ref); 10200fde882fSDavid Howells u = atomic_fetch_add_unless(&local->active_users, 1, 0); 10210fde882fSDavid Howells trace_rxrpc_local(local->debug_id, why, r, u); 10220fde882fSDavid Howells return u != 0; 10230fde882fSDavid Howells } 10240fde882fSDavid Howells 10250fde882fSDavid Howells static inline void rxrpc_see_local(struct rxrpc_local *local, 10260fde882fSDavid Howells enum rxrpc_local_trace why) 10270fde882fSDavid Howells { 10280fde882fSDavid Howells int r, u; 10290fde882fSDavid Howells 10300fde882fSDavid Howells r = refcount_read(&local->ref); 10310fde882fSDavid Howells u = atomic_read(&local->active_users); 10320fde882fSDavid Howells trace_rxrpc_local(local->debug_id, why, r, u); 103304d36d74SDavid Howells } 103404d36d74SDavid Howells 1035e0e4d82fSDavid Howells /* 10368e688d9cSDavid Howells * misc.c 10378e688d9cSDavid Howells */ 10380e119b41SDavid Howells extern unsigned int rxrpc_max_backlog __read_mostly; 1039a158bdd3SDavid Howells extern unsigned long rxrpc_soft_ack_delay; 1040a158bdd3SDavid Howells extern unsigned long rxrpc_idle_ack_delay; 10418e688d9cSDavid Howells extern unsigned int rxrpc_rx_window_size; 10428e688d9cSDavid Howells extern unsigned int rxrpc_rx_mtu; 10438e688d9cSDavid Howells extern unsigned int rxrpc_rx_jumbo_max; 10448e688d9cSDavid Howells 10458e688d9cSDavid Howells /* 10462baec2c3SDavid Howells * net_ns.c 10472baec2c3SDavid Howells */ 10482baec2c3SDavid Howells extern unsigned int rxrpc_net_id; 10492baec2c3SDavid Howells extern struct pernet_operations rxrpc_net_ops; 10502baec2c3SDavid Howells 10512baec2c3SDavid Howells static inline struct rxrpc_net *rxrpc_net(struct net *net) 10522baec2c3SDavid Howells { 10532baec2c3SDavid Howells return net_generic(net, rxrpc_net_id); 10542baec2c3SDavid Howells } 10552baec2c3SDavid Howells 10562baec2c3SDavid Howells /* 10570d81a51aSDavid Howells * output.c 10580d81a51aSDavid Howells */ 1059b0346843SDavid Howells int rxrpc_send_ack_packet(struct rxrpc_call *call, struct rxrpc_txbuf *txb); 106026cb02aaSDavid Howells int rxrpc_send_abort_packet(struct rxrpc_call *); 1061a4ea4c47SDavid Howells int rxrpc_send_data_packet(struct rxrpc_call *, struct rxrpc_txbuf *); 10625e6ef4f1SDavid Howells void rxrpc_reject_packet(struct rxrpc_local *local, struct sk_buff *skb); 1063ace45becSDavid Howells void rxrpc_send_keepalive(struct rxrpc_peer *); 1064cf37b598SDavid Howells void rxrpc_transmit_one(struct rxrpc_call *call, struct rxrpc_txbuf *txb); 10650d81a51aSDavid Howells 10660d81a51aSDavid Howells /* 1067abe89ef0SDavid Howells * peer_event.c 10680d81a51aSDavid Howells */ 1069ff734825SDavid Howells void rxrpc_input_error(struct rxrpc_local *, struct sk_buff *); 1070ace45becSDavid Howells void rxrpc_peer_keepalive_worker(struct work_struct *); 10710d81a51aSDavid Howells 10720d81a51aSDavid Howells /* 10730d81a51aSDavid Howells * peer_object.c 10740d81a51aSDavid Howells */ 1075be6e6707SDavid Howells struct rxrpc_peer *rxrpc_lookup_peer_rcu(struct rxrpc_local *, 1076be6e6707SDavid Howells const struct sockaddr_rxrpc *); 10778a758d98SDavid Howells struct rxrpc_peer *rxrpc_lookup_peer(struct rxrpc_local *local, 10788a758d98SDavid Howells struct sockaddr_rxrpc *srx, gfp_t gfp); 107947c810a7SDavid Howells struct rxrpc_peer *rxrpc_alloc_peer(struct rxrpc_local *, gfp_t, 108047c810a7SDavid Howells enum rxrpc_peer_trace); 10818a758d98SDavid Howells void rxrpc_new_incoming_peer(struct rxrpc_local *local, struct rxrpc_peer *peer); 108217226f12SDavid Howells void rxrpc_destroy_all_peers(struct rxrpc_net *); 108347c810a7SDavid Howells struct rxrpc_peer *rxrpc_get_peer(struct rxrpc_peer *, enum rxrpc_peer_trace); 108447c810a7SDavid Howells struct rxrpc_peer *rxrpc_get_peer_maybe(struct rxrpc_peer *, enum rxrpc_peer_trace); 108547c810a7SDavid Howells void rxrpc_put_peer(struct rxrpc_peer *, enum rxrpc_peer_trace); 10860d81a51aSDavid Howells 10870d81a51aSDavid Howells /* 10880d81a51aSDavid Howells * proc.c 10890d81a51aSDavid Howells */ 1090c3506372SChristoph Hellwig extern const struct seq_operations rxrpc_call_seq_ops; 1091c3506372SChristoph Hellwig extern const struct seq_operations rxrpc_connection_seq_ops; 1092bc0e7cf4SDavid Howells extern const struct seq_operations rxrpc_peer_seq_ops; 109333912c26SDavid Howells extern const struct seq_operations rxrpc_local_seq_ops; 10940d81a51aSDavid Howells 10950d81a51aSDavid Howells /* 10960d81a51aSDavid Howells * recvmsg.c 10970d81a51aSDavid Howells */ 1098248f219cSDavid Howells void rxrpc_notify_socket(struct rxrpc_call *); 10993067bf8cSDavid Howells bool __rxrpc_set_call_completion(struct rxrpc_call *, enum rxrpc_call_completion, u32, int); 11003067bf8cSDavid Howells bool rxrpc_set_call_completion(struct rxrpc_call *, enum rxrpc_call_completion, u32, int); 11013067bf8cSDavid Howells bool __rxrpc_call_completed(struct rxrpc_call *); 11023067bf8cSDavid Howells bool rxrpc_call_completed(struct rxrpc_call *); 11033067bf8cSDavid Howells bool __rxrpc_abort_call(const char *, struct rxrpc_call *, rxrpc_seq_t, u32, int); 11043067bf8cSDavid Howells bool rxrpc_abort_call(const char *, struct rxrpc_call *, rxrpc_seq_t, u32, int); 11050d81a51aSDavid Howells int rxrpc_recvmsg(struct socket *, struct msghdr *, size_t, int); 11060d81a51aSDavid Howells 11070d81a51aSDavid Howells /* 11083067bf8cSDavid Howells * Abort a call due to a protocol error. 11093067bf8cSDavid Howells */ 11103067bf8cSDavid Howells static inline bool __rxrpc_abort_eproto(struct rxrpc_call *call, 11113067bf8cSDavid Howells struct sk_buff *skb, 11123067bf8cSDavid Howells const char *eproto_why, 11133067bf8cSDavid Howells const char *why, 11143067bf8cSDavid Howells u32 abort_code) 11153067bf8cSDavid Howells { 11163067bf8cSDavid Howells struct rxrpc_skb_priv *sp = rxrpc_skb(skb); 11173067bf8cSDavid Howells 11183067bf8cSDavid Howells trace_rxrpc_rx_eproto(call, sp->hdr.serial, eproto_why); 11193067bf8cSDavid Howells return rxrpc_abort_call(why, call, sp->hdr.seq, abort_code, -EPROTO); 11203067bf8cSDavid Howells } 11213067bf8cSDavid Howells 11223067bf8cSDavid Howells #define rxrpc_abort_eproto(call, skb, eproto_why, abort_why, abort_code) \ 11233067bf8cSDavid Howells __rxrpc_abort_eproto((call), (skb), tracepoint_string(eproto_why), \ 11243067bf8cSDavid Howells (abort_why), (abort_code)) 11253067bf8cSDavid Howells 11263067bf8cSDavid Howells /* 1127c410bf01SDavid Howells * rtt.c 1128c410bf01SDavid Howells */ 11294700c4d8SDavid Howells void rxrpc_peer_add_rtt(struct rxrpc_call *, enum rxrpc_rtt_rx_trace, int, 1130c410bf01SDavid Howells rxrpc_serial_t, rxrpc_serial_t, ktime_t, ktime_t); 1131c410bf01SDavid Howells unsigned long rxrpc_get_rto_backoff(struct rxrpc_peer *, bool); 1132c410bf01SDavid Howells void rxrpc_peer_init_rtt(struct rxrpc_peer *); 1133c410bf01SDavid Howells 1134c410bf01SDavid Howells /* 1135648af7fcSDavid Howells * rxkad.c 1136648af7fcSDavid Howells */ 1137648af7fcSDavid Howells #ifdef CONFIG_RXKAD 1138648af7fcSDavid Howells extern const struct rxrpc_security rxkad; 1139648af7fcSDavid Howells #endif 1140648af7fcSDavid Howells 1141648af7fcSDavid Howells /* 11420d81a51aSDavid Howells * security.c 11430d81a51aSDavid Howells */ 11440d81a51aSDavid Howells int __init rxrpc_init_security(void); 114512da59fcSDavid Howells const struct rxrpc_security *rxrpc_security_lookup(u8); 11460d81a51aSDavid Howells void rxrpc_exit_security(void); 1147f3441d41SDavid Howells int rxrpc_init_client_call_security(struct rxrpc_call *); 11480d81a51aSDavid Howells int rxrpc_init_client_conn_security(struct rxrpc_connection *); 1149ec832bd0SDavid Howells const struct rxrpc_security *rxrpc_get_incoming_security(struct rxrpc_sock *, 1150063c60d3SDavid Howells struct sk_buff *); 1151ec832bd0SDavid Howells struct key *rxrpc_look_up_server_security(struct rxrpc_connection *, 1152ec832bd0SDavid Howells struct sk_buff *, u32, u32); 11530d81a51aSDavid Howells 11540d81a51aSDavid Howells /* 11550b58b8a1SDavid Howells * sendmsg.c 11560b58b8a1SDavid Howells */ 1157a343b174SDavid Howells bool rxrpc_propose_abort(struct rxrpc_call *call, 1158a343b174SDavid Howells u32 abort_code, int error, const char *why); 11590b58b8a1SDavid Howells int rxrpc_do_sendmsg(struct rxrpc_sock *, struct msghdr *, size_t); 11600b58b8a1SDavid Howells 11610b58b8a1SDavid Howells /* 1162ca7fb100SDavid Howells * server_key.c 1163ca7fb100SDavid Howells */ 1164ca7fb100SDavid Howells extern struct key_type key_type_rxrpc_s; 1165ca7fb100SDavid Howells 1166ca7fb100SDavid Howells int rxrpc_server_keyring(struct rxrpc_sock *, sockptr_t, int); 1167ca7fb100SDavid Howells 1168ca7fb100SDavid Howells /* 11690d81a51aSDavid Howells * skbuff.c 11700d81a51aSDavid Howells */ 1171d001648eSDavid Howells void rxrpc_kernel_data_consumed(struct rxrpc_call *, struct sk_buff *); 117271f3ca40SDavid Howells void rxrpc_new_skb(struct sk_buff *, enum rxrpc_skb_trace); 117371f3ca40SDavid Howells void rxrpc_see_skb(struct sk_buff *, enum rxrpc_skb_trace); 1174d0d5c0cdSDavid Howells void rxrpc_eaten_skb(struct sk_buff *, enum rxrpc_skb_trace); 117571f3ca40SDavid Howells void rxrpc_get_skb(struct sk_buff *, enum rxrpc_skb_trace); 117671f3ca40SDavid Howells void rxrpc_free_skb(struct sk_buff *, enum rxrpc_skb_trace); 1177df844fd4SDavid Howells void rxrpc_purge_queue(struct sk_buff_head *); 11780d81a51aSDavid Howells 11790d81a51aSDavid Howells /* 1180b0154246SDavid Howells * stats.c 1181b0154246SDavid Howells */ 1182b0154246SDavid Howells int rxrpc_stats_show(struct seq_file *seq, void *v); 1183b0154246SDavid Howells int rxrpc_stats_clear(struct file *file, char *buf, size_t size); 1184b0154246SDavid Howells 1185b0154246SDavid Howells #define rxrpc_inc_stat(rxnet, s) atomic_inc(&(rxnet)->s) 1186b0154246SDavid Howells #define rxrpc_dec_stat(rxnet, s) atomic_dec(&(rxnet)->s) 1187b0154246SDavid Howells 1188b0154246SDavid Howells /* 11895873c083SDavid Howells * sysctl.c 11905873c083SDavid Howells */ 11915873c083SDavid Howells #ifdef CONFIG_SYSCTL 11925873c083SDavid Howells extern int __init rxrpc_sysctl_init(void); 11935873c083SDavid Howells extern void rxrpc_sysctl_exit(void); 11945873c083SDavid Howells #else 11955873c083SDavid Howells static inline int __init rxrpc_sysctl_init(void) { return 0; } 11965873c083SDavid Howells static inline void rxrpc_sysctl_exit(void) {} 11975873c083SDavid Howells #endif 11985873c083SDavid Howells 11995873c083SDavid Howells /* 120002a19356SDavid Howells * txbuf.c 120102a19356SDavid Howells */ 120202a19356SDavid Howells extern atomic_t rxrpc_nr_txbuf; 120302a19356SDavid Howells struct rxrpc_txbuf *rxrpc_alloc_txbuf(struct rxrpc_call *call, u8 packet_type, 120402a19356SDavid Howells gfp_t gfp); 120502a19356SDavid Howells void rxrpc_get_txbuf(struct rxrpc_txbuf *txb, enum rxrpc_txbuf_trace what); 120602a19356SDavid Howells void rxrpc_see_txbuf(struct rxrpc_txbuf *txb, enum rxrpc_txbuf_trace what); 120702a19356SDavid Howells void rxrpc_put_txbuf(struct rxrpc_txbuf *txb, enum rxrpc_txbuf_trace what); 120802a19356SDavid Howells 120902a19356SDavid Howells /* 1210be6e6707SDavid Howells * utils.c 1211be6e6707SDavid Howells */ 12125a790b73SDavid Howells int rxrpc_extract_addr_from_skb(struct sockaddr_rxrpc *, struct sk_buff *); 1213be6e6707SDavid Howells 1214248f219cSDavid Howells static inline bool before(u32 seq1, u32 seq2) 1215248f219cSDavid Howells { 1216248f219cSDavid Howells return (s32)(seq1 - seq2) < 0; 1217248f219cSDavid Howells } 1218248f219cSDavid Howells static inline bool before_eq(u32 seq1, u32 seq2) 1219248f219cSDavid Howells { 1220248f219cSDavid Howells return (s32)(seq1 - seq2) <= 0; 1221248f219cSDavid Howells } 1222248f219cSDavid Howells static inline bool after(u32 seq1, u32 seq2) 1223248f219cSDavid Howells { 1224248f219cSDavid Howells return (s32)(seq1 - seq2) > 0; 1225248f219cSDavid Howells } 1226248f219cSDavid Howells static inline bool after_eq(u32 seq1, u32 seq2) 1227248f219cSDavid Howells { 1228248f219cSDavid Howells return (s32)(seq1 - seq2) >= 0; 1229248f219cSDavid Howells } 1230248f219cSDavid Howells 1231be6e6707SDavid Howells /* 123217926a79SDavid Howells * debug tracing 123317926a79SDavid Howells */ 123495c96174SEric Dumazet extern unsigned int rxrpc_debug; 123517926a79SDavid Howells 123617926a79SDavid Howells #define dbgprintk(FMT,...) \ 12379f389f4bSSven Schnelle printk("[%-6.6s] "FMT"\n", current->comm ,##__VA_ARGS__) 123817926a79SDavid Howells 12390dc47877SHarvey Harrison #define kenter(FMT,...) dbgprintk("==> %s("FMT")",__func__ ,##__VA_ARGS__) 12400dc47877SHarvey Harrison #define kleave(FMT,...) dbgprintk("<== %s()"FMT"",__func__ ,##__VA_ARGS__) 124117926a79SDavid Howells #define kdebug(FMT,...) dbgprintk(" "FMT ,##__VA_ARGS__) 124217926a79SDavid Howells 124317926a79SDavid Howells 124417926a79SDavid Howells #if defined(__KDEBUG) 124517926a79SDavid Howells #define _enter(FMT,...) kenter(FMT,##__VA_ARGS__) 124617926a79SDavid Howells #define _leave(FMT,...) kleave(FMT,##__VA_ARGS__) 124717926a79SDavid Howells #define _debug(FMT,...) kdebug(FMT,##__VA_ARGS__) 124817926a79SDavid Howells 124917926a79SDavid Howells #elif defined(CONFIG_AF_RXRPC_DEBUG) 125017926a79SDavid Howells #define RXRPC_DEBUG_KENTER 0x01 125117926a79SDavid Howells #define RXRPC_DEBUG_KLEAVE 0x02 125217926a79SDavid Howells #define RXRPC_DEBUG_KDEBUG 0x04 125317926a79SDavid Howells 125417926a79SDavid Howells #define _enter(FMT,...) \ 125517926a79SDavid Howells do { \ 125617926a79SDavid Howells if (unlikely(rxrpc_debug & RXRPC_DEBUG_KENTER)) \ 125717926a79SDavid Howells kenter(FMT,##__VA_ARGS__); \ 125817926a79SDavid Howells } while (0) 125917926a79SDavid Howells 126017926a79SDavid Howells #define _leave(FMT,...) \ 126117926a79SDavid Howells do { \ 126217926a79SDavid Howells if (unlikely(rxrpc_debug & RXRPC_DEBUG_KLEAVE)) \ 126317926a79SDavid Howells kleave(FMT,##__VA_ARGS__); \ 126417926a79SDavid Howells } while (0) 126517926a79SDavid Howells 126617926a79SDavid Howells #define _debug(FMT,...) \ 126717926a79SDavid Howells do { \ 126817926a79SDavid Howells if (unlikely(rxrpc_debug & RXRPC_DEBUG_KDEBUG)) \ 126917926a79SDavid Howells kdebug(FMT,##__VA_ARGS__); \ 127017926a79SDavid Howells } while (0) 127117926a79SDavid Howells 127217926a79SDavid Howells #else 127312fdff3fSDavid Howells #define _enter(FMT,...) no_printk("==> %s("FMT")",__func__ ,##__VA_ARGS__) 127412fdff3fSDavid Howells #define _leave(FMT,...) no_printk("<== %s()"FMT"",__func__ ,##__VA_ARGS__) 127512fdff3fSDavid Howells #define _debug(FMT,...) no_printk(" "FMT ,##__VA_ARGS__) 127617926a79SDavid Howells #endif 127717926a79SDavid Howells 127817926a79SDavid Howells /* 127917926a79SDavid Howells * debug assertion checking 128017926a79SDavid Howells */ 128117926a79SDavid Howells #if 1 // defined(__KDEBUGALL) 128217926a79SDavid Howells 128317926a79SDavid Howells #define ASSERT(X) \ 128417926a79SDavid Howells do { \ 128517926a79SDavid Howells if (unlikely(!(X))) { \ 12869b6d5398SJoe Perches pr_err("Assertion failed\n"); \ 128717926a79SDavid Howells BUG(); \ 128817926a79SDavid Howells } \ 128917926a79SDavid Howells } while (0) 129017926a79SDavid Howells 129117926a79SDavid Howells #define ASSERTCMP(X, OP, Y) \ 129217926a79SDavid Howells do { \ 1293cf13258fSDavid Howells __typeof__(X) _x = (X); \ 1294cf13258fSDavid Howells __typeof__(Y) _y = (__typeof__(X))(Y); \ 12959b6d5398SJoe Perches if (unlikely(!(_x OP _y))) { \ 12969b6d5398SJoe Perches pr_err("Assertion failed - %lu(0x%lx) %s %lu(0x%lx) is false\n", \ 1297cf13258fSDavid Howells (unsigned long)_x, (unsigned long)_x, #OP, \ 1298cf13258fSDavid Howells (unsigned long)_y, (unsigned long)_y); \ 129917926a79SDavid Howells BUG(); \ 130017926a79SDavid Howells } \ 130117926a79SDavid Howells } while (0) 130217926a79SDavid Howells 130317926a79SDavid Howells #define ASSERTIF(C, X) \ 130417926a79SDavid Howells do { \ 130517926a79SDavid Howells if (unlikely((C) && !(X))) { \ 13069b6d5398SJoe Perches pr_err("Assertion failed\n"); \ 130717926a79SDavid Howells BUG(); \ 130817926a79SDavid Howells } \ 130917926a79SDavid Howells } while (0) 131017926a79SDavid Howells 131117926a79SDavid Howells #define ASSERTIFCMP(C, X, OP, Y) \ 131217926a79SDavid Howells do { \ 1313cf13258fSDavid Howells __typeof__(X) _x = (X); \ 1314cf13258fSDavid Howells __typeof__(Y) _y = (__typeof__(X))(Y); \ 13159b6d5398SJoe Perches if (unlikely((C) && !(_x OP _y))) { \ 13169b6d5398SJoe Perches pr_err("Assertion failed - %lu(0x%lx) %s %lu(0x%lx) is false\n", \ 1317cf13258fSDavid Howells (unsigned long)_x, (unsigned long)_x, #OP, \ 1318cf13258fSDavid Howells (unsigned long)_y, (unsigned long)_y); \ 131917926a79SDavid Howells BUG(); \ 132017926a79SDavid Howells } \ 132117926a79SDavid Howells } while (0) 132217926a79SDavid Howells 132317926a79SDavid Howells #else 132417926a79SDavid Howells 132517926a79SDavid Howells #define ASSERT(X) \ 132617926a79SDavid Howells do { \ 132717926a79SDavid Howells } while (0) 132817926a79SDavid Howells 132917926a79SDavid Howells #define ASSERTCMP(X, OP, Y) \ 133017926a79SDavid Howells do { \ 133117926a79SDavid Howells } while (0) 133217926a79SDavid Howells 133317926a79SDavid Howells #define ASSERTIF(C, X) \ 133417926a79SDavid Howells do { \ 133517926a79SDavid Howells } while (0) 133617926a79SDavid Howells 133717926a79SDavid Howells #define ASSERTIFCMP(C, X, OP, Y) \ 133817926a79SDavid Howells do { \ 133917926a79SDavid Howells } while (0) 134017926a79SDavid Howells 134117926a79SDavid Howells #endif /* __KDEBUGALL */ 1342