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 /* 4317926a79SDavid Howells * sk_state for RxRPC sockets 4417926a79SDavid Howells */ 4517926a79SDavid Howells enum { 462341e077SDavid Howells RXRPC_UNBOUND = 0, 472341e077SDavid Howells RXRPC_CLIENT_UNBOUND, /* Unbound socket used as client */ 4817926a79SDavid Howells RXRPC_CLIENT_BOUND, /* client local address bound */ 4917926a79SDavid Howells RXRPC_SERVER_BOUND, /* server local address bound */ 5017926a79SDavid Howells RXRPC_SERVER_LISTENING, /* server listening for connections */ 5117926a79SDavid Howells RXRPC_CLOSE, /* socket is being closed */ 5217926a79SDavid Howells }; 5317926a79SDavid Howells 5417926a79SDavid Howells /* 5517926a79SDavid Howells * RxRPC socket definition 5617926a79SDavid Howells */ 5717926a79SDavid Howells struct rxrpc_sock { 5817926a79SDavid Howells /* WARNING: sk has to be the first member */ 5917926a79SDavid Howells struct sock sk; 60651350d1SDavid Howells rxrpc_interceptor_t interceptor; /* kernel service Rx interceptor function */ 6117926a79SDavid Howells struct rxrpc_local *local; /* local endpoint */ 6217926a79SDavid Howells struct list_head listen_link; /* link in the local endpoint's listen list */ 6317926a79SDavid Howells struct list_head secureq; /* calls awaiting connection security clearance */ 6417926a79SDavid Howells struct list_head acceptq; /* calls awaiting acceptance */ 6517926a79SDavid Howells struct key *key; /* security for this socket */ 6617926a79SDavid Howells struct key *securities; /* list of server security descriptors */ 6717926a79SDavid Howells struct rb_root calls; /* outstanding calls on this socket */ 6817926a79SDavid Howells unsigned long flags; 692341e077SDavid Howells #define RXRPC_SOCK_CONNECTED 0 /* connect_srx is set */ 7017926a79SDavid Howells rwlock_t call_lock; /* lock for calls */ 7117926a79SDavid Howells u32 min_sec_level; /* minimum security level */ 7217926a79SDavid Howells #define RXRPC_SECURITY_MAX RXRPC_SECURITY_ENCRYPT 73cc8feb8eSDavid Howells bool exclusive; /* Exclusive connection for a client socket */ 74cc8feb8eSDavid Howells sa_family_t family; /* Protocol family created with */ 7517926a79SDavid Howells struct sockaddr_rxrpc srx; /* local address */ 762341e077SDavid Howells struct sockaddr_rxrpc connect_srx; /* Default client address from connect() */ 7717926a79SDavid Howells }; 7817926a79SDavid Howells 7917926a79SDavid Howells #define rxrpc_sk(__sk) container_of((__sk), struct rxrpc_sock, sk) 8017926a79SDavid Howells 8117926a79SDavid Howells /* 820d12f8a4SDavid Howells * CPU-byteorder normalised Rx packet header. 830d12f8a4SDavid Howells */ 840d12f8a4SDavid Howells struct rxrpc_host_header { 850d12f8a4SDavid Howells u32 epoch; /* client boot timestamp */ 860d12f8a4SDavid Howells u32 cid; /* connection and channel ID */ 870d12f8a4SDavid Howells u32 callNumber; /* call ID (0 for connection-level packets) */ 880d12f8a4SDavid Howells u32 seq; /* sequence number of pkt in call stream */ 890d12f8a4SDavid Howells u32 serial; /* serial number of pkt sent to network */ 900d12f8a4SDavid Howells u8 type; /* packet type */ 910d12f8a4SDavid Howells u8 flags; /* packet flags */ 920d12f8a4SDavid Howells u8 userStatus; /* app-layer defined status */ 930d12f8a4SDavid Howells u8 securityIndex; /* security protocol ID */ 940d12f8a4SDavid Howells union { 950d12f8a4SDavid Howells u16 _rsvd; /* reserved */ 960d12f8a4SDavid Howells u16 cksum; /* kerberos security checksum */ 970d12f8a4SDavid Howells }; 980d12f8a4SDavid Howells u16 serviceId; /* service ID */ 990d12f8a4SDavid Howells } __packed; 1000d12f8a4SDavid Howells 1010d12f8a4SDavid Howells /* 10217926a79SDavid Howells * RxRPC socket buffer private variables 10317926a79SDavid Howells * - max 48 bytes (struct sk_buff::cb) 10417926a79SDavid Howells */ 10517926a79SDavid Howells struct rxrpc_skb_priv { 10617926a79SDavid Howells struct rxrpc_call *call; /* call with which associated */ 10717926a79SDavid Howells unsigned long resend_at; /* time in jiffies at which to resend */ 10817926a79SDavid Howells union { 10995c96174SEric Dumazet unsigned int offset; /* offset into buffer of next read */ 11017926a79SDavid Howells int remain; /* amount of space remaining for next write */ 11117926a79SDavid Howells u32 error; /* network error code */ 11217926a79SDavid Howells bool need_resend; /* T if needs resending */ 11317926a79SDavid Howells }; 11417926a79SDavid Howells 1150d12f8a4SDavid Howells struct rxrpc_host_header hdr; /* RxRPC packet header from this packet */ 11617926a79SDavid Howells }; 11717926a79SDavid Howells 11817926a79SDavid Howells #define rxrpc_skb(__skb) ((struct rxrpc_skb_priv *) &(__skb)->cb) 11917926a79SDavid Howells 12017926a79SDavid Howells enum rxrpc_command { 12117926a79SDavid Howells RXRPC_CMD_SEND_DATA, /* send data message */ 12217926a79SDavid Howells RXRPC_CMD_SEND_ABORT, /* request abort generation */ 12317926a79SDavid Howells RXRPC_CMD_ACCEPT, /* [server] accept incoming call */ 12417926a79SDavid Howells RXRPC_CMD_REJECT_BUSY, /* [server] reject a call as busy */ 12517926a79SDavid Howells }; 12617926a79SDavid Howells 12717926a79SDavid Howells /* 12817926a79SDavid Howells * RxRPC security module interface 12917926a79SDavid Howells */ 13017926a79SDavid Howells struct rxrpc_security { 13117926a79SDavid Howells const char *name; /* name of this service */ 13217926a79SDavid Howells u8 security_index; /* security type provided */ 13317926a79SDavid Howells 134648af7fcSDavid Howells /* Initialise a security service */ 135648af7fcSDavid Howells int (*init)(void); 136648af7fcSDavid Howells 137648af7fcSDavid Howells /* Clean up a security service */ 138648af7fcSDavid Howells void (*exit)(void); 139648af7fcSDavid Howells 14017926a79SDavid Howells /* initialise a connection's security */ 14117926a79SDavid Howells int (*init_connection_security)(struct rxrpc_connection *); 14217926a79SDavid Howells 14317926a79SDavid Howells /* prime a connection's packet security */ 144a263629dSHerbert Xu int (*prime_packet_security)(struct rxrpc_connection *); 14517926a79SDavid Howells 14617926a79SDavid Howells /* impose security on a packet */ 147a263629dSHerbert Xu int (*secure_packet)(struct rxrpc_call *, 14817926a79SDavid Howells struct sk_buff *, 14917926a79SDavid Howells size_t, 15017926a79SDavid Howells void *); 15117926a79SDavid Howells 15217926a79SDavid Howells /* verify the security on a received packet */ 153a263629dSHerbert Xu int (*verify_packet)(struct rxrpc_call *, struct sk_buff *, u32 *); 15417926a79SDavid Howells 15517926a79SDavid Howells /* issue a challenge */ 15617926a79SDavid Howells int (*issue_challenge)(struct rxrpc_connection *); 15717926a79SDavid Howells 15817926a79SDavid Howells /* respond to a challenge */ 15917926a79SDavid Howells int (*respond_to_challenge)(struct rxrpc_connection *, 16017926a79SDavid Howells struct sk_buff *, 16117926a79SDavid Howells u32 *); 16217926a79SDavid Howells 16317926a79SDavid Howells /* verify a response */ 16417926a79SDavid Howells int (*verify_response)(struct rxrpc_connection *, 16517926a79SDavid Howells struct sk_buff *, 16617926a79SDavid Howells u32 *); 16717926a79SDavid Howells 16817926a79SDavid Howells /* clear connection security */ 16917926a79SDavid Howells void (*clear)(struct rxrpc_connection *); 17017926a79SDavid Howells }; 17117926a79SDavid Howells 17217926a79SDavid Howells /* 1734f95dd78SDavid Howells * RxRPC local transport endpoint description 1744f95dd78SDavid Howells * - owned by a single AF_RXRPC socket 1754f95dd78SDavid Howells * - pointed to by transport socket struct sk_user_data 17617926a79SDavid Howells */ 17717926a79SDavid Howells struct rxrpc_local { 1784f95dd78SDavid Howells struct rcu_head rcu; 1794f95dd78SDavid Howells atomic_t usage; 1804f95dd78SDavid Howells struct list_head link; 18117926a79SDavid Howells struct socket *socket; /* my UDP socket */ 1824f95dd78SDavid Howells struct work_struct processor; 18317926a79SDavid Howells struct list_head services; /* services listening on this endpoint */ 18417926a79SDavid Howells struct rw_semaphore defrag_sem; /* control re-enablement of IP DF bit */ 18517926a79SDavid Howells struct sk_buff_head accept_queue; /* incoming calls awaiting acceptance */ 18617926a79SDavid Howells struct sk_buff_head reject_queue; /* packets awaiting rejection */ 18744ba0698SDavid Howells struct sk_buff_head event_queue; /* endpoint event packets awaiting processing */ 188999b69f8SDavid Howells struct rb_root client_conns; /* Client connections by socket params */ 189999b69f8SDavid Howells spinlock_t client_conns_lock; /* Lock for client_conns */ 19017926a79SDavid Howells spinlock_t lock; /* access lock */ 19117926a79SDavid Howells rwlock_t services_lock; /* lock for services list */ 19217926a79SDavid Howells int debug_id; /* debug ID for printks */ 1934f95dd78SDavid Howells bool dead; 19417926a79SDavid Howells struct sockaddr_rxrpc srx; /* local address */ 19517926a79SDavid Howells }; 19617926a79SDavid Howells 19717926a79SDavid Howells /* 19817926a79SDavid Howells * RxRPC remote transport endpoint definition 199be6e6707SDavid Howells * - matched by local endpoint, remote port, address and protocol type 20017926a79SDavid Howells */ 20117926a79SDavid Howells struct rxrpc_peer { 202be6e6707SDavid Howells struct rcu_head rcu; /* This must be first */ 203be6e6707SDavid Howells atomic_t usage; 204be6e6707SDavid Howells unsigned long hash_key; 205be6e6707SDavid Howells struct hlist_node hash_link; 206be6e6707SDavid Howells struct rxrpc_local *local; 207f66d7490SDavid Howells struct hlist_head error_targets; /* targets for net error distribution */ 208f66d7490SDavid Howells struct work_struct error_distributor; 209aa390bbeSDavid Howells struct rb_root service_conns; /* Service connections */ 2108496af50SDavid Howells seqlock_t service_conn_lock; 21117926a79SDavid Howells spinlock_t lock; /* access lock */ 21295c96174SEric Dumazet unsigned int if_mtu; /* interface MTU for this peer */ 21395c96174SEric Dumazet unsigned int mtu; /* network MTU for this peer */ 21495c96174SEric Dumazet unsigned int maxdata; /* data size (MTU - hdrsize) */ 21517926a79SDavid Howells unsigned short hdrsize; /* header size (IP + UDP + RxRPC) */ 21617926a79SDavid Howells int debug_id; /* debug ID for printks */ 217f66d7490SDavid Howells int error_report; /* Net (+0) or local (+1000000) to distribute */ 218f66d7490SDavid Howells #define RXRPC_LOCAL_ERROR_OFFSET 1000000 21917926a79SDavid Howells struct sockaddr_rxrpc srx; /* remote address */ 22017926a79SDavid Howells 22117926a79SDavid Howells /* calculated RTT cache */ 22217926a79SDavid Howells #define RXRPC_RTT_CACHE_SIZE 32 22317926a79SDavid Howells suseconds_t rtt; /* current RTT estimate (in uS) */ 22495c96174SEric Dumazet unsigned int rtt_point; /* next entry at which to insert */ 22595c96174SEric Dumazet unsigned int rtt_usage; /* amount of cache actually used */ 22617926a79SDavid Howells suseconds_t rtt_cache[RXRPC_RTT_CACHE_SIZE]; /* calculated RTT cache */ 22717926a79SDavid Howells }; 22817926a79SDavid Howells 22917926a79SDavid Howells /* 23019ffa01cSDavid Howells * Keys for matching a connection. 23119ffa01cSDavid Howells */ 23219ffa01cSDavid Howells struct rxrpc_conn_proto { 233e8d70ce1SDavid Howells union { 234e8d70ce1SDavid Howells struct { 23519ffa01cSDavid Howells u32 epoch; /* epoch of this connection */ 23619ffa01cSDavid Howells u32 cid; /* connection ID */ 237e8d70ce1SDavid Howells }; 238e8d70ce1SDavid Howells u64 index_key; 23919ffa01cSDavid Howells }; 24019ffa01cSDavid Howells }; 24119ffa01cSDavid Howells 24219ffa01cSDavid Howells struct rxrpc_conn_parameters { 24319ffa01cSDavid Howells struct rxrpc_local *local; /* Representation of local endpoint */ 24419ffa01cSDavid Howells struct rxrpc_peer *peer; /* Remote endpoint */ 24519ffa01cSDavid Howells struct key *key; /* Security details */ 24619ffa01cSDavid Howells bool exclusive; /* T if conn is exclusive */ 24719ffa01cSDavid Howells u16 service_id; /* Service ID for this connection */ 24819ffa01cSDavid Howells u32 security_level; /* Security level selected */ 24919ffa01cSDavid Howells }; 25019ffa01cSDavid Howells 25119ffa01cSDavid Howells /* 252bba304dbSDavid Howells * Bits in the connection flags. 253bba304dbSDavid Howells */ 254bba304dbSDavid Howells enum rxrpc_conn_flag { 255bba304dbSDavid Howells RXRPC_CONN_HAS_IDR, /* Has a client conn ID assigned */ 256001c1122SDavid Howells RXRPC_CONN_IN_SERVICE_CONNS, /* Conn is in peer->service_conns */ 257001c1122SDavid Howells RXRPC_CONN_IN_CLIENT_CONNS, /* Conn is in local->client_conns */ 25845025bceSDavid Howells RXRPC_CONN_EXPOSED, /* Conn has extra ref for exposure */ 25945025bceSDavid Howells RXRPC_CONN_DONT_REUSE, /* Don't reuse this connection */ 26045025bceSDavid Howells RXRPC_CONN_COUNTED, /* Counted by rxrpc_nr_client_conns */ 261bba304dbSDavid Howells }; 262bba304dbSDavid Howells 263bba304dbSDavid Howells /* 264bba304dbSDavid Howells * Events that can be raised upon a connection. 265bba304dbSDavid Howells */ 266bba304dbSDavid Howells enum rxrpc_conn_event { 267bba304dbSDavid Howells RXRPC_CONN_EV_CHALLENGE, /* Send challenge packet */ 268bba304dbSDavid Howells }; 269bba304dbSDavid Howells 270bba304dbSDavid Howells /* 27145025bceSDavid Howells * The connection cache state. 27245025bceSDavid Howells */ 27345025bceSDavid Howells enum rxrpc_conn_cache_state { 27445025bceSDavid Howells RXRPC_CONN_CLIENT_INACTIVE, /* Conn is not yet listed */ 27545025bceSDavid Howells RXRPC_CONN_CLIENT_WAITING, /* Conn is on wait list, waiting for capacity */ 27645025bceSDavid Howells RXRPC_CONN_CLIENT_ACTIVE, /* Conn is on active list, doing calls */ 27745025bceSDavid Howells RXRPC_CONN_CLIENT_CULLED, /* Conn is culled and delisted, doing calls */ 27845025bceSDavid Howells RXRPC_CONN_CLIENT_IDLE, /* Conn is on idle list, doing mostly nothing */ 27945025bceSDavid Howells }; 28045025bceSDavid Howells 28145025bceSDavid Howells /* 282bba304dbSDavid Howells * The connection protocol state. 283bba304dbSDavid Howells */ 284bba304dbSDavid Howells enum rxrpc_conn_proto_state { 285bba304dbSDavid Howells RXRPC_CONN_UNUSED, /* Connection not yet attempted */ 286bba304dbSDavid Howells RXRPC_CONN_CLIENT, /* Client connection */ 287bba304dbSDavid Howells RXRPC_CONN_SERVICE_UNSECURED, /* Service unsecured connection */ 288bba304dbSDavid Howells RXRPC_CONN_SERVICE_CHALLENGING, /* Service challenging for security */ 289bba304dbSDavid Howells RXRPC_CONN_SERVICE, /* Service secured connection */ 290bba304dbSDavid Howells RXRPC_CONN_REMOTELY_ABORTED, /* Conn aborted by peer */ 291bba304dbSDavid Howells RXRPC_CONN_LOCALLY_ABORTED, /* Conn aborted locally */ 292bba304dbSDavid Howells RXRPC_CONN_NETWORK_ERROR, /* Conn terminated by network error */ 29345025bceSDavid Howells RXRPC_CONN_LOCAL_ERROR, /* Conn terminated by local error */ 294bba304dbSDavid Howells RXRPC_CONN__NR_STATES 295bba304dbSDavid Howells }; 296bba304dbSDavid Howells 297bba304dbSDavid Howells /* 29817926a79SDavid Howells * RxRPC connection definition 299aa390bbeSDavid Howells * - matched by { local, peer, epoch, conn_id, direction } 30017926a79SDavid Howells * - each connection can only handle four simultaneous calls 30117926a79SDavid Howells */ 30217926a79SDavid Howells struct rxrpc_connection { 30319ffa01cSDavid Howells struct rxrpc_conn_proto proto; 30419ffa01cSDavid Howells struct rxrpc_conn_parameters params; 30519ffa01cSDavid Howells 30645025bceSDavid Howells atomic_t usage; 30745025bceSDavid Howells struct rcu_head rcu; 30845025bceSDavid Howells struct list_head cache_link; 309a1399f8bSDavid Howells 31045025bceSDavid Howells spinlock_t channel_lock; 31145025bceSDavid Howells unsigned char active_chans; /* Mask of active channels */ 31245025bceSDavid Howells #define RXRPC_ACTIVE_CHANS_MASK ((1 << RXRPC_MAXCALLS) - 1) 31345025bceSDavid Howells struct list_head waiting_calls; /* Calls waiting for channels */ 314a1399f8bSDavid Howells struct rxrpc_channel { 315a1399f8bSDavid Howells struct rxrpc_call __rcu *call; /* Active call */ 316a1399f8bSDavid Howells u32 call_id; /* ID of current call */ 317a1399f8bSDavid Howells u32 call_counter; /* Call ID counter */ 318a1399f8bSDavid Howells u32 last_call; /* ID of last call */ 31918bfeba5SDavid Howells u8 last_type; /* Type of last packet */ 32018bfeba5SDavid Howells u16 last_service_id; 32118bfeba5SDavid Howells union { 32218bfeba5SDavid Howells u32 last_seq; 32318bfeba5SDavid Howells u32 last_abort; 32418bfeba5SDavid Howells }; 325a1399f8bSDavid Howells } channels[RXRPC_MAXCALLS]; 326999b69f8SDavid Howells 32717926a79SDavid Howells struct work_struct processor; /* connection event processor */ 328999b69f8SDavid Howells union { 329999b69f8SDavid Howells struct rb_node client_node; /* Node in local->client_conns */ 330aa390bbeSDavid Howells struct rb_node service_node; /* Node in peer->service_conns */ 331999b69f8SDavid Howells }; 3324d028b2cSDavid Howells struct list_head proc_link; /* link in procfs list */ 33317926a79SDavid Howells struct list_head link; /* link in master connection list */ 33417926a79SDavid Howells struct sk_buff_head rx_queue; /* received conn-level packets */ 335648af7fcSDavid Howells const struct rxrpc_security *security; /* applied security module */ 33617926a79SDavid Howells struct key *server_key; /* security for this service */ 3371afe593bSHerbert Xu struct crypto_skcipher *cipher; /* encryption handle */ 33817926a79SDavid Howells struct rxrpc_crypt csum_iv; /* packet checksum base */ 3394a3388c8SDavid Howells unsigned long flags; 34017926a79SDavid Howells unsigned long events; 341f51b4480SDavid Howells unsigned long idle_timestamp; /* Time at which last became idle */ 34217926a79SDavid Howells spinlock_t state_lock; /* state-change lock */ 34345025bceSDavid Howells enum rxrpc_conn_cache_state cache_state : 8; 344bba304dbSDavid Howells enum rxrpc_conn_proto_state state : 8; /* current state of connection */ 345dc44b3a0SDavid Howells u32 local_abort; /* local abort code */ 346dc44b3a0SDavid Howells u32 remote_abort; /* remote abort code */ 347dc44b3a0SDavid Howells int error; /* local error incurred */ 34817926a79SDavid Howells int debug_id; /* debug ID for printks */ 34917926a79SDavid Howells atomic_t serial; /* packet serial number counter */ 350563ea7d5SDavid Howells unsigned int hi_serial; /* highest serial number received */ 35117926a79SDavid Howells u8 size_align; /* data size alignment (for security) */ 35217926a79SDavid Howells u8 header_size; /* rxrpc + security header size */ 35317926a79SDavid Howells u8 security_size; /* security header size */ 35417926a79SDavid Howells u32 security_nonce; /* response re-use preventer */ 35517926a79SDavid Howells u8 security_ix; /* security type */ 35617926a79SDavid Howells u8 out_clientflag; /* RXRPC_CLIENT_INITIATED if we are client */ 35717926a79SDavid Howells }; 35817926a79SDavid Howells 35917926a79SDavid Howells /* 3605b8848d1SDavid Howells * Flags in call->flags. 3615b8848d1SDavid Howells */ 3625b8848d1SDavid Howells enum rxrpc_call_flag { 3635b8848d1SDavid Howells RXRPC_CALL_RELEASED, /* call has been released - no more message to userspace */ 3645b8848d1SDavid Howells RXRPC_CALL_TERMINAL_MSG, /* call has given the socket its final message */ 3655b8848d1SDavid Howells RXRPC_CALL_RCVD_LAST, /* all packets received */ 3665b8848d1SDavid Howells RXRPC_CALL_RUN_RTIMER, /* Tx resend timer started */ 3675b8848d1SDavid Howells RXRPC_CALL_TX_SOFT_ACK, /* sent some soft ACKs */ 3685b8848d1SDavid Howells RXRPC_CALL_INIT_ACCEPT, /* acceptance was initiated */ 3695b8848d1SDavid Howells RXRPC_CALL_HAS_USERID, /* has a user ID attached */ 3705b8848d1SDavid Howells RXRPC_CALL_EXPECT_OOS, /* expect out of sequence packets */ 371dabe5a79SDavid Howells RXRPC_CALL_IS_SERVICE, /* Call is service call */ 37245025bceSDavid Howells RXRPC_CALL_EXPOSED, /* The call was exposed to the world */ 3735b8848d1SDavid Howells }; 3745b8848d1SDavid Howells 3755b8848d1SDavid Howells /* 3765b8848d1SDavid Howells * Events that can be raised on a call. 3775b8848d1SDavid Howells */ 3785b8848d1SDavid Howells enum rxrpc_call_event { 3794c198ad1SDavid Howells RXRPC_CALL_EV_RCVD_ACKALL, /* ACKALL or reply received */ 3804c198ad1SDavid Howells RXRPC_CALL_EV_RCVD_BUSY, /* busy packet received */ 3814c198ad1SDavid Howells RXRPC_CALL_EV_RCVD_ABORT, /* abort packet received */ 3824c198ad1SDavid Howells RXRPC_CALL_EV_RCVD_ERROR, /* network error received */ 3834c198ad1SDavid Howells RXRPC_CALL_EV_ACK_FINAL, /* need to generate final ACK (and release call) */ 3844c198ad1SDavid Howells RXRPC_CALL_EV_ACK, /* need to generate ACK */ 3854c198ad1SDavid Howells RXRPC_CALL_EV_REJECT_BUSY, /* need to generate busy message */ 3864c198ad1SDavid Howells RXRPC_CALL_EV_ABORT, /* need to generate abort */ 3874c198ad1SDavid Howells RXRPC_CALL_EV_CONN_ABORT, /* local connection abort generated */ 3884c198ad1SDavid Howells RXRPC_CALL_EV_RESEND_TIMER, /* Tx resend timer expired */ 3894c198ad1SDavid Howells RXRPC_CALL_EV_RESEND, /* Tx resend required */ 3904c198ad1SDavid Howells RXRPC_CALL_EV_DRAIN_RX_OOS, /* drain the Rx out of sequence queue */ 3914c198ad1SDavid Howells RXRPC_CALL_EV_LIFE_TIMER, /* call's lifetimer ran out */ 3924c198ad1SDavid Howells RXRPC_CALL_EV_ACCEPTED, /* incoming call accepted by userspace app */ 3934c198ad1SDavid Howells RXRPC_CALL_EV_SECURED, /* incoming call's connection is now secure */ 3944c198ad1SDavid Howells RXRPC_CALL_EV_POST_ACCEPT, /* need to post an "accept?" message to the app */ 3954c198ad1SDavid Howells RXRPC_CALL_EV_RELEASE, /* need to release the call's resources */ 3965b8848d1SDavid Howells }; 3975b8848d1SDavid Howells 3985b8848d1SDavid Howells /* 3995b8848d1SDavid Howells * The states that a call can be in. 4005b8848d1SDavid Howells */ 4015b8848d1SDavid Howells enum rxrpc_call_state { 402999b69f8SDavid Howells RXRPC_CALL_UNINITIALISED, 403999b69f8SDavid Howells RXRPC_CALL_CLIENT_AWAIT_CONN, /* - client waiting for connection to become available */ 4045b8848d1SDavid Howells RXRPC_CALL_CLIENT_SEND_REQUEST, /* - client sending request phase */ 4055b8848d1SDavid Howells RXRPC_CALL_CLIENT_AWAIT_REPLY, /* - client awaiting reply */ 4065b8848d1SDavid Howells RXRPC_CALL_CLIENT_RECV_REPLY, /* - client receiving reply phase */ 4075b8848d1SDavid Howells RXRPC_CALL_CLIENT_FINAL_ACK, /* - client sending final ACK phase */ 4085b8848d1SDavid Howells RXRPC_CALL_SERVER_SECURING, /* - server securing request connection */ 4095b8848d1SDavid Howells RXRPC_CALL_SERVER_ACCEPTING, /* - server accepting request */ 4105b8848d1SDavid Howells RXRPC_CALL_SERVER_RECV_REQUEST, /* - server receiving request */ 4115b8848d1SDavid Howells RXRPC_CALL_SERVER_ACK_REQUEST, /* - server pending ACK of request */ 4125b8848d1SDavid Howells RXRPC_CALL_SERVER_SEND_REPLY, /* - server sending reply */ 4135b8848d1SDavid Howells RXRPC_CALL_SERVER_AWAIT_ACK, /* - server awaiting final ACK */ 4145b8848d1SDavid Howells RXRPC_CALL_COMPLETE, /* - call completed */ 4155b8848d1SDavid Howells RXRPC_CALL_SERVER_BUSY, /* - call rejected by busy server */ 4165b8848d1SDavid Howells RXRPC_CALL_REMOTELY_ABORTED, /* - call aborted by peer */ 4175b8848d1SDavid Howells RXRPC_CALL_LOCALLY_ABORTED, /* - call aborted locally on error or close */ 4185b8848d1SDavid Howells RXRPC_CALL_NETWORK_ERROR, /* - call terminated by network error */ 4195b8848d1SDavid Howells RXRPC_CALL_DEAD, /* - call is dead */ 4205b8848d1SDavid Howells NR__RXRPC_CALL_STATES 4215b8848d1SDavid Howells }; 4225b8848d1SDavid Howells 4235b8848d1SDavid Howells /* 42417926a79SDavid Howells * RxRPC call definition 42517926a79SDavid Howells * - matched by { connection, call_id } 42617926a79SDavid Howells */ 42717926a79SDavid Howells struct rxrpc_call { 428dee46364SDavid Howells struct rcu_head rcu; 42917926a79SDavid Howells struct rxrpc_connection *conn; /* connection carrying call */ 430df5d8bf7SDavid Howells struct rxrpc_peer *peer; /* Peer record for remote address */ 43117926a79SDavid Howells struct rxrpc_sock *socket; /* socket responsible */ 43217926a79SDavid Howells struct timer_list lifetimer; /* lifetime remaining on call */ 43317926a79SDavid Howells struct timer_list deadspan; /* reap timer for re-ACK'ing, etc */ 43417926a79SDavid Howells struct timer_list ack_timer; /* ACK generation timer */ 43517926a79SDavid Howells struct timer_list resend_timer; /* Tx resend timer */ 43617926a79SDavid Howells struct work_struct destroyer; /* call destroyer */ 43717926a79SDavid Howells struct work_struct processor; /* packet processor and ACK generator */ 43817926a79SDavid Howells struct list_head link; /* link in master call list */ 43945025bceSDavid Howells struct list_head chan_wait_link; /* Link in conn->waiting_calls */ 440f66d7490SDavid Howells struct hlist_node error_link; /* link in error distribution list */ 44117926a79SDavid Howells struct list_head accept_link; /* calls awaiting acceptance */ 44217926a79SDavid Howells struct rb_node sock_node; /* node in socket call tree */ 44317926a79SDavid Howells struct sk_buff_head rx_queue; /* received packets */ 44417926a79SDavid Howells struct sk_buff_head rx_oos_queue; /* packets received out of sequence */ 44517926a79SDavid Howells struct sk_buff *tx_pending; /* Tx socket buffer being filled */ 44645025bceSDavid Howells wait_queue_head_t waitq; /* Wait queue for channel or Tx */ 447a263629dSHerbert Xu __be32 crypto_buf[2]; /* Temporary packet crypto buffer */ 44817926a79SDavid Howells unsigned long user_call_ID; /* user-defined call ID */ 44917926a79SDavid Howells unsigned long creation_jif; /* time of call creation */ 45017926a79SDavid Howells unsigned long flags; 45117926a79SDavid Howells unsigned long events; 45217926a79SDavid Howells spinlock_t lock; 45317926a79SDavid Howells rwlock_t state_lock; /* lock for state transition */ 45417926a79SDavid Howells atomic_t usage; 455372ee163SDavid Howells atomic_t skb_count; /* Outstanding packets on this call */ 45617926a79SDavid Howells atomic_t sequence; /* Tx data packet sequence counter */ 457dc44b3a0SDavid Howells u32 local_abort; /* local abort code */ 458dc44b3a0SDavid Howells u32 remote_abort; /* remote abort code */ 459f66d7490SDavid Howells int error_report; /* Network error (ICMP/local transport) */ 460f66d7490SDavid Howells int error; /* Local error incurred */ 4615b8848d1SDavid Howells enum rxrpc_call_state state : 8; /* current state of call */ 462dabe5a79SDavid Howells u16 service_id; /* service ID */ 463dabe5a79SDavid Howells u32 call_id; /* call ID on connection */ 464dabe5a79SDavid Howells u32 cid; /* connection ID plus channel index */ 465dabe5a79SDavid Howells int debug_id; /* debug ID for printks */ 46617926a79SDavid Howells 46717926a79SDavid Howells /* transmission-phase ACK management */ 4684e36a95eSDavid Howells u8 acks_head; /* offset into window of first entry */ 4694e36a95eSDavid Howells u8 acks_tail; /* offset into window of last entry */ 4704e36a95eSDavid Howells u8 acks_winsz; /* size of un-ACK'd window */ 4714e36a95eSDavid Howells u8 acks_unacked; /* lowest unacked packet in last ACK received */ 47217926a79SDavid Howells int acks_latest; /* serial number of latest ACK received */ 47317926a79SDavid Howells rxrpc_seq_t acks_hard; /* highest definitively ACK'd msg seq */ 47417926a79SDavid Howells unsigned long *acks_window; /* sent packet window 47517926a79SDavid Howells * - elements are pointers with LSB set if ACK'd 47617926a79SDavid Howells */ 47717926a79SDavid Howells 47817926a79SDavid Howells /* receive-phase ACK management */ 47917926a79SDavid Howells rxrpc_seq_t rx_data_expect; /* next data seq ID expected to be received */ 48017926a79SDavid Howells rxrpc_seq_t rx_data_post; /* next data seq ID expected to be posted */ 48117926a79SDavid Howells rxrpc_seq_t rx_data_recv; /* last data seq ID encountered by recvmsg */ 48217926a79SDavid Howells rxrpc_seq_t rx_data_eaten; /* last data seq ID consumed by recvmsg */ 48317926a79SDavid Howells rxrpc_seq_t rx_first_oos; /* first packet in rx_oos_queue (or 0) */ 48417926a79SDavid Howells rxrpc_seq_t ackr_win_top; /* top of ACK window (rx_data_eaten is bottom) */ 4850d12f8a4SDavid Howells rxrpc_seq_t ackr_prev_seq; /* previous sequence number received */ 4864e36a95eSDavid Howells u8 ackr_reason; /* reason to ACK */ 487563ea7d5SDavid Howells u16 ackr_skew; /* skew on packet being ACK'd */ 4880d12f8a4SDavid Howells rxrpc_serial_t ackr_serial; /* serial of packet being ACK'd */ 48917926a79SDavid Howells atomic_t ackr_not_idle; /* number of packets in Rx queue */ 49017926a79SDavid Howells 49117926a79SDavid Howells /* received packet records, 1 bit per record */ 49217926a79SDavid Howells #define RXRPC_ACKR_WINDOW_ASZ DIV_ROUND_UP(RXRPC_MAXACKS, BITS_PER_LONG) 49317926a79SDavid Howells unsigned long ackr_window[RXRPC_ACKR_WINDOW_ASZ + 1]; 49417926a79SDavid Howells }; 49517926a79SDavid Howells 49617926a79SDavid Howells /* 49717926a79SDavid Howells * locally abort an RxRPC call 49817926a79SDavid Howells */ 49917926a79SDavid Howells static inline void rxrpc_abort_call(struct rxrpc_call *call, u32 abort_code) 50017926a79SDavid Howells { 50117926a79SDavid Howells write_lock_bh(&call->state_lock); 50217926a79SDavid Howells if (call->state < RXRPC_CALL_COMPLETE) { 503dc44b3a0SDavid Howells call->local_abort = abort_code; 50417926a79SDavid Howells call->state = RXRPC_CALL_LOCALLY_ABORTED; 5054c198ad1SDavid Howells set_bit(RXRPC_CALL_EV_ABORT, &call->events); 50617926a79SDavid Howells } 50717926a79SDavid Howells write_unlock_bh(&call->state_lock); 50817926a79SDavid Howells } 50917926a79SDavid Howells 510df844fd4SDavid Howells #include <trace/events/rxrpc.h> 511df844fd4SDavid Howells 51217926a79SDavid Howells /* 513651350d1SDavid Howells * af_rxrpc.c 51417926a79SDavid Howells */ 515651350d1SDavid Howells extern atomic_t rxrpc_n_skbs; 5160d12f8a4SDavid Howells extern u32 rxrpc_epoch; 517651350d1SDavid Howells extern atomic_t rxrpc_debug_id; 518651350d1SDavid Howells extern struct workqueue_struct *rxrpc_workqueue; 51917926a79SDavid Howells 52017926a79SDavid Howells /* 5210d81a51aSDavid Howells * call_accept.c 52217926a79SDavid Howells */ 5234f95dd78SDavid Howells void rxrpc_accept_incoming_calls(struct rxrpc_local *); 524c1b1203dSJoe Perches struct rxrpc_call *rxrpc_accept_call(struct rxrpc_sock *, unsigned long); 525c1b1203dSJoe Perches int rxrpc_reject_call(struct rxrpc_sock *); 52617926a79SDavid Howells 52717926a79SDavid Howells /* 5280d81a51aSDavid Howells * call_event.c 52917926a79SDavid Howells */ 530563ea7d5SDavid Howells void __rxrpc_propose_ACK(struct rxrpc_call *, u8, u16, u32, bool); 531563ea7d5SDavid Howells void rxrpc_propose_ACK(struct rxrpc_call *, u8, u16, u32, bool); 532c1b1203dSJoe Perches void rxrpc_process_call(struct work_struct *); 53317926a79SDavid Howells 53417926a79SDavid Howells /* 5350d81a51aSDavid Howells * call_object.c 53617926a79SDavid Howells */ 537dad8aff7SDavid Howells extern unsigned int rxrpc_max_call_lifetime; 538dad8aff7SDavid Howells extern unsigned int rxrpc_dead_call_expiry; 53917926a79SDavid Howells extern struct kmem_cache *rxrpc_call_jar; 54017926a79SDavid Howells extern struct list_head rxrpc_calls; 54117926a79SDavid Howells extern rwlock_t rxrpc_call_lock; 54217926a79SDavid Howells 5432341e077SDavid Howells struct rxrpc_call *rxrpc_find_call_by_user_ID(struct rxrpc_sock *, unsigned long); 5442341e077SDavid Howells struct rxrpc_call *rxrpc_new_client_call(struct rxrpc_sock *, 54519ffa01cSDavid Howells struct rxrpc_conn_parameters *, 546999b69f8SDavid Howells struct sockaddr_rxrpc *, 5472341e077SDavid Howells unsigned long, gfp_t); 548c1b1203dSJoe Perches struct rxrpc_call *rxrpc_incoming_call(struct rxrpc_sock *, 54917926a79SDavid Howells struct rxrpc_connection *, 55042886ffeSDavid Howells struct sk_buff *); 551c1b1203dSJoe Perches void rxrpc_release_call(struct rxrpc_call *); 552c1b1203dSJoe Perches void rxrpc_release_calls_on_socket(struct rxrpc_sock *); 553c1b1203dSJoe Perches void __rxrpc_put_call(struct rxrpc_call *); 554c1b1203dSJoe Perches void __exit rxrpc_destroy_all_calls(void); 55517926a79SDavid Howells 556dabe5a79SDavid Howells static inline bool rxrpc_is_service_call(const struct rxrpc_call *call) 557dabe5a79SDavid Howells { 558dabe5a79SDavid Howells return test_bit(RXRPC_CALL_IS_SERVICE, &call->flags); 559dabe5a79SDavid Howells } 560dabe5a79SDavid Howells 561dabe5a79SDavid Howells static inline bool rxrpc_is_client_call(const struct rxrpc_call *call) 562dabe5a79SDavid Howells { 563dabe5a79SDavid Howells return !rxrpc_is_service_call(call); 564dabe5a79SDavid Howells } 565dabe5a79SDavid Howells 56617926a79SDavid Howells /* 5674a3388c8SDavid Howells * conn_client.c 5684a3388c8SDavid Howells */ 56945025bceSDavid Howells extern unsigned int rxrpc_max_client_connections; 57045025bceSDavid Howells extern unsigned int rxrpc_reap_client_connections; 57145025bceSDavid Howells extern unsigned int rxrpc_conn_idle_client_expiry; 57245025bceSDavid Howells extern unsigned int rxrpc_conn_idle_client_fast_expiry; 5734a3388c8SDavid Howells extern struct idr rxrpc_client_conn_ids; 5744a3388c8SDavid Howells 575eb9b9d22SDavid Howells void rxrpc_destroy_client_conn_ids(void); 576c6d2b8d7SDavid Howells int rxrpc_connect_call(struct rxrpc_call *, struct rxrpc_conn_parameters *, 577c6d2b8d7SDavid Howells struct sockaddr_rxrpc *, gfp_t); 57845025bceSDavid Howells void rxrpc_expose_client_call(struct rxrpc_call *); 57945025bceSDavid Howells void rxrpc_disconnect_client_call(struct rxrpc_call *); 58045025bceSDavid Howells void rxrpc_put_client_conn(struct rxrpc_connection *); 58145025bceSDavid Howells void __exit rxrpc_destroy_all_client_connections(void); 5824a3388c8SDavid Howells 5834a3388c8SDavid Howells /* 5840d81a51aSDavid Howells * conn_event.c 5850d81a51aSDavid Howells */ 5860d81a51aSDavid Howells void rxrpc_process_connection(struct work_struct *); 5870d81a51aSDavid Howells void rxrpc_reject_packet(struct rxrpc_local *, struct sk_buff *); 5884f95dd78SDavid Howells void rxrpc_reject_packets(struct rxrpc_local *); 5890d81a51aSDavid Howells 5900d81a51aSDavid Howells /* 5910d81a51aSDavid Howells * conn_object.c 59217926a79SDavid Howells */ 593dad8aff7SDavid Howells extern unsigned int rxrpc_connection_expiry; 59417926a79SDavid Howells extern struct list_head rxrpc_connections; 5954d028b2cSDavid Howells extern struct list_head rxrpc_connection_proc_list; 59617926a79SDavid Howells extern rwlock_t rxrpc_connection_lock; 59717926a79SDavid Howells 5988496af50SDavid Howells int rxrpc_extract_addr_from_skb(struct sockaddr_rxrpc *, struct sk_buff *); 599c6d2b8d7SDavid Howells struct rxrpc_connection *rxrpc_alloc_connection(gfp_t); 6008496af50SDavid Howells struct rxrpc_connection *rxrpc_find_connection_rcu(struct rxrpc_local *, 601aa390bbeSDavid Howells struct sk_buff *); 60245025bceSDavid Howells void __rxrpc_disconnect_call(struct rxrpc_connection *, struct rxrpc_call *); 603999b69f8SDavid Howells void rxrpc_disconnect_call(struct rxrpc_call *); 60445025bceSDavid Howells void rxrpc_kill_connection(struct rxrpc_connection *); 605f51b4480SDavid Howells void __rxrpc_put_connection(struct rxrpc_connection *); 606c1b1203dSJoe Perches void __exit rxrpc_destroy_all_connections(void); 60717926a79SDavid Howells 60819ffa01cSDavid Howells static inline bool rxrpc_conn_is_client(const struct rxrpc_connection *conn) 60919ffa01cSDavid Howells { 61019ffa01cSDavid Howells return conn->out_clientflag; 61119ffa01cSDavid Howells } 61219ffa01cSDavid Howells 61319ffa01cSDavid Howells static inline bool rxrpc_conn_is_service(const struct rxrpc_connection *conn) 61419ffa01cSDavid Howells { 615e8d70ce1SDavid Howells return !rxrpc_conn_is_client(conn); 61619ffa01cSDavid Howells } 61719ffa01cSDavid Howells 6185627cc8bSDavid Howells static inline void rxrpc_get_connection(struct rxrpc_connection *conn) 6195627cc8bSDavid Howells { 6205627cc8bSDavid Howells atomic_inc(&conn->usage); 6215627cc8bSDavid Howells } 6225627cc8bSDavid Howells 6232c4579e4SDavid Howells static inline 6242c4579e4SDavid Howells struct rxrpc_connection *rxrpc_get_connection_maybe(struct rxrpc_connection *conn) 6252c4579e4SDavid Howells { 6262c4579e4SDavid Howells return atomic_inc_not_zero(&conn->usage) ? conn : NULL; 6272c4579e4SDavid Howells } 6285acbee46SDavid Howells 629f51b4480SDavid Howells static inline void rxrpc_put_connection(struct rxrpc_connection *conn) 630f51b4480SDavid Howells { 63145025bceSDavid Howells if (!conn) 63245025bceSDavid Howells return; 63345025bceSDavid Howells 63445025bceSDavid Howells if (rxrpc_conn_is_client(conn)) { 63545025bceSDavid Howells if (atomic_dec_and_test(&conn->usage)) 63645025bceSDavid Howells rxrpc_put_client_conn(conn); 63745025bceSDavid Howells } else { 63845025bceSDavid Howells if (atomic_dec_return(&conn->usage) == 1) 639f51b4480SDavid Howells __rxrpc_put_connection(conn); 640f51b4480SDavid Howells } 64145025bceSDavid Howells } 642f51b4480SDavid Howells 643f51b4480SDavid Howells 6448496af50SDavid Howells static inline bool rxrpc_queue_conn(struct rxrpc_connection *conn) 6455acbee46SDavid Howells { 6468496af50SDavid Howells if (!rxrpc_get_connection_maybe(conn)) 6478496af50SDavid Howells return false; 6488496af50SDavid Howells if (!rxrpc_queue_work(&conn->processor)) 6492c4579e4SDavid Howells rxrpc_put_connection(conn); 6508496af50SDavid Howells return true; 6515acbee46SDavid Howells } 6525acbee46SDavid Howells 65317926a79SDavid Howells /* 6547877a4a4SDavid Howells * conn_service.c 6557877a4a4SDavid Howells */ 6568496af50SDavid Howells struct rxrpc_connection *rxrpc_find_service_conn_rcu(struct rxrpc_peer *, 6578496af50SDavid Howells struct sk_buff *); 6587877a4a4SDavid Howells struct rxrpc_connection *rxrpc_incoming_connection(struct rxrpc_local *, 659d991b4a3SDavid Howells struct sockaddr_rxrpc *, 6607877a4a4SDavid Howells struct sk_buff *); 661001c1122SDavid Howells void rxrpc_unpublish_service_conn(struct rxrpc_connection *); 6627877a4a4SDavid Howells 6637877a4a4SDavid Howells /* 6640d81a51aSDavid Howells * input.c 66517926a79SDavid Howells */ 666676d2369SDavid S. Miller void rxrpc_data_ready(struct sock *); 667c1b1203dSJoe Perches int rxrpc_queue_rcv_skb(struct rxrpc_call *, struct sk_buff *, bool, bool); 668c1b1203dSJoe Perches void rxrpc_fast_process_packet(struct rxrpc_call *, struct sk_buff *); 66917926a79SDavid Howells 67017926a79SDavid Howells /* 6710d81a51aSDavid Howells * insecure.c 67217926a79SDavid Howells */ 6730d81a51aSDavid Howells extern const struct rxrpc_security rxrpc_no_security; 67417926a79SDavid Howells 67517926a79SDavid Howells /* 6760d81a51aSDavid Howells * key.c 67717926a79SDavid Howells */ 67817926a79SDavid Howells extern struct key_type key_type_rxrpc; 67917926a79SDavid Howells extern struct key_type key_type_rxrpc_s; 68017926a79SDavid Howells 681c1b1203dSJoe Perches int rxrpc_request_key(struct rxrpc_sock *, char __user *, int); 682c1b1203dSJoe Perches int rxrpc_server_keyring(struct rxrpc_sock *, char __user *, int); 683c1b1203dSJoe Perches int rxrpc_get_server_data_key(struct rxrpc_connection *, const void *, time_t, 684c1b1203dSJoe Perches u32); 68517926a79SDavid Howells 68617926a79SDavid Howells /* 68787563616SDavid Howells * local_event.c 68887563616SDavid Howells */ 6894f95dd78SDavid Howells extern void rxrpc_process_local_events(struct rxrpc_local *); 69087563616SDavid Howells 69187563616SDavid Howells /* 6920d81a51aSDavid Howells * local_object.c 69317926a79SDavid Howells */ 6944f95dd78SDavid Howells struct rxrpc_local *rxrpc_lookup_local(const struct sockaddr_rxrpc *); 6954f95dd78SDavid Howells void __rxrpc_put_local(struct rxrpc_local *); 6960d81a51aSDavid Howells void __exit rxrpc_destroy_all_locals(void); 697e0e4d82fSDavid Howells 6984f95dd78SDavid Howells static inline void rxrpc_get_local(struct rxrpc_local *local) 6994f95dd78SDavid Howells { 7004f95dd78SDavid Howells atomic_inc(&local->usage); 7014f95dd78SDavid Howells } 7024f95dd78SDavid Howells 7034f95dd78SDavid Howells static inline 7044f95dd78SDavid Howells struct rxrpc_local *rxrpc_get_local_maybe(struct rxrpc_local *local) 7054f95dd78SDavid Howells { 7064f95dd78SDavid Howells return atomic_inc_not_zero(&local->usage) ? local : NULL; 7074f95dd78SDavid Howells } 7084f95dd78SDavid Howells 7094f95dd78SDavid Howells static inline void rxrpc_put_local(struct rxrpc_local *local) 7104f95dd78SDavid Howells { 7115627cc8bSDavid Howells if (local && atomic_dec_and_test(&local->usage)) 7124f95dd78SDavid Howells __rxrpc_put_local(local); 7134f95dd78SDavid Howells } 7144f95dd78SDavid Howells 7155acbee46SDavid Howells static inline void rxrpc_queue_local(struct rxrpc_local *local) 7165acbee46SDavid Howells { 7175acbee46SDavid Howells rxrpc_queue_work(&local->processor); 7185acbee46SDavid Howells } 7195acbee46SDavid Howells 720e0e4d82fSDavid Howells /* 7218e688d9cSDavid Howells * misc.c 7228e688d9cSDavid Howells */ 7230e119b41SDavid Howells extern unsigned int rxrpc_max_backlog __read_mostly; 7248e688d9cSDavid Howells extern unsigned int rxrpc_requested_ack_delay; 7258e688d9cSDavid Howells extern unsigned int rxrpc_soft_ack_delay; 7268e688d9cSDavid Howells extern unsigned int rxrpc_idle_ack_delay; 7278e688d9cSDavid Howells extern unsigned int rxrpc_rx_window_size; 7288e688d9cSDavid Howells extern unsigned int rxrpc_rx_mtu; 7298e688d9cSDavid Howells extern unsigned int rxrpc_rx_jumbo_max; 7308e688d9cSDavid Howells 7315b3e87f1SDavid Howells extern const char *const rxrpc_pkts[]; 7328e688d9cSDavid Howells extern const s8 rxrpc_ack_priority[]; 7338e688d9cSDavid Howells 7348e688d9cSDavid Howells extern const char *rxrpc_acks(u8 reason); 7358e688d9cSDavid Howells 7368e688d9cSDavid Howells /* 7370d81a51aSDavid Howells * output.c 7380d81a51aSDavid Howells */ 7390d81a51aSDavid Howells extern unsigned int rxrpc_resend_timeout; 7400d81a51aSDavid Howells 741985a5c82SDavid Howells int rxrpc_send_data_packet(struct rxrpc_connection *, struct sk_buff *); 7420d81a51aSDavid Howells int rxrpc_do_sendmsg(struct rxrpc_sock *, struct msghdr *, size_t); 7430d81a51aSDavid Howells 7440d81a51aSDavid Howells /* 745abe89ef0SDavid Howells * peer_event.c 7460d81a51aSDavid Howells */ 747abe89ef0SDavid Howells void rxrpc_error_report(struct sock *); 748f66d7490SDavid Howells void rxrpc_peer_error_distributor(struct work_struct *); 7490d81a51aSDavid Howells 7500d81a51aSDavid Howells /* 7510d81a51aSDavid Howells * peer_object.c 7520d81a51aSDavid Howells */ 753be6e6707SDavid Howells struct rxrpc_peer *rxrpc_lookup_peer_rcu(struct rxrpc_local *, 754be6e6707SDavid Howells const struct sockaddr_rxrpc *); 755be6e6707SDavid Howells struct rxrpc_peer *rxrpc_lookup_peer(struct rxrpc_local *, 756be6e6707SDavid Howells struct sockaddr_rxrpc *, gfp_t); 757be6e6707SDavid Howells struct rxrpc_peer *rxrpc_alloc_peer(struct rxrpc_local *, gfp_t); 758be6e6707SDavid Howells 759df5d8bf7SDavid Howells static inline struct rxrpc_peer *rxrpc_get_peer(struct rxrpc_peer *peer) 760be6e6707SDavid Howells { 761be6e6707SDavid Howells atomic_inc(&peer->usage); 762df5d8bf7SDavid Howells return peer; 763be6e6707SDavid Howells } 764be6e6707SDavid Howells 765be6e6707SDavid Howells static inline 766be6e6707SDavid Howells struct rxrpc_peer *rxrpc_get_peer_maybe(struct rxrpc_peer *peer) 767be6e6707SDavid Howells { 768be6e6707SDavid Howells return atomic_inc_not_zero(&peer->usage) ? peer : NULL; 769be6e6707SDavid Howells } 770be6e6707SDavid Howells 771be6e6707SDavid Howells extern void __rxrpc_put_peer(struct rxrpc_peer *peer); 772be6e6707SDavid Howells static inline void rxrpc_put_peer(struct rxrpc_peer *peer) 773be6e6707SDavid Howells { 7745627cc8bSDavid Howells if (peer && atomic_dec_and_test(&peer->usage)) 775be6e6707SDavid Howells __rxrpc_put_peer(peer); 776be6e6707SDavid Howells } 7770d81a51aSDavid Howells 7780d81a51aSDavid Howells /* 7790d81a51aSDavid Howells * proc.c 7800d81a51aSDavid Howells */ 7810d81a51aSDavid Howells extern const char *const rxrpc_call_states[]; 7820d81a51aSDavid Howells extern const struct file_operations rxrpc_call_seq_fops; 7830d81a51aSDavid Howells extern const struct file_operations rxrpc_connection_seq_fops; 7840d81a51aSDavid Howells 7850d81a51aSDavid Howells /* 7860d81a51aSDavid Howells * recvmsg.c 7870d81a51aSDavid Howells */ 7880d81a51aSDavid Howells void rxrpc_remove_user_ID(struct rxrpc_sock *, struct rxrpc_call *); 7890d81a51aSDavid Howells int rxrpc_recvmsg(struct socket *, struct msghdr *, size_t, int); 7900d81a51aSDavid Howells 7910d81a51aSDavid Howells /* 792648af7fcSDavid Howells * rxkad.c 793648af7fcSDavid Howells */ 794648af7fcSDavid Howells #ifdef CONFIG_RXKAD 795648af7fcSDavid Howells extern const struct rxrpc_security rxkad; 796648af7fcSDavid Howells #endif 797648af7fcSDavid Howells 798648af7fcSDavid Howells /* 7990d81a51aSDavid Howells * security.c 8000d81a51aSDavid Howells */ 8010d81a51aSDavid Howells int __init rxrpc_init_security(void); 8020d81a51aSDavid Howells void rxrpc_exit_security(void); 8030d81a51aSDavid Howells int rxrpc_init_client_conn_security(struct rxrpc_connection *); 8040d81a51aSDavid Howells int rxrpc_init_server_conn_security(struct rxrpc_connection *); 8050d81a51aSDavid Howells 8060d81a51aSDavid Howells /* 8070d81a51aSDavid Howells * skbuff.c 8080d81a51aSDavid Howells */ 8090d81a51aSDavid Howells void rxrpc_packet_destructor(struct sk_buff *); 810df844fd4SDavid Howells void rxrpc_new_skb(struct sk_buff *); 811df844fd4SDavid Howells void rxrpc_see_skb(struct sk_buff *); 812df844fd4SDavid Howells void rxrpc_get_skb(struct sk_buff *); 813df844fd4SDavid Howells void rxrpc_free_skb(struct sk_buff *); 814df844fd4SDavid Howells void rxrpc_purge_queue(struct sk_buff_head *); 8150d81a51aSDavid Howells 8160d81a51aSDavid Howells /* 8175873c083SDavid Howells * sysctl.c 8185873c083SDavid Howells */ 8195873c083SDavid Howells #ifdef CONFIG_SYSCTL 8205873c083SDavid Howells extern int __init rxrpc_sysctl_init(void); 8215873c083SDavid Howells extern void rxrpc_sysctl_exit(void); 8225873c083SDavid Howells #else 8235873c083SDavid Howells static inline int __init rxrpc_sysctl_init(void) { return 0; } 8245873c083SDavid Howells static inline void rxrpc_sysctl_exit(void) {} 8255873c083SDavid Howells #endif 8265873c083SDavid Howells 8275873c083SDavid Howells /* 828be6e6707SDavid Howells * utils.c 829be6e6707SDavid Howells */ 830d991b4a3SDavid Howells int rxrpc_extract_addr_from_skb(struct sockaddr_rxrpc *, struct sk_buff *); 831be6e6707SDavid Howells 832be6e6707SDavid Howells /* 83317926a79SDavid Howells * debug tracing 83417926a79SDavid Howells */ 83595c96174SEric Dumazet extern unsigned int rxrpc_debug; 83617926a79SDavid Howells 83717926a79SDavid Howells #define dbgprintk(FMT,...) \ 8389f389f4bSSven Schnelle printk("[%-6.6s] "FMT"\n", current->comm ,##__VA_ARGS__) 83917926a79SDavid Howells 8400dc47877SHarvey Harrison #define kenter(FMT,...) dbgprintk("==> %s("FMT")",__func__ ,##__VA_ARGS__) 8410dc47877SHarvey Harrison #define kleave(FMT,...) dbgprintk("<== %s()"FMT"",__func__ ,##__VA_ARGS__) 84217926a79SDavid Howells #define kdebug(FMT,...) dbgprintk(" "FMT ,##__VA_ARGS__) 84317926a79SDavid Howells #define kproto(FMT,...) dbgprintk("### "FMT ,##__VA_ARGS__) 84417926a79SDavid Howells #define knet(FMT,...) dbgprintk("@@@ "FMT ,##__VA_ARGS__) 84517926a79SDavid Howells 84617926a79SDavid Howells 84717926a79SDavid Howells #if defined(__KDEBUG) 84817926a79SDavid Howells #define _enter(FMT,...) kenter(FMT,##__VA_ARGS__) 84917926a79SDavid Howells #define _leave(FMT,...) kleave(FMT,##__VA_ARGS__) 85017926a79SDavid Howells #define _debug(FMT,...) kdebug(FMT,##__VA_ARGS__) 85117926a79SDavid Howells #define _proto(FMT,...) kproto(FMT,##__VA_ARGS__) 85217926a79SDavid Howells #define _net(FMT,...) knet(FMT,##__VA_ARGS__) 85317926a79SDavid Howells 85417926a79SDavid Howells #elif defined(CONFIG_AF_RXRPC_DEBUG) 85517926a79SDavid Howells #define RXRPC_DEBUG_KENTER 0x01 85617926a79SDavid Howells #define RXRPC_DEBUG_KLEAVE 0x02 85717926a79SDavid Howells #define RXRPC_DEBUG_KDEBUG 0x04 85817926a79SDavid Howells #define RXRPC_DEBUG_KPROTO 0x08 85917926a79SDavid Howells #define RXRPC_DEBUG_KNET 0x10 86017926a79SDavid Howells 86117926a79SDavid Howells #define _enter(FMT,...) \ 86217926a79SDavid Howells do { \ 86317926a79SDavid Howells if (unlikely(rxrpc_debug & RXRPC_DEBUG_KENTER)) \ 86417926a79SDavid Howells kenter(FMT,##__VA_ARGS__); \ 86517926a79SDavid Howells } while (0) 86617926a79SDavid Howells 86717926a79SDavid Howells #define _leave(FMT,...) \ 86817926a79SDavid Howells do { \ 86917926a79SDavid Howells if (unlikely(rxrpc_debug & RXRPC_DEBUG_KLEAVE)) \ 87017926a79SDavid Howells kleave(FMT,##__VA_ARGS__); \ 87117926a79SDavid Howells } while (0) 87217926a79SDavid Howells 87317926a79SDavid Howells #define _debug(FMT,...) \ 87417926a79SDavid Howells do { \ 87517926a79SDavid Howells if (unlikely(rxrpc_debug & RXRPC_DEBUG_KDEBUG)) \ 87617926a79SDavid Howells kdebug(FMT,##__VA_ARGS__); \ 87717926a79SDavid Howells } while (0) 87817926a79SDavid Howells 87917926a79SDavid Howells #define _proto(FMT,...) \ 88017926a79SDavid Howells do { \ 88117926a79SDavid Howells if (unlikely(rxrpc_debug & RXRPC_DEBUG_KPROTO)) \ 88217926a79SDavid Howells kproto(FMT,##__VA_ARGS__); \ 88317926a79SDavid Howells } while (0) 88417926a79SDavid Howells 88517926a79SDavid Howells #define _net(FMT,...) \ 88617926a79SDavid Howells do { \ 88717926a79SDavid Howells if (unlikely(rxrpc_debug & RXRPC_DEBUG_KNET)) \ 88817926a79SDavid Howells knet(FMT,##__VA_ARGS__); \ 88917926a79SDavid Howells } while (0) 89017926a79SDavid Howells 89117926a79SDavid Howells #else 89212fdff3fSDavid Howells #define _enter(FMT,...) no_printk("==> %s("FMT")",__func__ ,##__VA_ARGS__) 89312fdff3fSDavid Howells #define _leave(FMT,...) no_printk("<== %s()"FMT"",__func__ ,##__VA_ARGS__) 89412fdff3fSDavid Howells #define _debug(FMT,...) no_printk(" "FMT ,##__VA_ARGS__) 89512fdff3fSDavid Howells #define _proto(FMT,...) no_printk("### "FMT ,##__VA_ARGS__) 89612fdff3fSDavid Howells #define _net(FMT,...) no_printk("@@@ "FMT ,##__VA_ARGS__) 89717926a79SDavid Howells #endif 89817926a79SDavid Howells 89917926a79SDavid Howells /* 90017926a79SDavid Howells * debug assertion checking 90117926a79SDavid Howells */ 90217926a79SDavid Howells #if 1 // defined(__KDEBUGALL) 90317926a79SDavid Howells 90417926a79SDavid Howells #define ASSERT(X) \ 90517926a79SDavid Howells do { \ 90617926a79SDavid Howells if (unlikely(!(X))) { \ 9079b6d5398SJoe Perches pr_err("Assertion failed\n"); \ 90817926a79SDavid Howells BUG(); \ 90917926a79SDavid Howells } \ 91017926a79SDavid Howells } while (0) 91117926a79SDavid Howells 91217926a79SDavid Howells #define ASSERTCMP(X, OP, Y) \ 91317926a79SDavid Howells do { \ 9149b6d5398SJoe Perches unsigned long _x = (unsigned long)(X); \ 9159b6d5398SJoe Perches unsigned long _y = (unsigned long)(Y); \ 9169b6d5398SJoe Perches if (unlikely(!(_x OP _y))) { \ 9179b6d5398SJoe Perches pr_err("Assertion failed - %lu(0x%lx) %s %lu(0x%lx) is false\n", \ 9189b6d5398SJoe Perches _x, _x, #OP, _y, _y); \ 91917926a79SDavid Howells BUG(); \ 92017926a79SDavid Howells } \ 92117926a79SDavid Howells } while (0) 92217926a79SDavid Howells 92317926a79SDavid Howells #define ASSERTIF(C, X) \ 92417926a79SDavid Howells do { \ 92517926a79SDavid Howells if (unlikely((C) && !(X))) { \ 9269b6d5398SJoe Perches pr_err("Assertion failed\n"); \ 92717926a79SDavid Howells BUG(); \ 92817926a79SDavid Howells } \ 92917926a79SDavid Howells } while (0) 93017926a79SDavid Howells 93117926a79SDavid Howells #define ASSERTIFCMP(C, X, OP, Y) \ 93217926a79SDavid Howells do { \ 9339b6d5398SJoe Perches unsigned long _x = (unsigned long)(X); \ 9349b6d5398SJoe Perches unsigned long _y = (unsigned long)(Y); \ 9359b6d5398SJoe Perches if (unlikely((C) && !(_x OP _y))) { \ 9369b6d5398SJoe Perches pr_err("Assertion failed - %lu(0x%lx) %s %lu(0x%lx) is false\n", \ 9379b6d5398SJoe Perches _x, _x, #OP, _y, _y); \ 93817926a79SDavid Howells BUG(); \ 93917926a79SDavid Howells } \ 94017926a79SDavid Howells } while (0) 94117926a79SDavid Howells 94217926a79SDavid Howells #else 94317926a79SDavid Howells 94417926a79SDavid Howells #define ASSERT(X) \ 94517926a79SDavid Howells do { \ 94617926a79SDavid Howells } while (0) 94717926a79SDavid Howells 94817926a79SDavid Howells #define ASSERTCMP(X, OP, Y) \ 94917926a79SDavid Howells do { \ 95017926a79SDavid Howells } while (0) 95117926a79SDavid Howells 95217926a79SDavid Howells #define ASSERTIF(C, X) \ 95317926a79SDavid Howells do { \ 95417926a79SDavid Howells } while (0) 95517926a79SDavid Howells 95617926a79SDavid Howells #define ASSERTIFCMP(C, X, OP, Y) \ 95717926a79SDavid Howells do { \ 95817926a79SDavid Howells } while (0) 95917926a79SDavid Howells 96017926a79SDavid Howells #endif /* __KDEBUGALL */ 96117926a79SDavid Howells 96217926a79SDavid Howells 96317926a79SDavid Howells #define rxrpc_get_call(CALL) \ 96417926a79SDavid Howells do { \ 96517926a79SDavid Howells CHECK_SLAB_OKAY(&(CALL)->usage); \ 96617926a79SDavid Howells if (atomic_inc_return(&(CALL)->usage) == 1) \ 96717926a79SDavid Howells BUG(); \ 96817926a79SDavid Howells } while (0) 96917926a79SDavid Howells 97017926a79SDavid Howells #define rxrpc_put_call(CALL) \ 97117926a79SDavid Howells do { \ 97217926a79SDavid Howells __rxrpc_put_call(CALL); \ 97317926a79SDavid Howells } while (0) 974