Changeset 55432 in vbox for trunk/src/VBox/Devices/Network/DevINIP.cpp
- Timestamp:
- Apr 27, 2015 3:20:42 AM (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Devices/Network/DevINIP.cpp
r48947 r55432 34 34 #include "lwip/pbuf.h" 35 35 #include "lwip/netif.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 36 #include "lwip/api.h" 37 #include "lwip/tcp_impl.h" 38 # if LWIP_IPV6 39 # include "ipv6/lwip/ethip6.h" 40 # endif 43 41 #include "lwip/udp.h" 44 42 #include "lwip/tcp.h" … … 55 53 56 54 #include "VBoxDD.h" 57 58 #ifdef VBOX_WITH_NEW_LWIP 59 # include "VBoxLwipCore.h" 60 #endif 55 #include "VBoxLwipCore.h" 61 56 62 57 /******************************************************************************* … … 115 110 /** Flag whether the link is up. */ 116 111 bool fLnkUp; 117 #ifndef VBOX_WITH_NEW_LWIP118 /**119 * This hack-flag for spliting initialization logic in devINIPTcpipInitDone,120 * this is the only place when during initialization we can be called from TCPIP121 * thread.122 * This callback used for Initialization and Finalization with old lwip.123 */124 bool fTermination;125 #endif126 112 /** 127 113 * In callback we're getting status of interface adding operation (TCPIP thread), … … 159 145 * Internal Functions * 160 146 *******************************************************************************/ 161 #ifndef VBOX_WITH_NEW_LWIP162 static DECLCALLBACK(void) devINIPARPTimer(PPDMDEVINS pDevIns, PTMTIMER pTimer);163 static DECLCALLBACK(void) devINIPTCPFastTimer(PPDMDEVINS pDevIns, PTMTIMER pTimer);164 static DECLCALLBACK(void) devINIPTCPSlowTimer(PPDMDEVINS pDevIns, PTMTIMER pTimer);165 #endif166 147 static DECLCALLBACK(err_t) devINIPOutput(struct netif *netif, struct pbuf *p, struct ip_addr *ipaddr); 167 148 static DECLCALLBACK(err_t) devINIPOutputRaw(struct netif *netif, struct pbuf *p); 168 149 static DECLCALLBACK(err_t) devINIPInterface(struct netif *netif); 169 150 170 171 #ifndef VBOX_WITH_NEW_LWIP172 /**173 * ARP cache timeout handling for lwIP.174 *175 * @param pDevIns Device instance.176 * @param pTimer Pointer to timer.177 */178 static DECLCALLBACK(void) devINIPARPTimer(PPDMDEVINS pDevIns, PTMTIMER pTimer, void *pvUser)179 {180 PDEVINTNETIP pThis = (PDEVINTNETIP)pvUser;181 LogFlow(("%s: pDevIns=%p pTimer=%p\n", __FUNCTION__, pDevIns, pTimer));182 lwip_etharp_tmr();183 TMTimerSetMillies(pThis->ARPTimer, ARP_TMR_INTERVAL);184 LogFlow(("%s: return\n", __FUNCTION__));185 }186 187 /**188 * TCP fast timer handling for lwIP.189 *190 * @param pDevIns Device instance.191 * @param pTimer Pointer to timer.192 */193 static DECLCALLBACK(void) devINIPTCPFastTimer(PPDMDEVINS pDevIns, PTMTIMER pTimer, void *pvUser)194 {195 PDEVINTNETIP pThis = (PDEVINTNETIP)pvUser;196 LogFlow(("%s: pDevIns=%p pTimer=%p\n", __FUNCTION__, pDevIns, pTimer));197 lwip_tcp_fasttmr();198 TMTimerSetMillies(pThis->TCPFastTimer, TCP_FAST_INTERVAL);199 LogFlow(("%s: return\n", __FUNCTION__));200 }201 202 /**203 * TCP slow timer handling for lwIP.204 *205 * @param pDevIns Device instance.206 * @param pTimer Pointer to timer.207 */208 static DECLCALLBACK(void) devINIPTCPSlowTimer(PPDMDEVINS pDevIns, PTMTIMER pTimer, void *pvUser)209 {210 PDEVINTNETIP pThis = (PDEVINTNETIP)pvUser;211 LogFlow(("%s: pDevIns=%p pTimer=%p\n", __FUNCTION__, pDevIns, pTimer));212 lwip_tcp_slowtmr();213 TMTimerSetMillies(pThis->TCPSlowTimer, TCP_SLOW_INTERVAL);214 LogFlow(("%s: return\n", __FUNCTION__));215 }216 #endif /* VBOX_WITH_NEW_LWIP */217 151 218 152 /** … … 230 164 LogFlow(("%s: netif=%p p=%p ipaddr=%#04x\n", __FUNCTION__, netif, p, 231 165 ipaddr->addr)); 232 #ifndef VBOX_WITH_NEW_LWIP 233 lrc = lwip_etharp_output(netif, ipaddr, p); 234 #else 166 235 167 lrc = lwip_etharp_output(netif, p, ipaddr); 236 #endif 168 237 169 LogFlow(("%s: return %d\n", __FUNCTION__, lrc)); 238 170 return lrc; … … 327 259 netif->mtu = DEVINIP_MAX_FRAME; 328 260 netif->flags = NETIF_FLAG_BROADCAST; 329 #ifdef VBOX_WITH_NEW_LWIP330 /** @todo why explicit ARP routing required for 1.2.0 case? */331 261 netif->flags |= NETIF_FLAG_ETHARP; 332 262 netif->flags |= NETIF_FLAG_ETHERNET; 333 /* Note! We always assign link-local IPv6 address */ 263 264 #if LWIP_IPV6 334 265 netif_create_ip6_linklocal_address(netif, 0); 335 266 netif_ip6_addr_set_state(netif, 0, IP6_ADDR_VALID); … … 337 268 netif->ip6_autoconfig_enabled=1; 338 269 LogFunc(("netif: ipv6:%RTnaipv6\n", &netif->ip6_addr[0].addr[0])); 270 #endif 271 339 272 netif->output = lwip_etharp_output; 340 341 lwip_etharp_init();342 #else343 netif->output = devINIPOutput;344 345 lwip_etharp_init();346 TMTimerSetMillies(g_pDevINIPData->ARPTimer, ARP_TMR_INTERVAL);347 #endif348 273 netif->linkoutput = devINIPOutputRaw; 349 274 … … 452 377 ethhdr = (const struct eth_hdr *)p->payload; 453 378 struct netif *iface = &g_pDevINIPData->IntNetIF; 454 #ifndef VBOX_WITH_NEW_LWIP 455 err_t lrc; 456 switch (htons(ethhdr->type)) 457 { 458 case ETHTYPE_IP: /* IP packet */ 459 lwip_pbuf_header(p, -(ssize_t)sizeof(struct eth_hdr)); 460 lrc = iface->input(p, iface); 461 if (lrc) 462 rc = VERR_NET_IO_ERROR; 463 break; 464 case ETHTYPE_ARP: /* ARP packet */ 465 lwip_etharp_arp_input(iface, (struct eth_addr *)iface->hwaddr, p); 466 break; 467 default: 468 lwip_pbuf_free(p); 469 } 470 #else 379 471 380 /* We've setup flags NETIF_FLAG_ETHARP and NETIF_FLAG_ETHERNET 472 381 so this should be thread-safe. */ 473 382 tcpip_input(p,iface); 474 #endif475 383 } 476 384 … … 500 408 501 409 pThis->rcInitialization = VINF_SUCCESS; 502 #ifndef VBOX_WITH_NEW_LWIP 503 /* see PDEVINTNETIP::fTermination */ 504 if (!pThis->fTermination) 505 { 506 #endif 410 { 507 411 struct netif *ret; 508 412 struct ip_addr ipaddr, netmask, gw; … … 565 469 lwip_netif_set_default(&pThis->IntNetIF); 566 470 lwip_netif_set_up(&pThis->IntNetIF); 567 568 #ifndef VBOX_WITH_NEW_LWIP 569 } 570 done: 571 lwip_sys_sem_signal(pThis->LWIPTcpInitSem); 572 #else 471 } 573 472 done: 574 473 return; 575 #endif 576 } 577 578 #ifdef VBOX_WITH_NEW_LWIP 474 } 475 476 579 477 /** 580 478 * This callback is for finitializing our activity on TCPIP thread. … … 590 488 netif_remove(&pThis->IntNetIF); 591 489 } 592 #endif593 490 594 491 … … 688 585 689 586 if (g_pDevINIPData != NULL) 690 {691 #ifndef VBOX_WITH_NEW_LWIP692 netif_set_down(&pThis->IntNetIF);693 netif_remove(&pThis->IntNetIF);694 pThis->fTermination = true;695 tcpip_terminate();696 lwip_sys_sem_wait(pThis->LWIPTcpInitSem);697 lwip_sys_sem_free(pThis->LWIPTcpInitSem);698 #else699 587 vboxLwipCoreFinalize(devINIPTcpipFiniDone, pThis); 700 #endif701 }702 588 703 589 MMR3HeapFree(pThis->pszIP); … … 720 606 PDEVINTNETIP pThis = PDMINS_2_DATA(pDevIns, PDEVINTNETIP); 721 607 int rc = VINF_SUCCESS; 722 #ifdef VBOX_WITH_NEW_LWIP723 608 err_t errRc = ERR_OK; 724 #endif 609 725 610 LogFlow(("%s: pDevIns=%p iInstance=%d pCfg=%p\n", __FUNCTION__, 726 611 pDevIns, iInstance, pCfg)); … … 733 618 */ 734 619 if (!CFGMR3AreValuesValid(pCfg, "MAC\0IP\0" 735 #ifdef VBOX_WITH_NEW_LWIP736 620 "IPv6\0" 737 #endif738 621 "Netmask\0Gateway\0")) 739 622 return PDMDEV_SET_ERROR(pDevIns, VERR_PDM_DEVINS_UNKNOWN_CFG_VALUES, … … 822 705 * Initialize lwIP. 823 706 */ 824 #ifndef VBOX_WITH_NEW_LWIP825 lwip_stats_init();826 lwip_sys_init();827 # if MEM_LIBC_MALLOC == 0828 lwip_mem_init();829 # endif830 lwip_memp_init();831 lwip_pbuf_init();832 lwip_netif_init();833 rc = PDMDevHlpTMTimerCreate(pDevIns, TMCLOCK_VIRTUAL, devINIPARPTimer, pThis,834 TMTIMER_FLAGS_NO_CRIT_SECT, "lwIP ARP", &pThis->ARPTimer);835 AssertRCReturn(rc, rc);836 rc = PDMDevHlpTMTimerCreate(pDevIns, TMCLOCK_VIRTUAL, devINIPTCPFastTimer, pThis,837 TMTIMER_FLAGS_NO_CRIT_SECT, "lwIP fast TCP", &pThis->TCPFastTimer);838 AssertRCReturn(rc, rc);839 TMTimerSetMillies(pThis->TCPFastTimer, TCP_FAST_INTERVAL);840 rc = PDMDevHlpTMTimerCreate(pDevIns, TMCLOCK_VIRTUAL, devINIPTCPSlowTimer, pThis,841 TMTIMER_FLAGS_NO_CRIT_SECT, "lwIP slow TCP", &pThis->TCPSlowTimer);842 AssertRCReturn(rc, rc);843 TMTimerSetMillies(pThis->TCPFastTimer, TCP_SLOW_INTERVAL);844 845 pThis->LWIPTcpInitSem = lwip_sys_sem_new(0);846 847 lwip_tcpip_init(devINIPTcpipInitDone, pThis);848 lwip_sys_sem_wait(pThis->LWIPTcpInitSem);849 850 #else /* VBOX_WITH_NEW_LWIP */851 707 vboxLwipCoreInitialize(devINIPTcpipInitDone, pThis); 852 #endif853 708 854 709 /* this rc could be updated in devINIPTcpInitDone thread */
Note:
See TracChangeset
for help on using the changeset viewer.