Changeset 76132 in vbox for trunk/src/VBox/Main/src-server
- Timestamp:
- Dec 10, 2018 3:08:10 PM (6 years ago)
- Location:
- trunk/src/VBox/Main/src-server
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Main/src-server/DHCPServerImpl.cpp
r75819 r76132 467 467 if (aOption == DhcpOpt_Router) 468 468 { 469 m->dhcp.setOption(NetworkServiceRunner::kNsrKeyNeedMain, "on");470 469 m->router = true; 471 470 } … … 788 787 m->dhcp.setOption(DHCPServerRunner::kDsrKeyConfig, m->tempConfigFileName); 789 788 #else /* !VBOX_WITH_DHCPD */ 789 /* Main is needed for NATNetwork */ 790 if (m->router) 791 m->dhcp.setOption(NetworkServiceRunner::kNsrKeyNeedMain, "on"); 792 790 793 /* Commmon Network Settings */ 791 794 m->dhcp.setOption(NetworkServiceRunner::kNsrKeyNetwork, aNetworkName.c_str()); -
trunk/src/VBox/Main/src-server/NATNetworkImpl.cpp
r69500 r76132 643 643 644 644 645 void NATNetwork::i_updateDnsOptions() 646 { 647 RTNETADDRIPV4 networkid, netmask; 648 649 int rc = RTCidrStrToIPv4(m->s.strIPv4NetworkCidr.c_str(), &networkid, &netmask); 650 if (RT_FAILURE(rc)) 651 return; 652 653 ComPtr<IHost> host; 654 if (SUCCEEDED(m->pVirtualBox->COMGETTER(Host)(host.asOutParam()))) 655 { 656 com::Bstr domain; 657 if (SUCCEEDED(host->COMGETTER(DomainName)(domain.asOutParam()))) 658 { 659 if (domain.isNotEmpty()) 660 m->dhcpServer->AddGlobalOption(DhcpOpt_DomainName, domain.raw()); 661 } 662 RTCList<RTCString> lstServers; 663 com::SafeArray<BSTR> nameServers; 664 if (SUCCEEDED(host->COMGETTER(NameServers)(ComSafeArrayAsOutParam(nameServers)))) 665 { 666 size_t cAddresses = nameServers.size(); 667 if (cAddresses) 668 { 669 /* The following code was copied (and adapted a bit) from VBoxNetDhcp::hostDnsServers */ 670 /* 671 * Recent fashion is to run dnsmasq on 127.0.1.1 which we 672 * currently can't map. If that's the only nameserver we've got, 673 * we need to use DNS proxy for VMs to reach it. 674 */ 675 bool fUnmappedLoopback = false; 676 677 for (size_t i = 0; i < nameServers.size(); ++i) 678 { 679 RTNETADDRIPV4 addr; 680 681 com::Utf8Str strNameServerAddress(nameServers[i]); 682 rc = RTNetStrToIPv4Addr(strNameServerAddress.c_str(), &addr); 683 if (RT_FAILURE(rc)) 684 continue; 685 686 if (addr.u == INADDR_ANY) 687 { 688 /* 689 * This doesn't seem to be very well documented except for 690 * RTFS of res_init.c, but INADDR_ANY is a valid value for 691 * for "nameserver". 692 */ 693 addr.u = RT_H2N_U32_C(INADDR_LOOPBACK); 694 } 695 696 if (addr.au8[0] == 127) 697 { 698 settings::NATLoopbackOffsetList::const_iterator it; 699 for (it = m->s.llHostLoopbackOffsetList.begin(); 700 it != m->s.llHostLoopbackOffsetList.end(); ++it) 701 { 702 if (it->strLoopbackHostAddress == strNameServerAddress) 703 { 704 addr.u = RT_H2N_U32(RT_N2H_U32(networkid.u) + it->u32Offset); 705 break; 706 } 707 } 708 if (it == m->s.llHostLoopbackOffsetList.end()) 709 { 710 fUnmappedLoopback = true; 711 continue; 712 } 713 } 714 lstServers.append(RTCStringFmt("%RTnaipv4", addr)); 715 } 716 717 if (lstServers.isEmpty() && fUnmappedLoopback) 718 lstServers.append(RTCStringFmt("%RTnaipv4", networkid.u | RT_H2N_U32_C(1U))); /* proxy */ 719 720 m->dhcpServer->AddGlobalOption(DhcpOpt_DomainNameServer, Bstr(RTCString::join(lstServers, " ")).raw()); 721 } 722 } 723 } 724 } 725 726 645 727 HRESULT NATNetwork::start(const com::Utf8Str &aTrunkType) 646 728 { … … 714 796 } 715 797 716 /* XXX: AddGlobalOption(DhcpOpt_Router,) - enables attachement of DhcpServer to Main. */ 798 #ifdef VBOX_WITH_DHCPD 799 i_updateDnsOptions(); 800 #endif /* VBOX_WITH_DHCPD */ 801 /* XXX: AddGlobalOption(DhcpOpt_Router,) - enables attachement of DhcpServer to Main (no longer true with VBoxNetDhcpd). */ 717 802 m->dhcpServer->AddGlobalOption(DhcpOpt_Router, Bstr(m->IPv4Gateway).raw()); 718 803
Note:
See TracChangeset
for help on using the changeset viewer.