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> 1817926a79SDavid Howells #include <rxrpc/packet.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 */ 147cc8feb8eSDavid Howells sa_family_t family; /* Protocol family created with */ 14817926a79SDavid Howells struct sockaddr_rxrpc srx; /* local address */ 1492341e077SDavid Howells struct sockaddr_rxrpc connect_srx; /* Default client address from connect() */ 15017926a79SDavid Howells }; 15117926a79SDavid Howells 15217926a79SDavid Howells #define rxrpc_sk(__sk) container_of((__sk), struct rxrpc_sock, sk) 15317926a79SDavid Howells 15417926a79SDavid Howells /* 1550d12f8a4SDavid Howells * CPU-byteorder normalised Rx packet header. 1560d12f8a4SDavid Howells */ 1570d12f8a4SDavid Howells struct rxrpc_host_header { 1580d12f8a4SDavid Howells u32 epoch; /* client boot timestamp */ 1590d12f8a4SDavid Howells u32 cid; /* connection and channel ID */ 1600d12f8a4SDavid Howells u32 callNumber; /* call ID (0 for connection-level packets) */ 1610d12f8a4SDavid Howells u32 seq; /* sequence number of pkt in call stream */ 1620d12f8a4SDavid Howells u32 serial; /* serial number of pkt sent to network */ 1630d12f8a4SDavid Howells u8 type; /* packet type */ 1640d12f8a4SDavid Howells u8 flags; /* packet flags */ 1650d12f8a4SDavid Howells u8 userStatus; /* app-layer defined status */ 1660d12f8a4SDavid Howells u8 securityIndex; /* security protocol ID */ 1670d12f8a4SDavid Howells union { 1680d12f8a4SDavid Howells u16 _rsvd; /* reserved */ 1690d12f8a4SDavid Howells u16 cksum; /* kerberos security checksum */ 1700d12f8a4SDavid Howells }; 1710d12f8a4SDavid Howells u16 serviceId; /* service ID */ 1720d12f8a4SDavid Howells } __packed; 1730d12f8a4SDavid Howells 1740d12f8a4SDavid Howells /* 17517926a79SDavid Howells * RxRPC socket buffer private variables 17617926a79SDavid Howells * - max 48 bytes (struct sk_buff::cb) 17717926a79SDavid Howells */ 17817926a79SDavid Howells struct rxrpc_skb_priv { 179248f219cSDavid Howells union { 180248f219cSDavid Howells u8 nr_jumbo; /* Number of jumbo subpackets */ 181248f219cSDavid Howells }; 18217926a79SDavid Howells union { 18317926a79SDavid Howells int remain; /* amount of space remaining for next write */ 18417926a79SDavid Howells }; 18517926a79SDavid Howells 1860d12f8a4SDavid Howells struct rxrpc_host_header hdr; /* RxRPC packet header from this packet */ 18717926a79SDavid Howells }; 18817926a79SDavid Howells 18917926a79SDavid Howells #define rxrpc_skb(__skb) ((struct rxrpc_skb_priv *) &(__skb)->cb) 19017926a79SDavid Howells 19117926a79SDavid Howells /* 19217926a79SDavid Howells * RxRPC security module interface 19317926a79SDavid Howells */ 19417926a79SDavid Howells struct rxrpc_security { 19517926a79SDavid Howells const char *name; /* name of this service */ 19617926a79SDavid Howells u8 security_index; /* security type provided */ 19717926a79SDavid Howells 198648af7fcSDavid Howells /* Initialise a security service */ 199648af7fcSDavid Howells int (*init)(void); 200648af7fcSDavid Howells 201648af7fcSDavid Howells /* Clean up a security service */ 202648af7fcSDavid Howells void (*exit)(void); 203648af7fcSDavid Howells 20417926a79SDavid Howells /* initialise a connection's security */ 20517926a79SDavid Howells int (*init_connection_security)(struct rxrpc_connection *); 20617926a79SDavid Howells 20717926a79SDavid Howells /* prime a connection's packet security */ 208a263629dSHerbert Xu int (*prime_packet_security)(struct rxrpc_connection *); 20917926a79SDavid Howells 21017926a79SDavid Howells /* impose security on a packet */ 211a263629dSHerbert Xu int (*secure_packet)(struct rxrpc_call *, 21217926a79SDavid Howells struct sk_buff *, 21317926a79SDavid Howells size_t, 21417926a79SDavid Howells void *); 21517926a79SDavid Howells 21617926a79SDavid Howells /* verify the security on a received packet */ 2175a42976dSDavid Howells int (*verify_packet)(struct rxrpc_call *, struct sk_buff *, 218248f219cSDavid Howells unsigned int, unsigned int, rxrpc_seq_t, u16); 219248f219cSDavid Howells 220248f219cSDavid Howells /* Locate the data in a received packet that has been verified. */ 221248f219cSDavid Howells void (*locate_data)(struct rxrpc_call *, struct sk_buff *, 222248f219cSDavid Howells unsigned int *, unsigned int *); 22317926a79SDavid Howells 22417926a79SDavid Howells /* issue a challenge */ 22517926a79SDavid Howells int (*issue_challenge)(struct rxrpc_connection *); 22617926a79SDavid Howells 22717926a79SDavid Howells /* respond to a challenge */ 22817926a79SDavid Howells int (*respond_to_challenge)(struct rxrpc_connection *, 22917926a79SDavid Howells struct sk_buff *, 23017926a79SDavid Howells u32 *); 23117926a79SDavid Howells 23217926a79SDavid Howells /* verify a response */ 23317926a79SDavid Howells int (*verify_response)(struct rxrpc_connection *, 23417926a79SDavid Howells struct sk_buff *, 23517926a79SDavid Howells u32 *); 23617926a79SDavid Howells 23717926a79SDavid Howells /* clear connection security */ 23817926a79SDavid Howells void (*clear)(struct rxrpc_connection *); 23917926a79SDavid Howells }; 24017926a79SDavid Howells 24117926a79SDavid Howells /* 2424f95dd78SDavid Howells * RxRPC local transport endpoint description 2434f95dd78SDavid Howells * - owned by a single AF_RXRPC socket 2444f95dd78SDavid Howells * - pointed to by transport socket struct sk_user_data 24517926a79SDavid Howells */ 24617926a79SDavid Howells struct rxrpc_local { 2474f95dd78SDavid Howells struct rcu_head rcu; 2484f95dd78SDavid Howells atomic_t usage; 2492baec2c3SDavid Howells struct rxrpc_net *rxnet; /* The network ns in which this resides */ 2504f95dd78SDavid Howells struct list_head link; 25117926a79SDavid Howells struct socket *socket; /* my UDP socket */ 2524f95dd78SDavid Howells struct work_struct processor; 2531e9e5c95SDavid Howells struct rxrpc_sock __rcu *service; /* Service(s) listening on this endpoint */ 25417926a79SDavid Howells struct rw_semaphore defrag_sem; /* control re-enablement of IP DF bit */ 25517926a79SDavid Howells struct sk_buff_head reject_queue; /* packets awaiting rejection */ 25644ba0698SDavid Howells struct sk_buff_head event_queue; /* endpoint event packets awaiting processing */ 257999b69f8SDavid Howells struct rb_root client_conns; /* Client connections by socket params */ 258999b69f8SDavid Howells spinlock_t client_conns_lock; /* Lock for client_conns */ 25917926a79SDavid Howells spinlock_t lock; /* access lock */ 26017926a79SDavid Howells rwlock_t services_lock; /* lock for services list */ 26117926a79SDavid Howells int debug_id; /* debug ID for printks */ 2624f95dd78SDavid Howells bool dead; 26317926a79SDavid Howells struct sockaddr_rxrpc srx; /* local address */ 26417926a79SDavid Howells }; 26517926a79SDavid Howells 26617926a79SDavid Howells /* 26717926a79SDavid Howells * RxRPC remote transport endpoint definition 268be6e6707SDavid Howells * - matched by local endpoint, remote port, address and protocol type 26917926a79SDavid Howells */ 27017926a79SDavid Howells struct rxrpc_peer { 271be6e6707SDavid Howells struct rcu_head rcu; /* This must be first */ 272be6e6707SDavid Howells atomic_t usage; 273be6e6707SDavid Howells unsigned long hash_key; 274be6e6707SDavid Howells struct hlist_node hash_link; 275be6e6707SDavid Howells struct rxrpc_local *local; 276f66d7490SDavid Howells struct hlist_head error_targets; /* targets for net error distribution */ 277f66d7490SDavid Howells struct work_struct error_distributor; 278aa390bbeSDavid Howells struct rb_root service_conns; /* Service connections */ 2798496af50SDavid Howells seqlock_t service_conn_lock; 28017926a79SDavid Howells spinlock_t lock; /* access lock */ 28195c96174SEric Dumazet unsigned int if_mtu; /* interface MTU for this peer */ 28295c96174SEric Dumazet unsigned int mtu; /* network MTU for this peer */ 28395c96174SEric Dumazet unsigned int maxdata; /* data size (MTU - hdrsize) */ 28417926a79SDavid Howells unsigned short hdrsize; /* header size (IP + UDP + RxRPC) */ 28517926a79SDavid Howells int debug_id; /* debug ID for printks */ 286f66d7490SDavid Howells int error_report; /* Net (+0) or local (+1000000) to distribute */ 287f66d7490SDavid Howells #define RXRPC_LOCAL_ERROR_OFFSET 1000000 28817926a79SDavid Howells struct sockaddr_rxrpc srx; /* remote address */ 28917926a79SDavid Howells 29017926a79SDavid Howells /* calculated RTT cache */ 29117926a79SDavid Howells #define RXRPC_RTT_CACHE_SIZE 32 2920d4b103cSDavid Howells ktime_t rtt_last_req; /* Time of last RTT request */ 293cf1a6474SDavid Howells u64 rtt; /* Current RTT estimate (in nS) */ 294cf1a6474SDavid Howells u64 rtt_sum; /* Sum of cache contents */ 295cf1a6474SDavid Howells u64 rtt_cache[RXRPC_RTT_CACHE_SIZE]; /* Determined RTT cache */ 296cf1a6474SDavid Howells u8 rtt_cursor; /* next entry at which to insert */ 297cf1a6474SDavid Howells u8 rtt_usage; /* amount of cache actually used */ 29817926a79SDavid Howells }; 29917926a79SDavid Howells 30017926a79SDavid Howells /* 30119ffa01cSDavid Howells * Keys for matching a connection. 30219ffa01cSDavid Howells */ 30319ffa01cSDavid Howells struct rxrpc_conn_proto { 304e8d70ce1SDavid Howells union { 305e8d70ce1SDavid Howells struct { 30619ffa01cSDavid Howells u32 epoch; /* epoch of this connection */ 30719ffa01cSDavid Howells u32 cid; /* connection ID */ 308e8d70ce1SDavid Howells }; 309e8d70ce1SDavid Howells u64 index_key; 31019ffa01cSDavid Howells }; 31119ffa01cSDavid Howells }; 31219ffa01cSDavid Howells 31319ffa01cSDavid Howells struct rxrpc_conn_parameters { 31419ffa01cSDavid Howells struct rxrpc_local *local; /* Representation of local endpoint */ 31519ffa01cSDavid Howells struct rxrpc_peer *peer; /* Remote endpoint */ 31619ffa01cSDavid Howells struct key *key; /* Security details */ 31719ffa01cSDavid Howells bool exclusive; /* T if conn is exclusive */ 31819ffa01cSDavid Howells u16 service_id; /* Service ID for this connection */ 31919ffa01cSDavid Howells u32 security_level; /* Security level selected */ 32019ffa01cSDavid Howells }; 32119ffa01cSDavid Howells 32219ffa01cSDavid Howells /* 323bba304dbSDavid Howells * Bits in the connection flags. 324bba304dbSDavid Howells */ 325bba304dbSDavid Howells enum rxrpc_conn_flag { 326bba304dbSDavid Howells RXRPC_CONN_HAS_IDR, /* Has a client conn ID assigned */ 327001c1122SDavid Howells RXRPC_CONN_IN_SERVICE_CONNS, /* Conn is in peer->service_conns */ 328001c1122SDavid Howells RXRPC_CONN_IN_CLIENT_CONNS, /* Conn is in local->client_conns */ 32945025bceSDavid Howells RXRPC_CONN_EXPOSED, /* Conn has extra ref for exposure */ 33045025bceSDavid Howells RXRPC_CONN_DONT_REUSE, /* Don't reuse this connection */ 33145025bceSDavid Howells RXRPC_CONN_COUNTED, /* Counted by rxrpc_nr_client_conns */ 332bba304dbSDavid Howells }; 333bba304dbSDavid Howells 334bba304dbSDavid Howells /* 335bba304dbSDavid Howells * Events that can be raised upon a connection. 336bba304dbSDavid Howells */ 337bba304dbSDavid Howells enum rxrpc_conn_event { 338bba304dbSDavid Howells RXRPC_CONN_EV_CHALLENGE, /* Send challenge packet */ 339bba304dbSDavid Howells }; 340bba304dbSDavid Howells 341bba304dbSDavid Howells /* 34245025bceSDavid Howells * The connection cache state. 34345025bceSDavid Howells */ 34445025bceSDavid Howells enum rxrpc_conn_cache_state { 34545025bceSDavid Howells RXRPC_CONN_CLIENT_INACTIVE, /* Conn is not yet listed */ 34645025bceSDavid Howells RXRPC_CONN_CLIENT_WAITING, /* Conn is on wait list, waiting for capacity */ 34745025bceSDavid Howells RXRPC_CONN_CLIENT_ACTIVE, /* Conn is on active list, doing calls */ 34845025bceSDavid Howells RXRPC_CONN_CLIENT_CULLED, /* Conn is culled and delisted, doing calls */ 34945025bceSDavid Howells RXRPC_CONN_CLIENT_IDLE, /* Conn is on idle list, doing mostly nothing */ 350363deeabSDavid Howells RXRPC_CONN__NR_CACHE_STATES 35145025bceSDavid Howells }; 35245025bceSDavid Howells 35345025bceSDavid Howells /* 354bba304dbSDavid Howells * The connection protocol state. 355bba304dbSDavid Howells */ 356bba304dbSDavid Howells enum rxrpc_conn_proto_state { 357bba304dbSDavid Howells RXRPC_CONN_UNUSED, /* Connection not yet attempted */ 358bba304dbSDavid Howells RXRPC_CONN_CLIENT, /* Client connection */ 35900e90712SDavid Howells RXRPC_CONN_SERVICE_PREALLOC, /* Service connection preallocation */ 360bba304dbSDavid Howells RXRPC_CONN_SERVICE_UNSECURED, /* Service unsecured connection */ 361bba304dbSDavid Howells RXRPC_CONN_SERVICE_CHALLENGING, /* Service challenging for security */ 362bba304dbSDavid Howells RXRPC_CONN_SERVICE, /* Service secured connection */ 363bba304dbSDavid Howells RXRPC_CONN_REMOTELY_ABORTED, /* Conn aborted by peer */ 364bba304dbSDavid Howells RXRPC_CONN_LOCALLY_ABORTED, /* Conn aborted locally */ 365bba304dbSDavid Howells RXRPC_CONN__NR_STATES 366bba304dbSDavid Howells }; 367bba304dbSDavid Howells 368bba304dbSDavid Howells /* 36917926a79SDavid Howells * RxRPC connection definition 370aa390bbeSDavid Howells * - matched by { local, peer, epoch, conn_id, direction } 37117926a79SDavid Howells * - each connection can only handle four simultaneous calls 37217926a79SDavid Howells */ 37317926a79SDavid Howells struct rxrpc_connection { 37419ffa01cSDavid Howells struct rxrpc_conn_proto proto; 37519ffa01cSDavid Howells struct rxrpc_conn_parameters params; 37619ffa01cSDavid Howells 37745025bceSDavid Howells atomic_t usage; 37845025bceSDavid Howells struct rcu_head rcu; 37945025bceSDavid Howells struct list_head cache_link; 380a1399f8bSDavid Howells 38145025bceSDavid Howells spinlock_t channel_lock; 38245025bceSDavid Howells unsigned char active_chans; /* Mask of active channels */ 38345025bceSDavid Howells #define RXRPC_ACTIVE_CHANS_MASK ((1 << RXRPC_MAXCALLS) - 1) 38445025bceSDavid Howells struct list_head waiting_calls; /* Calls waiting for channels */ 385a1399f8bSDavid Howells struct rxrpc_channel { 386a1399f8bSDavid Howells struct rxrpc_call __rcu *call; /* Active call */ 387a1399f8bSDavid Howells u32 call_id; /* ID of current call */ 388a1399f8bSDavid Howells u32 call_counter; /* Call ID counter */ 389a1399f8bSDavid Howells u32 last_call; /* ID of last call */ 39018bfeba5SDavid Howells u8 last_type; /* Type of last packet */ 39118bfeba5SDavid Howells union { 39218bfeba5SDavid Howells u32 last_seq; 39318bfeba5SDavid Howells u32 last_abort; 39418bfeba5SDavid Howells }; 395a1399f8bSDavid Howells } channels[RXRPC_MAXCALLS]; 396999b69f8SDavid Howells 39717926a79SDavid Howells struct work_struct processor; /* connection event processor */ 398999b69f8SDavid Howells union { 399999b69f8SDavid Howells struct rb_node client_node; /* Node in local->client_conns */ 400aa390bbeSDavid Howells struct rb_node service_node; /* Node in peer->service_conns */ 401999b69f8SDavid Howells }; 4024d028b2cSDavid Howells struct list_head proc_link; /* link in procfs list */ 40317926a79SDavid Howells struct list_head link; /* link in master connection list */ 40417926a79SDavid Howells struct sk_buff_head rx_queue; /* received conn-level packets */ 405648af7fcSDavid Howells const struct rxrpc_security *security; /* applied security module */ 40617926a79SDavid Howells struct key *server_key; /* security for this service */ 4071afe593bSHerbert Xu struct crypto_skcipher *cipher; /* encryption handle */ 40817926a79SDavid Howells struct rxrpc_crypt csum_iv; /* packet checksum base */ 4094a3388c8SDavid Howells unsigned long flags; 41017926a79SDavid Howells unsigned long events; 411f51b4480SDavid Howells unsigned long idle_timestamp; /* Time at which last became idle */ 41217926a79SDavid Howells spinlock_t state_lock; /* state-change lock */ 413cf13258fSDavid Howells enum rxrpc_conn_cache_state cache_state; 414cf13258fSDavid Howells enum rxrpc_conn_proto_state state; /* current state of connection */ 415dc44b3a0SDavid Howells u32 local_abort; /* local abort code */ 416dc44b3a0SDavid Howells u32 remote_abort; /* remote abort code */ 41717926a79SDavid Howells int debug_id; /* debug ID for printks */ 41817926a79SDavid Howells atomic_t serial; /* packet serial number counter */ 419563ea7d5SDavid Howells unsigned int hi_serial; /* highest serial number received */ 42017926a79SDavid Howells u32 security_nonce; /* response re-use preventer */ 42168d6d1aeSDavid Howells u16 service_id; /* Service ID, possibly upgraded */ 4225a924b89SDavid Howells u8 size_align; /* data size alignment (for security) */ 4235a924b89SDavid Howells u8 security_size; /* security header size */ 42417926a79SDavid Howells u8 security_ix; /* security type */ 42517926a79SDavid Howells u8 out_clientflag; /* RXRPC_CLIENT_INITIATED if we are client */ 42617926a79SDavid Howells }; 42717926a79SDavid Howells 42817926a79SDavid Howells /* 4295b8848d1SDavid Howells * Flags in call->flags. 4305b8848d1SDavid Howells */ 4315b8848d1SDavid Howells enum rxrpc_call_flag { 4325b8848d1SDavid Howells RXRPC_CALL_RELEASED, /* call has been released - no more message to userspace */ 4335b8848d1SDavid Howells RXRPC_CALL_HAS_USERID, /* has a user ID attached */ 434dabe5a79SDavid Howells RXRPC_CALL_IS_SERVICE, /* Call is service call */ 43545025bceSDavid Howells RXRPC_CALL_EXPOSED, /* The call was exposed to the world */ 436248f219cSDavid Howells RXRPC_CALL_RX_LAST, /* Received the last packet (at rxtx_top) */ 437248f219cSDavid Howells RXRPC_CALL_TX_LAST, /* Last packet in Tx buffer (at rxtx_top) */ 438a5af7e1fSDavid Howells RXRPC_CALL_SEND_PING, /* A ping will need to be sent */ 4398e83134dSDavid Howells RXRPC_CALL_PINGING, /* Ping in process */ 44057494343SDavid Howells RXRPC_CALL_RETRANS_TIMEOUT, /* Retransmission due to timeout occurred */ 4415b8848d1SDavid Howells }; 4425b8848d1SDavid Howells 4435b8848d1SDavid Howells /* 4445b8848d1SDavid Howells * Events that can be raised on a call. 4455b8848d1SDavid Howells */ 4465b8848d1SDavid Howells enum rxrpc_call_event { 4474c198ad1SDavid Howells RXRPC_CALL_EV_ACK, /* need to generate ACK */ 4484c198ad1SDavid Howells RXRPC_CALL_EV_ABORT, /* need to generate abort */ 449248f219cSDavid Howells RXRPC_CALL_EV_TIMER, /* Timer expired */ 4504c198ad1SDavid Howells RXRPC_CALL_EV_RESEND, /* Tx resend required */ 451a5af7e1fSDavid Howells RXRPC_CALL_EV_PING, /* Ping send required */ 4525b8848d1SDavid Howells }; 4535b8848d1SDavid Howells 4545b8848d1SDavid Howells /* 4555b8848d1SDavid Howells * The states that a call can be in. 4565b8848d1SDavid Howells */ 4575b8848d1SDavid Howells enum rxrpc_call_state { 458999b69f8SDavid Howells RXRPC_CALL_UNINITIALISED, 459999b69f8SDavid Howells RXRPC_CALL_CLIENT_AWAIT_CONN, /* - client waiting for connection to become available */ 4605b8848d1SDavid Howells RXRPC_CALL_CLIENT_SEND_REQUEST, /* - client sending request phase */ 4615b8848d1SDavid Howells RXRPC_CALL_CLIENT_AWAIT_REPLY, /* - client awaiting reply */ 4625b8848d1SDavid Howells RXRPC_CALL_CLIENT_RECV_REPLY, /* - client receiving reply phase */ 46300e90712SDavid Howells RXRPC_CALL_SERVER_PREALLOC, /* - service preallocation */ 4645b8848d1SDavid Howells RXRPC_CALL_SERVER_SECURING, /* - server securing request connection */ 4655b8848d1SDavid Howells RXRPC_CALL_SERVER_ACCEPTING, /* - server accepting request */ 4665b8848d1SDavid Howells RXRPC_CALL_SERVER_RECV_REQUEST, /* - server receiving request */ 4675b8848d1SDavid Howells RXRPC_CALL_SERVER_ACK_REQUEST, /* - server pending ACK of request */ 4685b8848d1SDavid Howells RXRPC_CALL_SERVER_SEND_REPLY, /* - server sending reply */ 4695b8848d1SDavid Howells RXRPC_CALL_SERVER_AWAIT_ACK, /* - server awaiting final ACK */ 470f5c17aaeSDavid Howells RXRPC_CALL_COMPLETE, /* - call complete */ 471f5c17aaeSDavid Howells NR__RXRPC_CALL_STATES 472f5c17aaeSDavid Howells }; 473f5c17aaeSDavid Howells 474f5c17aaeSDavid Howells /* 475f5c17aaeSDavid Howells * Call completion condition (state == RXRPC_CALL_COMPLETE). 476f5c17aaeSDavid Howells */ 477f5c17aaeSDavid Howells enum rxrpc_call_completion { 478f5c17aaeSDavid Howells RXRPC_CALL_SUCCEEDED, /* - Normal termination */ 4795b8848d1SDavid Howells RXRPC_CALL_REMOTELY_ABORTED, /* - call aborted by peer */ 4805b8848d1SDavid Howells RXRPC_CALL_LOCALLY_ABORTED, /* - call aborted locally on error or close */ 481f5c17aaeSDavid Howells RXRPC_CALL_LOCAL_ERROR, /* - call failed due to local error */ 4825b8848d1SDavid Howells RXRPC_CALL_NETWORK_ERROR, /* - call terminated by network error */ 483f5c17aaeSDavid Howells NR__RXRPC_CALL_COMPLETIONS 4845b8848d1SDavid Howells }; 4855b8848d1SDavid Howells 4865b8848d1SDavid Howells /* 48757494343SDavid Howells * Call Tx congestion management modes. 48857494343SDavid Howells */ 48957494343SDavid Howells enum rxrpc_congest_mode { 49057494343SDavid Howells RXRPC_CALL_SLOW_START, 49157494343SDavid Howells RXRPC_CALL_CONGEST_AVOIDANCE, 49257494343SDavid Howells RXRPC_CALL_PACKET_LOSS, 49357494343SDavid Howells RXRPC_CALL_FAST_RETRANSMIT, 49457494343SDavid Howells NR__RXRPC_CONGEST_MODES 49557494343SDavid Howells }; 49657494343SDavid Howells 49757494343SDavid Howells /* 49817926a79SDavid Howells * RxRPC call definition 49917926a79SDavid Howells * - matched by { connection, call_id } 50017926a79SDavid Howells */ 50117926a79SDavid Howells struct rxrpc_call { 502dee46364SDavid Howells struct rcu_head rcu; 50317926a79SDavid Howells struct rxrpc_connection *conn; /* connection carrying call */ 504df5d8bf7SDavid Howells struct rxrpc_peer *peer; /* Peer record for remote address */ 5058d94aa38SDavid Howells struct rxrpc_sock __rcu *socket; /* socket responsible */ 506540b1c48SDavid Howells struct mutex user_mutex; /* User access mutex */ 507df0adc78SDavid Howells ktime_t ack_at; /* When deferred ACK needs to happen */ 508df0adc78SDavid Howells ktime_t resend_at; /* When next resend needs to happen */ 509a5af7e1fSDavid Howells ktime_t ping_at; /* When next to send a ping */ 510df0adc78SDavid Howells ktime_t expire_at; /* When the call times out */ 511248f219cSDavid Howells struct timer_list timer; /* Combined event timer */ 512248f219cSDavid Howells struct work_struct processor; /* Event processor */ 513d001648eSDavid Howells rxrpc_notify_rx_t notify_rx; /* kernel service Rx notification function */ 51417926a79SDavid Howells struct list_head link; /* link in master call list */ 51545025bceSDavid Howells struct list_head chan_wait_link; /* Link in conn->waiting_calls */ 516f66d7490SDavid Howells struct hlist_node error_link; /* link in error distribution list */ 517248f219cSDavid Howells struct list_head accept_link; /* Link in rx->acceptq */ 518248f219cSDavid Howells struct list_head recvmsg_link; /* Link in rx->recvmsg_q */ 519248f219cSDavid Howells struct list_head sock_link; /* Link in rx->sock_calls */ 520248f219cSDavid Howells struct rb_node sock_node; /* Node in rx->calls */ 52117926a79SDavid Howells struct sk_buff *tx_pending; /* Tx socket buffer being filled */ 52245025bceSDavid Howells wait_queue_head_t waitq; /* Wait queue for channel or Tx */ 523a263629dSHerbert Xu __be32 crypto_buf[2]; /* Temporary packet crypto buffer */ 52417926a79SDavid Howells unsigned long user_call_ID; /* user-defined call ID */ 52517926a79SDavid Howells unsigned long flags; 52617926a79SDavid Howells unsigned long events; 52717926a79SDavid Howells spinlock_t lock; 52817926a79SDavid Howells rwlock_t state_lock; /* lock for state transition */ 529f5c17aaeSDavid Howells u32 abort_code; /* Local/remote abort code */ 530f5c17aaeSDavid Howells int error; /* Local error incurred */ 531cf13258fSDavid Howells enum rxrpc_call_state state; /* current state of call */ 532cf13258fSDavid Howells enum rxrpc_call_completion completion; /* Call completion condition */ 53317926a79SDavid Howells atomic_t usage; 534dabe5a79SDavid Howells u16 service_id; /* service ID */ 535278ac0cdSDavid Howells u8 security_ix; /* Security type */ 536dabe5a79SDavid Howells u32 call_id; /* call ID on connection */ 537dabe5a79SDavid Howells u32 cid; /* connection ID plus channel index */ 538dabe5a79SDavid Howells int debug_id; /* debug ID for printks */ 5398e83134dSDavid Howells unsigned short rx_pkt_offset; /* Current recvmsg packet offset */ 5408e83134dSDavid Howells unsigned short rx_pkt_len; /* Current recvmsg packet len */ 54117926a79SDavid Howells 542248f219cSDavid Howells /* Rx/Tx circular buffer, depending on phase. 543248f219cSDavid Howells * 544248f219cSDavid Howells * In the Rx phase, packets are annotated with 0 or the number of the 545248f219cSDavid Howells * segment of a jumbo packet each buffer refers to. There can be up to 546248f219cSDavid Howells * 47 segments in a maximum-size UDP packet. 547248f219cSDavid Howells * 548248f219cSDavid Howells * In the Tx phase, packets are annotated with which buffers have been 549248f219cSDavid Howells * acked. 55017926a79SDavid Howells */ 551248f219cSDavid Howells #define RXRPC_RXTX_BUFF_SIZE 64 552248f219cSDavid Howells #define RXRPC_RXTX_BUFF_MASK (RXRPC_RXTX_BUFF_SIZE - 1) 55375e42126SDavid Howells #define RXRPC_INIT_RX_WINDOW_SIZE 32 554248f219cSDavid Howells struct sk_buff **rxtx_buffer; 555248f219cSDavid Howells u8 *rxtx_annotations; 556248f219cSDavid Howells #define RXRPC_TX_ANNO_ACK 0 557248f219cSDavid Howells #define RXRPC_TX_ANNO_UNACK 1 558248f219cSDavid Howells #define RXRPC_TX_ANNO_NAK 2 559248f219cSDavid Howells #define RXRPC_TX_ANNO_RETRANS 3 560f07373eaSDavid Howells #define RXRPC_TX_ANNO_MASK 0x03 56170790dbeSDavid Howells #define RXRPC_TX_ANNO_LAST 0x04 56270790dbeSDavid Howells #define RXRPC_TX_ANNO_RESENT 0x08 56370790dbeSDavid Howells 564248f219cSDavid Howells #define RXRPC_RX_ANNO_JUMBO 0x3f /* Jumbo subpacket number + 1 if not zero */ 565248f219cSDavid Howells #define RXRPC_RX_ANNO_JLAST 0x40 /* Set if last element of a jumbo packet */ 566248f219cSDavid Howells #define RXRPC_RX_ANNO_VERIFIED 0x80 /* Set if verified and decrypted */ 567248f219cSDavid Howells rxrpc_seq_t tx_hard_ack; /* Dead slot in buffer; the first transmitted but 568248f219cSDavid Howells * not hard-ACK'd packet follows this. 569248f219cSDavid Howells */ 570248f219cSDavid Howells rxrpc_seq_t tx_top; /* Highest Tx slot allocated. */ 57157494343SDavid Howells 57257494343SDavid Howells /* TCP-style slow-start congestion control [RFC5681]. Since the SMSS 57357494343SDavid Howells * is fixed, we keep these numbers in terms of segments (ie. DATA 57457494343SDavid Howells * packets) rather than bytes. 57557494343SDavid Howells */ 57657494343SDavid Howells #define RXRPC_TX_SMSS RXRPC_JUMBO_DATALEN 57757494343SDavid Howells u8 cong_cwnd; /* Congestion window size */ 57857494343SDavid Howells u8 cong_extra; /* Extra to send for congestion management */ 57957494343SDavid Howells u8 cong_ssthresh; /* Slow-start threshold */ 58057494343SDavid Howells enum rxrpc_congest_mode cong_mode:8; /* Congestion management mode */ 58157494343SDavid Howells u8 cong_dup_acks; /* Count of ACKs showing missing packets */ 58257494343SDavid Howells u8 cong_cumul_acks; /* Cumulative ACK count */ 58357494343SDavid Howells ktime_t cong_tstamp; /* Last time cwnd was changed */ 58457494343SDavid Howells 585248f219cSDavid Howells rxrpc_seq_t rx_hard_ack; /* Dead slot in buffer; the first received but not 586248f219cSDavid Howells * consumed packet follows this. 587248f219cSDavid Howells */ 588248f219cSDavid Howells rxrpc_seq_t rx_top; /* Highest Rx slot allocated. */ 589248f219cSDavid Howells rxrpc_seq_t rx_expect_next; /* Expected next packet sequence number */ 590248f219cSDavid Howells u8 rx_winsize; /* Size of Rx window */ 591248f219cSDavid Howells u8 tx_winsize; /* Maximum size of Tx window */ 59271f3ca40SDavid Howells bool tx_phase; /* T if transmission phase, F if receive phase */ 59375e42126SDavid Howells u8 nr_jumbo_bad; /* Number of jumbo dups/exceeds-windows */ 59417926a79SDavid Howells 59517926a79SDavid Howells /* receive-phase ACK management */ 5964e36a95eSDavid Howells u8 ackr_reason; /* reason to ACK */ 597563ea7d5SDavid Howells u16 ackr_skew; /* skew on packet being ACK'd */ 5980d12f8a4SDavid Howells rxrpc_serial_t ackr_serial; /* serial of packet being ACK'd */ 599248f219cSDavid Howells rxrpc_seq_t ackr_prev_seq; /* previous sequence number received */ 600805b21b9SDavid Howells rxrpc_seq_t ackr_consumed; /* Highest packet shown consumed */ 601805b21b9SDavid Howells rxrpc_seq_t ackr_seen; /* Highest packet shown seen */ 602a5af7e1fSDavid Howells 603a5af7e1fSDavid Howells /* ping management */ 604a5af7e1fSDavid Howells rxrpc_serial_t ping_serial; /* Last ping sent */ 605a5af7e1fSDavid Howells ktime_t ping_time; /* Time last ping sent */ 60617926a79SDavid Howells 607248f219cSDavid Howells /* transmission-phase ACK management */ 60857494343SDavid Howells ktime_t acks_latest_ts; /* Timestamp of latest ACK received */ 609248f219cSDavid Howells rxrpc_serial_t acks_latest; /* serial number of latest ACK received */ 61031a1b989SDavid Howells rxrpc_seq_t acks_lowest_nak; /* Lowest NACK in the buffer (or ==tx_hard_ack) */ 61131a1b989SDavid Howells }; 61231a1b989SDavid Howells 61331a1b989SDavid Howells /* 61457494343SDavid Howells * Summary of a new ACK and the changes it made to the Tx buffer packet states. 61531a1b989SDavid Howells */ 61631a1b989SDavid Howells struct rxrpc_ack_summary { 61731a1b989SDavid Howells u8 ack_reason; 61831a1b989SDavid Howells u8 nr_acks; /* Number of ACKs in packet */ 61931a1b989SDavid Howells u8 nr_nacks; /* Number of NACKs in packet */ 62031a1b989SDavid Howells u8 nr_new_acks; /* Number of new ACKs in packet */ 62131a1b989SDavid Howells u8 nr_new_nacks; /* Number of new NACKs in packet */ 62231a1b989SDavid Howells u8 nr_rot_new_acks; /* Number of rotated new ACKs */ 62331a1b989SDavid Howells bool new_low_nack; /* T if new low NACK found */ 62457494343SDavid Howells bool retrans_timeo; /* T if reTx due to timeout happened */ 62557494343SDavid Howells u8 flight_size; /* Number of unreceived transmissions */ 62657494343SDavid Howells /* Place to stash values for tracing */ 62757494343SDavid Howells enum rxrpc_congest_mode mode:8; 62857494343SDavid Howells u8 cwnd; 62957494343SDavid Howells u8 ssthresh; 63057494343SDavid Howells u8 dup_acks; 63157494343SDavid Howells u8 cumulative_acks; 63217926a79SDavid Howells }; 63317926a79SDavid Howells 634df844fd4SDavid Howells #include <trace/events/rxrpc.h> 635df844fd4SDavid Howells 63617926a79SDavid Howells /* 637651350d1SDavid Howells * af_rxrpc.c 63817926a79SDavid Howells */ 63971f3ca40SDavid Howells extern atomic_t rxrpc_n_tx_skbs, rxrpc_n_rx_skbs; 640651350d1SDavid Howells extern atomic_t rxrpc_debug_id; 641651350d1SDavid Howells extern struct workqueue_struct *rxrpc_workqueue; 64217926a79SDavid Howells 64317926a79SDavid Howells /* 6440d81a51aSDavid Howells * call_accept.c 64517926a79SDavid Howells */ 64600e90712SDavid Howells int rxrpc_service_prealloc(struct rxrpc_sock *, gfp_t); 64700e90712SDavid Howells void rxrpc_discard_prealloc(struct rxrpc_sock *); 648248f219cSDavid Howells struct rxrpc_call *rxrpc_new_incoming_call(struct rxrpc_local *, 649248f219cSDavid Howells struct rxrpc_connection *, 650248f219cSDavid Howells struct sk_buff *); 6514f95dd78SDavid Howells void rxrpc_accept_incoming_calls(struct rxrpc_local *); 652d001648eSDavid Howells struct rxrpc_call *rxrpc_accept_call(struct rxrpc_sock *, unsigned long, 653d001648eSDavid Howells rxrpc_notify_rx_t); 654c1b1203dSJoe Perches int rxrpc_reject_call(struct rxrpc_sock *); 65517926a79SDavid Howells 65617926a79SDavid Howells /* 6570d81a51aSDavid Howells * call_event.c 65817926a79SDavid Howells */ 6599749fd2bSDavid Howells void __rxrpc_set_timer(struct rxrpc_call *, enum rxrpc_timer_trace, ktime_t); 660df0adc78SDavid Howells void rxrpc_set_timer(struct rxrpc_call *, enum rxrpc_timer_trace, ktime_t); 6619c7ad434SDavid Howells void rxrpc_propose_ACK(struct rxrpc_call *, u8, u16, u32, bool, bool, 6629c7ad434SDavid Howells enum rxrpc_propose_ack_trace); 663c1b1203dSJoe Perches void rxrpc_process_call(struct work_struct *); 66417926a79SDavid Howells 66517926a79SDavid Howells /* 6660d81a51aSDavid Howells * call_object.c 66717926a79SDavid Howells */ 668f5c17aaeSDavid Howells extern const char *const rxrpc_call_states[]; 669f5c17aaeSDavid Howells extern const char *const rxrpc_call_completions[]; 670dad8aff7SDavid Howells extern unsigned int rxrpc_max_call_lifetime; 67117926a79SDavid Howells extern struct kmem_cache *rxrpc_call_jar; 67217926a79SDavid Howells 6732341e077SDavid Howells struct rxrpc_call *rxrpc_find_call_by_user_ID(struct rxrpc_sock *, unsigned long); 67400e90712SDavid Howells struct rxrpc_call *rxrpc_alloc_call(gfp_t); 6752341e077SDavid Howells struct rxrpc_call *rxrpc_new_client_call(struct rxrpc_sock *, 67619ffa01cSDavid Howells struct rxrpc_conn_parameters *, 677999b69f8SDavid Howells struct sockaddr_rxrpc *, 6782341e077SDavid Howells unsigned long, gfp_t); 679248f219cSDavid Howells void rxrpc_incoming_call(struct rxrpc_sock *, struct rxrpc_call *, 68042886ffeSDavid Howells struct sk_buff *); 6818d94aa38SDavid Howells void rxrpc_release_call(struct rxrpc_sock *, struct rxrpc_call *); 682c1b1203dSJoe Perches void rxrpc_release_calls_on_socket(struct rxrpc_sock *); 6838d94aa38SDavid Howells bool __rxrpc_queue_call(struct rxrpc_call *); 6848d94aa38SDavid Howells bool rxrpc_queue_call(struct rxrpc_call *); 685e34d4234SDavid Howells void rxrpc_see_call(struct rxrpc_call *); 686fff72429SDavid Howells void rxrpc_get_call(struct rxrpc_call *, enum rxrpc_call_trace); 687fff72429SDavid Howells void rxrpc_put_call(struct rxrpc_call *, enum rxrpc_call_trace); 68800e90712SDavid Howells void rxrpc_cleanup_call(struct rxrpc_call *); 6892baec2c3SDavid Howells void rxrpc_destroy_all_calls(struct rxrpc_net *); 69017926a79SDavid Howells 691dabe5a79SDavid Howells static inline bool rxrpc_is_service_call(const struct rxrpc_call *call) 692dabe5a79SDavid Howells { 693dabe5a79SDavid Howells return test_bit(RXRPC_CALL_IS_SERVICE, &call->flags); 694dabe5a79SDavid Howells } 695dabe5a79SDavid Howells 696dabe5a79SDavid Howells static inline bool rxrpc_is_client_call(const struct rxrpc_call *call) 697dabe5a79SDavid Howells { 698dabe5a79SDavid Howells return !rxrpc_is_service_call(call); 699dabe5a79SDavid Howells } 700dabe5a79SDavid Howells 70117926a79SDavid Howells /* 702f5c17aaeSDavid Howells * Transition a call to the complete state. 703f5c17aaeSDavid Howells */ 704f5c17aaeSDavid Howells static inline bool __rxrpc_set_call_completion(struct rxrpc_call *call, 705f5c17aaeSDavid Howells enum rxrpc_call_completion compl, 706f5c17aaeSDavid Howells u32 abort_code, 707f5c17aaeSDavid Howells int error) 708f5c17aaeSDavid Howells { 709f5c17aaeSDavid Howells if (call->state < RXRPC_CALL_COMPLETE) { 710f5c17aaeSDavid Howells call->abort_code = abort_code; 711f5c17aaeSDavid Howells call->error = error; 712f5c17aaeSDavid Howells call->completion = compl, 713f5c17aaeSDavid Howells call->state = RXRPC_CALL_COMPLETE; 714c0d058c2SDavid Howells wake_up(&call->waitq); 715f5c17aaeSDavid Howells return true; 716f5c17aaeSDavid Howells } 717f5c17aaeSDavid Howells return false; 718f5c17aaeSDavid Howells } 719f5c17aaeSDavid Howells 720f5c17aaeSDavid Howells static inline bool rxrpc_set_call_completion(struct rxrpc_call *call, 721f5c17aaeSDavid Howells enum rxrpc_call_completion compl, 722f5c17aaeSDavid Howells u32 abort_code, 723f5c17aaeSDavid Howells int error) 724f5c17aaeSDavid Howells { 725e8d6bbb0SDavid Howells bool ret; 726f5c17aaeSDavid Howells 727f5c17aaeSDavid Howells write_lock_bh(&call->state_lock); 728f5c17aaeSDavid Howells ret = __rxrpc_set_call_completion(call, compl, abort_code, error); 729f5c17aaeSDavid Howells write_unlock_bh(&call->state_lock); 730f5c17aaeSDavid Howells return ret; 731f5c17aaeSDavid Howells } 732f5c17aaeSDavid Howells 733f5c17aaeSDavid Howells /* 734f5c17aaeSDavid Howells * Record that a call successfully completed. 735f5c17aaeSDavid Howells */ 736e8d6bbb0SDavid Howells static inline bool __rxrpc_call_completed(struct rxrpc_call *call) 737f5c17aaeSDavid Howells { 738e8d6bbb0SDavid Howells return __rxrpc_set_call_completion(call, RXRPC_CALL_SUCCEEDED, 0, 0); 739f5c17aaeSDavid Howells } 740f5c17aaeSDavid Howells 741e8d6bbb0SDavid Howells static inline bool rxrpc_call_completed(struct rxrpc_call *call) 742f5c17aaeSDavid Howells { 743e8d6bbb0SDavid Howells bool ret; 744e8d6bbb0SDavid Howells 745f5c17aaeSDavid Howells write_lock_bh(&call->state_lock); 746e8d6bbb0SDavid Howells ret = __rxrpc_call_completed(call); 747f5c17aaeSDavid Howells write_unlock_bh(&call->state_lock); 748e8d6bbb0SDavid Howells return ret; 749f5c17aaeSDavid Howells } 750f5c17aaeSDavid Howells 751f5c17aaeSDavid Howells /* 752f5c17aaeSDavid Howells * Record that a call is locally aborted. 753f5c17aaeSDavid Howells */ 7545a42976dSDavid Howells static inline bool __rxrpc_abort_call(const char *why, struct rxrpc_call *call, 7555a42976dSDavid Howells rxrpc_seq_t seq, 756f5c17aaeSDavid Howells u32 abort_code, int error) 757f5c17aaeSDavid Howells { 7585a42976dSDavid Howells trace_rxrpc_abort(why, call->cid, call->call_id, seq, 7595a42976dSDavid Howells abort_code, error); 760248f219cSDavid Howells return __rxrpc_set_call_completion(call, RXRPC_CALL_LOCALLY_ABORTED, 761248f219cSDavid Howells abort_code, error); 762f5c17aaeSDavid Howells } 763f5c17aaeSDavid Howells 7645a42976dSDavid Howells static inline bool rxrpc_abort_call(const char *why, struct rxrpc_call *call, 7655a42976dSDavid Howells rxrpc_seq_t seq, u32 abort_code, int error) 766f5c17aaeSDavid Howells { 767f5c17aaeSDavid Howells bool ret; 768f5c17aaeSDavid Howells 769f5c17aaeSDavid Howells write_lock_bh(&call->state_lock); 7705a42976dSDavid Howells ret = __rxrpc_abort_call(why, call, seq, abort_code, error); 771f5c17aaeSDavid Howells write_unlock_bh(&call->state_lock); 772f5c17aaeSDavid Howells return ret; 773f5c17aaeSDavid Howells } 774f5c17aaeSDavid Howells 775f5c17aaeSDavid Howells /* 776fb46f6eeSDavid Howells * Abort a call due to a protocol error. 777fb46f6eeSDavid Howells */ 778fb46f6eeSDavid Howells static inline bool __rxrpc_abort_eproto(struct rxrpc_call *call, 779fb46f6eeSDavid Howells struct sk_buff *skb, 780fb46f6eeSDavid Howells const char *eproto_why, 781fb46f6eeSDavid Howells const char *why, 782fb46f6eeSDavid Howells u32 abort_code) 783fb46f6eeSDavid Howells { 784fb46f6eeSDavid Howells struct rxrpc_skb_priv *sp = rxrpc_skb(skb); 785fb46f6eeSDavid Howells 786fb46f6eeSDavid Howells trace_rxrpc_rx_eproto(call, sp->hdr.serial, eproto_why); 787fb46f6eeSDavid Howells return rxrpc_abort_call(why, call, sp->hdr.seq, abort_code, -EPROTO); 788fb46f6eeSDavid Howells } 789fb46f6eeSDavid Howells 790fb46f6eeSDavid Howells #define rxrpc_abort_eproto(call, skb, eproto_why, abort_why, abort_code) \ 791fb46f6eeSDavid Howells __rxrpc_abort_eproto((call), (skb), tracepoint_string(eproto_why), \ 792fb46f6eeSDavid Howells (abort_why), (abort_code)) 793fb46f6eeSDavid Howells 794fb46f6eeSDavid Howells /* 7954a3388c8SDavid Howells * conn_client.c 7964a3388c8SDavid Howells */ 79745025bceSDavid Howells extern unsigned int rxrpc_max_client_connections; 79845025bceSDavid Howells extern unsigned int rxrpc_reap_client_connections; 79945025bceSDavid Howells extern unsigned int rxrpc_conn_idle_client_expiry; 80045025bceSDavid Howells extern unsigned int rxrpc_conn_idle_client_fast_expiry; 8014a3388c8SDavid Howells extern struct idr rxrpc_client_conn_ids; 8024a3388c8SDavid Howells 803eb9b9d22SDavid Howells void rxrpc_destroy_client_conn_ids(void); 804c6d2b8d7SDavid Howells int rxrpc_connect_call(struct rxrpc_call *, struct rxrpc_conn_parameters *, 805c6d2b8d7SDavid Howells struct sockaddr_rxrpc *, gfp_t); 80645025bceSDavid Howells void rxrpc_expose_client_call(struct rxrpc_call *); 80745025bceSDavid Howells void rxrpc_disconnect_client_call(struct rxrpc_call *); 80845025bceSDavid Howells void rxrpc_put_client_conn(struct rxrpc_connection *); 8092baec2c3SDavid Howells void rxrpc_discard_expired_client_conns(struct work_struct *); 8102baec2c3SDavid Howells void rxrpc_destroy_all_client_connections(struct rxrpc_net *); 8114a3388c8SDavid Howells 8124a3388c8SDavid Howells /* 8130d81a51aSDavid Howells * conn_event.c 8140d81a51aSDavid Howells */ 8150d81a51aSDavid Howells void rxrpc_process_connection(struct work_struct *); 8160d81a51aSDavid Howells 8170d81a51aSDavid Howells /* 8180d81a51aSDavid Howells * conn_object.c 81917926a79SDavid Howells */ 820dad8aff7SDavid Howells extern unsigned int rxrpc_connection_expiry; 82117926a79SDavid Howells 8228496af50SDavid Howells int rxrpc_extract_addr_from_skb(struct sockaddr_rxrpc *, struct sk_buff *); 823c6d2b8d7SDavid Howells struct rxrpc_connection *rxrpc_alloc_connection(gfp_t); 8248496af50SDavid Howells struct rxrpc_connection *rxrpc_find_connection_rcu(struct rxrpc_local *, 825aa390bbeSDavid Howells struct sk_buff *); 82645025bceSDavid Howells void __rxrpc_disconnect_call(struct rxrpc_connection *, struct rxrpc_call *); 827999b69f8SDavid Howells void rxrpc_disconnect_call(struct rxrpc_call *); 82845025bceSDavid Howells void rxrpc_kill_connection(struct rxrpc_connection *); 829363deeabSDavid Howells bool rxrpc_queue_conn(struct rxrpc_connection *); 830363deeabSDavid Howells void rxrpc_see_connection(struct rxrpc_connection *); 831363deeabSDavid Howells void rxrpc_get_connection(struct rxrpc_connection *); 832363deeabSDavid Howells struct rxrpc_connection *rxrpc_get_connection_maybe(struct rxrpc_connection *); 833363deeabSDavid Howells void rxrpc_put_service_conn(struct rxrpc_connection *); 8342baec2c3SDavid Howells void rxrpc_service_connection_reaper(struct work_struct *); 8352baec2c3SDavid Howells void rxrpc_destroy_all_connections(struct rxrpc_net *); 83617926a79SDavid Howells 83719ffa01cSDavid Howells static inline bool rxrpc_conn_is_client(const struct rxrpc_connection *conn) 83819ffa01cSDavid Howells { 83919ffa01cSDavid Howells return conn->out_clientflag; 84019ffa01cSDavid Howells } 84119ffa01cSDavid Howells 84219ffa01cSDavid Howells static inline bool rxrpc_conn_is_service(const struct rxrpc_connection *conn) 84319ffa01cSDavid Howells { 844e8d70ce1SDavid Howells return !rxrpc_conn_is_client(conn); 84519ffa01cSDavid Howells } 84619ffa01cSDavid Howells 847f51b4480SDavid Howells static inline void rxrpc_put_connection(struct rxrpc_connection *conn) 848f51b4480SDavid Howells { 84945025bceSDavid Howells if (!conn) 85045025bceSDavid Howells return; 85145025bceSDavid Howells 852363deeabSDavid Howells if (rxrpc_conn_is_client(conn)) 85345025bceSDavid Howells rxrpc_put_client_conn(conn); 854363deeabSDavid Howells else 855363deeabSDavid Howells rxrpc_put_service_conn(conn); 8565acbee46SDavid Howells } 8575acbee46SDavid Howells 85817926a79SDavid Howells /* 8597877a4a4SDavid Howells * conn_service.c 8607877a4a4SDavid Howells */ 8618496af50SDavid Howells struct rxrpc_connection *rxrpc_find_service_conn_rcu(struct rxrpc_peer *, 8628496af50SDavid Howells struct sk_buff *); 8632baec2c3SDavid Howells struct rxrpc_connection *rxrpc_prealloc_service_connection(struct rxrpc_net *, gfp_t); 864248f219cSDavid Howells void rxrpc_new_incoming_connection(struct rxrpc_connection *, struct sk_buff *); 865001c1122SDavid Howells void rxrpc_unpublish_service_conn(struct rxrpc_connection *); 8667877a4a4SDavid Howells 8677877a4a4SDavid Howells /* 8680d81a51aSDavid Howells * input.c 86917926a79SDavid Howells */ 870676d2369SDavid S. Miller void rxrpc_data_ready(struct sock *); 87117926a79SDavid Howells 87217926a79SDavid Howells /* 8730d81a51aSDavid Howells * insecure.c 87417926a79SDavid Howells */ 8750d81a51aSDavid Howells extern const struct rxrpc_security rxrpc_no_security; 87617926a79SDavid Howells 87717926a79SDavid Howells /* 8780d81a51aSDavid Howells * key.c 87917926a79SDavid Howells */ 88017926a79SDavid Howells extern struct key_type key_type_rxrpc; 88117926a79SDavid Howells extern struct key_type key_type_rxrpc_s; 88217926a79SDavid Howells 883c1b1203dSJoe Perches int rxrpc_request_key(struct rxrpc_sock *, char __user *, int); 884c1b1203dSJoe Perches int rxrpc_server_keyring(struct rxrpc_sock *, char __user *, int); 885c1b1203dSJoe Perches int rxrpc_get_server_data_key(struct rxrpc_connection *, const void *, time_t, 886c1b1203dSJoe Perches u32); 88717926a79SDavid Howells 88817926a79SDavid Howells /* 88987563616SDavid Howells * local_event.c 89087563616SDavid Howells */ 8914f95dd78SDavid Howells extern void rxrpc_process_local_events(struct rxrpc_local *); 89287563616SDavid Howells 89387563616SDavid Howells /* 8940d81a51aSDavid Howells * local_object.c 89517926a79SDavid Howells */ 8962baec2c3SDavid Howells struct rxrpc_local *rxrpc_lookup_local(struct net *, const struct sockaddr_rxrpc *); 8974f95dd78SDavid Howells void __rxrpc_put_local(struct rxrpc_local *); 8982baec2c3SDavid Howells void rxrpc_destroy_all_locals(struct rxrpc_net *); 899e0e4d82fSDavid Howells 9004f95dd78SDavid Howells static inline void rxrpc_get_local(struct rxrpc_local *local) 9014f95dd78SDavid Howells { 9024f95dd78SDavid Howells atomic_inc(&local->usage); 9034f95dd78SDavid Howells } 9044f95dd78SDavid Howells 9054f95dd78SDavid Howells static inline 9064f95dd78SDavid Howells struct rxrpc_local *rxrpc_get_local_maybe(struct rxrpc_local *local) 9074f95dd78SDavid Howells { 9084f95dd78SDavid Howells return atomic_inc_not_zero(&local->usage) ? local : NULL; 9094f95dd78SDavid Howells } 9104f95dd78SDavid Howells 9114f95dd78SDavid Howells static inline void rxrpc_put_local(struct rxrpc_local *local) 9124f95dd78SDavid Howells { 9135627cc8bSDavid Howells if (local && atomic_dec_and_test(&local->usage)) 9144f95dd78SDavid Howells __rxrpc_put_local(local); 9154f95dd78SDavid Howells } 9164f95dd78SDavid Howells 9175acbee46SDavid Howells static inline void rxrpc_queue_local(struct rxrpc_local *local) 9185acbee46SDavid Howells { 9195acbee46SDavid Howells rxrpc_queue_work(&local->processor); 9205acbee46SDavid Howells } 9215acbee46SDavid Howells 922e0e4d82fSDavid Howells /* 9238e688d9cSDavid Howells * misc.c 9248e688d9cSDavid Howells */ 9250e119b41SDavid Howells extern unsigned int rxrpc_max_backlog __read_mostly; 9268e688d9cSDavid Howells extern unsigned int rxrpc_requested_ack_delay; 9278e688d9cSDavid Howells extern unsigned int rxrpc_soft_ack_delay; 9288e688d9cSDavid Howells extern unsigned int rxrpc_idle_ack_delay; 9298e688d9cSDavid Howells extern unsigned int rxrpc_rx_window_size; 9308e688d9cSDavid Howells extern unsigned int rxrpc_rx_mtu; 9318e688d9cSDavid Howells extern unsigned int rxrpc_rx_jumbo_max; 9320b58b8a1SDavid Howells extern unsigned int rxrpc_resend_timeout; 9338e688d9cSDavid Howells 9348e688d9cSDavid Howells extern const s8 rxrpc_ack_priority[]; 9358e688d9cSDavid Howells 9368e688d9cSDavid Howells /* 9372baec2c3SDavid Howells * net_ns.c 9382baec2c3SDavid Howells */ 9392baec2c3SDavid Howells extern unsigned int rxrpc_net_id; 9402baec2c3SDavid Howells extern struct pernet_operations rxrpc_net_ops; 9412baec2c3SDavid Howells 9422baec2c3SDavid Howells static inline struct rxrpc_net *rxrpc_net(struct net *net) 9432baec2c3SDavid Howells { 9442baec2c3SDavid Howells return net_generic(net, rxrpc_net_id); 9452baec2c3SDavid Howells } 9462baec2c3SDavid Howells 9472baec2c3SDavid Howells /* 9480d81a51aSDavid Howells * output.c 9490d81a51aSDavid Howells */ 950a5af7e1fSDavid Howells int rxrpc_send_ack_packet(struct rxrpc_call *, bool); 95126cb02aaSDavid Howells int rxrpc_send_abort_packet(struct rxrpc_call *); 952a1767077SDavid Howells int rxrpc_send_data_packet(struct rxrpc_call *, struct sk_buff *, bool); 953248f219cSDavid Howells void rxrpc_reject_packets(struct rxrpc_local *); 9540d81a51aSDavid Howells 9550d81a51aSDavid Howells /* 956abe89ef0SDavid Howells * peer_event.c 9570d81a51aSDavid Howells */ 958abe89ef0SDavid Howells void rxrpc_error_report(struct sock *); 959f66d7490SDavid Howells void rxrpc_peer_error_distributor(struct work_struct *); 960cf1a6474SDavid Howells void rxrpc_peer_add_rtt(struct rxrpc_call *, enum rxrpc_rtt_rx_trace, 961cf1a6474SDavid Howells rxrpc_serial_t, rxrpc_serial_t, ktime_t, ktime_t); 9620d81a51aSDavid Howells 9630d81a51aSDavid Howells /* 9640d81a51aSDavid Howells * peer_object.c 9650d81a51aSDavid Howells */ 966be6e6707SDavid Howells struct rxrpc_peer *rxrpc_lookup_peer_rcu(struct rxrpc_local *, 967be6e6707SDavid Howells const struct sockaddr_rxrpc *); 968be6e6707SDavid Howells struct rxrpc_peer *rxrpc_lookup_peer(struct rxrpc_local *, 969be6e6707SDavid Howells struct sockaddr_rxrpc *, gfp_t); 970be6e6707SDavid Howells struct rxrpc_peer *rxrpc_alloc_peer(struct rxrpc_local *, gfp_t); 971248f219cSDavid Howells struct rxrpc_peer *rxrpc_lookup_incoming_peer(struct rxrpc_local *, 972248f219cSDavid Howells struct rxrpc_peer *); 973be6e6707SDavid Howells 974df5d8bf7SDavid Howells static inline struct rxrpc_peer *rxrpc_get_peer(struct rxrpc_peer *peer) 975be6e6707SDavid Howells { 976be6e6707SDavid Howells atomic_inc(&peer->usage); 977df5d8bf7SDavid Howells return peer; 978be6e6707SDavid Howells } 979be6e6707SDavid Howells 980be6e6707SDavid Howells static inline 981be6e6707SDavid Howells struct rxrpc_peer *rxrpc_get_peer_maybe(struct rxrpc_peer *peer) 982be6e6707SDavid Howells { 983be6e6707SDavid Howells return atomic_inc_not_zero(&peer->usage) ? peer : NULL; 984be6e6707SDavid Howells } 985be6e6707SDavid Howells 986be6e6707SDavid Howells extern void __rxrpc_put_peer(struct rxrpc_peer *peer); 987be6e6707SDavid Howells static inline void rxrpc_put_peer(struct rxrpc_peer *peer) 988be6e6707SDavid Howells { 9895627cc8bSDavid Howells if (peer && atomic_dec_and_test(&peer->usage)) 990be6e6707SDavid Howells __rxrpc_put_peer(peer); 991be6e6707SDavid Howells } 9920d81a51aSDavid Howells 9930d81a51aSDavid Howells /* 9940d81a51aSDavid Howells * proc.c 9950d81a51aSDavid Howells */ 9960d81a51aSDavid Howells extern const struct file_operations rxrpc_call_seq_fops; 9970d81a51aSDavid Howells extern const struct file_operations rxrpc_connection_seq_fops; 9980d81a51aSDavid Howells 9990d81a51aSDavid Howells /* 10000d81a51aSDavid Howells * recvmsg.c 10010d81a51aSDavid Howells */ 1002248f219cSDavid Howells void rxrpc_notify_socket(struct rxrpc_call *); 10030d81a51aSDavid Howells int rxrpc_recvmsg(struct socket *, struct msghdr *, size_t, int); 10040d81a51aSDavid Howells 10050d81a51aSDavid Howells /* 1006648af7fcSDavid Howells * rxkad.c 1007648af7fcSDavid Howells */ 1008648af7fcSDavid Howells #ifdef CONFIG_RXKAD 1009648af7fcSDavid Howells extern const struct rxrpc_security rxkad; 1010648af7fcSDavid Howells #endif 1011648af7fcSDavid Howells 1012648af7fcSDavid Howells /* 10130d81a51aSDavid Howells * security.c 10140d81a51aSDavid Howells */ 10150d81a51aSDavid Howells int __init rxrpc_init_security(void); 10160d81a51aSDavid Howells void rxrpc_exit_security(void); 10170d81a51aSDavid Howells int rxrpc_init_client_conn_security(struct rxrpc_connection *); 10180d81a51aSDavid Howells int rxrpc_init_server_conn_security(struct rxrpc_connection *); 10190d81a51aSDavid Howells 10200d81a51aSDavid Howells /* 10210b58b8a1SDavid Howells * sendmsg.c 10220b58b8a1SDavid Howells */ 10230b58b8a1SDavid Howells int rxrpc_do_sendmsg(struct rxrpc_sock *, struct msghdr *, size_t); 10240b58b8a1SDavid Howells 10250b58b8a1SDavid Howells /* 10260d81a51aSDavid Howells * skbuff.c 10270d81a51aSDavid Howells */ 1028d001648eSDavid Howells void rxrpc_kernel_data_consumed(struct rxrpc_call *, struct sk_buff *); 10290d81a51aSDavid Howells void rxrpc_packet_destructor(struct sk_buff *); 103071f3ca40SDavid Howells void rxrpc_new_skb(struct sk_buff *, enum rxrpc_skb_trace); 103171f3ca40SDavid Howells void rxrpc_see_skb(struct sk_buff *, enum rxrpc_skb_trace); 103271f3ca40SDavid Howells void rxrpc_get_skb(struct sk_buff *, enum rxrpc_skb_trace); 103371f3ca40SDavid Howells void rxrpc_free_skb(struct sk_buff *, enum rxrpc_skb_trace); 103471f3ca40SDavid Howells void rxrpc_lose_skb(struct sk_buff *, enum rxrpc_skb_trace); 1035df844fd4SDavid Howells void rxrpc_purge_queue(struct sk_buff_head *); 10360d81a51aSDavid Howells 10370d81a51aSDavid Howells /* 10385873c083SDavid Howells * sysctl.c 10395873c083SDavid Howells */ 10405873c083SDavid Howells #ifdef CONFIG_SYSCTL 10415873c083SDavid Howells extern int __init rxrpc_sysctl_init(void); 10425873c083SDavid Howells extern void rxrpc_sysctl_exit(void); 10435873c083SDavid Howells #else 10445873c083SDavid Howells static inline int __init rxrpc_sysctl_init(void) { return 0; } 10455873c083SDavid Howells static inline void rxrpc_sysctl_exit(void) {} 10465873c083SDavid Howells #endif 10475873c083SDavid Howells 10485873c083SDavid Howells /* 1049be6e6707SDavid Howells * utils.c 1050be6e6707SDavid Howells */ 1051d991b4a3SDavid Howells int rxrpc_extract_addr_from_skb(struct sockaddr_rxrpc *, struct sk_buff *); 1052be6e6707SDavid Howells 1053248f219cSDavid Howells static inline bool before(u32 seq1, u32 seq2) 1054248f219cSDavid Howells { 1055248f219cSDavid Howells return (s32)(seq1 - seq2) < 0; 1056248f219cSDavid Howells } 1057248f219cSDavid Howells static inline bool before_eq(u32 seq1, u32 seq2) 1058248f219cSDavid Howells { 1059248f219cSDavid Howells return (s32)(seq1 - seq2) <= 0; 1060248f219cSDavid Howells } 1061248f219cSDavid Howells static inline bool after(u32 seq1, u32 seq2) 1062248f219cSDavid Howells { 1063248f219cSDavid Howells return (s32)(seq1 - seq2) > 0; 1064248f219cSDavid Howells } 1065248f219cSDavid Howells static inline bool after_eq(u32 seq1, u32 seq2) 1066248f219cSDavid Howells { 1067248f219cSDavid Howells return (s32)(seq1 - seq2) >= 0; 1068248f219cSDavid Howells } 1069248f219cSDavid Howells 1070be6e6707SDavid Howells /* 107117926a79SDavid Howells * debug tracing 107217926a79SDavid Howells */ 107395c96174SEric Dumazet extern unsigned int rxrpc_debug; 107417926a79SDavid Howells 107517926a79SDavid Howells #define dbgprintk(FMT,...) \ 10769f389f4bSSven Schnelle printk("[%-6.6s] "FMT"\n", current->comm ,##__VA_ARGS__) 107717926a79SDavid Howells 10780dc47877SHarvey Harrison #define kenter(FMT,...) dbgprintk("==> %s("FMT")",__func__ ,##__VA_ARGS__) 10790dc47877SHarvey Harrison #define kleave(FMT,...) dbgprintk("<== %s()"FMT"",__func__ ,##__VA_ARGS__) 108017926a79SDavid Howells #define kdebug(FMT,...) dbgprintk(" "FMT ,##__VA_ARGS__) 108117926a79SDavid Howells #define kproto(FMT,...) dbgprintk("### "FMT ,##__VA_ARGS__) 108217926a79SDavid Howells #define knet(FMT,...) dbgprintk("@@@ "FMT ,##__VA_ARGS__) 108317926a79SDavid Howells 108417926a79SDavid Howells 108517926a79SDavid Howells #if defined(__KDEBUG) 108617926a79SDavid Howells #define _enter(FMT,...) kenter(FMT,##__VA_ARGS__) 108717926a79SDavid Howells #define _leave(FMT,...) kleave(FMT,##__VA_ARGS__) 108817926a79SDavid Howells #define _debug(FMT,...) kdebug(FMT,##__VA_ARGS__) 108917926a79SDavid Howells #define _proto(FMT,...) kproto(FMT,##__VA_ARGS__) 109017926a79SDavid Howells #define _net(FMT,...) knet(FMT,##__VA_ARGS__) 109117926a79SDavid Howells 109217926a79SDavid Howells #elif defined(CONFIG_AF_RXRPC_DEBUG) 109317926a79SDavid Howells #define RXRPC_DEBUG_KENTER 0x01 109417926a79SDavid Howells #define RXRPC_DEBUG_KLEAVE 0x02 109517926a79SDavid Howells #define RXRPC_DEBUG_KDEBUG 0x04 109617926a79SDavid Howells #define RXRPC_DEBUG_KPROTO 0x08 109717926a79SDavid Howells #define RXRPC_DEBUG_KNET 0x10 109817926a79SDavid Howells 109917926a79SDavid Howells #define _enter(FMT,...) \ 110017926a79SDavid Howells do { \ 110117926a79SDavid Howells if (unlikely(rxrpc_debug & RXRPC_DEBUG_KENTER)) \ 110217926a79SDavid Howells kenter(FMT,##__VA_ARGS__); \ 110317926a79SDavid Howells } while (0) 110417926a79SDavid Howells 110517926a79SDavid Howells #define _leave(FMT,...) \ 110617926a79SDavid Howells do { \ 110717926a79SDavid Howells if (unlikely(rxrpc_debug & RXRPC_DEBUG_KLEAVE)) \ 110817926a79SDavid Howells kleave(FMT,##__VA_ARGS__); \ 110917926a79SDavid Howells } while (0) 111017926a79SDavid Howells 111117926a79SDavid Howells #define _debug(FMT,...) \ 111217926a79SDavid Howells do { \ 111317926a79SDavid Howells if (unlikely(rxrpc_debug & RXRPC_DEBUG_KDEBUG)) \ 111417926a79SDavid Howells kdebug(FMT,##__VA_ARGS__); \ 111517926a79SDavid Howells } while (0) 111617926a79SDavid Howells 111717926a79SDavid Howells #define _proto(FMT,...) \ 111817926a79SDavid Howells do { \ 111917926a79SDavid Howells if (unlikely(rxrpc_debug & RXRPC_DEBUG_KPROTO)) \ 112017926a79SDavid Howells kproto(FMT,##__VA_ARGS__); \ 112117926a79SDavid Howells } while (0) 112217926a79SDavid Howells 112317926a79SDavid Howells #define _net(FMT,...) \ 112417926a79SDavid Howells do { \ 112517926a79SDavid Howells if (unlikely(rxrpc_debug & RXRPC_DEBUG_KNET)) \ 112617926a79SDavid Howells knet(FMT,##__VA_ARGS__); \ 112717926a79SDavid Howells } while (0) 112817926a79SDavid Howells 112917926a79SDavid Howells #else 113012fdff3fSDavid Howells #define _enter(FMT,...) no_printk("==> %s("FMT")",__func__ ,##__VA_ARGS__) 113112fdff3fSDavid Howells #define _leave(FMT,...) no_printk("<== %s()"FMT"",__func__ ,##__VA_ARGS__) 113212fdff3fSDavid Howells #define _debug(FMT,...) no_printk(" "FMT ,##__VA_ARGS__) 113312fdff3fSDavid Howells #define _proto(FMT,...) no_printk("### "FMT ,##__VA_ARGS__) 113412fdff3fSDavid Howells #define _net(FMT,...) no_printk("@@@ "FMT ,##__VA_ARGS__) 113517926a79SDavid Howells #endif 113617926a79SDavid Howells 113717926a79SDavid Howells /* 113817926a79SDavid Howells * debug assertion checking 113917926a79SDavid Howells */ 114017926a79SDavid Howells #if 1 // defined(__KDEBUGALL) 114117926a79SDavid Howells 114217926a79SDavid Howells #define ASSERT(X) \ 114317926a79SDavid Howells do { \ 114417926a79SDavid Howells if (unlikely(!(X))) { \ 11459b6d5398SJoe Perches pr_err("Assertion failed\n"); \ 114617926a79SDavid Howells BUG(); \ 114717926a79SDavid Howells } \ 114817926a79SDavid Howells } while (0) 114917926a79SDavid Howells 115017926a79SDavid Howells #define ASSERTCMP(X, OP, Y) \ 115117926a79SDavid Howells do { \ 1152cf13258fSDavid Howells __typeof__(X) _x = (X); \ 1153cf13258fSDavid Howells __typeof__(Y) _y = (__typeof__(X))(Y); \ 11549b6d5398SJoe Perches if (unlikely(!(_x OP _y))) { \ 11559b6d5398SJoe Perches pr_err("Assertion failed - %lu(0x%lx) %s %lu(0x%lx) is false\n", \ 1156cf13258fSDavid Howells (unsigned long)_x, (unsigned long)_x, #OP, \ 1157cf13258fSDavid Howells (unsigned long)_y, (unsigned long)_y); \ 115817926a79SDavid Howells BUG(); \ 115917926a79SDavid Howells } \ 116017926a79SDavid Howells } while (0) 116117926a79SDavid Howells 116217926a79SDavid Howells #define ASSERTIF(C, X) \ 116317926a79SDavid Howells do { \ 116417926a79SDavid Howells if (unlikely((C) && !(X))) { \ 11659b6d5398SJoe Perches pr_err("Assertion failed\n"); \ 116617926a79SDavid Howells BUG(); \ 116717926a79SDavid Howells } \ 116817926a79SDavid Howells } while (0) 116917926a79SDavid Howells 117017926a79SDavid Howells #define ASSERTIFCMP(C, X, OP, Y) \ 117117926a79SDavid Howells do { \ 1172cf13258fSDavid Howells __typeof__(X) _x = (X); \ 1173cf13258fSDavid Howells __typeof__(Y) _y = (__typeof__(X))(Y); \ 11749b6d5398SJoe Perches if (unlikely((C) && !(_x OP _y))) { \ 11759b6d5398SJoe Perches pr_err("Assertion failed - %lu(0x%lx) %s %lu(0x%lx) is false\n", \ 1176cf13258fSDavid Howells (unsigned long)_x, (unsigned long)_x, #OP, \ 1177cf13258fSDavid Howells (unsigned long)_y, (unsigned long)_y); \ 117817926a79SDavid Howells BUG(); \ 117917926a79SDavid Howells } \ 118017926a79SDavid Howells } while (0) 118117926a79SDavid Howells 118217926a79SDavid Howells #else 118317926a79SDavid Howells 118417926a79SDavid Howells #define ASSERT(X) \ 118517926a79SDavid Howells do { \ 118617926a79SDavid Howells } while (0) 118717926a79SDavid Howells 118817926a79SDavid Howells #define ASSERTCMP(X, OP, Y) \ 118917926a79SDavid Howells do { \ 119017926a79SDavid Howells } while (0) 119117926a79SDavid Howells 119217926a79SDavid Howells #define ASSERTIF(C, X) \ 119317926a79SDavid Howells do { \ 119417926a79SDavid Howells } while (0) 119517926a79SDavid Howells 119617926a79SDavid Howells #define ASSERTIFCMP(C, X, OP, Y) \ 119717926a79SDavid Howells do { \ 119817926a79SDavid Howells } while (0) 119917926a79SDavid Howells 120017926a79SDavid Howells #endif /* __KDEBUGALL */ 1201