rxrpc.txt 36 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947
  1. ======================
  2. RxRPC NETWORK PROTOCOL
  3. ======================
  4. The RxRPC protocol driver provides a reliable two-phase transport on top of UDP
  5. that can be used to perform RxRPC remote operations. This is done over sockets
  6. of AF_RXRPC family, using sendmsg() and recvmsg() with control data to send and
  7. receive data, aborts and errors.
  8. Contents of this document:
  9. (*) Overview.
  10. (*) RxRPC protocol summary.
  11. (*) AF_RXRPC driver model.
  12. (*) Control messages.
  13. (*) Socket options.
  14. (*) Security.
  15. (*) Example client usage.
  16. (*) Example server usage.
  17. (*) AF_RXRPC kernel interface.
  18. (*) Configurable parameters.
  19. ========
  20. OVERVIEW
  21. ========
  22. RxRPC is a two-layer protocol. There is a session layer which provides
  23. reliable virtual connections using UDP over IPv4 (or IPv6) as the transport
  24. layer, but implements a real network protocol; and there's the presentation
  25. layer which renders structured data to binary blobs and back again using XDR
  26. (as does SunRPC):
  27. +-------------+
  28. | Application |
  29. +-------------+
  30. | XDR | Presentation
  31. +-------------+
  32. | RxRPC | Session
  33. +-------------+
  34. | UDP | Transport
  35. +-------------+
  36. AF_RXRPC provides:
  37. (1) Part of an RxRPC facility for both kernel and userspace applications by
  38. making the session part of it a Linux network protocol (AF_RXRPC).
  39. (2) A two-phase protocol. The client transmits a blob (the request) and then
  40. receives a blob (the reply), and the server receives the request and then
  41. transmits the reply.
  42. (3) Retention of the reusable bits of the transport system set up for one call
  43. to speed up subsequent calls.
  44. (4) A secure protocol, using the Linux kernel's key retention facility to
  45. manage security on the client end. The server end must of necessity be
  46. more active in security negotiations.
  47. AF_RXRPC does not provide XDR marshalling/presentation facilities. That is
  48. left to the application. AF_RXRPC only deals in blobs. Even the operation ID
  49. is just the first four bytes of the request blob, and as such is beyond the
  50. kernel's interest.
  51. Sockets of AF_RXRPC family are:
  52. (1) created as type SOCK_DGRAM;
  53. (2) provided with a protocol of the type of underlying transport they're going
  54. to use - currently only PF_INET is supported.
  55. The Andrew File System (AFS) is an example of an application that uses this and
  56. that has both kernel (filesystem) and userspace (utility) components.
  57. ======================
  58. RXRPC PROTOCOL SUMMARY
  59. ======================
  60. An overview of the RxRPC protocol:
  61. (*) RxRPC sits on top of another networking protocol (UDP is the only option
  62. currently), and uses this to provide network transport. UDP ports, for
  63. example, provide transport endpoints.
  64. (*) RxRPC supports multiple virtual "connections" from any given transport
  65. endpoint, thus allowing the endpoints to be shared, even to the same
  66. remote endpoint.
  67. (*) Each connection goes to a particular "service". A connection may not go
  68. to multiple services. A service may be considered the RxRPC equivalent of
  69. a port number. AF_RXRPC permits multiple services to share an endpoint.
  70. (*) Client-originating packets are marked, thus a transport endpoint can be
  71. shared between client and server connections (connections have a
  72. direction).
  73. (*) Up to a billion connections may be supported concurrently between one
  74. local transport endpoint and one service on one remote endpoint. An RxRPC
  75. connection is described by seven numbers:
  76. Local address }
  77. Local port } Transport (UDP) address
  78. Remote address }
  79. Remote port }
  80. Direction
  81. Connection ID
  82. Service ID
  83. (*) Each RxRPC operation is a "call". A connection may make up to four
  84. billion calls, but only up to four calls may be in progress on a
  85. connection at any one time.
  86. (*) Calls are two-phase and asymmetric: the client sends its request data,
  87. which the service receives; then the service transmits the reply data
  88. which the client receives.
  89. (*) The data blobs are of indefinite size, the end of a phase is marked with a
  90. flag in the packet. The number of packets of data making up one blob may
  91. not exceed 4 billion, however, as this would cause the sequence number to
  92. wrap.
  93. (*) The first four bytes of the request data are the service operation ID.
  94. (*) Security is negotiated on a per-connection basis. The connection is
  95. initiated by the first data packet on it arriving. If security is
  96. requested, the server then issues a "challenge" and then the client
  97. replies with a "response". If the response is successful, the security is
  98. set for the lifetime of that connection, and all subsequent calls made
  99. upon it use that same security. In the event that the server lets a
  100. connection lapse before the client, the security will be renegotiated if
  101. the client uses the connection again.
  102. (*) Calls use ACK packets to handle reliability. Data packets are also
  103. explicitly sequenced per call.
  104. (*) There are two types of positive acknowledgment: hard-ACKs and soft-ACKs.
  105. A hard-ACK indicates to the far side that all the data received to a point
  106. has been received and processed; a soft-ACK indicates that the data has
  107. been received but may yet be discarded and re-requested. The sender may
  108. not discard any transmittable packets until they've been hard-ACK'd.
  109. (*) Reception of a reply data packet implicitly hard-ACK's all the data
  110. packets that make up the request.
  111. (*) An call is complete when the request has been sent, the reply has been
  112. received and the final hard-ACK on the last packet of the reply has
  113. reached the server.
  114. (*) An call may be aborted by either end at any time up to its completion.
  115. =====================
  116. AF_RXRPC DRIVER MODEL
  117. =====================
  118. About the AF_RXRPC driver:
  119. (*) The AF_RXRPC protocol transparently uses internal sockets of the transport
  120. protocol to represent transport endpoints.
  121. (*) AF_RXRPC sockets map onto RxRPC connection bundles. Actual RxRPC
  122. connections are handled transparently. One client socket may be used to
  123. make multiple simultaneous calls to the same service. One server socket
  124. may handle calls from many clients.
  125. (*) Additional parallel client connections will be initiated to support extra
  126. concurrent calls, up to a tunable limit.
  127. (*) Each connection is retained for a certain amount of time [tunable] after
  128. the last call currently using it has completed in case a new call is made
  129. that could reuse it.
  130. (*) Each internal UDP socket is retained [tunable] for a certain amount of
  131. time [tunable] after the last connection using it discarded, in case a new
  132. connection is made that could use it.
  133. (*) A client-side connection is only shared between calls if they have have
  134. the same key struct describing their security (and assuming the calls
  135. would otherwise share the connection). Non-secured calls would also be
  136. able to share connections with each other.
  137. (*) A server-side connection is shared if the client says it is.
  138. (*) ACK'ing is handled by the protocol driver automatically, including ping
  139. replying.
  140. (*) SO_KEEPALIVE automatically pings the other side to keep the connection
  141. alive [TODO].
  142. (*) If an ICMP error is received, all calls affected by that error will be
  143. aborted with an appropriate network error passed through recvmsg().
  144. Interaction with the user of the RxRPC socket:
  145. (*) A socket is made into a server socket by binding an address with a
  146. non-zero service ID.
  147. (*) In the client, sending a request is achieved with one or more sendmsgs,
  148. followed by the reply being received with one or more recvmsgs.
  149. (*) The first sendmsg for a request to be sent from a client contains a tag to
  150. be used in all other sendmsgs or recvmsgs associated with that call. The
  151. tag is carried in the control data.
  152. (*) connect() is used to supply a default destination address for a client
  153. socket. This may be overridden by supplying an alternate address to the
  154. first sendmsg() of a call (struct msghdr::msg_name).
  155. (*) If connect() is called on an unbound client, a random local port will
  156. bound before the operation takes place.
  157. (*) A server socket may also be used to make client calls. To do this, the
  158. first sendmsg() of the call must specify the target address. The server's
  159. transport endpoint is used to send the packets.
  160. (*) Once the application has received the last message associated with a call,
  161. the tag is guaranteed not to be seen again, and so it can be used to pin
  162. client resources. A new call can then be initiated with the same tag
  163. without fear of interference.
  164. (*) In the server, a request is received with one or more recvmsgs, then the
  165. the reply is transmitted with one or more sendmsgs, and then the final ACK
  166. is received with a last recvmsg.
  167. (*) When sending data for a call, sendmsg is given MSG_MORE if there's more
  168. data to come on that call.
  169. (*) When receiving data for a call, recvmsg flags MSG_MORE if there's more
  170. data to come for that call.
  171. (*) When receiving data or messages for a call, MSG_EOR is flagged by recvmsg
  172. to indicate the terminal message for that call.
  173. (*) A call may be aborted by adding an abort control message to the control
  174. data. Issuing an abort terminates the kernel's use of that call's tag.
  175. Any messages waiting in the receive queue for that call will be discarded.
  176. (*) Aborts, busy notifications and challenge packets are delivered by recvmsg,
  177. and control data messages will be set to indicate the context. Receiving
  178. an abort or a busy message terminates the kernel's use of that call's tag.
  179. (*) The control data part of the msghdr struct is used for a number of things:
  180. (*) The tag of the intended or affected call.
  181. (*) Sending or receiving errors, aborts and busy notifications.
  182. (*) Notifications of incoming calls.
  183. (*) Sending debug requests and receiving debug replies [TODO].
  184. (*) When the kernel has received and set up an incoming call, it sends a
  185. message to server application to let it know there's a new call awaiting
  186. its acceptance [recvmsg reports a special control message]. The server
  187. application then uses sendmsg to assign a tag to the new call. Once that
  188. is done, the first part of the request data will be delivered by recvmsg.
  189. (*) The server application has to provide the server socket with a keyring of
  190. secret keys corresponding to the security types it permits. When a secure
  191. connection is being set up, the kernel looks up the appropriate secret key
  192. in the keyring and then sends a challenge packet to the client and
  193. receives a response packet. The kernel then checks the authorisation of
  194. the packet and either aborts the connection or sets up the security.
  195. (*) The name of the key a client will use to secure its communications is
  196. nominated by a socket option.
  197. Notes on recvmsg:
  198. (*) If there's a sequence of data messages belonging to a particular call on
  199. the receive queue, then recvmsg will keep working through them until:
  200. (a) it meets the end of that call's received data,
  201. (b) it meets a non-data message,
  202. (c) it meets a message belonging to a different call, or
  203. (d) it fills the user buffer.
  204. If recvmsg is called in blocking mode, it will keep sleeping, awaiting the
  205. reception of further data, until one of the above four conditions is met.
  206. (2) MSG_PEEK operates similarly, but will return immediately if it has put any
  207. data in the buffer rather than sleeping until it can fill the buffer.
  208. (3) If a data message is only partially consumed in filling a user buffer,
  209. then the remainder of that message will be left on the front of the queue
  210. for the next taker. MSG_TRUNC will never be flagged.
  211. (4) If there is more data to be had on a call (it hasn't copied the last byte
  212. of the last data message in that phase yet), then MSG_MORE will be
  213. flagged.
  214. ================
  215. CONTROL MESSAGES
  216. ================
  217. AF_RXRPC makes use of control messages in sendmsg() and recvmsg() to multiplex
  218. calls, to invoke certain actions and to report certain conditions. These are:
  219. MESSAGE ID SRT DATA MEANING
  220. ======================= === =========== ===============================
  221. RXRPC_USER_CALL_ID sr- User ID App's call specifier
  222. RXRPC_ABORT srt Abort code Abort code to issue/received
  223. RXRPC_ACK -rt n/a Final ACK received
  224. RXRPC_NET_ERROR -rt error num Network error on call
  225. RXRPC_BUSY -rt n/a Call rejected (server busy)
  226. RXRPC_LOCAL_ERROR -rt error num Local error encountered
  227. RXRPC_NEW_CALL -r- n/a New call received
  228. RXRPC_ACCEPT s-- n/a Accept new call
  229. (SRT = usable in Sendmsg / delivered by Recvmsg / Terminal message)
  230. (*) RXRPC_USER_CALL_ID
  231. This is used to indicate the application's call ID. It's an unsigned long
  232. that the app specifies in the client by attaching it to the first data
  233. message or in the server by passing it in association with an RXRPC_ACCEPT
  234. message. recvmsg() passes it in conjunction with all messages except
  235. those of the RXRPC_NEW_CALL message.
  236. (*) RXRPC_ABORT
  237. This is can be used by an application to abort a call by passing it to
  238. sendmsg, or it can be delivered by recvmsg to indicate a remote abort was
  239. received. Either way, it must be associated with an RXRPC_USER_CALL_ID to
  240. specify the call affected. If an abort is being sent, then error EBADSLT
  241. will be returned if there is no call with that user ID.
  242. (*) RXRPC_ACK
  243. This is delivered to a server application to indicate that the final ACK
  244. of a call was received from the client. It will be associated with an
  245. RXRPC_USER_CALL_ID to indicate the call that's now complete.
  246. (*) RXRPC_NET_ERROR
  247. This is delivered to an application to indicate that an ICMP error message
  248. was encountered in the process of trying to talk to the peer. An
  249. errno-class integer value will be included in the control message data
  250. indicating the problem, and an RXRPC_USER_CALL_ID will indicate the call
  251. affected.
  252. (*) RXRPC_BUSY
  253. This is delivered to a client application to indicate that a call was
  254. rejected by the server due to the server being busy. It will be
  255. associated with an RXRPC_USER_CALL_ID to indicate the rejected call.
  256. (*) RXRPC_LOCAL_ERROR
  257. This is delivered to an application to indicate that a local error was
  258. encountered and that a call has been aborted because of it. An
  259. errno-class integer value will be included in the control message data
  260. indicating the problem, and an RXRPC_USER_CALL_ID will indicate the call
  261. affected.
  262. (*) RXRPC_NEW_CALL
  263. This is delivered to indicate to a server application that a new call has
  264. arrived and is awaiting acceptance. No user ID is associated with this,
  265. as a user ID must subsequently be assigned by doing an RXRPC_ACCEPT.
  266. (*) RXRPC_ACCEPT
  267. This is used by a server application to attempt to accept a call and
  268. assign it a user ID. It should be associated with an RXRPC_USER_CALL_ID
  269. to indicate the user ID to be assigned. If there is no call to be
  270. accepted (it may have timed out, been aborted, etc.), then sendmsg will
  271. return error ENODATA. If the user ID is already in use by another call,
  272. then error EBADSLT will be returned.
  273. ==============
  274. SOCKET OPTIONS
  275. ==============
  276. AF_RXRPC sockets support a few socket options at the SOL_RXRPC level:
  277. (*) RXRPC_SECURITY_KEY
  278. This is used to specify the description of the key to be used. The key is
  279. extracted from the calling process's keyrings with request_key() and
  280. should be of "rxrpc" type.
  281. The optval pointer points to the description string, and optlen indicates
  282. how long the string is, without the NUL terminator.
  283. (*) RXRPC_SECURITY_KEYRING
  284. Similar to above but specifies a keyring of server secret keys to use (key
  285. type "keyring"). See the "Security" section.
  286. (*) RXRPC_EXCLUSIVE_CONNECTION
  287. This is used to request that new connections should be used for each call
  288. made subsequently on this socket. optval should be NULL and optlen 0.
  289. (*) RXRPC_MIN_SECURITY_LEVEL
  290. This is used to specify the minimum security level required for calls on
  291. this socket. optval must point to an int containing one of the following
  292. values:
  293. (a) RXRPC_SECURITY_PLAIN
  294. Encrypted checksum only.
  295. (b) RXRPC_SECURITY_AUTH
  296. Encrypted checksum plus packet padded and first eight bytes of packet
  297. encrypted - which includes the actual packet length.
  298. (c) RXRPC_SECURITY_ENCRYPTED
  299. Encrypted checksum plus entire packet padded and encrypted, including
  300. actual packet length.
  301. ========
  302. SECURITY
  303. ========
  304. Currently, only the kerberos 4 equivalent protocol has been implemented
  305. (security index 2 - rxkad). This requires the rxkad module to be loaded and,
  306. on the client, tickets of the appropriate type to be obtained from the AFS
  307. kaserver or the kerberos server and installed as "rxrpc" type keys. This is
  308. normally done using the klog program. An example simple klog program can be
  309. found at:
  310. http://people.redhat.com/~dhowells/rxrpc/klog.c
  311. The payload provided to add_key() on the client should be of the following
  312. form:
  313. struct rxrpc_key_sec2_v1 {
  314. uint16_t security_index; /* 2 */
  315. uint16_t ticket_length; /* length of ticket[] */
  316. uint32_t expiry; /* time at which expires */
  317. uint8_t kvno; /* key version number */
  318. uint8_t __pad[3];
  319. uint8_t session_key[8]; /* DES session key */
  320. uint8_t ticket[0]; /* the encrypted ticket */
  321. };
  322. Where the ticket blob is just appended to the above structure.
  323. For the server, keys of type "rxrpc_s" must be made available to the server.
  324. They have a description of "<serviceID>:<securityIndex>" (eg: "52:2" for an
  325. rxkad key for the AFS VL service). When such a key is created, it should be
  326. given the server's secret key as the instantiation data (see the example
  327. below).
  328. add_key("rxrpc_s", "52:2", secret_key, 8, keyring);
  329. A keyring is passed to the server socket by naming it in a sockopt. The server
  330. socket then looks the server secret keys up in this keyring when secure
  331. incoming connections are made. This can be seen in an example program that can
  332. be found at:
  333. http://people.redhat.com/~dhowells/rxrpc/listen.c
  334. ====================
  335. EXAMPLE CLIENT USAGE
  336. ====================
  337. A client would issue an operation by:
  338. (1) An RxRPC socket is set up by:
  339. client = socket(AF_RXRPC, SOCK_DGRAM, PF_INET);
  340. Where the third parameter indicates the protocol family of the transport
  341. socket used - usually IPv4 but it can also be IPv6 [TODO].
  342. (2) A local address can optionally be bound:
  343. struct sockaddr_rxrpc srx = {
  344. .srx_family = AF_RXRPC,
  345. .srx_service = 0, /* we're a client */
  346. .transport_type = SOCK_DGRAM, /* type of transport socket */
  347. .transport.sin_family = AF_INET,
  348. .transport.sin_port = htons(7000), /* AFS callback */
  349. .transport.sin_address = 0, /* all local interfaces */
  350. };
  351. bind(client, &srx, sizeof(srx));
  352. This specifies the local UDP port to be used. If not given, a random
  353. non-privileged port will be used. A UDP port may be shared between
  354. several unrelated RxRPC sockets. Security is handled on a basis of
  355. per-RxRPC virtual connection.
  356. (3) The security is set:
  357. const char *key = "AFS:cambridge.redhat.com";
  358. setsockopt(client, SOL_RXRPC, RXRPC_SECURITY_KEY, key, strlen(key));
  359. This issues a request_key() to get the key representing the security
  360. context. The minimum security level can be set:
  361. unsigned int sec = RXRPC_SECURITY_ENCRYPTED;
  362. setsockopt(client, SOL_RXRPC, RXRPC_MIN_SECURITY_LEVEL,
  363. &sec, sizeof(sec));
  364. (4) The server to be contacted can then be specified (alternatively this can
  365. be done through sendmsg):
  366. struct sockaddr_rxrpc srx = {
  367. .srx_family = AF_RXRPC,
  368. .srx_service = VL_SERVICE_ID,
  369. .transport_type = SOCK_DGRAM, /* type of transport socket */
  370. .transport.sin_family = AF_INET,
  371. .transport.sin_port = htons(7005), /* AFS volume manager */
  372. .transport.sin_address = ...,
  373. };
  374. connect(client, &srx, sizeof(srx));
  375. (5) The request data should then be posted to the server socket using a series
  376. of sendmsg() calls, each with the following control message attached:
  377. RXRPC_USER_CALL_ID - specifies the user ID for this call
  378. MSG_MORE should be set in msghdr::msg_flags on all but the last part of
  379. the request. Multiple requests may be made simultaneously.
  380. If a call is intended to go to a destination other than the default
  381. specified through connect(), then msghdr::msg_name should be set on the
  382. first request message of that call.
  383. (6) The reply data will then be posted to the server socket for recvmsg() to
  384. pick up. MSG_MORE will be flagged by recvmsg() if there's more reply data
  385. for a particular call to be read. MSG_EOR will be set on the terminal
  386. read for a call.
  387. All data will be delivered with the following control message attached:
  388. RXRPC_USER_CALL_ID - specifies the user ID for this call
  389. If an abort or error occurred, this will be returned in the control data
  390. buffer instead, and MSG_EOR will be flagged to indicate the end of that
  391. call.
  392. ====================
  393. EXAMPLE SERVER USAGE
  394. ====================
  395. A server would be set up to accept operations in the following manner:
  396. (1) An RxRPC socket is created by:
  397. server = socket(AF_RXRPC, SOCK_DGRAM, PF_INET);
  398. Where the third parameter indicates the address type of the transport
  399. socket used - usually IPv4.
  400. (2) Security is set up if desired by giving the socket a keyring with server
  401. secret keys in it:
  402. keyring = add_key("keyring", "AFSkeys", NULL, 0,
  403. KEY_SPEC_PROCESS_KEYRING);
  404. const char secret_key[8] = {
  405. 0xa7, 0x83, 0x8a, 0xcb, 0xc7, 0x83, 0xec, 0x94 };
  406. add_key("rxrpc_s", "52:2", secret_key, 8, keyring);
  407. setsockopt(server, SOL_RXRPC, RXRPC_SECURITY_KEYRING, "AFSkeys", 7);
  408. The keyring can be manipulated after it has been given to the socket. This
  409. permits the server to add more keys, replace keys, etc. whilst it is live.
  410. (2) A local address must then be bound:
  411. struct sockaddr_rxrpc srx = {
  412. .srx_family = AF_RXRPC,
  413. .srx_service = VL_SERVICE_ID, /* RxRPC service ID */
  414. .transport_type = SOCK_DGRAM, /* type of transport socket */
  415. .transport.sin_family = AF_INET,
  416. .transport.sin_port = htons(7000), /* AFS callback */
  417. .transport.sin_address = 0, /* all local interfaces */
  418. };
  419. bind(server, &srx, sizeof(srx));
  420. (3) The server is then set to listen out for incoming calls:
  421. listen(server, 100);
  422. (4) The kernel notifies the server of pending incoming connections by sending
  423. it a message for each. This is received with recvmsg() on the server
  424. socket. It has no data, and has a single dataless control message
  425. attached:
  426. RXRPC_NEW_CALL
  427. The address that can be passed back by recvmsg() at this point should be
  428. ignored since the call for which the message was posted may have gone by
  429. the time it is accepted - in which case the first call still on the queue
  430. will be accepted.
  431. (5) The server then accepts the new call by issuing a sendmsg() with two
  432. pieces of control data and no actual data:
  433. RXRPC_ACCEPT - indicate connection acceptance
  434. RXRPC_USER_CALL_ID - specify user ID for this call
  435. (6) The first request data packet will then be posted to the server socket for
  436. recvmsg() to pick up. At that point, the RxRPC address for the call can
  437. be read from the address fields in the msghdr struct.
  438. Subsequent request data will be posted to the server socket for recvmsg()
  439. to collect as it arrives. All but the last piece of the request data will
  440. be delivered with MSG_MORE flagged.
  441. All data will be delivered with the following control message attached:
  442. RXRPC_USER_CALL_ID - specifies the user ID for this call
  443. (8) The reply data should then be posted to the server socket using a series
  444. of sendmsg() calls, each with the following control messages attached:
  445. RXRPC_USER_CALL_ID - specifies the user ID for this call
  446. MSG_MORE should be set in msghdr::msg_flags on all but the last message
  447. for a particular call.
  448. (9) The final ACK from the client will be posted for retrieval by recvmsg()
  449. when it is received. It will take the form of a dataless message with two
  450. control messages attached:
  451. RXRPC_USER_CALL_ID - specifies the user ID for this call
  452. RXRPC_ACK - indicates final ACK (no data)
  453. MSG_EOR will be flagged to indicate that this is the final message for
  454. this call.
  455. (10) Up to the point the final packet of reply data is sent, the call can be
  456. aborted by calling sendmsg() with a dataless message with the following
  457. control messages attached:
  458. RXRPC_USER_CALL_ID - specifies the user ID for this call
  459. RXRPC_ABORT - indicates abort code (4 byte data)
  460. Any packets waiting in the socket's receive queue will be discarded if
  461. this is issued.
  462. Note that all the communications for a particular service take place through
  463. the one server socket, using control messages on sendmsg() and recvmsg() to
  464. determine the call affected.
  465. =========================
  466. AF_RXRPC KERNEL INTERFACE
  467. =========================
  468. The AF_RXRPC module also provides an interface for use by in-kernel utilities
  469. such as the AFS filesystem. This permits such a utility to:
  470. (1) Use different keys directly on individual client calls on one socket
  471. rather than having to open a whole slew of sockets, one for each key it
  472. might want to use.
  473. (2) Avoid having RxRPC call request_key() at the point of issue of a call or
  474. opening of a socket. Instead the utility is responsible for requesting a
  475. key at the appropriate point. AFS, for instance, would do this during VFS
  476. operations such as open() or unlink(). The key is then handed through
  477. when the call is initiated.
  478. (3) Request the use of something other than GFP_KERNEL to allocate memory.
  479. (4) Avoid the overhead of using the recvmsg() call. RxRPC messages can be
  480. intercepted before they get put into the socket Rx queue and the socket
  481. buffers manipulated directly.
  482. To use the RxRPC facility, a kernel utility must still open an AF_RXRPC socket,
  483. bind an address as appropriate and listen if it's to be a server socket, but
  484. then it passes this to the kernel interface functions.
  485. The kernel interface functions are as follows:
  486. (*) Begin a new client call.
  487. struct rxrpc_call *
  488. rxrpc_kernel_begin_call(struct socket *sock,
  489. struct sockaddr_rxrpc *srx,
  490. struct key *key,
  491. unsigned long user_call_ID,
  492. gfp_t gfp);
  493. This allocates the infrastructure to make a new RxRPC call and assigns
  494. call and connection numbers. The call will be made on the UDP port that
  495. the socket is bound to. The call will go to the destination address of a
  496. connected client socket unless an alternative is supplied (srx is
  497. non-NULL).
  498. If a key is supplied then this will be used to secure the call instead of
  499. the key bound to the socket with the RXRPC_SECURITY_KEY sockopt. Calls
  500. secured in this way will still share connections if at all possible.
  501. The user_call_ID is equivalent to that supplied to sendmsg() in the
  502. control data buffer. It is entirely feasible to use this to point to a
  503. kernel data structure.
  504. If this function is successful, an opaque reference to the RxRPC call is
  505. returned. The caller now holds a reference on this and it must be
  506. properly ended.
  507. (*) End a client call.
  508. void rxrpc_kernel_end_call(struct rxrpc_call *call);
  509. This is used to end a previously begun call. The user_call_ID is expunged
  510. from AF_RXRPC's knowledge and will not be seen again in association with
  511. the specified call.
  512. (*) Send data through a call.
  513. int rxrpc_kernel_send_data(struct rxrpc_call *call, struct msghdr *msg,
  514. size_t len);
  515. This is used to supply either the request part of a client call or the
  516. reply part of a server call. msg.msg_iovlen and msg.msg_iov specify the
  517. data buffers to be used. msg_iov may not be NULL and must point
  518. exclusively to in-kernel virtual addresses. msg.msg_flags may be given
  519. MSG_MORE if there will be subsequent data sends for this call.
  520. The msg must not specify a destination address, control data or any flags
  521. other than MSG_MORE. len is the total amount of data to transmit.
  522. (*) Abort a call.
  523. void rxrpc_kernel_abort_call(struct rxrpc_call *call, u32 abort_code);
  524. This is used to abort a call if it's still in an abortable state. The
  525. abort code specified will be placed in the ABORT message sent.
  526. (*) Intercept received RxRPC messages.
  527. typedef void (*rxrpc_interceptor_t)(struct sock *sk,
  528. unsigned long user_call_ID,
  529. struct sk_buff *skb);
  530. void
  531. rxrpc_kernel_intercept_rx_messages(struct socket *sock,
  532. rxrpc_interceptor_t interceptor);
  533. This installs an interceptor function on the specified AF_RXRPC socket.
  534. All messages that would otherwise wind up in the socket's Rx queue are
  535. then diverted to this function. Note that care must be taken to process
  536. the messages in the right order to maintain DATA message sequentiality.
  537. The interceptor function itself is provided with the address of the socket
  538. and handling the incoming message, the ID assigned by the kernel utility
  539. to the call and the socket buffer containing the message.
  540. The skb->mark field indicates the type of message:
  541. MARK MEANING
  542. =============================== =======================================
  543. RXRPC_SKB_MARK_DATA Data message
  544. RXRPC_SKB_MARK_FINAL_ACK Final ACK received for an incoming call
  545. RXRPC_SKB_MARK_BUSY Client call rejected as server busy
  546. RXRPC_SKB_MARK_REMOTE_ABORT Call aborted by peer
  547. RXRPC_SKB_MARK_NET_ERROR Network error detected
  548. RXRPC_SKB_MARK_LOCAL_ERROR Local error encountered
  549. RXRPC_SKB_MARK_NEW_CALL New incoming call awaiting acceptance
  550. The remote abort message can be probed with rxrpc_kernel_get_abort_code().
  551. The two error messages can be probed with rxrpc_kernel_get_error_number().
  552. A new call can be accepted with rxrpc_kernel_accept_call().
  553. Data messages can have their contents extracted with the usual bunch of
  554. socket buffer manipulation functions. A data message can be determined to
  555. be the last one in a sequence with rxrpc_kernel_is_data_last(). When a
  556. data message has been used up, rxrpc_kernel_data_delivered() should be
  557. called on it..
  558. Non-data messages should be handled to rxrpc_kernel_free_skb() to dispose
  559. of. It is possible to get extra refs on all types of message for later
  560. freeing, but this may pin the state of a call until the message is finally
  561. freed.
  562. (*) Accept an incoming call.
  563. struct rxrpc_call *
  564. rxrpc_kernel_accept_call(struct socket *sock,
  565. unsigned long user_call_ID);
  566. This is used to accept an incoming call and to assign it a call ID. This
  567. function is similar to rxrpc_kernel_begin_call() and calls accepted must
  568. be ended in the same way.
  569. If this function is successful, an opaque reference to the RxRPC call is
  570. returned. The caller now holds a reference on this and it must be
  571. properly ended.
  572. (*) Reject an incoming call.
  573. int rxrpc_kernel_reject_call(struct socket *sock);
  574. This is used to reject the first incoming call on the socket's queue with
  575. a BUSY message. -ENODATA is returned if there were no incoming calls.
  576. Other errors may be returned if the call had been aborted (-ECONNABORTED)
  577. or had timed out (-ETIME).
  578. (*) Record the delivery of a data message and free it.
  579. void rxrpc_kernel_data_delivered(struct sk_buff *skb);
  580. This is used to record a data message as having been delivered and to
  581. update the ACK state for the call. The socket buffer will be freed.
  582. (*) Free a message.
  583. void rxrpc_kernel_free_skb(struct sk_buff *skb);
  584. This is used to free a non-DATA socket buffer intercepted from an AF_RXRPC
  585. socket.
  586. (*) Determine if a data message is the last one on a call.
  587. bool rxrpc_kernel_is_data_last(struct sk_buff *skb);
  588. This is used to determine if a socket buffer holds the last data message
  589. to be received for a call (true will be returned if it does, false
  590. if not).
  591. The data message will be part of the reply on a client call and the
  592. request on an incoming call. In the latter case there will be more
  593. messages, but in the former case there will not.
  594. (*) Get the abort code from an abort message.
  595. u32 rxrpc_kernel_get_abort_code(struct sk_buff *skb);
  596. This is used to extract the abort code from a remote abort message.
  597. (*) Get the error number from a local or network error message.
  598. int rxrpc_kernel_get_error_number(struct sk_buff *skb);
  599. This is used to extract the error number from a message indicating either
  600. a local error occurred or a network error occurred.
  601. (*) Allocate a null key for doing anonymous security.
  602. struct key *rxrpc_get_null_key(const char *keyname);
  603. This is used to allocate a null RxRPC key that can be used to indicate
  604. anonymous security for a particular domain.
  605. =======================
  606. CONFIGURABLE PARAMETERS
  607. =======================
  608. The RxRPC protocol driver has a number of configurable parameters that can be
  609. adjusted through sysctls in /proc/net/rxrpc/:
  610. (*) req_ack_delay
  611. The amount of time in milliseconds after receiving a packet with the
  612. request-ack flag set before we honour the flag and actually send the
  613. requested ack.
  614. Usually the other side won't stop sending packets until the advertised
  615. reception window is full (to a maximum of 255 packets), so delaying the
  616. ACK permits several packets to be ACK'd in one go.
  617. (*) soft_ack_delay
  618. The amount of time in milliseconds after receiving a new packet before we
  619. generate a soft-ACK to tell the sender that it doesn't need to resend.
  620. (*) idle_ack_delay
  621. The amount of time in milliseconds after all the packets currently in the
  622. received queue have been consumed before we generate a hard-ACK to tell
  623. the sender it can free its buffers, assuming no other reason occurs that
  624. we would send an ACK.
  625. (*) resend_timeout
  626. The amount of time in milliseconds after transmitting a packet before we
  627. transmit it again, assuming no ACK is received from the receiver telling
  628. us they got it.
  629. (*) max_call_lifetime
  630. The maximum amount of time in seconds that a call may be in progress
  631. before we preemptively kill it.
  632. (*) dead_call_expiry
  633. The amount of time in seconds before we remove a dead call from the call
  634. list. Dead calls are kept around for a little while for the purpose of
  635. repeating ACK and ABORT packets.
  636. (*) connection_expiry
  637. The amount of time in seconds after a connection was last used before we
  638. remove it from the connection list. Whilst a connection is in existence,
  639. it serves as a placeholder for negotiated security; when it is deleted,
  640. the security must be renegotiated.
  641. (*) transport_expiry
  642. The amount of time in seconds after a transport was last used before we
  643. remove it from the transport list. Whilst a transport is in existence, it
  644. serves to anchor the peer data and keeps the connection ID counter.
  645. (*) rxrpc_rx_window_size
  646. The size of the receive window in packets. This is the maximum number of
  647. unconsumed received packets we're willing to hold in memory for any
  648. particular call.
  649. (*) rxrpc_rx_mtu
  650. The maximum packet MTU size that we're willing to receive in bytes. This
  651. indicates to the peer whether we're willing to accept jumbo packets.
  652. (*) rxrpc_rx_jumbo_max
  653. The maximum number of packets that we're willing to accept in a jumbo
  654. packet. Non-terminal packets in a jumbo packet must contain a four byte
  655. header plus exactly 1412 bytes of data. The terminal packet must contain
  656. a four byte header plus any amount of data. In any event, a jumbo packet
  657. may not exceed rxrpc_rx_mtu in size.