ar-internal.h 41 KB

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