VirtualBox

Changeset 46959 in vbox for trunk


Ignore:
Timestamp:
Jul 4, 2013 5:21:06 AM (12 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
86967
Message:

Main/Network: DHCP server has got the ear in Main, and we able create/describe more complex infrostructures. DHCP server together with Lwip NAT can handle per vm/slot configuration and store them in xml settings.

place-holder: Host interface nameserver list, domain name and search strings, I suppose that this functions should be used on initialization stage and then on host configuration change even or directly from event.

Location:
trunk
Files:
2 deleted
13 edited
2 moved

Legend:

Unmodified
Added
Removed
  • trunk/include/VBox/settings.h

    r46720 r46959  
    286286typedef std::list<MachineRegistryEntry> MachinesRegistry;
    287287
     288typedef std::map<DhcpOpt_T, com::Utf8Str> DhcpOptionMap;
     289typedef DhcpOptionMap::value_type DhcpOptValuePair;
     290typedef DhcpOptionMap::iterator DhcpOptIterator;
     291typedef DhcpOptionMap::const_iterator DhcpOptConstIterator;
     292
     293typedef 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;
     306typedef std::map<VmNameSlotKey, DhcpOptionMap> VmSlot2OptionsMap;
     307typedef VmSlot2OptionsMap::value_type VmSlot2OptionsPair;
     308typedef VmSlot2OptionsMap::iterator VmSlot2OptionsIterator;
     309typedef VmSlot2OptionsMap::const_iterator VmSlot2OptionsConstIterator;
     310
    288311struct DHCPServer
    289312{
     
    294317    com::Utf8Str    strNetworkName,
    295318                    strIPAddress,
    296                     strIPNetworkMask,
    297319                    strIPLower,
    298320                    strIPUpper;
    299321    bool            fEnabled;
     322    std::map<DhcpOpt_T, com::Utf8Str>  GlobalDhcpOptions;
     323    VmSlot2OptionsMap VmSlot2OptionsM;
    300324};
    301325typedef std::list<DHCPServer> DHCPServersList;
     
    337361    void readMachineRegistry(const xml::ElementNode &elmMachineRegistry);
    338362    void readDHCPServers(const xml::ElementNode &elmDHCPServers);
     363    void readDhcpOptions(DhcpOptionMap& map, const xml::ElementNode& options);
    339364    void readNATNetworks(const xml::ElementNode &elmNATNetworks);
    340365
  • trunk/src/VBox/Main/Makefile.kmk

    r46649 r46959  
    335335        src-server/BIOSSettingsImpl.cpp \
    336336        src-server/DHCPServerImpl.cpp \
    337         src-server/DHCPServerRunner.cpp \
     337        src-server/NetworkServiceRunner.cpp \
    338338        src-server/NATNetworkImpl.cpp \
    339         $(if $(VBOX_WITH_NAT_SERVICE),src-server/NATNetworkServiceRunner.cpp,) \
    340339        src-server/GuestOSTypeImpl.cpp \
    341340        src-server/HostImpl.cpp \
  • trunk/src/VBox/Main/idl/VirtualBox.xidl

    r46778 r46959  
    14661466  </interface>
    14671467
     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 
    14681536  <interface
    14691537    name="IDHCPServer" extends="$unknown"
    1470     uuid="6cfe387c-74fb-4ca7-bff6-973bec8af7a3"
     1538    uuid="ff0774c5-1f62-4bc3-919c-7fc942bf1d25"
    14711539    wsmap="managed"
    14721540    >
     
    14771545      <link to="IVirtualBox::DHCPServers"/> attribute.
    14781546    </desc>
    1479 
     1547    <!-- We want to keep our "real" servers updated about configuration changes -->
     1548    <attribute name="eventSource" type="IEventSource" readonly="yes"/>
    14801549    <attribute name="enabled" type="boolean">
    14811550      <desc>
     
    15131582      </desc>
    15141583    </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>
    15151640
    15161641    <method name="setConfiguration">
     
    80388163  <interface
    80398164    name="IHost" extends="$unknown"
    8040     uuid="30678943-32df-4830-b413-931b25ac86a0"
     8165    uuid="a6107246-f939-42c4-82b6-8aca40327b6d"
    80418166    wsmap="managed"
    80428167    >
     
    80998224    <attribute name="networkInterfaces" type="IHostNetworkInterface" safearray="yes" readonly="yes">
    81008225      <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>
    81018238    </attribute>
    81028239
  • trunk/src/VBox/Main/include/DHCPServerImpl.h

    r44528 r46959  
    3030{
    3131    struct DHCPServer;
     32    struct VmNameSlotKey;
    3233}
     34#ifdef RT_OS_WINDOWS
     35# define DHCP_EXECUTABLE_NAME "VBoxNetDHCP.exe"
     36#else
     37# define DHCP_EXECUTABLE_NAME "VBoxNetDHCP"
     38#endif
     39
     40class DHCPServerRunner: public NetworkServiceRunner
     41{
     42public:
     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
     60typedef std::map<DhcpOpt_T, com::Utf8Str> DhcpOptionMap;
     61typedef DhcpOptionMap::value_type DhcpOptValuePair;
     62typedef DhcpOptionMap::const_iterator DhcpOptConstIterator;
     63typedef DhcpOptionMap::iterator DhcpOptIterator;
     64
     65typedef std::map<settings::VmNameSlotKey, DhcpOptionMap> VmSlot2OptionsMap;
     66typedef VmSlot2OptionsMap::value_type VmSlot2OptionsPair;
     67typedef VmSlot2OptionsMap::iterator VmSlot2OptionsIterator;
     68
    3369
    3470class ATL_NO_VTABLE DHCPServer :
     
    70106    STDMETHOD(COMGETTER(UpperIP))(BSTR *aIPAddress);
    71107
     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   
     117
    72118    STDMETHOD(SetConfiguration)(IN_BSTR aIPAddress, IN_BSTR aNetworkMask, IN_BSTR aFromIPAddress, IN_BSTR aToIPAddress);
    73119
     
    86132
    87133        Bstr IPAddress;
    88         Bstr networkMask;
    89134        Bstr lowerIP;
    90135        Bstr upperIP;
     136
    91137        BOOL enabled;
    92 
    93138        DHCPServerRunner dhcp;
     139       
     140        DhcpOptionMap GlobalDhcpOptions;
     141        VmSlot2OptionsMap VmSlot2Options;
    94142    } m;
    95 
     143   
     144    DhcpOptionMap& findOptMapByVmNameSlot(const com::Utf8Str& aVmName,
     145                                   LONG Slot);
    96146};
    97147
  • trunk/src/VBox/Main/include/HostImpl.h

    r44528 r46959  
    6262    STDMETHOD(COMGETTER(USBDeviceFilters))(ComSafeArrayOut(IHostUSBDeviceFilter *, aUSBDeviceFilters));
    6363    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));
     67
    6468    STDMETHOD(COMGETTER(ProcessorCount))(ULONG *count);
    6569    STDMETHOD(COMGETTER(ProcessorOnlineCount))(ULONG *count);
     
    147151    HRESULT updateNetIfList();
    148152
     153#ifndef RT_OS_WINDOWS
     154    HRESULT parseResolvConf();
     155#else
     156    HRESULT fetchNameResolvingInformation();
     157#endif
     158
    149159#ifdef VBOX_WITH_RESOURCE_USAGE_API
    150160    void registerMetrics(PerformanceCollector *aCollector);
  • trunk/src/VBox/Main/include/NATNetworkImpl.h

    r45559 r46959  
    3737}
    3838
     39#ifdef RT_OS_WINDOWS
     40# define NATSR_EXECUTABLE_NAME "VBoxNetLwipNAT.exe"
     41#else
     42# define NATSR_EXECUTABLE_NAME "VBoxNetLwipNAT"
     43#endif
     44
     45class NATNetworkServiceRunner: public NetworkServiceRunner
     46{
     47public:
     48    NATNetworkServiceRunner(): NetworkServiceRunner(NATSR_EXECUTABLE_NAME){}
     49    virtual ~NATNetworkServiceRunner(){}
     50};
    3951
    4052class ATL_NO_VTABLE NATNetwork :
  • trunk/src/VBox/Main/include/NetworkServiceRunner.h

    r46958 r46959  
    2323typedef enum
    2424{
    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;
    4235
    4336#define TRUNKTYPE_WHATEVER "whatever"
     
    4639#define TRUNKTYPE_SRVNAT   "srvnat"
    4740
    48 class DHCPServerRunner
     41class NetworkServiceRunner
    4942{
    5043public:
    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 */}
    5351
    54     int setOption(DHCPCFG opt, const char *val, bool enabled)
     52    int setOption(NETCFG opt, const char *val, bool enabled)
    5553    {
    56         if (opt == 0 || opt >= DHCPCFG_NOTOPT_MAXVAL)
     54        if (opt == 0 || opt >= NETCFG_NOTOPT_MAXVAL)
    5755            return VERR_INVALID_PARAMETER;
    5856        if (isRunning())
     
    6462    }
    6563
    66     int setOption(DHCPCFG opt, const com::Utf8Str &val, bool enabled)
     64    int setOption(NETCFG opt, const com::Utf8Str &val, bool enabled)
    6765    {
    6866        return setOption(opt, val.c_str(), enabled);
     
    7573    void detachFromServer();
    7674private:
    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;
    7978    RTPROCESS mProcess;
    8079};
  • trunk/src/VBox/Main/src-client/ConsoleImpl2.cpp

    r46880 r46959  
    115115#endif /* VBOX_WITH_NETFLT */
    116116
    117 #include "DHCPServerRunner.h"
     117#include "NetworkServiceRunner.h"
    118118#include "BusAssignmentManager.h"
    119119#ifdef VBOX_WITH_EXTPACK
  • trunk/src/VBox/Main/src-server/DHCPServerImpl.cpp

    r44528 r46959  
    1818 */
    1919
    20 #include "DHCPServerRunner.h"
     20#include "NetworkServiceRunner.h"
    2121#include "DHCPServerImpl.h"
    2222#include "AutoCaller.h"
     
    2525#include <iprt/cpp/utils.h>
    2626
     27#include <VBox/com/array.h>
    2728#include <VBox/settings.h>
    2829
     
    3738}
    3839
     40
    3941DHCPServer::~DHCPServer()
    4042{
    4143}
    4244
     45
    4346HRESULT DHCPServer::FinalConstruct()
    4447{
     
    4649}
    4750
     51
    4852void DHCPServer::FinalRelease()
    4953{
     
    5256    BaseFinalRelease();
    5357}
     58
    5459
    5560void DHCPServer::uninit()
     
    6368}
    6469
     70
    6571HRESULT DHCPServer::init(VirtualBox *aVirtualBox, IN_BSTR aName)
    6672{
     
    7581    unconst(mName) = aName;
    7682    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")));
    7884    m.enabled = FALSE;
     85   
    7986    m.lowerIP = "0.0.0.0";
    8087    m.upperIP = "0.0.0.0";
     
    8592    return S_OK;
    8693}
     94
    8795
    8896HRESULT DHCPServer::init(VirtualBox *aVirtualBox,
     
    98106    unconst(mName) = data.strNetworkName;
    99107    m.IPAddress = data.strIPAddress;
    100     m.networkMask = data.strIPNetworkMask;
    101108    m.enabled = data.fEnabled;
    102109    m.lowerIP = data.strIPLower;
    103110    m.upperIP = data.strIPUpper;
    104111
     112   
     113    m.GlobalDhcpOptions.clear();
     114    m.GlobalDhcpOptions.insert(data.GlobalDhcpOptions.begin(),
     115                               data.GlobalDhcpOptions.end());
     116
     117    m.VmSlot2Options.clear();
     118    m.VmSlot2Options.insert(data.VmSlot2OptionsM.begin(),
     119                            data.VmSlot2OptionsM.end());
     120
    105121    autoInitSpan.setSucceeded();
    106122
    107123    return S_OK;
    108124}
     125
    109126
    110127HRESULT DHCPServer::saveSettings(settings::DHCPServer &data)
     
    117134    data.strNetworkName = mName;
    118135    data.strIPAddress = m.IPAddress;
    119     data.strIPNetworkMask = m.networkMask;
     136
    120137    data.fEnabled = !!m.enabled;
    121138    data.strIPLower = m.lowerIP;
    122139    data.strIPUpper = m.upperIP;
    123140
    124     return S_OK;
    125 }
     141    data.GlobalDhcpOptions.clear();
     142    data.GlobalDhcpOptions.insert(m.GlobalDhcpOptions.begin(),
     143                                  m.GlobalDhcpOptions.end());
     144   
     145    data.VmSlot2OptionsM.clear();
     146    data.VmSlot2OptionsM.insert(m.VmSlot2Options.begin(),
     147                                m.VmSlot2Options.end());
     148   
     149    return S_OK;
     150}
     151
    126152
    127153STDMETHODIMP DHCPServer::COMGETTER(NetworkName) (BSTR *aName)
     
    137163}
    138164
     165
    139166STDMETHODIMP DHCPServer::COMGETTER(Enabled) (BOOL *aEnabled)
    140167{
     
    148175    return S_OK;
    149176}
     177
    150178
    151179STDMETHODIMP DHCPServer::COMSETTER(Enabled) (BOOL aEnabled)
     
    165193}
    166194
     195
    167196STDMETHODIMP DHCPServer::COMGETTER(IPAddress) (BSTR *aIPAddress)
    168197{
     
    177206}
    178207
     208
    179209STDMETHODIMP DHCPServer::COMGETTER(NetworkMask) (BSTR *aNetworkMask)
    180210{
     
    184214    if (FAILED(autoCaller.rc())) return autoCaller.rc();
    185215
    186     m.networkMask.cloneTo(aNetworkMask);
    187 
    188     return S_OK;
    189 }
     216    m.GlobalDhcpOptions[DhcpOpt_SubnetMask].cloneTo(aNetworkMask);
     217
     218    return S_OK;
     219}
     220
    190221
    191222STDMETHODIMP DHCPServer::COMGETTER(LowerIP) (BSTR *aIPAddress)
     
    195226    AutoCaller autoCaller(this);
    196227    if (FAILED(autoCaller.rc())) return autoCaller.rc();
    197 
     228   
    198229    m.lowerIP.cloneTo(aIPAddress);
    199230
     
    201232}
    202233
     234
    203235STDMETHODIMP DHCPServer::COMGETTER(UpperIP) (BSTR *aIPAddress)
    204236{
     
    212244    return S_OK;
    213245}
     246
    214247
    215248STDMETHODIMP DHCPServer::SetConfiguration (IN_BSTR aIPAddress, IN_BSTR aNetworkMask, IN_BSTR aLowerIP, IN_BSTR aUpperIP)
     
    225258    AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
    226259    m.IPAddress = aIPAddress;
    227     m.networkMask = aNetworkMask;
     260    m.GlobalDhcpOptions[DhcpOpt_SubnetMask] = aNetworkMask;
     261
    228262    m.lowerIP = aLowerIP;
    229263    m.upperIP = aUpperIP;
     
    235269}
    236270
     271
     272STDMETHODIMP DHCPServer::AddGlobalOption(DhcpOpt_T aOption, IN_BSTR aValue)
     273{
     274    CheckComArgStr(aValue);
     275    /* store global option */
     276    AutoCaller autoCaller(this);
     277    if (FAILED(autoCaller.rc())) return autoCaller.rc();
     278
     279    AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
     280   
     281    m.GlobalDhcpOptions.insert(
     282      DhcpOptValuePair(aOption, Utf8Str(aValue)));
     283
     284    alock.release();
     285
     286    AutoWriteLock vboxLock(mVirtualBox COMMA_LOCKVAL_SRC_POS);
     287    return mVirtualBox->saveSettings();
     288}
     289
     290
     291STDMETHODIMP DHCPServer::COMGETTER(GlobalOptions)(ComSafeArrayOut(BSTR, aValue))
     292{
     293    CheckComArgOutSafeArrayPointerValid(aValue);
     294
     295    AutoCaller autoCaller(this);
     296    if (FAILED(autoCaller.rc())) return autoCaller.rc();
     297
     298    AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
     299
     300    SafeArray<BSTR> sf(m.GlobalDhcpOptions.size());
     301    int i = 0;
     302   
     303    for (DhcpOptIterator it = m.GlobalDhcpOptions.begin();
     304         it != m.GlobalDhcpOptions.end(); ++it)
     305    {
     306        Bstr(Utf8StrFmt("%d:%s", (*it).first, (*it).second.c_str())).detachTo(&sf[i]);
     307        i++;
     308    }
     309
     310    sf.detachTo(ComSafeArrayOutArg(aValue));
     311
     312    return S_OK;
     313}
     314
     315
     316STDMETHODIMP DHCPServer::COMGETTER(VmConfigs)(ComSafeArrayOut(BSTR, aValue))
     317{
     318    CheckComArgOutSafeArrayPointerValid(aValue);
     319   
     320    AutoCaller autoCaller(this);
     321    if (FAILED(autoCaller.rc())) return autoCaller.rc();
     322
     323    AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
     324
     325    SafeArray<BSTR> sf(m.VmSlot2Options.size());
     326    VmSlot2OptionsIterator it = m.VmSlot2Options.begin();
     327    int i = 0;
     328    for (;it != m.VmSlot2Options.end(); ++it)
     329    {
     330        Bstr(Utf8StrFmt("[%s]:%d",
     331                        it->first.VmName.c_str(),
     332                        it->first.Slot)).detachTo(&sf[i]);
     333        i++;
     334    }
     335
     336    sf.detachTo(ComSafeArrayOutArg(aValue));
     337
     338    return S_OK;
     339}
     340
     341
     342STDMETHODIMP DHCPServer::AddVmSlotOption(IN_BSTR aVmName, LONG aSlot, DhcpOpt_T aOption, IN_BSTR aValue)
     343{
     344    AutoCaller autoCaller(this);
     345    if (FAILED(autoCaller.rc())) return autoCaller.rc();
     346    AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
     347
     348    m.VmSlot2Options[settings::VmNameSlotKey(
     349          com::Utf8Str(aVmName),
     350          aSlot)][aOption] = com::Utf8Str(aValue);
     351
     352
     353    alock.release();
     354
     355    AutoWriteLock vboxLock(mVirtualBox COMMA_LOCKVAL_SRC_POS);   
     356    return mVirtualBox->saveSettings();
     357}
     358
     359
     360STDMETHODIMP DHCPServer::RemoveVmSlotOptions(IN_BSTR aVmName, LONG aSlot)
     361{
     362    AutoCaller autoCaller(this);
     363    if (FAILED(autoCaller.rc())) return autoCaller.rc();
     364    AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
     365
     366    DhcpOptionMap& map = findOptMapByVmNameSlot(com::Utf8Str(aVmName), aSlot);
     367
     368    map.clear();
     369   
     370    alock.release();   
     371
     372    AutoWriteLock vboxLock(mVirtualBox COMMA_LOCKVAL_SRC_POS);
     373    return mVirtualBox->saveSettings();
     374}
     375
     376
     377/**
     378 * this is mapping (vm, slot)
     379 */
     380STDMETHODIMP DHCPServer::GetVmSlotOptions(IN_BSTR aVmName, LONG aSlot, ComSafeArrayOut(BSTR, aValues))
     381{
     382    CheckComArgOutSafeArrayPointerValid(aValues);
     383    AutoCaller autoCaller(this);
     384    if (FAILED(autoCaller.rc())) return autoCaller.rc();
     385
     386    AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
     387
     388    DhcpOptionMap& map = findOptMapByVmNameSlot(com::Utf8Str(aVmName), aSlot);
     389
     390    SafeArray<BSTR> sf(map.size());
     391    int i = 0;
     392   
     393    for (DhcpOptIterator it = map.begin();
     394         it != map.end(); ++it)
     395    {
     396        Bstr(Utf8StrFmt("%d:%s", (*it).first, (*it).second.c_str())).detachTo(&sf[i]);
     397        i++;
     398    }
     399
     400    sf.detachTo(ComSafeArrayOutArg(aValues));
     401
     402    return S_OK;
     403}
     404
     405
     406STDMETHODIMP DHCPServer::GetMacOptions(IN_BSTR aMAC, ComSafeArrayOut(BSTR, aValues))
     407{
     408    CheckComArgOutSafeArrayPointerValid(aValues);
     409   
     410    AutoCaller autoCaller(this);
     411    if (FAILED(autoCaller.rc())) return autoCaller.rc();
     412
     413    AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
     414    HRESULT hrc;
     415
     416    ComPtr<IMachine> machine;
     417    ComPtr<INetworkAdapter> nic;
     418   
     419    VmSlot2OptionsIterator it;
     420    for(it = m.VmSlot2Options.begin();
     421        it != m.VmSlot2Options.end();
     422        ++it)
     423    {
     424
     425        alock.release();
     426        hrc = mVirtualBox->FindMachine(Bstr(it->first.VmName).raw(), machine.asOutParam());
     427        alock.acquire();   
     428
     429        if (FAILED(hrc))
     430            continue;
     431
     432        alock.release();
     433        hrc = machine->GetNetworkAdapter(it->first.Slot, nic.asOutParam());
     434        alock.acquire();
     435
     436        if (FAILED(hrc))
     437            continue;
     438   
     439        com::Bstr mac;
     440
     441        alock.release();
     442        hrc = nic->GetMACAddress(mac.asOutParam());
     443        alock.acquire();
     444
     445        if (FAILED(hrc)) /* no MAC address ??? */
     446            break;
     447   
     448        if (!RTStrICmp(com::Utf8Str(mac).c_str(), com::Utf8Str(aMAC).c_str()))
     449            return GetVmSlotOptions(Bstr(it->first.VmName).raw(),
     450                                    it->first.Slot,
     451                                    ComSafeArrayOutArg(aValues));
     452    } /* end of for */
     453   
     454    return hrc;
     455}
     456
     457
     458STDMETHODIMP DHCPServer::COMGETTER(EventSource)(IEventSource **aEventSource)
     459{
     460    ReturnComNotImplemented();
     461}
     462
     463
    237464STDMETHODIMP DHCPServer::Start(IN_BSTR aNetworkName, IN_BSTR aTrunkName, IN_BSTR aTrunkType)
    238465{
     
    240467    if (!m.enabled)
    241468        return S_OK;
    242 
    243     m.dhcp.setOption(DHCPCFG_NETNAME, Utf8Str(aNetworkName), true);
     469   
     470    /* Commmon Network Settings */
     471    m.dhcp.setOption(NETCFG_NETNAME, Utf8Str(aNetworkName), true);
     472
    244473    Bstr tmp(aTrunkName);
     474
    245475    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_NAME
     476        m.dhcp.setOption(NETCFG_TRUNKNAME, Utf8Str(tmp), true);
     477    m.dhcp.setOption(NETCFG_TRUNKTYPE, Utf8Str(aTrunkType), true);
     478
     479    /* XXX: should this MAC default initialization moved to NetworkServiceRunner? */
    250480    char strMAC[32];
    251481    Guid guid;
    252482    guid.create();
    253483    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 
     484                 guid.raw()->au8[0],
     485                 guid.raw()->au8[1],
     486                 guid.raw()->au8[2]);
     487    m.dhcp.setOption(NETCFG_MACADDRESS, strMAC, true);
     488    m.dhcp.setOption(NETCFG_IPADDRESS,  Utf8Str(m.IPAddress), true);
     489    m.dhcp.setOption(NETCFG_NETMASK, Utf8Str(m.GlobalDhcpOptions[DhcpOpt_SubnetMask]), true);
     490   
     491    /* XXX: This parameters Dhcp Server will fetch via API */
    269492    return RT_FAILURE(m.dhcp.start()) ? E_FAIL : S_OK;
    270493    //m.dhcp.detachFromServer(); /* need to do this to avoid server shutdown on runner destruction */
    271494}
    272495
     496
    273497STDMETHODIMP DHCPServer::Stop (void)
    274498{
    275499    return RT_FAILURE(m.dhcp.stop()) ? E_FAIL : S_OK;
    276500}
     501
     502DhcpOptionMap& DHCPServer::findOptMapByVmNameSlot(const com::Utf8Str& aVmName,
     503                                           LONG aSlot)
     504{
     505    return m.VmSlot2Options[settings::VmNameSlotKey(
     506          com::Utf8Str(aVmName),
     507          aSlot)];
     508}
  • trunk/src/VBox/Main/src-server/HostImpl.cpp

    r46820 r46959  
    134134#include <iprt/mem.h>
    135135#include <iprt/system.h>
     136#ifndef RT_OS_WINDOWS
     137# include <iprt/path.h>
     138#endif
    136139#ifdef RT_OS_SOLARIS
    137 # include <iprt/path.h>
    138140# include <iprt/ctype.h>
    139141#endif
     
    215217
    216218    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     */
    217227};
    218228
     229#ifndef RT_OS_WINDOWS
     230static char g_aszResolvConf[RTPATH_MAX];
     231
     232static 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
    219258
    220259////////////////////////////////////////////////////////////////////////////////
     
    797836#endif
    798837}
     838
     839
     840/**
     841 * This method return the list of registered name servers
     842 */
     843STDMETHODIMP 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 */
     852STDMETHODIMP Host::COMGETTER(DomainName)(BSTR *aDomainName)
     853{
     854    return E_NOTIMPL;
     855}
     856
     857
     858/**
     859 * This method returns the search string.
     860 */
     861STDMETHODIMP Host::COMGETTER(SearchStrings)(ComSafeArrayOut(BSTR, aSearchStrings))
     862{
     863    return E_NOTIMPL;
     864}
     865
    799866
    800867STDMETHODIMP Host::COMGETTER(USBDeviceFilters)(ComSafeArrayOut(IHostUSBDeviceFilter*, aUSBDeviceFilters))
  • trunk/src/VBox/Main/src-server/NATNetworkImpl.cpp

    r45559 r46959  
    1818 */
    1919
    20 #include "DHCPServerRunner.h"
     20#include "NetworkServiceRunner.h"
    2121#include "DHCPServerImpl.h"
    2222#include "NATNetworkImpl.h"
     
    3535#include "VBoxEvents.h"
    3636
    37 #include "NATNetworkServiceRunner.h"
    3837#include "VirtualBoxImpl.h"
    3938
     
    632631
    633632    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 */
    656640
    657641    if (m->fNeedDhcpServer)
     
    682666                  return E_FAIL;
    683667                /* breakthrough */
    684             case S_OK:
     668
    685669            {
    686670                LogFunc(("gateway: %s, dhcpserver:%s, dhcplowerip:%s, dhcpupperip:%s\n",
     
    689673                         Utf8Str(m->IPv4DhcpServerLowerIp.raw()).c_str(),
    690674                         Utf8Str(m->IPv4DhcpServerUpperIp.raw()).c_str()));
    691                          
     675
     676                m->dhcpServer->AddGlobalOption(DhcpOpt_Router, m->IPv4Gateway.raw());
    692677
    693678                rc = m->dhcpServer->SetEnabled(true);
     679
    694680                BSTR dhcpip = NULL;
    695681                BSTR netmask = NULL;
    696682                BSTR lowerip = NULL;
    697683                BSTR upperip = NULL;
     684
    698685                m->IPv4DhcpServer.cloneTo(&dhcpip);
    699686                m->IPv4NetworkMask.cloneTo(&netmask);
    700                
    701687                m->IPv4DhcpServerLowerIp.cloneTo(&lowerip);
    702688                m->IPv4DhcpServerUpperIp.cloneTo(&upperip);
     
    705691                                                     lowerip,
    706692                                                     upperip);
    707             break;
    708693            }
    709            
    710         default:
    711             return E_FAIL;
     694            case S_OK:
     695                break;
     696               
     697            default:
     698                return E_FAIL;
    712699        }
    713700
     
    728715#else
    729716    NOREF(aTrunkType);
    730     return E_NOTIMPL;
     717    ReturnComNotImplemented();
    731718#endif
    732719}
     
    741728    }
    742729    else return E_FAIL;
    743        
    744730#else
    745     return E_NOTIMPL;
     731    ReturnComNotImplemented();
    746732#endif
    747733}
     
    818804        m->IPv4DhcpServerLowerIp = aszDhcpLowerIp;
    819805        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));
    821812    }
    822813    /* we need IPv4NetworkMask for NAT's gw service start */
  • trunk/src/VBox/Main/src-server/NetworkServiceRunner.cpp

    r46958 r46959  
    1515 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
    1616 */
    17 #include "DHCPServerRunner.h"
     17#include "NetworkServiceRunner.h"
    1818#include <iprt/process.h>
    1919#include <iprt/param.h>
     
    2222struct ARGDEF
    2323{
    24     DHCPCFG Type;
     24    NETCFG Type;
    2525    const char * Name;
    2626};
    2727
    28 #ifdef RT_OS_WINDOWS
    29 # define DHCP_EXECUTABLE_NAME "VBoxNetDHCP.exe"
    30 #else
    31 # define DHCP_EXECUTABLE_NAME "VBoxNetDHCP"
    32 #endif
    33 
    3428static const ARGDEF g_aArgDefs[] =
    3529{
    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"},
    5138};
    5239
    53 static const ARGDEF * getArgDef(DHCPCFG type)
     40static const ARGDEF * getArgDef(NETCFG type)
    5441{
    5542    for (unsigned i = 0; i < RT_ELEMENTS(g_aArgDefs); i++)
     
    6047}
    6148
    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()
     49void NetworkServiceRunner::detachFromServer()
    7250{
    7351    mProcess = NIL_RTPROCESS;
    7452}
    7553
    76 int DHCPServerRunner::start()
     54int NetworkServiceRunner::start()
    7755{
    7856    if (isRunning())
    7957        return VINF_ALREADY_INITIALIZED;
    8058
    81     const char * args[DHCPCFG_NOTOPT_MAXVAL * 2];
     59    const char * args[NETCFG_NOTOPT_MAXVAL * 2];
    8260
    8361    /* get the path to the executable */
     
    9169    {
    9270        suffix++;
    93         strcpy(suffix, DHCP_EXECUTABLE_NAME);
     71        strcpy(suffix, mProcName);
    9472    }
    95     else
    96         exePath = DHCP_EXECUTABLE_NAME;
    9773
    9874    int index = 0;
     
    10076    args[index++] = exePath;
    10177
    102     for (unsigned i = 0; i < DHCPCFG_NOTOPT_MAXVAL; i++)
     78    for (unsigned i = 0; i < NETCFG_NOTOPT_MAXVAL; i++)
    10379    {
    10480        if (mOptionEnabled[i])
    10581        {
    106             const ARGDEF *pArgDef = getArgDef((DHCPCFG)i);
     82            const ARGDEF *pArgDef = getArgDef((NETCFG)i);
    10783            if (!pArgDef)
    10884                continue;
    109             args[index++] = pArgDef->Name;      // e.g. "--network"
     85            args[index++] = pArgDef->Name;
    11086
    111             /* value can be null for e.g. --begin-config has no value
    112              * and thus check the mOptions string length here
    113              */
    11487            if (mOptions[i].length())
    11588                args[index++] = mOptions[i].c_str();  // value
     
    11992    args[index++] = NULL;
    12093
    121     int rc = RTProcCreate(exePath, args, RTENV_DEFAULT, 0, &mProcess);
     94    int rc = RTProcCreate(suffix ? exePath : mProcName, args, RTENV_DEFAULT, 0, &mProcess);
    12295    if (RT_FAILURE(rc))
    12396        mProcess = NIL_RTPROCESS;
     
    12699}
    127100
    128 int DHCPServerRunner::stop()
     101int NetworkServiceRunner::stop()
    129102{
    130103    if (!isRunning())
     
    136109}
    137110
    138 bool DHCPServerRunner::isRunning()
     111bool NetworkServiceRunner::isRunning()
    139112{
    140113    if (mProcess == NIL_RTPROCESS)
  • trunk/src/VBox/Main/src-server/VirtualBoxImpl.cpp

    r46651 r46959  
    6161#include "SystemPropertiesImpl.h"
    6262#include "GuestOSTypeImpl.h"
    63 #include "DHCPServerRunner.h"
     63#include "NetworkServiceRunner.h"
    6464#include "DHCPServerImpl.h"
    6565#include "NATNetworkImpl.h"
  • trunk/src/VBox/Main/src-server/xpcom/server.cpp

    r46909 r46959  
    6767#include "BandwidthControlImpl.h"
    6868#include "BandwidthGroupImpl.h"
    69 #include "DHCPServerRunner.h"
     69#include "NetworkServiceRunner.h"
    7070#include "DHCPServerImpl.h"
    7171#include "GuestOSTypeImpl.h"
  • trunk/src/VBox/Main/xml/Settings.cpp

    r46720 r46959  
    13021302            if (    (pelmServer->getAttributeValue("networkName", srv.strNetworkName))
    13031303                 && (pelmServer->getAttributeValue("IPAddress", srv.strIPAddress))
    1304                  && (pelmServer->getAttributeValue("networkMask", srv.strIPNetworkMask))
     1304                    && (pelmServer->getAttributeValue("networkMask", srv.GlobalDhcpOptions[DhcpOpt_SubnetMask]))
    13051305                 && (pelmServer->getAttributeValue("lowerIP", srv.strIPLower))
    13061306                 && (pelmServer->getAttributeValue("upperIP", srv.strIPUpper))
    13071307                 && (pelmServer->getAttributeValue("enabled", srv.fEnabled))
    13081308               )
     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                }
    13091329                llDhcpServers.push_back(srv);
     1330            }
    13101331            else
    13111332                throw ConfigFileError(this, pelmServer, N_("Required DHCPServer/@networkName, @IPAddress, @networkMask, @lowerIP, @upperIP or @enabled attribute is missing"));
    13121333        }
    13131334    }
     1335}
     1336
     1337void 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
    13141357}
    13151358
     
    14461489#endif
    14471490        srv.strIPAddress = "192.168.56.100";
    1448         srv.strIPNetworkMask = "255.255.255.0";
     1491        srv.GlobalDhcpOptions[DhcpOpt_SubnetMask] = "255.255.255.0";
    14491492        srv.strIPLower = "192.168.56.101";
    14501493        srv.strIPUpper = "192.168.56.254";
     
    14891532        const DHCPServer &d = *it;
    14901533        xml::ElementNode *pelmThis = pelmDHCPServers->createChild("DHCPServer");
     1534        DhcpOptConstIterator itOpt;
     1535        itOpt = d.GlobalDhcpOptions.find(DhcpOpt_SubnetMask);
     1536
    14911537        pelmThis->setAttribute("networkName", d.strNetworkName);
    14921538        pelmThis->setAttribute("IPAddress", d.strIPAddress);
    1493         pelmThis->setAttribute("networkMask", d.strIPNetworkMask);
     1539        if (itOpt != d.GlobalDhcpOptions.end())
     1540            pelmThis->setAttribute("networkMask", itOpt->second);
    14941541        pelmThis->setAttribute("lowerIP", d.strIPLower);
    14951542        pelmThis->setAttribute("upperIP", d.strIPUpper);
    14961543        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     }
    14981593
    14991594    /* TODO: bump main version ? */
Note: See TracChangeset for help on using the changeset viewer.

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette