Changeset 87620 in vbox for trunk/src/VBox/NetworkServices/NAT
- Timestamp:
- Feb 5, 2021 3:48:44 AM (4 years ago)
- Location:
- trunk/src/VBox/NetworkServices/NAT
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/NetworkServices/NAT/VBoxNetLwipNAT.cpp
r87618 r87620 177 177 int homeInit(); 178 178 int logInit(); 179 int ipv4Init(); 179 180 int eventsInit(); 180 181 … … 239 240 LogFlowFuncEnter(); 240 241 242 RT_ZERO(m_ProxyOptions.ipv4_addr); 243 RT_ZERO(m_ProxyOptions.ipv4_mask); 241 244 m_ProxyOptions.ipv6_enabled = 0; 242 245 m_ProxyOptions.ipv6_defroute = 0; … … 362 365 AssertComRCReturn(hrc, VERR_INTERNAL_ERROR); 363 366 367 /* 368 * Get the settings related to IPv4. 369 */ 370 rc = ipv4Init(); 371 if (RT_FAILURE(rc)) 372 return rc; 373 364 374 365 375 BOOL fIPv6Enabled = FALSE; … … 377 387 m_ProxyOptions.ipv6_defroute = fIPv6DefaultRoute; 378 388 379 380 /*381 * IPv4 source address, if configured.382 */383 com::Utf8Str strSourceIp4;384 rc = getExtraData(strSourceIp4, "SourceIp4");385 if (RT_SUCCESS(rc) && strSourceIp4.isNotEmpty())386 {387 RTNETADDRIPV4 addr;388 rc = RTNetStrToIPv4Addr(strSourceIp4.c_str(), &addr);389 if (RT_SUCCESS(rc))390 {391 m_src4.sin_addr.s_addr = addr.u;392 m_ProxyOptions.src4 = &m_src4;393 394 LogRel(("Will use %RTnaipv4 as IPv4 source address\n",395 m_src4.sin_addr.s_addr));396 }397 else398 {399 LogRel(("Failed to parse \"%s\" IPv4 source address specification\n",400 strSourceIp4.c_str()));401 }402 }403 389 404 390 /* … … 431 417 432 418 433 createRawSock4();434 419 if (fIPv6Enabled) 435 420 createRawSock6(); … … 578 563 579 564 580 /** 581 * Create and register event listeners. 565 /* 566 * Read IPv4 related settings and do necessary initialization. These 567 * settings will be picked up by the proxy on the lwIP thread. See 568 * onLwipTcpIpInit(). 569 */ 570 int VBoxNetLwipNAT::ipv4Init() 571 { 572 HRESULT hrc; 573 int rc; 574 575 AssertReturn(m_net.isNotNull(), VERR_GENERAL_FAILURE); 576 577 /* 578 * IPv4 address and mask. 579 */ 580 com::Bstr bstrIPv4Prefix; 581 hrc = m_net->COMGETTER(Network)(bstrIPv4Prefix.asOutParam()); 582 if (FAILED(hrc)) 583 { 584 reportComError(m_net, "Network", hrc); 585 return VERR_GENERAL_FAILURE; 586 } 587 588 RTNETADDRIPV4 Net4, Mask4; 589 int iPrefixLength; 590 rc = RTNetStrToIPv4Cidr(com::Utf8Str(bstrIPv4Prefix).c_str(), 591 &Net4, &iPrefixLength); 592 if (RT_FAILURE(rc)) 593 { 594 reportError("Failed to parse IPv4 prefix %ls\n", bstrIPv4Prefix.raw()); 595 return rc; 596 } 597 598 if (iPrefixLength > 30) 599 { 600 reportError("IPv4 prefix length %d is too narrow\n", iPrefixLength); 601 return VERR_INVALID_PARAMETER; 602 } 603 604 rc = RTNetPrefixToMaskIPv4(iPrefixLength, &Mask4); 605 AssertRCReturn(rc, rc); 606 AssertReturn(iPrefixLength > 0, VERR_INVALID_PARAMETER); 607 608 RTNETADDRIPV4 Addr4; 609 Addr4.u = Net4.u | RT_H2N_U32_C(0x00000001); 610 611 /* Transitional: check that old and new ways agree */ 612 const RTNETADDRIPV4 &CmdLineAddr4 = getIpv4Address(); 613 AssertReturn(CmdLineAddr4.u == 0 || CmdLineAddr4.u == Addr4.u, 614 VERR_INVALID_PARAMETER); 615 616 const RTNETADDRIPV4 &CmdLineMask4 = getIpv4Netmask(); 617 AssertReturn(CmdLineMask4.u == 0 || CmdLineMask4.u == Mask4.u, 618 VERR_INVALID_PARAMETER); 619 620 memcpy(&m_ProxyOptions.ipv4_addr, &Addr4, sizeof(ip_addr)); 621 memcpy(&m_ProxyOptions.ipv4_mask, &Mask4, sizeof(ip_addr)); 622 623 624 /* 625 * Raw socket for ICMP. 626 */ 627 createRawSock4(); 628 629 630 /* 631 * IPv4 source address (host), if configured. 632 */ 633 com::Utf8Str strSourceIp4; 634 rc = getExtraData(strSourceIp4, "SourceIp4"); 635 if (RT_SUCCESS(rc) && strSourceIp4.isNotEmpty()) 636 { 637 RTNETADDRIPV4 addr; 638 rc = RTNetStrToIPv4Addr(strSourceIp4.c_str(), &addr); 639 if (RT_SUCCESS(rc)) 640 { 641 m_src4.sin_addr.s_addr = addr.u; 642 m_ProxyOptions.src4 = &m_src4; 643 644 LogRel(("Will use %RTnaipv4 as IPv4 source address\n", 645 m_src4.sin_addr.s_addr)); 646 } 647 else 648 { 649 LogRel(("Failed to parse \"%s\" IPv4 source address specification\n", 650 strSourceIp4.c_str())); 651 } 652 } 653 654 return VINF_SUCCESS; 655 } 656 657 658 659 /** 660 * Create and register API event listeners. 582 661 */ 583 662 int VBoxNetLwipNAT::eventsInit() … … 734 813 proxy_ip6_divert_hook = pxremap_ip6_divert; 735 814 736 /* lwip thread */737 RTNETADDRIPV4 network;738 RTNETADDRIPV4 address = self->getIpv4Address();739 RTNETADDRIPV4 netmask = self->getIpv4Netmask();740 network.u = address.u & netmask.u;741 742 ip_addr LwipIpAddr, LwipIpNetMask, LwipIpNetwork;743 744 memcpy(&LwipIpAddr, &address, sizeof(ip_addr));745 memcpy(&LwipIpNetMask, &netmask, sizeof(ip_addr));746 memcpy(&LwipIpNetwork, &network, sizeof(ip_addr));747 748 815 netif *pNetif = netif_add(&self->m_LwipNetIf /* Lwip Interface */, 749 & LwipIpAddr /* IP address*/,750 & LwipIpNetMask /* Network mask */,751 & LwipIpAddr /* gateway address, @todo: is self IP acceptable? */,816 &self->m_ProxyOptions.ipv4_addr, /* IP address*/ 817 &self->m_ProxyOptions.ipv4_mask, /* Network mask */ 818 &self->m_ProxyOptions.ipv4_addr, /* XXX: Gateway address */ 752 819 self /* state */, 753 820 VBoxNetLwipNAT::netifInit /* netif_init_fn */, -
trunk/src/VBox/NetworkServices/NAT/proxy.h
r82968 r87620 51 51 52 52 struct proxy_options { 53 ip_addr_t ipv4_addr; 54 ip_addr_t ipv4_mask; 53 55 int ipv6_enabled; 54 56 int ipv6_defroute;
Note:
See TracChangeset
for help on using the changeset viewer.