VirtualBox

Changeset 20521 in vbox for trunk/src/VBox/Devices


Ignore:
Timestamp:
Jun 12, 2009 3:28:26 PM (16 years ago)
Author:
vboxsync
Message:

NetworkAttachment: Allow changing the attachment between NONE/NAT/HIF/host-only/.. dynamically #3573

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

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Devices/Makefile.kmk

    r20501 r20521  
    286286        Serial/DevSerial.cpp \
    287287        Parallel/DevParallel.cpp
     288
     289ifdef VBOX_DYNAMIC_NET_ATTACH
     290 DevicesR3_DEFS += VBOX_DYNAMIC_NET_ATTACH
     291endif
    288292
    289293ifdef VBOX_WITH_E1000
     
    466470        Parallel/DevParallel.cpp
    467471
     472ifdef VBOX_DYNAMIC_NET_ATTACH
     473 VBoxDDGC_DEFS += VBOX_DYNAMIC_NET_ATTACH
     474endif
     475
    468476ifdef VBOX_WITH_E1000
    469477 VBoxDDGC_DEFS         += VBOX_WITH_E1000
     
    548556        Serial/DevSerial.cpp \
    549557        Parallel/DevParallel.cpp
     558
     559ifdef VBOX_DYNAMIC_NET_ATTACH
     560 VBoxDDR0_DEFS += VBOX_DYNAMIC_NET_ATTACH
     561endif
    550562
    551563ifdef VBOX_WITH_E1000
  • trunk/src/VBox/Devices/Network/DevPCNet.cpp

    r20374 r20521  
    46514651
    46524652
     4653#ifdef VBOX_DYNAMIC_NET_ATTACH
     4654/**
     4655 * Detach notification.
     4656 *
     4657 * One network card at one port has been unplugged.
     4658 * The VM is suspended at this point.
     4659 *
     4660 * @param   pDevIns     The device instance.
     4661 * @param   iLUN        The logical unit which is being detached.
     4662 */
     4663static DECLCALLBACK(void) pcnetDetach(PPDMDEVINS pDevIns, unsigned iLUN)
     4664{
     4665    PCNetState *pThis = PDMINS_2_DATA(pDevIns, PCNetState *);
     4666
     4667    Log(("%s:\n", __FUNCTION__));
     4668
     4669    int rc = PDMCritSectEnter(&pThis->CritSect, VERR_SEM_BUSY);
     4670    AssertReleaseRC(rc);
     4671
     4672    /* @todo: r=pritesh still need to check if i missed
     4673     * to clean something in this function
     4674     */
     4675
     4676    /*
     4677     * Zero some important members.
     4678     */
     4679    pThis->pDrvBase = NULL;
     4680    pThis->pDrv = NULL;
     4681
     4682    PDMCritSectLeave(&pThis->CritSect);
     4683}
     4684
     4685
     4686/**
     4687 * Attach the Network attachment.
     4688 *
     4689 * @returns VBox status code.
     4690 * @param   pDevIns     The device instance.
     4691 * @param   iLUN        The logical unit which is being detached.
     4692 */
     4693static DECLCALLBACK(int)  pcnetAttach(PPDMDEVINS pDevIns, unsigned iLUN)
     4694{
     4695    PCNetState *pThis = PDMINS_2_DATA(pDevIns, PCNetState *);
     4696    int         rc    = VINF_SUCCESS;
     4697
     4698    Log(("%s:\n", __FUNCTION__));
     4699
     4700    rc = PDMCritSectEnter(&pThis->CritSect, VERR_SEM_BUSY);
     4701    AssertReleaseRC(rc);
     4702
     4703    rc = PDMDevHlpDriverAttach(pDevIns, 0, &pThis->IBase, &pThis->pDrvBase, "Network Port");
     4704    if (RT_SUCCESS(rc))
     4705    {
     4706        if (rc == VINF_NAT_DNS)
     4707        {
     4708#ifdef RT_OS_LINUX
     4709            PDMDevHlpVMSetRuntimeError(pDevIns, 0 /*fFlags*/, "NoDNSforNAT",
     4710                                       N_("A Domain Name Server (DNS) for NAT networking could not be determined. Please check your /etc/resolv.conf for <tt>nameserver</tt> entries. Either add one manually (<i>man resolv.conf</i>) or ensure that your host is correctly connected to an ISP. If you ignore this warning the guest will not be able to perform nameserver lookups and it will probably observe delays if trying so"));
     4711#else
     4712            PDMDevHlpVMSetRuntimeError(pDevIns, 0 /*fFlags*/, "NoDNSforNAT",
     4713                                       N_("A Domain Name Server (DNS) for NAT networking could not be determined. Ensure that your host is correctly connected to an ISP. If you ignore this warning the guest will not be able to perform nameserver lookups and it will probably observe delays if trying so"));
     4714#endif
     4715        }
     4716        pThis->pDrv = (PPDMINETWORKCONNECTOR)
     4717            pThis->pDrvBase->pfnQueryInterface(pThis->pDrvBase, PDMINTERFACE_NETWORK_CONNECTOR);
     4718        if (!pThis->pDrv)
     4719        {
     4720            AssertMsgFailed(("Failed to obtain the PDMINTERFACE_NETWORK_CONNECTOR interface!\n"));
     4721            return VERR_PDM_MISSING_INTERFACE_BELOW;
     4722        }
     4723    }
     4724    else if (rc == VERR_PDM_NO_ATTACHED_DRIVER)
     4725        Log(("No attached driver!\n"));
     4726    else
     4727        return rc;
     4728
     4729    /*
     4730     * Temporary set the link down if it was up so that the guest
     4731     * will know that we have change the configuration of the
     4732     * network card
     4733     */
     4734    if (pThis->fLinkUp)
     4735    {
     4736        pThis->fLinkTempDown = true;
     4737        pThis->cLinkDownReported = 0;
     4738        pThis->aCSR[0] |= RT_BIT(15) | RT_BIT(13); /* ERR | CERR (this is probably wrong) */
     4739        pThis->Led.Asserted.s.fError = pThis->Led.Actual.s.fError = 1;
     4740        TMTimerSetMillies(pThis->pTimerRestore, 20000);
     4741    }
     4742    PDMCritSectLeave(&pThis->CritSect);
     4743
     4744    return rc;
     4745
     4746}
     4747#endif /* VBOX_DYNAMIC_NET_ATTACH */
     4748
     4749
    46534750/**
    46544751 * @copydoc FNPDMDEVSUSPEND
     
    51635260    /* pfnResume */
    51645261    NULL,
     5262#ifdef VBOX_DYNAMIC_NET_ATTACH
     5263    /* pfnAttach */
     5264    pcnetAttach,
     5265    /* pfnDetach */
     5266    pcnetDetach,
     5267#else /* !VBOX_DYNAMIC_NET_ATTACH */
    51655268    /* pfnAttach */
    51665269    NULL,
    51675270    /* pfnDetach */
    51685271    NULL,
     5272#endif /* !VBOX_DYNAMIC_NET_ATTACH */
    51695273    /* pfnQueryInterface. */
    51705274    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