VirtualBox

Changeset 91438 in vbox for trunk/src


Ignore:
Timestamp:
Sep 28, 2021 5:01:52 PM (3 years ago)
Author:
vboxsync
Message:

Devices: bugref:9932 Suspend/resume support, limit VMNET compilation to darwin

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Devices/Network/DrvVMNet.m

    r91418 r91438  
    6363*   Structures and Typedefs                                                                                                      *
    6464*********************************************************************************************************************************/
     65/**
     66 * VMNET driver states.
     67 */
     68 typedef enum VMNETSTATE
     69{
     70    /** The driver is suspended. */
     71    VMNETSTATE_SUSPENDED = 1,
     72    /** The driver is running. */
     73    VMNETSTATE_RUNNING,
     74    /** The usual 32-bit type blowup. */
     75    VMNETSTATE_32BIT_HACK = 0x7fffffff
     76} VMNETSTATE;
     77 
    6578/**
    6679 * VMNET driver instance data.
     
    89102    /** The operation mode: bridged or host. */
    90103    uint32_t                uMode;
     104    /** The operational state: suspended or running. */
     105    VMNETSTATE volatile     enmState;
    91106    /** The host interface name for bridge mode. */
    92107    char                    szHostInterface[VMNET_MAX_HOST_INTERFACE_NAME_LENGTH];
     
    180195static int drvVMNetReceive(PDRVVMNET pThis, const uint8_t *pbFrame, uint32_t cbFrame)
    181196{
     197    if (pThis->enmState != VMNETSTATE_RUNNING)
     198    {
     199        Log(("drvVMNetReceive: Ignoring incoming packet (%d bytes) in suspended state\n", cbFrame));
     200        return VINF_SUCCESS;
     201    }
     202
    182203    Log(("drvVMNetReceive: Incoming packet: %RTmac <= %RTmac (%d bytes)\n", pbFrame, pbFrame + 6, cbFrame));
    183204    Log2(("%.*Rhxd\n", cbFrame, pbFrame));
     
    190211static int drvVMNetSend(PDRVVMNET pThis, const uint8_t *pbFrame, uint32_t cbFrame)
    191212{
     213    if (pThis->enmState != VMNETSTATE_RUNNING)
     214    {
     215        Log(("drvVMNetReceive: Ignoring outgoing packet (%d bytes) in suspended state\n", cbFrame));
     216        return VINF_SUCCESS;
     217    }
     218
    192219    Log(("drvVMNetSend: Outgoing packet (%d bytes)\n", cbFrame));
    193220    Log2(("%.*Rhxd\n", cbFrame, pbFrame));
     
    346373                Log(("drvVMNetAttachBridged: Failed to convert '%s' to MAC address (%Rrc)\n", pcszMacAddress ? pcszMacAddress : "(null)", rc));
    347374#endif
     375#ifdef LOG_ENABLED
    348376            max_packet_size = xpc_dictionary_get_uint64(interface_param, vmnet_max_packet_size_key);
    349377            // Log(("MAC address: %s\n", xpc_dictionary_get_string(interface_param, vmnet_mac_address_key)));
     
    352380            Log(("Avaliable keys:\n"));
    353381            xpc_dictionary_apply(interface_param, ^bool(const char * _Nonnull key, xpc_object_t  _Nonnull value) {
    354                 Log(("%s=%s\n", key, value));
     382                RT_NOREF(value);
     383                Log(("%s\n", key));
    355384                return true;
    356385            });
     386#endif /* LOG_ENABLED */
    357387        }
    358388        dispatch_semaphore_signal(operation_done);
     
    408438{
    409439    if (pThis->Interface)
     440    {
    410441        vmnet_stop_interface(pThis->Interface, pThis->InterfaceQueue, ^(vmnet_return_t status){
    411442            Log(("VMNET interface has been stopped. Status = %d.\n", status));
    412443        });
     444        pThis->Interface = 0;
     445    }
    413446    if (pThis->InterfaceQueue)
     447    {
    414448        dispatch_release(pThis->InterfaceQueue);
     449        pThis->InterfaceQueue = 0;
     450    }
    415451
    416452    return 0;
     
    458494    pThis->INetworkUp.pfnSetPromiscuousMode         = drvVMNetUp_SetPromiscuousMode;
    459495    pThis->INetworkUp.pfnNotifyLinkChanged          = drvVMNetUp_NotifyLinkChanged;
     496
     497    /* Initialize the state. */
     498    pThis->enmState = VMNETSTATE_SUSPENDED;
    460499
    461500    /*
     
    588627
    589628    return VINF_SUCCESS;
     629}
     630
     631
     632/**
     633 * Power On notification.
     634 *
     635 * @param   pDrvIns     The driver instance.
     636 */
     637static DECLCALLBACK(void) drvVMNetPowerOn(PPDMDRVINS pDrvIns)
     638{
     639    LogFlow(("drvVMNetPowerOn\n"));
     640    PDRVVMNET pThis = PDMINS_2_DATA(pDrvIns, PDRVVMNET);
     641    ASMAtomicXchgSize(&pThis->enmState, VMNETSTATE_RUNNING);
     642}
     643
     644
     645/**
     646 * Suspend notification.
     647 *
     648 * @param   pDrvIns     The driver instance.
     649 */
     650static DECLCALLBACK(void) drvVMNetSuspend(PPDMDRVINS pDrvIns)
     651{
     652    LogFlow(("drvVMNetSuspend\n"));
     653    PDRVVMNET pThis = PDMINS_2_DATA(pDrvIns, PDRVVMNET);
     654    ASMAtomicXchgSize(&pThis->enmState, VMNETSTATE_SUSPENDED);
     655}
     656
     657
     658/**
     659 * Resume notification.
     660 *
     661 * @param   pDrvIns     The driver instance.
     662 */
     663static DECLCALLBACK(void) drvVMNetResume(PPDMDRVINS pDrvIns)
     664{
     665    LogFlow(("drvVMNetResume\n"));
     666    PDRVVMNET pThis = PDMINS_2_DATA(pDrvIns, PDRVVMNET);
     667    ASMAtomicXchgSize(&pThis->enmState, VMNETSTATE_RUNNING);
    590668}
    591669
     
    624702    NULL,
    625703    /* pfnPowerOn */
    626     NULL,
     704    drvVMNetPowerOn,
    627705    /* pfnReset */
    628706    NULL,
    629707    /* pfnSuspend */
    630     NULL,
     708    drvVMNetSuspend,
    631709    /* pfnResume */
    632     NULL,
     710    drvVMNetResume,
    633711    /* pfnAttach */
    634712    NULL,
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