ar-internal.h 41 KB

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