ar-internal.h 38 KB

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