ar-internal.h 37 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221
  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. struct rxrpc_connection;
  34. /*
  35. * Mark applied to socket buffers.
  36. */
  37. enum rxrpc_skb_mark {
  38. RXRPC_SKB_MARK_DATA, /* data message */
  39. RXRPC_SKB_MARK_FINAL_ACK, /* final ACK received message */
  40. RXRPC_SKB_MARK_BUSY, /* server busy message */
  41. RXRPC_SKB_MARK_REMOTE_ABORT, /* remote abort message */
  42. RXRPC_SKB_MARK_LOCAL_ABORT, /* local abort message */
  43. RXRPC_SKB_MARK_NET_ERROR, /* network error message */
  44. RXRPC_SKB_MARK_LOCAL_ERROR, /* local error message */
  45. RXRPC_SKB_MARK_NEW_CALL, /* local error message */
  46. };
  47. /*
  48. * sk_state for RxRPC sockets
  49. */
  50. enum {
  51. RXRPC_UNBOUND = 0,
  52. RXRPC_CLIENT_UNBOUND, /* Unbound socket used as client */
  53. RXRPC_CLIENT_BOUND, /* client local address bound */
  54. RXRPC_SERVER_BOUND, /* server local address bound */
  55. RXRPC_SERVER_LISTENING, /* server listening for connections */
  56. RXRPC_CLOSE, /* socket is being closed */
  57. };
  58. /*
  59. * Service backlog preallocation.
  60. *
  61. * This contains circular buffers of preallocated peers, connections and calls
  62. * for incoming service calls and their head and tail pointers. This allows
  63. * calls to be set up in the data_ready handler, thereby avoiding the need to
  64. * shuffle packets around so much.
  65. */
  66. struct rxrpc_backlog {
  67. unsigned short peer_backlog_head;
  68. unsigned short peer_backlog_tail;
  69. unsigned short conn_backlog_head;
  70. unsigned short conn_backlog_tail;
  71. unsigned short call_backlog_head;
  72. unsigned short call_backlog_tail;
  73. #define RXRPC_BACKLOG_MAX 32
  74. struct rxrpc_peer *peer_backlog[RXRPC_BACKLOG_MAX];
  75. struct rxrpc_connection *conn_backlog[RXRPC_BACKLOG_MAX];
  76. struct rxrpc_call *call_backlog[RXRPC_BACKLOG_MAX];
  77. };
  78. /*
  79. * RxRPC socket definition
  80. */
  81. struct rxrpc_sock {
  82. /* WARNING: sk has to be the first member */
  83. struct sock sk;
  84. rxrpc_notify_new_call_t notify_new_call; /* Func to notify of new call */
  85. rxrpc_discard_new_call_t discard_new_call; /* Func to discard a new call */
  86. struct rxrpc_local *local; /* local endpoint */
  87. struct hlist_node listen_link; /* link in the local endpoint's listen list */
  88. struct rxrpc_backlog *backlog; /* Preallocation for services */
  89. spinlock_t incoming_lock; /* Incoming call vs service shutdown lock */
  90. struct list_head sock_calls; /* List of calls owned by this socket */
  91. struct list_head to_be_accepted; /* calls awaiting acceptance */
  92. struct list_head recvmsg_q; /* Calls awaiting recvmsg's attention */
  93. rwlock_t recvmsg_lock; /* Lock for recvmsg_q */
  94. struct key *key; /* security for this socket */
  95. struct key *securities; /* list of server security descriptors */
  96. struct rb_root calls; /* User ID -> call mapping */
  97. unsigned long flags;
  98. #define RXRPC_SOCK_CONNECTED 0 /* connect_srx is set */
  99. rwlock_t call_lock; /* lock for calls */
  100. u32 min_sec_level; /* minimum security level */
  101. #define RXRPC_SECURITY_MAX RXRPC_SECURITY_ENCRYPT
  102. bool exclusive; /* Exclusive connection for a client socket */
  103. sa_family_t family; /* Protocol family created with */
  104. struct sockaddr_rxrpc srx; /* local address */
  105. struct sockaddr_rxrpc connect_srx; /* Default client address from connect() */
  106. };
  107. #define rxrpc_sk(__sk) container_of((__sk), struct rxrpc_sock, sk)
  108. /*
  109. * CPU-byteorder normalised Rx packet header.
  110. */
  111. struct rxrpc_host_header {
  112. u32 epoch; /* client boot timestamp */
  113. u32 cid; /* connection and channel ID */
  114. u32 callNumber; /* call ID (0 for connection-level packets) */
  115. u32 seq; /* sequence number of pkt in call stream */
  116. u32 serial; /* serial number of pkt sent to network */
  117. u8 type; /* packet type */
  118. u8 flags; /* packet flags */
  119. u8 userStatus; /* app-layer defined status */
  120. u8 securityIndex; /* security protocol ID */
  121. union {
  122. u16 _rsvd; /* reserved */
  123. u16 cksum; /* kerberos security checksum */
  124. };
  125. u16 serviceId; /* service ID */
  126. } __packed;
  127. /*
  128. * RxRPC socket buffer private variables
  129. * - max 48 bytes (struct sk_buff::cb)
  130. */
  131. struct rxrpc_skb_priv {
  132. union {
  133. u8 nr_jumbo; /* Number of jumbo subpackets */
  134. };
  135. union {
  136. unsigned int offset; /* offset into buffer of next read */
  137. int remain; /* amount of space remaining for next write */
  138. u32 error; /* network error code */
  139. };
  140. struct rxrpc_host_header hdr; /* RxRPC packet header from this packet */
  141. };
  142. #define rxrpc_skb(__skb) ((struct rxrpc_skb_priv *) &(__skb)->cb)
  143. /*
  144. * RxRPC security module interface
  145. */
  146. struct rxrpc_security {
  147. const char *name; /* name of this service */
  148. u8 security_index; /* security type provided */
  149. /* Initialise a security service */
  150. int (*init)(void);
  151. /* Clean up a security service */
  152. void (*exit)(void);
  153. /* initialise a connection's security */
  154. int (*init_connection_security)(struct rxrpc_connection *);
  155. /* prime a connection's packet security */
  156. int (*prime_packet_security)(struct rxrpc_connection *);
  157. /* impose security on a packet */
  158. int (*secure_packet)(struct rxrpc_call *,
  159. struct sk_buff *,
  160. size_t,
  161. void *);
  162. /* verify the security on a received packet */
  163. int (*verify_packet)(struct rxrpc_call *, struct sk_buff *,
  164. unsigned int, unsigned int, rxrpc_seq_t, u16);
  165. /* Locate the data in a received packet that has been verified. */
  166. void (*locate_data)(struct rxrpc_call *, struct sk_buff *,
  167. unsigned int *, unsigned int *);
  168. /* issue a challenge */
  169. int (*issue_challenge)(struct rxrpc_connection *);
  170. /* respond to a challenge */
  171. int (*respond_to_challenge)(struct rxrpc_connection *,
  172. struct sk_buff *,
  173. u32 *);
  174. /* verify a response */
  175. int (*verify_response)(struct rxrpc_connection *,
  176. struct sk_buff *,
  177. u32 *);
  178. /* clear connection security */
  179. void (*clear)(struct rxrpc_connection *);
  180. };
  181. /*
  182. * RxRPC local transport endpoint description
  183. * - owned by a single AF_RXRPC socket
  184. * - pointed to by transport socket struct sk_user_data
  185. */
  186. struct rxrpc_local {
  187. struct rcu_head rcu;
  188. atomic_t usage;
  189. struct list_head link;
  190. struct socket *socket; /* my UDP socket */
  191. struct work_struct processor;
  192. struct hlist_head services; /* services listening on this endpoint */
  193. struct rw_semaphore defrag_sem; /* control re-enablement of IP DF bit */
  194. struct sk_buff_head reject_queue; /* packets awaiting rejection */
  195. struct sk_buff_head event_queue; /* endpoint event packets awaiting processing */
  196. struct rb_root client_conns; /* Client connections by socket params */
  197. spinlock_t client_conns_lock; /* Lock for client_conns */
  198. spinlock_t lock; /* access lock */
  199. rwlock_t services_lock; /* lock for services list */
  200. int debug_id; /* debug ID for printks */
  201. bool dead;
  202. struct sockaddr_rxrpc srx; /* local address */
  203. };
  204. /*
  205. * RxRPC remote transport endpoint definition
  206. * - matched by local endpoint, remote port, address and protocol type
  207. */
  208. struct rxrpc_peer {
  209. struct rcu_head rcu; /* This must be first */
  210. atomic_t usage;
  211. unsigned long hash_key;
  212. struct hlist_node hash_link;
  213. struct rxrpc_local *local;
  214. struct hlist_head error_targets; /* targets for net error distribution */
  215. struct work_struct error_distributor;
  216. struct rb_root service_conns; /* Service connections */
  217. seqlock_t service_conn_lock;
  218. spinlock_t lock; /* access lock */
  219. unsigned int if_mtu; /* interface MTU for this peer */
  220. unsigned int mtu; /* network MTU for this peer */
  221. unsigned int maxdata; /* data size (MTU - hdrsize) */
  222. unsigned short hdrsize; /* header size (IP + UDP + RxRPC) */
  223. int debug_id; /* debug ID for printks */
  224. int error_report; /* Net (+0) or local (+1000000) to distribute */
  225. #define RXRPC_LOCAL_ERROR_OFFSET 1000000
  226. struct sockaddr_rxrpc srx; /* remote address */
  227. /* calculated RTT cache */
  228. #define RXRPC_RTT_CACHE_SIZE 32
  229. ktime_t rtt_last_req; /* Time of last RTT request */
  230. u64 rtt; /* Current RTT estimate (in nS) */
  231. u64 rtt_sum; /* Sum of cache contents */
  232. u64 rtt_cache[RXRPC_RTT_CACHE_SIZE]; /* Determined RTT cache */
  233. u8 rtt_cursor; /* next entry at which to insert */
  234. u8 rtt_usage; /* amount of cache actually used */
  235. };
  236. /*
  237. * Keys for matching a connection.
  238. */
  239. struct rxrpc_conn_proto {
  240. union {
  241. struct {
  242. u32 epoch; /* epoch of this connection */
  243. u32 cid; /* connection ID */
  244. };
  245. u64 index_key;
  246. };
  247. };
  248. struct rxrpc_conn_parameters {
  249. struct rxrpc_local *local; /* Representation of local endpoint */
  250. struct rxrpc_peer *peer; /* Remote endpoint */
  251. struct key *key; /* Security details */
  252. bool exclusive; /* T if conn is exclusive */
  253. u16 service_id; /* Service ID for this connection */
  254. u32 security_level; /* Security level selected */
  255. };
  256. /*
  257. * Bits in the connection flags.
  258. */
  259. enum rxrpc_conn_flag {
  260. RXRPC_CONN_HAS_IDR, /* Has a client conn ID assigned */
  261. RXRPC_CONN_IN_SERVICE_CONNS, /* Conn is in peer->service_conns */
  262. RXRPC_CONN_IN_CLIENT_CONNS, /* Conn is in local->client_conns */
  263. RXRPC_CONN_EXPOSED, /* Conn has extra ref for exposure */
  264. RXRPC_CONN_DONT_REUSE, /* Don't reuse this connection */
  265. RXRPC_CONN_COUNTED, /* Counted by rxrpc_nr_client_conns */
  266. };
  267. /*
  268. * Events that can be raised upon a connection.
  269. */
  270. enum rxrpc_conn_event {
  271. RXRPC_CONN_EV_CHALLENGE, /* Send challenge packet */
  272. };
  273. /*
  274. * The connection cache state.
  275. */
  276. enum rxrpc_conn_cache_state {
  277. RXRPC_CONN_CLIENT_INACTIVE, /* Conn is not yet listed */
  278. RXRPC_CONN_CLIENT_WAITING, /* Conn is on wait list, waiting for capacity */
  279. RXRPC_CONN_CLIENT_ACTIVE, /* Conn is on active list, doing calls */
  280. RXRPC_CONN_CLIENT_CULLED, /* Conn is culled and delisted, doing calls */
  281. RXRPC_CONN_CLIENT_IDLE, /* Conn is on idle list, doing mostly nothing */
  282. RXRPC_CONN__NR_CACHE_STATES
  283. };
  284. /*
  285. * The connection protocol state.
  286. */
  287. enum rxrpc_conn_proto_state {
  288. RXRPC_CONN_UNUSED, /* Connection not yet attempted */
  289. RXRPC_CONN_CLIENT, /* Client connection */
  290. RXRPC_CONN_SERVICE_PREALLOC, /* Service connection preallocation */
  291. RXRPC_CONN_SERVICE_UNSECURED, /* Service unsecured connection */
  292. RXRPC_CONN_SERVICE_CHALLENGING, /* Service challenging for security */
  293. RXRPC_CONN_SERVICE, /* Service secured connection */
  294. RXRPC_CONN_REMOTELY_ABORTED, /* Conn aborted by peer */
  295. RXRPC_CONN_LOCALLY_ABORTED, /* Conn aborted locally */
  296. RXRPC_CONN__NR_STATES
  297. };
  298. /*
  299. * RxRPC connection definition
  300. * - matched by { local, peer, epoch, conn_id, direction }
  301. * - each connection can only handle four simultaneous calls
  302. */
  303. struct rxrpc_connection {
  304. struct rxrpc_conn_proto proto;
  305. struct rxrpc_conn_parameters params;
  306. atomic_t usage;
  307. struct rcu_head rcu;
  308. struct list_head cache_link;
  309. spinlock_t channel_lock;
  310. unsigned char active_chans; /* Mask of active channels */
  311. #define RXRPC_ACTIVE_CHANS_MASK ((1 << RXRPC_MAXCALLS) - 1)
  312. struct list_head waiting_calls; /* Calls waiting for channels */
  313. struct rxrpc_channel {
  314. struct rxrpc_call __rcu *call; /* Active call */
  315. u32 call_id; /* ID of current call */
  316. u32 call_counter; /* Call ID counter */
  317. u32 last_call; /* ID of last call */
  318. u8 last_type; /* Type of last packet */
  319. u16 last_service_id;
  320. union {
  321. u32 last_seq;
  322. u32 last_abort;
  323. };
  324. } channels[RXRPC_MAXCALLS];
  325. struct work_struct processor; /* connection event processor */
  326. union {
  327. struct rb_node client_node; /* Node in local->client_conns */
  328. struct rb_node service_node; /* Node in peer->service_conns */
  329. };
  330. struct list_head proc_link; /* link in procfs list */
  331. struct list_head link; /* link in master connection list */
  332. struct sk_buff_head rx_queue; /* received conn-level packets */
  333. const struct rxrpc_security *security; /* applied security module */
  334. struct key *server_key; /* security for this service */
  335. struct crypto_skcipher *cipher; /* encryption handle */
  336. struct rxrpc_crypt csum_iv; /* packet checksum base */
  337. unsigned long flags;
  338. unsigned long events;
  339. unsigned long idle_timestamp; /* Time at which last became idle */
  340. spinlock_t state_lock; /* state-change lock */
  341. enum rxrpc_conn_cache_state cache_state;
  342. enum rxrpc_conn_proto_state state; /* current state of connection */
  343. u32 local_abort; /* local abort code */
  344. u32 remote_abort; /* remote abort code */
  345. int debug_id; /* debug ID for printks */
  346. atomic_t serial; /* packet serial number counter */
  347. unsigned int hi_serial; /* highest serial number received */
  348. u32 security_nonce; /* response re-use preventer */
  349. u8 size_align; /* data size alignment (for security) */
  350. u8 security_size; /* security header size */
  351. u8 security_ix; /* security type */
  352. u8 out_clientflag; /* RXRPC_CLIENT_INITIATED if we are client */
  353. };
  354. /*
  355. * Flags in call->flags.
  356. */
  357. enum rxrpc_call_flag {
  358. RXRPC_CALL_RELEASED, /* call has been released - no more message to userspace */
  359. RXRPC_CALL_HAS_USERID, /* has a user ID attached */
  360. RXRPC_CALL_IS_SERVICE, /* Call is service call */
  361. RXRPC_CALL_EXPOSED, /* The call was exposed to the world */
  362. RXRPC_CALL_RX_LAST, /* Received the last packet (at rxtx_top) */
  363. RXRPC_CALL_TX_LAST, /* Last packet in Tx buffer (at rxtx_top) */
  364. RXRPC_CALL_PINGING, /* Ping in process */
  365. };
  366. /*
  367. * Events that can be raised on a call.
  368. */
  369. enum rxrpc_call_event {
  370. RXRPC_CALL_EV_ACK, /* need to generate ACK */
  371. RXRPC_CALL_EV_ABORT, /* need to generate abort */
  372. RXRPC_CALL_EV_TIMER, /* Timer expired */
  373. RXRPC_CALL_EV_RESEND, /* Tx resend required */
  374. };
  375. /*
  376. * The states that a call can be in.
  377. */
  378. enum rxrpc_call_state {
  379. RXRPC_CALL_UNINITIALISED,
  380. RXRPC_CALL_CLIENT_AWAIT_CONN, /* - client waiting for connection to become available */
  381. RXRPC_CALL_CLIENT_SEND_REQUEST, /* - client sending request phase */
  382. RXRPC_CALL_CLIENT_AWAIT_REPLY, /* - client awaiting reply */
  383. RXRPC_CALL_CLIENT_RECV_REPLY, /* - client receiving reply phase */
  384. RXRPC_CALL_SERVER_PREALLOC, /* - service preallocation */
  385. RXRPC_CALL_SERVER_SECURING, /* - server securing request connection */
  386. RXRPC_CALL_SERVER_ACCEPTING, /* - server accepting request */
  387. RXRPC_CALL_SERVER_RECV_REQUEST, /* - server receiving request */
  388. RXRPC_CALL_SERVER_ACK_REQUEST, /* - server pending ACK of request */
  389. RXRPC_CALL_SERVER_SEND_REPLY, /* - server sending reply */
  390. RXRPC_CALL_SERVER_AWAIT_ACK, /* - server awaiting final ACK */
  391. RXRPC_CALL_COMPLETE, /* - call complete */
  392. NR__RXRPC_CALL_STATES
  393. };
  394. /*
  395. * Call completion condition (state == RXRPC_CALL_COMPLETE).
  396. */
  397. enum rxrpc_call_completion {
  398. RXRPC_CALL_SUCCEEDED, /* - Normal termination */
  399. RXRPC_CALL_REMOTELY_ABORTED, /* - call aborted by peer */
  400. RXRPC_CALL_LOCALLY_ABORTED, /* - call aborted locally on error or close */
  401. RXRPC_CALL_LOCAL_ERROR, /* - call failed due to local error */
  402. RXRPC_CALL_NETWORK_ERROR, /* - call terminated by network error */
  403. NR__RXRPC_CALL_COMPLETIONS
  404. };
  405. /*
  406. * RxRPC call definition
  407. * - matched by { connection, call_id }
  408. */
  409. struct rxrpc_call {
  410. struct rcu_head rcu;
  411. struct rxrpc_connection *conn; /* connection carrying call */
  412. struct rxrpc_peer *peer; /* Peer record for remote address */
  413. struct rxrpc_sock __rcu *socket; /* socket responsible */
  414. unsigned long ack_at; /* When deferred ACK needs to happen */
  415. unsigned long resend_at; /* When next resend needs to happen */
  416. unsigned long expire_at; /* When the call times out */
  417. struct timer_list timer; /* Combined event timer */
  418. struct work_struct processor; /* Event processor */
  419. rxrpc_notify_rx_t notify_rx; /* kernel service Rx notification function */
  420. struct list_head link; /* link in master call list */
  421. struct list_head chan_wait_link; /* Link in conn->waiting_calls */
  422. struct hlist_node error_link; /* link in error distribution list */
  423. struct list_head accept_link; /* Link in rx->acceptq */
  424. struct list_head recvmsg_link; /* Link in rx->recvmsg_q */
  425. struct list_head sock_link; /* Link in rx->sock_calls */
  426. struct rb_node sock_node; /* Node in rx->calls */
  427. struct sk_buff *tx_pending; /* Tx socket buffer being filled */
  428. wait_queue_head_t waitq; /* Wait queue for channel or Tx */
  429. __be32 crypto_buf[2]; /* Temporary packet crypto buffer */
  430. unsigned long user_call_ID; /* user-defined call ID */
  431. unsigned long flags;
  432. unsigned long events;
  433. spinlock_t lock;
  434. rwlock_t state_lock; /* lock for state transition */
  435. u32 abort_code; /* Local/remote abort code */
  436. int error; /* Local error incurred */
  437. enum rxrpc_call_state state; /* current state of call */
  438. enum rxrpc_call_completion completion; /* Call completion condition */
  439. atomic_t usage;
  440. u16 service_id; /* service ID */
  441. u8 security_ix; /* Security type */
  442. u32 call_id; /* call ID on connection */
  443. u32 cid; /* connection ID plus channel index */
  444. int debug_id; /* debug ID for printks */
  445. unsigned short rx_pkt_offset; /* Current recvmsg packet offset */
  446. unsigned short rx_pkt_len; /* Current recvmsg packet len */
  447. /* Rx/Tx circular buffer, depending on phase.
  448. *
  449. * In the Rx phase, packets are annotated with 0 or the number of the
  450. * segment of a jumbo packet each buffer refers to. There can be up to
  451. * 47 segments in a maximum-size UDP packet.
  452. *
  453. * In the Tx phase, packets are annotated with which buffers have been
  454. * acked.
  455. */
  456. #define RXRPC_RXTX_BUFF_SIZE 64
  457. #define RXRPC_RXTX_BUFF_MASK (RXRPC_RXTX_BUFF_SIZE - 1)
  458. #define RXRPC_INIT_RX_WINDOW_SIZE 32
  459. struct sk_buff **rxtx_buffer;
  460. u8 *rxtx_annotations;
  461. #define RXRPC_TX_ANNO_ACK 0
  462. #define RXRPC_TX_ANNO_UNACK 1
  463. #define RXRPC_TX_ANNO_NAK 2
  464. #define RXRPC_TX_ANNO_RETRANS 3
  465. #define RXRPC_TX_ANNO_MASK 0x03
  466. #define RXRPC_TX_ANNO_LAST 0x04
  467. #define RXRPC_TX_ANNO_RESENT 0x08
  468. #define RXRPC_RX_ANNO_JUMBO 0x3f /* Jumbo subpacket number + 1 if not zero */
  469. #define RXRPC_RX_ANNO_JLAST 0x40 /* Set if last element of a jumbo packet */
  470. #define RXRPC_RX_ANNO_VERIFIED 0x80 /* Set if verified and decrypted */
  471. rxrpc_seq_t tx_hard_ack; /* Dead slot in buffer; the first transmitted but
  472. * not hard-ACK'd packet follows this.
  473. */
  474. rxrpc_seq_t tx_top; /* Highest Tx slot allocated. */
  475. rxrpc_seq_t rx_hard_ack; /* Dead slot in buffer; the first received but not
  476. * consumed packet follows this.
  477. */
  478. rxrpc_seq_t rx_top; /* Highest Rx slot allocated. */
  479. rxrpc_seq_t rx_expect_next; /* Expected next packet sequence number */
  480. u8 rx_winsize; /* Size of Rx window */
  481. u8 tx_winsize; /* Maximum size of Tx window */
  482. bool tx_phase; /* T if transmission phase, F if receive phase */
  483. u8 nr_jumbo_bad; /* Number of jumbo dups/exceeds-windows */
  484. /* receive-phase ACK management */
  485. u8 ackr_reason; /* reason to ACK */
  486. u16 ackr_skew; /* skew on packet being ACK'd */
  487. rxrpc_serial_t ackr_serial; /* serial of packet being ACK'd */
  488. rxrpc_seq_t ackr_prev_seq; /* previous sequence number received */
  489. rxrpc_serial_t ackr_ping; /* Last ping sent */
  490. ktime_t ackr_ping_time; /* Time last ping sent */
  491. /* transmission-phase ACK management */
  492. rxrpc_serial_t acks_latest; /* serial number of latest ACK received */
  493. };
  494. enum rxrpc_skb_trace {
  495. rxrpc_skb_rx_cleaned,
  496. rxrpc_skb_rx_freed,
  497. rxrpc_skb_rx_got,
  498. rxrpc_skb_rx_lost,
  499. rxrpc_skb_rx_received,
  500. rxrpc_skb_rx_rotated,
  501. rxrpc_skb_rx_purged,
  502. rxrpc_skb_rx_seen,
  503. rxrpc_skb_tx_cleaned,
  504. rxrpc_skb_tx_freed,
  505. rxrpc_skb_tx_got,
  506. rxrpc_skb_tx_lost,
  507. rxrpc_skb_tx_new,
  508. rxrpc_skb_tx_rotated,
  509. rxrpc_skb_tx_seen,
  510. rxrpc_skb__nr_trace
  511. };
  512. extern const char rxrpc_skb_traces[rxrpc_skb__nr_trace][7];
  513. enum rxrpc_conn_trace {
  514. rxrpc_conn_new_client,
  515. rxrpc_conn_new_service,
  516. rxrpc_conn_queued,
  517. rxrpc_conn_seen,
  518. rxrpc_conn_got,
  519. rxrpc_conn_put_client,
  520. rxrpc_conn_put_service,
  521. rxrpc_conn__nr_trace
  522. };
  523. extern const char rxrpc_conn_traces[rxrpc_conn__nr_trace][4];
  524. enum rxrpc_client_trace {
  525. rxrpc_client_activate_chans,
  526. rxrpc_client_alloc,
  527. rxrpc_client_chan_activate,
  528. rxrpc_client_chan_disconnect,
  529. rxrpc_client_chan_pass,
  530. rxrpc_client_chan_unstarted,
  531. rxrpc_client_cleanup,
  532. rxrpc_client_count,
  533. rxrpc_client_discard,
  534. rxrpc_client_duplicate,
  535. rxrpc_client_exposed,
  536. rxrpc_client_replace,
  537. rxrpc_client_to_active,
  538. rxrpc_client_to_culled,
  539. rxrpc_client_to_idle,
  540. rxrpc_client_to_inactive,
  541. rxrpc_client_to_waiting,
  542. rxrpc_client_uncount,
  543. rxrpc_client__nr_trace
  544. };
  545. extern const char rxrpc_client_traces[rxrpc_client__nr_trace][7];
  546. extern const char rxrpc_conn_cache_states[RXRPC_CONN__NR_CACHE_STATES][5];
  547. enum rxrpc_call_trace {
  548. rxrpc_call_new_client,
  549. rxrpc_call_new_service,
  550. rxrpc_call_queued,
  551. rxrpc_call_queued_ref,
  552. rxrpc_call_seen,
  553. rxrpc_call_connected,
  554. rxrpc_call_release,
  555. rxrpc_call_got,
  556. rxrpc_call_got_userid,
  557. rxrpc_call_got_kernel,
  558. rxrpc_call_put,
  559. rxrpc_call_put_userid,
  560. rxrpc_call_put_kernel,
  561. rxrpc_call_put_noqueue,
  562. rxrpc_call_error,
  563. rxrpc_call__nr_trace
  564. };
  565. extern const char rxrpc_call_traces[rxrpc_call__nr_trace][4];
  566. enum rxrpc_transmit_trace {
  567. rxrpc_transmit_wait,
  568. rxrpc_transmit_queue,
  569. rxrpc_transmit_queue_last,
  570. rxrpc_transmit_rotate,
  571. rxrpc_transmit_rotate_last,
  572. rxrpc_transmit_await_reply,
  573. rxrpc_transmit_end,
  574. rxrpc_transmit__nr_trace
  575. };
  576. extern const char rxrpc_transmit_traces[rxrpc_transmit__nr_trace][4];
  577. enum rxrpc_receive_trace {
  578. rxrpc_receive_incoming,
  579. rxrpc_receive_queue,
  580. rxrpc_receive_queue_last,
  581. rxrpc_receive_front,
  582. rxrpc_receive_rotate,
  583. rxrpc_receive_end,
  584. rxrpc_receive__nr_trace
  585. };
  586. extern const char rxrpc_receive_traces[rxrpc_receive__nr_trace][4];
  587. enum rxrpc_recvmsg_trace {
  588. rxrpc_recvmsg_enter,
  589. rxrpc_recvmsg_wait,
  590. rxrpc_recvmsg_dequeue,
  591. rxrpc_recvmsg_hole,
  592. rxrpc_recvmsg_next,
  593. rxrpc_recvmsg_cont,
  594. rxrpc_recvmsg_full,
  595. rxrpc_recvmsg_data_return,
  596. rxrpc_recvmsg_terminal,
  597. rxrpc_recvmsg_to_be_accepted,
  598. rxrpc_recvmsg_return,
  599. rxrpc_recvmsg__nr_trace
  600. };
  601. extern const char rxrpc_recvmsg_traces[rxrpc_recvmsg__nr_trace][5];
  602. enum rxrpc_rtt_tx_trace {
  603. rxrpc_rtt_tx_ping,
  604. rxrpc_rtt_tx_data,
  605. rxrpc_rtt_tx__nr_trace
  606. };
  607. extern const char rxrpc_rtt_tx_traces[rxrpc_rtt_tx__nr_trace][5];
  608. enum rxrpc_rtt_rx_trace {
  609. rxrpc_rtt_rx_ping_response,
  610. rxrpc_rtt_rx_requested_ack,
  611. rxrpc_rtt_rx__nr_trace
  612. };
  613. extern const char rxrpc_rtt_rx_traces[rxrpc_rtt_rx__nr_trace][5];
  614. extern const char *const rxrpc_pkts[];
  615. extern const char *rxrpc_acks(u8 reason);
  616. #include <trace/events/rxrpc.h>
  617. /*
  618. * af_rxrpc.c
  619. */
  620. extern atomic_t rxrpc_n_tx_skbs, rxrpc_n_rx_skbs;
  621. extern u32 rxrpc_epoch;
  622. extern atomic_t rxrpc_debug_id;
  623. extern struct workqueue_struct *rxrpc_workqueue;
  624. /*
  625. * call_accept.c
  626. */
  627. int rxrpc_service_prealloc(struct rxrpc_sock *, gfp_t);
  628. void rxrpc_discard_prealloc(struct rxrpc_sock *);
  629. struct rxrpc_call *rxrpc_new_incoming_call(struct rxrpc_local *,
  630. struct rxrpc_connection *,
  631. struct sk_buff *);
  632. void rxrpc_accept_incoming_calls(struct rxrpc_local *);
  633. struct rxrpc_call *rxrpc_accept_call(struct rxrpc_sock *, unsigned long,
  634. rxrpc_notify_rx_t);
  635. int rxrpc_reject_call(struct rxrpc_sock *);
  636. /*
  637. * call_event.c
  638. */
  639. void rxrpc_set_timer(struct rxrpc_call *);
  640. void rxrpc_propose_ACK(struct rxrpc_call *, u8, u16, u32, bool, bool);
  641. void rxrpc_process_call(struct work_struct *);
  642. /*
  643. * call_object.c
  644. */
  645. extern const char *const rxrpc_call_states[];
  646. extern const char *const rxrpc_call_completions[];
  647. extern unsigned int rxrpc_max_call_lifetime;
  648. extern struct kmem_cache *rxrpc_call_jar;
  649. extern struct list_head rxrpc_calls;
  650. extern rwlock_t rxrpc_call_lock;
  651. struct rxrpc_call *rxrpc_find_call_by_user_ID(struct rxrpc_sock *, unsigned long);
  652. struct rxrpc_call *rxrpc_alloc_call(gfp_t);
  653. struct rxrpc_call *rxrpc_new_client_call(struct rxrpc_sock *,
  654. struct rxrpc_conn_parameters *,
  655. struct sockaddr_rxrpc *,
  656. unsigned long, gfp_t);
  657. void rxrpc_incoming_call(struct rxrpc_sock *, struct rxrpc_call *,
  658. struct sk_buff *);
  659. void rxrpc_release_call(struct rxrpc_sock *, struct rxrpc_call *);
  660. void rxrpc_release_calls_on_socket(struct rxrpc_sock *);
  661. bool __rxrpc_queue_call(struct rxrpc_call *);
  662. bool rxrpc_queue_call(struct rxrpc_call *);
  663. void rxrpc_see_call(struct rxrpc_call *);
  664. void rxrpc_get_call(struct rxrpc_call *, enum rxrpc_call_trace);
  665. void rxrpc_put_call(struct rxrpc_call *, enum rxrpc_call_trace);
  666. void rxrpc_cleanup_call(struct rxrpc_call *);
  667. void __exit rxrpc_destroy_all_calls(void);
  668. static inline bool rxrpc_is_service_call(const struct rxrpc_call *call)
  669. {
  670. return test_bit(RXRPC_CALL_IS_SERVICE, &call->flags);
  671. }
  672. static inline bool rxrpc_is_client_call(const struct rxrpc_call *call)
  673. {
  674. return !rxrpc_is_service_call(call);
  675. }
  676. /*
  677. * Transition a call to the complete state.
  678. */
  679. static inline bool __rxrpc_set_call_completion(struct rxrpc_call *call,
  680. enum rxrpc_call_completion compl,
  681. u32 abort_code,
  682. int error)
  683. {
  684. if (call->state < RXRPC_CALL_COMPLETE) {
  685. call->abort_code = abort_code;
  686. call->error = error;
  687. call->completion = compl,
  688. call->state = RXRPC_CALL_COMPLETE;
  689. wake_up(&call->waitq);
  690. return true;
  691. }
  692. return false;
  693. }
  694. static inline bool rxrpc_set_call_completion(struct rxrpc_call *call,
  695. enum rxrpc_call_completion compl,
  696. u32 abort_code,
  697. int error)
  698. {
  699. bool ret;
  700. write_lock_bh(&call->state_lock);
  701. ret = __rxrpc_set_call_completion(call, compl, abort_code, error);
  702. write_unlock_bh(&call->state_lock);
  703. return ret;
  704. }
  705. /*
  706. * Record that a call successfully completed.
  707. */
  708. static inline bool __rxrpc_call_completed(struct rxrpc_call *call)
  709. {
  710. return __rxrpc_set_call_completion(call, RXRPC_CALL_SUCCEEDED, 0, 0);
  711. }
  712. static inline bool rxrpc_call_completed(struct rxrpc_call *call)
  713. {
  714. bool ret;
  715. write_lock_bh(&call->state_lock);
  716. ret = __rxrpc_call_completed(call);
  717. write_unlock_bh(&call->state_lock);
  718. return ret;
  719. }
  720. /*
  721. * Record that a call is locally aborted.
  722. */
  723. static inline bool __rxrpc_abort_call(const char *why, struct rxrpc_call *call,
  724. rxrpc_seq_t seq,
  725. u32 abort_code, int error)
  726. {
  727. trace_rxrpc_abort(why, call->cid, call->call_id, seq,
  728. abort_code, error);
  729. return __rxrpc_set_call_completion(call, RXRPC_CALL_LOCALLY_ABORTED,
  730. abort_code, error);
  731. }
  732. static inline bool rxrpc_abort_call(const char *why, struct rxrpc_call *call,
  733. rxrpc_seq_t seq, u32 abort_code, int error)
  734. {
  735. bool ret;
  736. write_lock_bh(&call->state_lock);
  737. ret = __rxrpc_abort_call(why, call, seq, abort_code, error);
  738. write_unlock_bh(&call->state_lock);
  739. return ret;
  740. }
  741. /*
  742. * conn_client.c
  743. */
  744. extern unsigned int rxrpc_max_client_connections;
  745. extern unsigned int rxrpc_reap_client_connections;
  746. extern unsigned int rxrpc_conn_idle_client_expiry;
  747. extern unsigned int rxrpc_conn_idle_client_fast_expiry;
  748. extern struct idr rxrpc_client_conn_ids;
  749. void rxrpc_destroy_client_conn_ids(void);
  750. int rxrpc_connect_call(struct rxrpc_call *, struct rxrpc_conn_parameters *,
  751. struct sockaddr_rxrpc *, gfp_t);
  752. void rxrpc_expose_client_call(struct rxrpc_call *);
  753. void rxrpc_disconnect_client_call(struct rxrpc_call *);
  754. void rxrpc_put_client_conn(struct rxrpc_connection *);
  755. void __exit rxrpc_destroy_all_client_connections(void);
  756. /*
  757. * conn_event.c
  758. */
  759. void rxrpc_process_connection(struct work_struct *);
  760. /*
  761. * conn_object.c
  762. */
  763. extern unsigned int rxrpc_connection_expiry;
  764. extern struct list_head rxrpc_connections;
  765. extern struct list_head rxrpc_connection_proc_list;
  766. extern rwlock_t rxrpc_connection_lock;
  767. int rxrpc_extract_addr_from_skb(struct sockaddr_rxrpc *, struct sk_buff *);
  768. struct rxrpc_connection *rxrpc_alloc_connection(gfp_t);
  769. struct rxrpc_connection *rxrpc_find_connection_rcu(struct rxrpc_local *,
  770. struct sk_buff *);
  771. void __rxrpc_disconnect_call(struct rxrpc_connection *, struct rxrpc_call *);
  772. void rxrpc_disconnect_call(struct rxrpc_call *);
  773. void rxrpc_kill_connection(struct rxrpc_connection *);
  774. bool rxrpc_queue_conn(struct rxrpc_connection *);
  775. void rxrpc_see_connection(struct rxrpc_connection *);
  776. void rxrpc_get_connection(struct rxrpc_connection *);
  777. struct rxrpc_connection *rxrpc_get_connection_maybe(struct rxrpc_connection *);
  778. void rxrpc_put_service_conn(struct rxrpc_connection *);
  779. void __exit rxrpc_destroy_all_connections(void);
  780. static inline bool rxrpc_conn_is_client(const struct rxrpc_connection *conn)
  781. {
  782. return conn->out_clientflag;
  783. }
  784. static inline bool rxrpc_conn_is_service(const struct rxrpc_connection *conn)
  785. {
  786. return !rxrpc_conn_is_client(conn);
  787. }
  788. static inline void rxrpc_put_connection(struct rxrpc_connection *conn)
  789. {
  790. if (!conn)
  791. return;
  792. if (rxrpc_conn_is_client(conn))
  793. rxrpc_put_client_conn(conn);
  794. else
  795. rxrpc_put_service_conn(conn);
  796. }
  797. /*
  798. * conn_service.c
  799. */
  800. struct rxrpc_connection *rxrpc_find_service_conn_rcu(struct rxrpc_peer *,
  801. struct sk_buff *);
  802. struct rxrpc_connection *rxrpc_prealloc_service_connection(gfp_t);
  803. void rxrpc_new_incoming_connection(struct rxrpc_connection *, struct sk_buff *);
  804. void rxrpc_unpublish_service_conn(struct rxrpc_connection *);
  805. /*
  806. * input.c
  807. */
  808. void rxrpc_data_ready(struct sock *);
  809. /*
  810. * insecure.c
  811. */
  812. extern const struct rxrpc_security rxrpc_no_security;
  813. /*
  814. * key.c
  815. */
  816. extern struct key_type key_type_rxrpc;
  817. extern struct key_type key_type_rxrpc_s;
  818. int rxrpc_request_key(struct rxrpc_sock *, char __user *, int);
  819. int rxrpc_server_keyring(struct rxrpc_sock *, char __user *, int);
  820. int rxrpc_get_server_data_key(struct rxrpc_connection *, const void *, time_t,
  821. u32);
  822. /*
  823. * local_event.c
  824. */
  825. extern void rxrpc_process_local_events(struct rxrpc_local *);
  826. /*
  827. * local_object.c
  828. */
  829. struct rxrpc_local *rxrpc_lookup_local(const struct sockaddr_rxrpc *);
  830. void __rxrpc_put_local(struct rxrpc_local *);
  831. void __exit rxrpc_destroy_all_locals(void);
  832. static inline void rxrpc_get_local(struct rxrpc_local *local)
  833. {
  834. atomic_inc(&local->usage);
  835. }
  836. static inline
  837. struct rxrpc_local *rxrpc_get_local_maybe(struct rxrpc_local *local)
  838. {
  839. return atomic_inc_not_zero(&local->usage) ? local : NULL;
  840. }
  841. static inline void rxrpc_put_local(struct rxrpc_local *local)
  842. {
  843. if (local && atomic_dec_and_test(&local->usage))
  844. __rxrpc_put_local(local);
  845. }
  846. static inline void rxrpc_queue_local(struct rxrpc_local *local)
  847. {
  848. rxrpc_queue_work(&local->processor);
  849. }
  850. /*
  851. * misc.c
  852. */
  853. extern unsigned int rxrpc_max_backlog __read_mostly;
  854. extern unsigned int rxrpc_requested_ack_delay;
  855. extern unsigned int rxrpc_soft_ack_delay;
  856. extern unsigned int rxrpc_idle_ack_delay;
  857. extern unsigned int rxrpc_rx_window_size;
  858. extern unsigned int rxrpc_rx_mtu;
  859. extern unsigned int rxrpc_rx_jumbo_max;
  860. extern unsigned int rxrpc_resend_timeout;
  861. extern const s8 rxrpc_ack_priority[];
  862. /*
  863. * output.c
  864. */
  865. int rxrpc_send_call_packet(struct rxrpc_call *, u8);
  866. int rxrpc_send_data_packet(struct rxrpc_call *, struct sk_buff *);
  867. void rxrpc_reject_packets(struct rxrpc_local *);
  868. /*
  869. * peer_event.c
  870. */
  871. void rxrpc_error_report(struct sock *);
  872. void rxrpc_peer_error_distributor(struct work_struct *);
  873. void rxrpc_peer_add_rtt(struct rxrpc_call *, enum rxrpc_rtt_rx_trace,
  874. rxrpc_serial_t, rxrpc_serial_t, ktime_t, ktime_t);
  875. /*
  876. * peer_object.c
  877. */
  878. struct rxrpc_peer *rxrpc_lookup_peer_rcu(struct rxrpc_local *,
  879. const struct sockaddr_rxrpc *);
  880. struct rxrpc_peer *rxrpc_lookup_peer(struct rxrpc_local *,
  881. struct sockaddr_rxrpc *, gfp_t);
  882. struct rxrpc_peer *rxrpc_alloc_peer(struct rxrpc_local *, gfp_t);
  883. struct rxrpc_peer *rxrpc_lookup_incoming_peer(struct rxrpc_local *,
  884. struct rxrpc_peer *);
  885. static inline struct rxrpc_peer *rxrpc_get_peer(struct rxrpc_peer *peer)
  886. {
  887. atomic_inc(&peer->usage);
  888. return peer;
  889. }
  890. static inline
  891. struct rxrpc_peer *rxrpc_get_peer_maybe(struct rxrpc_peer *peer)
  892. {
  893. return atomic_inc_not_zero(&peer->usage) ? peer : NULL;
  894. }
  895. extern void __rxrpc_put_peer(struct rxrpc_peer *peer);
  896. static inline void rxrpc_put_peer(struct rxrpc_peer *peer)
  897. {
  898. if (peer && atomic_dec_and_test(&peer->usage))
  899. __rxrpc_put_peer(peer);
  900. }
  901. /*
  902. * proc.c
  903. */
  904. extern const struct file_operations rxrpc_call_seq_fops;
  905. extern const struct file_operations rxrpc_connection_seq_fops;
  906. /*
  907. * recvmsg.c
  908. */
  909. void rxrpc_notify_socket(struct rxrpc_call *);
  910. int rxrpc_recvmsg(struct socket *, struct msghdr *, size_t, int);
  911. /*
  912. * rxkad.c
  913. */
  914. #ifdef CONFIG_RXKAD
  915. extern const struct rxrpc_security rxkad;
  916. #endif
  917. /*
  918. * security.c
  919. */
  920. int __init rxrpc_init_security(void);
  921. void rxrpc_exit_security(void);
  922. int rxrpc_init_client_conn_security(struct rxrpc_connection *);
  923. int rxrpc_init_server_conn_security(struct rxrpc_connection *);
  924. /*
  925. * sendmsg.c
  926. */
  927. int rxrpc_do_sendmsg(struct rxrpc_sock *, struct msghdr *, size_t);
  928. /*
  929. * skbuff.c
  930. */
  931. void rxrpc_kernel_data_consumed(struct rxrpc_call *, struct sk_buff *);
  932. void rxrpc_packet_destructor(struct sk_buff *);
  933. void rxrpc_new_skb(struct sk_buff *, enum rxrpc_skb_trace);
  934. void rxrpc_see_skb(struct sk_buff *, enum rxrpc_skb_trace);
  935. void rxrpc_get_skb(struct sk_buff *, enum rxrpc_skb_trace);
  936. void rxrpc_free_skb(struct sk_buff *, enum rxrpc_skb_trace);
  937. void rxrpc_lose_skb(struct sk_buff *, enum rxrpc_skb_trace);
  938. void rxrpc_purge_queue(struct sk_buff_head *);
  939. /*
  940. * sysctl.c
  941. */
  942. #ifdef CONFIG_SYSCTL
  943. extern int __init rxrpc_sysctl_init(void);
  944. extern void rxrpc_sysctl_exit(void);
  945. #else
  946. static inline int __init rxrpc_sysctl_init(void) { return 0; }
  947. static inline void rxrpc_sysctl_exit(void) {}
  948. #endif
  949. /*
  950. * utils.c
  951. */
  952. int rxrpc_extract_addr_from_skb(struct sockaddr_rxrpc *, struct sk_buff *);
  953. static inline bool before(u32 seq1, u32 seq2)
  954. {
  955. return (s32)(seq1 - seq2) < 0;
  956. }
  957. static inline bool before_eq(u32 seq1, u32 seq2)
  958. {
  959. return (s32)(seq1 - seq2) <= 0;
  960. }
  961. static inline bool after(u32 seq1, u32 seq2)
  962. {
  963. return (s32)(seq1 - seq2) > 0;
  964. }
  965. static inline bool after_eq(u32 seq1, u32 seq2)
  966. {
  967. return (s32)(seq1 - seq2) >= 0;
  968. }
  969. /*
  970. * debug tracing
  971. */
  972. extern unsigned int rxrpc_debug;
  973. #define dbgprintk(FMT,...) \
  974. printk("[%-6.6s] "FMT"\n", current->comm ,##__VA_ARGS__)
  975. #define kenter(FMT,...) dbgprintk("==> %s("FMT")",__func__ ,##__VA_ARGS__)
  976. #define kleave(FMT,...) dbgprintk("<== %s()"FMT"",__func__ ,##__VA_ARGS__)
  977. #define kdebug(FMT,...) dbgprintk(" "FMT ,##__VA_ARGS__)
  978. #define kproto(FMT,...) dbgprintk("### "FMT ,##__VA_ARGS__)
  979. #define knet(FMT,...) dbgprintk("@@@ "FMT ,##__VA_ARGS__)
  980. #if defined(__KDEBUG)
  981. #define _enter(FMT,...) kenter(FMT,##__VA_ARGS__)
  982. #define _leave(FMT,...) kleave(FMT,##__VA_ARGS__)
  983. #define _debug(FMT,...) kdebug(FMT,##__VA_ARGS__)
  984. #define _proto(FMT,...) kproto(FMT,##__VA_ARGS__)
  985. #define _net(FMT,...) knet(FMT,##__VA_ARGS__)
  986. #elif defined(CONFIG_AF_RXRPC_DEBUG)
  987. #define RXRPC_DEBUG_KENTER 0x01
  988. #define RXRPC_DEBUG_KLEAVE 0x02
  989. #define RXRPC_DEBUG_KDEBUG 0x04
  990. #define RXRPC_DEBUG_KPROTO 0x08
  991. #define RXRPC_DEBUG_KNET 0x10
  992. #define _enter(FMT,...) \
  993. do { \
  994. if (unlikely(rxrpc_debug & RXRPC_DEBUG_KENTER)) \
  995. kenter(FMT,##__VA_ARGS__); \
  996. } while (0)
  997. #define _leave(FMT,...) \
  998. do { \
  999. if (unlikely(rxrpc_debug & RXRPC_DEBUG_KLEAVE)) \
  1000. kleave(FMT,##__VA_ARGS__); \
  1001. } while (0)
  1002. #define _debug(FMT,...) \
  1003. do { \
  1004. if (unlikely(rxrpc_debug & RXRPC_DEBUG_KDEBUG)) \
  1005. kdebug(FMT,##__VA_ARGS__); \
  1006. } while (0)
  1007. #define _proto(FMT,...) \
  1008. do { \
  1009. if (unlikely(rxrpc_debug & RXRPC_DEBUG_KPROTO)) \
  1010. kproto(FMT,##__VA_ARGS__); \
  1011. } while (0)
  1012. #define _net(FMT,...) \
  1013. do { \
  1014. if (unlikely(rxrpc_debug & RXRPC_DEBUG_KNET)) \
  1015. knet(FMT,##__VA_ARGS__); \
  1016. } while (0)
  1017. #else
  1018. #define _enter(FMT,...) no_printk("==> %s("FMT")",__func__ ,##__VA_ARGS__)
  1019. #define _leave(FMT,...) no_printk("<== %s()"FMT"",__func__ ,##__VA_ARGS__)
  1020. #define _debug(FMT,...) no_printk(" "FMT ,##__VA_ARGS__)
  1021. #define _proto(FMT,...) no_printk("### "FMT ,##__VA_ARGS__)
  1022. #define _net(FMT,...) no_printk("@@@ "FMT ,##__VA_ARGS__)
  1023. #endif
  1024. /*
  1025. * debug assertion checking
  1026. */
  1027. #if 1 // defined(__KDEBUGALL)
  1028. #define ASSERT(X) \
  1029. do { \
  1030. if (unlikely(!(X))) { \
  1031. pr_err("Assertion failed\n"); \
  1032. BUG(); \
  1033. } \
  1034. } while (0)
  1035. #define ASSERTCMP(X, OP, Y) \
  1036. do { \
  1037. __typeof__(X) _x = (X); \
  1038. __typeof__(Y) _y = (__typeof__(X))(Y); \
  1039. if (unlikely(!(_x OP _y))) { \
  1040. pr_err("Assertion failed - %lu(0x%lx) %s %lu(0x%lx) is false\n", \
  1041. (unsigned long)_x, (unsigned long)_x, #OP, \
  1042. (unsigned long)_y, (unsigned long)_y); \
  1043. BUG(); \
  1044. } \
  1045. } while (0)
  1046. #define ASSERTIF(C, X) \
  1047. do { \
  1048. if (unlikely((C) && !(X))) { \
  1049. pr_err("Assertion failed\n"); \
  1050. BUG(); \
  1051. } \
  1052. } while (0)
  1053. #define ASSERTIFCMP(C, X, OP, Y) \
  1054. do { \
  1055. __typeof__(X) _x = (X); \
  1056. __typeof__(Y) _y = (__typeof__(X))(Y); \
  1057. if (unlikely((C) && !(_x OP _y))) { \
  1058. pr_err("Assertion failed - %lu(0x%lx) %s %lu(0x%lx) is false\n", \
  1059. (unsigned long)_x, (unsigned long)_x, #OP, \
  1060. (unsigned long)_y, (unsigned long)_y); \
  1061. BUG(); \
  1062. } \
  1063. } while (0)
  1064. #else
  1065. #define ASSERT(X) \
  1066. do { \
  1067. } while (0)
  1068. #define ASSERTCMP(X, OP, Y) \
  1069. do { \
  1070. } while (0)
  1071. #define ASSERTIF(C, X) \
  1072. do { \
  1073. } while (0)
  1074. #define ASSERTIFCMP(C, X, OP, Y) \
  1075. do { \
  1076. } while (0)
  1077. #endif /* __KDEBUGALL */