ar-internal.h 28 KB

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