blob: f7f2e99dec84d329f29929ffe1be9704647d8f7c [file] [log] [blame]
Andy Kingd021c342013-02-06 14:23:56 +00001/*
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 _VM_SOCKETS_H_
17#define _VM_SOCKETS_H_
18
19#if !defined(__KERNEL__)
20#include <sys/socket.h>
21#endif
22
23/* Option name for STREAM socket buffer size. Use as the option name in
24 * setsockopt(3) or getsockopt(3) to set or get an unsigned long long that
25 * specifies the size of the buffer underlying a vSockets STREAM socket.
26 * Value is clamped to the MIN and MAX.
27 */
28
29#define SO_VM_SOCKETS_BUFFER_SIZE 0
30
31/* Option name for STREAM socket minimum buffer size. Use as the option name
32 * in setsockopt(3) or getsockopt(3) to set or get an unsigned long long that
33 * specifies the minimum size allowed for the buffer underlying a vSockets
34 * STREAM socket.
35 */
36
37#define SO_VM_SOCKETS_BUFFER_MIN_SIZE 1
38
39/* Option name for STREAM socket maximum buffer size. Use as the option name
40 * in setsockopt(3) or getsockopt(3) to set or get an unsigned long long
41 * that specifies the maximum size allowed for the buffer underlying a
42 * vSockets STREAM socket.
43 */
44
45#define SO_VM_SOCKETS_BUFFER_MAX_SIZE 2
46
47/* Option name for socket peer's host-specific VM ID. Use as the option name
48 * in getsockopt(3) to get a host-specific identifier for the peer endpoint's
49 * VM. The identifier is a signed integer.
50 * Only available for hypervisor endpoints.
51 */
52
53#define SO_VM_SOCKETS_PEER_HOST_VM_ID 3
54
55/* Option name for socket's service label. Use as the option name in
56 * setsockopt(3) or getsockopt(3) to set or get the service label for a socket.
57 * The service label is a C-style NUL-terminated string. Only available for
58 * hypervisor endpoints.
59 */
60
61#define SO_VM_SOCKETS_SERVICE_LABEL 4
62
63/* Option name for determining if a socket is trusted. Use as the option name
64 * in getsockopt(3) to determine if a socket is trusted. The value is a
65 * signed integer.
66 */
67
68#define SO_VM_SOCKETS_TRUSTED 5
69
70/* Option name for STREAM socket connection timeout. Use as the option name
71 * in setsockopt(3) or getsockopt(3) to set or get the connection
72 * timeout for a STREAM socket.
73 */
74
75#define SO_VM_SOCKETS_CONNECT_TIMEOUT 6
76
77/* Option name for using non-blocking send/receive. Use as the option name
78 * for setsockopt(3) or getsockopt(3) to set or get the non-blocking
79 * transmit/receive flag for a STREAM socket. This flag determines whether
80 * send() and recv() can be called in non-blocking contexts for the given
81 * socket. The value is a signed integer.
82 *
83 * This option is only relevant to kernel endpoints, where descheduling the
84 * thread of execution is not allowed, for example, while holding a spinlock.
85 * It is not to be confused with conventional non-blocking socket operations.
86 *
87 * Only available for hypervisor endpoints.
88 */
89
90#define SO_VM_SOCKETS_NONBLOCK_TXRX 7
91
92/* The vSocket equivalent of INADDR_ANY. This works for the svm_cid field of
93 * sockaddr_vm and indicates the context ID of the current endpoint.
94 */
95
96#define VMADDR_CID_ANY -1U
97
98/* Bind to any available port. Works for the svm_port field of
99 * sockaddr_vm.
100 */
101
102#define VMADDR_PORT_ANY -1U
103
104/* Use this as the destination CID in an address when referring to the
105 * hypervisor. VMCI relies on it being 0, but this would be useful for other
106 * transports too.
107 */
108
109#define VMADDR_CID_HYPERVISOR 0
110
111/* This CID is specific to VMCI and can be considered reserved (even VMCI
112 * doesn't use it anymore, it's a legacy value from an older release).
113 */
114
115#define VMADDR_CID_RESERVED 1
116
117/* Use this as the destination CID in an address when referring to the host
118 * (any process other than the hypervisor). VMCI relies on it being 2, but
119 * this would be useful for other transports too.
120 */
121
122#define VMADDR_CID_HOST 2
123
124/* Invalid vSockets version. */
125
126#define VM_SOCKETS_INVALID_VERSION -1U
127
128/* The epoch (first) component of the vSockets version. A single byte
129 * representing the epoch component of the vSockets version.
130 */
131
132#define VM_SOCKETS_VERSION_EPOCH(_v) (((_v) & 0xFF000000) >> 24)
133
134/* The major (second) component of the vSockets version. A single byte
135 * representing the major component of the vSockets version. Typically
136 * changes for every major release of a product.
137 */
138
139#define VM_SOCKETS_VERSION_MAJOR(_v) (((_v) & 0x00FF0000) >> 16)
140
141/* The minor (third) component of the vSockets version. Two bytes representing
142 * the minor component of the vSockets version.
143 */
144
145#define VM_SOCKETS_VERSION_MINOR(_v) (((_v) & 0x0000FFFF))
146
147/* Address structure for vSockets. The address family should be set to
148 * whatever vmci_sock_get_af_value_fd() returns. The structure members should
149 * all align on their natural boundaries without resorting to compiler packing
150 * directives. The total size of this structure should be exactly the same as
151 * that of struct sockaddr.
152 */
153
154struct sockaddr_vm {
155 sa_family_t svm_family;
156 unsigned short svm_reserved1;
157 unsigned int svm_port;
158 unsigned int svm_cid;
159 unsigned char svm_zero[sizeof(struct sockaddr) -
160 sizeof(sa_family_t) -
161 sizeof(unsigned short) -
162 sizeof(unsigned int) - sizeof(unsigned int)];
163};
164
165#define IOCTL_VM_SOCKETS_GET_LOCAL_CID _IO(7, 0xb9)
166
167#if defined(__KERNEL__)
168int vm_sockets_get_local_cid(void);
169#endif
170
171#endif