Changeset 43924 in vbox for trunk/src/VBox
- Timestamp:
- Nov 21, 2012 9:05:59 AM (12 years ago)
- svn:sync-xref-src-repo-rev:
- 82236
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Devices/Network/DevINIP.cpp
r43636 r43924 34 34 #include "lwip/pbuf.h" 35 35 #include "lwip/netif.h" 36 #include "ipv4/lwip/ip.h" 36 #ifndef VBOX_WITH_NEW_LWIP 37 # include "ipv4/lwip/ip.h" 38 #else 39 # include "lwip/api.h" 40 # include "lwip/tcp_impl.h" 41 # include "ipv6/lwip/ethip6.h" 42 #endif 37 43 #include "lwip/udp.h" 38 44 #include "lwip/tcp.h" 39 #ifdef VBOX_WITH_NEW_LWIP40 # include "lwip/tcp_impl.h"41 #endif42 45 #include "lwip/tcpip.h" 43 46 #include "lwip/sockets.h" … … 109 112 /** Flag whether the link is up. */ 110 113 bool fLnkUp; 114 /** Flag whether the configuration is IPv6 */ 115 bool fIpv6; 116 /** Static IPv6 address of the interface. */ 117 char *pszIP6; 111 118 } DEVINTNETIP, *PDEVINTNETIP; 112 119 … … 310 317 netif->flags |= NETIF_FLAG_ETHARP; 311 318 netif->flags |= NETIF_FLAG_ETHERNET; 312 #endif 319 if (g_pDevINIPData->fIpv6) 320 { 321 /* @todo: Don't bother user with entering IPv6 address explicitly, 322 * instead what is required here that IPv6 local-address generation ? 323 */ 324 if (!inet6_aton(g_pDevINIPData->pszIP6, &netif->ip6_addr[0])) 325 { 326 PDMDEV_SET_ERROR(g_pDevINIPData->pDevIns, VERR_PDM_DEVINS_UNKNOWN_CFG_VALUES, 327 N_("Configuration error: Invalid \"IPv6\" value")); 328 return ERR_IF; 329 } 330 netif_ip6_addr_set_state(netif, 0, IP6_ADDR_VALID); 331 netif->output_ip6 = ethip6_output; 332 netif->ip6_autoconfig_enabled=1; 333 } 334 else 335 netif->output = lwip_etharp_output; 336 337 #else 313 338 netif->output = devINIPOutput; 339 #endif 314 340 netif->linkoutput = devINIPOutputRaw; 315 341 … … 318 344 LogFlow(("%s: success\n", __FUNCTION__)); 319 345 return ERR_OK; 346 } 347 348 /** 349 * Parses CFGM parameters related to network connection 350 */ 351 static DECLCALLBACK(int) devINIPNetworkConfiguration(PPDMDEVINS pDevIns, PDEVINTNETIP pThis, PCFGMNODE pCfg) 352 { 353 int rc = VINF_SUCCESS; 354 rc = CFGMR3QueryStringAlloc(pCfg, "IP", &pThis->pszIP); 355 if (RT_FAILURE(rc)) 356 { 357 PDMDEV_SET_ERROR(pDevIns, rc, 358 N_("Configuration error: Failed to get the \"IP\" value")); 359 return rc; 360 } 361 #ifdef VBOX_WITH_NEW_LWIP 362 rc = CFGMR3QueryStringAlloc(pCfg, "IPv6", &pThis->pszIP6); 363 if (RT_SUCCESS(rc)) 364 pThis->fIpv6 = true; 365 else if (rc != VERR_CFGM_VALUE_NOT_FOUND) 366 { 367 PDMDEV_SET_ERROR(pDevIns, rc, 368 N_("Configuration error: Failed to get the \"IPv6\" value")); 369 AssertReturn(rc, rc); 370 } 371 #endif 372 rc = CFGMR3QueryStringAlloc(pCfg, "Netmask", &pThis->pszNetmask); 373 if (RT_FAILURE(rc)) 374 { 375 PDMDEV_SET_ERROR(pDevIns, rc, 376 N_("Configuration error: Failed to get the \"Netmask\" value")); 377 return rc; 378 } 379 rc = CFGMR3QueryStringAlloc(pCfg, "Gateway", &pThis->pszGateway); 380 if ( RT_FAILURE(rc) 381 && rc != VERR_CFGM_VALUE_NOT_FOUND) 382 { 383 PDMDEV_SET_ERROR(pDevIns, rc, 384 N_("Configuration error: Failed to get the \"Gateway\" value")); 385 return rc; 386 } 387 return VINF_SUCCESS; 320 388 } 321 389 … … 385 453 struct netif *iface = &g_pDevINIPData->IntNetIF; 386 454 err_t lrc; 455 #ifndef VBOX_WITH_NEW_LWIP 387 456 switch (htons(ethhdr->type)) 388 457 { 389 458 case ETHTYPE_IP: /* IP packet */ 390 #ifndef VBOX_WITH_NEW_LWIP391 459 lwip_pbuf_header(p, -(ssize_t)sizeof(struct eth_hdr)); 392 #endif393 460 lrc = iface->input(p, iface); 394 461 if (lrc) … … 396 463 break; 397 464 case ETHTYPE_ARP: /* ARP packet */ 398 #ifndef VBOX_WITH_NEW_LWIP399 465 lwip_etharp_arp_input(iface, (struct eth_addr *)iface->hwaddr, p); 400 #else401 ethernet_input(p, iface);402 #endif403 466 break; 404 467 default: 405 468 lwip_pbuf_free(p); 406 469 } 470 #else 471 /* We've setup flags NETIF_FLAG_ETHARP and NETIF_FLAG_ETHERNET 472 * so this should be thread-safe. 473 */ 474 tcpip_input(p,iface); 475 #endif 407 476 } 408 477 … … 535 604 netif_set_down(&pThis->IntNetIF); 536 605 netif_remove(&pThis->IntNetIF); 606 tcpip_terminate(); 537 607 #ifndef VBOX_WITH_NEW_LWIP 538 tcpip_terminate();539 608 lwip_sys_sem_wait(pThis->LWIPTcpInitSem); 540 609 lwip_sys_sem_free(pThis->LWIPTcpInitSem); 541 610 #else 542 /* no termination on new lwip ??? Hmmm... */543 611 lwip_sys_sem_wait(&pThis->LWIPTcpInitSem, 0); 544 612 lwip_sys_sem_free(&pThis->LWIPTcpInitSem); … … 578 646 * Validate the config. 579 647 */ 580 if (!CFGMR3AreValuesValid(pCfg, "MAC\0IP\0Netmask\0Gateway\0")) 648 if (!CFGMR3AreValuesValid(pCfg, "MAC\0IP\0" 649 #ifdef VBOX_WITH_NEW_LWIP 650 "IPv6\0" 651 #endif 652 "Netmask\0Gateway\0")) 581 653 { 582 654 rc = PDMDEV_SET_ERROR(pDevIns, VERR_PDM_DEVINS_UNKNOWN_CFG_VALUES, … … 644 716 goto out; 645 717 } 646 rc = CFGMR3QueryStringAlloc(pCfg, "IP", &pThis->pszIP);718 rc = devINIPNetworkConfiguration(pDevIns, pThis, pCfg); 647 719 if (RT_FAILURE(rc)) 648 { 649 PDMDEV_SET_ERROR(pDevIns, rc, 650 N_("Configuration error: Failed to get the \"IP\" value")); 651 goto out; 652 } 653 rc = CFGMR3QueryStringAlloc(pCfg, "Netmask", &pThis->pszNetmask); 654 if (RT_FAILURE(rc)) 655 { 656 PDMDEV_SET_ERROR(pDevIns, rc, 657 N_("Configuration error: Failed to get the \"Netmask\" value")); 658 goto out; 659 } 660 rc = CFGMR3QueryStringAlloc(pCfg, "Gateway", &pThis->pszGateway); 661 if (rc == VERR_CFGM_VALUE_NOT_FOUND) 662 rc = VINF_SUCCESS; 663 if (RT_FAILURE(rc)) 664 { 665 PDMDEV_SET_ERROR(pDevIns, rc, 666 N_("Configuration error: Failed to get the \"Gateway\" value")); 667 goto out; 668 } 720 goto out; 669 721 670 722 /* … … 723 775 memcpy(&gw, &ip, sizeof(gw)); 724 776 } 725 726 777 /* 727 778 * Initialize lwIP.
Note:
See TracChangeset
for help on using the changeset viewer.