VirtualBox

Changeset 36084 in vbox


Ignore:
Timestamp:
Feb 25, 2011 1:01:42 PM (14 years ago)
Author:
vboxsync
Message:

DrvIntNet: Consolidated policy config variables.

File:
1 edited

Legend:

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

    r36082 r36084  
    12311231
    12321232/**
    1233  * Queries the 'fixed' policy config value and sets the corresponding flag.
    1234  *
    1235  * @returns VBox status code (error set on failure).
    1236  * @param   pDrvIns             The driver instance.
    1237  * @param   pszName             The value name.
    1238  * @param   fFixedFlag          The open network flag.
    1239  * @param   pfFlags             The flags variable to update.
    1240  */
    1241 static int drvIntNetR3CfgFixedPolicy(PPDMDRVINS pDrvIns, const char *pszName, uint32_t fFixedFlag, uint32_t *pfFlags)
    1242 {
    1243     bool fFixed;
    1244     int rc = CFGMR3QueryBoolDef(pDrvIns->pCfg, pszName, &fFixed, false /*fDef*/);
    1245     if (RT_SUCCESS(rc))
    1246     {
    1247         if (fFixed)
    1248             *pfFlags |= fFixedFlag;
    1249     }
    1250     else
    1251         rc = PDMDrvHlpVMSetError(pDrvIns, rc, RT_SRC_POS,
    1252                                  N_("Configuration error: Failed to query the value of \"%s\""), pszName);
    1253     return rc;
    1254 }
    1255 
    1256 
    1257 /**
    12581233 * Queries a policy config value and translates it into open network flag.
    12591234 *
     
    12631238 * @param   paFlags             The open network flag descriptors.
    12641239 * @param   cFlags              The number of descriptors.
     1240 * @param   fFlags              The fixed flag.
    12651241 * @param   pfFlags             The flags variable to update.
    12661242 */
    1267 static int drvIntNetR3CfgGetPolicy(PPDMDRVINS pDrvIns, const char *pszName, PCDRVINTNETFLAG paFlags, size_t cFlags, uint32_t *pfFlags)
     1243static int drvIntNetR3CfgGetPolicy(PPDMDRVINS pDrvIns, const char *pszName, PCDRVINTNETFLAG paFlags, size_t cFlags,
     1244                                   uint32_t fFixedFlag, uint32_t *pfFlags)
    12681245{
    12691246    char szValue[64];
    12701247    int rc = CFGMR3QueryString(pDrvIns->pCfg, pszName, szValue, sizeof(szValue));
    1271     if (RT_SUCCESS(rc))
    1272     {
    1273         size_t i = cFlags;
    1274         while (i-- > 0)
    1275             if (!strcmp(paFlags[i].pszChoice, szValue))
    1276             {
    1277                 *pfFlags |= paFlags[i].fFlag;
    1278                 return VINF_SUCCESS;
    1279             }
    1280         if (!strcmp(szValue, "none"))
     1248    if (RT_FAILURE(rc))
     1249    {
     1250        if (rc == VERR_CFGM_VALUE_NOT_FOUND)
    12811251            return VINF_SUCCESS;
    1282 
    1283         rc = PDMDrvHlpVMSetError(pDrvIns, VERR_INVALID_PARAMETER, RT_SRC_POS,
    1284                                  N_("Configuration error: The value of \"%s\" is unknown: \"%s\""), pszName, szValue);
    1285     }
    1286     else if (rc == VERR_CFGM_VALUE_NOT_FOUND)
     1252        return PDMDrvHlpVMSetError(pDrvIns, rc, RT_SRC_POS,
     1253                                   N_("Configuration error: Failed to query value of \"%s\""), pszName);
     1254    }
     1255
     1256    /*
     1257     * Check for +fixed first, so it can be stripped off.
     1258     */
     1259    char *pszSep = strpbrk(szValue, "+,;");
     1260    if (*pszSep)
     1261    {
     1262        *pszSep++ = '\0';
     1263        const char *pszFixed = RTStrStripL(pszSep);
     1264        if (strcmp(pszFixed, "fixed"))
     1265        {
     1266            *pszSep = '+';
     1267            return PDMDrvHlpVMSetError(pDrvIns, VERR_INVALID_PARAMETER, RT_SRC_POS,
     1268                                       N_("Configuration error: The value of \"%s\" is unknown: \"%s\""), pszName, szValue);
     1269        }
     1270        *pfFlags |= fFixedFlag;
     1271        RTStrStripR(szValue);
     1272    }
     1273
     1274    /*
     1275     * Match against the flag values.
     1276     */
     1277    size_t i = cFlags;
     1278    while (i-- > 0)
     1279        if (!strcmp(paFlags[i].pszChoice, szValue))
     1280        {
     1281            *pfFlags |= paFlags[i].fFlag;
     1282            return VINF_SUCCESS;
     1283        }
     1284
     1285    if (!strcmp(szValue, "none"))
    12871286        return VINF_SUCCESS;
    1288     else
    1289         rc = PDMDrvHlpVMSetError(pDrvIns, rc, RT_SRC_POS,
    1290                                  N_("Configuration error: Failed to query value of \"%s\""), pszName);
    1291     return rc;
     1287
     1288    if (!strcmp(szValue, "fixed"))
     1289    {
     1290        *pfFlags |= fFixedFlag;
     1291        return VINF_SUCCESS;
     1292    }
     1293
     1294    return PDMDrvHlpVMSetError(pDrvIns, VERR_INVALID_PARAMETER, RT_SRC_POS,
     1295                               N_("Configuration error: The value of \"%s\" is unknown: \"%s\""), pszName, szValue);
    12921296}
    12931297
     
    13471351                                  "|RequireAsRestrictivePolicy"
    13481352                                  "|AccessPolicy"
    1349                                   "|AccessPolicyFixed"
    13501353                                  "|PromiscPolicyClients"
    13511354                                  "|PromiscPolicyHost"
    13521355                                  "|PromiscPolicyWire"
    1353                                   "|PromiscPolicyFixed"
    13541356                                  "|IfPolicyPromisc"
    1355                                   "|IfPolicyFixed"
    13561357                                  "|TrunkPolicyHost"
    13571358                                  "|TrunkPolicyWire"
    1358                                   "|TrunkPolicyFixed"
    13591359                                  "|IsService"
    13601360                                  "|IgnoreConnectFailure",
     
    14531453
    14541454    /** @cfgm{AccessPolicy, string, "none"}
    1455      * The access policy of the network: public, restricted or none.  A
    1456      * "public" network is accessible to everyone on the same host, while a
     1455     * The access policy of the network:
     1456     *      public, public+fixed, restricted, restricted+fixed, none or fixed.
     1457     *
     1458     * A "public" network is accessible to everyone on the same host, while a
    14571459     * "restricted" one is only accessible to VMs & services started by the
    14581460     * same user.  The "none" policy, which is the default, means no policy
     
    14651467    };
    14661468    rc = drvIntNetR3CfgGetPolicy(pDrvIns, "AccessPolicy", &s_aAccessPolicyFlags[0], RT_ELEMENTS(s_aAccessPolicyFlags),
    1467                                  &OpenReq.fFlags);
    1468     AssertRCReturn(rc, rc);
    1469     /** @cfgm{AccessPolicyFixed, boolean, false}
    1470      * Whether the access policy is to be locked against further changes. */
    1471     rc = drvIntNetR3CfgFixedPolicy(pDrvIns, "AccessPolicyFixed", INTNET_OPEN_FLAGS_ACCESS_FIXED, &OpenReq.fFlags);
     1469                                 INTNET_OPEN_FLAGS_ACCESS_FIXED, &OpenReq.fFlags);
    14721470    AssertRCReturn(rc, rc);
    14731471
    14741472    /** @cfgm{PromiscPolicyClients, string, "none"}
    14751473     * The network wide promiscuous mode policy for client (non-trunk)
    1476      * interfaces: allow, deny, none. */
     1474     * interfaces: allow, allow+fixed, deny, deny+fixed, none or fixed. */
    14771475    static const DRVINTNETFLAG s_aPromiscPolicyClient[] =
    14781476    {
     
    14811479    };
    14821480    rc = drvIntNetR3CfgGetPolicy(pDrvIns, "PromiscPolicyClients", &s_aPromiscPolicyClient[0], RT_ELEMENTS(s_aPromiscPolicyClient),
    1483                                  &OpenReq.fFlags);
     1481                                 INTNET_OPEN_FLAGS_PROMISC_FIXED, &OpenReq.fFlags);
    14841482    AssertRCReturn(rc, rc);
    14851483    /** @cfgm{PromiscPolicyHost, string, "none"}
    14861484     * The promiscuous mode policy for the trunk-host
    1487      * connection: allow, deny, none. */
     1485     * connection: allow, allow+fixed, deny, deny+fixed, none or fixed. */
    14881486    static const DRVINTNETFLAG s_aPromiscPolicyHost[] =
    14891487    {
     
    14921490    };
    14931491    rc = drvIntNetR3CfgGetPolicy(pDrvIns, "PromiscPolicyHost", &s_aPromiscPolicyHost[0], RT_ELEMENTS(s_aPromiscPolicyHost),
    1494                                  &OpenReq.fFlags);
     1492                                 INTNET_OPEN_FLAGS_PROMISC_FIXED, &OpenReq.fFlags);
    14951493    AssertRCReturn(rc, rc);
    14961494    /** @cfgm{PromiscPolicyWire, string, "none"}
    14971495     * The promiscuous mode policy for the trunk-host
    1498      * connection: allow, deny, none. */
     1496     * connection: allow, allow+fixed, deny, deny+fixed, none or fixed. */
    14991497    static const DRVINTNETFLAG s_aPromiscPolicyWire[] =
    15001498    {
     
    15031501    };
    15041502    rc = drvIntNetR3CfgGetPolicy(pDrvIns, "PromiscPolicyWire", &s_aPromiscPolicyWire[0], RT_ELEMENTS(s_aPromiscPolicyWire),
    1505                                  &OpenReq.fFlags);
    1506     AssertRCReturn(rc, rc);
    1507     /** @cfgm{PromiscPolicyFixed, boolean, false}
    1508      * Whether the promiscuous mode policies are to be locked against further
    1509      * changes. */
    1510     rc = drvIntNetR3CfgFixedPolicy(pDrvIns, "PromiscPolicyFixed", INTNET_OPEN_FLAGS_PROMISC_FIXED, &OpenReq.fFlags);
     1503                                 INTNET_OPEN_FLAGS_PROMISC_FIXED, &OpenReq.fFlags);
    15111504    AssertRCReturn(rc, rc);
    15121505
     
    15141507    /** @cfgm{IfPolicyPromisc, string, "none"}
    15151508     * The promiscuous mode policy for this
    1516      * interface: deny, allow-all, allow-network, none. */
     1509     * interface: deny, deny+fixed, allow-all, allow-all+fixed, allow-network,
     1510     *      allow-network+fixed, none or fixed. */
    15171511    static const DRVINTNETFLAG s_aIfPolicyPromisc[] =
    15181512    {
    15191513        { "allow-all",     INTNET_OPEN_FLAGS_IF_PROMISC_ALLOW | INTNET_OPEN_FLAGS_IF_PROMISC_SEE_TRUNK },
    15201514        { "allow-network", INTNET_OPEN_FLAGS_IF_PROMISC_ALLOW | INTNET_OPEN_FLAGS_IF_PROMISC_NO_TRUNK  },
    1521         { "deny",          INTNET_OPEN_FLAGS_IF_PROMISC_DENY            }
     1515        { "deny",          INTNET_OPEN_FLAGS_IF_PROMISC_DENY }
    15221516    };
    15231517    rc = drvIntNetR3CfgGetPolicy(pDrvIns, "IfPolicyPromisc", &s_aIfPolicyPromisc[0], RT_ELEMENTS(s_aIfPolicyPromisc),
    1524                                  &OpenReq.fFlags);
     1518                                 INTNET_OPEN_FLAGS_IF_FIXED, &OpenReq.fFlags);
    15251519    AssertRCReturn(rc, rc);
    15261520
    1527     /** @cfgm{IfPolicyFixed, boolean, false}
    1528      * Whether the interface policies are to be locked against further
    1529      * changes. */
    1530     rc = drvIntNetR3CfgFixedPolicy(pDrvIns, "IfPolicyFixed", INTNET_OPEN_FLAGS_IF_FIXED, &OpenReq.fFlags);
    1531     AssertRCReturn(rc, rc);
    1532 
    15331521
    15341522    /** @cfgm{TrunkPolicyHost, string, "none"}
    1535      * The trunk-host policy: enabled, disabled, non
     1523     * The trunk-host policy: promisc, promisc+fixed, enabled, enabled+fixed,
     1524     *      disabled, disabled+fixed, none or fixed
     1525     *
    15361526     * This can be used to prevent packages to be routed to the host. */
    15371527    static const DRVINTNETFLAG s_aTrunkPolicyHost[] =
    15381528    {
    1539         { "enabled",        INTNET_OPEN_FLAGS_TRUNK_HOST_ENABLED        },
    1540         { "disabled",       INTNET_OPEN_FLAGS_TRUNK_HOST_DISABLED       }
     1529        { "promisc",        INTNET_OPEN_FLAGS_TRUNK_HOST_ENABLED | INTNET_OPEN_FLAGS_TRUNK_HOST_PROMISC_MODE },
     1530        { "enabled",        INTNET_OPEN_FLAGS_TRUNK_HOST_ENABLED },
     1531        { "disabled",       INTNET_OPEN_FLAGS_TRUNK_HOST_DISABLED }
    15411532    };
    15421533    rc = drvIntNetR3CfgGetPolicy(pDrvIns, "TrunkPolicyHost", &s_aTrunkPolicyHost[0], RT_ELEMENTS(s_aTrunkPolicyHost),
    1543                                  &OpenReq.fFlags);
     1534                                 INTNET_OPEN_FLAGS_TRUNK_FIXED, &OpenReq.fFlags);
    15441535    AssertRCReturn(rc, rc);
    15451536    /** @cfgm{TrunkPolicyWire, string, "none"}
    1546      * The trunk-host policy: enabled, disabled, non
    1547      * This can be used to prevent packages to be routed to the host. */
     1537     * The trunk-host policy: promisc, promisc+fixed, enabled, enabled+fixed,
     1538     *      disabled, disabled+fixed, none or fixed.
     1539     *
     1540     * This can be used to prevent packages to be routed to the wire. */
    15481541    static const DRVINTNETFLAG s_aTrunkPolicyWire[] =
    15491542    {
    1550         { "enabled",        INTNET_OPEN_FLAGS_TRUNK_WIRE_ENABLED        },
    1551         { "disabled",       INTNET_OPEN_FLAGS_TRUNK_WIRE_DISABLED       }
     1543        { "promisc",        INTNET_OPEN_FLAGS_TRUNK_WIRE_ENABLED | INTNET_OPEN_FLAGS_TRUNK_WIRE_PROMISC_MODE },
     1544        { "enabled",        INTNET_OPEN_FLAGS_TRUNK_WIRE_ENABLED },
     1545        { "disabled",       INTNET_OPEN_FLAGS_TRUNK_WIRE_DISABLED }
    15521546    };
    15531547    rc = drvIntNetR3CfgGetPolicy(pDrvIns, "TrunkPolicyWire", &s_aTrunkPolicyWire[0], RT_ELEMENTS(s_aTrunkPolicyWire),
    1554                                  &OpenReq.fFlags);
    1555     AssertRCReturn(rc, rc);
    1556     /** @cfgm{TrunkPolicyFixed, boolean, false}
    1557      * Whether the trunk policies are to be locked against further changes. */
    1558     rc = drvIntNetR3CfgFixedPolicy(pDrvIns, "TrunkPolicyFixed", INTNET_OPEN_FLAGS_TRUNK_FIXED, &OpenReq.fFlags);
     1548                                 INTNET_OPEN_FLAGS_TRUNK_FIXED, &OpenReq.fFlags);
    15591549    AssertRCReturn(rc, rc);
    15601550
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