ar-internal.h 60 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702
  1. /* SPDX-License-Identifier: GPL-2.0-or-later */
  2. /* AF_RXRPC internal definitions
  3. *
  4. * Copyright (C) 2007 Red Hat, Inc. All Rights Reserved.
  5. * Written by David Howells (dhowells@redhat.com)
  6. */
  7. #include <linux/atomic.h>
  8. #include <linux/seqlock.h>
  9. #include <linux/win_minmax.h>
  10. #include <net/net_namespace.h>
  11. #include <net/netns/generic.h>
  12. #include <net/sock.h>
  13. #include <net/af_rxrpc.h>
  14. #include <keys/rxrpc-type.h>
  15. #include "protocol.h"
  16. #define FCRYPT_BSIZE 8
  17. struct rxrpc_crypt {
  18. union {
  19. u8 x[FCRYPT_BSIZE];
  20. __be32 n[2];
  21. };
  22. } __attribute__((aligned(8)));
  23. #define rxrpc_queue_work(WS) queue_work(rxrpc_workqueue, (WS))
  24. #define rxrpc_queue_delayed_work(WS,D) \
  25. queue_delayed_work(rxrpc_workqueue, (WS), (D))
  26. struct key_preparsed_payload;
  27. struct rxrpc_connection;
  28. struct rxrpc_txbuf;
  29. struct rxrpc_txqueue;
  30. struct rxgk_context;
  31. /*
  32. * Mark applied to socket buffers in skb->mark. skb->priority is used
  33. * to pass supplementary information.
  34. */
  35. enum rxrpc_skb_mark {
  36. RXRPC_SKB_MARK_PACKET, /* Received packet */
  37. RXRPC_SKB_MARK_ERROR, /* Error notification */
  38. RXRPC_SKB_MARK_CHALLENGE, /* Challenge notification */
  39. RXRPC_SKB_MARK_SERVICE_CONN_SECURED, /* Service connection response has been verified */
  40. RXRPC_SKB_MARK_REJECT_BUSY, /* Reject with BUSY */
  41. RXRPC_SKB_MARK_REJECT_ABORT, /* Reject with ABORT (code in skb->priority) */
  42. RXRPC_SKB_MARK_REJECT_CONN_ABORT, /* Reject with connection ABORT (code in skb->priority) */
  43. };
  44. /*
  45. * sk_state for RxRPC sockets
  46. */
  47. enum {
  48. RXRPC_UNBOUND = 0,
  49. RXRPC_CLIENT_UNBOUND, /* Unbound socket used as client */
  50. RXRPC_CLIENT_BOUND, /* client local address bound */
  51. RXRPC_SERVER_BOUND, /* server local address bound */
  52. RXRPC_SERVER_BOUND2, /* second server local address bound */
  53. RXRPC_SERVER_LISTENING, /* server listening for connections */
  54. RXRPC_SERVER_LISTEN_DISABLED, /* server listening disabled */
  55. RXRPC_CLOSE, /* socket is being closed */
  56. };
  57. /*
  58. * Per-network namespace data.
  59. */
  60. struct rxrpc_net {
  61. struct proc_dir_entry *proc_net; /* Subdir in /proc/net */
  62. u32 epoch; /* Local epoch for detecting local-end reset */
  63. struct list_head calls; /* List of calls active in this namespace */
  64. spinlock_t call_lock; /* Lock for ->calls */
  65. atomic_t nr_calls; /* Count of allocated calls */
  66. atomic_t nr_conns;
  67. struct list_head bundle_proc_list; /* List of bundles for proc */
  68. struct list_head conn_proc_list; /* List of conns in this namespace for proc */
  69. struct list_head service_conns; /* Service conns in this namespace */
  70. rwlock_t conn_lock; /* Lock for ->conn_proc_list, ->service_conns */
  71. struct work_struct service_conn_reaper;
  72. struct timer_list service_conn_reap_timer;
  73. bool live;
  74. atomic_t nr_client_conns;
  75. struct hlist_head local_endpoints;
  76. struct mutex local_mutex; /* Lock for ->local_endpoints */
  77. DECLARE_HASHTABLE (peer_hash, 10);
  78. spinlock_t peer_hash_lock; /* Lock for ->peer_hash */
  79. #define RXRPC_KEEPALIVE_TIME 20 /* NAT keepalive time in seconds */
  80. u8 peer_keepalive_cursor;
  81. time64_t peer_keepalive_base;
  82. struct list_head peer_keepalive[32];
  83. struct list_head peer_keepalive_new;
  84. struct timer_list peer_keepalive_timer;
  85. struct work_struct peer_keepalive_work;
  86. atomic_t stat_tx_data;
  87. atomic_t stat_tx_data_retrans;
  88. atomic_t stat_tx_data_send;
  89. atomic_t stat_tx_data_send_frag;
  90. atomic_t stat_tx_data_send_fail;
  91. atomic_t stat_tx_data_send_msgsize;
  92. atomic_t stat_tx_data_underflow;
  93. atomic_t stat_tx_data_cwnd_reset;
  94. atomic_t stat_rx_data;
  95. atomic_t stat_rx_data_reqack;
  96. atomic_t stat_rx_data_jumbo;
  97. atomic_t stat_tx_ack_fill;
  98. atomic_t stat_tx_ack_send;
  99. atomic_t stat_tx_ack_skip;
  100. atomic_t stat_tx_acks[256];
  101. atomic_t stat_rx_acks[256];
  102. atomic_t stat_tx_jumbo[10];
  103. atomic_t stat_rx_jumbo[10];
  104. atomic_t stat_why_req_ack[9];
  105. atomic_t stat_io_loop;
  106. };
  107. /*
  108. * Service backlog preallocation.
  109. *
  110. * This contains circular buffers of preallocated peers, connections and calls
  111. * for incoming service calls and their head and tail pointers. This allows
  112. * calls to be set up in the data_ready handler, thereby avoiding the need to
  113. * shuffle packets around so much.
  114. */
  115. struct rxrpc_backlog {
  116. unsigned short peer_backlog_head;
  117. unsigned short peer_backlog_tail;
  118. unsigned short conn_backlog_head;
  119. unsigned short conn_backlog_tail;
  120. unsigned short call_backlog_head;
  121. unsigned short call_backlog_tail;
  122. #define RXRPC_BACKLOG_MAX 32
  123. struct rxrpc_peer *peer_backlog[RXRPC_BACKLOG_MAX];
  124. struct rxrpc_connection *conn_backlog[RXRPC_BACKLOG_MAX];
  125. struct rxrpc_call *call_backlog[RXRPC_BACKLOG_MAX];
  126. };
  127. /*
  128. * RxRPC socket definition
  129. */
  130. struct rxrpc_sock {
  131. /* WARNING: sk has to be the first member */
  132. struct sock sk;
  133. const struct rxrpc_kernel_ops *app_ops; /* Table of kernel app notification funcs */
  134. struct rxrpc_local *local; /* local endpoint */
  135. struct rxrpc_backlog *backlog; /* Preallocation for services */
  136. struct sk_buff_head recvmsg_oobq; /* OOB messages for recvmsg to pick up */
  137. struct rb_root pending_oobq; /* OOB messages awaiting userspace to respond to */
  138. u64 oob_id_counter; /* OOB message ID counter */
  139. spinlock_t incoming_lock; /* Incoming call vs service shutdown lock */
  140. struct list_head sock_calls; /* List of calls owned by this socket */
  141. struct list_head to_be_accepted; /* calls awaiting acceptance */
  142. struct list_head recvmsg_q; /* Calls awaiting recvmsg's attention */
  143. spinlock_t recvmsg_lock; /* Lock for recvmsg_q */
  144. struct key *key; /* security for this socket */
  145. struct key *securities; /* list of server security descriptors */
  146. struct rb_root calls; /* User ID -> call mapping */
  147. unsigned long flags;
  148. #define RXRPC_SOCK_CONNECTED 0 /* connect_srx is set */
  149. #define RXRPC_SOCK_MANAGE_RESPONSE 1 /* User wants to manage RESPONSE packets */
  150. rwlock_t call_lock; /* lock for calls */
  151. u32 min_sec_level; /* minimum security level */
  152. #define RXRPC_SECURITY_MAX RXRPC_SECURITY_ENCRYPT
  153. bool exclusive; /* Exclusive connection for a client socket */
  154. u16 second_service; /* Additional service bound to the endpoint */
  155. struct {
  156. /* Service upgrade information */
  157. u16 from; /* Service ID to upgrade (if not 0) */
  158. u16 to; /* service ID to upgrade to */
  159. } service_upgrade;
  160. sa_family_t family; /* Protocol family created with */
  161. struct sockaddr_rxrpc srx; /* Primary Service/local addresses */
  162. struct sockaddr_rxrpc connect_srx; /* Default client address from connect() */
  163. };
  164. #define rxrpc_sk(__sk) container_of((__sk), struct rxrpc_sock, sk)
  165. /*
  166. * CPU-byteorder normalised Rx packet header.
  167. */
  168. struct rxrpc_host_header {
  169. u32 epoch; /* client boot timestamp */
  170. u32 cid; /* connection and channel ID */
  171. u32 callNumber; /* call ID (0 for connection-level packets) */
  172. u32 seq; /* sequence number of pkt in call stream */
  173. u32 serial; /* serial number of pkt sent to network */
  174. u8 type; /* packet type */
  175. u8 flags; /* packet flags */
  176. u8 userStatus; /* app-layer defined status */
  177. u8 securityIndex; /* security protocol ID */
  178. union {
  179. u16 _rsvd; /* reserved */
  180. u16 cksum; /* kerberos security checksum */
  181. };
  182. u16 serviceId; /* service ID */
  183. } __packed;
  184. /*
  185. * RxRPC socket buffer private variables
  186. * - max 48 bytes (struct sk_buff::cb)
  187. */
  188. struct rxrpc_skb_priv {
  189. union {
  190. struct rxrpc_connection *poke_conn; /* Conn referred to (poke packet) */
  191. struct {
  192. u16 offset; /* Offset of data */
  193. u16 len; /* Length of data */
  194. u8 flags;
  195. #define RXRPC_RX_VERIFIED 0x01
  196. };
  197. struct {
  198. rxrpc_seq_t first_ack; /* First packet in acks table */
  199. rxrpc_seq_t prev_ack; /* Highest seq seen */
  200. rxrpc_serial_t acked_serial; /* Packet in response to (or 0) */
  201. u16 nr_acks; /* Number of acks+nacks */
  202. u8 reason; /* Reason for ack */
  203. } ack;
  204. struct {
  205. struct rxrpc_connection *conn; /* Connection referred to */
  206. union {
  207. u32 rxkad_nonce;
  208. };
  209. } chall;
  210. struct {
  211. rxrpc_serial_t challenge_serial;
  212. u32 kvno;
  213. u32 version;
  214. u16 len;
  215. u16 ticket_len;
  216. } resp;
  217. };
  218. struct rxrpc_host_header hdr; /* RxRPC packet header from this packet */
  219. };
  220. #define rxrpc_skb(__skb) ((struct rxrpc_skb_priv *) &(__skb)->cb)
  221. /*
  222. * RxRPC security module interface
  223. */
  224. struct rxrpc_security {
  225. const char *name; /* name of this service */
  226. u8 security_index; /* security type provided */
  227. u32 no_key_abort; /* Abort code indicating no key */
  228. /* Initialise a security service */
  229. int (*init)(void);
  230. /* Clean up a security service */
  231. void (*exit)(void);
  232. /* Parse the information from a server key */
  233. int (*preparse_server_key)(struct key_preparsed_payload *);
  234. /* Clean up the preparse buffer after parsing a server key */
  235. void (*free_preparse_server_key)(struct key_preparsed_payload *);
  236. /* Destroy the payload of a server key */
  237. void (*destroy_server_key)(struct key *);
  238. /* Describe a server key */
  239. void (*describe_server_key)(const struct key *, struct seq_file *);
  240. /* initialise a connection's security */
  241. int (*init_connection_security)(struct rxrpc_connection *,
  242. struct rxrpc_key_token *);
  243. /* Work out how much data we can store in a packet, given an estimate
  244. * of the amount of data remaining and allocate a data buffer.
  245. */
  246. struct rxrpc_txbuf *(*alloc_txbuf)(struct rxrpc_call *call, size_t remaining, gfp_t gfp);
  247. /* impose security on a packet */
  248. int (*secure_packet)(struct rxrpc_call *, struct rxrpc_txbuf *);
  249. /* verify the security on a received packet */
  250. int (*verify_packet)(struct rxrpc_call *, struct sk_buff *);
  251. /* Free crypto request on a call */
  252. void (*free_call_crypto)(struct rxrpc_call *);
  253. /* issue a challenge */
  254. int (*issue_challenge)(struct rxrpc_connection *);
  255. /* Validate a challenge packet */
  256. bool (*validate_challenge)(struct rxrpc_connection *conn,
  257. struct sk_buff *skb);
  258. /* Fill out the cmsg for recvmsg() to pass on a challenge to userspace.
  259. * The security class gets to add additional information.
  260. */
  261. int (*challenge_to_recvmsg)(struct rxrpc_connection *conn,
  262. struct sk_buff *challenge,
  263. struct msghdr *msg);
  264. /* Parse sendmsg() control message and respond to challenge. */
  265. int (*sendmsg_respond_to_challenge)(struct sk_buff *challenge,
  266. struct msghdr *msg);
  267. /* respond to a challenge */
  268. int (*respond_to_challenge)(struct rxrpc_connection *conn,
  269. struct sk_buff *challenge);
  270. /* verify a response */
  271. int (*verify_response)(struct rxrpc_connection *,
  272. struct sk_buff *);
  273. /* clear connection security */
  274. void (*clear)(struct rxrpc_connection *);
  275. /* Default ticket -> key decoder */
  276. int (*default_decode_ticket)(struct rxrpc_connection *conn, struct sk_buff *skb,
  277. unsigned int ticket_offset, unsigned int ticket_len,
  278. struct key **_key);
  279. };
  280. /*
  281. * RxRPC local transport endpoint description
  282. * - owned by a single AF_RXRPC socket
  283. * - pointed to by transport socket struct sk_user_data
  284. */
  285. struct rxrpc_local {
  286. struct rcu_head rcu;
  287. atomic_t active_users; /* Number of users of the local endpoint */
  288. refcount_t ref; /* Number of references to the structure */
  289. struct net *net; /* The network namespace */
  290. struct rxrpc_net *rxnet; /* Our bits in the network namespace */
  291. struct hlist_node link;
  292. struct socket *socket; /* my UDP socket */
  293. struct task_struct *io_thread;
  294. struct completion io_thread_ready; /* Indication that the I/O thread started */
  295. struct page_frag_cache tx_alloc; /* Tx control packet allocation (I/O thread only) */
  296. struct rxrpc_sock *service; /* Service(s) listening on this endpoint */
  297. #ifdef CONFIG_AF_RXRPC_INJECT_RX_DELAY
  298. struct sk_buff_head rx_delay_queue; /* Delay injection queue */
  299. #endif
  300. struct sk_buff_head rx_queue; /* Received packets */
  301. struct list_head conn_attend_q; /* Conns requiring immediate attention */
  302. struct list_head call_attend_q; /* Calls requiring immediate attention */
  303. struct rb_root client_bundles; /* Client connection bundles by socket params */
  304. spinlock_t client_bundles_lock; /* Lock for client_bundles */
  305. bool kill_all_client_conns;
  306. struct list_head idle_client_conns;
  307. struct timer_list client_conn_reap_timer;
  308. unsigned long client_conn_flags;
  309. #define RXRPC_CLIENT_CONN_REAP_TIMER 0 /* The client conn reap timer expired */
  310. spinlock_t lock; /* access lock */
  311. rwlock_t services_lock; /* lock for services list */
  312. int debug_id; /* debug ID for printks */
  313. bool dead;
  314. bool service_closed; /* Service socket closed */
  315. struct idr conn_ids; /* List of connection IDs */
  316. struct list_head new_client_calls; /* Newly created client calls need connection */
  317. spinlock_t client_call_lock; /* Lock for ->new_client_calls */
  318. struct sockaddr_rxrpc srx; /* local address */
  319. union {
  320. /* Provide a kvec table sufficiently large to manage either a
  321. * DATA packet with a maximum set of jumbo subpackets or a PING
  322. * ACK padded out to 64K with zeropages for PMTUD.
  323. */
  324. struct kvec kvec[1 + RXRPC_MAX_NR_JUMBO > 3 + 16 ?
  325. 1 + RXRPC_MAX_NR_JUMBO : 3 + 16];
  326. struct bio_vec bvec[3 + 16];
  327. };
  328. };
  329. /*
  330. * RxRPC remote transport endpoint definition
  331. * - matched by local endpoint, remote port, address and protocol type
  332. */
  333. struct rxrpc_peer {
  334. struct rcu_head rcu; /* This must be first */
  335. refcount_t ref;
  336. unsigned long hash_key;
  337. struct hlist_node hash_link;
  338. struct rxrpc_local *local;
  339. struct hlist_head error_targets; /* targets for net error distribution */
  340. struct rb_root service_conns; /* Service connections */
  341. struct list_head keepalive_link; /* Link in net->peer_keepalive[] */
  342. unsigned long app_data; /* Application data (e.g. afs_server) */
  343. unsigned int last_tx_at; /* Last time packet sent here (time64_t LSW) */
  344. seqlock_t service_conn_lock;
  345. spinlock_t lock; /* access lock */
  346. int debug_id; /* debug ID for printks */
  347. struct sockaddr_rxrpc srx; /* remote address */
  348. /* Path MTU discovery [RFC8899] */
  349. unsigned int pmtud_trial; /* Current MTU probe size */
  350. unsigned int pmtud_good; /* Largest working MTU probe we've tried */
  351. unsigned int pmtud_bad; /* Smallest non-working MTU probe we've tried */
  352. bool pmtud_lost; /* T if MTU probe was lost */
  353. bool pmtud_probing; /* T if we have an active probe outstanding */
  354. bool pmtud_pending; /* T if a call to this peer should send a probe */
  355. u8 pmtud_jumbo; /* Max jumbo packets for the MTU */
  356. bool ackr_adv_pmtud; /* T if the peer advertises path-MTU */
  357. unsigned int ackr_max_data; /* Maximum data advertised by peer */
  358. unsigned int if_mtu; /* Local interface MTU (- hdrsize) for this peer */
  359. unsigned int max_data; /* Maximum packet data capacity for this peer */
  360. unsigned short hdrsize; /* header size (IP + UDP + RxRPC) */
  361. unsigned short tx_seg_max; /* Maximum number of transmissable segments */
  362. /* Calculated RTT cache */
  363. unsigned int recent_srtt_us;
  364. unsigned int recent_rto_us;
  365. u8 cong_ssthresh; /* Congestion slow-start threshold */
  366. };
  367. /*
  368. * Keys for matching a connection.
  369. */
  370. struct rxrpc_conn_proto {
  371. union {
  372. struct {
  373. u32 epoch; /* epoch of this connection */
  374. u32 cid; /* connection ID */
  375. };
  376. u64 index_key;
  377. };
  378. };
  379. struct rxrpc_conn_parameters {
  380. struct rxrpc_local *local; /* Representation of local endpoint */
  381. struct rxrpc_peer *peer; /* Representation of remote endpoint */
  382. struct key *key; /* Security details */
  383. bool exclusive; /* T if conn is exclusive */
  384. bool upgrade; /* T if service ID can be upgraded */
  385. u16 service_id; /* Service ID for this connection */
  386. u32 security_level; /* Security level selected */
  387. };
  388. /*
  389. * Call completion condition (state == RXRPC_CALL_COMPLETE).
  390. */
  391. enum rxrpc_call_completion {
  392. RXRPC_CALL_SUCCEEDED, /* - Normal termination */
  393. RXRPC_CALL_REMOTELY_ABORTED, /* - call aborted by peer */
  394. RXRPC_CALL_LOCALLY_ABORTED, /* - call aborted locally on error or close */
  395. RXRPC_CALL_LOCAL_ERROR, /* - call failed due to local error */
  396. RXRPC_CALL_NETWORK_ERROR, /* - call terminated by network error */
  397. NR__RXRPC_CALL_COMPLETIONS
  398. };
  399. /*
  400. * Bits in the connection flags.
  401. */
  402. enum rxrpc_conn_flag {
  403. RXRPC_CONN_IN_SERVICE_CONNS, /* Conn is in peer->service_conns */
  404. RXRPC_CONN_DONT_REUSE, /* Don't reuse this connection */
  405. RXRPC_CONN_PROBING_FOR_UPGRADE, /* Probing for service upgrade */
  406. RXRPC_CONN_FINAL_ACK_0, /* Need final ACK for channel 0 */
  407. RXRPC_CONN_FINAL_ACK_1, /* Need final ACK for channel 1 */
  408. RXRPC_CONN_FINAL_ACK_2, /* Need final ACK for channel 2 */
  409. RXRPC_CONN_FINAL_ACK_3, /* Need final ACK for channel 3 */
  410. };
  411. #define RXRPC_CONN_FINAL_ACK_MASK ((1UL << RXRPC_CONN_FINAL_ACK_0) | \
  412. (1UL << RXRPC_CONN_FINAL_ACK_1) | \
  413. (1UL << RXRPC_CONN_FINAL_ACK_2) | \
  414. (1UL << RXRPC_CONN_FINAL_ACK_3))
  415. /*
  416. * Events that can be raised upon a connection.
  417. */
  418. enum rxrpc_conn_event {
  419. RXRPC_CONN_EV_CHALLENGE, /* Send challenge packet */
  420. RXRPC_CONN_EV_ABORT_CALLS, /* Abort attached calls */
  421. };
  422. /*
  423. * The connection protocol state.
  424. */
  425. enum rxrpc_conn_proto_state {
  426. RXRPC_CONN_UNUSED, /* Connection not yet attempted */
  427. RXRPC_CONN_CLIENT_UNSECURED, /* Client connection needs security init */
  428. RXRPC_CONN_CLIENT, /* Client connection */
  429. RXRPC_CONN_SERVICE_PREALLOC, /* Service connection preallocation */
  430. RXRPC_CONN_SERVICE_UNSECURED, /* Service unsecured connection */
  431. RXRPC_CONN_SERVICE_CHALLENGING, /* Service challenging for security */
  432. RXRPC_CONN_SERVICE, /* Service secured connection */
  433. RXRPC_CONN_ABORTED, /* Conn aborted */
  434. RXRPC_CONN__NR_STATES
  435. };
  436. /*
  437. * RxRPC client connection bundle.
  438. */
  439. struct rxrpc_bundle {
  440. struct rxrpc_local *local; /* Representation of local endpoint */
  441. struct rxrpc_peer *peer; /* Remote endpoint */
  442. struct key *key; /* Security details */
  443. struct list_head proc_link; /* Link in net->bundle_proc_list */
  444. const struct rxrpc_security *security; /* applied security module */
  445. refcount_t ref;
  446. atomic_t active; /* Number of active users */
  447. unsigned int debug_id;
  448. u32 security_level; /* Security level selected */
  449. u16 service_id; /* Service ID for this connection */
  450. bool try_upgrade; /* True if the bundle is attempting upgrade */
  451. bool exclusive; /* T if conn is exclusive */
  452. bool upgrade; /* T if service ID can be upgraded */
  453. unsigned short alloc_error; /* Error from last conn allocation */
  454. struct rb_node local_node; /* Node in local->client_conns */
  455. struct list_head waiting_calls; /* Calls waiting for channels */
  456. unsigned long avail_chans; /* Mask of available channels */
  457. unsigned int conn_ids[4]; /* Connection IDs. */
  458. struct rxrpc_connection *conns[4]; /* The connections in the bundle (max 4) */
  459. };
  460. /*
  461. * RxRPC connection definition
  462. * - matched by { local, peer, epoch, conn_id, direction }
  463. * - each connection can only handle four simultaneous calls
  464. */
  465. struct rxrpc_connection {
  466. struct rxrpc_conn_proto proto;
  467. struct rxrpc_local *local; /* Representation of local endpoint */
  468. struct rxrpc_peer *peer; /* Remote endpoint */
  469. struct rxrpc_net *rxnet; /* Network namespace to which call belongs */
  470. struct key *key; /* Security details */
  471. struct list_head attend_link; /* Link in local->conn_attend_q */
  472. refcount_t ref;
  473. atomic_t active; /* Active count for service conns */
  474. struct rcu_head rcu;
  475. struct list_head cache_link;
  476. unsigned char act_chans; /* Mask of active channels */
  477. struct rxrpc_channel {
  478. unsigned long final_ack_at; /* Time at which to issue final ACK */
  479. struct rxrpc_call *call; /* Active call */
  480. unsigned int call_debug_id; /* call->debug_id */
  481. u32 call_id; /* ID of current call */
  482. u32 call_counter; /* Call ID counter */
  483. u32 last_call; /* ID of last call */
  484. u8 last_type; /* Type of last packet */
  485. union {
  486. u32 last_seq;
  487. u32 last_abort;
  488. };
  489. } channels[RXRPC_MAXCALLS];
  490. struct timer_list timer; /* Conn event timer */
  491. struct work_struct processor; /* connection event processor */
  492. struct work_struct destructor; /* In-process-context destroyer */
  493. struct rxrpc_bundle *bundle; /* Client connection bundle */
  494. struct rb_node service_node; /* Node in peer->service_conns */
  495. struct list_head proc_link; /* link in procfs list */
  496. struct list_head link; /* link in master connection list */
  497. struct sk_buff_head rx_queue; /* received conn-level packets */
  498. struct page_frag_cache tx_data_alloc; /* Tx DATA packet allocation */
  499. struct mutex tx_data_alloc_lock;
  500. struct mutex security_lock; /* Lock for security management */
  501. const struct rxrpc_security *security; /* applied security module */
  502. union {
  503. struct {
  504. struct crypto_sync_skcipher *cipher; /* encryption handle */
  505. struct rxrpc_crypt csum_iv; /* packet checksum base */
  506. u32 nonce; /* response re-use preventer */
  507. } rxkad;
  508. struct {
  509. struct rxgk_context *keys[4]; /* (Re-)keying buffer */
  510. u64 start_time; /* The start time for TK derivation */
  511. u8 nonce[20]; /* Response re-use preventer */
  512. u32 enctype; /* Kerberos 5 encoding type */
  513. u32 key_number; /* Current key number */
  514. } rxgk;
  515. };
  516. rwlock_t security_use_lock; /* Security use/modification lock */
  517. struct sk_buff *tx_response; /* Response packet to be transmitted */
  518. unsigned long flags;
  519. unsigned long events;
  520. unsigned long idle_timestamp; /* Time at which last became idle */
  521. spinlock_t state_lock; /* state-change lock */
  522. enum rxrpc_conn_proto_state state; /* current state of connection */
  523. enum rxrpc_call_completion completion; /* Completion condition */
  524. s32 abort_code; /* Abort code of connection abort */
  525. int debug_id; /* debug ID for printks */
  526. rxrpc_serial_t tx_serial; /* Outgoing packet serial number counter */
  527. unsigned int hi_serial; /* highest serial number received */
  528. rxrpc_serial_t pmtud_probe; /* Serial of MTU probe (or 0) */
  529. unsigned int pmtud_call; /* ID of call used for probe */
  530. u32 service_id; /* Service ID, possibly upgraded */
  531. u32 security_level; /* Security level selected */
  532. u8 security_ix; /* security type */
  533. u8 out_clientflag; /* RXRPC_CLIENT_INITIATED if we are client */
  534. u8 bundle_shift; /* Index into bundle->avail_chans */
  535. bool exclusive; /* T if conn is exclusive */
  536. bool upgrade; /* T if service ID can be upgraded */
  537. u16 orig_service_id; /* Originally requested service ID */
  538. short error; /* Local error code */
  539. };
  540. static inline bool rxrpc_to_server(const struct rxrpc_skb_priv *sp)
  541. {
  542. return sp->hdr.flags & RXRPC_CLIENT_INITIATED;
  543. }
  544. static inline bool rxrpc_to_client(const struct rxrpc_skb_priv *sp)
  545. {
  546. return !rxrpc_to_server(sp);
  547. }
  548. /*
  549. * Flags in call->flags.
  550. */
  551. enum rxrpc_call_flag {
  552. RXRPC_CALL_RELEASED, /* call has been released - no more message to userspace */
  553. RXRPC_CALL_HAS_USERID, /* has a user ID attached */
  554. RXRPC_CALL_IS_SERVICE, /* Call is service call */
  555. RXRPC_CALL_EXPOSED, /* The call was exposed to the world */
  556. RXRPC_CALL_RX_LAST, /* Received the last packet (at rxtx_top) */
  557. RXRPC_CALL_TX_LAST, /* Last packet in Tx buffer (at rxtx_top) */
  558. RXRPC_CALL_TX_ALL_ACKED, /* Last packet has been hard-acked */
  559. RXRPC_CALL_TX_NO_MORE, /* No more data to transmit (MSG_MORE deasserted) */
  560. RXRPC_CALL_SEND_PING, /* A ping will need to be sent */
  561. RXRPC_CALL_RETRANS_TIMEOUT, /* Retransmission due to timeout occurred */
  562. RXRPC_CALL_BEGAN_RX_TIMER, /* We began the expect_rx_by timer */
  563. RXRPC_CALL_RX_HEARD, /* The peer responded at least once to this call */
  564. RXRPC_CALL_DISCONNECTED, /* The call has been disconnected */
  565. RXRPC_CALL_KERNEL, /* The call was made by the kernel */
  566. RXRPC_CALL_UPGRADE, /* Service upgrade was requested for the call */
  567. RXRPC_CALL_EXCLUSIVE, /* The call uses a once-only connection */
  568. RXRPC_CALL_RX_IS_IDLE, /* recvmsg() is idle - send an ACK */
  569. RXRPC_CALL_RECVMSG_READ_ALL, /* recvmsg() read all of the received data */
  570. RXRPC_CALL_CONN_CHALLENGING, /* The connection is being challenged */
  571. };
  572. /*
  573. * Events that can be raised on a call.
  574. */
  575. enum rxrpc_call_event {
  576. RXRPC_CALL_EV_ACK_LOST, /* ACK may be lost, send ping */
  577. RXRPC_CALL_EV_INITIAL_PING, /* Send initial ping for a new service call */
  578. };
  579. /*
  580. * The states that a call can be in.
  581. */
  582. enum rxrpc_call_state {
  583. RXRPC_CALL_UNINITIALISED,
  584. RXRPC_CALL_CLIENT_AWAIT_CONN, /* - client waiting for connection to become available */
  585. RXRPC_CALL_CLIENT_SEND_REQUEST, /* - client sending request phase */
  586. RXRPC_CALL_CLIENT_AWAIT_REPLY, /* - client awaiting reply */
  587. RXRPC_CALL_CLIENT_RECV_REPLY, /* - client receiving reply phase */
  588. RXRPC_CALL_SERVER_PREALLOC, /* - service preallocation */
  589. RXRPC_CALL_SERVER_RECV_REQUEST, /* - server receiving request */
  590. RXRPC_CALL_SERVER_ACK_REQUEST, /* - server pending ACK of request */
  591. RXRPC_CALL_SERVER_SEND_REPLY, /* - server sending reply */
  592. RXRPC_CALL_SERVER_AWAIT_ACK, /* - server awaiting final ACK */
  593. RXRPC_CALL_COMPLETE, /* - call complete */
  594. NR__RXRPC_CALL_STATES
  595. };
  596. /*
  597. * Call Tx congestion management modes.
  598. */
  599. enum rxrpc_ca_state {
  600. RXRPC_CA_SLOW_START,
  601. RXRPC_CA_CONGEST_AVOIDANCE,
  602. RXRPC_CA_PACKET_LOSS,
  603. RXRPC_CA_FAST_RETRANSMIT,
  604. NR__RXRPC_CA_STATES
  605. } __mode(byte);
  606. /*
  607. * Current purpose of call RACK timer. According to the RACK-TLP protocol
  608. * [RFC8985], the transmission timer (call->rack_timo_at) may only be used for
  609. * one of these at once.
  610. */
  611. enum rxrpc_rack_timer_mode {
  612. RXRPC_CALL_RACKTIMER_OFF, /* Timer not running */
  613. RXRPC_CALL_RACKTIMER_RACK_REORDER, /* RACK reordering timer */
  614. RXRPC_CALL_RACKTIMER_TLP_PTO, /* TLP timeout */
  615. RXRPC_CALL_RACKTIMER_RTO, /* Retransmission timeout */
  616. } __mode(byte);
  617. /*
  618. * RxRPC call definition
  619. * - matched by { connection, call_id }
  620. */
  621. struct rxrpc_call {
  622. struct rcu_head rcu;
  623. struct rxrpc_connection *conn; /* connection carrying call */
  624. struct rxrpc_bundle *bundle; /* Connection bundle to use */
  625. struct rxrpc_peer *peer; /* Peer record for remote address */
  626. struct rxrpc_local *local; /* Representation of local endpoint */
  627. struct rxrpc_sock __rcu *socket; /* socket responsible */
  628. struct rxrpc_net *rxnet; /* Network namespace to which call belongs */
  629. struct key *key; /* Security details */
  630. const struct rxrpc_security *security; /* applied security module */
  631. struct mutex user_mutex; /* User access mutex */
  632. struct sockaddr_rxrpc dest_srx; /* Destination address */
  633. ktime_t delay_ack_at; /* When DELAY ACK needs to happen */
  634. ktime_t rack_timo_at; /* When ACK is figured as lost */
  635. ktime_t ping_at; /* When next to send a ping */
  636. ktime_t keepalive_at; /* When next to send a keepalive ping */
  637. ktime_t expect_rx_by; /* When we expect to get a packet by */
  638. ktime_t expect_req_by; /* When we expect to get a request DATA packet by */
  639. ktime_t expect_term_by; /* When we expect call termination by */
  640. u32 next_rx_timo; /* Timeout for next Rx packet (ms) */
  641. u32 next_req_timo; /* Timeout for next Rx request packet (ms) */
  642. u32 hard_timo; /* Maximum lifetime or 0 (s) */
  643. struct timer_list timer; /* Combined event timer */
  644. struct work_struct destroyer; /* In-process-context destroyer */
  645. rxrpc_notify_rx_t notify_rx; /* kernel service Rx notification function */
  646. struct list_head link; /* link in master call list */
  647. struct list_head wait_link; /* Link in local->new_client_calls */
  648. struct hlist_node error_link; /* link in error distribution list */
  649. struct list_head accept_link; /* Link in rx->acceptq */
  650. struct list_head recvmsg_link; /* Link in rx->recvmsg_q */
  651. struct list_head sock_link; /* Link in rx->sock_calls */
  652. struct rb_node sock_node; /* Node in rx->calls */
  653. struct list_head attend_link; /* Link in local->call_attend_q */
  654. struct rxrpc_txbuf *tx_pending; /* Tx buffer being filled */
  655. wait_queue_head_t waitq; /* Wait queue for channel or Tx */
  656. s64 tx_total_len; /* Total length left to be transmitted (or -1) */
  657. unsigned long user_call_ID; /* user-defined call ID */
  658. unsigned long flags;
  659. unsigned long events;
  660. spinlock_t notify_lock; /* Kernel notification lock */
  661. unsigned int send_abort_why; /* Why the abort [enum rxrpc_abort_reason] */
  662. s32 send_abort; /* Abort code to be sent */
  663. short send_abort_err; /* Error to be associated with the abort */
  664. rxrpc_seq_t send_abort_seq; /* DATA packet that incurred the abort (or 0) */
  665. s32 abort_code; /* Local/remote abort code */
  666. int error; /* Local error incurred */
  667. enum rxrpc_call_state _state; /* Current state of call (needs barrier) */
  668. enum rxrpc_call_completion completion; /* Call completion condition */
  669. refcount_t ref;
  670. u8 security_ix; /* Security type */
  671. enum rxrpc_interruptibility interruptibility; /* At what point call may be interrupted */
  672. u32 call_id; /* call ID on connection */
  673. u32 cid; /* connection ID plus channel index */
  674. u32 security_level; /* Security level selected */
  675. u32 security_enctype; /* Security-specific encoding type (or 0) */
  676. int debug_id; /* debug ID for printks */
  677. unsigned short rx_pkt_offset; /* Current recvmsg packet offset */
  678. unsigned short rx_pkt_len; /* Current recvmsg packet len */
  679. /* Sendmsg data tracking. */
  680. rxrpc_seq_t send_top; /* Highest Tx slot filled by sendmsg. */
  681. struct rxrpc_txqueue *send_queue; /* Queue that sendmsg is writing into */
  682. /* Transmitted data tracking. */
  683. struct rxrpc_txqueue *tx_queue; /* Start of transmission buffers */
  684. struct rxrpc_txqueue *tx_qtail; /* End of transmission buffers */
  685. rxrpc_seq_t tx_qbase; /* First slot in tx_queue */
  686. rxrpc_seq_t tx_bottom; /* First packet in buffer */
  687. rxrpc_seq_t tx_transmitted; /* Highest packet transmitted */
  688. rxrpc_seq_t tx_top; /* Highest Tx slot allocated. */
  689. rxrpc_serial_t tx_last_serial; /* Serial of last DATA transmitted */
  690. u16 tx_backoff; /* Delay to insert due to Tx failure (ms) */
  691. u16 tx_nr_sent; /* Number of packets sent, but unacked */
  692. u16 tx_nr_lost; /* Number of packets marked lost */
  693. u16 tx_nr_resent; /* Number of packets resent, but unacked */
  694. u16 tx_winsize; /* Maximum size of Tx window */
  695. #define RXRPC_TX_MAX_WINDOW 128
  696. u8 tx_jumbo_max; /* Maximum subpkts peer will accept */
  697. ktime_t tx_last_sent; /* Last time a transmission occurred */
  698. /* Received data tracking */
  699. struct sk_buff_head recvmsg_queue; /* Queue of packets ready for recvmsg() */
  700. struct sk_buff_head rx_queue; /* Queue of packets for this call to receive */
  701. struct sk_buff_head rx_oos_queue; /* Queue of out of sequence packets */
  702. rxrpc_seq_t rx_highest_seq; /* Higest sequence number received */
  703. rxrpc_seq_t rx_consumed; /* Highest packet consumed */
  704. rxrpc_serial_t rx_serial; /* Highest serial received for this call */
  705. u8 rx_winsize; /* Size of Rx window */
  706. /* TCP-style slow-start congestion control [RFC5681]. Since the SMSS
  707. * is fixed, we keep these numbers in terms of segments (ie. DATA
  708. * packets) rather than bytes.
  709. */
  710. #define RXRPC_TX_SMSS RXRPC_JUMBO_DATALEN
  711. #define RXRPC_MIN_CWND 4
  712. enum rxrpc_ca_state cong_ca_state; /* Congestion control state */
  713. u8 cong_extra; /* Extra to send for congestion management */
  714. u16 cong_cwnd; /* Congestion window size */
  715. u16 cong_ssthresh; /* Slow-start threshold */
  716. u16 cong_dup_acks; /* Count of ACKs showing missing packets */
  717. u16 cong_cumul_acks; /* Cumulative ACK count */
  718. ktime_t cong_tstamp; /* Last time cwnd was changed */
  719. /* RACK-TLP [RFC8985] state. */
  720. ktime_t rack_xmit_ts; /* Latest transmission timestamp */
  721. ktime_t rack_rtt; /* RTT of most recently ACK'd segment */
  722. ktime_t rack_rtt_ts; /* Timestamp of rack_rtt */
  723. ktime_t rack_reo_wnd; /* Reordering window */
  724. unsigned int rack_reo_wnd_mult; /* Multiplier applied to rack_reo_wnd */
  725. int rack_reo_wnd_persist; /* Num loss recoveries before reset reo_wnd */
  726. rxrpc_seq_t rack_fack; /* Highest sequence so far ACK'd */
  727. rxrpc_seq_t rack_end_seq; /* Highest sequence seen */
  728. rxrpc_seq_t rack_dsack_round; /* DSACK opt recv'd in latest roundtrip */
  729. bool rack_dsack_round_none; /* T if dsack_round is "None" */
  730. bool rack_reordering_seen; /* T if detected reordering event */
  731. enum rxrpc_rack_timer_mode rack_timer_mode; /* Current mode of RACK timer */
  732. bool tlp_is_retrans; /* T if unacked TLP retransmission */
  733. rxrpc_serial_t tlp_serial; /* Serial of TLP probe (or 0 if none in progress) */
  734. rxrpc_seq_t tlp_seq; /* Sequence of TLP probe */
  735. unsigned int tlp_rtt_taken; /* Last time RTT taken */
  736. ktime_t tlp_max_ack_delay; /* Sender budget for max delayed ACK interval */
  737. /* Receive-phase ACK management (ACKs we send). */
  738. u8 ackr_reason; /* reason to ACK */
  739. u16 ackr_sack_base; /* Starting slot in SACK table ring */
  740. rxrpc_seq_t ackr_window; /* Base of SACK window */
  741. rxrpc_seq_t ackr_wtop; /* Base of SACK window */
  742. unsigned int ackr_nr_unacked; /* Number of unacked packets */
  743. atomic_t ackr_nr_consumed; /* Number of packets needing hard ACK */
  744. struct {
  745. #define RXRPC_SACK_SIZE 256
  746. /* SACK table for soft-acked packets */
  747. u8 ackr_sack_table[RXRPC_SACK_SIZE];
  748. } __aligned(8);
  749. /* RTT management */
  750. rxrpc_serial_t rtt_serial[4]; /* Serial number of DATA or PING sent */
  751. ktime_t rtt_sent_at[4]; /* Time packet sent */
  752. unsigned long rtt_avail; /* Mask of available slots in bits 0-3,
  753. * Mask of pending samples in 8-11 */
  754. #define RXRPC_CALL_RTT_AVAIL_MASK 0xf
  755. #define RXRPC_CALL_RTT_PEND_SHIFT 8
  756. /* Transmission-phase ACK management (ACKs we've received). */
  757. ktime_t acks_latest_ts; /* Timestamp of latest ACK received */
  758. rxrpc_seq_t acks_hard_ack; /* Highest sequence hard acked */
  759. rxrpc_seq_t acks_prev_seq; /* Highest previousPacket received */
  760. rxrpc_seq_t acks_lowest_nak; /* Lowest NACK in the buffer (or ==tx_hard_ack) */
  761. rxrpc_serial_t acks_highest_serial; /* Highest serial number ACK'd */
  762. unsigned short acks_nr_sacks; /* Number of soft acks recorded */
  763. unsigned short acks_nr_snacks; /* Number of soft nacks recorded */
  764. /* Calculated RTT cache */
  765. ktime_t rtt_last_req; /* Time of last RTT request */
  766. unsigned int rtt_count; /* Number of samples we've got */
  767. unsigned int rtt_taken; /* Number of samples taken (wrapping) */
  768. struct minmax min_rtt; /* Estimated minimum RTT */
  769. u32 srtt_us; /* smoothed round trip time << 3 in usecs */
  770. u32 mdev_us; /* medium deviation */
  771. u32 mdev_max_us; /* maximal mdev for the last rtt period */
  772. u32 rttvar_us; /* smoothed mdev_max */
  773. u32 rto_us; /* Retransmission timeout in usec */
  774. u8 backoff; /* Backoff timeout (as shift) */
  775. };
  776. /*
  777. * Summary of a new ACK and the changes it made to the Tx buffer packet states.
  778. */
  779. struct rxrpc_ack_summary {
  780. rxrpc_serial_t ack_serial; /* Serial number of ACK */
  781. rxrpc_serial_t acked_serial; /* Serial number ACK'd */
  782. u16 in_flight; /* Number of unreceived transmissions */
  783. u16 nr_new_hacks; /* Number of rotated new ACKs */
  784. u16 nr_new_sacks; /* Number of new soft ACKs in packet */
  785. u16 nr_new_snacks; /* Number of new soft nacks in packet */
  786. u8 ack_reason;
  787. bool new_low_snack:1; /* T if new low soft NACK found */
  788. bool retrans_timeo:1; /* T if reTx due to timeout happened */
  789. bool need_retransmit:1; /* T if we need transmission */
  790. bool rtt_sample_avail:1; /* T if RTT sample available */
  791. bool in_fast_or_rto_recovery:1;
  792. bool exiting_fast_or_rto_recovery:1;
  793. bool tlp_probe_acked:1; /* T if the TLP probe seq was acked */
  794. u8 /*enum rxrpc_congest_change*/ change;
  795. };
  796. /*
  797. * sendmsg() cmsg-specified parameters.
  798. */
  799. enum rxrpc_command {
  800. RXRPC_CMD_SEND_DATA, /* send data message */
  801. RXRPC_CMD_SEND_ABORT, /* request abort generation */
  802. RXRPC_CMD_REJECT_BUSY, /* [server] reject a call as busy */
  803. RXRPC_CMD_CHARGE_ACCEPT, /* [server] charge accept preallocation */
  804. };
  805. struct rxrpc_call_params {
  806. s64 tx_total_len; /* Total Tx data length (if send data) */
  807. unsigned long user_call_ID; /* User's call ID */
  808. struct {
  809. u32 hard; /* Maximum lifetime (sec) */
  810. u32 idle; /* Max time since last data packet (msec) */
  811. u32 normal; /* Max time since last call packet (msec) */
  812. } timeouts;
  813. u8 nr_timeouts; /* Number of timeouts specified */
  814. bool kernel; /* T if kernel is making the call */
  815. enum rxrpc_interruptibility interruptibility; /* How is interruptible is the call? */
  816. };
  817. struct rxrpc_send_params {
  818. struct rxrpc_call_params call;
  819. u32 abort_code; /* Abort code to Tx (if abort) */
  820. enum rxrpc_command command : 8; /* The command to implement */
  821. bool exclusive; /* Shared or exclusive call */
  822. bool upgrade; /* If the connection is upgradeable */
  823. };
  824. /*
  825. * Buffer of data to be output as a packet.
  826. */
  827. struct rxrpc_txbuf {
  828. refcount_t ref;
  829. rxrpc_seq_t seq; /* Sequence number of this packet */
  830. rxrpc_serial_t serial; /* Last serial number transmitted with */
  831. unsigned int call_debug_id;
  832. unsigned int debug_id;
  833. unsigned short len; /* Amount of data in buffer */
  834. unsigned short space; /* Remaining data space */
  835. unsigned short offset; /* Offset of fill point */
  836. unsigned short crypto_header; /* Size of crypto header */
  837. unsigned short sec_header; /* Size of security header */
  838. unsigned short pkt_len; /* Size of packet content */
  839. unsigned short alloc_size; /* Amount of bufferage allocated */
  840. unsigned int flags;
  841. #define RXRPC_TXBUF_WIRE_FLAGS 0xff /* The wire protocol flags */
  842. #define RXRPC_TXBUF_RESENT 0x100 /* Set if has been resent */
  843. __be16 cksum; /* Checksum to go in header */
  844. bool jumboable; /* Can be non-terminal jumbo subpacket */
  845. void *data; /* Data with preceding jumbo header */
  846. };
  847. static inline bool rxrpc_sending_to_server(const struct rxrpc_txbuf *txb)
  848. {
  849. return txb->flags & RXRPC_CLIENT_INITIATED;
  850. }
  851. static inline bool rxrpc_sending_to_client(const struct rxrpc_txbuf *txb)
  852. {
  853. return !rxrpc_sending_to_server(txb);
  854. }
  855. /*
  856. * Transmit queue element, including RACK [RFC8985] per-segment metadata. The
  857. * transmission timestamp is in usec from the base.
  858. */
  859. struct rxrpc_txqueue {
  860. /* Start with the members we want to prefetch. */
  861. struct rxrpc_txqueue *next;
  862. ktime_t xmit_ts_base;
  863. rxrpc_seq_t qbase;
  864. u8 nr_reported_acks; /* Number of segments explicitly acked/nacked */
  865. unsigned long segment_acked; /* Bit-per-buf: Set if ACK'd */
  866. unsigned long segment_lost; /* Bit-per-buf: Set if declared lost */
  867. unsigned long segment_retransmitted; /* Bit-per-buf: Set if retransmitted */
  868. unsigned long rtt_samples; /* Bit-per-buf: Set if available for RTT */
  869. unsigned long ever_retransmitted; /* Bit-per-buf: Set if ever retransmitted */
  870. /* The arrays we want to pack into as few cache lines as possible. */
  871. struct {
  872. #define RXRPC_NR_TXQUEUE BITS_PER_LONG
  873. #define RXRPC_TXQ_MASK (RXRPC_NR_TXQUEUE - 1)
  874. struct rxrpc_txbuf *bufs[RXRPC_NR_TXQUEUE];
  875. unsigned int segment_serial[RXRPC_NR_TXQUEUE];
  876. unsigned int segment_xmit_ts[RXRPC_NR_TXQUEUE];
  877. } ____cacheline_aligned;
  878. };
  879. /*
  880. * Data transmission request.
  881. */
  882. struct rxrpc_send_data_req {
  883. ktime_t now; /* Current time */
  884. struct rxrpc_txqueue *tq; /* Tx queue segment holding first DATA */
  885. rxrpc_seq_t seq; /* Sequence of first data */
  886. int n; /* Number of DATA packets to glue into jumbo */
  887. bool retrans; /* T if this is a retransmission */
  888. bool did_send; /* T if did actually send */
  889. bool tlp_probe; /* T if this is a TLP probe */
  890. int /* enum rxrpc_txdata_trace */ trace;
  891. };
  892. #include <trace/events/rxrpc.h>
  893. /*
  894. * Allocate the next serial number on a connection. 0 must be skipped.
  895. */
  896. static inline rxrpc_serial_t rxrpc_get_next_serial(struct rxrpc_connection *conn)
  897. {
  898. rxrpc_serial_t serial;
  899. serial = conn->tx_serial;
  900. if (serial == 0)
  901. serial = 1;
  902. conn->tx_serial = serial + 1;
  903. return serial;
  904. }
  905. /*
  906. * Allocate the next serial n numbers on a connection. 0 must be skipped.
  907. */
  908. static inline rxrpc_serial_t rxrpc_get_next_serials(struct rxrpc_connection *conn,
  909. unsigned int n)
  910. {
  911. rxrpc_serial_t serial;
  912. serial = conn->tx_serial;
  913. if (serial + n <= n)
  914. serial = 1;
  915. conn->tx_serial = serial + n;
  916. return serial;
  917. }
  918. /*
  919. * af_rxrpc.c
  920. */
  921. extern atomic_t rxrpc_n_rx_skbs;
  922. extern struct workqueue_struct *rxrpc_workqueue;
  923. /*
  924. * call_accept.c
  925. */
  926. int rxrpc_service_prealloc(struct rxrpc_sock *, gfp_t);
  927. void rxrpc_discard_prealloc(struct rxrpc_sock *);
  928. bool rxrpc_new_incoming_call(struct rxrpc_local *local,
  929. struct rxrpc_peer *peer,
  930. struct rxrpc_connection *conn,
  931. struct sockaddr_rxrpc *peer_srx,
  932. struct sk_buff *skb);
  933. int rxrpc_user_charge_accept(struct rxrpc_sock *, unsigned long);
  934. /*
  935. * call_event.c
  936. */
  937. void rxrpc_propose_ping(struct rxrpc_call *call, u32 serial,
  938. enum rxrpc_propose_ack_trace why);
  939. void rxrpc_propose_delay_ACK(struct rxrpc_call *, rxrpc_serial_t,
  940. enum rxrpc_propose_ack_trace);
  941. void rxrpc_resend_tlp(struct rxrpc_call *call);
  942. void rxrpc_transmit_some_data(struct rxrpc_call *call, unsigned int limit,
  943. enum rxrpc_txdata_trace trace);
  944. bool rxrpc_input_call_event(struct rxrpc_call *call);
  945. /*
  946. * call_object.c
  947. */
  948. extern const char *const rxrpc_call_states[];
  949. extern const char *const rxrpc_call_completions[];
  950. extern struct kmem_cache *rxrpc_call_jar;
  951. void rxrpc_poke_call(struct rxrpc_call *call, enum rxrpc_call_poke_trace what);
  952. struct rxrpc_call *rxrpc_find_call_by_user_ID(struct rxrpc_sock *, unsigned long);
  953. struct rxrpc_call *rxrpc_alloc_call(struct rxrpc_sock *, gfp_t, unsigned int);
  954. struct rxrpc_call *rxrpc_new_client_call(struct rxrpc_sock *,
  955. struct rxrpc_conn_parameters *,
  956. struct rxrpc_call_params *, gfp_t,
  957. unsigned int)
  958. __releases(&rx->sk.sk_lock)
  959. __acquires(&call->user_mutex);
  960. void rxrpc_start_call_timer(struct rxrpc_call *call);
  961. void rxrpc_incoming_call(struct rxrpc_sock *, struct rxrpc_call *,
  962. struct sk_buff *);
  963. void rxrpc_release_call(struct rxrpc_sock *, struct rxrpc_call *);
  964. void rxrpc_release_calls_on_socket(struct rxrpc_sock *);
  965. void rxrpc_see_call(struct rxrpc_call *, enum rxrpc_call_trace);
  966. struct rxrpc_call *rxrpc_try_get_call(struct rxrpc_call *, enum rxrpc_call_trace);
  967. void rxrpc_get_call(struct rxrpc_call *, enum rxrpc_call_trace);
  968. void rxrpc_put_call(struct rxrpc_call *, enum rxrpc_call_trace);
  969. void rxrpc_cleanup_call(struct rxrpc_call *);
  970. void rxrpc_destroy_all_calls(struct rxrpc_net *);
  971. static inline bool rxrpc_is_service_call(const struct rxrpc_call *call)
  972. {
  973. return test_bit(RXRPC_CALL_IS_SERVICE, &call->flags);
  974. }
  975. static inline bool rxrpc_is_client_call(const struct rxrpc_call *call)
  976. {
  977. return !rxrpc_is_service_call(call);
  978. }
  979. /*
  980. * call_state.c
  981. */
  982. bool rxrpc_set_call_completion(struct rxrpc_call *call,
  983. enum rxrpc_call_completion compl,
  984. u32 abort_code,
  985. int error);
  986. bool rxrpc_call_completed(struct rxrpc_call *call);
  987. bool rxrpc_abort_call(struct rxrpc_call *call, rxrpc_seq_t seq,
  988. u32 abort_code, int error, enum rxrpc_abort_reason why);
  989. void rxrpc_prefail_call(struct rxrpc_call *call, enum rxrpc_call_completion compl,
  990. int error);
  991. static inline void rxrpc_set_call_state(struct rxrpc_call *call,
  992. enum rxrpc_call_state state)
  993. {
  994. /* Order write of completion info before write of ->state. */
  995. smp_store_release(&call->_state, state);
  996. wake_up(&call->waitq);
  997. }
  998. static inline enum rxrpc_call_state __rxrpc_call_state(const struct rxrpc_call *call)
  999. {
  1000. return call->_state; /* Only inside I/O thread */
  1001. }
  1002. static inline bool __rxrpc_call_is_complete(const struct rxrpc_call *call)
  1003. {
  1004. return __rxrpc_call_state(call) == RXRPC_CALL_COMPLETE;
  1005. }
  1006. static inline enum rxrpc_call_state rxrpc_call_state(const struct rxrpc_call *call)
  1007. {
  1008. /* Order read ->state before read of completion info. */
  1009. return smp_load_acquire(&call->_state);
  1010. }
  1011. static inline bool rxrpc_call_is_complete(const struct rxrpc_call *call)
  1012. {
  1013. return rxrpc_call_state(call) == RXRPC_CALL_COMPLETE;
  1014. }
  1015. static inline bool rxrpc_call_has_failed(const struct rxrpc_call *call)
  1016. {
  1017. return rxrpc_call_is_complete(call) && call->completion != RXRPC_CALL_SUCCEEDED;
  1018. }
  1019. /*
  1020. * conn_client.c
  1021. */
  1022. extern unsigned int rxrpc_reap_client_connections;
  1023. extern unsigned long rxrpc_conn_idle_client_expiry;
  1024. extern unsigned long rxrpc_conn_idle_client_fast_expiry;
  1025. void rxrpc_purge_client_connections(struct rxrpc_local *local);
  1026. struct rxrpc_bundle *rxrpc_get_bundle(struct rxrpc_bundle *, enum rxrpc_bundle_trace);
  1027. void rxrpc_put_bundle(struct rxrpc_bundle *, enum rxrpc_bundle_trace);
  1028. int rxrpc_look_up_bundle(struct rxrpc_call *call, gfp_t gfp);
  1029. void rxrpc_connect_client_calls(struct rxrpc_local *local);
  1030. void rxrpc_expose_client_call(struct rxrpc_call *);
  1031. void rxrpc_disconnect_client_call(struct rxrpc_bundle *, struct rxrpc_call *);
  1032. void rxrpc_deactivate_bundle(struct rxrpc_bundle *bundle);
  1033. void rxrpc_discard_expired_client_conns(struct rxrpc_local *local);
  1034. void rxrpc_clean_up_local_conns(struct rxrpc_local *);
  1035. /*
  1036. * conn_event.c
  1037. */
  1038. void rxrpc_conn_retransmit_call(struct rxrpc_connection *conn, struct sk_buff *skb,
  1039. unsigned int channel);
  1040. int rxrpc_abort_conn(struct rxrpc_connection *conn, struct sk_buff *skb,
  1041. s32 abort_code, int err, enum rxrpc_abort_reason why);
  1042. void rxrpc_process_connection(struct work_struct *);
  1043. void rxrpc_process_delayed_final_acks(struct rxrpc_connection *, bool);
  1044. bool rxrpc_input_conn_packet(struct rxrpc_connection *conn, struct sk_buff *skb);
  1045. void rxrpc_input_conn_event(struct rxrpc_connection *conn, struct sk_buff *skb);
  1046. static inline bool rxrpc_is_conn_aborted(const struct rxrpc_connection *conn)
  1047. {
  1048. /* Order reading the abort info after the state check. */
  1049. return smp_load_acquire(&conn->state) == RXRPC_CONN_ABORTED;
  1050. }
  1051. /*
  1052. * conn_object.c
  1053. */
  1054. extern unsigned int rxrpc_connection_expiry;
  1055. extern unsigned int rxrpc_closed_conn_expiry;
  1056. void rxrpc_poke_conn(struct rxrpc_connection *conn, enum rxrpc_conn_trace why);
  1057. struct rxrpc_connection *rxrpc_alloc_connection(struct rxrpc_net *, gfp_t);
  1058. struct rxrpc_connection *rxrpc_find_client_connection_rcu(struct rxrpc_local *,
  1059. struct sockaddr_rxrpc *,
  1060. struct sk_buff *);
  1061. void __rxrpc_disconnect_call(struct rxrpc_connection *, struct rxrpc_call *);
  1062. void rxrpc_disconnect_call(struct rxrpc_call *);
  1063. void rxrpc_kill_client_conn(struct rxrpc_connection *);
  1064. void rxrpc_queue_conn(struct rxrpc_connection *, enum rxrpc_conn_trace);
  1065. void rxrpc_see_connection(struct rxrpc_connection *, enum rxrpc_conn_trace);
  1066. struct rxrpc_connection *rxrpc_get_connection(struct rxrpc_connection *,
  1067. enum rxrpc_conn_trace);
  1068. struct rxrpc_connection *rxrpc_get_connection_maybe(struct rxrpc_connection *,
  1069. enum rxrpc_conn_trace);
  1070. void rxrpc_put_connection(struct rxrpc_connection *, enum rxrpc_conn_trace);
  1071. void rxrpc_service_connection_reaper(struct work_struct *);
  1072. void rxrpc_destroy_all_connections(struct rxrpc_net *);
  1073. static inline bool rxrpc_conn_is_client(const struct rxrpc_connection *conn)
  1074. {
  1075. return conn->out_clientflag;
  1076. }
  1077. static inline bool rxrpc_conn_is_service(const struct rxrpc_connection *conn)
  1078. {
  1079. return !rxrpc_conn_is_client(conn);
  1080. }
  1081. static inline void rxrpc_reduce_conn_timer(struct rxrpc_connection *conn,
  1082. unsigned long expire_at)
  1083. {
  1084. timer_reduce(&conn->timer, expire_at);
  1085. }
  1086. /*
  1087. * conn_service.c
  1088. */
  1089. struct rxrpc_connection *rxrpc_find_service_conn_rcu(struct rxrpc_peer *,
  1090. struct sk_buff *);
  1091. struct rxrpc_connection *rxrpc_prealloc_service_connection(struct rxrpc_net *, gfp_t);
  1092. void rxrpc_new_incoming_connection(struct rxrpc_sock *, struct rxrpc_connection *,
  1093. const struct rxrpc_security *, struct sk_buff *);
  1094. void rxrpc_unpublish_service_conn(struct rxrpc_connection *);
  1095. /*
  1096. * input.c
  1097. */
  1098. void rxrpc_congestion_degrade(struct rxrpc_call *);
  1099. void rxrpc_input_call_packet(struct rxrpc_call *, struct sk_buff *);
  1100. void rxrpc_implicit_end_call(struct rxrpc_call *, struct sk_buff *);
  1101. /*
  1102. * input_rack.c
  1103. */
  1104. void rxrpc_input_rack_one(struct rxrpc_call *call,
  1105. struct rxrpc_ack_summary *summary,
  1106. struct rxrpc_txqueue *tq,
  1107. unsigned int ix);
  1108. void rxrpc_input_rack(struct rxrpc_call *call,
  1109. struct rxrpc_ack_summary *summary,
  1110. struct rxrpc_txqueue *tq,
  1111. unsigned long new_acks);
  1112. void rxrpc_rack_detect_loss_and_arm_timer(struct rxrpc_call *call,
  1113. struct rxrpc_ack_summary *summary);
  1114. ktime_t rxrpc_tlp_calc_pto(struct rxrpc_call *call, ktime_t now);
  1115. void rxrpc_tlp_send_probe(struct rxrpc_call *call);
  1116. void rxrpc_tlp_process_ack(struct rxrpc_call *call, struct rxrpc_ack_summary *summary);
  1117. void rxrpc_rack_timer_expired(struct rxrpc_call *call, ktime_t overran_by);
  1118. /* Initialise TLP state [RFC8958 7.1]. */
  1119. static inline void rxrpc_tlp_init(struct rxrpc_call *call)
  1120. {
  1121. call->tlp_serial = 0;
  1122. call->tlp_seq = call->acks_hard_ack;
  1123. call->tlp_is_retrans = false;
  1124. }
  1125. /*
  1126. * io_thread.c
  1127. */
  1128. int rxrpc_encap_rcv(struct sock *, struct sk_buff *);
  1129. void rxrpc_error_report(struct sock *);
  1130. bool rxrpc_direct_abort(struct sk_buff *skb, enum rxrpc_abort_reason why,
  1131. s32 abort_code, int err);
  1132. bool rxrpc_direct_conn_abort(struct sk_buff *skb, enum rxrpc_abort_reason why,
  1133. s32 abort_code, int err);
  1134. int rxrpc_io_thread(void *data);
  1135. void rxrpc_post_response(struct rxrpc_connection *conn, struct sk_buff *skb);
  1136. static inline void rxrpc_wake_up_io_thread(struct rxrpc_local *local)
  1137. {
  1138. if (!local->io_thread)
  1139. return;
  1140. wake_up_process(READ_ONCE(local->io_thread));
  1141. }
  1142. static inline bool rxrpc_protocol_error(struct sk_buff *skb, enum rxrpc_abort_reason why)
  1143. {
  1144. return rxrpc_direct_abort(skb, why, RX_PROTOCOL_ERROR, -EPROTO);
  1145. }
  1146. /*
  1147. * insecure.c
  1148. */
  1149. extern const struct rxrpc_security rxrpc_no_security;
  1150. /*
  1151. * key.c
  1152. */
  1153. extern struct key_type key_type_rxrpc;
  1154. int rxrpc_request_key(struct rxrpc_sock *, sockptr_t , int);
  1155. int rxrpc_get_server_data_key(struct rxrpc_connection *, const void *, time64_t,
  1156. u32);
  1157. /*
  1158. * local_event.c
  1159. */
  1160. void rxrpc_gen_version_string(void);
  1161. void rxrpc_send_version_request(struct rxrpc_local *local,
  1162. struct rxrpc_host_header *hdr,
  1163. struct sk_buff *skb);
  1164. /*
  1165. * local_object.c
  1166. */
  1167. void rxrpc_local_dont_fragment(const struct rxrpc_local *local, bool set);
  1168. struct rxrpc_local *rxrpc_lookup_local(struct net *, const struct sockaddr_rxrpc *);
  1169. struct rxrpc_local *rxrpc_get_local(struct rxrpc_local *, enum rxrpc_local_trace);
  1170. struct rxrpc_local *rxrpc_get_local_maybe(struct rxrpc_local *, enum rxrpc_local_trace);
  1171. void rxrpc_put_local(struct rxrpc_local *, enum rxrpc_local_trace);
  1172. struct rxrpc_local *rxrpc_use_local(struct rxrpc_local *, enum rxrpc_local_trace);
  1173. void rxrpc_unuse_local(struct rxrpc_local *, enum rxrpc_local_trace);
  1174. void rxrpc_destroy_local(struct rxrpc_local *local);
  1175. void rxrpc_destroy_all_locals(struct rxrpc_net *);
  1176. static inline bool __rxrpc_use_local(struct rxrpc_local *local,
  1177. enum rxrpc_local_trace why)
  1178. {
  1179. int r, u;
  1180. r = refcount_read(&local->ref);
  1181. u = atomic_fetch_add_unless(&local->active_users, 1, 0);
  1182. trace_rxrpc_local(local->debug_id, why, r, u);
  1183. return u != 0;
  1184. }
  1185. static inline void rxrpc_see_local(struct rxrpc_local *local,
  1186. enum rxrpc_local_trace why)
  1187. {
  1188. int r, u;
  1189. r = refcount_read(&local->ref);
  1190. u = atomic_read(&local->active_users);
  1191. trace_rxrpc_local(local->debug_id, why, r, u);
  1192. }
  1193. /*
  1194. * misc.c
  1195. */
  1196. extern unsigned int rxrpc_max_backlog __read_mostly;
  1197. extern unsigned long rxrpc_soft_ack_delay;
  1198. extern unsigned long rxrpc_idle_ack_delay;
  1199. extern unsigned int rxrpc_rx_window_size;
  1200. extern unsigned int rxrpc_rx_mtu;
  1201. extern unsigned int rxrpc_rx_jumbo_max;
  1202. #ifdef CONFIG_AF_RXRPC_INJECT_RX_DELAY
  1203. extern unsigned long rxrpc_inject_rx_delay;
  1204. #endif
  1205. /*
  1206. * net_ns.c
  1207. */
  1208. extern unsigned int rxrpc_net_id;
  1209. extern struct pernet_operations rxrpc_net_ops;
  1210. static inline struct rxrpc_net *rxrpc_net(struct net *net)
  1211. {
  1212. return net_generic(net, rxrpc_net_id);
  1213. }
  1214. /*
  1215. * out_of_band.c
  1216. */
  1217. void rxrpc_notify_socket_oob(struct rxrpc_call *call, struct sk_buff *skb);
  1218. void rxrpc_add_pending_oob(struct rxrpc_sock *rx, struct sk_buff *skb);
  1219. int rxrpc_sendmsg_oob(struct rxrpc_sock *rx, struct msghdr *msg, size_t len);
  1220. /*
  1221. * output.c
  1222. */
  1223. ssize_t do_udp_sendmsg(struct socket *socket, struct msghdr *msg, size_t len);
  1224. void rxrpc_send_ACK(struct rxrpc_call *call, u8 ack_reason,
  1225. rxrpc_serial_t serial, enum rxrpc_propose_ack_trace why);
  1226. void rxrpc_send_probe_for_pmtud(struct rxrpc_call *call);
  1227. int rxrpc_send_abort_packet(struct rxrpc_call *);
  1228. void rxrpc_send_data_packet(struct rxrpc_call *call, struct rxrpc_send_data_req *req);
  1229. void rxrpc_send_conn_abort(struct rxrpc_connection *conn);
  1230. void rxrpc_reject_packet(struct rxrpc_local *local, struct sk_buff *skb);
  1231. void rxrpc_send_keepalive(struct rxrpc_peer *);
  1232. void rxrpc_send_response(struct rxrpc_connection *conn, struct sk_buff *skb);
  1233. /*
  1234. * peer_event.c
  1235. */
  1236. void rxrpc_input_error(struct rxrpc_local *, struct sk_buff *);
  1237. void rxrpc_peer_keepalive_worker(struct work_struct *);
  1238. void rxrpc_input_probe_for_pmtud(struct rxrpc_connection *conn, rxrpc_serial_t acked_serial,
  1239. bool sendmsg_fail);
  1240. /* Update the last transmission time on a peer for keepalive purposes. */
  1241. static inline void rxrpc_peer_mark_tx(struct rxrpc_peer *peer)
  1242. {
  1243. /* To avoid tearing on 32-bit systems, we only keep the LSW. */
  1244. WRITE_ONCE(peer->last_tx_at, ktime_get_seconds());
  1245. }
  1246. /*
  1247. * peer_object.c
  1248. */
  1249. struct rxrpc_peer *rxrpc_lookup_peer_rcu(struct rxrpc_local *,
  1250. const struct sockaddr_rxrpc *);
  1251. struct rxrpc_peer *rxrpc_lookup_peer(struct rxrpc_local *local,
  1252. struct sockaddr_rxrpc *srx, gfp_t gfp);
  1253. void rxrpc_assess_MTU_size(struct rxrpc_local *local, struct rxrpc_peer *peer);
  1254. struct rxrpc_peer *rxrpc_alloc_peer(struct rxrpc_local *, gfp_t,
  1255. enum rxrpc_peer_trace);
  1256. void rxrpc_new_incoming_peer(struct rxrpc_local *local, struct rxrpc_peer *peer);
  1257. void rxrpc_destroy_all_peers(struct rxrpc_net *);
  1258. struct rxrpc_peer *rxrpc_get_peer(struct rxrpc_peer *, enum rxrpc_peer_trace);
  1259. struct rxrpc_peer *rxrpc_get_peer_maybe(struct rxrpc_peer *, enum rxrpc_peer_trace);
  1260. void rxrpc_put_peer(struct rxrpc_peer *, enum rxrpc_peer_trace);
  1261. /*
  1262. * proc.c
  1263. */
  1264. extern const struct seq_operations rxrpc_call_seq_ops;
  1265. extern const struct seq_operations rxrpc_connection_seq_ops;
  1266. extern const struct seq_operations rxrpc_bundle_seq_ops;
  1267. extern const struct seq_operations rxrpc_peer_seq_ops;
  1268. extern const struct seq_operations rxrpc_local_seq_ops;
  1269. /*
  1270. * recvmsg.c
  1271. */
  1272. void rxrpc_notify_socket(struct rxrpc_call *);
  1273. int rxrpc_recvmsg(struct socket *, struct msghdr *, size_t, int);
  1274. /*
  1275. * Abort a call due to a protocol error.
  1276. */
  1277. static inline int rxrpc_abort_eproto(struct rxrpc_call *call,
  1278. struct sk_buff *skb,
  1279. s32 abort_code,
  1280. enum rxrpc_abort_reason why)
  1281. {
  1282. struct rxrpc_skb_priv *sp = rxrpc_skb(skb);
  1283. rxrpc_abort_call(call, sp->hdr.seq, abort_code, -EPROTO, why);
  1284. return -EPROTO;
  1285. }
  1286. /*
  1287. * rtt.c
  1288. */
  1289. void rxrpc_call_add_rtt(struct rxrpc_call *call, enum rxrpc_rtt_rx_trace why,
  1290. int rtt_slot,
  1291. rxrpc_serial_t send_serial, rxrpc_serial_t resp_serial,
  1292. ktime_t send_time, ktime_t resp_time);
  1293. ktime_t rxrpc_get_rto_backoff(struct rxrpc_call *call, bool retrans);
  1294. void rxrpc_call_init_rtt(struct rxrpc_call *call);
  1295. /*
  1296. * rxgk.c
  1297. */
  1298. extern const struct rxrpc_security rxgk_yfs;
  1299. /*
  1300. * rxkad.c
  1301. */
  1302. #ifdef CONFIG_RXKAD
  1303. extern const struct rxrpc_security rxkad;
  1304. #endif
  1305. /*
  1306. * security.c
  1307. */
  1308. int __init rxrpc_init_security(void);
  1309. const struct rxrpc_security *rxrpc_security_lookup(u8);
  1310. void rxrpc_exit_security(void);
  1311. int rxrpc_init_client_call_security(struct rxrpc_call *);
  1312. int rxrpc_init_client_conn_security(struct rxrpc_connection *);
  1313. const struct rxrpc_security *rxrpc_get_incoming_security(struct rxrpc_sock *,
  1314. struct sk_buff *);
  1315. struct key *rxrpc_look_up_server_security(struct rxrpc_connection *,
  1316. struct sk_buff *, u32, u32);
  1317. /*
  1318. * sendmsg.c
  1319. */
  1320. bool rxrpc_propose_abort(struct rxrpc_call *call, s32 abort_code, int error,
  1321. enum rxrpc_abort_reason why);
  1322. int rxrpc_do_sendmsg(struct rxrpc_sock *, struct msghdr *, size_t);
  1323. /*
  1324. * server_key.c
  1325. */
  1326. extern struct key_type key_type_rxrpc_s;
  1327. int rxrpc_server_keyring(struct rxrpc_sock *, sockptr_t, int);
  1328. /*
  1329. * skbuff.c
  1330. */
  1331. void rxrpc_kernel_data_consumed(struct rxrpc_call *, struct sk_buff *);
  1332. void rxrpc_new_skb(struct sk_buff *, enum rxrpc_skb_trace);
  1333. void rxrpc_see_skb(struct sk_buff *, enum rxrpc_skb_trace);
  1334. void rxrpc_eaten_skb(struct sk_buff *, enum rxrpc_skb_trace);
  1335. void rxrpc_get_skb(struct sk_buff *, enum rxrpc_skb_trace);
  1336. void rxrpc_free_skb(struct sk_buff *, enum rxrpc_skb_trace);
  1337. void rxrpc_purge_queue(struct sk_buff_head *);
  1338. /*
  1339. * stats.c
  1340. */
  1341. int rxrpc_stats_show(struct seq_file *seq, void *v);
  1342. int rxrpc_stats_clear(struct file *file, char *buf, size_t size);
  1343. #define rxrpc_inc_stat(rxnet, s) atomic_inc(&(rxnet)->s)
  1344. #define rxrpc_dec_stat(rxnet, s) atomic_dec(&(rxnet)->s)
  1345. /*
  1346. * sysctl.c
  1347. */
  1348. #ifdef CONFIG_SYSCTL
  1349. extern int __init rxrpc_sysctl_init(void);
  1350. extern void rxrpc_sysctl_exit(void);
  1351. #else
  1352. static inline int __init rxrpc_sysctl_init(void) { return 0; }
  1353. static inline void rxrpc_sysctl_exit(void) {}
  1354. #endif
  1355. /*
  1356. * txbuf.c
  1357. */
  1358. extern atomic_t rxrpc_nr_txbuf;
  1359. struct rxrpc_txbuf *rxrpc_alloc_data_txbuf(struct rxrpc_call *call, size_t data_size,
  1360. size_t data_align, gfp_t gfp);
  1361. void rxrpc_see_txbuf(struct rxrpc_txbuf *txb, enum rxrpc_txbuf_trace what);
  1362. void rxrpc_put_txbuf(struct rxrpc_txbuf *txb, enum rxrpc_txbuf_trace what);
  1363. /*
  1364. * utils.c
  1365. */
  1366. int rxrpc_extract_addr_from_skb(struct sockaddr_rxrpc *, struct sk_buff *);
  1367. static inline bool before(u32 seq1, u32 seq2)
  1368. {
  1369. return (s32)(seq1 - seq2) < 0;
  1370. }
  1371. static inline bool before_eq(u32 seq1, u32 seq2)
  1372. {
  1373. return (s32)(seq1 - seq2) <= 0;
  1374. }
  1375. static inline bool after(u32 seq1, u32 seq2)
  1376. {
  1377. return (s32)(seq1 - seq2) > 0;
  1378. }
  1379. static inline bool after_eq(u32 seq1, u32 seq2)
  1380. {
  1381. return (s32)(seq1 - seq2) >= 0;
  1382. }
  1383. static inline u32 earliest(u32 seq1, u32 seq2)
  1384. {
  1385. return before(seq1, seq2) ? seq1 : seq2;
  1386. }
  1387. static inline u32 latest(u32 seq1, u32 seq2)
  1388. {
  1389. return after(seq1, seq2) ? seq1 : seq2;
  1390. }
  1391. static inline bool rxrpc_seq_in_txq(const struct rxrpc_txqueue *tq, rxrpc_seq_t seq)
  1392. {
  1393. return (seq & (RXRPC_NR_TXQUEUE - 1)) == tq->qbase;
  1394. }
  1395. static inline void rxrpc_queue_rx_call_packet(struct rxrpc_call *call, struct sk_buff *skb)
  1396. {
  1397. rxrpc_get_skb(skb, rxrpc_skb_get_call_rx);
  1398. __skb_queue_tail(&call->rx_queue, skb);
  1399. rxrpc_poke_call(call, rxrpc_call_poke_rx_packet);
  1400. }
  1401. /*
  1402. * Calculate how much space there is for transmitting more DATA packets.
  1403. */
  1404. static inline unsigned int rxrpc_tx_window_space(const struct rxrpc_call *call)
  1405. {
  1406. int winsize = umin(call->tx_winsize, call->cong_cwnd + call->cong_extra);
  1407. int transmitted = call->tx_top - call->tx_bottom;
  1408. return max(winsize - transmitted, 0);
  1409. }
  1410. static inline unsigned int rxrpc_left_out(const struct rxrpc_call *call)
  1411. {
  1412. return call->acks_nr_sacks + call->tx_nr_lost;
  1413. }
  1414. /*
  1415. * Calculate the number of transmitted DATA packets assumed to be in flight
  1416. * [approx RFC6675].
  1417. */
  1418. static inline unsigned int rxrpc_tx_in_flight(const struct rxrpc_call *call)
  1419. {
  1420. return call->tx_nr_sent - rxrpc_left_out(call) + call->tx_nr_resent;
  1421. }
  1422. /*
  1423. * debug tracing
  1424. */
  1425. extern unsigned int rxrpc_debug;
  1426. #define dbgprintk(FMT,...) \
  1427. printk("[%-6.6s] "FMT"\n", current->comm ,##__VA_ARGS__)
  1428. #define kenter(FMT,...) dbgprintk("==> %s("FMT")",__func__ ,##__VA_ARGS__)
  1429. #define kleave(FMT,...) dbgprintk("<== %s()"FMT"",__func__ ,##__VA_ARGS__)
  1430. #define kdebug(FMT,...) dbgprintk(" "FMT ,##__VA_ARGS__)
  1431. #if defined(__KDEBUG)
  1432. #define _enter(FMT,...) kenter(FMT,##__VA_ARGS__)
  1433. #define _leave(FMT,...) kleave(FMT,##__VA_ARGS__)
  1434. #define _debug(FMT,...) kdebug(FMT,##__VA_ARGS__)
  1435. #elif defined(CONFIG_AF_RXRPC_DEBUG)
  1436. #define RXRPC_DEBUG_KENTER 0x01
  1437. #define RXRPC_DEBUG_KLEAVE 0x02
  1438. #define RXRPC_DEBUG_KDEBUG 0x04
  1439. #define _enter(FMT,...) \
  1440. do { \
  1441. if (unlikely(rxrpc_debug & RXRPC_DEBUG_KENTER)) \
  1442. kenter(FMT,##__VA_ARGS__); \
  1443. } while (0)
  1444. #define _leave(FMT,...) \
  1445. do { \
  1446. if (unlikely(rxrpc_debug & RXRPC_DEBUG_KLEAVE)) \
  1447. kleave(FMT,##__VA_ARGS__); \
  1448. } while (0)
  1449. #define _debug(FMT,...) \
  1450. do { \
  1451. if (unlikely(rxrpc_debug & RXRPC_DEBUG_KDEBUG)) \
  1452. kdebug(FMT,##__VA_ARGS__); \
  1453. } while (0)
  1454. #else
  1455. #define _enter(FMT,...) no_printk("==> %s("FMT")",__func__ ,##__VA_ARGS__)
  1456. #define _leave(FMT,...) no_printk("<== %s()"FMT"",__func__ ,##__VA_ARGS__)
  1457. #define _debug(FMT,...) no_printk(" "FMT ,##__VA_ARGS__)
  1458. #endif
  1459. /*
  1460. * debug assertion checking
  1461. */
  1462. #if 1 // defined(__KDEBUGALL)
  1463. #define ASSERT(X) \
  1464. do { \
  1465. if (unlikely(!(X))) { \
  1466. pr_err("Assertion failed\n"); \
  1467. BUG(); \
  1468. } \
  1469. } while (0)
  1470. #define ASSERTCMP(X, OP, Y) \
  1471. do { \
  1472. __typeof__(X) _x = (X); \
  1473. __typeof__(Y) _y = (__typeof__(X))(Y); \
  1474. if (unlikely(!(_x OP _y))) { \
  1475. pr_err("Assertion failed - %lu(0x%lx) %s %lu(0x%lx) is false\n", \
  1476. (unsigned long)_x, (unsigned long)_x, #OP, \
  1477. (unsigned long)_y, (unsigned long)_y); \
  1478. BUG(); \
  1479. } \
  1480. } while (0)
  1481. #define ASSERTIF(C, X) \
  1482. do { \
  1483. if (unlikely((C) && !(X))) { \
  1484. pr_err("Assertion failed\n"); \
  1485. BUG(); \
  1486. } \
  1487. } while (0)
  1488. #define ASSERTIFCMP(C, X, OP, Y) \
  1489. do { \
  1490. __typeof__(X) _x = (X); \
  1491. __typeof__(Y) _y = (__typeof__(X))(Y); \
  1492. if (unlikely((C) && !(_x OP _y))) { \
  1493. pr_err("Assertion failed - %lu(0x%lx) %s %lu(0x%lx) is false\n", \
  1494. (unsigned long)_x, (unsigned long)_x, #OP, \
  1495. (unsigned long)_y, (unsigned long)_y); \
  1496. BUG(); \
  1497. } \
  1498. } while (0)
  1499. #else
  1500. #define ASSERT(X) \
  1501. do { \
  1502. } while (0)
  1503. #define ASSERTCMP(X, OP, Y) \
  1504. do { \
  1505. } while (0)
  1506. #define ASSERTIF(C, X) \
  1507. do { \
  1508. } while (0)
  1509. #define ASSERTIFCMP(C, X, OP, Y) \
  1510. do { \
  1511. } while (0)
  1512. #endif /* __KDEBUGALL */