Changeset 44670 in vbox for trunk/src/VBox/Devices
- Timestamp:
- Feb 13, 2013 3:16:23 PM (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Devices/Network/DevINIP.cpp
r44528 r44670 5 5 6 6 /* 7 * Copyright (C) 2007-201 2Oracle Corporation7 * Copyright (C) 2007-2013 Oracle Corporation 8 8 * 9 9 * This file is part of VirtualBox Open Source Edition (OSE), as … … 86 86 PPDMIBASE pDrvBase; 87 87 /** The connector of the network driver below us. */ 88 PPDMINETWORKUP pDrv;88 PPDMINETWORKUP pDrv; 89 89 /** Pointer to the device instance. */ 90 90 PPDMDEVINSR3 pDevIns; … … 145 145 static DECLCALLBACK(void) devINIPTCPFastTimer(PPDMDEVINS pDevIns, PTMTIMER pTimer); 146 146 static DECLCALLBACK(void) devINIPTCPSlowTimer(PPDMDEVINS pDevIns, PTMTIMER pTimer); 147 static DECLCALLBACK(err_t) devINIPOutput(struct netif *netif, struct pbuf *p, 148 struct ip_addr *ipaddr); 149 static DECLCALLBACK(err_t) devINIPOutputRaw(struct netif *netif, 150 struct pbuf *p); 147 static DECLCALLBACK(err_t) devINIPOutput(struct netif *netif, struct pbuf *p, struct ip_addr *ipaddr); 148 static DECLCALLBACK(err_t) devINIPOutputRaw(struct netif *netif, struct pbuf *p); 151 149 static DECLCALLBACK(err_t) devINIPInterface(struct netif *netif); 150 152 151 153 152 /** … … 205 204 * @param ipaddr Destination IP address. 206 205 */ 207 static DECLCALLBACK(err_t) devINIPOutput(struct netif *netif, struct pbuf *p, 208 struct ip_addr *ipaddr) 206 static DECLCALLBACK(err_t) devINIPOutput(struct netif *netif, struct pbuf *p, struct ip_addr *ipaddr) 209 207 { 210 208 err_t lrc; … … 227 225 * @param p Frame data. 228 226 */ 229 static DECLCALLBACK(err_t) devINIPOutputRaw(struct netif *netif, 230 struct pbuf *p) 227 static DECLCALLBACK(err_t) devINIPOutputRaw(struct netif *netif, struct pbuf *p) 231 228 { 232 229 int rc = VINF_SUCCESS; … … 310 307 netif->flags = NETIF_FLAG_BROADCAST; 311 308 #ifdef VBOX_WITH_NEW_LWIP 312 /* @todo:why explicit ARP routing required for 1.2.0 case? */309 /** @todo why explicit ARP routing required for 1.2.0 case? */ 313 310 netif->flags |= NETIF_FLAG_ETHARP; 314 311 netif->flags |= NETIF_FLAG_ETHERNET; 315 /* 316 * @note: we always assign link-local IPv6 address 317 */ 312 /* Note! We always assign link-local IPv6 address */ 318 313 netif_create_ip6_linklocal_address(netif, 0); 319 314 netif_ip6_addr_set_state(netif, 0, IP6_ADDR_VALID); … … 390 385 * @param cb Frame size. 391 386 */ 392 static DECLCALLBACK(int) devINIPNetworkDown_Input(PPDMINETWORKDOWN pInterface, 393 const void *pvBuf, size_t cb) 387 static DECLCALLBACK(int) devINIPNetworkDown_Input(PPDMINETWORKDOWN pInterface, const void *pvBuf, size_t cb) 394 388 { 395 389 const uint8_t *pbBuf = (const uint8_t *)pvBuf; … … 399 393 int rc = VINF_SUCCESS; 400 394 401 LogFlow(("%s: pInterface=%p pvBuf=%p cb=%lu\n", __FUNCTION__, pInterface, 402 pvBuf, cb)); 395 LogFlow(("%s: pInterface=%p pvBuf=%p cb=%lu\n", __FUNCTION__, pInterface, pvBuf, cb)); 403 396 Assert(g_pDevINIPData); 404 397 Assert(g_pDevINIPData->pDrv); … … 406 399 /* Silently ignore packets being received while lwIP isn't set up. */ 407 400 if (!g_pDevINIPData) 408 goto out; 401 { 402 LogFlow(("%s: return %Rrc (no global)\n", __FUNCTION__, rc)); 403 return VINF_SUCCESS; 404 } 409 405 410 406 #if ETH_PAD_SIZE … … 449 445 } 450 446 #else 451 /* We've setup flags NETIF_FLAG_ETHARP and NETIF_FLAG_ETHERNET 452 * so this should be thread-safe. 453 */ 454 tcpip_input(p,iface); 447 /* We've setup flags NETIF_FLAG_ETHARP and NETIF_FLAG_ETHERNET 448 so this should be thread-safe. */ 449 tcpip_input(p,iface); 455 450 #endif 456 451 } … … 594 589 } 595 590 596 if (pThis->pszIP)597 MMR3HeapFree(pThis->pszIP);598 if (pThis->pszNetmask)599 MMR3HeapFree(pThis->pszNetmask);600 if (pThis->pszGateway)601 MMR3HeapFree(pThis->pszGateway);591 MMR3HeapFree(pThis->pszIP); 592 pThis->pszIP = NULL; 593 MMR3HeapFree(pThis->pszNetmask); 594 pThis->pszNetmask = NULL; 595 MMR3HeapFree(pThis->pszGateway); 596 pThis->pszGateway = NULL; 602 597 603 598 LogFlow(("%s: success\n", __FUNCTION__)); … … 609 604 * @interface_method_impl{PDMDEVREG,pfnConstruct} 610 605 */ 611 static DECLCALLBACK(int) devINIPConstruct(PPDMDEVINS pDevIns, int iInstance, 612 PCFGMNODE pCfg) 606 static DECLCALLBACK(int) devINIPConstruct(PPDMDEVINS pDevIns, int iInstance, PCFGMNODE pCfg) 613 607 { 614 608 PDEVINTNETIP pThis = PDMINS_2_DATA(pDevIns, PDEVINTNETIP); … … 631 625 #endif 632 626 "Netmask\0Gateway\0")) 633 { 634 rc = PDMDEV_SET_ERROR(pDevIns, VERR_PDM_DEVINS_UNKNOWN_CFG_VALUES, 635 N_("Unknown Internal Networking IP configuration option")); 636 goto out; 637 } 627 return PDMDEV_SET_ERROR(pDevIns, VERR_PDM_DEVINS_UNKNOWN_CFG_VALUES, 628 N_("Unknown Internal Networking IP configuration option")); 638 629 639 630 /* … … 672 663 if ( !*macStr || !*(macStr + 1) 673 664 || *macStr == ':' || *(macStr + 1) == ':') 674 { 675 rc = PDMDEV_SET_ERROR(pDevIns, 676 VERR_PDM_DEVINS_UNKNOWN_CFG_VALUES, 677 N_("Configuration error: Invalid \"MAC\" value")); 678 goto out; 679 } 665 return PDMDEV_SET_ERROR(pDevIns, 666 VERR_PDM_DEVINS_UNKNOWN_CFG_VALUES, 667 N_("Configuration error: Invalid \"MAC\" value")); 680 668 char c1 = *macStr++ - '0'; 681 669 if (c1 > 9) … … 691 679 } 692 680 if (RT_FAILURE(rc)) 693 { 694 PDMDEV_SET_ERROR(pDevIns, rc, 695 N_("Configuration error: Failed to get the \"MAC\" value")); 696 goto out; 697 } 681 return PDMDEV_SET_ERROR(pDevIns, rc, 682 N_("Configuration error: Failed to get the \"MAC\" value")); 698 683 rc = devINIPNetworkConfiguration(pDevIns, pThis, pCfg); 699 if (RT_FAILURE(rc)) 700 goto out; 684 AssertLogRelRCReturn(rc, rc); 701 685 702 686 /* 703 687 * Attach driver and query the network connector interface. 704 688 */ 705 rc = PDMDevHlpDriverAttach(pDevIns, 0, &pThis->IBase, &pThis->pDrvBase, 706 "Network Port"); 689 rc = PDMDevHlpDriverAttach(pDevIns, 0, &pThis->IBase, &pThis->pDrvBase, "Network Port"); 707 690 if (RT_FAILURE(rc)) 708 691 { 709 692 pThis->pDrvBase = NULL; 710 693 pThis->pDrv = NULL; 711 goto out; 712 } 713 else 714 { 715 pThis->pDrv = PDMIBASE_QUERY_INTERFACE(pThis->pDrvBase, PDMINETWORKUP); 716 if (!pThis->pDrv) 717 { 718 AssertMsgFailed(("Failed to obtain the PDMINETWORKUP interface!\n")); 719 rc = VERR_PDM_MISSING_INTERFACE_BELOW; 720 goto out; 721 } 722 } 694 return PDMDEV_SET_ERROR(pDevIns, rc, N_("Error attaching device below us")); 695 } 696 pThis->pDrv = PDMIBASE_QUERY_INTERFACE(pThis->pDrvBase, PDMINETWORKUP); 697 AssertMsgReturn(pThis->pDrv, ("Failed to obtain the PDMINETWORKUP interface!\n"), VERR_PDM_MISSING_INTERFACE_BELOW); 723 698 724 699 struct ip_addr ipaddr, netmask, gw; … … 726 701 727 702 if (!inet_aton(pThis->pszIP, &ip)) 728 { 729 rc = PDMDEV_SET_ERROR(pDevIns, VERR_PDM_DEVINS_UNKNOWN_CFG_VALUES, 730 N_("Configuration error: Invalid \"IP\" value")); 731 goto out; 732 } 703 return PDMDEV_SET_ERROR(pDevIns, VERR_PDM_DEVINS_UNKNOWN_CFG_VALUES, 704 N_("Configuration error: Invalid \"IP\" value")); 733 705 memcpy(&ipaddr, &ip, sizeof(ipaddr)); 734 706 if (!inet_aton(pThis->pszNetmask, &ip)) 735 { 736 rc = PDMDEV_SET_ERROR(pDevIns, VERR_PDM_DEVINS_UNKNOWN_CFG_VALUES, 737 N_("Configuration error: Invalid \"Netmask\" value")); 738 goto out; 739 } 707 return PDMDEV_SET_ERROR(pDevIns, VERR_PDM_DEVINS_UNKNOWN_CFG_VALUES, 708 N_("Configuration error: Invalid \"Netmask\" value")); 740 709 memcpy(&netmask, &ip, sizeof(netmask)); 741 710 if (pThis->pszGateway) 742 711 { 743 712 if (!inet_aton(pThis->pszGateway, &ip)) 744 { 745 rc = PDMDEV_SET_ERROR(pDevIns, 746 VERR_PDM_DEVINS_UNKNOWN_CFG_VALUES, 747 N_("Configuration error: Invalid \"Gateway\" value")); 748 goto out; 749 } 713 return PDMDEV_SET_ERROR(pDevIns, VERR_PDM_DEVINS_UNKNOWN_CFG_VALUES, 714 N_("Configuration error: Invalid \"Gateway\" value")); 750 715 memcpy(&gw, &ip, sizeof(gw)); 751 716 } … … 755 720 memcpy(&gw, &ip, sizeof(gw)); 756 721 } 722 757 723 /* 758 724 * Initialize lwIP. … … 768 734 rc = PDMDevHlpTMTimerCreate(pDevIns, TMCLOCK_VIRTUAL, devINIPARPTimer, pThis, 769 735 TMTIMER_FLAGS_NO_CRIT_SECT, "lwIP ARP", &pThis->ARPTimer); 770 if (RT_FAILURE(rc)) 771 goto out; 736 AssertRCReturn(rc, rc); 772 737 rc = PDMDevHlpTMTimerCreate(pDevIns, TMCLOCK_VIRTUAL, devINIPTCPFastTimer, pThis, 773 738 TMTIMER_FLAGS_NO_CRIT_SECT, "lwIP fast TCP", &pThis->TCPFastTimer); 774 if (RT_FAILURE(rc)) 775 goto out; 739 AssertRCReturn(rc, rc); 776 740 TMTimerSetMillies(pThis->TCPFastTimer, TCP_FAST_INTERVAL); 777 741 rc = PDMDevHlpTMTimerCreate(pDevIns, TMCLOCK_VIRTUAL, devINIPTCPSlowTimer, pThis, 778 742 TMTIMER_FLAGS_NO_CRIT_SECT, "lwIP slow TCP", &pThis->TCPSlowTimer); 779 if (RT_FAILURE(rc)) 780 goto out; 743 AssertRCReturn(rc, rc); 781 744 TMTimerSetMillies(pThis->TCPFastTimer, TCP_SLOW_INTERVAL); 782 745 #ifndef VBOX_WITH_NEW_LWIP … … 807 770 devINIPInterface, lwip_tcpip_input); 808 771 if (!ret) 809 { 810 rc = VERR_NET_NO_NETWORK; 811 goto out; 812 } 772 return PDMDEV_SET_ERROR(pDevIns, VERR_NET_NO_NETWORK, N_("netif_add failed")); 813 773 814 774 lwip_netif_set_default(&pThis->IntNetIF); … … 818 778 pThis->pLinkHack = g_pDevINILinkHack; 819 779 820 out:821 780 LogFlow(("%s: return %Rrc\n", __FUNCTION__, rc)); 822 781 return rc;
Note:
See TracChangeset
for help on using the changeset viewer.