ar-internal.h 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787
  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 <rxrpc/packet.h>
  12. #if 0
  13. #define CHECK_SLAB_OKAY(X) \
  14. BUG_ON(atomic_read((X)) >> (sizeof(atomic_t) - 2) == \
  15. (POISON_FREE << 8 | POISON_FREE))
  16. #else
  17. #define CHECK_SLAB_OKAY(X) do {} while(0)
  18. #endif
  19. #define FCRYPT_BSIZE 8
  20. struct rxrpc_crypt {
  21. union {
  22. u8 x[FCRYPT_BSIZE];
  23. __be32 n[2];
  24. };
  25. } __attribute__((aligned(8)));
  26. #define rxrpc_queue_work(WS) queue_work(rxrpc_workqueue, (WS))
  27. #define rxrpc_queue_delayed_work(WS,D) \
  28. queue_delayed_work(rxrpc_workqueue, (WS), (D))
  29. #define rxrpc_queue_call(CALL) rxrpc_queue_work(&(CALL)->processor)
  30. #define rxrpc_queue_conn(CONN) rxrpc_queue_work(&(CONN)->processor)
  31. /*
  32. * sk_state for RxRPC sockets
  33. */
  34. enum {
  35. RXRPC_UNCONNECTED = 0,
  36. RXRPC_CLIENT_BOUND, /* client local address bound */
  37. RXRPC_CLIENT_CONNECTED, /* client is connected */
  38. RXRPC_SERVER_BOUND, /* server local address bound */
  39. RXRPC_SERVER_LISTENING, /* server listening for connections */
  40. RXRPC_CLOSE, /* socket is being closed */
  41. };
  42. /*
  43. * RxRPC socket definition
  44. */
  45. struct rxrpc_sock {
  46. /* WARNING: sk has to be the first member */
  47. struct sock sk;
  48. rxrpc_interceptor_t interceptor; /* kernel service Rx interceptor function */
  49. struct rxrpc_local *local; /* local endpoint */
  50. struct rxrpc_transport *trans; /* transport handler */
  51. struct rxrpc_conn_bundle *bundle; /* virtual connection bundle */
  52. struct rxrpc_connection *conn; /* exclusive virtual connection */
  53. struct list_head listen_link; /* link in the local endpoint's listen list */
  54. struct list_head secureq; /* calls awaiting connection security clearance */
  55. struct list_head acceptq; /* calls awaiting acceptance */
  56. struct key *key; /* security for this socket */
  57. struct key *securities; /* list of server security descriptors */
  58. struct rb_root calls; /* outstanding calls on this socket */
  59. unsigned long flags;
  60. #define RXRPC_SOCK_EXCLUSIVE_CONN 1 /* exclusive connection for a client socket */
  61. rwlock_t call_lock; /* lock for calls */
  62. u32 min_sec_level; /* minimum security level */
  63. #define RXRPC_SECURITY_MAX RXRPC_SECURITY_ENCRYPT
  64. struct sockaddr_rxrpc srx; /* local address */
  65. sa_family_t proto; /* protocol created with */
  66. __be16 service_id; /* service ID of local/remote service */
  67. };
  68. #define rxrpc_sk(__sk) container_of((__sk), struct rxrpc_sock, sk)
  69. /*
  70. * RxRPC socket buffer private variables
  71. * - max 48 bytes (struct sk_buff::cb)
  72. */
  73. struct rxrpc_skb_priv {
  74. struct rxrpc_call *call; /* call with which associated */
  75. unsigned long resend_at; /* time in jiffies at which to resend */
  76. union {
  77. unsigned int offset; /* offset into buffer of next read */
  78. int remain; /* amount of space remaining for next write */
  79. u32 error; /* network error code */
  80. bool need_resend; /* T if needs resending */
  81. };
  82. struct rxrpc_header hdr; /* RxRPC packet header from this packet */
  83. };
  84. #define rxrpc_skb(__skb) ((struct rxrpc_skb_priv *) &(__skb)->cb)
  85. enum rxrpc_command {
  86. RXRPC_CMD_SEND_DATA, /* send data message */
  87. RXRPC_CMD_SEND_ABORT, /* request abort generation */
  88. RXRPC_CMD_ACCEPT, /* [server] accept incoming call */
  89. RXRPC_CMD_REJECT_BUSY, /* [server] reject a call as busy */
  90. };
  91. /*
  92. * RxRPC security module interface
  93. */
  94. struct rxrpc_security {
  95. struct module *owner; /* providing module */
  96. struct list_head link; /* link in master list */
  97. const char *name; /* name of this service */
  98. u8 security_index; /* security type provided */
  99. /* initialise a connection's security */
  100. int (*init_connection_security)(struct rxrpc_connection *);
  101. /* prime a connection's packet security */
  102. void (*prime_packet_security)(struct rxrpc_connection *);
  103. /* impose security on a packet */
  104. int (*secure_packet)(const struct rxrpc_call *,
  105. struct sk_buff *,
  106. size_t,
  107. void *);
  108. /* verify the security on a received packet */
  109. int (*verify_packet)(const struct rxrpc_call *, struct sk_buff *,
  110. u32 *);
  111. /* issue a challenge */
  112. int (*issue_challenge)(struct rxrpc_connection *);
  113. /* respond to a challenge */
  114. int (*respond_to_challenge)(struct rxrpc_connection *,
  115. struct sk_buff *,
  116. u32 *);
  117. /* verify a response */
  118. int (*verify_response)(struct rxrpc_connection *,
  119. struct sk_buff *,
  120. u32 *);
  121. /* clear connection security */
  122. void (*clear)(struct rxrpc_connection *);
  123. };
  124. /*
  125. * RxRPC local transport endpoint definition
  126. * - matched by local port, address and protocol type
  127. */
  128. struct rxrpc_local {
  129. struct socket *socket; /* my UDP socket */
  130. struct work_struct destroyer; /* endpoint destroyer */
  131. struct work_struct acceptor; /* incoming call processor */
  132. struct work_struct rejecter; /* packet reject writer */
  133. struct list_head services; /* services listening on this endpoint */
  134. struct list_head link; /* link in endpoint list */
  135. struct rw_semaphore defrag_sem; /* control re-enablement of IP DF bit */
  136. struct sk_buff_head accept_queue; /* incoming calls awaiting acceptance */
  137. struct sk_buff_head reject_queue; /* packets awaiting rejection */
  138. spinlock_t lock; /* access lock */
  139. rwlock_t services_lock; /* lock for services list */
  140. atomic_t usage;
  141. int debug_id; /* debug ID for printks */
  142. volatile char error_rcvd; /* T if received ICMP error outstanding */
  143. struct sockaddr_rxrpc srx; /* local address */
  144. };
  145. /*
  146. * RxRPC remote transport endpoint definition
  147. * - matched by remote port, address and protocol type
  148. * - holds the connection ID counter for connections between the two endpoints
  149. */
  150. struct rxrpc_peer {
  151. struct work_struct destroyer; /* peer destroyer */
  152. struct list_head link; /* link in master peer list */
  153. struct list_head error_targets; /* targets for net error distribution */
  154. spinlock_t lock; /* access lock */
  155. atomic_t usage;
  156. unsigned int if_mtu; /* interface MTU for this peer */
  157. unsigned int mtu; /* network MTU for this peer */
  158. unsigned int maxdata; /* data size (MTU - hdrsize) */
  159. unsigned short hdrsize; /* header size (IP + UDP + RxRPC) */
  160. int debug_id; /* debug ID for printks */
  161. int net_error; /* network error distributed */
  162. struct sockaddr_rxrpc srx; /* remote address */
  163. /* calculated RTT cache */
  164. #define RXRPC_RTT_CACHE_SIZE 32
  165. suseconds_t rtt; /* current RTT estimate (in uS) */
  166. unsigned int rtt_point; /* next entry at which to insert */
  167. unsigned int rtt_usage; /* amount of cache actually used */
  168. suseconds_t rtt_cache[RXRPC_RTT_CACHE_SIZE]; /* calculated RTT cache */
  169. };
  170. /*
  171. * RxRPC point-to-point transport / connection manager definition
  172. * - handles a bundle of connections between two endpoints
  173. * - matched by { local, peer }
  174. */
  175. struct rxrpc_transport {
  176. struct rxrpc_local *local; /* local transport endpoint */
  177. struct rxrpc_peer *peer; /* remote transport endpoint */
  178. struct work_struct error_handler; /* network error distributor */
  179. struct rb_root bundles; /* client connection bundles on this transport */
  180. struct rb_root client_conns; /* client connections on this transport */
  181. struct rb_root server_conns; /* server connections on this transport */
  182. struct list_head link; /* link in master session list */
  183. struct sk_buff_head error_queue; /* error packets awaiting processing */
  184. time_t put_time; /* time at which to reap */
  185. spinlock_t client_lock; /* client connection allocation lock */
  186. rwlock_t conn_lock; /* lock for active/dead connections */
  187. atomic_t usage;
  188. int debug_id; /* debug ID for printks */
  189. unsigned int conn_idcounter; /* connection ID counter (client) */
  190. };
  191. /*
  192. * RxRPC client connection bundle
  193. * - matched by { transport, service_id, key }
  194. */
  195. struct rxrpc_conn_bundle {
  196. struct rb_node node; /* node in transport's lookup tree */
  197. struct list_head unused_conns; /* unused connections in this bundle */
  198. struct list_head avail_conns; /* available connections in this bundle */
  199. struct list_head busy_conns; /* busy connections in this bundle */
  200. struct key *key; /* security for this bundle */
  201. wait_queue_head_t chanwait; /* wait for channel to become available */
  202. atomic_t usage;
  203. int debug_id; /* debug ID for printks */
  204. unsigned short num_conns; /* number of connections in this bundle */
  205. __be16 service_id; /* service ID */
  206. u8 security_ix; /* security type */
  207. };
  208. /*
  209. * RxRPC connection definition
  210. * - matched by { transport, service_id, conn_id, direction, key }
  211. * - each connection can only handle four simultaneous calls
  212. */
  213. struct rxrpc_connection {
  214. struct rxrpc_transport *trans; /* transport session */
  215. struct rxrpc_conn_bundle *bundle; /* connection bundle (client) */
  216. struct work_struct processor; /* connection event processor */
  217. struct rb_node node; /* node in transport's lookup tree */
  218. struct list_head link; /* link in master connection list */
  219. struct list_head bundle_link; /* link in bundle */
  220. struct rb_root calls; /* calls on this connection */
  221. struct sk_buff_head rx_queue; /* received conn-level packets */
  222. struct rxrpc_call *channels[RXRPC_MAXCALLS]; /* channels (active calls) */
  223. struct rxrpc_security *security; /* applied security module */
  224. struct key *key; /* security for this connection (client) */
  225. struct key *server_key; /* security for this service */
  226. struct crypto_blkcipher *cipher; /* encryption handle */
  227. struct rxrpc_crypt csum_iv; /* packet checksum base */
  228. unsigned long events;
  229. #define RXRPC_CONN_CHALLENGE 0 /* send challenge packet */
  230. time_t put_time; /* time at which to reap */
  231. rwlock_t lock; /* access lock */
  232. spinlock_t state_lock; /* state-change lock */
  233. atomic_t usage;
  234. u32 real_conn_id; /* connection ID (host-endian) */
  235. enum { /* current state of connection */
  236. RXRPC_CONN_UNUSED, /* - connection not yet attempted */
  237. RXRPC_CONN_CLIENT, /* - client connection */
  238. RXRPC_CONN_SERVER_UNSECURED, /* - server unsecured connection */
  239. RXRPC_CONN_SERVER_CHALLENGING, /* - server challenging for security */
  240. RXRPC_CONN_SERVER, /* - server secured connection */
  241. RXRPC_CONN_REMOTELY_ABORTED, /* - conn aborted by peer */
  242. RXRPC_CONN_LOCALLY_ABORTED, /* - conn aborted locally */
  243. RXRPC_CONN_NETWORK_ERROR, /* - conn terminated by network error */
  244. } state;
  245. int error; /* error code for local abort */
  246. int debug_id; /* debug ID for printks */
  247. unsigned int call_counter; /* call ID counter */
  248. atomic_t serial; /* packet serial number counter */
  249. atomic_t hi_serial; /* highest serial number received */
  250. u8 avail_calls; /* number of calls available */
  251. u8 size_align; /* data size alignment (for security) */
  252. u8 header_size; /* rxrpc + security header size */
  253. u8 security_size; /* security header size */
  254. u32 security_level; /* security level negotiated */
  255. u32 security_nonce; /* response re-use preventer */
  256. /* the following are all in net order */
  257. __be32 epoch; /* epoch of this connection */
  258. __be32 cid; /* connection ID */
  259. __be16 service_id; /* service ID */
  260. u8 security_ix; /* security type */
  261. u8 in_clientflag; /* RXRPC_CLIENT_INITIATED if we are server */
  262. u8 out_clientflag; /* RXRPC_CLIENT_INITIATED if we are client */
  263. };
  264. /*
  265. * RxRPC call definition
  266. * - matched by { connection, call_id }
  267. */
  268. struct rxrpc_call {
  269. struct rxrpc_connection *conn; /* connection carrying call */
  270. struct rxrpc_sock *socket; /* socket responsible */
  271. struct timer_list lifetimer; /* lifetime remaining on call */
  272. struct timer_list deadspan; /* reap timer for re-ACK'ing, etc */
  273. struct timer_list ack_timer; /* ACK generation timer */
  274. struct timer_list resend_timer; /* Tx resend timer */
  275. struct work_struct destroyer; /* call destroyer */
  276. struct work_struct processor; /* packet processor and ACK generator */
  277. struct list_head link; /* link in master call list */
  278. struct list_head error_link; /* link in error distribution list */
  279. struct list_head accept_link; /* calls awaiting acceptance */
  280. struct rb_node sock_node; /* node in socket call tree */
  281. struct rb_node conn_node; /* node in connection call tree */
  282. struct sk_buff_head rx_queue; /* received packets */
  283. struct sk_buff_head rx_oos_queue; /* packets received out of sequence */
  284. struct sk_buff *tx_pending; /* Tx socket buffer being filled */
  285. wait_queue_head_t tx_waitq; /* wait for Tx window space to become available */
  286. unsigned long user_call_ID; /* user-defined call ID */
  287. unsigned long creation_jif; /* time of call creation */
  288. unsigned long flags;
  289. #define RXRPC_CALL_RELEASED 0 /* call has been released - no more message to userspace */
  290. #define RXRPC_CALL_TERMINAL_MSG 1 /* call has given the socket its final message */
  291. #define RXRPC_CALL_RCVD_LAST 2 /* all packets received */
  292. #define RXRPC_CALL_RUN_RTIMER 3 /* Tx resend timer started */
  293. #define RXRPC_CALL_TX_SOFT_ACK 4 /* sent some soft ACKs */
  294. #define RXRPC_CALL_PROC_BUSY 5 /* the processor is busy */
  295. #define RXRPC_CALL_INIT_ACCEPT 6 /* acceptance was initiated */
  296. #define RXRPC_CALL_HAS_USERID 7 /* has a user ID attached */
  297. #define RXRPC_CALL_EXPECT_OOS 8 /* expect out of sequence packets */
  298. unsigned long events;
  299. #define RXRPC_CALL_RCVD_ACKALL 0 /* ACKALL or reply received */
  300. #define RXRPC_CALL_RCVD_BUSY 1 /* busy packet received */
  301. #define RXRPC_CALL_RCVD_ABORT 2 /* abort packet received */
  302. #define RXRPC_CALL_RCVD_ERROR 3 /* network error received */
  303. #define RXRPC_CALL_ACK_FINAL 4 /* need to generate final ACK (and release call) */
  304. #define RXRPC_CALL_ACK 5 /* need to generate ACK */
  305. #define RXRPC_CALL_REJECT_BUSY 6 /* need to generate busy message */
  306. #define RXRPC_CALL_ABORT 7 /* need to generate abort */
  307. #define RXRPC_CALL_CONN_ABORT 8 /* local connection abort generated */
  308. #define RXRPC_CALL_RESEND_TIMER 9 /* Tx resend timer expired */
  309. #define RXRPC_CALL_RESEND 10 /* Tx resend required */
  310. #define RXRPC_CALL_DRAIN_RX_OOS 11 /* drain the Rx out of sequence queue */
  311. #define RXRPC_CALL_LIFE_TIMER 12 /* call's lifetimer ran out */
  312. #define RXRPC_CALL_ACCEPTED 13 /* incoming call accepted by userspace app */
  313. #define RXRPC_CALL_SECURED 14 /* incoming call's connection is now secure */
  314. #define RXRPC_CALL_POST_ACCEPT 15 /* need to post an "accept?" message to the app */
  315. #define RXRPC_CALL_RELEASE 16 /* need to release the call's resources */
  316. spinlock_t lock;
  317. rwlock_t state_lock; /* lock for state transition */
  318. atomic_t usage;
  319. atomic_t sequence; /* Tx data packet sequence counter */
  320. u32 abort_code; /* local/remote abort code */
  321. enum { /* current state of call */
  322. RXRPC_CALL_CLIENT_SEND_REQUEST, /* - client sending request phase */
  323. RXRPC_CALL_CLIENT_AWAIT_REPLY, /* - client awaiting reply */
  324. RXRPC_CALL_CLIENT_RECV_REPLY, /* - client receiving reply phase */
  325. RXRPC_CALL_CLIENT_FINAL_ACK, /* - client sending final ACK phase */
  326. RXRPC_CALL_SERVER_SECURING, /* - server securing request connection */
  327. RXRPC_CALL_SERVER_ACCEPTING, /* - server accepting request */
  328. RXRPC_CALL_SERVER_RECV_REQUEST, /* - server receiving request */
  329. RXRPC_CALL_SERVER_ACK_REQUEST, /* - server pending ACK of request */
  330. RXRPC_CALL_SERVER_SEND_REPLY, /* - server sending reply */
  331. RXRPC_CALL_SERVER_AWAIT_ACK, /* - server awaiting final ACK */
  332. RXRPC_CALL_COMPLETE, /* - call completed */
  333. RXRPC_CALL_SERVER_BUSY, /* - call rejected by busy server */
  334. RXRPC_CALL_REMOTELY_ABORTED, /* - call aborted by peer */
  335. RXRPC_CALL_LOCALLY_ABORTED, /* - call aborted locally on error or close */
  336. RXRPC_CALL_NETWORK_ERROR, /* - call terminated by network error */
  337. RXRPC_CALL_DEAD, /* - call is dead */
  338. } state;
  339. int debug_id; /* debug ID for printks */
  340. u8 channel; /* connection channel occupied by this call */
  341. /* transmission-phase ACK management */
  342. u8 acks_head; /* offset into window of first entry */
  343. u8 acks_tail; /* offset into window of last entry */
  344. u8 acks_winsz; /* size of un-ACK'd window */
  345. u8 acks_unacked; /* lowest unacked packet in last ACK received */
  346. int acks_latest; /* serial number of latest ACK received */
  347. rxrpc_seq_t acks_hard; /* highest definitively ACK'd msg seq */
  348. unsigned long *acks_window; /* sent packet window
  349. * - elements are pointers with LSB set if ACK'd
  350. */
  351. /* receive-phase ACK management */
  352. rxrpc_seq_t rx_data_expect; /* next data seq ID expected to be received */
  353. rxrpc_seq_t rx_data_post; /* next data seq ID expected to be posted */
  354. rxrpc_seq_t rx_data_recv; /* last data seq ID encountered by recvmsg */
  355. rxrpc_seq_t rx_data_eaten; /* last data seq ID consumed by recvmsg */
  356. rxrpc_seq_t rx_first_oos; /* first packet in rx_oos_queue (or 0) */
  357. rxrpc_seq_t ackr_win_top; /* top of ACK window (rx_data_eaten is bottom) */
  358. rxrpc_seq_net_t ackr_prev_seq; /* previous sequence number received */
  359. u8 ackr_reason; /* reason to ACK */
  360. __be32 ackr_serial; /* serial of packet being ACK'd */
  361. atomic_t ackr_not_idle; /* number of packets in Rx queue */
  362. /* received packet records, 1 bit per record */
  363. #define RXRPC_ACKR_WINDOW_ASZ DIV_ROUND_UP(RXRPC_MAXACKS, BITS_PER_LONG)
  364. unsigned long ackr_window[RXRPC_ACKR_WINDOW_ASZ + 1];
  365. /* the following should all be in net order */
  366. __be32 cid; /* connection ID + channel index */
  367. __be32 call_id; /* call ID on connection */
  368. };
  369. /*
  370. * locally abort an RxRPC call
  371. */
  372. static inline void rxrpc_abort_call(struct rxrpc_call *call, u32 abort_code)
  373. {
  374. write_lock_bh(&call->state_lock);
  375. if (call->state < RXRPC_CALL_COMPLETE) {
  376. call->abort_code = abort_code;
  377. call->state = RXRPC_CALL_LOCALLY_ABORTED;
  378. set_bit(RXRPC_CALL_ABORT, &call->events);
  379. }
  380. write_unlock_bh(&call->state_lock);
  381. }
  382. /*
  383. * af_rxrpc.c
  384. */
  385. extern atomic_t rxrpc_n_skbs;
  386. extern __be32 rxrpc_epoch;
  387. extern atomic_t rxrpc_debug_id;
  388. extern struct workqueue_struct *rxrpc_workqueue;
  389. /*
  390. * ar-accept.c
  391. */
  392. extern void rxrpc_accept_incoming_calls(struct work_struct *);
  393. extern struct rxrpc_call *rxrpc_accept_call(struct rxrpc_sock *,
  394. unsigned long);
  395. extern int rxrpc_reject_call(struct rxrpc_sock *);
  396. /*
  397. * ar-ack.c
  398. */
  399. extern void __rxrpc_propose_ACK(struct rxrpc_call *, u8, __be32, bool);
  400. extern void rxrpc_propose_ACK(struct rxrpc_call *, u8, __be32, bool);
  401. extern void rxrpc_process_call(struct work_struct *);
  402. /*
  403. * ar-call.c
  404. */
  405. extern struct kmem_cache *rxrpc_call_jar;
  406. extern struct list_head rxrpc_calls;
  407. extern rwlock_t rxrpc_call_lock;
  408. extern struct rxrpc_call *rxrpc_get_client_call(struct rxrpc_sock *,
  409. struct rxrpc_transport *,
  410. struct rxrpc_conn_bundle *,
  411. unsigned long, int, gfp_t);
  412. extern struct rxrpc_call *rxrpc_incoming_call(struct rxrpc_sock *,
  413. struct rxrpc_connection *,
  414. struct rxrpc_header *, gfp_t);
  415. extern struct rxrpc_call *rxrpc_find_server_call(struct rxrpc_sock *,
  416. unsigned long);
  417. extern void rxrpc_release_call(struct rxrpc_call *);
  418. extern void rxrpc_release_calls_on_socket(struct rxrpc_sock *);
  419. extern void __rxrpc_put_call(struct rxrpc_call *);
  420. extern void __exit rxrpc_destroy_all_calls(void);
  421. /*
  422. * ar-connection.c
  423. */
  424. extern struct list_head rxrpc_connections;
  425. extern rwlock_t rxrpc_connection_lock;
  426. extern struct rxrpc_conn_bundle *rxrpc_get_bundle(struct rxrpc_sock *,
  427. struct rxrpc_transport *,
  428. struct key *,
  429. __be16, gfp_t);
  430. extern void rxrpc_put_bundle(struct rxrpc_transport *,
  431. struct rxrpc_conn_bundle *);
  432. extern int rxrpc_connect_call(struct rxrpc_sock *, struct rxrpc_transport *,
  433. struct rxrpc_conn_bundle *, struct rxrpc_call *,
  434. gfp_t);
  435. extern void rxrpc_put_connection(struct rxrpc_connection *);
  436. extern void __exit rxrpc_destroy_all_connections(void);
  437. extern struct rxrpc_connection *rxrpc_find_connection(struct rxrpc_transport *,
  438. struct rxrpc_header *);
  439. extern struct rxrpc_connection *
  440. rxrpc_incoming_connection(struct rxrpc_transport *, struct rxrpc_header *,
  441. gfp_t);
  442. /*
  443. * ar-connevent.c
  444. */
  445. extern void rxrpc_process_connection(struct work_struct *);
  446. extern void rxrpc_reject_packet(struct rxrpc_local *, struct sk_buff *);
  447. extern void rxrpc_reject_packets(struct work_struct *);
  448. /*
  449. * ar-error.c
  450. */
  451. extern void rxrpc_UDP_error_report(struct sock *);
  452. extern void rxrpc_UDP_error_handler(struct work_struct *);
  453. /*
  454. * ar-input.c
  455. */
  456. extern unsigned long rxrpc_ack_timeout;
  457. extern const char *rxrpc_pkts[];
  458. extern void rxrpc_data_ready(struct sock *, int);
  459. extern int rxrpc_queue_rcv_skb(struct rxrpc_call *, struct sk_buff *, bool,
  460. bool);
  461. extern void rxrpc_fast_process_packet(struct rxrpc_call *, struct sk_buff *);
  462. /*
  463. * ar-local.c
  464. */
  465. extern rwlock_t rxrpc_local_lock;
  466. extern struct rxrpc_local *rxrpc_lookup_local(struct sockaddr_rxrpc *);
  467. extern void rxrpc_put_local(struct rxrpc_local *);
  468. extern void __exit rxrpc_destroy_all_locals(void);
  469. /*
  470. * ar-key.c
  471. */
  472. extern struct key_type key_type_rxrpc;
  473. extern struct key_type key_type_rxrpc_s;
  474. extern int rxrpc_request_key(struct rxrpc_sock *, char __user *, int);
  475. extern int rxrpc_server_keyring(struct rxrpc_sock *, char __user *, int);
  476. extern int rxrpc_get_server_data_key(struct rxrpc_connection *, const void *,
  477. time_t, u32);
  478. /*
  479. * ar-output.c
  480. */
  481. extern int rxrpc_resend_timeout;
  482. extern int rxrpc_send_packet(struct rxrpc_transport *, struct sk_buff *);
  483. extern int rxrpc_client_sendmsg(struct kiocb *, struct rxrpc_sock *,
  484. struct rxrpc_transport *, struct msghdr *,
  485. size_t);
  486. extern int rxrpc_server_sendmsg(struct kiocb *, struct rxrpc_sock *,
  487. struct msghdr *, size_t);
  488. /*
  489. * ar-peer.c
  490. */
  491. extern struct rxrpc_peer *rxrpc_get_peer(struct sockaddr_rxrpc *, gfp_t);
  492. extern void rxrpc_put_peer(struct rxrpc_peer *);
  493. extern struct rxrpc_peer *rxrpc_find_peer(struct rxrpc_local *,
  494. __be32, __be16);
  495. extern void __exit rxrpc_destroy_all_peers(void);
  496. /*
  497. * ar-proc.c
  498. */
  499. extern const char *const rxrpc_call_states[];
  500. extern const struct file_operations rxrpc_call_seq_fops;
  501. extern const struct file_operations rxrpc_connection_seq_fops;
  502. /*
  503. * ar-recvmsg.c
  504. */
  505. extern void rxrpc_remove_user_ID(struct rxrpc_sock *, struct rxrpc_call *);
  506. extern int rxrpc_recvmsg(struct kiocb *, struct socket *, struct msghdr *,
  507. size_t, int);
  508. /*
  509. * ar-security.c
  510. */
  511. extern int rxrpc_register_security(struct rxrpc_security *);
  512. extern void rxrpc_unregister_security(struct rxrpc_security *);
  513. extern int rxrpc_init_client_conn_security(struct rxrpc_connection *);
  514. extern int rxrpc_init_server_conn_security(struct rxrpc_connection *);
  515. extern int rxrpc_secure_packet(const struct rxrpc_call *, struct sk_buff *,
  516. size_t, void *);
  517. extern int rxrpc_verify_packet(const struct rxrpc_call *, struct sk_buff *,
  518. u32 *);
  519. extern void rxrpc_clear_conn_security(struct rxrpc_connection *);
  520. /*
  521. * ar-skbuff.c
  522. */
  523. extern void rxrpc_packet_destructor(struct sk_buff *);
  524. /*
  525. * ar-transport.c
  526. */
  527. extern struct rxrpc_transport *rxrpc_get_transport(struct rxrpc_local *,
  528. struct rxrpc_peer *,
  529. gfp_t);
  530. extern void rxrpc_put_transport(struct rxrpc_transport *);
  531. extern void __exit rxrpc_destroy_all_transports(void);
  532. extern struct rxrpc_transport *rxrpc_find_transport(struct rxrpc_local *,
  533. struct rxrpc_peer *);
  534. /*
  535. * debug tracing
  536. */
  537. extern unsigned int rxrpc_debug;
  538. #define dbgprintk(FMT,...) \
  539. printk("[%-6.6s] "FMT"\n", current->comm ,##__VA_ARGS__)
  540. #define kenter(FMT,...) dbgprintk("==> %s("FMT")",__func__ ,##__VA_ARGS__)
  541. #define kleave(FMT,...) dbgprintk("<== %s()"FMT"",__func__ ,##__VA_ARGS__)
  542. #define kdebug(FMT,...) dbgprintk(" "FMT ,##__VA_ARGS__)
  543. #define kproto(FMT,...) dbgprintk("### "FMT ,##__VA_ARGS__)
  544. #define knet(FMT,...) dbgprintk("@@@ "FMT ,##__VA_ARGS__)
  545. #if defined(__KDEBUG)
  546. #define _enter(FMT,...) kenter(FMT,##__VA_ARGS__)
  547. #define _leave(FMT,...) kleave(FMT,##__VA_ARGS__)
  548. #define _debug(FMT,...) kdebug(FMT,##__VA_ARGS__)
  549. #define _proto(FMT,...) kproto(FMT,##__VA_ARGS__)
  550. #define _net(FMT,...) knet(FMT,##__VA_ARGS__)
  551. #elif defined(CONFIG_AF_RXRPC_DEBUG)
  552. #define RXRPC_DEBUG_KENTER 0x01
  553. #define RXRPC_DEBUG_KLEAVE 0x02
  554. #define RXRPC_DEBUG_KDEBUG 0x04
  555. #define RXRPC_DEBUG_KPROTO 0x08
  556. #define RXRPC_DEBUG_KNET 0x10
  557. #define _enter(FMT,...) \
  558. do { \
  559. if (unlikely(rxrpc_debug & RXRPC_DEBUG_KENTER)) \
  560. kenter(FMT,##__VA_ARGS__); \
  561. } while (0)
  562. #define _leave(FMT,...) \
  563. do { \
  564. if (unlikely(rxrpc_debug & RXRPC_DEBUG_KLEAVE)) \
  565. kleave(FMT,##__VA_ARGS__); \
  566. } while (0)
  567. #define _debug(FMT,...) \
  568. do { \
  569. if (unlikely(rxrpc_debug & RXRPC_DEBUG_KDEBUG)) \
  570. kdebug(FMT,##__VA_ARGS__); \
  571. } while (0)
  572. #define _proto(FMT,...) \
  573. do { \
  574. if (unlikely(rxrpc_debug & RXRPC_DEBUG_KPROTO)) \
  575. kproto(FMT,##__VA_ARGS__); \
  576. } while (0)
  577. #define _net(FMT,...) \
  578. do { \
  579. if (unlikely(rxrpc_debug & RXRPC_DEBUG_KNET)) \
  580. knet(FMT,##__VA_ARGS__); \
  581. } while (0)
  582. #else
  583. #define _enter(FMT,...) no_printk("==> %s("FMT")",__func__ ,##__VA_ARGS__)
  584. #define _leave(FMT,...) no_printk("<== %s()"FMT"",__func__ ,##__VA_ARGS__)
  585. #define _debug(FMT,...) no_printk(" "FMT ,##__VA_ARGS__)
  586. #define _proto(FMT,...) no_printk("### "FMT ,##__VA_ARGS__)
  587. #define _net(FMT,...) no_printk("@@@ "FMT ,##__VA_ARGS__)
  588. #endif
  589. /*
  590. * debug assertion checking
  591. */
  592. #if 1 // defined(__KDEBUGALL)
  593. #define ASSERT(X) \
  594. do { \
  595. if (unlikely(!(X))) { \
  596. printk(KERN_ERR "\n"); \
  597. printk(KERN_ERR "RxRPC: Assertion failed\n"); \
  598. BUG(); \
  599. } \
  600. } while(0)
  601. #define ASSERTCMP(X, OP, Y) \
  602. do { \
  603. if (unlikely(!((X) OP (Y)))) { \
  604. printk(KERN_ERR "\n"); \
  605. printk(KERN_ERR "RxRPC: Assertion failed\n"); \
  606. printk(KERN_ERR "%lu " #OP " %lu is false\n", \
  607. (unsigned long)(X), (unsigned long)(Y)); \
  608. printk(KERN_ERR "0x%lx " #OP " 0x%lx is false\n", \
  609. (unsigned long)(X), (unsigned long)(Y)); \
  610. BUG(); \
  611. } \
  612. } while(0)
  613. #define ASSERTIF(C, X) \
  614. do { \
  615. if (unlikely((C) && !(X))) { \
  616. printk(KERN_ERR "\n"); \
  617. printk(KERN_ERR "RxRPC: Assertion failed\n"); \
  618. BUG(); \
  619. } \
  620. } while(0)
  621. #define ASSERTIFCMP(C, X, OP, Y) \
  622. do { \
  623. if (unlikely((C) && !((X) OP (Y)))) { \
  624. printk(KERN_ERR "\n"); \
  625. printk(KERN_ERR "RxRPC: Assertion failed\n"); \
  626. printk(KERN_ERR "%lu " #OP " %lu is false\n", \
  627. (unsigned long)(X), (unsigned long)(Y)); \
  628. printk(KERN_ERR "0x%lx " #OP " 0x%lx is false\n", \
  629. (unsigned long)(X), (unsigned long)(Y)); \
  630. BUG(); \
  631. } \
  632. } while(0)
  633. #else
  634. #define ASSERT(X) \
  635. do { \
  636. } while(0)
  637. #define ASSERTCMP(X, OP, Y) \
  638. do { \
  639. } while(0)
  640. #define ASSERTIF(C, X) \
  641. do { \
  642. } while(0)
  643. #define ASSERTIFCMP(C, X, OP, Y) \
  644. do { \
  645. } while(0)
  646. #endif /* __KDEBUGALL */
  647. /*
  648. * socket buffer accounting / leak finding
  649. */
  650. static inline void __rxrpc_new_skb(struct sk_buff *skb, const char *fn)
  651. {
  652. //_net("new skb %p %s [%d]", skb, fn, atomic_read(&rxrpc_n_skbs));
  653. //atomic_inc(&rxrpc_n_skbs);
  654. }
  655. #define rxrpc_new_skb(skb) __rxrpc_new_skb((skb), __func__)
  656. static inline void __rxrpc_kill_skb(struct sk_buff *skb, const char *fn)
  657. {
  658. //_net("kill skb %p %s [%d]", skb, fn, atomic_read(&rxrpc_n_skbs));
  659. //atomic_dec(&rxrpc_n_skbs);
  660. }
  661. #define rxrpc_kill_skb(skb) __rxrpc_kill_skb((skb), __func__)
  662. static inline void __rxrpc_free_skb(struct sk_buff *skb, const char *fn)
  663. {
  664. if (skb) {
  665. CHECK_SLAB_OKAY(&skb->users);
  666. //_net("free skb %p %s [%d]",
  667. // skb, fn, atomic_read(&rxrpc_n_skbs));
  668. //atomic_dec(&rxrpc_n_skbs);
  669. kfree_skb(skb);
  670. }
  671. }
  672. #define rxrpc_free_skb(skb) __rxrpc_free_skb((skb), __func__)
  673. static inline void rxrpc_purge_queue(struct sk_buff_head *list)
  674. {
  675. struct sk_buff *skb;
  676. while ((skb = skb_dequeue((list))) != NULL)
  677. rxrpc_free_skb(skb);
  678. }
  679. static inline void __rxrpc_get_local(struct rxrpc_local *local, const char *f)
  680. {
  681. CHECK_SLAB_OKAY(&local->usage);
  682. if (atomic_inc_return(&local->usage) == 1)
  683. printk("resurrected (%s)\n", f);
  684. }
  685. #define rxrpc_get_local(LOCAL) __rxrpc_get_local((LOCAL), __func__)
  686. #define rxrpc_get_call(CALL) \
  687. do { \
  688. CHECK_SLAB_OKAY(&(CALL)->usage); \
  689. if (atomic_inc_return(&(CALL)->usage) == 1) \
  690. BUG(); \
  691. } while(0)
  692. #define rxrpc_put_call(CALL) \
  693. do { \
  694. __rxrpc_put_call(CALL); \
  695. } while(0)