← Documents Documentation/networking/rxrpc.rst GitHub 원문 ↗

Linux 6.18.37 · Networking

RxRPC 네트워크 프로토콜

UDP 위의 RxRPC 연결과 호출, ACK, 보안, 사용자 공간 및 커널 API를 설명합니다.

Source pathDocumentation/networking/rxrpc.rst
Source versionLinux v6.18.37
TranslationDUJINLABS 전문 번역 + 해설

요약·해설과 원문, 전문 번역을 서로 분리했습니다. API 이름, symbol, source path는 원문 표기를 사용합니다.

1. 요약·해설

원문의 핵심 논리와 kernel programming 관점의 보충 설명입니다. 아래의 전문 번역과는 별도로 작성했습니다.

요약·해설

rxrpc.rst:1-1162

RxRPC는 UDP 위에서 요청과 응답을 신뢰성 있게 전달하는 2단계 RPC 세션 프로토콜입니다. AF_RXRPC는 연결과 재전송, ACK, 호출 다중화, abort 및 보안을 담당하고, 응용 프로그램은 XDR을 포함한 데이터 표현과 연산 ID를 담당합니다. 사용자 공간은 `sendmsg()`와 `recvmsg()`의 제어 메시지를 사용하며, 커널 사용자는 불투명한 call 객체와 skb 기반 인터페이스를 사용할 수 있습니다.

운영에서 특히 중요한 경계는 세 가지입니다. user call ID는 terminal 이벤트가 올 때까지 재사용하지 않고, 송신 패킷은 hard ACK 전까지 보존되며, 서버 호출은 최종 응답에 대한 ACK를 받아야 완전히 종료됩니다. 보안은 연결 단위로 협상되고 현재 문서의 구현은 rxkad를 중심으로 설명합니다.

RxRPC 한 호출
클라이언트 요청서버 수락과 처리서버 응답클라이언트 hard ACK서버 terminal ACK호출 완료

호출 태그와 ACK가 요청부터 최종 완료까지 상태를 연결합니다.

2. 영어 원문 전체

번역 기준이 된 Linux v6.18.37 원문입니다. 줄 번호는 이 버전의 파일 좌표입니다.

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

3. 한국어 전문 번역

영어 원문의 문단 순서와 의미를 유지한 전체 번역입니다. 코드, 함수명, symbol과 URL은 원문 표기를 유지합니다.

RxRPC 문서의 범위

1-34

RxRPC는 UDP 위에 구현한 2단계 비대칭 원격 프로시저 호출 프로토콜입니다. Linux의 AF_RXRPC 주소 패밀리는 커널과 사용자 공간 모두에 RxRPC 소켓을 제공하며, 일반적인 소켓 호출인 `sendmsg()`와 `recvmsg()`를 사용합니다. 데이터, 중단 코드, 네트워크 오류 및 프로토콜 상태는 제어 메시지로 함께 전달됩니다.

이 문서는 프로토콜 자체의 요약에서 시작해 AF_RXRPC 드라이버 모델, 제어 메시지와 소켓 옵션, 보안 키, 클라이언트와 서버 사용 절차, 커널 내부 API, 조정 가능한 매개변수 및 함수 참조를 차례로 설명합니다. 각 API 이름, 상수, 구조체 및 source path는 구현과 대조할 수 있도록 원문 표기를 유지합니다.

RxRPC 문서 지도
프로토콜 개요AF_RXRPC 소켓 모델제어 메시지와 옵션보안클라이언트와 서버커널 APIsysctl과 함수 참조

사용자 공간 인터페이스에서 커널 내부 API까지 이어지는 전체 범위입니다.

.. SPDX-License-Identifier: GPL-2.0

======================
RxRPC Network Protocol
======================

The RxRPC protocol driver provides a reliable two-phase transport on top of UDP
that can be used to perform RxRPC remote operations.  This is done over sockets
of AF_RXRPC family, using sendmsg() and recvmsg() with control data to send and
receive data, aborts and errors.

