ar-internal.h 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946
  1. /* AF_RXRPC internal definitions
  2. *
  3. * Copyright (C) 2007 Red Hat, Inc. All Rights Reserved.
  4. * Written by David Howells (dhowells@redhat.com)
  5. *
  6. * This program is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU General Public License
  8. * as published by the Free Software Foundation; either version
  9. * 2 of the License, or (at your option) any later version.
  10. */
  11. #include <linux/atomic.h>
  12. #include <linux/seqlock.h>
  13. #include <net/sock.h>
  14. #include <net/af_rxrpc.h>
  15. #include <rxrpc/packet.h>
  16. #if 0
  17. #define CHECK_SLAB_OKAY(X) \
  18. BUG_ON(atomic_read((X)) >> (sizeof(atomic_t) - 2) == \
  19. (POISON_FREE << 8 | POISON_FREE))
  20. #else
  21. #define CHECK_SLAB_OKAY(X) do {} while (0)
  22. #endif
  23. #define FCRYPT_BSIZE 8
  24. struct rxrpc_crypt {
  25. union {
  26. u8 x[FCRYPT_BSIZE];
  27. __be32 n[2];
  28. };
  29. } __attribute__((aligned(8)));
  30. #define rxrpc_queue_work(WS) queue_work(rxrpc_workqueue, (WS))
  31. #define rxrpc_queue_delayed_work(WS,D) \
  32. queue_delayed_work(rxrpc_workqueue, (WS), (D))
  33. #define rxrpc_queue_call(CALL) rxrpc_queue_work(&(CALL)->processor)
  34. struct rxrpc_connection;
  35. /*
  36. * sk_state for RxRPC sockets
  37. */
  38. enum {
  39. RXRPC_UNBOUND = 0,
  40. RXRPC_CLIENT_UNBOUND, /* Unbound socket used as client */
  41. RXRPC_CLIENT_BOUND, /* client local address bound */
  42. RXRPC_SERVER_BOUND, /* server local address bound */
  43. RXRPC_SERVER_LISTENING, /* server listening for connections */
  44. RXRPC_CLOSE, /* socket is being closed */
  45. };
  46. /*
  47. * RxRPC socket definition
  48. */
  49. struct rxrpc_sock {
  50. /* WARNING: sk has to be the first member */
  51. struct sock sk;
  52. rxrpc_interceptor_t interceptor; /* kernel service Rx interceptor function */
  53. struct rxrpc_local *local; /* local endpoint */
  54. struct list_head listen_link; /* link in the local endpoint's listen list */
  55. struct list_head secureq; /* calls awaiting connection security clearance */
  56. struct list_head acceptq; /* calls awaiting acceptance */
  57. struct key *key; /* security for this socket */
  58. struct key *securities; /* list of server security descriptors */
  59. struct rb_root calls; /* outstanding calls on this socket */
  60. unsigned long flags;
  61. #define RXRPC_SOCK_CONNECTED 0 /* connect_srx is set */
  62. rwlock_t call_lock; /* lock for calls */
  63. u32 min_sec_level; /* minimum security level */
  64. #define RXRPC_SECURITY_MAX RXRPC_SECURITY_ENCRYPT
  65. bool exclusive; /* Exclusive connection for a client socket */
  66. sa_family_t family; /* Protocol family created with */
  67. struct sockaddr_rxrpc srx; /* local address */
  68. struct sockaddr_rxrpc connect_srx; /* Default client address from connect() */
  69. };
  70. #define rxrpc_sk(__sk) container_of((__sk), struct rxrpc_sock, sk)
  71. /*
  72. * CPU-byteorder normalised Rx packet header.
  73. */
  74. struct rxrpc_host_header {
  75. u32 epoch; /* client boot timestamp */
  76. u32 cid; /* connection and channel ID */
  77. u32 callNumber; /* call ID (0 for connection-level packets) */
  78. u32 seq; /* sequence number of pkt in call stream */
  79. u32 serial; /* serial number of pkt sent to network */
  80. u8 type; /* packet type */
  81. u8 flags; /* packet flags */
  82. u8 userStatus; /* app-layer defined status */
  83. u8 securityIndex; /* security protocol ID */
  84. union {
  85. u16 _rsvd; /* reserved */
  86. u16 cksum; /* kerberos security checksum */
  87. };
  88. u16 serviceId; /* service ID */
  89. } __packed;
  90. /*
  91. * RxRPC socket buffer private variables
  92. * - max 48 bytes (struct sk_buff::cb)
  93. */
  94. struct rxrpc_skb_priv {
  95. struct rxrpc_call *call; /* call with which associated */
  96. unsigned long resend_at; /* time in jiffies at which to resend */
  97. union {
  98. unsigned int offset; /* offset into buffer of next read */
  99. int remain; /* amount of space remaining for next write */
  100. u32 error; /* network error code */
  101. bool need_resend; /* T if needs resending */
  102. };
  103. struct rxrpc_host_header hdr; /* RxRPC packet header from this packet */
  104. };
  105. #define rxrpc_skb(__skb) ((struct rxrpc_skb_priv *) &(__skb)->cb)
  106. enum rxrpc_command {
  107. RXRPC_CMD_SEND_DATA, /* send data message */
  108. RXRPC_CMD_SEND_ABORT, /* request abort generation */
  109. RXRPC_CMD_ACCEPT, /* [server] accept incoming call */
  110. RXRPC_CMD_REJECT_BUSY, /* [server] reject a call as busy */
  111. };
  112. /*
  113. * RxRPC security module interface
  114. */
  115. struct rxrpc_security {
  116. const char *name; /* name of this service */
  117. u8 security_index; /* security type provided */
  118. /* Initialise a security service */
  119. int (*init)(void);
  120. /* Clean up a security service */
  121. void (*exit)(void);
  122. /* initialise a connection's security */
  123. int (*init_connection_security)(struct rxrpc_connection *);
  124. /* prime a connection's packet security */
  125. int (*prime_packet_security)(struct rxrpc_connection *);
  126. /* impose security on a packet */
  127. int (*secure_packet)(struct rxrpc_call *,
  128. struct sk_buff *,
  129. size_t,
  130. void *);
  131. /* verify the security on a received packet */
  132. int (*verify_packet)(struct rxrpc_call *, struct sk_buff *, u32 *);
  133. /* issue a challenge */
  134. int (*issue_challenge)(struct rxrpc_connection *);
  135. /* respond to a challenge */
  136. int (*respond_to_challenge)(struct rxrpc_connection *,
  137. struct sk_buff *,
  138. u32 *);
  139. /* verify a response */
  140. int (*verify_response)(struct rxrpc_connection *,
  141. struct sk_buff *,
  142. u32 *);
  143. /* clear connection security */
  144. void (*clear)(struct rxrpc_connection *);
  145. };
  146. /*
  147. * RxRPC local transport endpoint description
  148. * - owned by a single AF_RXRPC socket
  149. * - pointed to by transport socket struct sk_user_data
  150. */
  151. struct rxrpc_local {
  152. struct rcu_head rcu;
  153. atomic_t usage;
  154. struct list_head link;
  155. struct socket *socket; /* my UDP socket */
  156. struct work_struct processor;
  157. struct list_head services; /* services listening on this endpoint */
  158. struct rw_semaphore defrag_sem; /* control re-enablement of IP DF bit */
  159. struct sk_buff_head accept_queue; /* incoming calls awaiting acceptance */
  160. struct sk_buff_head reject_queue; /* packets awaiting rejection */
  161. struct sk_buff_head event_queue; /* endpoint event packets awaiting processing */
  162. struct rb_root client_conns; /* Client connections by socket params */
  163. spinlock_t client_conns_lock; /* Lock for client_conns */
  164. spinlock_t lock; /* access lock */
  165. rwlock_t services_lock; /* lock for services list */
  166. int debug_id; /* debug ID for printks */
  167. bool dead;
  168. struct sockaddr_rxrpc srx; /* local address */
  169. };
  170. /*
  171. * RxRPC remote transport endpoint definition
  172. * - matched by local endpoint, remote port, address and protocol type
  173. */
  174. struct rxrpc_peer {
  175. struct rcu_head rcu; /* This must be first */
  176. atomic_t usage;
  177. unsigned long hash_key;
  178. struct hlist_node hash_link;
  179. struct rxrpc_local *local;
  180. struct hlist_head error_targets; /* targets for net error distribution */
  181. struct work_struct error_distributor;
  182. struct rb_root service_conns; /* Service connections */
  183. seqlock_t service_conn_lock;
  184. spinlock_t lock; /* access lock */
  185. unsigned int if_mtu; /* interface MTU for this peer */
  186. unsigned int mtu; /* network MTU for this peer */
  187. unsigned int maxdata; /* data size (MTU - hdrsize) */
  188. unsigned short hdrsize; /* header size (IP + UDP + RxRPC) */
  189. int debug_id; /* debug ID for printks */
  190. int error_report; /* Net (+0) or local (+1000000) to distribute */
  191. #define RXRPC_LOCAL_ERROR_OFFSET 1000000
  192. struct sockaddr_rxrpc srx; /* remote address */
  193. /* calculated RTT cache */
  194. #define RXRPC_RTT_CACHE_SIZE 32
  195. suseconds_t rtt; /* current RTT estimate (in uS) */
  196. unsigned int rtt_point; /* next entry at which to insert */
  197. unsigned int rtt_usage; /* amount of cache actually used */
  198. suseconds_t rtt_cache[RXRPC_RTT_CACHE_SIZE]; /* calculated RTT cache */
  199. };
  200. /*
  201. * Keys for matching a connection.
  202. */
  203. struct rxrpc_conn_proto {
  204. union {
  205. struct {
  206. u32 epoch; /* epoch of this connection */
  207. u32 cid; /* connection ID */
  208. };
  209. u64 index_key;
  210. };
  211. };
  212. struct rxrpc_conn_parameters {
  213. struct rxrpc_local *local; /* Representation of local endpoint */
  214. struct rxrpc_peer *peer; /* Remote endpoint */
  215. struct key *key; /* Security details */
  216. bool exclusive; /* T if conn is exclusive */
  217. u16 service_id; /* Service ID for this connection */
  218. u32 security_level; /* Security level selected */
  219. };
  220. /*
  221. * Bits in the connection flags.
  222. */
  223. enum rxrpc_conn_flag {
  224. RXRPC_CONN_HAS_IDR, /* Has a client conn ID assigned */
  225. RXRPC_CONN_IN_SERVICE_CONNS, /* Conn is in peer->service_conns */
  226. RXRPC_CONN_IN_CLIENT_CONNS, /* Conn is in local->client_conns */
  227. };
  228. /*
  229. * Events that can be raised upon a connection.
  230. */
  231. enum rxrpc_conn_event {
  232. RXRPC_CONN_EV_CHALLENGE, /* Send challenge packet */
  233. };
  234. /*
  235. * The connection protocol state.
  236. */
  237. enum rxrpc_conn_proto_state {
  238. RXRPC_CONN_UNUSED, /* Connection not yet attempted */
  239. RXRPC_CONN_CLIENT, /* Client connection */
  240. RXRPC_CONN_SERVICE_UNSECURED, /* Service unsecured connection */
  241. RXRPC_CONN_SERVICE_CHALLENGING, /* Service challenging for security */
  242. RXRPC_CONN_SERVICE, /* Service secured connection */
  243. RXRPC_CONN_REMOTELY_ABORTED, /* Conn aborted by peer */
  244. RXRPC_CONN_LOCALLY_ABORTED, /* Conn aborted locally */
  245. RXRPC_CONN_NETWORK_ERROR, /* Conn terminated by network error */
  246. RXRPC_CONN__NR_STATES
  247. };
  248. /*
  249. * RxRPC connection definition
  250. * - matched by { local, peer, epoch, conn_id, direction }
  251. * - each connection can only handle four simultaneous calls
  252. */
  253. struct rxrpc_connection {
  254. struct rxrpc_conn_proto proto;
  255. struct rxrpc_conn_parameters params;
  256. spinlock_t channel_lock;
  257. struct rxrpc_channel {
  258. struct rxrpc_call __rcu *call; /* Active call */
  259. u32 call_id; /* ID of current call */
  260. u32 call_counter; /* Call ID counter */
  261. u32 last_call; /* ID of last call */
  262. u32 last_result; /* Result of last call (0/abort) */
  263. } channels[RXRPC_MAXCALLS];
  264. wait_queue_head_t channel_wq; /* queue to wait for channel to become available */
  265. struct rcu_head rcu;
  266. struct work_struct processor; /* connection event processor */
  267. union {
  268. struct rb_node client_node; /* Node in local->client_conns */
  269. struct rb_node service_node; /* Node in peer->service_conns */
  270. };
  271. struct list_head link; /* link in master connection list */
  272. struct sk_buff_head rx_queue; /* received conn-level packets */
  273. const struct rxrpc_security *security; /* applied security module */
  274. struct key *server_key; /* security for this service */
  275. struct crypto_skcipher *cipher; /* encryption handle */
  276. struct rxrpc_crypt csum_iv; /* packet checksum base */
  277. unsigned long flags;
  278. unsigned long events;
  279. unsigned long put_time; /* Time at which last put */
  280. spinlock_t state_lock; /* state-change lock */
  281. atomic_t usage;
  282. enum rxrpc_conn_proto_state state : 8; /* current state of connection */
  283. u32 local_abort; /* local abort code */
  284. u32 remote_abort; /* remote abort code */
  285. int error; /* local error incurred */
  286. int debug_id; /* debug ID for printks */
  287. atomic_t serial; /* packet serial number counter */
  288. atomic_t hi_serial; /* highest serial number received */
  289. atomic_t avail_chans; /* number of channels available */
  290. u8 size_align; /* data size alignment (for security) */
  291. u8 header_size; /* rxrpc + security header size */
  292. u8 security_size; /* security header size */
  293. u32 security_nonce; /* response re-use preventer */
  294. u8 security_ix; /* security type */
  295. u8 out_clientflag; /* RXRPC_CLIENT_INITIATED if we are client */
  296. };
  297. /*
  298. * Flags in call->flags.
  299. */
  300. enum rxrpc_call_flag {
  301. RXRPC_CALL_RELEASED, /* call has been released - no more message to userspace */
  302. RXRPC_CALL_TERMINAL_MSG, /* call has given the socket its final message */
  303. RXRPC_CALL_RCVD_LAST, /* all packets received */
  304. RXRPC_CALL_RUN_RTIMER, /* Tx resend timer started */
  305. RXRPC_CALL_TX_SOFT_ACK, /* sent some soft ACKs */
  306. RXRPC_CALL_PROC_BUSY, /* the processor is busy */
  307. RXRPC_CALL_INIT_ACCEPT, /* acceptance was initiated */
  308. RXRPC_CALL_HAS_USERID, /* has a user ID attached */
  309. RXRPC_CALL_EXPECT_OOS, /* expect out of sequence packets */
  310. };
  311. /*
  312. * Events that can be raised on a call.
  313. */
  314. enum rxrpc_call_event {
  315. RXRPC_CALL_EV_RCVD_ACKALL, /* ACKALL or reply received */
  316. RXRPC_CALL_EV_RCVD_BUSY, /* busy packet received */
  317. RXRPC_CALL_EV_RCVD_ABORT, /* abort packet received */
  318. RXRPC_CALL_EV_RCVD_ERROR, /* network error received */
  319. RXRPC_CALL_EV_ACK_FINAL, /* need to generate final ACK (and release call) */
  320. RXRPC_CALL_EV_ACK, /* need to generate ACK */
  321. RXRPC_CALL_EV_REJECT_BUSY, /* need to generate busy message */
  322. RXRPC_CALL_EV_ABORT, /* need to generate abort */
  323. RXRPC_CALL_EV_CONN_ABORT, /* local connection abort generated */
  324. RXRPC_CALL_EV_RESEND_TIMER, /* Tx resend timer expired */
  325. RXRPC_CALL_EV_RESEND, /* Tx resend required */
  326. RXRPC_CALL_EV_DRAIN_RX_OOS, /* drain the Rx out of sequence queue */
  327. RXRPC_CALL_EV_LIFE_TIMER, /* call's lifetimer ran out */
  328. RXRPC_CALL_EV_ACCEPTED, /* incoming call accepted by userspace app */
  329. RXRPC_CALL_EV_SECURED, /* incoming call's connection is now secure */
  330. RXRPC_CALL_EV_POST_ACCEPT, /* need to post an "accept?" message to the app */
  331. RXRPC_CALL_EV_RELEASE, /* need to release the call's resources */
  332. };
  333. /*
  334. * The states that a call can be in.
  335. */
  336. enum rxrpc_call_state {
  337. RXRPC_CALL_UNINITIALISED,
  338. RXRPC_CALL_CLIENT_AWAIT_CONN, /* - client waiting for connection to become available */
  339. RXRPC_CALL_CLIENT_SEND_REQUEST, /* - client sending request phase */
  340. RXRPC_CALL_CLIENT_AWAIT_REPLY, /* - client awaiting reply */
  341. RXRPC_CALL_CLIENT_RECV_REPLY, /* - client receiving reply phase */
  342. RXRPC_CALL_CLIENT_FINAL_ACK, /* - client sending final ACK phase */
  343. RXRPC_CALL_SERVER_SECURING, /* - server securing request connection */
  344. RXRPC_CALL_SERVER_ACCEPTING, /* - server accepting request */
  345. RXRPC_CALL_SERVER_RECV_REQUEST, /* - server receiving request */
  346. RXRPC_CALL_SERVER_ACK_REQUEST, /* - server pending ACK of request */
  347. RXRPC_CALL_SERVER_SEND_REPLY, /* - server sending reply */
  348. RXRPC_CALL_SERVER_AWAIT_ACK, /* - server awaiting final ACK */
  349. RXRPC_CALL_COMPLETE, /* - call completed */
  350. RXRPC_CALL_SERVER_BUSY, /* - call rejected by busy server */
  351. RXRPC_CALL_REMOTELY_ABORTED, /* - call aborted by peer */
  352. RXRPC_CALL_LOCALLY_ABORTED, /* - call aborted locally on error or close */
  353. RXRPC_CALL_NETWORK_ERROR, /* - call terminated by network error */
  354. RXRPC_CALL_DEAD, /* - call is dead */
  355. NR__RXRPC_CALL_STATES
  356. };
  357. /*
  358. * RxRPC call definition
  359. * - matched by { connection, call_id }
  360. */
  361. struct rxrpc_call {
  362. struct rcu_head rcu;
  363. struct rxrpc_connection *conn; /* connection carrying call */
  364. struct rxrpc_sock *socket; /* socket responsible */
  365. struct timer_list lifetimer; /* lifetime remaining on call */
  366. struct timer_list deadspan; /* reap timer for re-ACK'ing, etc */
  367. struct timer_list ack_timer; /* ACK generation timer */
  368. struct timer_list resend_timer; /* Tx resend timer */
  369. struct work_struct destroyer; /* call destroyer */
  370. struct work_struct processor; /* packet processor and ACK generator */
  371. struct list_head link; /* link in master call list */
  372. struct hlist_node error_link; /* link in error distribution list */
  373. struct list_head accept_link; /* calls awaiting acceptance */
  374. struct rb_node sock_node; /* node in socket call tree */
  375. struct sk_buff_head rx_queue; /* received packets */
  376. struct sk_buff_head rx_oos_queue; /* packets received out of sequence */
  377. struct sk_buff *tx_pending; /* Tx socket buffer being filled */
  378. wait_queue_head_t tx_waitq; /* wait for Tx window space to become available */
  379. __be32 crypto_buf[2]; /* Temporary packet crypto buffer */
  380. unsigned long user_call_ID; /* user-defined call ID */
  381. unsigned long creation_jif; /* time of call creation */
  382. unsigned long flags;
  383. unsigned long events;
  384. spinlock_t lock;
  385. rwlock_t state_lock; /* lock for state transition */
  386. atomic_t usage;
  387. atomic_t skb_count; /* Outstanding packets on this call */
  388. atomic_t sequence; /* Tx data packet sequence counter */
  389. u32 local_abort; /* local abort code */
  390. u32 remote_abort; /* remote abort code */
  391. int error_report; /* Network error (ICMP/local transport) */
  392. int error; /* Local error incurred */
  393. enum rxrpc_call_state state : 8; /* current state of call */
  394. int debug_id; /* debug ID for printks */
  395. u8 channel; /* connection channel occupied by this call */
  396. /* transmission-phase ACK management */
  397. u8 acks_head; /* offset into window of first entry */
  398. u8 acks_tail; /* offset into window of last entry */
  399. u8 acks_winsz; /* size of un-ACK'd window */
  400. u8 acks_unacked; /* lowest unacked packet in last ACK received */
  401. int acks_latest; /* serial number of latest ACK received */
  402. rxrpc_seq_t acks_hard; /* highest definitively ACK'd msg seq */
  403. unsigned long *acks_window; /* sent packet window
  404. * - elements are pointers with LSB set if ACK'd
  405. */
  406. /* receive-phase ACK management */
  407. rxrpc_seq_t rx_data_expect; /* next data seq ID expected to be received */
  408. rxrpc_seq_t rx_data_post; /* next data seq ID expected to be posted */
  409. rxrpc_seq_t rx_data_recv; /* last data seq ID encountered by recvmsg */
  410. rxrpc_seq_t rx_data_eaten; /* last data seq ID consumed by recvmsg */
  411. rxrpc_seq_t rx_first_oos; /* first packet in rx_oos_queue (or 0) */
  412. rxrpc_seq_t ackr_win_top; /* top of ACK window (rx_data_eaten is bottom) */
  413. rxrpc_seq_t ackr_prev_seq; /* previous sequence number received */
  414. u8 ackr_reason; /* reason to ACK */
  415. rxrpc_serial_t ackr_serial; /* serial of packet being ACK'd */
  416. atomic_t ackr_not_idle; /* number of packets in Rx queue */
  417. /* received packet records, 1 bit per record */
  418. #define RXRPC_ACKR_WINDOW_ASZ DIV_ROUND_UP(RXRPC_MAXACKS, BITS_PER_LONG)
  419. unsigned long ackr_window[RXRPC_ACKR_WINDOW_ASZ + 1];
  420. u8 in_clientflag; /* Copy of conn->in_clientflag */
  421. struct rxrpc_local *local; /* Local endpoint. */
  422. u32 call_id; /* call ID on connection */
  423. u32 cid; /* connection ID plus channel index */
  424. u32 epoch; /* epoch of this connection */
  425. u16 service_id; /* service ID */
  426. };
  427. /*
  428. * locally abort an RxRPC call
  429. */
  430. static inline void rxrpc_abort_call(struct rxrpc_call *call, u32 abort_code)
  431. {
  432. write_lock_bh(&call->state_lock);
  433. if (call->state < RXRPC_CALL_COMPLETE) {
  434. call->local_abort = abort_code;
  435. call->state = RXRPC_CALL_LOCALLY_ABORTED;
  436. set_bit(RXRPC_CALL_EV_ABORT, &call->events);
  437. }
  438. write_unlock_bh(&call->state_lock);
  439. }
  440. /*
  441. * af_rxrpc.c
  442. */
  443. extern atomic_t rxrpc_n_skbs;
  444. extern u32 rxrpc_epoch;
  445. extern atomic_t rxrpc_debug_id;
  446. extern struct workqueue_struct *rxrpc_workqueue;
  447. /*
  448. * call_accept.c
  449. */
  450. void rxrpc_accept_incoming_calls(struct rxrpc_local *);
  451. struct rxrpc_call *rxrpc_accept_call(struct rxrpc_sock *, unsigned long);
  452. int rxrpc_reject_call(struct rxrpc_sock *);
  453. /*
  454. * call_event.c
  455. */
  456. void __rxrpc_propose_ACK(struct rxrpc_call *, u8, u32, bool);
  457. void rxrpc_propose_ACK(struct rxrpc_call *, u8, u32, bool);
  458. void rxrpc_process_call(struct work_struct *);
  459. /*
  460. * call_object.c
  461. */
  462. extern unsigned int rxrpc_max_call_lifetime;
  463. extern unsigned int rxrpc_dead_call_expiry;
  464. extern struct kmem_cache *rxrpc_call_jar;
  465. extern struct list_head rxrpc_calls;
  466. extern rwlock_t rxrpc_call_lock;
  467. struct rxrpc_call *rxrpc_find_call_by_user_ID(struct rxrpc_sock *, unsigned long);
  468. struct rxrpc_call *rxrpc_new_client_call(struct rxrpc_sock *,
  469. struct rxrpc_conn_parameters *,
  470. struct sockaddr_rxrpc *,
  471. unsigned long, gfp_t);
  472. struct rxrpc_call *rxrpc_incoming_call(struct rxrpc_sock *,
  473. struct rxrpc_connection *,
  474. struct sk_buff *);
  475. void rxrpc_release_call(struct rxrpc_call *);
  476. void rxrpc_release_calls_on_socket(struct rxrpc_sock *);
  477. void __rxrpc_put_call(struct rxrpc_call *);
  478. void __exit rxrpc_destroy_all_calls(void);
  479. /*
  480. * conn_client.c
  481. */
  482. extern struct idr rxrpc_client_conn_ids;
  483. void rxrpc_destroy_client_conn_ids(void);
  484. int rxrpc_connect_call(struct rxrpc_call *, struct rxrpc_conn_parameters *,
  485. struct sockaddr_rxrpc *, gfp_t);
  486. void rxrpc_unpublish_client_conn(struct rxrpc_connection *);
  487. /*
  488. * conn_event.c
  489. */
  490. void rxrpc_process_connection(struct work_struct *);
  491. void rxrpc_reject_packet(struct rxrpc_local *, struct sk_buff *);
  492. void rxrpc_reject_packets(struct rxrpc_local *);
  493. /*
  494. * conn_object.c
  495. */
  496. extern unsigned int rxrpc_connection_expiry;
  497. extern struct list_head rxrpc_connections;
  498. extern rwlock_t rxrpc_connection_lock;
  499. int rxrpc_extract_addr_from_skb(struct sockaddr_rxrpc *, struct sk_buff *);
  500. struct rxrpc_connection *rxrpc_alloc_connection(gfp_t);
  501. struct rxrpc_connection *rxrpc_find_connection_rcu(struct rxrpc_local *,
  502. struct sk_buff *);
  503. void __rxrpc_disconnect_call(struct rxrpc_call *);
  504. void rxrpc_disconnect_call(struct rxrpc_call *);
  505. void rxrpc_put_connection(struct rxrpc_connection *);
  506. void __exit rxrpc_destroy_all_connections(void);
  507. static inline bool rxrpc_conn_is_client(const struct rxrpc_connection *conn)
  508. {
  509. return conn->out_clientflag;
  510. }
  511. static inline bool rxrpc_conn_is_service(const struct rxrpc_connection *conn)
  512. {
  513. return !rxrpc_conn_is_client(conn);
  514. }
  515. static inline void rxrpc_get_connection(struct rxrpc_connection *conn)
  516. {
  517. atomic_inc(&conn->usage);
  518. }
  519. static inline
  520. struct rxrpc_connection *rxrpc_get_connection_maybe(struct rxrpc_connection *conn)
  521. {
  522. return atomic_inc_not_zero(&conn->usage) ? conn : NULL;
  523. }
  524. static inline bool rxrpc_queue_conn(struct rxrpc_connection *conn)
  525. {
  526. if (!rxrpc_get_connection_maybe(conn))
  527. return false;
  528. if (!rxrpc_queue_work(&conn->processor))
  529. rxrpc_put_connection(conn);
  530. return true;
  531. }
  532. /*
  533. * conn_service.c
  534. */
  535. struct rxrpc_connection *rxrpc_find_service_conn_rcu(struct rxrpc_peer *,
  536. struct sk_buff *);
  537. struct rxrpc_connection *rxrpc_incoming_connection(struct rxrpc_local *,
  538. struct sockaddr_rxrpc *,
  539. struct sk_buff *);
  540. void rxrpc_unpublish_service_conn(struct rxrpc_connection *);
  541. /*
  542. * input.c
  543. */
  544. void rxrpc_data_ready(struct sock *);
  545. int rxrpc_queue_rcv_skb(struct rxrpc_call *, struct sk_buff *, bool, bool);
  546. void rxrpc_fast_process_packet(struct rxrpc_call *, struct sk_buff *);
  547. /*
  548. * insecure.c
  549. */
  550. extern const struct rxrpc_security rxrpc_no_security;
  551. /*
  552. * key.c
  553. */
  554. extern struct key_type key_type_rxrpc;
  555. extern struct key_type key_type_rxrpc_s;
  556. int rxrpc_request_key(struct rxrpc_sock *, char __user *, int);
  557. int rxrpc_server_keyring(struct rxrpc_sock *, char __user *, int);
  558. int rxrpc_get_server_data_key(struct rxrpc_connection *, const void *, time_t,
  559. u32);
  560. /*
  561. * local_event.c
  562. */
  563. extern void rxrpc_process_local_events(struct rxrpc_local *);
  564. /*
  565. * local_object.c
  566. */
  567. struct rxrpc_local *rxrpc_lookup_local(const struct sockaddr_rxrpc *);
  568. void __rxrpc_put_local(struct rxrpc_local *);
  569. void __exit rxrpc_destroy_all_locals(void);
  570. static inline void rxrpc_get_local(struct rxrpc_local *local)
  571. {
  572. atomic_inc(&local->usage);
  573. }
  574. static inline
  575. struct rxrpc_local *rxrpc_get_local_maybe(struct rxrpc_local *local)
  576. {
  577. return atomic_inc_not_zero(&local->usage) ? local : NULL;
  578. }
  579. static inline void rxrpc_put_local(struct rxrpc_local *local)
  580. {
  581. if (local && atomic_dec_and_test(&local->usage))
  582. __rxrpc_put_local(local);
  583. }
  584. static inline void rxrpc_queue_local(struct rxrpc_local *local)
  585. {
  586. rxrpc_queue_work(&local->processor);
  587. }
  588. /*
  589. * misc.c
  590. */
  591. extern unsigned int rxrpc_max_backlog __read_mostly;
  592. extern unsigned int rxrpc_requested_ack_delay;
  593. extern unsigned int rxrpc_soft_ack_delay;
  594. extern unsigned int rxrpc_idle_ack_delay;
  595. extern unsigned int rxrpc_rx_window_size;
  596. extern unsigned int rxrpc_rx_mtu;
  597. extern unsigned int rxrpc_rx_jumbo_max;
  598. extern const char *const rxrpc_pkts[];
  599. extern const s8 rxrpc_ack_priority[];
  600. extern const char *rxrpc_acks(u8 reason);
  601. /*
  602. * output.c
  603. */
  604. extern unsigned int rxrpc_resend_timeout;
  605. int rxrpc_send_data_packet(struct rxrpc_connection *, struct sk_buff *);
  606. int rxrpc_do_sendmsg(struct rxrpc_sock *, struct msghdr *, size_t);
  607. /*
  608. * peer_event.c
  609. */
  610. void rxrpc_error_report(struct sock *);
  611. void rxrpc_peer_error_distributor(struct work_struct *);
  612. /*
  613. * peer_object.c
  614. */
  615. struct rxrpc_peer *rxrpc_lookup_peer_rcu(struct rxrpc_local *,
  616. const struct sockaddr_rxrpc *);
  617. struct rxrpc_peer *rxrpc_lookup_peer(struct rxrpc_local *,
  618. struct sockaddr_rxrpc *, gfp_t);
  619. struct rxrpc_peer *rxrpc_alloc_peer(struct rxrpc_local *, gfp_t);
  620. static inline void rxrpc_get_peer(struct rxrpc_peer *peer)
  621. {
  622. atomic_inc(&peer->usage);
  623. }
  624. static inline
  625. struct rxrpc_peer *rxrpc_get_peer_maybe(struct rxrpc_peer *peer)
  626. {
  627. return atomic_inc_not_zero(&peer->usage) ? peer : NULL;
  628. }
  629. extern void __rxrpc_put_peer(struct rxrpc_peer *peer);
  630. static inline void rxrpc_put_peer(struct rxrpc_peer *peer)
  631. {
  632. if (peer && atomic_dec_and_test(&peer->usage))
  633. __rxrpc_put_peer(peer);
  634. }
  635. /*
  636. * proc.c
  637. */
  638. extern const char *const rxrpc_call_states[];
  639. extern const struct file_operations rxrpc_call_seq_fops;
  640. extern const struct file_operations rxrpc_connection_seq_fops;
  641. /*
  642. * recvmsg.c
  643. */
  644. void rxrpc_remove_user_ID(struct rxrpc_sock *, struct rxrpc_call *);
  645. int rxrpc_recvmsg(struct socket *, struct msghdr *, size_t, int);
  646. /*
  647. * rxkad.c
  648. */
  649. #ifdef CONFIG_RXKAD
  650. extern const struct rxrpc_security rxkad;
  651. #endif
  652. /*
  653. * security.c
  654. */
  655. int __init rxrpc_init_security(void);
  656. void rxrpc_exit_security(void);
  657. int rxrpc_init_client_conn_security(struct rxrpc_connection *);
  658. int rxrpc_init_server_conn_security(struct rxrpc_connection *);
  659. /*
  660. * skbuff.c
  661. */
  662. void rxrpc_packet_destructor(struct sk_buff *);
  663. /*
  664. * sysctl.c
  665. */
  666. #ifdef CONFIG_SYSCTL
  667. extern int __init rxrpc_sysctl_init(void);
  668. extern void rxrpc_sysctl_exit(void);
  669. #else
  670. static inline int __init rxrpc_sysctl_init(void) { return 0; }
  671. static inline void rxrpc_sysctl_exit(void) {}
  672. #endif
  673. /*
  674. * utils.c
  675. */
  676. int rxrpc_extract_addr_from_skb(struct sockaddr_rxrpc *, struct sk_buff *);
  677. /*
  678. * debug tracing
  679. */
  680. extern unsigned int rxrpc_debug;
  681. #define dbgprintk(FMT,...) \
  682. printk("[%-6.6s] "FMT"\n", current->comm ,##__VA_ARGS__)
  683. #define kenter(FMT,...) dbgprintk("==> %s("FMT")",__func__ ,##__VA_ARGS__)
  684. #define kleave(FMT,...) dbgprintk("<== %s()"FMT"",__func__ ,##__VA_ARGS__)
  685. #define kdebug(FMT,...) dbgprintk(" "FMT ,##__VA_ARGS__)
  686. #define kproto(FMT,...) dbgprintk("### "FMT ,##__VA_ARGS__)
  687. #define knet(FMT,...) dbgprintk("@@@ "FMT ,##__VA_ARGS__)
  688. #if defined(__KDEBUG)
  689. #define _enter(FMT,...) kenter(FMT,##__VA_ARGS__)
  690. #define _leave(FMT,...) kleave(FMT,##__VA_ARGS__)
  691. #define _debug(FMT,...) kdebug(FMT,##__VA_ARGS__)
  692. #define _proto(FMT,...) kproto(FMT,##__VA_ARGS__)
  693. #define _net(FMT,...) knet(FMT,##__VA_ARGS__)
  694. #elif defined(CONFIG_AF_RXRPC_DEBUG)
  695. #define RXRPC_DEBUG_KENTER 0x01
  696. #define RXRPC_DEBUG_KLEAVE 0x02
  697. #define RXRPC_DEBUG_KDEBUG 0x04
  698. #define RXRPC_DEBUG_KPROTO 0x08
  699. #define RXRPC_DEBUG_KNET 0x10
  700. #define _enter(FMT,...) \
  701. do { \
  702. if (unlikely(rxrpc_debug & RXRPC_DEBUG_KENTER)) \
  703. kenter(FMT,##__VA_ARGS__); \
  704. } while (0)
  705. #define _leave(FMT,...) \
  706. do { \
  707. if (unlikely(rxrpc_debug & RXRPC_DEBUG_KLEAVE)) \
  708. kleave(FMT,##__VA_ARGS__); \
  709. } while (0)
  710. #define _debug(FMT,...) \
  711. do { \
  712. if (unlikely(rxrpc_debug & RXRPC_DEBUG_KDEBUG)) \
  713. kdebug(FMT,##__VA_ARGS__); \
  714. } while (0)
  715. #define _proto(FMT,...) \
  716. do { \
  717. if (unlikely(rxrpc_debug & RXRPC_DEBUG_KPROTO)) \
  718. kproto(FMT,##__VA_ARGS__); \
  719. } while (0)
  720. #define _net(FMT,...) \
  721. do { \
  722. if (unlikely(rxrpc_debug & RXRPC_DEBUG_KNET)) \
  723. knet(FMT,##__VA_ARGS__); \
  724. } while (0)
  725. #else
  726. #define _enter(FMT,...) no_printk("==> %s("FMT")",__func__ ,##__VA_ARGS__)
  727. #define _leave(FMT,...) no_printk("<== %s()"FMT"",__func__ ,##__VA_ARGS__)
  728. #define _debug(FMT,...) no_printk(" "FMT ,##__VA_ARGS__)
  729. #define _proto(FMT,...) no_printk("### "FMT ,##__VA_ARGS__)
  730. #define _net(FMT,...) no_printk("@@@ "FMT ,##__VA_ARGS__)
  731. #endif
  732. /*
  733. * debug assertion checking
  734. */
  735. #if 1 // defined(__KDEBUGALL)
  736. #define ASSERT(X) \
  737. do { \
  738. if (unlikely(!(X))) { \
  739. pr_err("Assertion failed\n"); \
  740. BUG(); \
  741. } \
  742. } while (0)
  743. #define ASSERTCMP(X, OP, Y) \
  744. do { \
  745. unsigned long _x = (unsigned long)(X); \
  746. unsigned long _y = (unsigned long)(Y); \
  747. if (unlikely(!(_x OP _y))) { \
  748. pr_err("Assertion failed - %lu(0x%lx) %s %lu(0x%lx) is false\n", \
  749. _x, _x, #OP, _y, _y); \
  750. BUG(); \
  751. } \
  752. } while (0)
  753. #define ASSERTIF(C, X) \
  754. do { \
  755. if (unlikely((C) && !(X))) { \
  756. pr_err("Assertion failed\n"); \
  757. BUG(); \
  758. } \
  759. } while (0)
  760. #define ASSERTIFCMP(C, X, OP, Y) \
  761. do { \
  762. unsigned long _x = (unsigned long)(X); \
  763. unsigned long _y = (unsigned long)(Y); \
  764. if (unlikely((C) && !(_x OP _y))) { \
  765. pr_err("Assertion failed - %lu(0x%lx) %s %lu(0x%lx) is false\n", \
  766. _x, _x, #OP, _y, _y); \
  767. BUG(); \
  768. } \
  769. } while (0)
  770. #else
  771. #define ASSERT(X) \
  772. do { \
  773. } while (0)
  774. #define ASSERTCMP(X, OP, Y) \
  775. do { \
  776. } while (0)
  777. #define ASSERTIF(C, X) \
  778. do { \
  779. } while (0)
  780. #define ASSERTIFCMP(C, X, OP, Y) \
  781. do { \
  782. } while (0)
  783. #endif /* __KDEBUGALL */
  784. /*
  785. * socket buffer accounting / leak finding
  786. */
  787. static inline void __rxrpc_new_skb(struct sk_buff *skb, const char *fn)
  788. {
  789. //_net("new skb %p %s [%d]", skb, fn, atomic_read(&rxrpc_n_skbs));
  790. //atomic_inc(&rxrpc_n_skbs);
  791. }
  792. #define rxrpc_new_skb(skb) __rxrpc_new_skb((skb), __func__)
  793. static inline void __rxrpc_kill_skb(struct sk_buff *skb, const char *fn)
  794. {
  795. //_net("kill skb %p %s [%d]", skb, fn, atomic_read(&rxrpc_n_skbs));
  796. //atomic_dec(&rxrpc_n_skbs);
  797. }
  798. #define rxrpc_kill_skb(skb) __rxrpc_kill_skb((skb), __func__)
  799. static inline void __rxrpc_free_skb(struct sk_buff *skb, const char *fn)
  800. {
  801. if (skb) {
  802. CHECK_SLAB_OKAY(&skb->users);
  803. //_net("free skb %p %s [%d]",
  804. // skb, fn, atomic_read(&rxrpc_n_skbs));
  805. //atomic_dec(&rxrpc_n_skbs);
  806. kfree_skb(skb);
  807. }
  808. }
  809. #define rxrpc_free_skb(skb) __rxrpc_free_skb((skb), __func__)
  810. static inline void rxrpc_purge_queue(struct sk_buff_head *list)
  811. {
  812. struct sk_buff *skb;
  813. while ((skb = skb_dequeue((list))) != NULL)
  814. rxrpc_free_skb(skb);
  815. }
  816. #define rxrpc_get_call(CALL) \
  817. do { \
  818. CHECK_SLAB_OKAY(&(CALL)->usage); \
  819. if (atomic_inc_return(&(CALL)->usage) == 1) \
  820. BUG(); \
  821. } while (0)
  822. #define rxrpc_put_call(CALL) \
  823. do { \
  824. __rxrpc_put_call(CALL); \
  825. } while (0)