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> 13e0e4d82fSDavid Howells #include <net/sock.h> 14be6e6707SDavid Howells #include <net/af_rxrpc.h> 1517926a79SDavid Howells #include <rxrpc/packet.h> 1617926a79SDavid Howells 1717926a79SDavid Howells #if 0 1817926a79SDavid Howells #define CHECK_SLAB_OKAY(X) \ 1917926a79SDavid Howells BUG_ON(atomic_read((X)) >> (sizeof(atomic_t) - 2) == \ 2017926a79SDavid Howells (POISON_FREE << 8 | POISON_FREE)) 2117926a79SDavid Howells #else 2217926a79SDavid Howells #define CHECK_SLAB_OKAY(X) do {} while (0) 2317926a79SDavid Howells #endif 2417926a79SDavid Howells 2517926a79SDavid Howells #define FCRYPT_BSIZE 8 2617926a79SDavid Howells struct rxrpc_crypt { 2717926a79SDavid Howells union { 2817926a79SDavid Howells u8 x[FCRYPT_BSIZE]; 2991e916cfSAl Viro __be32 n[2]; 3017926a79SDavid Howells }; 3117926a79SDavid Howells } __attribute__((aligned(8))); 3217926a79SDavid Howells 33651350d1SDavid Howells #define rxrpc_queue_work(WS) queue_work(rxrpc_workqueue, (WS)) 34651350d1SDavid Howells #define rxrpc_queue_delayed_work(WS,D) \ 35651350d1SDavid Howells queue_delayed_work(rxrpc_workqueue, (WS), (D)) 36651350d1SDavid Howells 37651350d1SDavid Howells #define rxrpc_queue_call(CALL) rxrpc_queue_work(&(CALL)->processor) 3817926a79SDavid Howells 39cc8feb8eSDavid Howells struct rxrpc_connection; 40cc8feb8eSDavid Howells 4117926a79SDavid Howells /* 4217926a79SDavid Howells * sk_state for RxRPC sockets 4317926a79SDavid Howells */ 4417926a79SDavid Howells enum { 452341e077SDavid Howells RXRPC_UNBOUND = 0, 462341e077SDavid Howells RXRPC_CLIENT_UNBOUND, /* Unbound socket used as client */ 4717926a79SDavid Howells RXRPC_CLIENT_BOUND, /* client local address bound */ 4817926a79SDavid Howells RXRPC_SERVER_BOUND, /* server local address bound */ 4917926a79SDavid Howells RXRPC_SERVER_LISTENING, /* server listening for connections */ 5017926a79SDavid Howells RXRPC_CLOSE, /* socket is being closed */ 5117926a79SDavid Howells }; 5217926a79SDavid Howells 5317926a79SDavid Howells /* 5417926a79SDavid Howells * RxRPC socket definition 5517926a79SDavid Howells */ 5617926a79SDavid Howells struct rxrpc_sock { 5717926a79SDavid Howells /* WARNING: sk has to be the first member */ 5817926a79SDavid Howells struct sock sk; 59651350d1SDavid Howells rxrpc_interceptor_t interceptor; /* kernel service Rx interceptor function */ 6017926a79SDavid Howells struct rxrpc_local *local; /* local endpoint */ 6117926a79SDavid Howells struct list_head listen_link; /* link in the local endpoint's listen list */ 6217926a79SDavid Howells struct list_head secureq; /* calls awaiting connection security clearance */ 6317926a79SDavid Howells struct list_head acceptq; /* calls awaiting acceptance */ 6417926a79SDavid Howells struct key *key; /* security for this socket */ 6517926a79SDavid Howells struct key *securities; /* list of server security descriptors */ 6617926a79SDavid Howells struct rb_root calls; /* outstanding calls on this socket */ 6717926a79SDavid Howells unsigned long flags; 682341e077SDavid Howells #define RXRPC_SOCK_CONNECTED 0 /* connect_srx is set */ 6917926a79SDavid Howells rwlock_t call_lock; /* lock for calls */ 7017926a79SDavid Howells u32 min_sec_level; /* minimum security level */ 7117926a79SDavid Howells #define RXRPC_SECURITY_MAX RXRPC_SECURITY_ENCRYPT 72cc8feb8eSDavid Howells bool exclusive; /* Exclusive connection for a client socket */ 73cc8feb8eSDavid Howells sa_family_t family; /* Protocol family created with */ 7417926a79SDavid Howells struct sockaddr_rxrpc srx; /* local address */ 752341e077SDavid Howells struct sockaddr_rxrpc connect_srx; /* Default client address from connect() */ 7617926a79SDavid Howells }; 7717926a79SDavid Howells 7817926a79SDavid Howells #define rxrpc_sk(__sk) container_of((__sk), struct rxrpc_sock, sk) 7917926a79SDavid Howells 8017926a79SDavid Howells /* 810d12f8a4SDavid Howells * CPU-byteorder normalised Rx packet header. 820d12f8a4SDavid Howells */ 830d12f8a4SDavid Howells struct rxrpc_host_header { 840d12f8a4SDavid Howells u32 epoch; /* client boot timestamp */ 850d12f8a4SDavid Howells u32 cid; /* connection and channel ID */ 860d12f8a4SDavid Howells u32 callNumber; /* call ID (0 for connection-level packets) */ 870d12f8a4SDavid Howells u32 seq; /* sequence number of pkt in call stream */ 880d12f8a4SDavid Howells u32 serial; /* serial number of pkt sent to network */ 890d12f8a4SDavid Howells u8 type; /* packet type */ 900d12f8a4SDavid Howells u8 flags; /* packet flags */ 910d12f8a4SDavid Howells u8 userStatus; /* app-layer defined status */ 920d12f8a4SDavid Howells u8 securityIndex; /* security protocol ID */ 930d12f8a4SDavid Howells union { 940d12f8a4SDavid Howells u16 _rsvd; /* reserved */ 950d12f8a4SDavid Howells u16 cksum; /* kerberos security checksum */ 960d12f8a4SDavid Howells }; 970d12f8a4SDavid Howells u16 serviceId; /* service ID */ 980d12f8a4SDavid Howells } __packed; 990d12f8a4SDavid Howells 1000d12f8a4SDavid Howells /* 10117926a79SDavid Howells * RxRPC socket buffer private variables 10217926a79SDavid Howells * - max 48 bytes (struct sk_buff::cb) 10317926a79SDavid Howells */ 10417926a79SDavid Howells struct rxrpc_skb_priv { 10517926a79SDavid Howells struct rxrpc_call *call; /* call with which associated */ 10617926a79SDavid Howells unsigned long resend_at; /* time in jiffies at which to resend */ 10717926a79SDavid Howells union { 10895c96174SEric Dumazet unsigned int offset; /* offset into buffer of next read */ 10917926a79SDavid Howells int remain; /* amount of space remaining for next write */ 11017926a79SDavid Howells u32 error; /* network error code */ 11117926a79SDavid Howells bool need_resend; /* T if needs resending */ 11217926a79SDavid Howells }; 11317926a79SDavid Howells 1140d12f8a4SDavid Howells struct rxrpc_host_header hdr; /* RxRPC packet header from this packet */ 11517926a79SDavid Howells }; 11617926a79SDavid Howells 11717926a79SDavid Howells #define rxrpc_skb(__skb) ((struct rxrpc_skb_priv *) &(__skb)->cb) 11817926a79SDavid Howells 11917926a79SDavid Howells enum rxrpc_command { 12017926a79SDavid Howells RXRPC_CMD_SEND_DATA, /* send data message */ 12117926a79SDavid Howells RXRPC_CMD_SEND_ABORT, /* request abort generation */ 12217926a79SDavid Howells RXRPC_CMD_ACCEPT, /* [server] accept incoming call */ 12317926a79SDavid Howells RXRPC_CMD_REJECT_BUSY, /* [server] reject a call as busy */ 12417926a79SDavid Howells }; 12517926a79SDavid Howells 12617926a79SDavid Howells /* 12717926a79SDavid Howells * RxRPC security module interface 12817926a79SDavid Howells */ 12917926a79SDavid Howells struct rxrpc_security { 13017926a79SDavid Howells const char *name; /* name of this service */ 13117926a79SDavid Howells u8 security_index; /* security type provided */ 13217926a79SDavid Howells 133648af7fcSDavid Howells /* Initialise a security service */ 134648af7fcSDavid Howells int (*init)(void); 135648af7fcSDavid Howells 136648af7fcSDavid Howells /* Clean up a security service */ 137648af7fcSDavid Howells void (*exit)(void); 138648af7fcSDavid Howells 13917926a79SDavid Howells /* initialise a connection's security */ 14017926a79SDavid Howells int (*init_connection_security)(struct rxrpc_connection *); 14117926a79SDavid Howells 14217926a79SDavid Howells /* prime a connection's packet security */ 143a263629dSHerbert Xu int (*prime_packet_security)(struct rxrpc_connection *); 14417926a79SDavid Howells 14517926a79SDavid Howells /* impose security on a packet */ 146a263629dSHerbert Xu int (*secure_packet)(struct rxrpc_call *, 14717926a79SDavid Howells struct sk_buff *, 14817926a79SDavid Howells size_t, 14917926a79SDavid Howells void *); 15017926a79SDavid Howells 15117926a79SDavid Howells /* verify the security on a received packet */ 152a263629dSHerbert Xu int (*verify_packet)(struct rxrpc_call *, struct sk_buff *, u32 *); 15317926a79SDavid Howells 15417926a79SDavid Howells /* issue a challenge */ 15517926a79SDavid Howells int (*issue_challenge)(struct rxrpc_connection *); 15617926a79SDavid Howells 15717926a79SDavid Howells /* respond to a challenge */ 15817926a79SDavid Howells int (*respond_to_challenge)(struct rxrpc_connection *, 15917926a79SDavid Howells struct sk_buff *, 16017926a79SDavid Howells u32 *); 16117926a79SDavid Howells 16217926a79SDavid Howells /* verify a response */ 16317926a79SDavid Howells int (*verify_response)(struct rxrpc_connection *, 16417926a79SDavid Howells struct sk_buff *, 16517926a79SDavid Howells u32 *); 16617926a79SDavid Howells 16717926a79SDavid Howells /* clear connection security */ 16817926a79SDavid Howells void (*clear)(struct rxrpc_connection *); 16917926a79SDavid Howells }; 17017926a79SDavid Howells 17117926a79SDavid Howells /* 1724f95dd78SDavid Howells * RxRPC local transport endpoint description 1734f95dd78SDavid Howells * - owned by a single AF_RXRPC socket 1744f95dd78SDavid Howells * - pointed to by transport socket struct sk_user_data 17517926a79SDavid Howells */ 17617926a79SDavid Howells struct rxrpc_local { 1774f95dd78SDavid Howells struct rcu_head rcu; 1784f95dd78SDavid Howells atomic_t usage; 1794f95dd78SDavid Howells struct list_head link; 18017926a79SDavid Howells struct socket *socket; /* my UDP socket */ 1814f95dd78SDavid Howells struct work_struct processor; 18217926a79SDavid Howells struct list_head services; /* services listening on this endpoint */ 18317926a79SDavid Howells struct rw_semaphore defrag_sem; /* control re-enablement of IP DF bit */ 18417926a79SDavid Howells struct sk_buff_head accept_queue; /* incoming calls awaiting acceptance */ 18517926a79SDavid Howells struct sk_buff_head reject_queue; /* packets awaiting rejection */ 18644ba0698SDavid Howells struct sk_buff_head event_queue; /* endpoint event packets awaiting processing */ 187999b69f8SDavid Howells struct rb_root client_conns; /* Client connections by socket params */ 188999b69f8SDavid Howells spinlock_t client_conns_lock; /* Lock for client_conns */ 18917926a79SDavid Howells spinlock_t lock; /* access lock */ 19017926a79SDavid Howells rwlock_t services_lock; /* lock for services list */ 19117926a79SDavid Howells int debug_id; /* debug ID for printks */ 1924f95dd78SDavid Howells bool dead; 19317926a79SDavid Howells struct sockaddr_rxrpc srx; /* local address */ 19417926a79SDavid Howells }; 19517926a79SDavid Howells 19617926a79SDavid Howells /* 19717926a79SDavid Howells * RxRPC remote transport endpoint definition 198be6e6707SDavid Howells * - matched by local endpoint, remote port, address and protocol type 19917926a79SDavid Howells */ 20017926a79SDavid Howells struct rxrpc_peer { 201be6e6707SDavid Howells struct rcu_head rcu; /* This must be first */ 202be6e6707SDavid Howells atomic_t usage; 203be6e6707SDavid Howells unsigned long hash_key; 204be6e6707SDavid Howells struct hlist_node hash_link; 205be6e6707SDavid Howells struct rxrpc_local *local; 206f66d7490SDavid Howells struct hlist_head error_targets; /* targets for net error distribution */ 207f66d7490SDavid Howells struct work_struct error_distributor; 208aa390bbeSDavid Howells struct rb_root service_conns; /* Service connections */ 209aa390bbeSDavid Howells rwlock_t conn_lock; 21017926a79SDavid Howells spinlock_t lock; /* access lock */ 21195c96174SEric Dumazet unsigned int if_mtu; /* interface MTU for this peer */ 21295c96174SEric Dumazet unsigned int mtu; /* network MTU for this peer */ 21395c96174SEric Dumazet unsigned int maxdata; /* data size (MTU - hdrsize) */ 21417926a79SDavid Howells unsigned short hdrsize; /* header size (IP + UDP + RxRPC) */ 21517926a79SDavid Howells int debug_id; /* debug ID for printks */ 216f66d7490SDavid Howells int error_report; /* Net (+0) or local (+1000000) to distribute */ 217f66d7490SDavid Howells #define RXRPC_LOCAL_ERROR_OFFSET 1000000 21817926a79SDavid Howells struct sockaddr_rxrpc srx; /* remote address */ 21917926a79SDavid Howells 22017926a79SDavid Howells /* calculated RTT cache */ 22117926a79SDavid Howells #define RXRPC_RTT_CACHE_SIZE 32 22217926a79SDavid Howells suseconds_t rtt; /* current RTT estimate (in uS) */ 22395c96174SEric Dumazet unsigned int rtt_point; /* next entry at which to insert */ 22495c96174SEric Dumazet unsigned int rtt_usage; /* amount of cache actually used */ 22517926a79SDavid Howells suseconds_t rtt_cache[RXRPC_RTT_CACHE_SIZE]; /* calculated RTT cache */ 22617926a79SDavid Howells }; 22717926a79SDavid Howells 22817926a79SDavid Howells /* 22919ffa01cSDavid Howells * Keys for matching a connection. 23019ffa01cSDavid Howells */ 23119ffa01cSDavid Howells struct rxrpc_conn_proto { 23219ffa01cSDavid Howells unsigned long hash_key; 23319ffa01cSDavid Howells struct rxrpc_local *local; /* Representation of local endpoint */ 23419ffa01cSDavid Howells u32 epoch; /* epoch of this connection */ 23519ffa01cSDavid Howells u32 cid; /* connection ID */ 23619ffa01cSDavid Howells u8 in_clientflag; /* RXRPC_CLIENT_INITIATED if we are server */ 23719ffa01cSDavid Howells u8 addr_size; /* Size of the address */ 23819ffa01cSDavid Howells sa_family_t family; /* Transport protocol */ 23919ffa01cSDavid Howells __be16 port; /* Peer UDP/UDP6 port */ 24019ffa01cSDavid Howells union { /* Peer address */ 24119ffa01cSDavid Howells struct in_addr ipv4_addr; 24219ffa01cSDavid Howells struct in6_addr ipv6_addr; 24319ffa01cSDavid Howells u32 raw_addr[0]; 24419ffa01cSDavid Howells }; 24519ffa01cSDavid Howells }; 24619ffa01cSDavid Howells 24719ffa01cSDavid Howells struct rxrpc_conn_parameters { 24819ffa01cSDavid Howells struct rxrpc_local *local; /* Representation of local endpoint */ 24919ffa01cSDavid Howells struct rxrpc_peer *peer; /* Remote endpoint */ 25019ffa01cSDavid Howells struct key *key; /* Security details */ 25119ffa01cSDavid Howells bool exclusive; /* T if conn is exclusive */ 25219ffa01cSDavid Howells u16 service_id; /* Service ID for this connection */ 25319ffa01cSDavid Howells u32 security_level; /* Security level selected */ 25419ffa01cSDavid Howells }; 25519ffa01cSDavid Howells 25619ffa01cSDavid Howells /* 257bba304dbSDavid Howells * Bits in the connection flags. 258bba304dbSDavid Howells */ 259bba304dbSDavid Howells enum rxrpc_conn_flag { 260bba304dbSDavid Howells RXRPC_CONN_HAS_IDR, /* Has a client conn ID assigned */ 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 /* 271bba304dbSDavid Howells * The connection protocol state. 272bba304dbSDavid Howells */ 273bba304dbSDavid Howells enum rxrpc_conn_proto_state { 274bba304dbSDavid Howells RXRPC_CONN_UNUSED, /* Connection not yet attempted */ 275bba304dbSDavid Howells RXRPC_CONN_CLIENT, /* Client connection */ 276bba304dbSDavid Howells RXRPC_CONN_SERVICE_UNSECURED, /* Service unsecured connection */ 277bba304dbSDavid Howells RXRPC_CONN_SERVICE_CHALLENGING, /* Service challenging for security */ 278bba304dbSDavid Howells RXRPC_CONN_SERVICE, /* Service secured connection */ 279bba304dbSDavid Howells RXRPC_CONN_REMOTELY_ABORTED, /* Conn aborted by peer */ 280bba304dbSDavid Howells RXRPC_CONN_LOCALLY_ABORTED, /* Conn aborted locally */ 281bba304dbSDavid Howells RXRPC_CONN_NETWORK_ERROR, /* Conn terminated by network error */ 282bba304dbSDavid Howells RXRPC_CONN__NR_STATES 283bba304dbSDavid Howells }; 284bba304dbSDavid Howells 285bba304dbSDavid Howells /* 28617926a79SDavid Howells * RxRPC connection definition 287aa390bbeSDavid Howells * - matched by { local, peer, epoch, conn_id, direction } 28817926a79SDavid Howells * - each connection can only handle four simultaneous calls 28917926a79SDavid Howells */ 29017926a79SDavid Howells struct rxrpc_connection { 29119ffa01cSDavid Howells struct rxrpc_conn_proto proto; 29219ffa01cSDavid Howells struct rxrpc_conn_parameters params; 29319ffa01cSDavid Howells 294999b69f8SDavid Howells spinlock_t channel_lock; 295a1399f8bSDavid Howells 296a1399f8bSDavid Howells struct rxrpc_channel { 297a1399f8bSDavid Howells struct rxrpc_call __rcu *call; /* Active call */ 298a1399f8bSDavid Howells u32 call_id; /* ID of current call */ 299a1399f8bSDavid Howells u32 call_counter; /* Call ID counter */ 300a1399f8bSDavid Howells u32 last_call; /* ID of last call */ 301a1399f8bSDavid Howells u32 last_result; /* Result of last call (0/abort) */ 302a1399f8bSDavid Howells } channels[RXRPC_MAXCALLS]; 303999b69f8SDavid Howells wait_queue_head_t channel_wq; /* queue to wait for channel to become available */ 304999b69f8SDavid Howells 305dee46364SDavid Howells struct rcu_head rcu; 30617926a79SDavid Howells struct work_struct processor; /* connection event processor */ 307999b69f8SDavid Howells union { 308999b69f8SDavid Howells struct rb_node client_node; /* Node in local->client_conns */ 309aa390bbeSDavid Howells struct rb_node service_node; /* Node in peer->service_conns */ 310999b69f8SDavid Howells }; 31117926a79SDavid Howells struct list_head link; /* link in master connection list */ 31217926a79SDavid Howells struct sk_buff_head rx_queue; /* received conn-level packets */ 313648af7fcSDavid Howells const struct rxrpc_security *security; /* applied security module */ 31417926a79SDavid Howells struct key *server_key; /* security for this service */ 3151afe593bSHerbert Xu struct crypto_skcipher *cipher; /* encryption handle */ 31617926a79SDavid Howells struct rxrpc_crypt csum_iv; /* packet checksum base */ 3174a3388c8SDavid Howells unsigned long flags; 31817926a79SDavid Howells unsigned long events; 319999b69f8SDavid Howells unsigned long put_time; /* Time at which last put */ 32017926a79SDavid Howells spinlock_t state_lock; /* state-change lock */ 32117926a79SDavid Howells atomic_t usage; 322bba304dbSDavid Howells enum rxrpc_conn_proto_state state : 8; /* current state of connection */ 323dc44b3a0SDavid Howells u32 local_abort; /* local abort code */ 324dc44b3a0SDavid Howells u32 remote_abort; /* remote abort code */ 325dc44b3a0SDavid Howells int error; /* local error incurred */ 32617926a79SDavid Howells int debug_id; /* debug ID for printks */ 32717926a79SDavid Howells atomic_t serial; /* packet serial number counter */ 32817926a79SDavid Howells atomic_t hi_serial; /* highest serial number received */ 329999b69f8SDavid Howells atomic_t avail_chans; /* number of channels available */ 33017926a79SDavid Howells u8 size_align; /* data size alignment (for security) */ 33117926a79SDavid Howells u8 header_size; /* rxrpc + security header size */ 33217926a79SDavid Howells u8 security_size; /* security header size */ 33317926a79SDavid Howells u32 security_nonce; /* response re-use preventer */ 33417926a79SDavid Howells u8 security_ix; /* security type */ 33517926a79SDavid Howells u8 out_clientflag; /* RXRPC_CLIENT_INITIATED if we are client */ 33617926a79SDavid Howells }; 33717926a79SDavid Howells 33817926a79SDavid Howells /* 3395b8848d1SDavid Howells * Flags in call->flags. 3405b8848d1SDavid Howells */ 3415b8848d1SDavid Howells enum rxrpc_call_flag { 3425b8848d1SDavid Howells RXRPC_CALL_RELEASED, /* call has been released - no more message to userspace */ 3435b8848d1SDavid Howells RXRPC_CALL_TERMINAL_MSG, /* call has given the socket its final message */ 3445b8848d1SDavid Howells RXRPC_CALL_RCVD_LAST, /* all packets received */ 3455b8848d1SDavid Howells RXRPC_CALL_RUN_RTIMER, /* Tx resend timer started */ 3465b8848d1SDavid Howells RXRPC_CALL_TX_SOFT_ACK, /* sent some soft ACKs */ 3475b8848d1SDavid Howells RXRPC_CALL_PROC_BUSY, /* the processor is busy */ 3485b8848d1SDavid Howells RXRPC_CALL_INIT_ACCEPT, /* acceptance was initiated */ 3495b8848d1SDavid Howells RXRPC_CALL_HAS_USERID, /* has a user ID attached */ 3505b8848d1SDavid Howells RXRPC_CALL_EXPECT_OOS, /* expect out of sequence packets */ 3515b8848d1SDavid Howells }; 3525b8848d1SDavid Howells 3535b8848d1SDavid Howells /* 3545b8848d1SDavid Howells * Events that can be raised on a call. 3555b8848d1SDavid Howells */ 3565b8848d1SDavid Howells enum rxrpc_call_event { 3574c198ad1SDavid Howells RXRPC_CALL_EV_RCVD_ACKALL, /* ACKALL or reply received */ 3584c198ad1SDavid Howells RXRPC_CALL_EV_RCVD_BUSY, /* busy packet received */ 3594c198ad1SDavid Howells RXRPC_CALL_EV_RCVD_ABORT, /* abort packet received */ 3604c198ad1SDavid Howells RXRPC_CALL_EV_RCVD_ERROR, /* network error received */ 3614c198ad1SDavid Howells RXRPC_CALL_EV_ACK_FINAL, /* need to generate final ACK (and release call) */ 3624c198ad1SDavid Howells RXRPC_CALL_EV_ACK, /* need to generate ACK */ 3634c198ad1SDavid Howells RXRPC_CALL_EV_REJECT_BUSY, /* need to generate busy message */ 3644c198ad1SDavid Howells RXRPC_CALL_EV_ABORT, /* need to generate abort */ 3654c198ad1SDavid Howells RXRPC_CALL_EV_CONN_ABORT, /* local connection abort generated */ 3664c198ad1SDavid Howells RXRPC_CALL_EV_RESEND_TIMER, /* Tx resend timer expired */ 3674c198ad1SDavid Howells RXRPC_CALL_EV_RESEND, /* Tx resend required */ 3684c198ad1SDavid Howells RXRPC_CALL_EV_DRAIN_RX_OOS, /* drain the Rx out of sequence queue */ 3694c198ad1SDavid Howells RXRPC_CALL_EV_LIFE_TIMER, /* call's lifetimer ran out */ 3704c198ad1SDavid Howells RXRPC_CALL_EV_ACCEPTED, /* incoming call accepted by userspace app */ 3714c198ad1SDavid Howells RXRPC_CALL_EV_SECURED, /* incoming call's connection is now secure */ 3724c198ad1SDavid Howells RXRPC_CALL_EV_POST_ACCEPT, /* need to post an "accept?" message to the app */ 3734c198ad1SDavid Howells RXRPC_CALL_EV_RELEASE, /* need to release the call's resources */ 3745b8848d1SDavid Howells }; 3755b8848d1SDavid Howells 3765b8848d1SDavid Howells /* 3775b8848d1SDavid Howells * The states that a call can be in. 3785b8848d1SDavid Howells */ 3795b8848d1SDavid Howells enum rxrpc_call_state { 380999b69f8SDavid Howells RXRPC_CALL_UNINITIALISED, 381999b69f8SDavid Howells RXRPC_CALL_CLIENT_AWAIT_CONN, /* - client waiting for connection to become available */ 3825b8848d1SDavid Howells RXRPC_CALL_CLIENT_SEND_REQUEST, /* - client sending request phase */ 3835b8848d1SDavid Howells RXRPC_CALL_CLIENT_AWAIT_REPLY, /* - client awaiting reply */ 3845b8848d1SDavid Howells RXRPC_CALL_CLIENT_RECV_REPLY, /* - client receiving reply phase */ 3855b8848d1SDavid Howells RXRPC_CALL_CLIENT_FINAL_ACK, /* - client sending final ACK phase */ 3865b8848d1SDavid Howells RXRPC_CALL_SERVER_SECURING, /* - server securing request connection */ 3875b8848d1SDavid Howells RXRPC_CALL_SERVER_ACCEPTING, /* - server accepting request */ 3885b8848d1SDavid Howells RXRPC_CALL_SERVER_RECV_REQUEST, /* - server receiving request */ 3895b8848d1SDavid Howells RXRPC_CALL_SERVER_ACK_REQUEST, /* - server pending ACK of request */ 3905b8848d1SDavid Howells RXRPC_CALL_SERVER_SEND_REPLY, /* - server sending reply */ 3915b8848d1SDavid Howells RXRPC_CALL_SERVER_AWAIT_ACK, /* - server awaiting final ACK */ 3925b8848d1SDavid Howells RXRPC_CALL_COMPLETE, /* - call completed */ 3935b8848d1SDavid Howells RXRPC_CALL_SERVER_BUSY, /* - call rejected by busy server */ 3945b8848d1SDavid Howells RXRPC_CALL_REMOTELY_ABORTED, /* - call aborted by peer */ 3955b8848d1SDavid Howells RXRPC_CALL_LOCALLY_ABORTED, /* - call aborted locally on error or close */ 3965b8848d1SDavid Howells RXRPC_CALL_NETWORK_ERROR, /* - call terminated by network error */ 3975b8848d1SDavid Howells RXRPC_CALL_DEAD, /* - call is dead */ 3985b8848d1SDavid Howells NR__RXRPC_CALL_STATES 3995b8848d1SDavid Howells }; 4005b8848d1SDavid Howells 4015b8848d1SDavid Howells /* 40217926a79SDavid Howells * RxRPC call definition 40317926a79SDavid Howells * - matched by { connection, call_id } 40417926a79SDavid Howells */ 40517926a79SDavid Howells struct rxrpc_call { 406dee46364SDavid Howells struct rcu_head rcu; 40717926a79SDavid Howells struct rxrpc_connection *conn; /* connection carrying call */ 40817926a79SDavid Howells struct rxrpc_sock *socket; /* socket responsible */ 40917926a79SDavid Howells struct timer_list lifetimer; /* lifetime remaining on call */ 41017926a79SDavid Howells struct timer_list deadspan; /* reap timer for re-ACK'ing, etc */ 41117926a79SDavid Howells struct timer_list ack_timer; /* ACK generation timer */ 41217926a79SDavid Howells struct timer_list resend_timer; /* Tx resend timer */ 41317926a79SDavid Howells struct work_struct destroyer; /* call destroyer */ 41417926a79SDavid Howells struct work_struct processor; /* packet processor and ACK generator */ 41517926a79SDavid Howells struct list_head link; /* link in master call list */ 416f66d7490SDavid Howells struct hlist_node error_link; /* link in error distribution list */ 41717926a79SDavid Howells struct list_head accept_link; /* calls awaiting acceptance */ 41817926a79SDavid Howells struct rb_node sock_node; /* node in socket call tree */ 41917926a79SDavid Howells struct sk_buff_head rx_queue; /* received packets */ 42017926a79SDavid Howells struct sk_buff_head rx_oos_queue; /* packets received out of sequence */ 42117926a79SDavid Howells struct sk_buff *tx_pending; /* Tx socket buffer being filled */ 42217926a79SDavid Howells wait_queue_head_t tx_waitq; /* wait for Tx window space to become available */ 423a263629dSHerbert Xu __be32 crypto_buf[2]; /* Temporary packet crypto buffer */ 42417926a79SDavid Howells unsigned long user_call_ID; /* user-defined call ID */ 42517926a79SDavid Howells unsigned long creation_jif; /* time of call creation */ 42617926a79SDavid Howells unsigned long flags; 42717926a79SDavid Howells unsigned long events; 42817926a79SDavid Howells spinlock_t lock; 42917926a79SDavid Howells rwlock_t state_lock; /* lock for state transition */ 43017926a79SDavid Howells atomic_t usage; 43117926a79SDavid Howells atomic_t sequence; /* Tx data packet sequence counter */ 432dc44b3a0SDavid Howells u32 local_abort; /* local abort code */ 433dc44b3a0SDavid Howells u32 remote_abort; /* remote abort code */ 434f66d7490SDavid Howells int error_report; /* Network error (ICMP/local transport) */ 435f66d7490SDavid Howells int error; /* Local error incurred */ 4365b8848d1SDavid Howells enum rxrpc_call_state state : 8; /* current state of call */ 43717926a79SDavid Howells int debug_id; /* debug ID for printks */ 43817926a79SDavid Howells u8 channel; /* connection channel occupied by this call */ 43917926a79SDavid Howells 44017926a79SDavid Howells /* transmission-phase ACK management */ 4414e36a95eSDavid Howells u8 acks_head; /* offset into window of first entry */ 4424e36a95eSDavid Howells u8 acks_tail; /* offset into window of last entry */ 4434e36a95eSDavid Howells u8 acks_winsz; /* size of un-ACK'd window */ 4444e36a95eSDavid Howells u8 acks_unacked; /* lowest unacked packet in last ACK received */ 44517926a79SDavid Howells int acks_latest; /* serial number of latest ACK received */ 44617926a79SDavid Howells rxrpc_seq_t acks_hard; /* highest definitively ACK'd msg seq */ 44717926a79SDavid Howells unsigned long *acks_window; /* sent packet window 44817926a79SDavid Howells * - elements are pointers with LSB set if ACK'd 44917926a79SDavid Howells */ 45017926a79SDavid Howells 45117926a79SDavid Howells /* receive-phase ACK management */ 45217926a79SDavid Howells rxrpc_seq_t rx_data_expect; /* next data seq ID expected to be received */ 45317926a79SDavid Howells rxrpc_seq_t rx_data_post; /* next data seq ID expected to be posted */ 45417926a79SDavid Howells rxrpc_seq_t rx_data_recv; /* last data seq ID encountered by recvmsg */ 45517926a79SDavid Howells rxrpc_seq_t rx_data_eaten; /* last data seq ID consumed by recvmsg */ 45617926a79SDavid Howells rxrpc_seq_t rx_first_oos; /* first packet in rx_oos_queue (or 0) */ 45717926a79SDavid Howells rxrpc_seq_t ackr_win_top; /* top of ACK window (rx_data_eaten is bottom) */ 4580d12f8a4SDavid Howells rxrpc_seq_t ackr_prev_seq; /* previous sequence number received */ 4594e36a95eSDavid Howells u8 ackr_reason; /* reason to ACK */ 4600d12f8a4SDavid Howells rxrpc_serial_t ackr_serial; /* serial of packet being ACK'd */ 46117926a79SDavid Howells atomic_t ackr_not_idle; /* number of packets in Rx queue */ 46217926a79SDavid Howells 46317926a79SDavid Howells /* received packet records, 1 bit per record */ 46417926a79SDavid Howells #define RXRPC_ACKR_WINDOW_ASZ DIV_ROUND_UP(RXRPC_MAXACKS, BITS_PER_LONG) 46517926a79SDavid Howells unsigned long ackr_window[RXRPC_ACKR_WINDOW_ASZ + 1]; 46617926a79SDavid Howells 4677727640cSTim Smith struct hlist_node hash_node; 4687727640cSTim Smith unsigned long hash_key; /* Full hash key */ 4697727640cSTim Smith u8 in_clientflag; /* Copy of conn->in_clientflag for hashing */ 4707727640cSTim Smith struct rxrpc_local *local; /* Local endpoint. Used for hashing. */ 47119ffa01cSDavid Howells sa_family_t family; /* Frame protocol */ 4720d12f8a4SDavid Howells u32 call_id; /* call ID on connection */ 4730d12f8a4SDavid Howells u32 cid; /* connection ID plus channel index */ 4740d12f8a4SDavid Howells u32 epoch; /* epoch of this connection */ 4750d12f8a4SDavid Howells u16 service_id; /* service ID */ 4767727640cSTim Smith union { /* Peer IP address for hashing */ 4777727640cSTim Smith __be32 ipv4_addr; 4787727640cSTim Smith __u8 ipv6_addr[16]; /* Anticipates eventual IPv6 support */ 4797727640cSTim Smith } peer_ip; 48017926a79SDavid Howells }; 48117926a79SDavid Howells 48217926a79SDavid Howells /* 48317926a79SDavid Howells * locally abort an RxRPC call 48417926a79SDavid Howells */ 48517926a79SDavid Howells static inline void rxrpc_abort_call(struct rxrpc_call *call, u32 abort_code) 48617926a79SDavid Howells { 48717926a79SDavid Howells write_lock_bh(&call->state_lock); 48817926a79SDavid Howells if (call->state < RXRPC_CALL_COMPLETE) { 489dc44b3a0SDavid Howells call->local_abort = abort_code; 49017926a79SDavid Howells call->state = RXRPC_CALL_LOCALLY_ABORTED; 4914c198ad1SDavid Howells set_bit(RXRPC_CALL_EV_ABORT, &call->events); 49217926a79SDavid Howells } 49317926a79SDavid Howells write_unlock_bh(&call->state_lock); 49417926a79SDavid Howells } 49517926a79SDavid Howells 49617926a79SDavid Howells /* 497651350d1SDavid Howells * af_rxrpc.c 49817926a79SDavid Howells */ 499651350d1SDavid Howells extern atomic_t rxrpc_n_skbs; 5000d12f8a4SDavid Howells extern u32 rxrpc_epoch; 501651350d1SDavid Howells extern atomic_t rxrpc_debug_id; 502651350d1SDavid Howells extern struct workqueue_struct *rxrpc_workqueue; 50317926a79SDavid Howells 50417926a79SDavid Howells /* 5050d81a51aSDavid Howells * call_accept.c 50617926a79SDavid Howells */ 5074f95dd78SDavid Howells void rxrpc_accept_incoming_calls(struct rxrpc_local *); 508c1b1203dSJoe Perches struct rxrpc_call *rxrpc_accept_call(struct rxrpc_sock *, unsigned long); 509c1b1203dSJoe Perches int rxrpc_reject_call(struct rxrpc_sock *); 51017926a79SDavid Howells 51117926a79SDavid Howells /* 5120d81a51aSDavid Howells * call_event.c 51317926a79SDavid Howells */ 5140d12f8a4SDavid Howells void __rxrpc_propose_ACK(struct rxrpc_call *, u8, u32, bool); 5150d12f8a4SDavid Howells void rxrpc_propose_ACK(struct rxrpc_call *, u8, u32, bool); 516c1b1203dSJoe Perches void rxrpc_process_call(struct work_struct *); 51717926a79SDavid Howells 51817926a79SDavid Howells /* 5190d81a51aSDavid Howells * call_object.c 52017926a79SDavid Howells */ 521dad8aff7SDavid Howells extern unsigned int rxrpc_max_call_lifetime; 522dad8aff7SDavid Howells extern unsigned int rxrpc_dead_call_expiry; 52317926a79SDavid Howells extern struct kmem_cache *rxrpc_call_jar; 52417926a79SDavid Howells extern struct list_head rxrpc_calls; 52517926a79SDavid Howells extern rwlock_t rxrpc_call_lock; 52617926a79SDavid Howells 5270d12f8a4SDavid Howells struct rxrpc_call *rxrpc_find_call_hash(struct rxrpc_host_header *, 5280d12f8a4SDavid Howells void *, sa_family_t, const void *); 5292341e077SDavid Howells struct rxrpc_call *rxrpc_find_call_by_user_ID(struct rxrpc_sock *, unsigned long); 5302341e077SDavid Howells struct rxrpc_call *rxrpc_new_client_call(struct rxrpc_sock *, 53119ffa01cSDavid Howells struct rxrpc_conn_parameters *, 532999b69f8SDavid Howells struct sockaddr_rxrpc *, 5332341e077SDavid Howells unsigned long, gfp_t); 534c1b1203dSJoe Perches struct rxrpc_call *rxrpc_incoming_call(struct rxrpc_sock *, 53517926a79SDavid Howells struct rxrpc_connection *, 53642886ffeSDavid Howells struct sk_buff *); 537c1b1203dSJoe Perches void rxrpc_release_call(struct rxrpc_call *); 538c1b1203dSJoe Perches void rxrpc_release_calls_on_socket(struct rxrpc_sock *); 539c1b1203dSJoe Perches void __rxrpc_put_call(struct rxrpc_call *); 540c1b1203dSJoe Perches void __exit rxrpc_destroy_all_calls(void); 54117926a79SDavid Howells 54217926a79SDavid Howells /* 5434a3388c8SDavid Howells * conn_client.c 5444a3388c8SDavid Howells */ 5454a3388c8SDavid Howells extern struct idr rxrpc_client_conn_ids; 5464a3388c8SDavid Howells 5474a3388c8SDavid Howells void rxrpc_put_client_connection_id(struct rxrpc_connection *); 548eb9b9d22SDavid Howells void rxrpc_destroy_client_conn_ids(void); 549c6d2b8d7SDavid Howells int rxrpc_connect_call(struct rxrpc_call *, struct rxrpc_conn_parameters *, 550c6d2b8d7SDavid Howells struct sockaddr_rxrpc *, gfp_t); 5514a3388c8SDavid Howells 5524a3388c8SDavid Howells /* 5530d81a51aSDavid Howells * conn_event.c 5540d81a51aSDavid Howells */ 5550d81a51aSDavid Howells void rxrpc_process_connection(struct work_struct *); 5560d81a51aSDavid Howells void rxrpc_reject_packet(struct rxrpc_local *, struct sk_buff *); 5574f95dd78SDavid Howells void rxrpc_reject_packets(struct rxrpc_local *); 5580d81a51aSDavid Howells 5590d81a51aSDavid Howells /* 5600d81a51aSDavid Howells * conn_object.c 56117926a79SDavid Howells */ 562dad8aff7SDavid Howells extern unsigned int rxrpc_connection_expiry; 56317926a79SDavid Howells extern struct list_head rxrpc_connections; 56417926a79SDavid Howells extern rwlock_t rxrpc_connection_lock; 56517926a79SDavid Howells 5667877a4a4SDavid Howells void rxrpc_conn_hash_proto_key(struct rxrpc_conn_proto *); 5677877a4a4SDavid Howells void rxrpc_extract_conn_params(struct rxrpc_conn_proto *, 5687877a4a4SDavid Howells struct rxrpc_local *, struct sk_buff *); 569c6d2b8d7SDavid Howells struct rxrpc_connection *rxrpc_alloc_connection(gfp_t); 570aa390bbeSDavid Howells struct rxrpc_connection *rxrpc_find_connection(struct rxrpc_local *, 571aa390bbeSDavid Howells struct rxrpc_peer *, 572aa390bbeSDavid Howells struct sk_buff *); 573a1399f8bSDavid Howells void __rxrpc_disconnect_call(struct rxrpc_call *); 574999b69f8SDavid Howells void rxrpc_disconnect_call(struct rxrpc_call *); 575c1b1203dSJoe Perches void rxrpc_put_connection(struct rxrpc_connection *); 576c1b1203dSJoe Perches void __exit rxrpc_destroy_all_connections(void); 57717926a79SDavid Howells 57819ffa01cSDavid Howells static inline bool rxrpc_conn_is_client(const struct rxrpc_connection *conn) 57919ffa01cSDavid Howells { 58019ffa01cSDavid Howells return conn->out_clientflag; 58119ffa01cSDavid Howells } 58219ffa01cSDavid Howells 58319ffa01cSDavid Howells static inline bool rxrpc_conn_is_service(const struct rxrpc_connection *conn) 58419ffa01cSDavid Howells { 58519ffa01cSDavid Howells return conn->proto.in_clientflag; 58619ffa01cSDavid Howells } 58719ffa01cSDavid Howells 5885627cc8bSDavid Howells static inline void rxrpc_get_connection(struct rxrpc_connection *conn) 5895627cc8bSDavid Howells { 5905627cc8bSDavid Howells atomic_inc(&conn->usage); 5915627cc8bSDavid Howells } 5925627cc8bSDavid Howells 5932c4579e4SDavid Howells static inline 5942c4579e4SDavid Howells struct rxrpc_connection *rxrpc_get_connection_maybe(struct rxrpc_connection *conn) 5952c4579e4SDavid Howells { 5962c4579e4SDavid Howells return atomic_inc_not_zero(&conn->usage) ? conn : NULL; 5972c4579e4SDavid Howells } 5985acbee46SDavid Howells 5995acbee46SDavid Howells static inline void rxrpc_queue_conn(struct rxrpc_connection *conn) 6005acbee46SDavid Howells { 6012c4579e4SDavid Howells if (rxrpc_get_connection_maybe(conn) && 6022c4579e4SDavid Howells !rxrpc_queue_work(&conn->processor)) 6032c4579e4SDavid Howells rxrpc_put_connection(conn); 6045acbee46SDavid Howells } 6055acbee46SDavid Howells 60617926a79SDavid Howells /* 6077877a4a4SDavid Howells * conn_service.c 6087877a4a4SDavid Howells */ 6097877a4a4SDavid Howells struct rxrpc_connection *rxrpc_incoming_connection(struct rxrpc_local *, 6107877a4a4SDavid Howells struct rxrpc_peer *, 6117877a4a4SDavid Howells struct sk_buff *); 6127877a4a4SDavid Howells 6137877a4a4SDavid Howells /* 6140d81a51aSDavid Howells * input.c 61517926a79SDavid Howells */ 616676d2369SDavid S. Miller void rxrpc_data_ready(struct sock *); 617c1b1203dSJoe Perches int rxrpc_queue_rcv_skb(struct rxrpc_call *, struct sk_buff *, bool, bool); 618c1b1203dSJoe Perches void rxrpc_fast_process_packet(struct rxrpc_call *, struct sk_buff *); 61917926a79SDavid Howells 62017926a79SDavid Howells /* 6210d81a51aSDavid Howells * insecure.c 62217926a79SDavid Howells */ 6230d81a51aSDavid Howells extern const struct rxrpc_security rxrpc_no_security; 62417926a79SDavid Howells 62517926a79SDavid Howells /* 6260d81a51aSDavid Howells * key.c 62717926a79SDavid Howells */ 62817926a79SDavid Howells extern struct key_type key_type_rxrpc; 62917926a79SDavid Howells extern struct key_type key_type_rxrpc_s; 63017926a79SDavid Howells 631c1b1203dSJoe Perches int rxrpc_request_key(struct rxrpc_sock *, char __user *, int); 632c1b1203dSJoe Perches int rxrpc_server_keyring(struct rxrpc_sock *, char __user *, int); 633c1b1203dSJoe Perches int rxrpc_get_server_data_key(struct rxrpc_connection *, const void *, time_t, 634c1b1203dSJoe Perches u32); 63517926a79SDavid Howells 63617926a79SDavid Howells /* 63787563616SDavid Howells * local_event.c 63887563616SDavid Howells */ 6394f95dd78SDavid Howells extern void rxrpc_process_local_events(struct rxrpc_local *); 64087563616SDavid Howells 64187563616SDavid Howells /* 6420d81a51aSDavid Howells * local_object.c 64317926a79SDavid Howells */ 6444f95dd78SDavid Howells struct rxrpc_local *rxrpc_lookup_local(const struct sockaddr_rxrpc *); 6454f95dd78SDavid Howells void __rxrpc_put_local(struct rxrpc_local *); 6460d81a51aSDavid Howells void __exit rxrpc_destroy_all_locals(void); 647e0e4d82fSDavid Howells 6484f95dd78SDavid Howells static inline void rxrpc_get_local(struct rxrpc_local *local) 6494f95dd78SDavid Howells { 6504f95dd78SDavid Howells atomic_inc(&local->usage); 6514f95dd78SDavid Howells } 6524f95dd78SDavid Howells 6534f95dd78SDavid Howells static inline 6544f95dd78SDavid Howells struct rxrpc_local *rxrpc_get_local_maybe(struct rxrpc_local *local) 6554f95dd78SDavid Howells { 6564f95dd78SDavid Howells return atomic_inc_not_zero(&local->usage) ? local : NULL; 6574f95dd78SDavid Howells } 6584f95dd78SDavid Howells 6594f95dd78SDavid Howells static inline void rxrpc_put_local(struct rxrpc_local *local) 6604f95dd78SDavid Howells { 6615627cc8bSDavid Howells if (local && atomic_dec_and_test(&local->usage)) 6624f95dd78SDavid Howells __rxrpc_put_local(local); 6634f95dd78SDavid Howells } 6644f95dd78SDavid Howells 6655acbee46SDavid Howells static inline void rxrpc_queue_local(struct rxrpc_local *local) 6665acbee46SDavid Howells { 6675acbee46SDavid Howells rxrpc_queue_work(&local->processor); 6685acbee46SDavid Howells } 6695acbee46SDavid Howells 670e0e4d82fSDavid Howells /* 6718e688d9cSDavid Howells * misc.c 6728e688d9cSDavid Howells */ 6730e119b41SDavid Howells extern unsigned int rxrpc_max_backlog __read_mostly; 6748e688d9cSDavid Howells extern unsigned int rxrpc_requested_ack_delay; 6758e688d9cSDavid Howells extern unsigned int rxrpc_soft_ack_delay; 6768e688d9cSDavid Howells extern unsigned int rxrpc_idle_ack_delay; 6778e688d9cSDavid Howells extern unsigned int rxrpc_rx_window_size; 6788e688d9cSDavid Howells extern unsigned int rxrpc_rx_mtu; 6798e688d9cSDavid Howells extern unsigned int rxrpc_rx_jumbo_max; 6808e688d9cSDavid Howells 6815b3e87f1SDavid Howells extern const char *const rxrpc_pkts[]; 6828e688d9cSDavid Howells extern const s8 rxrpc_ack_priority[]; 6838e688d9cSDavid Howells 6848e688d9cSDavid Howells extern const char *rxrpc_acks(u8 reason); 6858e688d9cSDavid Howells 6868e688d9cSDavid Howells /* 6870d81a51aSDavid Howells * output.c 6880d81a51aSDavid Howells */ 6890d81a51aSDavid Howells extern unsigned int rxrpc_resend_timeout; 6900d81a51aSDavid Howells 691985a5c82SDavid Howells int rxrpc_send_data_packet(struct rxrpc_connection *, struct sk_buff *); 6920d81a51aSDavid Howells int rxrpc_do_sendmsg(struct rxrpc_sock *, struct msghdr *, size_t); 6930d81a51aSDavid Howells 6940d81a51aSDavid Howells /* 695abe89ef0SDavid Howells * peer_event.c 6960d81a51aSDavid Howells */ 697abe89ef0SDavid Howells void rxrpc_error_report(struct sock *); 698f66d7490SDavid Howells void rxrpc_peer_error_distributor(struct work_struct *); 6990d81a51aSDavid Howells 7000d81a51aSDavid Howells /* 7010d81a51aSDavid Howells * peer_object.c 7020d81a51aSDavid Howells */ 703be6e6707SDavid Howells struct rxrpc_peer *rxrpc_lookup_peer_rcu(struct rxrpc_local *, 704be6e6707SDavid Howells const struct sockaddr_rxrpc *); 705be6e6707SDavid Howells struct rxrpc_peer *rxrpc_lookup_peer(struct rxrpc_local *, 706be6e6707SDavid Howells struct sockaddr_rxrpc *, gfp_t); 707be6e6707SDavid Howells struct rxrpc_peer *rxrpc_alloc_peer(struct rxrpc_local *, gfp_t); 708be6e6707SDavid Howells 709be6e6707SDavid Howells static inline void rxrpc_get_peer(struct rxrpc_peer *peer) 710be6e6707SDavid Howells { 711be6e6707SDavid Howells atomic_inc(&peer->usage); 712be6e6707SDavid Howells } 713be6e6707SDavid Howells 714be6e6707SDavid Howells static inline 715be6e6707SDavid Howells struct rxrpc_peer *rxrpc_get_peer_maybe(struct rxrpc_peer *peer) 716be6e6707SDavid Howells { 717be6e6707SDavid Howells return atomic_inc_not_zero(&peer->usage) ? peer : NULL; 718be6e6707SDavid Howells } 719be6e6707SDavid Howells 720be6e6707SDavid Howells extern void __rxrpc_put_peer(struct rxrpc_peer *peer); 721be6e6707SDavid Howells static inline void rxrpc_put_peer(struct rxrpc_peer *peer) 722be6e6707SDavid Howells { 7235627cc8bSDavid Howells if (peer && atomic_dec_and_test(&peer->usage)) 724be6e6707SDavid Howells __rxrpc_put_peer(peer); 725be6e6707SDavid Howells } 7260d81a51aSDavid Howells 7270d81a51aSDavid Howells /* 7280d81a51aSDavid Howells * proc.c 7290d81a51aSDavid Howells */ 7300d81a51aSDavid Howells extern const char *const rxrpc_call_states[]; 7310d81a51aSDavid Howells extern const struct file_operations rxrpc_call_seq_fops; 7320d81a51aSDavid Howells extern const struct file_operations rxrpc_connection_seq_fops; 7330d81a51aSDavid Howells 7340d81a51aSDavid Howells /* 7350d81a51aSDavid Howells * recvmsg.c 7360d81a51aSDavid Howells */ 7370d81a51aSDavid Howells void rxrpc_remove_user_ID(struct rxrpc_sock *, struct rxrpc_call *); 7380d81a51aSDavid Howells int rxrpc_recvmsg(struct socket *, struct msghdr *, size_t, int); 7390d81a51aSDavid Howells 7400d81a51aSDavid Howells /* 741648af7fcSDavid Howells * rxkad.c 742648af7fcSDavid Howells */ 743648af7fcSDavid Howells #ifdef CONFIG_RXKAD 744648af7fcSDavid Howells extern const struct rxrpc_security rxkad; 745648af7fcSDavid Howells #endif 746648af7fcSDavid Howells 747648af7fcSDavid Howells /* 7480d81a51aSDavid Howells * security.c 7490d81a51aSDavid Howells */ 7500d81a51aSDavid Howells int __init rxrpc_init_security(void); 7510d81a51aSDavid Howells void rxrpc_exit_security(void); 7520d81a51aSDavid Howells int rxrpc_init_client_conn_security(struct rxrpc_connection *); 7530d81a51aSDavid Howells int rxrpc_init_server_conn_security(struct rxrpc_connection *); 7540d81a51aSDavid Howells 7550d81a51aSDavid Howells /* 7560d81a51aSDavid Howells * skbuff.c 7570d81a51aSDavid Howells */ 7580d81a51aSDavid Howells void rxrpc_packet_destructor(struct sk_buff *); 7590d81a51aSDavid Howells 7600d81a51aSDavid Howells /* 7615873c083SDavid Howells * sysctl.c 7625873c083SDavid Howells */ 7635873c083SDavid Howells #ifdef CONFIG_SYSCTL 7645873c083SDavid Howells extern int __init rxrpc_sysctl_init(void); 7655873c083SDavid Howells extern void rxrpc_sysctl_exit(void); 7665873c083SDavid Howells #else 7675873c083SDavid Howells static inline int __init rxrpc_sysctl_init(void) { return 0; } 7685873c083SDavid Howells static inline void rxrpc_sysctl_exit(void) {} 7695873c083SDavid Howells #endif 7705873c083SDavid Howells 7715873c083SDavid Howells /* 772be6e6707SDavid Howells * utils.c 773be6e6707SDavid Howells */ 774be6e6707SDavid Howells void rxrpc_get_addr_from_skb(struct rxrpc_local *, const struct sk_buff *, 775be6e6707SDavid Howells struct sockaddr_rxrpc *); 776be6e6707SDavid Howells 777be6e6707SDavid Howells /* 77817926a79SDavid Howells * debug tracing 77917926a79SDavid Howells */ 78095c96174SEric Dumazet extern unsigned int rxrpc_debug; 78117926a79SDavid Howells 78217926a79SDavid Howells #define dbgprintk(FMT,...) \ 7839f389f4bSSven Schnelle printk("[%-6.6s] "FMT"\n", current->comm ,##__VA_ARGS__) 78417926a79SDavid Howells 7850dc47877SHarvey Harrison #define kenter(FMT,...) dbgprintk("==> %s("FMT")",__func__ ,##__VA_ARGS__) 7860dc47877SHarvey Harrison #define kleave(FMT,...) dbgprintk("<== %s()"FMT"",__func__ ,##__VA_ARGS__) 78717926a79SDavid Howells #define kdebug(FMT,...) dbgprintk(" "FMT ,##__VA_ARGS__) 78817926a79SDavid Howells #define kproto(FMT,...) dbgprintk("### "FMT ,##__VA_ARGS__) 78917926a79SDavid Howells #define knet(FMT,...) dbgprintk("@@@ "FMT ,##__VA_ARGS__) 79017926a79SDavid Howells 79117926a79SDavid Howells 79217926a79SDavid Howells #if defined(__KDEBUG) 79317926a79SDavid Howells #define _enter(FMT,...) kenter(FMT,##__VA_ARGS__) 79417926a79SDavid Howells #define _leave(FMT,...) kleave(FMT,##__VA_ARGS__) 79517926a79SDavid Howells #define _debug(FMT,...) kdebug(FMT,##__VA_ARGS__) 79617926a79SDavid Howells #define _proto(FMT,...) kproto(FMT,##__VA_ARGS__) 79717926a79SDavid Howells #define _net(FMT,...) knet(FMT,##__VA_ARGS__) 79817926a79SDavid Howells 79917926a79SDavid Howells #elif defined(CONFIG_AF_RXRPC_DEBUG) 80017926a79SDavid Howells #define RXRPC_DEBUG_KENTER 0x01 80117926a79SDavid Howells #define RXRPC_DEBUG_KLEAVE 0x02 80217926a79SDavid Howells #define RXRPC_DEBUG_KDEBUG 0x04 80317926a79SDavid Howells #define RXRPC_DEBUG_KPROTO 0x08 80417926a79SDavid Howells #define RXRPC_DEBUG_KNET 0x10 80517926a79SDavid Howells 80617926a79SDavid Howells #define _enter(FMT,...) \ 80717926a79SDavid Howells do { \ 80817926a79SDavid Howells if (unlikely(rxrpc_debug & RXRPC_DEBUG_KENTER)) \ 80917926a79SDavid Howells kenter(FMT,##__VA_ARGS__); \ 81017926a79SDavid Howells } while (0) 81117926a79SDavid Howells 81217926a79SDavid Howells #define _leave(FMT,...) \ 81317926a79SDavid Howells do { \ 81417926a79SDavid Howells if (unlikely(rxrpc_debug & RXRPC_DEBUG_KLEAVE)) \ 81517926a79SDavid Howells kleave(FMT,##__VA_ARGS__); \ 81617926a79SDavid Howells } while (0) 81717926a79SDavid Howells 81817926a79SDavid Howells #define _debug(FMT,...) \ 81917926a79SDavid Howells do { \ 82017926a79SDavid Howells if (unlikely(rxrpc_debug & RXRPC_DEBUG_KDEBUG)) \ 82117926a79SDavid Howells kdebug(FMT,##__VA_ARGS__); \ 82217926a79SDavid Howells } while (0) 82317926a79SDavid Howells 82417926a79SDavid Howells #define _proto(FMT,...) \ 82517926a79SDavid Howells do { \ 82617926a79SDavid Howells if (unlikely(rxrpc_debug & RXRPC_DEBUG_KPROTO)) \ 82717926a79SDavid Howells kproto(FMT,##__VA_ARGS__); \ 82817926a79SDavid Howells } while (0) 82917926a79SDavid Howells 83017926a79SDavid Howells #define _net(FMT,...) \ 83117926a79SDavid Howells do { \ 83217926a79SDavid Howells if (unlikely(rxrpc_debug & RXRPC_DEBUG_KNET)) \ 83317926a79SDavid Howells knet(FMT,##__VA_ARGS__); \ 83417926a79SDavid Howells } while (0) 83517926a79SDavid Howells 83617926a79SDavid Howells #else 83712fdff3fSDavid Howells #define _enter(FMT,...) no_printk("==> %s("FMT")",__func__ ,##__VA_ARGS__) 83812fdff3fSDavid Howells #define _leave(FMT,...) no_printk("<== %s()"FMT"",__func__ ,##__VA_ARGS__) 83912fdff3fSDavid Howells #define _debug(FMT,...) no_printk(" "FMT ,##__VA_ARGS__) 84012fdff3fSDavid Howells #define _proto(FMT,...) no_printk("### "FMT ,##__VA_ARGS__) 84112fdff3fSDavid Howells #define _net(FMT,...) no_printk("@@@ "FMT ,##__VA_ARGS__) 84217926a79SDavid Howells #endif 84317926a79SDavid Howells 84417926a79SDavid Howells /* 84517926a79SDavid Howells * debug assertion checking 84617926a79SDavid Howells */ 84717926a79SDavid Howells #if 1 // defined(__KDEBUGALL) 84817926a79SDavid Howells 84917926a79SDavid Howells #define ASSERT(X) \ 85017926a79SDavid Howells do { \ 85117926a79SDavid Howells if (unlikely(!(X))) { \ 8529b6d5398SJoe Perches pr_err("Assertion failed\n"); \ 85317926a79SDavid Howells BUG(); \ 85417926a79SDavid Howells } \ 85517926a79SDavid Howells } while (0) 85617926a79SDavid Howells 85717926a79SDavid Howells #define ASSERTCMP(X, OP, Y) \ 85817926a79SDavid Howells do { \ 8599b6d5398SJoe Perches unsigned long _x = (unsigned long)(X); \ 8609b6d5398SJoe Perches unsigned long _y = (unsigned long)(Y); \ 8619b6d5398SJoe Perches if (unlikely(!(_x OP _y))) { \ 8629b6d5398SJoe Perches pr_err("Assertion failed - %lu(0x%lx) %s %lu(0x%lx) is false\n", \ 8639b6d5398SJoe Perches _x, _x, #OP, _y, _y); \ 86417926a79SDavid Howells BUG(); \ 86517926a79SDavid Howells } \ 86617926a79SDavid Howells } while (0) 86717926a79SDavid Howells 86817926a79SDavid Howells #define ASSERTIF(C, X) \ 86917926a79SDavid Howells do { \ 87017926a79SDavid Howells if (unlikely((C) && !(X))) { \ 8719b6d5398SJoe Perches pr_err("Assertion failed\n"); \ 87217926a79SDavid Howells BUG(); \ 87317926a79SDavid Howells } \ 87417926a79SDavid Howells } while (0) 87517926a79SDavid Howells 87617926a79SDavid Howells #define ASSERTIFCMP(C, X, OP, Y) \ 87717926a79SDavid Howells do { \ 8789b6d5398SJoe Perches unsigned long _x = (unsigned long)(X); \ 8799b6d5398SJoe Perches unsigned long _y = (unsigned long)(Y); \ 8809b6d5398SJoe Perches if (unlikely((C) && !(_x OP _y))) { \ 8819b6d5398SJoe Perches pr_err("Assertion failed - %lu(0x%lx) %s %lu(0x%lx) is false\n", \ 8829b6d5398SJoe Perches _x, _x, #OP, _y, _y); \ 88317926a79SDavid Howells BUG(); \ 88417926a79SDavid Howells } \ 88517926a79SDavid Howells } while (0) 88617926a79SDavid Howells 88717926a79SDavid Howells #else 88817926a79SDavid Howells 88917926a79SDavid Howells #define ASSERT(X) \ 89017926a79SDavid Howells do { \ 89117926a79SDavid Howells } while (0) 89217926a79SDavid Howells 89317926a79SDavid Howells #define ASSERTCMP(X, OP, Y) \ 89417926a79SDavid Howells do { \ 89517926a79SDavid Howells } while (0) 89617926a79SDavid Howells 89717926a79SDavid Howells #define ASSERTIF(C, X) \ 89817926a79SDavid Howells do { \ 89917926a79SDavid Howells } while (0) 90017926a79SDavid Howells 90117926a79SDavid Howells #define ASSERTIFCMP(C, X, OP, Y) \ 90217926a79SDavid Howells do { \ 90317926a79SDavid Howells } while (0) 90417926a79SDavid Howells 90517926a79SDavid Howells #endif /* __KDEBUGALL */ 90617926a79SDavid Howells 90717926a79SDavid Howells /* 90817926a79SDavid Howells * socket buffer accounting / leak finding 90917926a79SDavid Howells */ 91017926a79SDavid Howells static inline void __rxrpc_new_skb(struct sk_buff *skb, const char *fn) 91117926a79SDavid Howells { 91217926a79SDavid Howells //_net("new skb %p %s [%d]", skb, fn, atomic_read(&rxrpc_n_skbs)); 91317926a79SDavid Howells //atomic_inc(&rxrpc_n_skbs); 91417926a79SDavid Howells } 91517926a79SDavid Howells 91617926a79SDavid Howells #define rxrpc_new_skb(skb) __rxrpc_new_skb((skb), __func__) 91717926a79SDavid Howells 91817926a79SDavid Howells static inline void __rxrpc_kill_skb(struct sk_buff *skb, const char *fn) 91917926a79SDavid Howells { 92017926a79SDavid Howells //_net("kill skb %p %s [%d]", skb, fn, atomic_read(&rxrpc_n_skbs)); 92117926a79SDavid Howells //atomic_dec(&rxrpc_n_skbs); 92217926a79SDavid Howells } 92317926a79SDavid Howells 92417926a79SDavid Howells #define rxrpc_kill_skb(skb) __rxrpc_kill_skb((skb), __func__) 92517926a79SDavid Howells 92617926a79SDavid Howells static inline void __rxrpc_free_skb(struct sk_buff *skb, const char *fn) 92717926a79SDavid Howells { 92817926a79SDavid Howells if (skb) { 92917926a79SDavid Howells CHECK_SLAB_OKAY(&skb->users); 93017926a79SDavid Howells //_net("free skb %p %s [%d]", 93117926a79SDavid Howells // skb, fn, atomic_read(&rxrpc_n_skbs)); 93217926a79SDavid Howells //atomic_dec(&rxrpc_n_skbs); 93317926a79SDavid Howells kfree_skb(skb); 93417926a79SDavid Howells } 93517926a79SDavid Howells } 93617926a79SDavid Howells 93717926a79SDavid Howells #define rxrpc_free_skb(skb) __rxrpc_free_skb((skb), __func__) 93817926a79SDavid Howells 93917926a79SDavid Howells static inline void rxrpc_purge_queue(struct sk_buff_head *list) 94017926a79SDavid Howells { 94117926a79SDavid Howells struct sk_buff *skb; 94217926a79SDavid Howells while ((skb = skb_dequeue((list))) != NULL) 94317926a79SDavid Howells rxrpc_free_skb(skb); 94417926a79SDavid Howells } 94517926a79SDavid Howells 94617926a79SDavid Howells #define rxrpc_get_call(CALL) \ 94717926a79SDavid Howells do { \ 94817926a79SDavid Howells CHECK_SLAB_OKAY(&(CALL)->usage); \ 94917926a79SDavid Howells if (atomic_inc_return(&(CALL)->usage) == 1) \ 95017926a79SDavid Howells BUG(); \ 95117926a79SDavid Howells } while (0) 95217926a79SDavid Howells 95317926a79SDavid Howells #define rxrpc_put_call(CALL) \ 95417926a79SDavid Howells do { \ 95517926a79SDavid Howells __rxrpc_put_call(CALL); \ 95617926a79SDavid Howells } while (0) 957