Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
0002 /*
0003  * VMware vSockets Driver
0004  *
0005  * Copyright (C) 2007-2013 VMware, Inc. All rights reserved.
0006  *
0007  * This program is free software; you can redistribute it and/or modify it
0008  * under the terms of the GNU General Public License as published by the Free
0009  * Software Foundation version 2 and no later version.
0010  *
0011  * This program is distributed in the hope that it will be useful, but WITHOUT
0012  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0013  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
0014  * more details.
0015  */
0016 
0017 #ifndef _UAPI_VM_SOCKETS_H
0018 #define _UAPI_VM_SOCKETS_H
0019 
0020 #include <linux/socket.h>
0021 #include <linux/types.h>
0022 
0023 /* Option name for STREAM socket buffer size.  Use as the option name in
0024  * setsockopt(3) or getsockopt(3) to set or get an unsigned long long that
0025  * specifies the size of the buffer underlying a vSockets STREAM socket.
0026  * Value is clamped to the MIN and MAX.
0027  */
0028 
0029 #define SO_VM_SOCKETS_BUFFER_SIZE 0
0030 
0031 /* Option name for STREAM socket minimum buffer size.  Use as the option name
0032  * in setsockopt(3) or getsockopt(3) to set or get an unsigned long long that
0033  * specifies the minimum size allowed for the buffer underlying a vSockets
0034  * STREAM socket.
0035  */
0036 
0037 #define SO_VM_SOCKETS_BUFFER_MIN_SIZE 1
0038 
0039 /* Option name for STREAM socket maximum buffer size.  Use as the option name
0040  * in setsockopt(3) or getsockopt(3) to set or get an unsigned long long
0041  * that specifies the maximum size allowed for the buffer underlying a
0042  * vSockets STREAM socket.
0043  */
0044 
0045 #define SO_VM_SOCKETS_BUFFER_MAX_SIZE 2
0046 
0047 /* Option name for socket peer's host-specific VM ID.  Use as the option name
0048  * in getsockopt(3) to get a host-specific identifier for the peer endpoint's
0049  * VM.  The identifier is a signed integer.
0050  * Only available for hypervisor endpoints.
0051  */
0052 
0053 #define SO_VM_SOCKETS_PEER_HOST_VM_ID 3
0054 
0055 /* Option name for determining if a socket is trusted.  Use as the option name
0056  * in getsockopt(3) to determine if a socket is trusted.  The value is a
0057  * signed integer.
0058  */
0059 
0060 #define SO_VM_SOCKETS_TRUSTED 5
0061 
0062 /* Option name for STREAM socket connection timeout.  Use as the option name
0063  * in setsockopt(3) or getsockopt(3) to set or get the connection
0064  * timeout for a STREAM socket.
0065  */
0066 
0067 #define SO_VM_SOCKETS_CONNECT_TIMEOUT_OLD 6
0068 
0069 /* Option name for using non-blocking send/receive.  Use as the option name
0070  * for setsockopt(3) or getsockopt(3) to set or get the non-blocking
0071  * transmit/receive flag for a STREAM socket.  This flag determines whether
0072  * send() and recv() can be called in non-blocking contexts for the given
0073  * socket.  The value is a signed integer.
0074  *
0075  * This option is only relevant to kernel endpoints, where descheduling the
0076  * thread of execution is not allowed, for example, while holding a spinlock.
0077  * It is not to be confused with conventional non-blocking socket operations.
0078  *
0079  * Only available for hypervisor endpoints.
0080  */
0081 
0082 #define SO_VM_SOCKETS_NONBLOCK_TXRX 7
0083 
0084 #define SO_VM_SOCKETS_CONNECT_TIMEOUT_NEW 8
0085 
0086 #if !defined(__KERNEL__)
0087 #if __BITS_PER_LONG == 64 || (defined(__x86_64__) && defined(__ILP32__))
0088 #define SO_VM_SOCKETS_CONNECT_TIMEOUT SO_VM_SOCKETS_CONNECT_TIMEOUT_OLD
0089 #else
0090 #define SO_VM_SOCKETS_CONNECT_TIMEOUT \
0091     (sizeof(time_t) == sizeof(__kernel_long_t) ? SO_VM_SOCKETS_CONNECT_TIMEOUT_OLD : SO_VM_SOCKETS_CONNECT_TIMEOUT_NEW)
0092 #endif
0093 #endif
0094 
0095 /* The vSocket equivalent of INADDR_ANY.  This works for the svm_cid field of
0096  * sockaddr_vm and indicates the context ID of the current endpoint.
0097  */
0098 
0099 #define VMADDR_CID_ANY -1U
0100 
0101 /* Bind to any available port.  Works for the svm_port field of
0102  * sockaddr_vm.
0103  */
0104 
0105 #define VMADDR_PORT_ANY -1U
0106 
0107 /* Use this as the destination CID in an address when referring to the
0108  * hypervisor.  VMCI relies on it being 0, but this would be useful for other
0109  * transports too.
0110  */
0111 
0112 #define VMADDR_CID_HYPERVISOR 0
0113 
0114 /* Use this as the destination CID in an address when referring to the
0115  * local communication (loopback).
0116  * (This was VMADDR_CID_RESERVED, but even VMCI doesn't use it anymore,
0117  * it was a legacy value from an older release).
0118  */
0119 
0120 #define VMADDR_CID_LOCAL 1
0121 
0122 /* Use this as the destination CID in an address when referring to the host
0123  * (any process other than the hypervisor).  VMCI relies on it being 2, but
0124  * this would be useful for other transports too.
0125  */
0126 
0127 #define VMADDR_CID_HOST 2
0128 
0129 /* The current default use case for the vsock channel is the following:
0130  * local vsock communication between guest and host and nested VMs setup.
0131  * In addition to this, implicitly, the vsock packets are forwarded to the host
0132  * if no host->guest vsock transport is set.
0133  *
0134  * Set this flag value in the sockaddr_vm corresponding field if the vsock
0135  * packets need to be always forwarded to the host. Using this behavior,
0136  * vsock communication between sibling VMs can be setup.
0137  *
0138  * This way can explicitly distinguish between vsock channels created for
0139  * different use cases, such as nested VMs (or local communication between
0140  * guest and host) and sibling VMs.
0141  *
0142  * The flag can be set in the connect logic in the user space application flow.
0143  * In the listen logic (from kernel space) the flag is set on the remote peer
0144  * address. This happens for an incoming connection when it is routed from the
0145  * host and comes from the guest (local CID and remote CID > VMADDR_CID_HOST).
0146  */
0147 #define VMADDR_FLAG_TO_HOST 0x01
0148 
0149 /* Invalid vSockets version. */
0150 
0151 #define VM_SOCKETS_INVALID_VERSION -1U
0152 
0153 /* The epoch (first) component of the vSockets version.  A single byte
0154  * representing the epoch component of the vSockets version.
0155  */
0156 
0157 #define VM_SOCKETS_VERSION_EPOCH(_v) (((_v) & 0xFF000000) >> 24)
0158 
0159 /* The major (second) component of the vSockets version.   A single byte
0160  * representing the major component of the vSockets version.  Typically
0161  * changes for every major release of a product.
0162  */
0163 
0164 #define VM_SOCKETS_VERSION_MAJOR(_v) (((_v) & 0x00FF0000) >> 16)
0165 
0166 /* The minor (third) component of the vSockets version.  Two bytes representing
0167  * the minor component of the vSockets version.
0168  */
0169 
0170 #define VM_SOCKETS_VERSION_MINOR(_v) (((_v) & 0x0000FFFF))
0171 
0172 /* Address structure for vSockets.   The address family should be set to
0173  * AF_VSOCK.  The structure members should all align on their natural
0174  * boundaries without resorting to compiler packing directives.  The total size
0175  * of this structure should be exactly the same as that of struct sockaddr.
0176  */
0177 
0178 struct sockaddr_vm {
0179     __kernel_sa_family_t svm_family;
0180     unsigned short svm_reserved1;
0181     unsigned int svm_port;
0182     unsigned int svm_cid;
0183     __u8 svm_flags;
0184     unsigned char svm_zero[sizeof(struct sockaddr) -
0185                    sizeof(sa_family_t) -
0186                    sizeof(unsigned short) -
0187                    sizeof(unsigned int) -
0188                    sizeof(unsigned int) -
0189                    sizeof(__u8)];
0190 };
0191 
0192 #define IOCTL_VM_SOCKETS_GET_LOCAL_CID      _IO(7, 0xb9)
0193 
0194 #endif /* _UAPI_VM_SOCKETS_H */