diff options
Diffstat (limited to 'src/VBox/HostDrivers/VBoxNetFlt')
22 files changed, 397 insertions, 73 deletions
diff --git a/src/VBox/HostDrivers/VBoxNetFlt/VBoxNetFlt.c b/src/VBox/HostDrivers/VBoxNetFlt/VBoxNetFlt.c index 3aca286a..fd26e831 100644 --- a/src/VBox/HostDrivers/VBoxNetFlt/VBoxNetFlt.c +++ b/src/VBox/HostDrivers/VBoxNetFlt/VBoxNetFlt.c @@ -4,7 +4,7 @@ */ /* - * Copyright (C) 2008-2009 Oracle Corporation + * Copyright (C) 2008-2012 Oracle Corporation * * This file is part of VirtualBox Open Source Edition (OSE), as * available from http://www.virtualbox.org. This file is free software; diff --git a/src/VBox/HostDrivers/VBoxNetFlt/VBoxNetFltInternal.h b/src/VBox/HostDrivers/VBoxNetFlt/VBoxNetFltInternal.h index 90182a99..6d35a322 100644 --- a/src/VBox/HostDrivers/VBoxNetFlt/VBoxNetFltInternal.h +++ b/src/VBox/HostDrivers/VBoxNetFlt/VBoxNetFltInternal.h @@ -4,7 +4,7 @@ */ /* - * Copyright (C) 2008 Oracle Corporation + * Copyright (C) 2008-2012 Oracle Corporation * * This file is part of VirtualBox Open Source Edition (OSE), as * available from http://www.virtualbox.org. This file is free software; @@ -159,6 +159,8 @@ typedef struct VBOXNETFLTINS * @{ */ /** Pointer to the device. */ struct net_device * volatile pDev; + /** MTU of host's interface. */ + uint32_t cbMtu; /** Whether we've successfully put the interface into to promiscuous mode. * This is for dealing with the ENETDOWN case. */ bool volatile fPromiscuousSet; diff --git a/src/VBox/HostDrivers/VBoxNetFlt/darwin/Info.plist b/src/VBox/HostDrivers/VBoxNetFlt/darwin/Info.plist index e1864f4a..20338308 100644 --- a/src/VBox/HostDrivers/VBoxNetFlt/darwin/Info.plist +++ b/src/VBox/HostDrivers/VBoxNetFlt/darwin/Info.plist @@ -1,3 +1,4 @@ +<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> <plist version="1.0"> <dict> diff --git a/src/VBox/HostDrivers/VBoxNetFlt/darwin/VBoxNetFlt-darwin.cpp b/src/VBox/HostDrivers/VBoxNetFlt/darwin/VBoxNetFlt-darwin.cpp index a07c9323..be095dc7 100644 --- a/src/VBox/HostDrivers/VBoxNetFlt/darwin/VBoxNetFlt-darwin.cpp +++ b/src/VBox/HostDrivers/VBoxNetFlt/darwin/VBoxNetFlt-darwin.cpp @@ -4,7 +4,7 @@ */ /* - * Copyright (C) 2006-2008 Oracle Corporation + * Copyright (C) 2006-2014 Oracle Corporation * * This file is part of VirtualBox Open Source Edition (OSE), as * available from http://www.virtualbox.org. This file is free software; @@ -43,6 +43,9 @@ #include <iprt/alloca.h> #include <iprt/time.h> #include <iprt/net.h> +#include <iprt/thread.h> + +#include "../../darwin/VBoxNetSend.h" #include <mach/kmod.h> #include <sys/conf.h> @@ -135,11 +138,88 @@ static VBOXNETFLTGLOBALS g_VBoxNetFltGlobals; * It is used for tagging mbufs. */ static mbuf_tag_id_t g_idTag; -/** the offset of the struct ifnet::if_pcount variable. */ +/** The offset of the struct ifnet::if_pcount variable. + * @remarks Initial value is valid for Lion and earlier. We adjust it on attach + * for later releases. */ static unsigned g_offIfNetPCount = sizeof(void *) * (1 /*if_softc*/ + 1 /*if_name*/ + 2 /*if_link*/ + 2 /*if_addrhead*/ + 1 /*if_check_multi*/) + sizeof(u_long) /*if_refcnt*/; /** Macro for accessing ifnet::if_pcount. */ #define VBOX_GET_PCOUNT(pIfNet) ( *(int *)((uintptr_t)pIfNet + g_offIfNetPCount) ) +/** The size of area of ifnet structure we try to locate if_pcount in. */ +#define VBOXNETFLT_DARWIN_IFNET_SIZE 256 +/** Indicates whether g_offIfNetPCount has been adjusted already (no point in + * doing it more than once). */ +static bool g_fNetPCountFound = false; + + +/** + * Change the promiscuous setting and try spot the changed in @a pIfNet. + * + * @returns Offset of potential p_count field. + * @param pIfNet The interface we're attaching to. + * @param iPromisc Whether to enable (1) or disable (0) promiscuous mode. + * + * @note This implementation relies on if_pcount to be aligned on sizeof(int). + */ +static unsigned vboxNetFltDarwinSetAndDiff(ifnet_t pIfNet, int iPromisc) +{ + int aiSavedState[VBOXNETFLT_DARWIN_IFNET_SIZE / sizeof(int)]; + memcpy(aiSavedState, pIfNet, sizeof(aiSavedState)); + + ifnet_set_promiscuous(pIfNet, iPromisc); + + int const iDiff = iPromisc ? 1 : -1; + + /* + * We assume that ifnet structure will never have less members in front of if_pcount + * than it used to have in Lion. If this turns out to be false assumption we will + * have to start from zero offset. + */ + for (unsigned i = g_offIfNetPCount / sizeof(int); i < RT_ELEMENTS(aiSavedState); i++) + if (((int*)pIfNet)[i] - aiSavedState[i] == iDiff) + return i * sizeof(int); + + return 0; +} + + +/** + * Detect and adjust the offset of ifnet::if_pcount. + * + * @param pIfNet The interface we're attaching to. + */ +static void vboxNetFltDarwinDetectPCountOffset(ifnet_t pIfNet) +{ + if (g_fNetPCountFound) + return; + + /* + * It would be nice to use locking at this point, but it is not available via KPI. + * This is why we try several times. At each attempt we modify if_pcount four times + * to rule out false detections. + */ + unsigned offTry1, offTry2, offTry3, offTry4; + for (int iAttempt = 0; iAttempt < 3; iAttempt++) + { + offTry1 = vboxNetFltDarwinSetAndDiff(pIfNet, 1); + offTry2 = vboxNetFltDarwinSetAndDiff(pIfNet, 1); + offTry3 = vboxNetFltDarwinSetAndDiff(pIfNet, 0); + offTry4 = vboxNetFltDarwinSetAndDiff(pIfNet, 0); + if (offTry1 == offTry2 && offTry2 == offTry3 && offTry3 == offTry4) + { + if (g_offIfNetPCount != offTry1) + { + Log(("VBoxNetFltDarwinDetectPCountOffset: Adjusted if_pcount offset to %x from %x.\n", offTry1, g_offIfNetPCount)); + g_offIfNetPCount = offTry1; + g_fNetPCountFound = true; + } + break; + } + } + + if (g_offIfNetPCount != offTry1) + LogRel(("VBoxNetFlt: Failed to detect promiscuous count, all traffic may reach wire (%x != %x).\n", g_offIfNetPCount, offTry1)); +} /** @@ -882,6 +962,41 @@ static errno_t vboxNetFltDarwinIffInput(void *pvThis, ifnet_t pIfNet, protocol_f } +/** A worker thread for vboxNetFltSendDummy(). */ +static DECLCALLBACK(int) vboxNetFltSendDummyWorker(RTTHREAD hThreadSelf, void *pvUser) +{ + Assert(pvUser); + ifnet_t pIfNet = (ifnet_t)pvUser; + return VBoxNetSendDummy(pIfNet); +} + + +/** + * Prevent GUI icon freeze issue when VirtualBoxVM process terminates. + * + * This function is a workaround for stuck-in-dock issue. The idea here is to + * send a dummy packet to an interface from the context of a kernel thread. + * Therefore, an XNU's receive thread (which is created as a result if we are + * the first who is communicating with the interface) will be associated with + * the kernel thread instead of VirtualBoxVM process. + * + * @param pIfNet Interface to be used to send data. + */ +static void vboxNetFltSendDummy(ifnet_t pIfNet) +{ + RTTHREAD hThread; + int rc = RTThreadCreate(&hThread, vboxNetFltSendDummyWorker, (void *)pIfNet, 0, + RTTHREADTYPE_DEFAULT, RTTHREADFLAGS_WAITABLE, "DummyThread"); + if (RT_SUCCESS(rc)) + { + RTThreadWait(hThread, RT_INDEFINITE_WAIT, NULL); + LogFlow(("vboxNetFltSendDummy: a dummy packet has been successfully sent in order to prevent stuck-in-dock issue\n")); + } + else + LogFlow(("vboxNetFltSendDummy: unable to send dummy packet in order to prevent stuck-in-dock issue\n")); +} + + /** * Internal worker for vboxNetFltOsInitInstance and vboxNetFltOsMaybeRediscovered. * @@ -917,6 +1032,12 @@ static int vboxNetFltDarwinAttachToInterface(PVBOXNETFLTINS pThis, bool fRedisco ASMAtomicUoWritePtr(&pThis->u.s.pIfNet, pIfNet); RTSpinlockReleaseNoInts(pThis->hSpinlock); + /* Adjust g_offIfNetPCount as it varies for different versions of xnu. */ + vboxNetFltDarwinDetectPCountOffset(pIfNet); + + /* Prevent stuck-in-dock issue by associating interface receive thread with kernel thread. */ + vboxNetFltSendDummy(pIfNet); + /* * Get the mac address while we still have a valid ifnet reference. */ diff --git a/src/VBox/HostDrivers/VBoxNetFlt/freebsd/Makefile b/src/VBox/HostDrivers/VBoxNetFlt/freebsd/Makefile index a6792b01..d3868458 100644 --- a/src/VBox/HostDrivers/VBoxNetFlt/freebsd/Makefile +++ b/src/VBox/HostDrivers/VBoxNetFlt/freebsd/Makefile @@ -5,7 +5,7 @@ # # -# Copyright (C) 2006-2007 Oracle Corporation +# Copyright (C) 2006-2011 Oracle Corporation # # This file is part of VirtualBox Open Source Edition (OSE), as # available from http://www.virtualbox.org. This file is free software; diff --git a/src/VBox/HostDrivers/VBoxNetFlt/linux/Makefile b/src/VBox/HostDrivers/VBoxNetFlt/linux/Makefile index 7f3b5f37..195c872b 100644 --- a/src/VBox/HostDrivers/VBoxNetFlt/linux/Makefile +++ b/src/VBox/HostDrivers/VBoxNetFlt/linux/Makefile @@ -5,7 +5,7 @@ # # -# Copyright (C) 2006-2010 Oracle Corporation +# Copyright (C) 2006-2011 Oracle Corporation # # This file is part of VirtualBox Open Source Edition (OSE), as # available from http://www.virtualbox.org. This file is free software; @@ -160,7 +160,8 @@ else MANGLING := $(KBUILD_EXTMOD)/include/VBox/SUPDrvMangling.h endif KFLAGS := -D__KERNEL__ -DMODULE -DRT_OS_LINUX -DIN_RING0 -DIN_RT_R0 \ - -DIN_SUP_R0 -DVBOX -DRT_WITH_VBOX -DVBOX_WITH_HARDENING + -DIN_SUP_R0 -DVBOX -DRT_WITH_VBOX -DVBOX_WITH_HARDENING \ + -Wno-declaration-after-statement ifdef VBOX_REDHAT_KABI KFLAGS += -DVBOX_REDHAT_KABI endif diff --git a/src/VBox/HostDrivers/VBoxNetFlt/linux/VBoxNetFlt-linux.c b/src/VBox/HostDrivers/VBoxNetFlt/linux/VBoxNetFlt-linux.c index 82be076d..ff62274f 100644 --- a/src/VBox/HostDrivers/VBoxNetFlt/linux/VBoxNetFlt-linux.c +++ b/src/VBox/HostDrivers/VBoxNetFlt/linux/VBoxNetFlt-linux.c @@ -4,7 +4,7 @@ */ /* - * Copyright (C) 2006-2008 Oracle Corporation + * Copyright (C) 2006-2013 Oracle Corporation * * This file is part of VirtualBox Open Source Edition (OSE), as * available from http://www.virtualbox.org. This file is free software; @@ -445,7 +445,7 @@ static void vboxNetFltLinuxUnhookDev(PVBOXNETFLTINS pThis, struct net_device *pD if (pOverride) { - printk("vboxnetflt: dropped %llu out of %llu packets\n", pOverride->cFiltered, pOverride->cTotal); + printk("vboxnetflt: %llu out of %llu packets were not sent (directed to host)\n", pOverride->cFiltered, pOverride->cTotal); RTMemFree(pOverride); } } @@ -541,6 +541,59 @@ DECLINLINE(bool) vboxNetFltLinuxSkBufIsOur(struct sk_buff *pBuf) /** + * Checks whether this SG list contains a GSO packet. + * + * @returns true / false accordingly. + * @param pSG The (scatter/)gather list. + */ +DECLINLINE(bool) vboxNetFltLinuxIsGso(PINTNETSG pSG) +{ +#if defined(VBOXNETFLT_WITH_GSO_XMIT_WIRE) || defined(VBOXNETFLT_WITH_GSO_XMIT_HOST) + return !((PDMNETWORKGSOTYPE)pSG->GsoCtx.u8Type == PDMNETWORKGSOTYPE_INVALID); +#else /* !VBOXNETFLT_WITH_GSO_XMIT_WIRE && !VBOXNETFLT_WITH_GSO_XMIT_HOST */ + return false; +#endif /* !VBOXNETFLT_WITH_GSO_XMIT_WIRE && !VBOXNETFLT_WITH_GSO_XMIT_HOST */ +} + + +/** + * Find out the frame size (of a single segment in case of GSO frames). + * + * @returns the frame size. + * @param pSG The (scatter/)gather list. + */ +DECLINLINE(uint32_t) vboxNetFltLinuxFrameSize(PINTNETSG pSG) +{ + uint16_t u16Type = 0; + uint32_t cbVlanTag = 0; + if (pSG->aSegs[0].cb >= sizeof(RTNETETHERHDR)) + u16Type = RT_BE2H_U16(((PCRTNETETHERHDR)pSG->aSegs[0].pv)->EtherType); + else if (pSG->cbTotal >= sizeof(RTNETETHERHDR)) + { + uint32_t off = RT_OFFSETOF(RTNETETHERHDR, EtherType); + uint32_t i; + for (i = 0; i < pSG->cSegsUsed; ++i) + { + if (off <= pSG->aSegs[i].cb) + { + if (off + sizeof(uint16_t) <= pSG->aSegs[i].cb) + u16Type = RT_BE2H_U16(*(uint16_t *)((uintptr_t)pSG->aSegs[i].pv + off)); + else if (i + 1 < pSG->cSegsUsed) + u16Type = RT_BE2H_U16( ((uint16_t)( ((uint8_t *)pSG->aSegs[i].pv)[off] ) << 8) + + *(uint8_t *)pSG->aSegs[i + 1].pv); /* ASSUMES no empty segments! */ + /* else: frame is too short. */ + break; + } + off -= pSG->aSegs[i].cb; + } + } + if (u16Type == RTNET_ETHERTYPE_VLAN) + cbVlanTag = 4; + return (vboxNetFltLinuxIsGso(pSG) ? (uint32_t)pSG->GsoCtx.cbMaxSeg + pSG->GsoCtx.cbHdrsTotal : pSG->cbTotal) - cbVlanTag; +} + + +/** * Internal worker that create a linux sk_buff for a * (scatter/)gather list. * @@ -560,6 +613,17 @@ static struct sk_buff *vboxNetFltLinuxSkBufFromSG(PVBOXNETFLTINS pThis, PINTNETS LogRel(("VBoxNetFlt: Dropped empty packet coming from internal network.\n")); return NULL; } + Log5(("VBoxNetFlt: Packet to %s of %d bytes (frame=%d).\n", fDstWire?"wire":"host", pSG->cbTotal, vboxNetFltLinuxFrameSize(pSG))); + if (fDstWire && (vboxNetFltLinuxFrameSize(pSG) > ASMAtomicReadU32(&pThis->u.s.cbMtu) + 14)) + { + static bool s_fOnce = true; + if (s_fOnce) + { + s_fOnce = false; + printk("VBoxNetFlt: Dropped over-sized packet (%d bytes) coming from internal network.\n", vboxNetFltLinuxFrameSize(pSG)); + } + return NULL; + } /** @todo We should use fragments mapping the SG buffers with large packets. * 256 bytes seems to be the a threshold used a lot for this. It @@ -786,6 +850,7 @@ static int vboxNetFltLinuxPacketHandler(struct sk_buff *pBuf, * another copy going to the wire. */ Log2(("vboxNetFltLinuxPacketHandler: dropped loopback packet (cb=%u)\n", pBuf->len)); + dev_kfree_skb(pBuf); /* We must 'consume' all packets we get (@bugref{6539})! */ return 0; } @@ -794,6 +859,7 @@ static int vboxNetFltLinuxPacketHandler(struct sk_buff *pBuf, if (pDev != pSkbDev) { Log(("vboxNetFltLinuxPacketHandler: Devices do not match, pThis may be wrong! pThis=%p\n", pThis)); + kfree_skb(pBuf); /* This is a failure, so we use kfree_skb instead of dev_kfree_skb. */ return 0; } @@ -812,7 +878,7 @@ static int vboxNetFltLinuxPacketHandler(struct sk_buff *pBuf, */ unsigned int uMacLen = pBuf->mac_len; struct sk_buff *pCopy = skb_copy(pBuf, GFP_ATOMIC); - kfree_skb(pBuf); + dev_kfree_skb(pBuf); if (!pCopy) { LogRel(("VBoxNetFlt: Failed to allocate packet buffer, dropping the packet.\n")); @@ -1527,6 +1593,8 @@ static int vboxNetFltLinuxAttachToInterface(PVBOXNETFLTINS pThis, struct net_dev /* Get the mac address while we still have a valid net_device reference. */ memcpy(&pThis->u.s.MacAddr, pDev->dev_addr, sizeof(pThis->u.s.MacAddr)); + /* Initialize MTU */ + pThis->u.s.cbMtu = pDev->mtu; /* * Install a packet filter for this device with a protocol wildcard (ETH_P_ALL). @@ -1677,6 +1745,24 @@ static int vboxNetFltLinuxDeviceGoingDown(PVBOXNETFLTINS pThis, struct net_devic return NOTIFY_OK; } +/** + * Callback for listening to MTU change event. + * + * We need to track changes of host's inteface MTU to discard over-sized frames + * coming from the internal network as they may hang the TX queue of host's + * adapter. + * + * @returns NOTIFY_OK + * @param pThis The netfilter instance. + * @param pDev Pointer to device structure of host's interface. + */ +static int vboxNetFltLinuxDeviceMtuChange(PVBOXNETFLTINS pThis, struct net_device *pDev) +{ + ASMAtomicWriteU32(&pThis->u.s.cbMtu, pDev->mtu); + Log(("vboxNetFltLinuxDeviceMtuChange: set MTU for %s to %d\n", pThis->szName, pDev->mtu)); + return NOTIFY_OK; +} + #ifdef LOG_ENABLED /** Stringify the NETDEV_XXX constants. */ static const char *vboxNetFltLinuxGetNetDevEventName(unsigned long ulEventType) @@ -1718,7 +1804,11 @@ static int vboxNetFltLinuxNotifierCallback(struct notifier_block *self, unsigned { PVBOXNETFLTINS pThis = VBOX_FLT_NB_TO_INST(self); +#if LINUX_VERSION_CODE >= KERNEL_VERSION(3, 11, 0) + struct net_device *pDev = netdev_notifier_info_to_dev(ptr); +#else struct net_device *pDev = (struct net_device *)ptr; +#endif int rc = NOTIFY_OK; Log(("VBoxNetFlt: got event %s(0x%lx) on %s, pDev=%p pThis=%p pThis->u.s.pDev=%p\n", @@ -1744,6 +1834,9 @@ static int vboxNetFltLinuxNotifierCallback(struct notifier_block *self, unsigned case NETDEV_GOING_DOWN: rc = vboxNetFltLinuxDeviceGoingDown(pThis, pDev); break; + case NETDEV_CHANGEMTU: + rc = vboxNetFltLinuxDeviceMtuChange(pThis, pDev); + break; case NETDEV_CHANGENAME: break; #ifdef NETDEV_FEAT_CHANGE diff --git a/src/VBox/HostDrivers/VBoxNetFlt/linux/files_vboxnetflt b/src/VBox/HostDrivers/VBoxNetFlt/linux/files_vboxnetflt index 8e22c249..49008be3 100755 --- a/src/VBox/HostDrivers/VBoxNetFlt/linux/files_vboxnetflt +++ b/src/VBox/HostDrivers/VBoxNetFlt/linux/files_vboxnetflt @@ -5,7 +5,7 @@ # # -# Copyright (C) 2007-2010 Oracle Corporation +# Copyright (C) 2007-2011 Oracle Corporation # # This file is part of VirtualBox Open Source Edition (OSE), as # available from http://www.virtualbox.org. This file is free software; diff --git a/src/VBox/HostDrivers/VBoxNetFlt/solaris/VBoxNetFlt-solaris.c b/src/VBox/HostDrivers/VBoxNetFlt/solaris/VBoxNetFlt-solaris.c index e19a65ce..a69be968 100644 --- a/src/VBox/HostDrivers/VBoxNetFlt/solaris/VBoxNetFlt-solaris.c +++ b/src/VBox/HostDrivers/VBoxNetFlt/solaris/VBoxNetFlt-solaris.c @@ -786,7 +786,8 @@ static int VBoxNetFltSolarisModOpen(queue_t *pQueue, dev_t *pDev, int fOpenMode, && g_VBoxNetFltSolarisStreamType != kIp6Stream && g_VBoxNetFltSolarisStreamType != kIp4Stream) { - LogRel((DEVICE_NAME ":VBoxNetFltSolarisModOpen failed due to undefined VirtualBox open mode. Type=%d\n", g_VBoxNetFltSolarisStreamType)); + LogRel((DEVICE_NAME ":VBoxNetFltSolarisModOpen failed due to undefined VirtualBox open mode. Type=%d\n", + g_VBoxNetFltSolarisStreamType)); return ENOENT; } @@ -853,10 +854,10 @@ static int VBoxNetFltSolarisModOpen(queue_t *pQueue, dev_t *pDev, int fOpenMode, pStream->Type = g_VBoxNetFltSolarisStreamType; switch (pStream->Type) { - case kIp4Stream: ASMAtomicUoWritePtr(&pThis->u.s.pIp4Stream, pStream); break; - case kIp6Stream: ASMAtomicUoWritePtr(&pThis->u.s.pIp6Stream, pStream); break; - case kArpStream: ASMAtomicUoWritePtr(&pThis->u.s.pArpStream, pStream); break; - case kPromiscStream: ASMAtomicUoWritePtr(&pThis->u.s.pPromiscStream, pStream); break; + case kIp4Stream: ASMAtomicUoWritePtr((void**)&pThis->u.s.pIp4Stream, pStream); break; + case kIp6Stream: ASMAtomicUoWritePtr((void**)&pThis->u.s.pIp6Stream, pStream); break; + case kArpStream: ASMAtomicUoWritePtr((void**)&pThis->u.s.pArpStream, pStream); break; + case kPromiscStream: ASMAtomicUoWritePtr((void**)&pThis->u.s.pPromiscStream, pStream); break; default: /* Heh. */ { LogRel((DEVICE_NAME ":VBoxNetFltSolarisModOpen huh!? Invalid stream type %d\n", pStream->Type)); @@ -1123,8 +1124,8 @@ static int VBoxNetFltSolarisModReadPut(queue_t *pQueue, mblk_t *pMsg) { if (MBLKL(pMsg) < DL_NOTIFY_IND_SIZE) { - LogRel((DEVICE_NAME ":VBoxNetFltSolarisModReadPut: Invalid notification size; expected>=%d got=%d\n", - DL_NOTIFY_IND_SIZE, MBLKL(pMsg))); + LogRel((DEVICE_NAME ":VBoxNetFltSolarisModReadPut: Invalid notification size; expected>=%d" + " got=%d\n", DL_NOTIFY_IND_SIZE, MBLKL(pMsg))); break; } @@ -1141,7 +1142,8 @@ static int VBoxNetFltSolarisModReadPut(queue_t *pQueue, mblk_t *pMsg) if (!cOffset || !cbAddr) { - LogRel((DEVICE_NAME ":VBoxNetFltSolarisModReadPut: DL_NOTE_PHYS_ADDR. Invalid offset/addr.\n")); + LogRel((DEVICE_NAME ":VBoxNetFltSolarisModReadPut: DL_NOTE_PHYS_ADDR." + "Invalid offset/addr.\n")); fSendUpstream = false; break; } @@ -1466,7 +1468,8 @@ static void vboxNetFltSolarisPromiscReqWrap(void *pvData) if (RT_LIKELY(pParams)) { PVBOXNETFLTINS pThis = pParams->pThis; - vboxnetflt_promisc_stream_t *pPromiscStream = ASMAtomicUoReadPtrT(&pThis->u.s.pPromiscStream, vboxnetflt_promisc_stream_t *); + vboxnetflt_promisc_stream_t *pPromiscStream = ASMAtomicUoReadPtrT(&pThis->u.s.pPromiscStream, + vboxnetflt_promisc_stream_t *); if ( pPromiscStream && pPromiscStream->Stream.pReadQueue) { @@ -1643,8 +1646,8 @@ static int vboxNetFltSolarisOpenDev(char *pszDev, vnode_t **ppVNode, vnode_t **p } else { - LogRel((DEVICE_NAME ":vboxNetFltSolarisOpenDev failed. pUser=%p fp=%p f_vnode=%p\n", pUser, pUser ? pUser->fp : NULL, - pUser && pUser->fp ? VNODE_FOR_FILE_T(pUser->fp) : NULL)); + LogRel((DEVICE_NAME ":vboxNetFltSolarisOpenDev failed. pUser=%p fp=%p f_vnode=%p\n", pUser, + pUser ? pUser->fp : NULL, pUser && pUser->fp ? VNODE_FOR_FILE_T(pUser->fp) : NULL)); } if (pUser) @@ -1721,8 +1724,8 @@ static int vboxNetFltSolarisAttachReq(ldi_handle_t hDevice, int PPA) } else /* Garbled reply */ { - LogRel((DEVICE_NAME ":vboxNetFltSolarisAttachReq ldi_getmsg succeeded, but invalid op. expected %d recvd %d\n", - DL_OK_ACK, AckPrim)); + LogRel((DEVICE_NAME ":vboxNetFltSolarisAttachReq ldi_getmsg succeeded, but invalid op." + " expected %d recvd %d\n", DL_OK_ACK, AckPrim)); rc = VERR_INVALID_FUNCTION; } } @@ -2381,7 +2384,10 @@ static int vboxNetFltSolarisAttachIp4(PVBOXNETFLTINS pThis, bool fAttach) } } else - LogRel((DEVICE_NAME ":vboxNetFltSolarisAttachIp4: failed to find position. rc=%d rc2=%d\n", rc, rc2)); + { + LogRel((DEVICE_NAME ":vboxNetFltSolarisAttachIp4: failed to find position. rc=%d rc2=%d\n", rc, + rc2)); + } releasef(Ip4MuxFd); releasef(ArpMuxFd); @@ -2390,7 +2396,10 @@ static int vboxNetFltSolarisAttachIp4(PVBOXNETFLTINS pThis, bool fAttach) LogRel((DEVICE_NAME ":vboxNetFltSolarisAttachIp4: failed to get vnode from MuxFd.\n")); } else - LogRel((DEVICE_NAME ":vboxNetFltSolarisAttachIp4: failed to unlink upper stream rc=%d rc2=%d.\n", rc, rc2)); + { + LogRel((DEVICE_NAME ":vboxNetFltSolarisAttachIp4: failed to unlink upper stream rc=%d rc2=%d.\n", rc, + rc2)); + } } else LogRel((DEVICE_NAME ":vboxNetFltSolarisAttachIp4: failed to get MuxFd from MuxId. rc=%d rc2=%d\n", rc, rc2)); @@ -2679,8 +2688,8 @@ static int vboxNetFltSolarisSetupIp6Polling(PVBOXNETFLTINS pThis) int Interval = g_VBoxNetFltSolarisPollInterval; if (Interval < 1 || Interval > 120) { - LogRel((DEVICE_NAME ":vboxNetFltSolarisSetupIp6Polling: Invalid polling interval %d. Expected between 1 and 120 secs.\n", - Interval)); + LogRel((DEVICE_NAME ":vboxNetFltSolarisSetupIp6Polling: Invalid polling interval %d. Expected between" + " 1 and 120 secs.\n", Interval)); return VERR_INVALID_PARAMETER; } @@ -2692,7 +2701,8 @@ static int vboxNetFltSolarisSetupIp6Polling(PVBOXNETFLTINS pThis) if (RT_SUCCESS(rc)) { rc = RTTimerStart(pPromiscStream->pIp6Timer, 10 * (uint64_t)1000000000 /* 10 seconds to blastoff */); - Log((DEVICE_NAME ":vboxNetFltSolarisSetupIp6Polling: Ipv6 %d second timer begins firing in 10 seconds.\n", Interval)); + Log((DEVICE_NAME ":vboxNetFltSolarisSetupIp6Polling: Ipv6 %d second timer begins firing in 10 seconds.\n", + Interval)); } else LogRel((DEVICE_NAME ":vboxNetFltSolarisSetupIp6Polling: Failed to create timer. rc=%d\n", rc)); @@ -3478,8 +3488,8 @@ static int vboxNetFltSolarisRecv(PVBOXNETFLTINS pThis, vboxnetflt_stream_t *pStr } else { - LogRel((DEVICE_NAME ":vboxNetFltSolarisRecv insufficient memory for creating VLAN stripped packet cbMsg=%u.\n", - cbEthPrefix)); + LogRel((DEVICE_NAME ":vboxNetFltSolarisRecv insufficient memory for creating VLAN stripped packet" + " cbMsg=%u.\n", cbEthPrefix)); if (fCopied) freemsg(pMsg); return VERR_NO_MEMORY; @@ -3695,7 +3705,8 @@ static void vboxNetFltSolarisAnalyzeMBlk(mblk_t *pMsg) else if (pEthHdr->EtherType == RT_H2BE_U16(RTNET_ETHERTYPE_VLAN)) { PVLANHEADER pVlanHdr = (PVLANHEADER)(pMsg->b_rptr + sizeof(RTNETETHERHDR) - sizeof(pEthHdr->EtherType)); - LogRel((DEVICE_NAME ":VLAN Pcp=%u Cfi=%u Id=%u\n", VLAN_PRI(RT_BE2H_U16(pVlanHdr->Data)), VLAN_CFI(RT_BE2H_U16(pVlanHdr->Data)), VLAN_ID(RT_BE2H_U16(pVlanHdr->Data)))); + LogRel((DEVICE_NAME ":VLAN Pcp=%u Cfi=%u Id=%u\n", VLAN_PRI(RT_BE2H_U16(pVlanHdr->Data)), + VLAN_CFI(RT_BE2H_U16(pVlanHdr->Data)), VLAN_ID(RT_BE2H_U16(pVlanHdr->Data)))); LogRel((DEVICE_NAME "%.*Rhxd\n", sizeof(VLANHEADER), pVlanHdr)); } else if (pEthHdr->EtherType == RT_H2BE_U16(RTNET_ETHERTYPE_ARP)) @@ -3740,7 +3751,8 @@ void vboxNetFltPortOsSetActive(PVBOXNETFLTINS pThis, bool fActive) /* * See @bugref{5262} as to why we need to do all this qtimeout/qwriter tricks. */ - vboxnetflt_promisc_stream_t *pPromiscStream = ASMAtomicUoReadPtrT(&pThis->u.s.pPromiscStream, vboxnetflt_promisc_stream_t *); + vboxnetflt_promisc_stream_t *pPromiscStream = ASMAtomicUoReadPtrT(&pThis->u.s.pPromiscStream, + vboxnetflt_promisc_stream_t *); if ( pPromiscStream && pPromiscStream->Stream.pReadQueue) { @@ -3748,7 +3760,8 @@ void vboxNetFltPortOsSetActive(PVBOXNETFLTINS pThis, bool fActive) pData->fPromiscOn = fActive; if (ASMAtomicReadPtr(&pPromiscStream->TimeoutId)) quntimeout(WR(pPromiscStream->Stream.pReadQueue), pPromiscStream->TimeoutId); - timeout_id_t TimeoutId = qtimeout(WR(pPromiscStream->Stream.pReadQueue), vboxNetFltSolarisPromiscReqWrap, pData, 1 /* ticks */); + timeout_id_t TimeoutId = qtimeout(WR(pPromiscStream->Stream.pReadQueue), vboxNetFltSolarisPromiscReqWrap, + pData, 1 /* ticks */); ASMAtomicWritePtr(&pPromiscStream->TimeoutId, TimeoutId); return; /* pData will be freed by vboxNetFltSolarisPromiscReqWrap() */ } @@ -3890,7 +3903,8 @@ int vboxNetFltPortOsXmit(PVBOXNETFLTINS pThis, void *pvIfData, PINTNETSG pSG, ui int rc = VINF_SUCCESS; if (fDst & INTNETTRUNKDIR_WIRE) { - vboxnetflt_promisc_stream_t *pPromiscStream = ASMAtomicUoReadPtrT(&pThis->u.s.pPromiscStream, vboxnetflt_promisc_stream_t *); + vboxnetflt_promisc_stream_t *pPromiscStream = ASMAtomicUoReadPtrT(&pThis->u.s.pPromiscStream, + vboxnetflt_promisc_stream_t *); if (RT_LIKELY(pPromiscStream)) { mblk_t *pMsg = vboxNetFltSolarisMBlkFromSG(pThis, pSG, fDst); diff --git a/src/VBox/HostDrivers/VBoxNetFlt/solaris/VBoxNetFltBow-solaris.c b/src/VBox/HostDrivers/VBoxNetFlt/solaris/VBoxNetFltBow-solaris.c index 30fcc321..3265f48d 100644 --- a/src/VBox/HostDrivers/VBoxNetFlt/solaris/VBoxNetFltBow-solaris.c +++ b/src/VBox/HostDrivers/VBoxNetFlt/solaris/VBoxNetFltBow-solaris.c @@ -259,7 +259,7 @@ LOCAL mblk_t *vboxNetFltSolarisMBlkFromSG(PVBOXNETFLTINS pThis, PINTNETSG pSG, u LOCAL unsigned vboxNetFltSolarisMBlkCalcSGSegs(PVBOXNETFLTINS pThis, mblk_t *pMsg); LOCAL int vboxNetFltSolarisMBlkToSG(PVBOXNETFLTINS pThis, mblk_t *pMsg, PINTNETSG pSG, unsigned cSegs, uint32_t fSrc); LOCAL void vboxNetFltSolarisRecv(void *pvData, mac_resource_handle_t hResource, mblk_t *pMsg, boolean_t fLoopback); -LOCAL void vboxNetFltSolarisAnalyzeMBlk(mblk_t *pMsg); +//LOCAL void vboxNetFltSolarisAnalyzeMBlk(mblk_t *pMsg); LOCAL int vboxNetFltSolarisReportInfo(PVBOXNETFLTINS pThis, mac_handle_t hInterface, bool fIsVNIC); LOCAL int vboxNetFltSolarisInitVNIC(PVBOXNETFLTINS pThis, PVBOXNETFLTVNIC pVNIC); LOCAL int vboxNetFltSolarisInitVNICTemplate(PVBOXNETFLTINS pThis, PVBOXNETFLTVNICTEMPLATE pVNICTemplate); @@ -592,6 +592,7 @@ LOCAL int vboxNetFltSolarisMBlkToSG(PVBOXNETFLTINS pThis, mblk_t *pMsg, PINTNETS } +#if 0 /** * Simple packet dump, used for internal debugging. * @@ -631,7 +632,8 @@ LOCAL void vboxNetFltSolarisAnalyzeMBlk(mblk_t *pMsg) else if (pEthHdr->EtherType == RT_H2BE_U16(RTNET_ETHERTYPE_VLAN)) { PVLANHEADER pVlanHdr = (PVLANHEADER)(pMsg->b_rptr + sizeof(RTNETETHERHDR) - sizeof(pEthHdr->EtherType)); - LogRel((DEVICE_NAME ":VLAN Pcp=%u Cfi=%u Id=%u\n", VLAN_PRI(RT_BE2H_U16(pVlanHdr->Data)), VLAN_CFI(RT_BE2H_U16(pVlanHdr->Data)), VLAN_ID(RT_BE2H_U16(pVlanHdr->Data)))); + LogRel((DEVICE_NAME ":VLAN Pcp=%u Cfi=%u Id=%u\n", VLAN_PRI(RT_BE2H_U16(pVlanHdr->Data)), + VLAN_CFI(RT_BE2H_U16(pVlanHdr->Data)), VLAN_ID(RT_BE2H_U16(pVlanHdr->Data)))); LogRel((DEVICE_NAME "%.*Rhxd\n", sizeof(VLANHEADER), pVlanHdr)); } else if (pEthHdr->EtherType == RT_H2BE_U16(RTNET_ETHERTYPE_ARP)) @@ -643,7 +645,7 @@ LOCAL void vboxNetFltSolarisAnalyzeMBlk(mblk_t *pMsg) { LogRel((DEVICE_NAME ":IPv6 D=%.6Rhxs S=%.6Rhxs\n", pb, pb + 6)); } - else if (pEthHdr->EtherType == RT_H2BE_U16(RTNET_ETHERTYPE_IPX_1) + else if ( pEthHdr->EtherType == RT_H2BE_U16(RTNET_ETHERTYPE_IPX_1) || pEthHdr->EtherType == RT_H2BE_U16(RTNET_ETHERTYPE_IPX_2) || pEthHdr->EtherType == RT_H2BE_U16(RTNET_ETHERTYPE_IPX_3)) { @@ -656,6 +658,7 @@ LOCAL void vboxNetFltSolarisAnalyzeMBlk(mblk_t *pMsg) /* Log((DEVICE_NAME ":%.*Rhxd\n", MBLKL(pMsg), pMsg->b_rptr)); */ } } +#endif /** @@ -679,7 +682,8 @@ DECLINLINE(bool) vboxNetFltPortSolarisIsHostMac(PVBOXNETFLTINS pThis, PCRTMAC pM */ LOCAL void vboxNetFltSolarisRecv(void *pvData, mac_resource_handle_t hResource, mblk_t *pMsg, boolean_t fLoopback) { - Log((DEVICE_NAME ":vboxNetFltSolarisRecv pvData=%p pMsg=%p fLoopback=%d cbData=%d\n", pvData, pMsg, fLoopback, pMsg ? MBLKL(pMsg) : 0)); + Log((DEVICE_NAME ":vboxNetFltSolarisRecv pvData=%p pMsg=%p fLoopback=%d cbData=%d\n", pvData, pMsg, fLoopback, + pMsg ? MBLKL(pMsg) : 0)); PVBOXNETFLTINS pThis = (PVBOXNETFLTINS)pvData; AssertPtrReturnVoid(pThis); @@ -754,7 +758,8 @@ LOCAL void vboxNetFltSolarisLinkNotify(void *pvArg, mac_notify_type_t Type) if (fDisconnectedFromHost != ASMAtomicUoReadBool(&pThis->fDisconnectedFromHost)) { ASMAtomicUoWriteBool(&pThis->fDisconnectedFromHost, fDisconnectedFromHost); - LogRel((DEVICE_NAME ":vboxNetFltSolarisLinkNotify link state change: new state=%s\n", fDisconnectedFromHost ? "DOWN" : "UP")); + LogRel((DEVICE_NAME ":vboxNetFltSolarisLinkNotify link state change: new state=%s\n", + fDisconnectedFromHost ? "DOWN" : "UP")); } break; } @@ -945,11 +950,15 @@ LOCAL int vboxNetFltSolarisInitVNICTemplate(PVBOXNETFLTINS pThis, PVBOXNETFLTVNI } } else - LogRel((DEVICE_NAME ":vboxNetFltSolarisInitVNICTemplate failed to copy link name of underlying interface. rc=%d\n", rc)); + { + LogRel((DEVICE_NAME ":vboxNetFltSolarisInitVNICTemplate failed to copy link name of underlying interface" + ". rc=%d\n", rc)); + } } else { - LogRel((DEVICE_NAME ":vboxNetFltSolarisInitVNICTemplate failed to get lower handle for VNIC template '%s'.\n", pThis->szName)); + LogRel((DEVICE_NAME ":vboxNetFltSolarisInitVNICTemplate failed to get lower handle for VNIC template '%s'.\n", + pThis->szName)); rc = VERR_INTNET_FLT_IF_FAILED; } @@ -1159,7 +1168,7 @@ LOCAL int vboxNetFltSolarisCreateVNIC(PVBOXNETFLTINS pThis, PVBOXNETFLTVNIC *ppV rc = vboxNetFltSolarisInitVNIC(pThis, pVNIC); if (RT_SUCCESS(rc)) { - Log((DEVICE_NAME ":vboxNetFltSolarisCreateVNIC successfully created VNIC '%s' over '%s' with random mac %.6Rhxs\n", + Log((DEVICE_NAME ":vboxNetFltSolarisCreateVNIC created VNIC '%s' over '%s' with random mac %.6Rhxs\n", pVNIC->szName, pszLinkName, &GuestMac)); *ppVNIC = pVNIC; return VINF_SUCCESS; @@ -1455,7 +1464,8 @@ void vboxNetFltPortOsNotifyMacAddress(PVBOXNETFLTINS pThis, void *pvIfData, PCRT */ PVBOXNETFLTVNIC pVNIC = pvIfData; AssertMsgReturnVoid(VALID_PTR(pVNIC) && pVNIC->u32Magic == VBOXNETFLTVNIC_MAGIC, - ("Invalid pVNIC=%p magic=%#x (expected %#x)\n", pvIfData, VALID_PTR(pVNIC) ? pVNIC->u32Magic : 0, VBOXNETFLTVNIC_MAGIC)); + ("Invalid pVNIC=%p magic=%#x (expected %#x)\n", pvIfData, + VALID_PTR(pVNIC) ? pVNIC->u32Magic : 0, VBOXNETFLTVNIC_MAGIC)); AssertMsgReturnVoid(pVNIC->hLinkId != DATALINK_INVALID_LINKID, ("Invalid hLinkId pVNIC=%p magic=%#x\n", pVNIC, pVNIC->u32Magic)); @@ -1505,7 +1515,8 @@ void vboxNetFltPortOsNotifyMacAddress(PVBOXNETFLTINS pThis, void *pvIfData, PCRT /* * Set the RX receive function. * This shouldn't be necessary as vboxNetFltPortOsSetActive() will be invoked after this, but in the future, - * if the guest NIC changes MAC address this may not be followed by a vboxNetFltPortOsSetActive() call, so set it here anyway. + * if the guest NIC changes MAC address this may not be followed by a vboxNetFltPortOsSetActive() call, + * so set it here anyway. */ mac_rx_set(pVNIC->hClient, vboxNetFltSolarisRecv, pThis); Log((DEVICE_NAME ":vboxNetFltPortOsNotifyMacAddress successfully added unicast address %.6Rhxs\n", pMac)); @@ -1517,7 +1528,10 @@ void vboxNetFltPortOsNotifyMacAddress(PVBOXNETFLTINS pThis, void *pvIfData, PCRT #endif } else - LogRel((DEVICE_NAME ":vboxNetFltPortOsNotifyMacAddress failed to add primary unicast address. rc=%d Diag=%d\n", rc, MacDiag)); + { + LogRel((DEVICE_NAME ":vboxNetFltPortOsNotifyMacAddress failed to add primary unicast address. rc=%d Diag=%d\n", rc, + MacDiag)); + } } else { @@ -1607,7 +1621,10 @@ int vboxNetFltPortOsConnectInterface(PVBOXNETFLTINS pThis, void *pvIf, void **pp LogRel((DEVICE_NAME ":vboxNetFltPortOsConnectInterface failed to initialize VNIC. rc=%d\n", rc)); } else - LogRel((DEVICE_NAME ":vboxNetFltPortOsConnectInterface failed to get link id for '%s'. rc=%d\n", pThis->szName, rc)); + { + LogRel((DEVICE_NAME ":vboxNetFltPortOsConnectInterface failed to get link id for '%s'. rc=%d\n", + pThis->szName, rc)); + } } else { @@ -1634,13 +1651,14 @@ int vboxNetFltPortOsDisconnectInterface(PVBOXNETFLTINS pThis, void *pvIfData) PVBOXNETFLTVNIC pVNIC = pvIfData; AssertMsgReturn(VALID_PTR(pVNIC) && pVNIC->u32Magic == VBOXNETFLTVNIC_MAGIC, - ("Invalid pvIfData=%p magic=%#x (expected %#x)\n", pvIfData, pVNIC ? pVNIC->u32Magic : 0, VBOXNETFLTVNIC_MAGIC), - VERR_INVALID_POINTER); + ("Invalid pvIfData=%p magic=%#x (expected %#x)\n", pvIfData, + pVNIC ? pVNIC->u32Magic : 0, VBOXNETFLTVNIC_MAGIC), VERR_INVALID_POINTER); /* - * If the underlying interface is not a VNIC, we need to delete the created VNIC. + * If the underlying interface is a physical interface or a VNIC template, we need to delete the created VNIC. */ - if (!pThis->u.s.fIsVNIC) + if ( !pThis->u.s.fIsVNIC + || pThis->u.s.fIsVNICTemplate) { /* * Remove the VNIC from the list, destroy and free it. diff --git a/src/VBox/HostDrivers/VBoxNetFlt/win/cfg/VBoxNetCfg.cpp b/src/VBox/HostDrivers/VBoxNetFlt/win/cfg/VBoxNetCfg.cpp index 23906884..2a7bbc2a 100644 --- a/src/VBox/HostDrivers/VBoxNetFlt/win/cfg/VBoxNetCfg.cpp +++ b/src/VBox/HostDrivers/VBoxNetFlt/win/cfg/VBoxNetCfg.cpp @@ -3,7 +3,7 @@ * VBoxNetCfg.cpp - Network Configuration API. */ /* - * Copyright (C) 2011 Oracle Corporation + * Copyright (C) 2011-2012 Oracle Corporation * * This file is part of VirtualBox Open Source Edition (OSE), as * available from http://www.virtualbox.org. This file is free software; @@ -396,10 +396,17 @@ static HRESULT vboxNetCfgWinEnumNetCfgComponents(IN INetCfg *pNetCfg, return hr; } +/* + * Forward declarations of functions used in vboxNetCfgWinRemoveAllNetDevicesOfIdCallback. + */ +VBOXNETCFGWIN_DECL(HRESULT) VBoxNetCfgWinGenHostonlyConnectionName(PCWSTR DevName, WCHAR *pBuf, PULONG pcbBuf); +VBOXNETCFGWIN_DECL(HRESULT) VBoxNetCfgWinRenameConnection (LPWSTR pGuid, PCWSTR NewName); + static BOOL vboxNetCfgWinRemoveAllNetDevicesOfIdCallback(HDEVINFO hDevInfo, PSP_DEVINFO_DATA pDev, PVOID pContext) { HRESULT hr = S_OK; SP_REMOVEDEVICE_PARAMS rmdParams; + WCHAR pWCfgGuidString[50] = {L''}; rmdParams.ClassInstallHeader.cbSize = sizeof(SP_CLASSINSTALL_HEADER); rmdParams.ClassInstallHeader.InstallFunction = DIF_REMOVE; @@ -410,6 +417,57 @@ static BOOL vboxNetCfgWinRemoveAllNetDevicesOfIdCallback(HDEVINFO hDevInfo, PSP_ { if (SetupDiSetSelectedDevice (hDevInfo, pDev)) { + /* Figure out NetCfgInstanceId */ + HKEY hkey = SetupDiOpenDevRegKey(hDevInfo, + pDev, + DICS_FLAG_GLOBAL, + 0, + DIREG_DRV, + KEY_READ); + if (hkey == INVALID_HANDLE_VALUE) + NonStandardLogFlow(("SetupDiOpenDevRegKey failed (0x%08X)", GetLastError())); + else + { + DWORD cbSize = sizeof(pWCfgGuidString); + DWORD dwValueType; + DWORD ret = RegQueryValueExW (hkey, L"NetCfgInstanceId", NULL, + &dwValueType, (LPBYTE) pWCfgGuidString, &cbSize); + if (ret == ERROR_SUCCESS) + { + /* Figure out device name */ + WCHAR DevName[256], TempName[256]; + ULONG cbName = sizeof(TempName); + if (SetupDiGetDeviceRegistryPropertyW(hDevInfo, pDev, + SPDRP_FRIENDLYNAME , /* IN DWORD Property,*/ + NULL, /*OUT PDWORD PropertyRegDataType, OPTIONAL*/ + (PBYTE)DevName, /*OUT PBYTE PropertyBuffer,*/ + sizeof(DevName), /* IN DWORD PropertyBufferSize,*/ + NULL /*OUT PDWORD RequiredSize OPTIONAL*/)) + { + /* + * Rename the connection before removing the device. This will + * hopefully prevent an error when we will be attempting + * to rename a newly created connection (see @bugref{6740}). + */ + HRESULT hr_tmp = VBoxNetCfgWinGenHostonlyConnectionName(DevName, TempName, &cbName); + wcscat_s(TempName, sizeof(TempName), L" removed"); + if (SUCCEEDED(hr)) + hr_tmp = VBoxNetCfgWinRenameConnection(pWCfgGuidString, TempName); + //NonStandardLogFlow(("VBoxNetCfgWinRenameConnection(%S,%S) => 0x%x\n", pWCfgGuidString, TempName, hr_tmp)); + } + else + { + NonStandardLogFlow(("Failed to get 'friendly name' property for %S\n", pWCfgGuidString)); + } + } + else + { + NonStandardLogFlow(("RegQueryValueExW(L\"NetCfgInstanceId\") failed with %d\n", ret)); + } + + RegCloseKey (hkey); + } + if (SetupDiCallClassInstaller(DIF_REMOVE,hDevInfo,pDev)) { SP_DEVINSTALL_PARAMS devParams; @@ -890,7 +948,7 @@ static HRESULT netIfWinFindAdapterClassById(IWbemServices * pSvc, const GUID * p { swprintf(wszQuery, L"SELECT * FROM Win32_NetworkAdapterConfiguration WHERE SettingID = \"%s\"", wszGuid); IEnumWbemClassObject* pEnumerator = NULL; - hr = pSvc->ExecQuery(bstr_t("WQL"), bstr_t(wszQuery), WBEM_FLAG_FORWARD_ONLY | WBEM_FLAG_RETURN_IMMEDIATELY, + hr = pSvc->ExecQuery(bstr_t("WQL"), bstr_t(wszQuery), WBEM_FLAG_FORWARD_ONLY | WBEM_FLAG_RETURN_IMMEDIATELY, NULL, &pEnumerator); if (SUCCEEDED(hr)) { @@ -899,7 +957,7 @@ static HRESULT netIfWinFindAdapterClassById(IWbemServices * pSvc, const GUID * p IWbemClassObject *pclsObj; ULONG uReturn = 0; hr = pEnumerator->Next(WBEM_INFINITE, 1, &pclsObj, &uReturn); - NonStandardLogFlow(("netIfWinFindAdapterClassById: IEnumWbemClassObject::Next -> hr=0x%x pclsObj=%p uReturn=%u 42=%u\n", + NonStandardLogFlow(("netIfWinFindAdapterClassById: IEnumWbemClassObject::Next -> hr=0x%x pclsObj=%p uReturn=%u 42=%u\n", hr, (void *)pclsObj, uReturn, 42)); if (SUCCEEDED(hr)) { @@ -2080,7 +2138,7 @@ static BOOL vboxNetCfgWinAdjustHostOnlyNetworkInterfacePriority(IN INetCfg *pNc, } else { - if (hr = S_FALSE) /* No more binding paths? */ + if (hr == S_FALSE) /* No more binding paths? */ hr = S_OK; else NonStandardLogFlow(("Next bind path failed, hr (0x%x)\n", hr)); @@ -2139,8 +2197,6 @@ static UINT WINAPI vboxNetCfgWinPspFileCallback( */ -#define NETSHELL_LIBRARY _T("netshell.dll") - /** * Use the IShellFolder API to rename the connection. */ @@ -2188,6 +2244,24 @@ static HRESULT rename_shellfolder (PCWSTR wGuid, PCWSTR wNewName) return hr; } +/** + * Loads a system DLL. + * + * @returns Module handle or NULL + * @param pszName The DLL name. + */ +static HMODULE loadSystemDll(const char *pszName) +{ + char szPath[MAX_PATH]; + UINT cchPath = GetSystemDirectoryA(szPath, sizeof(szPath)); + size_t cbName = strlen(pszName) + 1; + if (cchPath + 1 + cbName > sizeof(szPath)) + return NULL; + szPath[cchPath] = '\\'; + memcpy(&szPath[cchPath + 1], pszName, cbName); + return LoadLibraryA(szPath); +} + VBOXNETCFGWIN_DECL(HRESULT) VBoxNetCfgWinRenameConnection (LPWSTR pGuid, PCWSTR NewName) { typedef HRESULT (WINAPI *lpHrRenameConnection) (const GUID *, PCWSTR); @@ -2208,7 +2282,7 @@ VBOXNETCFGWIN_DECL(HRESULT) VBoxNetCfgWinRenameConnection (LPWSTR pGuid, PCWSTR status = CLSIDFromString ((LPOLESTR) pGuid, &clsid); if (FAILED(status)) return E_FAIL; - hNetShell = LoadLibrary (NETSHELL_LIBRARY); + hNetShell = loadSystemDll("netshell.dll"); if (hNetShell == NULL) return E_FAIL; RenameConnectionFunc = diff --git a/src/VBox/HostDrivers/VBoxNetFlt/win/drv/VBoxNetFltM-win.cpp b/src/VBox/HostDrivers/VBoxNetFlt/win/drv/VBoxNetFltM-win.cpp index ab256088..91936f5e 100644 --- a/src/VBox/HostDrivers/VBoxNetFlt/win/drv/VBoxNetFltM-win.cpp +++ b/src/VBox/HostDrivers/VBoxNetFlt/win/drv/VBoxNetFltM-win.cpp @@ -4,7 +4,7 @@ * Miniport edge */ /* - * Copyright (C) 2011 Oracle Corporation + * Copyright (C) 2011-2012 Oracle Corporation * * This file is part of VirtualBox Open Source Edition (OSE), as * available from http://www.virtualbox.org. This file is free software; diff --git a/src/VBox/HostDrivers/VBoxNetFlt/win/drv/VBoxNetFltM-win.h b/src/VBox/HostDrivers/VBoxNetFlt/win/drv/VBoxNetFltM-win.h index 956b9920..4e82bbad 100644 --- a/src/VBox/HostDrivers/VBoxNetFlt/win/drv/VBoxNetFltM-win.h +++ b/src/VBox/HostDrivers/VBoxNetFlt/win/drv/VBoxNetFltM-win.h @@ -4,7 +4,7 @@ */ /* - * Copyright (C) 2011 Oracle Corporation + * Copyright (C) 2011-2012 Oracle Corporation * * This file is part of VirtualBox Open Source Edition (OSE), as * available from http://www.virtualbox.org. This file is free software; diff --git a/src/VBox/HostDrivers/VBoxNetFlt/win/drv/VBoxNetFltP-win.cpp b/src/VBox/HostDrivers/VBoxNetFlt/win/drv/VBoxNetFltP-win.cpp index ab45e91c..3fea0a39 100644 --- a/src/VBox/HostDrivers/VBoxNetFlt/win/drv/VBoxNetFltP-win.cpp +++ b/src/VBox/HostDrivers/VBoxNetFlt/win/drv/VBoxNetFltP-win.cpp @@ -4,7 +4,7 @@ * Protocol edge */ /* - * Copyright (C) 2011 Oracle Corporation + * Copyright (C) 2011-2012 Oracle Corporation * * This file is part of VirtualBox Open Source Edition (OSE), as * available from http://www.virtualbox.org. This file is free software; diff --git a/src/VBox/HostDrivers/VBoxNetFlt/win/drv/VBoxNetFltRt-win.cpp b/src/VBox/HostDrivers/VBoxNetFlt/win/drv/VBoxNetFltRt-win.cpp index f5e3b2ef..5aa2e7db 100644 --- a/src/VBox/HostDrivers/VBoxNetFlt/win/drv/VBoxNetFltRt-win.cpp +++ b/src/VBox/HostDrivers/VBoxNetFlt/win/drv/VBoxNetFltRt-win.cpp @@ -4,7 +4,7 @@ * NetFlt Runtime */ /* - * Copyright (C) 2011 Oracle Corporation + * Copyright (C) 2011-2012 Oracle Corporation * * This file is part of VirtualBox Open Source Edition (OSE), as * available from http://www.virtualbox.org. This file is free software; diff --git a/src/VBox/HostDrivers/VBoxNetFlt/win/drv/VBoxNetFltRt-win.h b/src/VBox/HostDrivers/VBoxNetFlt/win/drv/VBoxNetFltRt-win.h index 1a188152..7d02493f 100644 --- a/src/VBox/HostDrivers/VBoxNetFlt/win/drv/VBoxNetFltRt-win.h +++ b/src/VBox/HostDrivers/VBoxNetFlt/win/drv/VBoxNetFltRt-win.h @@ -4,7 +4,7 @@ * NetFlt Runtime API */ /* - * Copyright (C) 2011 Oracle Corporation + * Copyright (C) 2011-2012 Oracle Corporation * * This file is part of VirtualBox Open Source Edition (OSE), as * available from http://www.virtualbox.org. This file is free software; diff --git a/src/VBox/HostDrivers/VBoxNetFlt/win/nobj/VBoxNetFltNobj.def b/src/VBox/HostDrivers/VBoxNetFlt/win/nobj/VBoxNetFltNobj.def index c11bf395..8aea0b69 100644 --- a/src/VBox/HostDrivers/VBoxNetFlt/win/nobj/VBoxNetFltNobj.def +++ b/src/VBox/HostDrivers/VBoxNetFlt/win/nobj/VBoxNetFltNobj.def @@ -4,7 +4,7 @@ ; Library def file ; ; -; Copyright (C) 2011 Oracle Corporation +; Copyright (C) 2011-2012 Oracle Corporation ; ; This file is part of VirtualBox Open Source Edition (OSE), as ; available from http://www.virtualbox.org. This file is free software; diff --git a/src/VBox/HostDrivers/VBoxNetFlt/win/nobj/VBoxNetFltNobj.h b/src/VBox/HostDrivers/VBoxNetFlt/win/nobj/VBoxNetFltNobj.h index 41f8523c..cf8087bf 100644 --- a/src/VBox/HostDrivers/VBoxNetFlt/win/nobj/VBoxNetFltNobj.h +++ b/src/VBox/HostDrivers/VBoxNetFlt/win/nobj/VBoxNetFltNobj.h @@ -14,8 +14,8 @@ * VirtualBox OSE distribution. VirtualBox OSE is distributed in the * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind. */ -#ifndef ___VboxNetFltNobj_h___ -#define ___VboxNetFltNobj_h___ +#ifndef ___VBoxNetFltNobj_h___ +#define ___VBoxNetFltNobj_h___ #include <windows.h> /* atl stuff */ @@ -70,4 +70,4 @@ private: BOOL mbInstalling; }; -#endif /* #ifndef ___VboxNetFltNobj_h___ */ +#endif /* #ifndef ___VBoxNetFltNobj_h___ */ diff --git a/src/VBox/HostDrivers/VBoxNetFlt/win/nobj/VBoxNetFltNobjRc.h b/src/VBox/HostDrivers/VBoxNetFlt/win/nobj/VBoxNetFltNobjRc.h index ba168a3b..5cbf1846 100644 --- a/src/VBox/HostDrivers/VBoxNetFlt/win/nobj/VBoxNetFltNobjRc.h +++ b/src/VBox/HostDrivers/VBoxNetFlt/win/nobj/VBoxNetFltNobjRc.h @@ -14,10 +14,10 @@ * VirtualBox OSE distribution. VirtualBox OSE is distributed in the * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind. */ -#ifndef ___VboxNetFltNobjRc_h___ -#define ___VboxNetFltNobjRc_h___ +#ifndef ___VBoxNetFltNobjRc_h___ +#define ___VBoxNetFltNobjRc_h___ /* registry script rc ID */ #define IDR_VBOXNETFLT_NOBJ 101 -#endif /* #ifndef ___VboxNetFltNobjRc_h___ */ +#endif /* #ifndef ___VBoxNetFltNobjRc_h___ */ diff --git a/src/VBox/HostDrivers/VBoxNetFlt/win/tools/VBoxNetAdpUninstall.cpp b/src/VBox/HostDrivers/VBoxNetFlt/win/tools/VBoxNetAdpUninstall.cpp index f5b1b780..bbc7b91c 100644 --- a/src/VBox/HostDrivers/VBoxNetFlt/win/tools/VBoxNetAdpUninstall.cpp +++ b/src/VBox/HostDrivers/VBoxNetFlt/win/tools/VBoxNetAdpUninstall.cpp @@ -4,7 +4,7 @@ */ /* - * Copyright (C) 2009 Oracle Corporation + * Copyright (C) 2009-2011 Oracle Corporation * * This file is part of VirtualBox Open Source Edition (OSE), as * available from http://www.virtualbox.org. This file is free software; diff --git a/src/VBox/HostDrivers/VBoxNetFlt/win/tools/VBoxNetFltInstall.cpp b/src/VBox/HostDrivers/VBoxNetFlt/win/tools/VBoxNetFltInstall.cpp index f8e93be0..d89d60db 100644 --- a/src/VBox/HostDrivers/VBoxNetFlt/win/tools/VBoxNetFltInstall.cpp +++ b/src/VBox/HostDrivers/VBoxNetFlt/win/tools/VBoxNetFltInstall.cpp @@ -4,7 +4,7 @@ */ /* - * Copyright (C) 2008 Oracle Corporation + * Copyright (C) 2008-2011 Oracle Corporation * * This file is part of VirtualBox Open Source Edition (OSE), as * available from http://www.virtualbox.org. This file is free software; diff --git a/src/VBox/HostDrivers/VBoxNetFlt/win/tools/VBoxNetFltUninstall.cpp b/src/VBox/HostDrivers/VBoxNetFlt/win/tools/VBoxNetFltUninstall.cpp index 7c016945..0c8ca409 100644 --- a/src/VBox/HostDrivers/VBoxNetFlt/win/tools/VBoxNetFltUninstall.cpp +++ b/src/VBox/HostDrivers/VBoxNetFlt/win/tools/VBoxNetFltUninstall.cpp @@ -4,7 +4,7 @@ */ /* - * Copyright (C) 2008 Oracle Corporation + * Copyright (C) 2008-2011 Oracle Corporation * * This file is part of VirtualBox Open Source Edition (OSE), as * available from http://www.virtualbox.org. This file is free software; |
