VirtualBox

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


Ignore:
Timestamp:
Jul 11, 2008 2:46:47 PM (17 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
33215
Message:

Implemented trunk and flag matching when opening a network.

File:
1 edited

Legend:

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

    r10524 r10530  
    8383    void                   *pvObj;
    8484} INTNETIF;
     85/** Pointer to an internal network interface. */
    8586typedef INTNETIF *PINTNETIF;
    8687
     
    103104    /** The SUPR0 object id. */
    104105    void                   *pvObj;
    105     /**  Access restricted? */
    106     bool                    fRestrictAccess;
     106    /** Network creation flags (INTNET_OPEN_FLAGS_*). */
     107    uint32_t                fFlags;
    107108    /** The length of the network name. */
    108109    uint8_t                 cchName;
    109110    /** The network name. */
    110111    char                    szName[INTNET_MAX_NETWORK_NAME];
     112    /** The trunk type. */
     113    INTNETTRUNKTYPE         enmTrunkType;
     114    /** The trunk name. */
     115    char                    szTrunk[INTNET_MAX_TRUNK_NAME];
    111116} INTNETNETWORK;
     117/** Pointer to an internal network. */
    112118typedef INTNETNETWORK *PINTNETNETWORK;
    113119
     
    12721278 *
    12731279 * @returns VBox status code.
    1274  * @param   pIntNet     The instance data.
    1275  * @param   pSession    The current session.
    1276  * @param   pszNetwork  The network name. This has a valid length.
    1277  * @param   ppNetwork   Where to store the pointer to the network on success.
    1278  */
    1279 static int intnetOpenNetwork(PINTNET pIntNet, PSUPDRVSESSION pSession, const char *pszNetwork, PINTNETNETWORK *ppNetwork)
    1280 {
    1281     LogFlow(("intnetOpenNetwork: pIntNet=%p pSession=%p pszNetwork=%p:{%s} ppNetwork=%p\n",
    1282              pIntNet, pSession, pszNetwork, pszNetwork, ppNetwork));
    1283 
     1280 * @param   pIntNet         The instance data.
     1281 * @param   pSession        The current session.
     1282 * @param   pszNetwork      The network name. This has a valid length.
     1283 * @param   enmTrunkType    The trunk type.
     1284 * @param   pszTrunk        The trunk name. Its meaning is specfic to the type.
     1285 * @param   fFlags          Flags, see INTNET_OPEN_FLAGS_*.
     1286 * @param   ppNetwork       Where to store the pointer to the network on success.
     1287 */
     1288static int intnetOpenNetwork(PINTNET pIntNet, PSUPDRVSESSION pSession, const char *pszNetwork, INTNETTRUNKTYPE enmTrunkType,
     1289                             const char *pszTrunk, uint32_t fFlags, PINTNETNETWORK *ppNetwork)
     1290{
     1291    LogFlow(("intnetOpenNetwork: pIntNet=%p pSession=%p pszNetwork=%p:{%s} enmTrunkType=%d pszTrunk=%p:{%s} fFlags=%#x ppNetwork=%p\n",
     1292             pIntNet, pSession, pszNetwork, pszNetwork, enmTrunkType, pszTrunk, pszTrunk, fFlags, ppNetwork));
     1293
     1294    /* just pro forma validation, the caller is internal. */
    12841295    AssertPtr(pIntNet);
    12851296    AssertPtr(pSession);
    12861297    AssertPtr(pszNetwork);
     1298    Assert(enmTrunkType > kIntNetTrunkType_Invalid && enmTrunkType < kIntNetTrunkType_End);
     1299    AssertPtr(pszTrunk);
     1300    Assert(!(fFlags & ~(INTNET_OPEN_FLAGS_PUBLIC)));
    12871301    AssertPtr(ppNetwork);
    12881302    *ppNetwork = NULL;
     
    13041318        {
    13051319            /*
    1306              * Increment the reference and check that the
    1307              * session can access this network.
     1320             * Found the network, now check that we have the same ideas
     1321             * about the trunk setup and security.
    13081322             */
    1309             int rc = SUPR0ObjAddRef(pCur->pvObj, pSession);
    1310             RTSpinlockRelease(pIntNet->Spinlock, &Tmp);
    1311 
    1312             if (VBOX_SUCCESS(rc))
     1323            int rc;
     1324            if (    enmTrunkType == kIntNetTrunkType_WhateverNone
     1325                ||  (   pCur->enmTrunkType == enmTrunkType
     1326                     && !strcmp(pCur->szTrunk, pszTrunk)))
    13131327            {
    1314                 if (pCur->fRestrictAccess)
    1315                     rc = SUPR0ObjVerifyAccess(pCur->pvObj, pSession, pCur->szName);
    1316                 if (VBOX_SUCCESS(rc))
    1317                     *ppNetwork = pCur;
     1328                if (!((pCur->fFlags ^ fFlags) & (INTNET_OPEN_FLAGS_PUBLIC)))
     1329                {
     1330                    /*
     1331                     * Increment the reference and check that the
     1332                     * session can access this network.
     1333                     */
     1334                    rc = SUPR0ObjAddRef(pCur->pvObj, pSession);
     1335                    RTSpinlockRelease(pIntNet->Spinlock, &Tmp);
     1336
     1337                    if (VBOX_SUCCESS(rc))
     1338                    {
     1339                        if (!(pCur->fFlags & INTNET_OPEN_FLAGS_PUBLIC))
     1340                            rc = SUPR0ObjVerifyAccess(pCur->pvObj, pSession, pCur->szName);
     1341                        if (VBOX_SUCCESS(rc))
     1342                            *ppNetwork = pCur;
     1343                        else
     1344                        {
     1345                            RTSpinlockAcquire(pIntNet->Spinlock, &Tmp);
     1346                            SUPR0ObjRelease(pCur->pvObj, pSession);
     1347                            RTSpinlockRelease(pIntNet->Spinlock, &Tmp);
     1348                        }
     1349                    }
     1350                }
    13181351                else
    1319                 {
    1320                     RTSpinlockAcquire(pIntNet->Spinlock, &Tmp);
    1321                     SUPR0ObjRelease(pCur->pvObj, pSession);
    1322                     RTSpinlockRelease(pIntNet->Spinlock, &Tmp);
    1323                 }
     1352                    rc = VERR_INTNET_INCOMPATIBLE_FLAGS;
    13241353            }
     1354            else
     1355                rc = VERR_INTNET_INCOMPATIBLE_TRUNK;
     1356
    13251357            LogFlow(("intnetOpenNetwork: returns %Vrc *ppNetwork=%p\n", rc, *ppNetwork));
    13261358            return rc;
     
    13301362    RTSpinlockRelease(pIntNet->Spinlock, &Tmp);
    13311363
    1332     LogFlow(("intnetOpenNetwork: returns VERR_FILE_NOT_FOUND\n"));
    1333     return VERR_FILE_NOT_FOUND;
     1364    LogFlow(("intnetOpenNetwork: returns VERR_NOT_FOUND\n"));
     1365    return VERR_NOT_FOUND;
    13341366}
    13351367
     
    13431375 * @returns VBox status code.
    13441376 * @param   pIntNet         The instance data.
     1377 * @param   pSession        The session handle.
    13451378 * @param   pszNetwork      The name of the network. This must be at least one character long and no longer
    13461379 *                          than the INTNETNETWORK::szName.
    1347  * @param   fRestrictAccess Whether new participants should be subjected to access check or not.
    1348  * @param   pSession        The session handle.
     1380 * @param   enmTrunkType    The trunk type.
     1381 * @param   pszTrunk        The trunk name. Its meaning is specfic to the type.
     1382 * @param   fFlags          Flags, see INTNET_OPEN_FLAGS_*.
    13491383 * @param   ppNetwork       Where to store the network.
    13501384 */
    1351 static int intnetCreateNetwork(PINTNET pIntNet, PSUPDRVSESSION pSession, const char *pszNetwork, bool fRestrictAccess, PINTNETNETWORK *ppNetwork)
    1352 {
    1353     LogFlow(("intnetCreateNetwork: pIntNet=%p pSession=%p pszNetwork=%p:{%s} ppNetwork=%p\n",
    1354              pIntNet, pSession, pszNetwork, pszNetwork, ppNetwork));
    1355 
     1385static int intnetCreateNetwork(PINTNET pIntNet, PSUPDRVSESSION pSession, const char *pszNetwork, INTNETTRUNKTYPE enmTrunkType,
     1386                               const char *pszTrunk, uint32_t fFlags, PINTNETNETWORK *ppNetwork)
     1387{
     1388    LogFlow(("intnetCreateNetwork: pIntNet=%p pSession=%p pszNetwork=%p:{%s} enmTrunkType=%d pszTrunk=%p:{%s} fFlags=%#x ppNetwork=%p\n",
     1389             pIntNet, pSession, pszNetwork, pszNetwork, enmTrunkType, pszTrunk, pszTrunk, fFlags, ppNetwork));
     1390
     1391    /* just pro forma validation, the caller is internal. */
    13561392    AssertPtr(pIntNet);
    13571393    AssertPtr(pSession);
    13581394    AssertPtr(pszNetwork);
     1395    Assert(enmTrunkType > kIntNetTrunkType_Invalid && enmTrunkType < kIntNetTrunkType_End);
     1396    AssertPtr(pszTrunk);
     1397    Assert(!(fFlags & ~(INTNET_OPEN_FLAGS_PUBLIC)));
    13591398    AssertPtr(ppNetwork);
    13601399    *ppNetwork = NULL;
     
    13871426        //pNew->pIFs = NULL;
    13881427        pNew->pIntNet = pIntNet;
     1428        pNew->fFlags = fFlags;
    13891429        pNew->cchName = cchName;
    1390         pNew->fRestrictAccess = fRestrictAccess;
    13911430        Assert(cchName && cchName < sizeof(pNew->szName));  /* caller's responsibility. */
    13921431        memcpy(pNew->szName, pszNetwork, cchName);          /* '\0' by alloc. */
     1432        pNew->enmTrunkType = enmTrunkType;
     1433        Assert(strlen(pszTrunk) < sizeof(pNew->szTrunk));   /* caller's responsibility. */
     1434        strcpy(pNew->szTrunk, pszTrunk);
    13931435
    13941436        /*
     
    13991441        {
    14001442            /*
    1401              * Insert the network into the list.
     1443             * Check again that the network doesn't exist and then link in the new one.
    14021444             * This must be done before we attempt any SUPR0ObjRelease call.
    14031445             */
    14041446            RTSpinlockAcquire(pIntNet->Spinlock, &Tmp);
     1447            for (PINTNETNETWORK pCur = pIntNet->pNetworks; pCur; pCur = pCur->pNext)
     1448                if (    pCur->cchName == cchName
     1449                    &&  !memcmp(pCur->szName, pszNetwork, cchName))
     1450                    rc = VERR_ALREADY_EXISTS;
    14051451            pNew->pNext = pIntNet->pNetworks;
    14061452            pIntNet->pNetworks = pNew;
    14071453            RTSpinlockRelease(pIntNet->Spinlock, &Tmp);
    14081454
    1409             /*
    1410              * Check if the current session is actually allowed to create and open
    1411              * the network. It is possible to implement network name based policies
    1412              * and these must be checked now. SUPR0ObjRegister does no such checks.
    1413              */
    1414             rc = SUPR0ObjVerifyAccess(pNew->pvObj, pSession, pNew->szName);
    1415             if (VBOX_SUCCESS(rc))
     1455            if (RT_SUCCESS(rc))
    14161456            {
    1417                 *ppNetwork = pNew;
    1418                 LogFlow(("intnetCreateNetwork: returns VINF_SUCCESS *ppNetwork=%p\n", pNew));
    1419                 return VINF_SUCCESS;
     1457                /*
     1458                 * Check if the current session is actually allowed to create and open
     1459                 * the network. It is possible to implement network name based policies
     1460                 * and these must be checked now. SUPR0ObjRegister does no such checks.
     1461                 */
     1462                rc = SUPR0ObjVerifyAccess(pNew->pvObj, pSession, pNew->szName);
     1463                if (VBOX_SUCCESS(rc))
     1464                {
     1465                    *ppNetwork = pNew;
     1466                    LogFlow(("intnetCreateNetwork: returns VINF_SUCCESS *ppNetwork=%p\n", pNew));
     1467                    return VINF_SUCCESS;
     1468                }
    14201469            }
    14211470
     
    14741523        const char *pszTrunkEnd = (const char *)memchr(pszTrunk, '\0', INTNET_MAX_TRUNK_NAME);
    14751524        AssertReturn(pszTrunkEnd, VERR_INVALID_PARAMETER);
    1476         if (pszTrunkEnd == pszTrunk)
    1477             pszTrunk = NULL;
    1478     }
     1525    }
     1526    else
     1527        pszTrunk = "";
     1528
    14791529    AssertMsgReturn(enmTrunkType > kIntNetTrunkType_Invalid && enmTrunkType < kIntNetTrunkType_End,
    14801530                    ("%d\n", enmTrunkType), VERR_INVALID_PARAMETER);
     
    15081558     */
    15091559    PINTNETNETWORK pNetwork;
    1510     rc = intnetOpenNetwork(pIntNet, pSession, pszNetwork, &pNetwork);
    1511     if (rc == VERR_FILE_NOT_FOUND)
    1512         rc = intnetCreateNetwork(pIntNet, pSession, pszNetwork, !(fFlags & INTNET_OPEN_FLAGS_PUBLIC), &pNetwork);
     1560    rc = intnetOpenNetwork(pIntNet, pSession, pszNetwork, enmTrunkType, pszTrunk, fFlags, &pNetwork);
     1561    if (rc == VERR_NOT_FOUND)
     1562        rc = intnetCreateNetwork(pIntNet, pSession, pszNetwork, enmTrunkType, pszTrunk, fFlags, &pNetwork);
    15131563    if (VBOX_SUCCESS(rc))
    15141564    {
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