Changeset 81883 in vbox for trunk/src/VBox/Main/src-server
- Timestamp:
- Nov 15, 2019 4:31:00 PM (5 years ago)
- svn:sync-xref-src-repo-rev:
- 134678
- Location:
- trunk/src/VBox/Main/src-server
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Main/src-server/DHCPServerImpl.cpp
r79866 r81883 83 83 /** weak VirtualBox parent */ 84 84 VirtualBox * const pVirtualBox; 85 /** The DHCP server name (network). 86 * @todo Kind of duplicated by networkName, if I understand it correctly. */ 85 /** The DHCP server name (network). */ 87 86 Utf8Str const strName; 88 87 … … 98 97 com::Utf8Str strLogFilename; 99 98 100 com::Utf8Str networkName;101 99 com::Utf8Str trunkName; 102 100 com::Utf8Str trunkType; … … 573 571 hrc = i_doSaveSettings(); 574 572 return hrc; 575 }576 577 578 /**579 * Used by the legacy 6.0 IDHCPServer::GetVmSlotOptions() and580 * IDHCPServer::GetGlobalOptions() implementations.581 *582 * New interfaces have the option number and option encoding separate from the583 * value.584 */585 HRESULT DHCPServer::i_encode60Option(com::Utf8Str &strEncoded, DHCPOption_T enmOption,586 DHCPOptionEncoding_T enmEncoding, const com::Utf8Str &strValue)587 {588 int vrc;589 switch (enmEncoding)590 {591 case DHCPOptionEncoding_Normal:592 {593 /*594 * This is original encoding which assumed that for each595 * option we know its format and so we know how option596 * "value" text is to be interpreted.597 *598 * "2:10800" # integer 32599 * "6:1.2.3.4 8.8.8.8" # array of ip-address600 */601 vrc = strEncoded.printfNoThrow("%d:%s", (int)enmOption, strValue.c_str());602 break;603 }604 605 case DHCPOptionEncoding_Hex:606 {607 /*608 * This is a bypass for any option - preformatted value as609 * hex string with no semantic involved in formatting the610 * value for the DHCP reply.611 *612 * 234=68:65:6c:6c:6f:2c:20:77:6f:72:6c:64613 */614 vrc = strEncoded.printfNoThrow("%d=%s", (int)enmOption, strValue.c_str());615 break;616 }617 618 default:619 {620 /*621 * Try to be forward compatible.622 *623 * "254@42=i hope you know what this means"624 */625 vrc = strEncoded.printfNoThrow("%d@%d=%s", (int)enmOption, (int)enmEncoding, strValue.c_str());626 break;627 }628 }629 return RT_SUCCESS(vrc) ? S_OK : E_OUTOFMEMORY;630 }631 632 633 /**634 * worker for IDHCPServer::GetGlobalOptions.635 */636 HRESULT DHCPServer::i_getAllOptions60(DHCPConfig &aSourceConfig, std::vector<com::Utf8Str> &aValues)637 {638 /* Get the values using the new getter: */639 std::vector<DHCPOption_T> Options;640 std::vector<DHCPOptionEncoding_T> Encodings;641 std::vector<com::Utf8Str> Values;642 HRESULT hrc = aSourceConfig.i_getAllOptions(Options, Encodings, Values);643 if (SUCCEEDED(hrc))644 {645 /* Encoding them using in the 6.0 style: */646 size_t const cValues = Values.size();647 aValues.resize(cValues);648 for (size_t i = 0; i < cValues && SUCCEEDED(hrc); i++)649 hrc = i_encode60Option(aValues[i], Options[i], Encodings[i], Values[i]);650 }651 return hrc;652 }653 654 655 /**656 * Worker for legacy <=6.0 interfaces for adding options.657 *658 * @throws std::bad_alloc659 */660 HRESULT DHCPServer::i_add60Option(DHCPConfig &aTargetConfig, DhcpOpt_T aOption, const com::Utf8Str &aValue)661 {662 if (aOption != 0)663 return aTargetConfig.i_setOption((DHCPOption_T)aOption, DHCPOptionEncoding_Normal, aValue);664 665 /*666 * This is a kludge to sneak in option encoding information667 * through existing API. We use option 0 and supply the real668 * option/value in the same format that i_encode60Option() above669 * produces for getter methods.670 */671 uint8_t u8Code;672 char *pszNext;673 int vrc = RTStrToUInt8Ex(aValue.c_str(), &pszNext, 10, &u8Code);674 if (RT_FAILURE(vrc))675 return setErrorBoth(E_INVALIDARG, VERR_PARSE_ERROR);676 677 DHCPOptionEncoding_T enmEncoding;678 switch (*pszNext)679 {680 case ':': /* support legacy format too */681 {682 enmEncoding = DHCPOptionEncoding_Normal;683 break;684 }685 686 case '=':687 {688 enmEncoding = DHCPOptionEncoding_Hex;689 break;690 }691 692 case '@':693 {694 uint32_t u32Enc = 0;695 vrc = RTStrToUInt32Ex(pszNext + 1, &pszNext, 10, &u32Enc);696 if (RT_FAILURE(vrc))697 return setErrorBoth(E_INVALIDARG, VERR_PARSE_ERROR);698 if (*pszNext != '=')699 return setErrorBoth(E_INVALIDARG, VERR_PARSE_ERROR);700 enmEncoding = (DHCPOptionEncoding_T)u32Enc;701 break;702 }703 704 default:705 return VERR_PARSE_ERROR;706 }707 708 return aTargetConfig.i_setOption((DHCPOption_T)aOption, enmEncoding, com::Utf8Str(pszNext + 1));709 }710 711 712 HRESULT DHCPServer::addGlobalOption(DhcpOpt_T aOption, const com::Utf8Str &aValue)713 {714 return i_add60Option(*m->globalConfig, aOption, aValue);715 }716 717 718 HRESULT DHCPServer::removeGlobalOption(DhcpOpt_T aOption)719 {720 return m->globalConfig->i_removeOption((DHCPOption_T)aOption);721 }722 723 724 HRESULT DHCPServer::removeGlobalOptions()725 {726 return m->globalConfig->i_removeAllOptions();727 }728 729 730 HRESULT DHCPServer::getGlobalOptions(std::vector<com::Utf8Str> &aValues)731 {732 return i_getAllOptions60(*m->globalConfig, aValues);733 }734 735 736 HRESULT DHCPServer::getVmConfigs(std::vector<com::Utf8Str> &aValues)737 {738 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);739 740 try741 {742 aValues.resize(m->individualConfigs.size());743 size_t i = 0;744 for (Data::IndividualConfigIterator it = m->individualConfigs.begin(); it != m->individualConfigs.end(); ++it, i++)745 if (it->second->i_getScope() != DHCPConfigScope_MAC)746 aValues[i].printf("[%RTuuid]:%d", it->second->i_getMachineId().raw(), it->second->i_getSlot());747 else748 aValues[i].printf("[%RTmac]", it->second->i_getMACAddress());749 }750 catch (std::bad_alloc &)751 {752 return E_OUTOFMEMORY;753 }754 755 return S_OK;756 573 } 757 574 … … 876 693 877 694 878 HRESULT DHCPServer::addVmSlotOption(const com::Utf8Str &aVmName, LONG aSlot, DhcpOpt_T aOption, const com::Utf8Str &aValue)879 {880 ComObjPtr<DHCPIndividualConfig> ptrConfig;881 HRESULT hrc = i_vmNameAndSlotToConfig(aVmName, aSlot, true, ptrConfig);882 if (SUCCEEDED(hrc))883 hrc = i_add60Option(*ptrConfig, aOption, aValue);884 return hrc;885 }886 887 888 HRESULT DHCPServer::removeVmSlotOption(const com::Utf8Str &aVmName, LONG aSlot, DhcpOpt_T aOption)889 {890 ComObjPtr<DHCPIndividualConfig> ptrConfig;891 HRESULT hrc = i_vmNameAndSlotToConfig(aVmName, aSlot, false, ptrConfig);892 if (SUCCEEDED(hrc))893 hrc = ptrConfig->i_removeOption((DHCPOption_T)aOption);894 return hrc;895 }896 897 898 HRESULT DHCPServer::removeVmSlotOptions(const com::Utf8Str &aVmName, LONG aSlot)899 {900 ComObjPtr<DHCPIndividualConfig> ptrConfig;901 HRESULT hrc = i_vmNameAndSlotToConfig(aVmName, aSlot, false, ptrConfig);902 if (SUCCEEDED(hrc))903 hrc = ptrConfig->i_removeAllOptions();904 return hrc;905 }906 907 908 HRESULT DHCPServer::getVmSlotOptions(const com::Utf8Str &aVmName, LONG aSlot, std::vector<com::Utf8Str> &aValues)909 {910 ComObjPtr<DHCPIndividualConfig> ptrConfig;911 HRESULT hrc = i_vmNameAndSlotToConfig(aVmName, aSlot, false, ptrConfig);912 if (SUCCEEDED(hrc))913 hrc = i_getAllOptions60(*ptrConfig, aValues);914 else if (hrc == VBOX_E_OBJECT_NOT_FOUND)915 {916 aValues.resize(0);917 hrc = S_OK;918 }919 return hrc;920 }921 922 923 HRESULT DHCPServer::getMacOptions(const com::Utf8Str &aMAC, std::vector<com::Utf8Str> &aOption)924 {925 RT_NOREF(aMAC, aOption);926 AssertFailed();927 return setError(E_NOTIMPL, tr("The GetMacOptions method has been discontinued as it was only supposed to be used by the DHCP server and it does not need it any more. sorry"));928 }929 930 931 695 HRESULT DHCPServer::getEventSource(ComPtr<IEventSource> &aEventSource) 932 696 { … … 1008 772 HRESULT hrc = stop(); 1009 773 if (SUCCEEDED(hrc)) 1010 hrc = start(m-> networkName, m->trunkName, m->trunkType);774 hrc = start(m->trunkName, m->trunkType); 1011 775 return hrc; 1012 776 } … … 1025 789 { 1026 790 xml::ElementNode *pElmRoot = doc.createRootElement("DHCPServer"); 1027 pElmRoot->setAttribute("networkName", m-> networkName);791 pElmRoot->setAttribute("networkName", m->strName); 1028 792 if (m->trunkName.isNotEmpty()) 1029 793 pElmRoot->setAttribute("trunkName", m->trunkName); … … 1081 845 1082 846 1083 /** @todo r=bird: why do we get the network name passed in here? it's the same 1084 * as m->strName, isn't it? */ 1085 HRESULT DHCPServer::start(const com::Utf8Str &aNetworkName, const com::Utf8Str &aTrunkName, const com::Utf8Str &aTrunkType) 847 HRESULT DHCPServer::start(const com::Utf8Str &aTrunkName, const com::Utf8Str &aTrunkType) 1086 848 { 1087 849 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS); … … 1137 899 * Copy the startup parameters. 1138 900 */ 1139 m->networkName = aNetworkName;1140 901 m->trunkName = aTrunkName; 1141 902 m->trunkType = aTrunkType; 1142 HRESULT hrc = i_calcLeasesConfigAndLogFilenames( aNetworkName);903 HRESULT hrc = i_calcLeasesConfigAndLogFilenames(m->strName); 1143 904 if (SUCCEEDED(hrc)) 1144 905 { … … 1153 914 */ 1154 915 m->dhcp.resetArguments(); 1155 int vrc = m->dhcp.addArgPair("--comment", m-> networkName.c_str());916 int vrc = m->dhcp.addArgPair("--comment", m->strName.c_str()); 1156 917 if (RT_SUCCESS(vrc)) 1157 918 vrc = m->dhcp.addArgPair("--config", m->strConfigFilename.c_str()); … … 1213 974 if (m->strLeasesFilename.isEmpty()) 1214 975 { 1215 HRESULT hrc = i_calcLeasesConfigAndLogFilenames(m-> networkName.isEmpty() ? m->strName : m->networkName);976 HRESULT hrc = i_calcLeasesConfigAndLogFilenames(m->strName); 1216 977 if (FAILED(hrc)) 1217 978 return hrc; -
trunk/src/VBox/Main/src-server/NATNetworkImpl.cpp
r79644 r81883 648 648 if (FAILED(host->COMGETTER(DomainName)(domain.asOutParam()))) 649 649 LogRel(("NATNetwork: Failed to get host's domain name\n")); 650 ComPtr<IDHCPGlobalConfig> pDHCPConfig; 651 HRESULT hrc = m->dhcpServer->COMGETTER(GlobalConfig)(pDHCPConfig.asOutParam()); 652 if (FAILED(hrc)) 653 { 654 LogRel(("NATNetwork: Failed to get global DHCP config when updating domain name option with %Rhrc\n", hrc)); 655 return; 656 } 650 657 if (domain.isNotEmpty()) 651 658 { 652 HRESULT hrc = m->dhcpServer->AddGlobalOption(DhcpOpt_DomainName, domain.raw());659 hrc = pDHCPConfig->SetOption(DHCPOption_DomainName, DHCPOptionEncoding_Normal, domain.raw()); 653 660 if (FAILED(hrc)) 654 661 LogRel(("NATNetwork: Failed to add domain name option with %Rhrc\n", hrc)); 655 662 } 656 663 else 657 m->dhcpServer->RemoveGlobalOption(DhcpOpt_DomainName);664 pDHCPConfig->RemoveOption(DHCPOption_DomainName); 658 665 } 659 666 … … 678 685 { 679 686 LogRel(("NATNetwork: Failed to get name servers from host with %Rhrc\n", hrc)); 687 return; 688 } 689 ComPtr<IDHCPGlobalConfig> pDHCPConfig; 690 hrc = m->dhcpServer->COMGETTER(GlobalConfig)(pDHCPConfig.asOutParam()); 691 if (FAILED(hrc)) 692 { 693 LogRel(("NATNetwork: Failed to get global DHCP config when updating domain name server option with %Rhrc\n", hrc)); 680 694 return; 681 695 } … … 735 749 lstServers.append(RTCStringFmt("%RTnaipv4", networkid.u | RT_H2N_U32_C(1U))); /* proxy */ 736 750 737 hrc = m->dhcpServer->AddGlobalOption(DhcpOpt_DomainNameServer, Bstr(RTCString::join(lstServers, " ")).raw());751 hrc = pDHCPConfig->SetOption(DHCPOption_DomainNameServers, DHCPOptionEncoding_Normal, Bstr(RTCString::join(lstServers, " ")).raw()); 738 752 if (FAILED(hrc)) 739 753 LogRel(("NATNetwork: Failed to add domain name server option '%s' with %Rhrc\n", RTCString::join(lstServers, " ").c_str(), hrc)); 740 754 } 741 755 else 742 m->dhcpServer->RemoveGlobalOption(DhcpOpt_DomainNameServer);756 pDHCPConfig->RemoveOption(DHCPOption_DomainNameServers); 743 757 } 744 758 … … 754 768 755 769 756 HRESULT NATNetwork::start( const com::Utf8Str &aTrunkType)770 HRESULT NATNetwork::start() 757 771 { 758 772 #ifdef VBOX_WITH_NAT_SERVICE … … 761 775 762 776 m->NATRunner.addArgPair(NetworkServiceRunner::kpszKeyNetwork, Utf8Str(m->s.strNetworkName).c_str()); 763 m->NATRunner.addArgPair(NetworkServiceRunner::kpszKeyTrunkType, Utf8Str( aTrunkType).c_str());777 m->NATRunner.addArgPair(NetworkServiceRunner::kpszKeyTrunkType, Utf8Str(TRUNKTYPE_WHATEVER).c_str()); 764 778 m->NATRunner.addArgPair(NetworkServiceRunner::kpszIpAddress, Utf8Str(m->IPv4Gateway).c_str()); 765 779 m->NATRunner.addArgPair(NetworkServiceRunner::kpszIpNetmask, Utf8Str(m->IPv4NetworkMask).c_str()); … … 820 834 #endif /* VBOX_WITH_DHCPD */ 821 835 /* XXX: AddGlobalOption(DhcpOpt_Router,) - enables attachement of DhcpServer to Main (no longer true with VBoxNetDhcpd). */ 822 m->dhcpServer->AddGlobalOption(DhcpOpt_Router, Bstr(m->IPv4Gateway).raw()); 823 824 hrc = m->dhcpServer->Start(Bstr(m->s.strNetworkName).raw(), Bstr("").raw(), Bstr(aTrunkType).raw()); 836 ComPtr<IDHCPGlobalConfig> pDHCPConfig; 837 hrc = m->dhcpServer->COMGETTER(GlobalConfig)(pDHCPConfig.asOutParam()); 838 if (FAILED(hrc)) 839 { 840 LogRel(("NATNetwork: Failed to get global DHCP config when updating IPv4 gateway option with %Rhrc\n", hrc)); 841 m->dhcpServer.setNull(); 842 return E_FAIL; 843 } 844 pDHCPConfig->SetOption(DHCPOption_Routers, DHCPOptionEncoding_Normal, Bstr(m->IPv4Gateway).raw()); 845 846 hrc = m->dhcpServer->Start(Bstr::Empty.raw(), Bstr(TRUNKTYPE_WHATEVER).raw()); 825 847 if (FAILED(hrc)) 826 848 { … … 838 860 return E_FAIL; 839 861 #else 840 NOREF(aTrunkType);841 862 ReturnComNotImplemented(); 842 863 #endif -
trunk/src/VBox/Main/src-server/VirtualBoxImpl.cpp
r81710 r81883 1961 1961 strNewCreateFlags += ",directoryIncludesUUID=1"; 1962 1962 1963 com::Utf8Str blstr = "";1963 com::Utf8Str blstr; 1964 1964 rc = composeMachineFilename(aName, 1965 1965 llGroups.front(), … … 3891 3891 if (FAILED(rc)) return -1; 3892 3892 3893 rc = nat->Start( Bstr("whatever").raw());3893 rc = nat->Start(); 3894 3894 if (SUCCEEDED(rc)) 3895 3895 LogRel(("Started NAT network '%s'\n", aNetworkName.c_str()));
Note:
See TracChangeset
for help on using the changeset viewer.