vm_sockets.h 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. /*
  2. * VMware vSockets Driver
  3. *
  4. * Copyright (C) 2007-2013 VMware, Inc. All rights reserved.
  5. *
  6. * This program is free software; you can redistribute it and/or modify it
  7. * under the terms of the GNU General Public License as published by the Free
  8. * Software Foundation version 2 and no later version.
  9. *
  10. * This program is distributed in the hope that it will be useful, but WITHOUT
  11. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  12. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  13. * more details.
  14. */
  15. #ifndef _VM_SOCKETS_H_
  16. #define _VM_SOCKETS_H_
  17. #if !defined(__KERNEL__)
  18. #include <sys/socket.h>
  19. #endif
  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 socket's service label. Use as the option name in
  45. * setsockopt(3) or getsockopt(3) to set or get the service label for a socket.
  46. * The service label is a C-style NUL-terminated string. Only available for
  47. * hypervisor endpoints.
  48. */
  49. #define SO_VM_SOCKETS_SERVICE_LABEL 4
  50. /* Option name for determining if a socket is trusted. Use as the option name
  51. * in getsockopt(3) to determine if a socket is trusted. The value is a
  52. * signed integer.
  53. */
  54. #define SO_VM_SOCKETS_TRUSTED 5
  55. /* Option name for STREAM socket connection timeout. Use as the option name
  56. * in setsockopt(3) or getsockopt(3) to set or get the connection
  57. * timeout for a STREAM socket.
  58. */
  59. #define SO_VM_SOCKETS_CONNECT_TIMEOUT 6
  60. /* Option name for using non-blocking send/receive. Use as the option name
  61. * for setsockopt(3) or getsockopt(3) to set or get the non-blocking
  62. * transmit/receive flag for a STREAM socket. This flag determines whether
  63. * send() and recv() can be called in non-blocking contexts for the given
  64. * socket. The value is a signed integer.
  65. *
  66. * This option is only relevant to kernel endpoints, where descheduling the
  67. * thread of execution is not allowed, for example, while holding a spinlock.
  68. * It is not to be confused with conventional non-blocking socket operations.
  69. *
  70. * Only available for hypervisor endpoints.
  71. */
  72. #define SO_VM_SOCKETS_NONBLOCK_TXRX 7
  73. /* The vSocket equivalent of INADDR_ANY. This works for the svm_cid field of
  74. * sockaddr_vm and indicates the context ID of the current endpoint.
  75. */
  76. #define VMADDR_CID_ANY -1U
  77. /* Bind to any available port. Works for the svm_port field of
  78. * sockaddr_vm.
  79. */
  80. #define VMADDR_PORT_ANY -1U
  81. /* Use this as the destination CID in an address when referring to the
  82. * hypervisor. VMCI relies on it being 0, but this would be useful for other
  83. * transports too.
  84. */
  85. #define VMADDR_CID_HYPERVISOR 0
  86. /* This CID is specific to VMCI and can be considered reserved (even VMCI
  87. * doesn't use it anymore, it's a legacy value from an older release).
  88. */
  89. #define VMADDR_CID_RESERVED 1
  90. /* Use this as the destination CID in an address when referring to the host
  91. * (any process other than the hypervisor). VMCI relies on it being 2, but
  92. * this would be useful for other transports too.
  93. */
  94. #define VMADDR_CID_HOST 2
  95. /* Invalid vSockets version. */
  96. #define VM_SOCKETS_INVALID_VERSION -1U
  97. /* The epoch (first) component of the vSockets version. A single byte
  98. * representing the epoch component of the vSockets version.
  99. */
  100. #define VM_SOCKETS_VERSION_EPOCH(_v) (((_v) & 0xFF000000) >> 24)
  101. /* The major (second) component of the vSockets version. A single byte
  102. * representing the major component of the vSockets version. Typically
  103. * changes for every major release of a product.
  104. */
  105. #define VM_SOCKETS_VERSION_MAJOR(_v) (((_v) & 0x00FF0000) >> 16)
  106. /* The minor (third) component of the vSockets version. Two bytes representing
  107. * the minor component of the vSockets version.
  108. */
  109. #define VM_SOCKETS_VERSION_MINOR(_v) (((_v) & 0x0000FFFF))
  110. /* Address structure for vSockets. The address family should be set to
  111. * whatever vmci_sock_get_af_value_fd() returns. The structure members should
  112. * all align on their natural boundaries without resorting to compiler packing
  113. * directives. The total size of this structure should be exactly the same as
  114. * that of struct sockaddr.
  115. */
  116. struct sockaddr_vm {
  117. sa_family_t svm_family;
  118. unsigned short svm_reserved1;
  119. unsigned int svm_port;
  120. unsigned int svm_cid;
  121. unsigned char svm_zero[sizeof(struct sockaddr) -
  122. sizeof(sa_family_t) -
  123. sizeof(unsigned short) -
  124. sizeof(unsigned int) - sizeof(unsigned int)];
  125. };
  126. #define IOCTL_VM_SOCKETS_GET_LOCAL_CID _IO(7, 0xb9)
  127. #if defined(__KERNEL__)
  128. int vm_sockets_get_local_cid(void);
  129. #endif
  130. #endif