Contents of this document:

 (#) Overview.

 (#) RxRPC protocol summary.

 (#) AF_RXRPC driver model.

 (#) Control messages.

 (#) Socket options.

 (#) Security.

 (#) Example client usage.

 (#) Example server usage.

 (#) AF_RXRPC kernel interface.

 (#) Configurable parameters.

계층 구조와 통신 모델

35-88

RxRPC는 두 계층으로 나뉩니다. 세션 계층은 IPv4 또는 IPv6 UDP 위에 신뢰할 수 있는 가상 연결을 만들고, 표현 계층은 SunRPC와 비슷하게 XDR 형식의 데이터 블롭을 전달합니다. Linux의 AF_RXRPC는 이 가운데 세션 계층만 구현합니다. 호출자는 XDR 인코딩과 디코딩을 직접 담당하며 커널은 전송되는 바이트열의 의미를 해석하지 않습니다.

한 호출은 클라이언트가 요청을 보내고 서버가 응답을 반환하는 두 단계로 이루어집니다. 실제 UDP 전송 경로는 여러 호출에서 재사용될 수 있고, 키 보존 서비스를 통해 보안 계층을 붙일 수 있습니다. 요청의 첫 4바이트에는 보통 연산 ID가 들어가지만, 이것은 응용 프로그램 규약이며 커널 세션 계층의 관심 대상은 아닙니다.

AF_RXRPC 소켓은 `SOCK_DGRAM` 형식입니다. RxRPC가 사용하는 하위 전송 프로토콜은 현재 `PF_INET`이며, AFS가 대표적인 사용자입니다. AFS 파일 서버, 볼륨 위치 서비스 등은 같은 전송 모델 위에서 서로 다른 서비스 ID와 응용 프로토콜을 사용합니다.

RxRPC 계층
응용 프로그램XDR 표현 계층RxRPC 세션 계층UDP 전송 계층IP 네트워크

응용 프로그램 데이터는 AF_RXRPC 세션 계층과 UDP를 거쳐 전송됩니다.

Overview
========

RxRPC is a two-layer protocol.  There is a session layer which provides
reliable virtual connections using UDP over IPv4 (or IPv6) as the transport
layer, but implements a real network protocol; and there's the presentation
layer which renders structured data to binary blobs and back again using XDR
(as does SunRPC)::

                +-------------+
                | Application |
                +-------------+
                |     XDR     |                Presentation
                +-------------+
                |    RxRPC    |                Session
                +-------------+
                |     UDP     |                Transport
                +-------------+


AF_RXRPC provides:

 (1) Part of an RxRPC facility for both kernel and userspace applications by
     making the session part of it a Linux network protocol (AF_RXRPC).

 (2) A two-phase protocol.  The client transmits a blob (the request) and then
     receives a blob (the reply), and the server receives the request and then
     transmits the reply.

 (3) Retention of the reusable bits of the transport system set up for one call
     to speed up subsequent calls.

 (4) A secure protocol, using the Linux kernel's key retention facility to
     manage security on the client end.  The server end must of necessity be
     more active in security negotiations.

AF_RXRPC does not provide XDR marshalling/presentation facilities.  That is
left to the application.  AF_RXRPC only deals in blobs.  Even the operation ID
is just the first four bytes of the request blob, and as such is beyond the
kernel's interest.


Sockets of AF_RXRPC family are:

 (1) created as type SOCK_DGRAM;

 (2) provided with a protocol of the type of underlying transport they're going
     to use - currently only PF_INET is supported.


The Andrew File System (AFS) is an example of an application that uses this and
that has both kernel (filesystem) and userspace (utility) components.

연결, 호출, ACK와 완료 조건

89-164

RxRPC는 UDP만 사용하며, 로컬과 원격의 UDP 포트가 통신 끝점을 이룹니다. 하나의 끝점 쌍 사이에는 여러 가상 연결을 만들 수 있고, 각 연결은 하나의 서비스만 대상으로 합니다. 하나의 UDP 끝점이 여러 서비스를 제공할 수도 있으며, 방향 표시는 같은 끝점이 클라이언트와 서버 역할을 동시에 수행할 수 있게 합니다.

가상 연결은 로컬 주소와 포트, 원격 주소와 포트, 방향, 연결 ID, 서비스 ID라는 일곱 값으로 식별됩니다. 연결 하나에는 최대 약 40억 개의 호출 번호가 있고 최대 네 호출을 동시에 진행할 수 있습니다. 호출은 클라이언트 요청 단계와 서버 응답 단계로 나뉘며, 각 단계의 데이터는 길이가 정해지지 않은 블롭입니다. 마지막 패킷의 플래그가 단계 종료를 표시하고 시퀀스 번호가 순환하므로 한 단계는 40억 패킷 미만이어야 합니다.

보안은 연결 단위로 협상합니다. 첫 DATA 패킷이 보안 연결을 시작하면 서버가 challenge를 보내고 클라이언트가 response로 답합니다. 협상 결과는 연결 수명 동안 유지되지만 서버가 상태를 잊었다면 다시 협상합니다. 요청의 첫 4바이트에 들어가는 연산 ID는 서버가 어떤 작업을 수행할지 선택하는 응용 계층 값입니다.

신뢰성은 ACK로 보장합니다. hard ACK는 패킷을 수신하고 처리까지 마쳤음을 뜻하므로 송신자가 보관 사본을 버릴 수 있습니다. soft ACK는 현재 수신했지만 아직 버리고 다시 요청할 수 있다는 뜻입니다. 따라서 송신자는 hard ACK를 받을 때까지 각 패킷을 보관합니다. 응답의 첫 DATA 패킷은 전체 요청에 대한 암시적 hard ACK로도 작동합니다.

호출이 정상 완료되려면 클라이언트가 요청을 모두 보내고, 응답을 모두 받으며, 응답의 최종 hard ACK가 서버에 도착해야 합니다. 이 완료 지점 전에는 어느 쪽도 호출을 중단할 수 있으며, 중단 코드는 상대에게 전달됩니다.

RxRPC 식별과 수명
대상식별 또는 제한
가상 연결로컬 주소/포트, 원격 주소/포트, 방향, connection ID, service ID
연결 안의 호출최대 약 40억 개, 동시 진행 최대 4개
호출 단계클라이언트 요청 뒤 서버 응답
단계 크기시퀀스 번호 순환 전인 40억 패킷 미만
정상 완료최종 응답 ACK가 서버에 도착한 시점

연결과 호출의 핵심 경계를 요약합니다.

RxRPC Protocol Summary
======================

An overview of the RxRPC protocol:

 (#) RxRPC sits on top of another networking protocol (UDP is the only option
     currently), and uses this to provide network transport.  UDP ports, for
     example, provide transport endpoints.

 (#) RxRPC supports multiple virtual "connections" from any given transport
     endpoint, thus allowing the endpoints to be shared, even to the same
     remote endpoint.

 (#) Each connection goes to a particular "service".  A connection may not go
     to multiple services.  A service may be considered the RxRPC equivalent of
     a port number.  AF_RXRPC permits multiple services to share an endpoint.

 (#) Client-originating packets are marked, thus a transport endpoint can be
     shared between client and server connections (connections have a
     direction).

 (#) Up to a billion connections may be supported concurrently between one
     local transport endpoint and one service on one remote endpoint.  An RxRPC
     connection is described by seven numbers::

        Local address        }
        Local port        } Transport (UDP) address
        Remote address        }
        Remote port        }
        Direction
        Connection ID
        Service ID

 (#) Each RxRPC operation is a "call".  A connection may make up to four
     billion calls, but only up to four calls may be in progress on a
     connection at any one time.

 (#) Calls are two-phase and asymmetric: the client sends its request data,
     which the service receives; then the service transmits the reply data
     which the client receives.

 (#) The data blobs are of indefinite size, the end of a phase is marked with a
     flag in the packet.  The number of packets of data making up one blob may
     not exceed 4 billion, however, as this would cause the sequence number to
     wrap.

 (#) The first four bytes of the request data are the service operation ID.

 (#) Security is negotiated on a per-connection basis.  The connection is
     initiated by the first data packet on it arriving.  If security is
     requested, the server then issues a "challenge" and then the client
     replies with a "response".  If the response is successful, the security is
     set for the lifetime of that connection, and all subsequent calls made
     upon it use that same security.  In the event that the server lets a
     connection lapse before the client, the security will be renegotiated if
     the client uses the connection again.

 (#) Calls use ACK packets to handle reliability.  Data packets are also
     explicitly sequenced per call.

 (#) There are two types of positive acknowledgment: hard-ACKs and soft-ACKs.
     A hard-ACK indicates to the far side that all the data received to a point
     has been received and processed; a soft-ACK indicates that the data has
     been received but may yet be discarded and re-requested.  The sender may
     not discard any transmittable packets until they've been hard-ACK'd.

 (#) Reception of a reply data packet implicitly hard-ACK's all the data
     packets that make up the request.

 (#) An call is complete when the request has been sent, the reply has been
     received and the final hard-ACK on the last packet of the reply has
     reached the server.

 (#) An call may be aborted by either end at any time up to its completion.

AF_RXRPC 드라이버 모델과 호출 큐

165-321

AF_RXRPC 드라이버는 내부 UDP 소켓을 전송 끝점으로 사용하고, AF_RXRPC 소켓을 연결 묶음에 대응시킵니다. 응용 프로그램은 실제 연결 선택을 보지 않습니다. 클라이언트 소켓 하나로 같은 서비스에 여러 호출을 보낼 수 있고, 서버 소켓 하나로 여러 클라이언트의 호출을 받을 수 있습니다. 드라이버는 필요하면 조정 가능한 상한까지 병렬 연결을 만들고, 호출 종료 뒤에도 연결과 UDP 소켓을 일정 시간 보존해 재사용합니다.

같은 키와 보안 수준을 쓰는 클라이언트 호출은 연결을 공유할 수 있으며 보안을 쓰지 않는 호출도 공유할 수 있습니다. 서버 측 연결은 클라이언트가 공유 가능한 형태로 만들었을 때 공유됩니다. ACK와 ping은 자동으로 처리됩니다. `SO_KEEPALIVE` 지원은 문서상 아직 TODO입니다. ICMP 오류가 들어오면 영향을 받은 호출은 중단되고 `recvmsg()`를 통해 네트워크 오류가 보고됩니다.

0이 아닌 서비스 ID로 `bind()`한 소켓은 서버가 됩니다. 클라이언트는 하나 이상의 `sendmsg()`로 요청을 보내고 하나 이상의 `recvmsg()`로 응답을 받습니다. 첫 `sendmsg()`에는 응용 프로그램이 선택한 user call ID 태그를 붙여야 하며, 이후 모든 제어 정보가 이 태그와 연결됩니다. `connect()`는 기본 목적지를 정하고, 첫 송신의 `msg_name`으로 호출별 목적지를 바꿀 수도 있습니다. 아직 바인드하지 않은 소켓을 연결하면 임의 로컬 포트가 자동 선택됩니다.

서버 소켓도 첫 `sendmsg()`에 대상 주소를 주면 클라이언트 호출을 만들 수 있습니다. 태그는 호출의 terminal 메시지를 받은 뒤 다시 사용할 수 있습니다. 클라이언트는 요청 송신 뒤 응답을 받고, 서버는 요청 수신 뒤 응답을 보내고 마지막 ACK를 받습니다. 송수신 중 `MSG_MORE`는 현재 단계가 계속된다는 뜻이고 `MSG_EOR`은 terminal 이벤트를 표시합니다.

호출을 중단하는 제어 메시지는 해당 태그의 호출을 끝내고 큐에 남은 메시지를 버립니다. 원격 abort, server busy, challenge 및 각종 오류는 `recvmsg()`의 제어 데이터로 전달되며 abort와 busy는 terminal입니다. 서버에는 새 호출을 알리는 `RXRPC_NEW_CALL`이 먼저 도착합니다. 서버는 `RXRPC_ACCEPT`와 새 태그를 `sendmsg()`로 보내 호출을 수락하고, 그 뒤 요청 DATA가 일반 수신 큐에 제공됩니다.

보안 서버는 secret keyring으로 challenge/response를 처리하고, 클라이언트는 소켓 옵션으로 보안 키 이름을 지정합니다. `sendmsg(MSG_WAITALL)`은 상대가 적어도 2 RTT마다 한 패킷씩 진행하는 동안 신호를 무시하고 계속 기다립니다. 진전 없이 중단되면 아무 바이트도 소비하지 않은 경우 `-EINTR` 또는 `-ERESTARTSYS`, 일부를 소비한 경우 소비한 바이트 수를 반환합니다.

`recvmsg()`는 같은 호출의 데이터를 단계 끝, 비데이터 메시지, 다른 호출, 사용자 버퍼 포화 가운데 하나가 나타날 때까지 처리합니다. `MSG_PEEK`는 데이터가 하나라도 있으면 반환합니다. 메시지 일부만 복사했다면 나머지는 큐 앞으로 되돌리며 `MSG_TRUNC`는 사용하지 않습니다. 현재 단계에 데이터가 더 있으면 `MSG_MORE`가 반환됩니다.

클라이언트 호출
첫 sendmsg + USER_CALL_ID요청 DATA, MSG_MORE마지막 요청 DATA응답 recvmsgMSG_EOR terminal태그 재사용 가능

태그 하나가 요청부터 terminal 결과까지 호출을 식별합니다.

서버 호출
RXRPC_NEW_CALLRXRPC_ACCEPT + USER_CALL_ID요청 DATA 수신응답 DATA 송신최종 RXRPC_ACK호출 완료

새 호출 알림을 수락한 뒤 요청과 응답을 처리합니다.

AF_RXRPC Driver Model
=====================

About the AF_RXRPC driver:

 (#) The AF_RXRPC protocol transparently uses internal sockets of the transport
     protocol to represent transport endpoints.

 (#) AF_RXRPC sockets map onto RxRPC connection bundles.  Actual RxRPC
     connections are handled transparently.  One client socket may be used to
     make multiple simultaneous calls to the same service.  One server socket
     may handle calls from many clients.

 (#) Additional parallel client connections will be initiated to support extra
     concurrent calls, up to a tunable limit.

 (#) Each connection is retained for a certain amount of time [tunable] after
     the last call currently using it has completed in case a new call is made
     that could reuse it.

 (#) Each internal UDP socket is retained [tunable] for a certain amount of
     time [tunable] after the last connection using it discarded, in case a new
     connection is made that could use it.

 (#) A client-side connection is only shared between calls if they have
     the same key struct describing their security (and assuming the calls
     would otherwise share the connection).  Non-secured calls would also be
     able to share connections with each other.

 (#) A server-side connection is shared if the client says it is.

 (#) ACK'ing is handled by the protocol driver automatically, including ping
     replying.

 (#) SO_KEEPALIVE automatically pings the other side to keep the connection
     alive [TODO].

 (#) If an ICMP error is received, all calls affected by that error will be
     aborted with an appropriate network error passed through recvmsg().


Interaction with the user of the RxRPC socket:

 (#) A socket is made into a server socket by binding an address with a
     non-zero service ID.

 (#) In the client, sending a request is achieved with one or more sendmsgs,
     followed by the reply being received with one or more recvmsgs.

 (#) The first sendmsg for a request to be sent from a client contains a tag to
     be used in all other sendmsgs or recvmsgs associated with that call.  The
     tag is carried in the control data.

 (#) connect() is used to supply a default destination address for a client
     socket.  This may be overridden by supplying an alternate address to the
     first sendmsg() of a call (struct msghdr::msg_name).

 (#) If connect() is called on an unbound client, a random local port will
     bound before the operation takes place.

 (#) A server socket may also be used to make client calls.  To do this, the
     first sendmsg() of the call must specify the target address.  The server's
     transport endpoint is used to send the packets.

 (#) Once the application has received the last message associated with a call,
     the tag is guaranteed not to be seen again, and so it can be used to pin
     client resources.  A new call can then be initiated with the same tag
     without fear of interference.

 (#) In the server, a request is received with one or more recvmsgs, then the
     the reply is transmitted with one or more sendmsgs, and then the final ACK
     is received with a last recvmsg.

 (#) When sending data for a call, sendmsg is given MSG_MORE if there's more
     data to come on that call.

 (#) When receiving data for a call, recvmsg flags MSG_MORE if there's more
     data to come for that call.

 (#) When receiving data or messages for a call, MSG_EOR is flagged by recvmsg
     to indicate the terminal message for that call.

 (#) A call may be aborted by adding an abort control message to the control
     data.  Issuing an abort terminates the kernel's use of that call's tag.
     Any messages waiting in the receive queue for that call will be discarded.

 (#) Aborts, busy notifications and challenge packets are delivered by recvmsg,
     and control data messages will be set to indicate the context.  Receiving
     an abort or a busy message terminates the kernel's use of that call's tag.

 (#) The control data part of the msghdr struct is used for a number of things:

     (#) The tag of the intended or affected call.

     (#) Sending or receiving errors, aborts and busy notifications.

     (#) Notifications of incoming calls.

     (#) Sending debug requests and receiving debug replies [TODO].

 (#) When the kernel has received and set up an incoming call, it sends a
     message to server application to let it know there's a new call awaiting
     its acceptance [recvmsg reports a special control message].  The server
     application then uses sendmsg to assign a tag to the new call.  Once that
     is done, the first part of the request data will be delivered by recvmsg.

 (#) The server application has to provide the server socket with a keyring of
     secret keys corresponding to the security types it permits.  When a secure
     connection is being set up, the kernel looks up the appropriate secret key
     in the keyring and then sends a challenge packet to the client and
     receives a response packet.  The kernel then checks the authorisation of
     the packet and either aborts the connection or sets up the security.

 (#) The name of the key a client will use to secure its communications is
     nominated by a socket option.


Notes on sendmsg:

 (#) MSG_WAITALL can be set to tell sendmsg to ignore signals if the peer is
     making progress at accepting packets within a reasonable time such that we
     manage to queue up all the data for transmission.  This requires the
     client to accept at least one packet per 2*RTT time period.

     If this isn't set, sendmsg() will return immediately, either returning
     EINTR/ERESTARTSYS if nothing was consumed or returning the amount of data
     consumed.


Notes on recvmsg:

 (#) If there's a sequence of data messages belonging to a particular call on
     the receive queue, then recvmsg will keep working through them until:

     (a) it meets the end of that call's received data,

     (b) it meets a non-data message,

     (c) it meets a message belonging to a different call, or

     (d) it fills the user buffer.

     If recvmsg is called in blocking mode, it will keep sleeping, awaiting the
     reception of further data, until one of the above four conditions is met.

 (2) MSG_PEEK operates similarly, but will return immediately if it has put any
     data in the buffer rather than sleeping until it can fill the buffer.

 (3) If a data message is only partially consumed in filling a user buffer,
     then the remainder of that message will be left on the front of the queue
     for the next taker.  MSG_TRUNC will never be flagged.

 (4) If there is more data to be had on a call (it hasn't copied the last byte
     of the last data message in that phase yet), then MSG_MORE will be
     flagged.

제어 메시지

322-439

RxRPC 제어 메시지는 `SOL_RXRPC` 레벨에서 사용합니다. 문서 표의 S, R, T는 각각 `sendmsg()`에서 사용 가능, `recvmsg()`로 전달, terminal 이벤트를 뜻합니다. `RXRPC_USER_CALL_ID`는 첫 클라이언트 DATA 또는 서버의 `RXRPC_ACCEPT`에 넣는 `unsigned long` 응용 태그입니다. `RXRPC_NEW_CALL`을 제외한 수신 메시지에는 이 태그가 함께 제공됩니다.

`RXRPC_ABORT`는 로컬에서 abort 코드를 보내거나 원격 abort 코드를 받을 때 사용합니다. 송신에는 call ID가 필요하며 일치하는 호출이 없으면 `EBADSLT`입니다. `RXRPC_ACK`는 서버가 최종 ACK를 받았음을 알리는 terminal 메시지입니다. `RXRPC_NET_ERROR`, `RXRPC_BUSY`, `RXRPC_LOCAL_ERROR`는 각각 ICMP에서 유도한 errno, 서버의 busy 거절, 로컬 오류를 call ID와 함께 전달하며 모두 terminal입니다.

`RXRPC_NEW_CALL`은 서버 큐에 수락할 새 호출이 있음을 알리지만 call ID를 포함하지 않습니다. 서버는 데이터 없는 `sendmsg()`에 `RXRPC_ACCEPT`와 새 `RXRPC_USER_CALL_ID`를 넣어 가장 오래된 미수락 호출을 수락합니다. 호출이 없으면 `ENODATA`, 이미 사용 중인 ID면 `EBADSLT`입니다.

`RXRPC_EXCLUSIVE_CALL`은 호출 전용 일회성 연결을 요구하며 완료 뒤 연결을 폐기합니다. `RXRPC_UPGRADE_SERVICE`는 더 높은 서비스 ID를 탐색합니다. 응답의 `msg_name`에 있는 `srx_service`를 검사해 실제 선택을 확인해야 하며, 연산 ID와 인수는 두 서비스에서 같아야 합니다. 결과는 캐시되므로 성공한 목적지에 이후 호출을 보낼 때 upgrade 플래그를 중단할 수 있습니다.

`RXRPC_TX_LENGTH`는 첫 DATA 송신에서 전체 Tx 길이를 `__s64` 0 이상 값으로 알립니다. 커널은 이 정보를 이용해 사용자 공간에서 패킷으로 직접 암호화하여 복사를 피할 수 있습니다. 실제 길이가 선언과 다르면 `EMSGSIZE`가 발생합니다. `RXRPC__SUPPORTED`는 가장 큰 제어 메시지 번호보다 하나 큰 값이며 `RXRPC_SUPPORTED_CMSG` 소켓 옵션으로 구현 범위를 조회할 때 사용합니다.

RxRPC 제어 메시지
메시지방향의미
RXRPC_USER_CALL_IDS/R응용 프로그램 호출 태그
RXRPC_ABORTS/R/T로컬 또는 원격 abort 코드
RXRPC_ACKR/T서버가 받은 최종 ACK
RXRPC_NET_ERRORR/TICMP에서 유도한 네트워크 errno
RXRPC_BUSYR/T서버의 호출 거절
RXRPC_LOCAL_ERRORR/T로컬 처리 오류
RXRPC_NEW_CALLR수락 대기 중인 새 서버 호출
RXRPC_ACCEPTS가장 오래된 새 호출 수락
RXRPC_EXCLUSIVE_CALLS일회성 전용 연결
RXRPC_UPGRADE_SERVICES상위 서비스 탐색
RXRPC_TX_LENGTHS전체 송신 길이 선언

S/R/T는 송신, 수신, terminal 지원을 나타냅니다.

Control Messages
================

AF_RXRPC makes use of control messages in sendmsg() and recvmsg() to multiplex
calls, to invoke certain actions and to report certain conditions.  These are:

        =======================        === ===========        ===============================
        MESSAGE ID                SRT DATA        MEANING
        =======================        === ===========        ===============================
        RXRPC_USER_CALL_ID        sr- User ID        App's call specifier
        RXRPC_ABORT                srt Abort code        Abort code to issue/received
        RXRPC_ACK                -rt n/a                Final ACK received
        RXRPC_NET_ERROR                -rt error num        Network error on call
        RXRPC_BUSY                -rt n/a                Call rejected (server busy)
        RXRPC_LOCAL_ERROR        -rt error num        Local error encountered
        RXRPC_NEW_CALL                -r- n/a                New call received
        RXRPC_ACCEPT                s-- n/a                Accept new call
        RXRPC_EXCLUSIVE_CALL        s-- n/a                Make an exclusive client call
        RXRPC_UPGRADE_SERVICE        s-- n/a                Client call can be upgraded
        RXRPC_TX_LENGTH                s-- data len        Total length of Tx data
        =======================        === ===========        ===============================

        (SRT = usable in Sendmsg / delivered by Recvmsg / Terminal message)

 (#) RXRPC_USER_CALL_ID

     This is used to indicate the application's call ID.  It's an unsigned long
     that the app specifies in the client by attaching it to the first data
     message or in the server by passing it in association with an RXRPC_ACCEPT
     message.  recvmsg() passes it in conjunction with all messages except
     those of the RXRPC_NEW_CALL message.

 (#) RXRPC_ABORT

     This is can be used by an application to abort a call by passing it to
     sendmsg, or it can be delivered by recvmsg to indicate a remote abort was
     received.  Either way, it must be associated with an RXRPC_USER_CALL_ID to
     specify the call affected.  If an abort is being sent, then error EBADSLT
     will be returned if there is no call with that user ID.

 (#) RXRPC_ACK

     This is delivered to a server application to indicate that the final ACK
     of a call was received from the client.  It will be associated with an
     RXRPC_USER_CALL_ID to indicate the call that's now complete.

 (#) RXRPC_NET_ERROR

     This is delivered to an application to indicate that an ICMP error message
     was encountered in the process of trying to talk to the peer.  An
     errno-class integer value will be included in the control message data
     indicating the problem, and an RXRPC_USER_CALL_ID will indicate the call
     affected.

 (#) RXRPC_BUSY

     This is delivered to a client application to indicate that a call was
     rejected by the server due to the server being busy.  It will be
     associated with an RXRPC_USER_CALL_ID to indicate the rejected call.

 (#) RXRPC_LOCAL_ERROR

     This is delivered to an application to indicate that a local error was
     encountered and that a call has been aborted because of it.  An
     errno-class integer value will be included in the control message data
     indicating the problem, and an RXRPC_USER_CALL_ID will indicate the call
     affected.

 (#) RXRPC_NEW_CALL

     This is delivered to indicate to a server application that a new call has
     arrived and is awaiting acceptance.  No user ID is associated with this,
     as a user ID must subsequently be assigned by doing an RXRPC_ACCEPT.

 (#) RXRPC_ACCEPT

     This is used by a server application to attempt to accept a call and
     assign it a user ID.  It should be associated with an RXRPC_USER_CALL_ID
     to indicate the user ID to be assigned.  If there is no call to be
     accepted (it may have timed out, been aborted, etc.), then sendmsg will
     return error ENODATA.  If the user ID is already in use by another call,
     then error EBADSLT will be returned.

 (#) RXRPC_EXCLUSIVE_CALL

     This is used to indicate that a client call should be made on a one-off
     connection.  The connection is discarded once the call has terminated.

 (#) RXRPC_UPGRADE_SERVICE

     This is used to make a client call to probe if the specified service ID
     may be upgraded by the server.  The caller must check msg_name returned to
     recvmsg() for the service ID actually in use.  The operation probed must
     be one that takes the same arguments in both services.

     Once this has been used to establish the upgrade capability (or lack
     thereof) of the server, the service ID returned should be used for all
     future communication to that server and RXRPC_UPGRADE_SERVICE should no
     longer be set.

 (#) RXRPC_TX_LENGTH

     This is used to inform the kernel of the total amount of data that is
     going to be transmitted by a call (whether in a client request or a
     service response).  If given, it allows the kernel to encrypt from the
     userspace buffer directly to the packet buffers, rather than copying into
     the buffer and then encrypting in place.  This may only be given with the
     first sendmsg() providing data for a call.  EMSGSIZE will be generated if
     the amount of data actually given is different.

     This takes a parameter of __s64 type that indicates how much will be
     transmitted.  This may not be less than zero.

The symbol RXRPC__SUPPORTED is defined as one more than the highest control
message type supported.  At run time this can be queried by means of the
RXRPC_SUPPORTED_CMSG socket option (see below).

SOL_RXRPC 소켓 옵션

440-496

`RXRPC_SECURITY_KEY`는 클라이언트 보안 키의 설명 문자열을 지정합니다. 커널은 프로세스 keyring들에서 `rxrpc` 형식 키를 `request_key()`로 찾으며 `optlen`에는 문자열 끝 NUL을 포함하지 않습니다. `RXRPC_SECURITY_KEYRING`은 서버가 보안 키를 찾을 keyring의 설명을 지정합니다.

`RXRPC_EXCLUSIVE_CONNECTION`을 NULL, 길이 0으로 설정하면 이후 호출마다 새 연결을 사용합니다. `RXRPC_MIN_SECURITY_LEVEL`은 정수로 최소 보안 수준을 정합니다. `RXRPC_SECURITY_PLAIN`은 암호화된 checksum만 사용합니다. `RXRPC_SECURITY_AUTH`는 checksum에 더해 패킷을 패딩하고 실제 길이를 포함한 첫 8바이트를 암호화합니다. `RXRPC_SECURITY_ENCRYPT`는 실제 길이를 포함한 패킷 전체를 패딩하고 암호화합니다.

`RXRPC_UPGRADEABLE_SERVICE`는 원래 서비스와 업그레이드할 서비스 ID 두 개를 `unsigned short` 배열로 전달합니다. `RXRPC_SUPPORTED_CMSG`는 읽기 전용이며 구현이 지원하는 가장 높은 제어 메시지 형식을 반환합니다.

SOL_RXRPC 옵션
옵션용도
RXRPC_SECURITY_KEY클라이언트 rxrpc 키 설명
RXRPC_SECURITY_KEYRING서버 secret keyring 설명
RXRPC_EXCLUSIVE_CONNECTION호출별 새 연결
RXRPC_MIN_SECURITY_LEVELPLAIN, AUTH, ENCRYPT 최소 수준
RXRPC_UPGRADEABLE_SERVICE서비스 ID 업그레이드 쌍
RXRPC_SUPPORTED_CMSG지원하는 최고 제어 메시지 조회

클라이언트 키, 서버 keyring, 연결 및 보안 정책을 소켓에 설정합니다.

Socket Options
==============

AF_RXRPC sockets support a few socket options at the SOL_RXRPC level:

 (#) RXRPC_SECURITY_KEY

     This is used to specify the description of the key to be used.  The key is
     extracted from the calling process's keyrings with request_key() and
     should be of "rxrpc" type.

     The optval pointer points to the description string, and optlen indicates
     how long the string is, without the NUL terminator.

 (#) RXRPC_SECURITY_KEYRING

     Similar to above but specifies a keyring of server secret keys to use (key
     type "keyring").  See the "Security" section.

 (#) RXRPC_EXCLUSIVE_CONNECTION

     This is used to request that new connections should be used for each call
     made subsequently on this socket.  optval should be NULL and optlen 0.

 (#) RXRPC_MIN_SECURITY_LEVEL

     This is used to specify the minimum security level required for calls on
     this socket.  optval must point to an int containing one of the following
     values:

     (a) RXRPC_SECURITY_PLAIN

         Encrypted checksum only.

     (b) RXRPC_SECURITY_AUTH

         Encrypted checksum plus packet padded and first eight bytes of packet
         encrypted - which includes the actual packet length.

     (c) RXRPC_SECURITY_ENCRYPT

         Encrypted checksum plus entire packet padded and encrypted, including
         actual packet length.

 (#) RXRPC_UPGRADEABLE_SERVICE

     This is used to indicate that a service socket with two bindings may
     upgrade one bound service to the other if requested by the client.  optval
     must point to an array of two unsigned short ints.  The first is the
     service ID to upgrade from and the second the service ID to upgrade to.

 (#) RXRPC_SUPPORTED_CMSG

     This is a read-only option that writes an int into the buffer indicating
     the highest control message type supported.

rxkad 보안 키

497-540

현재 구현된 보안 형식은 Kerberos 4와 동등한 rxkad이며 보안 인덱스 2를 사용합니다. 구현은 `rxkad` 커널 모듈에 있습니다. 클라이언트 티켓은 AFS kaserver 또는 Kerberos 서버에서 얻고 `klog` 같은 도구가 이를 `rxrpc` 키로 설치합니다. 문서가 가리키는 OpenAFS `klog.c`는 사용자 공간 키 구성 예를 제공합니다.

클라이언트 키 payload는 `rxrpc_key_sec2_v1` 구조입니다. `security_index`는 2, `ticket_length`는 뒤따르는 티켓 길이, `expiry`는 만료 시각, `kvno`는 키 버전입니다. `session_key[8]`에는 DES 세션 키가 들어가고 실제 티켓 바이트는 가변 배열 `ticket[0]` 뒤에 연속해 붙습니다.

서버 키 형식은 `rxrpc_s`이며 설명은 `<serviceID>:<securityIndex>`입니다. 예를 들어 VL 서비스에서 rxkad를 쓰면 `52:2`입니다. 키 payload는 8바이트 secret이고 `add_key()`로 keyring에 추가합니다. 이 keyring을 `RXRPC_SECURITY_KEYRING`으로 서버 소켓에 연결하면 보안 호출이 들어올 때 적절한 키를 조회합니다. OpenAFS `listen.c`가 서버 설정 예를 보여 줍니다.

rxkad 키 구성
키 형식핵심 내용
클라이언트rxrpc / rxrpc_key_sec2_v1만료, kvno, DES session_key, ticket
서버rxrpc_s / serviceID:securityIndex8바이트 secret을 담은 keyring

클라이언트 티켓과 서버 secret의 역할이 다릅니다.

Security
========

Currently, only the kerberos 4 equivalent protocol has been implemented
(security index 2 - rxkad).  This requires the rxkad module to be loaded and,
on the client, tickets of the appropriate type to be obtained from the AFS
kaserver or the kerberos server and installed as "rxrpc" type keys.  This is
normally done using the klog program.  An example simple klog program can be
found at:

        http://people.redhat.com/~dhowells/rxrpc/klog.c

The payload provided to add_key() on the client should be of the following
form::

        struct rxrpc_key_sec2_v1 {
                uint16_t        security_index;        /* 2 */
                uint16_t        ticket_length;        /* length of ticket[] */
                uint32_t        expiry;                /* time at which expires */
                uint8_t                kvno;                /* key version number */
                uint8_t                __pad[3];
                uint8_t                session_key[8];        /* DES session key */
                uint8_t                ticket[0];        /* the encrypted ticket */
        };

Where the ticket blob is just appended to the above structure.


For the server, keys of type "rxrpc_s" must be made available to the server.
They have a description of "<serviceID>:<securityIndex>" (eg: "52:2" for an
rxkad key for the AFS VL service).  When such a key is created, it should be
given the server's secret key as the instantiation data (see the example
below).

        add_key("rxrpc_s", "52:2", secret_key, 8, keyring);

A keyring is passed to the server socket by naming it in a sockopt.  The server
socket then looks the server secret keys up in this keyring when secure
incoming connections are made.  This can be seen in an example program that can
be found at:

        http://people.redhat.com/~dhowells/rxrpc/listen.c

사용자 공간 클라이언트 절차

541-636

클라이언트는 `socket(AF_RXRPC, SOCK_DGRAM, PF_INET)`으로 소켓을 만듭니다. IPv6 사용 예는 문서상 TODO입니다. 필요하면 service ID 0인 `sockaddr_rxrpc`으로 `bind()`해 로컬 포트를 정합니다. AFS callback처럼 7000번 포트를 쓸 수 있고, 그렇지 않으면 임의의 비특권 포트가 선택됩니다. 여러 가상 연결이 같은 UDP 포트를 공유할 수 있으며 보안은 각 가상 연결에 적용됩니다.

보안이 필요하면 `request_key()`로 클라이언트 키를 얻고 `RXRPC_SECURITY_KEY` 소켓 옵션으로 선택합니다. 최소 수준은 `RXRPC_MIN_SECURITY_LEVEL`로 정하며 예에서는 `RXRPC_SECURITY_ENCRYPT`를 요구합니다. 이어서 `connect()`로 기본 목적지 주소, UDP 포트와 VL 같은 service ID를 설정합니다.

호출 요청은 여러 `sendmsg()`로 나눌 수 있습니다. 첫 메시지에는 `RXRPC_USER_CALL_ID`가 반드시 들어가며 마지막을 제외한 송신에는 `MSG_MORE`를 붙입니다. 전체 길이를 아는 경우 첫 메시지에 `RXRPC_TX_LENGTH`를 넣습니다. 연결된 기본 목적지와 다른 곳으로 보낼 때는 호출의 첫 `sendmsg()`에서 `msg_name`을 지정합니다.

응답은 `recvmsg()`로 받습니다. 같은 단계에 데이터가 더 있으면 `MSG_MORE`, 호출을 끝내는 메시지면 `MSG_EOR`이 반환됩니다. 제어 데이터의 `RXRPC_USER_CALL_ID`로 호출을 식별하고, `RXRPC_ABORT`, `RXRPC_NET_ERROR`, `RXRPC_LOCAL_ERROR`, `RXRPC_BUSY` 같은 terminal 결과도 함께 처리해야 합니다.

서비스 업그레이드를 요청하려면 첫 송신에 `RXRPC_UPGRADE_SERVICE`를 넣습니다. 응답 `msg_name`의 `srx_service`가 서버가 선택한 실제 서비스입니다. 같은 목적지에 다음 호출을 보내기 전에 첫 탐색 결과를 기다리면 캐시된 업그레이드 결과를 안전하게 사용할 수 있습니다.

클라이언트 사용 순서
AF_RXRPC socket선택적 bindsecurity key와 최소 수준connectsendmsg 요청recvmsg 응답terminal 결과 처리

선택적 바인드와 보안 설정 뒤 요청과 응답을 태그로 연결합니다.

Example Client Usage
====================

A client would issue an operation by:

 (1) An RxRPC socket is set up by::

        client = socket(AF_RXRPC, SOCK_DGRAM, PF_INET);

     Where the third parameter indicates the protocol family of the transport
     socket used - usually IPv4 but it can also be IPv6 [TODO].

 (2) A local address can optionally be bound::

        struct sockaddr_rxrpc srx = {
                .srx_family        = AF_RXRPC,
                .srx_service        = 0,  /* we're a client */
                .transport_type        = SOCK_DGRAM,        /* type of transport socket */
                .transport.sin_family        = AF_INET,
                .transport.sin_port        = htons(7000), /* AFS callback */
                .transport.sin_address        = 0,  /* all local interfaces */
        };
        bind(client, &srx, sizeof(srx));

     This specifies the local UDP port to be used.  If not given, a random
     non-privileged port will be used.  A UDP port may be shared between
     several unrelated RxRPC sockets.  Security is handled on a basis of
     per-RxRPC virtual connection.

 (3) The security is set::

        const char *key = "AFS:cambridge.redhat.com";
        setsockopt(client, SOL_RXRPC, RXRPC_SECURITY_KEY, key, strlen(key));

     This issues a request_key() to get the key representing the security
     context.  The minimum security level can be set::

        unsigned int sec = RXRPC_SECURITY_ENCRYPT;
        setsockopt(client, SOL_RXRPC, RXRPC_MIN_SECURITY_LEVEL,
                   &sec, sizeof(sec));

 (4) The server to be contacted can then be specified (alternatively this can
     be done through sendmsg)::

        struct sockaddr_rxrpc srx = {
                .srx_family        = AF_RXRPC,
                .srx_service        = VL_SERVICE_ID,
                .transport_type        = SOCK_DGRAM,        /* type of transport socket */
                .transport.sin_family        = AF_INET,
                .transport.sin_port        = htons(7005), /* AFS volume manager */
                .transport.sin_address        = ...,
        };
        connect(client, &srx, sizeof(srx));

 (5) The request data should then be posted to the server socket using a series
     of sendmsg() calls, each with the following control message attached:

        ==================        ===================================
        RXRPC_USER_CALL_ID        specifies the user ID for this call
        ==================        ===================================

     MSG_MORE should be set in msghdr::msg_flags on all but the last part of
     the request.  Multiple requests may be made simultaneously.

     An RXRPC_TX_LENGTH control message can also be specified on the first
     sendmsg() call.

     If a call is intended to go to a destination other than the default
     specified through connect(), then msghdr::msg_name should be set on the
     first request message of that call.

 (6) The reply data will then be posted to the server socket for recvmsg() to
     pick up.  MSG_MORE will be flagged by recvmsg() if there's more reply data
     for a particular call to be read.  MSG_EOR will be set on the terminal
     read for a call.

     All data will be delivered with the following control message attached:

        RXRPC_USER_CALL_ID        - specifies the user ID for this call

     If an abort or error occurred, this will be returned in the control data
     buffer instead, and MSG_EOR will be flagged to indicate the end of that
     call.

A client may ask for a service ID it knows and ask that this be upgraded to a
better service if one is available by supplying RXRPC_UPGRADE_SERVICE on the
first sendmsg() of a call.  The client should then check srx_service in the
msg_name filled in by recvmsg() when collecting the result.  srx_service will
hold the same value as given to sendmsg() if the upgrade request was ignored by
the service - otherwise it will be altered to indicate the service ID the
server upgraded to.  Note that the upgraded service ID is chosen by the server.
The caller has to wait until it sees the service ID in the reply before sending
any more calls (further calls to the same destination will be blocked until the
probe is concluded).

사용자 공간 서버 절차

637-768

서버도 `socket(AF_RXRPC, SOCK_DGRAM, PF_INET)`으로 시작합니다. 보안을 쓰면 `keyctl()`로 `AFSkeys` 같은 keyring을 만들고, `rxrpc_s` 형식의 `52:2` 같은 서버 키를 `add_key()`로 넣은 뒤 `RXRPC_SECURITY_KEYRING` 옵션으로 소켓에 연결합니다. 서비스 중에도 keyring 내용을 바꿀 수 있어 키 교체가 가능합니다.

0이 아닌 service ID와 UDP 포트로 `bind()`하면 서버가 됩니다. 같은 전송 소켓에서 최대 두 service ID를 제공하려면 `bind()`를 두 번 호출합니다. 두 서비스 사이 업그레이드를 허용하려면 두 바인드 뒤에 `RXRPC_UPGRADEABLE_SERVICE`를 설정합니다. `listen(100)`은 대기 호출 backlog를 설정합니다.

새 호출은 데이터 없는 `recvmsg()`의 `RXRPC_NEW_CALL`로 알립니다. 이 알림의 주소는 실제 수락 시점까지 호출이 사라질 수 있으므로 의존하지 않습니다. 서버는 데이터 없는 `sendmsg()`에 `RXRPC_ACCEPT`와 새 `RXRPC_USER_CALL_ID`를 넣어 가장 오래된 호출을 수락합니다.

수락 뒤 요청 데이터는 `recvmsg()`로 읽으며 주소는 `msg_name`, 호출 태그는 제어 데이터, 이어지는 데이터 여부는 `MSG_MORE`로 확인합니다. 응답은 같은 call ID를 붙인 하나 이상의 `sendmsg()`로 보내고 마지막 전까지 `MSG_MORE`를 사용합니다. 최종 응답을 보낸 뒤 데이터 없는 `recvmsg()`에서 `RXRPC_ACK`, 해당 ID와 `MSG_EOR`을 받으면 호출이 완전히 끝납니다.

최종 응답 패킷을 보내기 전에는 데이터 없는 `sendmsg()`에 call ID와 4바이트 `RXRPC_ABORT` 코드를 넣어 호출을 중단할 수 있습니다. 중단 시 큐에 남아 있던 해당 호출 메시지는 폐기됩니다. 서버 소켓 하나에는 여러 호출의 DATA와 제어 메시지가 섞여 들어오므로 모든 메시지를 `RXRPC_USER_CALL_ID`로 다중화해야 합니다.

서버 사용 순서
socket과 keyringservice bindlistenNEW_CALLACCEPT + call ID요청 수신응답 송신최종 ACK

새 호출을 명시적으로 수락하고 최종 ACK까지 추적합니다.

Example Server Usage
====================

A server would be set up to accept operations in the following manner:

 (1) An RxRPC socket is created by::

        server = socket(AF_RXRPC, SOCK_DGRAM, PF_INET);

     Where the third parameter indicates the address type of the transport
     socket used - usually IPv4.

 (2) Security is set up if desired by giving the socket a keyring with server
     secret keys in it::

        keyring = add_key("keyring", "AFSkeys", NULL, 0,
                          KEY_SPEC_PROCESS_KEYRING);

        const char secret_key[8] = {
                0xa7, 0x83, 0x8a, 0xcb, 0xc7, 0x83, 0xec, 0x94 };
        add_key("rxrpc_s", "52:2", secret_key, 8, keyring);

        setsockopt(server, SOL_RXRPC, RXRPC_SECURITY_KEYRING, "AFSkeys", 7);

     The keyring can be manipulated after it has been given to the socket. This
     permits the server to add more keys, replace keys, etc. while it is live.

 (3) A local address must then be bound::

        struct sockaddr_rxrpc srx = {
                .srx_family        = AF_RXRPC,
                .srx_service        = VL_SERVICE_ID, /* RxRPC service ID */
                .transport_type        = SOCK_DGRAM,        /* type of transport socket */
                .transport.sin_family        = AF_INET,
                .transport.sin_port        = htons(7000), /* AFS callback */
                .transport.sin_address        = 0,  /* all local interfaces */
        };
        bind(server, &srx, sizeof(srx));

     More than one service ID may be bound to a socket, provided the transport
     parameters are the same.  The limit is currently two.  To do this, bind()
     should be called twice.

 (4) If service upgrading is required, first two service IDs must have been
     bound and then the following option must be set::

        unsigned short service_ids[2] = { from_ID, to_ID };
        setsockopt(server, SOL_RXRPC, RXRPC_UPGRADEABLE_SERVICE,
                   service_ids, sizeof(service_ids));

     This will automatically upgrade connections on service from_ID to service
     to_ID if they request it.  This will be reflected in msg_name obtained
     through recvmsg() when the request data is delivered to userspace.

 (5) The server is then set to listen out for incoming calls::

        listen(server, 100);

 (6) The kernel notifies the server of pending incoming connections by sending
     it a message for each.  This is received with recvmsg() on the server
     socket.  It has no data, and has a single dataless control message
     attached::

        RXRPC_NEW_CALL

     The address that can be passed back by recvmsg() at this point should be
     ignored since the call for which the message was posted may have gone by
     the time it is accepted - in which case the first call still on the queue
     will be accepted.

 (7) The server then accepts the new call by issuing a sendmsg() with two
     pieces of control data and no actual data:

        ==================        ==============================
        RXRPC_ACCEPT                indicate connection acceptance
        RXRPC_USER_CALL_ID        specify user ID for this call
        ==================        ==============================

 (8) The first request data packet will then be posted to the server socket for
     recvmsg() to pick up.  At that point, the RxRPC address for the call can
     be read from the address fields in the msghdr struct.

     Subsequent request data will be posted to the server socket for recvmsg()
     to collect as it arrives.  All but the last piece of the request data will
     be delivered with MSG_MORE flagged.

     All data will be delivered with the following control message attached:


        ==================        ===================================
        RXRPC_USER_CALL_ID        specifies the user ID for this call
        ==================        ===================================

 (9) The reply data should then be posted to the server socket using a series
     of sendmsg() calls, each with the following control messages attached:

        ==================        ===================================
        RXRPC_USER_CALL_ID        specifies the user ID for this call
        ==================        ===================================

     MSG_MORE should be set in msghdr::msg_flags on all but the last message
     for a particular call.

(10) The final ACK from the client will be posted for retrieval by recvmsg()
     when it is received.  It will take the form of a dataless message with two
     control messages attached:

        ==================        ===================================
        RXRPC_USER_CALL_ID        specifies the user ID for this call
        RXRPC_ACK                indicates final ACK (no data)
        ==================        ===================================

     MSG_EOR will be flagged to indicate that this is the final message for
     this call.

(11) Up to the point the final packet of reply data is sent, the call can be
     aborted by calling sendmsg() with a dataless message with the following
     control messages attached:

        ==================        ===================================
        RXRPC_USER_CALL_ID        specifies the user ID for this call
        RXRPC_ABORT                indicates abort code (4 byte data)
        ==================        ===================================

     Any packets waiting in the socket's receive queue will be discarded if
     this is issued.

Note that all the communications for a particular service take place through
the one server socket, using control messages on sendmsg() and recvmsg() to
determine the call affected.

커널 호출 생성과 송신

769-889

커널 인터페이스는 한 소켓에서 호출마다 다른 키를 쓰고, 커널 호출자가 직접 키를 요청하며, 메모리 할당용 `gfp_t`를 지정하고, `recvmsg()` 대신 skb를 가로채 처리할 수 있게 합니다. 기본 준비는 사용자 공간과 같이 AF_RXRPC 소켓을 열고 `bind()` 또는 `listen()`하는 것입니다.

`rxrpc_kernel_begin_call()`은 호출에 필요한 상태를 할당하고 실제 연결과 채널을 선택합니다. `srx`가 없으면 연결된 소켓의 목적지를 쓰고, 명시적 `key`는 소켓의 기본 키를 덮어쓰지만 같은 조건의 연결 공유는 계속 가능합니다. `user_call_ID`는 호출자가 선택한 포인터 태그입니다. `tx_total_len`이 -1이면 길이를 모르며 0 이상이면 전체 송신 길이를 선언해 직접 암호화 경로를 허용합니다.

`notify_rx` 콜백은 수신 이벤트를 알리고 `upgrade`는 서비스 업그레이드 탐색을 요청합니다. `intr`가 참이면 채널을 기다리는 동안 신호에 의해 `-ERESTARTSYS`로 중단될 수 있습니다. `debug_id`에는 `rxrpc_debug_id`에서 원자적으로 얻은 추적 번호를 넣습니다. 성공하면 불투명한 `struct rxrpc_call *` 참조를 반환하며 반드시 종료 또는 해제해야 합니다.

`rxrpc_kernel_shutdown_call()`은 call ID를 소켓에서 제거하고 호출을 종료합니다. `rxrpc_kernel_put_call()`은 보유한 참조를 놓습니다. 두 함수의 책임이 다르므로 호출 수명과 참조 수명을 각각 맞춰야 합니다.

`rxrpc_kernel_send_data()`는 커널 가상 주소 iov를 담은 `msghdr`에서 데이터를 보냅니다. 허용되는 플래그는 단계가 계속됨을 뜻하는 `MSG_MORE`뿐이며 목적지 주소나 제어 메시지는 받지 않습니다. 마지막 DATA를 보내기 전에 Tx 단계가 끝났음을 알리는 콜백이 spinlock을 잡은 상태에서 호출될 수 있으므로 콜백은 잠금 문맥에 맞아야 합니다.

커널 송신 수명
rxrpc_kernel_begin_callrxrpc_kernel_send_dataTx 종료 콜백rxrpc_kernel_shutdown_callrxrpc_kernel_put_call

생성과 송신, 종료, 참조 해제를 분리해 관리합니다.

AF_RXRPC Kernel Interface
=========================

The AF_RXRPC module also provides an interface for use by in-kernel utilities
such as the AFS filesystem.  This permits such a utility to:

 (1) Use different keys directly on individual client calls on one socket
     rather than having to open a whole slew of sockets, one for each key it
     might want to use.

 (2) Avoid having RxRPC call request_key() at the point of issue of a call or
     opening of a socket.  Instead the utility is responsible for requesting a
     key at the appropriate point.  AFS, for instance, would do this during VFS
     operations such as open() or unlink().  The key is then handed through
     when the call is initiated.

 (3) Request the use of something other than GFP_KERNEL to allocate memory.

 (4) Avoid the overhead of using the recvmsg() call.  RxRPC messages can be
     intercepted before they get put into the socket Rx queue and the socket
     buffers manipulated directly.

To use the RxRPC facility, a kernel utility must still open an AF_RXRPC socket,
bind an address as appropriate and listen if it's to be a server socket, but
then it passes this to the kernel interface functions.

The kernel interface functions are as follows:

 (#) Begin a new client call::

        struct rxrpc_call *
        rxrpc_kernel_begin_call(struct socket *sock,
                                struct sockaddr_rxrpc *srx,
                                struct key *key,
                                unsigned long user_call_ID,
                                s64 tx_total_len,
                                gfp_t gfp,
                                rxrpc_notify_rx_t notify_rx,
                                bool upgrade,
                                bool intr,
                                unsigned int debug_id);

     This allocates the infrastructure to make a new RxRPC call and assigns
     call and connection numbers.  The call will be made on the UDP port that
     the socket is bound to.  The call will go to the destination address of a
     connected client socket unless an alternative is supplied (srx is
     non-NULL).

     If a key is supplied then this will be used to secure the call instead of
     the key bound to the socket with the RXRPC_SECURITY_KEY sockopt.  Calls
     secured in this way will still share connections if at all possible.

     The user_call_ID is equivalent to that supplied to sendmsg() in the
     control data buffer.  It is entirely feasible to use this to point to a
     kernel data structure.

     tx_total_len is the amount of data the caller is intending to transmit
     with this call (or -1 if unknown at this point).  Setting the data size
     allows the kernel to encrypt directly to the packet buffers, thereby
     saving a copy.  The value may not be less than -1.

     notify_rx is a pointer to a function to be called when events such as
     incoming data packets or remote aborts happen.

     upgrade should be set to true if a client operation should request that
     the server upgrade the service to a better one.  The resultant service ID
     is returned by rxrpc_kernel_recv_data().

     intr should be set to true if the call should be interruptible.  If this
     is not set, this function may not return until a channel has been
     allocated; if it is set, the function may return -ERESTARTSYS.

     debug_id is the call debugging ID to be used for tracing.  This can be
     obtained by atomically incrementing rxrpc_debug_id.

     If this function is successful, an opaque reference to the RxRPC call is
     returned.  The caller now holds a reference on this and it must be
     properly ended.

 (#) Shut down a client call::

        void rxrpc_kernel_shutdown_call(struct socket *sock,
                                        struct rxrpc_call *call);

     This is used to shut down a previously begun call.  The user_call_ID is
     expunged from AF_RXRPC's knowledge and will not be seen again in
     association with the specified call.

 (#) Release the ref on a client call::

        void rxrpc_kernel_put_call(struct socket *sock,
                                   struct rxrpc_call *call);

     This is used to release the caller's ref on an rxrpc call.

 (#) Send data through a call::

        typedef void (*rxrpc_notify_end_tx_t)(struct sock *sk,
                                              unsigned long user_call_ID,
                                              struct sk_buff *skb);

        int rxrpc_kernel_send_data(struct socket *sock,
                                   struct rxrpc_call *call,
                                   struct msghdr *msg,
                                   size_t len,
                                   rxrpc_notify_end_tx_t notify_end_rx);

     This is used to supply either the request part of a client call or the
     reply part of a server call.  msg.msg_iovlen and msg.msg_iov specify the
     data buffers to be used.  msg_iov may not be NULL and must point
     exclusively to in-kernel virtual addresses.  msg.msg_flags may be given
     MSG_MORE if there will be subsequent data sends for this call.

     The msg must not specify a destination address, control data or any flags
     other than MSG_MORE.  len is the total amount of data to transmit.

     notify_end_rx can be NULL or it can be used to specify a function to be
     called when the call changes state to end the Tx phase.  This function is
     called with a spinlock held to prevent the last DATA packet from being
     transmitted until the function returns.

커널 수신, skb 가로채기와 생존 확인

890-1071

`rxrpc_kernel_recv_data()`는 호출 응답을 `buf`로 복사하고 `offset`을 갱신합니다. 버퍼가 찼지만 더 받을 수 있으면 0과 `want_more=true`, 마지막 DATA까지 정확히 소비하면 1과 `want_more=false`, 지금 처리할 데이터가 없으면 `-EAGAIN`입니다. 마지막 패킷인데 요청한 크기를 채우지 못하면 `-EBADMSG`, `want_more=false`인데 여분 데이터가 있으면 `-EMSGSIZE`입니다. 원격 abort면 코드를 `abort`에 저장하고 `-ECONNABORTED`를 반환하며, `service`에는 업그레이드 결과가 기록됩니다.

`rxrpc_kernel_abort_call()`은 지정한 abort code로 호출을 중단합니다. 일반 수신 큐 대신 직접 메시지를 처리하려면 `rxrpc_kernel_intercept_rx_messages()`에 콜백을 등록합니다. 콜백에는 소켓, user call ID와 skb가 전달되며 DATA 순서는 보존됩니다. `skb->mark`는 `RXRPC_SKB_MARK_DATA`, `FINAL_ACK`, `BUSY`, `REMOTE_ABORT`, `NET_ERROR`, `LOCAL_ERROR`, `NEW_CALL` 가운데 하나로 메시지 종류를 나타냅니다.

abort와 errno는 전용 접근자로 꺼냅니다. 새 호출은 `rxrpc_kernel_accept_call()`로 수락하고 반환된 불투명 호출 참조는 다른 호출과 같은 방식으로 끝내야 합니다. DATA skb에서는 `rxrpc_kernel_extract_data()`로 바이트를 추출하고 `rxrpc_kernel_is_data_last()`로 마지막 패킷인지 검사하며, 소비가 끝나면 `rxrpc_kernel_data_consumed()`를 호출합니다. `rxrpc_kernel_free_skb()`가 skb를 해제합니다. skb가 보유한 추가 참조는 관련 호출 상태를 계속 고정합니다.

`rxrpc_kernel_reject_call()`은 가장 오래된 새 호출을 BUSY로 거절합니다. 대기 호출이 없으면 `-ENODATA`, 이미 중단됐으면 `-ECONNABORTED`, 만료됐으면 `-ETIME`입니다. `rxrpc_kernel_get_null_key()`는 익명 보안 호출용 null key를, `rxrpc_kernel_get_peer()`는 peer 객체를 반환합니다. `rxrpc_kernel_set_tx_length()`는 0 이상인 응답 길이를 설정하고 `rxrpc_kernel_get_rtt()`는 RTT를 ns 단위로 반환합니다.

`rxrpc_kernel_check_life()`는 ACK를 받을 때 증가하는 life counter를 표본과 비교합니다. PING ACK가 유도한 PING RESPONSE도 counter를 바꿉니다. 호출이 완료되지 않은 동안 최근 활동이 있었는지 확인할 수 있습니다. `rxrpc_kernel_probe_life()`는 PING ACK를 보내 생존을 확인하며 호출자는 `TASK_RUNNING` 상태여야 합니다. `rxrpc_sock_set_min_security_level()`은 커널 소켓의 최소 보안 수준을 설정합니다.

skb->mark 값
표시의미
RXRPC_SKB_MARK_DATA호출 DATA
RXRPC_SKB_MARK_FINAL_ACK서버가 받은 최종 ACK
RXRPC_SKB_MARK_BUSY호출 거절
RXRPC_SKB_MARK_REMOTE_ABORT원격 abort
RXRPC_SKB_MARK_NET_ERROR네트워크 오류
RXRPC_SKB_MARK_LOCAL_ERROR로컬 오류
RXRPC_SKB_MARK_NEW_CALL수락 대기 새 호출

가로챈 Rx skb의 의미를 분류합니다.

가로챈 DATA 처리
Rx callbackmark 검사extract_datais_data_lastdata_consumedfree_skb

skb에서 데이터를 꺼낸 뒤 소비 완료와 해제를 모두 알립니다.

 (#) Receive data from a call::

        int rxrpc_kernel_recv_data(struct socket *sock,
                                   struct rxrpc_call *call,
                                   void *buf,
                                   size_t size,
                                   size_t *_offset,
                                   bool want_more,
                                   u32 *_abort,
                                   u16 *_service)

      This is used to receive data from either the reply part of a client call
      or the request part of a service call.  buf and size specify how much
      data is desired and where to store it.  *_offset is added on to buf and
      subtracted from size internally; the amount copied into the buffer is
      added to *_offset before returning.

      want_more should be true if further data will be required after this is
      satisfied and false if this is the last item of the receive phase.

      There are three normal returns: 0 if the buffer was filled and want_more
      was true; 1 if the buffer was filled, the last DATA packet has been
      emptied and want_more was false; and -EAGAIN if the function needs to be
      called again.

      If the last DATA packet is processed but the buffer contains less than
      the amount requested, EBADMSG is returned.  If want_more wasn't set, but
      more data was available, EMSGSIZE is returned.

      If a remote ABORT is detected, the abort code received will be stored in
      ``*_abort`` and ECONNABORTED will be returned.

      The service ID that the call ended up with is returned into *_service.
      This can be used to see if a call got a service upgrade.

 (#) Abort a call??

     ::

        void rxrpc_kernel_abort_call(struct socket *sock,
                                     struct rxrpc_call *call,
                                     u32 abort_code);

     This is used to abort a call if it's still in an abortable state.  The
     abort code specified will be placed in the ABORT message sent.

 (#) Intercept received RxRPC messages::

        typedef void (*rxrpc_interceptor_t)(struct sock *sk,
                                            unsigned long user_call_ID,
                                            struct sk_buff *skb);

        void
        rxrpc_kernel_intercept_rx_messages(struct socket *sock,
                                           rxrpc_interceptor_t interceptor);

     This installs an interceptor function on the specified AF_RXRPC socket.
     All messages that would otherwise wind up in the socket's Rx queue are
     then diverted to this function.  Note that care must be taken to process
     the messages in the right order to maintain DATA message sequentiality.

     The interceptor function itself is provided with the address of the socket
     and handling the incoming message, the ID assigned by the kernel utility
     to the call and the socket buffer containing the message.

     The skb->mark field indicates the type of message:

        ===============================        =======================================
        Mark                                Meaning
        ===============================        =======================================
        RXRPC_SKB_MARK_DATA                Data message
        RXRPC_SKB_MARK_FINAL_ACK        Final ACK received for an incoming call
        RXRPC_SKB_MARK_BUSY                Client call rejected as server busy
        RXRPC_SKB_MARK_REMOTE_ABORT        Call aborted by peer
        RXRPC_SKB_MARK_NET_ERROR        Network error detected
        RXRPC_SKB_MARK_LOCAL_ERROR        Local error encountered
        RXRPC_SKB_MARK_NEW_CALL                New incoming call awaiting acceptance
        ===============================        =======================================

     The remote abort message can be probed with rxrpc_kernel_get_abort_code().
     The two error messages can be probed with rxrpc_kernel_get_error_number().
     A new call can be accepted with rxrpc_kernel_accept_call().

     Data messages can have their contents extracted with the usual bunch of
     socket buffer manipulation functions.  A data message can be determined to
     be the last one in a sequence with rxrpc_kernel_is_data_last().  When a
     data message has been used up, rxrpc_kernel_data_consumed() should be
     called on it.

     Messages should be handled to rxrpc_kernel_free_skb() to dispose of.  It
     is possible to get extra refs on all types of message for later freeing,
     but this may pin the state of a call until the message is finally freed.

 (#) Accept an incoming call::

        struct rxrpc_call *
        rxrpc_kernel_accept_call(struct socket *sock,
                                 unsigned long user_call_ID);

     This is used to accept an incoming call and to assign it a call ID.  This
     function is similar to rxrpc_kernel_begin_call() and calls accepted must
     be ended in the same way.

     If this function is successful, an opaque reference to the RxRPC call is
     returned.  The caller now holds a reference on this and it must be
     properly ended.

 (#) Reject an incoming call::

        int rxrpc_kernel_reject_call(struct socket *sock);

     This is used to reject the first incoming call on the socket's queue with
     a BUSY message.  -ENODATA is returned if there were no incoming calls.
     Other errors may be returned if the call had been aborted (-ECONNABORTED)
     or had timed out (-ETIME).

 (#) Allocate a null key for doing anonymous security::

        struct key *rxrpc_get_null_key(const char *keyname);

     This is used to allocate a null RxRPC key that can be used to indicate
     anonymous security for a particular domain.

 (#) Get the peer address of a call::

        void rxrpc_kernel_get_peer(struct socket *sock, struct rxrpc_call *call,
                                   struct sockaddr_rxrpc *_srx);

     This is used to find the remote peer address of a call.

 (#) Set the total transmit data size on a call::

        void rxrpc_kernel_set_tx_length(struct socket *sock,
                                        struct rxrpc_call *call,
                                        s64 tx_total_len);

     This sets the amount of data that the caller is intending to transmit on a
     call.  It's intended to be used for setting the reply size as the request
     size should be set when the call is begun.  tx_total_len may not be less
     than zero.

 (#) Get call RTT::

        u64 rxrpc_kernel_get_rtt(struct socket *sock, struct rxrpc_call *call);

     Get the RTT time to the peer in use by a call.  The value returned is in
     nanoseconds.

 (#) Check call still alive::

        bool rxrpc_kernel_check_life(struct socket *sock,
                                     struct rxrpc_call *call,
                                     u32 *_life);
        void rxrpc_kernel_probe_life(struct socket *sock,
                                     struct rxrpc_call *call);

     The first function passes back in ``*_life`` a number that is updated when
     ACKs are received from the peer (notably including PING RESPONSE ACKs
     which we can elicit by sending PING ACKs to see if the call still exists
     on the server).  The caller should compare the numbers of two calls to see
     if the call is still alive after waiting for a suitable interval.  It also
     returns true as long as the call hasn't yet reached the completed state.

     This allows the caller to work out if the server is still contactable and
     if the call is still alive on the server while waiting for the server to
     process a client operation.

     The second function causes a ping ACK to be transmitted to try to provoke
     the peer into responding, which would then cause the value returned by the
     first function to change.  Note that this must be called in TASK_RUNNING
     state.

 (#) Apply the RXRPC_MIN_SECURITY_LEVEL sockopt to a socket from within in the
     kernel::

       int rxrpc_sock_set_min_security_level(struct sock *sk,
                                             unsigned int val);

     This specifies the minimum security level required for calls on this
     socket.

조정 가능한 /proc/net/rxrpc 매개변수

1072-1149

RxRPC 조정값은 `/proc/net/rxrpc/` 아래에 있습니다. `req_ack_delay`는 요청 ACK 플래그를 붙이기 전 지연으로, 255패킷 수신 창 안에서 송신자가 ACK 요청을 함께 묶도록 합니다. `soft_ack_delay`는 새 패킷에 대한 soft ACK 지연, `idle_ack_delay`는 응용 프로그램이 데이터를 소비한 뒤 수신 버퍼를 해제하는 hard ACK 지연입니다. 모두 밀리초 단위입니다.

`resend_timeout`은 재전송을 시작할 시간이며 밀리초 단위입니다. `max_call_lifetime`은 호출 최대 수명, `dead_call_expiry`는 종료 호출을 보관해 반복 패킷에 ACK 또는 ABORT를 다시 보낼 시간, `connection_expiry`는 보안 상태를 포함한 연결을 보관할 시간, `transport_expiry`는 peer와 connection ID 카운터를 붙잡는 전송 객체 보관 시간입니다. 이 네 값은 초 단위입니다.

`rxrpc_rx_window_size`는 호출별로 응용 프로그램이 아직 소비하지 않은 수신 패킷 수의 상한입니다. `rxrpc_rx_mtu`는 jumbo packet 수용에 사용하는 바이트 MTU이고 `rxrpc_rx_jumbo_max`는 한 jumbo packet에 묶을 수 있는 패킷 수입니다. 비종단 하위 패킷은 4바이트 헤더와 정확히 1412바이트 데이터, 종단 하위 패킷은 4바이트 헤더와 임의 길이 데이터를 가지며 전체는 Rx MTU를 넘을 수 없습니다.

RxRPC 조정값
이름단위역할
req_ack_delaymsACK 요청 결합 지연
soft_ack_delayms새 패킷 soft ACK 지연
idle_ack_delayms소비 완료 hard ACK 지연
resend_timeoutms재전송 대기
max_call_lifetimes호출 최대 수명
dead_call_expirys종료 호출 보관
connection_expirys연결과 보안 상태 보관
transport_expirys전송 객체 보관
rxrpc_rx_window_sizepackets미소비 수신 창
rxrpc_rx_mtubytesjumbo 수신 MTU
rxrpc_rx_jumbo_maxpacketsjumbo 하위 패킷 상한

지연, 수명, 수신 창 및 jumbo 수용량을 제어합니다.

Configurable Parameters
=======================

The RxRPC protocol driver has a number of configurable parameters that can be
adjusted through sysctls in /proc/net/rxrpc/:

 (#) req_ack_delay

     The amount of time in milliseconds after receiving a packet with the
     request-ack flag set before we honour the flag and actually send the
     requested ack.

     Usually the other side won't stop sending packets until the advertised
     reception window is full (to a maximum of 255 packets), so delaying the
     ACK permits several packets to be ACK'd in one go.

 (#) soft_ack_delay

     The amount of time in milliseconds after receiving a new packet before we
     generate a soft-ACK to tell the sender that it doesn't need to resend.

 (#) idle_ack_delay

     The amount of time in milliseconds after all the packets currently in the
     received queue have been consumed before we generate a hard-ACK to tell
     the sender it can free its buffers, assuming no other reason occurs that
     we would send an ACK.

 (#) resend_timeout

     The amount of time in milliseconds after transmitting a packet before we
     transmit it again, assuming no ACK is received from the receiver telling
     us they got it.

 (#) max_call_lifetime

     The maximum amount of time in seconds that a call may be in progress
     before we preemptively kill it.

 (#) dead_call_expiry

     The amount of time in seconds before we remove a dead call from the call
     list.  Dead calls are kept around for a little while for the purpose of
     repeating ACK and ABORT packets.

 (#) connection_expiry

     The amount of time in seconds after a connection was last used before we
     remove it from the connection list.  While a connection is in existence,
     it serves as a placeholder for negotiated security; when it is deleted,
     the security must be renegotiated.

 (#) transport_expiry

     The amount of time in seconds after a transport was last used before we
     remove it from the transport list.  While a transport is in existence, it
     serves to anchor the peer data and keeps the connection ID counter.

 (#) rxrpc_rx_window_size

     The size of the receive window in packets.  This is the maximum number of
     unconsumed received packets we're willing to hold in memory for any
     particular call.

 (#) rxrpc_rx_mtu

     The maximum packet MTU size that we're willing to receive in bytes.  This
     indicates to the peer whether we're willing to accept jumbo packets.

 (#) rxrpc_rx_jumbo_max

     The maximum number of packets that we're willing to accept in a jumbo
     packet.  Non-terminal packets in a jumbo packet must contain a four byte
     header plus exactly 1412 bytes of data.  The terminal packet must contain
     a four byte header plus any amount of data.  In any event, a jumbo packet
     may not exceed rxrpc_rx_mtu in size.

커널 API 함수 참조 source path

1150-1162

마지막 절은 kernel-doc이 읽는 RxRPC 구현 파일을 나열합니다. 공개 함수의 실제 선언과 주석은 `net/rxrpc/af_rxrpc.c`, `call_object.c`, `key.c`, `oob.c`, `peer_object.c`, `recvmsg.c`, `rxgk.c`, `rxkad.c`, `sendmsg.c`, `server_key.c`에 있습니다. 이 경로는 API 설명과 현재 구현을 교차 확인할 기준입니다.

RxRPC API 구현 영역
영역파일
소켓과 호출af_rxrpc.c, call_object.c
키와 보안key.c, rxgk.c, rxkad.c, server_key.c
송수신recvmsg.c, sendmsg.c, oob.c
peerpeer_object.c

kernel-doc 입력 source path를 기능별로 묶었습니다.

API Function Reference
======================

.. kernel-doc:: net/rxrpc/af_rxrpc.c
.. kernel-doc:: net/rxrpc/call_object.c
.. kernel-doc:: net/rxrpc/key.c
.. kernel-doc:: net/rxrpc/oob.c
.. kernel-doc:: net/rxrpc/peer_object.c
.. kernel-doc:: net/rxrpc/recvmsg.c
.. kernel-doc:: net/rxrpc/rxgk.c
.. kernel-doc:: net/rxrpc/rxkad.c
.. kernel-doc:: net/rxrpc/sendmsg.c
.. kernel-doc:: net/rxrpc/server_key.c