diff options
author | Ritesh Raj Sarraf <rrs@debian.org> | 2013-11-19 03:24:56 -0500 |
---|---|---|
committer | Ritesh Raj Sarraf <rrs@debian.org> | 2013-11-19 03:24:56 -0500 |
commit | 1d0b96390adf6a8d181d6daad57b7228e69ec9e0 (patch) | |
tree | 3ea3b604ff6f42a30270c75bb97bdfa40032e6b9 /src/VBox/NetworkServices/NetLib/VBoxNetBaseService.cpp | |
parent | 915d69eb315216560c765c50574aa84bd89b197b (diff) | |
download | virtualbox-1d0b96390adf6a8d181d6daad57b7228e69ec9e0.tar.gz |
Imported Upstream version 4.3.2-dfsg
Diffstat (limited to 'src/VBox/NetworkServices/NetLib/VBoxNetBaseService.cpp')
-rw-r--r-- | src/VBox/NetworkServices/NetLib/VBoxNetBaseService.cpp | 150 |
1 files changed, 120 insertions, 30 deletions
diff --git a/src/VBox/NetworkServices/NetLib/VBoxNetBaseService.cpp b/src/VBox/NetworkServices/NetLib/VBoxNetBaseService.cpp index 435a1cb8a..eedeeab89 100644 --- a/src/VBox/NetworkServices/NetLib/VBoxNetBaseService.cpp +++ b/src/VBox/NetworkServices/NetLib/VBoxNetBaseService.cpp @@ -21,6 +21,16 @@ *******************************************************************************/ #define LOG_GROUP LOG_GROUP_NET_SERVICE +#include <VBox/com/com.h> +#include <VBox/com/listeners.h> +#include <VBox/com/string.h> +#include <VBox/com/Guid.h> +#include <VBox/com/array.h> +#include <VBox/com/ErrorInfo.h> +#include <VBox/com/errorprint.h> +#include <VBox/com/EventQueue.h> +#include <VBox/com/VirtualBox.h> + #include <iprt/alloca.h> #include <iprt/buildconfig.h> #include <iprt/err.h> @@ -29,19 +39,23 @@ #include <iprt/initterm.h> #include <iprt/param.h> #include <iprt/path.h> +#include <iprt/process.h> #include <iprt/stream.h> #include <iprt/string.h> #include <iprt/time.h> #include <iprt/mem.h> +#include <iprt/message.h> #include <VBox/sup.h> #include <VBox/intnet.h> +#include <VBox/intnetinline.h> #include <VBox/vmm/vmm.h> #include <VBox/version.h> #include <vector> #include <string> +#include <VBox/err.h> #include <VBox/log.h> #include "VBoxNetLib.h" @@ -56,6 +70,11 @@ /******************************************************************************* * Structures and Typedefs * *******************************************************************************/ + +/******************************************************************************* +* Global Variables * +*******************************************************************************/ +/* Commonly used options for network configuration */ static RTGETOPTDEF g_aGetOptDef[] = { { "--name", 'N', RTGETOPT_REQ_STRING }, @@ -64,11 +83,34 @@ static RTGETOPTDEF g_aGetOptDef[] = { "--trunk-type", 'T', RTGETOPT_REQ_STRING }, { "--mac-address", 'a', RTGETOPT_REQ_MACADDR }, { "--ip-address", 'i', RTGETOPT_REQ_IPV4ADDR }, + { "--netmask", 'm', RTGETOPT_REQ_IPV4ADDR }, { "--verbose", 'v', RTGETOPT_REQ_NOTHING }, }; + + VBoxNetBaseService::VBoxNetBaseService() { + int rc = RTCritSectInit(&m_csThis); + AssertRC(rc); + /* numbers from DrvIntNet */ + m_cbSendBuf = 128 * _1K; + m_cbRecvBuf = 256 * _1K; + m_hIf = INTNET_HANDLE_INVALID; + m_pIfBuf = NULL; + + m_cVerbosity = 0; + m_Name = "VBoxNetNAT"; + m_Network = "intnet"; + + for(unsigned int i = 0; i < RT_ELEMENTS(g_aGetOptDef); ++i) + m_vecOptionDefs.push_back(&g_aGetOptDef[i]); + + HRESULT hrc = virtualbox.createLocalObject(CLSID_VirtualBox); + if (FAILED(hrc)) + RTMsgError("Failed to create the VirtualBox object!"); } + + VBoxNetBaseService::~VBoxNetBaseService() { /* @@ -91,23 +133,16 @@ VBoxNetBaseService::~VBoxNetBaseService() SUPR3Term(false /*fForced*/); m_pSession = NIL_RTR0PTR; } + RTCritSectDelete(&m_csThis); } + int VBoxNetBaseService::init() { - /* numbers from DrvIntNet */ - m_cbSendBuf = 36 * _1K; - m_cbRecvBuf = 218 * _1K; - m_hIf = INTNET_HANDLE_INVALID; - m_pIfBuf = NULL; - - m_cVerbosity = 0; - m_Name = "VBoxNetNAT"; - m_Network = "intnet"; - for(unsigned int i = 0; i < RT_ELEMENTS(g_aGetOptDef); ++i) - m_vecOptionDefs.push_back(&g_aGetOptDef[i]); return VINF_SUCCESS; } + + /** * Parse the arguments. * @@ -123,6 +158,10 @@ int VBoxNetBaseService::parseArgs(int argc, char **argv) PRTGETOPTDEF paOptionArray = getOptionsPtr(); int rc = RTGetOptInit(&State, argc, argv, paOptionArray, m_vecOptionDefs.size(), 0, 0 /*fFlags*/); AssertRCReturn(rc, 49); +#if 0 + /* default initialization */ + m_enmTrunkType = kIntNetTrunkType_WhateverNone; +#endif Log2(("BaseService: parseArgs enter\n")); for (;;) @@ -165,6 +204,9 @@ int VBoxNetBaseService::parseArgs(int argc, char **argv) case 'i': m_Ipv4Address = Val.IPv4Addr; break; + case 'm': + m_Ipv4Netmask = Val.IPv4Addr; + break; case 'v': m_cVerbosity++; @@ -175,14 +217,17 @@ int VBoxNetBaseService::parseArgs(int argc, char **argv) return 1; case 'h': - RTPrintf("VBoxNetDHCP Version %s\n" + RTPrintf("%s Version %sr%u\n" "(C) 2009-" VBOX_C_YEAR " " VBOX_VENDOR "\n" "All rights reserved.\n" "\n" - "Usage: VBoxNetDHCP <options>\n" + "Usage: %s <options>\n" "\n" "Options:\n", - RTBldCfgVersion()); + RTProcShortName(), + RTBldCfgVersion(), + RTBldCfgRevision(), + RTProcShortName()); for (unsigned int i = 0; i < m_vecOptionDefs.size(); i++) RTPrintf(" -%c, %s\n", m_vecOptionDefs[i]->iShort, m_vecOptionDefs[i]->pszLong); usage(); /* to print Service Specific usage */ @@ -203,6 +248,7 @@ int VBoxNetBaseService::parseArgs(int argc, char **argv) return rc; } + int VBoxNetBaseService::tryGoOnline(void) { /* @@ -304,27 +350,66 @@ int VBoxNetBaseService::tryGoOnline(void) return 1; } + void VBoxNetBaseService::shutdown(void) { } -/** - * Print debug message depending on the m_cVerbosity level. - * - * @param iMinLevel The minimum m_cVerbosity level for this message. - * @param fMsg Whether to dump parts for the current DHCP message. - * @param pszFmt The message format string. - * @param ... Optional arguments. - */ -inline void VBoxNetBaseService::debugPrint(int32_t iMinLevel, bool fMsg, const char *pszFmt, ...) const + +int VBoxNetBaseService::waitForIntNetEvent(int cMillis) { - if (iMinLevel <= m_cVerbosity) + int rc = VINF_SUCCESS; + INTNETIFWAITREQ WaitReq; + LogFlowFunc(("ENTER:cMillis: %d\n", cMillis)); + WaitReq.Hdr.u32Magic = SUPVMMR0REQHDR_MAGIC; + WaitReq.Hdr.cbReq = sizeof(WaitReq); + WaitReq.pSession = m_pSession; + WaitReq.hIf = m_hIf; + WaitReq.cMillies = cMillis; + + rc = SUPR3CallVMMR0Ex(NIL_RTR0PTR, NIL_VMCPUID, VMMR0_DO_INTNET_IF_WAIT, 0, &WaitReq.Hdr); + LogFlowFuncLeaveRC(rc); + return rc; +} + +/* S/G API */ +int VBoxNetBaseService::sendBufferOnWire(PCINTNETSEG pcSg, int cSg, size_t cbFrame) +{ + int rc = VINF_SUCCESS; + PINTNETHDR pHdr = NULL; + uint8_t *pu8Frame = NULL; + int offFrame = 0; + int idxSg = 0; + /* Allocate frame */ + rc = IntNetRingAllocateFrame(&m_pIfBuf->Send, cbFrame, &pHdr, (void **)&pu8Frame); + AssertRCReturn(rc, rc); + /* Now we fill pvFrame with S/G above */ + for (idxSg = 0; idxSg < cSg; ++idxSg) { - va_list va; - va_start(va, pszFmt); - debugPrintV(iMinLevel, fMsg, pszFmt, va); - va_end(va); + memcpy(&pu8Frame[offFrame], pcSg[idxSg].pv, pcSg[idxSg].cb); + offFrame+=pcSg[idxSg].cb; } + /* Commit */ + IntNetRingCommitFrame(&m_pIfBuf->Send, pHdr); + + LogFlowFuncLeaveRC(rc); + return rc; +} +/** + * forcible ask for send packet on the "wire" + */ +void VBoxNetBaseService::flushWire() +{ + int rc = VINF_SUCCESS; + INTNETIFSENDREQ SendReq; + SendReq.Hdr.u32Magic = SUPVMMR0REQHDR_MAGIC; + SendReq.Hdr.cbReq = sizeof(SendReq); + SendReq.pSession = m_pSession; + SendReq.hIf = m_hIf; + rc = SUPR3CallVMMR0Ex(NIL_RTR0PTR, NIL_VMCPUID, VMMR0_DO_INTNET_IF_SEND, 0, &SendReq.Hdr); + AssertRCReturnVoid(rc); + LogFlowFuncLeave(); + } @@ -332,7 +417,7 @@ inline void VBoxNetBaseService::debugPrint(int32_t iMinLevel, bool fMsg, const c * Print debug message depending on the m_cVerbosity level. * * @param iMinLevel The minimum m_cVerbosity level for this message. - * @param fMsg Whether to dump parts for the current DHCP message. + * @param fMsg Whether to dump parts for the current service message. * @param pszFmt The message format string. * @param va Optional arguments. */ @@ -342,12 +427,17 @@ void VBoxNetBaseService::debugPrintV(int iMinLevel, bool fMsg, const char *pszFm { va_list vaCopy; /* This dude is *very* special, thus the copy. */ va_copy(vaCopy, va); - RTStrmPrintf(g_pStdErr, "VBoxNetDHCP: %s: %N\n", iMinLevel >= 2 ? "debug" : "info", pszFmt, &vaCopy); + RTStrmPrintf(g_pStdErr, "%s: %s: %N\n", + RTProcShortName(), + iMinLevel >= 2 ? "debug" : "info", + pszFmt, + &vaCopy); va_end(vaCopy); } } + PRTGETOPTDEF VBoxNetBaseService::getOptionsPtr() { PRTGETOPTDEF pOptArray = NULL; |