19f72374cSMauro Carvalho Chehab.. SPDX-License-Identifier: GPL-2.0 29f72374cSMauro Carvalho Chehab 39f72374cSMauro Carvalho Chehab====================== 49f72374cSMauro Carvalho ChehabRxRPC Network Protocol 59f72374cSMauro Carvalho Chehab====================== 69f72374cSMauro Carvalho Chehab 79f72374cSMauro Carvalho ChehabThe RxRPC protocol driver provides a reliable two-phase transport on top of UDP 89f72374cSMauro Carvalho Chehabthat can be used to perform RxRPC remote operations. This is done over sockets 99f72374cSMauro Carvalho Chehabof AF_RXRPC family, using sendmsg() and recvmsg() with control data to send and 109f72374cSMauro Carvalho Chehabreceive data, aborts and errors. 119f72374cSMauro Carvalho Chehab 129f72374cSMauro Carvalho ChehabContents of this document: 139f72374cSMauro Carvalho Chehab 149f72374cSMauro Carvalho Chehab (#) Overview. 159f72374cSMauro Carvalho Chehab 169f72374cSMauro Carvalho Chehab (#) RxRPC protocol summary. 179f72374cSMauro Carvalho Chehab 189f72374cSMauro Carvalho Chehab (#) AF_RXRPC driver model. 199f72374cSMauro Carvalho Chehab 209f72374cSMauro Carvalho Chehab (#) Control messages. 219f72374cSMauro Carvalho Chehab 229f72374cSMauro Carvalho Chehab (#) Socket options. 239f72374cSMauro Carvalho Chehab 249f72374cSMauro Carvalho Chehab (#) Security. 259f72374cSMauro Carvalho Chehab 269f72374cSMauro Carvalho Chehab (#) Example client usage. 279f72374cSMauro Carvalho Chehab 289f72374cSMauro Carvalho Chehab (#) Example server usage. 299f72374cSMauro Carvalho Chehab 309f72374cSMauro Carvalho Chehab (#) AF_RXRPC kernel interface. 319f72374cSMauro Carvalho Chehab 329f72374cSMauro Carvalho Chehab (#) Configurable parameters. 339f72374cSMauro Carvalho Chehab 349f72374cSMauro Carvalho Chehab 359f72374cSMauro Carvalho ChehabOverview 369f72374cSMauro Carvalho Chehab======== 379f72374cSMauro Carvalho Chehab 389f72374cSMauro Carvalho ChehabRxRPC is a two-layer protocol. There is a session layer which provides 399f72374cSMauro Carvalho Chehabreliable virtual connections using UDP over IPv4 (or IPv6) as the transport 409f72374cSMauro Carvalho Chehablayer, but implements a real network protocol; and there's the presentation 419f72374cSMauro Carvalho Chehablayer which renders structured data to binary blobs and back again using XDR 429f72374cSMauro Carvalho Chehab(as does SunRPC):: 439f72374cSMauro Carvalho Chehab 449f72374cSMauro Carvalho Chehab +-------------+ 459f72374cSMauro Carvalho Chehab | Application | 469f72374cSMauro Carvalho Chehab +-------------+ 479f72374cSMauro Carvalho Chehab | XDR | Presentation 489f72374cSMauro Carvalho Chehab +-------------+ 499f72374cSMauro Carvalho Chehab | RxRPC | Session 509f72374cSMauro Carvalho Chehab +-------------+ 519f72374cSMauro Carvalho Chehab | UDP | Transport 529f72374cSMauro Carvalho Chehab +-------------+ 539f72374cSMauro Carvalho Chehab 549f72374cSMauro Carvalho Chehab 559f72374cSMauro Carvalho ChehabAF_RXRPC provides: 569f72374cSMauro Carvalho Chehab 579f72374cSMauro Carvalho Chehab (1) Part of an RxRPC facility for both kernel and userspace applications by 589f72374cSMauro Carvalho Chehab making the session part of it a Linux network protocol (AF_RXRPC). 599f72374cSMauro Carvalho Chehab 609f72374cSMauro Carvalho Chehab (2) A two-phase protocol. The client transmits a blob (the request) and then 619f72374cSMauro Carvalho Chehab receives a blob (the reply), and the server receives the request and then 629f72374cSMauro Carvalho Chehab transmits the reply. 639f72374cSMauro Carvalho Chehab 649f72374cSMauro Carvalho Chehab (3) Retention of the reusable bits of the transport system set up for one call 659f72374cSMauro Carvalho Chehab to speed up subsequent calls. 669f72374cSMauro Carvalho Chehab 679f72374cSMauro Carvalho Chehab (4) A secure protocol, using the Linux kernel's key retention facility to 689f72374cSMauro Carvalho Chehab manage security on the client end. The server end must of necessity be 699f72374cSMauro Carvalho Chehab more active in security negotiations. 709f72374cSMauro Carvalho Chehab 719f72374cSMauro Carvalho ChehabAF_RXRPC does not provide XDR marshalling/presentation facilities. That is 729f72374cSMauro Carvalho Chehableft to the application. AF_RXRPC only deals in blobs. Even the operation ID 739f72374cSMauro Carvalho Chehabis just the first four bytes of the request blob, and as such is beyond the 749f72374cSMauro Carvalho Chehabkernel's interest. 759f72374cSMauro Carvalho Chehab 769f72374cSMauro Carvalho Chehab 779f72374cSMauro Carvalho ChehabSockets of AF_RXRPC family are: 789f72374cSMauro Carvalho Chehab 799f72374cSMauro Carvalho Chehab (1) created as type SOCK_DGRAM; 809f72374cSMauro Carvalho Chehab 819f72374cSMauro Carvalho Chehab (2) provided with a protocol of the type of underlying transport they're going 829f72374cSMauro Carvalho Chehab to use - currently only PF_INET is supported. 839f72374cSMauro Carvalho Chehab 849f72374cSMauro Carvalho Chehab 859f72374cSMauro Carvalho ChehabThe Andrew File System (AFS) is an example of an application that uses this and 869f72374cSMauro Carvalho Chehabthat has both kernel (filesystem) and userspace (utility) components. 879f72374cSMauro Carvalho Chehab 889f72374cSMauro Carvalho Chehab 899f72374cSMauro Carvalho ChehabRxRPC Protocol Summary 909f72374cSMauro Carvalho Chehab====================== 919f72374cSMauro Carvalho Chehab 929f72374cSMauro Carvalho ChehabAn overview of the RxRPC protocol: 939f72374cSMauro Carvalho Chehab 949f72374cSMauro Carvalho Chehab (#) RxRPC sits on top of another networking protocol (UDP is the only option 959f72374cSMauro Carvalho Chehab currently), and uses this to provide network transport. UDP ports, for 969f72374cSMauro Carvalho Chehab example, provide transport endpoints. 979f72374cSMauro Carvalho Chehab 989f72374cSMauro Carvalho Chehab (#) RxRPC supports multiple virtual "connections" from any given transport 999f72374cSMauro Carvalho Chehab endpoint, thus allowing the endpoints to be shared, even to the same 1009f72374cSMauro Carvalho Chehab remote endpoint. 1019f72374cSMauro Carvalho Chehab 1029f72374cSMauro Carvalho Chehab (#) Each connection goes to a particular "service". A connection may not go 1039f72374cSMauro Carvalho Chehab to multiple services. A service may be considered the RxRPC equivalent of 1049f72374cSMauro Carvalho Chehab a port number. AF_RXRPC permits multiple services to share an endpoint. 1059f72374cSMauro Carvalho Chehab 1069f72374cSMauro Carvalho Chehab (#) Client-originating packets are marked, thus a transport endpoint can be 1079f72374cSMauro Carvalho Chehab shared between client and server connections (connections have a 1089f72374cSMauro Carvalho Chehab direction). 1099f72374cSMauro Carvalho Chehab 1109f72374cSMauro Carvalho Chehab (#) Up to a billion connections may be supported concurrently between one 1119f72374cSMauro Carvalho Chehab local transport endpoint and one service on one remote endpoint. An RxRPC 1129f72374cSMauro Carvalho Chehab connection is described by seven numbers:: 1139f72374cSMauro Carvalho Chehab 1149f72374cSMauro Carvalho Chehab Local address } 1159f72374cSMauro Carvalho Chehab Local port } Transport (UDP) address 1169f72374cSMauro Carvalho Chehab Remote address } 1179f72374cSMauro Carvalho Chehab Remote port } 1189f72374cSMauro Carvalho Chehab Direction 1199f72374cSMauro Carvalho Chehab Connection ID 1209f72374cSMauro Carvalho Chehab Service ID 1219f72374cSMauro Carvalho Chehab 1229f72374cSMauro Carvalho Chehab (#) Each RxRPC operation is a "call". A connection may make up to four 1239f72374cSMauro Carvalho Chehab billion calls, but only up to four calls may be in progress on a 1249f72374cSMauro Carvalho Chehab connection at any one time. 1259f72374cSMauro Carvalho Chehab 1269f72374cSMauro Carvalho Chehab (#) Calls are two-phase and asymmetric: the client sends its request data, 1279f72374cSMauro Carvalho Chehab which the service receives; then the service transmits the reply data 1289f72374cSMauro Carvalho Chehab which the client receives. 1299f72374cSMauro Carvalho Chehab 1309f72374cSMauro Carvalho Chehab (#) The data blobs are of indefinite size, the end of a phase is marked with a 1319f72374cSMauro Carvalho Chehab flag in the packet. The number of packets of data making up one blob may 1329f72374cSMauro Carvalho Chehab not exceed 4 billion, however, as this would cause the sequence number to 1339f72374cSMauro Carvalho Chehab wrap. 1349f72374cSMauro Carvalho Chehab 1359f72374cSMauro Carvalho Chehab (#) The first four bytes of the request data are the service operation ID. 1369f72374cSMauro Carvalho Chehab 1379f72374cSMauro Carvalho Chehab (#) Security is negotiated on a per-connection basis. The connection is 1389f72374cSMauro Carvalho Chehab initiated by the first data packet on it arriving. If security is 1399f72374cSMauro Carvalho Chehab requested, the server then issues a "challenge" and then the client 1409f72374cSMauro Carvalho Chehab replies with a "response". If the response is successful, the security is 1419f72374cSMauro Carvalho Chehab set for the lifetime of that connection, and all subsequent calls made 1429f72374cSMauro Carvalho Chehab upon it use that same security. In the event that the server lets a 1439f72374cSMauro Carvalho Chehab connection lapse before the client, the security will be renegotiated if 1449f72374cSMauro Carvalho Chehab the client uses the connection again. 1459f72374cSMauro Carvalho Chehab 1469f72374cSMauro Carvalho Chehab (#) Calls use ACK packets to handle reliability. Data packets are also 1479f72374cSMauro Carvalho Chehab explicitly sequenced per call. 1489f72374cSMauro Carvalho Chehab 1499f72374cSMauro Carvalho Chehab (#) There are two types of positive acknowledgment: hard-ACKs and soft-ACKs. 1509f72374cSMauro Carvalho Chehab A hard-ACK indicates to the far side that all the data received to a point 1519f72374cSMauro Carvalho Chehab has been received and processed; a soft-ACK indicates that the data has 1529f72374cSMauro Carvalho Chehab been received but may yet be discarded and re-requested. The sender may 1539f72374cSMauro Carvalho Chehab not discard any transmittable packets until they've been hard-ACK'd. 1549f72374cSMauro Carvalho Chehab 1559f72374cSMauro Carvalho Chehab (#) Reception of a reply data packet implicitly hard-ACK's all the data 1569f72374cSMauro Carvalho Chehab packets that make up the request. 1579f72374cSMauro Carvalho Chehab 1589f72374cSMauro Carvalho Chehab (#) An call is complete when the request has been sent, the reply has been 1599f72374cSMauro Carvalho Chehab received and the final hard-ACK on the last packet of the reply has 1609f72374cSMauro Carvalho Chehab reached the server. 1619f72374cSMauro Carvalho Chehab 1629f72374cSMauro Carvalho Chehab (#) An call may be aborted by either end at any time up to its completion. 1639f72374cSMauro Carvalho Chehab 1649f72374cSMauro Carvalho Chehab 1659f72374cSMauro Carvalho ChehabAF_RXRPC Driver Model 1669f72374cSMauro Carvalho Chehab===================== 1679f72374cSMauro Carvalho Chehab 1689f72374cSMauro Carvalho ChehabAbout the AF_RXRPC driver: 1699f72374cSMauro Carvalho Chehab 1709f72374cSMauro Carvalho Chehab (#) The AF_RXRPC protocol transparently uses internal sockets of the transport 1719f72374cSMauro Carvalho Chehab protocol to represent transport endpoints. 1729f72374cSMauro Carvalho Chehab 1739f72374cSMauro Carvalho Chehab (#) AF_RXRPC sockets map onto RxRPC connection bundles. Actual RxRPC 1749f72374cSMauro Carvalho Chehab connections are handled transparently. One client socket may be used to 1759f72374cSMauro Carvalho Chehab make multiple simultaneous calls to the same service. One server socket 1769f72374cSMauro Carvalho Chehab may handle calls from many clients. 1779f72374cSMauro Carvalho Chehab 1789f72374cSMauro Carvalho Chehab (#) Additional parallel client connections will be initiated to support extra 1799f72374cSMauro Carvalho Chehab concurrent calls, up to a tunable limit. 1809f72374cSMauro Carvalho Chehab 1819f72374cSMauro Carvalho Chehab (#) Each connection is retained for a certain amount of time [tunable] after 1829f72374cSMauro Carvalho Chehab the last call currently using it has completed in case a new call is made 1839f72374cSMauro Carvalho Chehab that could reuse it. 1849f72374cSMauro Carvalho Chehab 1859f72374cSMauro Carvalho Chehab (#) Each internal UDP socket is retained [tunable] for a certain amount of 1869f72374cSMauro Carvalho Chehab time [tunable] after the last connection using it discarded, in case a new 1879f72374cSMauro Carvalho Chehab connection is made that could use it. 1889f72374cSMauro Carvalho Chehab 189e54ac95aSRandy Dunlap (#) A client-side connection is only shared between calls if they have 1909f72374cSMauro Carvalho Chehab the same key struct describing their security (and assuming the calls 1919f72374cSMauro Carvalho Chehab would otherwise share the connection). Non-secured calls would also be 1929f72374cSMauro Carvalho Chehab able to share connections with each other. 1939f72374cSMauro Carvalho Chehab 1949f72374cSMauro Carvalho Chehab (#) A server-side connection is shared if the client says it is. 1959f72374cSMauro Carvalho Chehab 1969f72374cSMauro Carvalho Chehab (#) ACK'ing is handled by the protocol driver automatically, including ping 1979f72374cSMauro Carvalho Chehab replying. 1989f72374cSMauro Carvalho Chehab 1999f72374cSMauro Carvalho Chehab (#) SO_KEEPALIVE automatically pings the other side to keep the connection 2009f72374cSMauro Carvalho Chehab alive [TODO]. 2019f72374cSMauro Carvalho Chehab 2029f72374cSMauro Carvalho Chehab (#) If an ICMP error is received, all calls affected by that error will be 2039f72374cSMauro Carvalho Chehab aborted with an appropriate network error passed through recvmsg(). 2049f72374cSMauro Carvalho Chehab 2059f72374cSMauro Carvalho Chehab 2069f72374cSMauro Carvalho ChehabInteraction with the user of the RxRPC socket: 2079f72374cSMauro Carvalho Chehab 2089f72374cSMauro Carvalho Chehab (#) A socket is made into a server socket by binding an address with a 2099f72374cSMauro Carvalho Chehab non-zero service ID. 2109f72374cSMauro Carvalho Chehab 2119f72374cSMauro Carvalho Chehab (#) In the client, sending a request is achieved with one or more sendmsgs, 2129f72374cSMauro Carvalho Chehab followed by the reply being received with one or more recvmsgs. 2139f72374cSMauro Carvalho Chehab 2149f72374cSMauro Carvalho Chehab (#) The first sendmsg for a request to be sent from a client contains a tag to 2159f72374cSMauro Carvalho Chehab be used in all other sendmsgs or recvmsgs associated with that call. The 2169f72374cSMauro Carvalho Chehab tag is carried in the control data. 2179f72374cSMauro Carvalho Chehab 2189f72374cSMauro Carvalho Chehab (#) connect() is used to supply a default destination address for a client 2199f72374cSMauro Carvalho Chehab socket. This may be overridden by supplying an alternate address to the 2209f72374cSMauro Carvalho Chehab first sendmsg() of a call (struct msghdr::msg_name). 2219f72374cSMauro Carvalho Chehab 2229f72374cSMauro Carvalho Chehab (#) If connect() is called on an unbound client, a random local port will 2239f72374cSMauro Carvalho Chehab bound before the operation takes place. 2249f72374cSMauro Carvalho Chehab 2259f72374cSMauro Carvalho Chehab (#) A server socket may also be used to make client calls. To do this, the 2269f72374cSMauro Carvalho Chehab first sendmsg() of the call must specify the target address. The server's 2279f72374cSMauro Carvalho Chehab transport endpoint is used to send the packets. 2289f72374cSMauro Carvalho Chehab 2299f72374cSMauro Carvalho Chehab (#) Once the application has received the last message associated with a call, 2309f72374cSMauro Carvalho Chehab the tag is guaranteed not to be seen again, and so it can be used to pin 2319f72374cSMauro Carvalho Chehab client resources. A new call can then be initiated with the same tag 2329f72374cSMauro Carvalho Chehab without fear of interference. 2339f72374cSMauro Carvalho Chehab 2349f72374cSMauro Carvalho Chehab (#) In the server, a request is received with one or more recvmsgs, then the 2359f72374cSMauro Carvalho Chehab the reply is transmitted with one or more sendmsgs, and then the final ACK 2369f72374cSMauro Carvalho Chehab is received with a last recvmsg. 2379f72374cSMauro Carvalho Chehab 2389f72374cSMauro Carvalho Chehab (#) When sending data for a call, sendmsg is given MSG_MORE if there's more 2399f72374cSMauro Carvalho Chehab data to come on that call. 2409f72374cSMauro Carvalho Chehab 2419f72374cSMauro Carvalho Chehab (#) When receiving data for a call, recvmsg flags MSG_MORE if there's more 2429f72374cSMauro Carvalho Chehab data to come for that call. 2439f72374cSMauro Carvalho Chehab 2449f72374cSMauro Carvalho Chehab (#) When receiving data or messages for a call, MSG_EOR is flagged by recvmsg 2459f72374cSMauro Carvalho Chehab to indicate the terminal message for that call. 2469f72374cSMauro Carvalho Chehab 2479f72374cSMauro Carvalho Chehab (#) A call may be aborted by adding an abort control message to the control 2489f72374cSMauro Carvalho Chehab data. Issuing an abort terminates the kernel's use of that call's tag. 2499f72374cSMauro Carvalho Chehab Any messages waiting in the receive queue for that call will be discarded. 2509f72374cSMauro Carvalho Chehab 2519f72374cSMauro Carvalho Chehab (#) Aborts, busy notifications and challenge packets are delivered by recvmsg, 2529f72374cSMauro Carvalho Chehab and control data messages will be set to indicate the context. Receiving 2539f72374cSMauro Carvalho Chehab an abort or a busy message terminates the kernel's use of that call's tag. 2549f72374cSMauro Carvalho Chehab 2559f72374cSMauro Carvalho Chehab (#) The control data part of the msghdr struct is used for a number of things: 2569f72374cSMauro Carvalho Chehab 2579f72374cSMauro Carvalho Chehab (#) The tag of the intended or affected call. 2589f72374cSMauro Carvalho Chehab 2599f72374cSMauro Carvalho Chehab (#) Sending or receiving errors, aborts and busy notifications. 2609f72374cSMauro Carvalho Chehab 2619f72374cSMauro Carvalho Chehab (#) Notifications of incoming calls. 2629f72374cSMauro Carvalho Chehab 2639f72374cSMauro Carvalho Chehab (#) Sending debug requests and receiving debug replies [TODO]. 2649f72374cSMauro Carvalho Chehab 2659f72374cSMauro Carvalho Chehab (#) When the kernel has received and set up an incoming call, it sends a 2669f72374cSMauro Carvalho Chehab message to server application to let it know there's a new call awaiting 2679f72374cSMauro Carvalho Chehab its acceptance [recvmsg reports a special control message]. The server 2689f72374cSMauro Carvalho Chehab application then uses sendmsg to assign a tag to the new call. Once that 2699f72374cSMauro Carvalho Chehab is done, the first part of the request data will be delivered by recvmsg. 2709f72374cSMauro Carvalho Chehab 2719f72374cSMauro Carvalho Chehab (#) The server application has to provide the server socket with a keyring of 2729f72374cSMauro Carvalho Chehab secret keys corresponding to the security types it permits. When a secure 2739f72374cSMauro Carvalho Chehab connection is being set up, the kernel looks up the appropriate secret key 2749f72374cSMauro Carvalho Chehab in the keyring and then sends a challenge packet to the client and 2759f72374cSMauro Carvalho Chehab receives a response packet. The kernel then checks the authorisation of 2769f72374cSMauro Carvalho Chehab the packet and either aborts the connection or sets up the security. 2779f72374cSMauro Carvalho Chehab 2789f72374cSMauro Carvalho Chehab (#) The name of the key a client will use to secure its communications is 2799f72374cSMauro Carvalho Chehab nominated by a socket option. 2809f72374cSMauro Carvalho Chehab 2819f72374cSMauro Carvalho Chehab 2829f72374cSMauro Carvalho ChehabNotes on sendmsg: 2839f72374cSMauro Carvalho Chehab 2849f72374cSMauro Carvalho Chehab (#) MSG_WAITALL can be set to tell sendmsg to ignore signals if the peer is 2859f72374cSMauro Carvalho Chehab making progress at accepting packets within a reasonable time such that we 2869f72374cSMauro Carvalho Chehab manage to queue up all the data for transmission. This requires the 2879f72374cSMauro Carvalho Chehab client to accept at least one packet per 2*RTT time period. 2889f72374cSMauro Carvalho Chehab 2899f72374cSMauro Carvalho Chehab If this isn't set, sendmsg() will return immediately, either returning 2909f72374cSMauro Carvalho Chehab EINTR/ERESTARTSYS if nothing was consumed or returning the amount of data 2919f72374cSMauro Carvalho Chehab consumed. 2929f72374cSMauro Carvalho Chehab 2939f72374cSMauro Carvalho Chehab 2949f72374cSMauro Carvalho ChehabNotes on recvmsg: 2959f72374cSMauro Carvalho Chehab 2969f72374cSMauro Carvalho Chehab (#) If there's a sequence of data messages belonging to a particular call on 2979f72374cSMauro Carvalho Chehab the receive queue, then recvmsg will keep working through them until: 2989f72374cSMauro Carvalho Chehab 2999f72374cSMauro Carvalho Chehab (a) it meets the end of that call's received data, 3009f72374cSMauro Carvalho Chehab 3019f72374cSMauro Carvalho Chehab (b) it meets a non-data message, 3029f72374cSMauro Carvalho Chehab 3039f72374cSMauro Carvalho Chehab (c) it meets a message belonging to a different call, or 3049f72374cSMauro Carvalho Chehab 3059f72374cSMauro Carvalho Chehab (d) it fills the user buffer. 3069f72374cSMauro Carvalho Chehab 3079f72374cSMauro Carvalho Chehab If recvmsg is called in blocking mode, it will keep sleeping, awaiting the 3089f72374cSMauro Carvalho Chehab reception of further data, until one of the above four conditions is met. 3099f72374cSMauro Carvalho Chehab 3109f72374cSMauro Carvalho Chehab (2) MSG_PEEK operates similarly, but will return immediately if it has put any 3119f72374cSMauro Carvalho Chehab data in the buffer rather than sleeping until it can fill the buffer. 3129f72374cSMauro Carvalho Chehab 3139f72374cSMauro Carvalho Chehab (3) If a data message is only partially consumed in filling a user buffer, 3149f72374cSMauro Carvalho Chehab then the remainder of that message will be left on the front of the queue 3159f72374cSMauro Carvalho Chehab for the next taker. MSG_TRUNC will never be flagged. 3169f72374cSMauro Carvalho Chehab 3179f72374cSMauro Carvalho Chehab (4) If there is more data to be had on a call (it hasn't copied the last byte 3189f72374cSMauro Carvalho Chehab of the last data message in that phase yet), then MSG_MORE will be 3199f72374cSMauro Carvalho Chehab flagged. 3209f72374cSMauro Carvalho Chehab 3219f72374cSMauro Carvalho Chehab 3229f72374cSMauro Carvalho ChehabControl Messages 3239f72374cSMauro Carvalho Chehab================ 3249f72374cSMauro Carvalho Chehab 3259f72374cSMauro Carvalho ChehabAF_RXRPC makes use of control messages in sendmsg() and recvmsg() to multiplex 3269f72374cSMauro Carvalho Chehabcalls, to invoke certain actions and to report certain conditions. These are: 3279f72374cSMauro Carvalho Chehab 3289f72374cSMauro Carvalho Chehab ======================= === =========== =============================== 3299f72374cSMauro Carvalho Chehab MESSAGE ID SRT DATA MEANING 3309f72374cSMauro Carvalho Chehab ======================= === =========== =============================== 3319f72374cSMauro Carvalho Chehab RXRPC_USER_CALL_ID sr- User ID App's call specifier 3329f72374cSMauro Carvalho Chehab RXRPC_ABORT srt Abort code Abort code to issue/received 3339f72374cSMauro Carvalho Chehab RXRPC_ACK -rt n/a Final ACK received 3349f72374cSMauro Carvalho Chehab RXRPC_NET_ERROR -rt error num Network error on call 3359f72374cSMauro Carvalho Chehab RXRPC_BUSY -rt n/a Call rejected (server busy) 3369f72374cSMauro Carvalho Chehab RXRPC_LOCAL_ERROR -rt error num Local error encountered 3379f72374cSMauro Carvalho Chehab RXRPC_NEW_CALL -r- n/a New call received 3389f72374cSMauro Carvalho Chehab RXRPC_ACCEPT s-- n/a Accept new call 3399f72374cSMauro Carvalho Chehab RXRPC_EXCLUSIVE_CALL s-- n/a Make an exclusive client call 3409f72374cSMauro Carvalho Chehab RXRPC_UPGRADE_SERVICE s-- n/a Client call can be upgraded 3419f72374cSMauro Carvalho Chehab RXRPC_TX_LENGTH s-- data len Total length of Tx data 3429f72374cSMauro Carvalho Chehab ======================= === =========== =============================== 3439f72374cSMauro Carvalho Chehab 3449f72374cSMauro Carvalho Chehab (SRT = usable in Sendmsg / delivered by Recvmsg / Terminal message) 3459f72374cSMauro Carvalho Chehab 3469f72374cSMauro Carvalho Chehab (#) RXRPC_USER_CALL_ID 3479f72374cSMauro Carvalho Chehab 3489f72374cSMauro Carvalho Chehab This is used to indicate the application's call ID. It's an unsigned long 3499f72374cSMauro Carvalho Chehab that the app specifies in the client by attaching it to the first data 3509f72374cSMauro Carvalho Chehab message or in the server by passing it in association with an RXRPC_ACCEPT 3519f72374cSMauro Carvalho Chehab message. recvmsg() passes it in conjunction with all messages except 3529f72374cSMauro Carvalho Chehab those of the RXRPC_NEW_CALL message. 3539f72374cSMauro Carvalho Chehab 3549f72374cSMauro Carvalho Chehab (#) RXRPC_ABORT 3559f72374cSMauro Carvalho Chehab 3569f72374cSMauro Carvalho Chehab This is can be used by an application to abort a call by passing it to 3579f72374cSMauro Carvalho Chehab sendmsg, or it can be delivered by recvmsg to indicate a remote abort was 3589f72374cSMauro Carvalho Chehab received. Either way, it must be associated with an RXRPC_USER_CALL_ID to 3599f72374cSMauro Carvalho Chehab specify the call affected. If an abort is being sent, then error EBADSLT 3609f72374cSMauro Carvalho Chehab will be returned if there is no call with that user ID. 3619f72374cSMauro Carvalho Chehab 3629f72374cSMauro Carvalho Chehab (#) RXRPC_ACK 3639f72374cSMauro Carvalho Chehab 3649f72374cSMauro Carvalho Chehab This is delivered to a server application to indicate that the final ACK 3659f72374cSMauro Carvalho Chehab of a call was received from the client. It will be associated with an 3669f72374cSMauro Carvalho Chehab RXRPC_USER_CALL_ID to indicate the call that's now complete. 3679f72374cSMauro Carvalho Chehab 3689f72374cSMauro Carvalho Chehab (#) RXRPC_NET_ERROR 3699f72374cSMauro Carvalho Chehab 3709f72374cSMauro Carvalho Chehab This is delivered to an application to indicate that an ICMP error message 3719f72374cSMauro Carvalho Chehab was encountered in the process of trying to talk to the peer. An 3729f72374cSMauro Carvalho Chehab errno-class integer value will be included in the control message data 3739f72374cSMauro Carvalho Chehab indicating the problem, and an RXRPC_USER_CALL_ID will indicate the call 3749f72374cSMauro Carvalho Chehab affected. 3759f72374cSMauro Carvalho Chehab 3769f72374cSMauro Carvalho Chehab (#) RXRPC_BUSY 3779f72374cSMauro Carvalho Chehab 3789f72374cSMauro Carvalho Chehab This is delivered to a client application to indicate that a call was 3799f72374cSMauro Carvalho Chehab rejected by the server due to the server being busy. It will be 3809f72374cSMauro Carvalho Chehab associated with an RXRPC_USER_CALL_ID to indicate the rejected call. 3819f72374cSMauro Carvalho Chehab 3829f72374cSMauro Carvalho Chehab (#) RXRPC_LOCAL_ERROR 3839f72374cSMauro Carvalho Chehab 3849f72374cSMauro Carvalho Chehab This is delivered to an application to indicate that a local error was 3859f72374cSMauro Carvalho Chehab encountered and that a call has been aborted because of it. An 3869f72374cSMauro Carvalho Chehab errno-class integer value will be included in the control message data 3879f72374cSMauro Carvalho Chehab indicating the problem, and an RXRPC_USER_CALL_ID will indicate the call 3889f72374cSMauro Carvalho Chehab affected. 3899f72374cSMauro Carvalho Chehab 3909f72374cSMauro Carvalho Chehab (#) RXRPC_NEW_CALL 3919f72374cSMauro Carvalho Chehab 3929f72374cSMauro Carvalho Chehab This is delivered to indicate to a server application that a new call has 3939f72374cSMauro Carvalho Chehab arrived and is awaiting acceptance. No user ID is associated with this, 3949f72374cSMauro Carvalho Chehab as a user ID must subsequently be assigned by doing an RXRPC_ACCEPT. 3959f72374cSMauro Carvalho Chehab 3969f72374cSMauro Carvalho Chehab (#) RXRPC_ACCEPT 3979f72374cSMauro Carvalho Chehab 3989f72374cSMauro Carvalho Chehab This is used by a server application to attempt to accept a call and 3999f72374cSMauro Carvalho Chehab assign it a user ID. It should be associated with an RXRPC_USER_CALL_ID 4009f72374cSMauro Carvalho Chehab to indicate the user ID to be assigned. If there is no call to be 4019f72374cSMauro Carvalho Chehab accepted (it may have timed out, been aborted, etc.), then sendmsg will 4029f72374cSMauro Carvalho Chehab return error ENODATA. If the user ID is already in use by another call, 4039f72374cSMauro Carvalho Chehab then error EBADSLT will be returned. 4049f72374cSMauro Carvalho Chehab 4059f72374cSMauro Carvalho Chehab (#) RXRPC_EXCLUSIVE_CALL 4069f72374cSMauro Carvalho Chehab 4079f72374cSMauro Carvalho Chehab This is used to indicate that a client call should be made on a one-off 4089f72374cSMauro Carvalho Chehab connection. The connection is discarded once the call has terminated. 4099f72374cSMauro Carvalho Chehab 4109f72374cSMauro Carvalho Chehab (#) RXRPC_UPGRADE_SERVICE 4119f72374cSMauro Carvalho Chehab 4129f72374cSMauro Carvalho Chehab This is used to make a client call to probe if the specified service ID 4139f72374cSMauro Carvalho Chehab may be upgraded by the server. The caller must check msg_name returned to 4149f72374cSMauro Carvalho Chehab recvmsg() for the service ID actually in use. The operation probed must 4159f72374cSMauro Carvalho Chehab be one that takes the same arguments in both services. 4169f72374cSMauro Carvalho Chehab 4179f72374cSMauro Carvalho Chehab Once this has been used to establish the upgrade capability (or lack 4189f72374cSMauro Carvalho Chehab thereof) of the server, the service ID returned should be used for all 4199f72374cSMauro Carvalho Chehab future communication to that server and RXRPC_UPGRADE_SERVICE should no 4209f72374cSMauro Carvalho Chehab longer be set. 4219f72374cSMauro Carvalho Chehab 4229f72374cSMauro Carvalho Chehab (#) RXRPC_TX_LENGTH 4239f72374cSMauro Carvalho Chehab 4249f72374cSMauro Carvalho Chehab This is used to inform the kernel of the total amount of data that is 4259f72374cSMauro Carvalho Chehab going to be transmitted by a call (whether in a client request or a 4269f72374cSMauro Carvalho Chehab service response). If given, it allows the kernel to encrypt from the 4279f72374cSMauro Carvalho Chehab userspace buffer directly to the packet buffers, rather than copying into 4289f72374cSMauro Carvalho Chehab the buffer and then encrypting in place. This may only be given with the 4299f72374cSMauro Carvalho Chehab first sendmsg() providing data for a call. EMSGSIZE will be generated if 4309f72374cSMauro Carvalho Chehab the amount of data actually given is different. 4319f72374cSMauro Carvalho Chehab 4329f72374cSMauro Carvalho Chehab This takes a parameter of __s64 type that indicates how much will be 4339f72374cSMauro Carvalho Chehab transmitted. This may not be less than zero. 4349f72374cSMauro Carvalho Chehab 4359f72374cSMauro Carvalho ChehabThe symbol RXRPC__SUPPORTED is defined as one more than the highest control 4369f72374cSMauro Carvalho Chehabmessage type supported. At run time this can be queried by means of the 4379f72374cSMauro Carvalho ChehabRXRPC_SUPPORTED_CMSG socket option (see below). 4389f72374cSMauro Carvalho Chehab 4399f72374cSMauro Carvalho Chehab 4409f72374cSMauro Carvalho Chehab============== 4419f72374cSMauro Carvalho ChehabSOCKET OPTIONS 4429f72374cSMauro Carvalho Chehab============== 4439f72374cSMauro Carvalho Chehab 4449f72374cSMauro Carvalho ChehabAF_RXRPC sockets support a few socket options at the SOL_RXRPC level: 4459f72374cSMauro Carvalho Chehab 4469f72374cSMauro Carvalho Chehab (#) RXRPC_SECURITY_KEY 4479f72374cSMauro Carvalho Chehab 4489f72374cSMauro Carvalho Chehab This is used to specify the description of the key to be used. The key is 4499f72374cSMauro Carvalho Chehab extracted from the calling process's keyrings with request_key() and 4509f72374cSMauro Carvalho Chehab should be of "rxrpc" type. 4519f72374cSMauro Carvalho Chehab 4529f72374cSMauro Carvalho Chehab The optval pointer points to the description string, and optlen indicates 4539f72374cSMauro Carvalho Chehab how long the string is, without the NUL terminator. 4549f72374cSMauro Carvalho Chehab 4559f72374cSMauro Carvalho Chehab (#) RXRPC_SECURITY_KEYRING 4569f72374cSMauro Carvalho Chehab 4579f72374cSMauro Carvalho Chehab Similar to above but specifies a keyring of server secret keys to use (key 4589f72374cSMauro Carvalho Chehab type "keyring"). See the "Security" section. 4599f72374cSMauro Carvalho Chehab 4609f72374cSMauro Carvalho Chehab (#) RXRPC_EXCLUSIVE_CONNECTION 4619f72374cSMauro Carvalho Chehab 4629f72374cSMauro Carvalho Chehab This is used to request that new connections should be used for each call 4639f72374cSMauro Carvalho Chehab made subsequently on this socket. optval should be NULL and optlen 0. 4649f72374cSMauro Carvalho Chehab 4659f72374cSMauro Carvalho Chehab (#) RXRPC_MIN_SECURITY_LEVEL 4669f72374cSMauro Carvalho Chehab 4679f72374cSMauro Carvalho Chehab This is used to specify the minimum security level required for calls on 4689f72374cSMauro Carvalho Chehab this socket. optval must point to an int containing one of the following 4699f72374cSMauro Carvalho Chehab values: 4709f72374cSMauro Carvalho Chehab 4719f72374cSMauro Carvalho Chehab (a) RXRPC_SECURITY_PLAIN 4729f72374cSMauro Carvalho Chehab 4739f72374cSMauro Carvalho Chehab Encrypted checksum only. 4749f72374cSMauro Carvalho Chehab 4759f72374cSMauro Carvalho Chehab (b) RXRPC_SECURITY_AUTH 4769f72374cSMauro Carvalho Chehab 4779f72374cSMauro Carvalho Chehab Encrypted checksum plus packet padded and first eight bytes of packet 4789f72374cSMauro Carvalho Chehab encrypted - which includes the actual packet length. 4799f72374cSMauro Carvalho Chehab 480298cd88aSChristoph Hellwig (c) RXRPC_SECURITY_ENCRYPT 4819f72374cSMauro Carvalho Chehab 4829f72374cSMauro Carvalho Chehab Encrypted checksum plus entire packet padded and encrypted, including 4839f72374cSMauro Carvalho Chehab actual packet length. 4849f72374cSMauro Carvalho Chehab 4859f72374cSMauro Carvalho Chehab (#) RXRPC_UPGRADEABLE_SERVICE 4869f72374cSMauro Carvalho Chehab 4879f72374cSMauro Carvalho Chehab This is used to indicate that a service socket with two bindings may 4889f72374cSMauro Carvalho Chehab upgrade one bound service to the other if requested by the client. optval 4899f72374cSMauro Carvalho Chehab must point to an array of two unsigned short ints. The first is the 4909f72374cSMauro Carvalho Chehab service ID to upgrade from and the second the service ID to upgrade to. 4919f72374cSMauro Carvalho Chehab 4929f72374cSMauro Carvalho Chehab (#) RXRPC_SUPPORTED_CMSG 4939f72374cSMauro Carvalho Chehab 4949f72374cSMauro Carvalho Chehab This is a read-only option that writes an int into the buffer indicating 4959f72374cSMauro Carvalho Chehab the highest control message type supported. 4969f72374cSMauro Carvalho Chehab 4979f72374cSMauro Carvalho Chehab 4989f72374cSMauro Carvalho Chehab======== 4999f72374cSMauro Carvalho ChehabSECURITY 5009f72374cSMauro Carvalho Chehab======== 5019f72374cSMauro Carvalho Chehab 5029f72374cSMauro Carvalho ChehabCurrently, only the kerberos 4 equivalent protocol has been implemented 5039f72374cSMauro Carvalho Chehab(security index 2 - rxkad). This requires the rxkad module to be loaded and, 5049f72374cSMauro Carvalho Chehabon the client, tickets of the appropriate type to be obtained from the AFS 5059f72374cSMauro Carvalho Chehabkaserver or the kerberos server and installed as "rxrpc" type keys. This is 5069f72374cSMauro Carvalho Chehabnormally done using the klog program. An example simple klog program can be 5079f72374cSMauro Carvalho Chehabfound at: 5089f72374cSMauro Carvalho Chehab 5099f72374cSMauro Carvalho Chehab http://people.redhat.com/~dhowells/rxrpc/klog.c 5109f72374cSMauro Carvalho Chehab 5119f72374cSMauro Carvalho ChehabThe payload provided to add_key() on the client should be of the following 5129f72374cSMauro Carvalho Chehabform:: 5139f72374cSMauro Carvalho Chehab 5149f72374cSMauro Carvalho Chehab struct rxrpc_key_sec2_v1 { 5159f72374cSMauro Carvalho Chehab uint16_t security_index; /* 2 */ 5169f72374cSMauro Carvalho Chehab uint16_t ticket_length; /* length of ticket[] */ 5179f72374cSMauro Carvalho Chehab uint32_t expiry; /* time at which expires */ 5189f72374cSMauro Carvalho Chehab uint8_t kvno; /* key version number */ 5199f72374cSMauro Carvalho Chehab uint8_t __pad[3]; 5209f72374cSMauro Carvalho Chehab uint8_t session_key[8]; /* DES session key */ 5219f72374cSMauro Carvalho Chehab uint8_t ticket[0]; /* the encrypted ticket */ 5229f72374cSMauro Carvalho Chehab }; 5239f72374cSMauro Carvalho Chehab 5249f72374cSMauro Carvalho ChehabWhere the ticket blob is just appended to the above structure. 5259f72374cSMauro Carvalho Chehab 5269f72374cSMauro Carvalho Chehab 5279f72374cSMauro Carvalho ChehabFor the server, keys of type "rxrpc_s" must be made available to the server. 5289f72374cSMauro Carvalho ChehabThey have a description of "<serviceID>:<securityIndex>" (eg: "52:2" for an 5299f72374cSMauro Carvalho Chehabrxkad key for the AFS VL service). When such a key is created, it should be 5309f72374cSMauro Carvalho Chehabgiven the server's secret key as the instantiation data (see the example 5319f72374cSMauro Carvalho Chehabbelow). 5329f72374cSMauro Carvalho Chehab 5339f72374cSMauro Carvalho Chehab add_key("rxrpc_s", "52:2", secret_key, 8, keyring); 5349f72374cSMauro Carvalho Chehab 5359f72374cSMauro Carvalho ChehabA keyring is passed to the server socket by naming it in a sockopt. The server 5369f72374cSMauro Carvalho Chehabsocket then looks the server secret keys up in this keyring when secure 5379f72374cSMauro Carvalho Chehabincoming connections are made. This can be seen in an example program that can 5389f72374cSMauro Carvalho Chehabbe found at: 5399f72374cSMauro Carvalho Chehab 5409f72374cSMauro Carvalho Chehab http://people.redhat.com/~dhowells/rxrpc/listen.c 5419f72374cSMauro Carvalho Chehab 5429f72374cSMauro Carvalho Chehab 5439f72374cSMauro Carvalho Chehab==================== 5449f72374cSMauro Carvalho ChehabEXAMPLE CLIENT USAGE 5459f72374cSMauro Carvalho Chehab==================== 5469f72374cSMauro Carvalho Chehab 5479f72374cSMauro Carvalho ChehabA client would issue an operation by: 5489f72374cSMauro Carvalho Chehab 5499f72374cSMauro Carvalho Chehab (1) An RxRPC socket is set up by:: 5509f72374cSMauro Carvalho Chehab 5519f72374cSMauro Carvalho Chehab client = socket(AF_RXRPC, SOCK_DGRAM, PF_INET); 5529f72374cSMauro Carvalho Chehab 5539f72374cSMauro Carvalho Chehab Where the third parameter indicates the protocol family of the transport 5549f72374cSMauro Carvalho Chehab socket used - usually IPv4 but it can also be IPv6 [TODO]. 5559f72374cSMauro Carvalho Chehab 5569f72374cSMauro Carvalho Chehab (2) A local address can optionally be bound:: 5579f72374cSMauro Carvalho Chehab 5589f72374cSMauro Carvalho Chehab struct sockaddr_rxrpc srx = { 5599f72374cSMauro Carvalho Chehab .srx_family = AF_RXRPC, 5609f72374cSMauro Carvalho Chehab .srx_service = 0, /* we're a client */ 5619f72374cSMauro Carvalho Chehab .transport_type = SOCK_DGRAM, /* type of transport socket */ 5629f72374cSMauro Carvalho Chehab .transport.sin_family = AF_INET, 5639f72374cSMauro Carvalho Chehab .transport.sin_port = htons(7000), /* AFS callback */ 5649f72374cSMauro Carvalho Chehab .transport.sin_address = 0, /* all local interfaces */ 5659f72374cSMauro Carvalho Chehab }; 5669f72374cSMauro Carvalho Chehab bind(client, &srx, sizeof(srx)); 5679f72374cSMauro Carvalho Chehab 5689f72374cSMauro Carvalho Chehab This specifies the local UDP port to be used. If not given, a random 5699f72374cSMauro Carvalho Chehab non-privileged port will be used. A UDP port may be shared between 5709f72374cSMauro Carvalho Chehab several unrelated RxRPC sockets. Security is handled on a basis of 5719f72374cSMauro Carvalho Chehab per-RxRPC virtual connection. 5729f72374cSMauro Carvalho Chehab 5739f72374cSMauro Carvalho Chehab (3) The security is set:: 5749f72374cSMauro Carvalho Chehab 5759f72374cSMauro Carvalho Chehab const char *key = "AFS:cambridge.redhat.com"; 5769f72374cSMauro Carvalho Chehab setsockopt(client, SOL_RXRPC, RXRPC_SECURITY_KEY, key, strlen(key)); 5779f72374cSMauro Carvalho Chehab 5789f72374cSMauro Carvalho Chehab This issues a request_key() to get the key representing the security 5799f72374cSMauro Carvalho Chehab context. The minimum security level can be set:: 5809f72374cSMauro Carvalho Chehab 581298cd88aSChristoph Hellwig unsigned int sec = RXRPC_SECURITY_ENCRYPT; 5829f72374cSMauro Carvalho Chehab setsockopt(client, SOL_RXRPC, RXRPC_MIN_SECURITY_LEVEL, 5839f72374cSMauro Carvalho Chehab &sec, sizeof(sec)); 5849f72374cSMauro Carvalho Chehab 5859f72374cSMauro Carvalho Chehab (4) The server to be contacted can then be specified (alternatively this can 5869f72374cSMauro Carvalho Chehab be done through sendmsg):: 5879f72374cSMauro Carvalho Chehab 5889f72374cSMauro Carvalho Chehab struct sockaddr_rxrpc srx = { 5899f72374cSMauro Carvalho Chehab .srx_family = AF_RXRPC, 5909f72374cSMauro Carvalho Chehab .srx_service = VL_SERVICE_ID, 5919f72374cSMauro Carvalho Chehab .transport_type = SOCK_DGRAM, /* type of transport socket */ 5929f72374cSMauro Carvalho Chehab .transport.sin_family = AF_INET, 5939f72374cSMauro Carvalho Chehab .transport.sin_port = htons(7005), /* AFS volume manager */ 5949f72374cSMauro Carvalho Chehab .transport.sin_address = ..., 5959f72374cSMauro Carvalho Chehab }; 5969f72374cSMauro Carvalho Chehab connect(client, &srx, sizeof(srx)); 5979f72374cSMauro Carvalho Chehab 5989f72374cSMauro Carvalho Chehab (5) The request data should then be posted to the server socket using a series 5999f72374cSMauro Carvalho Chehab of sendmsg() calls, each with the following control message attached: 6009f72374cSMauro Carvalho Chehab 6019f72374cSMauro Carvalho Chehab ================== =================================== 6029f72374cSMauro Carvalho Chehab RXRPC_USER_CALL_ID specifies the user ID for this call 6039f72374cSMauro Carvalho Chehab ================== =================================== 6049f72374cSMauro Carvalho Chehab 6059f72374cSMauro Carvalho Chehab MSG_MORE should be set in msghdr::msg_flags on all but the last part of 6069f72374cSMauro Carvalho Chehab the request. Multiple requests may be made simultaneously. 6079f72374cSMauro Carvalho Chehab 6089f72374cSMauro Carvalho Chehab An RXRPC_TX_LENGTH control message can also be specified on the first 6099f72374cSMauro Carvalho Chehab sendmsg() call. 6109f72374cSMauro Carvalho Chehab 6119f72374cSMauro Carvalho Chehab If a call is intended to go to a destination other than the default 6129f72374cSMauro Carvalho Chehab specified through connect(), then msghdr::msg_name should be set on the 6139f72374cSMauro Carvalho Chehab first request message of that call. 6149f72374cSMauro Carvalho Chehab 6159f72374cSMauro Carvalho Chehab (6) The reply data will then be posted to the server socket for recvmsg() to 6169f72374cSMauro Carvalho Chehab pick up. MSG_MORE will be flagged by recvmsg() if there's more reply data 6179f72374cSMauro Carvalho Chehab for a particular call to be read. MSG_EOR will be set on the terminal 6189f72374cSMauro Carvalho Chehab read for a call. 6199f72374cSMauro Carvalho Chehab 6209f72374cSMauro Carvalho Chehab All data will be delivered with the following control message attached: 6219f72374cSMauro Carvalho Chehab 6229f72374cSMauro Carvalho Chehab RXRPC_USER_CALL_ID - specifies the user ID for this call 6239f72374cSMauro Carvalho Chehab 6249f72374cSMauro Carvalho Chehab If an abort or error occurred, this will be returned in the control data 6259f72374cSMauro Carvalho Chehab buffer instead, and MSG_EOR will be flagged to indicate the end of that 6269f72374cSMauro Carvalho Chehab call. 6279f72374cSMauro Carvalho Chehab 6289f72374cSMauro Carvalho ChehabA client may ask for a service ID it knows and ask that this be upgraded to a 6299f72374cSMauro Carvalho Chehabbetter service if one is available by supplying RXRPC_UPGRADE_SERVICE on the 6309f72374cSMauro Carvalho Chehabfirst sendmsg() of a call. The client should then check srx_service in the 6319f72374cSMauro Carvalho Chehabmsg_name filled in by recvmsg() when collecting the result. srx_service will 6329f72374cSMauro Carvalho Chehabhold the same value as given to sendmsg() if the upgrade request was ignored by 6339f72374cSMauro Carvalho Chehabthe service - otherwise it will be altered to indicate the service ID the 6349f72374cSMauro Carvalho Chehabserver upgraded to. Note that the upgraded service ID is chosen by the server. 6359f72374cSMauro Carvalho ChehabThe caller has to wait until it sees the service ID in the reply before sending 6369f72374cSMauro Carvalho Chehabany more calls (further calls to the same destination will be blocked until the 6379f72374cSMauro Carvalho Chehabprobe is concluded). 6389f72374cSMauro Carvalho Chehab 6399f72374cSMauro Carvalho Chehab 6409f72374cSMauro Carvalho ChehabExample Server Usage 6419f72374cSMauro Carvalho Chehab==================== 6429f72374cSMauro Carvalho Chehab 6439f72374cSMauro Carvalho ChehabA server would be set up to accept operations in the following manner: 6449f72374cSMauro Carvalho Chehab 6459f72374cSMauro Carvalho Chehab (1) An RxRPC socket is created by:: 6469f72374cSMauro Carvalho Chehab 6479f72374cSMauro Carvalho Chehab server = socket(AF_RXRPC, SOCK_DGRAM, PF_INET); 6489f72374cSMauro Carvalho Chehab 6499f72374cSMauro Carvalho Chehab Where the third parameter indicates the address type of the transport 6509f72374cSMauro Carvalho Chehab socket used - usually IPv4. 6519f72374cSMauro Carvalho Chehab 6529f72374cSMauro Carvalho Chehab (2) Security is set up if desired by giving the socket a keyring with server 6539f72374cSMauro Carvalho Chehab secret keys in it:: 6549f72374cSMauro Carvalho Chehab 6559f72374cSMauro Carvalho Chehab keyring = add_key("keyring", "AFSkeys", NULL, 0, 6569f72374cSMauro Carvalho Chehab KEY_SPEC_PROCESS_KEYRING); 6579f72374cSMauro Carvalho Chehab 6589f72374cSMauro Carvalho Chehab const char secret_key[8] = { 6599f72374cSMauro Carvalho Chehab 0xa7, 0x83, 0x8a, 0xcb, 0xc7, 0x83, 0xec, 0x94 }; 6609f72374cSMauro Carvalho Chehab add_key("rxrpc_s", "52:2", secret_key, 8, keyring); 6619f72374cSMauro Carvalho Chehab 6629f72374cSMauro Carvalho Chehab setsockopt(server, SOL_RXRPC, RXRPC_SECURITY_KEYRING, "AFSkeys", 7); 6639f72374cSMauro Carvalho Chehab 6649f72374cSMauro Carvalho Chehab The keyring can be manipulated after it has been given to the socket. This 6659f72374cSMauro Carvalho Chehab permits the server to add more keys, replace keys, etc. while it is live. 6669f72374cSMauro Carvalho Chehab 6679f72374cSMauro Carvalho Chehab (3) A local address must then be bound:: 6689f72374cSMauro Carvalho Chehab 6699f72374cSMauro Carvalho Chehab struct sockaddr_rxrpc srx = { 6709f72374cSMauro Carvalho Chehab .srx_family = AF_RXRPC, 6719f72374cSMauro Carvalho Chehab .srx_service = VL_SERVICE_ID, /* RxRPC service ID */ 6729f72374cSMauro Carvalho Chehab .transport_type = SOCK_DGRAM, /* type of transport socket */ 6739f72374cSMauro Carvalho Chehab .transport.sin_family = AF_INET, 6749f72374cSMauro Carvalho Chehab .transport.sin_port = htons(7000), /* AFS callback */ 6759f72374cSMauro Carvalho Chehab .transport.sin_address = 0, /* all local interfaces */ 6769f72374cSMauro Carvalho Chehab }; 6779f72374cSMauro Carvalho Chehab bind(server, &srx, sizeof(srx)); 6789f72374cSMauro Carvalho Chehab 6799f72374cSMauro Carvalho Chehab More than one service ID may be bound to a socket, provided the transport 6809f72374cSMauro Carvalho Chehab parameters are the same. The limit is currently two. To do this, bind() 6819f72374cSMauro Carvalho Chehab should be called twice. 6829f72374cSMauro Carvalho Chehab 6839f72374cSMauro Carvalho Chehab (4) If service upgrading is required, first two service IDs must have been 6849f72374cSMauro Carvalho Chehab bound and then the following option must be set:: 6859f72374cSMauro Carvalho Chehab 6869f72374cSMauro Carvalho Chehab unsigned short service_ids[2] = { from_ID, to_ID }; 6879f72374cSMauro Carvalho Chehab setsockopt(server, SOL_RXRPC, RXRPC_UPGRADEABLE_SERVICE, 6889f72374cSMauro Carvalho Chehab service_ids, sizeof(service_ids)); 6899f72374cSMauro Carvalho Chehab 6909f72374cSMauro Carvalho Chehab This will automatically upgrade connections on service from_ID to service 6919f72374cSMauro Carvalho Chehab to_ID if they request it. This will be reflected in msg_name obtained 6929f72374cSMauro Carvalho Chehab through recvmsg() when the request data is delivered to userspace. 6939f72374cSMauro Carvalho Chehab 6949f72374cSMauro Carvalho Chehab (5) The server is then set to listen out for incoming calls:: 6959f72374cSMauro Carvalho Chehab 6969f72374cSMauro Carvalho Chehab listen(server, 100); 6979f72374cSMauro Carvalho Chehab 6989f72374cSMauro Carvalho Chehab (6) The kernel notifies the server of pending incoming connections by sending 6999f72374cSMauro Carvalho Chehab it a message for each. This is received with recvmsg() on the server 7009f72374cSMauro Carvalho Chehab socket. It has no data, and has a single dataless control message 7019f72374cSMauro Carvalho Chehab attached:: 7029f72374cSMauro Carvalho Chehab 7039f72374cSMauro Carvalho Chehab RXRPC_NEW_CALL 7049f72374cSMauro Carvalho Chehab 7059f72374cSMauro Carvalho Chehab The address that can be passed back by recvmsg() at this point should be 7069f72374cSMauro Carvalho Chehab ignored since the call for which the message was posted may have gone by 7079f72374cSMauro Carvalho Chehab the time it is accepted - in which case the first call still on the queue 7089f72374cSMauro Carvalho Chehab will be accepted. 7099f72374cSMauro Carvalho Chehab 7109f72374cSMauro Carvalho Chehab (7) The server then accepts the new call by issuing a sendmsg() with two 7119f72374cSMauro Carvalho Chehab pieces of control data and no actual data: 7129f72374cSMauro Carvalho Chehab 7139f72374cSMauro Carvalho Chehab ================== ============================== 7149f72374cSMauro Carvalho Chehab RXRPC_ACCEPT indicate connection acceptance 7159f72374cSMauro Carvalho Chehab RXRPC_USER_CALL_ID specify user ID for this call 7169f72374cSMauro Carvalho Chehab ================== ============================== 7179f72374cSMauro Carvalho Chehab 7189f72374cSMauro Carvalho Chehab (8) The first request data packet will then be posted to the server socket for 7199f72374cSMauro Carvalho Chehab recvmsg() to pick up. At that point, the RxRPC address for the call can 7209f72374cSMauro Carvalho Chehab be read from the address fields in the msghdr struct. 7219f72374cSMauro Carvalho Chehab 7229f72374cSMauro Carvalho Chehab Subsequent request data will be posted to the server socket for recvmsg() 7239f72374cSMauro Carvalho Chehab to collect as it arrives. All but the last piece of the request data will 7249f72374cSMauro Carvalho Chehab be delivered with MSG_MORE flagged. 7259f72374cSMauro Carvalho Chehab 7269f72374cSMauro Carvalho Chehab All data will be delivered with the following control message attached: 7279f72374cSMauro Carvalho Chehab 7289f72374cSMauro Carvalho Chehab 7299f72374cSMauro Carvalho Chehab ================== =================================== 7309f72374cSMauro Carvalho Chehab RXRPC_USER_CALL_ID specifies the user ID for this call 7319f72374cSMauro Carvalho Chehab ================== =================================== 7329f72374cSMauro Carvalho Chehab 7339f72374cSMauro Carvalho Chehab (9) The reply data should then be posted to the server socket using a series 7349f72374cSMauro Carvalho Chehab of sendmsg() calls, each with the following control messages attached: 7359f72374cSMauro Carvalho Chehab 7369f72374cSMauro Carvalho Chehab ================== =================================== 7379f72374cSMauro Carvalho Chehab RXRPC_USER_CALL_ID specifies the user ID for this call 7389f72374cSMauro Carvalho Chehab ================== =================================== 7399f72374cSMauro Carvalho Chehab 7409f72374cSMauro Carvalho Chehab MSG_MORE should be set in msghdr::msg_flags on all but the last message 7419f72374cSMauro Carvalho Chehab for a particular call. 7429f72374cSMauro Carvalho Chehab 7439f72374cSMauro Carvalho Chehab(10) The final ACK from the client will be posted for retrieval by recvmsg() 7449f72374cSMauro Carvalho Chehab when it is received. It will take the form of a dataless message with two 7459f72374cSMauro Carvalho Chehab control messages attached: 7469f72374cSMauro Carvalho Chehab 7479f72374cSMauro Carvalho Chehab ================== =================================== 7489f72374cSMauro Carvalho Chehab RXRPC_USER_CALL_ID specifies the user ID for this call 7499f72374cSMauro Carvalho Chehab RXRPC_ACK indicates final ACK (no data) 7509f72374cSMauro Carvalho Chehab ================== =================================== 7519f72374cSMauro Carvalho Chehab 7529f72374cSMauro Carvalho Chehab MSG_EOR will be flagged to indicate that this is the final message for 7539f72374cSMauro Carvalho Chehab this call. 7549f72374cSMauro Carvalho Chehab 7559f72374cSMauro Carvalho Chehab(11) Up to the point the final packet of reply data is sent, the call can be 7569f72374cSMauro Carvalho Chehab aborted by calling sendmsg() with a dataless message with the following 7579f72374cSMauro Carvalho Chehab control messages attached: 7589f72374cSMauro Carvalho Chehab 7599f72374cSMauro Carvalho Chehab ================== =================================== 7609f72374cSMauro Carvalho Chehab RXRPC_USER_CALL_ID specifies the user ID for this call 7619f72374cSMauro Carvalho Chehab RXRPC_ABORT indicates abort code (4 byte data) 7629f72374cSMauro Carvalho Chehab ================== =================================== 7639f72374cSMauro Carvalho Chehab 7649f72374cSMauro Carvalho Chehab Any packets waiting in the socket's receive queue will be discarded if 7659f72374cSMauro Carvalho Chehab this is issued. 7669f72374cSMauro Carvalho Chehab 7679f72374cSMauro Carvalho ChehabNote that all the communications for a particular service take place through 7689f72374cSMauro Carvalho Chehabthe one server socket, using control messages on sendmsg() and recvmsg() to 7699f72374cSMauro Carvalho Chehabdetermine the call affected. 7709f72374cSMauro Carvalho Chehab 7719f72374cSMauro Carvalho Chehab 7729f72374cSMauro Carvalho ChehabAF_RXRPC Kernel Interface 7739f72374cSMauro Carvalho Chehab========================= 7749f72374cSMauro Carvalho Chehab 7759f72374cSMauro Carvalho ChehabThe AF_RXRPC module also provides an interface for use by in-kernel utilities 7769f72374cSMauro Carvalho Chehabsuch as the AFS filesystem. This permits such a utility to: 7779f72374cSMauro Carvalho Chehab 7789f72374cSMauro Carvalho Chehab (1) Use different keys directly on individual client calls on one socket 7799f72374cSMauro Carvalho Chehab rather than having to open a whole slew of sockets, one for each key it 7809f72374cSMauro Carvalho Chehab might want to use. 7819f72374cSMauro Carvalho Chehab 7829f72374cSMauro Carvalho Chehab (2) Avoid having RxRPC call request_key() at the point of issue of a call or 7839f72374cSMauro Carvalho Chehab opening of a socket. Instead the utility is responsible for requesting a 7849f72374cSMauro Carvalho Chehab key at the appropriate point. AFS, for instance, would do this during VFS 7859f72374cSMauro Carvalho Chehab operations such as open() or unlink(). The key is then handed through 7869f72374cSMauro Carvalho Chehab when the call is initiated. 7879f72374cSMauro Carvalho Chehab 7889f72374cSMauro Carvalho Chehab (3) Request the use of something other than GFP_KERNEL to allocate memory. 7899f72374cSMauro Carvalho Chehab 7909f72374cSMauro Carvalho Chehab (4) Avoid the overhead of using the recvmsg() call. RxRPC messages can be 7919f72374cSMauro Carvalho Chehab intercepted before they get put into the socket Rx queue and the socket 7929f72374cSMauro Carvalho Chehab buffers manipulated directly. 7939f72374cSMauro Carvalho Chehab 7949f72374cSMauro Carvalho ChehabTo use the RxRPC facility, a kernel utility must still open an AF_RXRPC socket, 7959f72374cSMauro Carvalho Chehabbind an address as appropriate and listen if it's to be a server socket, but 7969f72374cSMauro Carvalho Chehabthen it passes this to the kernel interface functions. 7979f72374cSMauro Carvalho Chehab 7989f72374cSMauro Carvalho ChehabThe kernel interface functions are as follows: 7999f72374cSMauro Carvalho Chehab 8009f72374cSMauro Carvalho Chehab (#) Begin a new client call:: 8019f72374cSMauro Carvalho Chehab 8029f72374cSMauro Carvalho Chehab struct rxrpc_call * 8039f72374cSMauro Carvalho Chehab rxrpc_kernel_begin_call(struct socket *sock, 8049f72374cSMauro Carvalho Chehab struct sockaddr_rxrpc *srx, 8059f72374cSMauro Carvalho Chehab struct key *key, 8069f72374cSMauro Carvalho Chehab unsigned long user_call_ID, 8079f72374cSMauro Carvalho Chehab s64 tx_total_len, 8089f72374cSMauro Carvalho Chehab gfp_t gfp, 8099f72374cSMauro Carvalho Chehab rxrpc_notify_rx_t notify_rx, 8109f72374cSMauro Carvalho Chehab bool upgrade, 8119f72374cSMauro Carvalho Chehab bool intr, 8129f72374cSMauro Carvalho Chehab unsigned int debug_id); 8139f72374cSMauro Carvalho Chehab 8149f72374cSMauro Carvalho Chehab This allocates the infrastructure to make a new RxRPC call and assigns 8159f72374cSMauro Carvalho Chehab call and connection numbers. The call will be made on the UDP port that 8169f72374cSMauro Carvalho Chehab the socket is bound to. The call will go to the destination address of a 8179f72374cSMauro Carvalho Chehab connected client socket unless an alternative is supplied (srx is 8189f72374cSMauro Carvalho Chehab non-NULL). 8199f72374cSMauro Carvalho Chehab 8209f72374cSMauro Carvalho Chehab If a key is supplied then this will be used to secure the call instead of 8219f72374cSMauro Carvalho Chehab the key bound to the socket with the RXRPC_SECURITY_KEY sockopt. Calls 8229f72374cSMauro Carvalho Chehab secured in this way will still share connections if at all possible. 8239f72374cSMauro Carvalho Chehab 8249f72374cSMauro Carvalho Chehab The user_call_ID is equivalent to that supplied to sendmsg() in the 8259f72374cSMauro Carvalho Chehab control data buffer. It is entirely feasible to use this to point to a 8269f72374cSMauro Carvalho Chehab kernel data structure. 8279f72374cSMauro Carvalho Chehab 8289f72374cSMauro Carvalho Chehab tx_total_len is the amount of data the caller is intending to transmit 8299f72374cSMauro Carvalho Chehab with this call (or -1 if unknown at this point). Setting the data size 8309f72374cSMauro Carvalho Chehab allows the kernel to encrypt directly to the packet buffers, thereby 8319f72374cSMauro Carvalho Chehab saving a copy. The value may not be less than -1. 8329f72374cSMauro Carvalho Chehab 8339f72374cSMauro Carvalho Chehab notify_rx is a pointer to a function to be called when events such as 8349f72374cSMauro Carvalho Chehab incoming data packets or remote aborts happen. 8359f72374cSMauro Carvalho Chehab 8369f72374cSMauro Carvalho Chehab upgrade should be set to true if a client operation should request that 8379f72374cSMauro Carvalho Chehab the server upgrade the service to a better one. The resultant service ID 8389f72374cSMauro Carvalho Chehab is returned by rxrpc_kernel_recv_data(). 8399f72374cSMauro Carvalho Chehab 8409f72374cSMauro Carvalho Chehab intr should be set to true if the call should be interruptible. If this 8419f72374cSMauro Carvalho Chehab is not set, this function may not return until a channel has been 8429f72374cSMauro Carvalho Chehab allocated; if it is set, the function may return -ERESTARTSYS. 8439f72374cSMauro Carvalho Chehab 8449f72374cSMauro Carvalho Chehab debug_id is the call debugging ID to be used for tracing. This can be 8459f72374cSMauro Carvalho Chehab obtained by atomically incrementing rxrpc_debug_id. 8469f72374cSMauro Carvalho Chehab 8479f72374cSMauro Carvalho Chehab If this function is successful, an opaque reference to the RxRPC call is 8489f72374cSMauro Carvalho Chehab returned. The caller now holds a reference on this and it must be 8499f72374cSMauro Carvalho Chehab properly ended. 8509f72374cSMauro Carvalho Chehab 851*e0416e7dSDavid Howells (#) Shut down a client call:: 8529f72374cSMauro Carvalho Chehab 853*e0416e7dSDavid Howells void rxrpc_kernel_shutdown_call(struct socket *sock, 8549f72374cSMauro Carvalho Chehab struct rxrpc_call *call); 8559f72374cSMauro Carvalho Chehab 856*e0416e7dSDavid Howells This is used to shut down a previously begun call. The user_call_ID is 857*e0416e7dSDavid Howells expunged from AF_RXRPC's knowledge and will not be seen again in 858*e0416e7dSDavid Howells association with the specified call. 859*e0416e7dSDavid Howells 860*e0416e7dSDavid Howells (#) Release the ref on a client call:: 861*e0416e7dSDavid Howells 862*e0416e7dSDavid Howells void rxrpc_kernel_put_call(struct socket *sock, 863*e0416e7dSDavid Howells struct rxrpc_call *call); 864*e0416e7dSDavid Howells 865*e0416e7dSDavid Howells This is used to release the caller's ref on an rxrpc call. 8669f72374cSMauro Carvalho Chehab 8679f72374cSMauro Carvalho Chehab (#) Send data through a call:: 8689f72374cSMauro Carvalho Chehab 8699f72374cSMauro Carvalho Chehab typedef void (*rxrpc_notify_end_tx_t)(struct sock *sk, 8709f72374cSMauro Carvalho Chehab unsigned long user_call_ID, 8719f72374cSMauro Carvalho Chehab struct sk_buff *skb); 8729f72374cSMauro Carvalho Chehab 8739f72374cSMauro Carvalho Chehab int rxrpc_kernel_send_data(struct socket *sock, 8749f72374cSMauro Carvalho Chehab struct rxrpc_call *call, 8759f72374cSMauro Carvalho Chehab struct msghdr *msg, 8769f72374cSMauro Carvalho Chehab size_t len, 8779f72374cSMauro Carvalho Chehab rxrpc_notify_end_tx_t notify_end_rx); 8789f72374cSMauro Carvalho Chehab 8799f72374cSMauro Carvalho Chehab This is used to supply either the request part of a client call or the 8809f72374cSMauro Carvalho Chehab reply part of a server call. msg.msg_iovlen and msg.msg_iov specify the 8819f72374cSMauro Carvalho Chehab data buffers to be used. msg_iov may not be NULL and must point 8829f72374cSMauro Carvalho Chehab exclusively to in-kernel virtual addresses. msg.msg_flags may be given 8839f72374cSMauro Carvalho Chehab MSG_MORE if there will be subsequent data sends for this call. 8849f72374cSMauro Carvalho Chehab 8859f72374cSMauro Carvalho Chehab The msg must not specify a destination address, control data or any flags 8869f72374cSMauro Carvalho Chehab other than MSG_MORE. len is the total amount of data to transmit. 8879f72374cSMauro Carvalho Chehab 8889f72374cSMauro Carvalho Chehab notify_end_rx can be NULL or it can be used to specify a function to be 8899f72374cSMauro Carvalho Chehab called when the call changes state to end the Tx phase. This function is 8902d689424SDavid Howells called with a spinlock held to prevent the last DATA packet from being 8912d689424SDavid Howells transmitted until the function returns. 8929f72374cSMauro Carvalho Chehab 8939f72374cSMauro Carvalho Chehab (#) Receive data from a call:: 8949f72374cSMauro Carvalho Chehab 8959f72374cSMauro Carvalho Chehab int rxrpc_kernel_recv_data(struct socket *sock, 8969f72374cSMauro Carvalho Chehab struct rxrpc_call *call, 8979f72374cSMauro Carvalho Chehab void *buf, 8989f72374cSMauro Carvalho Chehab size_t size, 8999f72374cSMauro Carvalho Chehab size_t *_offset, 9009f72374cSMauro Carvalho Chehab bool want_more, 9019f72374cSMauro Carvalho Chehab u32 *_abort, 9029f72374cSMauro Carvalho Chehab u16 *_service) 9039f72374cSMauro Carvalho Chehab 9049f72374cSMauro Carvalho Chehab This is used to receive data from either the reply part of a client call 9059f72374cSMauro Carvalho Chehab or the request part of a service call. buf and size specify how much 9069f72374cSMauro Carvalho Chehab data is desired and where to store it. *_offset is added on to buf and 9079f72374cSMauro Carvalho Chehab subtracted from size internally; the amount copied into the buffer is 9089f72374cSMauro Carvalho Chehab added to *_offset before returning. 9099f72374cSMauro Carvalho Chehab 9109f72374cSMauro Carvalho Chehab want_more should be true if further data will be required after this is 9119f72374cSMauro Carvalho Chehab satisfied and false if this is the last item of the receive phase. 9129f72374cSMauro Carvalho Chehab 9139f72374cSMauro Carvalho Chehab There are three normal returns: 0 if the buffer was filled and want_more 9149f72374cSMauro Carvalho Chehab was true; 1 if the buffer was filled, the last DATA packet has been 9159f72374cSMauro Carvalho Chehab emptied and want_more was false; and -EAGAIN if the function needs to be 9169f72374cSMauro Carvalho Chehab called again. 9179f72374cSMauro Carvalho Chehab 9189f72374cSMauro Carvalho Chehab If the last DATA packet is processed but the buffer contains less than 9199f72374cSMauro Carvalho Chehab the amount requested, EBADMSG is returned. If want_more wasn't set, but 9209f72374cSMauro Carvalho Chehab more data was available, EMSGSIZE is returned. 9219f72374cSMauro Carvalho Chehab 9229f72374cSMauro Carvalho Chehab If a remote ABORT is detected, the abort code received will be stored in 9239f72374cSMauro Carvalho Chehab ``*_abort`` and ECONNABORTED will be returned. 9249f72374cSMauro Carvalho Chehab 9259f72374cSMauro Carvalho Chehab The service ID that the call ended up with is returned into *_service. 9269f72374cSMauro Carvalho Chehab This can be used to see if a call got a service upgrade. 9279f72374cSMauro Carvalho Chehab 9289f72374cSMauro Carvalho Chehab (#) Abort a call?? 9299f72374cSMauro Carvalho Chehab 9309f72374cSMauro Carvalho Chehab :: 9319f72374cSMauro Carvalho Chehab 9329f72374cSMauro Carvalho Chehab void rxrpc_kernel_abort_call(struct socket *sock, 9339f72374cSMauro Carvalho Chehab struct rxrpc_call *call, 9349f72374cSMauro Carvalho Chehab u32 abort_code); 9359f72374cSMauro Carvalho Chehab 9369f72374cSMauro Carvalho Chehab This is used to abort a call if it's still in an abortable state. The 9379f72374cSMauro Carvalho Chehab abort code specified will be placed in the ABORT message sent. 9389f72374cSMauro Carvalho Chehab 9399f72374cSMauro Carvalho Chehab (#) Intercept received RxRPC messages:: 9409f72374cSMauro Carvalho Chehab 9419f72374cSMauro Carvalho Chehab typedef void (*rxrpc_interceptor_t)(struct sock *sk, 9429f72374cSMauro Carvalho Chehab unsigned long user_call_ID, 9439f72374cSMauro Carvalho Chehab struct sk_buff *skb); 9449f72374cSMauro Carvalho Chehab 9459f72374cSMauro Carvalho Chehab void 9469f72374cSMauro Carvalho Chehab rxrpc_kernel_intercept_rx_messages(struct socket *sock, 9479f72374cSMauro Carvalho Chehab rxrpc_interceptor_t interceptor); 9489f72374cSMauro Carvalho Chehab 9499f72374cSMauro Carvalho Chehab This installs an interceptor function on the specified AF_RXRPC socket. 9509f72374cSMauro Carvalho Chehab All messages that would otherwise wind up in the socket's Rx queue are 9519f72374cSMauro Carvalho Chehab then diverted to this function. Note that care must be taken to process 9529f72374cSMauro Carvalho Chehab the messages in the right order to maintain DATA message sequentiality. 9539f72374cSMauro Carvalho Chehab 9549f72374cSMauro Carvalho Chehab The interceptor function itself is provided with the address of the socket 9559f72374cSMauro Carvalho Chehab and handling the incoming message, the ID assigned by the kernel utility 9569f72374cSMauro Carvalho Chehab to the call and the socket buffer containing the message. 9579f72374cSMauro Carvalho Chehab 9589f72374cSMauro Carvalho Chehab The skb->mark field indicates the type of message: 9599f72374cSMauro Carvalho Chehab 9609f72374cSMauro Carvalho Chehab =============================== ======================================= 9619f72374cSMauro Carvalho Chehab Mark Meaning 9629f72374cSMauro Carvalho Chehab =============================== ======================================= 9639f72374cSMauro Carvalho Chehab RXRPC_SKB_MARK_DATA Data message 9649f72374cSMauro Carvalho Chehab RXRPC_SKB_MARK_FINAL_ACK Final ACK received for an incoming call 9659f72374cSMauro Carvalho Chehab RXRPC_SKB_MARK_BUSY Client call rejected as server busy 9669f72374cSMauro Carvalho Chehab RXRPC_SKB_MARK_REMOTE_ABORT Call aborted by peer 9679f72374cSMauro Carvalho Chehab RXRPC_SKB_MARK_NET_ERROR Network error detected 9689f72374cSMauro Carvalho Chehab RXRPC_SKB_MARK_LOCAL_ERROR Local error encountered 9699f72374cSMauro Carvalho Chehab RXRPC_SKB_MARK_NEW_CALL New incoming call awaiting acceptance 9709f72374cSMauro Carvalho Chehab =============================== ======================================= 9719f72374cSMauro Carvalho Chehab 9729f72374cSMauro Carvalho Chehab The remote abort message can be probed with rxrpc_kernel_get_abort_code(). 9739f72374cSMauro Carvalho Chehab The two error messages can be probed with rxrpc_kernel_get_error_number(). 9749f72374cSMauro Carvalho Chehab A new call can be accepted with rxrpc_kernel_accept_call(). 9759f72374cSMauro Carvalho Chehab 9769f72374cSMauro Carvalho Chehab Data messages can have their contents extracted with the usual bunch of 9779f72374cSMauro Carvalho Chehab socket buffer manipulation functions. A data message can be determined to 9789f72374cSMauro Carvalho Chehab be the last one in a sequence with rxrpc_kernel_is_data_last(). When a 9799f72374cSMauro Carvalho Chehab data message has been used up, rxrpc_kernel_data_consumed() should be 9809f72374cSMauro Carvalho Chehab called on it. 9819f72374cSMauro Carvalho Chehab 9829f72374cSMauro Carvalho Chehab Messages should be handled to rxrpc_kernel_free_skb() to dispose of. It 9839f72374cSMauro Carvalho Chehab is possible to get extra refs on all types of message for later freeing, 9849f72374cSMauro Carvalho Chehab but this may pin the state of a call until the message is finally freed. 9859f72374cSMauro Carvalho Chehab 9869f72374cSMauro Carvalho Chehab (#) Accept an incoming call:: 9879f72374cSMauro Carvalho Chehab 9889f72374cSMauro Carvalho Chehab struct rxrpc_call * 9899f72374cSMauro Carvalho Chehab rxrpc_kernel_accept_call(struct socket *sock, 9909f72374cSMauro Carvalho Chehab unsigned long user_call_ID); 9919f72374cSMauro Carvalho Chehab 9929f72374cSMauro Carvalho Chehab This is used to accept an incoming call and to assign it a call ID. This 9939f72374cSMauro Carvalho Chehab function is similar to rxrpc_kernel_begin_call() and calls accepted must 9949f72374cSMauro Carvalho Chehab be ended in the same way. 9959f72374cSMauro Carvalho Chehab 9969f72374cSMauro Carvalho Chehab If this function is successful, an opaque reference to the RxRPC call is 9979f72374cSMauro Carvalho Chehab returned. The caller now holds a reference on this and it must be 9989f72374cSMauro Carvalho Chehab properly ended. 9999f72374cSMauro Carvalho Chehab 10009f72374cSMauro Carvalho Chehab (#) Reject an incoming call:: 10019f72374cSMauro Carvalho Chehab 10029f72374cSMauro Carvalho Chehab int rxrpc_kernel_reject_call(struct socket *sock); 10039f72374cSMauro Carvalho Chehab 10049f72374cSMauro Carvalho Chehab This is used to reject the first incoming call on the socket's queue with 10059f72374cSMauro Carvalho Chehab a BUSY message. -ENODATA is returned if there were no incoming calls. 10069f72374cSMauro Carvalho Chehab Other errors may be returned if the call had been aborted (-ECONNABORTED) 10079f72374cSMauro Carvalho Chehab or had timed out (-ETIME). 10089f72374cSMauro Carvalho Chehab 10099f72374cSMauro Carvalho Chehab (#) Allocate a null key for doing anonymous security:: 10109f72374cSMauro Carvalho Chehab 10119f72374cSMauro Carvalho Chehab struct key *rxrpc_get_null_key(const char *keyname); 10129f72374cSMauro Carvalho Chehab 10139f72374cSMauro Carvalho Chehab This is used to allocate a null RxRPC key that can be used to indicate 10149f72374cSMauro Carvalho Chehab anonymous security for a particular domain. 10159f72374cSMauro Carvalho Chehab 10169f72374cSMauro Carvalho Chehab (#) Get the peer address of a call:: 10179f72374cSMauro Carvalho Chehab 10189f72374cSMauro Carvalho Chehab void rxrpc_kernel_get_peer(struct socket *sock, struct rxrpc_call *call, 10199f72374cSMauro Carvalho Chehab struct sockaddr_rxrpc *_srx); 10209f72374cSMauro Carvalho Chehab 10219f72374cSMauro Carvalho Chehab This is used to find the remote peer address of a call. 10229f72374cSMauro Carvalho Chehab 10239f72374cSMauro Carvalho Chehab (#) Set the total transmit data size on a call:: 10249f72374cSMauro Carvalho Chehab 10259f72374cSMauro Carvalho Chehab void rxrpc_kernel_set_tx_length(struct socket *sock, 10269f72374cSMauro Carvalho Chehab struct rxrpc_call *call, 10279f72374cSMauro Carvalho Chehab s64 tx_total_len); 10289f72374cSMauro Carvalho Chehab 10299f72374cSMauro Carvalho Chehab This sets the amount of data that the caller is intending to transmit on a 10309f72374cSMauro Carvalho Chehab call. It's intended to be used for setting the reply size as the request 10319f72374cSMauro Carvalho Chehab size should be set when the call is begun. tx_total_len may not be less 10329f72374cSMauro Carvalho Chehab than zero. 10339f72374cSMauro Carvalho Chehab 10349f72374cSMauro Carvalho Chehab (#) Get call RTT:: 10359f72374cSMauro Carvalho Chehab 10369f72374cSMauro Carvalho Chehab u64 rxrpc_kernel_get_rtt(struct socket *sock, struct rxrpc_call *call); 10379f72374cSMauro Carvalho Chehab 10389f72374cSMauro Carvalho Chehab Get the RTT time to the peer in use by a call. The value returned is in 10399f72374cSMauro Carvalho Chehab nanoseconds. 10409f72374cSMauro Carvalho Chehab 10419f72374cSMauro Carvalho Chehab (#) Check call still alive:: 10429f72374cSMauro Carvalho Chehab 10439f72374cSMauro Carvalho Chehab bool rxrpc_kernel_check_life(struct socket *sock, 10449f72374cSMauro Carvalho Chehab struct rxrpc_call *call, 10459f72374cSMauro Carvalho Chehab u32 *_life); 10469f72374cSMauro Carvalho Chehab void rxrpc_kernel_probe_life(struct socket *sock, 10479f72374cSMauro Carvalho Chehab struct rxrpc_call *call); 10489f72374cSMauro Carvalho Chehab 10499f72374cSMauro Carvalho Chehab The first function passes back in ``*_life`` a number that is updated when 10509f72374cSMauro Carvalho Chehab ACKs are received from the peer (notably including PING RESPONSE ACKs 10519f72374cSMauro Carvalho Chehab which we can elicit by sending PING ACKs to see if the call still exists 10529f72374cSMauro Carvalho Chehab on the server). The caller should compare the numbers of two calls to see 10539f72374cSMauro Carvalho Chehab if the call is still alive after waiting for a suitable interval. It also 10549f72374cSMauro Carvalho Chehab returns true as long as the call hasn't yet reached the completed state. 10559f72374cSMauro Carvalho Chehab 10569f72374cSMauro Carvalho Chehab This allows the caller to work out if the server is still contactable and 10579f72374cSMauro Carvalho Chehab if the call is still alive on the server while waiting for the server to 10589f72374cSMauro Carvalho Chehab process a client operation. 10599f72374cSMauro Carvalho Chehab 10609f72374cSMauro Carvalho Chehab The second function causes a ping ACK to be transmitted to try to provoke 10619f72374cSMauro Carvalho Chehab the peer into responding, which would then cause the value returned by the 10629f72374cSMauro Carvalho Chehab first function to change. Note that this must be called in TASK_RUNNING 10639f72374cSMauro Carvalho Chehab state. 10649f72374cSMauro Carvalho Chehab 10659f72374cSMauro Carvalho Chehab (#) Get remote client epoch:: 10669f72374cSMauro Carvalho Chehab 10679f72374cSMauro Carvalho Chehab u32 rxrpc_kernel_get_epoch(struct socket *sock, 10689f72374cSMauro Carvalho Chehab struct rxrpc_call *call) 10699f72374cSMauro Carvalho Chehab 10709f72374cSMauro Carvalho Chehab This allows the epoch that's contained in packets of an incoming client 10719f72374cSMauro Carvalho Chehab call to be queried. This value is returned. The function always 10729f72374cSMauro Carvalho Chehab successful if the call is still in progress. It shouldn't be called once 10739f72374cSMauro Carvalho Chehab the call has expired. Note that calling this on a local client call only 10749f72374cSMauro Carvalho Chehab returns the local epoch. 10759f72374cSMauro Carvalho Chehab 10769f72374cSMauro Carvalho Chehab This value can be used to determine if the remote client has been 10779f72374cSMauro Carvalho Chehab restarted as it shouldn't change otherwise. 10789f72374cSMauro Carvalho Chehab 1079a266ef69SRandy Dunlap (#) Set the maximum lifespan on a call:: 10809f72374cSMauro Carvalho Chehab 10819f72374cSMauro Carvalho Chehab void rxrpc_kernel_set_max_life(struct socket *sock, 10829f72374cSMauro Carvalho Chehab struct rxrpc_call *call, 10839f72374cSMauro Carvalho Chehab unsigned long hard_timeout) 10849f72374cSMauro Carvalho Chehab 10859f72374cSMauro Carvalho Chehab This sets the maximum lifespan on a call to hard_timeout (which is in 10869f72374cSMauro Carvalho Chehab jiffies). In the event of the timeout occurring, the call will be 10879f72374cSMauro Carvalho Chehab aborted and -ETIME or -ETIMEDOUT will be returned. 10889f72374cSMauro Carvalho Chehab 1089298cd88aSChristoph Hellwig (#) Apply the RXRPC_MIN_SECURITY_LEVEL sockopt to a socket from within in the 1090298cd88aSChristoph Hellwig kernel:: 1091298cd88aSChristoph Hellwig 1092298cd88aSChristoph Hellwig int rxrpc_sock_set_min_security_level(struct sock *sk, 1093298cd88aSChristoph Hellwig unsigned int val); 1094298cd88aSChristoph Hellwig 1095298cd88aSChristoph Hellwig This specifies the minimum security level required for calls on this 1096298cd88aSChristoph Hellwig socket. 1097298cd88aSChristoph Hellwig 10989f72374cSMauro Carvalho Chehab 10999f72374cSMauro Carvalho ChehabConfigurable Parameters 11009f72374cSMauro Carvalho Chehab======================= 11019f72374cSMauro Carvalho Chehab 11029f72374cSMauro Carvalho ChehabThe RxRPC protocol driver has a number of configurable parameters that can be 11039f72374cSMauro Carvalho Chehabadjusted through sysctls in /proc/net/rxrpc/: 11049f72374cSMauro Carvalho Chehab 11059f72374cSMauro Carvalho Chehab (#) req_ack_delay 11069f72374cSMauro Carvalho Chehab 11079f72374cSMauro Carvalho Chehab The amount of time in milliseconds after receiving a packet with the 11089f72374cSMauro Carvalho Chehab request-ack flag set before we honour the flag and actually send the 11099f72374cSMauro Carvalho Chehab requested ack. 11109f72374cSMauro Carvalho Chehab 11119f72374cSMauro Carvalho Chehab Usually the other side won't stop sending packets until the advertised 11129f72374cSMauro Carvalho Chehab reception window is full (to a maximum of 255 packets), so delaying the 11139f72374cSMauro Carvalho Chehab ACK permits several packets to be ACK'd in one go. 11149f72374cSMauro Carvalho Chehab 11159f72374cSMauro Carvalho Chehab (#) soft_ack_delay 11169f72374cSMauro Carvalho Chehab 11179f72374cSMauro Carvalho Chehab The amount of time in milliseconds after receiving a new packet before we 11189f72374cSMauro Carvalho Chehab generate a soft-ACK to tell the sender that it doesn't need to resend. 11199f72374cSMauro Carvalho Chehab 11209f72374cSMauro Carvalho Chehab (#) idle_ack_delay 11219f72374cSMauro Carvalho Chehab 11229f72374cSMauro Carvalho Chehab The amount of time in milliseconds after all the packets currently in the 11239f72374cSMauro Carvalho Chehab received queue have been consumed before we generate a hard-ACK to tell 11249f72374cSMauro Carvalho Chehab the sender it can free its buffers, assuming no other reason occurs that 11259f72374cSMauro Carvalho Chehab we would send an ACK. 11269f72374cSMauro Carvalho Chehab 11279f72374cSMauro Carvalho Chehab (#) resend_timeout 11289f72374cSMauro Carvalho Chehab 11299f72374cSMauro Carvalho Chehab The amount of time in milliseconds after transmitting a packet before we 11309f72374cSMauro Carvalho Chehab transmit it again, assuming no ACK is received from the receiver telling 11319f72374cSMauro Carvalho Chehab us they got it. 11329f72374cSMauro Carvalho Chehab 11339f72374cSMauro Carvalho Chehab (#) max_call_lifetime 11349f72374cSMauro Carvalho Chehab 11359f72374cSMauro Carvalho Chehab The maximum amount of time in seconds that a call may be in progress 11369f72374cSMauro Carvalho Chehab before we preemptively kill it. 11379f72374cSMauro Carvalho Chehab 11389f72374cSMauro Carvalho Chehab (#) dead_call_expiry 11399f72374cSMauro Carvalho Chehab 11409f72374cSMauro Carvalho Chehab The amount of time in seconds before we remove a dead call from the call 11419f72374cSMauro Carvalho Chehab list. Dead calls are kept around for a little while for the purpose of 11429f72374cSMauro Carvalho Chehab repeating ACK and ABORT packets. 11439f72374cSMauro Carvalho Chehab 11449f72374cSMauro Carvalho Chehab (#) connection_expiry 11459f72374cSMauro Carvalho Chehab 11469f72374cSMauro Carvalho Chehab The amount of time in seconds after a connection was last used before we 11479f72374cSMauro Carvalho Chehab remove it from the connection list. While a connection is in existence, 11489f72374cSMauro Carvalho Chehab it serves as a placeholder for negotiated security; when it is deleted, 11499f72374cSMauro Carvalho Chehab the security must be renegotiated. 11509f72374cSMauro Carvalho Chehab 11519f72374cSMauro Carvalho Chehab (#) transport_expiry 11529f72374cSMauro Carvalho Chehab 11539f72374cSMauro Carvalho Chehab The amount of time in seconds after a transport was last used before we 11549f72374cSMauro Carvalho Chehab remove it from the transport list. While a transport is in existence, it 11559f72374cSMauro Carvalho Chehab serves to anchor the peer data and keeps the connection ID counter. 11569f72374cSMauro Carvalho Chehab 11579f72374cSMauro Carvalho Chehab (#) rxrpc_rx_window_size 11589f72374cSMauro Carvalho Chehab 11599f72374cSMauro Carvalho Chehab The size of the receive window in packets. This is the maximum number of 11609f72374cSMauro Carvalho Chehab unconsumed received packets we're willing to hold in memory for any 11619f72374cSMauro Carvalho Chehab particular call. 11629f72374cSMauro Carvalho Chehab 11639f72374cSMauro Carvalho Chehab (#) rxrpc_rx_mtu 11649f72374cSMauro Carvalho Chehab 11659f72374cSMauro Carvalho Chehab The maximum packet MTU size that we're willing to receive in bytes. This 11669f72374cSMauro Carvalho Chehab indicates to the peer whether we're willing to accept jumbo packets. 11679f72374cSMauro Carvalho Chehab 11689f72374cSMauro Carvalho Chehab (#) rxrpc_rx_jumbo_max 11699f72374cSMauro Carvalho Chehab 11709f72374cSMauro Carvalho Chehab The maximum number of packets that we're willing to accept in a jumbo 11719f72374cSMauro Carvalho Chehab packet. Non-terminal packets in a jumbo packet must contain a four byte 11729f72374cSMauro Carvalho Chehab header plus exactly 1412 bytes of data. The terminal packet must contain 11739f72374cSMauro Carvalho Chehab a four byte header plus any amount of data. In any event, a jumbo packet 11749f72374cSMauro Carvalho Chehab may not exceed rxrpc_rx_mtu in size. 1175