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> 102baec2c3SDavid Howells #include <net/net_namespace.h> 112baec2c3SDavid Howells #include <net/netns/generic.h> 12e0e4d82fSDavid Howells #include <net/sock.h> 13be6e6707SDavid Howells #include <net/af_rxrpc.h> 14ddc6c70fSDavid Howells #include "protocol.h" 1517926a79SDavid Howells 1617926a79SDavid Howells #if 0 1717926a79SDavid Howells #define CHECK_SLAB_OKAY(X) \ 1817926a79SDavid Howells BUG_ON(atomic_read((X)) >> (sizeof(atomic_t) - 2) == \ 1917926a79SDavid Howells (POISON_FREE << 8 | POISON_FREE)) 2017926a79SDavid Howells #else 2117926a79SDavid Howells #define CHECK_SLAB_OKAY(X) do {} while (0) 2217926a79SDavid Howells #endif 2317926a79SDavid Howells 2417926a79SDavid Howells #define FCRYPT_BSIZE 8 2517926a79SDavid Howells struct rxrpc_crypt { 2617926a79SDavid Howells union { 2717926a79SDavid Howells u8 x[FCRYPT_BSIZE]; 2891e916cfSAl Viro __be32 n[2]; 2917926a79SDavid Howells }; 3017926a79SDavid Howells } __attribute__((aligned(8))); 3117926a79SDavid Howells 32651350d1SDavid Howells #define rxrpc_queue_work(WS) queue_work(rxrpc_workqueue, (WS)) 33651350d1SDavid Howells #define rxrpc_queue_delayed_work(WS,D) \ 34651350d1SDavid Howells queue_delayed_work(rxrpc_workqueue, (WS), (D)) 35651350d1SDavid Howells 36cc8feb8eSDavid Howells struct rxrpc_connection; 37cc8feb8eSDavid Howells 3817926a79SDavid Howells /* 39ece64fecSDavid Howells * Mark applied to socket buffers in skb->mark. skb->priority is used 40ece64fecSDavid Howells * to pass supplementary information. 41d001648eSDavid Howells */ 42d001648eSDavid Howells enum rxrpc_skb_mark { 43ece64fecSDavid Howells RXRPC_SKB_MARK_REJECT_BUSY, /* Reject with BUSY */ 44ece64fecSDavid Howells RXRPC_SKB_MARK_REJECT_ABORT, /* Reject with ABORT (code in skb->priority) */ 45d001648eSDavid Howells }; 46d001648eSDavid Howells 47d001648eSDavid Howells /* 4817926a79SDavid Howells * sk_state for RxRPC sockets 4917926a79SDavid Howells */ 5017926a79SDavid Howells enum { 512341e077SDavid Howells RXRPC_UNBOUND = 0, 522341e077SDavid Howells RXRPC_CLIENT_UNBOUND, /* Unbound socket used as client */ 5317926a79SDavid Howells RXRPC_CLIENT_BOUND, /* client local address bound */ 5417926a79SDavid Howells RXRPC_SERVER_BOUND, /* server local address bound */ 5528036f44SDavid Howells RXRPC_SERVER_BOUND2, /* second server local address bound */ 5617926a79SDavid Howells RXRPC_SERVER_LISTENING, /* server listening for connections */ 57210f0353SDavid Howells RXRPC_SERVER_LISTEN_DISABLED, /* server listening disabled */ 5817926a79SDavid Howells RXRPC_CLOSE, /* socket is being closed */ 5917926a79SDavid Howells }; 6017926a79SDavid Howells 6117926a79SDavid Howells /* 622baec2c3SDavid Howells * Per-network namespace data. 632baec2c3SDavid Howells */ 642baec2c3SDavid Howells struct rxrpc_net { 652baec2c3SDavid Howells struct proc_dir_entry *proc_net; /* Subdir in /proc/net */ 662baec2c3SDavid Howells u32 epoch; /* Local epoch for detecting local-end reset */ 672baec2c3SDavid Howells struct list_head calls; /* List of calls active in this namespace */ 682baec2c3SDavid Howells rwlock_t call_lock; /* Lock for ->calls */ 69d3be4d24SDavid Howells atomic_t nr_calls; /* Count of allocated calls */ 702baec2c3SDavid Howells 7131f5f9a1SDavid Howells atomic_t nr_conns; 722baec2c3SDavid Howells struct list_head conn_proc_list; /* List of conns in this namespace for proc */ 732baec2c3SDavid Howells struct list_head service_conns; /* Service conns in this namespace */ 742baec2c3SDavid Howells rwlock_t conn_lock; /* Lock for ->conn_proc_list, ->service_conns */ 753d18cbb7SDavid Howells struct work_struct service_conn_reaper; 763d18cbb7SDavid Howells struct timer_list service_conn_reap_timer; 772baec2c3SDavid Howells 782baec2c3SDavid Howells unsigned int nr_client_conns; 792baec2c3SDavid Howells unsigned int nr_active_client_conns; 802baec2c3SDavid Howells bool kill_all_client_conns; 81f859ab61SDavid Howells bool live; 822baec2c3SDavid Howells spinlock_t client_conn_cache_lock; /* Lock for ->*_client_conns */ 832baec2c3SDavid Howells spinlock_t client_conn_discard_lock; /* Prevent multiple discarders */ 842baec2c3SDavid Howells struct list_head waiting_client_conns; 852baec2c3SDavid Howells struct list_head active_client_conns; 862baec2c3SDavid Howells struct list_head idle_client_conns; 873d18cbb7SDavid Howells struct work_struct client_conn_reaper; 883d18cbb7SDavid Howells struct timer_list client_conn_reap_timer; 892baec2c3SDavid Howells 902baec2c3SDavid Howells struct list_head local_endpoints; 912baec2c3SDavid Howells struct mutex local_mutex; /* Lock for ->local_endpoints */ 922baec2c3SDavid Howells 932baec2c3SDavid Howells DECLARE_HASHTABLE (peer_hash, 10); 94ace45becSDavid Howells spinlock_t peer_hash_lock; /* Lock for ->peer_hash */ 95ace45becSDavid Howells 96ace45becSDavid Howells #define RXRPC_KEEPALIVE_TIME 20 /* NAT keepalive time in seconds */ 97ace45becSDavid Howells u8 peer_keepalive_cursor; 98330bdcfaSDavid Howells time64_t peer_keepalive_base; 99330bdcfaSDavid Howells struct list_head peer_keepalive[32]; 100330bdcfaSDavid Howells struct list_head peer_keepalive_new; 101ace45becSDavid Howells struct timer_list peer_keepalive_timer; 102ace45becSDavid Howells struct work_struct peer_keepalive_work; 1032baec2c3SDavid Howells }; 1042baec2c3SDavid Howells 1052baec2c3SDavid Howells /* 10600e90712SDavid Howells * Service backlog preallocation. 10700e90712SDavid Howells * 10800e90712SDavid Howells * This contains circular buffers of preallocated peers, connections and calls 10900e90712SDavid Howells * for incoming service calls and their head and tail pointers. This allows 11000e90712SDavid Howells * calls to be set up in the data_ready handler, thereby avoiding the need to 11100e90712SDavid Howells * shuffle packets around so much. 11200e90712SDavid Howells */ 11300e90712SDavid Howells struct rxrpc_backlog { 11400e90712SDavid Howells unsigned short peer_backlog_head; 11500e90712SDavid Howells unsigned short peer_backlog_tail; 11600e90712SDavid Howells unsigned short conn_backlog_head; 11700e90712SDavid Howells unsigned short conn_backlog_tail; 11800e90712SDavid Howells unsigned short call_backlog_head; 11900e90712SDavid Howells unsigned short call_backlog_tail; 12000e90712SDavid Howells #define RXRPC_BACKLOG_MAX 32 12100e90712SDavid Howells struct rxrpc_peer *peer_backlog[RXRPC_BACKLOG_MAX]; 12200e90712SDavid Howells struct rxrpc_connection *conn_backlog[RXRPC_BACKLOG_MAX]; 12300e90712SDavid Howells struct rxrpc_call *call_backlog[RXRPC_BACKLOG_MAX]; 12400e90712SDavid Howells }; 12500e90712SDavid Howells 12600e90712SDavid Howells /* 12717926a79SDavid Howells * RxRPC socket definition 12817926a79SDavid Howells */ 12917926a79SDavid Howells struct rxrpc_sock { 13017926a79SDavid Howells /* WARNING: sk has to be the first member */ 13117926a79SDavid Howells struct sock sk; 132d001648eSDavid Howells rxrpc_notify_new_call_t notify_new_call; /* Func to notify of new call */ 13300e90712SDavid Howells rxrpc_discard_new_call_t discard_new_call; /* Func to discard a new call */ 13417926a79SDavid Howells struct rxrpc_local *local; /* local endpoint */ 13500e90712SDavid Howells struct rxrpc_backlog *backlog; /* Preallocation for services */ 136248f219cSDavid Howells spinlock_t incoming_lock; /* Incoming call vs service shutdown lock */ 137248f219cSDavid Howells struct list_head sock_calls; /* List of calls owned by this socket */ 138248f219cSDavid Howells struct list_head to_be_accepted; /* calls awaiting acceptance */ 139248f219cSDavid Howells struct list_head recvmsg_q; /* Calls awaiting recvmsg's attention */ 140248f219cSDavid Howells rwlock_t recvmsg_lock; /* Lock for recvmsg_q */ 14117926a79SDavid Howells struct key *key; /* security for this socket */ 14217926a79SDavid Howells struct key *securities; /* list of server security descriptors */ 14300e90712SDavid Howells struct rb_root calls; /* User ID -> call mapping */ 14417926a79SDavid Howells unsigned long flags; 1452341e077SDavid Howells #define RXRPC_SOCK_CONNECTED 0 /* connect_srx is set */ 14617926a79SDavid Howells rwlock_t call_lock; /* lock for calls */ 14717926a79SDavid Howells u32 min_sec_level; /* minimum security level */ 14817926a79SDavid Howells #define RXRPC_SECURITY_MAX RXRPC_SECURITY_ENCRYPT 149cc8feb8eSDavid Howells bool exclusive; /* Exclusive connection for a client socket */ 15028036f44SDavid Howells u16 second_service; /* Additional service bound to the endpoint */ 1514722974dSDavid Howells struct { 1524722974dSDavid Howells /* Service upgrade information */ 1534722974dSDavid Howells u16 from; /* Service ID to upgrade (if not 0) */ 1544722974dSDavid Howells u16 to; /* service ID to upgrade to */ 1554722974dSDavid Howells } service_upgrade; 156cc8feb8eSDavid Howells sa_family_t family; /* Protocol family created with */ 1574722974dSDavid Howells struct sockaddr_rxrpc srx; /* Primary Service/local addresses */ 1582341e077SDavid Howells struct sockaddr_rxrpc connect_srx; /* Default client address from connect() */ 15917926a79SDavid Howells }; 16017926a79SDavid Howells 16117926a79SDavid Howells #define rxrpc_sk(__sk) container_of((__sk), struct rxrpc_sock, sk) 16217926a79SDavid Howells 16317926a79SDavid Howells /* 1640d12f8a4SDavid Howells * CPU-byteorder normalised Rx packet header. 1650d12f8a4SDavid Howells */ 1660d12f8a4SDavid Howells struct rxrpc_host_header { 1670d12f8a4SDavid Howells u32 epoch; /* client boot timestamp */ 1680d12f8a4SDavid Howells u32 cid; /* connection and channel ID */ 1690d12f8a4SDavid Howells u32 callNumber; /* call ID (0 for connection-level packets) */ 1700d12f8a4SDavid Howells u32 seq; /* sequence number of pkt in call stream */ 1710d12f8a4SDavid Howells u32 serial; /* serial number of pkt sent to network */ 1720d12f8a4SDavid Howells u8 type; /* packet type */ 1730d12f8a4SDavid Howells u8 flags; /* packet flags */ 1740d12f8a4SDavid Howells u8 userStatus; /* app-layer defined status */ 1750d12f8a4SDavid Howells u8 securityIndex; /* security protocol ID */ 1760d12f8a4SDavid Howells union { 1770d12f8a4SDavid Howells u16 _rsvd; /* reserved */ 1780d12f8a4SDavid Howells u16 cksum; /* kerberos security checksum */ 1790d12f8a4SDavid Howells }; 1800d12f8a4SDavid Howells u16 serviceId; /* service ID */ 1810d12f8a4SDavid Howells } __packed; 1820d12f8a4SDavid Howells 1830d12f8a4SDavid Howells /* 18417926a79SDavid Howells * RxRPC socket buffer private variables 18517926a79SDavid Howells * - max 48 bytes (struct sk_buff::cb) 18617926a79SDavid Howells */ 18717926a79SDavid Howells struct rxrpc_skb_priv { 188987db9f7SDavid Howells atomic_t nr_ring_pins; /* Number of rxtx ring pins */ 189c3c9e3dfSDavid Howells u8 nr_subpackets; /* Number of subpackets */ 190c3c9e3dfSDavid Howells u8 rx_flags; /* Received packet flags */ 191c3c9e3dfSDavid Howells #define RXRPC_SKB_INCL_LAST 0x01 /* - Includes last packet */ 192b311e684SDavid Howells #define RXRPC_SKB_TX_BUFFER 0x02 /* - Is transmit buffer */ 19317926a79SDavid Howells union { 19417926a79SDavid Howells int remain; /* amount of space remaining for next write */ 195c3c9e3dfSDavid Howells 196c3c9e3dfSDavid Howells /* List of requested ACKs on subpackets */ 197c3c9e3dfSDavid Howells unsigned long rx_req_ack[(RXRPC_MAX_NR_JUMBO + BITS_PER_LONG - 1) / 198c3c9e3dfSDavid Howells BITS_PER_LONG]; 19917926a79SDavid Howells }; 20017926a79SDavid Howells 2010d12f8a4SDavid Howells struct rxrpc_host_header hdr; /* RxRPC packet header from this packet */ 20217926a79SDavid Howells }; 20317926a79SDavid Howells 20417926a79SDavid Howells #define rxrpc_skb(__skb) ((struct rxrpc_skb_priv *) &(__skb)->cb) 20517926a79SDavid Howells 20617926a79SDavid Howells /* 20717926a79SDavid Howells * RxRPC security module interface 20817926a79SDavid Howells */ 20917926a79SDavid Howells struct rxrpc_security { 21017926a79SDavid Howells const char *name; /* name of this service */ 21117926a79SDavid Howells u8 security_index; /* security type provided */ 21217926a79SDavid Howells 213648af7fcSDavid Howells /* Initialise a security service */ 214648af7fcSDavid Howells int (*init)(void); 215648af7fcSDavid Howells 216648af7fcSDavid Howells /* Clean up a security service */ 217648af7fcSDavid Howells void (*exit)(void); 218648af7fcSDavid Howells 21917926a79SDavid Howells /* initialise a connection's security */ 22017926a79SDavid Howells int (*init_connection_security)(struct rxrpc_connection *); 22117926a79SDavid Howells 22217926a79SDavid Howells /* prime a connection's packet security */ 223a263629dSHerbert Xu int (*prime_packet_security)(struct rxrpc_connection *); 22417926a79SDavid Howells 22517926a79SDavid Howells /* impose security on a packet */ 226a263629dSHerbert Xu int (*secure_packet)(struct rxrpc_call *, 22717926a79SDavid Howells struct sk_buff *, 22817926a79SDavid Howells size_t, 22917926a79SDavid Howells void *); 23017926a79SDavid Howells 23117926a79SDavid Howells /* verify the security on a received packet */ 2325a42976dSDavid Howells int (*verify_packet)(struct rxrpc_call *, struct sk_buff *, 233248f219cSDavid Howells unsigned int, unsigned int, rxrpc_seq_t, u16); 234248f219cSDavid Howells 235248f219cSDavid Howells /* Locate the data in a received packet that has been verified. */ 236248f219cSDavid Howells void (*locate_data)(struct rxrpc_call *, struct sk_buff *, 237248f219cSDavid Howells unsigned int *, unsigned int *); 23817926a79SDavid Howells 23917926a79SDavid Howells /* issue a challenge */ 24017926a79SDavid Howells int (*issue_challenge)(struct rxrpc_connection *); 24117926a79SDavid Howells 24217926a79SDavid Howells /* respond to a challenge */ 24317926a79SDavid Howells int (*respond_to_challenge)(struct rxrpc_connection *, 24417926a79SDavid Howells struct sk_buff *, 24517926a79SDavid Howells u32 *); 24617926a79SDavid Howells 24717926a79SDavid Howells /* verify a response */ 24817926a79SDavid Howells int (*verify_response)(struct rxrpc_connection *, 24917926a79SDavid Howells struct sk_buff *, 25017926a79SDavid Howells u32 *); 25117926a79SDavid Howells 25217926a79SDavid Howells /* clear connection security */ 25317926a79SDavid Howells void (*clear)(struct rxrpc_connection *); 25417926a79SDavid Howells }; 25517926a79SDavid Howells 25617926a79SDavid Howells /* 2574f95dd78SDavid Howells * RxRPC local transport endpoint description 2584f95dd78SDavid Howells * - owned by a single AF_RXRPC socket 2594f95dd78SDavid Howells * - pointed to by transport socket struct sk_user_data 26017926a79SDavid Howells */ 26117926a79SDavid Howells struct rxrpc_local { 2624f95dd78SDavid Howells struct rcu_head rcu; 263730c5fd4SDavid Howells atomic_t active_users; /* Number of users of the local endpoint */ 264730c5fd4SDavid Howells atomic_t usage; /* Number of references to the structure */ 2652baec2c3SDavid Howells struct rxrpc_net *rxnet; /* The network ns in which this resides */ 2664f95dd78SDavid Howells struct list_head link; 26717926a79SDavid Howells struct socket *socket; /* my UDP socket */ 2684f95dd78SDavid Howells struct work_struct processor; 2691e9e5c95SDavid Howells struct rxrpc_sock __rcu *service; /* Service(s) listening on this endpoint */ 27017926a79SDavid Howells struct rw_semaphore defrag_sem; /* control re-enablement of IP DF bit */ 27117926a79SDavid Howells struct sk_buff_head reject_queue; /* packets awaiting rejection */ 27244ba0698SDavid Howells struct sk_buff_head event_queue; /* endpoint event packets awaiting processing */ 273999b69f8SDavid Howells struct rb_root client_conns; /* Client connections by socket params */ 274999b69f8SDavid Howells spinlock_t client_conns_lock; /* Lock for client_conns */ 27517926a79SDavid Howells spinlock_t lock; /* access lock */ 27617926a79SDavid Howells rwlock_t services_lock; /* lock for services list */ 27717926a79SDavid Howells int debug_id; /* debug ID for printks */ 2784f95dd78SDavid Howells bool dead; 279f859ab61SDavid Howells bool service_closed; /* Service socket closed */ 28017926a79SDavid Howells struct sockaddr_rxrpc srx; /* local address */ 28117926a79SDavid Howells }; 28217926a79SDavid Howells 28317926a79SDavid Howells /* 28417926a79SDavid Howells * RxRPC remote transport endpoint definition 285be6e6707SDavid Howells * - matched by local endpoint, remote port, address and protocol type 28617926a79SDavid Howells */ 28717926a79SDavid Howells struct rxrpc_peer { 288be6e6707SDavid Howells struct rcu_head rcu; /* This must be first */ 289be6e6707SDavid Howells atomic_t usage; 290be6e6707SDavid Howells unsigned long hash_key; 291be6e6707SDavid Howells struct hlist_node hash_link; 292be6e6707SDavid Howells struct rxrpc_local *local; 293f66d7490SDavid Howells struct hlist_head error_targets; /* targets for net error distribution */ 294aa390bbeSDavid Howells struct rb_root service_conns; /* Service connections */ 295330bdcfaSDavid Howells struct list_head keepalive_link; /* Link in net->peer_keepalive[] */ 296ace45becSDavid Howells time64_t last_tx_at; /* Last time packet sent here */ 2978496af50SDavid Howells seqlock_t service_conn_lock; 29817926a79SDavid Howells spinlock_t lock; /* access lock */ 29995c96174SEric Dumazet unsigned int if_mtu; /* interface MTU for this peer */ 30095c96174SEric Dumazet unsigned int mtu; /* network MTU for this peer */ 30195c96174SEric Dumazet unsigned int maxdata; /* data size (MTU - hdrsize) */ 30217926a79SDavid Howells unsigned short hdrsize; /* header size (IP + UDP + RxRPC) */ 30317926a79SDavid Howells int debug_id; /* debug ID for printks */ 30417926a79SDavid Howells struct sockaddr_rxrpc srx; /* remote address */ 30517926a79SDavid Howells 30617926a79SDavid Howells /* calculated RTT cache */ 30717926a79SDavid Howells #define RXRPC_RTT_CACHE_SIZE 32 308c1e15b49SDavid Howells spinlock_t rtt_input_lock; /* RTT lock for input routine */ 3090d4b103cSDavid Howells ktime_t rtt_last_req; /* Time of last RTT request */ 310cf1a6474SDavid Howells u64 rtt; /* Current RTT estimate (in nS) */ 311cf1a6474SDavid Howells u64 rtt_sum; /* Sum of cache contents */ 312cf1a6474SDavid Howells u64 rtt_cache[RXRPC_RTT_CACHE_SIZE]; /* Determined RTT cache */ 313cf1a6474SDavid Howells u8 rtt_cursor; /* next entry at which to insert */ 314cf1a6474SDavid Howells u8 rtt_usage; /* amount of cache actually used */ 315f7aec129SDavid Howells 316f7aec129SDavid Howells u8 cong_cwnd; /* Congestion window size */ 31717926a79SDavid Howells }; 31817926a79SDavid Howells 31917926a79SDavid Howells /* 32019ffa01cSDavid Howells * Keys for matching a connection. 32119ffa01cSDavid Howells */ 32219ffa01cSDavid Howells struct rxrpc_conn_proto { 323e8d70ce1SDavid Howells union { 324e8d70ce1SDavid Howells struct { 32519ffa01cSDavid Howells u32 epoch; /* epoch of this connection */ 32619ffa01cSDavid Howells u32 cid; /* connection ID */ 327e8d70ce1SDavid Howells }; 328e8d70ce1SDavid Howells u64 index_key; 32919ffa01cSDavid Howells }; 33019ffa01cSDavid Howells }; 33119ffa01cSDavid Howells 33219ffa01cSDavid Howells struct rxrpc_conn_parameters { 33319ffa01cSDavid Howells struct rxrpc_local *local; /* Representation of local endpoint */ 33419ffa01cSDavid Howells struct rxrpc_peer *peer; /* Remote endpoint */ 33519ffa01cSDavid Howells struct key *key; /* Security details */ 33619ffa01cSDavid Howells bool exclusive; /* T if conn is exclusive */ 3374e255721SDavid Howells bool upgrade; /* T if service ID can be upgraded */ 33819ffa01cSDavid Howells u16 service_id; /* Service ID for this connection */ 33919ffa01cSDavid Howells u32 security_level; /* Security level selected */ 34019ffa01cSDavid Howells }; 34119ffa01cSDavid Howells 34219ffa01cSDavid Howells /* 343bba304dbSDavid Howells * Bits in the connection flags. 344bba304dbSDavid Howells */ 345bba304dbSDavid Howells enum rxrpc_conn_flag { 346bba304dbSDavid Howells RXRPC_CONN_HAS_IDR, /* Has a client conn ID assigned */ 347001c1122SDavid Howells RXRPC_CONN_IN_SERVICE_CONNS, /* Conn is in peer->service_conns */ 348001c1122SDavid Howells RXRPC_CONN_IN_CLIENT_CONNS, /* Conn is in local->client_conns */ 34945025bceSDavid Howells RXRPC_CONN_EXPOSED, /* Conn has extra ref for exposure */ 35045025bceSDavid Howells RXRPC_CONN_DONT_REUSE, /* Don't reuse this connection */ 35145025bceSDavid Howells RXRPC_CONN_COUNTED, /* Counted by rxrpc_nr_client_conns */ 3524e255721SDavid Howells RXRPC_CONN_PROBING_FOR_UPGRADE, /* Probing for service upgrade */ 3533136ef49SDavid Howells RXRPC_CONN_FINAL_ACK_0, /* Need final ACK for channel 0 */ 3543136ef49SDavid Howells RXRPC_CONN_FINAL_ACK_1, /* Need final ACK for channel 1 */ 3553136ef49SDavid Howells RXRPC_CONN_FINAL_ACK_2, /* Need final ACK for channel 2 */ 3563136ef49SDavid Howells RXRPC_CONN_FINAL_ACK_3, /* Need final ACK for channel 3 */ 357bba304dbSDavid Howells }; 358bba304dbSDavid Howells 3593136ef49SDavid Howells #define RXRPC_CONN_FINAL_ACK_MASK ((1UL << RXRPC_CONN_FINAL_ACK_0) | \ 3603136ef49SDavid Howells (1UL << RXRPC_CONN_FINAL_ACK_1) | \ 3613136ef49SDavid Howells (1UL << RXRPC_CONN_FINAL_ACK_2) | \ 3623136ef49SDavid Howells (1UL << RXRPC_CONN_FINAL_ACK_3)) 3633136ef49SDavid Howells 364bba304dbSDavid Howells /* 365bba304dbSDavid Howells * Events that can be raised upon a connection. 366bba304dbSDavid Howells */ 367bba304dbSDavid Howells enum rxrpc_conn_event { 368bba304dbSDavid Howells RXRPC_CONN_EV_CHALLENGE, /* Send challenge packet */ 369bba304dbSDavid Howells }; 370bba304dbSDavid Howells 371bba304dbSDavid Howells /* 37245025bceSDavid Howells * The connection cache state. 37345025bceSDavid Howells */ 37445025bceSDavid Howells enum rxrpc_conn_cache_state { 37545025bceSDavid Howells RXRPC_CONN_CLIENT_INACTIVE, /* Conn is not yet listed */ 37645025bceSDavid Howells RXRPC_CONN_CLIENT_WAITING, /* Conn is on wait list, waiting for capacity */ 37745025bceSDavid Howells RXRPC_CONN_CLIENT_ACTIVE, /* Conn is on active list, doing calls */ 3784e255721SDavid Howells RXRPC_CONN_CLIENT_UPGRADE, /* Conn is on active list, probing for upgrade */ 37945025bceSDavid Howells RXRPC_CONN_CLIENT_CULLED, /* Conn is culled and delisted, doing calls */ 38045025bceSDavid Howells RXRPC_CONN_CLIENT_IDLE, /* Conn is on idle list, doing mostly nothing */ 381363deeabSDavid Howells RXRPC_CONN__NR_CACHE_STATES 38245025bceSDavid Howells }; 38345025bceSDavid Howells 38445025bceSDavid Howells /* 385bba304dbSDavid Howells * The connection protocol state. 386bba304dbSDavid Howells */ 387bba304dbSDavid Howells enum rxrpc_conn_proto_state { 388bba304dbSDavid Howells RXRPC_CONN_UNUSED, /* Connection not yet attempted */ 389bba304dbSDavid Howells RXRPC_CONN_CLIENT, /* Client connection */ 39000e90712SDavid Howells RXRPC_CONN_SERVICE_PREALLOC, /* Service connection preallocation */ 391bba304dbSDavid Howells RXRPC_CONN_SERVICE_UNSECURED, /* Service unsecured connection */ 392bba304dbSDavid Howells RXRPC_CONN_SERVICE_CHALLENGING, /* Service challenging for security */ 393bba304dbSDavid Howells RXRPC_CONN_SERVICE, /* Service secured connection */ 394bba304dbSDavid Howells RXRPC_CONN_REMOTELY_ABORTED, /* Conn aborted by peer */ 395bba304dbSDavid Howells RXRPC_CONN_LOCALLY_ABORTED, /* Conn aborted locally */ 396bba304dbSDavid Howells RXRPC_CONN__NR_STATES 397bba304dbSDavid Howells }; 398bba304dbSDavid Howells 399bba304dbSDavid Howells /* 40017926a79SDavid Howells * RxRPC connection definition 401aa390bbeSDavid Howells * - matched by { local, peer, epoch, conn_id, direction } 40217926a79SDavid Howells * - each connection can only handle four simultaneous calls 40317926a79SDavid Howells */ 40417926a79SDavid Howells struct rxrpc_connection { 40519ffa01cSDavid Howells struct rxrpc_conn_proto proto; 40619ffa01cSDavid Howells struct rxrpc_conn_parameters params; 40719ffa01cSDavid Howells 40845025bceSDavid Howells atomic_t usage; 40945025bceSDavid Howells struct rcu_head rcu; 41045025bceSDavid Howells struct list_head cache_link; 411a1399f8bSDavid Howells 41245025bceSDavid Howells spinlock_t channel_lock; 41345025bceSDavid Howells unsigned char active_chans; /* Mask of active channels */ 41445025bceSDavid Howells #define RXRPC_ACTIVE_CHANS_MASK ((1 << RXRPC_MAXCALLS) - 1) 41545025bceSDavid Howells struct list_head waiting_calls; /* Calls waiting for channels */ 416a1399f8bSDavid Howells struct rxrpc_channel { 4173136ef49SDavid Howells unsigned long final_ack_at; /* Time at which to issue final ACK */ 418a1399f8bSDavid Howells struct rxrpc_call __rcu *call; /* Active call */ 4194764c0daSDavid Howells unsigned int call_debug_id; /* call->debug_id */ 420a1399f8bSDavid Howells u32 call_id; /* ID of current call */ 421a1399f8bSDavid Howells u32 call_counter; /* Call ID counter */ 422a1399f8bSDavid Howells u32 last_call; /* ID of last call */ 42318bfeba5SDavid Howells u8 last_type; /* Type of last packet */ 42418bfeba5SDavid Howells union { 42518bfeba5SDavid Howells u32 last_seq; 42618bfeba5SDavid Howells u32 last_abort; 42718bfeba5SDavid Howells }; 428a1399f8bSDavid Howells } channels[RXRPC_MAXCALLS]; 429999b69f8SDavid Howells 4303136ef49SDavid Howells struct timer_list timer; /* Conn event timer */ 43117926a79SDavid Howells struct work_struct processor; /* connection event processor */ 432999b69f8SDavid Howells union { 433999b69f8SDavid Howells struct rb_node client_node; /* Node in local->client_conns */ 434aa390bbeSDavid Howells struct rb_node service_node; /* Node in peer->service_conns */ 435999b69f8SDavid Howells }; 4364d028b2cSDavid Howells struct list_head proc_link; /* link in procfs list */ 43717926a79SDavid Howells struct list_head link; /* link in master connection list */ 43817926a79SDavid Howells struct sk_buff_head rx_queue; /* received conn-level packets */ 439648af7fcSDavid Howells const struct rxrpc_security *security; /* applied security module */ 44017926a79SDavid Howells struct key *server_key; /* security for this service */ 44169d826faSKees Cook struct crypto_sync_skcipher *cipher; /* encryption handle */ 44217926a79SDavid Howells struct rxrpc_crypt csum_iv; /* packet checksum base */ 4434a3388c8SDavid Howells unsigned long flags; 44417926a79SDavid Howells unsigned long events; 445f51b4480SDavid Howells unsigned long idle_timestamp; /* Time at which last became idle */ 44617926a79SDavid Howells spinlock_t state_lock; /* state-change lock */ 447cf13258fSDavid Howells enum rxrpc_conn_cache_state cache_state; 448cf13258fSDavid Howells enum rxrpc_conn_proto_state state; /* current state of connection */ 44964753092SDavid Howells u32 abort_code; /* Abort code of connection abort */ 45017926a79SDavid Howells int debug_id; /* debug ID for printks */ 45117926a79SDavid Howells atomic_t serial; /* packet serial number counter */ 452563ea7d5SDavid Howells unsigned int hi_serial; /* highest serial number received */ 45317926a79SDavid Howells u32 security_nonce; /* response re-use preventer */ 454c1e15b49SDavid Howells u32 service_id; /* Service ID, possibly upgraded */ 4555a924b89SDavid Howells u8 size_align; /* data size alignment (for security) */ 4565a924b89SDavid Howells u8 security_size; /* security header size */ 45717926a79SDavid Howells u8 security_ix; /* security type */ 45817926a79SDavid Howells u8 out_clientflag; /* RXRPC_CLIENT_INITIATED if we are client */ 45964753092SDavid Howells short error; /* Local error code */ 46017926a79SDavid Howells }; 46117926a79SDavid Howells 462dc71db34SDavid Howells static inline bool rxrpc_to_server(const struct rxrpc_skb_priv *sp) 463dc71db34SDavid Howells { 464dc71db34SDavid Howells return sp->hdr.flags & RXRPC_CLIENT_INITIATED; 465dc71db34SDavid Howells } 466dc71db34SDavid Howells 467dc71db34SDavid Howells static inline bool rxrpc_to_client(const struct rxrpc_skb_priv *sp) 468dc71db34SDavid Howells { 469dc71db34SDavid Howells return !rxrpc_to_server(sp); 470dc71db34SDavid Howells } 471dc71db34SDavid Howells 47217926a79SDavid Howells /* 4735b8848d1SDavid Howells * Flags in call->flags. 4745b8848d1SDavid Howells */ 4755b8848d1SDavid Howells enum rxrpc_call_flag { 4765b8848d1SDavid Howells RXRPC_CALL_RELEASED, /* call has been released - no more message to userspace */ 4775b8848d1SDavid Howells RXRPC_CALL_HAS_USERID, /* has a user ID attached */ 478dabe5a79SDavid Howells RXRPC_CALL_IS_SERVICE, /* Call is service call */ 47945025bceSDavid Howells RXRPC_CALL_EXPOSED, /* The call was exposed to the world */ 480248f219cSDavid Howells RXRPC_CALL_RX_LAST, /* Received the last packet (at rxtx_top) */ 481248f219cSDavid Howells RXRPC_CALL_TX_LAST, /* Last packet in Tx buffer (at rxtx_top) */ 482a5af7e1fSDavid Howells RXRPC_CALL_SEND_PING, /* A ping will need to be sent */ 4838e83134dSDavid Howells RXRPC_CALL_PINGING, /* Ping in process */ 48457494343SDavid Howells RXRPC_CALL_RETRANS_TIMEOUT, /* Retransmission due to timeout occurred */ 485c54e43d7SDavid Howells RXRPC_CALL_BEGAN_RX_TIMER, /* We began the expect_rx_by timer */ 4861a025028SDavid Howells RXRPC_CALL_RX_HEARD, /* The peer responded at least once to this call */ 487d0b35a42SDavid Howells RXRPC_CALL_RX_UNDERRUN, /* Got data underrun */ 488b960a34bSDavid Howells RXRPC_CALL_IS_INTR, /* The call is interruptible */ 4895b8848d1SDavid Howells }; 4905b8848d1SDavid Howells 4915b8848d1SDavid Howells /* 4925b8848d1SDavid Howells * Events that can be raised on a call. 4935b8848d1SDavid Howells */ 4945b8848d1SDavid Howells enum rxrpc_call_event { 4954c198ad1SDavid Howells RXRPC_CALL_EV_ACK, /* need to generate ACK */ 4964c198ad1SDavid Howells RXRPC_CALL_EV_ABORT, /* need to generate abort */ 4974c198ad1SDavid Howells RXRPC_CALL_EV_RESEND, /* Tx resend required */ 498a5af7e1fSDavid Howells RXRPC_CALL_EV_PING, /* Ping send required */ 499a158bdd3SDavid Howells RXRPC_CALL_EV_EXPIRED, /* Expiry occurred */ 500bd1fdf8cSDavid Howells RXRPC_CALL_EV_ACK_LOST, /* ACK may be lost, send ping */ 5015b8848d1SDavid Howells }; 5025b8848d1SDavid Howells 5035b8848d1SDavid Howells /* 5045b8848d1SDavid Howells * The states that a call can be in. 5055b8848d1SDavid Howells */ 5065b8848d1SDavid Howells enum rxrpc_call_state { 507999b69f8SDavid Howells RXRPC_CALL_UNINITIALISED, 508999b69f8SDavid Howells RXRPC_CALL_CLIENT_AWAIT_CONN, /* - client waiting for connection to become available */ 5095b8848d1SDavid Howells RXRPC_CALL_CLIENT_SEND_REQUEST, /* - client sending request phase */ 5105b8848d1SDavid Howells RXRPC_CALL_CLIENT_AWAIT_REPLY, /* - client awaiting reply */ 5115b8848d1SDavid Howells RXRPC_CALL_CLIENT_RECV_REPLY, /* - client receiving reply phase */ 51200e90712SDavid Howells RXRPC_CALL_SERVER_PREALLOC, /* - service preallocation */ 5135b8848d1SDavid Howells RXRPC_CALL_SERVER_SECURING, /* - server securing request connection */ 5145b8848d1SDavid Howells RXRPC_CALL_SERVER_ACCEPTING, /* - server accepting request */ 5155b8848d1SDavid Howells RXRPC_CALL_SERVER_RECV_REQUEST, /* - server receiving request */ 5165b8848d1SDavid Howells RXRPC_CALL_SERVER_ACK_REQUEST, /* - server pending ACK of request */ 5175b8848d1SDavid Howells RXRPC_CALL_SERVER_SEND_REPLY, /* - server sending reply */ 5185b8848d1SDavid Howells RXRPC_CALL_SERVER_AWAIT_ACK, /* - server awaiting final ACK */ 519f5c17aaeSDavid Howells RXRPC_CALL_COMPLETE, /* - call complete */ 520f5c17aaeSDavid Howells NR__RXRPC_CALL_STATES 521f5c17aaeSDavid Howells }; 522f5c17aaeSDavid Howells 523f5c17aaeSDavid Howells /* 524e122d845SDavid Howells * Call completion condition (state == RXRPC_CALL_COMPLETE). 525e122d845SDavid Howells */ 526e122d845SDavid Howells enum rxrpc_call_completion { 527e122d845SDavid Howells RXRPC_CALL_SUCCEEDED, /* - Normal termination */ 528e122d845SDavid Howells RXRPC_CALL_REMOTELY_ABORTED, /* - call aborted by peer */ 529e122d845SDavid Howells RXRPC_CALL_LOCALLY_ABORTED, /* - call aborted locally on error or close */ 530e122d845SDavid Howells RXRPC_CALL_LOCAL_ERROR, /* - call failed due to local error */ 531e122d845SDavid Howells RXRPC_CALL_NETWORK_ERROR, /* - call terminated by network error */ 532e122d845SDavid Howells NR__RXRPC_CALL_COMPLETIONS 533e122d845SDavid Howells }; 534e122d845SDavid Howells 535e122d845SDavid Howells /* 53657494343SDavid Howells * Call Tx congestion management modes. 53757494343SDavid Howells */ 53857494343SDavid Howells enum rxrpc_congest_mode { 53957494343SDavid Howells RXRPC_CALL_SLOW_START, 54057494343SDavid Howells RXRPC_CALL_CONGEST_AVOIDANCE, 54157494343SDavid Howells RXRPC_CALL_PACKET_LOSS, 54257494343SDavid Howells RXRPC_CALL_FAST_RETRANSMIT, 54357494343SDavid Howells NR__RXRPC_CONGEST_MODES 54457494343SDavid Howells }; 54557494343SDavid Howells 54657494343SDavid Howells /* 54717926a79SDavid Howells * RxRPC call definition 54817926a79SDavid Howells * - matched by { connection, call_id } 54917926a79SDavid Howells */ 55017926a79SDavid Howells struct rxrpc_call { 551dee46364SDavid Howells struct rcu_head rcu; 55217926a79SDavid Howells struct rxrpc_connection *conn; /* connection carrying call */ 553df5d8bf7SDavid Howells struct rxrpc_peer *peer; /* Peer record for remote address */ 5548d94aa38SDavid Howells struct rxrpc_sock __rcu *socket; /* socket responsible */ 555d3be4d24SDavid Howells struct rxrpc_net *rxnet; /* Network namespace to which call belongs */ 556540b1c48SDavid Howells struct mutex user_mutex; /* User access mutex */ 557a158bdd3SDavid Howells unsigned long ack_at; /* When deferred ACK needs to happen */ 558bd1fdf8cSDavid Howells unsigned long ack_lost_at; /* When ACK is figured as lost */ 559a158bdd3SDavid Howells unsigned long resend_at; /* When next resend needs to happen */ 560a158bdd3SDavid Howells unsigned long ping_at; /* When next to send a ping */ 561415f44e4SDavid Howells unsigned long keepalive_at; /* When next to send a keepalive ping */ 562a158bdd3SDavid Howells unsigned long expect_rx_by; /* When we expect to get a packet by */ 563a158bdd3SDavid Howells unsigned long expect_req_by; /* When we expect to get a request DATA packet by */ 564a158bdd3SDavid Howells unsigned long expect_term_by; /* When we expect call termination by */ 565a158bdd3SDavid Howells u32 next_rx_timo; /* Timeout for next Rx packet (jif) */ 566a158bdd3SDavid Howells u32 next_req_timo; /* Timeout for next Rx request packet (jif) */ 567248f219cSDavid Howells struct timer_list timer; /* Combined event timer */ 568248f219cSDavid Howells struct work_struct processor; /* Event processor */ 569d001648eSDavid Howells rxrpc_notify_rx_t notify_rx; /* kernel service Rx notification function */ 57017926a79SDavid Howells struct list_head link; /* link in master call list */ 57145025bceSDavid Howells struct list_head chan_wait_link; /* Link in conn->waiting_calls */ 572f66d7490SDavid Howells struct hlist_node error_link; /* link in error distribution list */ 573248f219cSDavid Howells struct list_head accept_link; /* Link in rx->acceptq */ 574248f219cSDavid Howells struct list_head recvmsg_link; /* Link in rx->recvmsg_q */ 575248f219cSDavid Howells struct list_head sock_link; /* Link in rx->sock_calls */ 576248f219cSDavid Howells struct rb_node sock_node; /* Node in rx->calls */ 57717926a79SDavid Howells struct sk_buff *tx_pending; /* Tx socket buffer being filled */ 57845025bceSDavid Howells wait_queue_head_t waitq; /* Wait queue for channel or Tx */ 579e754eba6SDavid Howells s64 tx_total_len; /* Total length left to be transmitted (or -1) */ 580a263629dSHerbert Xu __be32 crypto_buf[2]; /* Temporary packet crypto buffer */ 58117926a79SDavid Howells unsigned long user_call_ID; /* user-defined call ID */ 58217926a79SDavid Howells unsigned long flags; 58317926a79SDavid Howells unsigned long events; 58417926a79SDavid Howells spinlock_t lock; 58520acbd9aSDavid Howells spinlock_t notify_lock; /* Kernel notification lock */ 58617926a79SDavid Howells rwlock_t state_lock; /* lock for state transition */ 587f5c17aaeSDavid Howells u32 abort_code; /* Local/remote abort code */ 588f5c17aaeSDavid Howells int error; /* Local error incurred */ 589cf13258fSDavid Howells enum rxrpc_call_state state; /* current state of call */ 590cf13258fSDavid Howells enum rxrpc_call_completion completion; /* Call completion condition */ 59117926a79SDavid Howells atomic_t usage; 592dabe5a79SDavid Howells u16 service_id; /* service ID */ 593278ac0cdSDavid Howells u8 security_ix; /* Security type */ 594dabe5a79SDavid Howells u32 call_id; /* call ID on connection */ 595dabe5a79SDavid Howells u32 cid; /* connection ID plus channel index */ 596dabe5a79SDavid Howells int debug_id; /* debug ID for printks */ 5978e83134dSDavid Howells unsigned short rx_pkt_offset; /* Current recvmsg packet offset */ 5988e83134dSDavid Howells unsigned short rx_pkt_len; /* Current recvmsg packet len */ 59917926a79SDavid Howells 600248f219cSDavid Howells /* Rx/Tx circular buffer, depending on phase. 601248f219cSDavid Howells * 602248f219cSDavid Howells * In the Rx phase, packets are annotated with 0 or the number of the 603248f219cSDavid Howells * segment of a jumbo packet each buffer refers to. There can be up to 604248f219cSDavid Howells * 47 segments in a maximum-size UDP packet. 605248f219cSDavid Howells * 606248f219cSDavid Howells * In the Tx phase, packets are annotated with which buffers have been 607248f219cSDavid Howells * acked. 60817926a79SDavid Howells */ 609248f219cSDavid Howells #define RXRPC_RXTX_BUFF_SIZE 64 610248f219cSDavid Howells #define RXRPC_RXTX_BUFF_MASK (RXRPC_RXTX_BUFF_SIZE - 1) 6114075295aSDavid Howells #define RXRPC_INIT_RX_WINDOW_SIZE 63 612248f219cSDavid Howells struct sk_buff **rxtx_buffer; 613248f219cSDavid Howells u8 *rxtx_annotations; 614248f219cSDavid Howells #define RXRPC_TX_ANNO_ACK 0 615248f219cSDavid Howells #define RXRPC_TX_ANNO_UNACK 1 616248f219cSDavid Howells #define RXRPC_TX_ANNO_NAK 2 617248f219cSDavid Howells #define RXRPC_TX_ANNO_RETRANS 3 618f07373eaSDavid Howells #define RXRPC_TX_ANNO_MASK 0x03 61970790dbeSDavid Howells #define RXRPC_TX_ANNO_LAST 0x04 62070790dbeSDavid Howells #define RXRPC_TX_ANNO_RESENT 0x08 62170790dbeSDavid Howells 622e2de6c40SDavid Howells #define RXRPC_RX_ANNO_SUBPACKET 0x3f /* Subpacket number in jumbogram */ 623248f219cSDavid Howells #define RXRPC_RX_ANNO_VERIFIED 0x80 /* Set if verified and decrypted */ 624248f219cSDavid Howells rxrpc_seq_t tx_hard_ack; /* Dead slot in buffer; the first transmitted but 625248f219cSDavid Howells * not hard-ACK'd packet follows this. 626248f219cSDavid Howells */ 627248f219cSDavid Howells rxrpc_seq_t tx_top; /* Highest Tx slot allocated. */ 628c7e86acfSDavid Howells u16 tx_backoff; /* Delay to insert due to Tx failure */ 62957494343SDavid Howells 63057494343SDavid Howells /* TCP-style slow-start congestion control [RFC5681]. Since the SMSS 63157494343SDavid Howells * is fixed, we keep these numbers in terms of segments (ie. DATA 63257494343SDavid Howells * packets) rather than bytes. 63357494343SDavid Howells */ 63457494343SDavid Howells #define RXRPC_TX_SMSS RXRPC_JUMBO_DATALEN 63557494343SDavid Howells u8 cong_cwnd; /* Congestion window size */ 63657494343SDavid Howells u8 cong_extra; /* Extra to send for congestion management */ 63757494343SDavid Howells u8 cong_ssthresh; /* Slow-start threshold */ 63857494343SDavid Howells enum rxrpc_congest_mode cong_mode:8; /* Congestion management mode */ 63957494343SDavid Howells u8 cong_dup_acks; /* Count of ACKs showing missing packets */ 64057494343SDavid Howells u8 cong_cumul_acks; /* Cumulative ACK count */ 64157494343SDavid Howells ktime_t cong_tstamp; /* Last time cwnd was changed */ 64257494343SDavid Howells 643248f219cSDavid Howells rxrpc_seq_t rx_hard_ack; /* Dead slot in buffer; the first received but not 644248f219cSDavid Howells * consumed packet follows this. 645248f219cSDavid Howells */ 646248f219cSDavid Howells rxrpc_seq_t rx_top; /* Highest Rx slot allocated. */ 647248f219cSDavid Howells rxrpc_seq_t rx_expect_next; /* Expected next packet sequence number */ 6481a025028SDavid Howells rxrpc_serial_t rx_serial; /* Highest serial received for this call */ 649248f219cSDavid Howells u8 rx_winsize; /* Size of Rx window */ 650248f219cSDavid Howells u8 tx_winsize; /* Maximum size of Tx window */ 65171f3ca40SDavid Howells bool tx_phase; /* T if transmission phase, F if receive phase */ 65275e42126SDavid Howells u8 nr_jumbo_bad; /* Number of jumbo dups/exceeds-windows */ 65317926a79SDavid Howells 654c1e15b49SDavid Howells spinlock_t input_lock; /* Lock for packet input to this call */ 655c1e15b49SDavid Howells 65617926a79SDavid Howells /* receive-phase ACK management */ 6574e36a95eSDavid Howells u8 ackr_reason; /* reason to ACK */ 6580d12f8a4SDavid Howells rxrpc_serial_t ackr_serial; /* serial of packet being ACK'd */ 6591a2391c3SJeffrey Altman rxrpc_serial_t ackr_first_seq; /* first sequence number received */ 660248f219cSDavid Howells rxrpc_seq_t ackr_prev_seq; /* previous sequence number received */ 661805b21b9SDavid Howells rxrpc_seq_t ackr_consumed; /* Highest packet shown consumed */ 662805b21b9SDavid Howells rxrpc_seq_t ackr_seen; /* Highest packet shown seen */ 663a5af7e1fSDavid Howells 664a5af7e1fSDavid Howells /* ping management */ 665a5af7e1fSDavid Howells rxrpc_serial_t ping_serial; /* Last ping sent */ 666a5af7e1fSDavid Howells ktime_t ping_time; /* Time last ping sent */ 66717926a79SDavid Howells 668248f219cSDavid Howells /* transmission-phase ACK management */ 66957494343SDavid Howells ktime_t acks_latest_ts; /* Timestamp of latest ACK received */ 670248f219cSDavid Howells rxrpc_serial_t acks_latest; /* serial number of latest ACK received */ 67131a1b989SDavid Howells rxrpc_seq_t acks_lowest_nak; /* Lowest NACK in the buffer (or ==tx_hard_ack) */ 672bd1fdf8cSDavid Howells rxrpc_seq_t acks_lost_top; /* tx_top at the time lost-ack ping sent */ 673bd1fdf8cSDavid Howells rxrpc_serial_t acks_lost_ping; /* Serial number of probe ACK */ 67431a1b989SDavid Howells }; 67531a1b989SDavid Howells 67631a1b989SDavid Howells /* 67757494343SDavid Howells * Summary of a new ACK and the changes it made to the Tx buffer packet states. 67831a1b989SDavid Howells */ 67931a1b989SDavid Howells struct rxrpc_ack_summary { 68031a1b989SDavid Howells u8 ack_reason; 68131a1b989SDavid Howells u8 nr_acks; /* Number of ACKs in packet */ 68231a1b989SDavid Howells u8 nr_nacks; /* Number of NACKs in packet */ 68331a1b989SDavid Howells u8 nr_new_acks; /* Number of new ACKs in packet */ 68431a1b989SDavid Howells u8 nr_new_nacks; /* Number of new NACKs in packet */ 68531a1b989SDavid Howells u8 nr_rot_new_acks; /* Number of rotated new ACKs */ 68631a1b989SDavid Howells bool new_low_nack; /* T if new low NACK found */ 68757494343SDavid Howells bool retrans_timeo; /* T if reTx due to timeout happened */ 68857494343SDavid Howells u8 flight_size; /* Number of unreceived transmissions */ 68957494343SDavid Howells /* Place to stash values for tracing */ 69057494343SDavid Howells enum rxrpc_congest_mode mode:8; 69157494343SDavid Howells u8 cwnd; 69257494343SDavid Howells u8 ssthresh; 69357494343SDavid Howells u8 dup_acks; 69457494343SDavid Howells u8 cumulative_acks; 69517926a79SDavid Howells }; 69617926a79SDavid Howells 69748124178SDavid Howells /* 69848124178SDavid Howells * sendmsg() cmsg-specified parameters. 69948124178SDavid Howells */ 70048124178SDavid Howells enum rxrpc_command { 70148124178SDavid Howells RXRPC_CMD_SEND_DATA, /* send data message */ 70248124178SDavid Howells RXRPC_CMD_SEND_ABORT, /* request abort generation */ 70348124178SDavid Howells RXRPC_CMD_ACCEPT, /* [server] accept incoming call */ 70448124178SDavid Howells RXRPC_CMD_REJECT_BUSY, /* [server] reject a call as busy */ 70548124178SDavid Howells }; 70648124178SDavid Howells 70748124178SDavid Howells struct rxrpc_call_params { 70848124178SDavid Howells s64 tx_total_len; /* Total Tx data length (if send data) */ 70948124178SDavid Howells unsigned long user_call_ID; /* User's call ID */ 71048124178SDavid Howells struct { 71148124178SDavid Howells u32 hard; /* Maximum lifetime (sec) */ 71248124178SDavid Howells u32 idle; /* Max time since last data packet (msec) */ 71348124178SDavid Howells u32 normal; /* Max time since last call packet (msec) */ 71448124178SDavid Howells } timeouts; 71548124178SDavid Howells u8 nr_timeouts; /* Number of timeouts specified */ 716b960a34bSDavid Howells bool intr; /* The call is interruptible */ 71748124178SDavid Howells }; 71848124178SDavid Howells 71948124178SDavid Howells struct rxrpc_send_params { 72048124178SDavid Howells struct rxrpc_call_params call; 72148124178SDavid Howells u32 abort_code; /* Abort code to Tx (if abort) */ 72248124178SDavid Howells enum rxrpc_command command : 8; /* The command to implement */ 72348124178SDavid Howells bool exclusive; /* Shared or exclusive call */ 72448124178SDavid Howells bool upgrade; /* If the connection is upgradeable */ 72548124178SDavid Howells }; 72648124178SDavid Howells 727df844fd4SDavid Howells #include <trace/events/rxrpc.h> 728df844fd4SDavid Howells 72917926a79SDavid Howells /* 730651350d1SDavid Howells * af_rxrpc.c 73117926a79SDavid Howells */ 73271f3ca40SDavid Howells extern atomic_t rxrpc_n_tx_skbs, rxrpc_n_rx_skbs; 733651350d1SDavid Howells extern struct workqueue_struct *rxrpc_workqueue; 73417926a79SDavid Howells 73517926a79SDavid Howells /* 7360d81a51aSDavid Howells * call_accept.c 73717926a79SDavid Howells */ 73800e90712SDavid Howells int rxrpc_service_prealloc(struct rxrpc_sock *, gfp_t); 73900e90712SDavid Howells void rxrpc_discard_prealloc(struct rxrpc_sock *); 740248f219cSDavid Howells struct rxrpc_call *rxrpc_new_incoming_call(struct rxrpc_local *, 7410099dc58SDavid Howells struct rxrpc_sock *, 742248f219cSDavid Howells struct sk_buff *); 7434f95dd78SDavid Howells void rxrpc_accept_incoming_calls(struct rxrpc_local *); 744d001648eSDavid Howells struct rxrpc_call *rxrpc_accept_call(struct rxrpc_sock *, unsigned long, 745d001648eSDavid Howells rxrpc_notify_rx_t); 746c1b1203dSJoe Perches int rxrpc_reject_call(struct rxrpc_sock *); 74717926a79SDavid Howells 74817926a79SDavid Howells /* 7490d81a51aSDavid Howells * call_event.c 75017926a79SDavid Howells */ 751e8c3af6bSDavid Howells void rxrpc_propose_ACK(struct rxrpc_call *, u8, u32, bool, bool, 7529c7ad434SDavid Howells enum rxrpc_propose_ack_trace); 753c1b1203dSJoe Perches void rxrpc_process_call(struct work_struct *); 75417926a79SDavid Howells 755a158bdd3SDavid Howells static inline void rxrpc_reduce_call_timer(struct rxrpc_call *call, 756a158bdd3SDavid Howells unsigned long expire_at, 757a158bdd3SDavid Howells unsigned long now, 758a158bdd3SDavid Howells enum rxrpc_timer_trace why) 759a158bdd3SDavid Howells { 760a158bdd3SDavid Howells trace_rxrpc_timer(call, why, now); 761a158bdd3SDavid Howells timer_reduce(&call->timer, expire_at); 762a158bdd3SDavid Howells } 763a158bdd3SDavid Howells 76417926a79SDavid Howells /* 7650d81a51aSDavid Howells * call_object.c 76617926a79SDavid Howells */ 767f5c17aaeSDavid Howells extern const char *const rxrpc_call_states[]; 768f5c17aaeSDavid Howells extern const char *const rxrpc_call_completions[]; 769dad8aff7SDavid Howells extern unsigned int rxrpc_max_call_lifetime; 77017926a79SDavid Howells extern struct kmem_cache *rxrpc_call_jar; 77117926a79SDavid Howells 7722341e077SDavid Howells struct rxrpc_call *rxrpc_find_call_by_user_ID(struct rxrpc_sock *, unsigned long); 773a25e21f0SDavid Howells struct rxrpc_call *rxrpc_alloc_call(struct rxrpc_sock *, gfp_t, unsigned int); 7742341e077SDavid Howells struct rxrpc_call *rxrpc_new_client_call(struct rxrpc_sock *, 77519ffa01cSDavid Howells struct rxrpc_conn_parameters *, 776999b69f8SDavid Howells struct sockaddr_rxrpc *, 777a25e21f0SDavid Howells struct rxrpc_call_params *, gfp_t, 778a25e21f0SDavid Howells unsigned int); 779248f219cSDavid Howells void rxrpc_incoming_call(struct rxrpc_sock *, struct rxrpc_call *, 78042886ffeSDavid Howells struct sk_buff *); 7818d94aa38SDavid Howells void rxrpc_release_call(struct rxrpc_sock *, struct rxrpc_call *); 782c1b1203dSJoe Perches void rxrpc_release_calls_on_socket(struct rxrpc_sock *); 7838d94aa38SDavid Howells bool __rxrpc_queue_call(struct rxrpc_call *); 7848d94aa38SDavid Howells bool rxrpc_queue_call(struct rxrpc_call *); 785e34d4234SDavid Howells void rxrpc_see_call(struct rxrpc_call *); 786fff72429SDavid Howells void rxrpc_get_call(struct rxrpc_call *, enum rxrpc_call_trace); 787fff72429SDavid Howells void rxrpc_put_call(struct rxrpc_call *, enum rxrpc_call_trace); 78800e90712SDavid Howells void rxrpc_cleanup_call(struct rxrpc_call *); 7892baec2c3SDavid Howells void rxrpc_destroy_all_calls(struct rxrpc_net *); 79017926a79SDavid Howells 791dabe5a79SDavid Howells static inline bool rxrpc_is_service_call(const struct rxrpc_call *call) 792dabe5a79SDavid Howells { 793dabe5a79SDavid Howells return test_bit(RXRPC_CALL_IS_SERVICE, &call->flags); 794dabe5a79SDavid Howells } 795dabe5a79SDavid Howells 796dabe5a79SDavid Howells static inline bool rxrpc_is_client_call(const struct rxrpc_call *call) 797dabe5a79SDavid Howells { 798dabe5a79SDavid Howells return !rxrpc_is_service_call(call); 799dabe5a79SDavid Howells } 800dabe5a79SDavid Howells 80117926a79SDavid Howells /* 802f5c17aaeSDavid Howells * Transition a call to the complete state. 803f5c17aaeSDavid Howells */ 804f5c17aaeSDavid Howells static inline bool __rxrpc_set_call_completion(struct rxrpc_call *call, 805f5c17aaeSDavid Howells enum rxrpc_call_completion compl, 806f5c17aaeSDavid Howells u32 abort_code, 807f5c17aaeSDavid Howells int error) 808f5c17aaeSDavid Howells { 809f5c17aaeSDavid Howells if (call->state < RXRPC_CALL_COMPLETE) { 810f5c17aaeSDavid Howells call->abort_code = abort_code; 811f5c17aaeSDavid Howells call->error = error; 812f5c17aaeSDavid Howells call->completion = compl, 813f5c17aaeSDavid Howells call->state = RXRPC_CALL_COMPLETE; 8141bae5d22SDavid Howells trace_rxrpc_call_complete(call); 815c0d058c2SDavid Howells wake_up(&call->waitq); 816f5c17aaeSDavid Howells return true; 817f5c17aaeSDavid Howells } 818f5c17aaeSDavid Howells return false; 819f5c17aaeSDavid Howells } 820f5c17aaeSDavid Howells 821f5c17aaeSDavid Howells static inline bool rxrpc_set_call_completion(struct rxrpc_call *call, 822f5c17aaeSDavid Howells enum rxrpc_call_completion compl, 823f5c17aaeSDavid Howells u32 abort_code, 824f5c17aaeSDavid Howells int error) 825f5c17aaeSDavid Howells { 826e8d6bbb0SDavid Howells bool ret; 827f5c17aaeSDavid Howells 828f5c17aaeSDavid Howells write_lock_bh(&call->state_lock); 829f5c17aaeSDavid Howells ret = __rxrpc_set_call_completion(call, compl, abort_code, error); 830f5c17aaeSDavid Howells write_unlock_bh(&call->state_lock); 831f5c17aaeSDavid Howells return ret; 832f5c17aaeSDavid Howells } 833f5c17aaeSDavid Howells 834f5c17aaeSDavid Howells /* 835f5c17aaeSDavid Howells * Record that a call successfully completed. 836f5c17aaeSDavid Howells */ 837e8d6bbb0SDavid Howells static inline bool __rxrpc_call_completed(struct rxrpc_call *call) 838f5c17aaeSDavid Howells { 839e8d6bbb0SDavid Howells return __rxrpc_set_call_completion(call, RXRPC_CALL_SUCCEEDED, 0, 0); 840f5c17aaeSDavid Howells } 841f5c17aaeSDavid Howells 842e8d6bbb0SDavid Howells static inline bool rxrpc_call_completed(struct rxrpc_call *call) 843f5c17aaeSDavid Howells { 844e8d6bbb0SDavid Howells bool ret; 845e8d6bbb0SDavid Howells 846f5c17aaeSDavid Howells write_lock_bh(&call->state_lock); 847e8d6bbb0SDavid Howells ret = __rxrpc_call_completed(call); 848f5c17aaeSDavid Howells write_unlock_bh(&call->state_lock); 849e8d6bbb0SDavid Howells return ret; 850f5c17aaeSDavid Howells } 851f5c17aaeSDavid Howells 852f5c17aaeSDavid Howells /* 853f5c17aaeSDavid Howells * Record that a call is locally aborted. 854f5c17aaeSDavid Howells */ 8555a42976dSDavid Howells static inline bool __rxrpc_abort_call(const char *why, struct rxrpc_call *call, 8565a42976dSDavid Howells rxrpc_seq_t seq, 857f5c17aaeSDavid Howells u32 abort_code, int error) 858f5c17aaeSDavid Howells { 859a25e21f0SDavid Howells trace_rxrpc_abort(call->debug_id, why, call->cid, call->call_id, seq, 8605a42976dSDavid Howells abort_code, error); 861248f219cSDavid Howells return __rxrpc_set_call_completion(call, RXRPC_CALL_LOCALLY_ABORTED, 862248f219cSDavid Howells abort_code, error); 863f5c17aaeSDavid Howells } 864f5c17aaeSDavid Howells 8655a42976dSDavid Howells static inline bool rxrpc_abort_call(const char *why, struct rxrpc_call *call, 8665a42976dSDavid Howells rxrpc_seq_t seq, u32 abort_code, int error) 867f5c17aaeSDavid Howells { 868f5c17aaeSDavid Howells bool ret; 869f5c17aaeSDavid Howells 870f5c17aaeSDavid Howells write_lock_bh(&call->state_lock); 8715a42976dSDavid Howells ret = __rxrpc_abort_call(why, call, seq, abort_code, error); 872f5c17aaeSDavid Howells write_unlock_bh(&call->state_lock); 873f5c17aaeSDavid Howells return ret; 874f5c17aaeSDavid Howells } 875f5c17aaeSDavid Howells 876f5c17aaeSDavid Howells /* 877fb46f6eeSDavid Howells * Abort a call due to a protocol error. 878fb46f6eeSDavid Howells */ 879fb46f6eeSDavid Howells static inline bool __rxrpc_abort_eproto(struct rxrpc_call *call, 880fb46f6eeSDavid Howells struct sk_buff *skb, 881fb46f6eeSDavid Howells const char *eproto_why, 882fb46f6eeSDavid Howells const char *why, 883fb46f6eeSDavid Howells u32 abort_code) 884fb46f6eeSDavid Howells { 885fb46f6eeSDavid Howells struct rxrpc_skb_priv *sp = rxrpc_skb(skb); 886fb46f6eeSDavid Howells 887fb46f6eeSDavid Howells trace_rxrpc_rx_eproto(call, sp->hdr.serial, eproto_why); 888fb46f6eeSDavid Howells return rxrpc_abort_call(why, call, sp->hdr.seq, abort_code, -EPROTO); 889fb46f6eeSDavid Howells } 890fb46f6eeSDavid Howells 891fb46f6eeSDavid Howells #define rxrpc_abort_eproto(call, skb, eproto_why, abort_why, abort_code) \ 892fb46f6eeSDavid Howells __rxrpc_abort_eproto((call), (skb), tracepoint_string(eproto_why), \ 893fb46f6eeSDavid Howells (abort_why), (abort_code)) 894fb46f6eeSDavid Howells 895fb46f6eeSDavid Howells /* 8964a3388c8SDavid Howells * conn_client.c 8974a3388c8SDavid Howells */ 89845025bceSDavid Howells extern unsigned int rxrpc_max_client_connections; 89945025bceSDavid Howells extern unsigned int rxrpc_reap_client_connections; 900a158bdd3SDavid Howells extern unsigned long rxrpc_conn_idle_client_expiry; 901a158bdd3SDavid Howells extern unsigned long rxrpc_conn_idle_client_fast_expiry; 9024a3388c8SDavid Howells extern struct idr rxrpc_client_conn_ids; 9034a3388c8SDavid Howells 904eb9b9d22SDavid Howells void rxrpc_destroy_client_conn_ids(void); 9055e33a23bSDavid Howells int rxrpc_connect_call(struct rxrpc_sock *, struct rxrpc_call *, 9065e33a23bSDavid Howells struct rxrpc_conn_parameters *, struct sockaddr_rxrpc *, 9075e33a23bSDavid Howells gfp_t); 90845025bceSDavid Howells void rxrpc_expose_client_call(struct rxrpc_call *); 90945025bceSDavid Howells void rxrpc_disconnect_client_call(struct rxrpc_call *); 91045025bceSDavid Howells void rxrpc_put_client_conn(struct rxrpc_connection *); 9112baec2c3SDavid Howells void rxrpc_discard_expired_client_conns(struct work_struct *); 9122baec2c3SDavid Howells void rxrpc_destroy_all_client_connections(struct rxrpc_net *); 913d12040b6SDavid Howells void rxrpc_clean_up_local_conns(struct rxrpc_local *); 9144a3388c8SDavid Howells 9154a3388c8SDavid Howells /* 9160d81a51aSDavid Howells * conn_event.c 9170d81a51aSDavid Howells */ 9180d81a51aSDavid Howells void rxrpc_process_connection(struct work_struct *); 9190d81a51aSDavid Howells 9200d81a51aSDavid Howells /* 9210d81a51aSDavid Howells * conn_object.c 92217926a79SDavid Howells */ 923dad8aff7SDavid Howells extern unsigned int rxrpc_connection_expiry; 924f859ab61SDavid Howells extern unsigned int rxrpc_closed_conn_expiry; 92517926a79SDavid Howells 926c6d2b8d7SDavid Howells struct rxrpc_connection *rxrpc_alloc_connection(gfp_t); 9278496af50SDavid Howells struct rxrpc_connection *rxrpc_find_connection_rcu(struct rxrpc_local *, 9280099dc58SDavid Howells struct sk_buff *, 9290099dc58SDavid Howells struct rxrpc_peer **); 93045025bceSDavid Howells void __rxrpc_disconnect_call(struct rxrpc_connection *, struct rxrpc_call *); 931999b69f8SDavid Howells void rxrpc_disconnect_call(struct rxrpc_call *); 93245025bceSDavid Howells void rxrpc_kill_connection(struct rxrpc_connection *); 933363deeabSDavid Howells bool rxrpc_queue_conn(struct rxrpc_connection *); 934363deeabSDavid Howells void rxrpc_see_connection(struct rxrpc_connection *); 935363deeabSDavid Howells void rxrpc_get_connection(struct rxrpc_connection *); 936363deeabSDavid Howells struct rxrpc_connection *rxrpc_get_connection_maybe(struct rxrpc_connection *); 937363deeabSDavid Howells void rxrpc_put_service_conn(struct rxrpc_connection *); 9382baec2c3SDavid Howells void rxrpc_service_connection_reaper(struct work_struct *); 9392baec2c3SDavid Howells void rxrpc_destroy_all_connections(struct rxrpc_net *); 94017926a79SDavid Howells 94119ffa01cSDavid Howells static inline bool rxrpc_conn_is_client(const struct rxrpc_connection *conn) 94219ffa01cSDavid Howells { 94319ffa01cSDavid Howells return conn->out_clientflag; 94419ffa01cSDavid Howells } 94519ffa01cSDavid Howells 94619ffa01cSDavid Howells static inline bool rxrpc_conn_is_service(const struct rxrpc_connection *conn) 94719ffa01cSDavid Howells { 948e8d70ce1SDavid Howells return !rxrpc_conn_is_client(conn); 94919ffa01cSDavid Howells } 95019ffa01cSDavid Howells 951f51b4480SDavid Howells static inline void rxrpc_put_connection(struct rxrpc_connection *conn) 952f51b4480SDavid Howells { 95345025bceSDavid Howells if (!conn) 95445025bceSDavid Howells return; 95545025bceSDavid Howells 956363deeabSDavid Howells if (rxrpc_conn_is_client(conn)) 95745025bceSDavid Howells rxrpc_put_client_conn(conn); 958363deeabSDavid Howells else 959363deeabSDavid Howells rxrpc_put_service_conn(conn); 9605acbee46SDavid Howells } 9615acbee46SDavid Howells 9623136ef49SDavid Howells static inline void rxrpc_reduce_conn_timer(struct rxrpc_connection *conn, 9633136ef49SDavid Howells unsigned long expire_at) 9643136ef49SDavid Howells { 9653136ef49SDavid Howells timer_reduce(&conn->timer, expire_at); 9663136ef49SDavid Howells } 9673136ef49SDavid Howells 96817926a79SDavid Howells /* 9697877a4a4SDavid Howells * conn_service.c 9707877a4a4SDavid Howells */ 9718496af50SDavid Howells struct rxrpc_connection *rxrpc_find_service_conn_rcu(struct rxrpc_peer *, 9728496af50SDavid Howells struct sk_buff *); 9732baec2c3SDavid Howells struct rxrpc_connection *rxrpc_prealloc_service_connection(struct rxrpc_net *, gfp_t); 9744722974dSDavid Howells void rxrpc_new_incoming_connection(struct rxrpc_sock *, 9754722974dSDavid Howells struct rxrpc_connection *, struct sk_buff *); 976001c1122SDavid Howells void rxrpc_unpublish_service_conn(struct rxrpc_connection *); 9777877a4a4SDavid Howells 9787877a4a4SDavid Howells /* 9790d81a51aSDavid Howells * input.c 98017926a79SDavid Howells */ 9815271953cSDavid Howells int rxrpc_input_packet(struct sock *, struct sk_buff *); 98217926a79SDavid Howells 98317926a79SDavid Howells /* 9840d81a51aSDavid Howells * insecure.c 98517926a79SDavid Howells */ 9860d81a51aSDavid Howells extern const struct rxrpc_security rxrpc_no_security; 98717926a79SDavid Howells 98817926a79SDavid Howells /* 9890d81a51aSDavid Howells * key.c 99017926a79SDavid Howells */ 99117926a79SDavid Howells extern struct key_type key_type_rxrpc; 99217926a79SDavid Howells extern struct key_type key_type_rxrpc_s; 99317926a79SDavid Howells 994c1b1203dSJoe Perches int rxrpc_request_key(struct rxrpc_sock *, char __user *, int); 995c1b1203dSJoe Perches int rxrpc_server_keyring(struct rxrpc_sock *, char __user *, int); 99610674a03SBaolin Wang int rxrpc_get_server_data_key(struct rxrpc_connection *, const void *, time64_t, 997c1b1203dSJoe Perches u32); 99817926a79SDavid Howells 99917926a79SDavid Howells /* 100087563616SDavid Howells * local_event.c 100187563616SDavid Howells */ 10024f95dd78SDavid Howells extern void rxrpc_process_local_events(struct rxrpc_local *); 100387563616SDavid Howells 100487563616SDavid Howells /* 10050d81a51aSDavid Howells * local_object.c 100617926a79SDavid Howells */ 10072baec2c3SDavid Howells struct rxrpc_local *rxrpc_lookup_local(struct net *, const struct sockaddr_rxrpc *); 100809d2bf59SDavid Howells struct rxrpc_local *rxrpc_get_local(struct rxrpc_local *); 100909d2bf59SDavid Howells struct rxrpc_local *rxrpc_get_local_maybe(struct rxrpc_local *); 101009d2bf59SDavid Howells void rxrpc_put_local(struct rxrpc_local *); 1011730c5fd4SDavid Howells struct rxrpc_local *rxrpc_use_local(struct rxrpc_local *); 1012730c5fd4SDavid Howells void rxrpc_unuse_local(struct rxrpc_local *); 101309d2bf59SDavid Howells void rxrpc_queue_local(struct rxrpc_local *); 10142baec2c3SDavid Howells void rxrpc_destroy_all_locals(struct rxrpc_net *); 1015e0e4d82fSDavid Howells 1016e0e4d82fSDavid Howells /* 10178e688d9cSDavid Howells * misc.c 10188e688d9cSDavid Howells */ 10190e119b41SDavid Howells extern unsigned int rxrpc_max_backlog __read_mostly; 1020a158bdd3SDavid Howells extern unsigned long rxrpc_requested_ack_delay; 1021a158bdd3SDavid Howells extern unsigned long rxrpc_soft_ack_delay; 1022a158bdd3SDavid Howells extern unsigned long rxrpc_idle_ack_delay; 10238e688d9cSDavid Howells extern unsigned int rxrpc_rx_window_size; 10248e688d9cSDavid Howells extern unsigned int rxrpc_rx_mtu; 10258e688d9cSDavid Howells extern unsigned int rxrpc_rx_jumbo_max; 1026a158bdd3SDavid Howells extern unsigned long rxrpc_resend_timeout; 10278e688d9cSDavid Howells 10288e688d9cSDavid Howells extern const s8 rxrpc_ack_priority[]; 10298e688d9cSDavid Howells 10308e688d9cSDavid Howells /* 10312baec2c3SDavid Howells * net_ns.c 10322baec2c3SDavid Howells */ 10332baec2c3SDavid Howells extern unsigned int rxrpc_net_id; 10342baec2c3SDavid Howells extern struct pernet_operations rxrpc_net_ops; 10352baec2c3SDavid Howells 10362baec2c3SDavid Howells static inline struct rxrpc_net *rxrpc_net(struct net *net) 10372baec2c3SDavid Howells { 10382baec2c3SDavid Howells return net_generic(net, rxrpc_net_id); 10392baec2c3SDavid Howells } 10402baec2c3SDavid Howells 10412baec2c3SDavid Howells /* 10420d81a51aSDavid Howells * output.c 10430d81a51aSDavid Howells */ 1044bd1fdf8cSDavid Howells int rxrpc_send_ack_packet(struct rxrpc_call *, bool, rxrpc_serial_t *); 104526cb02aaSDavid Howells int rxrpc_send_abort_packet(struct rxrpc_call *); 1046a1767077SDavid Howells int rxrpc_send_data_packet(struct rxrpc_call *, struct sk_buff *, bool); 1047248f219cSDavid Howells void rxrpc_reject_packets(struct rxrpc_local *); 1048ace45becSDavid Howells void rxrpc_send_keepalive(struct rxrpc_peer *); 10490d81a51aSDavid Howells 10500d81a51aSDavid Howells /* 1051abe89ef0SDavid Howells * peer_event.c 10520d81a51aSDavid Howells */ 1053abe89ef0SDavid Howells void rxrpc_error_report(struct sock *); 1054cf1a6474SDavid Howells void rxrpc_peer_add_rtt(struct rxrpc_call *, enum rxrpc_rtt_rx_trace, 1055cf1a6474SDavid Howells rxrpc_serial_t, rxrpc_serial_t, ktime_t, ktime_t); 1056ace45becSDavid Howells void rxrpc_peer_keepalive_worker(struct work_struct *); 10570d81a51aSDavid Howells 10580d81a51aSDavid Howells /* 10590d81a51aSDavid Howells * peer_object.c 10600d81a51aSDavid Howells */ 1061be6e6707SDavid Howells struct rxrpc_peer *rxrpc_lookup_peer_rcu(struct rxrpc_local *, 1062be6e6707SDavid Howells const struct sockaddr_rxrpc *); 10635e33a23bSDavid Howells struct rxrpc_peer *rxrpc_lookup_peer(struct rxrpc_sock *, struct rxrpc_local *, 1064be6e6707SDavid Howells struct sockaddr_rxrpc *, gfp_t); 1065be6e6707SDavid Howells struct rxrpc_peer *rxrpc_alloc_peer(struct rxrpc_local *, gfp_t); 10665e33a23bSDavid Howells void rxrpc_new_incoming_peer(struct rxrpc_sock *, struct rxrpc_local *, 10675e33a23bSDavid Howells struct rxrpc_peer *); 106817226f12SDavid Howells void rxrpc_destroy_all_peers(struct rxrpc_net *); 10691159d4b4SDavid Howells struct rxrpc_peer *rxrpc_get_peer(struct rxrpc_peer *); 10701159d4b4SDavid Howells struct rxrpc_peer *rxrpc_get_peer_maybe(struct rxrpc_peer *); 10711159d4b4SDavid Howells void rxrpc_put_peer(struct rxrpc_peer *); 107260034d3dSDavid Howells void rxrpc_put_peer_locked(struct rxrpc_peer *); 10730d81a51aSDavid Howells 10740d81a51aSDavid Howells /* 10750d81a51aSDavid Howells * proc.c 10760d81a51aSDavid Howells */ 1077c3506372SChristoph Hellwig extern const struct seq_operations rxrpc_call_seq_ops; 1078c3506372SChristoph Hellwig extern const struct seq_operations rxrpc_connection_seq_ops; 1079bc0e7cf4SDavid Howells extern const struct seq_operations rxrpc_peer_seq_ops; 10800d81a51aSDavid Howells 10810d81a51aSDavid Howells /* 10820d81a51aSDavid Howells * recvmsg.c 10830d81a51aSDavid Howells */ 1084248f219cSDavid Howells void rxrpc_notify_socket(struct rxrpc_call *); 10850d81a51aSDavid Howells int rxrpc_recvmsg(struct socket *, struct msghdr *, size_t, int); 10860d81a51aSDavid Howells 10870d81a51aSDavid Howells /* 1088648af7fcSDavid Howells * rxkad.c 1089648af7fcSDavid Howells */ 1090648af7fcSDavid Howells #ifdef CONFIG_RXKAD 1091648af7fcSDavid Howells extern const struct rxrpc_security rxkad; 1092648af7fcSDavid Howells #endif 1093648af7fcSDavid Howells 1094648af7fcSDavid Howells /* 10950d81a51aSDavid Howells * security.c 10960d81a51aSDavid Howells */ 10970d81a51aSDavid Howells int __init rxrpc_init_security(void); 10980d81a51aSDavid Howells void rxrpc_exit_security(void); 10990d81a51aSDavid Howells int rxrpc_init_client_conn_security(struct rxrpc_connection *); 11000d81a51aSDavid Howells int rxrpc_init_server_conn_security(struct rxrpc_connection *); 11010d81a51aSDavid Howells 11020d81a51aSDavid Howells /* 11030b58b8a1SDavid Howells * sendmsg.c 11040b58b8a1SDavid Howells */ 11050b58b8a1SDavid Howells int rxrpc_do_sendmsg(struct rxrpc_sock *, struct msghdr *, size_t); 11060b58b8a1SDavid Howells 11070b58b8a1SDavid Howells /* 11080d81a51aSDavid Howells * skbuff.c 11090d81a51aSDavid Howells */ 1110d001648eSDavid Howells void rxrpc_kernel_data_consumed(struct rxrpc_call *, struct sk_buff *); 11110d81a51aSDavid Howells void rxrpc_packet_destructor(struct sk_buff *); 111271f3ca40SDavid Howells void rxrpc_new_skb(struct sk_buff *, enum rxrpc_skb_trace); 111371f3ca40SDavid Howells void rxrpc_see_skb(struct sk_buff *, enum rxrpc_skb_trace); 1114d0d5c0cdSDavid Howells void rxrpc_eaten_skb(struct sk_buff *, enum rxrpc_skb_trace); 111571f3ca40SDavid Howells void rxrpc_get_skb(struct sk_buff *, enum rxrpc_skb_trace); 111671f3ca40SDavid Howells void rxrpc_free_skb(struct sk_buff *, enum rxrpc_skb_trace); 1117df844fd4SDavid Howells void rxrpc_purge_queue(struct sk_buff_head *); 11180d81a51aSDavid Howells 11190d81a51aSDavid Howells /* 11205873c083SDavid Howells * sysctl.c 11215873c083SDavid Howells */ 11225873c083SDavid Howells #ifdef CONFIG_SYSCTL 11235873c083SDavid Howells extern int __init rxrpc_sysctl_init(void); 11245873c083SDavid Howells extern void rxrpc_sysctl_exit(void); 11255873c083SDavid Howells #else 11265873c083SDavid Howells static inline int __init rxrpc_sysctl_init(void) { return 0; } 11275873c083SDavid Howells static inline void rxrpc_sysctl_exit(void) {} 11285873c083SDavid Howells #endif 11295873c083SDavid Howells 11305873c083SDavid Howells /* 1131be6e6707SDavid Howells * utils.c 1132be6e6707SDavid Howells */ 11335a790b73SDavid Howells int rxrpc_extract_addr_from_skb(struct sockaddr_rxrpc *, struct sk_buff *); 1134be6e6707SDavid Howells 1135248f219cSDavid Howells static inline bool before(u32 seq1, u32 seq2) 1136248f219cSDavid Howells { 1137248f219cSDavid Howells return (s32)(seq1 - seq2) < 0; 1138248f219cSDavid Howells } 1139248f219cSDavid Howells static inline bool before_eq(u32 seq1, u32 seq2) 1140248f219cSDavid Howells { 1141248f219cSDavid Howells return (s32)(seq1 - seq2) <= 0; 1142248f219cSDavid Howells } 1143248f219cSDavid Howells static inline bool after(u32 seq1, u32 seq2) 1144248f219cSDavid Howells { 1145248f219cSDavid Howells return (s32)(seq1 - seq2) > 0; 1146248f219cSDavid Howells } 1147248f219cSDavid Howells static inline bool after_eq(u32 seq1, u32 seq2) 1148248f219cSDavid Howells { 1149248f219cSDavid Howells return (s32)(seq1 - seq2) >= 0; 1150248f219cSDavid Howells } 1151248f219cSDavid Howells 1152be6e6707SDavid Howells /* 115317926a79SDavid Howells * debug tracing 115417926a79SDavid Howells */ 115595c96174SEric Dumazet extern unsigned int rxrpc_debug; 115617926a79SDavid Howells 115717926a79SDavid Howells #define dbgprintk(FMT,...) \ 11589f389f4bSSven Schnelle printk("[%-6.6s] "FMT"\n", current->comm ,##__VA_ARGS__) 115917926a79SDavid Howells 11600dc47877SHarvey Harrison #define kenter(FMT,...) dbgprintk("==> %s("FMT")",__func__ ,##__VA_ARGS__) 11610dc47877SHarvey Harrison #define kleave(FMT,...) dbgprintk("<== %s()"FMT"",__func__ ,##__VA_ARGS__) 116217926a79SDavid Howells #define kdebug(FMT,...) dbgprintk(" "FMT ,##__VA_ARGS__) 116317926a79SDavid Howells #define kproto(FMT,...) dbgprintk("### "FMT ,##__VA_ARGS__) 116417926a79SDavid Howells #define knet(FMT,...) dbgprintk("@@@ "FMT ,##__VA_ARGS__) 116517926a79SDavid Howells 116617926a79SDavid Howells 116717926a79SDavid Howells #if defined(__KDEBUG) 116817926a79SDavid Howells #define _enter(FMT,...) kenter(FMT,##__VA_ARGS__) 116917926a79SDavid Howells #define _leave(FMT,...) kleave(FMT,##__VA_ARGS__) 117017926a79SDavid Howells #define _debug(FMT,...) kdebug(FMT,##__VA_ARGS__) 117117926a79SDavid Howells #define _proto(FMT,...) kproto(FMT,##__VA_ARGS__) 117217926a79SDavid Howells #define _net(FMT,...) knet(FMT,##__VA_ARGS__) 117317926a79SDavid Howells 117417926a79SDavid Howells #elif defined(CONFIG_AF_RXRPC_DEBUG) 117517926a79SDavid Howells #define RXRPC_DEBUG_KENTER 0x01 117617926a79SDavid Howells #define RXRPC_DEBUG_KLEAVE 0x02 117717926a79SDavid Howells #define RXRPC_DEBUG_KDEBUG 0x04 117817926a79SDavid Howells #define RXRPC_DEBUG_KPROTO 0x08 117917926a79SDavid Howells #define RXRPC_DEBUG_KNET 0x10 118017926a79SDavid Howells 118117926a79SDavid Howells #define _enter(FMT,...) \ 118217926a79SDavid Howells do { \ 118317926a79SDavid Howells if (unlikely(rxrpc_debug & RXRPC_DEBUG_KENTER)) \ 118417926a79SDavid Howells kenter(FMT,##__VA_ARGS__); \ 118517926a79SDavid Howells } while (0) 118617926a79SDavid Howells 118717926a79SDavid Howells #define _leave(FMT,...) \ 118817926a79SDavid Howells do { \ 118917926a79SDavid Howells if (unlikely(rxrpc_debug & RXRPC_DEBUG_KLEAVE)) \ 119017926a79SDavid Howells kleave(FMT,##__VA_ARGS__); \ 119117926a79SDavid Howells } while (0) 119217926a79SDavid Howells 119317926a79SDavid Howells #define _debug(FMT,...) \ 119417926a79SDavid Howells do { \ 119517926a79SDavid Howells if (unlikely(rxrpc_debug & RXRPC_DEBUG_KDEBUG)) \ 119617926a79SDavid Howells kdebug(FMT,##__VA_ARGS__); \ 119717926a79SDavid Howells } while (0) 119817926a79SDavid Howells 119917926a79SDavid Howells #define _proto(FMT,...) \ 120017926a79SDavid Howells do { \ 120117926a79SDavid Howells if (unlikely(rxrpc_debug & RXRPC_DEBUG_KPROTO)) \ 120217926a79SDavid Howells kproto(FMT,##__VA_ARGS__); \ 120317926a79SDavid Howells } while (0) 120417926a79SDavid Howells 120517926a79SDavid Howells #define _net(FMT,...) \ 120617926a79SDavid Howells do { \ 120717926a79SDavid Howells if (unlikely(rxrpc_debug & RXRPC_DEBUG_KNET)) \ 120817926a79SDavid Howells knet(FMT,##__VA_ARGS__); \ 120917926a79SDavid Howells } while (0) 121017926a79SDavid Howells 121117926a79SDavid Howells #else 121212fdff3fSDavid Howells #define _enter(FMT,...) no_printk("==> %s("FMT")",__func__ ,##__VA_ARGS__) 121312fdff3fSDavid Howells #define _leave(FMT,...) no_printk("<== %s()"FMT"",__func__ ,##__VA_ARGS__) 121412fdff3fSDavid Howells #define _debug(FMT,...) no_printk(" "FMT ,##__VA_ARGS__) 121512fdff3fSDavid Howells #define _proto(FMT,...) no_printk("### "FMT ,##__VA_ARGS__) 121612fdff3fSDavid Howells #define _net(FMT,...) no_printk("@@@ "FMT ,##__VA_ARGS__) 121717926a79SDavid Howells #endif 121817926a79SDavid Howells 121917926a79SDavid Howells /* 122017926a79SDavid Howells * debug assertion checking 122117926a79SDavid Howells */ 122217926a79SDavid Howells #if 1 // defined(__KDEBUGALL) 122317926a79SDavid Howells 122417926a79SDavid Howells #define ASSERT(X) \ 122517926a79SDavid Howells do { \ 122617926a79SDavid Howells if (unlikely(!(X))) { \ 12279b6d5398SJoe Perches pr_err("Assertion failed\n"); \ 122817926a79SDavid Howells BUG(); \ 122917926a79SDavid Howells } \ 123017926a79SDavid Howells } while (0) 123117926a79SDavid Howells 123217926a79SDavid Howells #define ASSERTCMP(X, OP, Y) \ 123317926a79SDavid Howells do { \ 1234cf13258fSDavid Howells __typeof__(X) _x = (X); \ 1235cf13258fSDavid Howells __typeof__(Y) _y = (__typeof__(X))(Y); \ 12369b6d5398SJoe Perches if (unlikely(!(_x OP _y))) { \ 12379b6d5398SJoe Perches pr_err("Assertion failed - %lu(0x%lx) %s %lu(0x%lx) is false\n", \ 1238cf13258fSDavid Howells (unsigned long)_x, (unsigned long)_x, #OP, \ 1239cf13258fSDavid Howells (unsigned long)_y, (unsigned long)_y); \ 124017926a79SDavid Howells BUG(); \ 124117926a79SDavid Howells } \ 124217926a79SDavid Howells } while (0) 124317926a79SDavid Howells 124417926a79SDavid Howells #define ASSERTIF(C, X) \ 124517926a79SDavid Howells do { \ 124617926a79SDavid Howells if (unlikely((C) && !(X))) { \ 12479b6d5398SJoe Perches pr_err("Assertion failed\n"); \ 124817926a79SDavid Howells BUG(); \ 124917926a79SDavid Howells } \ 125017926a79SDavid Howells } while (0) 125117926a79SDavid Howells 125217926a79SDavid Howells #define ASSERTIFCMP(C, X, OP, Y) \ 125317926a79SDavid Howells do { \ 1254cf13258fSDavid Howells __typeof__(X) _x = (X); \ 1255cf13258fSDavid Howells __typeof__(Y) _y = (__typeof__(X))(Y); \ 12569b6d5398SJoe Perches if (unlikely((C) && !(_x OP _y))) { \ 12579b6d5398SJoe Perches pr_err("Assertion failed - %lu(0x%lx) %s %lu(0x%lx) is false\n", \ 1258cf13258fSDavid Howells (unsigned long)_x, (unsigned long)_x, #OP, \ 1259cf13258fSDavid Howells (unsigned long)_y, (unsigned long)_y); \ 126017926a79SDavid Howells BUG(); \ 126117926a79SDavid Howells } \ 126217926a79SDavid Howells } while (0) 126317926a79SDavid Howells 126417926a79SDavid Howells #else 126517926a79SDavid Howells 126617926a79SDavid Howells #define ASSERT(X) \ 126717926a79SDavid Howells do { \ 126817926a79SDavid Howells } while (0) 126917926a79SDavid Howells 127017926a79SDavid Howells #define ASSERTCMP(X, OP, Y) \ 127117926a79SDavid Howells do { \ 127217926a79SDavid Howells } while (0) 127317926a79SDavid Howells 127417926a79SDavid Howells #define ASSERTIF(C, X) \ 127517926a79SDavid Howells do { \ 127617926a79SDavid Howells } while (0) 127717926a79SDavid Howells 127817926a79SDavid Howells #define ASSERTIFCMP(C, X, OP, Y) \ 127917926a79SDavid Howells do { \ 128017926a79SDavid Howells } while (0) 128117926a79SDavid Howells 128217926a79SDavid Howells #endif /* __KDEBUGALL */ 1283