From: VMware, Inc <> Date: Fri, 12 Apr 2013 19:48:26 +0000 (-0700) Subject: Fix VMCISock_GetAFValue() for upstream vsocket testing X-Git-Tag: 2013.04.16-1098359~42 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=143d82c15d0cbe1dc8f166e7f89fe14a15def724;p=thirdparty%2Fopen-vm-tools.git Fix VMCISock_GetAFValue() for upstream vsocket testing 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 --- diff --git a/open-vm-tools/lib/include/vmci_sockets.h b/open-vm-tools/lib/include/vmci_sockets.h index 7609250ba..e31f39e74 100644 --- a/open-vm-tools/lib/include/vmci_sockets.h +++ b/open-vm-tools/lib/include/vmci_sockets.h @@ -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);