Index: /trunk/src/VBox/Devices/Network/DevINIP.cpp
===================================================================
--- /trunk/src/VBox/Devices/Network/DevINIP.cpp	(revision 82454)
+++ /trunk/src/VBox/Devices/Network/DevINIP.cpp	(revision 82455)
@@ -66,5 +66,4 @@
 *   Structures and Typedefs                                                                                                      *
 *********************************************************************************************************************************/
-
 /**
  * Internal Network IP stack device instance data.
@@ -115,5 +114,7 @@
      */
     int rcInitialization;
-} DEVINTNETIP, *PDEVINTNETIP;
+} DEVINTNETIP;
+/** Pointer to the instance data for an Internal Network IP stack. */
+typedef DEVINTNETIP *PDEVINTNETIP;
 
 
@@ -121,5 +122,4 @@
 *   Global Variables                                                                                                             *
 *********************************************************************************************************************************/
-
 /**
  * Pointer to the (only) instance data in this device.
@@ -277,31 +277,21 @@
 static DECLCALLBACK(int) devINIPNetworkConfiguration(PPDMDEVINS pDevIns, PDEVINTNETIP pThis, PCFGMNODE pCfg)
 {
-    int rc = VINF_SUCCESS;
-    rc = CFGMR3QueryStringAlloc(pCfg, "IP", &pThis->pszIP);
+    PCPDMDEVHLPR3 pHlp = pDevIns->pHlpR3;
+
+    int rc = pHlp->pfnCFGMQueryStringAlloc(pCfg, "IP", &pThis->pszIP);
     if (RT_FAILURE(rc))
-    {
-        PDMDEV_SET_ERROR(pDevIns, rc,
-                         N_("Configuration error: Failed to get the \"IP\" value"));
         /** @todo perhaps we should panic if IPv4 address isn't specify, with assumtion that
-         * ISCSI target specified in IPv6 form.
-         */
-        return rc;
-    }
-
-    rc = CFGMR3QueryStringAlloc(pCfg, "Netmask", &pThis->pszNetmask);
+         * ISCSI target specified in IPv6 form.  */
+        return PDMDEV_SET_ERROR(pDevIns, rc, N_("Configuration error: Failed to get the \"IP\" value"));
+
+    rc = pHlp->pfnCFGMQueryStringAlloc(pCfg, "Netmask", &pThis->pszNetmask);
     if (RT_FAILURE(rc))
-    {
-        PDMDEV_SET_ERROR(pDevIns, rc,
-                         N_("Configuration error: Failed to get the \"Netmask\" value"));
-        return rc;
-    }
-    rc = CFGMR3QueryStringAlloc(pCfg, "Gateway", &pThis->pszGateway);
+        return PDMDEV_SET_ERROR(pDevIns, rc, N_("Configuration error: Failed to get the \"Netmask\" value"));
+
+    rc = pHlp->pfnCFGMQueryStringAlloc(pCfg, "Gateway", &pThis->pszGateway);
     if (   RT_FAILURE(rc)
         && rc != VERR_CFGM_VALUE_NOT_FOUND)
-    {
-        PDMDEV_SET_ERROR(pDevIns, rc,
-                         N_("Configuration error: Failed to get the \"Gateway\" value"));
-        return rc;
-    }
+        return PDMDEV_SET_ERROR(pDevIns, rc, N_("Configuration error: Failed to get the \"Gateway\" value"));
+
     return VINF_SUCCESS;
 }
@@ -396,6 +386,6 @@
  * Signals the end of lwIP TCPIP initialization.
  *
- * @note: TCPIP thread, corresponding EMT waiting on semaphore.
  * @param   arg     opaque argument, here the pointer to the PDEVINTNETIP.
+ * @note    TCPIP thread, corresponding EMT waiting on semaphore.
  */
 static DECLCALLBACK(void) devINIPTcpipInitDone(void *arg)
@@ -405,68 +395,51 @@
 
     pThis->rcInitialization = VINF_SUCCESS;
