VBoxNetAdp.c revision 57a2e9fd8744c4af7450639313f3216787e07ff5
af062818b47340eef15700d2f0211576ba3506eevboxsync * VBoxNetAdp - Virtual Network Adapter Driver (Host), Common Code.
af062818b47340eef15700d2f0211576ba3506eevboxsync * Copyright (C) 2008-2009 Oracle Corporation
af062818b47340eef15700d2f0211576ba3506eevboxsync * This file is part of VirtualBox Open Source Edition (OSE), as
af062818b47340eef15700d2f0211576ba3506eevboxsync * available from http://www.virtualbox.org. This file is free software;
af062818b47340eef15700d2f0211576ba3506eevboxsync * you can redistribute it and/or modify it under the terms of the GNU
af062818b47340eef15700d2f0211576ba3506eevboxsync * General Public License (GPL) as published by the Free Software
af062818b47340eef15700d2f0211576ba3506eevboxsync * Foundation, in version 2 as it comes in the "COPYING" file of the
af062818b47340eef15700d2f0211576ba3506eevboxsync * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
af062818b47340eef15700d2f0211576ba3506eevboxsync * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
af062818b47340eef15700d2f0211576ba3506eevboxsync/** @page pg_netadp VBoxNetAdp - Network Adapter
4b9d6701570cb98fd36e209314239d104ec584d3vboxsync * This is a kernel module that creates a virtual interface that can be attached
4b9d6701570cb98fd36e209314239d104ec584d3vboxsync * to an internal network.
589fd26cedb2b4ebbed14f2964cad03cc8ebbca2vboxsync * In the big picture we're one of the three trunk interface on the internal
589fd26cedb2b4ebbed14f2964cad03cc8ebbca2vboxsync * network, the one named "TAP Interface": @image html Networking_Overview.gif
af062818b47340eef15700d2f0211576ba3506eevboxsync/*******************************************************************************
af062818b47340eef15700d2f0211576ba3506eevboxsync* Header Files *
af062818b47340eef15700d2f0211576ba3506eevboxsync*******************************************************************************/
af062818b47340eef15700d2f0211576ba3506eevboxsync/** r=bird: why is this here in the agnostic code? */
af062818b47340eef15700d2f0211576ba3506eevboxsync/*******************************************************************************
af062818b47340eef15700d2f0211576ba3506eevboxsync* Defined Constants And Macros *
af062818b47340eef15700d2f0211576ba3506eevboxsync*******************************************************************************/
af062818b47340eef15700d2f0211576ba3506eevboxsync ( (PVBOXNETADP)((uint8_t *)pIfPort - RT_OFFSETOF(VBOXNETADP, MyPort)) )
af062818b47340eef15700d2f0211576ba3506eevboxsyncAssertCompileMemberSize(VBOXNETADP, enmState, sizeof(uint32_t));
af062818b47340eef15700d2f0211576ba3506eevboxsync * Gets the enmState member atomically.
af062818b47340eef15700d2f0211576ba3506eevboxsync * Used for all reads.
af062818b47340eef15700d2f0211576ba3506eevboxsync * @returns The enmState value.
Log(("vboxNetAdpSetState: pThis=%p, state change: %d -> %d.\n", pThis, vboxNetAdpGetState(pThis), enmNewState));
return enmState;
DECLINLINE(bool) vboxNetAdpCheckAndSetState(PVBOXNETADP pThis, VBOXNETADPSTATE enmOldState, VBOXNETADPSTATE enmNewState)
fRc = false;
if (fRc)
Log(("vboxNetAdpCheckAndSetState: pThis=%p, state changed: %d -> %d.\n", pThis, enmOldState, enmNewState));
Log(("vboxNetAdpCheckAndSetState: pThis=%p, no state change: %d != %d (expected).\n", pThis, enmActualState, enmOldState));
return fRc;
return pThis;
return NULL;
if (!cBusy)
bool fCanReceive = false;
fCanReceive = true;
return fCanReceive;
static DECLCALLBACK(int) vboxNetAdpPortXmit(PINTNETTRUNKIFPORT pIfPort, PINTNETSG pSG, uint32_t fDst)
return VERR_INVALID_STATE;
return rc;
int rc;
return rc;
bool fPreviouslyActive;
Log(("vboxNetAdpPortSetActive: pThis=%p, fActive=%d, state before: %d.\n", pThis, fActive, vboxNetAdpGetState(pThis)));
case kVBoxNetAdpState_Active:
return fPreviouslyActive;
int rc;
PVBOXNETADPGLOBALS pGlobals = (PVBOXNETADPGLOBALS)((uint8_t *)pIfFactory - RT_OFFSETOF(VBOXNETADPGLOBALS, TrunkFactory));
return rc;
return VERR_OUT_OF_RESOURCES;
return VERR_INTNET_FLT_IF_BUSY;
return rc;
static int vboxNetAdpConnectIt(PVBOXNETADP pThis, PINTNETTRUNKSWPORT pSwitchPort, PINTNETTRUNKIFPORT *ppIfPort)
int rc;
return rc;
static DECLCALLBACK(int) vboxNetAdpFactoryCreateAndConnect(PINTNETTRUNKFACTORY pIfFactory, const char *pszName,
PVBOXNETADPGLOBALS pGlobals = (PVBOXNETADPGLOBALS)((uint8_t *)pIfFactory - RT_OFFSETOF(VBOXNETADPGLOBALS, TrunkFactory));
int rc;
LogFlow(("vboxNetAdpFactoryCreateAndConnect: pszName=%p:{%s} fFlags=%#x\n", pszName, pszName, fFlags));
if (pThis)
vboxNetAdpSetStateWithLock(pThis, RT_SUCCESS(rc) ? kVBoxNetAdpState_Connected : kVBoxNetAdpState_Available);
return rc;
PVBOXNETADPGLOBALS pGlobals = (PVBOXNETADPGLOBALS)((uint8_t *)pIfFactory - RT_OFFSETOF(VBOXNETADPGLOBALS, TrunkFactory));
static DECLCALLBACK(void *) vboxNetAdpQueryFactoryInterface(PCSUPDRVFACTORY pSupDrvFactory, PSUPDRVSESSION pSession, const char *pszInterfaceUuid)
PVBOXNETADPGLOBALS pGlobals = (PVBOXNETADPGLOBALS)((uint8_t *)pSupDrvFactory - RT_OFFSETOF(VBOXNETADPGLOBALS, SupDrvFactory));
#ifdef LOG_ENABLED
return NULL;
fRc = false;
int rc;
return VERR_WRONG_ORDER;
return VERR_WRONG_ORDER;
return rc;
int rc;
return rc;
return rc;
#ifdef VBOXNETADP_STATIC_CONFIG
return rc;
return rc;
return rc;
int rc;
rc = SUPR0IdcOpen(&pGlobals->SupDrvIDC, 0 /* iReqVersion = default */, 0 /* iMinVersion = default */, NULL, NULL, NULL);
return rc;
return rc;
return rc;
return rc;
bool fOld;
bool fOld;
int iUnit;
if (iUnit < 0)
} while (fOld);
return iUnit;
int rc;
if (ASMAtomicCmpXchgU32((uint32_t volatile *)&pThis->enmState, kVBoxNetAdpState_Transitional, kVBoxNetAdpState_Invalid))
if (pcszName)
return rc;
return VERR_OUT_OF_RESOURCES;
if (!ASMAtomicCmpXchgU32((uint32_t volatile *)&pThis->enmState, kVBoxNetAdpState_Transitional, kVBoxNetAdpState_Active))
return VERR_INTNET_FLT_IF_BUSY;
return rc;
int vboxNetAdpInit(void)
return VINF_SUCCESS;
return pThis;
return NULL;
void vboxNetAdpShutdown(void)