- Timestamp:
- Dec 6, 2019 1:03:38 PM (5 years ago)
- svn:sync-xref-src-repo-rev:
- 135305
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Devices/Network/DevINIP.cpp
r81591 r82455 66 66 * Structures and Typedefs * 67 67 *********************************************************************************************************************************/ 68 69 68 /** 70 69 * Internal Network IP stack device instance data. … … 115 114 */ 116 115 int rcInitialization; 117 } DEVINTNETIP, *PDEVINTNETIP; 116 } DEVINTNETIP; 117 /** Pointer to the instance data for an Internal Network IP stack. */ 118 typedef DEVINTNETIP *PDEVINTNETIP; 118 119 119 120 … … 121 122 * Global Variables * 122 123 *********************************************************************************************************************************/ 123 124 124 /** 125 125 * Pointer to the (only) instance data in this device. … … 277 277 static DECLCALLBACK(int) devINIPNetworkConfiguration(PPDMDEVINS pDevIns, PDEVINTNETIP pThis, PCFGMNODE pCfg) 278 278 { 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); 281 282 if (RT_FAILURE(rc)) 282 {283 PDMDEV_SET_ERROR(pDevIns, rc,284 N_("Configuration error: Failed to get the \"IP\" value"));285 283 /** @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); 292 288 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); 299 292 if ( RT_FAILURE(rc) 300 293 && 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 306 296 return VINF_SUCCESS; 307 297 } … … 396 386 * Signals the end of lwIP TCPIP initialization. 397 387 * 398 * @note: TCPIP thread, corresponding EMT waiting on semaphore.399 388 * @param arg opaque argument, here the pointer to the PDEVINTNETIP. 389 * @note TCPIP thread, corresponding EMT waiting on semaphore. 400 390 */ 401 391 static DECLCALLBACK(void) devINIPTcpipInitDone(void *arg) … … 405 395 406 396 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)) 413 419 { 414 420 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; 419 423 } 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); 471 444 } 472 445 … … 474 447 /** 475 448 * 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. 477 450 */ 478 451 static DECLCALLBACK(void) devINIPTcpipFiniDone(void *arg) … … 576 549 static DECLCALLBACK(int) devINIPDestruct(PPDMDEVINS pDevIns) 577 550 { 551 PDMDEV_CHECK_VERSIONS_RETURN_QUIET(pDevIns); 552 LogFlow(("devINIPDestruct: pDevIns=%p\n", pDevIns)); 578 553 PDEVINTNETIP pThis = PDMDEVINS_2_DATA(pDevIns, PDEVINTNETIP); 579 580 LogFlow(("%s: pDevIns=%p\n", __FUNCTION__, pDevIns));581 PDMDEV_CHECK_VERSIONS_RETURN_QUIET(pDevIns);582 554 583 555 if (g_pDevINIPData != NULL) … … 601 573 static DECLCALLBACK(int) devINIPConstruct(PPDMDEVINS pDevIns, int iInstance, PCFGMNODE pCfg) 602 574 { 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)); 603 579 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));608 580 609 581 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"));620 582 621 583 /* 622 584 * Init the static parts. 623 585 */ 624 pThis->pszIP = NULL;625 pThis->pszNetmask = NULL;626 pThis->pszGateway = NULL;586 //pThis->pszIP = NULL; 587 //pThis->pszNetmask = NULL; 588 //pThis->pszGateway = NULL; 627 589 /* Pointer to device instance */ 628 590 pThis->pDevIns = pDevIns; … … 638 600 pThis->INetworkConfig.pfnSetLinkState = devINIPSetLinkState; 639 601 602 603 /* 604 * Validate the config. 605 */ 606 PDMDEV_VALIDATE_CONFIG_RETURN(pDevIns, "MAC|IP|IPv6|Netmask|Gateway", ""); 607 640 608 /* 641 609 * Get the configuration settings. 642 610 */ 643 int rc = CFGMR3QueryBytes(pCfg, "MAC", &pThis->MAC, sizeof(pThis->MAC));611 int rc = pHlp->pfnCFGMQueryBytes(pCfg, "MAC", &pThis->MAC, sizeof(pThis->MAC)); 644 612 if (rc == VERR_CFGM_NOT_BYTES) 645 613 { 646 614 char szMAC[64]; 647 rc = CFGMR3QueryString(pCfg, "MAC", &szMAC[0], sizeof(szMAC));615 rc = pHlp->pfnCFGMQueryString(pCfg, "MAC", &szMAC[0], sizeof(szMAC)); 648 616 if (RT_SUCCESS(rc)) 649 617 { … … 652 620 for (uint32_t i = 0; i < 6; i++) 653 621 { 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, 658 624 N_("Configuration error: Invalid \"MAC\" value")); 659 625 char c1 = *macStr++ - '0'; … … 670 636 } 671 637 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")); 674 639 rc = devINIPNetworkConfiguration(pDevIns, pThis, pCfg); 675 640 AssertLogRelRCReturn(rc, rc); … … 707 672 708 673 709 LogFlow((" %s: return %Rrc\n", __FUNCTION__, rc));674 LogFlow(("devINIPConstruct: return %Rrc\n", rc)); 710 675 return rc; 711 676 } … … 732 697 /* .uReserved0 = */ 0, 733 698 /* .szName = */ "IntNetIP", 734 /* .fFlags = */ PDM_DEVREG_FLAGS_DEFAULT_BITS ,699 /* .fFlags = */ PDM_DEVREG_FLAGS_DEFAULT_BITS | PDM_DEVREG_FLAGS_NEW_STYLE, 735 700 /* .fClass = */ PDM_DEVREG_CLASS_VMM_DEV, /* As this is used by the storage devices, it must come earlier. */ 736 701 /* .cMaxInstances = */ 1,
Note:
See TracChangeset
for help on using the changeset viewer.