- Timestamp:
- Jul 6, 2013 5:31:11 PM (12 years ago)
- Location:
- trunk
- Files:
-
- 13 edited
- 2 moved
Legend:
- Unmodified
- Added
- Removed
-
trunk/include/VBox/settings.h
r46969 r47018 286 286 typedef std::list<MachineRegistryEntry> MachinesRegistry; 287 287 288 typedef std::map<DhcpOpt_T, com::Utf8Str> DhcpOptionMap; 289 typedef DhcpOptionMap::value_type DhcpOptValuePair; 290 typedef DhcpOptionMap::iterator DhcpOptIterator; 291 typedef DhcpOptionMap::const_iterator DhcpOptConstIterator; 292 293 typedef struct VmNameSlotKey 294 { 295 VmNameSlotKey(const com::Utf8Str& aVmName, LONG aSlot): VmName(aVmName), 296 Slot(aSlot){} 297 const com::Utf8Str VmName; 298 LONG Slot; 299 bool operator< (const VmNameSlotKey& that) const 300 { 301 if (VmName == that.VmName) 302 return Slot < that.Slot; 303 else return VmName < that.VmName; 304 } 305 } VmNameSlotKey; 306 typedef std::map<VmNameSlotKey, DhcpOptionMap> VmSlot2OptionsMap; 307 typedef VmSlot2OptionsMap::value_type VmSlot2OptionsPair; 308 typedef VmSlot2OptionsMap::iterator VmSlot2OptionsIterator; 309 typedef VmSlot2OptionsMap::const_iterator VmSlot2OptionsConstIterator; 310 288 311 struct DHCPServer 289 312 { … … 294 317 com::Utf8Str strNetworkName, 295 318 strIPAddress, 296 strIPNetworkMask,297 319 strIPLower, 298 320 strIPUpper; 299 321 bool fEnabled; 322 std::map<DhcpOpt_T, com::Utf8Str> GlobalDhcpOptions; 323 VmSlot2OptionsMap VmSlot2OptionsM; 300 324 }; 301 325 typedef std::list<DHCPServer> DHCPServersList; … … 337 361 void readMachineRegistry(const xml::ElementNode &elmMachineRegistry); 338 362 void readDHCPServers(const xml::ElementNode &elmDHCPServers); 363 void readDhcpOptions(DhcpOptionMap& map, const xml::ElementNode& options); 339 364 void readNATNetworks(const xml::ElementNode &elmNATNetworks); 340 365 -
trunk/src/VBox/Main/Makefile.kmk
r46969 r47018 335 335 src-server/BIOSSettingsImpl.cpp \ 336 336 src-server/DHCPServerImpl.cpp \ 337 src-server/ DHCPServerRunner.cpp \337 src-server/NetworkServiceRunner.cpp \ 338 338 src-server/NATNetworkImpl.cpp \ 339 $(if $(VBOX_WITH_NAT_SERVICE),src-server/NATNetworkServiceRunner.cpp,) \340 339 src-server/GuestOSTypeImpl.cpp \ 341 340 src-server/HostImpl.cpp \ -
trunk/src/VBox/Main/idl/VirtualBox.xidl
r46969 r47018 1466 1466 </interface> 1467 1467 1468 <enum 1469 name="DhcpOpt" 1470 uuid="40d99bd3-3ece-44d2-a07e-1085fe9c4f0b"> 1471 <const name="SubnetMask" value="1"/> 1472 <const name="TimeOffset" value="2"/> 1473 <const name="Router" value="3"/> 1474 <const name="TimeServer" value="4"/> 1475 <const name="NameServer" value="5"/> 1476 <const name="DomainNameServer" value="6"/> 1477 <const name="LogServer" value="7"/> 1478 <const name="Cookie" value="8"/> 1479 <const name="LPRServer" value="9"/> 1480 <const name="ImpressServer" value="10"/> 1481 <const name="ResourseLocationServer" value="11"/> 1482 <const name="HostName" value="12"/> 1483 <const name="BootFileSize" value="13"/> 1484 <const name="MeritDumpFile" value="14"/> 1485 <const name="DomainName" value="15"/> 1486 <const name="SwapServer" value="16"/> 1487 <const name="RootPath" value="17"/> 1488 <const name="ExtensionPath" value="18"/> 1489 <const name="IPForwardingEnableDisable" value="19"/> 1490 <const name="NonLocalSourceRoutingEnableDisable" value="20"/> 1491 <const name="PolicyFilter" value="21"/> 1492 <const name="MaximumDatagramReassemblySize" value="22"/> 1493 <const name="DefaultIPTime2Live" value="23"/> 1494 <const name="PathMTUAgingTimeout" value="24"/> 1495 <const name="IPLayerParametersPerInterface" value="25"/> 1496 <const name="InterfaceMTU" value="26"/> 1497 <const name="AllSubnetsAreLocal" value="27"/> 1498 <const name="BroadcastAddress" value="28"/> 1499 <const name="PerformMaskDiscovery" value="29"/> 1500 <const name="MaskSupplier" value="30"/> 1501 <const name="PerformRouteDiscovery" value="31"/> 1502 <const name="RouterSolicitationAddress" value="32"/> 1503 <const name="StaticRoute" value="33"/> 1504 <const name="TrailerEncapsulation" value="34"/> 1505 <const name="ARPCacheTimeout" value="35"/> 1506 <const name="EthernetEncapsulation" value="36"/> 1507 <const name="TCPDefaultTTL" value="37"/> 1508 <const name="TCPKeepAliveInterval" value="38"/> 1509 <const name="TCPKeepAliveGarbage" value="39"/> 1510 <const name="NetworkInformationServiceDomain" value="40"/> 1511 <const name="NetworkInformationServiceServers" value="41"/> 1512 <const name="NetworkTimeProtocolServers" value="42"/> 1513 <const name="VendorSpecificInformation" value="43"/> 1514 <const name="Option_44" value="44"/> 1515 <const name="Option_45" value="45"/> 1516 <const name="Option_46" value="46"/> 1517 <const name="Option_47" value="47"/> 1518 <const name="Option_48" value="48"/> 1519 <const name="Option_49" value="49"/> 1520 <const name="IPAddressLeaseTime" value="51"/> 1521 <const name="Option_64" value="64"/> 1522 <const name="Option_65" value="65"/> 1523 <const name="TFTPServerName" value="66"/> 1524 <const name="BootfileName" value="67"/> 1525 <const name="Option_68" value="68"/> 1526 <const name="Option_69" value="69"/> 1527 <const name="Option_70" value="70"/> 1528 <const name="Option_71" value="71"/> 1529 <const name="Option_72" value="72"/> 1530 <const name="Option_73" value="73"/> 1531 <const name="Option_74" value="74"/> 1532 <const name="Option_75" value="75"/> 1533 <const name="Option_119" value="119"/> 1534 </enum> 1535 1468 1536 <interface 1469 1537 name="IDHCPServer" extends="$unknown" 1470 uuid=" 6cfe387c-74fb-4ca7-bff6-973bec8af7a3"1538 uuid="ff0774c5-1f62-4bc3-919c-7fc942bf1d25" 1471 1539 wsmap="managed" 1472 1540 > … … 1477 1545 <link to="IVirtualBox::DHCPServers"/> attribute. 1478 1546 </desc> 1479 1547 <!-- We want to keep our "real" servers updated about configuration changes --> 1548 <attribute name="eventSource" type="IEventSource" readonly="yes"/> 1480 1549 <attribute name="enabled" type="boolean"> 1481 1550 <desc> … … 1513 1582 </desc> 1514 1583 </attribute> 1584 1585 <method name="addGlobalOption"> 1586 <param name="option" type="DhcpOpt" dir="in"/> 1587 <param name="value" type="wstring" dir="in" /> 1588 </method> 1589 1590 <!-- string in format: "option_id:value" --> 1591 <attribute name="globalOptions" type="wstring" safearray="yes" readonly="yes"/> 1592 1593 <!-- string in format: "[vm name]:slot" --> 1594 <attribute name="vmConfigs" type="wstring" safearray="yes" readonly="yes"/> 1595 1596 <!-- VM-slot settings 1597 It's corresponds to dhcpd.conf entries, like: 1598 1599 host ncd1 { hardware ethernet 0:c0:c3:11:90:23; } 1600 1601 - in Main we can match (vm name, slot) to ethernet address 1602 that why it's easy to configure dhcp server in such way, 1603 then ask user to to enter valid name, 1604 1605 - mac address might change because of adapter type (e1k <-> pcnet) or because 1606 of import/export 1607 1608 - it's easy to provide vm-name.rom in boot filename VM with network boot. 1609 1610 XXX: do we need classic getOptionValueByMAC? 1611 1612 XML: O-o-oh, this settings are per VM, so perhaps they should be stored in 1613 VM configuration files. And we haven't got the attachment type for 1614 NATNetwork. 1615 --> 1616 <method name="addVmSlotOption"> 1617 <param name="vmname" type="wstring" dir="in"/> 1618 <param name="slot" type="long" dir="in"/> 1619 <param name="option" type="DhcpOpt" dir="in"/> 1620 <param name="value" type="wstring" dir="in" /> 1621 </method> 1622 1623 <method name="removeVmSlotOptions"> 1624 <param name="vmname" type="wstring" dir="in"/> 1625 <param name="slot" type="long" dir="in"/> 1626 </method> 1627 1628 <!-- returns array of strings in format: "option_id:value" for a given pair (vm, slot) --> 1629 <method name="getVmSlotOptions"> 1630 <param name="vmname" type="wstring" dir="in"/> 1631 <param name="slot" type="long" dir="in"/> 1632 <param name="option" type="wstring" safearray="yes" dir="return"/> 1633 </method> 1634 1635 <!-- Returns options by MAC address --> 1636 <method name="getMacOptions"> 1637 <param name="mac" type="wstring" dir="in"/> 1638 <param name="option" type="wstring" safearray="yes" dir="return"/> 1639 </method> 1515 1640 1516 1641 <method name="setConfiguration"> … … 4264 4389 This setting determines the filename VirtualBox uses to save 4265 4390 the recorded content. This setting cannot be changed while video 4266 capturing is enabled. 4391 capturing is enabled. 4267 4392 <note> 4268 4393 When setting this attribute, the specified path has to be … … 8038 8163 <interface 8039 8164 name="IHost" extends="$unknown" 8040 uuid=" 30678943-32df-4830-b413-931b25ac86a0"8165 uuid="a6107246-f939-42c4-82b6-8aca40327b6d" 8041 8166 wsmap="managed" 8042 8167 > … … 8099 8224 <attribute name="networkInterfaces" type="IHostNetworkInterface" safearray="yes" readonly="yes"> 8100 8225 <desc>List of host network interfaces currently defined on the host.</desc> 8226 </attribute> 8227 8228 <attribute name="nameServers" type="wstring" safearray="yes" readonly="yes"> 8229 <desc> The list of nameservers registered in host's name resolving system.</desc> 8230 </attribute> 8231 8232 <attribute name="domainName" type="wstring" readonly="yes"> 8233 <desc>Domain name used for name resoving.</desc> 8234 </attribute> 8235 8236 <attribute name="searchStrings" type="wstring" safearray="yes" readonly="yes"> 8237 <desc>Search string registered for name resoving.</desc> 8101 8238 </attribute> 8102 8239 -
trunk/src/VBox/Main/include/DHCPServerImpl.h
r46969 r47018 30 30 { 31 31 struct DHCPServer; 32 struct VmNameSlotKey; 32 33 } 34 #ifdef RT_OS_WINDOWS 35 # define DHCP_EXECUTABLE_NAME "VBoxNetDHCP.exe" 36 #else 37 # define DHCP_EXECUTABLE_NAME "VBoxNetDHCP" 38 #endif 39 40 class DHCPServerRunner: public NetworkServiceRunner 41 { 42 public: 43 DHCPServerRunner():NetworkServiceRunner(DHCP_EXECUTABLE_NAME){} 44 virtual ~DHCPServerRunner(){}; 45 }; 46 47 /** 48 * for server configuration needs, it's perhaps better to use (VM,slot) pair 49 * (vm-name, slot) <----> (MAC) 50 * 51 * but for client configuration, when server will have MACs at hand, it'd be 52 * easier to requiest options by MAC. 53 * (MAC) <----> (option-list) 54 * 55 * Doubts: What should be done if MAC changed for (vm-name, slot), when syncing should? 56 * XML: serialization of dependecy (DHCP options) - (VM,slot) shouldn't be done via MAC in 57 * the middle. 58 */ 59 60 typedef std::map<DhcpOpt_T, com::Utf8Str> DhcpOptionMap; 61 typedef DhcpOptionMap::value_type DhcpOptValuePair; 62 typedef DhcpOptionMap::const_iterator DhcpOptConstIterator; 63 typedef DhcpOptionMap::iterator DhcpOptIterator; 64 65 typedef std::map<settings::VmNameSlotKey, DhcpOptionMap> VmSlot2OptionsMap; 66 typedef VmSlot2OptionsMap::value_type VmSlot2OptionsPair; 67 typedef VmSlot2OptionsMap::iterator VmSlot2OptionsIterator; 68 33 69 34 70 class ATL_NO_VTABLE DHCPServer : … … 70 106 STDMETHOD(COMGETTER(UpperIP))(BSTR *aIPAddress); 71 107 108 STDMETHOD(AddGlobalOption)(DhcpOpt_T aOption, IN_BSTR aValue); 109 STDMETHOD(COMGETTER(GlobalOptions))(ComSafeArrayOut(BSTR, aValue)); 110 STDMETHOD(COMGETTER(VmConfigs))(ComSafeArrayOut(BSTR, aValue)); 111 STDMETHOD(AddVmSlotOption)(IN_BSTR aVmName, LONG aSlot, DhcpOpt_T aOption, IN_BSTR aValue); 112 STDMETHOD(RemoveVmSlotOptions)(IN_BSTR aVmName, LONG aSlot); 113 STDMETHOD(GetVmSlotOptions)(IN_BSTR aVmName, LONG aSlot, ComSafeArrayOut(BSTR, aValues)); 114 STDMETHOD(GetMacOptions)(IN_BSTR aMAC, ComSafeArrayOut(BSTR, aValues)); 115 STDMETHOD(COMGETTER(EventSource))(IEventSource **aEventSource); 116 72 117 STDMETHOD(SetConfiguration)(IN_BSTR aIPAddress, IN_BSTR aNetworkMask, IN_BSTR aFromIPAddress, IN_BSTR aToIPAddress); 73 118 … … 86 131 87 132 Bstr IPAddress; 88 Bstr networkMask;89 133 Bstr lowerIP; 90 134 Bstr upperIP; 135 91 136 BOOL enabled; 137 DHCPServerRunner dhcp; 92 138 93 DHCPServerRunner dhcp; 139 DhcpOptionMap GlobalDhcpOptions; 140 VmSlot2OptionsMap VmSlot2Options; 94 141 } m; 95 142 143 DhcpOptionMap& findOptMapByVmNameSlot(const com::Utf8Str& aVmName, 144 LONG Slot); 96 145 }; 97 146 -
trunk/src/VBox/Main/include/HostImpl.h
r46969 r47018 62 62 STDMETHOD(COMGETTER(USBDeviceFilters))(ComSafeArrayOut(IHostUSBDeviceFilter *, aUSBDeviceFilters)); 63 63 STDMETHOD(COMGETTER(NetworkInterfaces))(ComSafeArrayOut(IHostNetworkInterface *, aNetworkInterfaces)); 64 STDMETHOD(COMGETTER(NameServers))(ComSafeArrayOut(BSTR, aNameServers)); 65 STDMETHOD(COMGETTER(DomainName))(BSTR *aDomainName); 66 STDMETHOD(COMGETTER(SearchStrings))(ComSafeArrayOut(BSTR, aSearchStrings)); 64 67 STDMETHOD(COMGETTER(ProcessorCount))(ULONG *count); 65 68 STDMETHOD(COMGETTER(ProcessorOnlineCount))(ULONG *count); … … 147 150 HRESULT updateNetIfList(); 148 151 152 #ifndef RT_OS_WINDOWS 153 HRESULT parseResolvConf(); 154 #else 155 HRESULT fetchNameResolvingInformation(); 156 #endif 157 149 158 #ifdef VBOX_WITH_RESOURCE_USAGE_API 150 159 void registerMetrics(PerformanceCollector *aCollector); -
trunk/src/VBox/Main/include/NATNetworkImpl.h
r46969 r47018 37 37 } 38 38 39 #ifdef RT_OS_WINDOWS 40 # define NATSR_EXECUTABLE_NAME "VBoxNetLwipNAT.exe" 41 #else 42 # define NATSR_EXECUTABLE_NAME "VBoxNetLwipNAT" 43 #endif 44 45 class NATNetworkServiceRunner: public NetworkServiceRunner 46 { 47 public: 48 NATNetworkServiceRunner(): NetworkServiceRunner(NATSR_EXECUTABLE_NAME){} 49 virtual ~NATNetworkServiceRunner(){} 50 }; 39 51 40 52 class ATL_NO_VTABLE NATNetwork : … … 82 94 STDMETHOD(COMGETTER(Network))(BSTR *aIPNetwork); 83 95 STDMETHOD(COMSETTER(Network))(IN_BSTR aIPNetwork); 84 96 85 97 STDMETHOD(COMGETTER(IPv6Enabled))(BOOL *aEnabled); 86 98 STDMETHOD(COMSETTER(IPv6Enabled))(BOOL aEnabled); 87 99 88 100 STDMETHOD(COMGETTER(IPv6Prefix))(BSTR *aName); 89 101 STDMETHOD(COMSETTER(IPv6Prefix))(IN_BSTR aName); … … 91 103 STDMETHOD(COMGETTER(AdvertiseDefaultIPv6RouteEnabled))(BOOL *aEnabled); 92 104 STDMETHOD(COMSETTER(AdvertiseDefaultIPv6RouteEnabled))(BOOL aEnabled); 93 105 94 106 STDMETHOD(COMGETTER(NeedDhcpServer))(BOOL *aEnabled); 95 107 STDMETHOD(COMSETTER(NeedDhcpServer))(BOOL aEnabled); 96 108 97 109 STDMETHOD(COMGETTER(PortForwardRules4))(ComSafeArrayOut(BSTR, aPortForwardRules4)); 98 110 STDMETHOD(COMGETTER(PortForwardRules6))(ComSafeArrayOut(BSTR, aPortForwardRules6)); 99 111 100 STDMETHOD(AddPortForwardRule)(BOOL aIsIpv6, 101 IN_BSTR aPortForwardRuleName, 112 STDMETHOD(AddPortForwardRule)(BOOL aIsIpv6, 113 IN_BSTR aPortForwardRuleName, 102 114 NATProtocol_T aProto, 103 115 IN_BSTR aHostIp, -
trunk/src/VBox/Main/include/NetworkServiceRunner.h
r47017 r47018 23 23 typedef enum 24 24 { 25 DHCPCFG_NAME = 1, 26 DHCPCFG_NETNAME, 27 DHCPCFG_TRUNKTYPE, 28 DHCPCFG_TRUNKNAME, 29 DHCPCFG_MACADDRESS, 30 DHCPCFG_IPADDRESS, 31 DHCPCFG_LEASEDB, 32 DHCPCFG_VERBOSE, 33 DHCPCFG_GATEWAY, 34 DHCPCFG_LOWERIP, 35 DHCPCFG_UPPERIP, 36 DHCPCFG_NETMASK, 37 DHCPCFG_HELP, 38 DHCPCFG_VERSION, 39 DHCPCFG_BEGINCONFIG, 40 DHCPCFG_NOTOPT_MAXVAL 41 }DHCPCFG; 25 NETCFG_NAME = 1, 26 NETCFG_NETNAME, 27 NETCFG_TRUNKTYPE, 28 NETCFG_TRUNKNAME, 29 NETCFG_MACADDRESS, 30 NETCFG_IPADDRESS, 31 NETCFG_NETMASK, 32 NETCFG_VERBOSE, 33 NETCFG_NOTOPT_MAXVAL 34 }NETCFG; 42 35 43 36 #define TRUNKTYPE_WHATEVER "whatever" … … 46 39 #define TRUNKTYPE_SRVNAT "srvnat" 47 40 48 class DHCPServerRunner41 class NetworkServiceRunner 49 42 { 50 43 public: 51 DHCPServerRunner(); 52 ~DHCPServerRunner() { stop(); /* don't leave abandoned servers */} 44 NetworkServiceRunner(const char *aProcName): 45 mProcName(aProcName), 46 mProcess(NIL_RTPROCESS) 47 { 48 memset(mOptionEnabled, 0, sizeof(mOptionEnabled)); 49 }; 50 ~NetworkServiceRunner() { stop(); /* don't leave abandoned servers */} 53 51 54 int setOption( DHCPCFG opt, const char *val, bool enabled)52 int setOption(NETCFG opt, const char *val, bool enabled) 55 53 { 56 if (opt == 0 || opt >= DHCPCFG_NOTOPT_MAXVAL)54 if (opt == 0 || opt >= NETCFG_NOTOPT_MAXVAL) 57 55 return VERR_INVALID_PARAMETER; 58 56 if (isRunning()) … … 64 62 } 65 63 66 int setOption( DHCPCFG opt, const com::Utf8Str &val, bool enabled)64 int setOption(NETCFG opt, const com::Utf8Str &val, bool enabled) 67 65 { 68 66 return setOption(opt, val.c_str(), enabled); … … 75 73 void detachFromServer(); 76 74 private: 77 com::Utf8Str mOptions[DHCPCFG_NOTOPT_MAXVAL]; 78 bool mOptionEnabled[DHCPCFG_NOTOPT_MAXVAL]; 75 com::Utf8Str mOptions[NETCFG_NOTOPT_MAXVAL]; 76 bool mOptionEnabled[NETCFG_NOTOPT_MAXVAL]; 77 const char *mProcName; 79 78 RTPROCESS mProcess; 80 79 }; -
trunk/src/VBox/Main/src-client/ConsoleImpl2.cpp
r46969 r47018 115 115 #endif /* VBOX_WITH_NETFLT */ 116 116 117 #include " DHCPServerRunner.h"117 #include "NetworkServiceRunner.h" 118 118 #include "BusAssignmentManager.h" 119 119 #ifdef VBOX_WITH_EXTPACK -
trunk/src/VBox/Main/src-server/DHCPServerImpl.cpp
r46969 r47018 18 18 */ 19 19 20 #include " DHCPServerRunner.h"20 #include "NetworkServiceRunner.h" 21 21 #include "DHCPServerImpl.h" 22 22 #include "AutoCaller.h" … … 25 25 #include <iprt/cpp/utils.h> 26 26 27 #include <VBox/com/array.h> 27 28 #include <VBox/settings.h> 28 29 … … 37 38 } 38 39 40 39 41 DHCPServer::~DHCPServer() 40 42 { 41 43 } 42 44 45 43 46 HRESULT DHCPServer::FinalConstruct() 44 47 { … … 46 49 } 47 50 51 48 52 void DHCPServer::FinalRelease() 49 53 { … … 52 56 BaseFinalRelease(); 53 57 } 58 54 59 55 60 void DHCPServer::uninit() … … 63 68 } 64 69 70 65 71 HRESULT DHCPServer::init(VirtualBox *aVirtualBox, IN_BSTR aName) 66 72 { … … 75 81 unconst(mName) = aName; 76 82 m.IPAddress = "0.0.0.0"; 77 m. networkMask = "0.0.0.0";83 m.GlobalDhcpOptions.insert(DhcpOptValuePair(DhcpOpt_SubnetMask, Bstr("0.0.0.0"))); 78 84 m.enabled = FALSE; 85 79 86 m.lowerIP = "0.0.0.0"; 80 87 m.upperIP = "0.0.0.0"; … … 85 92 return S_OK; 86 93 } 94 87 95 88 96 HRESULT DHCPServer::init(VirtualBox *aVirtualBox, … … 98 106 unconst(mName) = data.strNetworkName; 99 107 m.IPAddress = data.strIPAddress; 100 m.networkMask = data.strIPNetworkMask;101 108 m.enabled = data.fEnabled; 102 109 m.lowerIP = data.strIPLower; 103 110 m.upperIP = data.strIPUpper; 104 111 112 m.GlobalDhcpOptions.clear(); 113 m.GlobalDhcpOptions.insert(data.GlobalDhcpOptions.begin(), 114 data.GlobalDhcpOptions.end()); 115 116 m.VmSlot2Options.clear(); 117 m.VmSlot2Options.insert(data.VmSlot2OptionsM.begin(), 118 data.VmSlot2OptionsM.end()); 119 105 120 autoInitSpan.setSucceeded(); 106 121 107 122 return S_OK; 108 123 } 124 109 125 110 126 HRESULT DHCPServer::saveSettings(settings::DHCPServer &data) … … 117 133 data.strNetworkName = mName; 118 134 data.strIPAddress = m.IPAddress; 119 data.strIPNetworkMask = m.networkMask; 135 120 136 data.fEnabled = !!m.enabled; 121 137 data.strIPLower = m.lowerIP; 122 138 data.strIPUpper = m.upperIP; 123 139 124 return S_OK; 125 } 140 data.GlobalDhcpOptions.clear(); 141 data.GlobalDhcpOptions.insert(m.GlobalDhcpOptions.begin(), 142 m.GlobalDhcpOptions.end()); 143 144 data.VmSlot2OptionsM.clear(); 145 data.VmSlot2OptionsM.insert(m.VmSlot2Options.begin(), 146 m.VmSlot2Options.end()); 147 148 return S_OK; 149 } 150 126 151 127 152 STDMETHODIMP DHCPServer::COMGETTER(NetworkName) (BSTR *aName) … … 137 162 } 138 163 164 139 165 STDMETHODIMP DHCPServer::COMGETTER(Enabled) (BOOL *aEnabled) 140 166 { … … 148 174 return S_OK; 149 175 } 176 150 177 151 178 STDMETHODIMP DHCPServer::COMSETTER(Enabled) (BOOL aEnabled) … … 165 192 } 166 193 194 167 195 STDMETHODIMP DHCPServer::COMGETTER(IPAddress) (BSTR *aIPAddress) 168 196 { … … 177 205 } 178 206 207 179 208 STDMETHODIMP DHCPServer::COMGETTER(NetworkMask) (BSTR *aNetworkMask) 180 209 { … … 184 213 if (FAILED(autoCaller.rc())) return autoCaller.rc(); 185 214 186 m.networkMask.cloneTo(aNetworkMask); 187 188 return S_OK; 189 } 215 m.GlobalDhcpOptions[DhcpOpt_SubnetMask].cloneTo(aNetworkMask); 216 217 return S_OK; 218 } 219 190 220 191 221 STDMETHODIMP DHCPServer::COMGETTER(LowerIP) (BSTR *aIPAddress) … … 201 231 } 202 232 233 203 234 STDMETHODIMP DHCPServer::COMGETTER(UpperIP) (BSTR *aIPAddress) 204 235 { … … 212 243 return S_OK; 213 244 } 245 214 246 215 247 STDMETHODIMP DHCPServer::SetConfiguration (IN_BSTR aIPAddress, IN_BSTR aNetworkMask, IN_BSTR aLowerIP, IN_BSTR aUpperIP) … … 225 257 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS); 226 258 m.IPAddress = aIPAddress; 227 m.networkMask = aNetworkMask; 259 m.GlobalDhcpOptions[DhcpOpt_SubnetMask] = aNetworkMask; 260 228 261 m.lowerIP = aLowerIP; 229 262 m.upperIP = aUpperIP; … … 235 268 } 236 269 270 271 STDMETHODIMP DHCPServer::AddGlobalOption(DhcpOpt_T aOption, IN_BSTR aValue) 272 { 273 CheckComArgStr(aValue); 274 /* store global option */ 275 AutoCaller autoCaller(this); 276 if (FAILED(autoCaller.rc())) return autoCaller.rc(); 277 278 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS); 279 280 m.GlobalDhcpOptions.insert( 281 DhcpOptValuePair(aOption, Utf8Str(aValue))); 282 283 alock.release(); 284 285 AutoWriteLock vboxLock(mVirtualBox COMMA_LOCKVAL_SRC_POS); 286 return mVirtualBox->saveSettings(); 287 } 288 289 290 STDMETHODIMP DHCPServer::COMGETTER(GlobalOptions)(ComSafeArrayOut(BSTR, aValue)) 291 { 292 CheckComArgOutSafeArrayPointerValid(aValue); 293 294 AutoCaller autoCaller(this); 295 if (FAILED(autoCaller.rc())) return autoCaller.rc(); 296 297 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS); 298 299 SafeArray<BSTR> sf(m.GlobalDhcpOptions.size()); 300 int i = 0; 301 302 for (DhcpOptIterator it = m.GlobalDhcpOptions.begin(); 303 it != m.GlobalDhcpOptions.end(); ++it) 304 { 305 Bstr(Utf8StrFmt("%d:%s", (*it).first, (*it).second.c_str())).detachTo(&sf[i]); 306 i++; 307 } 308 309 sf.detachTo(ComSafeArrayOutArg(aValue)); 310 311 return S_OK; 312 } 313 314 315 STDMETHODIMP DHCPServer::COMGETTER(VmConfigs)(ComSafeArrayOut(BSTR, aValue)) 316 { 317 CheckComArgOutSafeArrayPointerValid(aValue); 318 319 AutoCaller autoCaller(this); 320 if (FAILED(autoCaller.rc())) return autoCaller.rc(); 321 322 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS); 323 324 SafeArray<BSTR> sf(m.VmSlot2Options.size()); 325 VmSlot2OptionsIterator it = m.VmSlot2Options.begin(); 326 int i = 0; 327 for (;it != m.VmSlot2Options.end(); ++it) 328 { 329 Bstr(Utf8StrFmt("[%s]:%d", 330 it->first.VmName.c_str(), 331 it->first.Slot)).detachTo(&sf[i]); 332 i++; 333 } 334 335 sf.detachTo(ComSafeArrayOutArg(aValue)); 336 337 return S_OK; 338 } 339 340 341 STDMETHODIMP DHCPServer::AddVmSlotOption(IN_BSTR aVmName, LONG aSlot, DhcpOpt_T aOption, IN_BSTR aValue) 342 { 343 AutoCaller autoCaller(this); 344 if (FAILED(autoCaller.rc())) return autoCaller.rc(); 345 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS); 346 347 m.VmSlot2Options[settings::VmNameSlotKey( 348 com::Utf8Str(aVmName), 349 aSlot)][aOption] = com::Utf8Str(aValue); 350 351 352 alock.release(); 353 354 AutoWriteLock vboxLock(mVirtualBox COMMA_LOCKVAL_SRC_POS); 355 return mVirtualBox->saveSettings(); 356 } 357 358 359 STDMETHODIMP DHCPServer::RemoveVmSlotOptions(IN_BSTR aVmName, LONG aSlot) 360 { 361 AutoCaller autoCaller(this); 362 if (FAILED(autoCaller.rc())) return autoCaller.rc(); 363 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS); 364 365 DhcpOptionMap& map = findOptMapByVmNameSlot(com::Utf8Str(aVmName), aSlot); 366 367 map.clear(); 368 369 alock.release(); 370 371 AutoWriteLock vboxLock(mVirtualBox COMMA_LOCKVAL_SRC_POS); 372 return mVirtualBox->saveSettings(); 373 } 374 375 376 /** 377 * this is mapping (vm, slot) 378 */ 379 STDMETHODIMP DHCPServer::GetVmSlotOptions(IN_BSTR aVmName, 380 LONG aSlot, 381 ComSafeArrayOut(BSTR, aValues)) 382 { 383 CheckComArgOutSafeArrayPointerValid(aValues); 384 AutoCaller autoCaller(this); 385 if (FAILED(autoCaller.rc())) return autoCaller.rc(); 386 387 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS); 388 389 DhcpOptionMap& map = findOptMapByVmNameSlot(com::Utf8Str(aVmName), aSlot); 390 391 SafeArray<BSTR> sf(map.size()); 392 int i = 0; 393 394 for (DhcpOptIterator it = map.begin(); 395 it != map.end(); ++it) 396 { 397 Bstr(Utf8StrFmt("%d:%s", (*it).first, (*it).second.c_str())).detachTo(&sf[i]); 398 i++; 399 } 400 401 sf.detachTo(ComSafeArrayOutArg(aValues)); 402 403 return S_OK; 404 } 405 406 407 STDMETHODIMP DHCPServer::GetMacOptions(IN_BSTR aMAC, ComSafeArrayOut(BSTR, aValues)) 408 { 409 CheckComArgOutSafeArrayPointerValid(aValues); 410 411 AutoCaller autoCaller(this); 412 if (FAILED(autoCaller.rc())) return autoCaller.rc(); 413 414 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS); 415 HRESULT hrc; 416 417 ComPtr<IMachine> machine; 418 ComPtr<INetworkAdapter> nic; 419 420 VmSlot2OptionsIterator it; 421 for(it = m.VmSlot2Options.begin(); 422 it != m.VmSlot2Options.end(); 423 ++it) 424 { 425 426 alock.release(); 427 hrc = mVirtualBox->FindMachine(Bstr(it->first.VmName).raw(), machine.asOutParam()); 428 alock.acquire(); 429 430 if (FAILED(hrc)) 431 continue; 432 433 alock.release(); 434 hrc = machine->GetNetworkAdapter(it->first.Slot, nic.asOutParam()); 435 alock.acquire(); 436 437 if (FAILED(hrc)) 438 continue; 439 440 com::Bstr mac; 441 442 alock.release(); 443 hrc = nic->COMGETTER(MACAddress)(mac.asOutParam()); 444 alock.acquire(); 445 446 if (FAILED(hrc)) /* no MAC address ??? */ 447 break; 448 449 if (!RTStrICmp(com::Utf8Str(mac).c_str(), com::Utf8Str(aMAC).c_str())) 450 return GetVmSlotOptions(Bstr(it->first.VmName).raw(), 451 it->first.Slot, 452 ComSafeArrayOutArg(aValues)); 453 } /* end of for */ 454 455 return hrc; 456 } 457 458 459 STDMETHODIMP DHCPServer::COMGETTER(EventSource)(IEventSource **aEventSource) 460 { 461 ReturnComNotImplemented(); 462 } 463 464 237 465 STDMETHODIMP DHCPServer::Start(IN_BSTR aNetworkName, IN_BSTR aTrunkName, IN_BSTR aTrunkType) 238 466 { … … 241 469 return S_OK; 242 470 243 m.dhcp.setOption(DHCPCFG_NETNAME, Utf8Str(aNetworkName), true); 471 /* Commmon Network Settings */ 472 m.dhcp.setOption(NETCFG_NETNAME, Utf8Str(aNetworkName), true); 473 244 474 Bstr tmp(aTrunkName); 475 245 476 if (!tmp.isEmpty()) 246 m.dhcp.setOption( DHCPCFG_TRUNKNAME, Utf8Str(tmp), true);247 m.dhcp.setOption( DHCPCFG_TRUNKTYPE, Utf8Str(aTrunkType), true);248 //temporary hack for testing 249 / / DHCPCFG_NAME477 m.dhcp.setOption(NETCFG_TRUNKNAME, Utf8Str(tmp), true); 478 m.dhcp.setOption(NETCFG_TRUNKTYPE, Utf8Str(aTrunkType), true); 479 480 /* XXX: should this MAC default initialization moved to NetworkServiceRunner? */ 250 481 char strMAC[32]; 251 482 Guid guid; 252 483 guid.create(); 253 484 RTStrPrintf (strMAC, sizeof(strMAC), "08:00:27:%02X:%02X:%02X", 254 guid.raw()->au8[0], guid.raw()->au8[1], guid.raw()->au8[2]); 255 m.dhcp.setOption(DHCPCFG_MACADDRESS, strMAC, true); 256 m.dhcp.setOption(DHCPCFG_IPADDRESS, Utf8Str(m.IPAddress), true); 257 // DHCPCFG_LEASEDB, 258 // DHCPCFG_VERBOSE, 259 // DHCPCFG_GATEWAY, 260 m.dhcp.setOption(DHCPCFG_LOWERIP, Utf8Str(m.lowerIP), true); 261 m.dhcp.setOption(DHCPCFG_UPPERIP, Utf8Str(m.upperIP), true); 262 m.dhcp.setOption(DHCPCFG_NETMASK, Utf8Str(m.networkMask), true); 263 264 // DHCPCFG_HELP, 265 // DHCPCFG_VERSION, 266 // DHCPCFG_NOTOPT_MAXVAL 267 m.dhcp.setOption(DHCPCFG_BEGINCONFIG, "", true); 268 485 guid.raw()->au8[0], 486 guid.raw()->au8[1], 487 guid.raw()->au8[2]); 488 m.dhcp.setOption(NETCFG_MACADDRESS, strMAC, true); 489 m.dhcp.setOption(NETCFG_IPADDRESS, Utf8Str(m.IPAddress), true); 490 m.dhcp.setOption(NETCFG_NETMASK, Utf8Str(m.GlobalDhcpOptions[DhcpOpt_SubnetMask]), true); 491 492 /* XXX: This parameters Dhcp Server will fetch via API */ 269 493 return RT_FAILURE(m.dhcp.start()) ? E_FAIL : S_OK; 270 494 //m.dhcp.detachFromServer(); /* need to do this to avoid server shutdown on runner destruction */ 271 495 } 272 496 497 273 498 STDMETHODIMP DHCPServer::Stop (void) 274 499 { 275 500 return RT_FAILURE(m.dhcp.stop()) ? E_FAIL : S_OK; 276 501 } 502 503 504 DhcpOptionMap& DHCPServer::findOptMapByVmNameSlot(const com::Utf8Str& aVmName, 505 LONG aSlot) 506 { 507 return m.VmSlot2Options[settings::VmNameSlotKey( 508 com::Utf8Str(aVmName), 509 aSlot)]; 510 } -
trunk/src/VBox/Main/src-server/HostImpl.cpp
r46969 r47018 134 134 #include <iprt/mem.h> 135 135 #include <iprt/system.h> 136 #ifndef RT_OS_WINDOWS 137 # include <iprt/path.h> 138 #endif 136 139 #ifdef RT_OS_SOLARIS 137 # include <iprt/path.h>138 140 # include <iprt/ctype.h> 139 141 #endif … … 215 217 216 218 HostPowerService *pHostPowerService; 219 220 /* Name resolving */ 221 std::list<com::Bstr> llNameServers; 222 std::list<com::Bstr> llSearchStrings; 223 Bstr DomainName; 224 /* XXX: we need timestamp when these values were set, on repeate in some 225 * (~1h?, 5 min?) period, this values should be refetched from host syetem. 226 */ 217 227 }; 218 228 229 #ifndef RT_OS_WINDOWS 230 static char g_aszResolvConf[RTPATH_MAX]; 231 232 static inline char *getResolvConfPath() 233 { 234 int rc = VINF_SUCCESS; 235 if (!g_aszResolvConf[0]) return g_aszResolvConf; 236 # ifdef RT_OS_OS2 237 /* 238 * This was in an old Slirp code: 239 * IBM's "Technical Document # - 16070238", clearly says \MPTN\ETC\RESOLV2 240 * no redolv.conf (remark to code in old Slirp code) 241 */ 242 if (RTEnvExists("ETC")) 243 { 244 RTStrmPrintf(g_aszResolvConf, MAX_PATH, "%/RESOLV2", RTEnvGet("ETC")); 245 rc = RTFileExists(g_aszResolvConf); 246 if (RT_SUCCESS(rc)) 247 return g_aszResolvConf; 248 } 249 250 RT_ZERO(g_aszResolvConf); 251 RTStrmPrintf(g_aszResolvConf, MAX_PATH, "%/RESOLV2", _PATH_ETC); 252 # else 253 strcmp(g_aszResolvConf, "/etc/resolv.conf"); 254 # endif 255 return g_aszResolvConf; 256 } 257 #endif 219 258 220 259 //////////////////////////////////////////////////////////////////////////////// … … 797 836 #endif 798 837 } 838 839 840 /** 841 * This method return the list of registered name servers 842 */ 843 STDMETHODIMP Host::COMGETTER(NameServers)(ComSafeArrayOut(BSTR, aNameServers)) 844 { 845 return E_NOTIMPL; 846 } 847 848 849 /** 850 * This method returns the domain name of the host 851 */ 852 STDMETHODIMP Host::COMGETTER(DomainName)(BSTR *aDomainName) 853 { 854 return E_NOTIMPL; 855 } 856 857 858 /** 859 * This method returns the search string. 860 */ 861 STDMETHODIMP Host::COMGETTER(SearchStrings)(ComSafeArrayOut(BSTR, aSearchStrings)) 862 { 863 return E_NOTIMPL; 864 } 865 799 866 800 867 STDMETHODIMP Host::COMGETTER(USBDeviceFilters)(ComSafeArrayOut(IHostUSBDeviceFilter*, aUSBDeviceFilters)) -
trunk/src/VBox/Main/src-server/NATNetworkImpl.cpp
r46969 r47018 18 18 */ 19 19 20 #include " DHCPServerRunner.h"20 #include "NetworkServiceRunner.h" 21 21 #include "DHCPServerImpl.h" 22 22 #include "NATNetworkImpl.h" … … 35 35 #include "VBoxEvents.h" 36 36 37 #include "NATNetworkServiceRunner.h"38 37 #include "VirtualBoxImpl.h" 39 38 … … 44 43 struct NATNetwork::Data 45 44 { 46 Data() : 47 45 Data() : 46 48 47 fEnabled(FALSE), 49 48 fIPv6Enabled(FALSE), … … 128 127 m->fEnabled = FALSE; 129 128 130 131 129 130 132 131 RecalculateIpv4AddressAssignments(); 133 132 … … 137 136 hrc = m->pEventSource->init(static_cast<INATNetwork *>(this)); 138 137 if (FAILED(hrc)) throw hrc; 139 138 140 139 /* Confirm a successful initialization */ 141 140 autoInitSpan.setSucceeded(); … … 185 184 hrc = m->pEventSource->init(static_cast<INATNetwork *>(this)); 186 185 if (FAILED(hrc)) throw hrc; 187 186 188 187 autoInitSpan.setSucceeded(); 189 188 … … 206 205 data.fIPv6 = RT_BOOL(m->fIPv6Enabled); 207 206 data.strIPv6Prefix = m->IPv6Prefix; 208 207 209 208 /* saving ipv4 port-forward Rules*/ 210 209 data.llPortForwardRules4.clear(); … … 221 220 /* XXX: should we do here a copy of params */ 222 221 /* XXX: should we unlock here? */ 223 mVirtualBox->onNATNetworkSetting(mName.raw(), 222 mVirtualBox->onNATNetworkSetting(mName.raw(), 224 223 data.fEnabled ? TRUE : FALSE, 225 224 m->IPv4NetworkCidr.raw(), 226 m->IPv4Gateway.raw(), 225 m->IPv4Gateway.raw(), 227 226 data.fAdvertiseDefaultIPv6Route ? TRUE : FALSE, 228 227 data.fNeedDhcpServer ? TRUE : FALSE); … … 485 484 486 485 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS); 487 GetPortForwardRulesFromMap(ComSafeArrayInArg(aPortForwardRules4), 486 GetPortForwardRulesFromMap(ComSafeArrayInArg(aPortForwardRules4), 488 487 m->mapName2PortForwardRule4); 489 488 alock.release(); … … 491 490 } 492 491 493 STDMETHODIMP NATNetwork::COMGETTER(PortForwardRules6)(ComSafeArrayOut(BSTR, 492 STDMETHODIMP NATNetwork::COMGETTER(PortForwardRules6)(ComSafeArrayOut(BSTR, 494 493 aPortForwardRules6)) 495 494 { … … 504 503 } 505 504 506 STDMETHODIMP NATNetwork::AddPortForwardRule(BOOL aIsIpv6, 507 IN_BSTR aPortForwardRuleName, 505 STDMETHODIMP NATNetwork::AddPortForwardRule(BOOL aIsIpv6, 506 IN_BSTR aPortForwardRuleName, 508 507 NATProtocol_T aProto, 509 508 IN_BSTR aHostIp, … … 533 532 } 534 533 if (name.isEmpty()) 535 name = Utf8StrFmt("%s_[%s]%%%d_[%s]%%%d", proto.c_str(), 534 name = Utf8StrFmt("%s_[%s]%%%d_[%s]%%%d", proto.c_str(), 536 535 Utf8Str(aHostIp).c_str(), aHostPort, 537 536 Utf8Str(aGuestIp).c_str(), aGuestPort); … … 561 560 562 561 alock.release(); 563 mVirtualBox->onNATNetworkPortForward(mName.raw(), TRUE, aIsIpv6, 564 aPortForwardRuleName, aProto, 565 aHostIp, aHostPort, 562 mVirtualBox->onNATNetworkPortForward(mName.raw(), TRUE, aIsIpv6, 563 aPortForwardRuleName, aProto, 564 aHostIp, aHostPort, 566 565 aGuestIp, aGuestPort); 567 566 568 567 /* Notify listerners listening on this network only */ 569 fireNATNetworkPortForwardEvent(m->pEventSource, mName.raw(), TRUE, 568 fireNATNetworkPortForwardEvent(m->pEventSource, mName.raw(), TRUE, 570 569 aIsIpv6, aPortForwardRuleName, aProto, 571 570 aHostIp, aHostPort, … … 592 591 NATRuleMap& mapRules = aIsIpv6 ? m->mapName2PortForwardRule6 : m->mapName2PortForwardRule4; 593 592 NATRuleMap::iterator it = mapRules.find(aPortForwardRuleName); 594 593 595 594 if (it == mapRules.end()) 596 595 return E_INVALIDARG; 597 596 598 597 strHostIP = it->second.strHostIP; 599 598 strGuestIP = it->second.strGuestIP; … … 603 602 604 603 mapRules.erase(it); 605 604 606 605 alock.release(); 607 606 608 mVirtualBox->onNATNetworkPortForward(mName.raw(), FALSE, aIsIpv6, 609 aPortForwardRuleName, proto, 610 Bstr(strHostIP).raw(), u16HostPort, 607 mVirtualBox->onNATNetworkPortForward(mName.raw(), FALSE, aIsIpv6, 608 aPortForwardRuleName, proto, 609 Bstr(strHostIP).raw(), u16HostPort, 611 610 Bstr(strGuestIP).raw(), u16GuestPort); 612 611 613 612 /* Notify listerners listening on this network only */ 614 fireNATNetworkPortForwardEvent(m->pEventSource, mName.raw(), FALSE, 613 fireNATNetworkPortForwardEvent(m->pEventSource, mName.raw(), FALSE, 615 614 aIsIpv6, aPortForwardRuleName, proto, 616 615 Bstr(strHostIP).raw(), u16HostPort, … … 632 631 633 632 if (!m->fEnabled) return S_OK; 634 m->NATRunner.setOption(NATSCCFG_NAME, mName, true); 635 m->NATRunner.setOption(NATSCCFG_TRUNKTYPE, Utf8Str(aTrunkType), true); 636 m->NATRunner.setOption(NATSCCFG_IPADDRESS, m->IPv4Gateway, true); 637 m->NATRunner.setOption(NATSCCFG_NETMASK, m->IPv4NetworkMask, true); 638 639 /* port-forwarding */ 640 641 for (constNATRuleMapIterator it = m->mapName2PortForwardRule4.begin(); 642 it != m->mapName2PortForwardRule4.end(); ++it) 643 { 644 settings::NATRule r = it->second; 645 m->NATRunner.setOption(NATSCCFG_PORTFORWARD4, 646 Bstr(Utf8StrFmt("%s:%d:[%s]:%d:[%s]:%d", 647 r.strName.c_str(), 648 r.proto, 649 r.strHostIP.isEmpty() ? 650 "0.0.0.0" : 651 r.strHostIP.c_str(), 652 r.u16HostPort, 653 r.strGuestIP.c_str(), 654 r.u16GuestPort)), true); 655 } 633 634 m->NATRunner.setOption(NETCFG_NETNAME, mName, true); 635 m->NATRunner.setOption(NETCFG_TRUNKTYPE, Utf8Str(aTrunkType), true); 636 m->NATRunner.setOption(NETCFG_IPADDRESS, m->IPv4Gateway, true); 637 m->NATRunner.setOption(NETCFG_NETMASK, m->IPv4NetworkMask, true); 638 639 /* No portforwarding rules from command-line, all will be fetched via API */ 656 640 657 641 if (m->fNeedDhcpServer) … … 659 643 /** 660 644 * Just to as idea... via API (on creation user pass the cidr of network and) 661 * and we calculate it's addreses (mutable?). 645 * and we calculate it's addreses (mutable?). 662 646 */ 663 664 /* 647 648 /* 665 649 * Configuration and running DHCP server: 666 650 * 1. find server first createDHCPServer … … 668 652 * 3. if return status neither E_INVALRG nor S_OK => return E_FAIL 669 653 * 4. if return status S_OK proceed to DHCP server configuration 670 * 5. call setConfiguration() and pass all required parameters 654 * 5. call setConfiguration() and pass all required parameters 671 655 * 6. start dhcp server. 672 656 */ 673 int rc = mVirtualBox->FindDHCPServerByNetworkName(mName.raw(), 657 int rc = mVirtualBox->FindDHCPServerByNetworkName(mName.raw(), 674 658 m->dhcpServer.asOutParam()); 675 switch (rc) 659 switch (rc) 676 660 { 677 661 case E_INVALIDARG: 678 662 /* server haven't beeen found let create it then */ 679 rc = mVirtualBox->CreateDHCPServer(mName.raw(), 663 rc = mVirtualBox->CreateDHCPServer(mName.raw(), 680 664 m->dhcpServer.asOutParam()); 681 665 if (FAILED(rc)) 682 666 return E_FAIL; 683 667 /* breakthrough */ 684 case S_OK: 668 685 669 { 686 LogFunc(("gateway: %s, dhcpserver:%s, dhcplowerip:%s, dhcpupperip:%s\n", 687 Utf8Str(m->IPv4Gateway.raw()).c_str(), 670 LogFunc(("gateway: %s, dhcpserver:%s, dhcplowerip:%s, dhcpupperip:%s\n", 671 Utf8Str(m->IPv4Gateway.raw()).c_str(), 688 672 Utf8Str(m->IPv4DhcpServer.raw()).c_str(), 689 Utf8Str(m->IPv4DhcpServerLowerIp.raw()).c_str(), 673 Utf8Str(m->IPv4DhcpServerLowerIp.raw()).c_str(), 690 674 Utf8Str(m->IPv4DhcpServerUpperIp.raw()).c_str())); 691 675 676 m->dhcpServer->AddGlobalOption(DhcpOpt_Router, m->IPv4Gateway.raw()); 692 677 693 678 rc = m->dhcpServer->SetEnabled(true); 679 694 680 BSTR dhcpip = NULL; 695 681 BSTR netmask = NULL; 696 682 BSTR lowerip = NULL; 697 683 BSTR upperip = NULL; 684 698 685 m->IPv4DhcpServer.cloneTo(&dhcpip); 699 686 m->IPv4NetworkMask.cloneTo(&netmask); 700 701 m->IPv4DhcpServerLowerIp.cloneTo(&lowerip); 687 m->IPv4DhcpServerLowerIp.cloneTo(&lowerip); 702 688 m->IPv4DhcpServerUpperIp.cloneTo(&upperip); 703 rc = m->dhcpServer->SetConfiguration(dhcpip, 689 rc = m->dhcpServer->SetConfiguration(dhcpip, 704 690 netmask, 705 691 lowerip, 706 692 upperip); 707 break;708 693 } 709 710 default: 711 return E_FAIL; 694 case S_OK: 695 break; 696 697 default: 698 return E_FAIL; 712 699 } 713 700 … … 719 706 } 720 707 } 721 708 722 709 if (RT_SUCCESS(m->NATRunner.start())) 723 710 { … … 728 715 #else 729 716 NOREF(aTrunkType); 730 return E_NOTIMPL;717 ReturnComNotImplemented(); 731 718 #endif 732 719 } … … 741 728 } 742 729 else return E_FAIL; 743 744 730 #else 745 return E_NOTIMPL;731 ReturnComNotImplemented(); 746 732 #endif 747 733 } … … 773 759 char aszGatewayIp[16], aszNetmask[16]; 774 760 RT_ZERO(aszNetmask); 775 int rc = RTCidrStrToIPv4(Utf8Str(m->IPv4NetworkCidr.raw()).c_str(), 776 &network, 761 int rc = RTCidrStrToIPv4(Utf8Str(m->IPv4NetworkCidr.raw()).c_str(), 762 &network, 777 763 &netmask); 778 764 AssertRCReturn(rc, rc); 779 765 780 766 /* I don't remember the reason CIDR calcualted in host */ 781 767 gateway.u = network.u; … … 790 776 dhcplowerip, 791 777 dhcpupperip; 792 char aszNetwork[16], 778 char aszNetwork[16], 793 779 aszDhcpIp[16], 794 780 aszDhcpLowerIp[16], … … 802 788 dhcpserver.u = network.u; 803 789 dhcpserver.u += 2; 804 805 790 791 806 792 /* XXX: adding more services should change the math here */ 807 793 dhcplowerip.u = RT_H2N_U32(dhcpserver.u + 1); … … 809 795 dhcpserver.u = RT_H2N_U32(dhcpserver.u); 810 796 network.u = RT_H2N_U32(network.u); 811 797 812 798 RTStrPrintf(aszNetwork, 16, "%RTnaipv4", network); 813 799 RTStrPrintf(aszDhcpLowerIp, 16, "%RTnaipv4", dhcplowerip); … … 818 804 m->IPv4DhcpServerLowerIp = aszDhcpLowerIp; 819 805 m->IPv4DhcpServerUpperIp = aszDhcpUpperIp; 820 LogFunc(("network: %RTnaipv4, dhcpserver:%RTnaipv4, dhcplowerip:%RTnaipv4, dhcpupperip:%RTnaipv4\n", network, dhcpserver, dhcplowerip, dhcpupperip)); 806 807 LogFunc(("network: %RTnaipv4, dhcpserver:%RTnaipv4, dhcplowerip:%RTnaipv4, dhcpupperip:%RTnaipv4\n", 808 network, 809 dhcpserver, 810 dhcplowerip, 811 dhcpupperip)); 821 812 } 822 813 /* we need IPv4NetworkMask for NAT's gw service start */ -
trunk/src/VBox/Main/src-server/NetworkServiceRunner.cpp
r47017 r47018 15 15 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind. 16 16 */ 17 #include " DHCPServerRunner.h"17 #include "NetworkServiceRunner.h" 18 18 #include <iprt/process.h> 19 19 #include <iprt/param.h> … … 22 22 struct ARGDEF 23 23 { 24 DHCPCFG Type;24 NETCFG Type; 25 25 const char * Name; 26 26 }; 27 27 28 #ifdef RT_OS_WINDOWS29 # define DHCP_EXECUTABLE_NAME "VBoxNetDHCP.exe"30 #else31 # define DHCP_EXECUTABLE_NAME "VBoxNetDHCP"32 #endif33 34 28 static const ARGDEF g_aArgDefs[] = 35 29 { 36 {DHCPCFG_NAME, "--name"}, 37 {DHCPCFG_NETNAME, "--network"}, 38 {DHCPCFG_TRUNKTYPE, "--trunk-type"}, 39 {DHCPCFG_TRUNKNAME, "--trunk-name"}, 40 {DHCPCFG_MACADDRESS, "--mac-address"}, 41 {DHCPCFG_IPADDRESS, "--ip-address"}, 42 {DHCPCFG_LEASEDB, "--lease-db"}, 43 {DHCPCFG_VERBOSE, "--verbose"}, 44 {DHCPCFG_BEGINCONFIG, "--begin-config"}, 45 {DHCPCFG_GATEWAY, "--gateway"}, 46 {DHCPCFG_LOWERIP, "--lower-ip"}, 47 {DHCPCFG_UPPERIP, "--upper-ip"}, 48 {DHCPCFG_NETMASK, "--netmask"}, 49 {DHCPCFG_HELP, "--help"}, 50 {DHCPCFG_VERSION, "--version"} 30 {NETCFG_NAME, "--name"}, 31 {NETCFG_NETNAME, "--network"}, 32 {NETCFG_TRUNKTYPE, "--trunk-type"}, 33 {NETCFG_TRUNKNAME, "--trunk-name"}, 34 {NETCFG_MACADDRESS, "--mac-address"}, 35 {NETCFG_IPADDRESS, "--ip-address"}, 36 {NETCFG_VERBOSE, "--verbose"}, 37 {NETCFG_NETMASK, "--netmask"}, 51 38 }; 52 39 53 static const ARGDEF * getArgDef( DHCPCFG type)40 static const ARGDEF * getArgDef(NETCFG type) 54 41 { 55 42 for (unsigned i = 0; i < RT_ELEMENTS(g_aArgDefs); i++) … … 60 47 } 61 48 62 DHCPServerRunner::DHCPServerRunner() 63 { 64 mProcess = NIL_RTPROCESS; 65 for (unsigned i = 0; i < DHCPCFG_NOTOPT_MAXVAL; i++) 66 { 67 mOptionEnabled[i] = false; 68 } 69 } 70 71 void DHCPServerRunner::detachFromServer() 49 void NetworkServiceRunner::detachFromServer() 72 50 { 73 51 mProcess = NIL_RTPROCESS; 74 52 } 75 53 76 int DHCPServerRunner::start()54 int NetworkServiceRunner::start() 77 55 { 78 56 if (isRunning()) 79 57 return VINF_ALREADY_INITIALIZED; 80 58 81 const char * args[ DHCPCFG_NOTOPT_MAXVAL * 2];59 const char * args[NETCFG_NOTOPT_MAXVAL * 2]; 82 60 83 61 /* get the path to the executable */ … … 91 69 { 92 70 suffix++; 93 strcpy(suffix, DHCP_EXECUTABLE_NAME);71 strcpy(suffix, mProcName); 94 72 } 95 else96 exePath = DHCP_EXECUTABLE_NAME;97 73 98 74 int index = 0; … … 100 76 args[index++] = exePath; 101 77 102 for (unsigned i = 0; i < DHCPCFG_NOTOPT_MAXVAL; i++)78 for (unsigned i = 0; i < NETCFG_NOTOPT_MAXVAL; i++) 103 79 { 104 80 if (mOptionEnabled[i]) 105 81 { 106 const ARGDEF *pArgDef = getArgDef(( DHCPCFG)i);82 const ARGDEF *pArgDef = getArgDef((NETCFG)i); 107 83 if (!pArgDef) 108 84 continue; 109 args[index++] = pArgDef->Name; // e.g. "--network"85 args[index++] = pArgDef->Name; 110 86 111 /* value can be null for e.g. --begin-config has no value112 * and thus check the mOptions string length here113 */114 87 if (mOptions[i].length()) 115 88 args[index++] = mOptions[i].c_str(); // value … … 119 92 args[index++] = NULL; 120 93 121 int rc = RTProcCreate( exePath, args, RTENV_DEFAULT, 0, &mProcess);94 int rc = RTProcCreate(suffix ? exePath : mProcName, args, RTENV_DEFAULT, 0, &mProcess); 122 95 if (RT_FAILURE(rc)) 123 96 mProcess = NIL_RTPROCESS; … … 126 99 } 127 100 128 int DHCPServerRunner::stop()101 int NetworkServiceRunner::stop() 129 102 { 130 103 if (!isRunning()) … … 136 109 } 137 110 138 bool DHCPServerRunner::isRunning()111 bool NetworkServiceRunner::isRunning() 139 112 { 140 113 if (mProcess == NIL_RTPROCESS) -
trunk/src/VBox/Main/src-server/VirtualBoxImpl.cpp
r46969 r47018 61 61 #include "SystemPropertiesImpl.h" 62 62 #include "GuestOSTypeImpl.h" 63 #include " DHCPServerRunner.h"63 #include "NetworkServiceRunner.h" 64 64 #include "DHCPServerImpl.h" 65 65 #include "NATNetworkImpl.h" -
trunk/src/VBox/Main/src-server/xpcom/server.cpp
r46969 r47018 67 67 #include "BandwidthControlImpl.h" 68 68 #include "BandwidthGroupImpl.h" 69 #include " DHCPServerRunner.h"69 #include "NetworkServiceRunner.h" 70 70 #include "DHCPServerImpl.h" 71 71 #include "GuestOSTypeImpl.h" -
trunk/src/VBox/Main/xml/Settings.cpp
r46969 r47018 1302 1302 if ( (pelmServer->getAttributeValue("networkName", srv.strNetworkName)) 1303 1303 && (pelmServer->getAttributeValue("IPAddress", srv.strIPAddress)) 1304 && (pelmServer->getAttributeValue("networkMask", srv.strIPNetworkMask))1304 && (pelmServer->getAttributeValue("networkMask", srv.GlobalDhcpOptions[DhcpOpt_SubnetMask])) 1305 1305 && (pelmServer->getAttributeValue("lowerIP", srv.strIPLower)) 1306 1306 && (pelmServer->getAttributeValue("upperIP", srv.strIPUpper)) 1307 1307 && (pelmServer->getAttributeValue("enabled", srv.fEnabled)) 1308 1308 ) 1309 { 1310 xml::NodesLoop nlOptions(*pelmServer, "Options"); 1311 const xml::ElementNode *options; 1312 /* XXX: Options are in 1:1 relation to DHCPServer */ 1313 1314 while ((options = nlOptions.forAllNodes())) 1315 { 1316 readDhcpOptions(srv.GlobalDhcpOptions, *options); 1317 } /* end of forall("Options") */ 1318 xml::NodesLoop nlConfig(*pelmServer, "Config"); 1319 const xml::ElementNode *cfg; 1320 while ((cfg = nlConfig.forAllNodes())) 1321 { 1322 com::Utf8Str strVmName; 1323 uint32_t u32Slot; 1324 cfg->getAttributeValue("vm-name", strVmName); 1325 cfg->getAttributeValue("slot", (uint32_t&)u32Slot); 1326 readDhcpOptions(srv.VmSlot2OptionsM[VmNameSlotKey(strVmName, u32Slot)], 1327 *cfg); 1328 } 1309 1329 llDhcpServers.push_back(srv); 1330 } 1310 1331 else 1311 1332 throw ConfigFileError(this, pelmServer, N_("Required DHCPServer/@networkName, @IPAddress, @networkMask, @lowerIP, @upperIP or @enabled attribute is missing")); 1312 1333 } 1313 1334 } 1335 } 1336 1337 void MainConfigFile::readDhcpOptions(DhcpOptionMap& map, 1338 const xml::ElementNode& options) 1339 { 1340 xml::NodesLoop nl2(options, "Option"); 1341 const xml::ElementNode *opt; 1342 while((opt = nl2.forAllNodes())) 1343 { 1344 DhcpOpt_T OptName; 1345 com::Utf8Str OptValue; 1346 opt->getAttributeValue("name", (uint32_t&)OptName); 1347 1348 if (OptName == DhcpOpt_SubnetMask) 1349 continue; 1350 1351 opt->getAttributeValue("value", OptValue); 1352 1353 map.insert( 1354 std::map<DhcpOpt_T, Utf8Str>::value_type(OptName, OptValue)); 1355 } /* end of forall("Option") */ 1356 1314 1357 } 1315 1358 … … 1446 1489 #endif 1447 1490 srv.strIPAddress = "192.168.56.100"; 1448 srv. strIPNetworkMask= "255.255.255.0";1491 srv.GlobalDhcpOptions[DhcpOpt_SubnetMask] = "255.255.255.0"; 1449 1492 srv.strIPLower = "192.168.56.101"; 1450 1493 srv.strIPUpper = "192.168.56.254"; … … 1489 1532 const DHCPServer &d = *it; 1490 1533 xml::ElementNode *pelmThis = pelmDHCPServers->createChild("DHCPServer"); 1534 DhcpOptConstIterator itOpt; 1535 itOpt = d.GlobalDhcpOptions.find(DhcpOpt_SubnetMask); 1536 1491 1537 pelmThis->setAttribute("networkName", d.strNetworkName); 1492 1538 pelmThis->setAttribute("IPAddress", d.strIPAddress); 1493 pelmThis->setAttribute("networkMask", d.strIPNetworkMask); 1539 if (itOpt != d.GlobalDhcpOptions.end()) 1540 pelmThis->setAttribute("networkMask", itOpt->second); 1494 1541 pelmThis->setAttribute("lowerIP", d.strIPLower); 1495 1542 pelmThis->setAttribute("upperIP", d.strIPUpper); 1496 1543 pelmThis->setAttribute("enabled", (d.fEnabled) ? 1 : 0); // too bad we chose 1 vs. 0 here 1497 } 1544 /* We assume that if there're only 1 element it means that */ 1545 int cOpt = d.GlobalDhcpOptions.size(); 1546 /* We don't want duplicate validation check of networkMask here*/ 1547 if ( ( itOpt == d.GlobalDhcpOptions.end() 1548 && cOpt > 0) 1549 || cOpt > 1) 1550 { 1551 xml::ElementNode *pelmOptions = pelmThis->createChild("Options"); 1552 for (itOpt = d.GlobalDhcpOptions.begin(); 1553 itOpt != d.GlobalDhcpOptions.end(); 1554 ++itOpt) 1555 { 1556 if (itOpt->first == DhcpOpt_SubnetMask) 1557 continue; 1558 1559 xml::ElementNode *pelmOpt = pelmOptions->createChild("Option"); 1560 1561 if (!pelmOpt) 1562 break; 1563 1564 pelmOpt->setAttribute("name", itOpt->first); 1565 pelmOpt->setAttribute("value", itOpt->second); 1566 } 1567 } /* end of if */ 1568 1569 if (d.VmSlot2OptionsM.size() > 0) 1570 { 1571 VmSlot2OptionsConstIterator itVmSlot; 1572 DhcpOptConstIterator itOpt1; 1573 for(itVmSlot = d.VmSlot2OptionsM.begin(); 1574 itVmSlot != d.VmSlot2OptionsM.end(); 1575 ++itVmSlot) 1576 { 1577 xml::ElementNode *pelmCfg = pelmThis->createChild("Config"); 1578 pelmCfg->setAttribute("vm-name", itVmSlot->first.VmName); 1579 pelmCfg->setAttribute("slot", itVmSlot->first.Slot); 1580 1581 for (itOpt1 = itVmSlot->second.begin(); 1582 itOpt1 != itVmSlot->second.end(); 1583 ++itOpt1) 1584 { 1585 xml::ElementNode *pelmOpt = pelmCfg->createChild("Option"); 1586 pelmOpt->setAttribute("name", itOpt1->first); 1587 pelmOpt->setAttribute("value", itOpt1->second); 1588 } 1589 } 1590 } /* and of if */ 1591 1592 } 1498 1593 1499 1594 /* TODO: bump main version ? */
Note:
See TracChangeset
for help on using the changeset viewer.