VirtualBox

Changeset 10711 in vbox for trunk


Ignore:
Timestamp:
Jul 16, 2008 7:54:17 PM (16 years ago)
Author:
vboxsync
Message:

intnet: trunk activation / deactivation (promisc mode).

Location:
trunk/src/VBox/Devices/Network
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Devices/Network/SrvIntNetR0.cpp

    r10681 r10711  
    5959     * In promiscuous mode the interface will receive all packages except the one it's sending. */
    6060    bool                    fPromiscuous;
     61    /** Whether the interface is active or not. */
     62    bool                    fActive;
    6163    /** Number of yields done to try make the interface read pending data.
    6264     * We will stop yeilding when this reaches a threshold assuming that the VM is paused or
     
    139141    /** Network creation flags (INTNET_OPEN_FLAGS_*). */
    140142    uint32_t                fFlags;
     143    /** The number of active interfaces (excluding the trunk). */
     144    uint32_t                cActiveIFs;
    141145    /** The length of the network name. */
    142146    uint8_t                 cchName;
     
    208212*   Internal Functions                                                         *
    209213*******************************************************************************/
    210 static PINTNETTRUNKIF intnetTrunkIfRetain(PINTNETTRUNKIF pThis);
    211 static void intnetTrunkIfRelease(PINTNETTRUNKIF pThis);
    212 static bool intnetTrunkIfOutLock(PINTNETTRUNKIF pThis);
    213 static void intnetTrunkIfOutUnlock(PINTNETTRUNKIF pThis);
     214static PINTNETTRUNKIF intnetR0TrunkIfRetain(PINTNETTRUNKIF pThis);
     215static void intnetR0TrunkIfRelease(PINTNETTRUNKIF pThis);
     216static bool intnetR0TrunkIfOutLock(PINTNETTRUNKIF pThis);
     217static void intnetR0TrunkIfOutUnlock(PINTNETTRUNKIF pThis);
    214218
    215219
     
    228232 * @internal
    229233 */
    230 DECLINLINE(PINTNETIF) intnetHandle2IFPtrLocked(PINTNETHT pHT, INTNETIFHANDLE hIF)
     234DECLINLINE(PINTNETIF) intnetR0Handle2IFPtrLocked(PINTNETHT pHT, INTNETIFHANDLE hIF)
    231235{
    232236    if (RT_LIKELY((hIF & INTNET_HANDLE_MAGIC) == INTNET_HANDLE_MAGIC))
     
    250254 * @param   hIF         The interface handle to validate and translate.
    251255 */
    252 DECLINLINE(PINTNETIF) intnetHandle2IFPtr(PINTNETHT pHT, INTNETIFHANDLE hIF)
     256DECLINLINE(PINTNETIF) intnetR0Handle2IFPtr(PINTNETHT pHT, INTNETIFHANDLE hIF)
    253257{
    254258    AssertPtr(pHT);
    255259    RTSPINLOCKTMP   Tmp = RTSPINLOCKTMP_INITIALIZER;
    256260    RTSpinlockAcquire(pHT->Spinlock, &Tmp);
    257     PINTNETIF pIF = intnetHandle2IFPtrLocked(pHT, hIF);
     261    PINTNETIF pIF = intnetR0Handle2IFPtrLocked(pHT, hIF);
    258262    RTSpinlockRelease(pHT->Spinlock, &Tmp);
    259263
     
    270274 * @param   pIF         The interface which we're allocating a handle for.
    271275 */
    272 static INTNETIFHANDLE intnetHandleAllocate(PINTNET pIntNet, PINTNETIF pIF)
     276static INTNETIFHANDLE intnetR0HandleAllocate(PINTNET pIntNet, PINTNETIF pIF)
    273277{
    274278    Assert(pIF);
     
    355359 * @param   h           The handle we're freeing.
    356360 */
    357 static PINTNETIF intnetHandleFree(PINTNETHT pHT, INTNETIFHANDLE h)
     361static PINTNETIF intnetR0HandleFree(PINTNETHT pHT, INTNETIFHANDLE h)
    358362{
    359363    RTSPINLOCKTMP   Tmp = RTSPINLOCKTMP_INITIALIZER;
     
    364368     * at the end of the free list.
    365369     */
    366     PINTNETIF pIF = intnetHandle2IFPtrLocked(pHT, h);
     370    PINTNETIF pIF = intnetR0Handle2IFPtrLocked(pHT, h);
    367371    if (pIF)
    368372    {
     
    395399 *                      ensuring that there is sufficient space for the frame.
    396400 */
    397 static unsigned intnetRingReadFrame(PINTNETBUF pBuf, PINTNETRINGBUF pRingBuf, void *pvFrame)
     401static unsigned intnetR0RingReadFrame(PINTNETBUF pBuf, PINTNETRINGBUF pRingBuf, void *pvFrame)
    398402{
    399403    Assert(pRingBuf->offRead < pBuf->cbBuf);
     
    415419    return cb;
    416420}
    417 #endif
     421#endif /* IN_INTNET_TESTCASE */
    418422
    419423
     
    427431 * @param   cbFrame     The size of the frame.
    428432 */
    429 static int intnetRingWriteFrame(PINTNETBUF pBuf, PINTNETRINGBUF pRingBuf, const void *pvFrame, uint32_t cbFrame)
     433static int intnetR0RingWriteFrame(PINTNETBUF pBuf, PINTNETRINGBUF pRingBuf, const void *pvFrame, uint32_t cbFrame)
    430434{
    431435    /*
     
    530534 * @param   cbFrame     The size of the frame.
    531535 */
    532 static void intnetIfSend(PINTNETIF pIf, const void *pvFrame, unsigned cbFrame)
    533 {
    534     LogFlow(("intnetIfSend: pIf=%p:{.hIf=%RX32}\n", pIf, pIf->hIf));
    535     int rc = intnetRingWriteFrame(pIf->pIntBuf, &pIf->pIntBuf->Recv, pvFrame, cbFrame);
     536static void intnetR0IfSend(PINTNETIF pIf, const void *pvFrame, unsigned cbFrame)
     537{
     538    LogFlow(("intnetR0IfSend: pIf=%p:{.hIf=%RX32}\n", pIf, pIf->hIf));
     539    int rc = intnetR0RingWriteFrame(pIf->pIntBuf, &pIf->pIntBuf->Recv, pvFrame, cbFrame);
    536540    if (RT_SUCCESS(rc))
    537541    {
     
    554558            RTSemEventSignal(pIf->Event);
    555559            RTThreadYield();
    556             rc = intnetRingWriteFrame(pIf->pIntBuf, &pIf->pIntBuf->Recv, pvFrame, cbFrame);
     560            rc = intnetR0RingWriteFrame(pIf->pIntBuf, &pIf->pIntBuf->Recv, pvFrame, cbFrame);
    557561            if (RT_SUCCESS(rc))
    558562            {
     
    587591 * @param   cbFrame     The size of the frame.
    588592 */
    589 static void intnetNetworkSend(PINTNETNETWORK pNetwork, PINTNETIF pIfSender, const void *pvFrame, unsigned cbFrame)
     593static void intnetR0NetworkSend(PINTNETNETWORK pNetwork, PINTNETIF pIfSender, const void *pvFrame, unsigned cbFrame)
    590594{
    591595    /*
     
    632636        for (PINTNETIF pIf = pNetwork->pIFs; pIf; pIf = pIf->pNext)
    633637            if (pIf != pIfSender)
    634                 intnetIfSend(pIf, pvFrame, cbFrame);
     638                intnetR0IfSend(pIf, pvFrame, cbFrame);
    635639    }
    636640    else
     
    647651                ||  (   pIf->fPromiscuous
    648652                     && pIf != pIfSender /* promiscuous mode: omit the sender */))
    649                 intnetIfSend(pIf, pvFrame, cbFrame);
     653                intnetR0IfSend(pIf, pvFrame, cbFrame);
    650654        }
    651655    }
     
    675679     */
    676680    AssertReturn(pIntNet, VERR_INVALID_PARAMETER);
    677     PINTNETIF pIf = intnetHandle2IFPtr(&pIntNet->IfHandles, hIf);
     681    PINTNETIF pIf = intnetR0Handle2IFPtr(&pIntNet->IfHandles, hIf);
    678682    if (!pIf)
    679683        return VERR_INVALID_HANDLE;
     
    696700     */
    697701    if (pvFrame && cbFrame)
    698         intnetNetworkSend(pIf->pNetwork, pIf, pvFrame, cbFrame);
     702        intnetR0NetworkSend(pIf->pNetwork, pIf, pvFrame, cbFrame);
    699703
    700704    /*
     
    709713            void *pvCurFrame = INTNETHdrGetFramePtr(pHdr, pIf->pIntBuf);
    710714            if (pvCurFrame)
    711                 intnetNetworkSend(pIf->pNetwork, pIf, pvCurFrame, pHdr->cbFrame);
     715                intnetR0NetworkSend(pIf->pNetwork, pIf, pvCurFrame, pHdr->cbFrame);
    712716        }
    713717        /* else: ignore the frame */
     
    752756     */
    753757    AssertReturn(pIntNet, VERR_INVALID_PARAMETER);
    754     PINTNETIF pIf = intnetHandle2IFPtr(&pIntNet->IfHandles, hIf);
     758    PINTNETIF pIf = intnetR0Handle2IFPtr(&pIntNet->IfHandles, hIf);
    755759    if (!pIf)
    756760        return VERR_INVALID_HANDLE;
     
    807811    *ppRing0Buf = NULL;
    808812    AssertPtrReturn(pIntNet, VERR_INVALID_PARAMETER);
    809     PINTNETIF pIf = intnetHandle2IFPtr(&pIntNet->IfHandles, hIf);
     813    PINTNETIF pIf = intnetR0Handle2IFPtr(&pIntNet->IfHandles, hIf);
    810814    if (!pIf)
    811815        return VERR_INVALID_HANDLE;
     
    843847     */
    844848    AssertReturn(pIntNet, VERR_INVALID_PARAMETER);
    845     PINTNETIF pIf = intnetHandle2IFPtr(&pIntNet->IfHandles, hIf);
     849    PINTNETIF pIf = intnetR0Handle2IFPtr(&pIntNet->IfHandles, hIf);
    846850    if (!pIf)
    847851        return VERR_INVALID_HANDLE;
     
    884888     */
    885889    AssertReturn(pIntNet, VERR_INVALID_PARAMETER);
    886     PINTNETIF pIf = intnetHandle2IFPtr(&pIntNet->IfHandles, hIf);
     890    PINTNETIF pIf = intnetR0Handle2IFPtr(&pIntNet->IfHandles, hIf);
    887891    if (!pIf)
    888892    {
     
    894898     * Grab the network semaphore and make the change.
    895899     */
    896     int rc = RTSemFastMutexRequest(pIf->pNetwork->FastMutex);
     900    PINTNETNETWORK pNetwork = pIf->pNetwork;
     901    if (!pNetwork)
     902        return VERR_WRONG_ORDER;
     903    int rc = RTSemFastMutexRequest(pNetwork->FastMutex);
    897904    if (RT_FAILURE(rc))
    898905        return rc;
     
    905912    }
    906913
    907     RTSemFastMutexRelease(pIf->pNetwork->FastMutex);
     914    RTSemFastMutexRelease(pNetwork->FastMutex);
    908915    return VINF_SUCCESS;
    909916}
     
    922929        return VERR_INVALID_PARAMETER;
    923930    return INTNETR0IfSetPromiscuousMode(pIntNet, pReq->hIf, pReq->fPromiscuous);
     931}
     932
     933
     934/**
     935 * Worker for intnetR0IfSetActive.
     936 *
     937 * This function will update the active interface count on the network and
     938 * activate or deactivate the trunk connection if necessary. Note that in
     939 * order to do this it is necessary to abandond the network semaphore.
     940 *
     941 * @returns VBox status code.
     942 * @param   pNetwork        The network.
     943 * @param   fIf             The interface.
     944 * @param   fActive         What to do.
     945 */
     946static int intnetR0NetworkSetIfActive(PINTNETNETWORK pNetwork, PINTNETIF pIf, bool fActive)
     947{
     948    /* quick santiy check */
     949    AssertPtr(pNetwork);
     950    AssertPtr(pIf);
     951
     952    /*
     953     * If we've got a trunk, lock it now in case we need to call out, and
     954     * then lock the network.
     955     */
     956    PINTNETTRUNKIF pTrunkIf = pNetwork->pTrunkIF;
     957    if (pTrunkIf && !intnetR0TrunkIfOutLock(pTrunkIf))
     958        return VERR_SEM_DESTROYED;
     959
     960    int rc = RTSemFastMutexRequest(pNetwork->FastMutex); AssertRC(rc);
     961    if (RT_SUCCESS(rc))
     962    {
     963        bool fNetworkLocked = true;
     964
     965        /*
     966         * Make the change if necessary.
     967         */
     968        if (pIf->fActive != fActive)
     969        {
     970            pIf->fActive = fActive;
     971
     972            uint32_t const cActiveIFs = pNetwork->cActiveIFs;
     973            Assert((int32_t)cActiveIFs + (fActive ? 1 : -1) >= 0);
     974            pNetwork->cActiveIFs += fActive ? 1 : -1;
     975
     976            if (    pTrunkIf
     977                &&  (   !pNetwork->cActiveIFs
     978                     || !cActiveIFs))
     979            {
     980                /*
     981                 * We'll have to change the trunk status, so, leave
     982                 * the network semaphore so we don't create any deadlocks.
     983                 */
     984                int rc2 = RTSemFastMutexRelease(pNetwork->FastMutex); AssertRC(rc2);
     985                fNetworkLocked = false;
     986
     987                if (pTrunkIf->pIfPort)
     988                    pTrunkIf->pIfPort->pfnSetActive(pTrunkIf->pIfPort, fActive);
     989            }
     990        }
     991
     992        if (fNetworkLocked)
     993            RTSemFastMutexRelease(pNetwork->FastMutex);
     994    }
     995    if (pTrunkIf)
     996        intnetR0TrunkIfOutUnlock(pTrunkIf);
     997    return rc;
     998}
     999
     1000
     1001/**
     1002 * Activates or deactivates a interface.
     1003 *
     1004 * This is used to enable and disable the trunk connection on demans as well as
     1005 * know when not to expect an interface to want to receive packets.
     1006 *
     1007 * @returns VBox status code.
     1008 * @param   pIf         The interface.
     1009 * @param   fActive     What to do.
     1010 */
     1011static int intnetR0IfSetActive(PINTNETIF pIf, bool fActive)
     1012{
     1013    /* quick sanity check */
     1014    AssertPtrReturn(pIf, VERR_INVALID_POINTER);
     1015
     1016    /*
     1017     * Hand it to the network since it might involve the trunk
     1018     * and things are tricky there wrt to locking order.
     1019     */
     1020    PINTNETNETWORK pNetwork = pIf->pNetwork;
     1021    if (!pNetwork)
     1022        return VERR_WRONG_ORDER;
     1023    return intnetR0NetworkSetIfActive(pNetwork, pIf, fActive);
    9241024}
    9251025
     
    9431043     */
    9441044    AssertReturn(pIntNet, VERR_INVALID_PARAMETER);
    945     PINTNETIF pIf = intnetHandle2IFPtr(&pIntNet->IfHandles, hIf);
     1045    PINTNETIF pIf = intnetR0Handle2IFPtr(&pIntNet->IfHandles, hIf);
    9461046    if (!pIf)
    9471047    {
     
    10151115     */
    10161116    AssertPtrReturn(pIntNet, VERR_INVALID_PARAMETER);
    1017     PINTNETIF pIf = intnetHandleFree(&pIntNet->IfHandles, hIf);
     1117    PINTNETIF pIf = intnetR0HandleFree(&pIntNet->IfHandles, hIf);
    10181118    if (!pIf)
    10191119        return VERR_INVALID_HANDLE;
     
    10521152 * @param   pvUser2     Pointer to the INTNET instance data.
    10531153 */
    1054 static DECLCALLBACK(void) intnetIfDestruct(void *pvObj, void *pvUser1, void *pvUser2)
    1055 {
    1056     LogFlow(("intnetIfDestruct: pvObj=%p pvUser1=%p pvUser2=%p\n", pvObj, pvUser1, pvUser2));
     1154static DECLCALLBACK(void) intnetR0IfDestruct(void *pvObj, void *pvUser1, void *pvUser2)
     1155{
     1156    LogFlow(("intnetR0IfDestruct: pvObj=%p pvUser1=%p pvUser2=%p\n", pvObj, pvUser1, pvUser2));
    10571157    PINTNETIF pIf = (PINTNETIF)pvUser1;
    10581158    PINTNET   pIntNet = (PINTNET)pvUser2;
     
    10651165    INTNETIFHANDLE hIf = ASMAtomicXchgU32(&pIf->hIf, INTNET_HANDLE_INVALID);
    10661166    if (hIf != INTNET_HANDLE_INVALID)
    1067         intnetHandleFree(&pIntNet->IfHandles, hIf);
    1068 
    1069     /*
    1070      * If we've got a network unlink ourselves from it.
     1167        intnetR0HandleFree(&pIntNet->IfHandles, hIf);
     1168
     1169    /*
     1170     * If we've got a network deactivate and unlink ourselves from it.
    10711171     * Because of cleanup order we might be an orphan now.
    10721172     */
     
    10741174    if (pNetwork)
    10751175    {
     1176        intnetR0IfSetActive(pIf, false);
     1177
    10761178        if (pNetwork->pIFs == pIf)
    10771179            pNetwork->pIFs = pIf->pNext;
     
    11761278 * @param   phIf        Where to store the interface handle.
    11771279 */
    1178 static int intnetNetworkCreateIf(PINTNETNETWORK pNetwork, PSUPDRVSESSION pSession, unsigned cbSend, unsigned cbRecv, PINTNETIFHANDLE phIf)
    1179 {
    1180     LogFlow(("intnetNetworkCreateIf: pNetwork=%p pSession=%p cbSend=%u cbRecv=%u phIf=%p\n",
     1280static int intnetR0NetworkCreateIf(PINTNETNETWORK pNetwork, PSUPDRVSESSION pSession, unsigned cbSend, unsigned cbRecv, bool *pfCloseNetwork, PINTNETIFHANDLE phIf)
     1281{
     1282    LogFlow(("intnetR0NetworkCreateIf: pNetwork=%p pSession=%p cbSend=%u cbRecv=%u phIf=%p\n",
    11811283             pNetwork, pSession, cbSend, cbRecv, phIf));
    11821284
     
    11861288    AssertPtr(pNetwork);
    11871289    AssertPtr(phIf);
     1290    AssertPtr(pfCloseNetwork);
     1291    *pfCloseNetwork = false;
    11881292
    11891293    /*
     
    11931297    if (!pIf)
    11941298        return VERR_NO_MEMORY;
    1195 
     1299    //pIf->pNext = NULL;
    11961300    memset(&pIf->Mac, 0xff, sizeof(pIf->Mac)); /* broadcast */
    1197     //pIf->fMacSet = 0;
     1301    //pIf->fMacSet = false;
     1302    //pIf->fPromiscuous = false;
     1303    //pIf->fActive = false;
     1304    //pIf->pIntBuf = 0;
     1305    //pIf->pIntBufR3 = NIL_RTR3PTR;
     1306    //pIf->pIntBufDefault = 0;
     1307    //pIf->pIntBufDefaultR3 = NIL_RTR3PTR;
     1308    //pIf->cYields = 0;
     1309    pIf->Event = NIL_RTSEMEVENT;
     1310    //pIf->cSleepers = 0;
     1311    pIf->hIf = INTNET_HANDLE_INVALID;
     1312    pIf->pNetwork = pNetwork;
     1313    pIf->pSession = pSession;
     1314    //pIf->pvObj = NULL;
    11981315    int rc = RTSemEventCreate(&pIf->Event);
    11991316    if (RT_SUCCESS(rc))
    12001317    {
    1201         pIf->pSession = pSession;
    1202         pIf->pNetwork = pNetwork;
    1203 
    12041318        /*
    12051319         * Create the default buffer.
     
    12401354                 * Register the interface with the session.
    12411355                 */
    1242                 pIf->pvObj = SUPR0ObjRegister(pSession, SUPDRVOBJTYPE_INTERNAL_NETWORK_INTERFACE, intnetIfDestruct, pIf, pNetwork->pIntNet);
     1356                pIf->pvObj = SUPR0ObjRegister(pSession, SUPDRVOBJTYPE_INTERNAL_NETWORK_INTERFACE, intnetR0IfDestruct, pIf, pNetwork->pIntNet);
    12431357                if (pIf->pvObj)
    12441358                {
    1245                     pIf->hIf = intnetHandleAllocate(pNetwork->pIntNet, pIf);
     1359                    pIf->hIf = intnetR0HandleAllocate(pNetwork->pIntNet, pIf);
    12461360                    if (pIf->hIf != INTNET_HANDLE_INVALID)
    12471361                    {
     1362                        /* auto activation */ /** @todo do this manually in the future, ditto for setting the MAC address. */
     1363                        rc = intnetR0IfSetActive(pIf, true /* activate */);
     1364                        AssertRC(rc);
     1365
    12481366                        *phIf = pIf->hIf;
    1249                         LogFlow(("intnetNetworkCreateIf: returns VINF_SUCCESS *phIf=%p\n", *phIf));
     1367                        LogFlow(("intnetR0NetworkCreateIf: returns VINF_SUCCESS *phIf=%p\n", *phIf));
    12501368                        return VINF_SUCCESS;
    12511369                    }
     
    12531371
    12541372                    SUPR0ObjRelease(pIf->pvObj, pSession);
    1255                     LogFlow(("intnetNetworkCreateIf: returns %Rrc\n", rc));
     1373                    LogFlow(("intnetR0NetworkCreateIf: returns %Rrc\n", rc));
    12561374                    return rc;
    12571375                }
     1376
    12581377                rc = VERR_NO_MEMORY;
    12591378                RTSemFastMutexDestroy(pNetwork->FastMutex);
    12601379                pNetwork->FastMutex = NIL_RTSEMFASTMUTEX;
    12611380            }
     1381
    12621382            SUPR0MemFree(pIf->pSession, (RTHCUINTPTR)pIf->pIntBufDefault);
    12631383            pIf->pIntBufDefault = NULL;
     
    12691389    }
    12701390    RTMemFree(pIf);
    1271     LogFlow(("intnetNetworkCreateIf: returns %Rrc\n", rc));
     1391    LogFlow(("intnetR0NetworkCreateIf: returns %Rrc\n", rc));
     1392    *pfCloseNetwork = true;
    12721393    return rc;
    12731394}
     
    12781399
    12791400/** @copydoc INTNETTRUNKSWPORT::pfnSetSGPhys */
    1280 static DECLCALLBACK(bool) intnetTrunkIfPortSetSGPhys(PINTNETTRUNKSWPORT pSwitchPort, bool fEnable)
     1401static DECLCALLBACK(bool) intnetR0TrunkIfPortSetSGPhys(PINTNETTRUNKSWPORT pSwitchPort, bool fEnable)
    12811402{
    12821403    PINTNETTRUNKIF pThis = INTNET_SWITCHPORT_2_TRUNKIF(pSwitchPort);
     
    12871408
    12881409/** @copydoc INTNETTRUNKSWPORT::pfnRecv */
    1289 static DECLCALLBACK(bool) intnetTrunkIfPortRecv(PINTNETTRUNKSWPORT pSwitchPort, PINTNETSG pSG, uint32_t fSrc)
     1410static DECLCALLBACK(bool) intnetR0TrunkIfPortRecv(PINTNETTRUNKSWPORT pSwitchPort, PINTNETSG pSG, uint32_t fSrc)
    12901411{
    12911412    PINTNETTRUNKIF pThis = INTNET_SWITCHPORT_2_TRUNKIF(pSwitchPort);
     
    13081429
    13091430/** @copydoc INTNETTRUNKSWPORT::pfnSGRetain */
    1310 static DECLCALLBACK(void) intnetTrunkIfPortSGRetain(PINTNETTRUNKSWPORT pSwitchPort, PINTNETSG pSG)
     1431static DECLCALLBACK(void) intnetR0TrunkIfPortSGRetain(PINTNETTRUNKSWPORT pSwitchPort, PINTNETSG pSG)
    13111432{
    13121433    PINTNETTRUNKIF pThis = INTNET_SWITCHPORT_2_TRUNKIF(pSwitchPort);
     
    13251446
    13261447/** @copydoc INTNETTRUNKSWPORT::pfnSGRelease */
    1327 static DECLCALLBACK(void) intnetTrunkIfPortSGRelease(PINTNETTRUNKSWPORT pSwitchPort, PINTNETSG pSG)
     1448static DECLCALLBACK(void) intnetR0TrunkIfPortSGRelease(PINTNETTRUNKSWPORT pSwitchPort, PINTNETSG pSG)
    13281449{
    13291450    PINTNETTRUNKIF pThis = INTNET_SWITCHPORT_2_TRUNKIF(pSwitchPort);
     
    13551476 * @remarks Any locks.
    13561477 */
    1357 static PINTNETTRUNKIF intnetTrunkIfRetain(PINTNETTRUNKIF pThis)
     1478static PINTNETTRUNKIF intnetR0TrunkIfRetain(PINTNETTRUNKIF pThis)
    13581479{
    13591480    if (pThis && pThis->pIfPort)
     
    13681489 * @param   pThis       The trunk.
    13691490 */
    1370 static void intnetTrunkIfRelease(PINTNETTRUNKIF pThis)
     1491static void intnetR0TrunkIfRelease(PINTNETTRUNKIF pThis)
    13711492{
    13721493    if (pThis && pThis->pIfPort)
     
    13851506 * @remarks No locks other than the create/destroy one.
    13861507 */
    1387 static bool intnetTrunkIfOutLock(PINTNETTRUNKIF pThis)
     1508static bool intnetR0TrunkIfOutLock(PINTNETTRUNKIF pThis)
    13881509{
    13891510    AssertPtrReturn(pThis, false);
     
    14061527 * @param   pThis       The trunk.
    14071528 */
    1408 static void intnetTrunkIfOutUnlock(PINTNETTRUNKIF pThis)
     1529static void intnetR0TrunkIfOutUnlock(PINTNETTRUNKIF pThis)
    14091530{
    14101531    if (pThis)
     
    14241545 * @remarks Caller may only own the create/destroy lock.
    14251546 */
    1426 static void intnetTrunkIfActivate(PINTNETTRUNKIF pThis, bool fActive)
    1427 {
    1428     if (intnetTrunkIfOutLock(pThis))
     1547static void intnetR0TrunkIfActivate(PINTNETTRUNKIF pThis, bool fActive)
     1548{
     1549    if (intnetR0TrunkIfOutLock(pThis))
    14291550    {
    14301551        pThis->pIfPort->pfnSetActive(pThis->pIfPort, fActive);
    1431         intnetTrunkIfOutUnlock(pThis);
     1552        intnetR0TrunkIfOutUnlock(pThis);
    14321553    }
    14331554}
     
    14431564 *          create/destroy lock is fine though.
    14441565 */
    1445 static void intnetTrunkIfDestroy(PINTNETTRUNKIF pThis, PINTNETNETWORK pNetwork)
     1566static void intnetR0TrunkIfDestroy(PINTNETTRUNKIF pThis, PINTNETNETWORK pNetwork)
    14461567{
    14471568    /* assert sanity */
     
    14591580    if (pIfPort)
    14601581    {
    1461         intnetTrunkIfOutLock(pThis);
     1582        intnetR0TrunkIfOutLock(pThis);
    14621583
    14631584        /* unset it */
     
    15151636 * @param   pSession    The session handle.
    15161637 */
    1517 static int intnetNetworkCreateTrunkConnection(PINTNETNETWORK pNetwork, PSUPDRVSESSION pSession)
     1638static int intnetR0NetworkCreateTrunkIf(PINTNETNETWORK pNetwork, PSUPDRVSESSION pSession)
    15181639{
    15191640    const char *pszName;
     
    15521673        return VERR_NO_MEMORY;
    15531674    pTrunkIF->SwitchPort.u32Version     = INTNETTRUNKSWPORT_VERSION;
    1554     pTrunkIF->SwitchPort.pfnSetSGPhys   = intnetTrunkIfPortSetSGPhys;
    1555     pTrunkIF->SwitchPort.pfnRecv        = intnetTrunkIfPortRecv;
    1556     pTrunkIF->SwitchPort.pfnSGRetain    = intnetTrunkIfPortSGRetain;
    1557     pTrunkIF->SwitchPort.pfnSGRelease   = intnetTrunkIfPortSGRelease;
     1675    pTrunkIF->SwitchPort.pfnSetSGPhys   = intnetR0TrunkIfPortSetSGPhys;
     1676    pTrunkIF->SwitchPort.pfnRecv        = intnetR0TrunkIfPortRecv;
     1677    pTrunkIF->SwitchPort.pfnSGRetain    = intnetR0TrunkIfPortSGRetain;
     1678    pTrunkIF->SwitchPort.pfnSGRelease   = intnetR0TrunkIfPortSGRelease;
    15581679    pTrunkIF->SwitchPort.u32VersionEnd  = INTNETTRUNKSWPORT_VERSION;
    15591680    //pTrunkIF->pIfPort = NULL;
     
    15771698                Assert(pTrunkIF->pIfPort);
    15781699                pNetwork->pTrunkIF = pTrunkIF;
    1579                 LogFlow(("intnetNetworkCreateTrunkConnection: VINF_SUCCESS - pszName=%s szTrunk=%s Network=%s\n",
     1700                LogFlow(("intnetR0NetworkCreateTrunkIf: VINF_SUCCESS - pszName=%s szTrunk=%s Network=%s\n",
    15801701                         rc, pszName, pNetwork->szTrunk, pNetwork->szName));
    15811702                return VINF_SUCCESS;
     
    15861707    }
    15871708    RTMemFree(pTrunkIF);
    1588     LogFlow(("intnetNetworkCreateTrunkConnection: %Rrc - pszName=%s szTrunk=%s Network=%s\n",
     1709    LogFlow(("intnetR0NetworkCreateTrunkIf: %Rrc - pszName=%s szTrunk=%s Network=%s\n",
    15891710             rc, pszName, pNetwork->szTrunk, pNetwork->szName));
    15901711    return rc;
     
    15941715
    15951716/**
    1596  * Close a network which was opened/created using intnetOpenNetwork()/intnetCreateNetwork().
     1717 * Close a network which was opened/created using intnetR0OpenNetwork()/intnetR0CreateNetwork().
    15971718 *
    15981719 * @param   pNetwork    The network to close.
    15991720 * @param   pSession    The session handle.
    16001721 */
    1601 static int intnetNetworkClose(PINTNETNETWORK pNetwork, PSUPDRVSESSION pSession)
    1602 {
    1603     LogFlow(("intnetNetworkClose: pNetwork=%p pSession=%p\n", pNetwork, pSession));
     1722static int intnetR0NetworkClose(PINTNETNETWORK pNetwork, PSUPDRVSESSION pSession)
     1723{
     1724    LogFlow(("intnetR0NetworkClose: pNetwork=%p pSession=%p\n", pNetwork, pSession));
    16041725    AssertPtrReturn(pSession, VERR_INVALID_PARAMETER);
    16051726    AssertPtrReturn(pNetwork, VERR_INVALID_PARAMETER);
    16061727
    16071728    int rc = SUPR0ObjRelease(pNetwork->pvObj, pSession);
    1608     LogFlow(("intnetNetworkClose: return %Rrc\n", rc));
     1729    LogFlow(("intnetR0NetworkClose: return %Rrc\n", rc));
    16091730    return rc;
    16101731}
     
    16191740 * @param   pvUser2     Pointer to the INTNET instance data.
    16201741 */
    1621 static DECLCALLBACK(void) intnetNetworkDestruct(void *pvObj, void *pvUser1, void *pvUser2)
    1622 {
    1623     LogFlow(("intnetNetworkDestruct: pvObj=%p pvUser1=%p pvUser2=%p\n", pvObj, pvUser1, pvUser2));
     1742static DECLCALLBACK(void) intnetR0NetworkDestruct(void *pvObj, void *pvUser1, void *pvUser2)
     1743{
     1744    LogFlow(("intnetR0NetworkDestruct: pvObj=%p pvUser1=%p pvUser2=%p\n", pvObj, pvUser1, pvUser2));
    16241745    PINTNETNETWORK  pNetwork = (PINTNETNETWORK)pvUser1;
    16251746    PINTNET         pIntNet = (PINTNET)pvUser2;
     
    16331754     */
    16341755    if (pNetwork->pTrunkIF)
    1635         intnetTrunkIfActivate(pNetwork->pTrunkIF, false /* fActive */);
     1756        intnetR0TrunkIfActivate(pNetwork->pTrunkIF, false /* fActive */);
    16361757
    16371758    /*
     
    16811802     */
    16821803    if (pTrunkIF)
    1683         intnetTrunkIfDestroy(pTrunkIF, pNetwork);
     1804        intnetR0TrunkIfDestroy(pTrunkIF, pNetwork);
    16841805
    16851806    /*
     
    17071828 * @param   ppNetwork       Where to store the pointer to the network on success.
    17081829 */
    1709 static int intnetOpenNetwork(PINTNET pIntNet, PSUPDRVSESSION pSession, const char *pszNetwork, INTNETTRUNKTYPE enmTrunkType,
    1710                              const char *pszTrunk, uint32_t fFlags, PINTNETNETWORK *ppNetwork)
    1711 {
    1712     LogFlow(("intnetOpenNetwork: pIntNet=%p pSession=%p pszNetwork=%p:{%s} enmTrunkType=%d pszTrunk=%p:{%s} fFlags=%#x ppNetwork=%p\n",
     1830static int intnetR0OpenNetwork(PINTNET pIntNet, PSUPDRVSESSION pSession, const char *pszNetwork, INTNETTRUNKTYPE enmTrunkType,
     1831                               const char *pszTrunk, uint32_t fFlags, PINTNETNETWORK *ppNetwork)
     1832{
     1833    LogFlow(("intnetR0OpenNetwork: pIntNet=%p pSession=%p pszNetwork=%p:{%s} enmTrunkType=%d pszTrunk=%p:{%s} fFlags=%#x ppNetwork=%p\n",
    17131834             pIntNet, pSession, pszNetwork, pszNetwork, enmTrunkType, pszTrunk, pszTrunk, fFlags, ppNetwork));
    17141835
     
    17711892                rc = VERR_INTNET_INCOMPATIBLE_TRUNK;
    17721893
    1773             LogFlow(("intnetOpenNetwork: returns %Rrc *ppNetwork=%p\n", rc, *ppNetwork));
     1894            LogFlow(("intnetR0OpenNetwork: returns %Rrc *ppNetwork=%p\n", rc, *ppNetwork));
    17741895            return rc;
    17751896        }
     
    17771898    }
    17781899
    1779     LogFlow(("intnetOpenNetwork: returns VERR_NOT_FOUND\n"));
     1900    LogFlow(("intnetR0OpenNetwork: returns VERR_NOT_FOUND\n"));
    17801901    return VERR_NOT_FOUND;
    17811902}
     
    17991920 *                          here should be dereferenced outside the INTNET::FastMutex.
    18001921 */
    1801 static int intnetCreateNetwork(PINTNET pIntNet, PSUPDRVSESSION pSession, const char *pszNetwork, INTNETTRUNKTYPE enmTrunkType,
    1802                                const char *pszTrunk, uint32_t fFlags, PINTNETNETWORK *ppNetwork)
    1803 {
    1804     LogFlow(("intnetCreateNetwork: pIntNet=%p pSession=%p pszNetwork=%p:{%s} enmTrunkType=%d pszTrunk=%p:{%s} fFlags=%#x ppNetwork=%p\n",
     1922static int intnetR0CreateNetwork(PINTNET pIntNet, PSUPDRVSESSION pSession, const char *pszNetwork, INTNETTRUNKTYPE enmTrunkType,
     1923                                 const char *pszTrunk, uint32_t fFlags, PINTNETNETWORK *ppNetwork)
     1924{
     1925    LogFlow(("intnetR0CreateNetwork: pIntNet=%p pSession=%p pszNetwork=%p:{%s} enmTrunkType=%d pszTrunk=%p:{%s} fFlags=%#x ppNetwork=%p\n",
    18051926             pIntNet, pSession, pszNetwork, pszNetwork, enmTrunkType, pszTrunk, pszTrunk, fFlags, ppNetwork));
    18061927
     
    18261947        //pNew->pIFs = NULL;
    18271948        pNew->pIntNet = pIntNet;
     1949        //pNew->cActiveIFs = 0;
    18281950        pNew->fFlags = fFlags;
    18291951        size_t cchName = strlen(pszNetwork);
     
    18381960         * Register the object in the current session and link it into the network list.
    18391961         */
    1840         pNew->pvObj = SUPR0ObjRegister(pSession, SUPDRVOBJTYPE_INTERNAL_NETWORK, intnetNetworkDestruct, pNew, pIntNet);
     1962        pNew->pvObj = SUPR0ObjRegister(pSession, SUPDRVOBJTYPE_INTERNAL_NETWORK, intnetR0NetworkDestruct, pNew, pIntNet);
    18411963        if (pNew->pvObj)
    18421964        {
     
    18551977                 * Connect the trunk.
    18561978                 */
    1857 #ifdef IN_RING0
    1858                 rc = intnetNetworkCreateTrunkConnection(pNew, pSession);
    1859 #endif
     1979                rc = intnetR0NetworkCreateTrunkIf(pNew, pSession);
    18601980                if (RT_SUCCESS(rc))
    18611981                {
    18621982                    *ppNetwork = pNew;
    1863                     LogFlow(("intnetCreateNetwork: returns VINF_SUCCESS *ppNetwork=%p\n", pNew));
     1983                    LogFlow(("intnetR0CreateNetwork: returns VINF_SUCCESS *ppNetwork=%p\n", pNew));
    18641984                    return VINF_SUCCESS;
    18651985                }
     
    18751995
    18761996            *ppNetwork = pNew;
    1877             LogFlow(("intnetCreateNetwork: returns %Rrc\n", rc));
     1997            LogFlow(("intnetR0CreateNetwork: returns %Rrc\n", rc));
    18781998            return rc;
    18791999        }
     
    18842004    }
    18852005    RTMemFree(pNew);
    1886     LogFlow(("intnetCreateNetwork: returns %Rrc\n", rc));
     2006    LogFlow(("intnetR0CreateNetwork: returns %Rrc\n", rc));
    18872007    return rc;
    18882008}
     
    19632083     * Note that because of the destructors grabbing INTNET::FastMutex and us being required
    19642084     * to own this semaphore for the entire network opening / creation and interface creation
    1965      * sequence, intnetCreateNetwork will have to defer the network cleanup to us on failure.
     2085     * sequence, intnetR0CreateNetwork will have to defer the network cleanup to us on failure.
    19662086     */
    19672087    PINTNETNETWORK pNetwork = NULL;
    1968     rc = intnetOpenNetwork(pIntNet, pSession, pszNetwork, enmTrunkType, pszTrunk, fFlags, &pNetwork);
     2088    rc = intnetR0OpenNetwork(pIntNet, pSession, pszNetwork, enmTrunkType, pszTrunk, fFlags, &pNetwork);
    19692089    if (RT_SUCCESS(rc) || rc == VERR_NOT_FOUND)
    19702090    {
     2091        bool fCloseNetwork = true;
    19712092        if (rc == VERR_NOT_FOUND)
    1972             rc = intnetCreateNetwork(pIntNet, pSession, pszNetwork, enmTrunkType, pszTrunk, fFlags, &pNetwork);
     2093            rc = intnetR0CreateNetwork(pIntNet, pSession, pszNetwork, enmTrunkType, pszTrunk, fFlags, &pNetwork);
    19732094        if (RT_SUCCESS(rc))
    1974             rc = intnetNetworkCreateIf(pNetwork, pSession, cbSend, cbRecv, phIf);
     2095            rc = intnetR0NetworkCreateIf(pNetwork, pSession, cbSend, cbRecv, &fCloseNetwork, phIf);
    19752096
    19762097        RTSemFastMutexRelease(pIntNet->FastMutex);
    19772098
    1978         if (RT_FAILURE(rc) && pNetwork)
    1979             intnetNetworkClose(pNetwork, pSession);
     2099        if (RT_FAILURE(rc) && pNetwork && fCloseNetwork)
     2100            intnetR0NetworkClose(pNetwork, pSession);
    19802101    }
    19812102    else
  • trunk/src/VBox/Devices/Network/testcase/tstIntNetR0.cpp

    r10681 r10711  
    238238        int rc = INTNETR0IfSend(pArgs->pIntNet, pArgs->hIf, abBuf, cb);
    239239#else
    240         int rc = intnetRingWriteFrame(pArgs->pBuf, &pArgs->pBuf->Send, abBuf, cb);
     240        int rc = intnetR0RingWriteFrame(pArgs->pBuf, &pArgs->pBuf->Send, abBuf, cb);
    241241        if (RT_SUCCESS(rc))
    242242            rc = INTNETR0IfSend(pArgs->pIntNet, pArgs->hIf, NULL, 0);
     
    315315        {
    316316            uint8_t abBuf[16384];
    317             unsigned cb = intnetRingReadFrame(pArgs->pBuf, &pArgs->pBuf->Recv, abBuf);
     317            unsigned cb = intnetR0RingReadFrame(pArgs->pBuf, &pArgs->pBuf->Recv, abBuf);
    318318            unsigned *puFrame = (unsigned *)&abBuf[sizeof(PDMMAC) * 2];
    319319
     
    461461                                g_cErrors++;
    462462                            }
    463                             unsigned cb = intnetRingReadFrame(pBuf1, &pBuf1->Recv, abBuf);
     463                            unsigned cb = intnetR0RingReadFrame(pBuf1, &pBuf1->Recv, abBuf);
    464464                            if (cb != sizeof(g_TestFrame0))
    465465                            {
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