DrvIntNet.cpp revision 984d7b1e36f54578e08e05c5a129d9bd6f9bbc0a
/* $Id$ */
/** @file
* DrvIntNet - Internal network transport driver.
*/
/*
* Copyright (C) 2006-2010 Oracle Corporation
*
* This file is part of VirtualBox Open Source Edition (OSE), as
* available from http://www.virtualbox.org. This file is free software;
* General Public License (GPL) as published by the Free Software
* Foundation, in version 2 as it comes in the "COPYING" file of the
* VirtualBox OSE distribution. VirtualBox OSE is distributed in the
* hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
*/
/*******************************************************************************
* Header Files *
*******************************************************************************/
#define LOG_GROUP LOG_GROUP_DRV_INTNET
#include <VBox/pdmnetinline.h>
#include <VBox/pdmnetifs.h>
#include <VBox/intnetinline.h>
#include <iprt/memcache.h>
#include <iprt/semaphore.h>
#include "../Builtins.h"
/*******************************************************************************
* Defined Constants And Macros *
*******************************************************************************/
/** Enables the ring-0 part. */
#define VBOX_WITH_DRVINTNET_IN_R0
/*******************************************************************************
* Structures and Typedefs *
*******************************************************************************/
/**
* The state of the asynchronous thread.
*/
typedef enum RECVSTATE
{
/** The thread is suspended. */
RECVSTATE_SUSPENDED = 1,
/** The thread is running. */
/** The thread must (/has) terminate. */
/** The usual 32-bit type blowup. */
RECVSTATE_32BIT_HACK = 0x7fffffff
} RECVSTATE;
/**
* Internal networking driver instance data.
*
* @implements PDMINETWORKUP
*/
typedef struct DRVINTNET
{
/** The network interface. */
/** The network interface. */
/** The network config interface.
* Can (in theory at least) be NULL. */
/** Pointer to the driver instance (ring-3). */
/** Pointer to the communication buffer (ring-3). */
/** Ring-3 base interface for the ring-0 context. */
/** Ring-3 base interface for the raw-mode context. */
/** The network interface for the ring-0 context. */
/** Pointer to the driver instance (ring-0). */
/** Pointer to the communication buffer (ring-0). */
/** The network interface for the raw-mode context. */
/** Pointer to the driver instance. */
/** The transmit lock. */
/** Interface handle. */
/** The receive thread state. */
RECVSTATE volatile enmRecvState;
/** The receive thread. */
/** The event semaphore that the receive thread waits on. */
/** The transmit thread. */
/** The event semaphore that the transmit thread waits on. */
/** The support driver session handle. */
/** Set if the link is down.
* When the link is down all incoming packets will be dropped. */
bool volatile fLinkDown;
/** Set when the xmit thread has been signalled. (atomic) */
bool volatile fXmitSignalled;
/** Set if the transmit thread the one busy transmitting. */
bool volatile fXmitOnXmitThread;
/** The xmit thread should process the ring ASAP. */
bool fXmitProcessRing;
/** Set if data transmission should start immediately and deactivate
* as late as possible. */
/** Padding. */
/** Scratch space for holding the ring-0 scatter / gather descriptor.
* The PDMSCATTERGATHER::fFlags member is used to indicate whether it is in
* use or not. Always accessed while owning the XmitLock. */
union
{
} u;
/** The network name. */
char szNetwork[INTNET_MAX_NETWORK_NAME];
/** Number of GSO packets sent. */
/** Number of GSO packets recevied. */
/** Number of packets send from ring-0. */
/** The number of times we've had to wake up the xmit thread to contine the
* ring-0 job. */
/** The number of times we've had to wake up the xmit thread to contine the
* ring-3 job. */
/** The times the xmit thread has been told to process the ring. */
#ifdef VBOX_WITH_STATISTICS
/** Profiling packet transmit runs. */
/** Profiling packet receive runs. */
#endif /* VBOX_WITH_STATISTICS */
#ifdef LOG_ENABLED
/** The nano ts of the last transfer. */
/** The nano ts of the last receive. */
#endif
} DRVINTNET;
/** Pointer to instance data of the internal networking driver. */
typedef DRVINTNET *PDRVINTNET;
#ifdef IN_RING3
/**
* Updates the MAC address on the kernel side.
*
* @returns VBox status code.
* @param pThis The driver instance.
*/
{
if (!pThis->pIAboveConfigR3)
return VINF_SUCCESS;
if (RT_SUCCESS(rc))
&SetMacAddressReq, sizeof(SetMacAddressReq));
Log(("drvR3IntNetUpdateMacAddress: %.*Rhxs rc=%Rrc\n", sizeof(SetMacAddressReq.Mac), &SetMacAddressReq.Mac, rc));
return rc;
}
/**
* Sets the kernel interface active or inactive.
*
* Worker for poweron, poweroff, suspend and resume.
*
* @returns VBox status code.
* @param pThis The driver instance.
* @param fActive The new state.
*/
{
if (!pThis->pIAboveConfigR3)
return VINF_SUCCESS;
&SetActiveReq, sizeof(SetActiveReq));
return rc;
}
#endif /* IN_RING3 */
/* -=-=-=-=- PDMINETWORKUP -=-=-=-=- */
/**
* Helper for signalling the xmit thread.
*
* @returns VERR_TRY_AGAIN (convenience).
* @param pThis The instance data..
*/
{
/// @todo if (!ASMAtomicXchgBool(&pThis->fXmitSignalled, true)) - needs careful optimizing.
{
}
return VERR_TRY_AGAIN;
}
/**
* Helper for processing the ring-0 consumer side of the xmit ring.
*
* The caller MUST own the xmit lock.
*
* @returns Status code from IntNetR0IfSend, except for VERR_TRY_AGAIN.
* @param pThis The instance data..
*/
{
#ifdef IN_RING3
int rc = PDMDrvHlpSUPCallVMMR0Ex(pThis->pDrvInsR3, VMMR0_DO_INTNET_IF_SEND, &SendReq, sizeof(SendReq));
#else
if (rc == VERR_TRY_AGAIN)
{
rc = VINF_SUCCESS;
}
#endif
return rc;
}
/**
* @interface_method_impl{PDMINETWORKUP,pfnBeginXmit}
*/
{
#ifndef IN_RING3
#endif
if (RT_SUCCESS(rc))
{
if (fOnWorkerThread)
{
}
}
else if (rc == VERR_SEM_BUSY)
{
/** @todo Does this actually make sense if the other dude is an EMT and so
* forth? I seriously think this is ring-0 only...
* We might end up waking up the xmit thread unnecessarily here, even when in
* ring-0... This needs some more thought and opitmizations when the ring-0 bits
* are working. */
#ifdef IN_RING3
if ( !fOnWorkerThread
/*&& !ASMAtomicUoReadBool(&pThis->fXmitOnXmitThread)
&& ASMAtomicCmpXchgBool(&pThis->fXmitSignalled, true, false)*/)
{
}
rc = VERR_TRY_AGAIN;
#else /* IN_RING0 */
#endif /* IN_RING0 */
}
return rc;
}
/**
* @interface_method_impl{PDMINETWORKUP,pfnAllocBuf}
*/
{
int rc = VINF_SUCCESS;
/*
* Allocate a S/G descriptor.
* This shouldn't normally fail as the NICs usually won't allocate more
* than one buffer at a time and the SG gets freed on sending.
*/
#ifdef IN_RING3
if (!pSgBuf)
return VERR_NO_MEMORY;
#else
return drvIntNetSignalXmit(pThis);
#endif
/*
* Allocate room in the ring buffer.
*
* In ring-3 we may have to process the xmit ring before there is
* sufficient buffer space since we might've stacked up a few frames to the
* trunk while in ring-0. (There is not point of doing this in ring-0.)
*/
if (pGso)
else
#ifdef IN_RING3
if ( RT_FAILURE(rc)
{
if (pGso)
else
}
#endif
if (RT_SUCCESS(rc))
{
/*
* Set up the S/G descriptor and return successfully.
*/
return VINF_SUCCESS;
}
#ifdef IN_RING3
/*
* If the above fails, then we're really out of space. There are nobody
* competing with us here because of the xmit lock.
*/
rc = VERR_NO_MEMORY;
#else /* IN_RING0 */
/*
* If the request is reasonable, kick the xmit thread and tell it to
* process the xmit ring ASAP.
*/
{
pThis->fXmitProcessRing = true;
}
else
rc = VERR_NO_MEMORY;
#endif /* IN_RING0 */
return rc;
}
/**
* @interface_method_impl{PDMINETWORKUP,pfnFreeBuf}
*/
{
#ifdef IN_RING0
#endif
/** @todo LATER: try unalloc the frame. */
#ifdef IN_RING3
#else
#endif
return VINF_SUCCESS;
}
/**
* @interface_method_impl{PDMINETWORKUP,pfnSendBuf}
*/
PDMBOTHCBDECL(int) drvIntNetUp_SendBuf(PPDMINETWORKUP pInterface, PPDMSCATTERGATHER pSgBuf, bool fOnWorkerThread)
{
/*
* Commit the frame and push it thru the switch.
*/
/*
* Free the descriptor and return.
*/
#ifdef IN_RING3
#else
#endif
return rc;
}
/**
* @interface_method_impl{PDMINETWORKUP,pfnEndXmit}
*/
{
}
/**
* @interface_method_impl{PDMINETWORKUP,pfnSetPromiscuousMode}
*/
{
#ifdef IN_RING3
int rc = PDMDrvHlpSUPCallVMMR0Ex(pThis->pDrvInsR3, VMMR0_DO_INTNET_IF_SET_PROMISCUOUS_MODE, &Req, sizeof(Req));
#else /* IN_RING0 */
#endif /* IN_RING0 */
}
#ifdef IN_RING3
/**
* @interface_method_impl{PDMINETWORKUP,pfnNotifyLinkChanged}
*/
static DECLCALLBACK(void) drvR3IntNetUp_NotifyLinkChanged(PPDMINETWORKUP pInterface, PDMNETWORKLINKSTATE enmLinkState)
{
bool fLinkDown;
switch (enmLinkState)
{
case PDMNETWORKLINKSTATE_DOWN:
fLinkDown = true;
break;
default:
case PDMNETWORKLINKSTATE_UP:
fLinkDown = false;
break;
}
LogFlow(("drvR3IntNetUp_NotifyLinkChanged: enmLinkState=%d %d->%d\n", enmLinkState, pThis->fLinkDown, fLinkDown));
}
/* -=-=-=-=- Transmit Thread -=-=-=-=- */
/**
* Async I/O thread for defered packet transmission.
*
* @returns VBox status code. Returning failure will naturally terminate the thread.
* @param pDrvIns The internal networking driver instance.
* @param pThread The thread.
*/
{
{
/*
* Transmit any pending packets.
*/
/** @todo Optimize this. We shouldn't call pfnXmitPending unless asked for.
* Also there is no need to call drvIntNetProcessXmit if we also
* called pfnXmitPending and send one or more frames. */
{
}
{
}
/*
* Block until we've got something to send or is supposed
* to leave the running state.
*/
break;
}
/* The thread is being initialized, suspended or terminated. */
return VINF_SUCCESS;
}
/**
* @copydoc FNPDMTHREADWAKEUPDRV
*/
{
}
/* -=-=-=-=- Receive Thread -=-=-=-=- */
/**
*
* @returns VINF_SUCCESS if space is available.
* @returns VERR_STATE_CHANGED if the state changed.
* @returns VBox status code on other errors.
* @param pThis Pointer to the instance data.
*/
{
LogFlow(("drvR3IntNetRecvWaitForSpace:\n"));
return rc;
}
/**
* Executes async I/O (RUNNING mode).
*
* @returns VERR_STATE_CHANGED if the state changed.
* @returns Appropriate VBox status code (error) on fatal error.
* @param pThis The driver instance data.
*/
{
/*
* The running loop - processing received data and waiting for more to arrive.
*/
for (;;)
{
/*
* Process the receive buffer.
*/
{
/*
* Check the state and then inspect the packet.
*/
{
LogFlow(("drvR3IntNetRecvRun: returns VERR_STATE_CHANGED (state changed - #0)\n"));
return VERR_STATE_CHANGED;
}
if ( ( u16Type == INTNETHDR_TYPE_FRAME
|| u16Type == INTNETHDR_TYPE_GSO)
{
/*
* Check if there is room for the frame and pass it up.
*/
if (rc == VINF_SUCCESS)
{
if (u16Type == INTNETHDR_TYPE_FRAME)
{
/*
* Normal frame.
*/
#ifdef LOG_ENABLED
if (LogIsEnabled())
{
LogFlow(("drvR3IntNetRecvRun: %-4d bytes at %llu ns deltas: r=%llu t=%llu\n",
Log2(("drvR3IntNetRecvRun: cbFrame=%#x\n"
"%.*Rhxd\n",
}
#endif
/* skip to the next frame. */
}
else
{
/*
* Generic segment offload frame (INTNETHDR_TYPE_GSO).
*
* This is where we do the offloading since we don't
* emulate any NICs with large receive offload (LRO).
*/
{
cbFrame -= sizeof(PDMNETWORKGSO);
#ifdef LOG_ENABLED
if (LogIsEnabled())
{
LogFlow(("drvR3IntNetRecvRun: %-4d bytes at %llu ns deltas: r=%llu t=%llu; GSO - %u segs\n",
Log2(("drvR3IntNetRecvRun: cbFrame=%#x type=%d cbHdrs=%#x Hdr1=%#x Hdr2=%#x MMS=%#x\n"
"%.*Rhxd\n",
}
#endif
{
if (RT_FAILURE(rc))
{
break; /* we drop the rest. */
}
}
}
else
{
AssertMsgFailed(("cbFrame=%#x type=%d cbHdrs=%#x Hdr1=%#x Hdr2=%#x MMS=%#x\n",
}
}
}
else
{
/*
* Wait for sufficient space to become available and then retry.
*/
if (RT_FAILURE(rc))
{
if (rc == VERR_INTERRUPTED)
{
/*
* NIC is going down, likely because the VM is being reset. Skip the frame.
*/
AssertMsg(IntNetIsValidFrameType(pHdr->u16Type), ("Unknown frame type %RX16! offRead=%#x\n", pHdr->u16Type, pRingBuf->offReadX));
}
else
{
return rc;
}
}
}
}
else
{
/*
* Link down or unknown frame - skip to the next frame.
*/
AssertMsg(IntNetIsValidFrameType(pHdr->u16Type), ("Unknown frame type %RX16! offRead=%#x\n", pHdr->u16Type, pRingBuf->offReadX));
}
} /* while more received data */
/*
* Wait for data, checking the state before we block.
*/
{
LogFlow(("drvR3IntNetRecvRun: returns VINF_SUCCESS (state changed - #1)\n"));
return VERR_STATE_CHANGED;
}
if ( RT_FAILURE(rc)
&& rc != VERR_TIMEOUT
&& rc != VERR_INTERRUPTED)
{
return rc;
}
}
}
/**
* Asynchronous I/O thread for handling receive.
*
* @returns VINF_SUCCESS (ignored).
* @param ThreadSelf Thread handle.
* @param pvUser Pointer to a DRVINTNET structure.
*/
{
/*
* The main loop - acting on state.
*/
for (;;)
{
switch (enmRecvState)
{
case RECVSTATE_SUSPENDED:
{
if ( RT_FAILURE(rc)
&& rc != VERR_TIMEOUT)
{
return rc;
}
break;
}
case RECVSTATE_RUNNING:
{
if ( rc != VERR_STATE_CHANGED
&& RT_FAILURE(rc))
{
return rc;
}
break;
}
default:
case RECVSTATE_TERMINATE:
LogFlow(("drvR3IntNetRecvThread: returns VINF_SUCCESS\n"));
return VINF_SUCCESS;
}
}
}
/* -=-=-=-=- PDMIBASERC -=-=-=-=- */
/**
* @interface_method_impl{PDMIBASERC,pfnQueryInterface}
*/
static DECLCALLBACK(RTRCPTR) drvR3IntNetIBaseRC_QueryInterface(PPDMIBASERC pInterface, const char *pszIID)
{
#if 0
#endif
return NIL_RTRCPTR;
}
/* -=-=-=-=- PDMIBASER0 -=-=-=-=- */
/**
* @interface_method_impl{PDMIBASER0,pfnQueryInterface}
*/
static DECLCALLBACK(RTR0PTR) drvR3IntNetIBaseR0_QueryInterface(PPDMIBASER0 pInterface, const char *pszIID)
{
#ifdef VBOX_WITH_DRVINTNET_IN_R0
#endif
return NIL_RTR0PTR;
}
/* -=-=-=-=- PDMIBASE -=-=-=-=- */
/**
* @interface_method_impl{PDMIBASE,pfnQueryInterface}
*/
static DECLCALLBACK(void *) drvR3IntNetIBase_QueryInterface(PPDMIBASE pInterface, const char *pszIID)
{
return NULL;
}
/* -=-=-=-=- PDMDRVREG -=-=-=-=- */
/**
* Power Off notification.
*
* @param pDrvIns The driver instance.
*/
{
LogFlow(("drvR3IntNetPowerOff\n"));
{
}
}
/**
* drvR3IntNetResume helper.
*/
{
/*
* Add the frame to the send buffer and push it onto the network.
*/
if ( rc == VERR_BUFFER_OVERFLOW
{
}
if (RT_SUCCESS(rc))
{
}
return rc;
}
/**
* Resume notification.
*
* @param pDrvIns The driver instance.
*/
{
LogFlow(("drvR3IntNetPowerResume\n"));
{
}
&& pThis->pIAboveConfigR3)
{
/*
* We've just been teleported and need to drop a hint to the switch
* since we're likely to have changed to a different port. We just
* push out some ethernet frame that doesn't mean anything to anyone.
* For this purpose ethertype 0x801e was chosen since it was registered
*/
union
{
} Frame;
if (RT_SUCCESS(rc))
if (RT_FAILURE(rc))
}
}
/**
* Suspend notification.
*
* @param pDrvIns The driver instance.
*/
{
LogFlow(("drvR3IntNetPowerSuspend\n"));
{
}
}
/**
* Power On notification.
*
* @param pDrvIns The driver instance.
*/
{
LogFlow(("drvR3IntNetPowerOn\n"));
{
}
}
/**
* @interface_method_impl{PDMDRVREG,pfnRelocate}
*/
{
/* nothing to do here yet */
}
/**
* Destruct a driver instance.
*
* Most VM resources are freed by the VM. This callback is provided so that any non-VM
* resources can be freed correctly.
*
* @param pDrvIns The driver instance data.
*/
{
LogFlow(("drvR3IntNetDestruct\n"));
/*
* Indicate to the receive thread that it's time to quit.
*/
if (hRecvEvt != NIL_RTSEMEVENT)
{
AbortWaitReq.fNoMoreWaits = true;
int rc = PDMDrvHlpSUPCallVMMR0Ex(pDrvIns, VMMR0_DO_INTNET_IF_ABORT_WAIT, &AbortWaitReq, sizeof(AbortWaitReq));
}
/*
* Wait for the threads to terminate.
*/
if (pThis->pXmitThread)
{
}
{
}
/*
* Deregister statistics in case we're being detached.
*/
{
#ifdef VBOX_WITH_STATISTICS
#endif
}
/*
* Close the interface
*/
{
}
/*
* Destroy the semaphores, S/G cache and xmit lock.
*/
if (hRecvEvt != NIL_RTSEMEVENT)
{
}
}
/**
* Construct a TAP network transport driver instance.
*
* @copydoc FNPDMDRVCONSTRUCT
*/
{
bool f;
/*
* Init the static parts.
*/
pThis->fActivateEarlyDeactivateLate = false;
/* IBase* */
/* INetworkUp */
/*
* Validate the config.
*/
if (!CFGMR3AreValuesValid(pCfg,
"Network\0"
"Trunk\0"
"TrunkType\0"
"ReceiveBufferSize\0"
"SendBufferSize\0"
"RestrictAccess\0"
"SharedMacOnWire\0"
"IgnoreAllPromisc\0"
"QuietlyIgnoreAllPromisc\0"
"IgnoreClientPromisc\0"
"QuietlyIgnoreClientPromisc\0"
"IgnoreTrunkWirePromisc\0"
"QuietlyIgnoreTrunkWirePromisc\0"
"IgnoreTrunkHostPromisc\0"
"QuietlyIgnoreTrunkHostPromisc\0"
"IsService\0"))
/*
* Check that no-one is attached to us.
*/
("Configuration error: Not possible to attach anything to this driver!\n"),
/*
* Query the network port interface.
*/
if (!pThis->pIAboveNet)
{
AssertMsgFailed(("Configuration error: the above device/driver didn't export the network port interface!\n"));
return VERR_PDM_MISSING_INTERFACE_ABOVE;
}
/*
* Read the configuration.
*/
/** @cfgm{Network, string}
* The name of the internal network to connect to.
*/
if (RT_FAILURE(rc))
N_("Configuration error: Failed to get the \"Network\" value"));
/** @cfgm{TrunkType, uint32_t, kIntNetTrunkType_None}
* The trunk connection type see INTNETTRUNKTYPE.
*/
if (rc == VERR_CFGM_VALUE_NOT_FOUND)
else if (RT_FAILURE(rc))
N_("Configuration error: Failed to get the \"TrunkType\" value"));
/** @cfgm{Trunk, string, ""}
* The name of the trunk connection.
*/
if (rc == VERR_CFGM_VALUE_NOT_FOUND)
else if (RT_FAILURE(rc))
N_("Configuration error: Failed to get the \"Trunk\" value"));
/** @cfgm{RestrictAccess, boolean, true}
* Whether to restrict the access to the network or if it should be public. Everyone on
* the computer can connect to a public network. Don't change this.
*/
bool fRestrictAccess;
if (rc == VERR_CFGM_VALUE_NOT_FOUND)
fRestrictAccess = true;
else if (RT_FAILURE(rc))
N_("Configuration error: Failed to get the \"RestrictAccess\" value"));
/** @cfgm{IgnoreAllPromisc, boolean, false}
* When set all request for operating any interface or trunk in promiscuous
* mode will be ignored. */
if (RT_FAILURE(rc))
N_("Configuration error: Failed to get the \"IgnoreAllPromisc\" value"));
if (f)
/** @cfgm{QuietlyIgnoreAllPromisc, boolean, false}
* When set all request for operating any interface or trunk in promiscuous
* mode will be ignored. This differs from IgnoreAllPromisc in that clients
* won't get VERR_INTNET_INCOMPATIBLE_FLAGS. */
if (RT_FAILURE(rc))
N_("Configuration error: Failed to get the \"QuietlyIgnoreAllPromisc\" value"));
if (f)
/** @cfgm{IgnoreClientPromisc, boolean, false}
* When set all request for operating any non-trunk interface in promiscuous
* mode will be ignored. */
if (RT_FAILURE(rc))
N_("Configuration error: Failed to get the \"IgnoreClientPromisc\" value"));
if (f)
/** @cfgm{QuietlyIgnoreClientPromisc, boolean, false}
* When set all request for operating any non-trunk interface promiscuous mode
* will be ignored. This differs from IgnoreClientPromisc in that clients won't
* get VERR_INTNET_INCOMPATIBLE_FLAGS. */
if (RT_FAILURE(rc))
N_("Configuration error: Failed to get the \"QuietlyIgnoreClientPromisc\" value"));
if (f)
/** @cfgm{IgnoreTrunkWirePromisc, boolean, false}
* When set all request for operating the trunk-wire connection in promiscuous
* mode will be ignored. */
if (RT_FAILURE(rc))
N_("Configuration error: Failed to get the \"IgnoreTrunkWirePromisc\" value"));
if (f)
/** @cfgm{QuietlyIgnoreTrunkWirePromisc, boolean, false}
* When set all request for operating any trunk-wire connection promiscuous mode
* will be ignored. This differs from IgnoreTrunkWirePromisc in that clients
* won't get VERR_INTNET_INCOMPATIBLE_FLAGS. */
if (RT_FAILURE(rc))
N_("Configuration error: Failed to get the \"QuietlyIgnoreTrunkWirePromisc\" value"));
if (f)
/** @cfgm{IgnoreTrunkHostPromisc, boolean, false}
* When set all request for operating the trunk-host connection in promiscuous
* mode will be ignored. */
if (RT_FAILURE(rc))
N_("Configuration error: Failed to get the \"IgnoreTrunkHostPromisc\" value"));
if (f)
/** @cfgm{QuietlyIgnoreTrunkHostPromisc, boolean, false}
* When set all request for operating any trunk-host connection promiscuous mode
* will be ignored. This differs from IgnoreTrunkHostPromisc in that clients
* won't get VERR_INTNET_INCOMPATIBLE_FLAGS. */
if (RT_FAILURE(rc))
N_("Configuration error: Failed to get the \"QuietlyIgnoreTrunkHostPromisc\" value"));
if (f)
/** @todo flags for not sending to the host and for setting the trunk-wire
* connection in promiscuous mode. */
/** @cfgm{SharedMacOnWire, boolean, false}
* Whether to shared the MAC address of the host interface when using the wire. When
* attaching to a wireless NIC this option is usally a requirement.
*/
bool fSharedMacOnWire;
if (RT_FAILURE(rc))
N_("Configuration error: Failed to get the \"SharedMacOnWire\" value"));
if (fSharedMacOnWire)
/** @cfgm{ReceiveBufferSize, uint32_t, 318 KB}
* The size of the receive buffer.
*/
if (rc == VERR_CFGM_VALUE_NOT_FOUND)
else if (RT_FAILURE(rc))
N_("Configuration error: Failed to get the \"ReceiveBufferSize\" value"));
/** @cfgm{SendBufferSize, uint32_t, 196 KB}
* The size of the send (transmit) buffer.
* This should be more than twice the size of the larges frame size because
* the ring buffer is very simple and doesn't support splitting up frames
* nor inserting padding. So, if this is too close to the frame size the
* header will fragment the buffer such that the frame won't fit on either
* side of it and the code will get very upset about it all.
*/
if (rc == VERR_CFGM_VALUE_NOT_FOUND)
else if (RT_FAILURE(rc))
N_("Configuration error: Failed to get the \"SendBufferSize\" value"));
N_("Configuration error: The \"SendBufferSize\" value is too small"));
LogRel(("DrvIntNet: Warning! SendBufferSize=%u, Recommended minimum size %u butes.\n", OpenReq.cbSend, VBOX_MAX_GSO_SIZE * 4));
/** @cfgm{IsService, boolean, true}
* This alterns the way the thread is suspended and resumed. When it's being used by
*/
if (rc == VERR_CFGM_VALUE_NOT_FOUND)
pThis->fActivateEarlyDeactivateLate = false;
else if (RT_FAILURE(rc))
N_("Configuration error: Failed to get the \"IsService\" value"));
LogRel(("IntNet#%u: szNetwork={%s} enmTrunkType=%d szTrunk={%s} fFlags=%#x cbRecv=%u cbSend=%u\n",
#ifdef RT_OS_DARWIN
/* Temporary hack: attach to a network with the name 'if=en0' and you're hitting the wire. */
{
}
/* Temporary hack: attach to a network with the name 'wif=en0' and you're on the air. */
{
}
#endif /* DARWIN */
/*
* Create the event semaphore, S/G cache and xmit critsect.
*/
if (RT_FAILURE(rc))
return rc;
rc = RTMemCacheCreate(&pThis->hSgCache, sizeof(PDMSCATTERGATHER), 0, UINT32_MAX, NULL, NULL, pThis, 0);
if (RT_FAILURE(rc))
return rc;
if (RT_FAILURE(rc))
return rc;
/*
* Create the interface.
*/
if (RT_FAILURE(rc))
/*
* Get default buffer.
*/
rc = PDMDrvHlpSUPCallVMMR0Ex(pDrvIns, VMMR0_DO_INTNET_IF_GET_BUFFER_PTRS, &GetBufferPtrsReq, sizeof(GetBufferPtrsReq));
if (RT_FAILURE(rc))
/*
* Register statistics.
*/
PDMDrvHlpSTAMRegCounterEx(pDrvIns, &pThis->pBufR3->Recv.cbStatWritten, "Bytes/Received", STAMUNIT_BYTES, "Number of received bytes.");
PDMDrvHlpSTAMRegCounterEx(pDrvIns, &pThis->pBufR3->Send.cbStatWritten, "Bytes/Sent", STAMUNIT_BYTES, "Number of sent bytes.");
PDMDrvHlpSTAMRegCounter(pDrvIns, &pThis->pBufR3->Recv.cOverflows, "Overflows/Recv", "Number overflows.");
PDMDrvHlpSTAMRegCounter(pDrvIns, &pThis->pBufR3->Send.cOverflows, "Overflows/Sent", "Number overflows.");
PDMDrvHlpSTAMRegCounter(pDrvIns, &pThis->pBufR3->Recv.cStatFrames, "Packets/Received", "Number of received packets.");
PDMDrvHlpSTAMRegCounter(pDrvIns, &pThis->pBufR3->Send.cStatFrames, "Packets/Sent", "Number of sent packets.");
PDMDrvHlpSTAMRegCounter(pDrvIns, &pThis->StatReceivedGso, "Packets/Received-Gso", "The GSO portion of the received packets.");
PDMDrvHlpSTAMRegCounter(pDrvIns, &pThis->StatSentGso, "Packets/Sent-Gso", "The GSO portion of the sent packets.");
PDMDrvHlpSTAMRegCounter(pDrvIns, &pThis->StatSentR0, "Packets/Sent-R0", "The ring-0 portion of the sent packets.");
PDMDrvHlpSTAMRegCounter(pDrvIns, &pThis->pBufR3->cStatLost, "Packets/Lost", "Number of lost packets.");
PDMDrvHlpSTAMRegCounter(pDrvIns, &pThis->pBufR3->cStatYieldsNok, "YieldOk", "Number of times yielding helped fix an overflow.");
PDMDrvHlpSTAMRegCounter(pDrvIns, &pThis->pBufR3->cStatYieldsOk, "YieldNok", "Number of times yielding didn't help fix an overflow.");
PDMDrvHlpSTAMRegCounter(pDrvIns, &pThis->pBufR3->cStatBadFrames, "BadFrames", "Number of bad frames seed by the consumers.");
PDMDrvHlpSTAMRegProfile(pDrvIns, &pThis->pBufR3->StatSend2, "Send2", "Profiling sending to the trunk.");
PDMDrvHlpSTAMRegProfile(pDrvIns, &pThis->pBufR3->StatRecv1, "Recv1", "Reserved for future receive profiling.");
PDMDrvHlpSTAMRegProfile(pDrvIns, &pThis->pBufR3->StatRecv2, "Recv2", "Reserved for future receive profiling.");
PDMDrvHlpSTAMRegProfile(pDrvIns, &pThis->pBufR3->StatReserved, "Reserved", "Reserved for future use.");
#ifdef VBOX_WITH_STATISTICS
PDMDrvHlpSTAMRegProfileAdv(pDrvIns, &pThis->StatReceive, "Receive", "Profiling packet receive runs.");
PDMDrvHlpSTAMRegProfile(pDrvIns, &pThis->StatTransmit, "Transmit", "Profiling packet transmit runs.");
#endif
PDMDrvHlpSTAMRegCounter(pDrvIns, &pThis->StatXmitWakeupR0, "XmitWakeup-R0", "Xmit thread wakeups from ring-0.");
PDMDrvHlpSTAMRegCounter(pDrvIns, &pThis->StatXmitWakeupR3, "XmitWakeup-R3", "Xmit thread wakeups from ring-3.");
PDMDrvHlpSTAMRegCounter(pDrvIns, &pThis->StatXmitProcessRing, "XmitProcessRing", "Time xmit thread was told to process the ring.");
/*
* Create the async I/O threads.
* Note! Using a PDM thread here doesn't fit with the IsService=true operation.
*/
if (RT_FAILURE(rc))
{
return rc;
}
#ifdef VBOX_WITH_DRVINTNET_IN_R0
/*
* Resolve the ring-0 context interface addresses.
*/
rc = pDrvIns->pHlpR3->pfnLdrGetR0InterfaceSymbols(pDrvIns, &pThis->INetworkUpR0, sizeof(pThis->INetworkUpR0),
"drvIntNetUp_", PDMINETWORKUP_SYM_LIST);
#endif
/*
* Activate data transmission as early as possible
*/
{
}
return rc;
}
/**
* Internal networking transport driver registration record.
*/
const PDMDRVREG g_DrvIntNet =
{
/* u32Version */
/* szName */
"IntNet",
/* szRCMod */
"VBoxDDGC.rc",
/* szR0Mod */
"VBoxDDR0.r0",
/* pszDescription */
"Internal Networking Transport Driver",
/* fFlags */
#ifdef VBOX_WITH_DRVINTNET_IN_R0
#else
#endif
/* fClass. */
/* cMaxInstances */
~0,
/* cbInstance */
sizeof(DRVINTNET),
/* pfnConstruct */
/* pfnDestruct */
/* pfnRelocate */
/* pfnIOCtl */
NULL,
/* pfnPowerOn */
/* pfnReset */
NULL,
/* pfnSuspend */
/* pfnResume */
/* pfnAttach */
NULL,
/* pfnDetach */
NULL,
/* pfnPowerOff */
/* pfnSoftReset */
NULL,
/* u32EndVersion */
};
#endif /* IN_RING3 */