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