VirtualBox

Changeset 29635 in vbox for trunk/src/VBox


Ignore:
Timestamp:
May 18, 2010 1:42:54 PM (15 years ago)
Author:
vboxsync
Message:

SrvIntNetR0.cpp,VBoxNetFlt.c: Adjusted r61623 so it won't crash if the network is already destroyed when the interface is being destroyed. Added paranoia and comments.

Location:
trunk/src/VBox
Files:
2 edited

Legend:

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

    r29491 r29635  
    31893189     * Learn the MAC address of the sender.  No re-learning as the interface
    31903190     * user will normally tell us the right MAC address.
     3191     *
     3192     * Note! We don't notify the trunk about these mainly because of the
     3193     *       problematic contexts we might be called in.
    31913194     */
    31923195    if (RT_UNLIKELY(    pIfSender
     
    36073610    if (pNetwork)
    36083611    {
    3609         RTSPINLOCKTMP Tmp = RTSPINLOCKTMP_INITIALIZER;
     3612        RTSPINLOCKTMP   Tmp    = RTSPINLOCKTMP_INITIALIZER;
     3613        PINTNETTRUNKIF  pTrunk = NULL;
     3614
    36103615        RTSpinlockAcquireNoInts(pNetwork->hAddrSpinlock, &Tmp);
    36113616
     
    36153620                 hIf, &pIf->MacAddr, pMac));
    36163621
     3622            /* Update the two copies. */
    36173623            PINTNETMACTABENTRY pEntry = intnetR0NetworkFindMacAddrEntry(pNetwork, pIf); Assert(pEntry);
    36183624            if (RT_LIKELY(pEntry))
     
    36203626            pIf->MacAddr        = *pMac;
    36213627            pIf->fMacSet        = true;
     3628
     3629            /* Grab a busy reference to the trunk so we release the lock before notifying it. */
     3630            pTrunk = pNetwork->MacTab.pTrunk;
     3631            if (pTrunk)
     3632                intnetR0BusyIncTrunk(pTrunk);
    36223633        }
    36233634
    3624         PINTNETTRUNKIF pTrunk = pNetwork->MacTab.pTrunk;
    36253635        RTSpinlockReleaseNoInts(pNetwork->hAddrSpinlock, &Tmp);
    3626         if (pTrunk && pTrunk->pIfPort)
     3636
     3637        if (pTrunk)
    36273638        {
    36283639            Log(("IntNetR0IfSetMacAddress: pfnNotifyMacAddress hIf=%RX32\n", hIf));
    3629             pTrunk->pIfPort->pfnNotifyMacAddress(pTrunk->pIfPort, hIf, pMac);
     3640            PINTNETTRUNKIFPORT pIfPort = pTrunk->pIfPort;
     3641            if (pIfPort)
     3642                pIfPort->pfnNotifyMacAddress(pIfPort, hIf, pMac);
     3643            intnetR0BusyDecTrunk(pTrunk);
    36303644        }
    36313645    }
     
    38983912    /*
    38993913     * Validate and free the handle.
     3914     *
     3915     * We grab the big mutex before we free the handle to avoid any handle
     3916     * confusion on the trunk.
    39003917     */
    39013918    PINTNET pIntNet = g_pIntNet;
     
    39033920    AssertReturn(pIntNet->u32Magic, VERR_INVALID_MAGIC);
    39043921
     3922    RTSemMutexRequest(pIntNet->hMtxCreateOpenDestroy, RT_INDEFINITE_WAIT);
     3923
    39053924    PINTNETIF pIf = (PINTNETIF)RTHandleTableFreeWithCtx(pIntNet->hHtIfs, hIf, pSession);
    39063925    if (!pIf)
     3926    {
     3927        RTSemMutexRelease(pIntNet->hMtxCreateOpenDestroy);
    39073928        return VERR_INVALID_HANDLE;
    3908 
    3909     /* mark the handle as freed so intnetR0IfDestruct won't free it again. */
     3929    }
     3930
     3931    /* Mark the handle as freed so intnetR0IfDestruct won't free it again. */
    39103932    ASMAtomicWriteU32(&pIf->hIf, INTNET_HANDLE_INVALID);
    39113933
    3912     /*
    3913      * Release the references to the interface object (handle + free lookup).
    3914      * But signal the event semaphore first so any waiter holding a reference
    3915      * will wake up too (he'll see hIf == invalid and return correctly).
     3934    /* Notify the trunk that the interface has been disconnected. */
     3935    PINTNETNETWORK pNetwork = pIf->pNetwork;
     3936    PINTNETTRUNKIF pTrunk   = pNetwork ? pNetwork->MacTab.pTrunk : NULL;
     3937    if (pTrunk && pTrunk->pIfPort)
     3938        pTrunk->pIfPort->pfnDisconnectInterface(pTrunk->pIfPort, hIf);
     3939
     3940    RTSemMutexRelease(pIntNet->hMtxCreateOpenDestroy);
     3941
     3942    /*
     3943     * Signal the event semaphore to wake up any threads in IntNetR0IfWait
     3944     * and give them a moment to get out and release the interface.
    39163945     */
    39173946    uint32_t i = pIf->cSleepers;
     
    39233952    RTSemEventSignal(pIf->hRecvEvent);
    39243953
     3954    /*
     3955     * Release the references to the interface object (handle + free lookup).
     3956     */
    39253957    void *pvObj = pIf->pvObj;
    39263958    intnetR0IfRelease(pIf, pSession); /* (RTHandleTableFreeWithCtx) */
     
    39704002    ASMAtomicWriteBool(&pIf->fDestroying, true);
    39714003
    3972     PINTNETNETWORK pNetwork = pIf->pNetwork;
    3973     PINTNETTRUNKIF pTrunk = pNetwork->MacTab.pTrunk;
    3974     if (pTrunk && pTrunk->pIfPort)
    3975     {
    3976         Log(("intnetR0IfDestruct: pfnDisconnectInterface hIf=%RX32\n", pIf->hIf));
    3977         pTrunk->pIfPort->pfnDisconnectInterface(pTrunk->pIfPort, pIf->hIf);
    3978     }
    3979 
    39804004    /*
    39814005     * Delete the interface handle so the object no longer can be used.
     
    39934017     * of cleanup order we might have been orphaned by the network destructor.
    39944018     */
     4019    PINTNETNETWORK pNetwork = pIf->pNetwork;
    39954020    if (pNetwork)
    39964021    {
     
    40144039            }
    40154040
     4041        PINTNETTRUNKIF pTrunk = pNetwork->MacTab.pTrunk;
     4042
    40164043        RTSpinlockReleaseNoInts(pNetwork->hAddrSpinlock, &Tmp);
     4044
     4045        /* If we freed the handle just now, notify the trunk about the
     4046           interface being destroyed. */
     4047        if (hIf != INTNET_HANDLE_INVALID && pTrunk && pTrunk->pIfPort)
     4048            pTrunk->pIfPort->pfnDisconnectInterface(pTrunk->pIfPort, hIf);
    40174049
    40184050        /* Wait for the interface to quiesce while we still can. */
     
    42144246                    pIf->pNetwork = pNetwork;
    42154247
    4216                     /** @todo handle failure of pfnConnectInterface */
     4248                    /*
     4249                     * Grab a busy reference (paranoia) to the trunk before releaseing
     4250                     * the spinlock and then notify it about the new interface.
     4251                     */
    42174252                    PINTNETTRUNKIF pTrunk = pNetwork->MacTab.pTrunk;
    4218                     if (pTrunk && pTrunk->pIfPort)
     4253                    if (pTrunk)
     4254                        intnetR0BusyIncTrunk(pTrunk);
     4255
     4256                    RTSpinlockReleaseNoInts(pNetwork->hAddrSpinlock, &Tmp);
     4257
     4258                    if (pTrunk)
    42194259                    {
    42204260                        Log(("intnetR0NetworkCreateIf: pfnConnectInterface hIf=%RX32\n", pIf->hIf));
    4221                         pTrunk->pIfPort->pfnConnectInterface(pTrunk->pIfPort, pIf->hIf);
     4261                        if (pTrunk->pIfPort)
     4262                            rc = pTrunk->pIfPort->pfnConnectInterface(pTrunk->pIfPort, pIf->hIf);
     4263                        intnetR0BusyDecTrunk(pTrunk);
    42224264                    }
    4223 
    4224                     RTSpinlockReleaseNoInts(pNetwork->hAddrSpinlock, &Tmp);
    4225 
    4226                     *phIf = pIf->hIf;
    4227                     Log(("intnetR0NetworkCreateIf: returns VINF_SUCCESS *phIf=%RX32 cbSend=%u cbRecv=%u cbBuf=%u\n",
    4228                          *phIf, pIf->pIntBufDefault->cbSend, pIf->pIntBufDefault->cbRecv, pIf->pIntBufDefault->cbBuf));
    4229                     return VINF_SUCCESS;
     4265                    if (RT_SUCCESS(rc))
     4266                    {
     4267                        /*
     4268                         * We're good!
     4269                         */
     4270                        *phIf = pIf->hIf;
     4271                        Log(("intnetR0NetworkCreateIf: returns VINF_SUCCESS *phIf=%RX32 cbSend=%u cbRecv=%u cbBuf=%u\n",
     4272                             *phIf, pIf->pIntBufDefault->cbSend, pIf->pIntBufDefault->cbRecv, pIf->pIntBufDefault->cbBuf));
     4273                        return VINF_SUCCESS;
     4274                    }
    42304275                }
    42314276
     
    48524897        intnetR0BusyWait(pNetwork, &pNetwork->MacTab.paEntries[iIf].pIf->cBusy);
    48534898
    4854     /* Orphan the interfaces (not trunk). */
     4899    /* Orphan the interfaces (not trunk).  Don't bother with calling
     4900       pfnDisconnectInterface here since the networking is going away. */
    48554901    RTSpinlockAcquireNoInts(pNetwork->hAddrSpinlock, &Tmp);
    48564902    while ((iIf = pNetwork->MacTab.cEntries) > 0)
  • trunk/src/VBox/HostDrivers/VBoxNetFlt/VBoxNetFlt.c

    r29492 r29635  
    558558static DECLCALLBACK(int) vboxNetFltPortConnectInterface(PINTNETTRUNKIFPORT pIfPort,  INTNETIFHANDLE hIf)
    559559{
    560     PVBOXNETFLTINS pThis = IFPORT_2_VBOXNETFLTINS(pIfPort);
    561     int rc = VINF_SUCCESS;
     560    PVBOXNETFLTINS  pThis = IFPORT_2_VBOXNETFLTINS(pIfPort);
     561    int             rc;
    562562
    563563    /*
     
    578578 * @copydoc INTNETTRUNKIFPORT::pfnDisconnectInterface
    579579 */
    580 static DECLCALLBACK(int) vboxNetFltPortDisconnectInterface(PINTNETTRUNKIFPORT pIfPort, INTNETIFHANDLE hIf)
    581 {
    582     PVBOXNETFLTINS pThis = IFPORT_2_VBOXNETFLTINS(pIfPort);
    583     int rc = VINF_SUCCESS;
     580static DECLCALLBACK(void) vboxNetFltPortDisconnectInterface(PINTNETTRUNKIFPORT pIfPort, INTNETIFHANDLE hIf)
     581{
     582    PVBOXNETFLTINS  pThis = IFPORT_2_VBOXNETFLTINS(pIfPort);
     583    int             rc;
    584584
    585585    /*
     
    592592    rc = vboxNetFltPortOsDisconnectInterface(pThis, hIf);
    593593    vboxNetFltRelease(pThis, false /* fBusy */);
    594 
    595     return rc;
     594    AssertRC(rc); /** @todo fix vboxNetFltPortOsDisconnectInterface. */
    596595}
    597596
     
    998997    pNew->MyPort.pfnNotifyMacAddress    = vboxNetFltPortNotifyMacAddress;
    999998    pNew->MyPort.pfnConnectInterface    = vboxNetFltPortConnectInterface;
    1000     pNew->MyPort.pfnDisconnectInterface = vboxNetFltPortDisconnectInterface;   
     999    pNew->MyPort.pfnDisconnectInterface = vboxNetFltPortDisconnectInterface;
    10011000    pNew->MyPort.u32VersionEnd          = INTNETTRUNKIFPORT_VERSION;
    10021001    pNew->pSwitchPort                   = pSwitchPort;
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