Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

docs: networking: convert kcm.txt to ReST

- add SPDX header;
- adjust titles and chapters, adding proper markups;
- mark code blocks and literals as such;
- adjust identation, whitespaces and blank lines;
- add to networking/index.rst.

Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
Signed-off-by: David S. Miller <davem@davemloft.net>

authored by

Mauro Carvalho Chehab and committed by
David S. Miller
b9dd2bea 82a07bf3

+45 -39
+1
Documentation/networking/index.rst
··· 73 73 ipv6 74 74 ipvlan 75 75 ipvs-sysctl 76 + kcm 76 77 77 78 .. only:: subproject and html 78 79
+44 -39
Documentation/networking/kcm.txt Documentation/networking/kcm.rst
··· 1 + .. SPDX-License-Identifier: GPL-2.0 2 + 3 + ============================= 1 4 Kernel Connection Multiplexor 2 - ----------------------------- 5 + ============================= 3 6 4 7 Kernel Connection Multiplexor (KCM) is a mechanism that provides a message based 5 8 interface over TCP for generic application protocols. With KCM an application 6 9 can efficiently send and receive application protocol messages over TCP using 7 10 datagram sockets. 8 11 9 - KCM implements an NxM multiplexor in the kernel as diagrammed below: 12 + KCM implements an NxM multiplexor in the kernel as diagrammed below:: 10 13 11 - +------------+ +------------+ +------------+ +------------+ 12 - | KCM socket | | KCM socket | | KCM socket | | KCM socket | 13 - +------------+ +------------+ +------------+ +------------+ 14 - | | | | 15 - +-----------+ | | +----------+ 16 - | | | | 17 - +----------------------------------+ 18 - | Multiplexor | 19 - +----------------------------------+ 20 - | | | | | 21 - +---------+ | | | ------------+ 22 - | | | | | 23 - +----------+ +----------+ +----------+ +----------+ +----------+ 24 - | Psock | | Psock | | Psock | | Psock | | Psock | 25 - +----------+ +----------+ +----------+ +----------+ +----------+ 26 - | | | | | 27 - +----------+ +----------+ +----------+ +----------+ +----------+ 28 - | TCP sock | | TCP sock | | TCP sock | | TCP sock | | TCP sock | 29 - +----------+ +----------+ +----------+ +----------+ +----------+ 14 + +------------+ +------------+ +------------+ +------------+ 15 + | KCM socket | | KCM socket | | KCM socket | | KCM socket | 16 + +------------+ +------------+ +------------+ +------------+ 17 + | | | | 18 + +-----------+ | | +----------+ 19 + | | | | 20 + +----------------------------------+ 21 + | Multiplexor | 22 + +----------------------------------+ 23 + | | | | | 24 + +---------+ | | | ------------+ 25 + | | | | | 26 + +----------+ +----------+ +----------+ +----------+ +----------+ 27 + | Psock | | Psock | | Psock | | Psock | | Psock | 28 + +----------+ +----------+ +----------+ +----------+ +----------+ 29 + | | | | | 30 + +----------+ +----------+ +----------+ +----------+ +----------+ 31 + | TCP sock | | TCP sock | | TCP sock | | TCP sock | | TCP sock | 32 + +----------+ +----------+ +----------+ +----------+ +----------+ 30 33 31 34 KCM sockets 32 - ----------- 35 + =========== 33 36 34 37 The KCM sockets provide the user interface to the multiplexor. All the KCM sockets 35 38 bound to a multiplexor are considered to have equivalent function, and I/O ··· 40 37 synchronization between threads in userspace. 41 38 42 39 Multiplexor 43 - ----------- 40 + =========== 44 41 45 42 The multiplexor provides the message steering. In the transmit path, messages 46 43 written on a KCM socket are sent atomically on an appropriate TCP socket. ··· 48 45 (Psock) and complete messages are steered to a KCM socket. 49 46 50 47 TCP sockets & Psocks 51 - -------------------- 48 + ==================== 52 49 53 50 TCP sockets may be bound to a KCM multiplexor. A Psock structure is allocated 54 51 for each bound TCP socket, this structure holds the state for constructing 55 52 messages on receive as well as other connection specific information for KCM. 56 53 57 54 Connected mode semantics 58 - ------------------------ 55 + ======================== 59 56 60 57 Each multiplexor assumes that all attached TCP connections are to the same 61 58 destination and can use the different connections for load balancing when ··· 63 60 can be used to send and receive messages from the KCM socket. 64 61 65 62 Socket types 66 - ------------ 63 + ============ 67 64 68 65 KCM supports SOCK_DGRAM and SOCK_SEQPACKET socket types. 69 66 ··· 113 110 Creating a multiplexor 114 111 ---------------------- 115 112 116 - A new multiplexor and initial KCM socket is created by a socket call: 113 + A new multiplexor and initial KCM socket is created by a socket call:: 117 114 118 115 socket(AF_KCM, type, protocol) 119 116 120 - - type is either SOCK_DGRAM or SOCK_SEQPACKET 121 - - protocol is KCMPROTO_CONNECTED 117 + - type is either SOCK_DGRAM or SOCK_SEQPACKET 118 + - protocol is KCMPROTO_CONNECTED 122 119 123 120 Cloning KCM sockets 124 121 ------------------- 125 122 126 123 After the first KCM socket is created using the socket call as described 127 124 above, additional sockets for the multiplexor can be created by cloning 128 - a KCM socket. This is accomplished by an ioctl on a KCM socket: 125 + a KCM socket. This is accomplished by an ioctl on a KCM socket:: 129 126 130 127 /* From linux/kcm.h */ 131 128 struct kcm_clone { 132 - int fd; 129 + int fd; 133 130 }; 134 131 135 132 struct kcm_clone info; ··· 145 142 ------------------------ 146 143 147 144 Attaching of transport sockets to a multiplexor is performed by calling an 148 - ioctl on a KCM socket for the multiplexor. e.g.: 145 + ioctl on a KCM socket for the multiplexor. e.g.:: 149 146 150 147 /* From linux/kcm.h */ 151 148 struct kcm_attach { 152 - int fd; 149 + int fd; 153 150 int bpf_fd; 154 151 }; 155 152 ··· 163 160 ioctl(kcmfd, SIOCKCMATTACH, &info); 164 161 165 162 The kcm_attach structure contains: 166 - fd: file descriptor for TCP socket being attached 167 - bpf_prog_fd: file descriptor for compiled BPF program downloaded 163 + 164 + - fd: file descriptor for TCP socket being attached 165 + - bpf_prog_fd: file descriptor for compiled BPF program downloaded 168 166 169 167 Unattach transport sockets 170 168 -------------------------- 171 169 172 170 Unattaching a transport socket from a multiplexor is straightforward. An 173 - "unattach" ioctl is done with the kcm_unattach structure as the argument: 171 + "unattach" ioctl is done with the kcm_unattach structure as the argument:: 174 172 175 173 /* From linux/kcm.h */ 176 174 struct kcm_unattach { 177 - int fd; 175 + int fd; 178 176 }; 179 177 180 178 struct kcm_unattach info; ··· 194 190 receive buffer are moved to other sockets. This feature is useful 195 191 if an application thread knows that it will be doing a lot of 196 192 work on a request and won't be able to service new messages for a 197 - while. Example use: 193 + while. Example use:: 198 194 199 195 int val = 1; 200 196 ··· 204 200 ------------------------------------ 205 201 206 202 BPF programs can be compiled using the BPF LLVM backend. For example, 207 - the BPF program for parsing Thrift is: 203 + the BPF program for parsing Thrift is:: 208 204 209 205 #include "bpf.h" /* for __sk_buff */ 210 206 #include "bpf_helpers.h" /* for load_word intrinsic */ ··· 254 250 255 251 On transmit, there are three ways an application can batch (pipeline) 256 252 messages on a KCM socket. 253 + 257 254 1) Send multiple messages in a single sendmmsg. 258 255 2) Send a group of messages each with a sendmsg call, where all messages 259 256 except the last have MSG_BATCH in the flags of sendmsg call.