VirtualBox

Changeset 5283 in vbox for trunk


Ignore:
Timestamp:
Oct 12, 2007 11:21:09 PM (17 years ago)
Author:
vboxsync
Message:

internal networking fixes.

Location:
trunk
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/include/VBox/intnet.h

    r4071 r5283  
    2020#include <VBox/types.h>
    2121#include <VBox/stam.h>
     22#include <VBox/sup.h>
    2223#include <iprt/assert.h>
    2324#include <iprt/asm.h>
     
    2526__BEGIN_DECLS
    2627
     28
     29/** Pointer to an internal network ring-0 instance. */
     30typedef struct INTNET *PINTNET;
    2731
    2832/**
     
    164168    Assert(pHdr->u16Type == INTNETHDR_TYPE_FRAME);
    165169    Assert(off < pBuf->cbBuf);
    166     Assert(off + pHdr->cbFrame < pBuf->cbBuf);
     170    Assert(off + pHdr->cbFrame <= pBuf->cbBuf);
    167171#endif
    168172    NOREF(pBuf);
     
    198202
    199203
    200 
    201 /**
    202  * The packed down arguments of INTNETR0Open().
    203  * @see INTNETR0Open()
    204  */
    205 typedef struct INTNETOPENARGS
    206 {
     204/**
     205 * Request buffer for INTNETR0OpenReq / VMMR0_DO_INTNET_OPEN.
     206 * @see INTNETR0Open.
     207 */
     208typedef struct INTNETOPENREQ
     209{
     210    /** The request header. */
     211    SUPVMMR0REQHDR  Hdr;
    207212    /** The network name. (input) */
    208213    char            szNetwork[INTNET_MAX_NETWORK_NAME];
     
    215220    /** The handle to the network interface. (output) */
    216221    INTNETIFHANDLE  hIf;
    217 } INTNETOPENARGS;
    218 /** Pointer to an INTNETR0Open() argument package. */
    219 typedef INTNETOPENARGS *PINTNETOPENARGS;
    220 
    221 
    222 /**
    223  * The packed down arguments of INTNETR0IfClose().
    224  * @see INTNETR0IfClose()
    225  */
    226 typedef struct INTNETCLOSEARGS
    227 {
     222} INTNETOPENREQ;
     223/** Pointer to an INTNETR0OpenReq / VMMR0_DO_INTNET_OPEN request buffer. */
     224typedef INTNETOPENREQ *PINTNETOPENREQ;
     225
     226INTNETR0DECL(int) INTNETR0OpenReq(PINTNET pIntNet, PSUPDRVSESSION pSession, PINTNETOPENREQ pReq);
     227
     228
     229/**
     230 * Request buffer for INTNETR0IfCloseReq / VMMR0_DO_INTNET_IF_CLOSE.
     231 * @see INTNETR0IfClose.
     232 */
     233typedef struct INTNETIFCLOSEREQ
     234{
     235    /** The request header. */
     236    SUPVMMR0REQHDR  Hdr;
    228237    /** The handle to the network interface. */
    229238    INTNETIFHANDLE  hIf;
    230 } INTNETIFCLOSEARGS;
    231 /** Pointer to an INTNETR0Open() argument package. */
    232 typedef INTNETIFCLOSEARGS *PINTNETIFCLOSEARGS;
    233 
    234 
    235 /**
    236  * Argument buffer for calling INTNETR0IfGetRing3Buffer().
    237  * @see INTNETR0IfGetRing3Buffer()
    238  */
    239 typedef struct INTNETIFGETRING3BUFFERARGS
    240 {
     239} INTNETIFCLOSEREQ;
     240/** Pointer to an INTNETR0IfCloseReq / VMMR0_DO_INTNET_IF_CLOSE request buffer. */
     241typedef INTNETIFCLOSEREQ *PINTNETIFCLOSEREQ;
     242
     243INTNETR0DECL(int) INTNETR0IfCloseReq(PINTNET pIntNet, PINTNETIFCLOSEREQ pReq);
     244
     245
     246/**
     247 * Request buffer for INTNETR0IfGetRing3BufferReq / VMMR0_DO_INTNET_IF_GET_RING3_BUFFER.
     248 * @see INTNETR0IfGetRing3Buffer.
     249 */
     250typedef struct INTNETIFGETRING3BUFFERREQ
     251{
     252    /** The request header. */
     253    SUPVMMR0REQHDR          Hdr;
    241254    /** Handle to the interface. */
    242     INTNETIFHANDLE  hIf;
     255    INTNETIFHANDLE          hIf;
    243256    /** The pointer to the ring3 buffer. (output) */
    244     PINTNETBUF      pRing3Buf;
    245 } INTNETIFGETRING3BUFFERARGS;
    246 /** Pointer to an INTNETR0IfGetRing3Buffer() argument package. */
    247 typedef INTNETIFGETRING3BUFFERARGS *PINTNETIFGETRING3BUFFERARGS;
    248 
    249 /**
    250  * Argument buffer for calling INTNETR0IfSetPromiscuousMode().
    251  * @see INTNETR0IfSetPromiscuousMode()
    252  */
    253 typedef struct INTNETIFSETPROMISCUOUSMODEARGS
    254 {
     257    R3PTRTYPE(PINTNETBUF)   pRing3Buf;
     258} INTNETIFGETRING3BUFFERREQ;
     259/** Pointer to an INTNETR0IfGetRing3BufferReq / VMMR0_DO_INTNET_IF_GET_RING3_BUFFER request buffer. */
     260typedef INTNETIFGETRING3BUFFERREQ *PINTNETIFGETRING3BUFFERREQ;
     261
     262INTNETR0DECL(int) INTNETR0IfGetRing3BufferReq(PINTNET pIntNet, PINTNETIFGETRING3BUFFERREQ pReq);
     263
     264
     265/**
     266 * Request buffer for INTNETR0IfSetPromiscuousModeReq / VMMR0_DO_INTNET_IF_SET_PROMISCUOUS_MODE.
     267 * @see INTNETR0IfSetPromiscuousMode.
     268 */
     269typedef struct INTNETIFSETPROMISCUOUSMODEREQ
     270{
     271    /** The request header. */
     272    SUPVMMR0REQHDR  Hdr;
    255273    /** Handle to the interface. */
    256274    INTNETIFHANDLE  hIf;
    257275    /** The new promiscuous mode. */
    258276    bool            fPromiscuous;
    259 } INTNETIFSETPROMISCUOUSMODEARGS;
    260 /** Pointer to an INTNETR0IfSetPromiscuousMode() argument package. */
    261 typedef INTNETIFSETPROMISCUOUSMODEARGS *PINTNETIFSETPROMISCUOUSMODEARGS;
    262 
    263 
    264 /**
    265  * Argument buffer for calling INTNETR0IfSend().
    266  * @see INTNETR0IfSend()
    267  */
    268 typedef struct INTNETIFSENDARGS
    269 {
     277} INTNETIFSETPROMISCUOUSMODEREQ;
     278/** Pointer to an INTNETR0IfSetPromiscuousModeReq / VMMR0_DO_INTNET_IF_SET_PROMISCUOUS_MODE request buffer. */
     279typedef INTNETIFSETPROMISCUOUSMODEREQ *PINTNETIFSETPROMISCUOUSMODEREQ;
     280
     281INTNETR0DECL(int) INTNETR0IfSetPromiscuousModeReq(PINTNET pIntNet, PINTNETIFSETPROMISCUOUSMODEREQ pReq);
     282
     283
     284/**
     285 * Request buffer for INTNETR0IfSendReq / VMMR0_DO_INTNET_IF_SEND.
     286 * @see INTNETR0IfSend.
     287 */
     288typedef struct INTNETIFSENDREQ
     289{
     290    /** The request header. */
     291    SUPVMMR0REQHDR  Hdr;
    270292    /** Handle to the interface. */
    271293    INTNETIFHANDLE  hIf;
    272     /** Pointer to the frame. (Optional) */
    273     const void     *pvFrame;
    274     /** The size of the frame. (Optional) */
    275     uint32_t        cbFrame;
    276 } INTNETIFSENDARGS;
     294} INTNETIFSENDREQ;
    277295/** Pointer to an INTNETR0IfSend() argument package. */
    278 typedef INTNETIFSENDARGS *PINTNETIFSENDARGS;
    279 
    280 
    281 /**
    282  * Argument buffer for calling INTNETR0IfWait().
    283  * @see INTNETR0IfWait()
    284  */
    285 typedef struct INTNETIFWAITARGS
    286 {
     296typedef INTNETIFSENDREQ *PINTNETIFSENDREQ;
     297
     298INTNETR0DECL(int) INTNETR0IfSendReq(PINTNET pIntNet, PINTNETIFSENDREQ pReq);
     299
     300
     301/**
     302 * Request buffer for INTNETR0IfWaitReq / VMMR0_DO_INTNET_IF_WAIT.
     303 * @see INTNETR0IfWait.
     304 */
     305typedef struct INTNETIFWAITREQ
     306{
     307    /** The request header. */
     308    SUPVMMR0REQHDR  Hdr;
    287309    /** Handle to the interface. */
    288310    INTNETIFHANDLE  hIf;
    289311    /** The number of milliseconds to wait. */
    290     unsigned        cMillies;
    291 } INTNETSENDARGS;
    292 /** Pointer to an INTNETR0IfWait() argument package. */
    293 typedef INTNETIFWAITARGS *PINTNETIFWAITARGS;
     312    uint32_t        cMillies;
     313} INTNETIFWAITREQ;
     314/** Pointer to an INTNETR0IfWaitReq / VMMR0_DO_INTNET_IF_WAIT request buffer. */
     315typedef INTNETIFWAITREQ *PINTNETIFWAITREQ;
     316
     317INTNETR0DECL(int) INTNETR0IfWaitReq(PINTNET pIntNet, PINTNETIFWAITREQ pReq);
    294318
    295319
     
    298322 * @{
    299323 */
    300 
    301 /** Pointer to an internal network ring-0 instance. */
    302 typedef struct INTNET *PINTNET;
    303324
    304325/**
     
    358379 * @param   ppRing3Buf  Where to store the address of the ring-3 mapping.
    359380 */
    360 INTNETR0DECL(int) INTNETR0IfGetRing3Buffer(PINTNET pIntNet, INTNETIFHANDLE hIf, PINTNETBUF *ppRing3Buf);
     381INTNETR0DECL(int) INTNETR0IfGetRing3Buffer(PINTNET pIntNet, INTNETIFHANDLE hIf, R3PTRTYPE(PINTNETBUF) *ppRing3Buf);
    361382
    362383/**
     
    396417 *                      used if indefinite wait is desired.
    397418 */
    398 INTNETR0DECL(int) INTNETR0IfWait(PINTNET pIntNet, INTNETIFHANDLE hIf, unsigned cMillies);
     419INTNETR0DECL(int) INTNETR0IfWait(PINTNET pIntNet, INTNETIFHANDLE hIf, uint32_t cMillies);
    399420
    400421/** @} */
  • trunk/src/VBox/Devices/Network/DrvIntNet.cpp

    r4071 r5283  
    113113
    114114/**
     115 * Writes a frame packet to the buffer.
     116 *
     117 * @returns VBox status code.
     118 * @param   pBuf        The buffer.
     119 * @param   pRingBuf    The ring buffer to read from.
     120 * @param   pvFrame     The frame to write.
     121 * @param   cbFrame     The size of the frame.
     122 * @remark  This is the same as INTNETRingWriteFrame
     123 */
     124static int drvIntNetRingWriteFrame(PINTNETBUF pBuf, PINTNETRINGBUF pRingBuf, const void *pvFrame, uint32_t cbFrame)
     125{
     126    /*
     127     * Validate input.
     128     */
     129    Assert(pBuf);
     130    Assert(pRingBuf);
     131    Assert(pvFrame);
     132    Assert(cbFrame >= sizeof(PDMMAC) * 2);
     133    uint32_t offWrite = pRingBuf->offWrite;
     134    Assert(offWrite == RT_ALIGN_32(offWrite, sizeof(INTNETHDR)));
     135    uint32_t offRead = pRingBuf->offRead;
     136    Assert(offRead == RT_ALIGN_32(offRead, sizeof(INTNETHDR)));
     137
     138    const uint32_t cb = RT_ALIGN_32(cbFrame, sizeof(INTNETHDR));
     139    if (offRead <= offWrite)
     140    {
     141        /*
     142         * Try fit it all before the end of the buffer.
     143         */
     144        if (pRingBuf->offEnd - offWrite >= cb + sizeof(INTNETHDR))
     145        {
     146            PINTNETHDR pHdr = (PINTNETHDR)((uint8_t *)pBuf + offWrite);
     147            pHdr->u16Type  = INTNETHDR_TYPE_FRAME;
     148            pHdr->cbFrame  = cbFrame;
     149            pHdr->offFrame = sizeof(INTNETHDR);
     150
     151            memcpy(pHdr + 1, pvFrame, cbFrame);
     152
     153            offWrite += cb + sizeof(INTNETHDR);
     154            Assert(offWrite <= pRingBuf->offEnd && offWrite >= pRingBuf->offStart);
     155            if (offWrite >= pRingBuf->offEnd)
     156                offWrite = pRingBuf->offStart;
     157            Log2(("WriteFrame: offWrite: %#x -> %#x (1)\n", pRingBuf->offWrite, offWrite));
     158            ASMAtomicXchgU32(&pRingBuf->offWrite, offWrite);
     159            return VINF_SUCCESS;
     160        }
     161
     162        /*
     163         * Try fit the frame at the start of the buffer.
     164         * (The header fits before the end of the buffer because of alignment.)
     165         */
     166        AssertMsg(pRingBuf->offEnd - offWrite >= sizeof(INTNETHDR), ("offEnd=%x offWrite=%x\n", pRingBuf->offEnd, offWrite));
     167        if (offRead - pRingBuf->offStart > cb) /* not >= ! */
     168        {
     169            PINTNETHDR  pHdr = (PINTNETHDR)((uint8_t *)pBuf + offWrite);
     170            void       *pvFrameOut = (PINTNETHDR)((uint8_t *)pBuf + pRingBuf->offStart);
     171            pHdr->u16Type  = INTNETHDR_TYPE_FRAME;
     172            pHdr->cbFrame  = cbFrame;
     173            pHdr->offFrame = (intptr_t)pvFrameOut - (intptr_t)pHdr;
     174
     175            memcpy(pvFrameOut, pvFrame, cbFrame);
     176
     177            offWrite = pRingBuf->offStart + cb;
     178            ASMAtomicXchgU32(&pRingBuf->offWrite, offWrite);
     179            Log2(("WriteFrame: offWrite: %#x -> %#x (2)\n", pRingBuf->offWrite, offWrite));
     180            return VINF_SUCCESS;
     181        }
     182    }
     183    /*
     184     * The reader is ahead of the writer, try fit it into that space.
     185     */
     186    else if (offRead - offWrite > cb + sizeof(INTNETHDR)) /* not >= ! */
     187    {
     188        PINTNETHDR pHdr = (PINTNETHDR)((uint8_t *)pBuf + offWrite);
     189        pHdr->u16Type  = INTNETHDR_TYPE_FRAME;
     190        pHdr->cbFrame  = cbFrame;
     191        pHdr->offFrame = sizeof(INTNETHDR);
     192
     193        memcpy(pHdr + 1, pvFrame, cbFrame);
     194
     195        offWrite += cb + sizeof(INTNETHDR);
     196        ASMAtomicXchgU32(&pRingBuf->offWrite, offWrite);
     197        Log2(("WriteFrame: offWrite: %#x -> %#x (3)\n", pRingBuf->offWrite, offWrite));
     198        return VINF_SUCCESS;
     199    }
     200
     201    /* (it didn't fit) */
     202    /** @todo stats */
     203    return VERR_BUFFER_OVERFLOW;
     204}
     205
     206
     207/**
    115208 * Send data to the network.
    116209 *
     
    136229#endif
    137230
    138     /** @todo copy to send buffer, this is not safe. */
    139     INTNETIFSENDARGS SendArgs;
    140     SendArgs.hIf = pThis->hIf;
    141     SendArgs.pvFrame = pvBuf;
    142     SendArgs.cbFrame = cb;
    143     int rc = pThis->pDrvIns->pDrvHlp->pfnSUPCallVMMR0Ex(pThis->pDrvIns, VMMR0_DO_INTNET_IF_SEND, &SendArgs, sizeof(SendArgs));
     231    /*
     232     * Add the frame to the send buffer and push it onto the network.
     233     */
     234    int rc = drvIntNetRingWriteFrame(pThis->pBuf, &pThis->pBuf->Send, pvBuf, cb);
     235    if (    rc == VERR_BUFFER_OVERFLOW
     236        &&  pThis->pBuf->cbSend < cb)
     237    {
     238        INTNETIFSENDREQ SendReq;
     239        SendReq.Hdr.u32Magic = SUPVMMR0REQHDR_MAGIC;
     240        SendReq.Hdr.cbReq = sizeof(SendReq);
     241        SendReq.hIf = pThis->hIf;
     242        pThis->pDrvIns->pDrvHlp->pfnSUPCallVMMR0Ex(pThis->pDrvIns, VMMR0_DO_INTNET_IF_SEND, &SendReq, sizeof(SendReq));
     243
     244        rc = drvIntNetRingWriteFrame(pThis->pBuf, &pThis->pBuf->Send, pvBuf, cb);
     245    }
     246
     247    if (RT_SUCCESS(rc))
     248    {
     249        INTNETIFSENDREQ SendReq;
     250        SendReq.Hdr.u32Magic = SUPVMMR0REQHDR_MAGIC;
     251        SendReq.Hdr.cbReq = sizeof(SendReq);
     252        SendReq.hIf = pThis->hIf;
     253        rc = pThis->pDrvIns->pDrvHlp->pfnSUPCallVMMR0Ex(pThis->pDrvIns, VMMR0_DO_INTNET_IF_SEND, &SendReq, sizeof(SendReq));
     254    }
    144255
    145256    STAM_PROFILE_STOP(&pThis->StatTransmit, a);
     
    162273{
    163274    PDRVINTNET pThis = PDMINETWORKCONNECTOR_2_DRVINTNET(pInterface);
    164     INTNETIFSETPROMISCUOUSMODEARGS SetArgs = {0};
    165     SetArgs.hIf          = pThis->hIf;
    166     SetArgs.fPromiscuous = fPromiscuous;
    167     int rc = pThis->pDrvIns->pDrvHlp->pfnSUPCallVMMR0Ex(pThis->pDrvIns, VMMR0_DO_INTNET_IF_SET_PROMISCUOUS_MODE, &SetArgs, sizeof(SetArgs));
    168     LogFlow(("drvIntNetSetPromiscuousMode: fPromiscuous=%d\n", fPromiscuous));
     275    INTNETIFSETPROMISCUOUSMODEREQ Req;
     276    Req.Hdr.u32Magic    = SUPVMMR0REQHDR_MAGIC;
     277    Req.Hdr.cbReq       = sizeof(Req);
     278    Req.hIf             = pThis->hIf;
     279    Req.fPromiscuous    = fPromiscuous;
     280    int rc = pThis->pDrvIns->pDrvHlp->pfnSUPCallVMMR0Ex(pThis->pDrvIns, VMMR0_DO_INTNET_IF_SET_PROMISCUOUS_MODE, &Req, sizeof(Req));
     281    LogFlow(("drvIntNetSetPromiscuousMode: fPromiscuous=%RTbool\n", fPromiscuous));
    169282    AssertRC(rc);
    170283}
     
    368481            return VERR_STATE_CHANGED;
    369482        }
    370         INTNETIFWAITARGS WaitArgs;
    371         WaitArgs.hIf      = pThis->hIf;
    372         WaitArgs.cMillies = 30000;      /* don't wait forever, timeout now and then. */
     483        INTNETIFWAITREQ WaitReq;
     484        WaitReq.Hdr.u32Magic = SUPVMMR0REQHDR_MAGIC;
     485        WaitReq.Hdr.cbReq    = sizeof(WaitReq);
     486        WaitReq.hIf          = pThis->hIf;
     487        WaitReq.cMillies     = 30000; /* 30s - don't wait forever, timeout now and then. */
    373488        STAM_PROFILE_ADV_STOP(&pThis->StatReceive, a);
    374         int rc = pDrvIns->pDrvHlp->pfnSUPCallVMMR0Ex(pDrvIns, VMMR0_DO_INTNET_IF_WAIT, &WaitArgs, sizeof(WaitArgs));
     489        int rc = pDrvIns->pDrvHlp->pfnSUPCallVMMR0Ex(pDrvIns, VMMR0_DO_INTNET_IF_WAIT, &WaitReq, sizeof(WaitReq));
    375490        if (    VBOX_FAILURE(rc)
    376491            &&  rc != VERR_TIMEOUT
     
    547662    if (pThis->hIf != INTNET_HANDLE_INVALID)
    548663    {
    549         INTNETIFCLOSEARGS CloseArgs = {0};
    550         CloseArgs.hIf = pThis->hIf;
     664        INTNETIFCLOSEREQ CloseReq;
     665        CloseReq.Hdr.u32Magic = SUPVMMR0REQHDR_MAGIC;
     666        CloseReq.Hdr.cbReq = sizeof(CloseReq);
     667        CloseReq.hIf = pThis->hIf;
    551668        pThis->hIf = INTNET_HANDLE_INVALID;
    552         int rc = pDrvIns->pDrvHlp->pfnSUPCallVMMR0Ex(pDrvIns, VMMR0_DO_INTNET_IF_CLOSE, &CloseArgs, sizeof(CloseArgs));
     669        int rc = pDrvIns->pDrvHlp->pfnSUPCallVMMR0Ex(pDrvIns, VMMR0_DO_INTNET_IF_CLOSE, &CloseReq, sizeof(CloseReq));
    553670        AssertRC(rc);
    554671    }
     
    638755     * Read the configuration.
    639756     */
    640     INTNETOPENARGS OpenArgs;
    641     memset(&OpenArgs, 0, sizeof(OpenArgs));
    642     rc = CFGMR3QueryString(pCfgHandle, "Network", OpenArgs.szNetwork, sizeof(OpenArgs.szNetwork));
     757    INTNETOPENREQ OpenReq;
     758    memset(&OpenReq, 0, sizeof(OpenReq));
     759    OpenReq.Hdr.cbReq = sizeof(OpenReq);
     760    OpenReq.Hdr.u32Magic = SUPVMMR0REQHDR_MAGIC;
     761
     762    rc = CFGMR3QueryString(pCfgHandle, "Network", OpenReq.szNetwork, sizeof(OpenReq.szNetwork));
    643763    if (VBOX_FAILURE(rc))
    644764        return PDMDRV_SET_ERROR(pDrvIns, rc,
    645765                                N_("Configuration error: Failed to get the \"Network\" value"));
    646     strcpy(pThis->szNetwork, OpenArgs.szNetwork);
    647 
    648     rc = CFGMR3QueryU32(pCfgHandle, "ReceiveBufferSize", &OpenArgs.cbRecv);
     766    strcpy(pThis->szNetwork, OpenReq.szNetwork);
     767
     768    rc = CFGMR3QueryU32(pCfgHandle, "ReceiveBufferSize", &OpenReq.cbRecv);
    649769    if (rc == VERR_CFGM_VALUE_NOT_FOUND)
    650         OpenArgs.cbRecv = _256K;
     770        OpenReq.cbRecv = _256K;
    651771    else if (VBOX_FAILURE(rc))
    652772        return PDMDRV_SET_ERROR(pDrvIns, rc,
    653773                                N_("Configuration error: Failed to get the \"ReceiveBufferSize\" value"));
    654774
    655     rc = CFGMR3QueryU32(pCfgHandle, "SendBufferSize", &OpenArgs.cbSend);
     775    rc = CFGMR3QueryU32(pCfgHandle, "SendBufferSize", &OpenReq.cbSend);
    656776    if (rc == VERR_CFGM_VALUE_NOT_FOUND)
    657         OpenArgs.cbSend = _4K;
     777        OpenReq.cbSend = _4K;
    658778    else if (VBOX_FAILURE(rc))
    659779        return PDMDRV_SET_ERROR(pDrvIns, rc,
    660780                                N_("Configuration error: Failed to get the \"SendBufferSize\" value"));
    661 
    662     rc = CFGMR3QueryBool(pCfgHandle, "RestrictAccess", &OpenArgs.fRestrictAccess);
     781    if (OpenReq.cbSend < 16)
     782        return PDMDRV_SET_ERROR(pDrvIns, rc,
     783                                N_("Configuration error: The \"SendBufferSize\" value is too small."));
     784    if (OpenReq.cbSend < 1536*2 + 4)
     785        LogRel(("DrvIntNet: Warning! SendBufferSize=%u, Recommended minimum size %u butes.\n", OpenReq.cbSend, 1536*2 + 4));
     786
     787    rc = CFGMR3QueryBool(pCfgHandle, "RestrictAccess", &OpenReq.fRestrictAccess);
    663788    if (rc == VERR_CFGM_VALUE_NOT_FOUND)
    664         OpenArgs.fRestrictAccess = true;
     789        OpenReq.fRestrictAccess = true;
    665790    else if (VBOX_FAILURE(rc))
    666791        return PDMDRV_SET_ERROR(pDrvIns, rc,
     
    680805     * Create the interface.
    681806     */
    682     OpenArgs.hIf = INTNET_HANDLE_INVALID;
    683     rc = pDrvIns->pDrvHlp->pfnSUPCallVMMR0Ex(pDrvIns, VMMR0_DO_INTNET_OPEN, &OpenArgs, sizeof(OpenArgs));
     807    OpenReq.hIf = INTNET_HANDLE_INVALID;
     808    rc = pDrvIns->pDrvHlp->pfnSUPCallVMMR0Ex(pDrvIns, VMMR0_DO_INTNET_OPEN, &OpenReq, sizeof(OpenReq));
    684809    if (VBOX_FAILURE(rc))
    685810        return PDMDrvHlpVMSetError(pDrvIns, rc, RT_SRC_POS,
    686811                                   N_("Failed to open/create the internal network '%s'"), pThis->szNetwork);
    687     AssertRelease(OpenArgs.hIf != INTNET_HANDLE_INVALID);
    688     pThis->hIf = OpenArgs.hIf;
     812    AssertRelease(OpenReq.hIf != INTNET_HANDLE_INVALID);
     813    pThis->hIf = OpenReq.hIf;
    689814    Log(("IntNet%d: hIf=%RX32 '%s'\n", pDrvIns->iInstance, pThis->hIf, pThis->szNetwork));
    690815
     
    692817     * Get default buffer.
    693818     */
    694     INTNETIFGETRING3BUFFERARGS GetRing3BufferArgs = {0};
    695     GetRing3BufferArgs.hIf = pThis->hIf;
    696     GetRing3BufferArgs.pRing3Buf = NULL;
    697     rc = pDrvIns->pDrvHlp->pfnSUPCallVMMR0Ex(pDrvIns, VMMR0_DO_INTNET_IF_GET_RING3_BUFFER, &GetRing3BufferArgs, sizeof(GetRing3BufferArgs));
     819    INTNETIFGETRING3BUFFERREQ GetRing3BufferReq;
     820    GetRing3BufferReq.Hdr.u32Magic = SUPVMMR0REQHDR_MAGIC;
     821    GetRing3BufferReq.Hdr.cbReq = sizeof(GetRing3BufferReq);
     822    GetRing3BufferReq.hIf = pThis->hIf;
     823    GetRing3BufferReq.pRing3Buf = NULL;
     824    rc = pDrvIns->pDrvHlp->pfnSUPCallVMMR0Ex(pDrvIns, VMMR0_DO_INTNET_IF_GET_RING3_BUFFER, &GetRing3BufferReq, sizeof(GetRing3BufferReq));
    698825    if (VBOX_FAILURE(rc))
    699826        return PDMDrvHlpVMSetError(pDrvIns, rc, RT_SRC_POS,
    700827                                   N_("Failed to get ring-3 buffer for the newly created interface to '%s'"), pThis->szNetwork);
    701     AssertRelease(VALID_PTR(GetRing3BufferArgs.pRing3Buf));
    702     pThis->pBuf = GetRing3BufferArgs.pRing3Buf;
     828    AssertRelease(VALID_PTR(GetRing3BufferReq.pRing3Buf));
     829    pThis->pBuf = GetRing3BufferReq.pRing3Buf;
    703830
    704831    /*
     
    737864#endif
    738865
    739     LogRel(("IntNet#%u: cbRecv=%u cbSend=%u fRestrictAccess=%d\n", pDrvIns->iInstance, OpenArgs.cbRecv, OpenArgs.cbSend, OpenArgs.fRestrictAccess));
     866    LogRel(("IntNet#%u: cbRecv=%u cbSend=%u fRestrictAccess=%d\n", pDrvIns->iInstance, OpenReq.cbRecv, OpenReq.cbSend, OpenReq.fRestrictAccess));
    740867
    741868    return rc;
  • trunk/src/VBox/Devices/Network/SrvIntNetR0.cpp

    r4071 r5283  
    6060    PINTNETBUF              pIntBuf;
    6161    /** Pointer to ring-3 mapping of the current exchange buffer. */
    62     PINTNETBUF              pIntBufR3;
     62    R3PTRTYPE(PINTNETBUF)   pIntBufR3;
    6363    /** Pointer to the default exchange buffer for the interface. */
    6464    PINTNETBUF              pIntBufDefault;
    6565    /** Pointer to ring-3 mapping of the default exchange buffer. */
    66     PINTNETBUF              pIntBufDefaultR3;
     66    R3PTRTYPE(PINTNETBUF)   pIntBufDefaultR3;
    6767    /** Event semaphore which a receiver thread will sleep on while waiting for data to arrive. */
    6868    RTSEMEVENT              Event;
     
    625625     * Process the send buffer.
    626626     */
    627     if (pIf->pIntBuf->Send.offRead != pIf->pIntBuf->Send.offWrite)
    628     {
    629         for (;;)
     627    while (pIf->pIntBuf->Send.offRead != pIf->pIntBuf->Send.offWrite)
     628    {
     629        /* Send the frame if the type is sane. */
     630        PINTNETHDR pHdr = (PINTNETHDR)((uintptr_t)pIf->pIntBuf + pIf->pIntBuf->Send.offRead);
     631        if (pHdr->u16Type == INTNETHDR_TYPE_FRAME)
    630632        {
    631             /*
    632              * Anything we know what is, if so send it.
    633              */
    634             PINTNETHDR pHdr = (PINTNETHDR)((uintptr_t)pIf->pIntBuf + pIf->pIntBuf->Send.offRead);
    635             if (pHdr->u16Type == INTNETHDR_TYPE_FRAME)
    636             {
    637                 void *pvCurFrame = INTNETHdrGetFramePtr(pHdr, pIf->pIntBuf);
    638                 if (pvCurFrame)
    639                     intnetNetworkSend(pIf->pNetwork, pIf, pvCurFrame, pHdr->cbFrame);
    640             }
    641             /* else: ignore the frame */
    642 
    643             /*
    644              * Skip to the next frame.
    645              */
    646             INTNETRingSkipFrame(pIf->pIntBuf, &pIf->pIntBuf->Send);
     633            void *pvCurFrame = INTNETHdrGetFramePtr(pHdr, pIf->pIntBuf);
     634            if (pvCurFrame)
     635                intnetNetworkSend(pIf->pNetwork, pIf, pvCurFrame, pHdr->cbFrame);
    647636        }
     637        /* else: ignore the frame */
     638
     639        /* Skip to the next frame. */
     640        INTNETRingSkipFrame(pIf->pIntBuf, &pIf->pIntBuf->Send);
    648641    }
    649642
    650643    return RTSemFastMutexRelease(pIf->pNetwork->FastMutex);
     644}
     645
     646
     647/**
     648 * VMMR0 request wrapper for INTNETR0IfSend.
     649 *
     650 * @returns see INTNETR0IfSend.
     651 * @param   pIntNet         The internal networking instance.
     652 * @param   pReq            The request packet.
     653 */
     654INTNETR0DECL(int) INTNETR0IfSendReq(PINTNET pIntNet, PINTNETIFSENDREQ pReq)
     655{
     656    if (RT_UNLIKELY(pReq->Hdr.cbReq != sizeof(*pReq)))
     657        return VERR_INVALID_PARAMETER;
     658    return INTNETR0IfSend(pIntNet, pReq->hIf, NULL, 0);
    651659}
    652660
     
    660668 * @param   ppRing3Buf  Where to store the address of the ring-3 mapping.
    661669 */
    662 INTNETR0DECL(int) INTNETR0IfGetRing3Buffer(PINTNET pIntNet, INTNETIFHANDLE hIf, PINTNETBUF *ppRing3Buf)
     670INTNETR0DECL(int) INTNETR0IfGetRing3Buffer(PINTNET pIntNet, INTNETIFHANDLE hIf, R3PTRTYPE(PINTNETBUF) *ppRing3Buf)
    663671{
    664672    LogFlow(("INTNETR0IfGetRing3Buffer: pIntNet=%p hIf=%RX32 ppRing3Buf=%p\n", pIntNet, hIf, ppRing3Buf));
     
    687695    LogFlow(("INTNETR0IfGetRing3Buffer: returns %Vrc *ppRing3Buf=%p\n", rc, *ppRing3Buf));
    688696    return rc;
     697}
     698
     699
     700/**
     701 * VMMR0 request wrapper for INTNETR0IfGetRing3Buffer.
     702 *
     703 * @returns see INTNETR0IfGetRing3Buffer.
     704 * @param   pIntNet         The internal networking instance.
     705 * @param   pReq            The request packet.
     706 */
     707INTNETR0DECL(int) INTNETR0IfGetRing3BufferReq(PINTNET pIntNet, PINTNETIFGETRING3BUFFERREQ pReq)
     708{
     709    if (RT_UNLIKELY(pReq->Hdr.cbReq != sizeof(*pReq)))
     710        return VERR_INVALID_PARAMETER;
     711    return INTNETR0IfGetRing3Buffer(pIntNet, pReq->hIf, &pReq->pRing3Buf);
    689712}
    690713
     
    799822
    800823/**
     824 * VMMR0 request wrapper for INTNETR0IfSetPromiscuousMode.
     825 *
     826 * @returns see INTNETR0IfSetPromiscuousMode.
     827 * @param   pIntNet         The internal networking instance.
     828 * @param   pReq            The request packet.
     829 */
     830INTNETR0DECL(int) INTNETR0IfSetPromiscuousModeReq(PINTNET pIntNet, PINTNETIFSETPROMISCUOUSMODEREQ pReq)
     831{
     832    if (RT_UNLIKELY(pReq->Hdr.cbReq != sizeof(*pReq)))
     833        return VERR_INVALID_PARAMETER;
     834    return INTNETR0IfSetPromiscuousMode(pIntNet, pReq->hIf, pReq->fPromiscuous);
     835}
     836
     837
     838/**
    801839 * Wait for the interface to get signaled.
    802840 * The interface will be signaled when is put into the receive buffer.
     
    808846 *                      used if indefinite wait is desired.
    809847 */
    810 INTNETR0DECL(int) INTNETR0IfWait(PINTNET pIntNet, INTNETIFHANDLE hIf, unsigned cMillies)
     848INTNETR0DECL(int) INTNETR0IfWait(PINTNET pIntNet, INTNETIFHANDLE hIf, uint32_t cMillies)
    811849{
    812850    LogFlow(("INTNETR0IfWait: pIntNet=%p hIf=%RX32 cMillies=%u\n", pIntNet, hIf, cMillies));
     
    844882     */
    845883    ASMAtomicIncU32(&pIf->cSleepers);
    846     int rc = RTSemEventWait(Event, cMillies);
     884    int rc = RTSemEventWaitNoResume(Event, cMillies);
    847885    if (pIf->Event == Event)
    848886    {
     
    859897
    860898/**
     899 * VMMR0 request wrapper for INTNETR0IfWait.
     900 *
     901 * @returns see INTNETR0IfWait.
     902 * @param   pIntNet         The internal networking instance.
     903 * @param   pReq            The request packet.
     904 */
     905INTNETR0DECL(int) INTNETR0IfWaitReq(PINTNET pIntNet, PINTNETIFWAITREQ pReq)
     906{
     907    if (RT_UNLIKELY(pReq->Hdr.cbReq != sizeof(*pReq)))
     908        return VERR_INVALID_PARAMETER;
     909    return INTNETR0IfWait(pIntNet, pReq->hIf, pReq->cMillies);
     910}
     911
     912
     913/**
    861914 * Close an interface.
    862915 *
     
    880933    LogFlow(("INTNETR0IfClose: returns %Vrc\n", rc));
    881934    return rc;
     935}
     936
     937
     938/**
     939 * VMMR0 request wrapper for INTNETR0IfCloseReq.
     940 *
     941 * @returns see INTNETR0IfClose.
     942 * @param   pIntNet         The internal networking instance.
     943 * @param   pReq            The request packet.
     944 */
     945INTNETR0DECL(int) INTNETR0IfCloseReq(PINTNET pIntNet, PINTNETIFCLOSEREQ pReq)
     946{
     947    if (RT_UNLIKELY(pReq->Hdr.cbReq != sizeof(*pReq)))
     948        return VERR_INVALID_PARAMETER;
     949    return INTNETR0IfClose(pIntNet, pReq->hIf);
    882950}
    883951
     
    9781046        SUPR0MemFree(pIf->pSession, (RTHCUINTPTR)pIf->pIntBufDefault);
    9791047        pIf->pIntBufDefault = NULL;
    980         pIf->pIntBufDefaultR3 = NULL;
    981         pIf->pIntBufR3 = NULL;
     1048        pIf->pIntBufDefaultR3 = 0;
    9821049        pIf->pIntBuf = NULL;
     1050        pIf->pIntBufR3 = 0;
    9831051    }
    9841052
     
    14191487
    14201488/**
     1489 * VMMR0 request wrapper for GMMR0MapUnmapChunk.
     1490 *
     1491 * @returns see GMMR0MapUnmapChunk.
     1492 * @param   pIntNet         The internal networking instance.
     1493 * @param   pSession        The session handle.
     1494 * @param   pReq            The request packet.
     1495 */
     1496INTNETR0DECL(int) INTNETR0OpenReq(PINTNET pIntNet, PSUPDRVSESSION pSession, PINTNETOPENREQ pReq)
     1497{
     1498    if (RT_UNLIKELY(pReq->Hdr.cbReq != sizeof(*pReq)))
     1499        return VERR_INVALID_PARAMETER;
     1500    return INTNETR0Open(pIntNet, pSession, &pReq->szNetwork[0], pReq->cbSend, pReq->cbRecv, pReq->fRestrictAccess, &pReq->hIf);
     1501}
     1502
     1503
     1504/**
    14211505 * Destroys an instance of the Ring-0 internal networking service.
    14221506 *
  • trunk/src/VBox/Devices/Network/testcase/tstIntNetR0.cpp

    r4071 r5283  
    202202
    203203
    204 #define TEST_TRANSFER_SIZE (_1M*128)
     204#define TEST_TRANSFER_SIZE (_1M*384)
    205205
    206206/**
     
    229229        const unsigned cb = iFrame % 1519 + 12 + sizeof(unsigned);
    230230        *puFrame = iFrame;
     231#if 0
    231232        int rc = INTNETR0IfSend(pArgs->pIntNet, pArgs->hIf, abBuf, cb);
     233#else
     234        int rc = INTNETRingWriteFrame(pArgs->pBuf, &pArgs->pBuf->Send, abBuf, cb);
     235        if (RT_SUCCESS(rc))
     236            rc = INTNETR0IfSend(pArgs->pIntNet, pArgs->hIf, NULL, 0);
     237#endif
    232238        if (VBOX_FAILURE(rc))
    233239        {
    234240            g_cErrors++;
    235             RTPrintf("tstIntNetR0: Failed sending %d bytes, rc=%Vrc\n", cb, rc);
     241            RTPrintf("tstIntNetR0: Failed sending %d bytes, rc=%Vrc (%d)\n", cb, rc, INTNETRingGetWritable(&pArgs->pBuf->Send));
    236242        }
    237243        cbSent += cb;
     
    384390     */
    385391    INTNETIFHANDLE hIf0 = INTNET_HANDLE_INVALID;
    386     rc = INTNETR0Open(pIntNet, g_pSession, "test", 1536, 0x8000, true, &hIf0);
     392    rc = INTNETR0Open(pIntNet, g_pSession, "test", 1536*2 + 4, 0x8000, true, &hIf0);
    387393    if (VBOX_SUCCESS(rc))
    388394    {
     
    390396        {
    391397            INTNETIFHANDLE hIf1 = INTNET_HANDLE_INVALID;
    392             rc = INTNETR0Open(pIntNet, g_pSession, "test", 1536, 0x8000, true, &hIf1);
     398            rc = INTNETR0Open(pIntNet, g_pSession, "test", 1536*2 + 4, 0x8000, true, &hIf1);
    393399            if (VBOX_SUCCESS(rc))
    394400            {
  • trunk/src/VBox/VMM/PDMDriver.cpp

    r4800 r5283  
    991991    if (    uOperation >= VMMR0_DO_SRV_START
    992992        &&  uOperation <  VMMR0_DO_SRV_END)
    993 #if 0 /** @todo fix internal networking */
    994         rc = SUPCallVMMR0Ex(pDrvIns->Internal.s.pVM->pVMR0, uOperation, pvArg, cbArg);
    995 #else
    996 {
    997 LogRel(("Sorry, internal networking is currently broken in the devlopment tree. Will be fixed in a bit, no time right now.\n"));
    998 rc = VERR_NOT_IMPLEMENTED;
    999 }
    1000 #endif
     993        rc = SUPCallVMMR0Ex(pDrvIns->Internal.s.pVM->pVMR0, uOperation, 0, (PSUPVMMR0REQHDR)pvArg);
    1001994    else
    1002995    {
  • trunk/src/VBox/VMM/VMMR0/VMMR0.cpp

    r5274 r5283  
    832832
    833833
    834 #if 0//def VBOX_WITH_INTERNAL_NETWORKING - currently busted
    835         /*
    836          * Services.
     834#ifdef VBOX_WITH_INTERNAL_NETWORKING
     835        /*
     836         * Requests to the internal networking service.
    837837         */
    838838        case VMMR0_DO_INTNET_OPEN:
     839            if (!pVM || u64Arg)
     840                return VERR_INVALID_PARAMETER;
     841            if (!g_pIntNet)
     842                return VERR_NOT_SUPPORTED;
     843            return INTNETR0OpenReq(g_pIntNet, pVM->pSession, (PINTNETOPENREQ)pReqHdr);
     844
    839845        case VMMR0_DO_INTNET_IF_CLOSE:
     846            if (!pVM || u64Arg)
     847                return VERR_INVALID_PARAMETER;
     848            if (!g_pIntNet)
     849                return VERR_NOT_SUPPORTED;
     850            return INTNETR0IfCloseReq(g_pIntNet, (PINTNETIFCLOSEREQ)pReqHdr);
     851
    840852        case VMMR0_DO_INTNET_IF_GET_RING3_BUFFER:
     853            if (!pVM || u64Arg)
     854                return VERR_INVALID_PARAMETER;
     855            if (!g_pIntNet)
     856                return VERR_NOT_SUPPORTED;
     857            return INTNETR0IfGetRing3BufferReq(g_pIntNet, (PINTNETIFGETRING3BUFFERREQ)pReqHdr);
     858
    841859        case VMMR0_DO_INTNET_IF_SET_PROMISCUOUS_MODE:
     860            if (!pVM || u64Arg)
     861                return VERR_INVALID_PARAMETER;
     862            if (!g_pIntNet)
     863                return VERR_NOT_SUPPORTED;
     864            return INTNETR0IfSetPromiscuousModeReq(g_pIntNet, (PINTNETIFSETPROMISCUOUSMODEREQ)pReqHdr);
     865
    842866        case VMMR0_DO_INTNET_IF_SEND:
     867            if (!pVM || u64Arg)
     868                return VERR_INVALID_PARAMETER;
     869            if (!g_pIntNet)
     870                return VERR_NOT_SUPPORTED;
     871            return INTNETR0IfSendReq(g_pIntNet, (PINTNETIFSENDREQ)pReqHdr);
     872
    843873        case VMMR0_DO_INTNET_IF_WAIT:
    844         {
    845             /*
    846              * Validate arguments a bit first.
    847              */
    848             if (!VALID_PTR(pvArg))
    849                 return VERR_INVALID_POINTER;
    850             if (!VALID_PTR(pVM))
    851                 return VERR_INVALID_POINTER;
    852             if (pVM->pVMR0 != pVM)
    853                 return VERR_INVALID_POINTER;
    854             if (!VALID_PTR(pVM->pSession))
    855                 return VERR_INVALID_POINTER;
     874            if (!pVM || u64Arg)
     875                return VERR_INVALID_PARAMETER;
    856876            if (!g_pIntNet)
    857                 return VERR_FILE_NOT_FOUND; ///@todo fix this status code!
    858 
    859             /*
    860              * Unpack the arguments and call the service.
    861              */
    862             switch (enmOperation)
    863             {
    864                 case VMMR0_DO_INTNET_OPEN:
    865                 {
    866                     PINTNETOPENARGS pArgs = (PINTNETOPENARGS)pvArg;
    867                     return INTNETR0Open(g_pIntNet, pVM->pSession, &pArgs->szNetwork[0], pArgs->cbSend, pArgs->cbRecv, pArgs->fRestrictAccess, &pArgs->hIf);
    868                 }
    869 
    870                 case VMMR0_DO_INTNET_IF_CLOSE:
    871                 {
    872                     PINTNETIFCLOSEARGS pArgs = (PINTNETIFCLOSEARGS)pvArg;
    873                     return INTNETR0IfClose(g_pIntNet, pArgs->hIf);
    874                 }
    875 
    876                 case VMMR0_DO_INTNET_IF_GET_RING3_BUFFER:
    877                 {
    878                     PINTNETIFGETRING3BUFFERARGS pArgs = (PINTNETIFGETRING3BUFFERARGS)pvArg;
    879                     return INTNETR0IfGetRing3Buffer(g_pIntNet, pArgs->hIf, &pArgs->pRing3Buf);
    880                 }
    881 
    882                 case VMMR0_DO_INTNET_IF_SET_PROMISCUOUS_MODE:
    883                 {
    884                     PINTNETIFSETPROMISCUOUSMODEARGS pArgs = (PINTNETIFSETPROMISCUOUSMODEARGS)pvArg;
    885                     return INTNETR0IfSetPromiscuousMode(g_pIntNet, pArgs->hIf, pArgs->fPromiscuous);
    886                 }
    887 
    888                 case VMMR0_DO_INTNET_IF_SEND:
    889                 {
    890                     PINTNETIFSENDARGS pArgs = (PINTNETIFSENDARGS)pvArg;
    891                     return INTNETR0IfSend(g_pIntNet, pArgs->hIf, pArgs->pvFrame, pArgs->cbFrame);
    892                 }
    893 
    894                 case VMMR0_DO_INTNET_IF_WAIT:
    895                 {
    896                     PINTNETIFWAITARGS pArgs = (PINTNETIFWAITARGS)pvArg;
    897                     return INTNETR0IfWait(g_pIntNet, pArgs->hIf, pArgs->cMillies);
    898                 }
    899 
    900                 default:
    901                     return VERR_NOT_SUPPORTED;
    902             }
    903         }
     877                return VERR_NOT_SUPPORTED;
     878            return INTNETR0IfWaitReq(g_pIntNet, (PINTNETIFWAITREQ)pReqHdr);
    904879#endif /* VBOX_WITH_INTERNAL_NETWORKING */
    905880
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