ar-internal.h 42 KB

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