VirtualBox

Ignore:
Timestamp:
Oct 10, 2022 4:30:56 PM (2 years ago)
Author:
vboxsync
Message:

NetworkServices: Implement support for communicating over the R3 internal network service in driverless mode, bugref:10297

Location:
trunk/src/VBox/NetworkServices/Dhcpd
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/NetworkServices/Dhcpd/Makefile.kmk

    r96407 r97071  
    6565VBoxNetDHCP_DEFS      = KBUILD_TYPE=\"$(KBUILD_TYPE)\"
    6666endif
    67 #VBoxNetDHCP_DEFS     = IPv6
     67VBoxNetDHCP_DEFS       += \
     68        $(if $(VBOX_WITH_INTNET_SERVICE_IN_R3),VBOX_WITH_INTNET_SERVICE_IN_R3,)
     69
     70#VBoxNetDHCP_DEFS     += IPv6
    6871#VBoxNetDHCP_DEFS.linux = WITH_VALGRIND
    6972ifneq ($(KBUILD_TARGET),win)
     
    7578 endif
    7679endif
     80VBoxNetDHCP_INCS += \
     81        ../NetLib
    7782VBoxNetDHCP_SOURCES = \
    7883        ClientId.cpp \
     
    8590        Timestamp.cpp \
    8691        VBoxNetDhcpd.cpp \
     92        ../NetLib/IntNetIfCtx.cpp \
    8793        ../../Main/glue/VBoxLogRelCreate.cpp \
    8894        ../../Main/glue/GetVBoxUserHomeDirectory.cpp \
  • trunk/src/VBox/NetworkServices/Dhcpd/VBoxNetDhcpd.cpp

    r96407 r97071  
    8888#endif
    8989
     90#include "IntNetIf.h"
     91
    9092struct delete_pbuf
    9193{
     
    9799
    98100
    99 #define CALL_VMMR0(op, req) \
    100     (SUPR3CallVMMR0Ex(NIL_RTR0PTR, NIL_VMCPUID, (op), 0, &(req).Hdr))
    101 
    102 
    103101class VBoxNetDhcpd
    104102{
     
    109107
    110108    /* intnet plumbing */
    111     PSUPDRVSESSION m_pSession;
    112     INTNETIFHANDLE m_hIf;
    113     PINTNETBUF m_pIfBuf;
     109    INTNETIFCTX    m_hIf;
     110    PINTNETBUF     m_pIfBuf;
    114111
    115112    /* lwip stack connected to the intnet */
     
    178175VBoxNetDhcpd::VBoxNetDhcpd()
    179176  : m_pStderrReleaseLogger(NULL),
    180     m_pSession(NIL_RTR0PTR),
    181177    m_hIf(INTNET_HANDLE_INVALID),
    182178    m_pIfBuf(NULL),
     
    185181    m_Dhcp4Pcb(NULL)
    186182{
    187     int rc;
    188 
    189183    logInitStderr();
    190 
    191     rc = r3Init();
    192     if (RT_FAILURE(rc))
    193         return;
    194 
    195     vmmInit();
    196184}
    197185
     
    200188{
    201189    ifClose();
    202     r3Fini();
    203190}
    204191
     
    241228
    242229
    243 int VBoxNetDhcpd::r3Init()
    244 {
    245     AssertReturn(m_pSession == NIL_RTR0PTR, VERR_GENERAL_FAILURE);
    246 
    247     int rc = SUPR3Init(&m_pSession);
    248     return rc;
    249 }
    250 
    251 
    252 void VBoxNetDhcpd::r3Fini()
    253 {
    254     if (m_pSession == NIL_RTR0PTR)
    255         return;
    256 
    257     SUPR3Term();
    258     m_pSession = NIL_RTR0PTR;
    259 }
    260 
    261 
    262 int VBoxNetDhcpd::vmmInit()
    263 {
    264     char szPathVMMR0[RTPATH_MAX];
    265     int rc = RTPathExecDir(szPathVMMR0, sizeof(szPathVMMR0));
    266     if (RT_SUCCESS(rc))
    267         rc = RTPathAppend(szPathVMMR0, sizeof(szPathVMMR0), "VMMR0.r0");
    268     if (RT_SUCCESS(rc))
    269         rc = SUPR3LoadVMM(szPathVMMR0, NULL /*pErrInfo*/);
    270     return rc;
    271 }
    272 
    273 
    274230int VBoxNetDhcpd::ifInit(const RTCString &strNetwork,
    275231                         const RTCString &strTrunk,
     
    298254                         INTNETTRUNKTYPE enmTrunkType)
    299255{
    300     AssertReturn(m_pSession != NIL_RTR0PTR, VERR_GENERAL_FAILURE);
    301     AssertReturn(m_hIf == INTNET_HANDLE_INVALID, VERR_GENERAL_FAILURE);
    302 
    303     INTNETOPENREQ OpenReq;
    304     RT_ZERO(OpenReq);
    305 
    306     OpenReq.Hdr.u32Magic = SUPVMMR0REQHDR_MAGIC;
    307     OpenReq.Hdr.cbReq = sizeof(OpenReq);
    308     OpenReq.pSession = m_pSession;
    309 
    310     int rc = RTStrCopy(OpenReq.szNetwork, sizeof(OpenReq.szNetwork), strNetwork.c_str());
    311     AssertRCReturn(rc, rc);
    312 
    313     rc = RTStrCopy(OpenReq.szTrunk, sizeof(OpenReq.szTrunk), strTrunk.c_str());
    314     AssertRCReturn(rc, rc);
    315 
    316     if (enmTrunkType != kIntNetTrunkType_Invalid)
    317         OpenReq.enmTrunkType = enmTrunkType;
    318     else
    319         OpenReq.enmTrunkType = kIntNetTrunkType_WhateverNone;
    320 
    321     OpenReq.fFlags = 0;
    322     OpenReq.cbSend = _128K;
    323     OpenReq.cbRecv = _256K;
    324 
    325     OpenReq.hIf = INTNET_HANDLE_INVALID;
    326 
    327     rc = CALL_VMMR0(VMMR0_DO_INTNET_OPEN, OpenReq);
    328     if (RT_FAILURE(rc))
    329         return rc;
    330 
    331     m_hIf = OpenReq.hIf;
    332     AssertReturn(m_hIf != INTNET_HANDLE_INVALID, VERR_GENERAL_FAILURE);
    333 
    334     return VINF_SUCCESS;
     256    AssertReturn(m_hIf == NULL, VERR_GENERAL_FAILURE);
     257
     258    if (enmTrunkType == kIntNetTrunkType_Invalid)
     259        enmTrunkType = kIntNetTrunkType_WhateverNone;
     260
     261    return IntNetR3IfCtxCreate(&m_hIf, strNetwork.c_str(), enmTrunkType,
     262                               strTrunk.c_str(), _128K /*cbSend*/, _256K /*cbRecv*/,
     263                               0 /*fFlags*/);
    335264}
    336265
     
    338267int VBoxNetDhcpd::ifGetBuf()
    339268{
    340     AssertReturn(m_pSession != NIL_RTR0PTR, VERR_GENERAL_FAILURE);
    341     AssertReturn(m_hIf != INTNET_HANDLE_INVALID, VERR_GENERAL_FAILURE);
     269    AssertReturn(m_hIf != NULL, VERR_GENERAL_FAILURE);
    342270    AssertReturn(m_pIfBuf == NULL, VERR_GENERAL_FAILURE);
    343271
    344     INTNETIFGETBUFFERPTRSREQ GetBufferPtrsReq;
    345     int rc;
    346 
    347     GetBufferPtrsReq.Hdr.u32Magic = SUPVMMR0REQHDR_MAGIC;
    348     GetBufferPtrsReq.Hdr.cbReq = sizeof(GetBufferPtrsReq);
    349     GetBufferPtrsReq.pSession = m_pSession;
    350     GetBufferPtrsReq.hIf = m_hIf;
    351 
    352     GetBufferPtrsReq.pRing0Buf = NIL_RTR0PTR;
    353     GetBufferPtrsReq.pRing3Buf = NULL;
    354 
    355     rc = CALL_VMMR0(VMMR0_DO_INTNET_IF_GET_BUFFER_PTRS, GetBufferPtrsReq);
    356     if (RT_FAILURE(rc))
    357         return rc;
    358 
    359     m_pIfBuf = GetBufferPtrsReq.pRing3Buf;
     272    return IntNetR3IfCtxQueryBufferPtr(m_hIf, &m_pIfBuf);
     273}
     274
     275
     276int VBoxNetDhcpd::ifActivate()
     277{
     278    AssertReturn(m_hIf != NULL, VERR_GENERAL_FAILURE);
    360279    AssertReturn(m_pIfBuf != NULL, VERR_GENERAL_FAILURE);
    361280
    362     return VINF_SUCCESS;
    363 }
    364 
    365 
    366 int VBoxNetDhcpd::ifActivate()
    367 {
    368     AssertReturn(m_pSession != NIL_RTR0PTR, VERR_GENERAL_FAILURE);
    369     AssertReturn(m_hIf != INTNET_HANDLE_INVALID, VERR_GENERAL_FAILURE);
    370     AssertReturn(m_pIfBuf != NULL, VERR_GENERAL_FAILURE);
    371 
    372     INTNETIFSETACTIVEREQ ActiveReq;
    373     int rc;
    374 
    375     ActiveReq.Hdr.u32Magic = SUPVMMR0REQHDR_MAGIC;
    376     ActiveReq.Hdr.cbReq = sizeof(ActiveReq);
    377     ActiveReq.pSession = m_pSession;
    378     ActiveReq.hIf = m_hIf;
    379 
    380     ActiveReq.fActive = 1;
    381 
    382     rc = CALL_VMMR0(VMMR0_DO_INTNET_IF_SET_ACTIVE, ActiveReq);
    383     return rc;
     281    return IntNetR3IfCtxSetActive(m_hIf, true /*fActive*/);
    384282}
    385283
     
    398296         * Wait for input:
    399297         */
    400         INTNETIFWAITREQ WaitReq;
    401         WaitReq.Hdr.u32Magic = SUPVMMR0REQHDR_MAGIC;
    402         WaitReq.Hdr.cbReq = sizeof(WaitReq);
    403         WaitReq.pSession = m_pSession;
    404         WaitReq.hIf = m_hIf;
    405         WaitReq.cMillies = RT_INDEFINITE_WAIT;
    406         int rc = CALL_VMMR0(VMMR0_DO_INTNET_IF_WAIT, WaitReq);
    407 
     298        int rc = IntNetR3IfWait(m_hIf, RT_INDEFINITE_WAIT);
    408299        /*
    409300         * Process any pending input before we wait again:
     
    424315int VBoxNetDhcpd::ifProcessInput()
    425316{
    426     AssertReturn(m_pSession != NIL_RTR0PTR, VERR_GENERAL_FAILURE);
    427     AssertReturn(m_hIf != INTNET_HANDLE_INVALID, VERR_GENERAL_FAILURE);
     317    AssertReturn(m_hIf != NULL, VERR_GENERAL_FAILURE);
    428318    AssertReturn(m_pIfBuf != NULL, VERR_GENERAL_FAILURE);
    429319
     
    544434int VBoxNetDhcpd::ifFlush()
    545435{
    546     INTNETIFSENDREQ SendReq;
    547 
    548     SendReq.Hdr.u32Magic = SUPVMMR0REQHDR_MAGIC;
    549     SendReq.Hdr.cbReq = sizeof(SendReq);
    550     SendReq.pSession = m_pSession;
    551 
    552     SendReq.hIf = m_hIf;
    553 
    554     return CALL_VMMR0(VMMR0_DO_INTNET_IF_SEND, SendReq);
     436    return IntNetR3IfSend(m_hIf);
    555437}
    556438
     
    558440int VBoxNetDhcpd::ifClose()
    559441{
    560     if (m_hIf == INTNET_HANDLE_INVALID)
     442    if (m_hIf == NULL)
    561443        return VINF_SUCCESS;
    562444
    563     INTNETIFCLOSEREQ CloseReq;
    564 
    565     CloseReq.Hdr.u32Magic = SUPVMMR0REQHDR_MAGIC;
    566     CloseReq.Hdr.cbReq = sizeof(CloseReq);
    567     CloseReq.pSession = m_pSession;
    568 
    569     CloseReq.hIf = m_hIf;
    570 
    571     m_hIf = INTNET_HANDLE_INVALID;
    572     m_pIfBuf = NULL;
    573 
    574     CALL_VMMR0(VMMR0_DO_INTNET_IF_CLOSE, CloseReq);
    575     return VINF_SUCCESS;
     445    int rc = IntNetR3IfCtxDestroy(m_hIf);
     446    m_hIf = NULL;
     447    return rc;
    576448}
    577449
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette