117926a79SDavid Howells /* AF_RXRPC internal definitions 217926a79SDavid Howells * 317926a79SDavid Howells * Copyright (C) 2007 Red Hat, Inc. All Rights Reserved. 417926a79SDavid Howells * Written by David Howells (dhowells@redhat.com) 517926a79SDavid Howells * 617926a79SDavid Howells * This program is free software; you can redistribute it and/or 717926a79SDavid Howells * modify it under the terms of the GNU General Public License 817926a79SDavid Howells * as published by the Free Software Foundation; either version 917926a79SDavid Howells * 2 of the License, or (at your option) any later version. 1017926a79SDavid Howells */ 1117926a79SDavid Howells 12be6e6707SDavid Howells #include <linux/atomic.h> 138496af50SDavid Howells #include <linux/seqlock.h> 142baec2c3SDavid Howells #include <net/net_namespace.h> 152baec2c3SDavid Howells #include <net/netns/generic.h> 16e0e4d82fSDavid Howells #include <net/sock.h> 17be6e6707SDavid Howells #include <net/af_rxrpc.h> 18ddc6c70fSDavid Howells #include "protocol.h" 1917926a79SDavid Howells 2017926a79SDavid Howells #if 0 2117926a79SDavid Howells #define CHECK_SLAB_OKAY(X) \ 2217926a79SDavid Howells BUG_ON(atomic_read((X)) >> (sizeof(atomic_t) - 2) == \ 2317926a79SDavid Howells (POISON_FREE << 8 | POISON_FREE)) 2417926a79SDavid Howells #else 2517926a79SDavid Howells #define CHECK_SLAB_OKAY(X) do {} while (0) 2617926a79SDavid Howells #endif 2717926a79SDavid Howells 2817926a79SDavid Howells #define FCRYPT_BSIZE 8 2917926a79SDavid Howells struct rxrpc_crypt { 3017926a79SDavid Howells union { 3117926a79SDavid Howells u8 x[FCRYPT_BSIZE]; 3291e916cfSAl Viro __be32 n[2]; 3317926a79SDavid Howells }; 3417926a79SDavid Howells } __attribute__((aligned(8))); 3517926a79SDavid Howells 36651350d1SDavid Howells #define rxrpc_queue_work(WS) queue_work(rxrpc_workqueue, (WS)) 37651350d1SDavid Howells #define rxrpc_queue_delayed_work(WS,D) \ 38651350d1SDavid Howells queue_delayed_work(rxrpc_workqueue, (WS), (D)) 39651350d1SDavid Howells 40cc8feb8eSDavid Howells struct rxrpc_connection; 41cc8feb8eSDavid Howells 4217926a79SDavid Howells /* 43d001648eSDavid Howells * Mark applied to socket buffers. 44d001648eSDavid Howells */ 45d001648eSDavid Howells enum rxrpc_skb_mark { 46d001648eSDavid Howells RXRPC_SKB_MARK_DATA, /* data message */ 47d001648eSDavid Howells RXRPC_SKB_MARK_FINAL_ACK, /* final ACK received message */ 48d001648eSDavid Howells RXRPC_SKB_MARK_BUSY, /* server busy message */ 49d001648eSDavid Howells RXRPC_SKB_MARK_REMOTE_ABORT, /* remote abort message */ 50d001648eSDavid Howells RXRPC_SKB_MARK_LOCAL_ABORT, /* local abort message */ 51d001648eSDavid Howells RXRPC_SKB_MARK_NET_ERROR, /* network error message */ 52d001648eSDavid Howells RXRPC_SKB_MARK_LOCAL_ERROR, /* local error message */ 53d001648eSDavid Howells RXRPC_SKB_MARK_NEW_CALL, /* local error message */ 54d001648eSDavid Howells }; 55d001648eSDavid Howells 56d001648eSDavid Howells /* 5717926a79SDavid Howells * sk_state for RxRPC sockets 5817926a79SDavid Howells */ 5917926a79SDavid Howells enum { 602341e077SDavid Howells RXRPC_UNBOUND = 0, 612341e077SDavid Howells RXRPC_CLIENT_UNBOUND, /* Unbound socket used as client */ 6217926a79SDavid Howells RXRPC_CLIENT_BOUND, /* client local address bound */ 6317926a79SDavid Howells RXRPC_SERVER_BOUND, /* server local address bound */ 6428036f44SDavid Howells RXRPC_SERVER_BOUND2, /* second server local address bound */ 6517926a79SDavid Howells RXRPC_SERVER_LISTENING, /* server listening for connections */ 66210f0353SDavid Howells RXRPC_SERVER_LISTEN_DISABLED, /* server listening disabled */ 6717926a79SDavid Howells RXRPC_CLOSE, /* socket is being closed */ 6817926a79SDavid Howells }; 6917926a79SDavid Howells 7017926a79SDavid Howells /* 712baec2c3SDavid Howells * Per-network namespace data. 722baec2c3SDavid Howells */ 732baec2c3SDavid Howells struct rxrpc_net { 742baec2c3SDavid Howells struct proc_dir_entry *proc_net; /* Subdir in /proc/net */ 752baec2c3SDavid Howells u32 epoch; /* Local epoch for detecting local-end reset */ 762baec2c3SDavid Howells struct list_head calls; /* List of calls active in this namespace */ 772baec2c3SDavid Howells rwlock_t call_lock; /* Lock for ->calls */ 782baec2c3SDavid Howells 792baec2c3SDavid Howells struct list_head conn_proc_list; /* List of conns in this namespace for proc */ 802baec2c3SDavid Howells struct list_head service_conns; /* Service conns in this namespace */ 812baec2c3SDavid Howells rwlock_t conn_lock; /* Lock for ->conn_proc_list, ->service_conns */ 822baec2c3SDavid Howells struct delayed_work service_conn_reaper; 832baec2c3SDavid Howells 842baec2c3SDavid Howells unsigned int nr_client_conns; 852baec2c3SDavid Howells unsigned int nr_active_client_conns; 862baec2c3SDavid Howells bool kill_all_client_conns; 872baec2c3SDavid Howells spinlock_t client_conn_cache_lock; /* Lock for ->*_client_conns */ 882baec2c3SDavid Howells spinlock_t client_conn_discard_lock; /* Prevent multiple discarders */ 892baec2c3SDavid Howells struct list_head waiting_client_conns; 902baec2c3SDavid Howells struct list_head active_client_conns; 912baec2c3SDavid Howells struct list_head idle_client_conns; 922baec2c3SDavid Howells struct delayed_work client_conn_reaper; 932baec2c3SDavid Howells 942baec2c3SDavid Howells struct list_head local_endpoints; 952baec2c3SDavid Howells struct mutex local_mutex; /* Lock for ->local_endpoints */ 962baec2c3SDavid Howells 972baec2c3SDavid Howells spinlock_t peer_hash_lock; /* Lock for ->peer_hash */ 982baec2c3SDavid Howells DECLARE_HASHTABLE (peer_hash, 10); 992baec2c3SDavid Howells }; 1002baec2c3SDavid Howells 1012baec2c3SDavid Howells /* 10200e90712SDavid Howells * Service backlog preallocation. 10300e90712SDavid Howells * 10400e90712SDavid Howells * This contains circular buffers of preallocated peers, connections and calls 10500e90712SDavid Howells * for incoming service calls and their head and tail pointers. This allows 10600e90712SDavid Howells * calls to be set up in the data_ready handler, thereby avoiding the need to 10700e90712SDavid Howells * shuffle packets around so much. 10800e90712SDavid Howells */ 10900e90712SDavid Howells struct rxrpc_backlog { 11000e90712SDavid Howells unsigned short peer_backlog_head; 11100e90712SDavid Howells unsigned short peer_backlog_tail; 11200e90712SDavid Howells unsigned short conn_backlog_head; 11300e90712SDavid Howells unsigned short conn_backlog_tail; 11400e90712SDavid Howells unsigned short call_backlog_head; 11500e90712SDavid Howells unsigned short call_backlog_tail; 11600e90712SDavid Howells #define RXRPC_BACKLOG_MAX 32 11700e90712SDavid Howells struct rxrpc_peer *peer_backlog[RXRPC_BACKLOG_MAX]; 11800e90712SDavid Howells struct rxrpc_connection *conn_backlog[RXRPC_BACKLOG_MAX]; 11900e90712SDavid Howells struct rxrpc_call *call_backlog[RXRPC_BACKLOG_MAX]; 12000e90712SDavid Howells }; 12100e90712SDavid Howells 12200e90712SDavid Howells /* 12317926a79SDavid Howells * RxRPC socket definition 12417926a79SDavid Howells */ 12517926a79SDavid Howells struct rxrpc_sock { 12617926a79SDavid Howells /* WARNING: sk has to be the first member */ 12717926a79SDavid Howells struct sock sk; 128d001648eSDavid Howells rxrpc_notify_new_call_t notify_new_call; /* Func to notify of new call */ 12900e90712SDavid Howells rxrpc_discard_new_call_t discard_new_call; /* Func to discard a new call */ 13017926a79SDavid Howells struct rxrpc_local *local; /* local endpoint */ 13100e90712SDavid Howells struct rxrpc_backlog *backlog; /* Preallocation for services */ 132248f219cSDavid Howells spinlock_t incoming_lock; /* Incoming call vs service shutdown lock */ 133248f219cSDavid Howells struct list_head sock_calls; /* List of calls owned by this socket */ 134248f219cSDavid Howells struct list_head to_be_accepted; /* calls awaiting acceptance */ 135248f219cSDavid Howells struct list_head recvmsg_q; /* Calls awaiting recvmsg's attention */ 136248f219cSDavid Howells rwlock_t recvmsg_lock; /* Lock for recvmsg_q */ 13717926a79SDavid Howells struct key *key; /* security for this socket */ 13817926a79SDavid Howells struct key *securities; /* list of server security descriptors */ 13900e90712SDavid Howells struct rb_root calls; /* User ID -> call mapping */ 14017926a79SDavid Howells unsigned long flags; 1412341e077SDavid Howells #define RXRPC_SOCK_CONNECTED 0 /* connect_srx is set */ 14217926a79SDavid Howells rwlock_t call_lock; /* lock for calls */ 14317926a79SDavid Howells u32 min_sec_level; /* minimum security level */ 14417926a79SDavid Howells #define RXRPC_SECURITY_MAX RXRPC_SECURITY_ENCRYPT 145cc8feb8eSDavid Howells bool exclusive; /* Exclusive connection for a client socket */ 14628036f44SDavid Howells u16 second_service; /* Additional service bound to the endpoint */ 1474722974dSDavid Howells struct { 1484722974dSDavid Howells /* Service upgrade information */ 1494722974dSDavid Howells u16 from; /* Service ID to upgrade (if not 0) */ 1504722974dSDavid Howells u16 to; /* service ID to upgrade to */ 1514722974dSDavid Howells } service_upgrade; 152cc8feb8eSDavid Howells sa_family_t family; /* Protocol family created with */ 1534722974dSDavid Howells struct sockaddr_rxrpc srx; /* Primary Service/local addresses */ 1542341e077SDavid Howells struct sockaddr_rxrpc connect_srx; /* Default client address from connect() */ 15517926a79SDavid Howells }; 15617926a79SDavid Howells 15717926a79SDavid Howells #define rxrpc_sk(__sk) container_of((__sk), struct rxrpc_sock, sk) 15817926a79SDavid Howells 15917926a79SDavid Howells /* 1600d12f8a4SDavid Howells * CPU-byteorder normalised Rx packet header. 1610d12f8a4SDavid Howells */ 1620d12f8a4SDavid Howells struct rxrpc_host_header { 1630d12f8a4SDavid Howells u32 epoch; /* client boot timestamp */ 1640d12f8a4SDavid Howells u32 cid; /* connection and channel ID */ 1650d12f8a4SDavid Howells u32 callNumber; /* call ID (0 for connection-level packets) */ 1660d12f8a4SDavid Howells u32 seq; /* sequence number of pkt in call stream */ 1670d12f8a4SDavid Howells u32 serial; /* serial number of pkt sent to network */ 1680d12f8a4SDavid Howells u8 type; /* packet type */ 1690d12f8a4SDavid Howells u8 flags; /* packet flags */ 1700d12f8a4SDavid Howells u8 userStatus; /* app-layer defined status */ 1710d12f8a4SDavid Howells u8 securityIndex; /* security protocol ID */ 1720d12f8a4SDavid Howells union { 1730d12f8a4SDavid Howells u16 _rsvd; /* reserved */ 1740d12f8a4SDavid Howells u16 cksum; /* kerberos security checksum */ 1750d12f8a4SDavid Howells }; 1760d12f8a4SDavid Howells u16 serviceId; /* service ID */ 1770d12f8a4SDavid Howells } __packed; 1780d12f8a4SDavid Howells 1790d12f8a4SDavid Howells /* 18017926a79SDavid Howells * RxRPC socket buffer private variables 18117926a79SDavid Howells * - max 48 bytes (struct sk_buff::cb) 18217926a79SDavid Howells */ 18317926a79SDavid Howells struct rxrpc_skb_priv { 184248f219cSDavid Howells union { 185248f219cSDavid Howells u8 nr_jumbo; /* Number of jumbo subpackets */ 186248f219cSDavid Howells }; 18717926a79SDavid Howells union { 18817926a79SDavid Howells int remain; /* amount of space remaining for next write */ 18917926a79SDavid Howells }; 19017926a79SDavid Howells 1910d12f8a4SDavid Howells struct rxrpc_host_header hdr; /* RxRPC packet header from this packet */ 19217926a79SDavid Howells }; 19317926a79SDavid Howells 19417926a79SDavid Howells #define rxrpc_skb(__skb) ((struct rxrpc_skb_priv *) &(__skb)->cb) 19517926a79SDavid Howells 19617926a79SDavid Howells /* 19717926a79SDavid Howells * RxRPC security module interface 19817926a79SDavid Howells */ 19917926a79SDavid Howells struct rxrpc_security { 20017926a79SDavid Howells const char *name; /* name of this service */ 20117926a79SDavid Howells u8 security_index; /* security type provided */ 20217926a79SDavid Howells 203648af7fcSDavid Howells /* Initialise a security service */ 204648af7fcSDavid Howells int (*init)(void); 205648af7fcSDavid Howells 206648af7fcSDavid Howells /* Clean up a security service */ 207648af7fcSDavid Howells void (*exit)(void); 208648af7fcSDavid Howells 20917926a79SDavid Howells /* initialise a connection's security */ 21017926a79SDavid Howells int (*init_connection_security)(struct rxrpc_connection *); 21117926a79SDavid Howells 21217926a79SDavid Howells /* prime a connection's packet security */ 213a263629dSHerbert Xu int (*prime_packet_security)(struct rxrpc_connection *); 21417926a79SDavid Howells 21517926a79SDavid Howells /* impose security on a packet */ 216a263629dSHerbert Xu int (*secure_packet)(struct rxrpc_call *, 21717926a79SDavid Howells struct sk_buff *, 21817926a79SDavid Howells size_t, 21917926a79SDavid Howells void *); 22017926a79SDavid Howells 22117926a79SDavid Howells /* verify the security on a received packet */ 2225a42976dSDavid Howells int (*verify_packet)(struct rxrpc_call *, struct sk_buff *, 223248f219cSDavid Howells unsigned int, unsigned int, rxrpc_seq_t, u16); 224248f219cSDavid Howells 225248f219cSDavid Howells /* Locate the data in a received packet that has been verified. */ 226248f219cSDavid Howells void (*locate_data)(struct rxrpc_call *, struct sk_buff *, 227248f219cSDavid Howells unsigned int *, unsigned int *); 22817926a79SDavid Howells 22917926a79SDavid Howells /* issue a challenge */ 23017926a79SDavid Howells int (*issue_challenge)(struct rxrpc_connection *); 23117926a79SDavid Howells 23217926a79SDavid Howells /* respond to a challenge */ 23317926a79SDavid Howells int (*respond_to_challenge)(struct rxrpc_connection *, 23417926a79SDavid Howells struct sk_buff *, 23517926a79SDavid Howells u32 *); 23617926a79SDavid Howells 23717926a79SDavid Howells /* verify a response */ 23817926a79SDavid Howells int (*verify_response)(struct rxrpc_connection *, 23917926a79SDavid Howells struct sk_buff *, 24017926a79SDavid Howells u32 *); 24117926a79SDavid Howells 24217926a79SDavid Howells /* clear connection security */ 24317926a79SDavid Howells void (*clear)(struct rxrpc_connection *); 24417926a79SDavid Howells }; 24517926a79SDavid Howells 24617926a79SDavid Howells /* 2474f95dd78SDavid Howells * RxRPC local transport endpoint description 2484f95dd78SDavid Howells * - owned by a single AF_RXRPC socket 2494f95dd78SDavid Howells * - pointed to by transport socket struct sk_user_data 25017926a79SDavid Howells */ 25117926a79SDavid Howells struct rxrpc_local { 2524f95dd78SDavid Howells struct rcu_head rcu; 2534f95dd78SDavid Howells atomic_t usage; 2542baec2c3SDavid Howells struct rxrpc_net *rxnet; /* The network ns in which this resides */ 2554f95dd78SDavid Howells struct list_head link; 25617926a79SDavid Howells struct socket *socket; /* my UDP socket */ 2574f95dd78SDavid Howells struct work_struct processor; 2581e9e5c95SDavid Howells struct rxrpc_sock __rcu *service; /* Service(s) listening on this endpoint */ 25917926a79SDavid Howells struct rw_semaphore defrag_sem; /* control re-enablement of IP DF bit */ 26017926a79SDavid Howells struct sk_buff_head reject_queue; /* packets awaiting rejection */ 26144ba0698SDavid Howells struct sk_buff_head event_queue; /* endpoint event packets awaiting processing */ 262999b69f8SDavid Howells struct rb_root client_conns; /* Client connections by socket params */ 263999b69f8SDavid Howells spinlock_t client_conns_lock; /* Lock for client_conns */ 26417926a79SDavid Howells spinlock_t lock; /* access lock */ 26517926a79SDavid Howells rwlock_t services_lock; /* lock for services list */ 26617926a79SDavid Howells int debug_id; /* debug ID for printks */ 2674f95dd78SDavid Howells bool dead; 26817926a79SDavid Howells struct sockaddr_rxrpc srx; /* local address */ 26917926a79SDavid Howells }; 27017926a79SDavid Howells 27117926a79SDavid Howells /* 27217926a79SDavid Howells * RxRPC remote transport endpoint definition 273be6e6707SDavid Howells * - matched by local endpoint, remote port, address and protocol type 27417926a79SDavid Howells */ 27517926a79SDavid Howells struct rxrpc_peer { 276be6e6707SDavid Howells struct rcu_head rcu; /* This must be first */ 277be6e6707SDavid Howells atomic_t usage; 278be6e6707SDavid Howells unsigned long hash_key; 279be6e6707SDavid Howells struct hlist_node hash_link; 280be6e6707SDavid Howells struct rxrpc_local *local; 281f66d7490SDavid Howells struct hlist_head error_targets; /* targets for net error distribution */ 282f66d7490SDavid Howells struct work_struct error_distributor; 283aa390bbeSDavid Howells struct rb_root service_conns; /* Service connections */ 2848496af50SDavid Howells seqlock_t service_conn_lock; 28517926a79SDavid Howells spinlock_t lock; /* access lock */ 28695c96174SEric Dumazet unsigned int if_mtu; /* interface MTU for this peer */ 28795c96174SEric Dumazet unsigned int mtu; /* network MTU for this peer */ 28895c96174SEric Dumazet unsigned int maxdata; /* data size (MTU - hdrsize) */ 28917926a79SDavid Howells unsigned short hdrsize; /* header size (IP + UDP + RxRPC) */ 29017926a79SDavid Howells int debug_id; /* debug ID for printks */ 291f66d7490SDavid Howells int error_report; /* Net (+0) or local (+1000000) to distribute */ 292f66d7490SDavid Howells #define RXRPC_LOCAL_ERROR_OFFSET 1000000 29317926a79SDavid Howells struct sockaddr_rxrpc srx; /* remote address */ 29417926a79SDavid Howells 29517926a79SDavid Howells /* calculated RTT cache */ 29617926a79SDavid Howells #define RXRPC_RTT_CACHE_SIZE 32 2970d4b103cSDavid Howells ktime_t rtt_last_req; /* Time of last RTT request */ 298cf1a6474SDavid Howells u64 rtt; /* Current RTT estimate (in nS) */ 299cf1a6474SDavid Howells u64 rtt_sum; /* Sum of cache contents */ 300cf1a6474SDavid Howells u64 rtt_cache[RXRPC_RTT_CACHE_SIZE]; /* Determined RTT cache */ 301cf1a6474SDavid Howells u8 rtt_cursor; /* next entry at which to insert */ 302cf1a6474SDavid Howells u8 rtt_usage; /* amount of cache actually used */ 303f7aec129SDavid Howells 304f7aec129SDavid Howells u8 cong_cwnd; /* Congestion window size */ 30517926a79SDavid Howells }; 30617926a79SDavid Howells 30717926a79SDavid Howells /* 30819ffa01cSDavid Howells * Keys for matching a connection. 30919ffa01cSDavid Howells */ 31019ffa01cSDavid Howells struct rxrpc_conn_proto { 311e8d70ce1SDavid Howells union { 312e8d70ce1SDavid Howells struct { 31319ffa01cSDavid Howells u32 epoch; /* epoch of this connection */ 31419ffa01cSDavid Howells u32 cid; /* connection ID */ 315e8d70ce1SDavid Howells }; 316e8d70ce1SDavid Howells u64 index_key; 31719ffa01cSDavid Howells }; 31819ffa01cSDavid Howells }; 31919ffa01cSDavid Howells 32019ffa01cSDavid Howells struct rxrpc_conn_parameters { 32119ffa01cSDavid Howells struct rxrpc_local *local; /* Representation of local endpoint */ 32219ffa01cSDavid Howells struct rxrpc_peer *peer; /* Remote endpoint */ 32319ffa01cSDavid Howells struct key *key; /* Security details */ 32419ffa01cSDavid Howells bool exclusive; /* T if conn is exclusive */ 3254e255721SDavid Howells bool upgrade; /* T if service ID can be upgraded */ 32619ffa01cSDavid Howells u16 service_id; /* Service ID for this connection */ 32719ffa01cSDavid Howells u32 security_level; /* Security level selected */ 32819ffa01cSDavid Howells }; 32919ffa01cSDavid Howells 33019ffa01cSDavid Howells /* 331bba304dbSDavid Howells * Bits in the connection flags. 332bba304dbSDavid Howells */ 333bba304dbSDavid Howells enum rxrpc_conn_flag { 334bba304dbSDavid Howells RXRPC_CONN_HAS_IDR, /* Has a client conn ID assigned */ 335001c1122SDavid Howells RXRPC_CONN_IN_SERVICE_CONNS, /* Conn is in peer->service_conns */ 336001c1122SDavid Howells RXRPC_CONN_IN_CLIENT_CONNS, /* Conn is in local->client_conns */ 33745025bceSDavid Howells RXRPC_CONN_EXPOSED, /* Conn has extra ref for exposure */ 33845025bceSDavid Howells RXRPC_CONN_DONT_REUSE, /* Don't reuse this connection */ 33945025bceSDavid Howells RXRPC_CONN_COUNTED, /* Counted by rxrpc_nr_client_conns */ 3404e255721SDavid Howells RXRPC_CONN_PROBING_FOR_UPGRADE, /* Probing for service upgrade */ 3413136ef49SDavid Howells RXRPC_CONN_FINAL_ACK_0, /* Need final ACK for channel 0 */ 3423136ef49SDavid Howells RXRPC_CONN_FINAL_ACK_1, /* Need final ACK for channel 1 */ 3433136ef49SDavid Howells RXRPC_CONN_FINAL_ACK_2, /* Need final ACK for channel 2 */ 3443136ef49SDavid Howells RXRPC_CONN_FINAL_ACK_3, /* Need final ACK for channel 3 */ 345bba304dbSDavid Howells }; 346bba304dbSDavid Howells 3473136ef49SDavid Howells #define RXRPC_CONN_FINAL_ACK_MASK ((1UL << RXRPC_CONN_FINAL_ACK_0) | \ 3483136ef49SDavid Howells (1UL << RXRPC_CONN_FINAL_ACK_1) | \ 3493136ef49SDavid Howells (1UL << RXRPC_CONN_FINAL_ACK_2) | \ 3503136ef49SDavid Howells (1UL << RXRPC_CONN_FINAL_ACK_3)) 3513136ef49SDavid Howells 352bba304dbSDavid Howells /* 353bba304dbSDavid Howells * Events that can be raised upon a connection. 354bba304dbSDavid Howells */ 355bba304dbSDavid Howells enum rxrpc_conn_event { 356bba304dbSDavid Howells RXRPC_CONN_EV_CHALLENGE, /* Send challenge packet */ 357bba304dbSDavid Howells }; 358bba304dbSDavid Howells 359bba304dbSDavid Howells /* 36045025bceSDavid Howells * The connection cache state. 36145025bceSDavid Howells */ 36245025bceSDavid Howells enum rxrpc_conn_cache_state { 36345025bceSDavid Howells RXRPC_CONN_CLIENT_INACTIVE, /* Conn is not yet listed */ 36445025bceSDavid Howells RXRPC_CONN_CLIENT_WAITING, /* Conn is on wait list, waiting for capacity */ 36545025bceSDavid Howells RXRPC_CONN_CLIENT_ACTIVE, /* Conn is on active list, doing calls */ 3664e255721SDavid Howells RXRPC_CONN_CLIENT_UPGRADE, /* Conn is on active list, probing for upgrade */ 36745025bceSDavid Howells RXRPC_CONN_CLIENT_CULLED, /* Conn is culled and delisted, doing calls */ 36845025bceSDavid Howells RXRPC_CONN_CLIENT_IDLE, /* Conn is on idle list, doing mostly nothing */ 369363deeabSDavid Howells RXRPC_CONN__NR_CACHE_STATES 37045025bceSDavid Howells }; 37145025bceSDavid Howells 37245025bceSDavid Howells /* 373bba304dbSDavid Howells * The connection protocol state. 374bba304dbSDavid Howells */ 375bba304dbSDavid Howells enum rxrpc_conn_proto_state { 376bba304dbSDavid Howells RXRPC_CONN_UNUSED, /* Connection not yet attempted */ 377bba304dbSDavid Howells RXRPC_CONN_CLIENT, /* Client connection */ 37800e90712SDavid Howells RXRPC_CONN_SERVICE_PREALLOC, /* Service connection preallocation */ 379bba304dbSDavid Howells RXRPC_CONN_SERVICE_UNSECURED, /* Service unsecured connection */ 380bba304dbSDavid Howells RXRPC_CONN_SERVICE_CHALLENGING, /* Service challenging for security */ 381bba304dbSDavid Howells RXRPC_CONN_SERVICE, /* Service secured connection */ 382bba304dbSDavid Howells RXRPC_CONN_REMOTELY_ABORTED, /* Conn aborted by peer */ 383bba304dbSDavid Howells RXRPC_CONN_LOCALLY_ABORTED, /* Conn aborted locally */ 384bba304dbSDavid Howells RXRPC_CONN__NR_STATES 385bba304dbSDavid Howells }; 386bba304dbSDavid Howells 387bba304dbSDavid Howells /* 38817926a79SDavid Howells * RxRPC connection definition 389aa390bbeSDavid Howells * - matched by { local, peer, epoch, conn_id, direction } 39017926a79SDavid Howells * - each connection can only handle four simultaneous calls 39117926a79SDavid Howells */ 39217926a79SDavid Howells struct rxrpc_connection { 39319ffa01cSDavid Howells struct rxrpc_conn_proto proto; 39419ffa01cSDavid Howells struct rxrpc_conn_parameters params; 39519ffa01cSDavid Howells 39645025bceSDavid Howells atomic_t usage; 39745025bceSDavid Howells struct rcu_head rcu; 39845025bceSDavid Howells struct list_head cache_link; 399a1399f8bSDavid Howells 40045025bceSDavid Howells spinlock_t channel_lock; 40145025bceSDavid Howells unsigned char active_chans; /* Mask of active channels */ 40245025bceSDavid Howells #define RXRPC_ACTIVE_CHANS_MASK ((1 << RXRPC_MAXCALLS) - 1) 40345025bceSDavid Howells struct list_head waiting_calls; /* Calls waiting for channels */ 404a1399f8bSDavid Howells struct rxrpc_channel { 4053136ef49SDavid Howells unsigned long final_ack_at; /* Time at which to issue final ACK */ 406a1399f8bSDavid Howells struct rxrpc_call __rcu *call; /* Active call */ 407a1399f8bSDavid Howells u32 call_id; /* ID of current call */ 408a1399f8bSDavid Howells u32 call_counter; /* Call ID counter */ 409a1399f8bSDavid Howells u32 last_call; /* ID of last call */ 41018bfeba5SDavid Howells u8 last_type; /* Type of last packet */ 41118bfeba5SDavid Howells union { 41218bfeba5SDavid Howells u32 last_seq; 41318bfeba5SDavid Howells u32 last_abort; 41418bfeba5SDavid Howells }; 415a1399f8bSDavid Howells } channels[RXRPC_MAXCALLS]; 416999b69f8SDavid Howells 4173136ef49SDavid Howells struct timer_list timer; /* Conn event timer */ 41817926a79SDavid Howells struct work_struct processor; /* connection event processor */ 419999b69f8SDavid Howells union { 420999b69f8SDavid Howells struct rb_node client_node; /* Node in local->client_conns */ 421aa390bbeSDavid Howells struct rb_node service_node; /* Node in peer->service_conns */ 422999b69f8SDavid Howells }; 4234d028b2cSDavid Howells struct list_head proc_link; /* link in procfs list */ 42417926a79SDavid Howells struct list_head link; /* link in master connection list */ 42517926a79SDavid Howells struct sk_buff_head rx_queue; /* received conn-level packets */ 426648af7fcSDavid Howells const struct rxrpc_security *security; /* applied security module */ 42717926a79SDavid Howells struct key *server_key; /* security for this service */ 4281afe593bSHerbert Xu struct crypto_skcipher *cipher; /* encryption handle */ 42917926a79SDavid Howells struct rxrpc_crypt csum_iv; /* packet checksum base */ 4304a3388c8SDavid Howells unsigned long flags; 43117926a79SDavid Howells unsigned long events; 432f51b4480SDavid Howells unsigned long idle_timestamp; /* Time at which last became idle */ 43317926a79SDavid Howells spinlock_t state_lock; /* state-change lock */ 434cf13258fSDavid Howells enum rxrpc_conn_cache_state cache_state; 435cf13258fSDavid Howells enum rxrpc_conn_proto_state state; /* current state of connection */ 436dc44b3a0SDavid Howells u32 local_abort; /* local abort code */ 437dc44b3a0SDavid Howells u32 remote_abort; /* remote abort code */ 43817926a79SDavid Howells int debug_id; /* debug ID for printks */ 43917926a79SDavid Howells atomic_t serial; /* packet serial number counter */ 440563ea7d5SDavid Howells unsigned int hi_serial; /* highest serial number received */ 44117926a79SDavid Howells u32 security_nonce; /* response re-use preventer */ 44268d6d1aeSDavid Howells u16 service_id; /* Service ID, possibly upgraded */ 4435a924b89SDavid Howells u8 size_align; /* data size alignment (for security) */ 4445a924b89SDavid Howells u8 security_size; /* security header size */ 44517926a79SDavid Howells u8 security_ix; /* security type */ 44617926a79SDavid Howells u8 out_clientflag; /* RXRPC_CLIENT_INITIATED if we are client */ 44717926a79SDavid Howells }; 44817926a79SDavid Howells 44917926a79SDavid Howells /* 4505b8848d1SDavid Howells * Flags in call->flags. 4515b8848d1SDavid Howells */ 4525b8848d1SDavid Howells enum rxrpc_call_flag { 4535b8848d1SDavid Howells RXRPC_CALL_RELEASED, /* call has been released - no more message to userspace */ 4545b8848d1SDavid Howells RXRPC_CALL_HAS_USERID, /* has a user ID attached */ 455dabe5a79SDavid Howells RXRPC_CALL_IS_SERVICE, /* Call is service call */ 45645025bceSDavid Howells RXRPC_CALL_EXPOSED, /* The call was exposed to the world */ 457248f219cSDavid Howells RXRPC_CALL_RX_LAST, /* Received the last packet (at rxtx_top) */ 458248f219cSDavid Howells RXRPC_CALL_TX_LAST, /* Last packet in Tx buffer (at rxtx_top) */ 459c038a58cSDavid Howells RXRPC_CALL_TX_LASTQ, /* Last packet has been queued */ 460a5af7e1fSDavid Howells RXRPC_CALL_SEND_PING, /* A ping will need to be sent */ 4618e83134dSDavid Howells RXRPC_CALL_PINGING, /* Ping in process */ 46257494343SDavid Howells RXRPC_CALL_RETRANS_TIMEOUT, /* Retransmission due to timeout occurred */ 4635b8848d1SDavid Howells }; 4645b8848d1SDavid Howells 4655b8848d1SDavid Howells /* 4665b8848d1SDavid Howells * Events that can be raised on a call. 4675b8848d1SDavid Howells */ 4685b8848d1SDavid Howells enum rxrpc_call_event { 4694c198ad1SDavid Howells RXRPC_CALL_EV_ACK, /* need to generate ACK */ 4704c198ad1SDavid Howells RXRPC_CALL_EV_ABORT, /* need to generate abort */ 4714c198ad1SDavid Howells RXRPC_CALL_EV_RESEND, /* Tx resend required */ 472a5af7e1fSDavid Howells RXRPC_CALL_EV_PING, /* Ping send required */ 473a158bdd3SDavid Howells RXRPC_CALL_EV_EXPIRED, /* Expiry occurred */ 474bd1fdf8cSDavid Howells RXRPC_CALL_EV_ACK_LOST, /* ACK may be lost, send ping */ 4755b8848d1SDavid Howells }; 4765b8848d1SDavid Howells 4775b8848d1SDavid Howells /* 4785b8848d1SDavid Howells * The states that a call can be in. 4795b8848d1SDavid Howells */ 4805b8848d1SDavid Howells enum rxrpc_call_state { 481999b69f8SDavid Howells RXRPC_CALL_UNINITIALISED, 482999b69f8SDavid Howells RXRPC_CALL_CLIENT_AWAIT_CONN, /* - client waiting for connection to become available */ 4835b8848d1SDavid Howells RXRPC_CALL_CLIENT_SEND_REQUEST, /* - client sending request phase */ 4845b8848d1SDavid Howells RXRPC_CALL_CLIENT_AWAIT_REPLY, /* - client awaiting reply */ 4855b8848d1SDavid Howells RXRPC_CALL_CLIENT_RECV_REPLY, /* - client receiving reply phase */ 48600e90712SDavid Howells RXRPC_CALL_SERVER_PREALLOC, /* - service preallocation */ 4875b8848d1SDavid Howells RXRPC_CALL_SERVER_SECURING, /* - server securing request connection */ 4885b8848d1SDavid Howells RXRPC_CALL_SERVER_ACCEPTING, /* - server accepting request */ 4895b8848d1SDavid Howells RXRPC_CALL_SERVER_RECV_REQUEST, /* - server receiving request */ 4905b8848d1SDavid Howells RXRPC_CALL_SERVER_ACK_REQUEST, /* - server pending ACK of request */ 4915b8848d1SDavid Howells RXRPC_CALL_SERVER_SEND_REPLY, /* - server sending reply */ 4925b8848d1SDavid Howells RXRPC_CALL_SERVER_AWAIT_ACK, /* - server awaiting final ACK */ 493f5c17aaeSDavid Howells RXRPC_CALL_COMPLETE, /* - call complete */ 494f5c17aaeSDavid Howells NR__RXRPC_CALL_STATES 495f5c17aaeSDavid Howells }; 496f5c17aaeSDavid Howells 497f5c17aaeSDavid Howells /* 49857494343SDavid Howells * Call Tx congestion management modes. 49957494343SDavid Howells */ 50057494343SDavid Howells enum rxrpc_congest_mode { 50157494343SDavid Howells RXRPC_CALL_SLOW_START, 50257494343SDavid Howells RXRPC_CALL_CONGEST_AVOIDANCE, 50357494343SDavid Howells RXRPC_CALL_PACKET_LOSS, 50457494343SDavid Howells RXRPC_CALL_FAST_RETRANSMIT, 50557494343SDavid Howells NR__RXRPC_CONGEST_MODES 50657494343SDavid Howells }; 50757494343SDavid Howells 50857494343SDavid Howells /* 50917926a79SDavid Howells * RxRPC call definition 51017926a79SDavid Howells * - matched by { connection, call_id } 51117926a79SDavid Howells */ 51217926a79SDavid Howells struct rxrpc_call { 513dee46364SDavid Howells struct rcu_head rcu; 51417926a79SDavid Howells struct rxrpc_connection *conn; /* connection carrying call */ 515df5d8bf7SDavid Howells struct rxrpc_peer *peer; /* Peer record for remote address */ 5168d94aa38SDavid Howells struct rxrpc_sock __rcu *socket; /* socket responsible */ 517540b1c48SDavid Howells struct mutex user_mutex; /* User access mutex */ 518a158bdd3SDavid Howells unsigned long ack_at; /* When deferred ACK needs to happen */ 519bd1fdf8cSDavid Howells unsigned long ack_lost_at; /* When ACK is figured as lost */ 520a158bdd3SDavid Howells unsigned long resend_at; /* When next resend needs to happen */ 521a158bdd3SDavid Howells unsigned long ping_at; /* When next to send a ping */ 522415f44e4SDavid Howells unsigned long keepalive_at; /* When next to send a keepalive ping */ 523a158bdd3SDavid Howells unsigned long expect_rx_by; /* When we expect to get a packet by */ 524a158bdd3SDavid Howells unsigned long expect_req_by; /* When we expect to get a request DATA packet by */ 525a158bdd3SDavid Howells unsigned long expect_term_by; /* When we expect call termination by */ 526a158bdd3SDavid Howells u32 next_rx_timo; /* Timeout for next Rx packet (jif) */ 527a158bdd3SDavid Howells u32 next_req_timo; /* Timeout for next Rx request packet (jif) */ 528248f219cSDavid Howells struct timer_list timer; /* Combined event timer */ 529248f219cSDavid Howells struct work_struct processor; /* Event processor */ 530d001648eSDavid Howells rxrpc_notify_rx_t notify_rx; /* kernel service Rx notification function */ 53117926a79SDavid Howells struct list_head link; /* link in master call list */ 53245025bceSDavid Howells struct list_head chan_wait_link; /* Link in conn->waiting_calls */ 533f66d7490SDavid Howells struct hlist_node error_link; /* link in error distribution list */ 534248f219cSDavid Howells struct list_head accept_link; /* Link in rx->acceptq */ 535248f219cSDavid Howells struct list_head recvmsg_link; /* Link in rx->recvmsg_q */ 536248f219cSDavid Howells struct list_head sock_link; /* Link in rx->sock_calls */ 537248f219cSDavid Howells struct rb_node sock_node; /* Node in rx->calls */ 53817926a79SDavid Howells struct sk_buff *tx_pending; /* Tx socket buffer being filled */ 53945025bceSDavid Howells wait_queue_head_t waitq; /* Wait queue for channel or Tx */ 540e754eba6SDavid Howells s64 tx_total_len; /* Total length left to be transmitted (or -1) */ 541a263629dSHerbert Xu __be32 crypto_buf[2]; /* Temporary packet crypto buffer */ 54217926a79SDavid Howells unsigned long user_call_ID; /* user-defined call ID */ 54317926a79SDavid Howells unsigned long flags; 54417926a79SDavid Howells unsigned long events; 54517926a79SDavid Howells spinlock_t lock; 54620acbd9aSDavid Howells spinlock_t notify_lock; /* Kernel notification lock */ 54717926a79SDavid Howells rwlock_t state_lock; /* lock for state transition */ 548f5c17aaeSDavid Howells u32 abort_code; /* Local/remote abort code */ 549f5c17aaeSDavid Howells int error; /* Local error incurred */ 550cf13258fSDavid Howells enum rxrpc_call_state state; /* current state of call */ 551cf13258fSDavid Howells enum rxrpc_call_completion completion; /* Call completion condition */ 55217926a79SDavid Howells atomic_t usage; 553dabe5a79SDavid Howells u16 service_id; /* service ID */ 554278ac0cdSDavid Howells u8 security_ix; /* Security type */ 555dabe5a79SDavid Howells u32 call_id; /* call ID on connection */ 556dabe5a79SDavid Howells u32 cid; /* connection ID plus channel index */ 557dabe5a79SDavid Howells int debug_id; /* debug ID for printks */ 5588e83134dSDavid Howells unsigned short rx_pkt_offset; /* Current recvmsg packet offset */ 5598e83134dSDavid Howells unsigned short rx_pkt_len; /* Current recvmsg packet len */ 56017926a79SDavid Howells 561248f219cSDavid Howells /* Rx/Tx circular buffer, depending on phase. 562248f219cSDavid Howells * 563248f219cSDavid Howells * In the Rx phase, packets are annotated with 0 or the number of the 564248f219cSDavid Howells * segment of a jumbo packet each buffer refers to. There can be up to 565248f219cSDavid Howells * 47 segments in a maximum-size UDP packet. 566248f219cSDavid Howells * 567248f219cSDavid Howells * In the Tx phase, packets are annotated with which buffers have been 568248f219cSDavid Howells * acked. 56917926a79SDavid Howells */ 570248f219cSDavid Howells #define RXRPC_RXTX_BUFF_SIZE 64 571248f219cSDavid Howells #define RXRPC_RXTX_BUFF_MASK (RXRPC_RXTX_BUFF_SIZE - 1) 57275e42126SDavid Howells #define RXRPC_INIT_RX_WINDOW_SIZE 32 573248f219cSDavid Howells struct sk_buff **rxtx_buffer; 574248f219cSDavid Howells u8 *rxtx_annotations; 575248f219cSDavid Howells #define RXRPC_TX_ANNO_ACK 0 576248f219cSDavid Howells #define RXRPC_TX_ANNO_UNACK 1 577248f219cSDavid Howells #define RXRPC_TX_ANNO_NAK 2 578248f219cSDavid Howells #define RXRPC_TX_ANNO_RETRANS 3 579f07373eaSDavid Howells #define RXRPC_TX_ANNO_MASK 0x03 58070790dbeSDavid Howells #define RXRPC_TX_ANNO_LAST 0x04 58170790dbeSDavid Howells #define RXRPC_TX_ANNO_RESENT 0x08 58270790dbeSDavid Howells 583248f219cSDavid Howells #define RXRPC_RX_ANNO_JUMBO 0x3f /* Jumbo subpacket number + 1 if not zero */ 584248f219cSDavid Howells #define RXRPC_RX_ANNO_JLAST 0x40 /* Set if last element of a jumbo packet */ 585248f219cSDavid Howells #define RXRPC_RX_ANNO_VERIFIED 0x80 /* Set if verified and decrypted */ 586248f219cSDavid Howells rxrpc_seq_t tx_hard_ack; /* Dead slot in buffer; the first transmitted but 587248f219cSDavid Howells * not hard-ACK'd packet follows this. 588248f219cSDavid Howells */ 589248f219cSDavid Howells rxrpc_seq_t tx_top; /* Highest Tx slot allocated. */ 59057494343SDavid Howells 59157494343SDavid Howells /* TCP-style slow-start congestion control [RFC5681]. Since the SMSS 59257494343SDavid Howells * is fixed, we keep these numbers in terms of segments (ie. DATA 59357494343SDavid Howells * packets) rather than bytes. 59457494343SDavid Howells */ 59557494343SDavid Howells #define RXRPC_TX_SMSS RXRPC_JUMBO_DATALEN 59657494343SDavid Howells u8 cong_cwnd; /* Congestion window size */ 59757494343SDavid Howells u8 cong_extra; /* Extra to send for congestion management */ 59857494343SDavid Howells u8 cong_ssthresh; /* Slow-start threshold */ 59957494343SDavid Howells enum rxrpc_congest_mode cong_mode:8; /* Congestion management mode */ 60057494343SDavid Howells u8 cong_dup_acks; /* Count of ACKs showing missing packets */ 60157494343SDavid Howells u8 cong_cumul_acks; /* Cumulative ACK count */ 60257494343SDavid Howells ktime_t cong_tstamp; /* Last time cwnd was changed */ 60357494343SDavid Howells 604248f219cSDavid Howells rxrpc_seq_t rx_hard_ack; /* Dead slot in buffer; the first received but not 605248f219cSDavid Howells * consumed packet follows this. 606248f219cSDavid Howells */ 607248f219cSDavid Howells rxrpc_seq_t rx_top; /* Highest Rx slot allocated. */ 608248f219cSDavid Howells rxrpc_seq_t rx_expect_next; /* Expected next packet sequence number */ 609248f219cSDavid Howells u8 rx_winsize; /* Size of Rx window */ 610248f219cSDavid Howells u8 tx_winsize; /* Maximum size of Tx window */ 61171f3ca40SDavid Howells bool tx_phase; /* T if transmission phase, F if receive phase */ 61275e42126SDavid Howells u8 nr_jumbo_bad; /* Number of jumbo dups/exceeds-windows */ 61317926a79SDavid Howells 61417926a79SDavid Howells /* receive-phase ACK management */ 6154e36a95eSDavid Howells u8 ackr_reason; /* reason to ACK */ 616563ea7d5SDavid Howells u16 ackr_skew; /* skew on packet being ACK'd */ 6170d12f8a4SDavid Howells rxrpc_serial_t ackr_serial; /* serial of packet being ACK'd */ 618248f219cSDavid Howells rxrpc_seq_t ackr_prev_seq; /* previous sequence number received */ 619805b21b9SDavid Howells rxrpc_seq_t ackr_consumed; /* Highest packet shown consumed */ 620805b21b9SDavid Howells rxrpc_seq_t ackr_seen; /* Highest packet shown seen */ 621a5af7e1fSDavid Howells 622a5af7e1fSDavid Howells /* ping management */ 623a5af7e1fSDavid Howells rxrpc_serial_t ping_serial; /* Last ping sent */ 624a5af7e1fSDavid Howells ktime_t ping_time; /* Time last ping sent */ 62517926a79SDavid Howells 626248f219cSDavid Howells /* transmission-phase ACK management */ 62757494343SDavid Howells ktime_t acks_latest_ts; /* Timestamp of latest ACK received */ 628248f219cSDavid Howells rxrpc_serial_t acks_latest; /* serial number of latest ACK received */ 62931a1b989SDavid Howells rxrpc_seq_t acks_lowest_nak; /* Lowest NACK in the buffer (or ==tx_hard_ack) */ 630bd1fdf8cSDavid Howells rxrpc_seq_t acks_lost_top; /* tx_top at the time lost-ack ping sent */ 631bd1fdf8cSDavid Howells rxrpc_serial_t acks_lost_ping; /* Serial number of probe ACK */ 63231a1b989SDavid Howells }; 63331a1b989SDavid Howells 63431a1b989SDavid Howells /* 63557494343SDavid Howells * Summary of a new ACK and the changes it made to the Tx buffer packet states. 63631a1b989SDavid Howells */ 63731a1b989SDavid Howells struct rxrpc_ack_summary { 63831a1b989SDavid Howells u8 ack_reason; 63931a1b989SDavid Howells u8 nr_acks; /* Number of ACKs in packet */ 64031a1b989SDavid Howells u8 nr_nacks; /* Number of NACKs in packet */ 64131a1b989SDavid Howells u8 nr_new_acks; /* Number of new ACKs in packet */ 64231a1b989SDavid Howells u8 nr_new_nacks; /* Number of new NACKs in packet */ 64331a1b989SDavid Howells u8 nr_rot_new_acks; /* Number of rotated new ACKs */ 64431a1b989SDavid Howells bool new_low_nack; /* T if new low NACK found */ 64557494343SDavid Howells bool retrans_timeo; /* T if reTx due to timeout happened */ 64657494343SDavid Howells u8 flight_size; /* Number of unreceived transmissions */ 64757494343SDavid Howells /* Place to stash values for tracing */ 64857494343SDavid Howells enum rxrpc_congest_mode mode:8; 64957494343SDavid Howells u8 cwnd; 65057494343SDavid Howells u8 ssthresh; 65157494343SDavid Howells u8 dup_acks; 65257494343SDavid Howells u8 cumulative_acks; 65317926a79SDavid Howells }; 65417926a79SDavid Howells 65548124178SDavid Howells /* 65648124178SDavid Howells * sendmsg() cmsg-specified parameters. 65748124178SDavid Howells */ 65848124178SDavid Howells enum rxrpc_command { 65948124178SDavid Howells RXRPC_CMD_SEND_DATA, /* send data message */ 66048124178SDavid Howells RXRPC_CMD_SEND_ABORT, /* request abort generation */ 66148124178SDavid Howells RXRPC_CMD_ACCEPT, /* [server] accept incoming call */ 66248124178SDavid Howells RXRPC_CMD_REJECT_BUSY, /* [server] reject a call as busy */ 66348124178SDavid Howells }; 66448124178SDavid Howells 66548124178SDavid Howells struct rxrpc_call_params { 66648124178SDavid Howells s64 tx_total_len; /* Total Tx data length (if send data) */ 66748124178SDavid Howells unsigned long user_call_ID; /* User's call ID */ 66848124178SDavid Howells struct { 66948124178SDavid Howells u32 hard; /* Maximum lifetime (sec) */ 67048124178SDavid Howells u32 idle; /* Max time since last data packet (msec) */ 67148124178SDavid Howells u32 normal; /* Max time since last call packet (msec) */ 67248124178SDavid Howells } timeouts; 67348124178SDavid Howells u8 nr_timeouts; /* Number of timeouts specified */ 67448124178SDavid Howells }; 67548124178SDavid Howells 67648124178SDavid Howells struct rxrpc_send_params { 67748124178SDavid Howells struct rxrpc_call_params call; 67848124178SDavid Howells u32 abort_code; /* Abort code to Tx (if abort) */ 67948124178SDavid Howells enum rxrpc_command command : 8; /* The command to implement */ 68048124178SDavid Howells bool exclusive; /* Shared or exclusive call */ 68148124178SDavid Howells bool upgrade; /* If the connection is upgradeable */ 68248124178SDavid Howells }; 68348124178SDavid Howells 684df844fd4SDavid Howells #include <trace/events/rxrpc.h> 685df844fd4SDavid Howells 68617926a79SDavid Howells /* 687651350d1SDavid Howells * af_rxrpc.c 68817926a79SDavid Howells */ 68971f3ca40SDavid Howells extern atomic_t rxrpc_n_tx_skbs, rxrpc_n_rx_skbs; 690651350d1SDavid Howells extern atomic_t rxrpc_debug_id; 691651350d1SDavid Howells extern struct workqueue_struct *rxrpc_workqueue; 69217926a79SDavid Howells 69317926a79SDavid Howells /* 6940d81a51aSDavid Howells * call_accept.c 69517926a79SDavid Howells */ 69600e90712SDavid Howells int rxrpc_service_prealloc(struct rxrpc_sock *, gfp_t); 69700e90712SDavid Howells void rxrpc_discard_prealloc(struct rxrpc_sock *); 698248f219cSDavid Howells struct rxrpc_call *rxrpc_new_incoming_call(struct rxrpc_local *, 699248f219cSDavid Howells struct rxrpc_connection *, 700248f219cSDavid Howells struct sk_buff *); 7014f95dd78SDavid Howells void rxrpc_accept_incoming_calls(struct rxrpc_local *); 702d001648eSDavid Howells struct rxrpc_call *rxrpc_accept_call(struct rxrpc_sock *, unsigned long, 703d001648eSDavid Howells rxrpc_notify_rx_t); 704c1b1203dSJoe Perches int rxrpc_reject_call(struct rxrpc_sock *); 70517926a79SDavid Howells 70617926a79SDavid Howells /* 7070d81a51aSDavid Howells * call_event.c 70817926a79SDavid Howells */ 7099c7ad434SDavid Howells void rxrpc_propose_ACK(struct rxrpc_call *, u8, u16, u32, bool, bool, 7109c7ad434SDavid Howells enum rxrpc_propose_ack_trace); 711c1b1203dSJoe Perches void rxrpc_process_call(struct work_struct *); 71217926a79SDavid Howells 713a158bdd3SDavid Howells static inline void rxrpc_reduce_call_timer(struct rxrpc_call *call, 714a158bdd3SDavid Howells unsigned long expire_at, 715a158bdd3SDavid Howells unsigned long now, 716a158bdd3SDavid Howells enum rxrpc_timer_trace why) 717a158bdd3SDavid Howells { 718a158bdd3SDavid Howells trace_rxrpc_timer(call, why, now); 719a158bdd3SDavid Howells timer_reduce(&call->timer, expire_at); 720a158bdd3SDavid Howells } 721a158bdd3SDavid Howells 72217926a79SDavid Howells /* 7230d81a51aSDavid Howells * call_object.c 72417926a79SDavid Howells */ 725f5c17aaeSDavid Howells extern const char *const rxrpc_call_states[]; 726f5c17aaeSDavid Howells extern const char *const rxrpc_call_completions[]; 727dad8aff7SDavid Howells extern unsigned int rxrpc_max_call_lifetime; 72817926a79SDavid Howells extern struct kmem_cache *rxrpc_call_jar; 72917926a79SDavid Howells 7302341e077SDavid Howells struct rxrpc_call *rxrpc_find_call_by_user_ID(struct rxrpc_sock *, unsigned long); 7319faaff59SDavid Howells struct rxrpc_call *rxrpc_alloc_call(struct rxrpc_sock *, gfp_t); 7322341e077SDavid Howells struct rxrpc_call *rxrpc_new_client_call(struct rxrpc_sock *, 73319ffa01cSDavid Howells struct rxrpc_conn_parameters *, 734999b69f8SDavid Howells struct sockaddr_rxrpc *, 73548124178SDavid Howells struct rxrpc_call_params *, gfp_t); 736c038a58cSDavid Howells int rxrpc_retry_client_call(struct rxrpc_sock *, 737c038a58cSDavid Howells struct rxrpc_call *, 738c038a58cSDavid Howells struct rxrpc_conn_parameters *, 739c038a58cSDavid Howells struct sockaddr_rxrpc *, 740c038a58cSDavid Howells gfp_t); 741248f219cSDavid Howells void rxrpc_incoming_call(struct rxrpc_sock *, struct rxrpc_call *, 74242886ffeSDavid Howells struct sk_buff *); 7438d94aa38SDavid Howells void rxrpc_release_call(struct rxrpc_sock *, struct rxrpc_call *); 744c038a58cSDavid Howells int rxrpc_prepare_call_for_retry(struct rxrpc_sock *, struct rxrpc_call *); 745c1b1203dSJoe Perches void rxrpc_release_calls_on_socket(struct rxrpc_sock *); 7468d94aa38SDavid Howells bool __rxrpc_queue_call(struct rxrpc_call *); 7478d94aa38SDavid Howells bool rxrpc_queue_call(struct rxrpc_call *); 748e34d4234SDavid Howells void rxrpc_see_call(struct rxrpc_call *); 749fff72429SDavid Howells void rxrpc_get_call(struct rxrpc_call *, enum rxrpc_call_trace); 750fff72429SDavid Howells void rxrpc_put_call(struct rxrpc_call *, enum rxrpc_call_trace); 75100e90712SDavid Howells void rxrpc_cleanup_call(struct rxrpc_call *); 7522baec2c3SDavid Howells void rxrpc_destroy_all_calls(struct rxrpc_net *); 75317926a79SDavid Howells 754dabe5a79SDavid Howells static inline bool rxrpc_is_service_call(const struct rxrpc_call *call) 755dabe5a79SDavid Howells { 756dabe5a79SDavid Howells return test_bit(RXRPC_CALL_IS_SERVICE, &call->flags); 757dabe5a79SDavid Howells } 758dabe5a79SDavid Howells 759dabe5a79SDavid Howells static inline bool rxrpc_is_client_call(const struct rxrpc_call *call) 760dabe5a79SDavid Howells { 761dabe5a79SDavid Howells return !rxrpc_is_service_call(call); 762dabe5a79SDavid Howells } 763dabe5a79SDavid Howells 76417926a79SDavid Howells /* 765f5c17aaeSDavid Howells * Transition a call to the complete state. 766f5c17aaeSDavid Howells */ 767f5c17aaeSDavid Howells static inline bool __rxrpc_set_call_completion(struct rxrpc_call *call, 768f5c17aaeSDavid Howells enum rxrpc_call_completion compl, 769f5c17aaeSDavid Howells u32 abort_code, 770f5c17aaeSDavid Howells int error) 771f5c17aaeSDavid Howells { 772f5c17aaeSDavid Howells if (call->state < RXRPC_CALL_COMPLETE) { 773f5c17aaeSDavid Howells call->abort_code = abort_code; 774f5c17aaeSDavid Howells call->error = error; 775f5c17aaeSDavid Howells call->completion = compl, 776f5c17aaeSDavid Howells call->state = RXRPC_CALL_COMPLETE; 777c0d058c2SDavid Howells wake_up(&call->waitq); 778f5c17aaeSDavid Howells return true; 779f5c17aaeSDavid Howells } 780f5c17aaeSDavid Howells return false; 781f5c17aaeSDavid Howells } 782f5c17aaeSDavid Howells 783f5c17aaeSDavid Howells static inline bool rxrpc_set_call_completion(struct rxrpc_call *call, 784f5c17aaeSDavid Howells enum rxrpc_call_completion compl, 785f5c17aaeSDavid Howells u32 abort_code, 786f5c17aaeSDavid Howells int error) 787f5c17aaeSDavid Howells { 788e8d6bbb0SDavid Howells bool ret; 789f5c17aaeSDavid Howells 790f5c17aaeSDavid Howells write_lock_bh(&call->state_lock); 791f5c17aaeSDavid Howells ret = __rxrpc_set_call_completion(call, compl, abort_code, error); 792f5c17aaeSDavid Howells write_unlock_bh(&call->state_lock); 793f5c17aaeSDavid Howells return ret; 794f5c17aaeSDavid Howells } 795f5c17aaeSDavid Howells 796f5c17aaeSDavid Howells /* 797f5c17aaeSDavid Howells * Record that a call successfully completed. 798f5c17aaeSDavid Howells */ 799e8d6bbb0SDavid Howells static inline bool __rxrpc_call_completed(struct rxrpc_call *call) 800f5c17aaeSDavid Howells { 801e8d6bbb0SDavid Howells return __rxrpc_set_call_completion(call, RXRPC_CALL_SUCCEEDED, 0, 0); 802f5c17aaeSDavid Howells } 803f5c17aaeSDavid Howells 804e8d6bbb0SDavid Howells static inline bool rxrpc_call_completed(struct rxrpc_call *call) 805f5c17aaeSDavid Howells { 806e8d6bbb0SDavid Howells bool ret; 807e8d6bbb0SDavid Howells 808f5c17aaeSDavid Howells write_lock_bh(&call->state_lock); 809e8d6bbb0SDavid Howells ret = __rxrpc_call_completed(call); 810f5c17aaeSDavid Howells write_unlock_bh(&call->state_lock); 811e8d6bbb0SDavid Howells return ret; 812f5c17aaeSDavid Howells } 813f5c17aaeSDavid Howells 814f5c17aaeSDavid Howells /* 815f5c17aaeSDavid Howells * Record that a call is locally aborted. 816f5c17aaeSDavid Howells */ 8175a42976dSDavid Howells static inline bool __rxrpc_abort_call(const char *why, struct rxrpc_call *call, 8185a42976dSDavid Howells rxrpc_seq_t seq, 819f5c17aaeSDavid Howells u32 abort_code, int error) 820f5c17aaeSDavid Howells { 8215a42976dSDavid Howells trace_rxrpc_abort(why, call->cid, call->call_id, seq, 8225a42976dSDavid Howells abort_code, error); 823248f219cSDavid Howells return __rxrpc_set_call_completion(call, RXRPC_CALL_LOCALLY_ABORTED, 824248f219cSDavid Howells abort_code, error); 825f5c17aaeSDavid Howells } 826f5c17aaeSDavid Howells 8275a42976dSDavid Howells static inline bool rxrpc_abort_call(const char *why, struct rxrpc_call *call, 8285a42976dSDavid Howells rxrpc_seq_t seq, u32 abort_code, int error) 829f5c17aaeSDavid Howells { 830f5c17aaeSDavid Howells bool ret; 831f5c17aaeSDavid Howells 832f5c17aaeSDavid Howells write_lock_bh(&call->state_lock); 8335a42976dSDavid Howells ret = __rxrpc_abort_call(why, call, seq, abort_code, error); 834f5c17aaeSDavid Howells write_unlock_bh(&call->state_lock); 835f5c17aaeSDavid Howells return ret; 836f5c17aaeSDavid Howells } 837f5c17aaeSDavid Howells 838f5c17aaeSDavid Howells /* 839fb46f6eeSDavid Howells * Abort a call due to a protocol error. 840fb46f6eeSDavid Howells */ 841fb46f6eeSDavid Howells static inline bool __rxrpc_abort_eproto(struct rxrpc_call *call, 842fb46f6eeSDavid Howells struct sk_buff *skb, 843fb46f6eeSDavid Howells const char *eproto_why, 844fb46f6eeSDavid Howells const char *why, 845fb46f6eeSDavid Howells u32 abort_code) 846fb46f6eeSDavid Howells { 847fb46f6eeSDavid Howells struct rxrpc_skb_priv *sp = rxrpc_skb(skb); 848fb46f6eeSDavid Howells 849fb46f6eeSDavid Howells trace_rxrpc_rx_eproto(call, sp->hdr.serial, eproto_why); 850fb46f6eeSDavid Howells return rxrpc_abort_call(why, call, sp->hdr.seq, abort_code, -EPROTO); 851fb46f6eeSDavid Howells } 852fb46f6eeSDavid Howells 853fb46f6eeSDavid Howells #define rxrpc_abort_eproto(call, skb, eproto_why, abort_why, abort_code) \ 854fb46f6eeSDavid Howells __rxrpc_abort_eproto((call), (skb), tracepoint_string(eproto_why), \ 855fb46f6eeSDavid Howells (abort_why), (abort_code)) 856fb46f6eeSDavid Howells 857fb46f6eeSDavid Howells /* 8584a3388c8SDavid Howells * conn_client.c 8594a3388c8SDavid Howells */ 86045025bceSDavid Howells extern unsigned int rxrpc_max_client_connections; 86145025bceSDavid Howells extern unsigned int rxrpc_reap_client_connections; 862a158bdd3SDavid Howells extern unsigned long rxrpc_conn_idle_client_expiry; 863a158bdd3SDavid Howells extern unsigned long rxrpc_conn_idle_client_fast_expiry; 8644a3388c8SDavid Howells extern struct idr rxrpc_client_conn_ids; 8654a3388c8SDavid Howells 866eb9b9d22SDavid Howells void rxrpc_destroy_client_conn_ids(void); 867c6d2b8d7SDavid Howells int rxrpc_connect_call(struct rxrpc_call *, struct rxrpc_conn_parameters *, 868c6d2b8d7SDavid Howells struct sockaddr_rxrpc *, gfp_t); 86945025bceSDavid Howells void rxrpc_expose_client_call(struct rxrpc_call *); 87045025bceSDavid Howells void rxrpc_disconnect_client_call(struct rxrpc_call *); 87145025bceSDavid Howells void rxrpc_put_client_conn(struct rxrpc_connection *); 8722baec2c3SDavid Howells void rxrpc_discard_expired_client_conns(struct work_struct *); 8732baec2c3SDavid Howells void rxrpc_destroy_all_client_connections(struct rxrpc_net *); 8744a3388c8SDavid Howells 8754a3388c8SDavid Howells /* 8760d81a51aSDavid Howells * conn_event.c 8770d81a51aSDavid Howells */ 8780d81a51aSDavid Howells void rxrpc_process_connection(struct work_struct *); 8790d81a51aSDavid Howells 8800d81a51aSDavid Howells /* 8810d81a51aSDavid Howells * conn_object.c 88217926a79SDavid Howells */ 883dad8aff7SDavid Howells extern unsigned int rxrpc_connection_expiry; 88417926a79SDavid Howells 885c6d2b8d7SDavid Howells struct rxrpc_connection *rxrpc_alloc_connection(gfp_t); 8868496af50SDavid Howells struct rxrpc_connection *rxrpc_find_connection_rcu(struct rxrpc_local *, 887aa390bbeSDavid Howells struct sk_buff *); 88845025bceSDavid Howells void __rxrpc_disconnect_call(struct rxrpc_connection *, struct rxrpc_call *); 889999b69f8SDavid Howells void rxrpc_disconnect_call(struct rxrpc_call *); 89045025bceSDavid Howells void rxrpc_kill_connection(struct rxrpc_connection *); 891363deeabSDavid Howells bool rxrpc_queue_conn(struct rxrpc_connection *); 892363deeabSDavid Howells void rxrpc_see_connection(struct rxrpc_connection *); 893363deeabSDavid Howells void rxrpc_get_connection(struct rxrpc_connection *); 894363deeabSDavid Howells struct rxrpc_connection *rxrpc_get_connection_maybe(struct rxrpc_connection *); 895363deeabSDavid Howells void rxrpc_put_service_conn(struct rxrpc_connection *); 8962baec2c3SDavid Howells void rxrpc_service_connection_reaper(struct work_struct *); 8972baec2c3SDavid Howells void rxrpc_destroy_all_connections(struct rxrpc_net *); 89817926a79SDavid Howells 89919ffa01cSDavid Howells static inline bool rxrpc_conn_is_client(const struct rxrpc_connection *conn) 90019ffa01cSDavid Howells { 90119ffa01cSDavid Howells return conn->out_clientflag; 90219ffa01cSDavid Howells } 90319ffa01cSDavid Howells 90419ffa01cSDavid Howells static inline bool rxrpc_conn_is_service(const struct rxrpc_connection *conn) 90519ffa01cSDavid Howells { 906e8d70ce1SDavid Howells return !rxrpc_conn_is_client(conn); 90719ffa01cSDavid Howells } 90819ffa01cSDavid Howells 909f51b4480SDavid Howells static inline void rxrpc_put_connection(struct rxrpc_connection *conn) 910f51b4480SDavid Howells { 91145025bceSDavid Howells if (!conn) 91245025bceSDavid Howells return; 91345025bceSDavid Howells 914363deeabSDavid Howells if (rxrpc_conn_is_client(conn)) 91545025bceSDavid Howells rxrpc_put_client_conn(conn); 916363deeabSDavid Howells else 917363deeabSDavid Howells rxrpc_put_service_conn(conn); 9185acbee46SDavid Howells } 9195acbee46SDavid Howells 9203136ef49SDavid Howells static inline void rxrpc_reduce_conn_timer(struct rxrpc_connection *conn, 9213136ef49SDavid Howells unsigned long expire_at) 9223136ef49SDavid Howells { 9233136ef49SDavid Howells timer_reduce(&conn->timer, expire_at); 9243136ef49SDavid Howells } 9253136ef49SDavid Howells 92617926a79SDavid Howells /* 9277877a4a4SDavid Howells * conn_service.c 9287877a4a4SDavid Howells */ 9298496af50SDavid Howells struct rxrpc_connection *rxrpc_find_service_conn_rcu(struct rxrpc_peer *, 9308496af50SDavid Howells struct sk_buff *); 9312baec2c3SDavid Howells struct rxrpc_connection *rxrpc_prealloc_service_connection(struct rxrpc_net *, gfp_t); 9324722974dSDavid Howells void rxrpc_new_incoming_connection(struct rxrpc_sock *, 9334722974dSDavid Howells struct rxrpc_connection *, struct sk_buff *); 934001c1122SDavid Howells void rxrpc_unpublish_service_conn(struct rxrpc_connection *); 9357877a4a4SDavid Howells 9367877a4a4SDavid Howells /* 9370d81a51aSDavid Howells * input.c 93817926a79SDavid Howells */ 939676d2369SDavid S. Miller void rxrpc_data_ready(struct sock *); 94017926a79SDavid Howells 94117926a79SDavid Howells /* 9420d81a51aSDavid Howells * insecure.c 94317926a79SDavid Howells */ 9440d81a51aSDavid Howells extern const struct rxrpc_security rxrpc_no_security; 94517926a79SDavid Howells 94617926a79SDavid Howells /* 9470d81a51aSDavid Howells * key.c 94817926a79SDavid Howells */ 94917926a79SDavid Howells extern struct key_type key_type_rxrpc; 95017926a79SDavid Howells extern struct key_type key_type_rxrpc_s; 95117926a79SDavid Howells 952c1b1203dSJoe Perches int rxrpc_request_key(struct rxrpc_sock *, char __user *, int); 953c1b1203dSJoe Perches int rxrpc_server_keyring(struct rxrpc_sock *, char __user *, int); 95410674a03SBaolin Wang int rxrpc_get_server_data_key(struct rxrpc_connection *, const void *, time64_t, 955c1b1203dSJoe Perches u32); 95617926a79SDavid Howells 95717926a79SDavid Howells /* 95887563616SDavid Howells * local_event.c 95987563616SDavid Howells */ 9604f95dd78SDavid Howells extern void rxrpc_process_local_events(struct rxrpc_local *); 96187563616SDavid Howells 96287563616SDavid Howells /* 9630d81a51aSDavid Howells * local_object.c 96417926a79SDavid Howells */ 9652baec2c3SDavid Howells struct rxrpc_local *rxrpc_lookup_local(struct net *, const struct sockaddr_rxrpc *); 9664f95dd78SDavid Howells void __rxrpc_put_local(struct rxrpc_local *); 9672baec2c3SDavid Howells void rxrpc_destroy_all_locals(struct rxrpc_net *); 968e0e4d82fSDavid Howells 9694f95dd78SDavid Howells static inline void rxrpc_get_local(struct rxrpc_local *local) 9704f95dd78SDavid Howells { 9714f95dd78SDavid Howells atomic_inc(&local->usage); 9724f95dd78SDavid Howells } 9734f95dd78SDavid Howells 9744f95dd78SDavid Howells static inline 9754f95dd78SDavid Howells struct rxrpc_local *rxrpc_get_local_maybe(struct rxrpc_local *local) 9764f95dd78SDavid Howells { 9774f95dd78SDavid Howells return atomic_inc_not_zero(&local->usage) ? local : NULL; 9784f95dd78SDavid Howells } 9794f95dd78SDavid Howells 9804f95dd78SDavid Howells static inline void rxrpc_put_local(struct rxrpc_local *local) 9814f95dd78SDavid Howells { 9825627cc8bSDavid Howells if (local && atomic_dec_and_test(&local->usage)) 9834f95dd78SDavid Howells __rxrpc_put_local(local); 9844f95dd78SDavid Howells } 9854f95dd78SDavid Howells 9865acbee46SDavid Howells static inline void rxrpc_queue_local(struct rxrpc_local *local) 9875acbee46SDavid Howells { 9885acbee46SDavid Howells rxrpc_queue_work(&local->processor); 9895acbee46SDavid Howells } 9905acbee46SDavid Howells 991e0e4d82fSDavid Howells /* 9928e688d9cSDavid Howells * misc.c 9938e688d9cSDavid Howells */ 9940e119b41SDavid Howells extern unsigned int rxrpc_max_backlog __read_mostly; 995a158bdd3SDavid Howells extern unsigned long rxrpc_requested_ack_delay; 996a158bdd3SDavid Howells extern unsigned long rxrpc_soft_ack_delay; 997a158bdd3SDavid Howells extern unsigned long rxrpc_idle_ack_delay; 9988e688d9cSDavid Howells extern unsigned int rxrpc_rx_window_size; 9998e688d9cSDavid Howells extern unsigned int rxrpc_rx_mtu; 10008e688d9cSDavid Howells extern unsigned int rxrpc_rx_jumbo_max; 1001a158bdd3SDavid Howells extern unsigned long rxrpc_resend_timeout; 10028e688d9cSDavid Howells 10038e688d9cSDavid Howells extern const s8 rxrpc_ack_priority[]; 10048e688d9cSDavid Howells 10058e688d9cSDavid Howells /* 10062baec2c3SDavid Howells * net_ns.c 10072baec2c3SDavid Howells */ 10082baec2c3SDavid Howells extern unsigned int rxrpc_net_id; 10092baec2c3SDavid Howells extern struct pernet_operations rxrpc_net_ops; 10102baec2c3SDavid Howells 10112baec2c3SDavid Howells static inline struct rxrpc_net *rxrpc_net(struct net *net) 10122baec2c3SDavid Howells { 10132baec2c3SDavid Howells return net_generic(net, rxrpc_net_id); 10142baec2c3SDavid Howells } 10152baec2c3SDavid Howells 10162baec2c3SDavid Howells /* 10170d81a51aSDavid Howells * output.c 10180d81a51aSDavid Howells */ 1019bd1fdf8cSDavid Howells int rxrpc_send_ack_packet(struct rxrpc_call *, bool, rxrpc_serial_t *); 102026cb02aaSDavid Howells int rxrpc_send_abort_packet(struct rxrpc_call *); 1021a1767077SDavid Howells int rxrpc_send_data_packet(struct rxrpc_call *, struct sk_buff *, bool); 1022248f219cSDavid Howells void rxrpc_reject_packets(struct rxrpc_local *); 10230d81a51aSDavid Howells 10240d81a51aSDavid Howells /* 1025abe89ef0SDavid Howells * peer_event.c 10260d81a51aSDavid Howells */ 1027abe89ef0SDavid Howells void rxrpc_error_report(struct sock *); 1028f66d7490SDavid Howells void rxrpc_peer_error_distributor(struct work_struct *); 1029cf1a6474SDavid Howells void rxrpc_peer_add_rtt(struct rxrpc_call *, enum rxrpc_rtt_rx_trace, 1030cf1a6474SDavid Howells rxrpc_serial_t, rxrpc_serial_t, ktime_t, ktime_t); 10310d81a51aSDavid Howells 10320d81a51aSDavid Howells /* 10330d81a51aSDavid Howells * peer_object.c 10340d81a51aSDavid Howells */ 1035be6e6707SDavid Howells struct rxrpc_peer *rxrpc_lookup_peer_rcu(struct rxrpc_local *, 1036be6e6707SDavid Howells const struct sockaddr_rxrpc *); 1037be6e6707SDavid Howells struct rxrpc_peer *rxrpc_lookup_peer(struct rxrpc_local *, 1038be6e6707SDavid Howells struct sockaddr_rxrpc *, gfp_t); 1039be6e6707SDavid Howells struct rxrpc_peer *rxrpc_alloc_peer(struct rxrpc_local *, gfp_t); 1040248f219cSDavid Howells struct rxrpc_peer *rxrpc_lookup_incoming_peer(struct rxrpc_local *, 1041248f219cSDavid Howells struct rxrpc_peer *); 1042be6e6707SDavid Howells 1043df5d8bf7SDavid Howells static inline struct rxrpc_peer *rxrpc_get_peer(struct rxrpc_peer *peer) 1044be6e6707SDavid Howells { 1045be6e6707SDavid Howells atomic_inc(&peer->usage); 1046df5d8bf7SDavid Howells return peer; 1047be6e6707SDavid Howells } 1048be6e6707SDavid Howells 1049be6e6707SDavid Howells static inline 1050be6e6707SDavid Howells struct rxrpc_peer *rxrpc_get_peer_maybe(struct rxrpc_peer *peer) 1051be6e6707SDavid Howells { 1052be6e6707SDavid Howells return atomic_inc_not_zero(&peer->usage) ? peer : NULL; 1053be6e6707SDavid Howells } 1054be6e6707SDavid Howells 1055be6e6707SDavid Howells extern void __rxrpc_put_peer(struct rxrpc_peer *peer); 1056be6e6707SDavid Howells static inline void rxrpc_put_peer(struct rxrpc_peer *peer) 1057be6e6707SDavid Howells { 10585627cc8bSDavid Howells if (peer && atomic_dec_and_test(&peer->usage)) 1059be6e6707SDavid Howells __rxrpc_put_peer(peer); 1060be6e6707SDavid Howells } 10610d81a51aSDavid Howells 10620d81a51aSDavid Howells /* 10630d81a51aSDavid Howells * proc.c 10640d81a51aSDavid Howells */ 10650d81a51aSDavid Howells extern const struct file_operations rxrpc_call_seq_fops; 10660d81a51aSDavid Howells extern const struct file_operations rxrpc_connection_seq_fops; 10670d81a51aSDavid Howells 10680d81a51aSDavid Howells /* 10690d81a51aSDavid Howells * recvmsg.c 10700d81a51aSDavid Howells */ 1071248f219cSDavid Howells void rxrpc_notify_socket(struct rxrpc_call *); 10720d81a51aSDavid Howells int rxrpc_recvmsg(struct socket *, struct msghdr *, size_t, int); 10730d81a51aSDavid Howells 10740d81a51aSDavid Howells /* 1075648af7fcSDavid Howells * rxkad.c 1076648af7fcSDavid Howells */ 1077648af7fcSDavid Howells #ifdef CONFIG_RXKAD 1078648af7fcSDavid Howells extern const struct rxrpc_security rxkad; 1079648af7fcSDavid Howells #endif 1080648af7fcSDavid Howells 1081648af7fcSDavid Howells /* 10820d81a51aSDavid Howells * security.c 10830d81a51aSDavid Howells */ 10840d81a51aSDavid Howells int __init rxrpc_init_security(void); 10850d81a51aSDavid Howells void rxrpc_exit_security(void); 10860d81a51aSDavid Howells int rxrpc_init_client_conn_security(struct rxrpc_connection *); 10870d81a51aSDavid Howells int rxrpc_init_server_conn_security(struct rxrpc_connection *); 10880d81a51aSDavid Howells 10890d81a51aSDavid Howells /* 10900b58b8a1SDavid Howells * sendmsg.c 10910b58b8a1SDavid Howells */ 10920b58b8a1SDavid Howells int rxrpc_do_sendmsg(struct rxrpc_sock *, struct msghdr *, size_t); 10930b58b8a1SDavid Howells 10940b58b8a1SDavid Howells /* 10950d81a51aSDavid Howells * skbuff.c 10960d81a51aSDavid Howells */ 1097d001648eSDavid Howells void rxrpc_kernel_data_consumed(struct rxrpc_call *, struct sk_buff *); 10980d81a51aSDavid Howells void rxrpc_packet_destructor(struct sk_buff *); 109971f3ca40SDavid Howells void rxrpc_new_skb(struct sk_buff *, enum rxrpc_skb_trace); 110071f3ca40SDavid Howells void rxrpc_see_skb(struct sk_buff *, enum rxrpc_skb_trace); 110171f3ca40SDavid Howells void rxrpc_get_skb(struct sk_buff *, enum rxrpc_skb_trace); 110271f3ca40SDavid Howells void rxrpc_free_skb(struct sk_buff *, enum rxrpc_skb_trace); 110371f3ca40SDavid Howells void rxrpc_lose_skb(struct sk_buff *, enum rxrpc_skb_trace); 1104df844fd4SDavid Howells void rxrpc_purge_queue(struct sk_buff_head *); 11050d81a51aSDavid Howells 11060d81a51aSDavid Howells /* 11075873c083SDavid Howells * sysctl.c 11085873c083SDavid Howells */ 11095873c083SDavid Howells #ifdef CONFIG_SYSCTL 11105873c083SDavid Howells extern int __init rxrpc_sysctl_init(void); 11115873c083SDavid Howells extern void rxrpc_sysctl_exit(void); 11125873c083SDavid Howells #else 11135873c083SDavid Howells static inline int __init rxrpc_sysctl_init(void) { return 0; } 11145873c083SDavid Howells static inline void rxrpc_sysctl_exit(void) {} 11155873c083SDavid Howells #endif 11165873c083SDavid Howells 11175873c083SDavid Howells /* 1118be6e6707SDavid Howells * utils.c 1119be6e6707SDavid Howells */ 11207b674e39SDavid Howells int rxrpc_extract_addr_from_skb(struct rxrpc_local *, struct sockaddr_rxrpc *, 11217b674e39SDavid Howells struct sk_buff *); 1122be6e6707SDavid Howells 1123248f219cSDavid Howells static inline bool before(u32 seq1, u32 seq2) 1124248f219cSDavid Howells { 1125248f219cSDavid Howells return (s32)(seq1 - seq2) < 0; 1126248f219cSDavid Howells } 1127248f219cSDavid Howells static inline bool before_eq(u32 seq1, u32 seq2) 1128248f219cSDavid Howells { 1129248f219cSDavid Howells return (s32)(seq1 - seq2) <= 0; 1130248f219cSDavid Howells } 1131248f219cSDavid Howells static inline bool after(u32 seq1, u32 seq2) 1132248f219cSDavid Howells { 1133248f219cSDavid Howells return (s32)(seq1 - seq2) > 0; 1134248f219cSDavid Howells } 1135248f219cSDavid Howells static inline bool after_eq(u32 seq1, u32 seq2) 1136248f219cSDavid Howells { 1137248f219cSDavid Howells return (s32)(seq1 - seq2) >= 0; 1138248f219cSDavid Howells } 1139248f219cSDavid Howells 1140be6e6707SDavid Howells /* 114117926a79SDavid Howells * debug tracing 114217926a79SDavid Howells */ 114395c96174SEric Dumazet extern unsigned int rxrpc_debug; 114417926a79SDavid Howells 114517926a79SDavid Howells #define dbgprintk(FMT,...) \ 11469f389f4bSSven Schnelle printk("[%-6.6s] "FMT"\n", current->comm ,##__VA_ARGS__) 114717926a79SDavid Howells 11480dc47877SHarvey Harrison #define kenter(FMT,...) dbgprintk("==> %s("FMT")",__func__ ,##__VA_ARGS__) 11490dc47877SHarvey Harrison #define kleave(FMT,...) dbgprintk("<== %s()"FMT"",__func__ ,##__VA_ARGS__) 115017926a79SDavid Howells #define kdebug(FMT,...) dbgprintk(" "FMT ,##__VA_ARGS__) 115117926a79SDavid Howells #define kproto(FMT,...) dbgprintk("### "FMT ,##__VA_ARGS__) 115217926a79SDavid Howells #define knet(FMT,...) dbgprintk("@@@ "FMT ,##__VA_ARGS__) 115317926a79SDavid Howells 115417926a79SDavid Howells 115517926a79SDavid Howells #if defined(__KDEBUG) 115617926a79SDavid Howells #define _enter(FMT,...) kenter(FMT,##__VA_ARGS__) 115717926a79SDavid Howells #define _leave(FMT,...) kleave(FMT,##__VA_ARGS__) 115817926a79SDavid Howells #define _debug(FMT,...) kdebug(FMT,##__VA_ARGS__) 115917926a79SDavid Howells #define _proto(FMT,...) kproto(FMT,##__VA_ARGS__) 116017926a79SDavid Howells #define _net(FMT,...) knet(FMT,##__VA_ARGS__) 116117926a79SDavid Howells 116217926a79SDavid Howells #elif defined(CONFIG_AF_RXRPC_DEBUG) 116317926a79SDavid Howells #define RXRPC_DEBUG_KENTER 0x01 116417926a79SDavid Howells #define RXRPC_DEBUG_KLEAVE 0x02 116517926a79SDavid Howells #define RXRPC_DEBUG_KDEBUG 0x04 116617926a79SDavid Howells #define RXRPC_DEBUG_KPROTO 0x08 116717926a79SDavid Howells #define RXRPC_DEBUG_KNET 0x10 116817926a79SDavid Howells 116917926a79SDavid Howells #define _enter(FMT,...) \ 117017926a79SDavid Howells do { \ 117117926a79SDavid Howells if (unlikely(rxrpc_debug & RXRPC_DEBUG_KENTER)) \ 117217926a79SDavid Howells kenter(FMT,##__VA_ARGS__); \ 117317926a79SDavid Howells } while (0) 117417926a79SDavid Howells 117517926a79SDavid Howells #define _leave(FMT,...) \ 117617926a79SDavid Howells do { \ 117717926a79SDavid Howells if (unlikely(rxrpc_debug & RXRPC_DEBUG_KLEAVE)) \ 117817926a79SDavid Howells kleave(FMT,##__VA_ARGS__); \ 117917926a79SDavid Howells } while (0) 118017926a79SDavid Howells 118117926a79SDavid Howells #define _debug(FMT,...) \ 118217926a79SDavid Howells do { \ 118317926a79SDavid Howells if (unlikely(rxrpc_debug & RXRPC_DEBUG_KDEBUG)) \ 118417926a79SDavid Howells kdebug(FMT,##__VA_ARGS__); \ 118517926a79SDavid Howells } while (0) 118617926a79SDavid Howells 118717926a79SDavid Howells #define _proto(FMT,...) \ 118817926a79SDavid Howells do { \ 118917926a79SDavid Howells if (unlikely(rxrpc_debug & RXRPC_DEBUG_KPROTO)) \ 119017926a79SDavid Howells kproto(FMT,##__VA_ARGS__); \ 119117926a79SDavid Howells } while (0) 119217926a79SDavid Howells 119317926a79SDavid Howells #define _net(FMT,...) \ 119417926a79SDavid Howells do { \ 119517926a79SDavid Howells if (unlikely(rxrpc_debug & RXRPC_DEBUG_KNET)) \ 119617926a79SDavid Howells knet(FMT,##__VA_ARGS__); \ 119717926a79SDavid Howells } while (0) 119817926a79SDavid Howells 119917926a79SDavid Howells #else 120012fdff3fSDavid Howells #define _enter(FMT,...) no_printk("==> %s("FMT")",__func__ ,##__VA_ARGS__) 120112fdff3fSDavid Howells #define _leave(FMT,...) no_printk("<== %s()"FMT"",__func__ ,##__VA_ARGS__) 120212fdff3fSDavid Howells #define _debug(FMT,...) no_printk(" "FMT ,##__VA_ARGS__) 120312fdff3fSDavid Howells #define _proto(FMT,...) no_printk("### "FMT ,##__VA_ARGS__) 120412fdff3fSDavid Howells #define _net(FMT,...) no_printk("@@@ "FMT ,##__VA_ARGS__) 120517926a79SDavid Howells #endif 120617926a79SDavid Howells 120717926a79SDavid Howells /* 120817926a79SDavid Howells * debug assertion checking 120917926a79SDavid Howells */ 121017926a79SDavid Howells #if 1 // defined(__KDEBUGALL) 121117926a79SDavid Howells 121217926a79SDavid Howells #define ASSERT(X) \ 121317926a79SDavid Howells do { \ 121417926a79SDavid Howells if (unlikely(!(X))) { \ 12159b6d5398SJoe Perches pr_err("Assertion failed\n"); \ 121617926a79SDavid Howells BUG(); \ 121717926a79SDavid Howells } \ 121817926a79SDavid Howells } while (0) 121917926a79SDavid Howells 122017926a79SDavid Howells #define ASSERTCMP(X, OP, Y) \ 122117926a79SDavid Howells do { \ 1222cf13258fSDavid Howells __typeof__(X) _x = (X); \ 1223cf13258fSDavid Howells __typeof__(Y) _y = (__typeof__(X))(Y); \ 12249b6d5398SJoe Perches if (unlikely(!(_x OP _y))) { \ 12259b6d5398SJoe Perches pr_err("Assertion failed - %lu(0x%lx) %s %lu(0x%lx) is false\n", \ 1226cf13258fSDavid Howells (unsigned long)_x, (unsigned long)_x, #OP, \ 1227cf13258fSDavid Howells (unsigned long)_y, (unsigned long)_y); \ 122817926a79SDavid Howells BUG(); \ 122917926a79SDavid Howells } \ 123017926a79SDavid Howells } while (0) 123117926a79SDavid Howells 123217926a79SDavid Howells #define ASSERTIF(C, X) \ 123317926a79SDavid Howells do { \ 123417926a79SDavid Howells if (unlikely((C) && !(X))) { \ 12359b6d5398SJoe Perches pr_err("Assertion failed\n"); \ 123617926a79SDavid Howells BUG(); \ 123717926a79SDavid Howells } \ 123817926a79SDavid Howells } while (0) 123917926a79SDavid Howells 124017926a79SDavid Howells #define ASSERTIFCMP(C, X, OP, Y) \ 124117926a79SDavid Howells do { \ 1242cf13258fSDavid Howells __typeof__(X) _x = (X); \ 1243cf13258fSDavid Howells __typeof__(Y) _y = (__typeof__(X))(Y); \ 12449b6d5398SJoe Perches if (unlikely((C) && !(_x OP _y))) { \ 12459b6d5398SJoe Perches pr_err("Assertion failed - %lu(0x%lx) %s %lu(0x%lx) is false\n", \ 1246cf13258fSDavid Howells (unsigned long)_x, (unsigned long)_x, #OP, \ 1247cf13258fSDavid Howells (unsigned long)_y, (unsigned long)_y); \ 124817926a79SDavid Howells BUG(); \ 124917926a79SDavid Howells } \ 125017926a79SDavid Howells } while (0) 125117926a79SDavid Howells 125217926a79SDavid Howells #else 125317926a79SDavid Howells 125417926a79SDavid Howells #define ASSERT(X) \ 125517926a79SDavid Howells do { \ 125617926a79SDavid Howells } while (0) 125717926a79SDavid Howells 125817926a79SDavid Howells #define ASSERTCMP(X, OP, Y) \ 125917926a79SDavid Howells do { \ 126017926a79SDavid Howells } while (0) 126117926a79SDavid Howells 126217926a79SDavid Howells #define ASSERTIF(C, X) \ 126317926a79SDavid Howells do { \ 126417926a79SDavid Howells } while (0) 126517926a79SDavid Howells 126617926a79SDavid Howells #define ASSERTIFCMP(C, X, OP, Y) \ 126717926a79SDavid Howells do { \ 126817926a79SDavid Howells } while (0) 126917926a79SDavid Howells 127017926a79SDavid Howells #endif /* __KDEBUGALL */ 1271