]> git.ipfire.org Git - thirdparty/open-vm-tools.git/commitdiff
Fix VMCISock_GetAFValue() for upstream vsocket testing
authorVMware, Inc <>
Fri, 12 Apr 2013 19:48:26 +0000 (12:48 -0700)
committerDmitry Torokhov <dtor@vmware.com>
Wed, 17 Apr 2013 19:16:54 +0000 (12:16 -0700)
The Tools driver exposes an IOCTL to get the address family, since
it's not fixed.  The upstream driver was given a fixed address family,
so it doesn't need this IOCTL.  But our tests (and other apps) still
try to use the IOCTL, which causes them to fail with the upstream
driver.  Fix our header (the Tools version) so that it can cope with
both.

Note: not very performant, so best to cache the result if possible.
The test suite common code already caches it.

Signed-off-by: Dmitry Torokhov <dtor@vmware.com>
open-vm-tools/lib/include/vmci_sockets.h

index 7609250bad64bd8953eeafdf23aaacde34b95319..e31f39e74eb206a36a753af70895a9c91731bf0b 100644 (file)
@@ -621,6 +621,29 @@ struct uuid_2_cid {
       int fd;
       int family;
 
+#if defined(linux)
+      /*
+       * vSockets is now in mainline kernel with address family 40.  As part
+       * of upstreaming, we removed the IOCTL we use below to determine the
+       * address family.  So to handle both a new and old kernel we do this:
+       * 1. Check if our family already exists by making a socket with it.
+       *    Some weird kernel might claim this too, but it's very unlikely
+       *    (Linus' tree has us at 40, and that's what we care about).
+       * 2. If that fails, try the normal IOCTL path, since it's probably an
+       *    older kernel with vSockets from Tools.
+       * 3. If that fails, then vSockets really isn't available.
+       */
+#define AF_VSOCK_LOCAL 40
+      {
+         int s = socket(AF_VSOCK_LOCAL, SOCK_DGRAM, 0);
+         if (s != -1) {
+            close(s);
+            return AF_VSOCK_LOCAL;
+         }
+      }
+#undef AF_VSOCK_LOCAL
+#endif // linux
+
       fd = open(VMCI_SOCKETS_DEFAULT_DEVICE, O_RDWR);
       if (fd < 0) {
          fd = open(VMCI_SOCKETS_CLASSIC_ESX_DEVICE, O_RDWR);