- Timestamp:
- Feb 11, 2021 2:14:40 AM (4 years ago)
- Location:
- trunk/src/VBox/NetworkServices
- Files:
-
- 3 edited
-
NAT/VBoxNetLwipNAT.cpp (modified) (4 diffs)
-
NetLib/ComHostUtils.cpp (modified) (1 diff)
-
NetLib/utils.h (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/NetworkServices/NAT/VBoxNetLwipNAT.cpp
r87707 r87710 260 260 m_src6.sin6_len = sizeof(m_src6); 261 261 #endif 262 m_ProxyOptions.lomap_desc = NULL; 262 263 m_ProxyOptions.nameservers = NULL; 263 264 … … 277 278 for (PCRTGETOPTDEF pcOpt = &s_aGetOptDef[0]; pcOpt->iShort != 0; ++pcOpt) 278 279 addCommandLineOption(pcOpt); 280 281 m_loOptDescriptor.lomap = NULL; 282 m_loOptDescriptor.num_lomap = 0; 279 283 280 284 LogFlowFuncLeave(); … … 594 598 } 595 599 600 /* Make host's loopback(s) available from inside the natnet */ 601 ipv4LoopbackMapInit(); 596 602 597 603 return VINF_SUCCESS; … … 607 613 int VBoxNetLwipNAT::ipv4LoopbackMapInit() 608 614 { 615 HRESULT hrc; 609 616 int rc; 610 617 611 AddressToOffsetMapping tmp; 612 rc = localMappings(m_net, tmp); 613 if (RT_SUCCESS(rc) && !tmp.empty()) 614 { 615 unsigned long i = 0; 616 for (AddressToOffsetMapping::iterator it = tmp.begin(); 617 it != tmp.end() && i < RT_ELEMENTS(m_lo2off); 618 ++it, ++i) 619 { 620 ip4_addr_set_u32(&m_lo2off[i].loaddr, it->first.u); 621 m_lo2off[i].off = it->second; 622 } 623 618 com::SafeArray<BSTR> aStrLocalMappings; 619 hrc = m_net->COMGETTER(LocalMappings)(ComSafeArrayAsOutParam(aStrLocalMappings)); 620 if (FAILED(hrc)) 621 { 622 reportComError(m_net, "LocalMappings", hrc); 623 return VERR_GENERAL_FAILURE; 624 } 625 626 if (aStrLocalMappings.size() == 0) 627 return VINF_SUCCESS; 628 629 630 /* netmask in host order, to verify the offsets */ 631 uint32_t uMask = RT_N2H_U32(getIpv4Netmask().u); 632 633 634 /* 635 * Process mappings of the form "127.x.y.z=off" 636 */ 637 size_t dst = 0; 638 for (size_t i = 0; i < aStrLocalMappings.size(); ++i) 639 { 640 com::Utf8Str strMapping(aStrLocalMappings[i]); 641 const char *pcszRule = strMapping.c_str(); 642 LogRel(("IPv4 loopback mapping %zu: %s\n", i, pcszRule)); 643 644 RTNETADDRIPV4 Loopback4; 645 char *pszNext; 646 rc = RTNetStrToIPv4AddrEx(pcszRule, &Loopback4, &pszNext); 647 if (RT_FAILURE(rc)) 648 { 649 LogRel(("Failed to parse IPv4 address: %Rra\n", rc)); 650 continue; 651 } 652 653 if (Loopback4.au8[0] != 127) 654 { 655 LogRel(("Not an IPv4 loopback address\n")); 656 continue; 657 } 658 659 if (rc != VWRN_TRAILING_CHARS) 660 { 661 LogRel(("Missing right hand side\n")); 662 continue; 663 } 664 665 pcszRule = RTStrStripL(pszNext); 666 if (*pcszRule != '=') 667 { 668 LogRel(("Invalid rule format\n")); 669 continue; 670 } 671 672 pcszRule = RTStrStripL(pcszRule+1); 673 if (*pszNext == '\0') 674 { 675 LogRel(("Empty right hand side\n")); 676 continue; 677 } 678 679 uint32_t u32Offset; 680 rc = RTStrToUInt32Ex(pcszRule, &pszNext, 10, &u32Offset); 681 if (rc != VINF_SUCCESS && rc != VWRN_TRAILING_SPACES) 682 { 683 LogRel(("Invalid offset\n")); 684 continue; 685 } 686 687 if (u32Offset <= 1 || u32Offset == ~uMask) 688 { 689 LogRel(("Offset maps to a reserved address\n")); 690 continue; 691 } 692 693 if ((u32Offset & uMask) != 0) 694 { 695 LogRel(("Offset exceeds the network size\n")); 696 continue; 697 } 698 699 if (dst >= RT_ELEMENTS(m_lo2off)) 700 { 701 LogRel(("Ignoring the mapping, too many mappings already\n")); 702 continue; 703 } 704 705 ip4_addr_set_u32(&m_lo2off[dst].loaddr, Loopback4.u); 706 m_lo2off[dst].off = u32Offset; 707 ++dst; 708 } 709 710 if (dst > 0) 711 { 624 712 m_loOptDescriptor.lomap = m_lo2off; 625 m_loOptDescriptor.num_lomap = i; 626 m_ProxyOptions.lomap_desc = &m_loOptDescriptor; 713 m_loOptDescriptor.num_lomap = dst; 627 714 } 628 715 -
trunk/src/VBox/NetworkServices/NetLib/ComHostUtils.cpp
r87698 r87710 73 73 74 74 VBOX_LISTENER_DECLARE(NATNetworkListenerImpl) 75 76 77 int localMappings(const ComNatPtr& nat, AddressToOffsetMapping& mapping)78 {79 mapping.clear();80 81 ComBstrArray strs;82 size_t cStrs;83 HRESULT hrc = nat->COMGETTER(LocalMappings)(ComSafeArrayAsOutParam(strs));84 if ( SUCCEEDED(hrc)85 && (cStrs = strs.size()))86 {87 for (size_t i = 0; i < cStrs; ++i)88 {89 char szAddr[17];90 RTNETADDRIPV4 ip4addr;91 char *pszTerm;92 uint32_t u32Off;93 com::Utf8Str strLo2Off(strs[i]);94 const char *pszLo2Off = strLo2Off.c_str();95 96 RT_ZERO(szAddr);97 98 pszTerm = RTStrStr(pszLo2Off, "=");99 100 if ( pszTerm101 && (pszTerm - pszLo2Off) <= INET_ADDRSTRLEN)102 {103 memcpy(szAddr, pszLo2Off, (pszTerm - pszLo2Off));104 int rc = RTNetStrToIPv4Addr(szAddr, &ip4addr);105 if (RT_SUCCESS(rc))106 {107 u32Off = RTStrToUInt32(pszTerm + 1);108 if (u32Off != 0)109 mapping.insert(110 AddressToOffsetMapping::value_type(ip4addr, u32Off));111 }112 }113 }114 }115 else116 return VERR_NOT_FOUND;117 118 return VINF_SUCCESS;119 }120 75 121 76 -
trunk/src/VBox/NetworkServices/NetLib/utils.h
r87698 r87710 34 34 typedef ComPtr<INATNetwork> ComNatPtr; 35 35 typedef com::SafeArray<BSTR> ComBstrArray; 36 37 typedef std::vector<RTNETADDRIPV4> AddressList;38 typedef std::map<RTNETADDRIPV4, int> AddressToOffsetMapping;39 40 41 int localMappings(const ComNatPtr&, AddressToOffsetMapping&);42 36 43 37
Note:
See TracChangeset
for help on using the changeset viewer.

