VirtualBox

Changeset 1698 in vbox


Ignore:
Timestamp:
Mar 26, 2007 11:40:27 AM (18 years ago)
Author:
vboxsync
Message:

Change configuration option for TCP/UDP setting. Better config checking.

File:
1 edited

Legend:

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

    r1186 r1698  
    310310    for (PCFGMNODE pNode = CFGMR3GetFirstChild(pCfgHandle); pNode; pNode = CFGMR3GetNextChild(pNode))
    311311    {
     312        /*
     313         * Validate the port forwarding config.
     314         */
     315        if (!CFGMR3AreValuesValid(pNode, "Protocol\0UDP\0HostPort\0GuestPort\0GuestIP\0"))
     316            return PDMDRV_SET_ERROR(pData->pDrvIns, VERR_PDM_DRVINS_UNKNOWN_CFG_VALUES, N_("Unknown configuration in port forwarding"));
     317
    312318        /* protocol type */
    313319        bool fUDP;
    314         int rc = CFGMR3QueryBool(pNode, "UDP", &fUDP);
     320        char szProtocol[32];
     321        int rc = CFGMR3QueryString(pNode, "Protocol", &szProtocol[0], sizeof(szProtocol));
    315322        if (rc == VERR_CFGM_VALUE_NOT_FOUND)
    316             fUDP = true;
    317         else if (VBOX_FAILURE(rc))
    318323        {
    319             AssertMsgFailed(("Configuration error: Boolean \"UDP\" -> %Vrc\n", rc));
    320             return rc;
     324            rc = CFGMR3QueryBool(pNode, "UDP", &fUDP);
     325            if (rc == VERR_CFGM_VALUE_NOT_FOUND)
     326                fUDP = false;
     327            else if (VBOX_FAILURE(rc))
     328                return PDMDrvHlpVMSetError(pData->pDrvIns, rc, RT_SRC_POS, N_("NAT#%d: configuration query for \"UDP\" boolean returned %Vrc"), rc);
     329        }
     330        else if (VBOX_SUCCESS(rc))
     331        {
     332            if (!strcasecmp(szProtocol, "TCP"))
     333                fUDP = false;
     334            else if (!strcasecmp(szProtocol, "UDP"))
     335                fUDP = true;
     336            else
     337                return PDMDrvHlpVMSetError(pData->pDrvIns, rc, RT_SRC_POS, N_("NAT#%d: configuration query for \"Protocol\" string returned %Vrc"), rc);
    321338        }
    322339
     
    325342        rc = CFGMR3QueryS32(pNode, "HostPort", &iHostPort);
    326343        if (VBOX_FAILURE(rc))
    327         {
    328             AssertMsgFailed(("Configuration error: Boolean \"HostPort\" -> %Vrc\n", rc));
    329             return rc;
    330         }
     344            return PDMDrvHlpVMSetError(pData->pDrvIns, rc, RT_SRC_POS, N_("NAT#%d: configuration query for \"HostPort\" integer returned %Vrc"), rc);
    331345
    332346        /* guest port */
     
    334348        rc = CFGMR3QueryS32(pNode, "GuestPort", &iGuestPort);
    335349        if (VBOX_FAILURE(rc))
    336         {
    337             AssertMsgFailed(("Configuration error: Boolean \"GuestPort\" -> %Vrc\n", rc));
    338             return rc;
    339         }
     350            return PDMDrvHlpVMSetError(pData->pDrvIns, rc, RT_SRC_POS, N_("NAT#%d: configuration query for \"GuestPort\" integer returned %Vrc"), rc);
    340351
    341352        /* guest address */
     
    345356            strcpy(szGuestIP, "10.0.2.15");
    346357        else if (VBOX_FAILURE(rc))
    347         {
    348             AssertMsgFailed(("Configuration error: Boolean \"HostPort\" -> %Vrc\n", rc));
    349             return rc;
    350         }
     358            return PDMDrvHlpVMSetError(pData->pDrvIns, rc, RT_SRC_POS, N_("NAT#%d: configuration query for \"GuestIP\" string returned %Vrc"), rc);
    351359        struct in_addr GuestIP;
    352360        if (!inet_aton(szGuestIP, &GuestIP))
    353         {
    354             AssertMsgFailed(("Configuration error: Invalid \"GuestIP\"=\"%s\", inet_aton failed.\n", szGuestIP));
    355             return VERR_NAT_REDIR_GUEST_IP;
    356         }
     361            return PDMDrvHlpVMSetError(pData->pDrvIns, VERR_NAT_REDIR_GUEST_IP, RT_SRC_POS, N_("NAT#%d: configuration error: invalid \"GuestIP\"=\"%s\", inet_aton failed"), szGuestIP);
    357362
    358363        /*
     
    361366        Log(("drvNATConstruct: Redir %d -> %s:%d\n", iHostPort, szGuestIP, iGuestPort));
    362367        if (slirp_redir(pData->pNATState, fUDP, iHostPort, GuestIP, iGuestPort) < 0)
    363         {
    364             AssertMsgFailed(("Configuration error: failed to setup redirection of %d to %s:%d. Probably a conflict with existing services or other rules.\n",
    365                              iHostPort, szGuestIP, iGuestPort));
    366             return VERR_NAT_REDIR_SETUP;
    367         }
     368            return PDMDrvHlpVMSetError(pData->pDrvIns, VERR_NAT_REDIR_SETUP, RT_SRC_POS, N_("NAT#%d: configuration error: failed to set up redirection of %d to %s:%d. Probably a conflict with existing services or other rules"), iHostPort, szGuestIP, iGuestPort);
    368369    } /* for each redir rule */
    369370
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