1 | /* $Id: DHCPConfigImpl.h 93115 2022-01-01 11:31:46Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * VirtualBox Main - IDHCPConfig, IDHCPConfigGlobal, IDHCPConfigGroup, IDHCPConfigIndividual header.
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2006-2022 Oracle Corporation
|
---|
8 | *
|
---|
9 | * This file is part of VirtualBox Open Source Edition (OSE), as
|
---|
10 | * available from http://www.virtualbox.org. This file is free software;
|
---|
11 | * you can redistribute it and/or modify it under the terms of the GNU
|
---|
12 | * General Public License (GPL) as published by the Free Software
|
---|
13 | * Foundation, in version 2 as it comes in the "COPYING" file of the
|
---|
14 | * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
|
---|
15 | * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
|
---|
16 | */
|
---|
17 |
|
---|
18 | #ifndef MAIN_INCLUDED_DHCPConfigImpl_h
|
---|
19 | #define MAIN_INCLUDED_DHCPConfigImpl_h
|
---|
20 | #ifndef RT_WITHOUT_PRAGMA_ONCE
|
---|
21 | # pragma once
|
---|
22 | #endif
|
---|
23 |
|
---|
24 | #include "DHCPGlobalConfigWrap.h"
|
---|
25 | #include "DHCPGroupConditionWrap.h"
|
---|
26 | #include "DHCPGroupConfigWrap.h"
|
---|
27 | #include "DHCPIndividualConfigWrap.h"
|
---|
28 | #include <VBox/settings.h>
|
---|
29 |
|
---|
30 |
|
---|
31 | class DHCPServer;
|
---|
32 | class DHCPGroupConfig;
|
---|
33 |
|
---|
34 |
|
---|
35 | /**
|
---|
36 | * Base class for the a DHCP configration layer.
|
---|
37 | *
|
---|
38 | * This does not inherit from DHCPConfigWrap because its children need to
|
---|
39 | * inherit from children of DHCPConfigWrap, which smells like trouble and thus
|
---|
40 | * wasn't even attempted. Instead, we have a hack for passing a pointer that we
|
---|
41 | * can call setError and such on.
|
---|
42 | */
|
---|
43 | class DHCPConfig
|
---|
44 | {
|
---|
45 | protected:
|
---|
46 | /** Config scope (global, group, vm+nic, mac). */
|
---|
47 | DHCPConfigScope_T const m_enmScope;
|
---|
48 | /** Minimum lease time. */
|
---|
49 | ULONG m_secMinLeaseTime;
|
---|
50 | /** Default lease time. */
|
---|
51 | ULONG m_secDefaultLeaseTime;
|
---|
52 | /** Maximum lease time. */
|
---|
53 | ULONG m_secMaxLeaseTime;
|
---|
54 | /** List of options which are forced upon the client when available, whether
|
---|
55 | * requested by it or not. */
|
---|
56 | std::vector<DHCPOption_T> m_vecForcedOptions;
|
---|
57 | /** List of options which should be suppressed and not returned the the client
|
---|
58 | * when available and requested. */
|
---|
59 | std::vector<DHCPOption_T> m_vecSuppressedOptions;
|
---|
60 | /** DHCP option map. */
|
---|
61 | settings::DhcpOptionMap m_OptionMap;
|
---|
62 | /** The DHCP server parent (weak). */
|
---|
63 | DHCPServer * const m_pParent;
|
---|
64 | /** The DHCP server parent (weak). */
|
---|
65 | VirtualBox * const m_pVirtualBox;
|
---|
66 | private:
|
---|
67 | /** For setError and such. */
|
---|
68 | VirtualBoxBase * const m_pHack;
|
---|
69 |
|
---|
70 | protected:
|
---|
71 | /** @name Constructors and destructors.
|
---|
72 | * @{ */
|
---|
73 | DHCPConfig(DHCPConfigScope_T a_enmScope, VirtualBoxBase *a_pHack)
|
---|
74 | : m_enmScope(a_enmScope), m_secMinLeaseTime(0), m_secDefaultLeaseTime(0), m_secMaxLeaseTime(0), m_OptionMap()
|
---|
75 | , m_pParent(NULL), m_pVirtualBox(NULL), m_pHack(a_pHack)
|
---|
76 | {}
|
---|
77 | DHCPConfig();
|
---|
78 | virtual ~DHCPConfig()
|
---|
79 | {}
|
---|
80 | HRESULT i_initWithDefaults(VirtualBox *a_pVirtualBox, DHCPServer *a_pParent);
|
---|
81 | HRESULT i_initWithSettings(VirtualBox *a_pVirtualBox, DHCPServer *a_pParent, const settings::DHCPConfig &rConfig);
|
---|
82 | /** @} */
|
---|
83 |
|
---|
84 | /** @name IDHCPConfig properties
|
---|
85 | * @{ */
|
---|
86 | HRESULT i_getScope(DHCPConfigScope_T *aScope);
|
---|
87 | HRESULT i_getMinLeaseTime(ULONG *aMinLeaseTime);
|
---|
88 | HRESULT i_setMinLeaseTime(ULONG aMinLeaseTime);
|
---|
89 | HRESULT i_getDefaultLeaseTime(ULONG *aDefaultLeaseTime);
|
---|
90 | HRESULT i_setDefaultLeaseTime(ULONG aDefaultLeaseTime);
|
---|
91 | HRESULT i_getMaxLeaseTime(ULONG *aMaxLeaseTime);
|
---|
92 | HRESULT i_setMaxLeaseTime(ULONG aMaxLeaseTime);
|
---|
93 | HRESULT i_getForcedOptions(std::vector<DHCPOption_T> &aOptions);
|
---|
94 | HRESULT i_setForcedOptions(const std::vector<DHCPOption_T> &aOptions);
|
---|
95 | HRESULT i_getSuppressedOptions(std::vector<DHCPOption_T> &aOptions);
|
---|
96 | HRESULT i_setSuppressedOptions(const std::vector<DHCPOption_T> &aOptions);
|
---|
97 | /** @} */
|
---|
98 |
|
---|
99 | public:
|
---|
100 | DECLARE_TRANSLATE_METHODS(DHCPConfig)
|
---|
101 |
|
---|
102 | /** @name IDHCPConfig methods
|
---|
103 | * @note public because the DHCPServer needs them for 6.0 interfaces.
|
---|
104 | * @todo Make protected again when IDHCPServer is cleaned up.
|
---|
105 | * @{ */
|
---|
106 | virtual HRESULT i_setOption(DHCPOption_T aOption, DHCPOptionEncoding_T aEncoding, const com::Utf8Str &aValue);
|
---|
107 |
|
---|
108 | virtual HRESULT i_removeOption(DHCPOption_T aOption);
|
---|
109 | virtual HRESULT i_removeAllOptions();
|
---|
110 | HRESULT i_getOption(DHCPOption_T aOption, DHCPOptionEncoding_T *aEncoding, com::Utf8Str &aValue);
|
---|
111 | HRESULT i_getAllOptions(std::vector<DHCPOption_T> &aOptions, std::vector<DHCPOptionEncoding_T> &aEncodings,
|
---|
112 | std::vector<com::Utf8Str> &aValues);
|
---|
113 | virtual HRESULT i_remove();
|
---|
114 | /** @} */
|
---|
115 |
|
---|
116 |
|
---|
117 | public:
|
---|
118 | HRESULT i_doWriteConfig();
|
---|
119 | HRESULT i_saveSettings(settings::DHCPConfig &a_rDst);
|
---|
120 | DHCPConfigScope_T i_getScope() const RT_NOEXCEPT { return m_enmScope; }
|
---|
121 | virtual void i_writeDhcpdConfig(xml::ElementNode *pElm);
|
---|
122 | };
|
---|
123 |
|
---|
124 |
|
---|
125 | /**
|
---|
126 | * Global DHCP configuration.
|
---|
127 | */
|
---|
128 | class DHCPGlobalConfig : public DHCPGlobalConfigWrap, public DHCPConfig
|
---|
129 | {
|
---|
130 | public:
|
---|
131 | DECLARE_TRANSLATE_METHODS(DHCPGlobalConfig)
|
---|
132 |
|
---|
133 | /** @name Constructors and destructors.
|
---|
134 | * @{ */
|
---|
135 | DHCPGlobalConfig()
|
---|
136 | : DHCPConfig(DHCPConfigScope_Global, this)
|
---|
137 | { }
|
---|
138 | HRESULT FinalConstruct()
|
---|
139 | {
|
---|
140 | return BaseFinalConstruct();
|
---|
141 | }
|
---|
142 | void FinalRelease()
|
---|
143 | {
|
---|
144 | uninit();
|
---|
145 | BaseFinalRelease();
|
---|
146 | }
|
---|
147 | HRESULT initWithDefaults(VirtualBox *a_pVirtualBox, DHCPServer *a_pParent);
|
---|
148 | HRESULT initWithSettings(VirtualBox *a_pVirtualBox, DHCPServer *a_pParent, const settings::DHCPConfig &rConfig);
|
---|
149 | void uninit();
|
---|
150 | /** @} */
|
---|
151 |
|
---|
152 | HRESULT i_saveSettings(settings::DHCPConfig &a_rDst);
|
---|
153 | HRESULT i_getNetworkMask(com::Utf8Str &a_rDst);
|
---|
154 | HRESULT i_setNetworkMask(const com::Utf8Str &a_rSrc);
|
---|
155 |
|
---|
156 | protected:
|
---|
157 | /** @name wrapped IDHCPConfig properties
|
---|
158 | * @{ */
|
---|
159 | HRESULT getScope(DHCPConfigScope_T *aScope) RT_OVERRIDE { return i_getScope(aScope); }
|
---|
160 | HRESULT getMinLeaseTime(ULONG *aMinLeaseTime) RT_OVERRIDE { return i_getMinLeaseTime(aMinLeaseTime); }
|
---|
161 | HRESULT setMinLeaseTime(ULONG aMinLeaseTime) RT_OVERRIDE { return i_setMinLeaseTime(aMinLeaseTime); }
|
---|
162 | HRESULT getDefaultLeaseTime(ULONG *aDefaultLeaseTime) RT_OVERRIDE { return i_getDefaultLeaseTime(aDefaultLeaseTime); }
|
---|
163 | HRESULT setDefaultLeaseTime(ULONG aDefaultLeaseTime) RT_OVERRIDE { return i_setDefaultLeaseTime(aDefaultLeaseTime); }
|
---|
164 | HRESULT getMaxLeaseTime(ULONG *aMaxLeaseTime) RT_OVERRIDE { return i_getMaxLeaseTime(aMaxLeaseTime); }
|
---|
165 | HRESULT setMaxLeaseTime(ULONG aMaxLeaseTime) RT_OVERRIDE { return i_setMaxLeaseTime(aMaxLeaseTime); }
|
---|
166 | HRESULT getForcedOptions(std::vector<DHCPOption_T> &aOptions) RT_OVERRIDE { return i_getForcedOptions(aOptions); }
|
---|
167 | HRESULT setForcedOptions(const std::vector<DHCPOption_T> &aOptions) RT_OVERRIDE { return i_setForcedOptions(aOptions); }
|
---|
168 | HRESULT getSuppressedOptions(std::vector<DHCPOption_T> &aOptions) RT_OVERRIDE { return i_getSuppressedOptions(aOptions); }
|
---|
169 | HRESULT setSuppressedOptions(const std::vector<DHCPOption_T> &aOptions) RT_OVERRIDE { return i_setSuppressedOptions(aOptions); }
|
---|
170 | /** @} */
|
---|
171 |
|
---|
172 | /** @name wrapped IDHCPConfig methods
|
---|
173 | * @{ */
|
---|
174 | HRESULT setOption(DHCPOption_T aOption, DHCPOptionEncoding_T aEncoding, const com::Utf8Str &aValue) RT_OVERRIDE
|
---|
175 | {
|
---|
176 | return i_setOption(aOption, aEncoding, aValue);
|
---|
177 | }
|
---|
178 |
|
---|
179 | HRESULT removeOption(DHCPOption_T aOption) RT_OVERRIDE
|
---|
180 | {
|
---|
181 | return i_removeOption(aOption);
|
---|
182 | }
|
---|
183 |
|
---|
184 | HRESULT removeAllOptions() RT_OVERRIDE
|
---|
185 | {
|
---|
186 | return i_removeAllOptions();
|
---|
187 | }
|
---|
188 |
|
---|
189 | HRESULT getOption(DHCPOption_T aOption, DHCPOptionEncoding_T *aEncoding, com::Utf8Str &aValue) RT_OVERRIDE
|
---|
190 | {
|
---|
191 | return i_getOption(aOption, aEncoding, aValue);
|
---|
192 | }
|
---|
193 |
|
---|
194 | HRESULT getAllOptions(std::vector<DHCPOption_T> &aOptions, std::vector<DHCPOptionEncoding_T> &aEncodings,
|
---|
195 | std::vector<com::Utf8Str> &aValues) RT_OVERRIDE
|
---|
196 | {
|
---|
197 | return i_getAllOptions(aOptions, aEncodings, aValues);
|
---|
198 | }
|
---|
199 |
|
---|
200 | HRESULT remove() RT_OVERRIDE
|
---|
201 | {
|
---|
202 | return i_remove();
|
---|
203 | }
|
---|
204 | /** @} */
|
---|
205 |
|
---|
206 | public:
|
---|
207 | HRESULT i_setOption(DHCPOption_T aOption, DHCPOptionEncoding_T aEncoding, const com::Utf8Str &aValue) RT_OVERRIDE;
|
---|
208 | HRESULT i_removeOption(DHCPOption_T aOption) RT_OVERRIDE;
|
---|
209 | HRESULT i_removeAllOptions() RT_OVERRIDE;
|
---|
210 | HRESULT i_remove() RT_OVERRIDE;
|
---|
211 | };
|
---|
212 |
|
---|
213 |
|
---|
214 | /**
|
---|
215 | * DHCP Group inclusion/exclusion condition.
|
---|
216 | */
|
---|
217 | class DHCPGroupCondition : public DHCPGroupConditionWrap
|
---|
218 | {
|
---|
219 | private:
|
---|
220 | /** Inclusive or exclusive condition. */
|
---|
221 | bool m_fInclusive;
|
---|
222 | /** The condition type (or how m_strValue should be interpreted). */
|
---|
223 | DHCPGroupConditionType_T m_enmType;
|
---|
224 | /** The value. Interpreted according to m_enmType. */
|
---|
225 | com::Utf8Str m_strValue;
|
---|
226 | /** Pointer to the parent (weak). */
|
---|
227 | DHCPGroupConfig *m_pParent;
|
---|
228 |
|
---|
229 | public:
|
---|
230 | DECLARE_TRANSLATE_METHODS(DHCPGroupCondition)
|
---|
231 |
|
---|
232 | /** @name Constructors and destructors.
|
---|
233 | * @{ */
|
---|
234 | DHCPGroupCondition()
|
---|
235 | : m_enmType(DHCPGroupConditionType_MAC)
|
---|
236 | , m_pParent(NULL)
|
---|
237 | {}
|
---|
238 | HRESULT FinalConstruct()
|
---|
239 | {
|
---|
240 | return BaseFinalConstruct();
|
---|
241 | }
|
---|
242 | void FinalRelease()
|
---|
243 | {
|
---|
244 | uninit();
|
---|
245 | BaseFinalRelease();
|
---|
246 | }
|
---|
247 | HRESULT initWithDefaults(DHCPGroupConfig *a_pParent, bool a_fInclusive, DHCPGroupConditionType_T a_enmType,
|
---|
248 | const com::Utf8Str a_strValue);
|
---|
249 | HRESULT initWithSettings(DHCPGroupConfig *a_pParent, const settings::DHCPGroupCondition &a_rSrc);
|
---|
250 | void uninit();
|
---|
251 | /** @} */
|
---|
252 |
|
---|
253 | HRESULT i_saveSettings(settings::DHCPGroupCondition &a_rDst);
|
---|
254 | static HRESULT i_validateTypeAndValue(DHCPGroupConditionType_T enmType, com::Utf8Str const &strValue,
|
---|
255 | VirtualBoxBase *pErrorDst);
|
---|
256 |
|
---|
257 | /** @name Internal accessors
|
---|
258 | * @{ */
|
---|
259 | bool i_getInclusive() const RT_NOEXCEPT { return m_fInclusive; }
|
---|
260 | DHCPGroupConditionType_T i_getType() const RT_NOEXCEPT { return m_enmType; }
|
---|
261 | com::Utf8Str const &i_getValue() const RT_NOEXCEPT { return m_strValue; }
|
---|
262 | /** @} */
|
---|
263 |
|
---|
264 | protected:
|
---|
265 | /** @name Wrapped IDHCPGroupCondition properties
|
---|
266 | * @{ */
|
---|
267 | HRESULT getInclusive(BOOL *aInclusive) RT_OVERRIDE;
|
---|
268 | HRESULT setInclusive(BOOL aInclusive) RT_OVERRIDE;
|
---|
269 | HRESULT getType(DHCPGroupConditionType_T *aType) RT_OVERRIDE;
|
---|
270 | HRESULT setType(DHCPGroupConditionType_T aType) RT_OVERRIDE;
|
---|
271 | HRESULT getValue(com::Utf8Str &aValue) RT_OVERRIDE;
|
---|
272 | HRESULT setValue(const com::Utf8Str &aValue) RT_OVERRIDE;
|
---|
273 | /** @} */
|
---|
274 |
|
---|
275 | /** @name Wrapped IDHCPGroupCondition methods
|
---|
276 | * @{ */
|
---|
277 | HRESULT remove() RT_OVERRIDE;
|
---|
278 | /** @} */
|
---|
279 | };
|
---|
280 |
|
---|
281 |
|
---|
282 | /**
|
---|
283 | * Group configuration.
|
---|
284 | */
|
---|
285 | class DHCPGroupConfig : public DHCPGroupConfigWrap, public DHCPConfig
|
---|
286 | {
|
---|
287 | private:
|
---|
288 | /** Group name. */
|
---|
289 | com::Utf8Str m_strName;
|
---|
290 | /** Group membership conditions. */
|
---|
291 | std::vector<ComObjPtr<DHCPGroupCondition> > m_Conditions;
|
---|
292 | /** Iterator for m_Conditions. */
|
---|
293 | typedef std::vector<ComObjPtr<DHCPGroupCondition> >::iterator ConditionsIterator;
|
---|
294 |
|
---|
295 | public:
|
---|
296 | DECLARE_TRANSLATE_METHODS(DHCPGroupConfig)
|
---|
297 |
|
---|
298 | /** @name Constructors and destructors.
|
---|
299 | * @{ */
|
---|
300 | DHCPGroupConfig()
|
---|
301 | : DHCPConfig(DHCPConfigScope_Group, this)
|
---|
302 | { }
|
---|
303 | HRESULT FinalConstruct()
|
---|
304 | {
|
---|
305 | return BaseFinalConstruct();
|
---|
306 | }
|
---|
307 | void FinalRelease()
|
---|
308 | {
|
---|
309 | uninit();
|
---|
310 | BaseFinalRelease();
|
---|
311 | }
|
---|
312 | HRESULT initWithDefaults(VirtualBox *a_pVirtualBox, DHCPServer *a_pParent, const com::Utf8Str &a_rName);
|
---|
313 | HRESULT initWithSettings(VirtualBox *a_pVirtualBox, DHCPServer *a_pParent, const settings::DHCPGroupConfig &a_rSrc);
|
---|
314 | void uninit();
|
---|
315 | /** @} */
|
---|
316 |
|
---|
317 | HRESULT i_saveSettings(settings::DHCPGroupConfig &a_rDst);
|
---|
318 | HRESULT i_removeCondition(DHCPGroupCondition *a_pCondition);
|
---|
319 | void i_writeDhcpdConfig(xml::ElementNode *a_pElmGroup) RT_OVERRIDE;
|
---|
320 |
|
---|
321 | protected:
|
---|
322 | /** @name Wrapped IDHCPConfig properties
|
---|
323 | * @{ */
|
---|
324 | HRESULT getScope(DHCPConfigScope_T *aScope) RT_OVERRIDE { return i_getScope(aScope); }
|
---|
325 | HRESULT getMinLeaseTime(ULONG *aMinLeaseTime) RT_OVERRIDE { return i_getMinLeaseTime(aMinLeaseTime); }
|
---|
326 | HRESULT setMinLeaseTime(ULONG aMinLeaseTime) RT_OVERRIDE { return i_setMinLeaseTime(aMinLeaseTime); }
|
---|
327 | HRESULT getDefaultLeaseTime(ULONG *aDefaultLeaseTime) RT_OVERRIDE { return i_getDefaultLeaseTime(aDefaultLeaseTime); }
|
---|
328 | HRESULT setDefaultLeaseTime(ULONG aDefaultLeaseTime) RT_OVERRIDE { return i_setDefaultLeaseTime(aDefaultLeaseTime); }
|
---|
329 | HRESULT getMaxLeaseTime(ULONG *aMaxLeaseTime) RT_OVERRIDE { return i_getMaxLeaseTime(aMaxLeaseTime); }
|
---|
330 | HRESULT setMaxLeaseTime(ULONG aMaxLeaseTime) RT_OVERRIDE { return i_setMaxLeaseTime(aMaxLeaseTime); }
|
---|
331 | HRESULT getForcedOptions(std::vector<DHCPOption_T> &aOptions) RT_OVERRIDE { return i_getForcedOptions(aOptions); }
|
---|
332 | HRESULT setForcedOptions(const std::vector<DHCPOption_T> &aOptions) RT_OVERRIDE { return i_setForcedOptions(aOptions); }
|
---|
333 | HRESULT getSuppressedOptions(std::vector<DHCPOption_T> &aOptions) RT_OVERRIDE { return i_getSuppressedOptions(aOptions); }
|
---|
334 | HRESULT setSuppressedOptions(const std::vector<DHCPOption_T> &aOptions) RT_OVERRIDE { return i_setSuppressedOptions(aOptions); }
|
---|
335 | /** @} */
|
---|
336 |
|
---|
337 | /** @name Wrapped IDHCPGroupConfig properties
|
---|
338 | * @{ */
|
---|
339 | HRESULT getName(com::Utf8Str &aName) RT_OVERRIDE;
|
---|
340 | HRESULT setName(const com::Utf8Str &aName) RT_OVERRIDE;
|
---|
341 | HRESULT getConditions(std::vector<ComPtr<IDHCPGroupCondition> > &aConditions) RT_OVERRIDE;
|
---|
342 | /** @} */
|
---|
343 |
|
---|
344 | /** @name Wrapped IDHCPConfig methods
|
---|
345 | * @{ */
|
---|
346 | HRESULT setOption(DHCPOption_T aOption, DHCPOptionEncoding_T aEncoding, const com::Utf8Str &aValue) RT_OVERRIDE
|
---|
347 | {
|
---|
348 | return i_setOption(aOption, aEncoding, aValue);
|
---|
349 | }
|
---|
350 |
|
---|
351 | HRESULT removeOption(DHCPOption_T aOption) RT_OVERRIDE
|
---|
352 | {
|
---|
353 | return i_removeOption(aOption);
|
---|
354 | }
|
---|
355 |
|
---|
356 | HRESULT removeAllOptions() RT_OVERRIDE
|
---|
357 | {
|
---|
358 | return i_removeAllOptions();
|
---|
359 | }
|
---|
360 |
|
---|
361 | HRESULT getOption(DHCPOption_T aOption, DHCPOptionEncoding_T *aEncoding, com::Utf8Str &aValue) RT_OVERRIDE
|
---|
362 | {
|
---|
363 | return i_getOption(aOption, aEncoding, aValue);
|
---|
364 | }
|
---|
365 |
|
---|
366 | HRESULT getAllOptions(std::vector<DHCPOption_T> &aOptions, std::vector<DHCPOptionEncoding_T> &aEncodings,
|
---|
367 | std::vector<com::Utf8Str> &aValues) RT_OVERRIDE
|
---|
368 | {
|
---|
369 | return i_getAllOptions(aOptions, aEncodings, aValues);
|
---|
370 | }
|
---|
371 |
|
---|
372 | HRESULT remove() RT_OVERRIDE
|
---|
373 | {
|
---|
374 | return i_remove();
|
---|
375 | }
|
---|
376 | /** @} */
|
---|
377 |
|
---|
378 | /** @name Wrapped IDHCPGroupConfig methods
|
---|
379 | * @{ */
|
---|
380 | HRESULT addCondition(BOOL aInclusive, DHCPGroupConditionType_T aType, const com::Utf8Str &aValue,
|
---|
381 | ComPtr<IDHCPGroupCondition> &aCondition) RT_OVERRIDE;
|
---|
382 | HRESULT removeAllConditions() RT_OVERRIDE;
|
---|
383 | /** @} */
|
---|
384 | };
|
---|
385 |
|
---|
386 |
|
---|
387 | /**
|
---|
388 | * Individual DHCP configuration.
|
---|
389 | */
|
---|
390 | class DHCPIndividualConfig : public DHCPIndividualConfigWrap, public DHCPConfig
|
---|
391 | {
|
---|
392 | private:
|
---|
393 | /** The MAC address or all zeros. */
|
---|
394 | RTMAC m_MACAddress;
|
---|
395 | /** The VM ID or all zeros. */
|
---|
396 | com::Guid const m_idMachine;
|
---|
397 | /** The VM NIC slot number, or ~(ULONG)0. */
|
---|
398 | ULONG const m_uSlot;
|
---|
399 | /** This is part of a hack to resolve the MAC address for
|
---|
400 | * DHCPConfigScope_MachineNIC instances. If non-zero, we m_MACAddress is valid.
|
---|
401 | * To deal with the impossibly theoretical scenario that the DHCP server is
|
---|
402 | * being started by more than one thread, this is a version number and not just
|
---|
403 | * a boolean indicator. */
|
---|
404 | uint32_t volatile m_uMACAddressResolvedVersion;
|
---|
405 |
|
---|
406 | /** The fixed IPv4 address, empty if dynamic. */
|
---|
407 | com::Utf8Str m_strFixedAddress;
|
---|
408 |
|
---|
409 | public:
|
---|
410 | DECLARE_TRANSLATE_METHODS(DHCPIndividualConfig)
|
---|
411 |
|
---|
412 | /** @name Constructors and destructors.
|
---|
413 | * @{ */
|
---|
414 | DHCPIndividualConfig()
|
---|
415 | : DHCPConfig(DHCPConfigScope_MAC, this)
|
---|
416 | , m_uSlot(~(ULONG)0)
|
---|
417 | , m_uMACAddressResolvedVersion(0)
|
---|
418 | {
|
---|
419 | RT_ZERO(m_MACAddress);
|
---|
420 | }
|
---|
421 | HRESULT FinalConstruct()
|
---|
422 | {
|
---|
423 | return BaseFinalConstruct();
|
---|
424 | }
|
---|
425 | void FinalRelease()
|
---|
426 | {
|
---|
427 | uninit();
|
---|
428 | BaseFinalRelease();
|
---|
429 | }
|
---|
430 | HRESULT initWithMachineIdAndSlot(VirtualBox *a_pVirtualBox, DHCPServer *a_pParent, com::Guid const &a_idMachine,
|
---|
431 | ULONG a_uSlot, uint32_t a_uMACAddressVersion);
|
---|
432 | HRESULT initWithMACAddress(VirtualBox *a_pVirtualBox, DHCPServer *a_pParent, PCRTMAC a_pMACAddress);
|
---|
433 | HRESULT initWithSettingsAndMachineIdAndSlot(VirtualBox *a_pVirtualBox, DHCPServer *a_pParent,
|
---|
434 | const settings::DHCPIndividualConfig &rData, com::Guid const &a_idMachine,
|
---|
435 | ULONG a_uSlot, uint32_t a_uMACAddressVersion);
|
---|
436 | HRESULT initWithSettingsAndMACAddress(VirtualBox *a_pVirtualBox, DHCPServer *a_pParent,
|
---|
437 | const settings::DHCPIndividualConfig &rData, PCRTMAC a_pMACAddress);
|
---|
438 | void uninit();
|
---|
439 | /** @} */
|
---|
440 |
|
---|
441 | /** @name Internal methods that are public for various reasons
|
---|
442 | * @{ */
|
---|
443 | HRESULT i_saveSettings(settings::DHCPIndividualConfig &a_rDst);
|
---|
444 | RTMAC const &i_getMACAddress() const RT_NOEXCEPT { return m_MACAddress; }
|
---|
445 | com::Guid const &i_getMachineId() const RT_NOEXCEPT { return m_idMachine; }
|
---|
446 | ULONG i_getSlot() const RT_NOEXCEPT { return m_uSlot; }
|
---|
447 | HRESULT i_getMachineMAC(PRTMAC pMACAddress);
|
---|
448 |
|
---|
449 | HRESULT i_resolveMACAddress(uint32_t uVersion);
|
---|
450 | /** This is used to avoid producing bogus Dhcpd configuration elements. */
|
---|
451 | bool i_isMACAddressResolved(uint32_t uVersion) const
|
---|
452 | {
|
---|
453 | return m_enmScope != DHCPConfigScope_MachineNIC || (int32_t)(m_uMACAddressResolvedVersion - uVersion) >= 0;
|
---|
454 | }
|
---|
455 | void i_writeDhcpdConfig(xml::ElementNode *pElm) RT_OVERRIDE;
|
---|
456 | /** @} */
|
---|
457 |
|
---|
458 | protected:
|
---|
459 | /** @name wrapped IDHCPConfig properties
|
---|
460 | * @{ */
|
---|
461 | HRESULT getScope(DHCPConfigScope_T *aScope) RT_OVERRIDE { return i_getScope(aScope); }
|
---|
462 | HRESULT getMinLeaseTime(ULONG *aMinLeaseTime) RT_OVERRIDE { return i_getMinLeaseTime(aMinLeaseTime); }
|
---|
463 | HRESULT setMinLeaseTime(ULONG aMinLeaseTime) RT_OVERRIDE { return i_setMinLeaseTime(aMinLeaseTime); }
|
---|
464 | HRESULT getDefaultLeaseTime(ULONG *aDefaultLeaseTime) RT_OVERRIDE { return i_getDefaultLeaseTime(aDefaultLeaseTime); }
|
---|
465 | HRESULT setDefaultLeaseTime(ULONG aDefaultLeaseTime) RT_OVERRIDE { return i_setDefaultLeaseTime(aDefaultLeaseTime); }
|
---|
466 | HRESULT getMaxLeaseTime(ULONG *aMaxLeaseTime) RT_OVERRIDE { return i_getMaxLeaseTime(aMaxLeaseTime); }
|
---|
467 | HRESULT setMaxLeaseTime(ULONG aMaxLeaseTime) RT_OVERRIDE { return i_setMaxLeaseTime(aMaxLeaseTime); }
|
---|
468 | HRESULT getForcedOptions(std::vector<DHCPOption_T> &aOptions) RT_OVERRIDE { return i_getForcedOptions(aOptions); }
|
---|
469 | HRESULT setForcedOptions(const std::vector<DHCPOption_T> &aOptions) RT_OVERRIDE { return i_setForcedOptions(aOptions); }
|
---|
470 | HRESULT getSuppressedOptions(std::vector<DHCPOption_T> &aOptions) RT_OVERRIDE { return i_getSuppressedOptions(aOptions); }
|
---|
471 | HRESULT setSuppressedOptions(const std::vector<DHCPOption_T> &aOptions) RT_OVERRIDE { return i_setSuppressedOptions(aOptions); }
|
---|
472 | /** @} */
|
---|
473 |
|
---|
474 | /** @name wrapped IDHCPConfig methods
|
---|
475 | * @{ */
|
---|
476 | HRESULT setOption(DHCPOption_T aOption, DHCPOptionEncoding_T aEncoding, const com::Utf8Str &aValue) RT_OVERRIDE
|
---|
477 | {
|
---|
478 | return i_setOption(aOption, aEncoding, aValue);
|
---|
479 | }
|
---|
480 |
|
---|
481 | HRESULT removeOption(DHCPOption_T aOption) RT_OVERRIDE
|
---|
482 | {
|
---|
483 | return i_removeOption(aOption);
|
---|
484 | }
|
---|
485 |
|
---|
486 | HRESULT removeAllOptions() RT_OVERRIDE
|
---|
487 | {
|
---|
488 | return i_removeAllOptions();
|
---|
489 | }
|
---|
490 |
|
---|
491 | HRESULT getOption(DHCPOption_T aOption, DHCPOptionEncoding_T *aEncoding, com::Utf8Str &aValue) RT_OVERRIDE
|
---|
492 | {
|
---|
493 | return i_getOption(aOption, aEncoding, aValue);
|
---|
494 | }
|
---|
495 |
|
---|
496 | HRESULT getAllOptions(std::vector<DHCPOption_T> &aOptions, std::vector<DHCPOptionEncoding_T> &aEncodings,
|
---|
497 | std::vector<com::Utf8Str> &aValues) RT_OVERRIDE
|
---|
498 | {
|
---|
499 | return i_getAllOptions(aOptions, aEncodings, aValues);
|
---|
500 | }
|
---|
501 |
|
---|
502 | HRESULT remove() RT_OVERRIDE
|
---|
503 | {
|
---|
504 | return i_remove();
|
---|
505 | }
|
---|
506 | /** @} */
|
---|
507 |
|
---|
508 | /** @name IDHCPIndividualConfig properties
|
---|
509 | * @{ */
|
---|
510 | HRESULT getMACAddress(com::Utf8Str &aMacAddress) RT_OVERRIDE;
|
---|
511 | HRESULT getMachineId(com::Guid &aId) RT_OVERRIDE;
|
---|
512 | HRESULT getSlot(ULONG *aSlot) RT_OVERRIDE;
|
---|
513 | HRESULT getFixedAddress(com::Utf8Str &aFixedAddress) RT_OVERRIDE;
|
---|
514 | HRESULT setFixedAddress(const com::Utf8Str &aFixedAddress) RT_OVERRIDE;
|
---|
515 | /** @} */
|
---|
516 | };
|
---|
517 |
|
---|
518 | #endif /* !MAIN_INCLUDED_DHCPConfigImpl_h */
|
---|
519 |
|
---|