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