VirtualBox

Changeset 35785 in vbox


Ignore:
Timestamp:
Jan 31, 2011 12:45:37 PM (14 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
69756
Message:

netadp: Re-create configured vboxnetX interfaces (#4213) on Linux

Location:
trunk/src
Files:
10 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/HostDrivers/VBoxNetAdp/VBoxNetAdp.c

    r33540 r35785  
    10771077}
    10781078
    1079 int vboxNetAdpCreate (PVBOXNETADP *ppNew)
     1079int vboxNetAdpCreate (PVBOXNETADP *ppNew, const char *pcszName)
    10801080{
    10811081    int rc;
     
    10911091            Log(("vboxNetAdpCreate: found empty slot: %d\n", i));
    10921092            vboxNetAdpComposeMACAddress(pThis, &Mac);
    1093             rc = vboxNetAdpOsCreate(pThis, &Mac);
     1093            rc = vboxNetAdpOsCreate(pThis, &Mac, pcszName);
    10941094            Log(("vboxNetAdpCreate: pThis=%p pThis->szName=%p\n", pThis, pThis->szName));
    10951095            if (RT_SUCCESS(rc))
     
    11431143    }
    11441144
    1145     /* Create vboxnet0 */
    1146     return vboxNetAdpCreate(&pVboxnet0);
     1145    return VINF_SUCCESS;
     1146    /* Create vboxnet0
     1147       return vboxNetAdpCreate(&pVboxnet0);*/
    11471148}
    11481149
  • trunk/src/VBox/HostDrivers/VBoxNetAdp/VBoxNetAdpInternal.h

    r28800 r35785  
    141141DECLHIDDEN(int) vboxNetAdpInit(void);
    142142DECLHIDDEN(void) vboxNetAdpShutdown(void);
    143 DECLHIDDEN(int) vboxNetAdpCreate (PVBOXNETADP *ppNew);
     143DECLHIDDEN(int) vboxNetAdpCreate (PVBOXNETADP *ppNew, const char *pcszName);
    144144DECLHIDDEN(int) vboxNetAdpDestroy(PVBOXNETADP pThis);
    145145DECLHIDDEN(PVBOXNETADP) vboxNetAdpFindByName(const char *pszName);
     
    177177 * @remarks Owns no locks.
    178178 */
    179 DECLHIDDEN(int) vboxNetAdpOsCreate(PVBOXNETADP pThis, PCRTMAC pMac);
     179DECLHIDDEN(int) vboxNetAdpOsCreate(PVBOXNETADP pThis, PCRTMAC pMac, const char *pcszName);
    180180
    181181
  • trunk/src/VBox/HostDrivers/VBoxNetAdp/darwin/VBoxNetAdp-darwin.cpp

    r30320 r35785  
    193193
    194194
    195 int vboxNetAdpOsCreate(PVBOXNETADP pThis, PCRTMAC pMACAddress)
    196 {
     195int vboxNetAdpOsCreate(PVBOXNETADP pThis, PCRTMAC pMACAddress, const char *pcszName)
     196{
     197    /* TODO: Use pcszName */
    197198    int rc;
    198199    struct ifnet_init_params Params;
  • trunk/src/VBox/HostDrivers/VBoxNetAdp/freebsd/VBoxNetAdp-freebsd.c

    r33540 r35785  
    255255}
    256256
    257 int vboxNetAdpOsCreate(PVBOXNETADP pThis, PCRTMAC pMac)
    258 {
     257int vboxNetAdpOsCreate(PVBOXNETADP pThis, PCRTMAC pMac, const char *pcszName)
     258{
     259    /* TODO: Use pcszName */
    259260    struct ifnet *ifp;
    260261
  • trunk/src/VBox/HostDrivers/VBoxNetAdp/linux/VBoxNetAdp-linux.c

    r33540 r35785  
    176176
    177177
    178 int vboxNetAdpOsCreate(PVBOXNETADP pThis, PCRTMAC pMACAddress)
     178int vboxNetAdpOsCreate(PVBOXNETADP pThis, PCRTMAC pMACAddress, const char *pcszName)
    179179{
    180180    int rc = VINF_SUCCESS;
     
    182182
    183183    /* No need for private data. */
    184     pNetDev = alloc_netdev(sizeof(VBOXNETADPPRIV), VBOXNETADP_LINUX_NAME, vboxNetAdpNetDevInit);
     184    pNetDev = alloc_netdev(sizeof(VBOXNETADPPRIV),
     185                           pcszName ? pcszName : VBOXNETADP_LINUX_NAME,
     186                           vboxNetAdpNetDevInit);
    185187    if (pNetDev)
    186188    {
     
    277279    PVBOXNETADP pAdp;
    278280    int rc;
     281    char *pszName = NULL;
    279282
    280283    Log(("VBoxNetAdpLinuxIOCtl: param len %#x; uCmd=%#x; add=%#x\n", _IOC_SIZE(uCmd), uCmd, VBOXNETADP_CTL_ADD));
     
    289292        case VBOXNETADP_CTL_ADD:
    290293            Log(("VBoxNetAdpLinuxIOCtl: _IOC_DIR(uCmd)=%#x; IOC_OUT=%#x\n", _IOC_DIR(uCmd), IOC_OUT));
    291             rc = vboxNetAdpCreate(&pAdp);
     294            if (RT_UNLIKELY(copy_from_user(&Req, (void *)ulArg, sizeof(Req))))
     295            {
     296                Log(("VBoxNetAdpLinuxIOCtl: copy_from_user(,%#lx,) failed; uCmd=%#x.\n", ulArg, uCmd));
     297                return -EFAULT;
     298            }
     299            Log(("VBoxNetAdpLinuxIOCtl: Add %s\n", Req.szName));
     300
     301            if (Req.szName[0])
     302            {
     303                pAdp = vboxNetAdpFindByName(Req.szName);
     304                if (pAdp)
     305                {
     306                    Log(("VBoxNetAdpLinuxIOCtl: '%s' already exists\n", Req.szName));
     307                    return -EINVAL;
     308                }
     309                pszName = Req.szName;
     310            }
     311            rc = vboxNetAdpCreate(&pAdp, pszName);
    292312            if (RT_FAILURE(rc))
    293313            {
  • trunk/src/VBox/Main/include/netif.h

    r35356 r35785  
    8787int NetIfEnableStaticIpConfigV6(VirtualBox *pVbox, HostNetworkInterface * pIf, IN_BSTR aOldIPV6Address, IN_BSTR aIPV6Address, ULONG aIPV6MaskPrefixLength);
    8888int NetIfEnableDynamicIpConfig(VirtualBox *pVbox, HostNetworkInterface * pIf);
    89 int NetIfCreateHostOnlyNetworkInterface (VirtualBox *pVbox, IHostNetworkInterface **aHostNetworkInterface, IProgress **aProgress);
     89int NetIfCreateHostOnlyNetworkInterface (VirtualBox *pVbox, IHostNetworkInterface **aHostNetworkInterface, IProgress **aProgress, const char *pcszName = NULL);
    9090int NetIfRemoveHostOnlyNetworkInterface (VirtualBox *pVbox, IN_GUID aId, IProgress **aProgress);
    9191int NetIfGetConfig(HostNetworkInterface * pIf, NETIFINFO *);
  • trunk/src/VBox/Main/src-server/HostImpl.cpp

    r35638 r35785  
    4141#if defined(RT_OS_LINUX) || defined(RT_OS_FREEBSD)
    4242# include <HostHardwareLinux.h>
     43#endif
     44
     45#if defined(RT_OS_LINUX)
     46# include <set>
    4347#endif
    4448
     
    362366    m->f3DAccelerationSupported = is3DAccelerationSupported();
    363367#endif /* VBOX_WITH_CROGL */
     368
     369#if defined (RT_OS_LINUX)
     370    /* Extract the list of configured host-only interfaces */
     371    std::set<Utf8Str> aConfiguredNames;
     372    SafeArray<BSTR> aGlobalExtraDataKeys;
     373    hrc = aParent->GetExtraDataKeys(ComSafeArrayAsOutParam(aGlobalExtraDataKeys));
     374    AssertMsg(SUCCEEDED(hrc), ("VirtualBox::GetExtraDataKeys failed with %Rhrc\n", hrc));
     375    for (size_t i = 0; i < aGlobalExtraDataKeys.size(); ++i)
     376    {
     377        Utf8Str strKey = aGlobalExtraDataKeys[i];
     378
     379        if (!strKey.startsWith("HostOnly/vboxnet"))
     380            continue;
     381
     382        size_t pos = strKey.find("/", sizeof("HostOnly/vboxnet"));
     383        if (pos != Utf8Str::npos)
     384            aConfiguredNames.insert(strKey.substr(sizeof("HostOnly"),
     385                                                  pos - sizeof("HostOnly")));
     386    }
     387
     388    for (std::set<Utf8Str>::const_iterator it = aConfiguredNames.begin();
     389         it != aConfiguredNames.end();
     390         ++it)
     391    {
     392        ComPtr<IHostNetworkInterface> hif;
     393        ComPtr<IProgress> progress;
     394
     395        int r = NetIfCreateHostOnlyNetworkInterface(m->pParent,
     396                                                    hif.asOutParam(),
     397                                                    progress.asOutParam(),
     398                                                    it->c_str());
     399        if (RT_FAILURE(r))
     400            return E_FAIL;
     401    }
     402
     403#endif /* defined (RT_OS_LINUX) */
    364404
    365405    /* Confirm a successful initialization */
     
    10821122     * violations with the called functions. */
    10831123
     1124    Bstr name;
     1125    HRESULT rc;
     1126
    10841127    /* first check whether an interface with the given name already exists */
    10851128    {
     
    10901133                            tr("Host network interface with UUID {%RTuuid} does not exist"),
    10911134                            Guid (aId).raw());
     1135        rc = iface->COMGETTER(Name)(name.asOutParam());
     1136        ComAssertComRCRet(rc, rc);
    10921137    }
    10931138
    10941139    int r = NetIfRemoveHostOnlyNetworkInterface(m->pParent, Guid(aId).ref(), aProgress);
    10951140    if (RT_SUCCESS(r))
     1141    {
     1142        /* Drop configuration parameters for removed interface */
     1143        rc = m->pParent->SetExtraData(BstrFmt("HostOnly/%ls/IPAddress", name.raw()).raw(), NULL);
     1144        rc = m->pParent->SetExtraData(BstrFmt("HostOnly/%ls/IPNetMask", name.raw()).raw(), NULL);
     1145        rc = m->pParent->SetExtraData(BstrFmt("HostOnly/%ls/IPV6Address", name.raw()).raw(), NULL);
     1146        rc = m->pParent->SetExtraData(BstrFmt("HostOnly/%ls/IPV6NetMask", name.raw()).raw(), NULL);
     1147
    10961148        return S_OK;
     1149    }
    10971150
    10981151    return r == VERR_NOT_IMPLEMENTED ? E_NOTIMPL : E_FAIL;
  • trunk/src/VBox/Main/src-server/generic/NetIf-generic.cpp

    r32718 r35785  
    127127
    128128
    129 int NetIfCreateHostOnlyNetworkInterface(VirtualBox *pVBox, IHostNetworkInterface **aHostNetworkInterface, IProgress **aProgress)
     129int NetIfCreateHostOnlyNetworkInterface(VirtualBox *pVBox,
     130                                        IHostNetworkInterface **aHostNetworkInterface,
     131                                        IProgress **aProgress,
     132                                        const char *pcszName)
    130133{
    131134#if defined(RT_OS_LINUX) || defined(RT_OS_DARWIN) || defined(RT_OS_FREEBSD)
     
    155158                return rc;
    156159            }
    157             strcat(szAdpCtl, "/" VBOXNETADPCTL_NAME " add");
     160            strcat(szAdpCtl, "/" VBOXNETADPCTL_NAME " ");
     161            if (pcszName && strlen(pcszName) <= RTPATH_MAX - strlen(szAdpCtl) - sizeof(" add"))
     162            {
     163                strcat(szAdpCtl, pcszName);
     164                strcat(szAdpCtl, " add");
     165            }
     166            else
     167                strcat(szAdpCtl, "add");
    158168            FILE *fp = popen(szAdpCtl, "r");
    159169
  • trunk/src/VBox/Main/src-server/win/NetIf-win.cpp

    r35368 r35785  
    10851085int NetIfCreateHostOnlyNetworkInterface(VirtualBox *pVBox,
    10861086                                        IHostNetworkInterface **aHostNetworkInterface,
    1087                                         IProgress **aProgress)
     1087                                        IProgress **aProgress,
     1088                                        const char *pcszName)
    10881089{
    10891090#ifndef VBOX_WITH_NETFLT
  • trunk/src/apps/adpctl/VBoxNetAdpCtl.cpp

    r28800 r35785  
    6666{
    6767    fprintf(stderr, "Usage: VBoxNetAdpCtl <adapter> <address> ([netmask <address>] | remove)\n");
    68     fprintf(stderr, "     | VBoxNetAdpCtl add\n");
     68    fprintf(stderr, "     | VBoxNetAdpCtl [<adapter>] add\n");
    6969    fprintf(stderr, "     | VBoxNetAdpCtl <adapter> remove\n");
    7070}
     
    268268        case 3:
    269269        {
    270             /* Remove an existing interface */
    271270            pszAdapterName = argv[1];
     271            memset(&Req, '\0', sizeof(Req));
     272            rc = checkAdapterName(pszAdapterName, szAdapterName);
     273            if (rc)
     274                return rc;
     275            snprintf(Req.szName, sizeof(Req.szName), "%s", szAdapterName);
    272276            pszAddress = argv[2];
    273277            if (strcmp("remove", pszAddress) == 0)
    274278            {
    275                 rc = checkAdapterName(pszAdapterName, szAdapterName);
    276                 if (rc)
    277                     return rc;
    278 #ifdef RT_OS_SOLARIS
    279                 return 1;
    280 #else
    281                 memset(&Req, '\0', sizeof(Req));
    282                 snprintf(Req.szName, sizeof(Req.szName), "%s", szAdapterName);
     279                /* Remove an existing interface */
     280#ifdef RT_OS_SOLARIS
     281                return 1;
     282#else
    283283                return doIOCtl(VBOXNETADP_CTL_REMOVE, &Req);
    284284#endif
     285            }
     286            else if (strcmp("add", pszAddress) == 0)
     287            {
     288                /* Create an interface with given name */
     289#ifdef RT_OS_SOLARIS
     290                return 1;
     291#else
     292                rc = doIOCtl(VBOXNETADP_CTL_ADD, &Req);
     293                if (rc == 0)
     294                    puts(Req.szName);
     295#endif
     296                return rc;
    285297            }
    286298            break;
Note: See TracChangeset for help on using the changeset viewer.

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette