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 { 39ece64fecSDavid Howells RXRPC_SKB_MARK_REJECT_BUSY, /* Reject with BUSY */ 40ece64fecSDavid Howells RXRPC_SKB_MARK_REJECT_ABORT, /* Reject with ABORT (code in skb->priority) */ 41d001648eSDavid Howells }; 42d001648eSDavid Howells 43d001648eSDavid Howells /* 4417926a79SDavid Howells * sk_state for RxRPC sockets 4517926a79SDavid Howells */ 4617926a79SDavid Howells enum { 472341e077SDavid Howells RXRPC_UNBOUND = 0, 482341e077SDavid Howells RXRPC_CLIENT_UNBOUND, /* Unbound socket used as client */ 4917926a79SDavid Howells RXRPC_CLIENT_BOUND, /* client local address bound */ 5017926a79SDavid Howells RXRPC_SERVER_BOUND, /* server local address bound */ 5128036f44SDavid Howells RXRPC_SERVER_BOUND2, /* second server local address bound */ 5217926a79SDavid Howells RXRPC_SERVER_LISTENING, /* server listening for connections */ 53210f0353SDavid Howells RXRPC_SERVER_LISTEN_DISABLED, /* server listening disabled */ 5417926a79SDavid Howells RXRPC_CLOSE, /* socket is being closed */ 5517926a79SDavid Howells }; 5617926a79SDavid Howells 5717926a79SDavid Howells /* 582baec2c3SDavid Howells * Per-network namespace data. 592baec2c3SDavid Howells */ 602baec2c3SDavid Howells struct rxrpc_net { 612baec2c3SDavid Howells struct proc_dir_entry *proc_net; /* Subdir in /proc/net */ 622baec2c3SDavid Howells u32 epoch; /* Local epoch for detecting local-end reset */ 632baec2c3SDavid Howells struct list_head calls; /* List of calls active in this namespace */ 64ad25f5cbSDavid Howells spinlock_t call_lock; /* Lock for ->calls */ 65d3be4d24SDavid Howells atomic_t nr_calls; /* Count of allocated calls */ 662baec2c3SDavid Howells 6731f5f9a1SDavid Howells atomic_t nr_conns; 682baec2c3SDavid Howells struct list_head conn_proc_list; /* List of conns in this namespace for proc */ 692baec2c3SDavid Howells struct list_head service_conns; /* Service conns in this namespace */ 702baec2c3SDavid Howells rwlock_t conn_lock; /* Lock for ->conn_proc_list, ->service_conns */ 713d18cbb7SDavid Howells struct work_struct service_conn_reaper; 723d18cbb7SDavid Howells struct timer_list service_conn_reap_timer; 732baec2c3SDavid Howells 74f859ab61SDavid Howells bool live; 75245500d8SDavid Howells 76245500d8SDavid Howells bool kill_all_client_conns; 77245500d8SDavid Howells atomic_t nr_client_conns; 782baec2c3SDavid Howells spinlock_t client_conn_cache_lock; /* Lock for ->*_client_conns */ 792baec2c3SDavid Howells spinlock_t client_conn_discard_lock; /* Prevent multiple discarders */ 802baec2c3SDavid Howells struct list_head idle_client_conns; 813d18cbb7SDavid Howells struct work_struct client_conn_reaper; 823d18cbb7SDavid Howells struct timer_list client_conn_reap_timer; 832baec2c3SDavid Howells 8433912c26SDavid Howells struct hlist_head local_endpoints; 852baec2c3SDavid Howells struct mutex local_mutex; /* Lock for ->local_endpoints */ 862baec2c3SDavid Howells 872baec2c3SDavid Howells DECLARE_HASHTABLE (peer_hash, 10); 88ace45becSDavid Howells spinlock_t peer_hash_lock; /* Lock for ->peer_hash */ 89ace45becSDavid Howells 90ace45becSDavid Howells #define RXRPC_KEEPALIVE_TIME 20 /* NAT keepalive time in seconds */ 91ace45becSDavid Howells u8 peer_keepalive_cursor; 92330bdcfaSDavid Howells time64_t peer_keepalive_base; 93330bdcfaSDavid Howells struct list_head peer_keepalive[32]; 94330bdcfaSDavid Howells struct list_head peer_keepalive_new; 95ace45becSDavid Howells struct timer_list peer_keepalive_timer; 96ace45becSDavid Howells struct work_struct peer_keepalive_work; 97b0154246SDavid Howells 98b0154246SDavid Howells atomic_t stat_tx_data; 99b0154246SDavid Howells atomic_t stat_tx_data_retrans; 100b0154246SDavid Howells atomic_t stat_tx_data_send; 101b0154246SDavid Howells atomic_t stat_tx_data_send_frag; 102b0154246SDavid Howells atomic_t stat_rx_data; 103b0154246SDavid Howells atomic_t stat_rx_data_reqack; 104b0154246SDavid Howells atomic_t stat_rx_data_jumbo; 105f2a676d1SDavid Howells 106f2a676d1SDavid Howells atomic_t stat_tx_ack_fill; 107f2a676d1SDavid Howells atomic_t stat_tx_ack_send; 108f2a676d1SDavid Howells atomic_t stat_tx_ack_skip; 109f2a676d1SDavid Howells atomic_t stat_tx_acks[256]; 110f2a676d1SDavid Howells atomic_t stat_rx_acks[256]; 111f7fa5242SDavid Howells 112f7fa5242SDavid Howells atomic_t stat_why_req_ack[8]; 1132baec2c3SDavid Howells }; 1142baec2c3SDavid Howells 1152baec2c3SDavid Howells /* 11600e90712SDavid Howells * Service backlog preallocation. 11700e90712SDavid Howells * 11800e90712SDavid Howells * This contains circular buffers of preallocated peers, connections and calls 11900e90712SDavid Howells * for incoming service calls and their head and tail pointers. This allows 12000e90712SDavid Howells * calls to be set up in the data_ready handler, thereby avoiding the need to 12100e90712SDavid Howells * shuffle packets around so much. 12200e90712SDavid Howells */ 12300e90712SDavid Howells struct rxrpc_backlog { 12400e90712SDavid Howells unsigned short peer_backlog_head; 12500e90712SDavid Howells unsigned short peer_backlog_tail; 12600e90712SDavid Howells unsigned short conn_backlog_head; 12700e90712SDavid Howells unsigned short conn_backlog_tail; 12800e90712SDavid Howells unsigned short call_backlog_head; 12900e90712SDavid Howells unsigned short call_backlog_tail; 13000e90712SDavid Howells #define RXRPC_BACKLOG_MAX 32 13100e90712SDavid Howells struct rxrpc_peer *peer_backlog[RXRPC_BACKLOG_MAX]; 13200e90712SDavid Howells struct rxrpc_connection *conn_backlog[RXRPC_BACKLOG_MAX]; 13300e90712SDavid Howells struct rxrpc_call *call_backlog[RXRPC_BACKLOG_MAX]; 13400e90712SDavid Howells }; 13500e90712SDavid Howells 13600e90712SDavid Howells /* 13717926a79SDavid Howells * RxRPC socket definition 13817926a79SDavid Howells */ 13917926a79SDavid Howells struct rxrpc_sock { 14017926a79SDavid Howells /* WARNING: sk has to be the first member */ 14117926a79SDavid Howells struct sock sk; 142d001648eSDavid Howells rxrpc_notify_new_call_t notify_new_call; /* Func to notify of new call */ 14300e90712SDavid Howells rxrpc_discard_new_call_t discard_new_call; /* Func to discard a new call */ 14417926a79SDavid Howells struct rxrpc_local *local; /* local endpoint */ 14500e90712SDavid Howells struct rxrpc_backlog *backlog; /* Preallocation for services */ 146248f219cSDavid Howells spinlock_t incoming_lock; /* Incoming call vs service shutdown lock */ 147248f219cSDavid Howells struct list_head sock_calls; /* List of calls owned by this socket */ 148248f219cSDavid Howells struct list_head to_be_accepted; /* calls awaiting acceptance */ 149248f219cSDavid Howells struct list_head recvmsg_q; /* Calls awaiting recvmsg's attention */ 150248f219cSDavid Howells rwlock_t recvmsg_lock; /* Lock for recvmsg_q */ 15117926a79SDavid Howells struct key *key; /* security for this socket */ 15217926a79SDavid Howells struct key *securities; /* list of server security descriptors */ 15300e90712SDavid Howells struct rb_root calls; /* User ID -> call mapping */ 15417926a79SDavid Howells unsigned long flags; 1552341e077SDavid Howells #define RXRPC_SOCK_CONNECTED 0 /* connect_srx is set */ 15617926a79SDavid Howells rwlock_t call_lock; /* lock for calls */ 15717926a79SDavid Howells u32 min_sec_level; /* minimum security level */ 15817926a79SDavid Howells #define RXRPC_SECURITY_MAX RXRPC_SECURITY_ENCRYPT 159cc8feb8eSDavid Howells bool exclusive; /* Exclusive connection for a client socket */ 16028036f44SDavid Howells u16 second_service; /* Additional service bound to the endpoint */ 1614722974dSDavid Howells struct { 1624722974dSDavid Howells /* Service upgrade information */ 1634722974dSDavid Howells u16 from; /* Service ID to upgrade (if not 0) */ 1644722974dSDavid Howells u16 to; /* service ID to upgrade to */ 1654722974dSDavid Howells } service_upgrade; 166cc8feb8eSDavid Howells sa_family_t family; /* Protocol family created with */ 1674722974dSDavid Howells struct sockaddr_rxrpc srx; /* Primary Service/local addresses */ 1682341e077SDavid Howells struct sockaddr_rxrpc connect_srx; /* Default client address from connect() */ 16917926a79SDavid Howells }; 17017926a79SDavid Howells 17117926a79SDavid Howells #define rxrpc_sk(__sk) container_of((__sk), struct rxrpc_sock, sk) 17217926a79SDavid Howells 17317926a79SDavid Howells /* 1740d12f8a4SDavid Howells * CPU-byteorder normalised Rx packet header. 1750d12f8a4SDavid Howells */ 1760d12f8a4SDavid Howells struct rxrpc_host_header { 1770d12f8a4SDavid Howells u32 epoch; /* client boot timestamp */ 1780d12f8a4SDavid Howells u32 cid; /* connection and channel ID */ 1790d12f8a4SDavid Howells u32 callNumber; /* call ID (0 for connection-level packets) */ 1800d12f8a4SDavid Howells u32 seq; /* sequence number of pkt in call stream */ 1810d12f8a4SDavid Howells u32 serial; /* serial number of pkt sent to network */ 1820d12f8a4SDavid Howells u8 type; /* packet type */ 1830d12f8a4SDavid Howells u8 flags; /* packet flags */ 1840d12f8a4SDavid Howells u8 userStatus; /* app-layer defined status */ 1850d12f8a4SDavid Howells u8 securityIndex; /* security protocol ID */ 1860d12f8a4SDavid Howells union { 1870d12f8a4SDavid Howells u16 _rsvd; /* reserved */ 1880d12f8a4SDavid Howells u16 cksum; /* kerberos security checksum */ 1890d12f8a4SDavid Howells }; 1900d12f8a4SDavid Howells u16 serviceId; /* service ID */ 1910d12f8a4SDavid Howells } __packed; 1920d12f8a4SDavid Howells 1930d12f8a4SDavid Howells /* 19417926a79SDavid Howells * RxRPC socket buffer private variables 19517926a79SDavid Howells * - max 48 bytes (struct sk_buff::cb) 19617926a79SDavid Howells */ 19717926a79SDavid Howells struct rxrpc_skb_priv { 198d4d02d8bSDavid Howells u16 remain; 199d4d02d8bSDavid Howells u16 offset; /* Offset of data */ 200d4d02d8bSDavid Howells u16 len; /* Length of data */ 201d4d02d8bSDavid Howells u8 flags; 202d4d02d8bSDavid Howells #define RXRPC_RX_VERIFIED 0x01 20317926a79SDavid Howells 2040d12f8a4SDavid Howells struct rxrpc_host_header hdr; /* RxRPC packet header from this packet */ 20517926a79SDavid Howells }; 20617926a79SDavid Howells 20717926a79SDavid Howells #define rxrpc_skb(__skb) ((struct rxrpc_skb_priv *) &(__skb)->cb) 20817926a79SDavid Howells 20917926a79SDavid Howells /* 21017926a79SDavid Howells * RxRPC security module interface 21117926a79SDavid Howells */ 21217926a79SDavid Howells struct rxrpc_security { 21317926a79SDavid Howells const char *name; /* name of this service */ 21417926a79SDavid Howells u8 security_index; /* security type provided */ 215063c60d3SDavid Howells u32 no_key_abort; /* Abort code indicating no key */ 21617926a79SDavid Howells 217648af7fcSDavid Howells /* Initialise a security service */ 218648af7fcSDavid Howells int (*init)(void); 219648af7fcSDavid Howells 220648af7fcSDavid Howells /* Clean up a security service */ 221648af7fcSDavid Howells void (*exit)(void); 222648af7fcSDavid Howells 22312da59fcSDavid Howells /* Parse the information from a server key */ 22412da59fcSDavid Howells int (*preparse_server_key)(struct key_preparsed_payload *); 22512da59fcSDavid Howells 22612da59fcSDavid Howells /* Clean up the preparse buffer after parsing a server key */ 22712da59fcSDavid Howells void (*free_preparse_server_key)(struct key_preparsed_payload *); 22812da59fcSDavid Howells 22912da59fcSDavid Howells /* Destroy the payload of a server key */ 23012da59fcSDavid Howells void (*destroy_server_key)(struct key *); 23112da59fcSDavid Howells 232d5953f65SDavid Howells /* Describe a server key */ 233d5953f65SDavid Howells void (*describe_server_key)(const struct key *, struct seq_file *); 234d5953f65SDavid Howells 23517926a79SDavid Howells /* initialise a connection's security */ 23641057ebdSDavid Howells int (*init_connection_security)(struct rxrpc_connection *, 23741057ebdSDavid Howells struct rxrpc_key_token *); 23817926a79SDavid Howells 239d7d775b1SDavid Howells /* Work out how much data we can store in a packet, given an estimate 240d7d775b1SDavid Howells * of the amount of data remaining. 241d7d775b1SDavid Howells */ 242d7d775b1SDavid Howells int (*how_much_data)(struct rxrpc_call *, size_t, 243d7d775b1SDavid Howells size_t *, size_t *, size_t *); 24417926a79SDavid Howells 24517926a79SDavid Howells /* impose security on a packet */ 246f4bdf3d6SDavid Howells int (*secure_packet)(struct rxrpc_call *, struct sk_buff *, size_t); 24717926a79SDavid Howells 24817926a79SDavid Howells /* verify the security on a received packet */ 249d4d02d8bSDavid Howells int (*verify_packet)(struct rxrpc_call *, struct sk_buff *); 250248f219cSDavid Howells 2511db88c53SDavid Howells /* Free crypto request on a call */ 2521db88c53SDavid Howells void (*free_call_crypto)(struct rxrpc_call *); 2531db88c53SDavid Howells 25417926a79SDavid Howells /* issue a challenge */ 25517926a79SDavid Howells int (*issue_challenge)(struct rxrpc_connection *); 25617926a79SDavid Howells 25717926a79SDavid Howells /* respond to a challenge */ 25817926a79SDavid Howells int (*respond_to_challenge)(struct rxrpc_connection *, 25917926a79SDavid Howells struct sk_buff *, 26017926a79SDavid Howells u32 *); 26117926a79SDavid Howells 26217926a79SDavid Howells /* verify a response */ 26317926a79SDavid Howells int (*verify_response)(struct rxrpc_connection *, 26417926a79SDavid Howells struct sk_buff *, 26517926a79SDavid Howells u32 *); 26617926a79SDavid Howells 26717926a79SDavid Howells /* clear connection security */ 26817926a79SDavid Howells void (*clear)(struct rxrpc_connection *); 26917926a79SDavid Howells }; 27017926a79SDavid Howells 27117926a79SDavid Howells /* 2724f95dd78SDavid Howells * RxRPC local transport endpoint description 2734f95dd78SDavid Howells * - owned by a single AF_RXRPC socket 2744f95dd78SDavid Howells * - pointed to by transport socket struct sk_user_data 27517926a79SDavid Howells */ 27617926a79SDavid Howells struct rxrpc_local { 2774f95dd78SDavid Howells struct rcu_head rcu; 278730c5fd4SDavid Howells atomic_t active_users; /* Number of users of the local endpoint */ 279a0575429SDavid Howells refcount_t ref; /* Number of references to the structure */ 2802baec2c3SDavid Howells struct rxrpc_net *rxnet; /* The network ns in which this resides */ 28133912c26SDavid Howells struct hlist_node link; 28217926a79SDavid Howells struct socket *socket; /* my UDP socket */ 2834f95dd78SDavid Howells struct work_struct processor; 28472f0c6fbSDavid Howells struct list_head ack_tx_queue; /* List of ACKs that need sending */ 28572f0c6fbSDavid Howells spinlock_t ack_tx_lock; /* ACK list lock */ 2861e9e5c95SDavid Howells struct rxrpc_sock __rcu *service; /* Service(s) listening on this endpoint */ 28717926a79SDavid Howells struct rw_semaphore defrag_sem; /* control re-enablement of IP DF bit */ 28817926a79SDavid Howells struct sk_buff_head reject_queue; /* packets awaiting rejection */ 28944ba0698SDavid Howells struct sk_buff_head event_queue; /* endpoint event packets awaiting processing */ 290245500d8SDavid Howells struct rb_root client_bundles; /* Client connection bundles by socket params */ 291245500d8SDavid Howells spinlock_t client_bundles_lock; /* Lock for client_bundles */ 29217926a79SDavid Howells spinlock_t lock; /* access lock */ 29317926a79SDavid Howells rwlock_t services_lock; /* lock for services list */ 29417926a79SDavid Howells int debug_id; /* debug ID for printks */ 2954f95dd78SDavid Howells bool dead; 296f859ab61SDavid Howells bool service_closed; /* Service socket closed */ 29717926a79SDavid Howells struct sockaddr_rxrpc srx; /* local address */ 29817926a79SDavid Howells }; 29917926a79SDavid Howells 30017926a79SDavid Howells /* 30117926a79SDavid Howells * RxRPC remote transport endpoint definition 302be6e6707SDavid Howells * - matched by local endpoint, remote port, address and protocol type 30317926a79SDavid Howells */ 30417926a79SDavid Howells struct rxrpc_peer { 305be6e6707SDavid Howells struct rcu_head rcu; /* This must be first */ 306a0575429SDavid Howells refcount_t ref; 307be6e6707SDavid Howells unsigned long hash_key; 308be6e6707SDavid Howells struct hlist_node hash_link; 309be6e6707SDavid Howells struct rxrpc_local *local; 310f66d7490SDavid Howells struct hlist_head error_targets; /* targets for net error distribution */ 311aa390bbeSDavid Howells struct rb_root service_conns; /* Service connections */ 312330bdcfaSDavid Howells struct list_head keepalive_link; /* Link in net->peer_keepalive[] */ 313ace45becSDavid Howells time64_t last_tx_at; /* Last time packet sent here */ 3148496af50SDavid Howells seqlock_t service_conn_lock; 31517926a79SDavid Howells spinlock_t lock; /* access lock */ 31695c96174SEric Dumazet unsigned int if_mtu; /* interface MTU for this peer */ 31795c96174SEric Dumazet unsigned int mtu; /* network MTU for this peer */ 31895c96174SEric Dumazet unsigned int maxdata; /* data size (MTU - hdrsize) */ 31917926a79SDavid Howells unsigned short hdrsize; /* header size (IP + UDP + RxRPC) */ 32017926a79SDavid Howells int debug_id; /* debug ID for printks */ 32117926a79SDavid Howells struct sockaddr_rxrpc srx; /* remote address */ 32217926a79SDavid Howells 32317926a79SDavid Howells /* calculated RTT cache */ 32417926a79SDavid Howells #define RXRPC_RTT_CACHE_SIZE 32 325c1e15b49SDavid Howells spinlock_t rtt_input_lock; /* RTT lock for input routine */ 3260d4b103cSDavid Howells ktime_t rtt_last_req; /* Time of last RTT request */ 327c410bf01SDavid Howells unsigned int rtt_count; /* Number of samples we've got */ 328c410bf01SDavid Howells 329c410bf01SDavid Howells u32 srtt_us; /* smoothed round trip time << 3 in usecs */ 330c410bf01SDavid Howells u32 mdev_us; /* medium deviation */ 331c410bf01SDavid Howells u32 mdev_max_us; /* maximal mdev for the last rtt period */ 332c410bf01SDavid Howells u32 rttvar_us; /* smoothed mdev_max */ 333c410bf01SDavid Howells u32 rto_j; /* Retransmission timeout in jiffies */ 334c410bf01SDavid Howells u8 backoff; /* Backoff timeout */ 335f7aec129SDavid Howells 336f7aec129SDavid Howells u8 cong_cwnd; /* Congestion window size */ 33717926a79SDavid Howells }; 33817926a79SDavid Howells 33917926a79SDavid Howells /* 34019ffa01cSDavid Howells * Keys for matching a connection. 34119ffa01cSDavid Howells */ 34219ffa01cSDavid Howells struct rxrpc_conn_proto { 343e8d70ce1SDavid Howells union { 344e8d70ce1SDavid Howells struct { 34519ffa01cSDavid Howells u32 epoch; /* epoch of this connection */ 34619ffa01cSDavid Howells u32 cid; /* connection ID */ 347e8d70ce1SDavid Howells }; 348e8d70ce1SDavid Howells u64 index_key; 34919ffa01cSDavid Howells }; 35019ffa01cSDavid Howells }; 35119ffa01cSDavid Howells 35219ffa01cSDavid Howells struct rxrpc_conn_parameters { 35319ffa01cSDavid Howells struct rxrpc_local *local; /* Representation of local endpoint */ 35419ffa01cSDavid Howells struct rxrpc_peer *peer; /* Remote endpoint */ 35519ffa01cSDavid Howells struct key *key; /* Security details */ 35619ffa01cSDavid Howells bool exclusive; /* T if conn is exclusive */ 3574e255721SDavid Howells bool upgrade; /* T if service ID can be upgraded */ 35819ffa01cSDavid Howells u16 service_id; /* Service ID for this connection */ 35919ffa01cSDavid Howells u32 security_level; /* Security level selected */ 36019ffa01cSDavid Howells }; 36119ffa01cSDavid Howells 36219ffa01cSDavid Howells /* 363bba304dbSDavid Howells * Bits in the connection flags. 364bba304dbSDavid Howells */ 365bba304dbSDavid Howells enum rxrpc_conn_flag { 366bba304dbSDavid Howells RXRPC_CONN_HAS_IDR, /* Has a client conn ID assigned */ 367001c1122SDavid Howells RXRPC_CONN_IN_SERVICE_CONNS, /* Conn is in peer->service_conns */ 36845025bceSDavid Howells RXRPC_CONN_DONT_REUSE, /* Don't reuse this connection */ 3694e255721SDavid Howells RXRPC_CONN_PROBING_FOR_UPGRADE, /* Probing for service upgrade */ 3703136ef49SDavid Howells RXRPC_CONN_FINAL_ACK_0, /* Need final ACK for channel 0 */ 3713136ef49SDavid Howells RXRPC_CONN_FINAL_ACK_1, /* Need final ACK for channel 1 */ 3723136ef49SDavid Howells RXRPC_CONN_FINAL_ACK_2, /* Need final ACK for channel 2 */ 3733136ef49SDavid Howells RXRPC_CONN_FINAL_ACK_3, /* Need final ACK for channel 3 */ 374bba304dbSDavid Howells }; 375bba304dbSDavid Howells 3763136ef49SDavid Howells #define RXRPC_CONN_FINAL_ACK_MASK ((1UL << RXRPC_CONN_FINAL_ACK_0) | \ 3773136ef49SDavid Howells (1UL << RXRPC_CONN_FINAL_ACK_1) | \ 3783136ef49SDavid Howells (1UL << RXRPC_CONN_FINAL_ACK_2) | \ 3793136ef49SDavid Howells (1UL << RXRPC_CONN_FINAL_ACK_3)) 3803136ef49SDavid Howells 381bba304dbSDavid Howells /* 382bba304dbSDavid Howells * Events that can be raised upon a connection. 383bba304dbSDavid Howells */ 384bba304dbSDavid Howells enum rxrpc_conn_event { 385bba304dbSDavid Howells RXRPC_CONN_EV_CHALLENGE, /* Send challenge packet */ 386bba304dbSDavid Howells }; 387bba304dbSDavid Howells 388bba304dbSDavid Howells /* 389bba304dbSDavid Howells * The connection protocol state. 390bba304dbSDavid Howells */ 391bba304dbSDavid Howells enum rxrpc_conn_proto_state { 392bba304dbSDavid Howells RXRPC_CONN_UNUSED, /* Connection not yet attempted */ 393bba304dbSDavid Howells RXRPC_CONN_CLIENT, /* Client connection */ 39400e90712SDavid Howells RXRPC_CONN_SERVICE_PREALLOC, /* Service connection preallocation */ 395bba304dbSDavid Howells RXRPC_CONN_SERVICE_UNSECURED, /* Service unsecured connection */ 396bba304dbSDavid Howells RXRPC_CONN_SERVICE_CHALLENGING, /* Service challenging for security */ 397bba304dbSDavid Howells RXRPC_CONN_SERVICE, /* Service secured connection */ 398bba304dbSDavid Howells RXRPC_CONN_REMOTELY_ABORTED, /* Conn aborted by peer */ 399bba304dbSDavid Howells RXRPC_CONN_LOCALLY_ABORTED, /* Conn aborted locally */ 400bba304dbSDavid Howells RXRPC_CONN__NR_STATES 401bba304dbSDavid Howells }; 402bba304dbSDavid Howells 403bba304dbSDavid Howells /* 404245500d8SDavid Howells * RxRPC client connection bundle. 405245500d8SDavid Howells */ 406245500d8SDavid Howells struct rxrpc_bundle { 407245500d8SDavid Howells struct rxrpc_conn_parameters params; 408a0575429SDavid Howells refcount_t ref; 409245500d8SDavid Howells unsigned int debug_id; 410245500d8SDavid Howells bool try_upgrade; /* True if the bundle is attempting upgrade */ 411245500d8SDavid Howells bool alloc_conn; /* True if someone's getting a conn */ 4128806245aSDavid Howells short alloc_error; /* Error from last conn allocation */ 413245500d8SDavid Howells spinlock_t channel_lock; 414245500d8SDavid Howells struct rb_node local_node; /* Node in local->client_conns */ 415245500d8SDavid Howells struct list_head waiting_calls; /* Calls waiting for channels */ 416245500d8SDavid Howells unsigned long avail_chans; /* Mask of available channels */ 417245500d8SDavid Howells struct rxrpc_connection *conns[4]; /* The connections in the bundle (max 4) */ 418245500d8SDavid Howells }; 419245500d8SDavid Howells 420245500d8SDavid Howells /* 42117926a79SDavid Howells * RxRPC connection definition 422aa390bbeSDavid Howells * - matched by { local, peer, epoch, conn_id, direction } 42317926a79SDavid Howells * - each connection can only handle four simultaneous calls 42417926a79SDavid Howells */ 42517926a79SDavid Howells struct rxrpc_connection { 42619ffa01cSDavid Howells struct rxrpc_conn_proto proto; 42719ffa01cSDavid Howells struct rxrpc_conn_parameters params; 42819ffa01cSDavid Howells 429a0575429SDavid Howells refcount_t ref; 43045025bceSDavid Howells struct rcu_head rcu; 43145025bceSDavid Howells struct list_head cache_link; 432a1399f8bSDavid Howells 433245500d8SDavid Howells unsigned char act_chans; /* Mask of active channels */ 434a1399f8bSDavid Howells struct rxrpc_channel { 4353136ef49SDavid Howells unsigned long final_ack_at; /* Time at which to issue final ACK */ 436a1399f8bSDavid Howells struct rxrpc_call __rcu *call; /* Active call */ 4374764c0daSDavid Howells unsigned int call_debug_id; /* call->debug_id */ 438a1399f8bSDavid Howells u32 call_id; /* ID of current call */ 439a1399f8bSDavid Howells u32 call_counter; /* Call ID counter */ 440a1399f8bSDavid Howells u32 last_call; /* ID of last call */ 44118bfeba5SDavid Howells u8 last_type; /* Type of last packet */ 44218bfeba5SDavid Howells union { 44318bfeba5SDavid Howells u32 last_seq; 44418bfeba5SDavid Howells u32 last_abort; 44518bfeba5SDavid Howells }; 446a1399f8bSDavid Howells } channels[RXRPC_MAXCALLS]; 447999b69f8SDavid Howells 4483136ef49SDavid Howells struct timer_list timer; /* Conn event timer */ 44917926a79SDavid Howells struct work_struct processor; /* connection event processor */ 450245500d8SDavid Howells struct rxrpc_bundle *bundle; /* Client connection bundle */ 451aa390bbeSDavid Howells struct rb_node service_node; /* Node in peer->service_conns */ 4524d028b2cSDavid Howells struct list_head proc_link; /* link in procfs list */ 45317926a79SDavid Howells struct list_head link; /* link in master connection list */ 45417926a79SDavid Howells struct sk_buff_head rx_queue; /* received conn-level packets */ 455521bb304SDavid Howells 456648af7fcSDavid Howells const struct rxrpc_security *security; /* applied security module */ 457521bb304SDavid Howells union { 458521bb304SDavid Howells struct { 45969d826faSKees Cook struct crypto_sync_skcipher *cipher; /* encryption handle */ 46017926a79SDavid Howells struct rxrpc_crypt csum_iv; /* packet checksum base */ 461521bb304SDavid Howells u32 nonce; /* response re-use preventer */ 462521bb304SDavid Howells } rxkad; 463521bb304SDavid Howells }; 4644a3388c8SDavid Howells unsigned long flags; 46517926a79SDavid Howells unsigned long events; 466f51b4480SDavid Howells unsigned long idle_timestamp; /* Time at which last became idle */ 46717926a79SDavid Howells spinlock_t state_lock; /* state-change lock */ 468cf13258fSDavid Howells enum rxrpc_conn_proto_state state; /* current state of connection */ 46964753092SDavid Howells u32 abort_code; /* Abort code of connection abort */ 47017926a79SDavid Howells int debug_id; /* debug ID for printks */ 47117926a79SDavid Howells atomic_t serial; /* packet serial number counter */ 472563ea7d5SDavid Howells unsigned int hi_serial; /* highest serial number received */ 473c1e15b49SDavid Howells u32 service_id; /* Service ID, possibly upgraded */ 47417926a79SDavid Howells u8 security_ix; /* security type */ 47517926a79SDavid Howells u8 out_clientflag; /* RXRPC_CLIENT_INITIATED if we are client */ 476245500d8SDavid Howells u8 bundle_shift; /* Index into bundle->avail_chans */ 47764753092SDavid Howells short error; /* Local error code */ 47817926a79SDavid Howells }; 47917926a79SDavid Howells 480dc71db34SDavid Howells static inline bool rxrpc_to_server(const struct rxrpc_skb_priv *sp) 481dc71db34SDavid Howells { 482dc71db34SDavid Howells return sp->hdr.flags & RXRPC_CLIENT_INITIATED; 483dc71db34SDavid Howells } 484dc71db34SDavid Howells 485dc71db34SDavid Howells static inline bool rxrpc_to_client(const struct rxrpc_skb_priv *sp) 486dc71db34SDavid Howells { 487dc71db34SDavid Howells return !rxrpc_to_server(sp); 488dc71db34SDavid Howells } 489dc71db34SDavid Howells 49017926a79SDavid Howells /* 4915b8848d1SDavid Howells * Flags in call->flags. 4925b8848d1SDavid Howells */ 4935b8848d1SDavid Howells enum rxrpc_call_flag { 4945b8848d1SDavid Howells RXRPC_CALL_RELEASED, /* call has been released - no more message to userspace */ 4955b8848d1SDavid Howells RXRPC_CALL_HAS_USERID, /* has a user ID attached */ 496dabe5a79SDavid Howells RXRPC_CALL_IS_SERVICE, /* Call is service call */ 49745025bceSDavid Howells RXRPC_CALL_EXPOSED, /* The call was exposed to the world */ 498248f219cSDavid Howells RXRPC_CALL_RX_LAST, /* Received the last packet (at rxtx_top) */ 499248f219cSDavid Howells RXRPC_CALL_TX_LAST, /* Last packet in Tx buffer (at rxtx_top) */ 500a5af7e1fSDavid Howells RXRPC_CALL_SEND_PING, /* A ping will need to be sent */ 50157494343SDavid Howells RXRPC_CALL_RETRANS_TIMEOUT, /* Retransmission due to timeout occurred */ 502c54e43d7SDavid Howells RXRPC_CALL_BEGAN_RX_TIMER, /* We began the expect_rx_by timer */ 5031a025028SDavid Howells RXRPC_CALL_RX_HEARD, /* The peer responded at least once to this call */ 504d0b35a42SDavid Howells RXRPC_CALL_RX_UNDERRUN, /* Got data underrun */ 5055273a191SDavid Howells RXRPC_CALL_DISCONNECTED, /* The call has been disconnected */ 506b7a7d674SDavid Howells RXRPC_CALL_KERNEL, /* The call was made by the kernel */ 507245500d8SDavid Howells RXRPC_CALL_UPGRADE, /* Service upgrade was requested for the call */ 508530403d9SDavid Howells RXRPC_CALL_DELAY_ACK_PENDING, /* DELAY ACK generation is pending */ 509530403d9SDavid Howells RXRPC_CALL_IDLE_ACK_PENDING, /* IDLE ACK generation is pending */ 5105b8848d1SDavid Howells }; 5115b8848d1SDavid Howells 5125b8848d1SDavid Howells /* 5135b8848d1SDavid Howells * Events that can be raised on a call. 5145b8848d1SDavid Howells */ 5155b8848d1SDavid Howells enum rxrpc_call_event { 5164c198ad1SDavid Howells RXRPC_CALL_EV_ABORT, /* need to generate abort */ 5174c198ad1SDavid Howells RXRPC_CALL_EV_RESEND, /* Tx resend required */ 518a158bdd3SDavid Howells RXRPC_CALL_EV_EXPIRED, /* Expiry occurred */ 519bd1fdf8cSDavid Howells RXRPC_CALL_EV_ACK_LOST, /* ACK may be lost, send ping */ 5205b8848d1SDavid Howells }; 5215b8848d1SDavid Howells 5225b8848d1SDavid Howells /* 5235b8848d1SDavid Howells * The states that a call can be in. 5245b8848d1SDavid Howells */ 5255b8848d1SDavid Howells enum rxrpc_call_state { 526999b69f8SDavid Howells RXRPC_CALL_UNINITIALISED, 527999b69f8SDavid Howells RXRPC_CALL_CLIENT_AWAIT_CONN, /* - client waiting for connection to become available */ 5285b8848d1SDavid Howells RXRPC_CALL_CLIENT_SEND_REQUEST, /* - client sending request phase */ 5295b8848d1SDavid Howells RXRPC_CALL_CLIENT_AWAIT_REPLY, /* - client awaiting reply */ 5305b8848d1SDavid Howells RXRPC_CALL_CLIENT_RECV_REPLY, /* - client receiving reply phase */ 53100e90712SDavid Howells RXRPC_CALL_SERVER_PREALLOC, /* - service preallocation */ 5325b8848d1SDavid Howells RXRPC_CALL_SERVER_SECURING, /* - server securing request connection */ 5335b8848d1SDavid Howells RXRPC_CALL_SERVER_RECV_REQUEST, /* - server receiving request */ 5345b8848d1SDavid Howells RXRPC_CALL_SERVER_ACK_REQUEST, /* - server pending ACK of request */ 5355b8848d1SDavid Howells RXRPC_CALL_SERVER_SEND_REPLY, /* - server sending reply */ 5365b8848d1SDavid Howells RXRPC_CALL_SERVER_AWAIT_ACK, /* - server awaiting final ACK */ 537f5c17aaeSDavid Howells RXRPC_CALL_COMPLETE, /* - call complete */ 538f5c17aaeSDavid Howells NR__RXRPC_CALL_STATES 539f5c17aaeSDavid Howells }; 540f5c17aaeSDavid Howells 541f5c17aaeSDavid Howells /* 542e122d845SDavid Howells * Call completion condition (state == RXRPC_CALL_COMPLETE). 543e122d845SDavid Howells */ 544e122d845SDavid Howells enum rxrpc_call_completion { 545e122d845SDavid Howells RXRPC_CALL_SUCCEEDED, /* - Normal termination */ 546e122d845SDavid Howells RXRPC_CALL_REMOTELY_ABORTED, /* - call aborted by peer */ 547e122d845SDavid Howells RXRPC_CALL_LOCALLY_ABORTED, /* - call aborted locally on error or close */ 548e122d845SDavid Howells RXRPC_CALL_LOCAL_ERROR, /* - call failed due to local error */ 549e122d845SDavid Howells RXRPC_CALL_NETWORK_ERROR, /* - call terminated by network error */ 550e122d845SDavid Howells NR__RXRPC_CALL_COMPLETIONS 551e122d845SDavid Howells }; 552e122d845SDavid Howells 553e122d845SDavid Howells /* 55457494343SDavid Howells * Call Tx congestion management modes. 55557494343SDavid Howells */ 55657494343SDavid Howells enum rxrpc_congest_mode { 55757494343SDavid Howells RXRPC_CALL_SLOW_START, 55857494343SDavid Howells RXRPC_CALL_CONGEST_AVOIDANCE, 55957494343SDavid Howells RXRPC_CALL_PACKET_LOSS, 56057494343SDavid Howells RXRPC_CALL_FAST_RETRANSMIT, 56157494343SDavid Howells NR__RXRPC_CONGEST_MODES 56257494343SDavid Howells }; 56357494343SDavid Howells 56457494343SDavid Howells /* 56517926a79SDavid Howells * RxRPC call definition 56617926a79SDavid Howells * - matched by { connection, call_id } 56717926a79SDavid Howells */ 56817926a79SDavid Howells struct rxrpc_call { 569dee46364SDavid Howells struct rcu_head rcu; 57017926a79SDavid Howells struct rxrpc_connection *conn; /* connection carrying call */ 571df5d8bf7SDavid Howells struct rxrpc_peer *peer; /* Peer record for remote address */ 5728d94aa38SDavid Howells struct rxrpc_sock __rcu *socket; /* socket responsible */ 573d3be4d24SDavid Howells struct rxrpc_net *rxnet; /* Network namespace to which call belongs */ 57491fcfbe8SDavid Howells const struct rxrpc_security *security; /* applied security module */ 575540b1c48SDavid Howells struct mutex user_mutex; /* User access mutex */ 576530403d9SDavid Howells unsigned long delay_ack_at; /* When DELAY ACK needs to happen */ 577bd1fdf8cSDavid Howells unsigned long ack_lost_at; /* When ACK is figured as lost */ 578a158bdd3SDavid Howells unsigned long resend_at; /* When next resend needs to happen */ 579a158bdd3SDavid Howells unsigned long ping_at; /* When next to send a ping */ 580415f44e4SDavid Howells unsigned long keepalive_at; /* When next to send a keepalive ping */ 581a158bdd3SDavid Howells unsigned long expect_rx_by; /* When we expect to get a packet by */ 582a158bdd3SDavid Howells unsigned long expect_req_by; /* When we expect to get a request DATA packet by */ 583a158bdd3SDavid Howells unsigned long expect_term_by; /* When we expect call termination by */ 584a158bdd3SDavid Howells u32 next_rx_timo; /* Timeout for next Rx packet (jif) */ 585a158bdd3SDavid Howells u32 next_req_timo; /* Timeout for next Rx request packet (jif) */ 5861db88c53SDavid Howells struct skcipher_request *cipher_req; /* Packet cipher request buffer */ 587248f219cSDavid Howells struct timer_list timer; /* Combined event timer */ 588248f219cSDavid Howells struct work_struct processor; /* Event processor */ 589d001648eSDavid Howells rxrpc_notify_rx_t notify_rx; /* kernel service Rx notification function */ 59017926a79SDavid Howells struct list_head link; /* link in master call list */ 591245500d8SDavid Howells struct list_head chan_wait_link; /* Link in conn->bundle->waiting_calls */ 592f66d7490SDavid Howells struct hlist_node error_link; /* link in error distribution list */ 593248f219cSDavid Howells struct list_head accept_link; /* Link in rx->acceptq */ 594248f219cSDavid Howells struct list_head recvmsg_link; /* Link in rx->recvmsg_q */ 595248f219cSDavid Howells struct list_head sock_link; /* Link in rx->sock_calls */ 596248f219cSDavid Howells struct rb_node sock_node; /* Node in rx->calls */ 59717926a79SDavid Howells struct sk_buff *tx_pending; /* Tx socket buffer being filled */ 59845025bceSDavid Howells wait_queue_head_t waitq; /* Wait queue for channel or Tx */ 599e754eba6SDavid Howells s64 tx_total_len; /* Total length left to be transmitted (or -1) */ 600a263629dSHerbert Xu __be32 crypto_buf[2]; /* Temporary packet crypto buffer */ 60117926a79SDavid Howells unsigned long user_call_ID; /* user-defined call ID */ 60217926a79SDavid Howells unsigned long flags; 60317926a79SDavid Howells unsigned long events; 60417926a79SDavid Howells spinlock_t lock; 60520acbd9aSDavid Howells spinlock_t notify_lock; /* Kernel notification lock */ 60617926a79SDavid Howells rwlock_t state_lock; /* lock for state transition */ 607f5c17aaeSDavid Howells u32 abort_code; /* Local/remote abort code */ 608f5c17aaeSDavid Howells int error; /* Local error incurred */ 609cf13258fSDavid Howells enum rxrpc_call_state state; /* current state of call */ 610cf13258fSDavid Howells enum rxrpc_call_completion completion; /* Call completion condition */ 611a0575429SDavid Howells refcount_t ref; 612dabe5a79SDavid Howells u16 service_id; /* service ID */ 613278ac0cdSDavid Howells u8 security_ix; /* Security type */ 614e138aa7dSDavid Howells enum rxrpc_interruptibility interruptibility; /* At what point call may be interrupted */ 615dabe5a79SDavid Howells u32 call_id; /* call ID on connection */ 616dabe5a79SDavid Howells u32 cid; /* connection ID plus channel index */ 617dabe5a79SDavid Howells int debug_id; /* debug ID for printks */ 6188e83134dSDavid Howells unsigned short rx_pkt_offset; /* Current recvmsg packet offset */ 6198e83134dSDavid Howells unsigned short rx_pkt_len; /* Current recvmsg packet len */ 62017926a79SDavid Howells 621248f219cSDavid Howells /* Rx/Tx circular buffer, depending on phase. 622248f219cSDavid Howells * 623248f219cSDavid Howells * In the Rx phase, packets are annotated with 0 or the number of the 624248f219cSDavid Howells * segment of a jumbo packet each buffer refers to. There can be up to 625248f219cSDavid Howells * 47 segments in a maximum-size UDP packet. 626248f219cSDavid Howells * 627248f219cSDavid Howells * In the Tx phase, packets are annotated with which buffers have been 628248f219cSDavid Howells * acked. 62917926a79SDavid Howells */ 630248f219cSDavid Howells #define RXRPC_RXTX_BUFF_SIZE 64 631248f219cSDavid Howells #define RXRPC_RXTX_BUFF_MASK (RXRPC_RXTX_BUFF_SIZE - 1) 6324075295aSDavid Howells #define RXRPC_INIT_RX_WINDOW_SIZE 63 633248f219cSDavid Howells struct sk_buff **rxtx_buffer; 634248f219cSDavid Howells u8 *rxtx_annotations; 635248f219cSDavid Howells #define RXRPC_TX_ANNO_ACK 0 636248f219cSDavid Howells #define RXRPC_TX_ANNO_UNACK 1 637248f219cSDavid Howells #define RXRPC_TX_ANNO_NAK 2 638248f219cSDavid Howells #define RXRPC_TX_ANNO_RETRANS 3 639f07373eaSDavid Howells #define RXRPC_TX_ANNO_MASK 0x03 64070790dbeSDavid Howells #define RXRPC_TX_ANNO_LAST 0x04 64170790dbeSDavid Howells #define RXRPC_TX_ANNO_RESENT 0x08 64270790dbeSDavid Howells 643248f219cSDavid Howells rxrpc_seq_t tx_hard_ack; /* Dead slot in buffer; the first transmitted but 644248f219cSDavid Howells * not hard-ACK'd packet follows this. 645248f219cSDavid Howells */ 646*5d7edbc9SDavid Howells 647*5d7edbc9SDavid Howells /* Transmitted data tracking. */ 648248f219cSDavid Howells rxrpc_seq_t tx_top; /* Highest Tx slot allocated. */ 649c7e86acfSDavid Howells u16 tx_backoff; /* Delay to insert due to Tx failure */ 650*5d7edbc9SDavid Howells u8 tx_winsize; /* Maximum size of Tx window */ 651*5d7edbc9SDavid Howells 652*5d7edbc9SDavid Howells /* Received data tracking */ 653*5d7edbc9SDavid Howells struct sk_buff_head recvmsg_queue; /* Queue of packets ready for recvmsg() */ 654*5d7edbc9SDavid Howells struct sk_buff_head rx_oos_queue; /* Queue of out of sequence packets */ 655*5d7edbc9SDavid Howells 656*5d7edbc9SDavid Howells rxrpc_seq_t rx_highest_seq; /* Higest sequence number received */ 657*5d7edbc9SDavid Howells rxrpc_seq_t rx_consumed; /* Highest packet consumed */ 658*5d7edbc9SDavid Howells rxrpc_serial_t rx_serial; /* Highest serial received for this call */ 659*5d7edbc9SDavid Howells u8 rx_winsize; /* Size of Rx window */ 66057494343SDavid Howells 66157494343SDavid Howells /* TCP-style slow-start congestion control [RFC5681]. Since the SMSS 66257494343SDavid Howells * is fixed, we keep these numbers in terms of segments (ie. DATA 66357494343SDavid Howells * packets) rather than bytes. 66457494343SDavid Howells */ 66557494343SDavid Howells #define RXRPC_TX_SMSS RXRPC_JUMBO_DATALEN 66657494343SDavid Howells u8 cong_cwnd; /* Congestion window size */ 66757494343SDavid Howells u8 cong_extra; /* Extra to send for congestion management */ 66857494343SDavid Howells u8 cong_ssthresh; /* Slow-start threshold */ 66957494343SDavid Howells enum rxrpc_congest_mode cong_mode:8; /* Congestion management mode */ 67057494343SDavid Howells u8 cong_dup_acks; /* Count of ACKs showing missing packets */ 67157494343SDavid Howells u8 cong_cumul_acks; /* Cumulative ACK count */ 67257494343SDavid Howells ktime_t cong_tstamp; /* Last time cwnd was changed */ 67357494343SDavid Howells 674c1e15b49SDavid Howells spinlock_t input_lock; /* Lock for packet input to this call */ 675c1e15b49SDavid Howells 6768940ba3cSDavid Howells /* Receive-phase ACK management (ACKs we send). */ 6774e36a95eSDavid Howells u8 ackr_reason; /* reason to ACK */ 6780d12f8a4SDavid Howells rxrpc_serial_t ackr_serial; /* serial of packet being ACK'd */ 679*5d7edbc9SDavid Howells atomic64_t ackr_window; /* Base (in LSW) and top (in MSW) of SACK window */ 6809a3dedcfSDavid Howells atomic_t ackr_nr_unacked; /* Number of unacked packets */ 6819a3dedcfSDavid Howells atomic_t ackr_nr_consumed; /* Number of packets needing hard ACK */ 682*5d7edbc9SDavid Howells struct { 683*5d7edbc9SDavid Howells #define RXRPC_SACK_SIZE 256 684*5d7edbc9SDavid Howells /* SACK table for soft-acked packets */ 685*5d7edbc9SDavid Howells u8 ackr_sack_table[RXRPC_SACK_SIZE]; 686*5d7edbc9SDavid Howells } __aligned(8); 687a5af7e1fSDavid Howells 6884700c4d8SDavid Howells /* RTT management */ 6894700c4d8SDavid Howells rxrpc_serial_t rtt_serial[4]; /* Serial number of DATA or PING sent */ 6904700c4d8SDavid Howells ktime_t rtt_sent_at[4]; /* Time packet sent */ 6914700c4d8SDavid Howells unsigned long rtt_avail; /* Mask of available slots in bits 0-3, 6924700c4d8SDavid Howells * Mask of pending samples in 8-11 */ 6934700c4d8SDavid Howells #define RXRPC_CALL_RTT_AVAIL_MASK 0xf 6944700c4d8SDavid Howells #define RXRPC_CALL_RTT_PEND_SHIFT 8 69517926a79SDavid Howells 6968940ba3cSDavid Howells /* Transmission-phase ACK management (ACKs we've received). */ 69757494343SDavid Howells ktime_t acks_latest_ts; /* Timestamp of latest ACK received */ 6988940ba3cSDavid Howells rxrpc_seq_t acks_first_seq; /* first sequence number received */ 69981524b63SDavid Howells rxrpc_seq_t acks_prev_seq; /* Highest previousPacket received */ 70031a1b989SDavid Howells rxrpc_seq_t acks_lowest_nak; /* Lowest NACK in the buffer (or ==tx_hard_ack) */ 701bd1fdf8cSDavid Howells rxrpc_seq_t acks_lost_top; /* tx_top at the time lost-ack ping sent */ 702bd1fdf8cSDavid Howells rxrpc_serial_t acks_lost_ping; /* Serial number of probe ACK */ 703589a0c1eSDavid Howells rxrpc_serial_t acks_highest_serial; /* Highest serial number ACK'd */ 70431a1b989SDavid Howells }; 70531a1b989SDavid Howells 70631a1b989SDavid Howells /* 70757494343SDavid Howells * Summary of a new ACK and the changes it made to the Tx buffer packet states. 70831a1b989SDavid Howells */ 70931a1b989SDavid Howells struct rxrpc_ack_summary { 71031a1b989SDavid Howells u8 ack_reason; 71131a1b989SDavid Howells u8 nr_acks; /* Number of ACKs in packet */ 71231a1b989SDavid Howells u8 nr_nacks; /* Number of NACKs in packet */ 71331a1b989SDavid Howells u8 nr_new_acks; /* Number of new ACKs in packet */ 71431a1b989SDavid Howells u8 nr_new_nacks; /* Number of new NACKs in packet */ 71531a1b989SDavid Howells u8 nr_rot_new_acks; /* Number of rotated new ACKs */ 71631a1b989SDavid Howells bool new_low_nack; /* T if new low NACK found */ 71757494343SDavid Howells bool retrans_timeo; /* T if reTx due to timeout happened */ 71857494343SDavid Howells u8 flight_size; /* Number of unreceived transmissions */ 71957494343SDavid Howells /* Place to stash values for tracing */ 72057494343SDavid Howells enum rxrpc_congest_mode mode:8; 72157494343SDavid Howells u8 cwnd; 72257494343SDavid Howells u8 ssthresh; 72357494343SDavid Howells u8 dup_acks; 72457494343SDavid Howells u8 cumulative_acks; 72517926a79SDavid Howells }; 72617926a79SDavid Howells 72748124178SDavid Howells /* 72848124178SDavid Howells * sendmsg() cmsg-specified parameters. 72948124178SDavid Howells */ 73048124178SDavid Howells enum rxrpc_command { 73148124178SDavid Howells RXRPC_CMD_SEND_DATA, /* send data message */ 73248124178SDavid Howells RXRPC_CMD_SEND_ABORT, /* request abort generation */ 73348124178SDavid Howells RXRPC_CMD_REJECT_BUSY, /* [server] reject a call as busy */ 7342d914c1bSDavid Howells RXRPC_CMD_CHARGE_ACCEPT, /* [server] charge accept preallocation */ 73548124178SDavid Howells }; 73648124178SDavid Howells 73748124178SDavid Howells struct rxrpc_call_params { 73848124178SDavid Howells s64 tx_total_len; /* Total Tx data length (if send data) */ 73948124178SDavid Howells unsigned long user_call_ID; /* User's call ID */ 74048124178SDavid Howells struct { 74148124178SDavid Howells u32 hard; /* Maximum lifetime (sec) */ 74248124178SDavid Howells u32 idle; /* Max time since last data packet (msec) */ 74348124178SDavid Howells u32 normal; /* Max time since last call packet (msec) */ 74448124178SDavid Howells } timeouts; 74548124178SDavid Howells u8 nr_timeouts; /* Number of timeouts specified */ 746b7a7d674SDavid Howells bool kernel; /* T if kernel is making the call */ 747e138aa7dSDavid Howells enum rxrpc_interruptibility interruptibility; /* How is interruptible is the call? */ 74848124178SDavid Howells }; 74948124178SDavid Howells 75048124178SDavid Howells struct rxrpc_send_params { 75148124178SDavid Howells struct rxrpc_call_params call; 75248124178SDavid Howells u32 abort_code; /* Abort code to Tx (if abort) */ 75348124178SDavid Howells enum rxrpc_command command : 8; /* The command to implement */ 75448124178SDavid Howells bool exclusive; /* Shared or exclusive call */ 75548124178SDavid Howells bool upgrade; /* If the connection is upgradeable */ 75648124178SDavid Howells }; 75748124178SDavid Howells 75802a19356SDavid Howells /* 75902a19356SDavid Howells * Buffer of data to be output as a packet. 76002a19356SDavid Howells */ 76102a19356SDavid Howells struct rxrpc_txbuf { 76202a19356SDavid Howells struct rcu_head rcu; 76302a19356SDavid Howells struct list_head call_link; /* Link in call->tx_queue */ 76402a19356SDavid Howells struct list_head tx_link; /* Link in live Enc queue or Tx queue */ 76502a19356SDavid Howells struct rxrpc_call *call; /* Call to which belongs */ 76602a19356SDavid Howells ktime_t last_sent; /* Time at which last transmitted */ 76702a19356SDavid Howells refcount_t ref; 76802a19356SDavid Howells rxrpc_seq_t seq; /* Sequence number of this packet */ 76902a19356SDavid Howells unsigned int call_debug_id; 77002a19356SDavid Howells unsigned int debug_id; 77102a19356SDavid Howells unsigned int len; /* Amount of data in buffer */ 77202a19356SDavid Howells unsigned int space; /* Remaining data space */ 77302a19356SDavid Howells unsigned int offset; /* Offset of fill point */ 77402a19356SDavid Howells unsigned long flags; 77502a19356SDavid Howells #define RXRPC_TXBUF_ACKED 0 /* Set if ACK'd */ 77602a19356SDavid Howells #define RXRPC_TXBUF_NACKED 1 /* Set if NAK'd */ 77702a19356SDavid Howells #define RXRPC_TXBUF_LAST 2 /* Set if last packet in Tx phase */ 77802a19356SDavid Howells #define RXRPC_TXBUF_RESENT 3 /* Set if has been resent */ 77902a19356SDavid Howells #define RXRPC_TXBUF_RETRANS 4 /* Set if should be retransmitted */ 78072f0c6fbSDavid Howells u8 /*enum rxrpc_propose_ack_trace*/ ack_why; /* If ack, why */ 78102a19356SDavid Howells struct { 78202a19356SDavid Howells /* The packet for encrypting and DMA'ing. We align it such 78302a19356SDavid Howells * that data[] aligns correctly for any crypto blocksize. 78402a19356SDavid Howells */ 78502a19356SDavid Howells u8 pad[64 - sizeof(struct rxrpc_wire_header)]; 78602a19356SDavid Howells struct rxrpc_wire_header wire; /* Network-ready header */ 78772f0c6fbSDavid Howells union { 78802a19356SDavid Howells u8 data[RXRPC_JUMBO_DATALEN]; /* Data packet */ 78972f0c6fbSDavid Howells struct { 79072f0c6fbSDavid Howells struct rxrpc_ackpacket ack; 79172f0c6fbSDavid Howells u8 acks[0]; 79272f0c6fbSDavid Howells }; 79372f0c6fbSDavid Howells }; 79402a19356SDavid Howells } __aligned(64); 79502a19356SDavid Howells }; 79602a19356SDavid Howells 79702a19356SDavid Howells static inline bool rxrpc_sending_to_server(const struct rxrpc_txbuf *txb) 79802a19356SDavid Howells { 79902a19356SDavid Howells return txb->wire.flags & RXRPC_CLIENT_INITIATED; 80002a19356SDavid Howells } 80102a19356SDavid Howells 80202a19356SDavid Howells static inline bool rxrpc_sending_to_client(const struct rxrpc_txbuf *txb) 80302a19356SDavid Howells { 80402a19356SDavid Howells return !rxrpc_sending_to_server(txb); 80502a19356SDavid Howells } 80602a19356SDavid Howells 807df844fd4SDavid Howells #include <trace/events/rxrpc.h> 808df844fd4SDavid Howells 80917926a79SDavid Howells /* 810651350d1SDavid Howells * af_rxrpc.c 81117926a79SDavid Howells */ 81271f3ca40SDavid Howells extern atomic_t rxrpc_n_tx_skbs, rxrpc_n_rx_skbs; 813651350d1SDavid Howells extern struct workqueue_struct *rxrpc_workqueue; 81417926a79SDavid Howells 81517926a79SDavid Howells /* 8160d81a51aSDavid Howells * call_accept.c 81717926a79SDavid Howells */ 81800e90712SDavid Howells int rxrpc_service_prealloc(struct rxrpc_sock *, gfp_t); 81900e90712SDavid Howells void rxrpc_discard_prealloc(struct rxrpc_sock *); 820248f219cSDavid Howells struct rxrpc_call *rxrpc_new_incoming_call(struct rxrpc_local *, 8210099dc58SDavid Howells struct rxrpc_sock *, 822248f219cSDavid Howells struct sk_buff *); 8234f95dd78SDavid Howells void rxrpc_accept_incoming_calls(struct rxrpc_local *); 8242d914c1bSDavid Howells int rxrpc_user_charge_accept(struct rxrpc_sock *, unsigned long); 82517926a79SDavid Howells 82617926a79SDavid Howells /* 8270d81a51aSDavid Howells * call_event.c 82817926a79SDavid Howells */ 82972f0c6fbSDavid Howells void rxrpc_propose_ping(struct rxrpc_call *call, u32 serial, 83072f0c6fbSDavid Howells enum rxrpc_propose_ack_trace why); 83172f0c6fbSDavid Howells void rxrpc_send_ACK(struct rxrpc_call *, u8, rxrpc_serial_t, enum rxrpc_propose_ack_trace); 832530403d9SDavid Howells void rxrpc_propose_delay_ACK(struct rxrpc_call *, rxrpc_serial_t, 833530403d9SDavid Howells enum rxrpc_propose_ack_trace); 834c1b1203dSJoe Perches void rxrpc_process_call(struct work_struct *); 83517926a79SDavid Howells 8364a7f62f9SDavid Howells void rxrpc_reduce_call_timer(struct rxrpc_call *call, 837a158bdd3SDavid Howells unsigned long expire_at, 838a158bdd3SDavid Howells unsigned long now, 8394a7f62f9SDavid Howells enum rxrpc_timer_trace why); 8404a7f62f9SDavid Howells 8414a7f62f9SDavid Howells void rxrpc_delete_call_timer(struct rxrpc_call *call); 842a158bdd3SDavid Howells 84317926a79SDavid Howells /* 8440d81a51aSDavid Howells * call_object.c 84517926a79SDavid Howells */ 846f5c17aaeSDavid Howells extern const char *const rxrpc_call_states[]; 847f5c17aaeSDavid Howells extern const char *const rxrpc_call_completions[]; 84817926a79SDavid Howells extern struct kmem_cache *rxrpc_call_jar; 84917926a79SDavid Howells 8502341e077SDavid Howells struct rxrpc_call *rxrpc_find_call_by_user_ID(struct rxrpc_sock *, unsigned long); 851a25e21f0SDavid Howells struct rxrpc_call *rxrpc_alloc_call(struct rxrpc_sock *, gfp_t, unsigned int); 8522341e077SDavid Howells struct rxrpc_call *rxrpc_new_client_call(struct rxrpc_sock *, 85319ffa01cSDavid Howells struct rxrpc_conn_parameters *, 854999b69f8SDavid Howells struct sockaddr_rxrpc *, 855a25e21f0SDavid Howells struct rxrpc_call_params *, gfp_t, 856a25e21f0SDavid Howells unsigned int); 857248f219cSDavid Howells void rxrpc_incoming_call(struct rxrpc_sock *, struct rxrpc_call *, 85842886ffeSDavid Howells struct sk_buff *); 8598d94aa38SDavid Howells void rxrpc_release_call(struct rxrpc_sock *, struct rxrpc_call *); 860c1b1203dSJoe Perches void rxrpc_release_calls_on_socket(struct rxrpc_sock *); 8618d94aa38SDavid Howells bool __rxrpc_queue_call(struct rxrpc_call *); 8628d94aa38SDavid Howells bool rxrpc_queue_call(struct rxrpc_call *); 863e34d4234SDavid Howells void rxrpc_see_call(struct rxrpc_call *); 8644a7f62f9SDavid Howells bool rxrpc_try_get_call(struct rxrpc_call *call, enum rxrpc_call_trace op); 865fff72429SDavid Howells void rxrpc_get_call(struct rxrpc_call *, enum rxrpc_call_trace); 866fff72429SDavid Howells void rxrpc_put_call(struct rxrpc_call *, enum rxrpc_call_trace); 86700e90712SDavid Howells void rxrpc_cleanup_call(struct rxrpc_call *); 8682baec2c3SDavid Howells void rxrpc_destroy_all_calls(struct rxrpc_net *); 86917926a79SDavid Howells 870dabe5a79SDavid Howells static inline bool rxrpc_is_service_call(const struct rxrpc_call *call) 871dabe5a79SDavid Howells { 872dabe5a79SDavid Howells return test_bit(RXRPC_CALL_IS_SERVICE, &call->flags); 873dabe5a79SDavid Howells } 874dabe5a79SDavid Howells 875dabe5a79SDavid Howells static inline bool rxrpc_is_client_call(const struct rxrpc_call *call) 876dabe5a79SDavid Howells { 877dabe5a79SDavid Howells return !rxrpc_is_service_call(call); 878dabe5a79SDavid Howells } 879dabe5a79SDavid Howells 88017926a79SDavid Howells /* 8814a3388c8SDavid Howells * conn_client.c 8824a3388c8SDavid Howells */ 88345025bceSDavid Howells extern unsigned int rxrpc_reap_client_connections; 884a158bdd3SDavid Howells extern unsigned long rxrpc_conn_idle_client_expiry; 885a158bdd3SDavid Howells extern unsigned long rxrpc_conn_idle_client_fast_expiry; 8864a3388c8SDavid Howells extern struct idr rxrpc_client_conn_ids; 8874a3388c8SDavid Howells 888eb9b9d22SDavid Howells void rxrpc_destroy_client_conn_ids(void); 889245500d8SDavid Howells struct rxrpc_bundle *rxrpc_get_bundle(struct rxrpc_bundle *); 890245500d8SDavid Howells void rxrpc_put_bundle(struct rxrpc_bundle *); 8915e33a23bSDavid Howells int rxrpc_connect_call(struct rxrpc_sock *, struct rxrpc_call *, 8925e33a23bSDavid Howells struct rxrpc_conn_parameters *, struct sockaddr_rxrpc *, 8935e33a23bSDavid Howells gfp_t); 89445025bceSDavid Howells void rxrpc_expose_client_call(struct rxrpc_call *); 895245500d8SDavid Howells void rxrpc_disconnect_client_call(struct rxrpc_bundle *, struct rxrpc_call *); 89645025bceSDavid Howells void rxrpc_put_client_conn(struct rxrpc_connection *); 8972baec2c3SDavid Howells void rxrpc_discard_expired_client_conns(struct work_struct *); 8982baec2c3SDavid Howells void rxrpc_destroy_all_client_connections(struct rxrpc_net *); 899d12040b6SDavid Howells void rxrpc_clean_up_local_conns(struct rxrpc_local *); 9004a3388c8SDavid Howells 9014a3388c8SDavid Howells /* 9020d81a51aSDavid Howells * conn_event.c 9030d81a51aSDavid Howells */ 9040d81a51aSDavid Howells void rxrpc_process_connection(struct work_struct *); 905ddc7834aSDavid Howells void rxrpc_process_delayed_final_acks(struct rxrpc_connection *, bool); 9060d81a51aSDavid Howells 9070d81a51aSDavid Howells /* 9080d81a51aSDavid Howells * conn_object.c 90917926a79SDavid Howells */ 910dad8aff7SDavid Howells extern unsigned int rxrpc_connection_expiry; 911f859ab61SDavid Howells extern unsigned int rxrpc_closed_conn_expiry; 91217926a79SDavid Howells 913c6d2b8d7SDavid Howells struct rxrpc_connection *rxrpc_alloc_connection(gfp_t); 9148496af50SDavid Howells struct rxrpc_connection *rxrpc_find_connection_rcu(struct rxrpc_local *, 9150099dc58SDavid Howells struct sk_buff *, 9160099dc58SDavid Howells struct rxrpc_peer **); 91745025bceSDavid Howells void __rxrpc_disconnect_call(struct rxrpc_connection *, struct rxrpc_call *); 918999b69f8SDavid Howells void rxrpc_disconnect_call(struct rxrpc_call *); 91945025bceSDavid Howells void rxrpc_kill_connection(struct rxrpc_connection *); 920363deeabSDavid Howells bool rxrpc_queue_conn(struct rxrpc_connection *); 921363deeabSDavid Howells void rxrpc_see_connection(struct rxrpc_connection *); 922245500d8SDavid Howells struct rxrpc_connection *rxrpc_get_connection(struct rxrpc_connection *); 923363deeabSDavid Howells struct rxrpc_connection *rxrpc_get_connection_maybe(struct rxrpc_connection *); 924363deeabSDavid Howells void rxrpc_put_service_conn(struct rxrpc_connection *); 9252baec2c3SDavid Howells void rxrpc_service_connection_reaper(struct work_struct *); 9262baec2c3SDavid Howells void rxrpc_destroy_all_connections(struct rxrpc_net *); 92717926a79SDavid Howells 92819ffa01cSDavid Howells static inline bool rxrpc_conn_is_client(const struct rxrpc_connection *conn) 92919ffa01cSDavid Howells { 93019ffa01cSDavid Howells return conn->out_clientflag; 93119ffa01cSDavid Howells } 93219ffa01cSDavid Howells 93319ffa01cSDavid Howells static inline bool rxrpc_conn_is_service(const struct rxrpc_connection *conn) 93419ffa01cSDavid Howells { 935e8d70ce1SDavid Howells return !rxrpc_conn_is_client(conn); 93619ffa01cSDavid Howells } 93719ffa01cSDavid Howells 938f51b4480SDavid Howells static inline void rxrpc_put_connection(struct rxrpc_connection *conn) 939f51b4480SDavid Howells { 94045025bceSDavid Howells if (!conn) 94145025bceSDavid Howells return; 94245025bceSDavid Howells 943363deeabSDavid Howells if (rxrpc_conn_is_client(conn)) 94445025bceSDavid Howells rxrpc_put_client_conn(conn); 945363deeabSDavid Howells else 946363deeabSDavid Howells rxrpc_put_service_conn(conn); 9475acbee46SDavid Howells } 9485acbee46SDavid Howells 9493136ef49SDavid Howells static inline void rxrpc_reduce_conn_timer(struct rxrpc_connection *conn, 9503136ef49SDavid Howells unsigned long expire_at) 9513136ef49SDavid Howells { 9523136ef49SDavid Howells timer_reduce(&conn->timer, expire_at); 9533136ef49SDavid Howells } 9543136ef49SDavid Howells 95517926a79SDavid Howells /* 9567877a4a4SDavid Howells * conn_service.c 9577877a4a4SDavid Howells */ 9588496af50SDavid Howells struct rxrpc_connection *rxrpc_find_service_conn_rcu(struct rxrpc_peer *, 9598496af50SDavid Howells struct sk_buff *); 9602baec2c3SDavid Howells struct rxrpc_connection *rxrpc_prealloc_service_connection(struct rxrpc_net *, gfp_t); 961063c60d3SDavid Howells void rxrpc_new_incoming_connection(struct rxrpc_sock *, struct rxrpc_connection *, 962ec832bd0SDavid Howells const struct rxrpc_security *, struct sk_buff *); 963001c1122SDavid Howells void rxrpc_unpublish_service_conn(struct rxrpc_connection *); 9647877a4a4SDavid Howells 9657877a4a4SDavid Howells /* 9660d81a51aSDavid Howells * input.c 96717926a79SDavid Howells */ 9685271953cSDavid Howells int rxrpc_input_packet(struct sock *, struct sk_buff *); 96917926a79SDavid Howells 97017926a79SDavid Howells /* 9710d81a51aSDavid Howells * insecure.c 97217926a79SDavid Howells */ 9730d81a51aSDavid Howells extern const struct rxrpc_security rxrpc_no_security; 97417926a79SDavid Howells 97517926a79SDavid Howells /* 9760d81a51aSDavid Howells * key.c 97717926a79SDavid Howells */ 97817926a79SDavid Howells extern struct key_type key_type_rxrpc; 97917926a79SDavid Howells 980a7b75c5aSChristoph Hellwig int rxrpc_request_key(struct rxrpc_sock *, sockptr_t , int); 98110674a03SBaolin Wang int rxrpc_get_server_data_key(struct rxrpc_connection *, const void *, time64_t, 982c1b1203dSJoe Perches u32); 98317926a79SDavid Howells 98417926a79SDavid Howells /* 98587563616SDavid Howells * local_event.c 98687563616SDavid Howells */ 9874f95dd78SDavid Howells extern void rxrpc_process_local_events(struct rxrpc_local *); 98887563616SDavid Howells 98987563616SDavid Howells /* 9900d81a51aSDavid Howells * local_object.c 99117926a79SDavid Howells */ 9922baec2c3SDavid Howells struct rxrpc_local *rxrpc_lookup_local(struct net *, const struct sockaddr_rxrpc *); 99309d2bf59SDavid Howells struct rxrpc_local *rxrpc_get_local(struct rxrpc_local *); 99409d2bf59SDavid Howells struct rxrpc_local *rxrpc_get_local_maybe(struct rxrpc_local *); 99509d2bf59SDavid Howells void rxrpc_put_local(struct rxrpc_local *); 996730c5fd4SDavid Howells struct rxrpc_local *rxrpc_use_local(struct rxrpc_local *); 997730c5fd4SDavid Howells void rxrpc_unuse_local(struct rxrpc_local *); 99809d2bf59SDavid Howells void rxrpc_queue_local(struct rxrpc_local *); 9992baec2c3SDavid Howells void rxrpc_destroy_all_locals(struct rxrpc_net *); 1000e0e4d82fSDavid Howells 100104d36d74SDavid Howells static inline bool __rxrpc_unuse_local(struct rxrpc_local *local) 100204d36d74SDavid Howells { 100304d36d74SDavid Howells return atomic_dec_return(&local->active_users) == 0; 100404d36d74SDavid Howells } 100504d36d74SDavid Howells 100604d36d74SDavid Howells static inline bool __rxrpc_use_local(struct rxrpc_local *local) 100704d36d74SDavid Howells { 100804d36d74SDavid Howells return atomic_fetch_add_unless(&local->active_users, 1, 0) != 0; 100904d36d74SDavid Howells } 101004d36d74SDavid Howells 1011e0e4d82fSDavid Howells /* 10128e688d9cSDavid Howells * misc.c 10138e688d9cSDavid Howells */ 10140e119b41SDavid Howells extern unsigned int rxrpc_max_backlog __read_mostly; 1015a158bdd3SDavid Howells extern unsigned long rxrpc_soft_ack_delay; 1016a158bdd3SDavid Howells extern unsigned long rxrpc_idle_ack_delay; 10178e688d9cSDavid Howells extern unsigned int rxrpc_rx_window_size; 10188e688d9cSDavid Howells extern unsigned int rxrpc_rx_mtu; 10198e688d9cSDavid Howells extern unsigned int rxrpc_rx_jumbo_max; 10208e688d9cSDavid Howells 10218e688d9cSDavid Howells /* 10222baec2c3SDavid Howells * net_ns.c 10232baec2c3SDavid Howells */ 10242baec2c3SDavid Howells extern unsigned int rxrpc_net_id; 10252baec2c3SDavid Howells extern struct pernet_operations rxrpc_net_ops; 10262baec2c3SDavid Howells 10272baec2c3SDavid Howells static inline struct rxrpc_net *rxrpc_net(struct net *net) 10282baec2c3SDavid Howells { 10292baec2c3SDavid Howells return net_generic(net, rxrpc_net_id); 10302baec2c3SDavid Howells } 10312baec2c3SDavid Howells 10322baec2c3SDavid Howells /* 10330d81a51aSDavid Howells * output.c 10340d81a51aSDavid Howells */ 103572f0c6fbSDavid Howells void rxrpc_transmit_ack_packets(struct rxrpc_local *); 103626cb02aaSDavid Howells int rxrpc_send_abort_packet(struct rxrpc_call *); 1037a1767077SDavid Howells int rxrpc_send_data_packet(struct rxrpc_call *, struct sk_buff *, bool); 1038248f219cSDavid Howells void rxrpc_reject_packets(struct rxrpc_local *); 1039ace45becSDavid Howells void rxrpc_send_keepalive(struct rxrpc_peer *); 10400d81a51aSDavid Howells 10410d81a51aSDavid Howells /* 1042abe89ef0SDavid Howells * peer_event.c 10430d81a51aSDavid Howells */ 1044abe89ef0SDavid Howells void rxrpc_error_report(struct sock *); 1045ace45becSDavid Howells void rxrpc_peer_keepalive_worker(struct work_struct *); 10460d81a51aSDavid Howells 10470d81a51aSDavid Howells /* 10480d81a51aSDavid Howells * peer_object.c 10490d81a51aSDavid Howells */ 1050be6e6707SDavid Howells struct rxrpc_peer *rxrpc_lookup_peer_rcu(struct rxrpc_local *, 1051be6e6707SDavid Howells const struct sockaddr_rxrpc *); 10525e33a23bSDavid Howells struct rxrpc_peer *rxrpc_lookup_peer(struct rxrpc_sock *, struct rxrpc_local *, 1053be6e6707SDavid Howells struct sockaddr_rxrpc *, gfp_t); 1054be6e6707SDavid Howells struct rxrpc_peer *rxrpc_alloc_peer(struct rxrpc_local *, gfp_t); 10555e33a23bSDavid Howells void rxrpc_new_incoming_peer(struct rxrpc_sock *, struct rxrpc_local *, 10565e33a23bSDavid Howells struct rxrpc_peer *); 105717226f12SDavid Howells void rxrpc_destroy_all_peers(struct rxrpc_net *); 10581159d4b4SDavid Howells struct rxrpc_peer *rxrpc_get_peer(struct rxrpc_peer *); 10591159d4b4SDavid Howells struct rxrpc_peer *rxrpc_get_peer_maybe(struct rxrpc_peer *); 10601159d4b4SDavid Howells void rxrpc_put_peer(struct rxrpc_peer *); 106160034d3dSDavid Howells void rxrpc_put_peer_locked(struct rxrpc_peer *); 10620d81a51aSDavid Howells 10630d81a51aSDavid Howells /* 10640d81a51aSDavid Howells * proc.c 10650d81a51aSDavid Howells */ 1066c3506372SChristoph Hellwig extern const struct seq_operations rxrpc_call_seq_ops; 1067c3506372SChristoph Hellwig extern const struct seq_operations rxrpc_connection_seq_ops; 1068bc0e7cf4SDavid Howells extern const struct seq_operations rxrpc_peer_seq_ops; 106933912c26SDavid Howells extern const struct seq_operations rxrpc_local_seq_ops; 10700d81a51aSDavid Howells 10710d81a51aSDavid Howells /* 10720d81a51aSDavid Howells * recvmsg.c 10730d81a51aSDavid Howells */ 1074248f219cSDavid Howells void rxrpc_notify_socket(struct rxrpc_call *); 10753067bf8cSDavid Howells bool __rxrpc_set_call_completion(struct rxrpc_call *, enum rxrpc_call_completion, u32, int); 10763067bf8cSDavid Howells bool rxrpc_set_call_completion(struct rxrpc_call *, enum rxrpc_call_completion, u32, int); 10773067bf8cSDavid Howells bool __rxrpc_call_completed(struct rxrpc_call *); 10783067bf8cSDavid Howells bool rxrpc_call_completed(struct rxrpc_call *); 10793067bf8cSDavid Howells bool __rxrpc_abort_call(const char *, struct rxrpc_call *, rxrpc_seq_t, u32, int); 10803067bf8cSDavid Howells bool rxrpc_abort_call(const char *, struct rxrpc_call *, rxrpc_seq_t, u32, int); 10810d81a51aSDavid Howells int rxrpc_recvmsg(struct socket *, struct msghdr *, size_t, int); 10820d81a51aSDavid Howells 10830d81a51aSDavid Howells /* 10843067bf8cSDavid Howells * Abort a call due to a protocol error. 10853067bf8cSDavid Howells */ 10863067bf8cSDavid Howells static inline bool __rxrpc_abort_eproto(struct rxrpc_call *call, 10873067bf8cSDavid Howells struct sk_buff *skb, 10883067bf8cSDavid Howells const char *eproto_why, 10893067bf8cSDavid Howells const char *why, 10903067bf8cSDavid Howells u32 abort_code) 10913067bf8cSDavid Howells { 10923067bf8cSDavid Howells struct rxrpc_skb_priv *sp = rxrpc_skb(skb); 10933067bf8cSDavid Howells 10943067bf8cSDavid Howells trace_rxrpc_rx_eproto(call, sp->hdr.serial, eproto_why); 10953067bf8cSDavid Howells return rxrpc_abort_call(why, call, sp->hdr.seq, abort_code, -EPROTO); 10963067bf8cSDavid Howells } 10973067bf8cSDavid Howells 10983067bf8cSDavid Howells #define rxrpc_abort_eproto(call, skb, eproto_why, abort_why, abort_code) \ 10993067bf8cSDavid Howells __rxrpc_abort_eproto((call), (skb), tracepoint_string(eproto_why), \ 11003067bf8cSDavid Howells (abort_why), (abort_code)) 11013067bf8cSDavid Howells 11023067bf8cSDavid Howells /* 1103c410bf01SDavid Howells * rtt.c 1104c410bf01SDavid Howells */ 11054700c4d8SDavid Howells void rxrpc_peer_add_rtt(struct rxrpc_call *, enum rxrpc_rtt_rx_trace, int, 1106c410bf01SDavid Howells rxrpc_serial_t, rxrpc_serial_t, ktime_t, ktime_t); 1107c410bf01SDavid Howells unsigned long rxrpc_get_rto_backoff(struct rxrpc_peer *, bool); 1108c410bf01SDavid Howells void rxrpc_peer_init_rtt(struct rxrpc_peer *); 1109c410bf01SDavid Howells 1110c410bf01SDavid Howells /* 1111648af7fcSDavid Howells * rxkad.c 1112648af7fcSDavid Howells */ 1113648af7fcSDavid Howells #ifdef CONFIG_RXKAD 1114648af7fcSDavid Howells extern const struct rxrpc_security rxkad; 1115648af7fcSDavid Howells #endif 1116648af7fcSDavid Howells 1117648af7fcSDavid Howells /* 11180d81a51aSDavid Howells * security.c 11190d81a51aSDavid Howells */ 11200d81a51aSDavid Howells int __init rxrpc_init_security(void); 112112da59fcSDavid Howells const struct rxrpc_security *rxrpc_security_lookup(u8); 11220d81a51aSDavid Howells void rxrpc_exit_security(void); 11230d81a51aSDavid Howells int rxrpc_init_client_conn_security(struct rxrpc_connection *); 1124ec832bd0SDavid Howells const struct rxrpc_security *rxrpc_get_incoming_security(struct rxrpc_sock *, 1125063c60d3SDavid Howells struct sk_buff *); 1126ec832bd0SDavid Howells struct key *rxrpc_look_up_server_security(struct rxrpc_connection *, 1127ec832bd0SDavid Howells struct sk_buff *, u32, u32); 11280d81a51aSDavid Howells 11290d81a51aSDavid Howells /* 11300b58b8a1SDavid Howells * sendmsg.c 11310b58b8a1SDavid Howells */ 11320b58b8a1SDavid Howells int rxrpc_do_sendmsg(struct rxrpc_sock *, struct msghdr *, size_t); 11330b58b8a1SDavid Howells 11340b58b8a1SDavid Howells /* 1135ca7fb100SDavid Howells * server_key.c 1136ca7fb100SDavid Howells */ 1137ca7fb100SDavid Howells extern struct key_type key_type_rxrpc_s; 1138ca7fb100SDavid Howells 1139ca7fb100SDavid Howells int rxrpc_server_keyring(struct rxrpc_sock *, sockptr_t, int); 1140ca7fb100SDavid Howells 1141ca7fb100SDavid Howells /* 11420d81a51aSDavid Howells * skbuff.c 11430d81a51aSDavid Howells */ 1144d001648eSDavid Howells void rxrpc_kernel_data_consumed(struct rxrpc_call *, struct sk_buff *); 11450d81a51aSDavid Howells void rxrpc_packet_destructor(struct sk_buff *); 114671f3ca40SDavid Howells void rxrpc_new_skb(struct sk_buff *, enum rxrpc_skb_trace); 114771f3ca40SDavid Howells void rxrpc_see_skb(struct sk_buff *, enum rxrpc_skb_trace); 1148d0d5c0cdSDavid Howells void rxrpc_eaten_skb(struct sk_buff *, enum rxrpc_skb_trace); 114971f3ca40SDavid Howells void rxrpc_get_skb(struct sk_buff *, enum rxrpc_skb_trace); 115071f3ca40SDavid Howells void rxrpc_free_skb(struct sk_buff *, enum rxrpc_skb_trace); 1151df844fd4SDavid Howells void rxrpc_purge_queue(struct sk_buff_head *); 11520d81a51aSDavid Howells 11530d81a51aSDavid Howells /* 1154b0154246SDavid Howells * stats.c 1155b0154246SDavid Howells */ 1156b0154246SDavid Howells int rxrpc_stats_show(struct seq_file *seq, void *v); 1157b0154246SDavid Howells int rxrpc_stats_clear(struct file *file, char *buf, size_t size); 1158b0154246SDavid Howells 1159b0154246SDavid Howells #define rxrpc_inc_stat(rxnet, s) atomic_inc(&(rxnet)->s) 1160b0154246SDavid Howells #define rxrpc_dec_stat(rxnet, s) atomic_dec(&(rxnet)->s) 1161b0154246SDavid Howells 1162b0154246SDavid Howells /* 11635873c083SDavid Howells * sysctl.c 11645873c083SDavid Howells */ 11655873c083SDavid Howells #ifdef CONFIG_SYSCTL 11665873c083SDavid Howells extern int __init rxrpc_sysctl_init(void); 11675873c083SDavid Howells extern void rxrpc_sysctl_exit(void); 11685873c083SDavid Howells #else 11695873c083SDavid Howells static inline int __init rxrpc_sysctl_init(void) { return 0; } 11705873c083SDavid Howells static inline void rxrpc_sysctl_exit(void) {} 11715873c083SDavid Howells #endif 11725873c083SDavid Howells 11735873c083SDavid Howells /* 117402a19356SDavid Howells * txbuf.c 117502a19356SDavid Howells */ 117602a19356SDavid Howells extern atomic_t rxrpc_nr_txbuf; 117702a19356SDavid Howells struct rxrpc_txbuf *rxrpc_alloc_txbuf(struct rxrpc_call *call, u8 packet_type, 117802a19356SDavid Howells gfp_t gfp); 117902a19356SDavid Howells void rxrpc_get_txbuf(struct rxrpc_txbuf *txb, enum rxrpc_txbuf_trace what); 118002a19356SDavid Howells void rxrpc_see_txbuf(struct rxrpc_txbuf *txb, enum rxrpc_txbuf_trace what); 118102a19356SDavid Howells void rxrpc_put_txbuf(struct rxrpc_txbuf *txb, enum rxrpc_txbuf_trace what); 118202a19356SDavid Howells 118302a19356SDavid Howells /* 1184be6e6707SDavid Howells * utils.c 1185be6e6707SDavid Howells */ 11865a790b73SDavid Howells int rxrpc_extract_addr_from_skb(struct sockaddr_rxrpc *, struct sk_buff *); 1187be6e6707SDavid Howells 1188248f219cSDavid Howells static inline bool before(u32 seq1, u32 seq2) 1189248f219cSDavid Howells { 1190248f219cSDavid Howells return (s32)(seq1 - seq2) < 0; 1191248f219cSDavid Howells } 1192248f219cSDavid Howells static inline bool before_eq(u32 seq1, u32 seq2) 1193248f219cSDavid Howells { 1194248f219cSDavid Howells return (s32)(seq1 - seq2) <= 0; 1195248f219cSDavid Howells } 1196248f219cSDavid Howells static inline bool after(u32 seq1, u32 seq2) 1197248f219cSDavid Howells { 1198248f219cSDavid Howells return (s32)(seq1 - seq2) > 0; 1199248f219cSDavid Howells } 1200248f219cSDavid Howells static inline bool after_eq(u32 seq1, u32 seq2) 1201248f219cSDavid Howells { 1202248f219cSDavid Howells return (s32)(seq1 - seq2) >= 0; 1203248f219cSDavid Howells } 1204248f219cSDavid Howells 1205be6e6707SDavid Howells /* 120617926a79SDavid Howells * debug tracing 120717926a79SDavid Howells */ 120895c96174SEric Dumazet extern unsigned int rxrpc_debug; 120917926a79SDavid Howells 121017926a79SDavid Howells #define dbgprintk(FMT,...) \ 12119f389f4bSSven Schnelle printk("[%-6.6s] "FMT"\n", current->comm ,##__VA_ARGS__) 121217926a79SDavid Howells 12130dc47877SHarvey Harrison #define kenter(FMT,...) dbgprintk("==> %s("FMT")",__func__ ,##__VA_ARGS__) 12140dc47877SHarvey Harrison #define kleave(FMT,...) dbgprintk("<== %s()"FMT"",__func__ ,##__VA_ARGS__) 121517926a79SDavid Howells #define kdebug(FMT,...) dbgprintk(" "FMT ,##__VA_ARGS__) 121617926a79SDavid Howells #define kproto(FMT,...) dbgprintk("### "FMT ,##__VA_ARGS__) 121717926a79SDavid Howells #define knet(FMT,...) dbgprintk("@@@ "FMT ,##__VA_ARGS__) 121817926a79SDavid Howells 121917926a79SDavid Howells 122017926a79SDavid Howells #if defined(__KDEBUG) 122117926a79SDavid Howells #define _enter(FMT,...) kenter(FMT,##__VA_ARGS__) 122217926a79SDavid Howells #define _leave(FMT,...) kleave(FMT,##__VA_ARGS__) 122317926a79SDavid Howells #define _debug(FMT,...) kdebug(FMT,##__VA_ARGS__) 122417926a79SDavid Howells #define _proto(FMT,...) kproto(FMT,##__VA_ARGS__) 122517926a79SDavid Howells #define _net(FMT,...) knet(FMT,##__VA_ARGS__) 122617926a79SDavid Howells 122717926a79SDavid Howells #elif defined(CONFIG_AF_RXRPC_DEBUG) 122817926a79SDavid Howells #define RXRPC_DEBUG_KENTER 0x01 122917926a79SDavid Howells #define RXRPC_DEBUG_KLEAVE 0x02 123017926a79SDavid Howells #define RXRPC_DEBUG_KDEBUG 0x04 123117926a79SDavid Howells #define RXRPC_DEBUG_KPROTO 0x08 123217926a79SDavid Howells #define RXRPC_DEBUG_KNET 0x10 123317926a79SDavid Howells 123417926a79SDavid Howells #define _enter(FMT,...) \ 123517926a79SDavid Howells do { \ 123617926a79SDavid Howells if (unlikely(rxrpc_debug & RXRPC_DEBUG_KENTER)) \ 123717926a79SDavid Howells kenter(FMT,##__VA_ARGS__); \ 123817926a79SDavid Howells } while (0) 123917926a79SDavid Howells 124017926a79SDavid Howells #define _leave(FMT,...) \ 124117926a79SDavid Howells do { \ 124217926a79SDavid Howells if (unlikely(rxrpc_debug & RXRPC_DEBUG_KLEAVE)) \ 124317926a79SDavid Howells kleave(FMT,##__VA_ARGS__); \ 124417926a79SDavid Howells } while (0) 124517926a79SDavid Howells 124617926a79SDavid Howells #define _debug(FMT,...) \ 124717926a79SDavid Howells do { \ 124817926a79SDavid Howells if (unlikely(rxrpc_debug & RXRPC_DEBUG_KDEBUG)) \ 124917926a79SDavid Howells kdebug(FMT,##__VA_ARGS__); \ 125017926a79SDavid Howells } while (0) 125117926a79SDavid Howells 125217926a79SDavid Howells #define _proto(FMT,...) \ 125317926a79SDavid Howells do { \ 125417926a79SDavid Howells if (unlikely(rxrpc_debug & RXRPC_DEBUG_KPROTO)) \ 125517926a79SDavid Howells kproto(FMT,##__VA_ARGS__); \ 125617926a79SDavid Howells } while (0) 125717926a79SDavid Howells 125817926a79SDavid Howells #define _net(FMT,...) \ 125917926a79SDavid Howells do { \ 126017926a79SDavid Howells if (unlikely(rxrpc_debug & RXRPC_DEBUG_KNET)) \ 126117926a79SDavid Howells knet(FMT,##__VA_ARGS__); \ 126217926a79SDavid Howells } while (0) 126317926a79SDavid Howells 126417926a79SDavid Howells #else 126512fdff3fSDavid Howells #define _enter(FMT,...) no_printk("==> %s("FMT")",__func__ ,##__VA_ARGS__) 126612fdff3fSDavid Howells #define _leave(FMT,...) no_printk("<== %s()"FMT"",__func__ ,##__VA_ARGS__) 126712fdff3fSDavid Howells #define _debug(FMT,...) no_printk(" "FMT ,##__VA_ARGS__) 126812fdff3fSDavid Howells #define _proto(FMT,...) no_printk("### "FMT ,##__VA_ARGS__) 126912fdff3fSDavid Howells #define _net(FMT,...) no_printk("@@@ "FMT ,##__VA_ARGS__) 127017926a79SDavid Howells #endif 127117926a79SDavid Howells 127217926a79SDavid Howells /* 127317926a79SDavid Howells * debug assertion checking 127417926a79SDavid Howells */ 127517926a79SDavid Howells #if 1 // defined(__KDEBUGALL) 127617926a79SDavid Howells 127717926a79SDavid Howells #define ASSERT(X) \ 127817926a79SDavid Howells do { \ 127917926a79SDavid Howells if (unlikely(!(X))) { \ 12809b6d5398SJoe Perches pr_err("Assertion failed\n"); \ 128117926a79SDavid Howells BUG(); \ 128217926a79SDavid Howells } \ 128317926a79SDavid Howells } while (0) 128417926a79SDavid Howells 128517926a79SDavid Howells #define ASSERTCMP(X, OP, Y) \ 128617926a79SDavid Howells do { \ 1287cf13258fSDavid Howells __typeof__(X) _x = (X); \ 1288cf13258fSDavid Howells __typeof__(Y) _y = (__typeof__(X))(Y); \ 12899b6d5398SJoe Perches if (unlikely(!(_x OP _y))) { \ 12909b6d5398SJoe Perches pr_err("Assertion failed - %lu(0x%lx) %s %lu(0x%lx) is false\n", \ 1291cf13258fSDavid Howells (unsigned long)_x, (unsigned long)_x, #OP, \ 1292cf13258fSDavid Howells (unsigned long)_y, (unsigned long)_y); \ 129317926a79SDavid Howells BUG(); \ 129417926a79SDavid Howells } \ 129517926a79SDavid Howells } while (0) 129617926a79SDavid Howells 129717926a79SDavid Howells #define ASSERTIF(C, X) \ 129817926a79SDavid Howells do { \ 129917926a79SDavid Howells if (unlikely((C) && !(X))) { \ 13009b6d5398SJoe Perches pr_err("Assertion failed\n"); \ 130117926a79SDavid Howells BUG(); \ 130217926a79SDavid Howells } \ 130317926a79SDavid Howells } while (0) 130417926a79SDavid Howells 130517926a79SDavid Howells #define ASSERTIFCMP(C, X, OP, Y) \ 130617926a79SDavid Howells do { \ 1307cf13258fSDavid Howells __typeof__(X) _x = (X); \ 1308cf13258fSDavid Howells __typeof__(Y) _y = (__typeof__(X))(Y); \ 13099b6d5398SJoe Perches if (unlikely((C) && !(_x OP _y))) { \ 13109b6d5398SJoe Perches pr_err("Assertion failed - %lu(0x%lx) %s %lu(0x%lx) is false\n", \ 1311cf13258fSDavid Howells (unsigned long)_x, (unsigned long)_x, #OP, \ 1312cf13258fSDavid Howells (unsigned long)_y, (unsigned long)_y); \ 131317926a79SDavid Howells BUG(); \ 131417926a79SDavid Howells } \ 131517926a79SDavid Howells } while (0) 131617926a79SDavid Howells 131717926a79SDavid Howells #else 131817926a79SDavid Howells 131917926a79SDavid Howells #define ASSERT(X) \ 132017926a79SDavid Howells do { \ 132117926a79SDavid Howells } while (0) 132217926a79SDavid Howells 132317926a79SDavid Howells #define ASSERTCMP(X, OP, Y) \ 132417926a79SDavid Howells do { \ 132517926a79SDavid Howells } while (0) 132617926a79SDavid Howells 132717926a79SDavid Howells #define ASSERTIF(C, X) \ 132817926a79SDavid Howells do { \ 132917926a79SDavid Howells } while (0) 133017926a79SDavid Howells 133117926a79SDavid Howells #define ASSERTIFCMP(C, X, OP, Y) \ 133217926a79SDavid Howells do { \ 133317926a79SDavid Howells } while (0) 133417926a79SDavid Howells 133517926a79SDavid Howells #endif /* __KDEBUGALL */ 1336