162306a36Sopenharmony_ci.. SPDX-License-Identifier: GPL-2.0
262306a36Sopenharmony_ci
362306a36Sopenharmony_ci======================
462306a36Sopenharmony_ciRxRPC Network Protocol
562306a36Sopenharmony_ci======================
662306a36Sopenharmony_ci
762306a36Sopenharmony_ciThe RxRPC protocol driver provides a reliable two-phase transport on top of UDP
862306a36Sopenharmony_cithat can be used to perform RxRPC remote operations.  This is done over sockets
962306a36Sopenharmony_ciof AF_RXRPC family, using sendmsg() and recvmsg() with control data to send and
1062306a36Sopenharmony_cireceive data, aborts and errors.
1162306a36Sopenharmony_ci
1262306a36Sopenharmony_ciContents of this document:
1362306a36Sopenharmony_ci
1462306a36Sopenharmony_ci (#) Overview.
1562306a36Sopenharmony_ci
1662306a36Sopenharmony_ci (#) RxRPC protocol summary.
1762306a36Sopenharmony_ci
1862306a36Sopenharmony_ci (#) AF_RXRPC driver model.
1962306a36Sopenharmony_ci
2062306a36Sopenharmony_ci (#) Control messages.
2162306a36Sopenharmony_ci
2262306a36Sopenharmony_ci (#) Socket options.
2362306a36Sopenharmony_ci
2462306a36Sopenharmony_ci (#) Security.
2562306a36Sopenharmony_ci
2662306a36Sopenharmony_ci (#) Example client usage.
2762306a36Sopenharmony_ci
2862306a36Sopenharmony_ci (#) Example server usage.
2962306a36Sopenharmony_ci
3062306a36Sopenharmony_ci (#) AF_RXRPC kernel interface.
3162306a36Sopenharmony_ci
3262306a36Sopenharmony_ci (#) Configurable parameters.
3362306a36Sopenharmony_ci
3462306a36Sopenharmony_ci
3562306a36Sopenharmony_ciOverview
3662306a36Sopenharmony_ci========
3762306a36Sopenharmony_ci
3862306a36Sopenharmony_ciRxRPC is a two-layer protocol.  There is a session layer which provides
3962306a36Sopenharmony_cireliable virtual connections using UDP over IPv4 (or IPv6) as the transport
4062306a36Sopenharmony_cilayer, but implements a real network protocol; and there's the presentation
4162306a36Sopenharmony_cilayer which renders structured data to binary blobs and back again using XDR
4262306a36Sopenharmony_ci(as does SunRPC)::
4362306a36Sopenharmony_ci
4462306a36Sopenharmony_ci		+-------------+
4562306a36Sopenharmony_ci		| Application |
4662306a36Sopenharmony_ci		+-------------+
4762306a36Sopenharmony_ci		|     XDR     |		Presentation
4862306a36Sopenharmony_ci		+-------------+
4962306a36Sopenharmony_ci		|    RxRPC    |		Session
5062306a36Sopenharmony_ci		+-------------+
5162306a36Sopenharmony_ci		|     UDP     |		Transport
5262306a36Sopenharmony_ci		+-------------+
5362306a36Sopenharmony_ci
5462306a36Sopenharmony_ci
5562306a36Sopenharmony_ciAF_RXRPC provides:
5662306a36Sopenharmony_ci
5762306a36Sopenharmony_ci (1) Part of an RxRPC facility for both kernel and userspace applications by
5862306a36Sopenharmony_ci     making the session part of it a Linux network protocol (AF_RXRPC).
5962306a36Sopenharmony_ci
6062306a36Sopenharmony_ci (2) A two-phase protocol.  The client transmits a blob (the request) and then
6162306a36Sopenharmony_ci     receives a blob (the reply), and the server receives the request and then
6262306a36Sopenharmony_ci     transmits the reply.
6362306a36Sopenharmony_ci
6462306a36Sopenharmony_ci (3) Retention of the reusable bits of the transport system set up for one call
6562306a36Sopenharmony_ci     to speed up subsequent calls.
6662306a36Sopenharmony_ci
6762306a36Sopenharmony_ci (4) A secure protocol, using the Linux kernel's key retention facility to
6862306a36Sopenharmony_ci     manage security on the client end.  The server end must of necessity be
6962306a36Sopenharmony_ci     more active in security negotiations.
7062306a36Sopenharmony_ci
7162306a36Sopenharmony_ciAF_RXRPC does not provide XDR marshalling/presentation facilities.  That is
7262306a36Sopenharmony_cileft to the application.  AF_RXRPC only deals in blobs.  Even the operation ID
7362306a36Sopenharmony_ciis just the first four bytes of the request blob, and as such is beyond the
7462306a36Sopenharmony_cikernel's interest.
7562306a36Sopenharmony_ci
7662306a36Sopenharmony_ci
7762306a36Sopenharmony_ciSockets of AF_RXRPC family are:
7862306a36Sopenharmony_ci
7962306a36Sopenharmony_ci (1) created as type SOCK_DGRAM;
8062306a36Sopenharmony_ci
8162306a36Sopenharmony_ci (2) provided with a protocol of the type of underlying transport they're going
8262306a36Sopenharmony_ci     to use - currently only PF_INET is supported.
8362306a36Sopenharmony_ci
8462306a36Sopenharmony_ci
8562306a36Sopenharmony_ciThe Andrew File System (AFS) is an example of an application that uses this and
8662306a36Sopenharmony_cithat has both kernel (filesystem) and userspace (utility) components.
8762306a36Sopenharmony_ci
8862306a36Sopenharmony_ci
8962306a36Sopenharmony_ciRxRPC Protocol Summary
9062306a36Sopenharmony_ci======================
9162306a36Sopenharmony_ci
9262306a36Sopenharmony_ciAn overview of the RxRPC protocol:
9362306a36Sopenharmony_ci
9462306a36Sopenharmony_ci (#) RxRPC sits on top of another networking protocol (UDP is the only option
9562306a36Sopenharmony_ci     currently), and uses this to provide network transport.  UDP ports, for
9662306a36Sopenharmony_ci     example, provide transport endpoints.
9762306a36Sopenharmony_ci
9862306a36Sopenharmony_ci (#) RxRPC supports multiple virtual "connections" from any given transport
9962306a36Sopenharmony_ci     endpoint, thus allowing the endpoints to be shared, even to the same
10062306a36Sopenharmony_ci     remote endpoint.
10162306a36Sopenharmony_ci
10262306a36Sopenharmony_ci (#) Each connection goes to a particular "service".  A connection may not go
10362306a36Sopenharmony_ci     to multiple services.  A service may be considered the RxRPC equivalent of
10462306a36Sopenharmony_ci     a port number.  AF_RXRPC permits multiple services to share an endpoint.
10562306a36Sopenharmony_ci
10662306a36Sopenharmony_ci (#) Client-originating packets are marked, thus a transport endpoint can be
10762306a36Sopenharmony_ci     shared between client and server connections (connections have a
10862306a36Sopenharmony_ci     direction).
10962306a36Sopenharmony_ci
11062306a36Sopenharmony_ci (#) Up to a billion connections may be supported concurrently between one
11162306a36Sopenharmony_ci     local transport endpoint and one service on one remote endpoint.  An RxRPC
11262306a36Sopenharmony_ci     connection is described by seven numbers::
11362306a36Sopenharmony_ci
11462306a36Sopenharmony_ci	Local address	}
11562306a36Sopenharmony_ci	Local port	} Transport (UDP) address
11662306a36Sopenharmony_ci	Remote address	}
11762306a36Sopenharmony_ci	Remote port	}
11862306a36Sopenharmony_ci	Direction
11962306a36Sopenharmony_ci	Connection ID
12062306a36Sopenharmony_ci	Service ID
12162306a36Sopenharmony_ci
12262306a36Sopenharmony_ci (#) Each RxRPC operation is a "call".  A connection may make up to four
12362306a36Sopenharmony_ci     billion calls, but only up to four calls may be in progress on a
12462306a36Sopenharmony_ci     connection at any one time.
12562306a36Sopenharmony_ci
12662306a36Sopenharmony_ci (#) Calls are two-phase and asymmetric: the client sends its request data,
12762306a36Sopenharmony_ci     which the service receives; then the service transmits the reply data
12862306a36Sopenharmony_ci     which the client receives.
12962306a36Sopenharmony_ci
13062306a36Sopenharmony_ci (#) The data blobs are of indefinite size, the end of a phase is marked with a
13162306a36Sopenharmony_ci     flag in the packet.  The number of packets of data making up one blob may
13262306a36Sopenharmony_ci     not exceed 4 billion, however, as this would cause the sequence number to
13362306a36Sopenharmony_ci     wrap.
13462306a36Sopenharmony_ci
13562306a36Sopenharmony_ci (#) The first four bytes of the request data are the service operation ID.
13662306a36Sopenharmony_ci
13762306a36Sopenharmony_ci (#) Security is negotiated on a per-connection basis.  The connection is
13862306a36Sopenharmony_ci     initiated by the first data packet on it arriving.  If security is
13962306a36Sopenharmony_ci     requested, the server then issues a "challenge" and then the client
14062306a36Sopenharmony_ci     replies with a "response".  If the response is successful, the security is
14162306a36Sopenharmony_ci     set for the lifetime of that connection, and all subsequent calls made
14262306a36Sopenharmony_ci     upon it use that same security.  In the event that the server lets a
14362306a36Sopenharmony_ci     connection lapse before the client, the security will be renegotiated if
14462306a36Sopenharmony_ci     the client uses the connection again.
14562306a36Sopenharmony_ci
14662306a36Sopenharmony_ci (#) Calls use ACK packets to handle reliability.  Data packets are also
14762306a36Sopenharmony_ci     explicitly sequenced per call.
14862306a36Sopenharmony_ci
14962306a36Sopenharmony_ci (#) There are two types of positive acknowledgment: hard-ACKs and soft-ACKs.
15062306a36Sopenharmony_ci     A hard-ACK indicates to the far side that all the data received to a point
15162306a36Sopenharmony_ci     has been received and processed; a soft-ACK indicates that the data has
15262306a36Sopenharmony_ci     been received but may yet be discarded and re-requested.  The sender may
15362306a36Sopenharmony_ci     not discard any transmittable packets until they've been hard-ACK'd.
15462306a36Sopenharmony_ci
15562306a36Sopenharmony_ci (#) Reception of a reply data packet implicitly hard-ACK's all the data
15662306a36Sopenharmony_ci     packets that make up the request.
15762306a36Sopenharmony_ci
15862306a36Sopenharmony_ci (#) An call is complete when the request has been sent, the reply has been
15962306a36Sopenharmony_ci     received and the final hard-ACK on the last packet of the reply has
16062306a36Sopenharmony_ci     reached the server.
16162306a36Sopenharmony_ci
16262306a36Sopenharmony_ci (#) An call may be aborted by either end at any time up to its completion.
16362306a36Sopenharmony_ci
16462306a36Sopenharmony_ci
16562306a36Sopenharmony_ciAF_RXRPC Driver Model
16662306a36Sopenharmony_ci=====================
16762306a36Sopenharmony_ci
16862306a36Sopenharmony_ciAbout the AF_RXRPC driver:
16962306a36Sopenharmony_ci
17062306a36Sopenharmony_ci (#) The AF_RXRPC protocol transparently uses internal sockets of the transport
17162306a36Sopenharmony_ci     protocol to represent transport endpoints.
17262306a36Sopenharmony_ci
17362306a36Sopenharmony_ci (#) AF_RXRPC sockets map onto RxRPC connection bundles.  Actual RxRPC
17462306a36Sopenharmony_ci     connections are handled transparently.  One client socket may be used to
17562306a36Sopenharmony_ci     make multiple simultaneous calls to the same service.  One server socket
17662306a36Sopenharmony_ci     may handle calls from many clients.
17762306a36Sopenharmony_ci
17862306a36Sopenharmony_ci (#) Additional parallel client connections will be initiated to support extra
17962306a36Sopenharmony_ci     concurrent calls, up to a tunable limit.
18062306a36Sopenharmony_ci
18162306a36Sopenharmony_ci (#) Each connection is retained for a certain amount of time [tunable] after
18262306a36Sopenharmony_ci     the last call currently using it has completed in case a new call is made
18362306a36Sopenharmony_ci     that could reuse it.
18462306a36Sopenharmony_ci
18562306a36Sopenharmony_ci (#) Each internal UDP socket is retained [tunable] for a certain amount of
18662306a36Sopenharmony_ci     time [tunable] after the last connection using it discarded, in case a new
18762306a36Sopenharmony_ci     connection is made that could use it.
18862306a36Sopenharmony_ci
18962306a36Sopenharmony_ci (#) A client-side connection is only shared between calls if they have
19062306a36Sopenharmony_ci     the same key struct describing their security (and assuming the calls
19162306a36Sopenharmony_ci     would otherwise share the connection).  Non-secured calls would also be
19262306a36Sopenharmony_ci     able to share connections with each other.
19362306a36Sopenharmony_ci
19462306a36Sopenharmony_ci (#) A server-side connection is shared if the client says it is.
19562306a36Sopenharmony_ci
19662306a36Sopenharmony_ci (#) ACK'ing is handled by the protocol driver automatically, including ping
19762306a36Sopenharmony_ci     replying.
19862306a36Sopenharmony_ci
19962306a36Sopenharmony_ci (#) SO_KEEPALIVE automatically pings the other side to keep the connection
20062306a36Sopenharmony_ci     alive [TODO].
20162306a36Sopenharmony_ci
20262306a36Sopenharmony_ci (#) If an ICMP error is received, all calls affected by that error will be
20362306a36Sopenharmony_ci     aborted with an appropriate network error passed through recvmsg().
20462306a36Sopenharmony_ci
20562306a36Sopenharmony_ci
20662306a36Sopenharmony_ciInteraction with the user of the RxRPC socket:
20762306a36Sopenharmony_ci
20862306a36Sopenharmony_ci (#) A socket is made into a server socket by binding an address with a
20962306a36Sopenharmony_ci     non-zero service ID.
21062306a36Sopenharmony_ci
21162306a36Sopenharmony_ci (#) In the client, sending a request is achieved with one or more sendmsgs,
21262306a36Sopenharmony_ci     followed by the reply being received with one or more recvmsgs.
21362306a36Sopenharmony_ci
21462306a36Sopenharmony_ci (#) The first sendmsg for a request to be sent from a client contains a tag to
21562306a36Sopenharmony_ci     be used in all other sendmsgs or recvmsgs associated with that call.  The
21662306a36Sopenharmony_ci     tag is carried in the control data.
21762306a36Sopenharmony_ci
21862306a36Sopenharmony_ci (#) connect() is used to supply a default destination address for a client
21962306a36Sopenharmony_ci     socket.  This may be overridden by supplying an alternate address to the
22062306a36Sopenharmony_ci     first sendmsg() of a call (struct msghdr::msg_name).
22162306a36Sopenharmony_ci
22262306a36Sopenharmony_ci (#) If connect() is called on an unbound client, a random local port will
22362306a36Sopenharmony_ci     bound before the operation takes place.
22462306a36Sopenharmony_ci
22562306a36Sopenharmony_ci (#) A server socket may also be used to make client calls.  To do this, the
22662306a36Sopenharmony_ci     first sendmsg() of the call must specify the target address.  The server's
22762306a36Sopenharmony_ci     transport endpoint is used to send the packets.
22862306a36Sopenharmony_ci
22962306a36Sopenharmony_ci (#) Once the application has received the last message associated with a call,
23062306a36Sopenharmony_ci     the tag is guaranteed not to be seen again, and so it can be used to pin
23162306a36Sopenharmony_ci     client resources.  A new call can then be initiated with the same tag
23262306a36Sopenharmony_ci     without fear of interference.
23362306a36Sopenharmony_ci
23462306a36Sopenharmony_ci (#) In the server, a request is received with one or more recvmsgs, then the
23562306a36Sopenharmony_ci     the reply is transmitted with one or more sendmsgs, and then the final ACK
23662306a36Sopenharmony_ci     is received with a last recvmsg.
23762306a36Sopenharmony_ci
23862306a36Sopenharmony_ci (#) When sending data for a call, sendmsg is given MSG_MORE if there's more
23962306a36Sopenharmony_ci     data to come on that call.
24062306a36Sopenharmony_ci
24162306a36Sopenharmony_ci (#) When receiving data for a call, recvmsg flags MSG_MORE if there's more
24262306a36Sopenharmony_ci     data to come for that call.
24362306a36Sopenharmony_ci
24462306a36Sopenharmony_ci (#) When receiving data or messages for a call, MSG_EOR is flagged by recvmsg
24562306a36Sopenharmony_ci     to indicate the terminal message for that call.
24662306a36Sopenharmony_ci
24762306a36Sopenharmony_ci (#) A call may be aborted by adding an abort control message to the control
24862306a36Sopenharmony_ci     data.  Issuing an abort terminates the kernel's use of that call's tag.
24962306a36Sopenharmony_ci     Any messages waiting in the receive queue for that call will be discarded.
25062306a36Sopenharmony_ci
25162306a36Sopenharmony_ci (#) Aborts, busy notifications and challenge packets are delivered by recvmsg,
25262306a36Sopenharmony_ci     and control data messages will be set to indicate the context.  Receiving
25362306a36Sopenharmony_ci     an abort or a busy message terminates the kernel's use of that call's tag.
25462306a36Sopenharmony_ci
25562306a36Sopenharmony_ci (#) The control data part of the msghdr struct is used for a number of things:
25662306a36Sopenharmony_ci
25762306a36Sopenharmony_ci     (#) The tag of the intended or affected call.
25862306a36Sopenharmony_ci
25962306a36Sopenharmony_ci     (#) Sending or receiving errors, aborts and busy notifications.
26062306a36Sopenharmony_ci
26162306a36Sopenharmony_ci     (#) Notifications of incoming calls.
26262306a36Sopenharmony_ci
26362306a36Sopenharmony_ci     (#) Sending debug requests and receiving debug replies [TODO].
26462306a36Sopenharmony_ci
26562306a36Sopenharmony_ci (#) When the kernel has received and set up an incoming call, it sends a
26662306a36Sopenharmony_ci     message to server application to let it know there's a new call awaiting
26762306a36Sopenharmony_ci     its acceptance [recvmsg reports a special control message].  The server
26862306a36Sopenharmony_ci     application then uses sendmsg to assign a tag to the new call.  Once that
26962306a36Sopenharmony_ci     is done, the first part of the request data will be delivered by recvmsg.
27062306a36Sopenharmony_ci
27162306a36Sopenharmony_ci (#) The server application has to provide the server socket with a keyring of
27262306a36Sopenharmony_ci     secret keys corresponding to the security types it permits.  When a secure
27362306a36Sopenharmony_ci     connection is being set up, the kernel looks up the appropriate secret key
27462306a36Sopenharmony_ci     in the keyring and then sends a challenge packet to the client and
27562306a36Sopenharmony_ci     receives a response packet.  The kernel then checks the authorisation of
27662306a36Sopenharmony_ci     the packet and either aborts the connection or sets up the security.
27762306a36Sopenharmony_ci
27862306a36Sopenharmony_ci (#) The name of the key a client will use to secure its communications is
27962306a36Sopenharmony_ci     nominated by a socket option.
28062306a36Sopenharmony_ci
28162306a36Sopenharmony_ci
28262306a36Sopenharmony_ciNotes on sendmsg:
28362306a36Sopenharmony_ci
28462306a36Sopenharmony_ci (#) MSG_WAITALL can be set to tell sendmsg to ignore signals if the peer is
28562306a36Sopenharmony_ci     making progress at accepting packets within a reasonable time such that we
28662306a36Sopenharmony_ci     manage to queue up all the data for transmission.  This requires the
28762306a36Sopenharmony_ci     client to accept at least one packet per 2*RTT time period.
28862306a36Sopenharmony_ci
28962306a36Sopenharmony_ci     If this isn't set, sendmsg() will return immediately, either returning
29062306a36Sopenharmony_ci     EINTR/ERESTARTSYS if nothing was consumed or returning the amount of data
29162306a36Sopenharmony_ci     consumed.
29262306a36Sopenharmony_ci
29362306a36Sopenharmony_ci
29462306a36Sopenharmony_ciNotes on recvmsg:
29562306a36Sopenharmony_ci
29662306a36Sopenharmony_ci (#) If there's a sequence of data messages belonging to a particular call on
29762306a36Sopenharmony_ci     the receive queue, then recvmsg will keep working through them until:
29862306a36Sopenharmony_ci
29962306a36Sopenharmony_ci     (a) it meets the end of that call's received data,
30062306a36Sopenharmony_ci
30162306a36Sopenharmony_ci     (b) it meets a non-data message,
30262306a36Sopenharmony_ci
30362306a36Sopenharmony_ci     (c) it meets a message belonging to a different call, or
30462306a36Sopenharmony_ci
30562306a36Sopenharmony_ci     (d) it fills the user buffer.
30662306a36Sopenharmony_ci
30762306a36Sopenharmony_ci     If recvmsg is called in blocking mode, it will keep sleeping, awaiting the
30862306a36Sopenharmony_ci     reception of further data, until one of the above four conditions is met.
30962306a36Sopenharmony_ci
31062306a36Sopenharmony_ci (2) MSG_PEEK operates similarly, but will return immediately if it has put any
31162306a36Sopenharmony_ci     data in the buffer rather than sleeping until it can fill the buffer.
31262306a36Sopenharmony_ci
31362306a36Sopenharmony_ci (3) If a data message is only partially consumed in filling a user buffer,
31462306a36Sopenharmony_ci     then the remainder of that message will be left on the front of the queue
31562306a36Sopenharmony_ci     for the next taker.  MSG_TRUNC will never be flagged.
31662306a36Sopenharmony_ci
31762306a36Sopenharmony_ci (4) If there is more data to be had on a call (it hasn't copied the last byte
31862306a36Sopenharmony_ci     of the last data message in that phase yet), then MSG_MORE will be
31962306a36Sopenharmony_ci     flagged.
32062306a36Sopenharmony_ci
32162306a36Sopenharmony_ci
32262306a36Sopenharmony_ciControl Messages
32362306a36Sopenharmony_ci================
32462306a36Sopenharmony_ci
32562306a36Sopenharmony_ciAF_RXRPC makes use of control messages in sendmsg() and recvmsg() to multiplex
32662306a36Sopenharmony_cicalls, to invoke certain actions and to report certain conditions.  These are:
32762306a36Sopenharmony_ci
32862306a36Sopenharmony_ci	=======================	=== ===========	===============================
32962306a36Sopenharmony_ci	MESSAGE ID		SRT DATA	MEANING
33062306a36Sopenharmony_ci	=======================	=== ===========	===============================
33162306a36Sopenharmony_ci	RXRPC_USER_CALL_ID	sr- User ID	App's call specifier
33262306a36Sopenharmony_ci	RXRPC_ABORT		srt Abort code	Abort code to issue/received
33362306a36Sopenharmony_ci	RXRPC_ACK		-rt n/a		Final ACK received
33462306a36Sopenharmony_ci	RXRPC_NET_ERROR		-rt error num	Network error on call
33562306a36Sopenharmony_ci	RXRPC_BUSY		-rt n/a		Call rejected (server busy)
33662306a36Sopenharmony_ci	RXRPC_LOCAL_ERROR	-rt error num	Local error encountered
33762306a36Sopenharmony_ci	RXRPC_NEW_CALL		-r- n/a		New call received
33862306a36Sopenharmony_ci	RXRPC_ACCEPT		s-- n/a		Accept new call
33962306a36Sopenharmony_ci	RXRPC_EXCLUSIVE_CALL	s-- n/a		Make an exclusive client call
34062306a36Sopenharmony_ci	RXRPC_UPGRADE_SERVICE	s-- n/a		Client call can be upgraded
34162306a36Sopenharmony_ci	RXRPC_TX_LENGTH		s-- data len	Total length of Tx data
34262306a36Sopenharmony_ci	=======================	=== ===========	===============================
34362306a36Sopenharmony_ci
34462306a36Sopenharmony_ci	(SRT = usable in Sendmsg / delivered by Recvmsg / Terminal message)
34562306a36Sopenharmony_ci
34662306a36Sopenharmony_ci (#) RXRPC_USER_CALL_ID
34762306a36Sopenharmony_ci
34862306a36Sopenharmony_ci     This is used to indicate the application's call ID.  It's an unsigned long
34962306a36Sopenharmony_ci     that the app specifies in the client by attaching it to the first data
35062306a36Sopenharmony_ci     message or in the server by passing it in association with an RXRPC_ACCEPT
35162306a36Sopenharmony_ci     message.  recvmsg() passes it in conjunction with all messages except
35262306a36Sopenharmony_ci     those of the RXRPC_NEW_CALL message.
35362306a36Sopenharmony_ci
35462306a36Sopenharmony_ci (#) RXRPC_ABORT
35562306a36Sopenharmony_ci
35662306a36Sopenharmony_ci     This is can be used by an application to abort a call by passing it to
35762306a36Sopenharmony_ci     sendmsg, or it can be delivered by recvmsg to indicate a remote abort was
35862306a36Sopenharmony_ci     received.  Either way, it must be associated with an RXRPC_USER_CALL_ID to
35962306a36Sopenharmony_ci     specify the call affected.  If an abort is being sent, then error EBADSLT
36062306a36Sopenharmony_ci     will be returned if there is no call with that user ID.
36162306a36Sopenharmony_ci
36262306a36Sopenharmony_ci (#) RXRPC_ACK
36362306a36Sopenharmony_ci
36462306a36Sopenharmony_ci     This is delivered to a server application to indicate that the final ACK
36562306a36Sopenharmony_ci     of a call was received from the client.  It will be associated with an
36662306a36Sopenharmony_ci     RXRPC_USER_CALL_ID to indicate the call that's now complete.
36762306a36Sopenharmony_ci
36862306a36Sopenharmony_ci (#) RXRPC_NET_ERROR
36962306a36Sopenharmony_ci
37062306a36Sopenharmony_ci     This is delivered to an application to indicate that an ICMP error message
37162306a36Sopenharmony_ci     was encountered in the process of trying to talk to the peer.  An
37262306a36Sopenharmony_ci     errno-class integer value will be included in the control message data
37362306a36Sopenharmony_ci     indicating the problem, and an RXRPC_USER_CALL_ID will indicate the call
37462306a36Sopenharmony_ci     affected.
37562306a36Sopenharmony_ci
37662306a36Sopenharmony_ci (#) RXRPC_BUSY
37762306a36Sopenharmony_ci
37862306a36Sopenharmony_ci     This is delivered to a client application to indicate that a call was
37962306a36Sopenharmony_ci     rejected by the server due to the server being busy.  It will be
38062306a36Sopenharmony_ci     associated with an RXRPC_USER_CALL_ID to indicate the rejected call.
38162306a36Sopenharmony_ci
38262306a36Sopenharmony_ci (#) RXRPC_LOCAL_ERROR
38362306a36Sopenharmony_ci
38462306a36Sopenharmony_ci     This is delivered to an application to indicate that a local error was
38562306a36Sopenharmony_ci     encountered and that a call has been aborted because of it.  An
38662306a36Sopenharmony_ci     errno-class integer value will be included in the control message data
38762306a36Sopenharmony_ci     indicating the problem, and an RXRPC_USER_CALL_ID will indicate the call
38862306a36Sopenharmony_ci     affected.
38962306a36Sopenharmony_ci
39062306a36Sopenharmony_ci (#) RXRPC_NEW_CALL
39162306a36Sopenharmony_ci
39262306a36Sopenharmony_ci     This is delivered to indicate to a server application that a new call has
39362306a36Sopenharmony_ci     arrived and is awaiting acceptance.  No user ID is associated with this,
39462306a36Sopenharmony_ci     as a user ID must subsequently be assigned by doing an RXRPC_ACCEPT.
39562306a36Sopenharmony_ci
39662306a36Sopenharmony_ci (#) RXRPC_ACCEPT
39762306a36Sopenharmony_ci
39862306a36Sopenharmony_ci     This is used by a server application to attempt to accept a call and
39962306a36Sopenharmony_ci     assign it a user ID.  It should be associated with an RXRPC_USER_CALL_ID
40062306a36Sopenharmony_ci     to indicate the user ID to be assigned.  If there is no call to be
40162306a36Sopenharmony_ci     accepted (it may have timed out, been aborted, etc.), then sendmsg will
40262306a36Sopenharmony_ci     return error ENODATA.  If the user ID is already in use by another call,
40362306a36Sopenharmony_ci     then error EBADSLT will be returned.
40462306a36Sopenharmony_ci
40562306a36Sopenharmony_ci (#) RXRPC_EXCLUSIVE_CALL
40662306a36Sopenharmony_ci
40762306a36Sopenharmony_ci     This is used to indicate that a client call should be made on a one-off
40862306a36Sopenharmony_ci     connection.  The connection is discarded once the call has terminated.
40962306a36Sopenharmony_ci
41062306a36Sopenharmony_ci (#) RXRPC_UPGRADE_SERVICE
41162306a36Sopenharmony_ci
41262306a36Sopenharmony_ci     This is used to make a client call to probe if the specified service ID
41362306a36Sopenharmony_ci     may be upgraded by the server.  The caller must check msg_name returned to
41462306a36Sopenharmony_ci     recvmsg() for the service ID actually in use.  The operation probed must
41562306a36Sopenharmony_ci     be one that takes the same arguments in both services.
41662306a36Sopenharmony_ci
41762306a36Sopenharmony_ci     Once this has been used to establish the upgrade capability (or lack
41862306a36Sopenharmony_ci     thereof) of the server, the service ID returned should be used for all
41962306a36Sopenharmony_ci     future communication to that server and RXRPC_UPGRADE_SERVICE should no
42062306a36Sopenharmony_ci     longer be set.
42162306a36Sopenharmony_ci
42262306a36Sopenharmony_ci (#) RXRPC_TX_LENGTH
42362306a36Sopenharmony_ci
42462306a36Sopenharmony_ci     This is used to inform the kernel of the total amount of data that is
42562306a36Sopenharmony_ci     going to be transmitted by a call (whether in a client request or a
42662306a36Sopenharmony_ci     service response).  If given, it allows the kernel to encrypt from the
42762306a36Sopenharmony_ci     userspace buffer directly to the packet buffers, rather than copying into
42862306a36Sopenharmony_ci     the buffer and then encrypting in place.  This may only be given with the
42962306a36Sopenharmony_ci     first sendmsg() providing data for a call.  EMSGSIZE will be generated if
43062306a36Sopenharmony_ci     the amount of data actually given is different.
43162306a36Sopenharmony_ci
43262306a36Sopenharmony_ci     This takes a parameter of __s64 type that indicates how much will be
43362306a36Sopenharmony_ci     transmitted.  This may not be less than zero.
43462306a36Sopenharmony_ci
43562306a36Sopenharmony_ciThe symbol RXRPC__SUPPORTED is defined as one more than the highest control
43662306a36Sopenharmony_cimessage type supported.  At run time this can be queried by means of the
43762306a36Sopenharmony_ciRXRPC_SUPPORTED_CMSG socket option (see below).
43862306a36Sopenharmony_ci
43962306a36Sopenharmony_ci
44062306a36Sopenharmony_ci==============
44162306a36Sopenharmony_ciSOCKET OPTIONS
44262306a36Sopenharmony_ci==============
44362306a36Sopenharmony_ci
44462306a36Sopenharmony_ciAF_RXRPC sockets support a few socket options at the SOL_RXRPC level:
44562306a36Sopenharmony_ci
44662306a36Sopenharmony_ci (#) RXRPC_SECURITY_KEY
44762306a36Sopenharmony_ci
44862306a36Sopenharmony_ci     This is used to specify the description of the key to be used.  The key is
44962306a36Sopenharmony_ci     extracted from the calling process's keyrings with request_key() and
45062306a36Sopenharmony_ci     should be of "rxrpc" type.
45162306a36Sopenharmony_ci
45262306a36Sopenharmony_ci     The optval pointer points to the description string, and optlen indicates
45362306a36Sopenharmony_ci     how long the string is, without the NUL terminator.
45462306a36Sopenharmony_ci
45562306a36Sopenharmony_ci (#) RXRPC_SECURITY_KEYRING
45662306a36Sopenharmony_ci
45762306a36Sopenharmony_ci     Similar to above but specifies a keyring of server secret keys to use (key
45862306a36Sopenharmony_ci     type "keyring").  See the "Security" section.
45962306a36Sopenharmony_ci
46062306a36Sopenharmony_ci (#) RXRPC_EXCLUSIVE_CONNECTION
46162306a36Sopenharmony_ci
46262306a36Sopenharmony_ci     This is used to request that new connections should be used for each call
46362306a36Sopenharmony_ci     made subsequently on this socket.  optval should be NULL and optlen 0.
46462306a36Sopenharmony_ci
46562306a36Sopenharmony_ci (#) RXRPC_MIN_SECURITY_LEVEL
46662306a36Sopenharmony_ci
46762306a36Sopenharmony_ci     This is used to specify the minimum security level required for calls on
46862306a36Sopenharmony_ci     this socket.  optval must point to an int containing one of the following
46962306a36Sopenharmony_ci     values:
47062306a36Sopenharmony_ci
47162306a36Sopenharmony_ci     (a) RXRPC_SECURITY_PLAIN
47262306a36Sopenharmony_ci
47362306a36Sopenharmony_ci	 Encrypted checksum only.
47462306a36Sopenharmony_ci
47562306a36Sopenharmony_ci     (b) RXRPC_SECURITY_AUTH
47662306a36Sopenharmony_ci
47762306a36Sopenharmony_ci	 Encrypted checksum plus packet padded and first eight bytes of packet
47862306a36Sopenharmony_ci	 encrypted - which includes the actual packet length.
47962306a36Sopenharmony_ci
48062306a36Sopenharmony_ci     (c) RXRPC_SECURITY_ENCRYPT
48162306a36Sopenharmony_ci
48262306a36Sopenharmony_ci	 Encrypted checksum plus entire packet padded and encrypted, including
48362306a36Sopenharmony_ci	 actual packet length.
48462306a36Sopenharmony_ci
48562306a36Sopenharmony_ci (#) RXRPC_UPGRADEABLE_SERVICE
48662306a36Sopenharmony_ci
48762306a36Sopenharmony_ci     This is used to indicate that a service socket with two bindings may
48862306a36Sopenharmony_ci     upgrade one bound service to the other if requested by the client.  optval
48962306a36Sopenharmony_ci     must point to an array of two unsigned short ints.  The first is the
49062306a36Sopenharmony_ci     service ID to upgrade from and the second the service ID to upgrade to.
49162306a36Sopenharmony_ci
49262306a36Sopenharmony_ci (#) RXRPC_SUPPORTED_CMSG
49362306a36Sopenharmony_ci
49462306a36Sopenharmony_ci     This is a read-only option that writes an int into the buffer indicating
49562306a36Sopenharmony_ci     the highest control message type supported.
49662306a36Sopenharmony_ci
49762306a36Sopenharmony_ci
49862306a36Sopenharmony_ci========
49962306a36Sopenharmony_ciSECURITY
50062306a36Sopenharmony_ci========
50162306a36Sopenharmony_ci
50262306a36Sopenharmony_ciCurrently, only the kerberos 4 equivalent protocol has been implemented
50362306a36Sopenharmony_ci(security index 2 - rxkad).  This requires the rxkad module to be loaded and,
50462306a36Sopenharmony_cion the client, tickets of the appropriate type to be obtained from the AFS
50562306a36Sopenharmony_cikaserver or the kerberos server and installed as "rxrpc" type keys.  This is
50662306a36Sopenharmony_cinormally done using the klog program.  An example simple klog program can be
50762306a36Sopenharmony_cifound at:
50862306a36Sopenharmony_ci
50962306a36Sopenharmony_ci	http://people.redhat.com/~dhowells/rxrpc/klog.c
51062306a36Sopenharmony_ci
51162306a36Sopenharmony_ciThe payload provided to add_key() on the client should be of the following
51262306a36Sopenharmony_ciform::
51362306a36Sopenharmony_ci
51462306a36Sopenharmony_ci	struct rxrpc_key_sec2_v1 {
51562306a36Sopenharmony_ci		uint16_t	security_index;	/* 2 */
51662306a36Sopenharmony_ci		uint16_t	ticket_length;	/* length of ticket[] */
51762306a36Sopenharmony_ci		uint32_t	expiry;		/* time at which expires */
51862306a36Sopenharmony_ci		uint8_t		kvno;		/* key version number */
51962306a36Sopenharmony_ci		uint8_t		__pad[3];
52062306a36Sopenharmony_ci		uint8_t		session_key[8];	/* DES session key */
52162306a36Sopenharmony_ci		uint8_t		ticket[0];	/* the encrypted ticket */
52262306a36Sopenharmony_ci	};
52362306a36Sopenharmony_ci
52462306a36Sopenharmony_ciWhere the ticket blob is just appended to the above structure.
52562306a36Sopenharmony_ci
52662306a36Sopenharmony_ci
52762306a36Sopenharmony_ciFor the server, keys of type "rxrpc_s" must be made available to the server.
52862306a36Sopenharmony_ciThey have a description of "<serviceID>:<securityIndex>" (eg: "52:2" for an
52962306a36Sopenharmony_cirxkad key for the AFS VL service).  When such a key is created, it should be
53062306a36Sopenharmony_cigiven the server's secret key as the instantiation data (see the example
53162306a36Sopenharmony_cibelow).
53262306a36Sopenharmony_ci
53362306a36Sopenharmony_ci	add_key("rxrpc_s", "52:2", secret_key, 8, keyring);
53462306a36Sopenharmony_ci
53562306a36Sopenharmony_ciA keyring is passed to the server socket by naming it in a sockopt.  The server
53662306a36Sopenharmony_cisocket then looks the server secret keys up in this keyring when secure
53762306a36Sopenharmony_ciincoming connections are made.  This can be seen in an example program that can
53862306a36Sopenharmony_cibe found at:
53962306a36Sopenharmony_ci
54062306a36Sopenharmony_ci	http://people.redhat.com/~dhowells/rxrpc/listen.c
54162306a36Sopenharmony_ci
54262306a36Sopenharmony_ci
54362306a36Sopenharmony_ci====================
54462306a36Sopenharmony_ciEXAMPLE CLIENT USAGE
54562306a36Sopenharmony_ci====================
54662306a36Sopenharmony_ci
54762306a36Sopenharmony_ciA client would issue an operation by:
54862306a36Sopenharmony_ci
54962306a36Sopenharmony_ci (1) An RxRPC socket is set up by::
55062306a36Sopenharmony_ci
55162306a36Sopenharmony_ci	client = socket(AF_RXRPC, SOCK_DGRAM, PF_INET);
55262306a36Sopenharmony_ci
55362306a36Sopenharmony_ci     Where the third parameter indicates the protocol family of the transport
55462306a36Sopenharmony_ci     socket used - usually IPv4 but it can also be IPv6 [TODO].
55562306a36Sopenharmony_ci
55662306a36Sopenharmony_ci (2) A local address can optionally be bound::
55762306a36Sopenharmony_ci
55862306a36Sopenharmony_ci	struct sockaddr_rxrpc srx = {
55962306a36Sopenharmony_ci		.srx_family	= AF_RXRPC,
56062306a36Sopenharmony_ci		.srx_service	= 0,  /* we're a client */
56162306a36Sopenharmony_ci		.transport_type	= SOCK_DGRAM,	/* type of transport socket */
56262306a36Sopenharmony_ci		.transport.sin_family	= AF_INET,
56362306a36Sopenharmony_ci		.transport.sin_port	= htons(7000), /* AFS callback */
56462306a36Sopenharmony_ci		.transport.sin_address	= 0,  /* all local interfaces */
56562306a36Sopenharmony_ci	};
56662306a36Sopenharmony_ci	bind(client, &srx, sizeof(srx));
56762306a36Sopenharmony_ci
56862306a36Sopenharmony_ci     This specifies the local UDP port to be used.  If not given, a random
56962306a36Sopenharmony_ci     non-privileged port will be used.  A UDP port may be shared between
57062306a36Sopenharmony_ci     several unrelated RxRPC sockets.  Security is handled on a basis of
57162306a36Sopenharmony_ci     per-RxRPC virtual connection.
57262306a36Sopenharmony_ci
57362306a36Sopenharmony_ci (3) The security is set::
57462306a36Sopenharmony_ci
57562306a36Sopenharmony_ci	const char *key = "AFS:cambridge.redhat.com";
57662306a36Sopenharmony_ci	setsockopt(client, SOL_RXRPC, RXRPC_SECURITY_KEY, key, strlen(key));
57762306a36Sopenharmony_ci
57862306a36Sopenharmony_ci     This issues a request_key() to get the key representing the security
57962306a36Sopenharmony_ci     context.  The minimum security level can be set::
58062306a36Sopenharmony_ci
58162306a36Sopenharmony_ci	unsigned int sec = RXRPC_SECURITY_ENCRYPT;
58262306a36Sopenharmony_ci	setsockopt(client, SOL_RXRPC, RXRPC_MIN_SECURITY_LEVEL,
58362306a36Sopenharmony_ci		   &sec, sizeof(sec));
58462306a36Sopenharmony_ci
58562306a36Sopenharmony_ci (4) The server to be contacted can then be specified (alternatively this can
58662306a36Sopenharmony_ci     be done through sendmsg)::
58762306a36Sopenharmony_ci
58862306a36Sopenharmony_ci	struct sockaddr_rxrpc srx = {
58962306a36Sopenharmony_ci		.srx_family	= AF_RXRPC,
59062306a36Sopenharmony_ci		.srx_service	= VL_SERVICE_ID,
59162306a36Sopenharmony_ci		.transport_type	= SOCK_DGRAM,	/* type of transport socket */
59262306a36Sopenharmony_ci		.transport.sin_family	= AF_INET,
59362306a36Sopenharmony_ci		.transport.sin_port	= htons(7005), /* AFS volume manager */
59462306a36Sopenharmony_ci		.transport.sin_address	= ...,
59562306a36Sopenharmony_ci	};
59662306a36Sopenharmony_ci	connect(client, &srx, sizeof(srx));
59762306a36Sopenharmony_ci
59862306a36Sopenharmony_ci (5) The request data should then be posted to the server socket using a series
59962306a36Sopenharmony_ci     of sendmsg() calls, each with the following control message attached:
60062306a36Sopenharmony_ci
60162306a36Sopenharmony_ci	==================	===================================
60262306a36Sopenharmony_ci	RXRPC_USER_CALL_ID	specifies the user ID for this call
60362306a36Sopenharmony_ci	==================	===================================
60462306a36Sopenharmony_ci
60562306a36Sopenharmony_ci     MSG_MORE should be set in msghdr::msg_flags on all but the last part of
60662306a36Sopenharmony_ci     the request.  Multiple requests may be made simultaneously.
60762306a36Sopenharmony_ci
60862306a36Sopenharmony_ci     An RXRPC_TX_LENGTH control message can also be specified on the first
60962306a36Sopenharmony_ci     sendmsg() call.
61062306a36Sopenharmony_ci
61162306a36Sopenharmony_ci     If a call is intended to go to a destination other than the default
61262306a36Sopenharmony_ci     specified through connect(), then msghdr::msg_name should be set on the
61362306a36Sopenharmony_ci     first request message of that call.
61462306a36Sopenharmony_ci
61562306a36Sopenharmony_ci (6) The reply data will then be posted to the server socket for recvmsg() to
61662306a36Sopenharmony_ci     pick up.  MSG_MORE will be flagged by recvmsg() if there's more reply data
61762306a36Sopenharmony_ci     for a particular call to be read.  MSG_EOR will be set on the terminal
61862306a36Sopenharmony_ci     read for a call.
61962306a36Sopenharmony_ci
62062306a36Sopenharmony_ci     All data will be delivered with the following control message attached:
62162306a36Sopenharmony_ci
62262306a36Sopenharmony_ci	RXRPC_USER_CALL_ID	- specifies the user ID for this call
62362306a36Sopenharmony_ci
62462306a36Sopenharmony_ci     If an abort or error occurred, this will be returned in the control data
62562306a36Sopenharmony_ci     buffer instead, and MSG_EOR will be flagged to indicate the end of that
62662306a36Sopenharmony_ci     call.
62762306a36Sopenharmony_ci
62862306a36Sopenharmony_ciA client may ask for a service ID it knows and ask that this be upgraded to a
62962306a36Sopenharmony_cibetter service if one is available by supplying RXRPC_UPGRADE_SERVICE on the
63062306a36Sopenharmony_cifirst sendmsg() of a call.  The client should then check srx_service in the
63162306a36Sopenharmony_cimsg_name filled in by recvmsg() when collecting the result.  srx_service will
63262306a36Sopenharmony_cihold the same value as given to sendmsg() if the upgrade request was ignored by
63362306a36Sopenharmony_cithe service - otherwise it will be altered to indicate the service ID the
63462306a36Sopenharmony_ciserver upgraded to.  Note that the upgraded service ID is chosen by the server.
63562306a36Sopenharmony_ciThe caller has to wait until it sees the service ID in the reply before sending
63662306a36Sopenharmony_ciany more calls (further calls to the same destination will be blocked until the
63762306a36Sopenharmony_ciprobe is concluded).
63862306a36Sopenharmony_ci
63962306a36Sopenharmony_ci
64062306a36Sopenharmony_ciExample Server Usage
64162306a36Sopenharmony_ci====================
64262306a36Sopenharmony_ci
64362306a36Sopenharmony_ciA server would be set up to accept operations in the following manner:
64462306a36Sopenharmony_ci
64562306a36Sopenharmony_ci (1) An RxRPC socket is created by::
64662306a36Sopenharmony_ci
64762306a36Sopenharmony_ci	server = socket(AF_RXRPC, SOCK_DGRAM, PF_INET);
64862306a36Sopenharmony_ci
64962306a36Sopenharmony_ci     Where the third parameter indicates the address type of the transport
65062306a36Sopenharmony_ci     socket used - usually IPv4.
65162306a36Sopenharmony_ci
65262306a36Sopenharmony_ci (2) Security is set up if desired by giving the socket a keyring with server
65362306a36Sopenharmony_ci     secret keys in it::
65462306a36Sopenharmony_ci
65562306a36Sopenharmony_ci	keyring = add_key("keyring", "AFSkeys", NULL, 0,
65662306a36Sopenharmony_ci			  KEY_SPEC_PROCESS_KEYRING);
65762306a36Sopenharmony_ci
65862306a36Sopenharmony_ci	const char secret_key[8] = {
65962306a36Sopenharmony_ci		0xa7, 0x83, 0x8a, 0xcb, 0xc7, 0x83, 0xec, 0x94 };
66062306a36Sopenharmony_ci	add_key("rxrpc_s", "52:2", secret_key, 8, keyring);
66162306a36Sopenharmony_ci
66262306a36Sopenharmony_ci	setsockopt(server, SOL_RXRPC, RXRPC_SECURITY_KEYRING, "AFSkeys", 7);
66362306a36Sopenharmony_ci
66462306a36Sopenharmony_ci     The keyring can be manipulated after it has been given to the socket. This
66562306a36Sopenharmony_ci     permits the server to add more keys, replace keys, etc. while it is live.
66662306a36Sopenharmony_ci
66762306a36Sopenharmony_ci (3) A local address must then be bound::
66862306a36Sopenharmony_ci
66962306a36Sopenharmony_ci	struct sockaddr_rxrpc srx = {
67062306a36Sopenharmony_ci		.srx_family	= AF_RXRPC,
67162306a36Sopenharmony_ci		.srx_service	= VL_SERVICE_ID, /* RxRPC service ID */
67262306a36Sopenharmony_ci		.transport_type	= SOCK_DGRAM,	/* type of transport socket */
67362306a36Sopenharmony_ci		.transport.sin_family	= AF_INET,
67462306a36Sopenharmony_ci		.transport.sin_port	= htons(7000), /* AFS callback */
67562306a36Sopenharmony_ci		.transport.sin_address	= 0,  /* all local interfaces */
67662306a36Sopenharmony_ci	};
67762306a36Sopenharmony_ci	bind(server, &srx, sizeof(srx));
67862306a36Sopenharmony_ci
67962306a36Sopenharmony_ci     More than one service ID may be bound to a socket, provided the transport
68062306a36Sopenharmony_ci     parameters are the same.  The limit is currently two.  To do this, bind()
68162306a36Sopenharmony_ci     should be called twice.
68262306a36Sopenharmony_ci
68362306a36Sopenharmony_ci (4) If service upgrading is required, first two service IDs must have been
68462306a36Sopenharmony_ci     bound and then the following option must be set::
68562306a36Sopenharmony_ci
68662306a36Sopenharmony_ci	unsigned short service_ids[2] = { from_ID, to_ID };
68762306a36Sopenharmony_ci	setsockopt(server, SOL_RXRPC, RXRPC_UPGRADEABLE_SERVICE,
68862306a36Sopenharmony_ci		   service_ids, sizeof(service_ids));
68962306a36Sopenharmony_ci
69062306a36Sopenharmony_ci     This will automatically upgrade connections on service from_ID to service
69162306a36Sopenharmony_ci     to_ID if they request it.  This will be reflected in msg_name obtained
69262306a36Sopenharmony_ci     through recvmsg() when the request data is delivered to userspace.
69362306a36Sopenharmony_ci
69462306a36Sopenharmony_ci (5) The server is then set to listen out for incoming calls::
69562306a36Sopenharmony_ci
69662306a36Sopenharmony_ci	listen(server, 100);
69762306a36Sopenharmony_ci
69862306a36Sopenharmony_ci (6) The kernel notifies the server of pending incoming connections by sending
69962306a36Sopenharmony_ci     it a message for each.  This is received with recvmsg() on the server
70062306a36Sopenharmony_ci     socket.  It has no data, and has a single dataless control message
70162306a36Sopenharmony_ci     attached::
70262306a36Sopenharmony_ci
70362306a36Sopenharmony_ci	RXRPC_NEW_CALL
70462306a36Sopenharmony_ci
70562306a36Sopenharmony_ci     The address that can be passed back by recvmsg() at this point should be
70662306a36Sopenharmony_ci     ignored since the call for which the message was posted may have gone by
70762306a36Sopenharmony_ci     the time it is accepted - in which case the first call still on the queue
70862306a36Sopenharmony_ci     will be accepted.
70962306a36Sopenharmony_ci
71062306a36Sopenharmony_ci (7) The server then accepts the new call by issuing a sendmsg() with two
71162306a36Sopenharmony_ci     pieces of control data and no actual data:
71262306a36Sopenharmony_ci
71362306a36Sopenharmony_ci	==================	==============================
71462306a36Sopenharmony_ci	RXRPC_ACCEPT		indicate connection acceptance
71562306a36Sopenharmony_ci	RXRPC_USER_CALL_ID	specify user ID for this call
71662306a36Sopenharmony_ci	==================	==============================
71762306a36Sopenharmony_ci
71862306a36Sopenharmony_ci (8) The first request data packet will then be posted to the server socket for
71962306a36Sopenharmony_ci     recvmsg() to pick up.  At that point, the RxRPC address for the call can
72062306a36Sopenharmony_ci     be read from the address fields in the msghdr struct.
72162306a36Sopenharmony_ci
72262306a36Sopenharmony_ci     Subsequent request data will be posted to the server socket for recvmsg()
72362306a36Sopenharmony_ci     to collect as it arrives.  All but the last piece of the request data will
72462306a36Sopenharmony_ci     be delivered with MSG_MORE flagged.
72562306a36Sopenharmony_ci
72662306a36Sopenharmony_ci     All data will be delivered with the following control message attached:
72762306a36Sopenharmony_ci
72862306a36Sopenharmony_ci
72962306a36Sopenharmony_ci	==================	===================================
73062306a36Sopenharmony_ci	RXRPC_USER_CALL_ID	specifies the user ID for this call
73162306a36Sopenharmony_ci	==================	===================================
73262306a36Sopenharmony_ci
73362306a36Sopenharmony_ci (9) The reply data should then be posted to the server socket using a series
73462306a36Sopenharmony_ci     of sendmsg() calls, each with the following control messages attached:
73562306a36Sopenharmony_ci
73662306a36Sopenharmony_ci	==================	===================================
73762306a36Sopenharmony_ci	RXRPC_USER_CALL_ID	specifies the user ID for this call
73862306a36Sopenharmony_ci	==================	===================================
73962306a36Sopenharmony_ci
74062306a36Sopenharmony_ci     MSG_MORE should be set in msghdr::msg_flags on all but the last message
74162306a36Sopenharmony_ci     for a particular call.
74262306a36Sopenharmony_ci
74362306a36Sopenharmony_ci(10) The final ACK from the client will be posted for retrieval by recvmsg()
74462306a36Sopenharmony_ci     when it is received.  It will take the form of a dataless message with two
74562306a36Sopenharmony_ci     control messages attached:
74662306a36Sopenharmony_ci
74762306a36Sopenharmony_ci	==================	===================================
74862306a36Sopenharmony_ci	RXRPC_USER_CALL_ID	specifies the user ID for this call
74962306a36Sopenharmony_ci	RXRPC_ACK		indicates final ACK (no data)
75062306a36Sopenharmony_ci	==================	===================================
75162306a36Sopenharmony_ci
75262306a36Sopenharmony_ci     MSG_EOR will be flagged to indicate that this is the final message for
75362306a36Sopenharmony_ci     this call.
75462306a36Sopenharmony_ci
75562306a36Sopenharmony_ci(11) Up to the point the final packet of reply data is sent, the call can be
75662306a36Sopenharmony_ci     aborted by calling sendmsg() with a dataless message with the following
75762306a36Sopenharmony_ci     control messages attached:
75862306a36Sopenharmony_ci
75962306a36Sopenharmony_ci	==================	===================================
76062306a36Sopenharmony_ci	RXRPC_USER_CALL_ID	specifies the user ID for this call
76162306a36Sopenharmony_ci	RXRPC_ABORT		indicates abort code (4 byte data)
76262306a36Sopenharmony_ci	==================	===================================
76362306a36Sopenharmony_ci
76462306a36Sopenharmony_ci     Any packets waiting in the socket's receive queue will be discarded if
76562306a36Sopenharmony_ci     this is issued.
76662306a36Sopenharmony_ci
76762306a36Sopenharmony_ciNote that all the communications for a particular service take place through
76862306a36Sopenharmony_cithe one server socket, using control messages on sendmsg() and recvmsg() to
76962306a36Sopenharmony_cidetermine the call affected.
77062306a36Sopenharmony_ci
77162306a36Sopenharmony_ci
77262306a36Sopenharmony_ciAF_RXRPC Kernel Interface
77362306a36Sopenharmony_ci=========================
77462306a36Sopenharmony_ci
77562306a36Sopenharmony_ciThe AF_RXRPC module also provides an interface for use by in-kernel utilities
77662306a36Sopenharmony_cisuch as the AFS filesystem.  This permits such a utility to:
77762306a36Sopenharmony_ci
77862306a36Sopenharmony_ci (1) Use different keys directly on individual client calls on one socket
77962306a36Sopenharmony_ci     rather than having to open a whole slew of sockets, one for each key it
78062306a36Sopenharmony_ci     might want to use.
78162306a36Sopenharmony_ci
78262306a36Sopenharmony_ci (2) Avoid having RxRPC call request_key() at the point of issue of a call or
78362306a36Sopenharmony_ci     opening of a socket.  Instead the utility is responsible for requesting a
78462306a36Sopenharmony_ci     key at the appropriate point.  AFS, for instance, would do this during VFS
78562306a36Sopenharmony_ci     operations such as open() or unlink().  The key is then handed through
78662306a36Sopenharmony_ci     when the call is initiated.
78762306a36Sopenharmony_ci
78862306a36Sopenharmony_ci (3) Request the use of something other than GFP_KERNEL to allocate memory.
78962306a36Sopenharmony_ci
79062306a36Sopenharmony_ci (4) Avoid the overhead of using the recvmsg() call.  RxRPC messages can be
79162306a36Sopenharmony_ci     intercepted before they get put into the socket Rx queue and the socket
79262306a36Sopenharmony_ci     buffers manipulated directly.
79362306a36Sopenharmony_ci
79462306a36Sopenharmony_ciTo use the RxRPC facility, a kernel utility must still open an AF_RXRPC socket,
79562306a36Sopenharmony_cibind an address as appropriate and listen if it's to be a server socket, but
79662306a36Sopenharmony_cithen it passes this to the kernel interface functions.
79762306a36Sopenharmony_ci
79862306a36Sopenharmony_ciThe kernel interface functions are as follows:
79962306a36Sopenharmony_ci
80062306a36Sopenharmony_ci (#) Begin a new client call::
80162306a36Sopenharmony_ci
80262306a36Sopenharmony_ci	struct rxrpc_call *
80362306a36Sopenharmony_ci	rxrpc_kernel_begin_call(struct socket *sock,
80462306a36Sopenharmony_ci				struct sockaddr_rxrpc *srx,
80562306a36Sopenharmony_ci				struct key *key,
80662306a36Sopenharmony_ci				unsigned long user_call_ID,
80762306a36Sopenharmony_ci				s64 tx_total_len,
80862306a36Sopenharmony_ci				gfp_t gfp,
80962306a36Sopenharmony_ci				rxrpc_notify_rx_t notify_rx,
81062306a36Sopenharmony_ci				bool upgrade,
81162306a36Sopenharmony_ci				bool intr,
81262306a36Sopenharmony_ci				unsigned int debug_id);
81362306a36Sopenharmony_ci
81462306a36Sopenharmony_ci     This allocates the infrastructure to make a new RxRPC call and assigns
81562306a36Sopenharmony_ci     call and connection numbers.  The call will be made on the UDP port that
81662306a36Sopenharmony_ci     the socket is bound to.  The call will go to the destination address of a
81762306a36Sopenharmony_ci     connected client socket unless an alternative is supplied (srx is
81862306a36Sopenharmony_ci     non-NULL).
81962306a36Sopenharmony_ci
82062306a36Sopenharmony_ci     If a key is supplied then this will be used to secure the call instead of
82162306a36Sopenharmony_ci     the key bound to the socket with the RXRPC_SECURITY_KEY sockopt.  Calls
82262306a36Sopenharmony_ci     secured in this way will still share connections if at all possible.
82362306a36Sopenharmony_ci
82462306a36Sopenharmony_ci     The user_call_ID is equivalent to that supplied to sendmsg() in the
82562306a36Sopenharmony_ci     control data buffer.  It is entirely feasible to use this to point to a
82662306a36Sopenharmony_ci     kernel data structure.
82762306a36Sopenharmony_ci
82862306a36Sopenharmony_ci     tx_total_len is the amount of data the caller is intending to transmit
82962306a36Sopenharmony_ci     with this call (or -1 if unknown at this point).  Setting the data size
83062306a36Sopenharmony_ci     allows the kernel to encrypt directly to the packet buffers, thereby
83162306a36Sopenharmony_ci     saving a copy.  The value may not be less than -1.
83262306a36Sopenharmony_ci
83362306a36Sopenharmony_ci     notify_rx is a pointer to a function to be called when events such as
83462306a36Sopenharmony_ci     incoming data packets or remote aborts happen.
83562306a36Sopenharmony_ci
83662306a36Sopenharmony_ci     upgrade should be set to true if a client operation should request that
83762306a36Sopenharmony_ci     the server upgrade the service to a better one.  The resultant service ID
83862306a36Sopenharmony_ci     is returned by rxrpc_kernel_recv_data().
83962306a36Sopenharmony_ci
84062306a36Sopenharmony_ci     intr should be set to true if the call should be interruptible.  If this
84162306a36Sopenharmony_ci     is not set, this function may not return until a channel has been
84262306a36Sopenharmony_ci     allocated; if it is set, the function may return -ERESTARTSYS.
84362306a36Sopenharmony_ci
84462306a36Sopenharmony_ci     debug_id is the call debugging ID to be used for tracing.  This can be
84562306a36Sopenharmony_ci     obtained by atomically incrementing rxrpc_debug_id.
84662306a36Sopenharmony_ci
84762306a36Sopenharmony_ci     If this function is successful, an opaque reference to the RxRPC call is
84862306a36Sopenharmony_ci     returned.  The caller now holds a reference on this and it must be
84962306a36Sopenharmony_ci     properly ended.
85062306a36Sopenharmony_ci
85162306a36Sopenharmony_ci (#) Shut down a client call::
85262306a36Sopenharmony_ci
85362306a36Sopenharmony_ci	void rxrpc_kernel_shutdown_call(struct socket *sock,
85462306a36Sopenharmony_ci					struct rxrpc_call *call);
85562306a36Sopenharmony_ci
85662306a36Sopenharmony_ci     This is used to shut down a previously begun call.  The user_call_ID is
85762306a36Sopenharmony_ci     expunged from AF_RXRPC's knowledge and will not be seen again in
85862306a36Sopenharmony_ci     association with the specified call.
85962306a36Sopenharmony_ci
86062306a36Sopenharmony_ci (#) Release the ref on a client call::
86162306a36Sopenharmony_ci
86262306a36Sopenharmony_ci	void rxrpc_kernel_put_call(struct socket *sock,
86362306a36Sopenharmony_ci				   struct rxrpc_call *call);
86462306a36Sopenharmony_ci
86562306a36Sopenharmony_ci     This is used to release the caller's ref on an rxrpc call.
86662306a36Sopenharmony_ci
86762306a36Sopenharmony_ci (#) Send data through a call::
86862306a36Sopenharmony_ci
86962306a36Sopenharmony_ci	typedef void (*rxrpc_notify_end_tx_t)(struct sock *sk,
87062306a36Sopenharmony_ci					      unsigned long user_call_ID,
87162306a36Sopenharmony_ci					      struct sk_buff *skb);
87262306a36Sopenharmony_ci
87362306a36Sopenharmony_ci	int rxrpc_kernel_send_data(struct socket *sock,
87462306a36Sopenharmony_ci				   struct rxrpc_call *call,
87562306a36Sopenharmony_ci				   struct msghdr *msg,
87662306a36Sopenharmony_ci				   size_t len,
87762306a36Sopenharmony_ci				   rxrpc_notify_end_tx_t notify_end_rx);
87862306a36Sopenharmony_ci
87962306a36Sopenharmony_ci     This is used to supply either the request part of a client call or the
88062306a36Sopenharmony_ci     reply part of a server call.  msg.msg_iovlen and msg.msg_iov specify the
88162306a36Sopenharmony_ci     data buffers to be used.  msg_iov may not be NULL and must point
88262306a36Sopenharmony_ci     exclusively to in-kernel virtual addresses.  msg.msg_flags may be given
88362306a36Sopenharmony_ci     MSG_MORE if there will be subsequent data sends for this call.
88462306a36Sopenharmony_ci
88562306a36Sopenharmony_ci     The msg must not specify a destination address, control data or any flags
88662306a36Sopenharmony_ci     other than MSG_MORE.  len is the total amount of data to transmit.
88762306a36Sopenharmony_ci
88862306a36Sopenharmony_ci     notify_end_rx can be NULL or it can be used to specify a function to be
88962306a36Sopenharmony_ci     called when the call changes state to end the Tx phase.  This function is
89062306a36Sopenharmony_ci     called with a spinlock held to prevent the last DATA packet from being
89162306a36Sopenharmony_ci     transmitted until the function returns.
89262306a36Sopenharmony_ci
89362306a36Sopenharmony_ci (#) Receive data from a call::
89462306a36Sopenharmony_ci
89562306a36Sopenharmony_ci	int rxrpc_kernel_recv_data(struct socket *sock,
89662306a36Sopenharmony_ci				   struct rxrpc_call *call,
89762306a36Sopenharmony_ci				   void *buf,
89862306a36Sopenharmony_ci				   size_t size,
89962306a36Sopenharmony_ci				   size_t *_offset,
90062306a36Sopenharmony_ci				   bool want_more,
90162306a36Sopenharmony_ci				   u32 *_abort,
90262306a36Sopenharmony_ci				   u16 *_service)
90362306a36Sopenharmony_ci
90462306a36Sopenharmony_ci      This is used to receive data from either the reply part of a client call
90562306a36Sopenharmony_ci      or the request part of a service call.  buf and size specify how much
90662306a36Sopenharmony_ci      data is desired and where to store it.  *_offset is added on to buf and
90762306a36Sopenharmony_ci      subtracted from size internally; the amount copied into the buffer is
90862306a36Sopenharmony_ci      added to *_offset before returning.
90962306a36Sopenharmony_ci
91062306a36Sopenharmony_ci      want_more should be true if further data will be required after this is
91162306a36Sopenharmony_ci      satisfied and false if this is the last item of the receive phase.
91262306a36Sopenharmony_ci
91362306a36Sopenharmony_ci      There are three normal returns: 0 if the buffer was filled and want_more
91462306a36Sopenharmony_ci      was true; 1 if the buffer was filled, the last DATA packet has been
91562306a36Sopenharmony_ci      emptied and want_more was false; and -EAGAIN if the function needs to be
91662306a36Sopenharmony_ci      called again.
91762306a36Sopenharmony_ci
91862306a36Sopenharmony_ci      If the last DATA packet is processed but the buffer contains less than
91962306a36Sopenharmony_ci      the amount requested, EBADMSG is returned.  If want_more wasn't set, but
92062306a36Sopenharmony_ci      more data was available, EMSGSIZE is returned.
92162306a36Sopenharmony_ci
92262306a36Sopenharmony_ci      If a remote ABORT is detected, the abort code received will be stored in
92362306a36Sopenharmony_ci      ``*_abort`` and ECONNABORTED will be returned.
92462306a36Sopenharmony_ci
92562306a36Sopenharmony_ci      The service ID that the call ended up with is returned into *_service.
92662306a36Sopenharmony_ci      This can be used to see if a call got a service upgrade.
92762306a36Sopenharmony_ci
92862306a36Sopenharmony_ci (#) Abort a call??
92962306a36Sopenharmony_ci
93062306a36Sopenharmony_ci     ::
93162306a36Sopenharmony_ci
93262306a36Sopenharmony_ci	void rxrpc_kernel_abort_call(struct socket *sock,
93362306a36Sopenharmony_ci				     struct rxrpc_call *call,
93462306a36Sopenharmony_ci				     u32 abort_code);
93562306a36Sopenharmony_ci
93662306a36Sopenharmony_ci     This is used to abort a call if it's still in an abortable state.  The
93762306a36Sopenharmony_ci     abort code specified will be placed in the ABORT message sent.
93862306a36Sopenharmony_ci
93962306a36Sopenharmony_ci (#) Intercept received RxRPC messages::
94062306a36Sopenharmony_ci
94162306a36Sopenharmony_ci	typedef void (*rxrpc_interceptor_t)(struct sock *sk,
94262306a36Sopenharmony_ci					    unsigned long user_call_ID,
94362306a36Sopenharmony_ci					    struct sk_buff *skb);
94462306a36Sopenharmony_ci
94562306a36Sopenharmony_ci	void
94662306a36Sopenharmony_ci	rxrpc_kernel_intercept_rx_messages(struct socket *sock,
94762306a36Sopenharmony_ci					   rxrpc_interceptor_t interceptor);
94862306a36Sopenharmony_ci
94962306a36Sopenharmony_ci     This installs an interceptor function on the specified AF_RXRPC socket.
95062306a36Sopenharmony_ci     All messages that would otherwise wind up in the socket's Rx queue are
95162306a36Sopenharmony_ci     then diverted to this function.  Note that care must be taken to process
95262306a36Sopenharmony_ci     the messages in the right order to maintain DATA message sequentiality.
95362306a36Sopenharmony_ci
95462306a36Sopenharmony_ci     The interceptor function itself is provided with the address of the socket
95562306a36Sopenharmony_ci     and handling the incoming message, the ID assigned by the kernel utility
95662306a36Sopenharmony_ci     to the call and the socket buffer containing the message.
95762306a36Sopenharmony_ci
95862306a36Sopenharmony_ci     The skb->mark field indicates the type of message:
95962306a36Sopenharmony_ci
96062306a36Sopenharmony_ci	===============================	=======================================
96162306a36Sopenharmony_ci	Mark				Meaning
96262306a36Sopenharmony_ci	===============================	=======================================
96362306a36Sopenharmony_ci	RXRPC_SKB_MARK_DATA		Data message
96462306a36Sopenharmony_ci	RXRPC_SKB_MARK_FINAL_ACK	Final ACK received for an incoming call
96562306a36Sopenharmony_ci	RXRPC_SKB_MARK_BUSY		Client call rejected as server busy
96662306a36Sopenharmony_ci	RXRPC_SKB_MARK_REMOTE_ABORT	Call aborted by peer
96762306a36Sopenharmony_ci	RXRPC_SKB_MARK_NET_ERROR	Network error detected
96862306a36Sopenharmony_ci	RXRPC_SKB_MARK_LOCAL_ERROR	Local error encountered
96962306a36Sopenharmony_ci	RXRPC_SKB_MARK_NEW_CALL		New incoming call awaiting acceptance
97062306a36Sopenharmony_ci	===============================	=======================================
97162306a36Sopenharmony_ci
97262306a36Sopenharmony_ci     The remote abort message can be probed with rxrpc_kernel_get_abort_code().
97362306a36Sopenharmony_ci     The two error messages can be probed with rxrpc_kernel_get_error_number().
97462306a36Sopenharmony_ci     A new call can be accepted with rxrpc_kernel_accept_call().
97562306a36Sopenharmony_ci
97662306a36Sopenharmony_ci     Data messages can have their contents extracted with the usual bunch of
97762306a36Sopenharmony_ci     socket buffer manipulation functions.  A data message can be determined to
97862306a36Sopenharmony_ci     be the last one in a sequence with rxrpc_kernel_is_data_last().  When a
97962306a36Sopenharmony_ci     data message has been used up, rxrpc_kernel_data_consumed() should be
98062306a36Sopenharmony_ci     called on it.
98162306a36Sopenharmony_ci
98262306a36Sopenharmony_ci     Messages should be handled to rxrpc_kernel_free_skb() to dispose of.  It
98362306a36Sopenharmony_ci     is possible to get extra refs on all types of message for later freeing,
98462306a36Sopenharmony_ci     but this may pin the state of a call until the message is finally freed.
98562306a36Sopenharmony_ci
98662306a36Sopenharmony_ci (#) Accept an incoming call::
98762306a36Sopenharmony_ci
98862306a36Sopenharmony_ci	struct rxrpc_call *
98962306a36Sopenharmony_ci	rxrpc_kernel_accept_call(struct socket *sock,
99062306a36Sopenharmony_ci				 unsigned long user_call_ID);
99162306a36Sopenharmony_ci
99262306a36Sopenharmony_ci     This is used to accept an incoming call and to assign it a call ID.  This
99362306a36Sopenharmony_ci     function is similar to rxrpc_kernel_begin_call() and calls accepted must
99462306a36Sopenharmony_ci     be ended in the same way.
99562306a36Sopenharmony_ci
99662306a36Sopenharmony_ci     If this function is successful, an opaque reference to the RxRPC call is
99762306a36Sopenharmony_ci     returned.  The caller now holds a reference on this and it must be
99862306a36Sopenharmony_ci     properly ended.
99962306a36Sopenharmony_ci
100062306a36Sopenharmony_ci (#) Reject an incoming call::
100162306a36Sopenharmony_ci
100262306a36Sopenharmony_ci	int rxrpc_kernel_reject_call(struct socket *sock);
100362306a36Sopenharmony_ci
100462306a36Sopenharmony_ci     This is used to reject the first incoming call on the socket's queue with
100562306a36Sopenharmony_ci     a BUSY message.  -ENODATA is returned if there were no incoming calls.
100662306a36Sopenharmony_ci     Other errors may be returned if the call had been aborted (-ECONNABORTED)
100762306a36Sopenharmony_ci     or had timed out (-ETIME).
100862306a36Sopenharmony_ci
100962306a36Sopenharmony_ci (#) Allocate a null key for doing anonymous security::
101062306a36Sopenharmony_ci
101162306a36Sopenharmony_ci	struct key *rxrpc_get_null_key(const char *keyname);
101262306a36Sopenharmony_ci
101362306a36Sopenharmony_ci     This is used to allocate a null RxRPC key that can be used to indicate
101462306a36Sopenharmony_ci     anonymous security for a particular domain.
101562306a36Sopenharmony_ci
101662306a36Sopenharmony_ci (#) Get the peer address of a call::
101762306a36Sopenharmony_ci
101862306a36Sopenharmony_ci	void rxrpc_kernel_get_peer(struct socket *sock, struct rxrpc_call *call,
101962306a36Sopenharmony_ci				   struct sockaddr_rxrpc *_srx);
102062306a36Sopenharmony_ci
102162306a36Sopenharmony_ci     This is used to find the remote peer address of a call.
102262306a36Sopenharmony_ci
102362306a36Sopenharmony_ci (#) Set the total transmit data size on a call::
102462306a36Sopenharmony_ci
102562306a36Sopenharmony_ci	void rxrpc_kernel_set_tx_length(struct socket *sock,
102662306a36Sopenharmony_ci					struct rxrpc_call *call,
102762306a36Sopenharmony_ci					s64 tx_total_len);
102862306a36Sopenharmony_ci
102962306a36Sopenharmony_ci     This sets the amount of data that the caller is intending to transmit on a
103062306a36Sopenharmony_ci     call.  It's intended to be used for setting the reply size as the request
103162306a36Sopenharmony_ci     size should be set when the call is begun.  tx_total_len may not be less
103262306a36Sopenharmony_ci     than zero.
103362306a36Sopenharmony_ci
103462306a36Sopenharmony_ci (#) Get call RTT::
103562306a36Sopenharmony_ci
103662306a36Sopenharmony_ci	u64 rxrpc_kernel_get_rtt(struct socket *sock, struct rxrpc_call *call);
103762306a36Sopenharmony_ci
103862306a36Sopenharmony_ci     Get the RTT time to the peer in use by a call.  The value returned is in
103962306a36Sopenharmony_ci     nanoseconds.
104062306a36Sopenharmony_ci
104162306a36Sopenharmony_ci (#) Check call still alive::
104262306a36Sopenharmony_ci
104362306a36Sopenharmony_ci	bool rxrpc_kernel_check_life(struct socket *sock,
104462306a36Sopenharmony_ci				     struct rxrpc_call *call,
104562306a36Sopenharmony_ci				     u32 *_life);
104662306a36Sopenharmony_ci	void rxrpc_kernel_probe_life(struct socket *sock,
104762306a36Sopenharmony_ci				     struct rxrpc_call *call);
104862306a36Sopenharmony_ci
104962306a36Sopenharmony_ci     The first function passes back in ``*_life`` a number that is updated when
105062306a36Sopenharmony_ci     ACKs are received from the peer (notably including PING RESPONSE ACKs
105162306a36Sopenharmony_ci     which we can elicit by sending PING ACKs to see if the call still exists
105262306a36Sopenharmony_ci     on the server).  The caller should compare the numbers of two calls to see
105362306a36Sopenharmony_ci     if the call is still alive after waiting for a suitable interval.  It also
105462306a36Sopenharmony_ci     returns true as long as the call hasn't yet reached the completed state.
105562306a36Sopenharmony_ci
105662306a36Sopenharmony_ci     This allows the caller to work out if the server is still contactable and
105762306a36Sopenharmony_ci     if the call is still alive on the server while waiting for the server to
105862306a36Sopenharmony_ci     process a client operation.
105962306a36Sopenharmony_ci
106062306a36Sopenharmony_ci     The second function causes a ping ACK to be transmitted to try to provoke
106162306a36Sopenharmony_ci     the peer into responding, which would then cause the value returned by the
106262306a36Sopenharmony_ci     first function to change.  Note that this must be called in TASK_RUNNING
106362306a36Sopenharmony_ci     state.
106462306a36Sopenharmony_ci
106562306a36Sopenharmony_ci (#) Get remote client epoch::
106662306a36Sopenharmony_ci
106762306a36Sopenharmony_ci	u32 rxrpc_kernel_get_epoch(struct socket *sock,
106862306a36Sopenharmony_ci				   struct rxrpc_call *call)
106962306a36Sopenharmony_ci
107062306a36Sopenharmony_ci     This allows the epoch that's contained in packets of an incoming client
107162306a36Sopenharmony_ci     call to be queried.  This value is returned.  The function always
107262306a36Sopenharmony_ci     successful if the call is still in progress.  It shouldn't be called once
107362306a36Sopenharmony_ci     the call has expired.  Note that calling this on a local client call only
107462306a36Sopenharmony_ci     returns the local epoch.
107562306a36Sopenharmony_ci
107662306a36Sopenharmony_ci     This value can be used to determine if the remote client has been
107762306a36Sopenharmony_ci     restarted as it shouldn't change otherwise.
107862306a36Sopenharmony_ci
107962306a36Sopenharmony_ci (#) Set the maximum lifespan on a call::
108062306a36Sopenharmony_ci
108162306a36Sopenharmony_ci	void rxrpc_kernel_set_max_life(struct socket *sock,
108262306a36Sopenharmony_ci				       struct rxrpc_call *call,
108362306a36Sopenharmony_ci				       unsigned long hard_timeout)
108462306a36Sopenharmony_ci
108562306a36Sopenharmony_ci     This sets the maximum lifespan on a call to hard_timeout (which is in
108662306a36Sopenharmony_ci     jiffies).  In the event of the timeout occurring, the call will be
108762306a36Sopenharmony_ci     aborted and -ETIME or -ETIMEDOUT will be returned.
108862306a36Sopenharmony_ci
108962306a36Sopenharmony_ci (#) Apply the RXRPC_MIN_SECURITY_LEVEL sockopt to a socket from within in the
109062306a36Sopenharmony_ci     kernel::
109162306a36Sopenharmony_ci
109262306a36Sopenharmony_ci       int rxrpc_sock_set_min_security_level(struct sock *sk,
109362306a36Sopenharmony_ci					     unsigned int val);
109462306a36Sopenharmony_ci
109562306a36Sopenharmony_ci     This specifies the minimum security level required for calls on this
109662306a36Sopenharmony_ci     socket.
109762306a36Sopenharmony_ci
109862306a36Sopenharmony_ci
109962306a36Sopenharmony_ciConfigurable Parameters
110062306a36Sopenharmony_ci=======================
110162306a36Sopenharmony_ci
110262306a36Sopenharmony_ciThe RxRPC protocol driver has a number of configurable parameters that can be
110362306a36Sopenharmony_ciadjusted through sysctls in /proc/net/rxrpc/:
110462306a36Sopenharmony_ci
110562306a36Sopenharmony_ci (#) req_ack_delay
110662306a36Sopenharmony_ci
110762306a36Sopenharmony_ci     The amount of time in milliseconds after receiving a packet with the
110862306a36Sopenharmony_ci     request-ack flag set before we honour the flag and actually send the
110962306a36Sopenharmony_ci     requested ack.
111062306a36Sopenharmony_ci
111162306a36Sopenharmony_ci     Usually the other side won't stop sending packets until the advertised
111262306a36Sopenharmony_ci     reception window is full (to a maximum of 255 packets), so delaying the
111362306a36Sopenharmony_ci     ACK permits several packets to be ACK'd in one go.
111462306a36Sopenharmony_ci
111562306a36Sopenharmony_ci (#) soft_ack_delay
111662306a36Sopenharmony_ci
111762306a36Sopenharmony_ci     The amount of time in milliseconds after receiving a new packet before we
111862306a36Sopenharmony_ci     generate a soft-ACK to tell the sender that it doesn't need to resend.
111962306a36Sopenharmony_ci
112062306a36Sopenharmony_ci (#) idle_ack_delay
112162306a36Sopenharmony_ci
112262306a36Sopenharmony_ci     The amount of time in milliseconds after all the packets currently in the
112362306a36Sopenharmony_ci     received queue have been consumed before we generate a hard-ACK to tell
112462306a36Sopenharmony_ci     the sender it can free its buffers, assuming no other reason occurs that
112562306a36Sopenharmony_ci     we would send an ACK.
112662306a36Sopenharmony_ci
112762306a36Sopenharmony_ci (#) resend_timeout
112862306a36Sopenharmony_ci
112962306a36Sopenharmony_ci     The amount of time in milliseconds after transmitting a packet before we
113062306a36Sopenharmony_ci     transmit it again, assuming no ACK is received from the receiver telling
113162306a36Sopenharmony_ci     us they got it.
113262306a36Sopenharmony_ci
113362306a36Sopenharmony_ci (#) max_call_lifetime
113462306a36Sopenharmony_ci
113562306a36Sopenharmony_ci     The maximum amount of time in seconds that a call may be in progress
113662306a36Sopenharmony_ci     before we preemptively kill it.
113762306a36Sopenharmony_ci
113862306a36Sopenharmony_ci (#) dead_call_expiry
113962306a36Sopenharmony_ci
114062306a36Sopenharmony_ci     The amount of time in seconds before we remove a dead call from the call
114162306a36Sopenharmony_ci     list.  Dead calls are kept around for a little while for the purpose of
114262306a36Sopenharmony_ci     repeating ACK and ABORT packets.
114362306a36Sopenharmony_ci
114462306a36Sopenharmony_ci (#) connection_expiry
114562306a36Sopenharmony_ci
114662306a36Sopenharmony_ci     The amount of time in seconds after a connection was last used before we
114762306a36Sopenharmony_ci     remove it from the connection list.  While a connection is in existence,
114862306a36Sopenharmony_ci     it serves as a placeholder for negotiated security; when it is deleted,
114962306a36Sopenharmony_ci     the security must be renegotiated.
115062306a36Sopenharmony_ci
115162306a36Sopenharmony_ci (#) transport_expiry
115262306a36Sopenharmony_ci
115362306a36Sopenharmony_ci     The amount of time in seconds after a transport was last used before we
115462306a36Sopenharmony_ci     remove it from the transport list.  While a transport is in existence, it
115562306a36Sopenharmony_ci     serves to anchor the peer data and keeps the connection ID counter.
115662306a36Sopenharmony_ci
115762306a36Sopenharmony_ci (#) rxrpc_rx_window_size
115862306a36Sopenharmony_ci
115962306a36Sopenharmony_ci     The size of the receive window in packets.  This is the maximum number of
116062306a36Sopenharmony_ci     unconsumed received packets we're willing to hold in memory for any
116162306a36Sopenharmony_ci     particular call.
116262306a36Sopenharmony_ci
116362306a36Sopenharmony_ci (#) rxrpc_rx_mtu
116462306a36Sopenharmony_ci
116562306a36Sopenharmony_ci     The maximum packet MTU size that we're willing to receive in bytes.  This
116662306a36Sopenharmony_ci     indicates to the peer whether we're willing to accept jumbo packets.
116762306a36Sopenharmony_ci
116862306a36Sopenharmony_ci (#) rxrpc_rx_jumbo_max
116962306a36Sopenharmony_ci
117062306a36Sopenharmony_ci     The maximum number of packets that we're willing to accept in a jumbo
117162306a36Sopenharmony_ci     packet.  Non-terminal packets in a jumbo packet must contain a four byte
117262306a36Sopenharmony_ci     header plus exactly 1412 bytes of data.  The terminal packet must contain
117362306a36Sopenharmony_ci     a four byte header plus any amount of data.  In any event, a jumbo packet
117462306a36Sopenharmony_ci     may not exceed rxrpc_rx_mtu in size.
1175