• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1			    ======================
2			    RxRPC NETWORK PROTOCOL
3			    ======================
4
5The RxRPC protocol driver provides a reliable two-phase transport on top of UDP
6that can be used to perform RxRPC remote operations.  This is done over sockets
7of AF_RXRPC family, using sendmsg() and recvmsg() with control data to send and
8receive data, aborts and errors.
9
10Contents of this document:
11
12 (*) Overview.
13
14 (*) RxRPC protocol summary.
15
16 (*) AF_RXRPC driver model.
17
18 (*) Control messages.
19
20 (*) Socket options.
21
22 (*) Security.
23
24 (*) Example client usage.
25
26 (*) Example server usage.
27
28 (*) AF_RXRPC kernel interface.
29
30 (*) Configurable parameters.
31
32
33========
34OVERVIEW
35========
36
37RxRPC is a two-layer protocol.  There is a session layer which provides
38reliable virtual connections using UDP over IPv4 (or IPv6) as the transport
39layer, but implements a real network protocol; and there's the presentation
40layer which renders structured data to binary blobs and back again using XDR
41(as does SunRPC):
42
43		+-------------+
44		| Application |
45		+-------------+
46		|     XDR     |		Presentation
47		+-------------+
48		|    RxRPC    |		Session
49		+-------------+
50		|     UDP     |		Transport
51		+-------------+
52
53
54AF_RXRPC provides:
55
56 (1) Part of an RxRPC facility for both kernel and userspace applications by
57     making the session part of it a Linux network protocol (AF_RXRPC).
58
59 (2) A two-phase protocol.  The client transmits a blob (the request) and then
60     receives a blob (the reply), and the server receives the request and then
61     transmits the reply.
62
63 (3) Retention of the reusable bits of the transport system set up for one call
64     to speed up subsequent calls.
65
66 (4) A secure protocol, using the Linux kernel's key retention facility to
67     manage security on the client end.  The server end must of necessity be
68     more active in security negotiations.
69
70AF_RXRPC does not provide XDR marshalling/presentation facilities.  That is
71left to the application.  AF_RXRPC only deals in blobs.  Even the operation ID
72is just the first four bytes of the request blob, and as such is beyond the
73kernel's interest.
74
75
76Sockets of AF_RXRPC family are:
77
78 (1) created as type SOCK_DGRAM;
79
80 (2) provided with a protocol of the type of underlying transport they're going
81     to use - currently only PF_INET is supported.
82
83
84The Andrew File System (AFS) is an example of an application that uses this and
85that has both kernel (filesystem) and userspace (utility) components.
86
87
88======================
89RXRPC PROTOCOL SUMMARY
90======================
91
92An overview of the RxRPC protocol:
93
94 (*) RxRPC sits on top of another networking protocol (UDP is the only option
95     currently), and uses this to provide network transport.  UDP ports, for
96     example, provide transport endpoints.
97
98 (*) RxRPC supports multiple virtual "connections" from any given transport
99     endpoint, thus allowing the endpoints to be shared, even to the same
100     remote endpoint.
101
102 (*) Each connection goes to a particular "service".  A connection may not go
103     to multiple services.  A service may be considered the RxRPC equivalent of
104     a port number.  AF_RXRPC permits multiple services to share an endpoint.
105
106 (*) Client-originating packets are marked, thus a transport endpoint can be
107     shared between client and server connections (connections have a
108     direction).
109
110 (*) Up to a billion connections may be supported concurrently between one
111     local transport endpoint and one service on one remote endpoint.  An RxRPC
112     connection is described by seven numbers:
113
114	Local address	}
115	Local port	} Transport (UDP) address
116	Remote address	}
117	Remote port	}
118	Direction
119	Connection ID
120	Service ID
121
122 (*) Each RxRPC operation is a "call".  A connection may make up to four
123     billion calls, but only up to four calls may be in progress on a
124     connection at any one time.
125
126 (*) Calls are two-phase and asymmetric: the client sends its request data,
127     which the service receives; then the service transmits the reply data
128     which the client receives.
129
130 (*) The data blobs are of indefinite size, the end of a phase is marked with a
131     flag in the packet.  The number of packets of data making up one blob may
132     not exceed 4 billion, however, as this would cause the sequence number to
133     wrap.
134
135 (*) The first four bytes of the request data are the service operation ID.
136
137 (*) Security is negotiated on a per-connection basis.  The connection is
138     initiated by the first data packet on it arriving.  If security is
139     requested, the server then issues a "challenge" and then the client
140     replies with a "response".  If the response is successful, the security is
141     set for the lifetime of that connection, and all subsequent calls made
142     upon it use that same security.  In the event that the server lets a
143     connection lapse before the client, the security will be renegotiated if
144     the client uses the connection again.
145
146 (*) Calls use ACK packets to handle reliability.  Data packets are also
147     explicitly sequenced per call.
148
149 (*) There are two types of positive acknowledgment: hard-ACKs and soft-ACKs.
150     A hard-ACK indicates to the far side that all the data received to a point
151     has been received and processed; a soft-ACK indicates that the data has
152     been received but may yet be discarded and re-requested.  The sender may
153     not discard any transmittable packets until they've been hard-ACK'd.
154
155 (*) Reception of a reply data packet implicitly hard-ACK's all the data
156     packets that make up the request.
157
158 (*) An call is complete when the request has been sent, the reply has been
159     received and the final hard-ACK on the last packet of the reply has
160     reached the server.
161
162 (*) An call may be aborted by either end at any time up to its completion.
163
164
165=====================
166AF_RXRPC DRIVER MODEL
167=====================
168
169About the AF_RXRPC driver:
170
171 (*) The AF_RXRPC protocol transparently uses internal sockets of the transport
172     protocol to represent transport endpoints.
173
174 (*) AF_RXRPC sockets map onto RxRPC connection bundles.  Actual RxRPC
175     connections are handled transparently.  One client socket may be used to
176     make multiple simultaneous calls to the same service.  One server socket
177     may handle calls from many clients.
178
179 (*) Additional parallel client connections will be initiated to support extra
180     concurrent calls, up to a tunable limit.
181
182 (*) Each connection is retained for a certain amount of time [tunable] after
183     the last call currently using it has completed in case a new call is made
184     that could reuse it.
185
186 (*) Each internal UDP socket is retained [tunable] for a certain amount of
187     time [tunable] after the last connection using it discarded, in case a new
188     connection is made that could use it.
189
190 (*) A client-side connection is only shared between calls if they have have
191     the same key struct describing their security (and assuming the calls
192     would otherwise share the connection).  Non-secured calls would also be
193     able to share connections with each other.
194
195 (*) A server-side connection is shared if the client says it is.
196
197 (*) ACK'ing is handled by the protocol driver automatically, including ping
198     replying.
199
200 (*) SO_KEEPALIVE automatically pings the other side to keep the connection
201     alive [TODO].
202
203 (*) If an ICMP error is received, all calls affected by that error will be
204     aborted with an appropriate network error passed through recvmsg().
205
206
207Interaction with the user of the RxRPC socket:
208
209 (*) A socket is made into a server socket by binding an address with a
210     non-zero service ID.
211
212 (*) In the client, sending a request is achieved with one or more sendmsgs,
213     followed by the reply being received with one or more recvmsgs.
214
215 (*) The first sendmsg for a request to be sent from a client contains a tag to
216     be used in all other sendmsgs or recvmsgs associated with that call.  The
217     tag is carried in the control data.
218
219 (*) connect() is used to supply a default destination address for a client
220     socket.  This may be overridden by supplying an alternate address to the
221     first sendmsg() of a call (struct msghdr::msg_name).
222
223 (*) If connect() is called on an unbound client, a random local port will
224     bound before the operation takes place.
225
226 (*) A server socket may also be used to make client calls.  To do this, the
227     first sendmsg() of the call must specify the target address.  The server's
228     transport endpoint is used to send the packets.
229
230 (*) Once the application has received the last message associated with a call,
231     the tag is guaranteed not to be seen again, and so it can be used to pin
232     client resources.  A new call can then be initiated with the same tag
233     without fear of interference.
234
235 (*) In the server, a request is received with one or more recvmsgs, then the
236     the reply is transmitted with one or more sendmsgs, and then the final ACK
237     is received with a last recvmsg.
238
239 (*) When sending data for a call, sendmsg is given MSG_MORE if there's more
240     data to come on that call.
241
242 (*) When receiving data for a call, recvmsg flags MSG_MORE if there's more
243     data to come for that call.
244
245 (*) When receiving data or messages for a call, MSG_EOR is flagged by recvmsg
246     to indicate the terminal message for that call.
247
248 (*) A call may be aborted by adding an abort control message to the control
249     data.  Issuing an abort terminates the kernel's use of that call's tag.
250     Any messages waiting in the receive queue for that call will be discarded.
251
252 (*) Aborts, busy notifications and challenge packets are delivered by recvmsg,
253     and control data messages will be set to indicate the context.  Receiving
254     an abort or a busy message terminates the kernel's use of that call's tag.
255
256 (*) The control data part of the msghdr struct is used for a number of things:
257
258     (*) The tag of the intended or affected call.
259
260     (*) Sending or receiving errors, aborts and busy notifications.
261
262     (*) Notifications of incoming calls.
263
264     (*) Sending debug requests and receiving debug replies [TODO].
265
266 (*) When the kernel has received and set up an incoming call, it sends a
267     message to server application to let it know there's a new call awaiting
268     its acceptance [recvmsg reports a special control message].  The server
269     application then uses sendmsg to assign a tag to the new call.  Once that
270     is done, the first part of the request data will be delivered by recvmsg.
271
272 (*) The server application has to provide the server socket with a keyring of
273     secret keys corresponding to the security types it permits.  When a secure
274     connection is being set up, the kernel looks up the appropriate secret key
275     in the keyring and then sends a challenge packet to the client and
276     receives a response packet.  The kernel then checks the authorisation of
277     the packet and either aborts the connection or sets up the security.
278
279 (*) The name of the key a client will use to secure its communications is
280     nominated by a socket option.
281
282
283Notes on recvmsg:
284
285 (*) If there's a sequence of data messages belonging to a particular call on
286     the receive queue, then recvmsg will keep working through them until:
287
288     (a) it meets the end of that call's received data,
289
290     (b) it meets a non-data message,
291
292     (c) it meets a message belonging to a different call, or
293
294     (d) it fills the user buffer.
295
296     If recvmsg is called in blocking mode, it will keep sleeping, awaiting the
297     reception of further data, until one of the above four conditions is met.
298
299 (2) MSG_PEEK operates similarly, but will return immediately if it has put any
300     data in the buffer rather than sleeping until it can fill the buffer.
301
302 (3) If a data message is only partially consumed in filling a user buffer,
303     then the remainder of that message will be left on the front of the queue
304     for the next taker.  MSG_TRUNC will never be flagged.
305
306 (4) If there is more data to be had on a call (it hasn't copied the last byte
307     of the last data message in that phase yet), then MSG_MORE will be
308     flagged.
309
310
311================
312CONTROL MESSAGES
313================
314
315AF_RXRPC makes use of control messages in sendmsg() and recvmsg() to multiplex
316calls, to invoke certain actions and to report certain conditions.  These are:
317
318	MESSAGE ID		SRT DATA	MEANING
319	=======================	=== ===========	===============================
320	RXRPC_USER_CALL_ID	sr- User ID	App's call specifier
321	RXRPC_ABORT		srt Abort code	Abort code to issue/received
322	RXRPC_ACK		-rt n/a		Final ACK received
323	RXRPC_NET_ERROR		-rt error num	Network error on call
324	RXRPC_BUSY		-rt n/a		Call rejected (server busy)
325	RXRPC_LOCAL_ERROR	-rt error num	Local error encountered
326	RXRPC_NEW_CALL		-r- n/a		New call received
327	RXRPC_ACCEPT		s-- n/a		Accept new call
328	RXRPC_EXCLUSIVE_CALL	s-- n/a		Make an exclusive client call
329	RXRPC_UPGRADE_SERVICE	s-- n/a		Client call can be upgraded
330	RXRPC_TX_LENGTH		s-- data len	Total length of Tx data
331
332	(SRT = usable in Sendmsg / delivered by Recvmsg / Terminal message)
333
334 (*) RXRPC_USER_CALL_ID
335
336     This is used to indicate the application's call ID.  It's an unsigned long
337     that the app specifies in the client by attaching it to the first data
338     message or in the server by passing it in association with an RXRPC_ACCEPT
339     message.  recvmsg() passes it in conjunction with all messages except
340     those of the RXRPC_NEW_CALL message.
341
342 (*) RXRPC_ABORT
343
344     This is can be used by an application to abort a call by passing it to
345     sendmsg, or it can be delivered by recvmsg to indicate a remote abort was
346     received.  Either way, it must be associated with an RXRPC_USER_CALL_ID to
347     specify the call affected.  If an abort is being sent, then error EBADSLT
348     will be returned if there is no call with that user ID.
349
350 (*) RXRPC_ACK
351
352     This is delivered to a server application to indicate that the final ACK
353     of a call was received from the client.  It will be associated with an
354     RXRPC_USER_CALL_ID to indicate the call that's now complete.
355
356 (*) RXRPC_NET_ERROR
357
358     This is delivered to an application to indicate that an ICMP error message
359     was encountered in the process of trying to talk to the peer.  An
360     errno-class integer value will be included in the control message data
361     indicating the problem, and an RXRPC_USER_CALL_ID will indicate the call
362     affected.
363
364 (*) RXRPC_BUSY
365
366     This is delivered to a client application to indicate that a call was
367     rejected by the server due to the server being busy.  It will be
368     associated with an RXRPC_USER_CALL_ID to indicate the rejected call.
369
370 (*) RXRPC_LOCAL_ERROR
371
372     This is delivered to an application to indicate that a local error was
373     encountered and that a call has been aborted because of it.  An
374     errno-class integer value will be included in the control message data
375     indicating the problem, and an RXRPC_USER_CALL_ID will indicate the call
376     affected.
377
378 (*) RXRPC_NEW_CALL
379
380     This is delivered to indicate to a server application that a new call has
381     arrived and is awaiting acceptance.  No user ID is associated with this,
382     as a user ID must subsequently be assigned by doing an RXRPC_ACCEPT.
383
384 (*) RXRPC_ACCEPT
385
386     This is used by a server application to attempt to accept a call and
387     assign it a user ID.  It should be associated with an RXRPC_USER_CALL_ID
388     to indicate the user ID to be assigned.  If there is no call to be
389     accepted (it may have timed out, been aborted, etc.), then sendmsg will
390     return error ENODATA.  If the user ID is already in use by another call,
391     then error EBADSLT will be returned.
392
393 (*) RXRPC_EXCLUSIVE_CALL
394
395     This is used to indicate that a client call should be made on a one-off
396     connection.  The connection is discarded once the call has terminated.
397
398 (*) RXRPC_UPGRADE_SERVICE
399
400     This is used to make a client call to probe if the specified service ID
401     may be upgraded by the server.  The caller must check msg_name returned to
402     recvmsg() for the service ID actually in use.  The operation probed must
403     be one that takes the same arguments in both services.
404
405     Once this has been used to establish the upgrade capability (or lack
406     thereof) of the server, the service ID returned should be used for all
407     future communication to that server and RXRPC_UPGRADE_SERVICE should no
408     longer be set.
409
410 (*) RXRPC_TX_LENGTH
411
412     This is used to inform the kernel of the total amount of data that is
413     going to be transmitted by a call (whether in a client request or a
414     service response).  If given, it allows the kernel to encrypt from the
415     userspace buffer directly to the packet buffers, rather than copying into
416     the buffer and then encrypting in place.  This may only be given with the
417     first sendmsg() providing data for a call.  EMSGSIZE will be generated if
418     the amount of data actually given is different.
419
420     This takes a parameter of __s64 type that indicates how much will be
421     transmitted.  This may not be less than zero.
422
423The symbol RXRPC__SUPPORTED is defined as one more than the highest control
424message type supported.  At run time this can be queried by means of the
425RXRPC_SUPPORTED_CMSG socket option (see below).
426
427
428==============
429SOCKET OPTIONS
430==============
431
432AF_RXRPC sockets support a few socket options at the SOL_RXRPC level:
433
434 (*) RXRPC_SECURITY_KEY
435
436     This is used to specify the description of the key to be used.  The key is
437     extracted from the calling process's keyrings with request_key() and
438     should be of "rxrpc" type.
439
440     The optval pointer points to the description string, and optlen indicates
441     how long the string is, without the NUL terminator.
442
443 (*) RXRPC_SECURITY_KEYRING
444
445     Similar to above but specifies a keyring of server secret keys to use (key
446     type "keyring").  See the "Security" section.
447
448 (*) RXRPC_EXCLUSIVE_CONNECTION
449
450     This is used to request that new connections should be used for each call
451     made subsequently on this socket.  optval should be NULL and optlen 0.
452
453 (*) RXRPC_MIN_SECURITY_LEVEL
454
455     This is used to specify the minimum security level required for calls on
456     this socket.  optval must point to an int containing one of the following
457     values:
458
459     (a) RXRPC_SECURITY_PLAIN
460
461	 Encrypted checksum only.
462
463     (b) RXRPC_SECURITY_AUTH
464
465	 Encrypted checksum plus packet padded and first eight bytes of packet
466	 encrypted - which includes the actual packet length.
467
468     (c) RXRPC_SECURITY_ENCRYPTED
469
470	 Encrypted checksum plus entire packet padded and encrypted, including
471	 actual packet length.
472
473 (*) RXRPC_UPGRADEABLE_SERVICE
474
475     This is used to indicate that a service socket with two bindings may
476     upgrade one bound service to the other if requested by the client.  optval
477     must point to an array of two unsigned short ints.  The first is the
478     service ID to upgrade from and the second the service ID to upgrade to.
479
480 (*) RXRPC_SUPPORTED_CMSG
481
482     This is a read-only option that writes an int into the buffer indicating
483     the highest control message type supported.
484
485
486========
487SECURITY
488========
489
490Currently, only the kerberos 4 equivalent protocol has been implemented
491(security index 2 - rxkad).  This requires the rxkad module to be loaded and,
492on the client, tickets of the appropriate type to be obtained from the AFS
493kaserver or the kerberos server and installed as "rxrpc" type keys.  This is
494normally done using the klog program.  An example simple klog program can be
495found at:
496
497	http://people.redhat.com/~dhowells/rxrpc/klog.c
498
499The payload provided to add_key() on the client should be of the following
500form:
501
502	struct rxrpc_key_sec2_v1 {
503		uint16_t	security_index;	/* 2 */
504		uint16_t	ticket_length;	/* length of ticket[] */
505		uint32_t	expiry;		/* time at which expires */
506		uint8_t		kvno;		/* key version number */
507		uint8_t		__pad[3];
508		uint8_t		session_key[8];	/* DES session key */
509		uint8_t		ticket[0];	/* the encrypted ticket */
510	};
511
512Where the ticket blob is just appended to the above structure.
513
514
515For the server, keys of type "rxrpc_s" must be made available to the server.
516They have a description of "<serviceID>:<securityIndex>" (eg: "52:2" for an
517rxkad key for the AFS VL service).  When such a key is created, it should be
518given the server's secret key as the instantiation data (see the example
519below).
520
521	add_key("rxrpc_s", "52:2", secret_key, 8, keyring);
522
523A keyring is passed to the server socket by naming it in a sockopt.  The server
524socket then looks the server secret keys up in this keyring when secure
525incoming connections are made.  This can be seen in an example program that can
526be found at:
527
528	http://people.redhat.com/~dhowells/rxrpc/listen.c
529
530
531====================
532EXAMPLE CLIENT USAGE
533====================
534
535A client would issue an operation by:
536
537 (1) An RxRPC socket is set up by:
538
539	client = socket(AF_RXRPC, SOCK_DGRAM, PF_INET);
540
541     Where the third parameter indicates the protocol family of the transport
542     socket used - usually IPv4 but it can also be IPv6 [TODO].
543
544 (2) A local address can optionally be bound:
545
546	struct sockaddr_rxrpc srx = {
547		.srx_family	= AF_RXRPC,
548		.srx_service	= 0,  /* we're a client */
549		.transport_type	= SOCK_DGRAM,	/* type of transport socket */
550		.transport.sin_family	= AF_INET,
551		.transport.sin_port	= htons(7000), /* AFS callback */
552		.transport.sin_address	= 0,  /* all local interfaces */
553	};
554	bind(client, &srx, sizeof(srx));
555
556     This specifies the local UDP port to be used.  If not given, a random
557     non-privileged port will be used.  A UDP port may be shared between
558     several unrelated RxRPC sockets.  Security is handled on a basis of
559     per-RxRPC virtual connection.
560
561 (3) The security is set:
562
563	const char *key = "AFS:cambridge.redhat.com";
564	setsockopt(client, SOL_RXRPC, RXRPC_SECURITY_KEY, key, strlen(key));
565
566     This issues a request_key() to get the key representing the security
567     context.  The minimum security level can be set:
568
569	unsigned int sec = RXRPC_SECURITY_ENCRYPTED;
570	setsockopt(client, SOL_RXRPC, RXRPC_MIN_SECURITY_LEVEL,
571		   &sec, sizeof(sec));
572
573 (4) The server to be contacted can then be specified (alternatively this can
574     be done through sendmsg):
575
576	struct sockaddr_rxrpc srx = {
577		.srx_family	= AF_RXRPC,
578		.srx_service	= VL_SERVICE_ID,
579		.transport_type	= SOCK_DGRAM,	/* type of transport socket */
580		.transport.sin_family	= AF_INET,
581		.transport.sin_port	= htons(7005), /* AFS volume manager */
582		.transport.sin_address	= ...,
583	};
584	connect(client, &srx, sizeof(srx));
585
586 (5) The request data should then be posted to the server socket using a series
587     of sendmsg() calls, each with the following control message attached:
588
589	RXRPC_USER_CALL_ID	- specifies the user ID for this call
590
591     MSG_MORE should be set in msghdr::msg_flags on all but the last part of
592     the request.  Multiple requests may be made simultaneously.
593
594     An RXRPC_TX_LENGTH control message can also be specified on the first
595     sendmsg() call.
596
597     If a call is intended to go to a destination other than the default
598     specified through connect(), then msghdr::msg_name should be set on the
599     first request message of that call.
600
601 (6) The reply data will then be posted to the server socket for recvmsg() to
602     pick up.  MSG_MORE will be flagged by recvmsg() if there's more reply data
603     for a particular call to be read.  MSG_EOR will be set on the terminal
604     read for a call.
605
606     All data will be delivered with the following control message attached:
607
608	RXRPC_USER_CALL_ID	- specifies the user ID for this call
609
610     If an abort or error occurred, this will be returned in the control data
611     buffer instead, and MSG_EOR will be flagged to indicate the end of that
612     call.
613
614A client may ask for a service ID it knows and ask that this be upgraded to a
615better service if one is available by supplying RXRPC_UPGRADE_SERVICE on the
616first sendmsg() of a call.  The client should then check srx_service in the
617msg_name filled in by recvmsg() when collecting the result.  srx_service will
618hold the same value as given to sendmsg() if the upgrade request was ignored by
619the service - otherwise it will be altered to indicate the service ID the
620server upgraded to.  Note that the upgraded service ID is chosen by the server.
621The caller has to wait until it sees the service ID in the reply before sending
622any more calls (further calls to the same destination will be blocked until the
623probe is concluded).
624
625
626====================
627EXAMPLE SERVER USAGE
628====================
629
630A server would be set up to accept operations in the following manner:
631
632 (1) An RxRPC socket is created by:
633
634	server = socket(AF_RXRPC, SOCK_DGRAM, PF_INET);
635
636     Where the third parameter indicates the address type of the transport
637     socket used - usually IPv4.
638
639 (2) Security is set up if desired by giving the socket a keyring with server
640     secret keys in it:
641
642	keyring = add_key("keyring", "AFSkeys", NULL, 0,
643			  KEY_SPEC_PROCESS_KEYRING);
644
645	const char secret_key[8] = {
646		0xa7, 0x83, 0x8a, 0xcb, 0xc7, 0x83, 0xec, 0x94 };
647	add_key("rxrpc_s", "52:2", secret_key, 8, keyring);
648
649	setsockopt(server, SOL_RXRPC, RXRPC_SECURITY_KEYRING, "AFSkeys", 7);
650
651     The keyring can be manipulated after it has been given to the socket. This
652     permits the server to add more keys, replace keys, etc. whilst it is live.
653
654 (3) A local address must then be bound:
655
656	struct sockaddr_rxrpc srx = {
657		.srx_family	= AF_RXRPC,
658		.srx_service	= VL_SERVICE_ID, /* RxRPC service ID */
659		.transport_type	= SOCK_DGRAM,	/* type of transport socket */
660		.transport.sin_family	= AF_INET,
661		.transport.sin_port	= htons(7000), /* AFS callback */
662		.transport.sin_address	= 0,  /* all local interfaces */
663	};
664	bind(server, &srx, sizeof(srx));
665
666     More than one service ID may be bound to a socket, provided the transport
667     parameters are the same.  The limit is currently two.  To do this, bind()
668     should be called twice.
669
670 (4) If service upgrading is required, first two service IDs must have been
671     bound and then the following option must be set:
672
673	unsigned short service_ids[2] = { from_ID, to_ID };
674	setsockopt(server, SOL_RXRPC, RXRPC_UPGRADEABLE_SERVICE,
675		   service_ids, sizeof(service_ids));
676
677     This will automatically upgrade connections on service from_ID to service
678     to_ID if they request it.  This will be reflected in msg_name obtained
679     through recvmsg() when the request data is delivered to userspace.
680
681 (5) The server is then set to listen out for incoming calls:
682
683	listen(server, 100);
684
685 (6) The kernel notifies the server of pending incoming connections by sending
686     it a message for each.  This is received with recvmsg() on the server
687     socket.  It has no data, and has a single dataless control message
688     attached:
689
690	RXRPC_NEW_CALL
691
692     The address that can be passed back by recvmsg() at this point should be
693     ignored since the call for which the message was posted may have gone by
694     the time it is accepted - in which case the first call still on the queue
695     will be accepted.
696
697 (7) The server then accepts the new call by issuing a sendmsg() with two
698     pieces of control data and no actual data:
699
700	RXRPC_ACCEPT		- indicate connection acceptance
701	RXRPC_USER_CALL_ID	- specify user ID for this call
702
703 (8) The first request data packet will then be posted to the server socket for
704     recvmsg() to pick up.  At that point, the RxRPC address for the call can
705     be read from the address fields in the msghdr struct.
706
707     Subsequent request data will be posted to the server socket for recvmsg()
708     to collect as it arrives.  All but the last piece of the request data will
709     be delivered with MSG_MORE flagged.
710
711     All data will be delivered with the following control message attached:
712
713	RXRPC_USER_CALL_ID	- specifies the user ID for this call
714
715 (9) The reply data should then be posted to the server socket using a series
716     of sendmsg() calls, each with the following control messages attached:
717
718	RXRPC_USER_CALL_ID	- specifies the user ID for this call
719
720     MSG_MORE should be set in msghdr::msg_flags on all but the last message
721     for a particular call.
722
723(10) The final ACK from the client will be posted for retrieval by recvmsg()
724     when it is received.  It will take the form of a dataless message with two
725     control messages attached:
726
727	RXRPC_USER_CALL_ID	- specifies the user ID for this call
728	RXRPC_ACK		- indicates final ACK (no data)
729
730     MSG_EOR will be flagged to indicate that this is the final message for
731     this call.
732
733(11) Up to the point the final packet of reply data is sent, the call can be
734     aborted by calling sendmsg() with a dataless message with the following
735     control messages attached:
736
737	RXRPC_USER_CALL_ID	- specifies the user ID for this call
738	RXRPC_ABORT		- indicates abort code (4 byte data)
739
740     Any packets waiting in the socket's receive queue will be discarded if
741     this is issued.
742
743Note that all the communications for a particular service take place through
744the one server socket, using control messages on sendmsg() and recvmsg() to
745determine the call affected.
746
747
748=========================
749AF_RXRPC KERNEL INTERFACE
750=========================
751
752The AF_RXRPC module also provides an interface for use by in-kernel utilities
753such as the AFS filesystem.  This permits such a utility to:
754
755 (1) Use different keys directly on individual client calls on one socket
756     rather than having to open a whole slew of sockets, one for each key it
757     might want to use.
758
759 (2) Avoid having RxRPC call request_key() at the point of issue of a call or
760     opening of a socket.  Instead the utility is responsible for requesting a
761     key at the appropriate point.  AFS, for instance, would do this during VFS
762     operations such as open() or unlink().  The key is then handed through
763     when the call is initiated.
764
765 (3) Request the use of something other than GFP_KERNEL to allocate memory.
766
767 (4) Avoid the overhead of using the recvmsg() call.  RxRPC messages can be
768     intercepted before they get put into the socket Rx queue and the socket
769     buffers manipulated directly.
770
771To use the RxRPC facility, a kernel utility must still open an AF_RXRPC socket,
772bind an address as appropriate and listen if it's to be a server socket, but
773then it passes this to the kernel interface functions.
774
775The kernel interface functions are as follows:
776
777 (*) Begin a new client call.
778
779	struct rxrpc_call *
780	rxrpc_kernel_begin_call(struct socket *sock,
781				struct sockaddr_rxrpc *srx,
782				struct key *key,
783				unsigned long user_call_ID,
784				s64 tx_total_len,
785				gfp_t gfp);
786
787     This allocates the infrastructure to make a new RxRPC call and assigns
788     call and connection numbers.  The call will be made on the UDP port that
789     the socket is bound to.  The call will go to the destination address of a
790     connected client socket unless an alternative is supplied (srx is
791     non-NULL).
792
793     If a key is supplied then this will be used to secure the call instead of
794     the key bound to the socket with the RXRPC_SECURITY_KEY sockopt.  Calls
795     secured in this way will still share connections if at all possible.
796
797     The user_call_ID is equivalent to that supplied to sendmsg() in the
798     control data buffer.  It is entirely feasible to use this to point to a
799     kernel data structure.
800
801     tx_total_len is the amount of data the caller is intending to transmit
802     with this call (or -1 if unknown at this point).  Setting the data size
803     allows the kernel to encrypt directly to the packet buffers, thereby
804     saving a copy.  The value may not be less than -1.
805
806     If this function is successful, an opaque reference to the RxRPC call is
807     returned.  The caller now holds a reference on this and it must be
808     properly ended.
809
810 (*) End a client call.
811
812	void rxrpc_kernel_end_call(struct socket *sock,
813				   struct rxrpc_call *call);
814
815     This is used to end a previously begun call.  The user_call_ID is expunged
816     from AF_RXRPC's knowledge and will not be seen again in association with
817     the specified call.
818
819 (*) Send data through a call.
820
821	typedef void (*rxrpc_notify_end_tx_t)(struct sock *sk,
822					      unsigned long user_call_ID,
823					      struct sk_buff *skb);
824
825	int rxrpc_kernel_send_data(struct socket *sock,
826				   struct rxrpc_call *call,
827				   struct msghdr *msg,
828				   size_t len,
829				   rxrpc_notify_end_tx_t notify_end_rx);
830
831     This is used to supply either the request part of a client call or the
832     reply part of a server call.  msg.msg_iovlen and msg.msg_iov specify the
833     data buffers to be used.  msg_iov may not be NULL and must point
834     exclusively to in-kernel virtual addresses.  msg.msg_flags may be given
835     MSG_MORE if there will be subsequent data sends for this call.
836
837     The msg must not specify a destination address, control data or any flags
838     other than MSG_MORE.  len is the total amount of data to transmit.
839
840     notify_end_rx can be NULL or it can be used to specify a function to be
841     called when the call changes state to end the Tx phase.  This function is
842     called with the call-state spinlock held to prevent any reply or final ACK
843     from being delivered first.
844
845 (*) Receive data from a call.
846
847	int rxrpc_kernel_recv_data(struct socket *sock,
848				   struct rxrpc_call *call,
849				   void *buf,
850				   size_t size,
851				   size_t *_offset,
852				   bool want_more,
853				   u32 *_abort)
854
855      This is used to receive data from either the reply part of a client call
856      or the request part of a service call.  buf and size specify how much
857      data is desired and where to store it.  *_offset is added on to buf and
858      subtracted from size internally; the amount copied into the buffer is
859      added to *_offset before returning.
860
861      want_more should be true if further data will be required after this is
862      satisfied and false if this is the last item of the receive phase.
863
864      There are three normal returns: 0 if the buffer was filled and want_more
865      was true; 1 if the buffer was filled, the last DATA packet has been
866      emptied and want_more was false; and -EAGAIN if the function needs to be
867      called again.
868
869      If the last DATA packet is processed but the buffer contains less than
870      the amount requested, EBADMSG is returned.  If want_more wasn't set, but
871      more data was available, EMSGSIZE is returned.
872
873      If a remote ABORT is detected, the abort code received will be stored in
874      *_abort and ECONNABORTED will be returned.
875
876 (*) Abort a call.
877
878	void rxrpc_kernel_abort_call(struct socket *sock,
879				     struct rxrpc_call *call,
880				     u32 abort_code);
881
882     This is used to abort a call if it's still in an abortable state.  The
883     abort code specified will be placed in the ABORT message sent.
884
885 (*) Intercept received RxRPC messages.
886
887	typedef void (*rxrpc_interceptor_t)(struct sock *sk,
888					    unsigned long user_call_ID,
889					    struct sk_buff *skb);
890
891	void
892	rxrpc_kernel_intercept_rx_messages(struct socket *sock,
893					   rxrpc_interceptor_t interceptor);
894
895     This installs an interceptor function on the specified AF_RXRPC socket.
896     All messages that would otherwise wind up in the socket's Rx queue are
897     then diverted to this function.  Note that care must be taken to process
898     the messages in the right order to maintain DATA message sequentiality.
899
900     The interceptor function itself is provided with the address of the socket
901     and handling the incoming message, the ID assigned by the kernel utility
902     to the call and the socket buffer containing the message.
903
904     The skb->mark field indicates the type of message:
905
906	MARK				MEANING
907	===============================	=======================================
908	RXRPC_SKB_MARK_DATA		Data message
909	RXRPC_SKB_MARK_FINAL_ACK	Final ACK received for an incoming call
910	RXRPC_SKB_MARK_BUSY		Client call rejected as server busy
911	RXRPC_SKB_MARK_REMOTE_ABORT	Call aborted by peer
912	RXRPC_SKB_MARK_NET_ERROR	Network error detected
913	RXRPC_SKB_MARK_LOCAL_ERROR	Local error encountered
914	RXRPC_SKB_MARK_NEW_CALL		New incoming call awaiting acceptance
915
916     The remote abort message can be probed with rxrpc_kernel_get_abort_code().
917     The two error messages can be probed with rxrpc_kernel_get_error_number().
918     A new call can be accepted with rxrpc_kernel_accept_call().
919
920     Data messages can have their contents extracted with the usual bunch of
921     socket buffer manipulation functions.  A data message can be determined to
922     be the last one in a sequence with rxrpc_kernel_is_data_last().  When a
923     data message has been used up, rxrpc_kernel_data_consumed() should be
924     called on it.
925
926     Messages should be handled to rxrpc_kernel_free_skb() to dispose of.  It
927     is possible to get extra refs on all types of message for later freeing,
928     but this may pin the state of a call until the message is finally freed.
929
930 (*) Accept an incoming call.
931
932	struct rxrpc_call *
933	rxrpc_kernel_accept_call(struct socket *sock,
934				 unsigned long user_call_ID);
935
936     This is used to accept an incoming call and to assign it a call ID.  This
937     function is similar to rxrpc_kernel_begin_call() and calls accepted must
938     be ended in the same way.
939
940     If this function is successful, an opaque reference to the RxRPC call is
941     returned.  The caller now holds a reference on this and it must be
942     properly ended.
943
944 (*) Reject an incoming call.
945
946	int rxrpc_kernel_reject_call(struct socket *sock);
947
948     This is used to reject the first incoming call on the socket's queue with
949     a BUSY message.  -ENODATA is returned if there were no incoming calls.
950     Other errors may be returned if the call had been aborted (-ECONNABORTED)
951     or had timed out (-ETIME).
952
953 (*) Allocate a null key for doing anonymous security.
954
955	struct key *rxrpc_get_null_key(const char *keyname);
956
957     This is used to allocate a null RxRPC key that can be used to indicate
958     anonymous security for a particular domain.
959
960 (*) Get the peer address of a call.
961
962	void rxrpc_kernel_get_peer(struct socket *sock, struct rxrpc_call *call,
963				   struct sockaddr_rxrpc *_srx);
964
965     This is used to find the remote peer address of a call.
966
967 (*) Set the total transmit data size on a call.
968
969	void rxrpc_kernel_set_tx_length(struct socket *sock,
970					struct rxrpc_call *call,
971					s64 tx_total_len);
972
973     This sets the amount of data that the caller is intending to transmit on a
974     call.  It's intended to be used for setting the reply size as the request
975     size should be set when the call is begun.  tx_total_len may not be less
976     than zero.
977
978 (*) Check to see the completion state of a call so that the caller can assess
979     whether it needs to be retried.
980
981	enum rxrpc_call_completion {
982		RXRPC_CALL_SUCCEEDED,
983		RXRPC_CALL_REMOTELY_ABORTED,
984		RXRPC_CALL_LOCALLY_ABORTED,
985		RXRPC_CALL_LOCAL_ERROR,
986		RXRPC_CALL_NETWORK_ERROR,
987	};
988
989	int rxrpc_kernel_check_call(struct socket *sock, struct rxrpc_call *call,
990				    enum rxrpc_call_completion *_compl,
991				    u32 *_abort_code);
992
993     On return, -EINPROGRESS will be returned if the call is still ongoing; if
994     it is finished, *_compl will be set to indicate the manner of completion,
995     *_abort_code will be set to any abort code that occurred.  0 will be
996     returned on a successful completion, -ECONNABORTED will be returned if the
997     client failed due to a remote abort and anything else will return an
998     appropriate error code.
999
1000     The caller should look at this information to decide if it's worth
1001     retrying the call.
1002
1003 (*) Retry a client call.
1004
1005	int rxrpc_kernel_retry_call(struct socket *sock,
1006				    struct rxrpc_call *call,
1007				    struct sockaddr_rxrpc *srx,
1008				    struct key *key);
1009
1010     This attempts to partially reinitialise a call and submit it again whilst
1011     reusing the original call's Tx queue to avoid the need to repackage and
1012     re-encrypt the data to be sent.  call indicates the call to retry, srx the
1013     new address to send it to and key the encryption key to use for signing or
1014     encrypting the packets.
1015
1016     For this to work, the first Tx data packet must still be in the transmit
1017     queue, and currently this is only permitted for local and network errors
1018     and the call must not have been aborted.  Any partially constructed Tx
1019     packet is left as is and can continue being filled afterwards.
1020
1021     It returns 0 if the call was requeued and an error otherwise.
1022
1023
1024=======================
1025CONFIGURABLE PARAMETERS
1026=======================
1027
1028The RxRPC protocol driver has a number of configurable parameters that can be
1029adjusted through sysctls in /proc/net/rxrpc/:
1030
1031 (*) req_ack_delay
1032
1033     The amount of time in milliseconds after receiving a packet with the
1034     request-ack flag set before we honour the flag and actually send the
1035     requested ack.
1036
1037     Usually the other side won't stop sending packets until the advertised
1038     reception window is full (to a maximum of 255 packets), so delaying the
1039     ACK permits several packets to be ACK'd in one go.
1040
1041 (*) soft_ack_delay
1042
1043     The amount of time in milliseconds after receiving a new packet before we
1044     generate a soft-ACK to tell the sender that it doesn't need to resend.
1045
1046 (*) idle_ack_delay
1047
1048     The amount of time in milliseconds after all the packets currently in the
1049     received queue have been consumed before we generate a hard-ACK to tell
1050     the sender it can free its buffers, assuming no other reason occurs that
1051     we would send an ACK.
1052
1053 (*) resend_timeout
1054
1055     The amount of time in milliseconds after transmitting a packet before we
1056     transmit it again, assuming no ACK is received from the receiver telling
1057     us they got it.
1058
1059 (*) max_call_lifetime
1060
1061     The maximum amount of time in seconds that a call may be in progress
1062     before we preemptively kill it.
1063
1064 (*) dead_call_expiry
1065
1066     The amount of time in seconds before we remove a dead call from the call
1067     list.  Dead calls are kept around for a little while for the purpose of
1068     repeating ACK and ABORT packets.
1069
1070 (*) connection_expiry
1071
1072     The amount of time in seconds after a connection was last used before we
1073     remove it from the connection list.  Whilst a connection is in existence,
1074     it serves as a placeholder for negotiated security; when it is deleted,
1075     the security must be renegotiated.
1076
1077 (*) transport_expiry
1078
1079     The amount of time in seconds after a transport was last used before we
1080     remove it from the transport list.  Whilst a transport is in existence, it
1081     serves to anchor the peer data and keeps the connection ID counter.
1082
1083 (*) rxrpc_rx_window_size
1084
1085     The size of the receive window in packets.  This is the maximum number of
1086     unconsumed received packets we're willing to hold in memory for any
1087     particular call.
1088
1089 (*) rxrpc_rx_mtu
1090
1091     The maximum packet MTU size that we're willing to receive in bytes.  This
1092     indicates to the peer whether we're willing to accept jumbo packets.
1093
1094 (*) rxrpc_rx_jumbo_max
1095
1096     The maximum number of packets that we're willing to accept in a jumbo
1097     packet.  Non-terminal packets in a jumbo packet must contain a four byte
1098     header plus exactly 1412 bytes of data.  The terminal packet must contain
1099     a four byte header plus any amount of data.  In any event, a jumbo packet
1100     may not exceed rxrpc_rx_mtu in size.
1101