-    {
-        struct netif *ret;
-        struct ip_addr ipaddr, netmask, gw;
-        struct in_addr ip;
-
-        if (!inet_aton(pThis->pszIP, &ip))
+    struct in_addr ip;
+    if (!inet_aton(pThis->pszIP, &ip))
+    {
+        pThis->rcInitialization = VERR_PDM_DEVINS_UNKNOWN_CFG_VALUES;
+        PDMDEV_SET_ERROR(pThis->pDevIns, pThis->rcInitialization, N_("Configuration error: Invalid \"IP\" value"));
+        return;
+    }
+    struct ip_addr ipaddr;
+    memcpy(&ipaddr, &ip, sizeof(ipaddr));
+
+    if (!inet_aton(pThis->pszNetmask, &ip))
+    {
+        pThis->rcInitialization = VERR_PDM_DEVINS_UNKNOWN_CFG_VALUES;
+        PDMDEV_SET_ERROR(pThis->pDevIns, pThis->rcInitialization, N_("Configuration error: Invalid \"Netmask\" value"));
+        return;
+    }
+    struct ip_addr netmask;
+    memcpy(&netmask, &ip, sizeof(netmask));
+
+    if (pThis->pszGateway)
+    {
+        if (!inet_aton(pThis->pszGateway, &ip))
         {
             pThis->rcInitialization = VERR_PDM_DEVINS_UNKNOWN_CFG_VALUES;
-            PDMDEV_SET_ERROR(pThis->pDevIns,
-                             pThis->rcInitialization,
-                             N_("Configuration error: Invalid \"IP\" value"));
-            goto done;
+            PDMDEV_SET_ERROR(pThis->pDevIns, pThis->rcInitialization, N_("Configuration error: Invalid \"Gateway\" value"));
+            return;
         }
-        memcpy(&ipaddr, &ip, sizeof(ipaddr));
-
-        if (!inet_aton(pThis->pszNetmask, &ip))
-        {
-            pThis->rcInitialization = VERR_PDM_DEVINS_UNKNOWN_CFG_VALUES;
-            PDMDEV_SET_ERROR(pThis->pDevIns,
-                             pThis->rcInitialization,
-                             N_("Configuration error: Invalid \"Netmask\" value"));
-            goto done;
-        }
-        memcpy(&netmask, &ip, sizeof(netmask));
-
-        if (pThis->pszGateway)
-        {
-            if (!inet_aton(pThis->pszGateway, &ip))
-            {
-                pThis->rcInitialization = VERR_PDM_DEVINS_UNKNOWN_CFG_VALUES;
-                PDMDEV_SET_ERROR(pThis->pDevIns,
-                                 pThis->rcInitialization,
-                                 N_("Configuration error: Invalid \"Gateway\" value"));
-                goto done;
-            }
-
-        }
-        else
-        {
-            inet_aton(pThis->pszIP, &ip);
-        }
-        memcpy(&gw, &ip, sizeof(gw));
-
-        pThis->IntNetIF.name[0] = 'I';
-        pThis->IntNetIF.name[1] = 'N';
-
-        ret = netif_add(&pThis->IntNetIF, &ipaddr, &netmask, &gw, NULL,
-                        devINIPInterface, lwip_tcpip_input);
-
-        if (!ret)
-        {
-
-            pThis->rcInitialization = VERR_NET_NO_NETWORK;
-            PDMDEV_SET_ERROR(pThis->pDevIns,
-                             pThis->rcInitialization,
-                             N_("netif_add failed"));
-            goto done;
-        }
-
-        lwip_netif_set_default(&pThis->IntNetIF);
-        lwip_netif_set_up(&pThis->IntNetIF);
-    }
-    done:
-    return;
+    }
+    else
+        inet_aton(pThis->pszIP, &ip);
+    struct ip_addr gw;
+    memcpy(&gw, &ip, sizeof(gw));
+
+    pThis->IntNetIF.name[0] = 'I';
+    pThis->IntNetIF.name[1] = 'N';
+
+    struct netif *ret = netif_add(&pThis->IntNetIF, &ipaddr, &netmask, &gw, NULL, devINIPInterface, lwip_tcpip_input);
+    if (!ret)
+    {
+
+        pThis->rcInitialization = VERR_NET_NO_NETWORK;
+        PDMDEV_SET_ERROR(pThis->pDevIns, pThis->rcInitialization, N_("netif_add failed"));
+        return;
+    }
+
+    lwip_netif_set_default(&pThis->IntNetIF);
+    lwip_netif_set_up(&pThis->IntNetIF);
 }
 
@@ -474,5 +447,5 @@
 /**
  * This callback is for finitializing our activity on TCPIP thread.
- * XXX: We do it only for new LWIP, old LWIP will stay broken for now.
+ * @todo XXX: We do it only for new LWIP, old LWIP will stay broken for now.
  */
 static DECLCALLBACK(void) devINIPTcpipFiniDone(void *arg)
