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 38651350d1SDavid Howells #define rxrpc_queue_call(CALL) rxrpc_queue_work(&(CALL)->processor) 3917926a79SDavid 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 */ 6417926a79SDavid Howells RXRPC_SERVER_LISTENING, /* server listening for connections */ 6517926a79SDavid Howells RXRPC_CLOSE, /* socket is being closed */ 6617926a79SDavid Howells }; 6717926a79SDavid Howells 6817926a79SDavid Howells /* 6917926a79SDavid Howells * RxRPC socket definition 7017926a79SDavid Howells */ 7117926a79SDavid Howells struct rxrpc_sock { 7217926a79SDavid Howells /* WARNING: sk has to be the first member */ 7317926a79SDavid Howells struct sock sk; 74d001648eSDavid Howells rxrpc_notify_new_call_t notify_new_call; /* Func to notify of new call */ 7517926a79SDavid Howells struct rxrpc_local *local; /* local endpoint */ 7617926a79SDavid Howells struct list_head listen_link; /* link in the local endpoint's listen list */ 7717926a79SDavid Howells struct list_head secureq; /* calls awaiting connection security clearance */ 7817926a79SDavid Howells struct list_head acceptq; /* calls awaiting acceptance */ 7917926a79SDavid Howells struct key *key; /* security for this socket */ 8017926a79SDavid Howells struct key *securities; /* list of server security descriptors */ 8117926a79SDavid Howells struct rb_root calls; /* outstanding calls on this socket */ 8217926a79SDavid Howells unsigned long flags; 832341e077SDavid Howells #define RXRPC_SOCK_CONNECTED 0 /* connect_srx is set */ 8417926a79SDavid Howells rwlock_t call_lock; /* lock for calls */ 8517926a79SDavid Howells u32 min_sec_level; /* minimum security level */ 8617926a79SDavid Howells #define RXRPC_SECURITY_MAX RXRPC_SECURITY_ENCRYPT 87cc8feb8eSDavid Howells bool exclusive; /* Exclusive connection for a client socket */ 88cc8feb8eSDavid Howells sa_family_t family; /* Protocol family created with */ 8917926a79SDavid Howells struct sockaddr_rxrpc srx; /* local address */ 902341e077SDavid Howells struct sockaddr_rxrpc connect_srx; /* Default client address from connect() */ 9117926a79SDavid Howells }; 9217926a79SDavid Howells 9317926a79SDavid Howells #define rxrpc_sk(__sk) container_of((__sk), struct rxrpc_sock, sk) 9417926a79SDavid Howells 9517926a79SDavid Howells /* 960d12f8a4SDavid Howells * CPU-byteorder normalised Rx packet header. 970d12f8a4SDavid Howells */ 980d12f8a4SDavid Howells struct rxrpc_host_header { 990d12f8a4SDavid Howells u32 epoch; /* client boot timestamp */ 1000d12f8a4SDavid Howells u32 cid; /* connection and channel ID */ 1010d12f8a4SDavid Howells u32 callNumber; /* call ID (0 for connection-level packets) */ 1020d12f8a4SDavid Howells u32 seq; /* sequence number of pkt in call stream */ 1030d12f8a4SDavid Howells u32 serial; /* serial number of pkt sent to network */ 1040d12f8a4SDavid Howells u8 type; /* packet type */ 1050d12f8a4SDavid Howells u8 flags; /* packet flags */ 1060d12f8a4SDavid Howells u8 userStatus; /* app-layer defined status */ 1070d12f8a4SDavid Howells u8 securityIndex; /* security protocol ID */ 1080d12f8a4SDavid Howells union { 1090d12f8a4SDavid Howells u16 _rsvd; /* reserved */ 1100d12f8a4SDavid Howells u16 cksum; /* kerberos security checksum */ 1110d12f8a4SDavid Howells }; 1120d12f8a4SDavid Howells u16 serviceId; /* service ID */ 1130d12f8a4SDavid Howells } __packed; 1140d12f8a4SDavid Howells 1150d12f8a4SDavid Howells /* 11617926a79SDavid Howells * RxRPC socket buffer private variables 11717926a79SDavid Howells * - max 48 bytes (struct sk_buff::cb) 11817926a79SDavid Howells */ 11917926a79SDavid Howells struct rxrpc_skb_priv { 12017926a79SDavid Howells struct rxrpc_call *call; /* call with which associated */ 12117926a79SDavid Howells unsigned long resend_at; /* time in jiffies at which to resend */ 12217926a79SDavid Howells union { 12395c96174SEric Dumazet unsigned int offset; /* offset into buffer of next read */ 12417926a79SDavid Howells int remain; /* amount of space remaining for next write */ 12517926a79SDavid Howells u32 error; /* network error code */ 12617926a79SDavid Howells bool need_resend; /* T if needs resending */ 12717926a79SDavid Howells }; 12817926a79SDavid Howells 1290d12f8a4SDavid Howells struct rxrpc_host_header hdr; /* RxRPC packet header from this packet */ 13017926a79SDavid Howells }; 13117926a79SDavid Howells 13217926a79SDavid Howells #define rxrpc_skb(__skb) ((struct rxrpc_skb_priv *) &(__skb)->cb) 13317926a79SDavid Howells 13417926a79SDavid Howells /* 13517926a79SDavid Howells * RxRPC security module interface 13617926a79SDavid Howells */ 13717926a79SDavid Howells struct rxrpc_security { 13817926a79SDavid Howells const char *name; /* name of this service */ 13917926a79SDavid Howells u8 security_index; /* security type provided */ 14017926a79SDavid Howells 141648af7fcSDavid Howells /* Initialise a security service */ 142648af7fcSDavid Howells int (*init)(void); 143648af7fcSDavid Howells 144648af7fcSDavid Howells /* Clean up a security service */ 145648af7fcSDavid Howells void (*exit)(void); 146648af7fcSDavid Howells 14717926a79SDavid Howells /* initialise a connection's security */ 14817926a79SDavid Howells int (*init_connection_security)(struct rxrpc_connection *); 14917926a79SDavid Howells 15017926a79SDavid Howells /* prime a connection's packet security */ 151a263629dSHerbert Xu int (*prime_packet_security)(struct rxrpc_connection *); 15217926a79SDavid Howells 15317926a79SDavid Howells /* impose security on a packet */ 154a263629dSHerbert Xu int (*secure_packet)(struct rxrpc_call *, 15517926a79SDavid Howells struct sk_buff *, 15617926a79SDavid Howells size_t, 15717926a79SDavid Howells void *); 15817926a79SDavid Howells 15917926a79SDavid Howells /* verify the security on a received packet */ 160a263629dSHerbert Xu int (*verify_packet)(struct rxrpc_call *, struct sk_buff *, u32 *); 16117926a79SDavid Howells 16217926a79SDavid Howells /* issue a challenge */ 16317926a79SDavid Howells int (*issue_challenge)(struct rxrpc_connection *); 16417926a79SDavid Howells 16517926a79SDavid Howells /* respond to a challenge */ 16617926a79SDavid Howells int (*respond_to_challenge)(struct rxrpc_connection *, 16717926a79SDavid Howells struct sk_buff *, 16817926a79SDavid Howells u32 *); 16917926a79SDavid Howells 17017926a79SDavid Howells /* verify a response */ 17117926a79SDavid Howells int (*verify_response)(struct rxrpc_connection *, 17217926a79SDavid Howells struct sk_buff *, 17317926a79SDavid Howells u32 *); 17417926a79SDavid Howells 17517926a79SDavid Howells /* clear connection security */ 17617926a79SDavid Howells void (*clear)(struct rxrpc_connection *); 17717926a79SDavid Howells }; 17817926a79SDavid Howells 17917926a79SDavid Howells /* 1804f95dd78SDavid Howells * RxRPC local transport endpoint description 1814f95dd78SDavid Howells * - owned by a single AF_RXRPC socket 1824f95dd78SDavid Howells * - pointed to by transport socket struct sk_user_data 18317926a79SDavid Howells */ 18417926a79SDavid Howells struct rxrpc_local { 1854f95dd78SDavid Howells struct rcu_head rcu; 1864f95dd78SDavid Howells atomic_t usage; 1874f95dd78SDavid Howells struct list_head link; 18817926a79SDavid Howells struct socket *socket; /* my UDP socket */ 1894f95dd78SDavid Howells struct work_struct processor; 19017926a79SDavid Howells struct list_head services; /* services listening on this endpoint */ 19117926a79SDavid Howells struct rw_semaphore defrag_sem; /* control re-enablement of IP DF bit */ 19217926a79SDavid Howells struct sk_buff_head accept_queue; /* incoming calls awaiting acceptance */ 19317926a79SDavid Howells struct sk_buff_head reject_queue; /* packets awaiting rejection */ 19444ba0698SDavid Howells struct sk_buff_head event_queue; /* endpoint event packets awaiting processing */ 195999b69f8SDavid Howells struct rb_root client_conns; /* Client connections by socket params */ 196999b69f8SDavid Howells spinlock_t client_conns_lock; /* Lock for client_conns */ 19717926a79SDavid Howells spinlock_t lock; /* access lock */ 19817926a79SDavid Howells rwlock_t services_lock; /* lock for services list */ 19917926a79SDavid Howells int debug_id; /* debug ID for printks */ 2004f95dd78SDavid Howells bool dead; 20117926a79SDavid Howells struct sockaddr_rxrpc srx; /* local address */ 20217926a79SDavid Howells }; 20317926a79SDavid Howells 20417926a79SDavid Howells /* 20517926a79SDavid Howells * RxRPC remote transport endpoint definition 206be6e6707SDavid Howells * - matched by local endpoint, remote port, address and protocol type 20717926a79SDavid Howells */ 20817926a79SDavid Howells struct rxrpc_peer { 209be6e6707SDavid Howells struct rcu_head rcu; /* This must be first */ 210be6e6707SDavid Howells atomic_t usage; 211be6e6707SDavid Howells unsigned long hash_key; 212be6e6707SDavid Howells struct hlist_node hash_link; 213be6e6707SDavid Howells struct rxrpc_local *local; 214f66d7490SDavid Howells struct hlist_head error_targets; /* targets for net error distribution */ 215f66d7490SDavid Howells struct work_struct error_distributor; 216aa390bbeSDavid Howells struct rb_root service_conns; /* Service connections */ 2178496af50SDavid Howells seqlock_t service_conn_lock; 21817926a79SDavid Howells spinlock_t lock; /* access lock */ 21995c96174SEric Dumazet unsigned int if_mtu; /* interface MTU for this peer */ 22095c96174SEric Dumazet unsigned int mtu; /* network MTU for this peer */ 22195c96174SEric Dumazet unsigned int maxdata; /* data size (MTU - hdrsize) */ 22217926a79SDavid Howells unsigned short hdrsize; /* header size (IP + UDP + RxRPC) */ 22317926a79SDavid Howells int debug_id; /* debug ID for printks */ 224f66d7490SDavid Howells int error_report; /* Net (+0) or local (+1000000) to distribute */ 225f66d7490SDavid Howells #define RXRPC_LOCAL_ERROR_OFFSET 1000000 22617926a79SDavid Howells struct sockaddr_rxrpc srx; /* remote address */ 22717926a79SDavid Howells 22817926a79SDavid Howells /* calculated RTT cache */ 22917926a79SDavid Howells #define RXRPC_RTT_CACHE_SIZE 32 23017926a79SDavid Howells suseconds_t rtt; /* current RTT estimate (in uS) */ 23195c96174SEric Dumazet unsigned int rtt_point; /* next entry at which to insert */ 23295c96174SEric Dumazet unsigned int rtt_usage; /* amount of cache actually used */ 23317926a79SDavid Howells suseconds_t rtt_cache[RXRPC_RTT_CACHE_SIZE]; /* calculated RTT cache */ 23417926a79SDavid Howells }; 23517926a79SDavid Howells 23617926a79SDavid Howells /* 23719ffa01cSDavid Howells * Keys for matching a connection. 23819ffa01cSDavid Howells */ 23919ffa01cSDavid Howells struct rxrpc_conn_proto { 240e8d70ce1SDavid Howells union { 241e8d70ce1SDavid Howells struct { 24219ffa01cSDavid Howells u32 epoch; /* epoch of this connection */ 24319ffa01cSDavid Howells u32 cid; /* connection ID */ 244e8d70ce1SDavid Howells }; 245e8d70ce1SDavid Howells u64 index_key; 24619ffa01cSDavid Howells }; 24719ffa01cSDavid Howells }; 24819ffa01cSDavid Howells 24919ffa01cSDavid Howells struct rxrpc_conn_parameters { 25019ffa01cSDavid Howells struct rxrpc_local *local; /* Representation of local endpoint */ 25119ffa01cSDavid Howells struct rxrpc_peer *peer; /* Remote endpoint */ 25219ffa01cSDavid Howells struct key *key; /* Security details */ 25319ffa01cSDavid Howells bool exclusive; /* T if conn is exclusive */ 25419ffa01cSDavid Howells u16 service_id; /* Service ID for this connection */ 25519ffa01cSDavid Howells u32 security_level; /* Security level selected */ 25619ffa01cSDavid Howells }; 25719ffa01cSDavid Howells 25819ffa01cSDavid Howells /* 259bba304dbSDavid Howells * Bits in the connection flags. 260bba304dbSDavid Howells */ 261bba304dbSDavid Howells enum rxrpc_conn_flag { 262bba304dbSDavid Howells RXRPC_CONN_HAS_IDR, /* Has a client conn ID assigned */ 263001c1122SDavid Howells RXRPC_CONN_IN_SERVICE_CONNS, /* Conn is in peer->service_conns */ 264001c1122SDavid Howells RXRPC_CONN_IN_CLIENT_CONNS, /* Conn is in local->client_conns */ 26545025bceSDavid Howells RXRPC_CONN_EXPOSED, /* Conn has extra ref for exposure */ 26645025bceSDavid Howells RXRPC_CONN_DONT_REUSE, /* Don't reuse this connection */ 26745025bceSDavid Howells RXRPC_CONN_COUNTED, /* Counted by rxrpc_nr_client_conns */ 268bba304dbSDavid Howells }; 269bba304dbSDavid Howells 270bba304dbSDavid Howells /* 271bba304dbSDavid Howells * Events that can be raised upon a connection. 272bba304dbSDavid Howells */ 273bba304dbSDavid Howells enum rxrpc_conn_event { 274bba304dbSDavid Howells RXRPC_CONN_EV_CHALLENGE, /* Send challenge packet */ 275bba304dbSDavid Howells }; 276bba304dbSDavid Howells 277bba304dbSDavid Howells /* 27845025bceSDavid Howells * The connection cache state. 27945025bceSDavid Howells */ 28045025bceSDavid Howells enum rxrpc_conn_cache_state { 28145025bceSDavid Howells RXRPC_CONN_CLIENT_INACTIVE, /* Conn is not yet listed */ 28245025bceSDavid Howells RXRPC_CONN_CLIENT_WAITING, /* Conn is on wait list, waiting for capacity */ 28345025bceSDavid Howells RXRPC_CONN_CLIENT_ACTIVE, /* Conn is on active list, doing calls */ 28445025bceSDavid Howells RXRPC_CONN_CLIENT_CULLED, /* Conn is culled and delisted, doing calls */ 28545025bceSDavid Howells RXRPC_CONN_CLIENT_IDLE, /* Conn is on idle list, doing mostly nothing */ 28645025bceSDavid Howells }; 28745025bceSDavid Howells 28845025bceSDavid Howells /* 289bba304dbSDavid Howells * The connection protocol state. 290bba304dbSDavid Howells */ 291bba304dbSDavid Howells enum rxrpc_conn_proto_state { 292bba304dbSDavid Howells RXRPC_CONN_UNUSED, /* Connection not yet attempted */ 293bba304dbSDavid Howells RXRPC_CONN_CLIENT, /* Client connection */ 294bba304dbSDavid Howells RXRPC_CONN_SERVICE_UNSECURED, /* Service unsecured connection */ 295bba304dbSDavid Howells RXRPC_CONN_SERVICE_CHALLENGING, /* Service challenging for security */ 296bba304dbSDavid Howells RXRPC_CONN_SERVICE, /* Service secured connection */ 297bba304dbSDavid Howells RXRPC_CONN_REMOTELY_ABORTED, /* Conn aborted by peer */ 298bba304dbSDavid Howells RXRPC_CONN_LOCALLY_ABORTED, /* Conn aborted locally */ 299bba304dbSDavid Howells RXRPC_CONN__NR_STATES 300bba304dbSDavid Howells }; 301bba304dbSDavid Howells 302bba304dbSDavid Howells /* 30317926a79SDavid Howells * RxRPC connection definition 304aa390bbeSDavid Howells * - matched by { local, peer, epoch, conn_id, direction } 30517926a79SDavid Howells * - each connection can only handle four simultaneous calls 30617926a79SDavid Howells */ 30717926a79SDavid Howells struct rxrpc_connection { 30819ffa01cSDavid Howells struct rxrpc_conn_proto proto; 30919ffa01cSDavid Howells struct rxrpc_conn_parameters params; 31019ffa01cSDavid Howells 31145025bceSDavid Howells atomic_t usage; 31245025bceSDavid Howells struct rcu_head rcu; 31345025bceSDavid Howells struct list_head cache_link; 314a1399f8bSDavid Howells 31545025bceSDavid Howells spinlock_t channel_lock; 31645025bceSDavid Howells unsigned char active_chans; /* Mask of active channels */ 31745025bceSDavid Howells #define RXRPC_ACTIVE_CHANS_MASK ((1 << RXRPC_MAXCALLS) - 1) 31845025bceSDavid Howells struct list_head waiting_calls; /* Calls waiting for channels */ 319a1399f8bSDavid Howells struct rxrpc_channel { 320a1399f8bSDavid Howells struct rxrpc_call __rcu *call; /* Active call */ 321a1399f8bSDavid Howells u32 call_id; /* ID of current call */ 322a1399f8bSDavid Howells u32 call_counter; /* Call ID counter */ 323a1399f8bSDavid Howells u32 last_call; /* ID of last call */ 32418bfeba5SDavid Howells u8 last_type; /* Type of last packet */ 32518bfeba5SDavid Howells u16 last_service_id; 32618bfeba5SDavid Howells union { 32718bfeba5SDavid Howells u32 last_seq; 32818bfeba5SDavid Howells u32 last_abort; 32918bfeba5SDavid Howells }; 330a1399f8bSDavid Howells } channels[RXRPC_MAXCALLS]; 331999b69f8SDavid Howells 33217926a79SDavid Howells struct work_struct processor; /* connection event processor */ 333999b69f8SDavid Howells union { 334999b69f8SDavid Howells struct rb_node client_node; /* Node in local->client_conns */ 335aa390bbeSDavid Howells struct rb_node service_node; /* Node in peer->service_conns */ 336999b69f8SDavid Howells }; 3374d028b2cSDavid Howells struct list_head proc_link; /* link in procfs list */ 33817926a79SDavid Howells struct list_head link; /* link in master connection list */ 33917926a79SDavid Howells struct sk_buff_head rx_queue; /* received conn-level packets */ 340648af7fcSDavid Howells const struct rxrpc_security *security; /* applied security module */ 34117926a79SDavid Howells struct key *server_key; /* security for this service */ 3421afe593bSHerbert Xu struct crypto_skcipher *cipher; /* encryption handle */ 34317926a79SDavid Howells struct rxrpc_crypt csum_iv; /* packet checksum base */ 3444a3388c8SDavid Howells unsigned long flags; 34517926a79SDavid Howells unsigned long events; 346f51b4480SDavid Howells unsigned long idle_timestamp; /* Time at which last became idle */ 34717926a79SDavid Howells spinlock_t state_lock; /* state-change lock */ 34845025bceSDavid Howells enum rxrpc_conn_cache_state cache_state : 8; 349bba304dbSDavid Howells enum rxrpc_conn_proto_state state : 8; /* current state of connection */ 350dc44b3a0SDavid Howells u32 local_abort; /* local abort code */ 351dc44b3a0SDavid Howells u32 remote_abort; /* remote abort code */ 35217926a79SDavid Howells int debug_id; /* debug ID for printks */ 35317926a79SDavid Howells atomic_t serial; /* packet serial number counter */ 354563ea7d5SDavid Howells unsigned int hi_serial; /* highest serial number received */ 35517926a79SDavid Howells u8 size_align; /* data size alignment (for security) */ 35617926a79SDavid Howells u8 header_size; /* rxrpc + security header size */ 35717926a79SDavid Howells u8 security_size; /* security header size */ 35817926a79SDavid Howells u32 security_nonce; /* response re-use preventer */ 35917926a79SDavid Howells u8 security_ix; /* security type */ 36017926a79SDavid Howells u8 out_clientflag; /* RXRPC_CLIENT_INITIATED if we are client */ 36117926a79SDavid Howells }; 36217926a79SDavid Howells 36317926a79SDavid Howells /* 3645b8848d1SDavid Howells * Flags in call->flags. 3655b8848d1SDavid Howells */ 3665b8848d1SDavid Howells enum rxrpc_call_flag { 3675b8848d1SDavid Howells RXRPC_CALL_RELEASED, /* call has been released - no more message to userspace */ 3685b8848d1SDavid Howells RXRPC_CALL_TERMINAL_MSG, /* call has given the socket its final message */ 3695b8848d1SDavid Howells RXRPC_CALL_RCVD_LAST, /* all packets received */ 3705b8848d1SDavid Howells RXRPC_CALL_RUN_RTIMER, /* Tx resend timer started */ 3715b8848d1SDavid Howells RXRPC_CALL_TX_SOFT_ACK, /* sent some soft ACKs */ 3725b8848d1SDavid Howells RXRPC_CALL_INIT_ACCEPT, /* acceptance was initiated */ 3735b8848d1SDavid Howells RXRPC_CALL_HAS_USERID, /* has a user ID attached */ 3745b8848d1SDavid Howells RXRPC_CALL_EXPECT_OOS, /* expect out of sequence packets */ 375dabe5a79SDavid Howells RXRPC_CALL_IS_SERVICE, /* Call is service call */ 37645025bceSDavid Howells RXRPC_CALL_EXPOSED, /* The call was exposed to the world */ 377d001648eSDavid Howells RXRPC_CALL_RX_NO_MORE, /* Don't indicate MSG_MORE from recvmsg() */ 3785b8848d1SDavid Howells }; 3795b8848d1SDavid Howells 3805b8848d1SDavid Howells /* 3815b8848d1SDavid Howells * Events that can be raised on a call. 3825b8848d1SDavid Howells */ 3835b8848d1SDavid Howells enum rxrpc_call_event { 3844c198ad1SDavid Howells RXRPC_CALL_EV_RCVD_ACKALL, /* ACKALL or reply received */ 3854c198ad1SDavid Howells RXRPC_CALL_EV_RCVD_BUSY, /* busy packet received */ 3864c198ad1SDavid Howells RXRPC_CALL_EV_RCVD_ABORT, /* abort packet received */ 3874c198ad1SDavid Howells RXRPC_CALL_EV_RCVD_ERROR, /* network error received */ 3884c198ad1SDavid Howells RXRPC_CALL_EV_ACK_FINAL, /* need to generate final ACK (and release call) */ 3894c198ad1SDavid Howells RXRPC_CALL_EV_ACK, /* need to generate ACK */ 3904c198ad1SDavid Howells RXRPC_CALL_EV_REJECT_BUSY, /* need to generate busy message */ 3914c198ad1SDavid Howells RXRPC_CALL_EV_ABORT, /* need to generate abort */ 3924c198ad1SDavid Howells RXRPC_CALL_EV_CONN_ABORT, /* local connection abort generated */ 3934c198ad1SDavid Howells RXRPC_CALL_EV_RESEND_TIMER, /* Tx resend timer expired */ 3944c198ad1SDavid Howells RXRPC_CALL_EV_RESEND, /* Tx resend required */ 3954c198ad1SDavid Howells RXRPC_CALL_EV_DRAIN_RX_OOS, /* drain the Rx out of sequence queue */ 3964c198ad1SDavid Howells RXRPC_CALL_EV_LIFE_TIMER, /* call's lifetimer ran out */ 3974c198ad1SDavid Howells RXRPC_CALL_EV_ACCEPTED, /* incoming call accepted by userspace app */ 3984c198ad1SDavid Howells RXRPC_CALL_EV_SECURED, /* incoming call's connection is now secure */ 3994c198ad1SDavid Howells RXRPC_CALL_EV_POST_ACCEPT, /* need to post an "accept?" message to the app */ 4004c198ad1SDavid Howells RXRPC_CALL_EV_RELEASE, /* need to release the call's resources */ 4015b8848d1SDavid Howells }; 4025b8848d1SDavid Howells 4035b8848d1SDavid Howells /* 4045b8848d1SDavid Howells * The states that a call can be in. 4055b8848d1SDavid Howells */ 4065b8848d1SDavid Howells enum rxrpc_call_state { 407999b69f8SDavid Howells RXRPC_CALL_UNINITIALISED, 408999b69f8SDavid Howells RXRPC_CALL_CLIENT_AWAIT_CONN, /* - client waiting for connection to become available */ 4095b8848d1SDavid Howells RXRPC_CALL_CLIENT_SEND_REQUEST, /* - client sending request phase */ 4105b8848d1SDavid Howells RXRPC_CALL_CLIENT_AWAIT_REPLY, /* - client awaiting reply */ 4115b8848d1SDavid Howells RXRPC_CALL_CLIENT_RECV_REPLY, /* - client receiving reply phase */ 4125b8848d1SDavid Howells RXRPC_CALL_CLIENT_FINAL_ACK, /* - client sending final ACK phase */ 4135b8848d1SDavid Howells RXRPC_CALL_SERVER_SECURING, /* - server securing request connection */ 4145b8848d1SDavid Howells RXRPC_CALL_SERVER_ACCEPTING, /* - server accepting request */ 4155b8848d1SDavid Howells RXRPC_CALL_SERVER_RECV_REQUEST, /* - server receiving request */ 4165b8848d1SDavid Howells RXRPC_CALL_SERVER_ACK_REQUEST, /* - server pending ACK of request */ 4175b8848d1SDavid Howells RXRPC_CALL_SERVER_SEND_REPLY, /* - server sending reply */ 4185b8848d1SDavid Howells RXRPC_CALL_SERVER_AWAIT_ACK, /* - server awaiting final ACK */ 419f5c17aaeSDavid Howells RXRPC_CALL_COMPLETE, /* - call complete */ 420f5c17aaeSDavid Howells RXRPC_CALL_DEAD, /* - call is dead */ 421f5c17aaeSDavid Howells NR__RXRPC_CALL_STATES 422f5c17aaeSDavid Howells }; 423f5c17aaeSDavid Howells 424f5c17aaeSDavid Howells /* 425f5c17aaeSDavid Howells * Call completion condition (state == RXRPC_CALL_COMPLETE). 426f5c17aaeSDavid Howells */ 427f5c17aaeSDavid Howells enum rxrpc_call_completion { 428f5c17aaeSDavid Howells RXRPC_CALL_SUCCEEDED, /* - Normal termination */ 4295b8848d1SDavid Howells RXRPC_CALL_SERVER_BUSY, /* - call rejected by busy server */ 4305b8848d1SDavid Howells RXRPC_CALL_REMOTELY_ABORTED, /* - call aborted by peer */ 4315b8848d1SDavid Howells RXRPC_CALL_LOCALLY_ABORTED, /* - call aborted locally on error or close */ 432f5c17aaeSDavid Howells RXRPC_CALL_LOCAL_ERROR, /* - call failed due to local error */ 4335b8848d1SDavid Howells RXRPC_CALL_NETWORK_ERROR, /* - call terminated by network error */ 434f5c17aaeSDavid Howells NR__RXRPC_CALL_COMPLETIONS 4355b8848d1SDavid Howells }; 4365b8848d1SDavid Howells 4375b8848d1SDavid Howells /* 43817926a79SDavid Howells * RxRPC call definition 43917926a79SDavid Howells * - matched by { connection, call_id } 44017926a79SDavid Howells */ 44117926a79SDavid Howells struct rxrpc_call { 442dee46364SDavid Howells struct rcu_head rcu; 44317926a79SDavid Howells struct rxrpc_connection *conn; /* connection carrying call */ 444df5d8bf7SDavid Howells struct rxrpc_peer *peer; /* Peer record for remote address */ 44517926a79SDavid Howells struct rxrpc_sock *socket; /* socket responsible */ 44617926a79SDavid Howells struct timer_list lifetimer; /* lifetime remaining on call */ 44717926a79SDavid Howells struct timer_list deadspan; /* reap timer for re-ACK'ing, etc */ 44817926a79SDavid Howells struct timer_list ack_timer; /* ACK generation timer */ 44917926a79SDavid Howells struct timer_list resend_timer; /* Tx resend timer */ 45017926a79SDavid Howells struct work_struct destroyer; /* call destroyer */ 45117926a79SDavid Howells struct work_struct processor; /* packet processor and ACK generator */ 452d001648eSDavid Howells rxrpc_notify_rx_t notify_rx; /* kernel service Rx notification function */ 45317926a79SDavid Howells struct list_head link; /* link in master call list */ 45445025bceSDavid Howells struct list_head chan_wait_link; /* Link in conn->waiting_calls */ 455f66d7490SDavid Howells struct hlist_node error_link; /* link in error distribution list */ 45617926a79SDavid Howells struct list_head accept_link; /* calls awaiting acceptance */ 45717926a79SDavid Howells struct rb_node sock_node; /* node in socket call tree */ 45817926a79SDavid Howells struct sk_buff_head rx_queue; /* received packets */ 45917926a79SDavid Howells struct sk_buff_head rx_oos_queue; /* packets received out of sequence */ 460d001648eSDavid Howells struct sk_buff_head knlrecv_queue; /* Queue for kernel_recv [TODO: replace this] */ 46117926a79SDavid Howells struct sk_buff *tx_pending; /* Tx socket buffer being filled */ 46245025bceSDavid Howells wait_queue_head_t waitq; /* Wait queue for channel or Tx */ 463a263629dSHerbert Xu __be32 crypto_buf[2]; /* Temporary packet crypto buffer */ 46417926a79SDavid Howells unsigned long user_call_ID; /* user-defined call ID */ 46517926a79SDavid Howells unsigned long creation_jif; /* time of call creation */ 46617926a79SDavid Howells unsigned long flags; 46717926a79SDavid Howells unsigned long events; 46817926a79SDavid Howells spinlock_t lock; 46917926a79SDavid Howells rwlock_t state_lock; /* lock for state transition */ 470f5c17aaeSDavid Howells u32 abort_code; /* Local/remote abort code */ 471f5c17aaeSDavid Howells int error; /* Local error incurred */ 472f5c17aaeSDavid Howells enum rxrpc_call_state state : 8; /* current state of call */ 473f5c17aaeSDavid Howells enum rxrpc_call_completion completion : 8; /* Call completion condition */ 47417926a79SDavid Howells atomic_t usage; 475372ee163SDavid Howells atomic_t skb_count; /* Outstanding packets on this call */ 47617926a79SDavid Howells atomic_t sequence; /* Tx data packet sequence counter */ 477dabe5a79SDavid Howells u16 service_id; /* service ID */ 478278ac0cdSDavid Howells u8 security_ix; /* Security type */ 479dabe5a79SDavid Howells u32 call_id; /* call ID on connection */ 480dabe5a79SDavid Howells u32 cid; /* connection ID plus channel index */ 481dabe5a79SDavid Howells int debug_id; /* debug ID for printks */ 48217926a79SDavid Howells 48317926a79SDavid Howells /* transmission-phase ACK management */ 4844e36a95eSDavid Howells u8 acks_head; /* offset into window of first entry */ 4854e36a95eSDavid Howells u8 acks_tail; /* offset into window of last entry */ 4864e36a95eSDavid Howells u8 acks_winsz; /* size of un-ACK'd window */ 4874e36a95eSDavid Howells u8 acks_unacked; /* lowest unacked packet in last ACK received */ 48817926a79SDavid Howells int acks_latest; /* serial number of latest ACK received */ 48917926a79SDavid Howells rxrpc_seq_t acks_hard; /* highest definitively ACK'd msg seq */ 49017926a79SDavid Howells unsigned long *acks_window; /* sent packet window 49117926a79SDavid Howells * - elements are pointers with LSB set if ACK'd 49217926a79SDavid Howells */ 49317926a79SDavid Howells 49417926a79SDavid Howells /* receive-phase ACK management */ 49517926a79SDavid Howells rxrpc_seq_t rx_data_expect; /* next data seq ID expected to be received */ 49617926a79SDavid Howells rxrpc_seq_t rx_data_post; /* next data seq ID expected to be posted */ 49717926a79SDavid Howells rxrpc_seq_t rx_data_recv; /* last data seq ID encountered by recvmsg */ 49817926a79SDavid Howells rxrpc_seq_t rx_data_eaten; /* last data seq ID consumed by recvmsg */ 49917926a79SDavid Howells rxrpc_seq_t rx_first_oos; /* first packet in rx_oos_queue (or 0) */ 50017926a79SDavid Howells rxrpc_seq_t ackr_win_top; /* top of ACK window (rx_data_eaten is bottom) */ 5010d12f8a4SDavid Howells rxrpc_seq_t ackr_prev_seq; /* previous sequence number received */ 5024e36a95eSDavid Howells u8 ackr_reason; /* reason to ACK */ 503563ea7d5SDavid Howells u16 ackr_skew; /* skew on packet being ACK'd */ 5040d12f8a4SDavid Howells rxrpc_serial_t ackr_serial; /* serial of packet being ACK'd */ 50517926a79SDavid Howells atomic_t ackr_not_idle; /* number of packets in Rx queue */ 50617926a79SDavid Howells 50717926a79SDavid Howells /* received packet records, 1 bit per record */ 50817926a79SDavid Howells #define RXRPC_ACKR_WINDOW_ASZ DIV_ROUND_UP(RXRPC_MAXACKS, BITS_PER_LONG) 50917926a79SDavid Howells unsigned long ackr_window[RXRPC_ACKR_WINDOW_ASZ + 1]; 51017926a79SDavid Howells }; 51117926a79SDavid Howells 512fff72429SDavid Howells enum rxrpc_call_trace { 513fff72429SDavid Howells rxrpc_call_new_client, 514fff72429SDavid Howells rxrpc_call_new_service, 515fff72429SDavid Howells rxrpc_call_queued, 516fff72429SDavid Howells rxrpc_call_queued_ref, 517fff72429SDavid Howells rxrpc_call_seen, 518fff72429SDavid Howells rxrpc_call_got, 519fff72429SDavid Howells rxrpc_call_got_skb, 520fff72429SDavid Howells rxrpc_call_got_userid, 521fff72429SDavid Howells rxrpc_call_put, 522fff72429SDavid Howells rxrpc_call_put_skb, 523fff72429SDavid Howells rxrpc_call_put_userid, 524fff72429SDavid Howells rxrpc_call_put_noqueue, 525fff72429SDavid Howells rxrpc_call__nr_trace 526fff72429SDavid Howells }; 527fff72429SDavid Howells 528fff72429SDavid Howells extern const char rxrpc_call_traces[rxrpc_call__nr_trace][4]; 529fff72429SDavid Howells 530df844fd4SDavid Howells #include <trace/events/rxrpc.h> 531df844fd4SDavid Howells 53217926a79SDavid Howells /* 533651350d1SDavid Howells * af_rxrpc.c 53417926a79SDavid Howells */ 535651350d1SDavid Howells extern atomic_t rxrpc_n_skbs; 5360d12f8a4SDavid Howells extern u32 rxrpc_epoch; 537651350d1SDavid Howells extern atomic_t rxrpc_debug_id; 538651350d1SDavid Howells extern struct workqueue_struct *rxrpc_workqueue; 53917926a79SDavid Howells 54017926a79SDavid Howells /* 5410d81a51aSDavid Howells * call_accept.c 54217926a79SDavid Howells */ 5434f95dd78SDavid Howells void rxrpc_accept_incoming_calls(struct rxrpc_local *); 544d001648eSDavid Howells struct rxrpc_call *rxrpc_accept_call(struct rxrpc_sock *, unsigned long, 545d001648eSDavid Howells rxrpc_notify_rx_t); 546c1b1203dSJoe Perches int rxrpc_reject_call(struct rxrpc_sock *); 54717926a79SDavid Howells 54817926a79SDavid Howells /* 5490d81a51aSDavid Howells * call_event.c 55017926a79SDavid Howells */ 551563ea7d5SDavid Howells void __rxrpc_propose_ACK(struct rxrpc_call *, u8, u16, u32, bool); 552563ea7d5SDavid Howells void rxrpc_propose_ACK(struct rxrpc_call *, u8, u16, u32, bool); 553c1b1203dSJoe Perches void rxrpc_process_call(struct work_struct *); 55417926a79SDavid Howells 55517926a79SDavid Howells /* 5560d81a51aSDavid Howells * call_object.c 55717926a79SDavid Howells */ 558f5c17aaeSDavid Howells extern const char *const rxrpc_call_states[]; 559f5c17aaeSDavid Howells extern const char *const rxrpc_call_completions[]; 560dad8aff7SDavid Howells extern unsigned int rxrpc_max_call_lifetime; 561dad8aff7SDavid Howells extern unsigned int rxrpc_dead_call_expiry; 56217926a79SDavid Howells extern struct kmem_cache *rxrpc_call_jar; 56317926a79SDavid Howells extern struct list_head rxrpc_calls; 56417926a79SDavid Howells extern rwlock_t rxrpc_call_lock; 56517926a79SDavid Howells 5662341e077SDavid Howells struct rxrpc_call *rxrpc_find_call_by_user_ID(struct rxrpc_sock *, unsigned long); 5672341e077SDavid Howells struct rxrpc_call *rxrpc_new_client_call(struct rxrpc_sock *, 56819ffa01cSDavid Howells struct rxrpc_conn_parameters *, 569999b69f8SDavid Howells struct sockaddr_rxrpc *, 5702341e077SDavid Howells unsigned long, gfp_t); 571c1b1203dSJoe Perches struct rxrpc_call *rxrpc_incoming_call(struct rxrpc_sock *, 57217926a79SDavid Howells struct rxrpc_connection *, 57342886ffeSDavid Howells struct sk_buff *); 574c1b1203dSJoe Perches void rxrpc_release_call(struct rxrpc_call *); 575c1b1203dSJoe Perches void rxrpc_release_calls_on_socket(struct rxrpc_sock *); 576e34d4234SDavid Howells void rxrpc_see_call(struct rxrpc_call *); 577fff72429SDavid Howells void rxrpc_get_call(struct rxrpc_call *, enum rxrpc_call_trace); 578fff72429SDavid Howells void rxrpc_put_call(struct rxrpc_call *, enum rxrpc_call_trace); 579e34d4234SDavid Howells void rxrpc_get_call_for_skb(struct rxrpc_call *, struct sk_buff *); 580e34d4234SDavid Howells void rxrpc_put_call_for_skb(struct rxrpc_call *, struct sk_buff *); 581c1b1203dSJoe Perches void __exit rxrpc_destroy_all_calls(void); 58217926a79SDavid Howells 583dabe5a79SDavid Howells static inline bool rxrpc_is_service_call(const struct rxrpc_call *call) 584dabe5a79SDavid Howells { 585dabe5a79SDavid Howells return test_bit(RXRPC_CALL_IS_SERVICE, &call->flags); 586dabe5a79SDavid Howells } 587dabe5a79SDavid Howells 588dabe5a79SDavid Howells static inline bool rxrpc_is_client_call(const struct rxrpc_call *call) 589dabe5a79SDavid Howells { 590dabe5a79SDavid Howells return !rxrpc_is_service_call(call); 591dabe5a79SDavid Howells } 592dabe5a79SDavid Howells 59317926a79SDavid Howells /* 594f5c17aaeSDavid Howells * Transition a call to the complete state. 595f5c17aaeSDavid Howells */ 596f5c17aaeSDavid Howells static inline bool __rxrpc_set_call_completion(struct rxrpc_call *call, 597f5c17aaeSDavid Howells enum rxrpc_call_completion compl, 598f5c17aaeSDavid Howells u32 abort_code, 599f5c17aaeSDavid Howells int error) 600f5c17aaeSDavid Howells { 601f5c17aaeSDavid Howells if (call->state < RXRPC_CALL_COMPLETE) { 602f5c17aaeSDavid Howells call->abort_code = abort_code; 603f5c17aaeSDavid Howells call->error = error; 604f5c17aaeSDavid Howells call->completion = compl, 605f5c17aaeSDavid Howells call->state = RXRPC_CALL_COMPLETE; 606f5c17aaeSDavid Howells return true; 607f5c17aaeSDavid Howells } 608f5c17aaeSDavid Howells return false; 609f5c17aaeSDavid Howells } 610f5c17aaeSDavid Howells 611f5c17aaeSDavid Howells static inline bool rxrpc_set_call_completion(struct rxrpc_call *call, 612f5c17aaeSDavid Howells enum rxrpc_call_completion compl, 613f5c17aaeSDavid Howells u32 abort_code, 614f5c17aaeSDavid Howells int error) 615f5c17aaeSDavid Howells { 616f5c17aaeSDavid Howells int ret; 617f5c17aaeSDavid Howells 618f5c17aaeSDavid Howells write_lock_bh(&call->state_lock); 619f5c17aaeSDavid Howells ret = __rxrpc_set_call_completion(call, compl, abort_code, error); 620f5c17aaeSDavid Howells write_unlock_bh(&call->state_lock); 621f5c17aaeSDavid Howells return ret; 622f5c17aaeSDavid Howells } 623f5c17aaeSDavid Howells 624f5c17aaeSDavid Howells /* 625f5c17aaeSDavid Howells * Record that a call successfully completed. 626f5c17aaeSDavid Howells */ 627f5c17aaeSDavid Howells static inline void __rxrpc_call_completed(struct rxrpc_call *call) 628f5c17aaeSDavid Howells { 629f5c17aaeSDavid Howells __rxrpc_set_call_completion(call, RXRPC_CALL_SUCCEEDED, 0, 0); 630f5c17aaeSDavid Howells } 631f5c17aaeSDavid Howells 632f5c17aaeSDavid Howells static inline void rxrpc_call_completed(struct rxrpc_call *call) 633f5c17aaeSDavid Howells { 634f5c17aaeSDavid Howells write_lock_bh(&call->state_lock); 635f5c17aaeSDavid Howells __rxrpc_call_completed(call); 636f5c17aaeSDavid Howells write_unlock_bh(&call->state_lock); 637f5c17aaeSDavid Howells } 638f5c17aaeSDavid Howells 639f5c17aaeSDavid Howells /* 640f5c17aaeSDavid Howells * Record that a call is locally aborted. 641f5c17aaeSDavid Howells */ 642f5c17aaeSDavid Howells static inline bool __rxrpc_abort_call(struct rxrpc_call *call, 643f5c17aaeSDavid Howells u32 abort_code, int error) 644f5c17aaeSDavid Howells { 645f5c17aaeSDavid Howells if (__rxrpc_set_call_completion(call, 646f5c17aaeSDavid Howells RXRPC_CALL_LOCALLY_ABORTED, 647f5c17aaeSDavid Howells abort_code, error)) { 648f5c17aaeSDavid Howells set_bit(RXRPC_CALL_EV_ABORT, &call->events); 649f5c17aaeSDavid Howells return true; 650f5c17aaeSDavid Howells } 651f5c17aaeSDavid Howells return false; 652f5c17aaeSDavid Howells } 653f5c17aaeSDavid Howells 654f5c17aaeSDavid Howells static inline bool rxrpc_abort_call(struct rxrpc_call *call, 655f5c17aaeSDavid Howells u32 abort_code, int error) 656f5c17aaeSDavid Howells { 657f5c17aaeSDavid Howells bool ret; 658f5c17aaeSDavid Howells 659f5c17aaeSDavid Howells write_lock_bh(&call->state_lock); 660f5c17aaeSDavid Howells ret = __rxrpc_abort_call(call, abort_code, error); 661f5c17aaeSDavid Howells write_unlock_bh(&call->state_lock); 662f5c17aaeSDavid Howells return ret; 663f5c17aaeSDavid Howells } 664f5c17aaeSDavid Howells 665f5c17aaeSDavid Howells /* 6664a3388c8SDavid Howells * conn_client.c 6674a3388c8SDavid Howells */ 66845025bceSDavid Howells extern unsigned int rxrpc_max_client_connections; 66945025bceSDavid Howells extern unsigned int rxrpc_reap_client_connections; 67045025bceSDavid Howells extern unsigned int rxrpc_conn_idle_client_expiry; 67145025bceSDavid Howells extern unsigned int rxrpc_conn_idle_client_fast_expiry; 6724a3388c8SDavid Howells extern struct idr rxrpc_client_conn_ids; 6734a3388c8SDavid Howells 674eb9b9d22SDavid Howells void rxrpc_destroy_client_conn_ids(void); 675c6d2b8d7SDavid Howells int rxrpc_connect_call(struct rxrpc_call *, struct rxrpc_conn_parameters *, 676c6d2b8d7SDavid Howells struct sockaddr_rxrpc *, gfp_t); 67745025bceSDavid Howells void rxrpc_expose_client_call(struct rxrpc_call *); 67845025bceSDavid Howells void rxrpc_disconnect_client_call(struct rxrpc_call *); 67945025bceSDavid Howells void rxrpc_put_client_conn(struct rxrpc_connection *); 68045025bceSDavid Howells void __exit rxrpc_destroy_all_client_connections(void); 6814a3388c8SDavid Howells 6824a3388c8SDavid Howells /* 6830d81a51aSDavid Howells * conn_event.c 6840d81a51aSDavid Howells */ 6850d81a51aSDavid Howells void rxrpc_process_connection(struct work_struct *); 6860d81a51aSDavid Howells void rxrpc_reject_packet(struct rxrpc_local *, struct sk_buff *); 6874f95dd78SDavid Howells void rxrpc_reject_packets(struct rxrpc_local *); 6880d81a51aSDavid Howells 6890d81a51aSDavid Howells /* 6900d81a51aSDavid Howells * conn_object.c 69117926a79SDavid Howells */ 692dad8aff7SDavid Howells extern unsigned int rxrpc_connection_expiry; 69317926a79SDavid Howells extern struct list_head rxrpc_connections; 6944d028b2cSDavid Howells extern struct list_head rxrpc_connection_proc_list; 69517926a79SDavid Howells extern rwlock_t rxrpc_connection_lock; 69617926a79SDavid Howells 6978496af50SDavid Howells int rxrpc_extract_addr_from_skb(struct sockaddr_rxrpc *, struct sk_buff *); 698c6d2b8d7SDavid Howells struct rxrpc_connection *rxrpc_alloc_connection(gfp_t); 6998496af50SDavid Howells struct rxrpc_connection *rxrpc_find_connection_rcu(struct rxrpc_local *, 700aa390bbeSDavid Howells struct sk_buff *); 70145025bceSDavid Howells void __rxrpc_disconnect_call(struct rxrpc_connection *, struct rxrpc_call *); 702999b69f8SDavid Howells void rxrpc_disconnect_call(struct rxrpc_call *); 70345025bceSDavid Howells void rxrpc_kill_connection(struct rxrpc_connection *); 704f51b4480SDavid Howells void __rxrpc_put_connection(struct rxrpc_connection *); 705c1b1203dSJoe Perches void __exit rxrpc_destroy_all_connections(void); 70617926a79SDavid Howells 70719ffa01cSDavid Howells static inline bool rxrpc_conn_is_client(const struct rxrpc_connection *conn) 70819ffa01cSDavid Howells { 70919ffa01cSDavid Howells return conn->out_clientflag; 71019ffa01cSDavid Howells } 71119ffa01cSDavid Howells 71219ffa01cSDavid Howells static inline bool rxrpc_conn_is_service(const struct rxrpc_connection *conn) 71319ffa01cSDavid Howells { 714e8d70ce1SDavid Howells return !rxrpc_conn_is_client(conn); 71519ffa01cSDavid Howells } 71619ffa01cSDavid Howells 7175627cc8bSDavid Howells static inline void rxrpc_get_connection(struct rxrpc_connection *conn) 7185627cc8bSDavid Howells { 7195627cc8bSDavid Howells atomic_inc(&conn->usage); 7205627cc8bSDavid Howells } 7215627cc8bSDavid Howells 7222c4579e4SDavid Howells static inline 7232c4579e4SDavid Howells struct rxrpc_connection *rxrpc_get_connection_maybe(struct rxrpc_connection *conn) 7242c4579e4SDavid Howells { 7252c4579e4SDavid Howells return atomic_inc_not_zero(&conn->usage) ? conn : NULL; 7262c4579e4SDavid Howells } 7275acbee46SDavid Howells 728f51b4480SDavid Howells static inline void rxrpc_put_connection(struct rxrpc_connection *conn) 729f51b4480SDavid Howells { 73045025bceSDavid Howells if (!conn) 73145025bceSDavid Howells return; 73245025bceSDavid Howells 73345025bceSDavid Howells if (rxrpc_conn_is_client(conn)) { 73445025bceSDavid Howells if (atomic_dec_and_test(&conn->usage)) 73545025bceSDavid Howells rxrpc_put_client_conn(conn); 73645025bceSDavid Howells } else { 73745025bceSDavid Howells if (atomic_dec_return(&conn->usage) == 1) 738f51b4480SDavid Howells __rxrpc_put_connection(conn); 739f51b4480SDavid Howells } 74045025bceSDavid Howells } 741f51b4480SDavid Howells 7428496af50SDavid Howells static inline bool rxrpc_queue_conn(struct rxrpc_connection *conn) 7435acbee46SDavid Howells { 7448496af50SDavid Howells if (!rxrpc_get_connection_maybe(conn)) 7458496af50SDavid Howells return false; 7468496af50SDavid Howells if (!rxrpc_queue_work(&conn->processor)) 7472c4579e4SDavid Howells rxrpc_put_connection(conn); 7488496af50SDavid Howells return true; 7495acbee46SDavid Howells } 7505acbee46SDavid Howells 75117926a79SDavid Howells /* 7527877a4a4SDavid Howells * conn_service.c 7537877a4a4SDavid Howells */ 7548496af50SDavid Howells struct rxrpc_connection *rxrpc_find_service_conn_rcu(struct rxrpc_peer *, 7558496af50SDavid Howells struct sk_buff *); 7567877a4a4SDavid Howells struct rxrpc_connection *rxrpc_incoming_connection(struct rxrpc_local *, 757d991b4a3SDavid Howells struct sockaddr_rxrpc *, 7587877a4a4SDavid Howells struct sk_buff *); 759001c1122SDavid Howells void rxrpc_unpublish_service_conn(struct rxrpc_connection *); 7607877a4a4SDavid Howells 7617877a4a4SDavid Howells /* 7620d81a51aSDavid Howells * input.c 76317926a79SDavid Howells */ 764676d2369SDavid S. Miller void rxrpc_data_ready(struct sock *); 765c1b1203dSJoe Perches int rxrpc_queue_rcv_skb(struct rxrpc_call *, struct sk_buff *, bool, bool); 766c1b1203dSJoe Perches void rxrpc_fast_process_packet(struct rxrpc_call *, struct sk_buff *); 76717926a79SDavid Howells 76817926a79SDavid Howells /* 7690d81a51aSDavid Howells * insecure.c 77017926a79SDavid Howells */ 7710d81a51aSDavid Howells extern const struct rxrpc_security rxrpc_no_security; 77217926a79SDavid Howells 77317926a79SDavid Howells /* 7740d81a51aSDavid Howells * key.c 77517926a79SDavid Howells */ 77617926a79SDavid Howells extern struct key_type key_type_rxrpc; 77717926a79SDavid Howells extern struct key_type key_type_rxrpc_s; 77817926a79SDavid Howells 779c1b1203dSJoe Perches int rxrpc_request_key(struct rxrpc_sock *, char __user *, int); 780c1b1203dSJoe Perches int rxrpc_server_keyring(struct rxrpc_sock *, char __user *, int); 781c1b1203dSJoe Perches int rxrpc_get_server_data_key(struct rxrpc_connection *, const void *, time_t, 782c1b1203dSJoe Perches u32); 78317926a79SDavid Howells 78417926a79SDavid Howells /* 78587563616SDavid Howells * local_event.c 78687563616SDavid Howells */ 7874f95dd78SDavid Howells extern void rxrpc_process_local_events(struct rxrpc_local *); 78887563616SDavid Howells 78987563616SDavid Howells /* 7900d81a51aSDavid Howells * local_object.c 79117926a79SDavid Howells */ 7924f95dd78SDavid Howells struct rxrpc_local *rxrpc_lookup_local(const struct sockaddr_rxrpc *); 7934f95dd78SDavid Howells void __rxrpc_put_local(struct rxrpc_local *); 7940d81a51aSDavid Howells void __exit rxrpc_destroy_all_locals(void); 795e0e4d82fSDavid Howells 7964f95dd78SDavid Howells static inline void rxrpc_get_local(struct rxrpc_local *local) 7974f95dd78SDavid Howells { 7984f95dd78SDavid Howells atomic_inc(&local->usage); 7994f95dd78SDavid Howells } 8004f95dd78SDavid Howells 8014f95dd78SDavid Howells static inline 8024f95dd78SDavid Howells struct rxrpc_local *rxrpc_get_local_maybe(struct rxrpc_local *local) 8034f95dd78SDavid Howells { 8044f95dd78SDavid Howells return atomic_inc_not_zero(&local->usage) ? local : NULL; 8054f95dd78SDavid Howells } 8064f95dd78SDavid Howells 8074f95dd78SDavid Howells static inline void rxrpc_put_local(struct rxrpc_local *local) 8084f95dd78SDavid Howells { 8095627cc8bSDavid Howells if (local && atomic_dec_and_test(&local->usage)) 8104f95dd78SDavid Howells __rxrpc_put_local(local); 8114f95dd78SDavid Howells } 8124f95dd78SDavid Howells 8135acbee46SDavid Howells static inline void rxrpc_queue_local(struct rxrpc_local *local) 8145acbee46SDavid Howells { 8155acbee46SDavid Howells rxrpc_queue_work(&local->processor); 8165acbee46SDavid Howells } 8175acbee46SDavid Howells 818e0e4d82fSDavid Howells /* 8198e688d9cSDavid Howells * misc.c 8208e688d9cSDavid Howells */ 8210e119b41SDavid Howells extern unsigned int rxrpc_max_backlog __read_mostly; 8228e688d9cSDavid Howells extern unsigned int rxrpc_requested_ack_delay; 8238e688d9cSDavid Howells extern unsigned int rxrpc_soft_ack_delay; 8248e688d9cSDavid Howells extern unsigned int rxrpc_idle_ack_delay; 8258e688d9cSDavid Howells extern unsigned int rxrpc_rx_window_size; 8268e688d9cSDavid Howells extern unsigned int rxrpc_rx_mtu; 8278e688d9cSDavid Howells extern unsigned int rxrpc_rx_jumbo_max; 8280b58b8a1SDavid Howells extern unsigned int rxrpc_resend_timeout; 8298e688d9cSDavid Howells 8305b3e87f1SDavid Howells extern const char *const rxrpc_pkts[]; 8318e688d9cSDavid Howells extern const s8 rxrpc_ack_priority[]; 8328e688d9cSDavid Howells 8338e688d9cSDavid Howells extern const char *rxrpc_acks(u8 reason); 8348e688d9cSDavid Howells 8358e688d9cSDavid Howells /* 8360d81a51aSDavid Howells * output.c 8370d81a51aSDavid Howells */ 838985a5c82SDavid Howells int rxrpc_send_data_packet(struct rxrpc_connection *, struct sk_buff *); 8390d81a51aSDavid Howells 8400d81a51aSDavid Howells /* 841abe89ef0SDavid Howells * peer_event.c 8420d81a51aSDavid Howells */ 843abe89ef0SDavid Howells void rxrpc_error_report(struct sock *); 844f66d7490SDavid Howells void rxrpc_peer_error_distributor(struct work_struct *); 8450d81a51aSDavid Howells 8460d81a51aSDavid Howells /* 8470d81a51aSDavid Howells * peer_object.c 8480d81a51aSDavid Howells */ 849be6e6707SDavid Howells struct rxrpc_peer *rxrpc_lookup_peer_rcu(struct rxrpc_local *, 850be6e6707SDavid Howells const struct sockaddr_rxrpc *); 851be6e6707SDavid Howells struct rxrpc_peer *rxrpc_lookup_peer(struct rxrpc_local *, 852be6e6707SDavid Howells struct sockaddr_rxrpc *, gfp_t); 853be6e6707SDavid Howells struct rxrpc_peer *rxrpc_alloc_peer(struct rxrpc_local *, gfp_t); 854be6e6707SDavid Howells 855df5d8bf7SDavid Howells static inline struct rxrpc_peer *rxrpc_get_peer(struct rxrpc_peer *peer) 856be6e6707SDavid Howells { 857be6e6707SDavid Howells atomic_inc(&peer->usage); 858df5d8bf7SDavid Howells return peer; 859be6e6707SDavid Howells } 860be6e6707SDavid Howells 861be6e6707SDavid Howells static inline 862be6e6707SDavid Howells struct rxrpc_peer *rxrpc_get_peer_maybe(struct rxrpc_peer *peer) 863be6e6707SDavid Howells { 864be6e6707SDavid Howells return atomic_inc_not_zero(&peer->usage) ? peer : NULL; 865be6e6707SDavid Howells } 866be6e6707SDavid Howells 867be6e6707SDavid Howells extern void __rxrpc_put_peer(struct rxrpc_peer *peer); 868be6e6707SDavid Howells static inline void rxrpc_put_peer(struct rxrpc_peer *peer) 869be6e6707SDavid Howells { 8705627cc8bSDavid Howells if (peer && atomic_dec_and_test(&peer->usage)) 871be6e6707SDavid Howells __rxrpc_put_peer(peer); 872be6e6707SDavid Howells } 8730d81a51aSDavid Howells 8740d81a51aSDavid Howells /* 8750d81a51aSDavid Howells * proc.c 8760d81a51aSDavid Howells */ 8770d81a51aSDavid Howells extern const struct file_operations rxrpc_call_seq_fops; 8780d81a51aSDavid Howells extern const struct file_operations rxrpc_connection_seq_fops; 8790d81a51aSDavid Howells 8800d81a51aSDavid Howells /* 8810d81a51aSDavid Howells * recvmsg.c 8820d81a51aSDavid Howells */ 8830d81a51aSDavid Howells void rxrpc_remove_user_ID(struct rxrpc_sock *, struct rxrpc_call *); 8840d81a51aSDavid Howells int rxrpc_recvmsg(struct socket *, struct msghdr *, size_t, int); 8850d81a51aSDavid Howells 8860d81a51aSDavid Howells /* 887648af7fcSDavid Howells * rxkad.c 888648af7fcSDavid Howells */ 889648af7fcSDavid Howells #ifdef CONFIG_RXKAD 890648af7fcSDavid Howells extern const struct rxrpc_security rxkad; 891648af7fcSDavid Howells #endif 892648af7fcSDavid Howells 893648af7fcSDavid Howells /* 8940d81a51aSDavid Howells * security.c 8950d81a51aSDavid Howells */ 8960d81a51aSDavid Howells int __init rxrpc_init_security(void); 8970d81a51aSDavid Howells void rxrpc_exit_security(void); 8980d81a51aSDavid Howells int rxrpc_init_client_conn_security(struct rxrpc_connection *); 8990d81a51aSDavid Howells int rxrpc_init_server_conn_security(struct rxrpc_connection *); 9000d81a51aSDavid Howells 9010d81a51aSDavid Howells /* 9020b58b8a1SDavid Howells * sendmsg.c 9030b58b8a1SDavid Howells */ 9040b58b8a1SDavid Howells int rxrpc_do_sendmsg(struct rxrpc_sock *, struct msghdr *, size_t); 9050b58b8a1SDavid Howells 9060b58b8a1SDavid Howells /* 9070d81a51aSDavid Howells * skbuff.c 9080d81a51aSDavid Howells */ 909d001648eSDavid Howells void rxrpc_kernel_data_consumed(struct rxrpc_call *, struct sk_buff *); 9100d81a51aSDavid Howells void rxrpc_packet_destructor(struct sk_buff *); 911df844fd4SDavid Howells void rxrpc_new_skb(struct sk_buff *); 912df844fd4SDavid Howells void rxrpc_see_skb(struct sk_buff *); 913df844fd4SDavid Howells void rxrpc_get_skb(struct sk_buff *); 914df844fd4SDavid Howells void rxrpc_free_skb(struct sk_buff *); 915df844fd4SDavid Howells void rxrpc_purge_queue(struct sk_buff_head *); 9160d81a51aSDavid Howells 9170d81a51aSDavid Howells /* 9185873c083SDavid Howells * sysctl.c 9195873c083SDavid Howells */ 9205873c083SDavid Howells #ifdef CONFIG_SYSCTL 9215873c083SDavid Howells extern int __init rxrpc_sysctl_init(void); 9225873c083SDavid Howells extern void rxrpc_sysctl_exit(void); 9235873c083SDavid Howells #else 9245873c083SDavid Howells static inline int __init rxrpc_sysctl_init(void) { return 0; } 9255873c083SDavid Howells static inline void rxrpc_sysctl_exit(void) {} 9265873c083SDavid Howells #endif 9275873c083SDavid Howells 9285873c083SDavid Howells /* 929be6e6707SDavid Howells * utils.c 930be6e6707SDavid Howells */ 931d991b4a3SDavid Howells int rxrpc_extract_addr_from_skb(struct sockaddr_rxrpc *, struct sk_buff *); 932be6e6707SDavid Howells 933be6e6707SDavid Howells /* 93417926a79SDavid Howells * debug tracing 93517926a79SDavid Howells */ 93695c96174SEric Dumazet extern unsigned int rxrpc_debug; 93717926a79SDavid Howells 93817926a79SDavid Howells #define dbgprintk(FMT,...) \ 9399f389f4bSSven Schnelle printk("[%-6.6s] "FMT"\n", current->comm ,##__VA_ARGS__) 94017926a79SDavid Howells 9410dc47877SHarvey Harrison #define kenter(FMT,...) dbgprintk("==> %s("FMT")",__func__ ,##__VA_ARGS__) 9420dc47877SHarvey Harrison #define kleave(FMT,...) dbgprintk("<== %s()"FMT"",__func__ ,##__VA_ARGS__) 94317926a79SDavid Howells #define kdebug(FMT,...) dbgprintk(" "FMT ,##__VA_ARGS__) 94417926a79SDavid Howells #define kproto(FMT,...) dbgprintk("### "FMT ,##__VA_ARGS__) 94517926a79SDavid Howells #define knet(FMT,...) dbgprintk("@@@ "FMT ,##__VA_ARGS__) 94617926a79SDavid Howells 94717926a79SDavid Howells 94817926a79SDavid Howells #if defined(__KDEBUG) 94917926a79SDavid Howells #define _enter(FMT,...) kenter(FMT,##__VA_ARGS__) 95017926a79SDavid Howells #define _leave(FMT,...) kleave(FMT,##__VA_ARGS__) 95117926a79SDavid Howells #define _debug(FMT,...) kdebug(FMT,##__VA_ARGS__) 95217926a79SDavid Howells #define _proto(FMT,...) kproto(FMT,##__VA_ARGS__) 95317926a79SDavid Howells #define _net(FMT,...) knet(FMT,##__VA_ARGS__) 95417926a79SDavid Howells 95517926a79SDavid Howells #elif defined(CONFIG_AF_RXRPC_DEBUG) 95617926a79SDavid Howells #define RXRPC_DEBUG_KENTER 0x01 95717926a79SDavid Howells #define RXRPC_DEBUG_KLEAVE 0x02 95817926a79SDavid Howells #define RXRPC_DEBUG_KDEBUG 0x04 95917926a79SDavid Howells #define RXRPC_DEBUG_KPROTO 0x08 96017926a79SDavid Howells #define RXRPC_DEBUG_KNET 0x10 96117926a79SDavid Howells 96217926a79SDavid Howells #define _enter(FMT,...) \ 96317926a79SDavid Howells do { \ 96417926a79SDavid Howells if (unlikely(rxrpc_debug & RXRPC_DEBUG_KENTER)) \ 96517926a79SDavid Howells kenter(FMT,##__VA_ARGS__); \ 96617926a79SDavid Howells } while (0) 96717926a79SDavid Howells 96817926a79SDavid Howells #define _leave(FMT,...) \ 96917926a79SDavid Howells do { \ 97017926a79SDavid Howells if (unlikely(rxrpc_debug & RXRPC_DEBUG_KLEAVE)) \ 97117926a79SDavid Howells kleave(FMT,##__VA_ARGS__); \ 97217926a79SDavid Howells } while (0) 97317926a79SDavid Howells 97417926a79SDavid Howells #define _debug(FMT,...) \ 97517926a79SDavid Howells do { \ 97617926a79SDavid Howells if (unlikely(rxrpc_debug & RXRPC_DEBUG_KDEBUG)) \ 97717926a79SDavid Howells kdebug(FMT,##__VA_ARGS__); \ 97817926a79SDavid Howells } while (0) 97917926a79SDavid Howells 98017926a79SDavid Howells #define _proto(FMT,...) \ 98117926a79SDavid Howells do { \ 98217926a79SDavid Howells if (unlikely(rxrpc_debug & RXRPC_DEBUG_KPROTO)) \ 98317926a79SDavid Howells kproto(FMT,##__VA_ARGS__); \ 98417926a79SDavid Howells } while (0) 98517926a79SDavid Howells 98617926a79SDavid Howells #define _net(FMT,...) \ 98717926a79SDavid Howells do { \ 98817926a79SDavid Howells if (unlikely(rxrpc_debug & RXRPC_DEBUG_KNET)) \ 98917926a79SDavid Howells knet(FMT,##__VA_ARGS__); \ 99017926a79SDavid Howells } while (0) 99117926a79SDavid Howells 99217926a79SDavid Howells #else 99312fdff3fSDavid Howells #define _enter(FMT,...) no_printk("==> %s("FMT")",__func__ ,##__VA_ARGS__) 99412fdff3fSDavid Howells #define _leave(FMT,...) no_printk("<== %s()"FMT"",__func__ ,##__VA_ARGS__) 99512fdff3fSDavid Howells #define _debug(FMT,...) no_printk(" "FMT ,##__VA_ARGS__) 99612fdff3fSDavid Howells #define _proto(FMT,...) no_printk("### "FMT ,##__VA_ARGS__) 99712fdff3fSDavid Howells #define _net(FMT,...) no_printk("@@@ "FMT ,##__VA_ARGS__) 99817926a79SDavid Howells #endif 99917926a79SDavid Howells 100017926a79SDavid Howells /* 100117926a79SDavid Howells * debug assertion checking 100217926a79SDavid Howells */ 100317926a79SDavid Howells #if 1 // defined(__KDEBUGALL) 100417926a79SDavid Howells 100517926a79SDavid Howells #define ASSERT(X) \ 100617926a79SDavid Howells do { \ 100717926a79SDavid Howells if (unlikely(!(X))) { \ 10089b6d5398SJoe Perches pr_err("Assertion failed\n"); \ 100917926a79SDavid Howells BUG(); \ 101017926a79SDavid Howells } \ 101117926a79SDavid Howells } while (0) 101217926a79SDavid Howells 101317926a79SDavid Howells #define ASSERTCMP(X, OP, Y) \ 101417926a79SDavid Howells do { \ 10159b6d5398SJoe Perches unsigned long _x = (unsigned long)(X); \ 10169b6d5398SJoe Perches unsigned long _y = (unsigned long)(Y); \ 10179b6d5398SJoe Perches if (unlikely(!(_x OP _y))) { \ 10189b6d5398SJoe Perches pr_err("Assertion failed - %lu(0x%lx) %s %lu(0x%lx) is false\n", \ 10199b6d5398SJoe Perches _x, _x, #OP, _y, _y); \ 102017926a79SDavid Howells BUG(); \ 102117926a79SDavid Howells } \ 102217926a79SDavid Howells } while (0) 102317926a79SDavid Howells 102417926a79SDavid Howells #define ASSERTIF(C, X) \ 102517926a79SDavid Howells do { \ 102617926a79SDavid Howells if (unlikely((C) && !(X))) { \ 10279b6d5398SJoe Perches pr_err("Assertion failed\n"); \ 102817926a79SDavid Howells BUG(); \ 102917926a79SDavid Howells } \ 103017926a79SDavid Howells } while (0) 103117926a79SDavid Howells 103217926a79SDavid Howells #define ASSERTIFCMP(C, X, OP, Y) \ 103317926a79SDavid Howells do { \ 10349b6d5398SJoe Perches unsigned long _x = (unsigned long)(X); \ 10359b6d5398SJoe Perches unsigned long _y = (unsigned long)(Y); \ 10369b6d5398SJoe Perches if (unlikely((C) && !(_x OP _y))) { \ 10379b6d5398SJoe Perches pr_err("Assertion failed - %lu(0x%lx) %s %lu(0x%lx) is false\n", \ 10389b6d5398SJoe Perches _x, _x, #OP, _y, _y); \ 103917926a79SDavid Howells BUG(); \ 104017926a79SDavid Howells } \ 104117926a79SDavid Howells } while (0) 104217926a79SDavid Howells 104317926a79SDavid Howells #else 104417926a79SDavid Howells 104517926a79SDavid Howells #define ASSERT(X) \ 104617926a79SDavid Howells do { \ 104717926a79SDavid Howells } while (0) 104817926a79SDavid Howells 104917926a79SDavid Howells #define ASSERTCMP(X, OP, Y) \ 105017926a79SDavid Howells do { \ 105117926a79SDavid Howells } while (0) 105217926a79SDavid Howells 105317926a79SDavid Howells #define ASSERTIF(C, X) \ 105417926a79SDavid Howells do { \ 105517926a79SDavid Howells } while (0) 105617926a79SDavid Howells 105717926a79SDavid Howells #define ASSERTIFCMP(C, X, OP, Y) \ 105817926a79SDavid Howells do { \ 105917926a79SDavid Howells } while (0) 106017926a79SDavid Howells 106117926a79SDavid Howells #endif /* __KDEBUGALL */ 1062