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