1 | /* $Id: HostNetworkInterfaceImpl.cpp 17713 2009-03-11 17:30:58Z vboxsync $ */
|
---|
2 |
|
---|
3 | /** @file
|
---|
4 | *
|
---|
5 | * VirtualBox COM class implementation
|
---|
6 | */
|
---|
7 |
|
---|
8 | /*
|
---|
9 | * Copyright (C) 2006-2008 Sun Microsystems, Inc.
|
---|
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 | * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
|
---|
20 | * Clara, CA 95054 USA or visit http://www.sun.com if you need
|
---|
21 | * additional information or have any questions.
|
---|
22 | */
|
---|
23 |
|
---|
24 | #include "HostNetworkInterfaceImpl.h"
|
---|
25 | #include "Logging.h"
|
---|
26 | #include "netif.h"
|
---|
27 |
|
---|
28 | // constructor / destructor
|
---|
29 | /////////////////////////////////////////////////////////////////////////////
|
---|
30 |
|
---|
31 | DEFINE_EMPTY_CTOR_DTOR (HostNetworkInterface)
|
---|
32 |
|
---|
33 | HRESULT HostNetworkInterface::FinalConstruct()
|
---|
34 | {
|
---|
35 | return S_OK;
|
---|
36 | }
|
---|
37 |
|
---|
38 | void HostNetworkInterface::FinalRelease()
|
---|
39 | {
|
---|
40 | uninit ();
|
---|
41 | }
|
---|
42 |
|
---|
43 | // public initializer/uninitializer for internal purposes only
|
---|
44 | /////////////////////////////////////////////////////////////////////////////
|
---|
45 |
|
---|
46 | /**
|
---|
47 | * Initializes the host object.
|
---|
48 | *
|
---|
49 | * @returns COM result indicator
|
---|
50 | * @param aInterfaceName name of the network interface
|
---|
51 | * @param aGuid GUID of the host network interface
|
---|
52 | */
|
---|
53 | HRESULT HostNetworkInterface::init (Bstr aInterfaceName, Guid aGuid, HostNetworkInterfaceType_T ifType)
|
---|
54 | {
|
---|
55 | LogFlowThisFunc (("aInterfaceName={%ls}, aGuid={%s}\n",
|
---|
56 | aInterfaceName.raw(), aGuid.toString().raw()));
|
---|
57 |
|
---|
58 | ComAssertRet (aInterfaceName, E_INVALIDARG);
|
---|
59 | ComAssertRet (!aGuid.isEmpty(), E_INVALIDARG);
|
---|
60 |
|
---|
61 | /* Enclose the state transition NotReady->InInit->Ready */
|
---|
62 | AutoInitSpan autoInitSpan (this);
|
---|
63 | AssertReturn (autoInitSpan.isOk(), E_FAIL);
|
---|
64 |
|
---|
65 | unconst (mInterfaceName) = aInterfaceName;
|
---|
66 | unconst (mGuid) = aGuid;
|
---|
67 | mIfType = ifType;
|
---|
68 |
|
---|
69 |
|
---|
70 | /* Confirm a successful initialization */
|
---|
71 | autoInitSpan.setSucceeded();
|
---|
72 |
|
---|
73 | return S_OK;
|
---|
74 | }
|
---|
75 |
|
---|
76 | #ifdef VBOX_WITH_HOSTNETIF_API
|
---|
77 |
|
---|
78 | HRESULT HostNetworkInterface::updateConfig ()
|
---|
79 | {
|
---|
80 | NETIFINFO info;
|
---|
81 | int rc = NetIfGetConfig(this, &info);
|
---|
82 | if(RT_SUCCESS(rc))
|
---|
83 | {
|
---|
84 | m.IPAddress = info.IPAddress.u;
|
---|
85 | m.networkMask = info.IPNetMask.u;
|
---|
86 | m.dhcpEnabled = info.bDhcpEnabled;
|
---|
87 | m.IPV6Address = composeIPv6Address(&info.IPv6Address);
|
---|
88 | m.IPV6NetworkMaskPrefixLength = composeIPv6PrefixLenghFromAddress(&info.IPv6NetMask);
|
---|
89 | m.hardwareAddress = composeHardwareAddress(&info.MACAddress);
|
---|
90 | #ifdef RT_OS_WINDOWS
|
---|
91 | m.mediumType = (HostNetworkInterfaceMediumType)info.enmMediumType;
|
---|
92 | m.status = (HostNetworkInterfaceStatus)info.enmStatus;
|
---|
93 | #else /* !RT_OS_WINDOWS */
|
---|
94 | m.mediumType = info.enmMediumType;
|
---|
95 | m.status = info.enmStatus;
|
---|
96 |
|
---|
97 | #endif /* !RT_OS_WINDOWS */
|
---|
98 | return S_OK;
|
---|
99 | }
|
---|
100 | return rc == VERR_NOT_IMPLEMENTED ? E_NOTIMPL : E_FAIL;
|
---|
101 | }
|
---|
102 |
|
---|
103 | /**
|
---|
104 | * Initializes the host object.
|
---|
105 | *
|
---|
106 | * @returns COM result indicator
|
---|
107 | * @param aInterfaceName name of the network interface
|
---|
108 | * @param aGuid GUID of the host network interface
|
---|
109 | */
|
---|
110 | HRESULT HostNetworkInterface::init (Bstr aInterfaceName, HostNetworkInterfaceType_T ifType, PNETIFINFO pIf)
|
---|
111 | {
|
---|
112 | // LogFlowThisFunc (("aInterfaceName={%ls}, aGuid={%s}\n",
|
---|
113 | // aInterfaceName.raw(), aGuid.toString().raw()));
|
---|
114 |
|
---|
115 | // ComAssertRet (aInterfaceName, E_INVALIDARG);
|
---|
116 | // ComAssertRet (!aGuid.isEmpty(), E_INVALIDARG);
|
---|
117 | ComAssertRet (pIf, E_INVALIDARG);
|
---|
118 |
|
---|
119 | /* Enclose the state transition NotReady->InInit->Ready */
|
---|
120 | AutoInitSpan autoInitSpan (this);
|
---|
121 | AssertReturn (autoInitSpan.isOk(), E_FAIL);
|
---|
122 |
|
---|
123 | unconst (mInterfaceName) = aInterfaceName;
|
---|
124 | unconst (mGuid) = pIf->Uuid;
|
---|
125 | mIfType = ifType;
|
---|
126 |
|
---|
127 | m.IPAddress = pIf->IPAddress.u;
|
---|
128 | m.networkMask = pIf->IPNetMask.u;
|
---|
129 | m.IPV6Address = composeIPv6Address(&pIf->IPv6Address);
|
---|
130 | m.IPV6NetworkMaskPrefixLength = composeIPv6PrefixLenghFromAddress(&pIf->IPv6NetMask);
|
---|
131 | m.dhcpEnabled = pIf->bDhcpEnabled;
|
---|
132 | m.hardwareAddress = composeHardwareAddress(&pIf->MACAddress);
|
---|
133 | #ifdef RT_OS_WINDOWS
|
---|
134 | m.mediumType = (HostNetworkInterfaceMediumType)pIf->enmMediumType;
|
---|
135 | m.status = (HostNetworkInterfaceStatus)pIf->enmStatus;
|
---|
136 | #else /* !RT_OS_WINDOWS */
|
---|
137 | m.mediumType = pIf->enmMediumType;
|
---|
138 | m.status = pIf->enmStatus;
|
---|
139 | #endif /* !RT_OS_WINDOWS */
|
---|
140 |
|
---|
141 | /* Confirm a successful initialization */
|
---|
142 | autoInitSpan.setSucceeded();
|
---|
143 |
|
---|
144 | return S_OK;
|
---|
145 | }
|
---|
146 | #endif
|
---|
147 |
|
---|
148 | // IHostNetworkInterface properties
|
---|
149 | /////////////////////////////////////////////////////////////////////////////
|
---|
150 |
|
---|
151 | /**
|
---|
152 | * Returns the name of the host network interface.
|
---|
153 | *
|
---|
154 | * @returns COM status code
|
---|
155 | * @param aInterfaceName address of result pointer
|
---|
156 | */
|
---|
157 | STDMETHODIMP HostNetworkInterface::COMGETTER(Name) (BSTR *aInterfaceName)
|
---|
158 | {
|
---|
159 | CheckComArgOutPointerValid(aInterfaceName);
|
---|
160 |
|
---|
161 | AutoCaller autoCaller (this);
|
---|
162 | CheckComRCReturnRC (autoCaller.rc());
|
---|
163 |
|
---|
164 | mInterfaceName.cloneTo (aInterfaceName);
|
---|
165 |
|
---|
166 | return S_OK;
|
---|
167 | }
|
---|
168 |
|
---|
169 | /**
|
---|
170 | * Returns the GUID of the host network interface.
|
---|
171 | *
|
---|
172 | * @returns COM status code
|
---|
173 | * @param aGuid address of result pointer
|
---|
174 | */
|
---|
175 | STDMETHODIMP HostNetworkInterface::COMGETTER(Id) (OUT_GUID aGuid)
|
---|
176 | {
|
---|
177 | CheckComArgOutPointerValid(aGuid);
|
---|
178 |
|
---|
179 | AutoCaller autoCaller (this);
|
---|
180 | CheckComRCReturnRC (autoCaller.rc());
|
---|
181 |
|
---|
182 | mGuid.cloneTo (aGuid);
|
---|
183 |
|
---|
184 | return S_OK;
|
---|
185 | }
|
---|
186 |
|
---|
187 | STDMETHODIMP HostNetworkInterface::COMGETTER(DhcpEnabled) (BOOL *aDhcpEnabled)
|
---|
188 | {
|
---|
189 | CheckComArgOutPointerValid(aDhcpEnabled);
|
---|
190 |
|
---|
191 | AutoCaller autoCaller (this);
|
---|
192 | CheckComRCReturnRC (autoCaller.rc());
|
---|
193 |
|
---|
194 | *aDhcpEnabled = m.dhcpEnabled;
|
---|
195 |
|
---|
196 | return S_OK;
|
---|
197 | }
|
---|
198 |
|
---|
199 |
|
---|
200 | /**
|
---|
201 | * Returns the IP address of the host network interface.
|
---|
202 | *
|
---|
203 | * @returns COM status code
|
---|
204 | * @param aIPAddress address of result pointer
|
---|
205 | */
|
---|
206 | STDMETHODIMP HostNetworkInterface::COMGETTER(IPAddress) (ULONG *aIPAddress)
|
---|
207 | {
|
---|
208 | CheckComArgOutPointerValid(aIPAddress);
|
---|
209 |
|
---|
210 | AutoCaller autoCaller (this);
|
---|
211 | CheckComRCReturnRC (autoCaller.rc());
|
---|
212 |
|
---|
213 | *aIPAddress = m.IPAddress;
|
---|
214 |
|
---|
215 | return S_OK;
|
---|
216 | }
|
---|
217 |
|
---|
218 | /**
|
---|
219 | * Returns the netwok mask of the host network interface.
|
---|
220 | *
|
---|
221 | * @returns COM status code
|
---|
222 | * @param aNetworkMask address of result pointer
|
---|
223 | */
|
---|
224 | STDMETHODIMP HostNetworkInterface::COMGETTER(NetworkMask) (ULONG *aNetworkMask)
|
---|
225 | {
|
---|
226 | CheckComArgOutPointerValid(aNetworkMask);
|
---|
227 |
|
---|
228 | AutoCaller autoCaller (this);
|
---|
229 | CheckComRCReturnRC (autoCaller.rc());
|
---|
230 |
|
---|
231 | *aNetworkMask = m.networkMask;
|
---|
232 |
|
---|
233 | return S_OK;
|
---|
234 | }
|
---|
235 |
|
---|
236 | STDMETHODIMP HostNetworkInterface::COMGETTER(IPV6Supported) (BOOL *aIPV6Supported)
|
---|
237 | {
|
---|
238 | CheckComArgOutPointerValid(aIPV6Supported);
|
---|
239 |
|
---|
240 | *aIPV6Supported = TRUE;
|
---|
241 |
|
---|
242 | return S_OK;
|
---|
243 | }
|
---|
244 |
|
---|
245 | /**
|
---|
246 | * Returns the IP V6 address of the host network interface.
|
---|
247 | *
|
---|
248 | * @returns COM status code
|
---|
249 | * @param aIPV6Address address of result pointer
|
---|
250 | */
|
---|
251 | STDMETHODIMP HostNetworkInterface::COMGETTER(IPV6Address) (BSTR *aIPV6Address)
|
---|
252 | {
|
---|
253 | CheckComArgOutPointerValid(aIPV6Address);
|
---|
254 |
|
---|
255 | AutoCaller autoCaller (this);
|
---|
256 | CheckComRCReturnRC (autoCaller.rc());
|
---|
257 |
|
---|
258 | m.IPV6Address.cloneTo (aIPV6Address);
|
---|
259 |
|
---|
260 | return S_OK;
|
---|
261 | }
|
---|
262 |
|
---|
263 | /**
|
---|
264 | * Returns the IP V6 network mask of the host network interface.
|
---|
265 | *
|
---|
266 | * @returns COM status code
|
---|
267 | * @param aIPV6Mask address of result pointer
|
---|
268 | */
|
---|
269 | STDMETHODIMP HostNetworkInterface::COMGETTER(IPV6NetworkMaskPrefixLength) (ULONG *aIPV6NetworkMaskPrefixLength)
|
---|
270 | {
|
---|
271 | CheckComArgOutPointerValid(aIPV6NetworkMaskPrefixLength);
|
---|
272 |
|
---|
273 | AutoCaller autoCaller (this);
|
---|
274 | CheckComRCReturnRC (autoCaller.rc());
|
---|
275 |
|
---|
276 | *aIPV6NetworkMaskPrefixLength = m.IPV6NetworkMaskPrefixLength;
|
---|
277 |
|
---|
278 | return S_OK;
|
---|
279 | }
|
---|
280 |
|
---|
281 | /**
|
---|
282 | * Returns the hardware address of the host network interface.
|
---|
283 | *
|
---|
284 | * @returns COM status code
|
---|
285 | * @param aHardwareAddress address of result pointer
|
---|
286 | */
|
---|
287 | STDMETHODIMP HostNetworkInterface::COMGETTER(HardwareAddress) (BSTR *aHardwareAddress)
|
---|
288 | {
|
---|
289 | CheckComArgOutPointerValid(aHardwareAddress);
|
---|
290 |
|
---|
291 | AutoCaller autoCaller (this);
|
---|
292 | CheckComRCReturnRC (autoCaller.rc());
|
---|
293 |
|
---|
294 | m.hardwareAddress.cloneTo (aHardwareAddress);
|
---|
295 |
|
---|
296 | return S_OK;
|
---|
297 | }
|
---|
298 |
|
---|
299 | /**
|
---|
300 | * Returns the encapsulation protocol type of the host network interface.
|
---|
301 | *
|
---|
302 | * @returns COM status code
|
---|
303 | * @param aType address of result pointer
|
---|
304 | */
|
---|
305 | STDMETHODIMP HostNetworkInterface::COMGETTER(MediumType) (HostNetworkInterfaceMediumType_T *aType)
|
---|
306 | {
|
---|
307 | CheckComArgOutPointerValid(aType);
|
---|
308 |
|
---|
309 | AutoCaller autoCaller (this);
|
---|
310 | CheckComRCReturnRC (autoCaller.rc());
|
---|
311 |
|
---|
312 | *aType = m.mediumType;
|
---|
313 |
|
---|
314 | return S_OK;
|
---|
315 | }
|
---|
316 |
|
---|
317 | /**
|
---|
318 | * Returns the current state of the host network interface.
|
---|
319 | *
|
---|
320 | * @returns COM status code
|
---|
321 | * @param aStatus address of result pointer
|
---|
322 | */
|
---|
323 | STDMETHODIMP HostNetworkInterface::COMGETTER(Status) (HostNetworkInterfaceStatus_T *aStatus)
|
---|
324 | {
|
---|
325 | CheckComArgOutPointerValid(aStatus);
|
---|
326 |
|
---|
327 | AutoCaller autoCaller (this);
|
---|
328 | CheckComRCReturnRC (autoCaller.rc());
|
---|
329 |
|
---|
330 | *aStatus = m.status;
|
---|
331 |
|
---|
332 | return S_OK;
|
---|
333 | }
|
---|
334 |
|
---|
335 | /**
|
---|
336 | * Returns network interface type
|
---|
337 | *
|
---|
338 | * @returns COM status code
|
---|
339 | * @param aType address of result pointer
|
---|
340 | */
|
---|
341 | STDMETHODIMP HostNetworkInterface::COMGETTER(InterfaceType) (HostNetworkInterfaceType_T *aType)
|
---|
342 | {
|
---|
343 | CheckComArgOutPointerValid(aType);
|
---|
344 |
|
---|
345 | AutoCaller autoCaller (this);
|
---|
346 | CheckComRCReturnRC (autoCaller.rc());
|
---|
347 |
|
---|
348 | *aType = mIfType;
|
---|
349 |
|
---|
350 | return S_OK;
|
---|
351 |
|
---|
352 | }
|
---|
353 |
|
---|
354 | STDMETHODIMP HostNetworkInterface::EnableStaticIpConfig (ULONG aIPAddress, ULONG aNetworkMask)
|
---|
355 | {
|
---|
356 | #ifndef VBOX_WITH_HOSTNETIF_API
|
---|
357 | return E_NOTIMPL;
|
---|
358 | #else
|
---|
359 | AutoCaller autoCaller (this);
|
---|
360 | CheckComRCReturnRC (autoCaller.rc());
|
---|
361 |
|
---|
362 | int rc = NetIfEnableStaticIpConfig(mVBox, this, aIPAddress, aNetworkMask);
|
---|
363 | if (RT_FAILURE(rc))
|
---|
364 | {
|
---|
365 | LogRel(("Failed to EnableStaticIpConfigV6 with rc=%Vrc\n", rc));
|
---|
366 | return rc == VERR_NOT_IMPLEMENTED ? E_NOTIMPL : E_FAIL;
|
---|
367 | }
|
---|
368 | return S_OK;
|
---|
369 | #endif
|
---|
370 | }
|
---|
371 |
|
---|
372 | STDMETHODIMP HostNetworkInterface::EnableStaticIpConfigV6 (IN_BSTR aIPV6Address, ULONG aIPV6MaskPrefixLength)
|
---|
373 | {
|
---|
374 | #ifndef VBOX_WITH_HOSTNETIF_API
|
---|
375 | return E_NOTIMPL;
|
---|
376 | #else
|
---|
377 | if (!aIPV6Address)
|
---|
378 | return E_INVALIDARG;
|
---|
379 | if (aIPV6MaskPrefixLength > 128)
|
---|
380 | return E_INVALIDARG;
|
---|
381 |
|
---|
382 | AutoCaller autoCaller (this);
|
---|
383 | CheckComRCReturnRC (autoCaller.rc());
|
---|
384 |
|
---|
385 | int rc = NetIfEnableStaticIpConfigV6(mVBox, this, aIPV6Address, aIPV6MaskPrefixLength);
|
---|
386 | if (RT_FAILURE(rc))
|
---|
387 | {
|
---|
388 | LogRel(("Failed to EnableStaticIpConfigV6 with rc=%Vrc\n", rc));
|
---|
389 | return rc == VERR_NOT_IMPLEMENTED ? E_NOTIMPL : E_FAIL;
|
---|
390 | }
|
---|
391 | return S_OK;
|
---|
392 | #endif
|
---|
393 | }
|
---|
394 |
|
---|
395 | STDMETHODIMP HostNetworkInterface::EnableDynamicIpConfig ()
|
---|
396 | {
|
---|
397 | #ifndef VBOX_WITH_HOSTNETIF_API
|
---|
398 | return E_NOTIMPL;
|
---|
399 | #else
|
---|
400 | AutoCaller autoCaller (this);
|
---|
401 | CheckComRCReturnRC (autoCaller.rc());
|
---|
402 |
|
---|
403 | int rc = NetIfEnableDynamicIpConfig(mVBox, this);
|
---|
404 | if (RT_FAILURE(rc))
|
---|
405 | {
|
---|
406 | LogRel(("Failed to EnableStaticIpConfigV6 with rc=%Vrc\n", rc));
|
---|
407 | return rc == VERR_NOT_IMPLEMENTED ? E_NOTIMPL : E_FAIL;
|
---|
408 | }
|
---|
409 | return S_OK;
|
---|
410 | #endif
|
---|
411 | }
|
---|
412 |
|
---|
413 | HRESULT HostNetworkInterface::setVirtualBox(VirtualBox *pVBox)
|
---|
414 | {
|
---|
415 | AutoCaller autoCaller (this);
|
---|
416 | CheckComRCReturnRC (autoCaller.rc());
|
---|
417 | mVBox = pVBox;
|
---|
418 |
|
---|
419 | return S_OK;
|
---|
420 | }
|
---|
421 |
|
---|
422 | /* vi: set tabstop=4 shiftwidth=4 expandtab: */
|
---|