zig

fork of https://codeberg.org/ziglang/zig
Log | Files | Refs | README | LICENSE

vm_sockets.h (7353B) - Raw


      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 _VM_SOCKETS_H
     18 #define _VM_SOCKETS_H
     19 
     20 #include <linux/socket.h>
     21 #include <linux/types.h>
     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 determining if a socket is trusted.  Use as the option name
     56  * in getsockopt(3) to determine if a socket is trusted.  The value is a
     57  * signed integer.
     58  */
     59 
     60 #define SO_VM_SOCKETS_TRUSTED 5
     61 
     62 /* Option name for STREAM socket connection timeout.  Use as the option name
     63  * in setsockopt(3) or getsockopt(3) to set or get the connection
     64  * timeout for a STREAM socket.
     65  */
     66 
     67 #define SO_VM_SOCKETS_CONNECT_TIMEOUT_OLD 6
     68 
     69 /* Option name for using non-blocking send/receive.  Use as the option name
     70  * for setsockopt(3) or getsockopt(3) to set or get the non-blocking
     71  * transmit/receive flag for a STREAM socket.  This flag determines whether
     72  * send() and recv() can be called in non-blocking contexts for the given
     73  * socket.  The value is a signed integer.
     74  *
     75  * This option is only relevant to kernel endpoints, where descheduling the
     76  * thread of execution is not allowed, for example, while holding a spinlock.
     77  * It is not to be confused with conventional non-blocking socket operations.
     78  *
     79  * Only available for hypervisor endpoints.
     80  */
     81 
     82 #define SO_VM_SOCKETS_NONBLOCK_TXRX 7
     83 
     84 #define SO_VM_SOCKETS_CONNECT_TIMEOUT_NEW 8
     85 
     86 #if __BITS_PER_LONG == 64 || (defined(__x86_64__) && defined(__ILP32__))
     87 #define SO_VM_SOCKETS_CONNECT_TIMEOUT SO_VM_SOCKETS_CONNECT_TIMEOUT_OLD
     88 #else
     89 #define SO_VM_SOCKETS_CONNECT_TIMEOUT \
     90 	(sizeof(time_t) == sizeof(__kernel_long_t) ? SO_VM_SOCKETS_CONNECT_TIMEOUT_OLD : SO_VM_SOCKETS_CONNECT_TIMEOUT_NEW)
     91 #endif
     92 
     93 /* The vSocket equivalent of INADDR_ANY.  This works for the svm_cid field of
     94  * sockaddr_vm and indicates the context ID of the current endpoint.
     95  */
     96 
     97 #define VMADDR_CID_ANY -1U
     98 
     99 /* Bind to any available port.  Works for the svm_port field of
    100  * sockaddr_vm.
    101  */
    102 
    103 #define VMADDR_PORT_ANY -1U
    104 
    105 /* Use this as the destination CID in an address when referring to the
    106  * hypervisor.  VMCI relies on it being 0, but this would be useful for other
    107  * transports too.
    108  */
    109 
    110 #define VMADDR_CID_HYPERVISOR 0
    111 
    112 /* Use this as the destination CID in an address when referring to the
    113  * local communication (loopback).
    114  * (This was VMADDR_CID_RESERVED, but even VMCI doesn't use it anymore,
    115  * it was a legacy value from an older release).
    116  */
    117 
    118 #define VMADDR_CID_LOCAL 1
    119 
    120 /* Use this as the destination CID in an address when referring to the host
    121  * (any process other than the hypervisor).  VMCI relies on it being 2, but
    122  * this would be useful for other transports too.
    123  */
    124 
    125 #define VMADDR_CID_HOST 2
    126 
    127 /* The current default use case for the vsock channel is the following:
    128  * local vsock communication between guest and host and nested VMs setup.
    129  * In addition to this, implicitly, the vsock packets are forwarded to the host
    130  * if no host->guest vsock transport is set.
    131  *
    132  * Set this flag value in the sockaddr_vm corresponding field if the vsock
    133  * packets need to be always forwarded to the host. Using this behavior,
    134  * vsock communication between sibling VMs can be setup.
    135  *
    136  * This way can explicitly distinguish between vsock channels created for
    137  * different use cases, such as nested VMs (or local communication between
    138  * guest and host) and sibling VMs.
    139  *
    140  * The flag can be set in the connect logic in the user space application flow.
    141  * In the listen logic (from kernel space) the flag is set on the remote peer
    142  * address. This happens for an incoming connection when it is routed from the
    143  * host and comes from the guest (local CID and remote CID > VMADDR_CID_HOST).
    144  */
    145 #define VMADDR_FLAG_TO_HOST 0x01
    146 
    147 /* Invalid vSockets version. */
    148 
    149 #define VM_SOCKETS_INVALID_VERSION -1U
    150 
    151 /* The epoch (first) component of the vSockets version.  A single byte
    152  * representing the epoch component of the vSockets version.
    153  */
    154 
    155 #define VM_SOCKETS_VERSION_EPOCH(_v) (((_v) & 0xFF000000) >> 24)
    156 
    157 /* The major (second) component of the vSockets version.   A single byte
    158  * representing the major component of the vSockets version.  Typically
    159  * changes for every major release of a product.
    160  */
    161 
    162 #define VM_SOCKETS_VERSION_MAJOR(_v) (((_v) & 0x00FF0000) >> 16)
    163 
    164 /* The minor (third) component of the vSockets version.  Two bytes representing
    165  * the minor component of the vSockets version.
    166  */
    167 
    168 #define VM_SOCKETS_VERSION_MINOR(_v) (((_v) & 0x0000FFFF))
    169 
    170 /* Address structure for vSockets.   The address family should be set to
    171  * AF_VSOCK.  The structure members should all align on their natural
    172  * boundaries without resorting to compiler packing directives.  The total size
    173  * of this structure should be exactly the same as that of struct sockaddr.
    174  */
    175 
    176 struct sockaddr_vm {
    177 	__kernel_sa_family_t svm_family;
    178 	unsigned short svm_reserved1;
    179 	unsigned int svm_port;
    180 	unsigned int svm_cid;
    181 	__u8 svm_flags;
    182 	unsigned char svm_zero[sizeof(struct sockaddr) -
    183 			       sizeof(sa_family_t) -
    184 			       sizeof(unsigned short) -
    185 			       sizeof(unsigned int) -
    186 			       sizeof(unsigned int) -
    187 			       sizeof(__u8)];
    188 };
    189 
    190 #define IOCTL_VM_SOCKETS_GET_LOCAL_CID		_IO(7, 0xb9)
    191 
    192 /* MSG_ZEROCOPY notifications are encoded in the standard error format,
    193  * sock_extended_err. See Documentation/networking/msg_zerocopy.rst in
    194  * kernel source tree for more details.
    195  */
    196 
    197 /* 'cmsg_level' field value of 'struct cmsghdr' for notification parsing
    198  * when MSG_ZEROCOPY flag is used on transmissions.
    199  */
    200 
    201 #define SOL_VSOCK	287
    202 
    203 /* 'cmsg_type' field value of 'struct cmsghdr' for notification parsing
    204  * when MSG_ZEROCOPY flag is used on transmissions.
    205  */
    206 
    207 #define VSOCK_RECVERR	1
    208 
    209 #endif /* _VM_SOCKETS_H */