VirtualBox

Changeset 22375 in vbox


Ignore:
Timestamp:
Aug 20, 2009 1:42:49 PM (15 years ago)
Author:
vboxsync
Message:

NetSniffer: do not erase the dump file even if network attachment is changed

Location:
trunk/src/VBox
Files:
4 edited

Legend:

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

    r22277 r22375  
    277277
    278278/**
     279 * Detach a driver instance.
     280 *
     281 * @param   pDrvIns     The driver instance.
     282 * @param   fFlags      Flags, combination of the PDM_TACH_FLAGS_* \#defines.
     283 */
     284static DECLCALLBACK(void) drvNetSnifferDetach(PPDMDRVINS pDrvIns, uint32_t fFlags)
     285{
     286    PDRVNETSNIFFER pThis = PDMINS_2_DATA(pDrvIns, PDRVNETSNIFFER);
     287
     288    LogFlow(("drvNetSnifferDetach: pDrvIns: %p, fFlags: %u\n", pDrvIns, fFlags));
     289
     290    pThis->pConnector = NULL;
     291    pThis->pPort      = NULL;
     292    pThis->pConfig    = NULL;
     293}
     294
     295
     296/**
     297 * Attach a driver instance.
     298 *
     299 * @returns VBox status code.
     300 * @param   pDrvIns     The driver instance.
     301 * @param   fFlags      Flags, combination of the PDM_TACH_FLAGS_* \#defines.
     302 */
     303static DECLCALLBACK(int) drvNetSnifferAttach(PPDMDRVINS pDrvIns, uint32_t fFlags)
     304{
     305    PDRVNETSNIFFER pThis = PDMINS_2_DATA(pDrvIns, PDRVNETSNIFFER);
     306
     307    LogFlow(("drvNetSnifferAttach: pDrvIns: %p, fFlags: %u\n", pDrvIns, fFlags));
     308
     309    /*
     310     * Query the network port interface.
     311     */
     312    pThis->pPort = (PPDMINETWORKPORT)pDrvIns->pUpBase->pfnQueryInterface(pDrvIns->pUpBase, PDMINTERFACE_NETWORK_PORT);
     313    if (!pThis->pPort)
     314    {
     315        AssertMsgFailed(("Configuration error: the above device/driver didn't export the network port interface!\n"));
     316        return VERR_PDM_MISSING_INTERFACE_ABOVE;
     317    }
     318
     319    /*
     320     * Query the network config interface.
     321     */
     322    pThis->pConfig = (PPDMINETWORKCONFIG)pDrvIns->pUpBase->pfnQueryInterface(pDrvIns->pUpBase, PDMINTERFACE_NETWORK_CONFIG);
     323    if (!pThis->pConfig)
     324    {
     325        AssertMsgFailed(("Configuration error: the above device/driver didn't export the network config interface!\n"));
     326        return VERR_PDM_MISSING_INTERFACE_ABOVE;
     327    }
     328
     329    /*
     330     * Query the network connector interface.
     331     */
     332    PPDMIBASE   pBaseDown;
     333    int rc = PDMDrvHlpAttach(pDrvIns, fFlags, &pBaseDown);
     334    if (rc == VERR_PDM_NO_ATTACHED_DRIVER)
     335        pThis->pConnector = NULL;
     336    else if (RT_SUCCESS(rc))
     337    {
     338        pThis->pConnector = (PPDMINETWORKCONNECTOR)pBaseDown->pfnQueryInterface(pBaseDown, PDMINTERFACE_NETWORK_CONNECTOR);
     339        if (!pThis->pConnector)
     340        {
     341            AssertMsgFailed(("Configuration error: the driver below didn't export the network connector interface!\n"));
     342            return VERR_PDM_MISSING_INTERFACE_BELOW;
     343        }
     344    }
     345    else
     346    {
     347        AssertMsgFailed(("Failed to attach to driver below! rc=%Rrc\n", rc));
     348        return rc;
     349    }
     350
     351    return VINF_SUCCESS;
     352}
     353
     354
     355/**
    279356 * Destruct a driver instance.
    280357 *
     
    454531    NULL,
    455532    /* pfnAttach */
    456     NULL,
     533    drvNetSnifferAttach,
    457534    /* pfnDetach */
    458     NULL,
     535    drvNetSnifferDetach,
    459536    /* pfnPowerOff */
    460     NULL, 
     537    NULL,
    461538    /* pfnSoftReset */
    462539    NULL,
  • trunk/src/VBox/Main/ConsoleImpl.cpp

    r22338 r22375  
    32903290
    32913291    /* Get the properties we need from the adapter */
    3292     BOOL fCableConnected;
     3292    BOOL fCableConnected, fTraceEnabled;
    32933293    HRESULT rc = aNetworkAdapter->COMGETTER(CableConnected) (&fCableConnected);
    32943294    AssertComRC(rc);
     3295    if (SUCCEEDED(rc))
     3296    {
     3297        rc = aNetworkAdapter->COMGETTER(TraceEnabled) (&fTraceEnabled);
     3298        AssertComRC(rc);
     3299    }
    32953300    if (SUCCEEDED(rc))
    32963301    {
     
    33363341                    ComAssertRC(vrc);
    33373342                }
     3343#ifdef VBOX_DYNAMIC_NET_ATTACH
     3344                if (RT_SUCCESS(vrc) && changeAdapter)
     3345                {
     3346                    VMSTATE enmVMState = VMR3GetState(mpVM);
     3347
     3348                    if (   enmVMState == VMSTATE_RUNNING
     3349                        || enmVMState == VMSTATE_SUSPENDED)
     3350                    {
     3351                        if (fTraceEnabled && fCableConnected && pINetCfg)
     3352                        {
     3353                            vrc = pINetCfg->pfnSetLinkState (pINetCfg, PDMNETWORKLINKSTATE_DOWN);
     3354                            ComAssertRC(vrc);
     3355                        }
     3356
     3357                        rc = doNetworkAdapterChange(pszAdapterName, ulInstance, 0, aNetworkAdapter);
     3358
     3359                        if (fTraceEnabled && fCableConnected && pINetCfg)
     3360                        {
     3361                            vrc = pINetCfg->pfnSetLinkState (pINetCfg, PDMNETWORKLINKSTATE_UP);
     3362                            ComAssertRC(vrc);
     3363                        }
     3364                    }
     3365                }
     3366#endif /* VBOX_DYNAMIC_NET_ATTACH */
    33383367            }
    3339 
    3340 #ifdef VBOX_DYNAMIC_NET_ATTACH
    3341             if (RT_SUCCESS(vrc) && changeAdapter)
    3342             {
    3343                 VMSTATE enmVMState = VMR3GetState(mpVM);
    3344                 if (   enmVMState == VMSTATE_RUNNING
    3345                     || enmVMState == VMSTATE_SUSPENDED)
    3346                     rc = doNetworkAdapterChange(pszAdapterName, ulInstance, 0, aNetworkAdapter);
    3347             }
    3348 #endif /* VBOX_DYNAMIC_NET_ATTACH */
    33493368
    33503369            if (VBOX_FAILURE (vrc))
     
    76247643};
    76257644
     7645/**
     7646 * Initializing the attachment type for the network adapters
     7647 */
     7648NetworkAttachmentType_T Console::meAttachmentType[] = {};
     7649
    76267650/* vi: set tabstop=4 shiftwidth=4 expandtab: */
  • trunk/src/VBox/Main/ConsoleImpl2.cpp

    r22345 r22375  
    21172117    H();
    21182118
    2119     /*
    2120      * Detach the device train for the current network attachment.
    2121      */
    2122     if (fAttachDetach)
     2119    BOOL fSniffer;
     2120    hrc = aNetworkAdapter->COMGETTER(TraceEnabled)(&fSniffer);
     2121    H();
     2122
     2123    if (fAttachDetach && fSniffer)
     2124    {
     2125        const char *pszNetDriver = "IntNet";
     2126        if (meAttachmentType[uInstance] == NetworkAttachmentType_NAT)
     2127            pszNetDriver = "NAT";
     2128#if !defined(VBOX_WITH_NETFLT) && defined(RT_OS_LINUX)
     2129        if (meAttachmentType[uInstance] == NetworkAttachmentType_Bridged)
     2130            pszNetDriver = "HostInterface";
     2131#endif
     2132
     2133        rc = PDMR3DriverDetach(pVM, pszDevice, uInstance, uLun, pszNetDriver, 0, 0 /*fFlags*/);
     2134        if (rc == VINF_PDM_NO_DRIVER_ATTACHED_TO_LUN)
     2135            rc = VINF_SUCCESS;
     2136        AssertLogRelRCReturn(rc, rc);
     2137
     2138        pLunL0 = CFGMR3GetChildF(pInst, "LUN#%u", uLun);
     2139        CFGMR3RemoveNode(CFGMR3GetChildF(pLunL0, "AttachedDriver"));
     2140    }
     2141    else if (fAttachDetach && !fSniffer)
    21232142    {
    21242143        rc = PDMR3DeviceDetach(pVM, pszDevice, uInstance, uLun, 0 /*fFlags*/);
     
    21302149        CFGMR3RemoveNode(CFGMR3GetChildF(pInst, "LUN#%u", uLun));
    21312150    }
    2132 
    2133     /*
    2134      * Enable the packet sniffer if requested.
    2135      */
    2136     BOOL fSniffer;
    2137     hrc = aNetworkAdapter->COMGETTER(TraceEnabled)(&fSniffer);
    2138     H();
    2139     if (fSniffer)
     2151    else if (!fAttachDetach && fSniffer)
    21402152    {
    21412153        /* insert the sniffer filter driver. */
     
    27702782                if (fAttachDetach)
    27712783                {
    2772                     rc = PDMR3DeviceAttach(pVM, pszDevice, uInstance, uLun, 0 /*fFlags*/, NULL /*ppBase*/);
     2784                    rc = PDMR3DriverAttach(pVM, pszDevice, uInstance, uLun, 0 /*fFlags*/, NULL /* ppBase */);
    27732785                    AssertRC(rc);
    27742786                }
     
    28182830    }
    28192831
     2832    meAttachmentType[uInstance] = eAttachmentType;
     2833
    28202834#undef STR_FREE
    28212835#undef H
  • trunk/src/VBox/Main/include/ConsoleImpl.h

    r22338 r22375  
    557557    DriveState_T meFloppyState;
    558558
     559    /** The current network attachment type in the VM.
     560     * This doesn't have to match the network attachment type
     561     * maintained in the NetworkAdapter. This is needed to
     562     * change the network attachment dynamically.
     563     */
     564    static NetworkAttachmentType_T meAttachmentType[SchemaDefs::NetworkAdapterCount];
     565
    559566    VMMDev * const mVMMDev;
    560567    AudioSniffer * const mAudioSniffer;
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