]> git.ipfire.org Git - thirdparty/man-pages.git/blob - man7/vsock.7
proc.5 Add missing Inode field to /proc/net/unix
[thirdparty/man-pages.git] / man7 / vsock.7
1 .\" Copyright (C) 2018, Stefan Hajnoczi <stefanha@redhat.com>
2 .\"
3 .\" %%%LICENSE_START(VERBATIM)
4 .\" Permission is granted to make and distribute verbatim copies of this
5 .\" manual provided the copyright notice and this permission notice are
6 .\" preserved on all copies.
7 .\"
8 .\" Permission is granted to copy and distribute modified versions of this
9 .\" manual under the conditions for verbatim copying, provided that the
10 .\" entire resulting derived work is distributed under the terms of a
11 .\" permission notice identical to this one.
12 .\"
13 .\" Since the Linux kernel and libraries are constantly changing, this
14 .\" manual page may be incorrect or out-of-date. The author(s) assume no
15 .\" responsibility for errors or omissions, or for damages resulting from
16 .\" the use of the information contained herein. The author(s) may not
17 .\" have taken the same level of care in the production of this manual,
18 .\" which is licensed free of charge, as they might when working
19 .\" professionally.
20 .\"
21 .\" Formatted or processed versions of this manual, if unaccompanied by
22 .\" the source, must acknowledge the copyright and authors of this work.
23 .\" %%%LICENSE_END
24 .\"
25 .TH VSOCK 7 2017-11-30 "Linux" "Linux Programmer's Manual"
26 .SH NAME
27 vsock \- Linux VSOCK address family
28 .SH SYNOPSIS
29 .B #include <sys/socket.h>
30 .br
31 .B #include <linux/vm_sockets.h>
32 .PP
33 .IB stream_socket " = socket(AF_VSOCK, SOCK_STREAM, 0);"
34 .br
35 .IB datagram_socket " = socket(AF_VSOCK, SOCK_DGRAM, 0);"
36 .SH DESCRIPTION
37 The VSOCK address family facilitates communication between virtual machines and
38 the host they are running on.
39 This address family is used by guest agents and
40 hypervisor services that need a communications channel that is independent of
41 virtual machine network configuration.
42 .PP
43 Valid socket types are
44 .B SOCK_STREAM
45 and
46 .BR SOCK_DGRAM .
47 .B SOCK_STREAM
48 provides connection-oriented byte streams with guaranteed, in-order delivery.
49 .B SOCK_DGRAM
50 provides a connectionless datagram packet service with best-effort delivery and
51 best-effort ordering.
52 Availability of these socket types is dependent on the
53 underlying hypervisor.
54 .PP
55 A new socket is created with
56 .PP
57 .in +4n
58 .EX
59 socket(AF_VSOCK, socket_type, 0);
60 .EE
61 .in
62 .PP
63 When a process wants to establish a connection, it calls
64 .BR connect (2)
65 with a given destination socket address.
66 The socket is automatically bound to a free port if unbound.
67 .PP
68 A process can listen for incoming connections by first binding to a socket
69 address using
70 .BR bind (2)
71 and then calling
72 .BR listen (2).
73 .PP
74 Data is transmitted using the
75 .BR send (2)
76 or
77 .BR write (2)
78 families of system calls and data is received using the
79 .BR recv (2)
80 or
81 .BR read (2)
82 families of system calls.
83 .SS Address format
84 A socket address is defined as a combination of a 32-bit Context Identifier
85 (CID) and a 32-bit port number.
86 The CID identifies the source or destination,
87 which is either a virtual machine or the host.
88 The port number differentiates between multiple services running on
89 a single machine.
90 .PP
91 .in +4n
92 .EX
93 struct sockaddr_vm {
94 sa_family_t svm_family; /* Address family: AF_VSOCK */
95 unsigned short svm_reserved1;
96 unsigned int svm_port; /* Port # in host byte order */
97 unsigned int svm_cid; /* Address in host byte order */
98 };
99 .EE
100 .in
101 .PP
102 .I svm_family
103 is always set to
104 .BR AF_VSOCK .
105 .I svm_reserved1
106 is always set to 0.
107 .I svm_port
108 contains the port number in host byte order.
109 The port numbers below 1024 are called
110 .IR "privileged ports" .
111 Only a process with the
112 .B CAP_NET_BIND_SERVICE
113 capability may
114 .BR bind (2)
115 to these port numbers.
116 .PP
117 There are several special addresses:
118 .B VMADDR_CID_ANY
119 (\-1U)
120 means any address for binding;
121 .B VMADDR_CID_HYPERVISOR
122 (0) is reserved for services built into the hypervisor;
123 .B VMADDR_CID_RESERVED
124 (1) must not be used;
125 .B VMADDR_CID_HOST
126 (2)
127 is the well-known address of the host.
128 .PP
129 The special constant
130 .B VMADDR_PORT_ANY
131 (\-1U)
132 means any port number for binding.
133 .SS Live migration
134 Sockets are affected by live migration of virtual machines.
135 Connected
136 .B SOCK_STREAM
137 sockets become disconnected when the virtual machine migrates to a new host.
138 Applications must reconnect when this happens.
139 .PP
140 The local CID may change across live migration if the old CID is
141 not available on the new host.
142 Bound sockets are automatically updated to the new CID.
143 .SS Ioctls
144 .TP
145 .B IOCTL_VM_SOCKETS_GET_LOCAL_CID
146 Get the CID of the local machine.
147 The argument is a pointer to an
148 .IR "unsigned int" .
149 .IP
150 .in +4n
151 .EX
152 ioctl(socket, IOCTL_VM_SOCKETS_GET_LOCAL_CID, &cid);
153 .EE
154 .in
155 .IP
156 Consider using
157 .B VMADDR_CID_ANY
158 when binding instead of getting the local CID with
159 .BR IOCTL_VM_SOCKETS_GET_LOCAL_CID .
160 .SH ERRORS
161 .TP
162 .B EACCES
163 Unable to bind to a privileged port without the
164 .B CAP_NET_BIND_SERVICE
165 capability.
166 .TP
167 .B EADDRINUSE
168 Unable to bind to a port that is already in use.
169 .TP
170 .B EADDRNOTAVAIL
171 Unable to find a free port for binding or unable to bind to a nonlocal CID.
172 .TP
173 .B EINVAL
174 Invalid parameters.
175 This includes:
176 attempting to bind a socket that is already bound, providing an invalid struct
177 .IR sockaddr_vm ,
178 and other input validation errors.
179 .TP
180 .B ENOPROTOOPT
181 Invalid socket option in
182 .BR setsockopt (2)
183 or
184 .BR getsockopt (2).
185 .TP
186 .B ENOTCONN
187 Unable to perform operation on an unconnected socket.
188 .TP
189 .B EOPNOTSUPP
190 Operation not supported.
191 This includes:
192 the
193 .B MSG_OOB
194 flag that is not implemented for the
195 .BR send (2)
196 family of syscalls and
197 .B MSG_PEEK
198 for the
199 .BR recv (2)
200 family of syscalls.
201 .TP
202 .B EPROTONOSUPPORT
203 Invalid socket protocol number.
204 The protocol should always be 0.
205 .TP
206 .B ESOCKTNOSUPPORT
207 Unsupported socket type in
208 .BR socket (2).
209 Only
210 .B SOCK_STREAM
211 and
212 .B SOCK_DGRAM
213 are valid.
214 .SH VERSIONS
215 Support for VMware (VMCI) has been available since Linux 3.9.
216 KVM (virtio) is supported since Linux 4.8.
217 Hyper-V is supported since Linux 4.14.
218 .SH SEE ALSO
219 .BR bind (2),
220 .BR connect (2),
221 .BR listen (2),
222 .BR recv (2),
223 .BR send (2),
224 .BR socket (2),
225 .BR capabilities (7)