VirtualBox

Changeset 82455 in vbox for trunk/src


Ignore:
Timestamp:
Dec 6, 2019 1:03:38 PM (5 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
135305
Message:

DevINIP: Converted to new style. bugref:9218

File:
1 edited

Legend:

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

    r81591 r82455  
    6666*   Structures and Typedefs                                                                                                      *
    6767*********************************************************************************************************************************/
    68 
    6968/**
    7069 * Internal Network IP stack device instance data.
     
    115114     */
    116115    int rcInitialization;
    117 } DEVINTNETIP, *PDEVINTNETIP;
     116} DEVINTNETIP;
     117/** Pointer to the instance data for an Internal Network IP stack. */
     118typedef DEVINTNETIP *PDEVINTNETIP;
    118119
    119120
     
    121122*   Global Variables                                                                                                             *
    122123*********************************************************************************************************************************/
    123 
    124124/**
    125125 * Pointer to the (only) instance data in this device.
     
    277277static DECLCALLBACK(int) devINIPNetworkConfiguration(PPDMDEVINS pDevIns, PDEVINTNETIP pThis, PCFGMNODE pCfg)
    278278{
    279     int rc = VINF_SUCCESS;
    280     rc = CFGMR3QueryStringAlloc(pCfg, "IP", &pThis->pszIP);
     279    PCPDMDEVHLPR3 pHlp = pDevIns->pHlpR3;
     280
     281    int rc = pHlp->pfnCFGMQueryStringAlloc(pCfg, "IP", &pThis->pszIP);
    281282    if (RT_FAILURE(rc))
    282     {
    283         PDMDEV_SET_ERROR(pDevIns, rc,
    284                          N_("Configuration error: Failed to get the \"IP\" value"));
    285283        /** @todo perhaps we should panic if IPv4 address isn't specify, with assumtion that
    286          * ISCSI target specified in IPv6 form.
    287          */
    288         return rc;
    289     }
    290 
    291     rc = CFGMR3QueryStringAlloc(pCfg, "Netmask", &pThis->pszNetmask);
     284         * ISCSI target specified in IPv6 form.  */
     285        return PDMDEV_SET_ERROR(pDevIns, rc, N_("Configuration error: Failed to get the \"IP\" value"));
     286
     287    rc = pHlp->pfnCFGMQueryStringAlloc(pCfg, "Netmask", &pThis->pszNetmask);
    292288    if (RT_FAILURE(rc))
    293     {
    294         PDMDEV_SET_ERROR(pDevIns, rc,
    295                          N_("Configuration error: Failed to get the \"Netmask\" value"));
    296         return rc;
    297     }
    298     rc = CFGMR3QueryStringAlloc(pCfg, "Gateway", &pThis->pszGateway);
     289        return PDMDEV_SET_ERROR(pDevIns, rc, N_("Configuration error: Failed to get the \"Netmask\" value"));
     290
     291    rc = pHlp->pfnCFGMQueryStringAlloc(pCfg, "Gateway", &pThis->pszGateway);
    299292    if (   RT_FAILURE(rc)
    300293        && rc != VERR_CFGM_VALUE_NOT_FOUND)
    301     {
    302         PDMDEV_SET_ERROR(pDevIns, rc,
    303                          N_("Configuration error: Failed to get the \"Gateway\" value"));
    304         return rc;
    305     }
     294        return PDMDEV_SET_ERROR(pDevIns, rc, N_("Configuration error: Failed to get the \"Gateway\" value"));
     295
    306296    return VINF_SUCCESS;
    307297}
     
    396386 * Signals the end of lwIP TCPIP initialization.
    397387 *
    398  * @note: TCPIP thread, corresponding EMT waiting on semaphore.
    399388 * @param   arg     opaque argument, here the pointer to the PDEVINTNETIP.
     389 * @note    TCPIP thread, corresponding EMT waiting on semaphore.
    400390 */
    401391static DECLCALLBACK(void) devINIPTcpipInitDone(void *arg)
     
    405395
    406396    pThis->rcInitialization = VINF_SUCCESS;
    407     {
    408         struct netif *ret;
    409         struct ip_addr ipaddr, netmask, gw;
    410         struct in_addr ip;
    411 
    412         if (!inet_aton(pThis->pszIP, &ip))
     397    struct in_addr ip;
     398    if (!inet_aton(pThis->pszIP, &ip))
     399    {
     400        pThis->rcInitialization = VERR_PDM_DEVINS_UNKNOWN_CFG_VALUES;
     401        PDMDEV_SET_ERROR(pThis->pDevIns, pThis->rcInitialization, N_("Configuration error: Invalid \"IP\" value"));
     402        return;
     403    }
     404    struct ip_addr ipaddr;
     405    memcpy(&ipaddr, &ip, sizeof(ipaddr));
     406
     407    if (!inet_aton(pThis->pszNetmask, &ip))
     408    {
     409        pThis->rcInitialization = VERR_PDM_DEVINS_UNKNOWN_CFG_VALUES;
     410        PDMDEV_SET_ERROR(pThis->pDevIns, pThis->rcInitialization, N_("Configuration error: Invalid \"Netmask\" value"));
     411        return;
     412    }
     413    struct ip_addr netmask;
     414    memcpy(&netmask, &ip, sizeof(netmask));
     415
     416    if (pThis->pszGateway)
     417    {
     418        if (!inet_aton(pThis->pszGateway, &ip))
    413419        {
    414420            pThis->rcInitialization = VERR_PDM_DEVINS_UNKNOWN_CFG_VALUES;
    415             PDMDEV_SET_ERROR(pThis->pDevIns,
    416                              pThis->rcInitialization,
    417                              N_("Configuration error: Invalid \"IP\" value"));
    418             goto done;
     421            PDMDEV_SET_ERROR(pThis->pDevIns, pThis->rcInitialization, N_("Configuration error: Invalid \"Gateway\" value"));
     422            return;
    419423        }
    420         memcpy(&ipaddr, &ip, sizeof(ipaddr));
    421 
    422         if (!inet_aton(pThis->pszNetmask, &ip))
    423         {
    424             pThis->rcInitialization = VERR_PDM_DEVINS_UNKNOWN_CFG_VALUES;
    425             PDMDEV_SET_ERROR(pThis->pDevIns,
    426                              pThis->rcInitialization,
    427                              N_("Configuration error: Invalid \"Netmask\" value"));
    428             goto done;
    429         }
    430         memcpy(&netmask, &ip, sizeof(netmask));
    431 
    432         if (pThis->pszGateway)
    433         {
    434             if (!inet_aton(pThis->pszGateway, &ip))
    435             {
    436                 pThis->rcInitialization = VERR_PDM_DEVINS_UNKNOWN_CFG_VALUES;
    437                 PDMDEV_SET_ERROR(pThis->pDevIns,
    438                                  pThis->rcInitialization,
    439                                  N_("Configuration error: Invalid \"Gateway\" value"));
    440                 goto done;
    441             }
    442 
    443         }
    444         else
    445         {
    446             inet_aton(pThis->pszIP, &ip);
    447         }
    448         memcpy(&gw, &ip, sizeof(gw));
    449 
    450         pThis->IntNetIF.name[0] = 'I';
    451         pThis->IntNetIF.name[1] = 'N';
    452 
    453         ret = netif_add(&pThis->IntNetIF, &ipaddr, &netmask, &gw, NULL,
    454                         devINIPInterface, lwip_tcpip_input);
    455 
    456         if (!ret)
    457         {
    458 
    459             pThis->rcInitialization = VERR_NET_NO_NETWORK;
    460             PDMDEV_SET_ERROR(pThis->pDevIns,
    461                              pThis->rcInitialization,
    462                              N_("netif_add failed"));
    463             goto done;
    464         }
    465 
    466         lwip_netif_set_default(&pThis->IntNetIF);
    467         lwip_netif_set_up(&pThis->IntNetIF);
    468     }
    469     done:
    470     return;
     424    }
     425    else
     426        inet_aton(pThis->pszIP, &ip);
     427    struct ip_addr gw;
     428    memcpy(&gw, &ip, sizeof(gw));
     429
     430    pThis->IntNetIF.name[0] = 'I';
     431    pThis->IntNetIF.name[1] = 'N';
     432
     433    struct netif *ret = netif_add(&pThis->IntNetIF, &ipaddr, &netmask, &gw, NULL, devINIPInterface, lwip_tcpip_input);
     434    if (!ret)
     435    {
     436
     437        pThis->rcInitialization = VERR_NET_NO_NETWORK;
     438        PDMDEV_SET_ERROR(pThis->pDevIns, pThis->rcInitialization, N_("netif_add failed"));
     439        return;
     440    }
     441
     442    lwip_netif_set_default(&pThis->IntNetIF);
     443    lwip_netif_set_up(&pThis->IntNetIF);
    471444}
    472445
     
    474447/**
    475448 * This callback is for finitializing our activity on TCPIP thread.
    476  * XXX: We do it only for new LWIP, old LWIP will stay broken for now.
     449 * @todo XXX: We do it only for new LWIP, old LWIP will stay broken for now.
    477450 */
    478451static DECLCALLBACK(void) devINIPTcpipFiniDone(void *arg)
     
    576549static DECLCALLBACK(int) devINIPDestruct(PPDMDEVINS pDevIns)
    577550{
     551    PDMDEV_CHECK_VERSIONS_RETURN_QUIET(pDevIns);
     552    LogFlow(("devINIPDestruct: pDevIns=%p\n", pDevIns));
    578553    PDEVINTNETIP pThis = PDMDEVINS_2_DATA(pDevIns, PDEVINTNETIP);
    579 
    580     LogFlow(("%s: pDevIns=%p\n", __FUNCTION__, pDevIns));
    581     PDMDEV_CHECK_VERSIONS_RETURN_QUIET(pDevIns);
    582554
    583555    if (g_pDevINIPData != NULL)
     
    601573static DECLCALLBACK(int) devINIPConstruct(PPDMDEVINS pDevIns, int iInstance, PCFGMNODE pCfg)
    602574{
     575    PDMDEV_CHECK_VERSIONS_RETURN(pDevIns);
     576    PDEVINTNETIP    pThis = PDMDEVINS_2_DATA(pDevIns, PDEVINTNETIP);
     577    PCPDMDEVHLPR3   pHlp  = pDevIns->pHlpR3;
     578    LogFlow(("devINIPConstruct: pDevIns=%p iInstance=%d pCfg=%p\n", pDevIns, iInstance, pCfg));
    603579    RT_NOREF(iInstance);
    604     PDEVINTNETIP pThis = PDMDEVINS_2_DATA(pDevIns, PDEVINTNETIP);
    605 
    606     LogFlow(("%s: pDevIns=%p iInstance=%d pCfg=%p\n", __FUNCTION__,
    607              pDevIns, iInstance, pCfg));
    608580
    609581    Assert(iInstance == 0);
    610     PDMDEV_CHECK_VERSIONS_RETURN(pDevIns);
    611 
    612     /*
    613      * Validate the config.
    614      */
    615     if (!CFGMR3AreValuesValid(pCfg, "MAC\0IP\0"
    616                                     "IPv6\0"
    617                                     "Netmask\0Gateway\0"))
    618         return PDMDEV_SET_ERROR(pDevIns, VERR_PDM_DEVINS_UNKNOWN_CFG_VALUES,
    619                                 N_("Unknown Internal Networking IP configuration option"));
    620582
    621583    /*
    622584     * Init the static parts.
    623585     */
    624     pThis->pszIP                            = NULL;
    625     pThis->pszNetmask                       = NULL;
    626     pThis->pszGateway                       = NULL;
     586    //pThis->pszIP                            = NULL;
     587    //pThis->pszNetmask                       = NULL;
     588    //pThis->pszGateway                       = NULL;
    627589    /* Pointer to device instance */
    628590    pThis->pDevIns                          = pDevIns;
     
    638600    pThis->INetworkConfig.pfnSetLinkState   = devINIPSetLinkState;
    639601
     602
     603    /*
     604     * Validate the config.
     605     */
     606    PDMDEV_VALIDATE_CONFIG_RETURN(pDevIns, "MAC|IP|IPv6|Netmask|Gateway", "");
     607
    640608    /*
    641609     * Get the configuration settings.
    642610     */
    643     int rc = CFGMR3QueryBytes(pCfg, "MAC", &pThis->MAC, sizeof(pThis->MAC));
     611    int rc = pHlp->pfnCFGMQueryBytes(pCfg, "MAC", &pThis->MAC, sizeof(pThis->MAC));
    644612    if (rc == VERR_CFGM_NOT_BYTES)
    645613    {
    646614        char szMAC[64];
    647         rc = CFGMR3QueryString(pCfg, "MAC", &szMAC[0], sizeof(szMAC));
     615        rc = pHlp->pfnCFGMQueryString(pCfg, "MAC", &szMAC[0], sizeof(szMAC));
    648616        if (RT_SUCCESS(rc))
    649617        {
     
    652620            for (uint32_t i = 0; i < 6; i++)
    653621            {
    654                 if (   !*macStr || !*(macStr + 1)
    655                     || *macStr == ':' || *(macStr + 1) == ':')
    656                     return PDMDEV_SET_ERROR(pDevIns,
    657                                             VERR_PDM_DEVINS_UNKNOWN_CFG_VALUES,
     622                if (!*macStr || !macStr[1] || *macStr == ':' || macStr[1] == ':')
     623                    return PDMDEV_SET_ERROR(pDevIns, VERR_PDM_DEVINS_UNKNOWN_CFG_VALUES,
    658624                                            N_("Configuration error: Invalid \"MAC\" value"));
    659625                char c1 = *macStr++ - '0';
     
    670636    }
    671637    if (RT_FAILURE(rc))
    672         return PDMDEV_SET_ERROR(pDevIns, rc,
    673                                 N_("Configuration error: Failed to get the \"MAC\" value"));
     638        return PDMDEV_SET_ERROR(pDevIns, rc, N_("Configuration error: Failed to get the \"MAC\" value"));
    674639    rc = devINIPNetworkConfiguration(pDevIns, pThis, pCfg);
    675640    AssertLogRelRCReturn(rc, rc);
     
    707672
    708673
    709     LogFlow(("%s: return %Rrc\n", __FUNCTION__, rc));
     674    LogFlow(("devINIPConstruct: return %Rrc\n", rc));
    710675    return rc;
    711676}
     
    732697    /* .uReserved0 = */             0,
    733698    /* .szName = */                 "IntNetIP",
    734     /* .fFlags = */                 PDM_DEVREG_FLAGS_DEFAULT_BITS,
     699    /* .fFlags = */                 PDM_DEVREG_FLAGS_DEFAULT_BITS | PDM_DEVREG_FLAGS_NEW_STYLE,
    735700    /* .fClass = */                 PDM_DEVREG_CLASS_VMM_DEV, /* As this is used by the storage devices, it must come earlier. */
    736701    /* .cMaxInstances = */          1,
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