@@ -576,8 +549,7 @@
 static DECLCALLBACK(int) devINIPDestruct(PPDMDEVINS pDevIns)
 {
+    PDMDEV_CHECK_VERSIONS_RETURN_QUIET(pDevIns);
+    LogFlow(("devINIPDestruct: pDevIns=%p\n", pDevIns));
     PDEVINTNETIP pThis = PDMDEVINS_2_DATA(pDevIns, PDEVINTNETIP);
-
-    LogFlow(("%s: pDevIns=%p\n", __FUNCTION__, pDevIns));
-    PDMDEV_CHECK_VERSIONS_RETURN_QUIET(pDevIns);
 
     if (g_pDevINIPData != NULL)
@@ -601,28 +573,18 @@
 static DECLCALLBACK(int) devINIPConstruct(PPDMDEVINS pDevIns, int iInstance, PCFGMNODE pCfg)
 {
+    PDMDEV_CHECK_VERSIONS_RETURN(pDevIns);
+    PDEVINTNETIP    pThis = PDMDEVINS_2_DATA(pDevIns, PDEVINTNETIP);
+    PCPDMDEVHLPR3   pHlp  = pDevIns->pHlpR3;
+    LogFlow(("devINIPConstruct: pDevIns=%p iInstance=%d pCfg=%p\n", pDevIns, iInstance, pCfg));
     RT_NOREF(iInstance);
-    PDEVINTNETIP pThis = PDMDEVINS_2_DATA(pDevIns, PDEVINTNETIP);
-
-    LogFlow(("%s: pDevIns=%p iInstance=%d pCfg=%p\n", __FUNCTION__,
-             pDevIns, iInstance, pCfg));
 
     Assert(iInstance == 0);
-    PDMDEV_CHECK_VERSIONS_RETURN(pDevIns);
-
-    /*
-     * Validate the config.
-     */
-    if (!CFGMR3AreValuesValid(pCfg, "MAC\0IP\0"
-                                    "IPv6\0"
-                                    "Netmask\0Gateway\0"))
-        return PDMDEV_SET_ERROR(pDevIns, VERR_PDM_DEVINS_UNKNOWN_CFG_VALUES,
-                                N_("Unknown Internal Networking IP configuration option"));
 
     /*
      * Init the static parts.
      */
-    pThis->pszIP                            = NULL;
-    pThis->pszNetmask                       = NULL;
-    pThis->pszGateway                       = NULL;
+    //pThis->pszIP                            = NULL;
+    //pThis->pszNetmask                       = NULL;
+    //pThis->pszGateway                       = NULL;
     /* Pointer to device instance */
     pThis->pDevIns                          = pDevIns;
@@ -638,12 +600,18 @@
     pThis->INetworkConfig.pfnSetLinkState   = devINIPSetLinkState;
 
+
+    /*
+     * Validate the config.
+     */
+    PDMDEV_VALIDATE_CONFIG_RETURN(pDevIns, "MAC|IP|IPv6|Netmask|Gateway", "");
+
     /*
      * Get the configuration settings.
      */
-    int rc = CFGMR3QueryBytes(pCfg, "MAC", &pThis->MAC, sizeof(pThis->MAC));
+    int rc = pHlp->pfnCFGMQueryBytes(pCfg, "MAC", &pThis->MAC, sizeof(pThis->MAC));
     if (rc == VERR_CFGM_NOT_BYTES)
     {
         char szMAC[64];
-        rc = CFGMR3QueryString(pCfg, "MAC", &szMAC[0], sizeof(szMAC));
+        rc = pHlp->pfnCFGMQueryString(pCfg, "MAC", &szMAC[0], sizeof(szMAC));
         if (RT_SUCCESS(rc))
         {
@@ -652,8 +620,6 @@
             for (uint32_t i = 0; i < 6; i++)
             {
-                if (   !*macStr || !*(macStr + 1)
-                    || *macStr == ':' || *(macStr + 1) == ':')
-                    return PDMDEV_SET_ERROR(pDevIns,
-                                            VERR_PDM_DEVINS_UNKNOWN_CFG_VALUES,
+                if (!*macStr || !macStr[1] || *macStr == ':' || macStr[1] == ':')
+                    return PDMDEV_SET_ERROR(pDevIns, VERR_PDM_DEVINS_UNKNOWN_CFG_VALUES,
                                             N_("Configuration error: Invalid \"MAC\" value"));
                 char c1 = *macStr++ - '0';
@@ -670,6 +636,5 @@
     }
     if (RT_FAILURE(rc))
-        return PDMDEV_SET_ERROR(pDevIns, rc,
-                                N_("Configuration error: Failed to get the \"MAC\" value"));
+        return PDMDEV_SET_ERROR(pDevIns, rc, N_("Configuration error: Failed to get the \"MAC\" value"));
     rc = devINIPNetworkConfiguration(pDevIns, pThis, pCfg);
     AssertLogRelRCReturn(rc, rc);
@@ -707,5 +672,5 @@
 
 
-    LogFlow(("%s: return %Rrc\n", __FUNCTION__, rc));
+    LogFlow(("devINIPConstruct: return %Rrc\n", rc));
     return rc;
 }
@@ -732,5 +697,5 @@
     /* .uReserved0 = */             0,
     /* .szName = */                 "IntNetIP",
-    /* .fFlags = */                 PDM_DEVREG_FLAGS_DEFAULT_BITS,
+    /* .fFlags = */                 PDM_DEVREG_FLAGS_DEFAULT_BITS | PDM_DEVREG_FLAGS_NEW_STYLE,
     /* .fClass = */                 PDM_DEVREG_CLASS_VMM_DEV, /* As this is used by the storage devices, it must come earlier. */
     /* .cMaxInstances = */          1,
