vm_sockets.h 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211
  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. #ifndef _UAPI_VM_SOCKETS_H
  17. #define _UAPI_VM_SOCKETS_H
  18. #include <linux/socket.h>
  19. #include <linux/types.h>
  20. /* Option name for STREAM socket buffer size. Use as the option name in
  21. * setsockopt(3) or getsockopt(3) to set or get an unsigned long long that
  22. * specifies the size of the buffer underlying a vSockets STREAM socket.
  23. * Value is clamped to the MIN and MAX.
  24. */
  25. #define SO_VM_SOCKETS_BUFFER_SIZE 0
  26. /* Option name for STREAM socket minimum buffer size. Use as the option name
  27. * in setsockopt(3) or getsockopt(3) to set or get an unsigned long long that
  28. * specifies the minimum size allowed for the buffer underlying a vSockets
  29. * STREAM socket.
  30. */
  31. #define SO_VM_SOCKETS_BUFFER_MIN_SIZE 1
  32. /* Option name for STREAM socket maximum buffer size. Use as the option name
  33. * in setsockopt(3) or getsockopt(3) to set or get an unsigned long long
  34. * that specifies the maximum size allowed for the buffer underlying a
  35. * vSockets STREAM socket.
  36. */
  37. #define SO_VM_SOCKETS_BUFFER_MAX_SIZE 2
  38. /* Option name for socket peer's host-specific VM ID. Use as the option name
  39. * in getsockopt(3) to get a host-specific identifier for the peer endpoint's
  40. * VM. The identifier is a signed integer.
  41. * Only available for hypervisor endpoints.
  42. */
  43. #define SO_VM_SOCKETS_PEER_HOST_VM_ID 3
  44. /* Option name for determining if a socket is trusted. Use as the option name
  45. * in getsockopt(3) to determine if a socket is trusted. The value is a
  46. * signed integer.
  47. */
  48. #define SO_VM_SOCKETS_TRUSTED 5
  49. /* Option name for STREAM socket connection timeout. Use as the option name
  50. * in setsockopt(3) or getsockopt(3) to set or get the connection
  51. * timeout for a STREAM socket.
  52. */
  53. #define SO_VM_SOCKETS_CONNECT_TIMEOUT_OLD 6
  54. /* Option name for using non-blocking send/receive. Use as the option name
  55. * for setsockopt(3) or getsockopt(3) to set or get the non-blocking
  56. * transmit/receive flag for a STREAM socket. This flag determines whether
  57. * send() and recv() can be called in non-blocking contexts for the given
  58. * socket. The value is a signed integer.
  59. *
  60. * This option is only relevant to kernel endpoints, where descheduling the
  61. * thread of execution is not allowed, for example, while holding a spinlock.
  62. * It is not to be confused with conventional non-blocking socket operations.
  63. *
  64. * Only available for hypervisor endpoints.
  65. */
  66. #define SO_VM_SOCKETS_NONBLOCK_TXRX 7
  67. #define SO_VM_SOCKETS_CONNECT_TIMEOUT_NEW 8
  68. #if !defined(__KERNEL__)
  69. #if __BITS_PER_LONG == 64 || (defined(__x86_64__) && defined(__ILP32__))
  70. #define SO_VM_SOCKETS_CONNECT_TIMEOUT SO_VM_SOCKETS_CONNECT_TIMEOUT_OLD
  71. #else
  72. #define SO_VM_SOCKETS_CONNECT_TIMEOUT \
  73. (sizeof(time_t) == sizeof(__kernel_long_t) ? SO_VM_SOCKETS_CONNECT_TIMEOUT_OLD : SO_VM_SOCKETS_CONNECT_TIMEOUT_NEW)
  74. #endif
  75. #endif
  76. /* The vSocket equivalent of INADDR_ANY. This works for the svm_cid field of
  77. * sockaddr_vm and indicates the context ID of the current endpoint.
  78. */
  79. #define VMADDR_CID_ANY -1U
  80. /* Bind to any available port. Works for the svm_port field of
  81. * sockaddr_vm.
  82. */
  83. #define VMADDR_PORT_ANY -1U
  84. /* Use this as the destination CID in an address when referring to the
  85. * hypervisor. VMCI relies on it being 0, but this would be useful for other
  86. * transports too.
  87. */
  88. #define VMADDR_CID_HYPERVISOR 0
  89. /* Use this as the destination CID in an address when referring to the
  90. * local communication (loopback).
  91. * (This was VMADDR_CID_RESERVED, but even VMCI doesn't use it anymore,
  92. * it was a legacy value from an older release).
  93. */
  94. #define VMADDR_CID_LOCAL 1
  95. /* Use this as the destination CID in an address when referring to the host
  96. * (any process other than the hypervisor). VMCI relies on it being 2, but
  97. * this would be useful for other transports too.
  98. */
  99. #define VMADDR_CID_HOST 2
  100. /* The current default use case for the vsock channel is the following:
  101. * local vsock communication between guest and host and nested VMs setup.
  102. * In addition to this, implicitly, the vsock packets are forwarded to the host
  103. * if no host->guest vsock transport is set.
  104. *
  105. * Set this flag value in the sockaddr_vm corresponding field if the vsock
  106. * packets need to be always forwarded to the host. Using this behavior,
  107. * vsock communication between sibling VMs can be setup.
  108. *
  109. * This way can explicitly distinguish between vsock channels created for
  110. * different use cases, such as nested VMs (or local communication between
  111. * guest and host) and sibling VMs.
  112. *
  113. * The flag can be set in the connect logic in the user space application flow.
  114. * In the listen logic (from kernel space) the flag is set on the remote peer
  115. * address. This happens for an incoming connection when it is routed from the
  116. * host and comes from the guest (local CID and remote CID > VMADDR_CID_HOST).
  117. */
  118. #define VMADDR_FLAG_TO_HOST 0x01
  119. /* Invalid vSockets version. */
  120. #define VM_SOCKETS_INVALID_VERSION -1U
  121. /* The epoch (first) component of the vSockets version. A single byte
  122. * representing the epoch component of the vSockets version.
  123. */
  124. #define VM_SOCKETS_VERSION_EPOCH(_v) (((_v) & 0xFF000000) >> 24)
  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. #define VM_SOCKETS_VERSION_MAJOR(_v) (((_v) & 0x00FF0000) >> 16)
  130. /* The minor (third) component of the vSockets version. Two bytes representing
  131. * the minor component of the vSockets version.
  132. */
  133. #define VM_SOCKETS_VERSION_MINOR(_v) (((_v) & 0x0000FFFF))
  134. /* Address structure for vSockets. The address family should be set to
  135. * AF_VSOCK. The structure members should all align on their natural
  136. * boundaries without resorting to compiler packing directives. The total size
  137. * of this structure should be exactly the same as that of struct sockaddr.
  138. */
  139. struct sockaddr_vm {
  140. __kernel_sa_family_t svm_family;
  141. unsigned short svm_reserved1;
  142. unsigned int svm_port;
  143. unsigned int svm_cid;
  144. __u8 svm_flags;
  145. unsigned char svm_zero[sizeof(struct sockaddr) -
  146. sizeof(sa_family_t) -
  147. sizeof(unsigned short) -
  148. sizeof(unsigned int) -
  149. sizeof(unsigned int) -
  150. sizeof(__u8)];
  151. };
  152. #define IOCTL_VM_SOCKETS_GET_LOCAL_CID _IO(7, 0xb9)
  153. /* MSG_ZEROCOPY notifications are encoded in the standard error format,
  154. * sock_extended_err. See Documentation/networking/msg_zerocopy.rst in
  155. * kernel source tree for more details.
  156. */
  157. /* 'cmsg_level' field value of 'struct cmsghdr' for notification parsing
  158. * when MSG_ZEROCOPY flag is used on transmissions.
  159. */
  160. #define SOL_VSOCK 287
  161. /* 'cmsg_type' field value of 'struct cmsghdr' for notification parsing
  162. * when MSG_ZEROCOPY flag is used on transmissions.
  163. */
  164. #define VSOCK_RECVERR 1
  165. #endif /* _UAPI_VM_SOCKETS_H */