1 /* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */ 2 /* 3 * VMware vSockets Driver 4 * 5 * Copyright (C) 2007-2013 VMware, Inc. All rights reserved. 6 * 7 * This program is free software; you can redistribute it and/or modify it 8 * under the terms of the GNU General Public License as published by the Free 9 * Software Foundation version 2 and no later version. 10 * 11 * This program is distributed in the hope that it will be useful, but WITHOUT 12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 14 * more details. 15 */ 16 17 #ifndef _UAPI_VM_SOCKETS_H 18 #define _UAPI_VM_SOCKETS_H 19 20 #ifndef __KERNEL__ 21 #include <sys/socket.h> /* for struct sockaddr and sa_family_t */ 22 #endif 23 24 #include <linux/socket.h> 25 #include <linux/types.h> 26 27 /* Option name for STREAM socket buffer size. Use as the option name in 28 * setsockopt(3) or getsockopt(3) to set or get an unsigned long long that 29 * specifies the size of the buffer underlying a vSockets STREAM socket. 30 * Value is clamped to the MIN and MAX. 31 */ 32 33 #define SO_VM_SOCKETS_BUFFER_SIZE 0 34 35 /* Option name for STREAM socket minimum buffer size. Use as the option name 36 * in setsockopt(3) or getsockopt(3) to set or get an unsigned long long that 37 * specifies the minimum size allowed for the buffer underlying a vSockets 38 * STREAM socket. 39 */ 40 41 #define SO_VM_SOCKETS_BUFFER_MIN_SIZE 1 42 43 /* Option name for STREAM socket maximum buffer size. Use as the option name 44 * in setsockopt(3) or getsockopt(3) to set or get an unsigned long long 45 * that specifies the maximum size allowed for the buffer underlying a 46 * vSockets STREAM socket. 47 */ 48 49 #define SO_VM_SOCKETS_BUFFER_MAX_SIZE 2 50 51 /* Option name for socket peer's host-specific VM ID. Use as the option name 52 * in getsockopt(3) to get a host-specific identifier for the peer endpoint's 53 * VM. The identifier is a signed integer. 54 * Only available for hypervisor endpoints. 55 */ 56 57 #define SO_VM_SOCKETS_PEER_HOST_VM_ID 3 58 59 /* Option name for determining if a socket is trusted. Use as the option name 60 * in getsockopt(3) to determine if a socket is trusted. The value is a 61 * signed integer. 62 */ 63 64 #define SO_VM_SOCKETS_TRUSTED 5 65 66 /* Option name for STREAM socket connection timeout. Use as the option name 67 * in setsockopt(3) or getsockopt(3) to set or get the connection 68 * timeout for a STREAM socket. 69 */ 70 71 #define SO_VM_SOCKETS_CONNECT_TIMEOUT_OLD 6 72 73 /* Option name for using non-blocking send/receive. Use as the option name 74 * for setsockopt(3) or getsockopt(3) to set or get the non-blocking 75 * transmit/receive flag for a STREAM socket. This flag determines whether 76 * send() and recv() can be called in non-blocking contexts for the given 77 * socket. The value is a signed integer. 78 * 79 * This option is only relevant to kernel endpoints, where descheduling the 80 * thread of execution is not allowed, for example, while holding a spinlock. 81 * It is not to be confused with conventional non-blocking socket operations. 82 * 83 * Only available for hypervisor endpoints. 84 */ 85 86 #define SO_VM_SOCKETS_NONBLOCK_TXRX 7 87 88 #define SO_VM_SOCKETS_CONNECT_TIMEOUT_NEW 8 89 90 #if !defined(__KERNEL__) 91 #if __BITS_PER_LONG == 64 || (defined(__x86_64__) && defined(__ILP32__)) 92 #define SO_VM_SOCKETS_CONNECT_TIMEOUT SO_VM_SOCKETS_CONNECT_TIMEOUT_OLD 93 #else 94 #define SO_VM_SOCKETS_CONNECT_TIMEOUT \ 95 (sizeof(time_t) == sizeof(__kernel_long_t) ? SO_VM_SOCKETS_CONNECT_TIMEOUT_OLD : SO_VM_SOCKETS_CONNECT_TIMEOUT_NEW) 96 #endif 97 #endif 98 99 /* The vSocket equivalent of INADDR_ANY. This works for the svm_cid field of 100 * sockaddr_vm and indicates the context ID of the current endpoint. 101 */ 102 103 #define VMADDR_CID_ANY -1U 104 105 /* Bind to any available port. Works for the svm_port field of 106 * sockaddr_vm. 107 */ 108 109 #define VMADDR_PORT_ANY -1U 110 111 /* Use this as the destination CID in an address when referring to the 112 * hypervisor. VMCI relies on it being 0, but this would be useful for other 113 * transports too. 114 */ 115 116 #define VMADDR_CID_HYPERVISOR 0 117 118 /* Use this as the destination CID in an address when referring to the 119 * local communication (loopback). 120 * (This was VMADDR_CID_RESERVED, but even VMCI doesn't use it anymore, 121 * it was a legacy value from an older release). 122 */ 123 124 #define VMADDR_CID_LOCAL 1 125 126 /* Use this as the destination CID in an address when referring to the host 127 * (any process other than the hypervisor). VMCI relies on it being 2, but 128 * this would be useful for other transports too. 129 */ 130 131 #define VMADDR_CID_HOST 2 132 133 /* The current default use case for the vsock channel is the following: 134 * local vsock communication between guest and host and nested VMs setup. 135 * In addition to this, implicitly, the vsock packets are forwarded to the host 136 * if no host->guest vsock transport is set. 137 * 138 * Set this flag value in the sockaddr_vm corresponding field if the vsock 139 * packets need to be always forwarded to the host. Using this behavior, 140 * vsock communication between sibling VMs can be setup. 141 * 142 * This way can explicitly distinguish between vsock channels created for 143 * different use cases, such as nested VMs (or local communication between 144 * guest and host) and sibling VMs. 145 * 146 * The flag can be set in the connect logic in the user space application flow. 147 * In the listen logic (from kernel space) the flag is set on the remote peer 148 * address. This happens for an incoming connection when it is routed from the 149 * host and comes from the guest (local CID and remote CID > VMADDR_CID_HOST). 150 */ 151 #define VMADDR_FLAG_TO_HOST 0x01 152 153 /* Invalid vSockets version. */ 154 155 #define VM_SOCKETS_INVALID_VERSION -1U 156 157 /* The epoch (first) component of the vSockets version. A single byte 158 * representing the epoch component of the vSockets version. 159 */ 160 161 #define VM_SOCKETS_VERSION_EPOCH(_v) (((_v) & 0xFF000000) >> 24) 162 163 /* The major (second) component of the vSockets version. A single byte 164 * representing the major component of the vSockets version. Typically 165 * changes for every major release of a product. 166 */ 167 168 #define VM_SOCKETS_VERSION_MAJOR(_v) (((_v) & 0x00FF0000) >> 16) 169 170 /* The minor (third) component of the vSockets version. Two bytes representing 171 * the minor component of the vSockets version. 172 */ 173 174 #define VM_SOCKETS_VERSION_MINOR(_v) (((_v) & 0x0000FFFF)) 175 176 /* Address structure for vSockets. The address family should be set to 177 * AF_VSOCK. The structure members should all align on their natural 178 * boundaries without resorting to compiler packing directives. The total size 179 * of this structure should be exactly the same as that of struct sockaddr. 180 */ 181 182 struct sockaddr_vm { 183 __kernel_sa_family_t svm_family; 184 unsigned short svm_reserved1; 185 unsigned int svm_port; 186 unsigned int svm_cid; 187 __u8 svm_flags; 188 unsigned char svm_zero[sizeof(struct sockaddr) - 189 sizeof(sa_family_t) - 190 sizeof(unsigned short) - 191 sizeof(unsigned int) - 192 sizeof(unsigned int) - 193 sizeof(__u8)]; 194 }; 195 196 #define IOCTL_VM_SOCKETS_GET_LOCAL_CID _IO(7, 0xb9) 197 198 /* MSG_ZEROCOPY notifications are encoded in the standard error format, 199 * sock_extended_err. See Documentation/networking/msg_zerocopy.rst in 200 * kernel source tree for more details. 201 */ 202 203 /* 'cmsg_level' field value of 'struct cmsghdr' for notification parsing 204 * when MSG_ZEROCOPY flag is used on transmissions. 205 */ 206 207 #define SOL_VSOCK 287 208 209 /* 'cmsg_type' field value of 'struct cmsghdr' for notification parsing 210 * when MSG_ZEROCOPY flag is used on transmissions. 211 */ 212 213 #define VSOCK_RECVERR 1 214 215 #endif /* _UAPI_VM_SOCKETS_H */ 216