1 | /* $Id: DHCPServerImpl.h 47018 2013-07-06 17:31:11Z vboxsync $ */
|
---|
2 |
|
---|
3 | /** @file
|
---|
4 | *
|
---|
5 | * VirtualBox COM class implementation
|
---|
6 | */
|
---|
7 |
|
---|
8 | /*
|
---|
9 | * Copyright (C) 2006-2011 Oracle Corporation
|
---|
10 | *
|
---|
11 | * This file is part of VirtualBox Open Source Edition (OSE), as
|
---|
12 | * available from http://www.virtualbox.org. This file is free software;
|
---|
13 | * you can redistribute it and/or modify it under the terms of the GNU
|
---|
14 | * General Public License (GPL) as published by the Free Software
|
---|
15 | * Foundation, in version 2 as it comes in the "COPYING" file of the
|
---|
16 | * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
|
---|
17 | * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
|
---|
18 | */
|
---|
19 |
|
---|
20 | #ifndef ____H_H_DHCPSERVERIMPL
|
---|
21 | #define ____H_H_DHCPSERVERIMPL
|
---|
22 |
|
---|
23 | #include "VirtualBoxBase.h"
|
---|
24 |
|
---|
25 | #ifdef VBOX_WITH_HOSTNETIF_API
|
---|
26 | struct NETIFINFO;
|
---|
27 | #endif
|
---|
28 |
|
---|
29 | namespace settings
|
---|
30 | {
|
---|
31 | struct DHCPServer;
|
---|
32 | struct VmNameSlotKey;
|
---|
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 |
|
---|
69 |
|
---|
70 | class ATL_NO_VTABLE DHCPServer :
|
---|
71 | public VirtualBoxBase,
|
---|
72 | VBOX_SCRIPTABLE_IMPL(IDHCPServer)
|
---|
73 | {
|
---|
74 | public:
|
---|
75 |
|
---|
76 | VIRTUALBOXBASE_ADD_ERRORINFO_SUPPORT(DHCPServer, IDHCPServer)
|
---|
77 |
|
---|
78 | DECLARE_NOT_AGGREGATABLE (DHCPServer)
|
---|
79 |
|
---|
80 | DECLARE_PROTECT_FINAL_CONSTRUCT()
|
---|
81 |
|
---|
82 | BEGIN_COM_MAP (DHCPServer)
|
---|
83 | VBOX_DEFAULT_INTERFACE_ENTRIES(IDHCPServer)
|
---|
84 | END_COM_MAP()
|
---|
85 |
|
---|
86 | DECLARE_EMPTY_CTOR_DTOR (DHCPServer)
|
---|
87 |
|
---|
88 | HRESULT FinalConstruct();
|
---|
89 | void FinalRelease();
|
---|
90 |
|
---|
91 | HRESULT init(VirtualBox *aVirtualBox,
|
---|
92 | IN_BSTR aName);
|
---|
93 | HRESULT init(VirtualBox *aVirtualBox,
|
---|
94 | const settings::DHCPServer &data);
|
---|
95 | HRESULT saveSettings(settings::DHCPServer &data);
|
---|
96 |
|
---|
97 | void uninit();
|
---|
98 |
|
---|
99 | // IDHCPServer properties
|
---|
100 | STDMETHOD(COMGETTER(NetworkName))(BSTR *aName);
|
---|
101 | STDMETHOD(COMGETTER(Enabled))(BOOL *aEnabled);
|
---|
102 | STDMETHOD(COMSETTER(Enabled))(BOOL aEnabled);
|
---|
103 | STDMETHOD(COMGETTER(IPAddress))(BSTR *aIPAddress);
|
---|
104 | STDMETHOD(COMGETTER(NetworkMask))(BSTR *aNetworkMask);
|
---|
105 | STDMETHOD(COMGETTER(LowerIP))(BSTR *aIPAddress);
|
---|
106 | STDMETHOD(COMGETTER(UpperIP))(BSTR *aIPAddress);
|
---|
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 |
|
---|
117 | STDMETHOD(SetConfiguration)(IN_BSTR aIPAddress, IN_BSTR aNetworkMask, IN_BSTR aFromIPAddress, IN_BSTR aToIPAddress);
|
---|
118 |
|
---|
119 | STDMETHOD(Start)(IN_BSTR aNetworkName, IN_BSTR aTrunkName, IN_BSTR aTrunkType);
|
---|
120 | STDMETHOD(Stop)();
|
---|
121 |
|
---|
122 | private:
|
---|
123 | /** weak VirtualBox parent */
|
---|
124 | VirtualBox * const mVirtualBox;
|
---|
125 |
|
---|
126 | const Bstr mName;
|
---|
127 |
|
---|
128 | struct Data
|
---|
129 | {
|
---|
130 | Data() : enabled(FALSE) {}
|
---|
131 |
|
---|
132 | Bstr IPAddress;
|
---|
133 | Bstr lowerIP;
|
---|
134 | Bstr upperIP;
|
---|
135 |
|
---|
136 | BOOL enabled;
|
---|
137 | DHCPServerRunner dhcp;
|
---|
138 |
|
---|
139 | DhcpOptionMap GlobalDhcpOptions;
|
---|
140 | VmSlot2OptionsMap VmSlot2Options;
|
---|
141 | } m;
|
---|
142 |
|
---|
143 | DhcpOptionMap& findOptMapByVmNameSlot(const com::Utf8Str& aVmName,
|
---|
144 | LONG Slot);
|
---|
145 | };
|
---|
146 |
|
---|
147 | #endif // ____H_H_DHCPSERVERIMPL
|
---|