Changeset 87396 in vbox for trunk/src/VBox/NetworkServices/NAT
- Timestamp:
- Jan 23, 2021 12:25:40 AM (4 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/NetworkServices/NAT/VBoxNetLwipNAT.cpp
r87394 r87396 481 481 482 482 483 /* 483 /** 484 * Perform lwIP initialization on the lwIP "tcpip" thread. 485 * 486 * The lwIP thread was created in init() and this function is run 487 * before the main lwIP loop is started. It is responsible for 488 * setting up lwIP state, configuring interface(s), etc. 489 a*/ 490 /*static*/ 491 DECLCALLBACK(void) VBoxNetLwipNAT::onLwipTcpIpInit(void *arg) 492 { 493 AssertPtrReturnVoid(arg); 494 VBoxNetLwipNAT *self = static_cast<VBoxNetLwipNAT *>(arg); 495 496 HRESULT hrc = com::Initialize(); 497 AssertComRCReturnVoid(hrc); 498 499 proxy_arp_hook = pxremap_proxy_arp; 500 proxy_ip4_divert_hook = pxremap_ip4_divert; 501 502 proxy_na_hook = pxremap_proxy_na; 503 proxy_ip6_divert_hook = pxremap_ip6_divert; 504 505 /* lwip thread */ 506 RTNETADDRIPV4 network; 507 RTNETADDRIPV4 address = self->getIpv4Address(); 508 RTNETADDRIPV4 netmask = self->getIpv4Netmask(); 509 network.u = address.u & netmask.u; 510 511 ip_addr LwipIpAddr, LwipIpNetMask, LwipIpNetwork; 512 513 memcpy(&LwipIpAddr, &address, sizeof(ip_addr)); 514 memcpy(&LwipIpNetMask, &netmask, sizeof(ip_addr)); 515 memcpy(&LwipIpNetwork, &network, sizeof(ip_addr)); 516 517 netif *pNetif = netif_add(&self->m_LwipNetIf /* Lwip Interface */, 518 &LwipIpAddr /* IP address*/, 519 &LwipIpNetMask /* Network mask */, 520 &LwipIpAddr /* gateway address, @todo: is self IP acceptable? */, 521 self /* state */, 522 VBoxNetLwipNAT::netifInit /* netif_init_fn */, 523 tcpip_input /* netif_input_fn */); 524 525 AssertPtrReturnVoid(pNetif); 526 527 LogRel(("netif %c%c%d: mac %RTmac\n", 528 pNetif->name[0], pNetif->name[1], pNetif->num, 529 pNetif->hwaddr)); 530 LogRel(("netif %c%c%d: inet %RTnaipv4 netmask %RTnaipv4\n", 531 pNetif->name[0], pNetif->name[1], pNetif->num, 532 pNetif->ip_addr, pNetif->netmask)); 533 for (int i = 0; i < LWIP_IPV6_NUM_ADDRESSES; ++i) { 534 if (!ip6_addr_isinvalid(netif_ip6_addr_state(pNetif, i))) { 535 LogRel(("netif %c%c%d: inet6 %RTnaipv6\n", 536 pNetif->name[0], pNetif->name[1], pNetif->num, 537 netif_ip6_addr(pNetif, i))); 538 } 539 } 540 541 netif_set_up(pNetif); 542 netif_set_link_up(pNetif); 543 544 if (self->m_ProxyOptions.ipv6_enabled) { 545 /* 546 * XXX: lwIP currently only ever calls mld6_joingroup() in 547 * nd6_tmr() for fresh tentative addresses, which is a wrong place 548 * to do it - but I'm not keen on fixing this properly for now 549 * (with correct handling of interface up and down transitions, 550 * etc). So stick it here as a kludge. 551 */ 552 for (int i = 0; i <= 1; ++i) { 553 ip6_addr_t *paddr = netif_ip6_addr(pNetif, i); 554 555 ip6_addr_t solicited_node_multicast_address; 556 ip6_addr_set_solicitednode(&solicited_node_multicast_address, 557 paddr->addr[3]); 558 mld6_joingroup(paddr, &solicited_node_multicast_address); 559 } 560 561 /* 562 * XXX: We must join the solicited-node multicast for the 563 * addresses we do IPv6 NA-proxy for. We map IPv6 loopback to 564 * proxy address + 1. We only need the low 24 bits, and those are 565 * fixed. 566 */ 567 { 568 ip6_addr_t solicited_node_multicast_address; 569 570 ip6_addr_set_solicitednode(&solicited_node_multicast_address, 571 /* last 24 bits of the address */ 572 PP_HTONL(0x00000002)); 573 mld6_netif_joingroup(pNetif, &solicited_node_multicast_address); 574 } 575 } 576 577 proxy_init(&self->m_LwipNetIf, &self->m_ProxyOptions); 578 579 natServiceProcessRegisteredPf(self->m_vecPortForwardRule4); 580 natServiceProcessRegisteredPf(self->m_vecPortForwardRule6); 581 } 582 583 584 /** 484 585 * Run the pumps. 485 586 * … … 729 830 730 831 731 /*static*/ DECLCALLBACK(void) VBoxNetLwipNAT::onLwipTcpIpInit(void *arg)732 {733 AssertPtrReturnVoid(arg);734 VBoxNetLwipNAT *self = static_cast<VBoxNetLwipNAT *>(arg);735 736 HRESULT hrc = com::Initialize();737 AssertComRCReturnVoid(hrc);738 739 proxy_arp_hook = pxremap_proxy_arp;740 proxy_ip4_divert_hook = pxremap_ip4_divert;741 742 proxy_na_hook = pxremap_proxy_na;743 proxy_ip6_divert_hook = pxremap_ip6_divert;744 745 /* lwip thread */746 RTNETADDRIPV4 network;747 RTNETADDRIPV4 address = self->getIpv4Address();748 RTNETADDRIPV4 netmask = self->getIpv4Netmask();749 network.u = address.u & netmask.u;750 751 ip_addr LwipIpAddr, LwipIpNetMask, LwipIpNetwork;752 753 memcpy(&LwipIpAddr, &address, sizeof(ip_addr));754 memcpy(&LwipIpNetMask, &netmask, sizeof(ip_addr));755 memcpy(&LwipIpNetwork, &network, sizeof(ip_addr));756 757 netif *pNetif = netif_add(&self->m_LwipNetIf /* Lwip Interface */,758 &LwipIpAddr /* IP address*/,759 &LwipIpNetMask /* Network mask */,760 &LwipIpAddr /* gateway address, @todo: is self IP acceptable? */,761 self /* state */,762 VBoxNetLwipNAT::netifInit /* netif_init_fn */,763 tcpip_input /* netif_input_fn */);764 765 AssertPtrReturnVoid(pNetif);766 767 LogRel(("netif %c%c%d: mac %RTmac\n",768 pNetif->name[0], pNetif->name[1], pNetif->num,769 pNetif->hwaddr));770 LogRel(("netif %c%c%d: inet %RTnaipv4 netmask %RTnaipv4\n",771 pNetif->name[0], pNetif->name[1], pNetif->num,772 pNetif->ip_addr, pNetif->netmask));773 for (int i = 0; i < LWIP_IPV6_NUM_ADDRESSES; ++i) {774 if (!ip6_addr_isinvalid(netif_ip6_addr_state(pNetif, i))) {775 LogRel(("netif %c%c%d: inet6 %RTnaipv6\n",776 pNetif->name[0], pNetif->name[1], pNetif->num,777 netif_ip6_addr(pNetif, i)));778 }779 }780 781 netif_set_up(pNetif);782 netif_set_link_up(pNetif);783 784 if (self->m_ProxyOptions.ipv6_enabled) {785 /*786 * XXX: lwIP currently only ever calls mld6_joingroup() in787 * nd6_tmr() for fresh tentative addresses, which is a wrong place788 * to do it - but I'm not keen on fixing this properly for now789 * (with correct handling of interface up and down transitions,790 * etc). So stick it here as a kludge.791 */792 for (int i = 0; i <= 1; ++i) {793 ip6_addr_t *paddr = netif_ip6_addr(pNetif, i);794 795 ip6_addr_t solicited_node_multicast_address;796 ip6_addr_set_solicitednode(&solicited_node_multicast_address,797 paddr->addr[3]);798 mld6_joingroup(paddr, &solicited_node_multicast_address);799 }800 801 /*802 * XXX: We must join the solicited-node multicast for the803 * addresses we do IPv6 NA-proxy for. We map IPv6 loopback to804 * proxy address + 1. We only need the low 24 bits, and those are805 * fixed.806 */807 {808 ip6_addr_t solicited_node_multicast_address;809 810 ip6_addr_set_solicitednode(&solicited_node_multicast_address,811 /* last 24 bits of the address */812 PP_HTONL(0x00000002));813 mld6_netif_joingroup(pNetif, &solicited_node_multicast_address);814 }815 }816 817 proxy_init(&self->m_LwipNetIf, &self->m_ProxyOptions);818 819 natServiceProcessRegisteredPf(self->m_vecPortForwardRule4);820 natServiceProcessRegisteredPf(self->m_vecPortForwardRule6);821 }822 823 824 832 /*static*/ DECLCALLBACK(void) VBoxNetLwipNAT::onLwipTcpIpFini(void* arg) 825 833 {
Note:
See TracChangeset
for help on using the changeset viewer.