xref: /linux/include/uapi/linux/vm_sockets.h (revision ca55b2fef3a9373fcfc30f82fd26bc7fccbda732)
1 /*
2  * VMware vSockets Driver
3  *
4  * Copyright (C) 2007-2013 VMware, Inc. All rights reserved.
5  *
6  * This program is free software; you can redistribute it and/or modify it
7  * under the terms of the GNU General Public License as published by the Free
8  * Software Foundation version 2 and no later version.
9  *
10  * This program is distributed in the hope that it will be useful, but WITHOUT
11  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
13  * more details.
14  */
15 
16 #ifndef _UAPI_VM_SOCKETS_H
17 #define _UAPI_VM_SOCKETS_H
18 
19 #include <linux/socket.h>
20 
21 /* Option name for STREAM socket buffer size.  Use as the option name in
22  * setsockopt(3) or getsockopt(3) to set or get an unsigned long long that
23  * specifies the size of the buffer underlying a vSockets STREAM socket.
24  * Value is clamped to the MIN and MAX.
25  */
26 
27 #define SO_VM_SOCKETS_BUFFER_SIZE 0
28 
29 /* Option name for STREAM socket minimum buffer size.  Use as the option name
30  * in setsockopt(3) or getsockopt(3) to set or get an unsigned long long that
31  * specifies the minimum size allowed for the buffer underlying a vSockets
32  * STREAM socket.
33  */
34 
35 #define SO_VM_SOCKETS_BUFFER_MIN_SIZE 1
36 
37 /* Option name for STREAM socket maximum buffer size.  Use as the option name
38  * in setsockopt(3) or getsockopt(3) to set or get an unsigned long long
39  * that specifies the maximum size allowed for the buffer underlying a
40  * vSockets STREAM socket.
41  */
42 
43 #define SO_VM_SOCKETS_BUFFER_MAX_SIZE 2
44 
45 /* Option name for socket peer's host-specific VM ID.  Use as the option name
46  * in getsockopt(3) to get a host-specific identifier for the peer endpoint's
47  * VM.  The identifier is a signed integer.
48  * Only available for hypervisor endpoints.
49  */
50 
51 #define SO_VM_SOCKETS_PEER_HOST_VM_ID 3
52 
53 /* Option name for determining if a socket is trusted.  Use as the option name
54  * in getsockopt(3) to determine if a socket is trusted.  The value is a
55  * signed integer.
56  */
57 
58 #define SO_VM_SOCKETS_TRUSTED 5
59 
60 /* Option name for STREAM socket connection timeout.  Use as the option name
61  * in setsockopt(3) or getsockopt(3) to set or get the connection
62  * timeout for a STREAM socket.
63  */
64 
65 #define SO_VM_SOCKETS_CONNECT_TIMEOUT 6
66 
67 /* Option name for using non-blocking send/receive.  Use as the option name
68  * for setsockopt(3) or getsockopt(3) to set or get the non-blocking
69  * transmit/receive flag for a STREAM socket.  This flag determines whether
70  * send() and recv() can be called in non-blocking contexts for the given
71  * socket.  The value is a signed integer.
72  *
73  * This option is only relevant to kernel endpoints, where descheduling the
74  * thread of execution is not allowed, for example, while holding a spinlock.
75  * It is not to be confused with conventional non-blocking socket operations.
76  *
77  * Only available for hypervisor endpoints.
78  */
79 
80 #define SO_VM_SOCKETS_NONBLOCK_TXRX 7
81 
82 /* The vSocket equivalent of INADDR_ANY.  This works for the svm_cid field of
83  * sockaddr_vm and indicates the context ID of the current endpoint.
84  */
85 
86 #define VMADDR_CID_ANY -1U
87 
88 /* Bind to any available port.  Works for the svm_port field of
89  * sockaddr_vm.
90  */
91 
92 #define VMADDR_PORT_ANY -1U
93 
94 /* Use this as the destination CID in an address when referring to the
95  * hypervisor.  VMCI relies on it being 0, but this would be useful for other
96  * transports too.
97  */
98 
99 #define VMADDR_CID_HYPERVISOR 0
100 
101 /* This CID is specific to VMCI and can be considered reserved (even VMCI
102  * doesn't use it anymore, it's a legacy value from an older release).
103  */
104 
105 #define VMADDR_CID_RESERVED 1
106 
107 /* Use this as the destination CID in an address when referring to the host
108  * (any process other than the hypervisor).  VMCI relies on it being 2, but
109  * this would be useful for other transports too.
110  */
111 
112 #define VMADDR_CID_HOST 2
113 
114 /* Invalid vSockets version. */
115 
116 #define VM_SOCKETS_INVALID_VERSION -1U
117 
118 /* The epoch (first) component of the vSockets version.  A single byte
119  * representing the epoch component of the vSockets version.
120  */
121 
122 #define VM_SOCKETS_VERSION_EPOCH(_v) (((_v) & 0xFF000000) >> 24)
123 
124 /* The major (second) component of the vSockets version.   A single byte
125  * representing the major component of the vSockets version.  Typically
126  * changes for every major release of a product.
127  */
128 
129 #define VM_SOCKETS_VERSION_MAJOR(_v) (((_v) & 0x00FF0000) >> 16)
130 
131 /* The minor (third) component of the vSockets version.  Two bytes representing
132  * the minor component of the vSockets version.
133  */
134 
135 #define VM_SOCKETS_VERSION_MINOR(_v) (((_v) & 0x0000FFFF))
136 
137 /* Address structure for vSockets.   The address family should be set to
138  * AF_VSOCK.  The structure members should all align on their natural
139  * boundaries without resorting to compiler packing directives.  The total size
140  * of this structure should be exactly the same as that of struct sockaddr.
141  */
142 
143 struct sockaddr_vm {
144 	__kernel_sa_family_t svm_family;
145 	unsigned short svm_reserved1;
146 	unsigned int svm_port;
147 	unsigned int svm_cid;
148 	unsigned char svm_zero[sizeof(struct sockaddr) -
149 			       sizeof(sa_family_t) -
150 			       sizeof(unsigned short) -
151 			       sizeof(unsigned int) - sizeof(unsigned int)];
152 };
153 
154 #define IOCTL_VM_SOCKETS_GET_LOCAL_CID		_IO(7, 0xb9)
155 
156 #endif /* _UAPI_VM_SOCKETS_H */
157