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> 14e0e4d82fSDavid Howells #include <net/sock.h> 15be6e6707SDavid Howells #include <net/af_rxrpc.h> 1617926a79SDavid Howells #include <rxrpc/packet.h> 1717926a79SDavid Howells 1817926a79SDavid Howells #if 0 1917926a79SDavid Howells #define CHECK_SLAB_OKAY(X) \ 2017926a79SDavid Howells BUG_ON(atomic_read((X)) >> (sizeof(atomic_t) - 2) == \ 2117926a79SDavid Howells (POISON_FREE << 8 | POISON_FREE)) 2217926a79SDavid Howells #else 2317926a79SDavid Howells #define CHECK_SLAB_OKAY(X) do {} while (0) 2417926a79SDavid Howells #endif 2517926a79SDavid Howells 2617926a79SDavid Howells #define FCRYPT_BSIZE 8 2717926a79SDavid Howells struct rxrpc_crypt { 2817926a79SDavid Howells union { 2917926a79SDavid Howells u8 x[FCRYPT_BSIZE]; 3091e916cfSAl Viro __be32 n[2]; 3117926a79SDavid Howells }; 3217926a79SDavid Howells } __attribute__((aligned(8))); 3317926a79SDavid Howells 34651350d1SDavid Howells #define rxrpc_queue_work(WS) queue_work(rxrpc_workqueue, (WS)) 35651350d1SDavid Howells #define rxrpc_queue_delayed_work(WS,D) \ 36651350d1SDavid Howells queue_delayed_work(rxrpc_workqueue, (WS), (D)) 37651350d1SDavid Howells 38cc8feb8eSDavid Howells struct rxrpc_connection; 39cc8feb8eSDavid Howells 4017926a79SDavid Howells /* 41d001648eSDavid Howells * Mark applied to socket buffers. 42d001648eSDavid Howells */ 43d001648eSDavid Howells enum rxrpc_skb_mark { 44d001648eSDavid Howells RXRPC_SKB_MARK_DATA, /* data message */ 45d001648eSDavid Howells RXRPC_SKB_MARK_FINAL_ACK, /* final ACK received message */ 46d001648eSDavid Howells RXRPC_SKB_MARK_BUSY, /* server busy message */ 47d001648eSDavid Howells RXRPC_SKB_MARK_REMOTE_ABORT, /* remote abort message */ 48d001648eSDavid Howells RXRPC_SKB_MARK_LOCAL_ABORT, /* local abort message */ 49d001648eSDavid Howells RXRPC_SKB_MARK_NET_ERROR, /* network error message */ 50d001648eSDavid Howells RXRPC_SKB_MARK_LOCAL_ERROR, /* local error message */ 51d001648eSDavid Howells RXRPC_SKB_MARK_NEW_CALL, /* local error message */ 52d001648eSDavid Howells }; 53d001648eSDavid Howells 54d001648eSDavid Howells /* 5517926a79SDavid Howells * sk_state for RxRPC sockets 5617926a79SDavid Howells */ 5717926a79SDavid Howells enum { 582341e077SDavid Howells RXRPC_UNBOUND = 0, 592341e077SDavid Howells RXRPC_CLIENT_UNBOUND, /* Unbound socket used as client */ 6017926a79SDavid Howells RXRPC_CLIENT_BOUND, /* client local address bound */ 6117926a79SDavid Howells RXRPC_SERVER_BOUND, /* server local address bound */ 6217926a79SDavid Howells RXRPC_SERVER_LISTENING, /* server listening for connections */ 63210f0353SDavid Howells RXRPC_SERVER_LISTEN_DISABLED, /* server listening disabled */ 6417926a79SDavid Howells RXRPC_CLOSE, /* socket is being closed */ 6517926a79SDavid Howells }; 6617926a79SDavid Howells 6717926a79SDavid Howells /* 6800e90712SDavid Howells * Service backlog preallocation. 6900e90712SDavid Howells * 7000e90712SDavid Howells * This contains circular buffers of preallocated peers, connections and calls 7100e90712SDavid Howells * for incoming service calls and their head and tail pointers. This allows 7200e90712SDavid Howells * calls to be set up in the data_ready handler, thereby avoiding the need to 7300e90712SDavid Howells * shuffle packets around so much. 7400e90712SDavid Howells */ 7500e90712SDavid Howells struct rxrpc_backlog { 7600e90712SDavid Howells unsigned short peer_backlog_head; 7700e90712SDavid Howells unsigned short peer_backlog_tail; 7800e90712SDavid Howells unsigned short conn_backlog_head; 7900e90712SDavid Howells unsigned short conn_backlog_tail; 8000e90712SDavid Howells unsigned short call_backlog_head; 8100e90712SDavid Howells unsigned short call_backlog_tail; 8200e90712SDavid Howells #define RXRPC_BACKLOG_MAX 32 8300e90712SDavid Howells struct rxrpc_peer *peer_backlog[RXRPC_BACKLOG_MAX]; 8400e90712SDavid Howells struct rxrpc_connection *conn_backlog[RXRPC_BACKLOG_MAX]; 8500e90712SDavid Howells struct rxrpc_call *call_backlog[RXRPC_BACKLOG_MAX]; 8600e90712SDavid Howells }; 8700e90712SDavid Howells 8800e90712SDavid Howells /* 8917926a79SDavid Howells * RxRPC socket definition 9017926a79SDavid Howells */ 9117926a79SDavid Howells struct rxrpc_sock { 9217926a79SDavid Howells /* WARNING: sk has to be the first member */ 9317926a79SDavid Howells struct sock sk; 94d001648eSDavid Howells rxrpc_notify_new_call_t notify_new_call; /* Func to notify of new call */ 9500e90712SDavid Howells rxrpc_discard_new_call_t discard_new_call; /* Func to discard a new call */ 9617926a79SDavid Howells struct rxrpc_local *local; /* local endpoint */ 9700e90712SDavid Howells struct rxrpc_backlog *backlog; /* Preallocation for services */ 98248f219cSDavid Howells spinlock_t incoming_lock; /* Incoming call vs service shutdown lock */ 99248f219cSDavid Howells struct list_head sock_calls; /* List of calls owned by this socket */ 100248f219cSDavid Howells struct list_head to_be_accepted; /* calls awaiting acceptance */ 101248f219cSDavid Howells struct list_head recvmsg_q; /* Calls awaiting recvmsg's attention */ 102248f219cSDavid Howells rwlock_t recvmsg_lock; /* Lock for recvmsg_q */ 10317926a79SDavid Howells struct key *key; /* security for this socket */ 10417926a79SDavid Howells struct key *securities; /* list of server security descriptors */ 10500e90712SDavid Howells struct rb_root calls; /* User ID -> call mapping */ 10617926a79SDavid Howells unsigned long flags; 1072341e077SDavid Howells #define RXRPC_SOCK_CONNECTED 0 /* connect_srx is set */ 10817926a79SDavid Howells rwlock_t call_lock; /* lock for calls */ 10917926a79SDavid Howells u32 min_sec_level; /* minimum security level */ 11017926a79SDavid Howells #define RXRPC_SECURITY_MAX RXRPC_SECURITY_ENCRYPT 111cc8feb8eSDavid Howells bool exclusive; /* Exclusive connection for a client socket */ 112cc8feb8eSDavid Howells sa_family_t family; /* Protocol family created with */ 11317926a79SDavid Howells struct sockaddr_rxrpc srx; /* local address */ 1142341e077SDavid Howells struct sockaddr_rxrpc connect_srx; /* Default client address from connect() */ 11517926a79SDavid Howells }; 11617926a79SDavid Howells 11717926a79SDavid Howells #define rxrpc_sk(__sk) container_of((__sk), struct rxrpc_sock, sk) 11817926a79SDavid Howells 11917926a79SDavid Howells /* 1200d12f8a4SDavid Howells * CPU-byteorder normalised Rx packet header. 1210d12f8a4SDavid Howells */ 1220d12f8a4SDavid Howells struct rxrpc_host_header { 1230d12f8a4SDavid Howells u32 epoch; /* client boot timestamp */ 1240d12f8a4SDavid Howells u32 cid; /* connection and channel ID */ 1250d12f8a4SDavid Howells u32 callNumber; /* call ID (0 for connection-level packets) */ 1260d12f8a4SDavid Howells u32 seq; /* sequence number of pkt in call stream */ 1270d12f8a4SDavid Howells u32 serial; /* serial number of pkt sent to network */ 1280d12f8a4SDavid Howells u8 type; /* packet type */ 1290d12f8a4SDavid Howells u8 flags; /* packet flags */ 1300d12f8a4SDavid Howells u8 userStatus; /* app-layer defined status */ 1310d12f8a4SDavid Howells u8 securityIndex; /* security protocol ID */ 1320d12f8a4SDavid Howells union { 1330d12f8a4SDavid Howells u16 _rsvd; /* reserved */ 1340d12f8a4SDavid Howells u16 cksum; /* kerberos security checksum */ 1350d12f8a4SDavid Howells }; 1360d12f8a4SDavid Howells u16 serviceId; /* service ID */ 1370d12f8a4SDavid Howells } __packed; 1380d12f8a4SDavid Howells 1390d12f8a4SDavid Howells /* 14017926a79SDavid Howells * RxRPC socket buffer private variables 14117926a79SDavid Howells * - max 48 bytes (struct sk_buff::cb) 14217926a79SDavid Howells */ 14317926a79SDavid Howells struct rxrpc_skb_priv { 144248f219cSDavid Howells union { 145248f219cSDavid Howells u8 nr_jumbo; /* Number of jumbo subpackets */ 146248f219cSDavid Howells }; 14717926a79SDavid Howells union { 14817926a79SDavid Howells int remain; /* amount of space remaining for next write */ 14917926a79SDavid Howells }; 15017926a79SDavid Howells 1510d12f8a4SDavid Howells struct rxrpc_host_header hdr; /* RxRPC packet header from this packet */ 15217926a79SDavid Howells }; 15317926a79SDavid Howells 15417926a79SDavid Howells #define rxrpc_skb(__skb) ((struct rxrpc_skb_priv *) &(__skb)->cb) 15517926a79SDavid Howells 15617926a79SDavid Howells /* 15717926a79SDavid Howells * RxRPC security module interface 15817926a79SDavid Howells */ 15917926a79SDavid Howells struct rxrpc_security { 16017926a79SDavid Howells const char *name; /* name of this service */ 16117926a79SDavid Howells u8 security_index; /* security type provided */ 16217926a79SDavid Howells 163648af7fcSDavid Howells /* Initialise a security service */ 164648af7fcSDavid Howells int (*init)(void); 165648af7fcSDavid Howells 166648af7fcSDavid Howells /* Clean up a security service */ 167648af7fcSDavid Howells void (*exit)(void); 168648af7fcSDavid Howells 16917926a79SDavid Howells /* initialise a connection's security */ 17017926a79SDavid Howells int (*init_connection_security)(struct rxrpc_connection *); 17117926a79SDavid Howells 17217926a79SDavid Howells /* prime a connection's packet security */ 173a263629dSHerbert Xu int (*prime_packet_security)(struct rxrpc_connection *); 17417926a79SDavid Howells 17517926a79SDavid Howells /* impose security on a packet */ 176a263629dSHerbert Xu int (*secure_packet)(struct rxrpc_call *, 17717926a79SDavid Howells struct sk_buff *, 17817926a79SDavid Howells size_t, 17917926a79SDavid Howells void *); 18017926a79SDavid Howells 18117926a79SDavid Howells /* verify the security on a received packet */ 1825a42976dSDavid Howells int (*verify_packet)(struct rxrpc_call *, struct sk_buff *, 183248f219cSDavid Howells unsigned int, unsigned int, rxrpc_seq_t, u16); 184248f219cSDavid Howells 185248f219cSDavid Howells /* Locate the data in a received packet that has been verified. */ 186248f219cSDavid Howells void (*locate_data)(struct rxrpc_call *, struct sk_buff *, 187248f219cSDavid Howells unsigned int *, unsigned int *); 18817926a79SDavid Howells 18917926a79SDavid Howells /* issue a challenge */ 19017926a79SDavid Howells int (*issue_challenge)(struct rxrpc_connection *); 19117926a79SDavid Howells 19217926a79SDavid Howells /* respond to a challenge */ 19317926a79SDavid Howells int (*respond_to_challenge)(struct rxrpc_connection *, 19417926a79SDavid Howells struct sk_buff *, 19517926a79SDavid Howells u32 *); 19617926a79SDavid Howells 19717926a79SDavid Howells /* verify a response */ 19817926a79SDavid Howells int (*verify_response)(struct rxrpc_connection *, 19917926a79SDavid Howells struct sk_buff *, 20017926a79SDavid Howells u32 *); 20117926a79SDavid Howells 20217926a79SDavid Howells /* clear connection security */ 20317926a79SDavid Howells void (*clear)(struct rxrpc_connection *); 20417926a79SDavid Howells }; 20517926a79SDavid Howells 20617926a79SDavid Howells /* 2074f95dd78SDavid Howells * RxRPC local transport endpoint description 2084f95dd78SDavid Howells * - owned by a single AF_RXRPC socket 2094f95dd78SDavid Howells * - pointed to by transport socket struct sk_user_data 21017926a79SDavid Howells */ 21117926a79SDavid Howells struct rxrpc_local { 2124f95dd78SDavid Howells struct rcu_head rcu; 2134f95dd78SDavid Howells atomic_t usage; 2144f95dd78SDavid Howells struct list_head link; 21517926a79SDavid Howells struct socket *socket; /* my UDP socket */ 2164f95dd78SDavid Howells struct work_struct processor; 2171e9e5c95SDavid Howells struct rxrpc_sock __rcu *service; /* Service(s) listening on this endpoint */ 21817926a79SDavid Howells struct rw_semaphore defrag_sem; /* control re-enablement of IP DF bit */ 21917926a79SDavid Howells struct sk_buff_head reject_queue; /* packets awaiting rejection */ 22044ba0698SDavid Howells struct sk_buff_head event_queue; /* endpoint event packets awaiting processing */ 221999b69f8SDavid Howells struct rb_root client_conns; /* Client connections by socket params */ 222999b69f8SDavid Howells spinlock_t client_conns_lock; /* Lock for client_conns */ 22317926a79SDavid Howells spinlock_t lock; /* access lock */ 22417926a79SDavid Howells rwlock_t services_lock; /* lock for services list */ 22517926a79SDavid Howells int debug_id; /* debug ID for printks */ 2264f95dd78SDavid Howells bool dead; 22717926a79SDavid Howells struct sockaddr_rxrpc srx; /* local address */ 22817926a79SDavid Howells }; 22917926a79SDavid Howells 23017926a79SDavid Howells /* 23117926a79SDavid Howells * RxRPC remote transport endpoint definition 232be6e6707SDavid Howells * - matched by local endpoint, remote port, address and protocol type 23317926a79SDavid Howells */ 23417926a79SDavid Howells struct rxrpc_peer { 235be6e6707SDavid Howells struct rcu_head rcu; /* This must be first */ 236be6e6707SDavid Howells atomic_t usage; 237be6e6707SDavid Howells unsigned long hash_key; 238be6e6707SDavid Howells struct hlist_node hash_link; 239be6e6707SDavid Howells struct rxrpc_local *local; 240f66d7490SDavid Howells struct hlist_head error_targets; /* targets for net error distribution */ 241f66d7490SDavid Howells struct work_struct error_distributor; 242aa390bbeSDavid Howells struct rb_root service_conns; /* Service connections */ 2438496af50SDavid Howells seqlock_t service_conn_lock; 24417926a79SDavid Howells spinlock_t lock; /* access lock */ 24595c96174SEric Dumazet unsigned int if_mtu; /* interface MTU for this peer */ 24695c96174SEric Dumazet unsigned int mtu; /* network MTU for this peer */ 24795c96174SEric Dumazet unsigned int maxdata; /* data size (MTU - hdrsize) */ 24817926a79SDavid Howells unsigned short hdrsize; /* header size (IP + UDP + RxRPC) */ 24917926a79SDavid Howells int debug_id; /* debug ID for printks */ 250f66d7490SDavid Howells int error_report; /* Net (+0) or local (+1000000) to distribute */ 251f66d7490SDavid Howells #define RXRPC_LOCAL_ERROR_OFFSET 1000000 25217926a79SDavid Howells struct sockaddr_rxrpc srx; /* remote address */ 25317926a79SDavid Howells 25417926a79SDavid Howells /* calculated RTT cache */ 25517926a79SDavid Howells #define RXRPC_RTT_CACHE_SIZE 32 2560d4b103cSDavid Howells ktime_t rtt_last_req; /* Time of last RTT request */ 257cf1a6474SDavid Howells u64 rtt; /* Current RTT estimate (in nS) */ 258cf1a6474SDavid Howells u64 rtt_sum; /* Sum of cache contents */ 259cf1a6474SDavid Howells u64 rtt_cache[RXRPC_RTT_CACHE_SIZE]; /* Determined RTT cache */ 260cf1a6474SDavid Howells u8 rtt_cursor; /* next entry at which to insert */ 261cf1a6474SDavid Howells u8 rtt_usage; /* amount of cache actually used */ 26217926a79SDavid Howells }; 26317926a79SDavid Howells 26417926a79SDavid Howells /* 26519ffa01cSDavid Howells * Keys for matching a connection. 26619ffa01cSDavid Howells */ 26719ffa01cSDavid Howells struct rxrpc_conn_proto { 268e8d70ce1SDavid Howells union { 269e8d70ce1SDavid Howells struct { 27019ffa01cSDavid Howells u32 epoch; /* epoch of this connection */ 27119ffa01cSDavid Howells u32 cid; /* connection ID */ 272e8d70ce1SDavid Howells }; 273e8d70ce1SDavid Howells u64 index_key; 27419ffa01cSDavid Howells }; 27519ffa01cSDavid Howells }; 27619ffa01cSDavid Howells 27719ffa01cSDavid Howells struct rxrpc_conn_parameters { 27819ffa01cSDavid Howells struct rxrpc_local *local; /* Representation of local endpoint */ 27919ffa01cSDavid Howells struct rxrpc_peer *peer; /* Remote endpoint */ 28019ffa01cSDavid Howells struct key *key; /* Security details */ 28119ffa01cSDavid Howells bool exclusive; /* T if conn is exclusive */ 28219ffa01cSDavid Howells u16 service_id; /* Service ID for this connection */ 28319ffa01cSDavid Howells u32 security_level; /* Security level selected */ 28419ffa01cSDavid Howells }; 28519ffa01cSDavid Howells 28619ffa01cSDavid Howells /* 287bba304dbSDavid Howells * Bits in the connection flags. 288bba304dbSDavid Howells */ 289bba304dbSDavid Howells enum rxrpc_conn_flag { 290bba304dbSDavid Howells RXRPC_CONN_HAS_IDR, /* Has a client conn ID assigned */ 291001c1122SDavid Howells RXRPC_CONN_IN_SERVICE_CONNS, /* Conn is in peer->service_conns */ 292001c1122SDavid Howells RXRPC_CONN_IN_CLIENT_CONNS, /* Conn is in local->client_conns */ 29345025bceSDavid Howells RXRPC_CONN_EXPOSED, /* Conn has extra ref for exposure */ 29445025bceSDavid Howells RXRPC_CONN_DONT_REUSE, /* Don't reuse this connection */ 29545025bceSDavid Howells RXRPC_CONN_COUNTED, /* Counted by rxrpc_nr_client_conns */ 296bba304dbSDavid Howells }; 297bba304dbSDavid Howells 298bba304dbSDavid Howells /* 299bba304dbSDavid Howells * Events that can be raised upon a connection. 300bba304dbSDavid Howells */ 301bba304dbSDavid Howells enum rxrpc_conn_event { 302bba304dbSDavid Howells RXRPC_CONN_EV_CHALLENGE, /* Send challenge packet */ 303bba304dbSDavid Howells }; 304bba304dbSDavid Howells 305bba304dbSDavid Howells /* 30645025bceSDavid Howells * The connection cache state. 30745025bceSDavid Howells */ 30845025bceSDavid Howells enum rxrpc_conn_cache_state { 30945025bceSDavid Howells RXRPC_CONN_CLIENT_INACTIVE, /* Conn is not yet listed */ 31045025bceSDavid Howells RXRPC_CONN_CLIENT_WAITING, /* Conn is on wait list, waiting for capacity */ 31145025bceSDavid Howells RXRPC_CONN_CLIENT_ACTIVE, /* Conn is on active list, doing calls */ 31245025bceSDavid Howells RXRPC_CONN_CLIENT_CULLED, /* Conn is culled and delisted, doing calls */ 31345025bceSDavid Howells RXRPC_CONN_CLIENT_IDLE, /* Conn is on idle list, doing mostly nothing */ 314363deeabSDavid Howells RXRPC_CONN__NR_CACHE_STATES 31545025bceSDavid Howells }; 31645025bceSDavid Howells 31745025bceSDavid Howells /* 318bba304dbSDavid Howells * The connection protocol state. 319bba304dbSDavid Howells */ 320bba304dbSDavid Howells enum rxrpc_conn_proto_state { 321bba304dbSDavid Howells RXRPC_CONN_UNUSED, /* Connection not yet attempted */ 322bba304dbSDavid Howells RXRPC_CONN_CLIENT, /* Client connection */ 32300e90712SDavid Howells RXRPC_CONN_SERVICE_PREALLOC, /* Service connection preallocation */ 324bba304dbSDavid Howells RXRPC_CONN_SERVICE_UNSECURED, /* Service unsecured connection */ 325bba304dbSDavid Howells RXRPC_CONN_SERVICE_CHALLENGING, /* Service challenging for security */ 326bba304dbSDavid Howells RXRPC_CONN_SERVICE, /* Service secured connection */ 327bba304dbSDavid Howells RXRPC_CONN_REMOTELY_ABORTED, /* Conn aborted by peer */ 328bba304dbSDavid Howells RXRPC_CONN_LOCALLY_ABORTED, /* Conn aborted locally */ 329bba304dbSDavid Howells RXRPC_CONN__NR_STATES 330bba304dbSDavid Howells }; 331bba304dbSDavid Howells 332bba304dbSDavid Howells /* 33317926a79SDavid Howells * RxRPC connection definition 334aa390bbeSDavid Howells * - matched by { local, peer, epoch, conn_id, direction } 33517926a79SDavid Howells * - each connection can only handle four simultaneous calls 33617926a79SDavid Howells */ 33717926a79SDavid Howells struct rxrpc_connection { 33819ffa01cSDavid Howells struct rxrpc_conn_proto proto; 33919ffa01cSDavid Howells struct rxrpc_conn_parameters params; 34019ffa01cSDavid Howells 34145025bceSDavid Howells atomic_t usage; 34245025bceSDavid Howells struct rcu_head rcu; 34345025bceSDavid Howells struct list_head cache_link; 344a1399f8bSDavid Howells 34545025bceSDavid Howells spinlock_t channel_lock; 34645025bceSDavid Howells unsigned char active_chans; /* Mask of active channels */ 34745025bceSDavid Howells #define RXRPC_ACTIVE_CHANS_MASK ((1 << RXRPC_MAXCALLS) - 1) 34845025bceSDavid Howells struct list_head waiting_calls; /* Calls waiting for channels */ 349a1399f8bSDavid Howells struct rxrpc_channel { 350a1399f8bSDavid Howells struct rxrpc_call __rcu *call; /* Active call */ 351a1399f8bSDavid Howells u32 call_id; /* ID of current call */ 352a1399f8bSDavid Howells u32 call_counter; /* Call ID counter */ 353a1399f8bSDavid Howells u32 last_call; /* ID of last call */ 35418bfeba5SDavid Howells u8 last_type; /* Type of last packet */ 35518bfeba5SDavid Howells u16 last_service_id; 35618bfeba5SDavid Howells union { 35718bfeba5SDavid Howells u32 last_seq; 35818bfeba5SDavid Howells u32 last_abort; 35918bfeba5SDavid Howells }; 360a1399f8bSDavid Howells } channels[RXRPC_MAXCALLS]; 361999b69f8SDavid Howells 36217926a79SDavid Howells struct work_struct processor; /* connection event processor */ 363999b69f8SDavid Howells union { 364999b69f8SDavid Howells struct rb_node client_node; /* Node in local->client_conns */ 365aa390bbeSDavid Howells struct rb_node service_node; /* Node in peer->service_conns */ 366999b69f8SDavid Howells }; 3674d028b2cSDavid Howells struct list_head proc_link; /* link in procfs list */ 36817926a79SDavid Howells struct list_head link; /* link in master connection list */ 36917926a79SDavid Howells struct sk_buff_head rx_queue; /* received conn-level packets */ 370648af7fcSDavid Howells const struct rxrpc_security *security; /* applied security module */ 37117926a79SDavid Howells struct key *server_key; /* security for this service */ 3721afe593bSHerbert Xu struct crypto_skcipher *cipher; /* encryption handle */ 37317926a79SDavid Howells struct rxrpc_crypt csum_iv; /* packet checksum base */ 3744a3388c8SDavid Howells unsigned long flags; 37517926a79SDavid Howells unsigned long events; 376f51b4480SDavid Howells unsigned long idle_timestamp; /* Time at which last became idle */ 37717926a79SDavid Howells spinlock_t state_lock; /* state-change lock */ 378cf13258fSDavid Howells enum rxrpc_conn_cache_state cache_state; 379cf13258fSDavid Howells enum rxrpc_conn_proto_state state; /* current state of connection */ 380dc44b3a0SDavid Howells u32 local_abort; /* local abort code */ 381dc44b3a0SDavid Howells u32 remote_abort; /* remote abort code */ 38217926a79SDavid Howells int debug_id; /* debug ID for printks */ 38317926a79SDavid Howells atomic_t serial; /* packet serial number counter */ 384563ea7d5SDavid Howells unsigned int hi_serial; /* highest serial number received */ 38517926a79SDavid Howells u32 security_nonce; /* response re-use preventer */ 3865a924b89SDavid Howells u8 size_align; /* data size alignment (for security) */ 3875a924b89SDavid Howells u8 security_size; /* security header size */ 38817926a79SDavid Howells u8 security_ix; /* security type */ 38917926a79SDavid Howells u8 out_clientflag; /* RXRPC_CLIENT_INITIATED if we are client */ 39017926a79SDavid Howells }; 39117926a79SDavid Howells 39217926a79SDavid Howells /* 3935b8848d1SDavid Howells * Flags in call->flags. 3945b8848d1SDavid Howells */ 3955b8848d1SDavid Howells enum rxrpc_call_flag { 3965b8848d1SDavid Howells RXRPC_CALL_RELEASED, /* call has been released - no more message to userspace */ 3975b8848d1SDavid Howells RXRPC_CALL_HAS_USERID, /* has a user ID attached */ 398dabe5a79SDavid Howells RXRPC_CALL_IS_SERVICE, /* Call is service call */ 39945025bceSDavid Howells RXRPC_CALL_EXPOSED, /* The call was exposed to the world */ 400248f219cSDavid Howells RXRPC_CALL_RX_LAST, /* Received the last packet (at rxtx_top) */ 401248f219cSDavid Howells RXRPC_CALL_TX_LAST, /* Last packet in Tx buffer (at rxtx_top) */ 402a5af7e1fSDavid Howells RXRPC_CALL_SEND_PING, /* A ping will need to be sent */ 4038e83134dSDavid Howells RXRPC_CALL_PINGING, /* Ping in process */ 40457494343SDavid Howells RXRPC_CALL_RETRANS_TIMEOUT, /* Retransmission due to timeout occurred */ 4055b8848d1SDavid Howells }; 4065b8848d1SDavid Howells 4075b8848d1SDavid Howells /* 4085b8848d1SDavid Howells * Events that can be raised on a call. 4095b8848d1SDavid Howells */ 4105b8848d1SDavid Howells enum rxrpc_call_event { 4114c198ad1SDavid Howells RXRPC_CALL_EV_ACK, /* need to generate ACK */ 4124c198ad1SDavid Howells RXRPC_CALL_EV_ABORT, /* need to generate abort */ 413248f219cSDavid Howells RXRPC_CALL_EV_TIMER, /* Timer expired */ 4144c198ad1SDavid Howells RXRPC_CALL_EV_RESEND, /* Tx resend required */ 415a5af7e1fSDavid Howells RXRPC_CALL_EV_PING, /* Ping send required */ 4165b8848d1SDavid Howells }; 4175b8848d1SDavid Howells 4185b8848d1SDavid Howells /* 4195b8848d1SDavid Howells * The states that a call can be in. 4205b8848d1SDavid Howells */ 4215b8848d1SDavid Howells enum rxrpc_call_state { 422999b69f8SDavid Howells RXRPC_CALL_UNINITIALISED, 423999b69f8SDavid Howells RXRPC_CALL_CLIENT_AWAIT_CONN, /* - client waiting for connection to become available */ 4245b8848d1SDavid Howells RXRPC_CALL_CLIENT_SEND_REQUEST, /* - client sending request phase */ 4255b8848d1SDavid Howells RXRPC_CALL_CLIENT_AWAIT_REPLY, /* - client awaiting reply */ 4265b8848d1SDavid Howells RXRPC_CALL_CLIENT_RECV_REPLY, /* - client receiving reply phase */ 42700e90712SDavid Howells RXRPC_CALL_SERVER_PREALLOC, /* - service preallocation */ 4285b8848d1SDavid Howells RXRPC_CALL_SERVER_SECURING, /* - server securing request connection */ 4295b8848d1SDavid Howells RXRPC_CALL_SERVER_ACCEPTING, /* - server accepting request */ 4305b8848d1SDavid Howells RXRPC_CALL_SERVER_RECV_REQUEST, /* - server receiving request */ 4315b8848d1SDavid Howells RXRPC_CALL_SERVER_ACK_REQUEST, /* - server pending ACK of request */ 4325b8848d1SDavid Howells RXRPC_CALL_SERVER_SEND_REPLY, /* - server sending reply */ 4335b8848d1SDavid Howells RXRPC_CALL_SERVER_AWAIT_ACK, /* - server awaiting final ACK */ 434f5c17aaeSDavid Howells RXRPC_CALL_COMPLETE, /* - call complete */ 435f5c17aaeSDavid Howells NR__RXRPC_CALL_STATES 436f5c17aaeSDavid Howells }; 437f5c17aaeSDavid Howells 438f5c17aaeSDavid Howells /* 439f5c17aaeSDavid Howells * Call completion condition (state == RXRPC_CALL_COMPLETE). 440f5c17aaeSDavid Howells */ 441f5c17aaeSDavid Howells enum rxrpc_call_completion { 442f5c17aaeSDavid Howells RXRPC_CALL_SUCCEEDED, /* - Normal termination */ 4435b8848d1SDavid Howells RXRPC_CALL_REMOTELY_ABORTED, /* - call aborted by peer */ 4445b8848d1SDavid Howells RXRPC_CALL_LOCALLY_ABORTED, /* - call aborted locally on error or close */ 445f5c17aaeSDavid Howells RXRPC_CALL_LOCAL_ERROR, /* - call failed due to local error */ 4465b8848d1SDavid Howells RXRPC_CALL_NETWORK_ERROR, /* - call terminated by network error */ 447f5c17aaeSDavid Howells NR__RXRPC_CALL_COMPLETIONS 4485b8848d1SDavid Howells }; 4495b8848d1SDavid Howells 4505b8848d1SDavid Howells /* 45157494343SDavid Howells * Call Tx congestion management modes. 45257494343SDavid Howells */ 45357494343SDavid Howells enum rxrpc_congest_mode { 45457494343SDavid Howells RXRPC_CALL_SLOW_START, 45557494343SDavid Howells RXRPC_CALL_CONGEST_AVOIDANCE, 45657494343SDavid Howells RXRPC_CALL_PACKET_LOSS, 45757494343SDavid Howells RXRPC_CALL_FAST_RETRANSMIT, 45857494343SDavid Howells NR__RXRPC_CONGEST_MODES 45957494343SDavid Howells }; 46057494343SDavid Howells 46157494343SDavid Howells /* 46217926a79SDavid Howells * RxRPC call definition 46317926a79SDavid Howells * - matched by { connection, call_id } 46417926a79SDavid Howells */ 46517926a79SDavid Howells struct rxrpc_call { 466dee46364SDavid Howells struct rcu_head rcu; 46717926a79SDavid Howells struct rxrpc_connection *conn; /* connection carrying call */ 468df5d8bf7SDavid Howells struct rxrpc_peer *peer; /* Peer record for remote address */ 4698d94aa38SDavid Howells struct rxrpc_sock __rcu *socket; /* socket responsible */ 470df0adc78SDavid Howells ktime_t ack_at; /* When deferred ACK needs to happen */ 471df0adc78SDavid Howells ktime_t resend_at; /* When next resend needs to happen */ 472a5af7e1fSDavid Howells ktime_t ping_at; /* When next to send a ping */ 473df0adc78SDavid Howells ktime_t expire_at; /* When the call times out */ 474248f219cSDavid Howells struct timer_list timer; /* Combined event timer */ 475248f219cSDavid Howells struct work_struct processor; /* Event processor */ 476d001648eSDavid Howells rxrpc_notify_rx_t notify_rx; /* kernel service Rx notification function */ 47717926a79SDavid Howells struct list_head link; /* link in master call list */ 47845025bceSDavid Howells struct list_head chan_wait_link; /* Link in conn->waiting_calls */ 479f66d7490SDavid Howells struct hlist_node error_link; /* link in error distribution list */ 480248f219cSDavid Howells struct list_head accept_link; /* Link in rx->acceptq */ 481248f219cSDavid Howells struct list_head recvmsg_link; /* Link in rx->recvmsg_q */ 482248f219cSDavid Howells struct list_head sock_link; /* Link in rx->sock_calls */ 483248f219cSDavid Howells struct rb_node sock_node; /* Node in rx->calls */ 48417926a79SDavid Howells struct sk_buff *tx_pending; /* Tx socket buffer being filled */ 48545025bceSDavid Howells wait_queue_head_t waitq; /* Wait queue for channel or Tx */ 486a263629dSHerbert Xu __be32 crypto_buf[2]; /* Temporary packet crypto buffer */ 48717926a79SDavid Howells unsigned long user_call_ID; /* user-defined call ID */ 48817926a79SDavid Howells unsigned long flags; 48917926a79SDavid Howells unsigned long events; 49017926a79SDavid Howells spinlock_t lock; 49117926a79SDavid Howells rwlock_t state_lock; /* lock for state transition */ 492f5c17aaeSDavid Howells u32 abort_code; /* Local/remote abort code */ 493f5c17aaeSDavid Howells int error; /* Local error incurred */ 494cf13258fSDavid Howells enum rxrpc_call_state state; /* current state of call */ 495cf13258fSDavid Howells enum rxrpc_call_completion completion; /* Call completion condition */ 49617926a79SDavid Howells atomic_t usage; 497dabe5a79SDavid Howells u16 service_id; /* service ID */ 498278ac0cdSDavid Howells u8 security_ix; /* Security type */ 499dabe5a79SDavid Howells u32 call_id; /* call ID on connection */ 500dabe5a79SDavid Howells u32 cid; /* connection ID plus channel index */ 501dabe5a79SDavid Howells int debug_id; /* debug ID for printks */ 5028e83134dSDavid Howells unsigned short rx_pkt_offset; /* Current recvmsg packet offset */ 5038e83134dSDavid Howells unsigned short rx_pkt_len; /* Current recvmsg packet len */ 50417926a79SDavid Howells 505248f219cSDavid Howells /* Rx/Tx circular buffer, depending on phase. 506248f219cSDavid Howells * 507248f219cSDavid Howells * In the Rx phase, packets are annotated with 0 or the number of the 508248f219cSDavid Howells * segment of a jumbo packet each buffer refers to. There can be up to 509248f219cSDavid Howells * 47 segments in a maximum-size UDP packet. 510248f219cSDavid Howells * 511248f219cSDavid Howells * In the Tx phase, packets are annotated with which buffers have been 512248f219cSDavid Howells * acked. 51317926a79SDavid Howells */ 514248f219cSDavid Howells #define RXRPC_RXTX_BUFF_SIZE 64 515248f219cSDavid Howells #define RXRPC_RXTX_BUFF_MASK (RXRPC_RXTX_BUFF_SIZE - 1) 51675e42126SDavid Howells #define RXRPC_INIT_RX_WINDOW_SIZE 32 517248f219cSDavid Howells struct sk_buff **rxtx_buffer; 518248f219cSDavid Howells u8 *rxtx_annotations; 519248f219cSDavid Howells #define RXRPC_TX_ANNO_ACK 0 520248f219cSDavid Howells #define RXRPC_TX_ANNO_UNACK 1 521248f219cSDavid Howells #define RXRPC_TX_ANNO_NAK 2 522248f219cSDavid Howells #define RXRPC_TX_ANNO_RETRANS 3 523f07373eaSDavid Howells #define RXRPC_TX_ANNO_MASK 0x03 52470790dbeSDavid Howells #define RXRPC_TX_ANNO_LAST 0x04 52570790dbeSDavid Howells #define RXRPC_TX_ANNO_RESENT 0x08 52670790dbeSDavid Howells 527248f219cSDavid Howells #define RXRPC_RX_ANNO_JUMBO 0x3f /* Jumbo subpacket number + 1 if not zero */ 528248f219cSDavid Howells #define RXRPC_RX_ANNO_JLAST 0x40 /* Set if last element of a jumbo packet */ 529248f219cSDavid Howells #define RXRPC_RX_ANNO_VERIFIED 0x80 /* Set if verified and decrypted */ 530248f219cSDavid Howells rxrpc_seq_t tx_hard_ack; /* Dead slot in buffer; the first transmitted but 531248f219cSDavid Howells * not hard-ACK'd packet follows this. 532248f219cSDavid Howells */ 533248f219cSDavid Howells rxrpc_seq_t tx_top; /* Highest Tx slot allocated. */ 53457494343SDavid Howells 53557494343SDavid Howells /* TCP-style slow-start congestion control [RFC5681]. Since the SMSS 53657494343SDavid Howells * is fixed, we keep these numbers in terms of segments (ie. DATA 53757494343SDavid Howells * packets) rather than bytes. 53857494343SDavid Howells */ 53957494343SDavid Howells #define RXRPC_TX_SMSS RXRPC_JUMBO_DATALEN 54057494343SDavid Howells u8 cong_cwnd; /* Congestion window size */ 54157494343SDavid Howells u8 cong_extra; /* Extra to send for congestion management */ 54257494343SDavid Howells u8 cong_ssthresh; /* Slow-start threshold */ 54357494343SDavid Howells enum rxrpc_congest_mode cong_mode:8; /* Congestion management mode */ 54457494343SDavid Howells u8 cong_dup_acks; /* Count of ACKs showing missing packets */ 54557494343SDavid Howells u8 cong_cumul_acks; /* Cumulative ACK count */ 54657494343SDavid Howells ktime_t cong_tstamp; /* Last time cwnd was changed */ 54757494343SDavid Howells 548248f219cSDavid Howells rxrpc_seq_t rx_hard_ack; /* Dead slot in buffer; the first received but not 549248f219cSDavid Howells * consumed packet follows this. 550248f219cSDavid Howells */ 551248f219cSDavid Howells rxrpc_seq_t rx_top; /* Highest Rx slot allocated. */ 552248f219cSDavid Howells rxrpc_seq_t rx_expect_next; /* Expected next packet sequence number */ 553248f219cSDavid Howells u8 rx_winsize; /* Size of Rx window */ 554248f219cSDavid Howells u8 tx_winsize; /* Maximum size of Tx window */ 55571f3ca40SDavid Howells bool tx_phase; /* T if transmission phase, F if receive phase */ 55675e42126SDavid Howells u8 nr_jumbo_bad; /* Number of jumbo dups/exceeds-windows */ 55717926a79SDavid Howells 55817926a79SDavid Howells /* receive-phase ACK management */ 5594e36a95eSDavid Howells u8 ackr_reason; /* reason to ACK */ 560563ea7d5SDavid Howells u16 ackr_skew; /* skew on packet being ACK'd */ 5610d12f8a4SDavid Howells rxrpc_serial_t ackr_serial; /* serial of packet being ACK'd */ 562248f219cSDavid Howells rxrpc_seq_t ackr_prev_seq; /* previous sequence number received */ 563805b21b9SDavid Howells rxrpc_seq_t ackr_consumed; /* Highest packet shown consumed */ 564805b21b9SDavid Howells rxrpc_seq_t ackr_seen; /* Highest packet shown seen */ 565a5af7e1fSDavid Howells 566a5af7e1fSDavid Howells /* ping management */ 567a5af7e1fSDavid Howells rxrpc_serial_t ping_serial; /* Last ping sent */ 568a5af7e1fSDavid Howells ktime_t ping_time; /* Time last ping sent */ 56917926a79SDavid Howells 570248f219cSDavid Howells /* transmission-phase ACK management */ 57157494343SDavid Howells ktime_t acks_latest_ts; /* Timestamp of latest ACK received */ 572248f219cSDavid Howells rxrpc_serial_t acks_latest; /* serial number of latest ACK received */ 57331a1b989SDavid Howells rxrpc_seq_t acks_lowest_nak; /* Lowest NACK in the buffer (or ==tx_hard_ack) */ 57431a1b989SDavid Howells }; 57531a1b989SDavid Howells 57631a1b989SDavid Howells /* 57757494343SDavid Howells * Summary of a new ACK and the changes it made to the Tx buffer packet states. 57831a1b989SDavid Howells */ 57931a1b989SDavid Howells struct rxrpc_ack_summary { 58031a1b989SDavid Howells u8 ack_reason; 58131a1b989SDavid Howells u8 nr_acks; /* Number of ACKs in packet */ 58231a1b989SDavid Howells u8 nr_nacks; /* Number of NACKs in packet */ 58331a1b989SDavid Howells u8 nr_new_acks; /* Number of new ACKs in packet */ 58431a1b989SDavid Howells u8 nr_new_nacks; /* Number of new NACKs in packet */ 58531a1b989SDavid Howells u8 nr_rot_new_acks; /* Number of rotated new ACKs */ 58631a1b989SDavid Howells bool new_low_nack; /* T if new low NACK found */ 58757494343SDavid Howells bool retrans_timeo; /* T if reTx due to timeout happened */ 58857494343SDavid Howells u8 flight_size; /* Number of unreceived transmissions */ 58957494343SDavid Howells /* Place to stash values for tracing */ 59057494343SDavid Howells enum rxrpc_congest_mode mode:8; 59157494343SDavid Howells u8 cwnd; 59257494343SDavid Howells u8 ssthresh; 59357494343SDavid Howells u8 dup_acks; 59457494343SDavid Howells u8 cumulative_acks; 59517926a79SDavid Howells }; 59617926a79SDavid Howells 597df844fd4SDavid Howells #include <trace/events/rxrpc.h> 598df844fd4SDavid Howells 59917926a79SDavid Howells /* 600651350d1SDavid Howells * af_rxrpc.c 60117926a79SDavid Howells */ 60271f3ca40SDavid Howells extern atomic_t rxrpc_n_tx_skbs, rxrpc_n_rx_skbs; 6030d12f8a4SDavid Howells extern u32 rxrpc_epoch; 604651350d1SDavid Howells extern atomic_t rxrpc_debug_id; 605651350d1SDavid Howells extern struct workqueue_struct *rxrpc_workqueue; 60617926a79SDavid Howells 60717926a79SDavid Howells /* 6080d81a51aSDavid Howells * call_accept.c 60917926a79SDavid Howells */ 61000e90712SDavid Howells int rxrpc_service_prealloc(struct rxrpc_sock *, gfp_t); 61100e90712SDavid Howells void rxrpc_discard_prealloc(struct rxrpc_sock *); 612248f219cSDavid Howells struct rxrpc_call *rxrpc_new_incoming_call(struct rxrpc_local *, 613248f219cSDavid Howells struct rxrpc_connection *, 614248f219cSDavid Howells struct sk_buff *); 6154f95dd78SDavid Howells void rxrpc_accept_incoming_calls(struct rxrpc_local *); 616d001648eSDavid Howells struct rxrpc_call *rxrpc_accept_call(struct rxrpc_sock *, unsigned long, 617d001648eSDavid Howells rxrpc_notify_rx_t); 618c1b1203dSJoe Perches int rxrpc_reject_call(struct rxrpc_sock *); 61917926a79SDavid Howells 62017926a79SDavid Howells /* 6210d81a51aSDavid Howells * call_event.c 62217926a79SDavid Howells */ 6239749fd2bSDavid Howells void __rxrpc_set_timer(struct rxrpc_call *, enum rxrpc_timer_trace, ktime_t); 624df0adc78SDavid Howells void rxrpc_set_timer(struct rxrpc_call *, enum rxrpc_timer_trace, ktime_t); 6259c7ad434SDavid Howells void rxrpc_propose_ACK(struct rxrpc_call *, u8, u16, u32, bool, bool, 6269c7ad434SDavid Howells enum rxrpc_propose_ack_trace); 627c1b1203dSJoe Perches void rxrpc_process_call(struct work_struct *); 62817926a79SDavid Howells 62917926a79SDavid Howells /* 6300d81a51aSDavid Howells * call_object.c 63117926a79SDavid Howells */ 632f5c17aaeSDavid Howells extern const char *const rxrpc_call_states[]; 633f5c17aaeSDavid Howells extern const char *const rxrpc_call_completions[]; 634dad8aff7SDavid Howells extern unsigned int rxrpc_max_call_lifetime; 63517926a79SDavid Howells extern struct kmem_cache *rxrpc_call_jar; 63617926a79SDavid Howells extern struct list_head rxrpc_calls; 63717926a79SDavid Howells extern rwlock_t rxrpc_call_lock; 63817926a79SDavid Howells 6392341e077SDavid Howells struct rxrpc_call *rxrpc_find_call_by_user_ID(struct rxrpc_sock *, unsigned long); 64000e90712SDavid Howells struct rxrpc_call *rxrpc_alloc_call(gfp_t); 6412341e077SDavid Howells struct rxrpc_call *rxrpc_new_client_call(struct rxrpc_sock *, 64219ffa01cSDavid Howells struct rxrpc_conn_parameters *, 643999b69f8SDavid Howells struct sockaddr_rxrpc *, 6442341e077SDavid Howells unsigned long, gfp_t); 645248f219cSDavid Howells void rxrpc_incoming_call(struct rxrpc_sock *, struct rxrpc_call *, 64642886ffeSDavid Howells struct sk_buff *); 6478d94aa38SDavid Howells void rxrpc_release_call(struct rxrpc_sock *, struct rxrpc_call *); 648c1b1203dSJoe Perches void rxrpc_release_calls_on_socket(struct rxrpc_sock *); 6498d94aa38SDavid Howells bool __rxrpc_queue_call(struct rxrpc_call *); 6508d94aa38SDavid Howells bool rxrpc_queue_call(struct rxrpc_call *); 651e34d4234SDavid Howells void rxrpc_see_call(struct rxrpc_call *); 652fff72429SDavid Howells void rxrpc_get_call(struct rxrpc_call *, enum rxrpc_call_trace); 653fff72429SDavid Howells void rxrpc_put_call(struct rxrpc_call *, enum rxrpc_call_trace); 65400e90712SDavid Howells void rxrpc_cleanup_call(struct rxrpc_call *); 655c1b1203dSJoe Perches void __exit rxrpc_destroy_all_calls(void); 65617926a79SDavid Howells 657dabe5a79SDavid Howells static inline bool rxrpc_is_service_call(const struct rxrpc_call *call) 658dabe5a79SDavid Howells { 659dabe5a79SDavid Howells return test_bit(RXRPC_CALL_IS_SERVICE, &call->flags); 660dabe5a79SDavid Howells } 661dabe5a79SDavid Howells 662dabe5a79SDavid Howells static inline bool rxrpc_is_client_call(const struct rxrpc_call *call) 663dabe5a79SDavid Howells { 664dabe5a79SDavid Howells return !rxrpc_is_service_call(call); 665dabe5a79SDavid Howells } 666dabe5a79SDavid Howells 66717926a79SDavid Howells /* 668f5c17aaeSDavid Howells * Transition a call to the complete state. 669f5c17aaeSDavid Howells */ 670f5c17aaeSDavid Howells static inline bool __rxrpc_set_call_completion(struct rxrpc_call *call, 671f5c17aaeSDavid Howells enum rxrpc_call_completion compl, 672f5c17aaeSDavid Howells u32 abort_code, 673f5c17aaeSDavid Howells int error) 674f5c17aaeSDavid Howells { 675f5c17aaeSDavid Howells if (call->state < RXRPC_CALL_COMPLETE) { 676f5c17aaeSDavid Howells call->abort_code = abort_code; 677f5c17aaeSDavid Howells call->error = error; 678f5c17aaeSDavid Howells call->completion = compl, 679f5c17aaeSDavid Howells call->state = RXRPC_CALL_COMPLETE; 680c0d058c2SDavid Howells wake_up(&call->waitq); 681f5c17aaeSDavid Howells return true; 682f5c17aaeSDavid Howells } 683f5c17aaeSDavid Howells return false; 684f5c17aaeSDavid Howells } 685f5c17aaeSDavid Howells 686f5c17aaeSDavid Howells static inline bool rxrpc_set_call_completion(struct rxrpc_call *call, 687f5c17aaeSDavid Howells enum rxrpc_call_completion compl, 688f5c17aaeSDavid Howells u32 abort_code, 689f5c17aaeSDavid Howells int error) 690f5c17aaeSDavid Howells { 691e8d6bbb0SDavid Howells bool ret; 692f5c17aaeSDavid Howells 693f5c17aaeSDavid Howells write_lock_bh(&call->state_lock); 694f5c17aaeSDavid Howells ret = __rxrpc_set_call_completion(call, compl, abort_code, error); 695f5c17aaeSDavid Howells write_unlock_bh(&call->state_lock); 696f5c17aaeSDavid Howells return ret; 697f5c17aaeSDavid Howells } 698f5c17aaeSDavid Howells 699f5c17aaeSDavid Howells /* 700f5c17aaeSDavid Howells * Record that a call successfully completed. 701f5c17aaeSDavid Howells */ 702e8d6bbb0SDavid Howells static inline bool __rxrpc_call_completed(struct rxrpc_call *call) 703f5c17aaeSDavid Howells { 704e8d6bbb0SDavid Howells return __rxrpc_set_call_completion(call, RXRPC_CALL_SUCCEEDED, 0, 0); 705f5c17aaeSDavid Howells } 706f5c17aaeSDavid Howells 707e8d6bbb0SDavid Howells static inline bool rxrpc_call_completed(struct rxrpc_call *call) 708f5c17aaeSDavid Howells { 709e8d6bbb0SDavid Howells bool ret; 710e8d6bbb0SDavid Howells 711f5c17aaeSDavid Howells write_lock_bh(&call->state_lock); 712e8d6bbb0SDavid Howells ret = __rxrpc_call_completed(call); 713f5c17aaeSDavid Howells write_unlock_bh(&call->state_lock); 714e8d6bbb0SDavid Howells return ret; 715f5c17aaeSDavid Howells } 716f5c17aaeSDavid Howells 717f5c17aaeSDavid Howells /* 718f5c17aaeSDavid Howells * Record that a call is locally aborted. 719f5c17aaeSDavid Howells */ 7205a42976dSDavid Howells static inline bool __rxrpc_abort_call(const char *why, struct rxrpc_call *call, 7215a42976dSDavid Howells rxrpc_seq_t seq, 722f5c17aaeSDavid Howells u32 abort_code, int error) 723f5c17aaeSDavid Howells { 7245a42976dSDavid Howells trace_rxrpc_abort(why, call->cid, call->call_id, seq, 7255a42976dSDavid Howells abort_code, error); 726248f219cSDavid Howells return __rxrpc_set_call_completion(call, RXRPC_CALL_LOCALLY_ABORTED, 727248f219cSDavid Howells abort_code, error); 728f5c17aaeSDavid Howells } 729f5c17aaeSDavid Howells 7305a42976dSDavid Howells static inline bool rxrpc_abort_call(const char *why, struct rxrpc_call *call, 7315a42976dSDavid Howells rxrpc_seq_t seq, u32 abort_code, int error) 732f5c17aaeSDavid Howells { 733f5c17aaeSDavid Howells bool ret; 734f5c17aaeSDavid Howells 735f5c17aaeSDavid Howells write_lock_bh(&call->state_lock); 7365a42976dSDavid Howells ret = __rxrpc_abort_call(why, call, seq, abort_code, error); 737f5c17aaeSDavid Howells write_unlock_bh(&call->state_lock); 738f5c17aaeSDavid Howells return ret; 739f5c17aaeSDavid Howells } 740f5c17aaeSDavid Howells 741f5c17aaeSDavid Howells /* 7424a3388c8SDavid Howells * conn_client.c 7434a3388c8SDavid Howells */ 74445025bceSDavid Howells extern unsigned int rxrpc_max_client_connections; 74545025bceSDavid Howells extern unsigned int rxrpc_reap_client_connections; 74645025bceSDavid Howells extern unsigned int rxrpc_conn_idle_client_expiry; 74745025bceSDavid Howells extern unsigned int rxrpc_conn_idle_client_fast_expiry; 7484a3388c8SDavid Howells extern struct idr rxrpc_client_conn_ids; 7494a3388c8SDavid Howells 750eb9b9d22SDavid Howells void rxrpc_destroy_client_conn_ids(void); 751c6d2b8d7SDavid Howells int rxrpc_connect_call(struct rxrpc_call *, struct rxrpc_conn_parameters *, 752c6d2b8d7SDavid Howells struct sockaddr_rxrpc *, gfp_t); 75345025bceSDavid Howells void rxrpc_expose_client_call(struct rxrpc_call *); 75445025bceSDavid Howells void rxrpc_disconnect_client_call(struct rxrpc_call *); 75545025bceSDavid Howells void rxrpc_put_client_conn(struct rxrpc_connection *); 75645025bceSDavid Howells void __exit rxrpc_destroy_all_client_connections(void); 7574a3388c8SDavid Howells 7584a3388c8SDavid Howells /* 7590d81a51aSDavid Howells * conn_event.c 7600d81a51aSDavid Howells */ 7610d81a51aSDavid Howells void rxrpc_process_connection(struct work_struct *); 7620d81a51aSDavid Howells 7630d81a51aSDavid Howells /* 7640d81a51aSDavid Howells * conn_object.c 76517926a79SDavid Howells */ 766dad8aff7SDavid Howells extern unsigned int rxrpc_connection_expiry; 76717926a79SDavid Howells extern struct list_head rxrpc_connections; 7684d028b2cSDavid Howells extern struct list_head rxrpc_connection_proc_list; 76917926a79SDavid Howells extern rwlock_t rxrpc_connection_lock; 77017926a79SDavid Howells 7718496af50SDavid Howells int rxrpc_extract_addr_from_skb(struct sockaddr_rxrpc *, struct sk_buff *); 772c6d2b8d7SDavid Howells struct rxrpc_connection *rxrpc_alloc_connection(gfp_t); 7738496af50SDavid Howells struct rxrpc_connection *rxrpc_find_connection_rcu(struct rxrpc_local *, 774aa390bbeSDavid Howells struct sk_buff *); 77545025bceSDavid Howells void __rxrpc_disconnect_call(struct rxrpc_connection *, struct rxrpc_call *); 776999b69f8SDavid Howells void rxrpc_disconnect_call(struct rxrpc_call *); 77745025bceSDavid Howells void rxrpc_kill_connection(struct rxrpc_connection *); 778363deeabSDavid Howells bool rxrpc_queue_conn(struct rxrpc_connection *); 779363deeabSDavid Howells void rxrpc_see_connection(struct rxrpc_connection *); 780363deeabSDavid Howells void rxrpc_get_connection(struct rxrpc_connection *); 781363deeabSDavid Howells struct rxrpc_connection *rxrpc_get_connection_maybe(struct rxrpc_connection *); 782363deeabSDavid Howells void rxrpc_put_service_conn(struct rxrpc_connection *); 783c1b1203dSJoe Perches void __exit rxrpc_destroy_all_connections(void); 78417926a79SDavid Howells 78519ffa01cSDavid Howells static inline bool rxrpc_conn_is_client(const struct rxrpc_connection *conn) 78619ffa01cSDavid Howells { 78719ffa01cSDavid Howells return conn->out_clientflag; 78819ffa01cSDavid Howells } 78919ffa01cSDavid Howells 79019ffa01cSDavid Howells static inline bool rxrpc_conn_is_service(const struct rxrpc_connection *conn) 79119ffa01cSDavid Howells { 792e8d70ce1SDavid Howells return !rxrpc_conn_is_client(conn); 79319ffa01cSDavid Howells } 79419ffa01cSDavid Howells 795f51b4480SDavid Howells static inline void rxrpc_put_connection(struct rxrpc_connection *conn) 796f51b4480SDavid Howells { 79745025bceSDavid Howells if (!conn) 79845025bceSDavid Howells return; 79945025bceSDavid Howells 800363deeabSDavid Howells if (rxrpc_conn_is_client(conn)) 80145025bceSDavid Howells rxrpc_put_client_conn(conn); 802363deeabSDavid Howells else 803363deeabSDavid Howells rxrpc_put_service_conn(conn); 8045acbee46SDavid Howells } 8055acbee46SDavid Howells 80617926a79SDavid Howells /* 8077877a4a4SDavid Howells * conn_service.c 8087877a4a4SDavid Howells */ 8098496af50SDavid Howells struct rxrpc_connection *rxrpc_find_service_conn_rcu(struct rxrpc_peer *, 8108496af50SDavid Howells struct sk_buff *); 81100e90712SDavid Howells struct rxrpc_connection *rxrpc_prealloc_service_connection(gfp_t); 812248f219cSDavid Howells void rxrpc_new_incoming_connection(struct rxrpc_connection *, struct sk_buff *); 813001c1122SDavid Howells void rxrpc_unpublish_service_conn(struct rxrpc_connection *); 8147877a4a4SDavid Howells 8157877a4a4SDavid Howells /* 8160d81a51aSDavid Howells * input.c 81717926a79SDavid Howells */ 818676d2369SDavid S. Miller void rxrpc_data_ready(struct sock *); 81917926a79SDavid Howells 82017926a79SDavid Howells /* 8210d81a51aSDavid Howells * insecure.c 82217926a79SDavid Howells */ 8230d81a51aSDavid Howells extern const struct rxrpc_security rxrpc_no_security; 82417926a79SDavid Howells 82517926a79SDavid Howells /* 8260d81a51aSDavid Howells * key.c 82717926a79SDavid Howells */ 82817926a79SDavid Howells extern struct key_type key_type_rxrpc; 82917926a79SDavid Howells extern struct key_type key_type_rxrpc_s; 83017926a79SDavid Howells 831c1b1203dSJoe Perches int rxrpc_request_key(struct rxrpc_sock *, char __user *, int); 832c1b1203dSJoe Perches int rxrpc_server_keyring(struct rxrpc_sock *, char __user *, int); 833c1b1203dSJoe Perches int rxrpc_get_server_data_key(struct rxrpc_connection *, const void *, time_t, 834c1b1203dSJoe Perches u32); 83517926a79SDavid Howells 83617926a79SDavid Howells /* 83787563616SDavid Howells * local_event.c 83887563616SDavid Howells */ 8394f95dd78SDavid Howells extern void rxrpc_process_local_events(struct rxrpc_local *); 84087563616SDavid Howells 84187563616SDavid Howells /* 8420d81a51aSDavid Howells * local_object.c 84317926a79SDavid Howells */ 8444f95dd78SDavid Howells struct rxrpc_local *rxrpc_lookup_local(const struct sockaddr_rxrpc *); 8454f95dd78SDavid Howells void __rxrpc_put_local(struct rxrpc_local *); 8460d81a51aSDavid Howells void __exit rxrpc_destroy_all_locals(void); 847e0e4d82fSDavid Howells 8484f95dd78SDavid Howells static inline void rxrpc_get_local(struct rxrpc_local *local) 8494f95dd78SDavid Howells { 8504f95dd78SDavid Howells atomic_inc(&local->usage); 8514f95dd78SDavid Howells } 8524f95dd78SDavid Howells 8534f95dd78SDavid Howells static inline 8544f95dd78SDavid Howells struct rxrpc_local *rxrpc_get_local_maybe(struct rxrpc_local *local) 8554f95dd78SDavid Howells { 8564f95dd78SDavid Howells return atomic_inc_not_zero(&local->usage) ? local : NULL; 8574f95dd78SDavid Howells } 8584f95dd78SDavid Howells 8594f95dd78SDavid Howells static inline void rxrpc_put_local(struct rxrpc_local *local) 8604f95dd78SDavid Howells { 8615627cc8bSDavid Howells if (local && atomic_dec_and_test(&local->usage)) 8624f95dd78SDavid Howells __rxrpc_put_local(local); 8634f95dd78SDavid Howells } 8644f95dd78SDavid Howells 8655acbee46SDavid Howells static inline void rxrpc_queue_local(struct rxrpc_local *local) 8665acbee46SDavid Howells { 8675acbee46SDavid Howells rxrpc_queue_work(&local->processor); 8685acbee46SDavid Howells } 8695acbee46SDavid Howells 870e0e4d82fSDavid Howells /* 8718e688d9cSDavid Howells * misc.c 8728e688d9cSDavid Howells */ 8730e119b41SDavid Howells extern unsigned int rxrpc_max_backlog __read_mostly; 8748e688d9cSDavid Howells extern unsigned int rxrpc_requested_ack_delay; 8758e688d9cSDavid Howells extern unsigned int rxrpc_soft_ack_delay; 8768e688d9cSDavid Howells extern unsigned int rxrpc_idle_ack_delay; 8778e688d9cSDavid Howells extern unsigned int rxrpc_rx_window_size; 8788e688d9cSDavid Howells extern unsigned int rxrpc_rx_mtu; 8798e688d9cSDavid Howells extern unsigned int rxrpc_rx_jumbo_max; 8800b58b8a1SDavid Howells extern unsigned int rxrpc_resend_timeout; 8818e688d9cSDavid Howells 8828e688d9cSDavid Howells extern const s8 rxrpc_ack_priority[]; 8838e688d9cSDavid Howells 8848e688d9cSDavid Howells /* 8850d81a51aSDavid Howells * output.c 8860d81a51aSDavid Howells */ 887a5af7e1fSDavid Howells int rxrpc_send_ack_packet(struct rxrpc_call *, bool); 88826cb02aaSDavid Howells int rxrpc_send_abort_packet(struct rxrpc_call *); 889a1767077SDavid Howells int rxrpc_send_data_packet(struct rxrpc_call *, struct sk_buff *, bool); 890248f219cSDavid Howells void rxrpc_reject_packets(struct rxrpc_local *); 8910d81a51aSDavid Howells 8920d81a51aSDavid Howells /* 893abe89ef0SDavid Howells * peer_event.c 8940d81a51aSDavid Howells */ 895abe89ef0SDavid Howells void rxrpc_error_report(struct sock *); 896f66d7490SDavid Howells void rxrpc_peer_error_distributor(struct work_struct *); 897cf1a6474SDavid Howells void rxrpc_peer_add_rtt(struct rxrpc_call *, enum rxrpc_rtt_rx_trace, 898cf1a6474SDavid Howells rxrpc_serial_t, rxrpc_serial_t, ktime_t, ktime_t); 8990d81a51aSDavid Howells 9000d81a51aSDavid Howells /* 9010d81a51aSDavid Howells * peer_object.c 9020d81a51aSDavid Howells */ 903be6e6707SDavid Howells struct rxrpc_peer *rxrpc_lookup_peer_rcu(struct rxrpc_local *, 904be6e6707SDavid Howells const struct sockaddr_rxrpc *); 905be6e6707SDavid Howells struct rxrpc_peer *rxrpc_lookup_peer(struct rxrpc_local *, 906be6e6707SDavid Howells struct sockaddr_rxrpc *, gfp_t); 907be6e6707SDavid Howells struct rxrpc_peer *rxrpc_alloc_peer(struct rxrpc_local *, gfp_t); 908248f219cSDavid Howells struct rxrpc_peer *rxrpc_lookup_incoming_peer(struct rxrpc_local *, 909248f219cSDavid Howells struct rxrpc_peer *); 910be6e6707SDavid Howells 911df5d8bf7SDavid Howells static inline struct rxrpc_peer *rxrpc_get_peer(struct rxrpc_peer *peer) 912be6e6707SDavid Howells { 913be6e6707SDavid Howells atomic_inc(&peer->usage); 914df5d8bf7SDavid Howells return peer; 915be6e6707SDavid Howells } 916be6e6707SDavid Howells 917be6e6707SDavid Howells static inline 918be6e6707SDavid Howells struct rxrpc_peer *rxrpc_get_peer_maybe(struct rxrpc_peer *peer) 919be6e6707SDavid Howells { 920be6e6707SDavid Howells return atomic_inc_not_zero(&peer->usage) ? peer : NULL; 921be6e6707SDavid Howells } 922be6e6707SDavid Howells 923be6e6707SDavid Howells extern void __rxrpc_put_peer(struct rxrpc_peer *peer); 924be6e6707SDavid Howells static inline void rxrpc_put_peer(struct rxrpc_peer *peer) 925be6e6707SDavid Howells { 9265627cc8bSDavid Howells if (peer && atomic_dec_and_test(&peer->usage)) 927be6e6707SDavid Howells __rxrpc_put_peer(peer); 928be6e6707SDavid Howells } 9290d81a51aSDavid Howells 9300d81a51aSDavid Howells /* 9310d81a51aSDavid Howells * proc.c 9320d81a51aSDavid Howells */ 9330d81a51aSDavid Howells extern const struct file_operations rxrpc_call_seq_fops; 9340d81a51aSDavid Howells extern const struct file_operations rxrpc_connection_seq_fops; 9350d81a51aSDavid Howells 9360d81a51aSDavid Howells /* 9370d81a51aSDavid Howells * recvmsg.c 9380d81a51aSDavid Howells */ 939248f219cSDavid Howells void rxrpc_notify_socket(struct rxrpc_call *); 9400d81a51aSDavid Howells int rxrpc_recvmsg(struct socket *, struct msghdr *, size_t, int); 9410d81a51aSDavid Howells 9420d81a51aSDavid Howells /* 943648af7fcSDavid Howells * rxkad.c 944648af7fcSDavid Howells */ 945648af7fcSDavid Howells #ifdef CONFIG_RXKAD 946648af7fcSDavid Howells extern const struct rxrpc_security rxkad; 947648af7fcSDavid Howells #endif 948648af7fcSDavid Howells 949648af7fcSDavid Howells /* 9500d81a51aSDavid Howells * security.c 9510d81a51aSDavid Howells */ 9520d81a51aSDavid Howells int __init rxrpc_init_security(void); 9530d81a51aSDavid Howells void rxrpc_exit_security(void); 9540d81a51aSDavid Howells int rxrpc_init_client_conn_security(struct rxrpc_connection *); 9550d81a51aSDavid Howells int rxrpc_init_server_conn_security(struct rxrpc_connection *); 9560d81a51aSDavid Howells 9570d81a51aSDavid Howells /* 9580b58b8a1SDavid Howells * sendmsg.c 9590b58b8a1SDavid Howells */ 9600b58b8a1SDavid Howells int rxrpc_do_sendmsg(struct rxrpc_sock *, struct msghdr *, size_t); 9610b58b8a1SDavid Howells 9620b58b8a1SDavid Howells /* 9630d81a51aSDavid Howells * skbuff.c 9640d81a51aSDavid Howells */ 965d001648eSDavid Howells void rxrpc_kernel_data_consumed(struct rxrpc_call *, struct sk_buff *); 9660d81a51aSDavid Howells void rxrpc_packet_destructor(struct sk_buff *); 96771f3ca40SDavid Howells void rxrpc_new_skb(struct sk_buff *, enum rxrpc_skb_trace); 96871f3ca40SDavid Howells void rxrpc_see_skb(struct sk_buff *, enum rxrpc_skb_trace); 96971f3ca40SDavid Howells void rxrpc_get_skb(struct sk_buff *, enum rxrpc_skb_trace); 97071f3ca40SDavid Howells void rxrpc_free_skb(struct sk_buff *, enum rxrpc_skb_trace); 97171f3ca40SDavid Howells void rxrpc_lose_skb(struct sk_buff *, enum rxrpc_skb_trace); 972df844fd4SDavid Howells void rxrpc_purge_queue(struct sk_buff_head *); 9730d81a51aSDavid Howells 9740d81a51aSDavid Howells /* 9755873c083SDavid Howells * sysctl.c 9765873c083SDavid Howells */ 9775873c083SDavid Howells #ifdef CONFIG_SYSCTL 9785873c083SDavid Howells extern int __init rxrpc_sysctl_init(void); 9795873c083SDavid Howells extern void rxrpc_sysctl_exit(void); 9805873c083SDavid Howells #else 9815873c083SDavid Howells static inline int __init rxrpc_sysctl_init(void) { return 0; } 9825873c083SDavid Howells static inline void rxrpc_sysctl_exit(void) {} 9835873c083SDavid Howells #endif 9845873c083SDavid Howells 9855873c083SDavid Howells /* 986be6e6707SDavid Howells * utils.c 987be6e6707SDavid Howells */ 988d991b4a3SDavid Howells int rxrpc_extract_addr_from_skb(struct sockaddr_rxrpc *, struct sk_buff *); 989be6e6707SDavid Howells 990248f219cSDavid Howells static inline bool before(u32 seq1, u32 seq2) 991248f219cSDavid Howells { 992248f219cSDavid Howells return (s32)(seq1 - seq2) < 0; 993248f219cSDavid Howells } 994248f219cSDavid Howells static inline bool before_eq(u32 seq1, u32 seq2) 995248f219cSDavid Howells { 996248f219cSDavid Howells return (s32)(seq1 - seq2) <= 0; 997248f219cSDavid Howells } 998248f219cSDavid Howells static inline bool after(u32 seq1, u32 seq2) 999248f219cSDavid Howells { 1000248f219cSDavid Howells return (s32)(seq1 - seq2) > 0; 1001248f219cSDavid Howells } 1002248f219cSDavid Howells static inline bool after_eq(u32 seq1, u32 seq2) 1003248f219cSDavid Howells { 1004248f219cSDavid Howells return (s32)(seq1 - seq2) >= 0; 1005248f219cSDavid Howells } 1006248f219cSDavid Howells 1007be6e6707SDavid Howells /* 100817926a79SDavid Howells * debug tracing 100917926a79SDavid Howells */ 101095c96174SEric Dumazet extern unsigned int rxrpc_debug; 101117926a79SDavid Howells 101217926a79SDavid Howells #define dbgprintk(FMT,...) \ 10139f389f4bSSven Schnelle printk("[%-6.6s] "FMT"\n", current->comm ,##__VA_ARGS__) 101417926a79SDavid Howells 10150dc47877SHarvey Harrison #define kenter(FMT,...) dbgprintk("==> %s("FMT")",__func__ ,##__VA_ARGS__) 10160dc47877SHarvey Harrison #define kleave(FMT,...) dbgprintk("<== %s()"FMT"",__func__ ,##__VA_ARGS__) 101717926a79SDavid Howells #define kdebug(FMT,...) dbgprintk(" "FMT ,##__VA_ARGS__) 101817926a79SDavid Howells #define kproto(FMT,...) dbgprintk("### "FMT ,##__VA_ARGS__) 101917926a79SDavid Howells #define knet(FMT,...) dbgprintk("@@@ "FMT ,##__VA_ARGS__) 102017926a79SDavid Howells 102117926a79SDavid Howells 102217926a79SDavid Howells #if defined(__KDEBUG) 102317926a79SDavid Howells #define _enter(FMT,...) kenter(FMT,##__VA_ARGS__) 102417926a79SDavid Howells #define _leave(FMT,...) kleave(FMT,##__VA_ARGS__) 102517926a79SDavid Howells #define _debug(FMT,...) kdebug(FMT,##__VA_ARGS__) 102617926a79SDavid Howells #define _proto(FMT,...) kproto(FMT,##__VA_ARGS__) 102717926a79SDavid Howells #define _net(FMT,...) knet(FMT,##__VA_ARGS__) 102817926a79SDavid Howells 102917926a79SDavid Howells #elif defined(CONFIG_AF_RXRPC_DEBUG) 103017926a79SDavid Howells #define RXRPC_DEBUG_KENTER 0x01 103117926a79SDavid Howells #define RXRPC_DEBUG_KLEAVE 0x02 103217926a79SDavid Howells #define RXRPC_DEBUG_KDEBUG 0x04 103317926a79SDavid Howells #define RXRPC_DEBUG_KPROTO 0x08 103417926a79SDavid Howells #define RXRPC_DEBUG_KNET 0x10 103517926a79SDavid Howells 103617926a79SDavid Howells #define _enter(FMT,...) \ 103717926a79SDavid Howells do { \ 103817926a79SDavid Howells if (unlikely(rxrpc_debug & RXRPC_DEBUG_KENTER)) \ 103917926a79SDavid Howells kenter(FMT,##__VA_ARGS__); \ 104017926a79SDavid Howells } while (0) 104117926a79SDavid Howells 104217926a79SDavid Howells #define _leave(FMT,...) \ 104317926a79SDavid Howells do { \ 104417926a79SDavid Howells if (unlikely(rxrpc_debug & RXRPC_DEBUG_KLEAVE)) \ 104517926a79SDavid Howells kleave(FMT,##__VA_ARGS__); \ 104617926a79SDavid Howells } while (0) 104717926a79SDavid Howells 104817926a79SDavid Howells #define _debug(FMT,...) \ 104917926a79SDavid Howells do { \ 105017926a79SDavid Howells if (unlikely(rxrpc_debug & RXRPC_DEBUG_KDEBUG)) \ 105117926a79SDavid Howells kdebug(FMT,##__VA_ARGS__); \ 105217926a79SDavid Howells } while (0) 105317926a79SDavid Howells 105417926a79SDavid Howells #define _proto(FMT,...) \ 105517926a79SDavid Howells do { \ 105617926a79SDavid Howells if (unlikely(rxrpc_debug & RXRPC_DEBUG_KPROTO)) \ 105717926a79SDavid Howells kproto(FMT,##__VA_ARGS__); \ 105817926a79SDavid Howells } while (0) 105917926a79SDavid Howells 106017926a79SDavid Howells #define _net(FMT,...) \ 106117926a79SDavid Howells do { \ 106217926a79SDavid Howells if (unlikely(rxrpc_debug & RXRPC_DEBUG_KNET)) \ 106317926a79SDavid Howells knet(FMT,##__VA_ARGS__); \ 106417926a79SDavid Howells } while (0) 106517926a79SDavid Howells 106617926a79SDavid Howells #else 106712fdff3fSDavid Howells #define _enter(FMT,...) no_printk("==> %s("FMT")",__func__ ,##__VA_ARGS__) 106812fdff3fSDavid Howells #define _leave(FMT,...) no_printk("<== %s()"FMT"",__func__ ,##__VA_ARGS__) 106912fdff3fSDavid Howells #define _debug(FMT,...) no_printk(" "FMT ,##__VA_ARGS__) 107012fdff3fSDavid Howells #define _proto(FMT,...) no_printk("### "FMT ,##__VA_ARGS__) 107112fdff3fSDavid Howells #define _net(FMT,...) no_printk("@@@ "FMT ,##__VA_ARGS__) 107217926a79SDavid Howells #endif 107317926a79SDavid Howells 107417926a79SDavid Howells /* 107517926a79SDavid Howells * debug assertion checking 107617926a79SDavid Howells */ 107717926a79SDavid Howells #if 1 // defined(__KDEBUGALL) 107817926a79SDavid Howells 107917926a79SDavid Howells #define ASSERT(X) \ 108017926a79SDavid Howells do { \ 108117926a79SDavid Howells if (unlikely(!(X))) { \ 10829b6d5398SJoe Perches pr_err("Assertion failed\n"); \ 108317926a79SDavid Howells BUG(); \ 108417926a79SDavid Howells } \ 108517926a79SDavid Howells } while (0) 108617926a79SDavid Howells 108717926a79SDavid Howells #define ASSERTCMP(X, OP, Y) \ 108817926a79SDavid Howells do { \ 1089cf13258fSDavid Howells __typeof__(X) _x = (X); \ 1090cf13258fSDavid Howells __typeof__(Y) _y = (__typeof__(X))(Y); \ 10919b6d5398SJoe Perches if (unlikely(!(_x OP _y))) { \ 10929b6d5398SJoe Perches pr_err("Assertion failed - %lu(0x%lx) %s %lu(0x%lx) is false\n", \ 1093cf13258fSDavid Howells (unsigned long)_x, (unsigned long)_x, #OP, \ 1094cf13258fSDavid Howells (unsigned long)_y, (unsigned long)_y); \ 109517926a79SDavid Howells BUG(); \ 109617926a79SDavid Howells } \ 109717926a79SDavid Howells } while (0) 109817926a79SDavid Howells 109917926a79SDavid Howells #define ASSERTIF(C, X) \ 110017926a79SDavid Howells do { \ 110117926a79SDavid Howells if (unlikely((C) && !(X))) { \ 11029b6d5398SJoe Perches pr_err("Assertion failed\n"); \ 110317926a79SDavid Howells BUG(); \ 110417926a79SDavid Howells } \ 110517926a79SDavid Howells } while (0) 110617926a79SDavid Howells 110717926a79SDavid Howells #define ASSERTIFCMP(C, X, OP, Y) \ 110817926a79SDavid Howells do { \ 1109cf13258fSDavid Howells __typeof__(X) _x = (X); \ 1110cf13258fSDavid Howells __typeof__(Y) _y = (__typeof__(X))(Y); \ 11119b6d5398SJoe Perches if (unlikely((C) && !(_x OP _y))) { \ 11129b6d5398SJoe Perches pr_err("Assertion failed - %lu(0x%lx) %s %lu(0x%lx) is false\n", \ 1113cf13258fSDavid Howells (unsigned long)_x, (unsigned long)_x, #OP, \ 1114cf13258fSDavid Howells (unsigned long)_y, (unsigned long)_y); \ 111517926a79SDavid Howells BUG(); \ 111617926a79SDavid Howells } \ 111717926a79SDavid Howells } while (0) 111817926a79SDavid Howells 111917926a79SDavid Howells #else 112017926a79SDavid Howells 112117926a79SDavid Howells #define ASSERT(X) \ 112217926a79SDavid Howells do { \ 112317926a79SDavid Howells } while (0) 112417926a79SDavid Howells 112517926a79SDavid Howells #define ASSERTCMP(X, OP, Y) \ 112617926a79SDavid Howells do { \ 112717926a79SDavid Howells } while (0) 112817926a79SDavid Howells 112917926a79SDavid Howells #define ASSERTIF(C, X) \ 113017926a79SDavid Howells do { \ 113117926a79SDavid Howells } while (0) 113217926a79SDavid Howells 113317926a79SDavid Howells #define ASSERTIFCMP(C, X, OP, Y) \ 113417926a79SDavid Howells do { \ 113517926a79SDavid Howells } while (0) 113617926a79SDavid Howells 113717926a79SDavid Howells #endif /* __KDEBUGALL */ 1138