1 | /* $Id: HostNetworkInterfaceImpl.cpp 17380 2009-03-05 10:05:30Z 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 (struct NETIFINFO *pIf)
|
---|
79 | {
|
---|
80 | m.IPAddress = pIf->IPAddress.u;
|
---|
81 | m.networkMask = pIf->IPNetMask.u;
|
---|
82 | m.defaultGateway = pIf->IPDefaultGateway.u;
|
---|
83 | m.IPV6Address = composeIPv6Address(&pIf->IPv6Address);
|
---|
84 | m.IPV6NetworkMask = composeIPv6Address(&pIf->IPv6NetMask);
|
---|
85 | m.IPV6DefaultGateway = composeIPv6Address(&pIf->IPV6DefaultGateway);
|
---|
86 | m.hardwareAddress = composeHardwareAddress(&pIf->MACAddress);
|
---|
87 | #ifdef RT_OS_WINDOWS
|
---|
88 | m.mediumType = (HostNetworkInterfaceMediumType)pIf->enmMediumType;
|
---|
89 | m.status = (HostNetworkInterfaceStatus)pIf->enmStatus;
|
---|
90 | #else /* !RT_OS_WINDOWS */
|
---|
91 | m.mediumType = pIf->enmMediumType;
|
---|
92 | m.status = pIf->enmStatus;
|
---|
93 | #endif /* !RT_OS_WINDOWS */
|
---|
94 |
|
---|
95 | return S_OK;
|
---|
96 | }
|
---|
97 |
|
---|
98 | /**
|
---|
99 | * Initializes the host object.
|
---|
100 | *
|
---|
101 | * @returns COM result indicator
|
---|
102 | * @param aInterfaceName name of the network interface
|
---|
103 | * @param aGuid GUID of the host network interface
|
---|
104 | */
|
---|
105 | HRESULT HostNetworkInterface::init (Bstr aInterfaceName, HostNetworkInterfaceType_T ifType, PNETIFINFO pIf)
|
---|
106 | {
|
---|
107 | // LogFlowThisFunc (("aInterfaceName={%ls}, aGuid={%s}\n",
|
---|
108 | // aInterfaceName.raw(), aGuid.toString().raw()));
|
---|
109 |
|
---|
110 | // ComAssertRet (aInterfaceName, E_INVALIDARG);
|
---|
111 | // ComAssertRet (!aGuid.isEmpty(), E_INVALIDARG);
|
---|
112 | ComAssertRet (pIf, E_INVALIDARG);
|
---|
113 |
|
---|
114 | /* Enclose the state transition NotReady->InInit->Ready */
|
---|
115 | AutoInitSpan autoInitSpan (this);
|
---|
116 | AssertReturn (autoInitSpan.isOk(), E_FAIL);
|
---|
117 |
|
---|
118 | unconst (mInterfaceName) = aInterfaceName;
|
---|
119 | unconst (mGuid) = pIf->Uuid;
|
---|
120 | mIfType = ifType;
|
---|
121 |
|
---|
122 | updateConfig(pIf);
|
---|
123 |
|
---|
124 | /* Confirm a successful initialization */
|
---|
125 | autoInitSpan.setSucceeded();
|
---|
126 |
|
---|
127 | return S_OK;
|
---|
128 | }
|
---|
129 | #endif
|
---|
130 |
|
---|
131 | // IHostNetworkInterface properties
|
---|
132 | /////////////////////////////////////////////////////////////////////////////
|
---|
133 |
|
---|
134 | /**
|
---|
135 | * Returns the name of the host network interface.
|
---|
136 | *
|
---|
137 | * @returns COM status code
|
---|
138 | * @param aInterfaceName address of result pointer
|
---|
139 | */
|
---|
140 | STDMETHODIMP HostNetworkInterface::COMGETTER(Name) (BSTR *aInterfaceName)
|
---|
141 | {
|
---|
142 | CheckComArgOutPointerValid(aInterfaceName);
|
---|
143 |
|
---|
144 | AutoCaller autoCaller (this);
|
---|
145 | CheckComRCReturnRC (autoCaller.rc());
|
---|
146 |
|
---|
147 | mInterfaceName.cloneTo (aInterfaceName);
|
---|
148 |
|
---|
149 | return S_OK;
|
---|
150 | }
|
---|
151 |
|
---|
152 | /**
|
---|
153 | * Returns the GUID of the host network interface.
|
---|
154 | *
|
---|
155 | * @returns COM status code
|
---|
156 | * @param aGuid address of result pointer
|
---|
157 | */
|
---|
158 | STDMETHODIMP HostNetworkInterface::COMGETTER(Id) (OUT_GUID aGuid)
|
---|
159 | {
|
---|
160 | CheckComArgOutPointerValid(aGuid);
|
---|
161 |
|
---|
162 | AutoCaller autoCaller (this);
|
---|
163 | CheckComRCReturnRC (autoCaller.rc());
|
---|
164 |
|
---|
165 | mGuid.cloneTo (aGuid);
|
---|
166 |
|
---|
167 | return S_OK;
|
---|
168 | }
|
---|
169 |
|
---|
170 |
|
---|
171 | /**
|
---|
172 | * Returns the IP address of the host network interface.
|
---|
173 | *
|
---|
174 | * @returns COM status code
|
---|
175 | * @param aIPAddress address of result pointer
|
---|
176 | */
|
---|
177 | STDMETHODIMP HostNetworkInterface::COMGETTER(IPAddress) (ULONG *aIPAddress)
|
---|
178 | {
|
---|
179 | CheckComArgOutPointerValid(aIPAddress);
|
---|
180 |
|
---|
181 | AutoCaller autoCaller (this);
|
---|
182 | CheckComRCReturnRC (autoCaller.rc());
|
---|
183 |
|
---|
184 | *aIPAddress = m.IPAddress;
|
---|
185 |
|
---|
186 | return S_OK;
|
---|
187 | }
|
---|
188 |
|
---|
189 | /**
|
---|
190 | * Returns the netwok mask of the host network interface.
|
---|
191 | *
|
---|
192 | * @returns COM status code
|
---|
193 | * @param aNetworkMask address of result pointer
|
---|
194 | */
|
---|
195 | STDMETHODIMP HostNetworkInterface::COMGETTER(NetworkMask) (ULONG *aNetworkMask)
|
---|
196 | {
|
---|
197 | CheckComArgOutPointerValid(aNetworkMask);
|
---|
198 |
|
---|
199 | AutoCaller autoCaller (this);
|
---|
200 | CheckComRCReturnRC (autoCaller.rc());
|
---|
201 |
|
---|
202 | *aNetworkMask = m.networkMask;
|
---|
203 |
|
---|
204 | return S_OK;
|
---|
205 | }
|
---|
206 |
|
---|
207 | /**
|
---|
208 | * Returns the default gateway of the host network interface.
|
---|
209 | *
|
---|
210 | * @returns COM status code
|
---|
211 | * @param aNetworkMask address of result pointer
|
---|
212 | */
|
---|
213 | STDMETHODIMP HostNetworkInterface::COMGETTER(DefaultGateway) (ULONG *aDefaultGateway)
|
---|
214 | {
|
---|
215 | CheckComArgOutPointerValid(aDefaultGateway);
|
---|
216 |
|
---|
217 | AutoCaller autoCaller (this);
|
---|
218 | CheckComRCReturnRC (autoCaller.rc());
|
---|
219 |
|
---|
220 | *aDefaultGateway = m.defaultGateway;
|
---|
221 |
|
---|
222 | return S_OK;
|
---|
223 | }
|
---|
224 |
|
---|
225 | STDMETHODIMP HostNetworkInterface::COMGETTER(IPV6Supported) (BOOL *aIPV6Supported)
|
---|
226 | {
|
---|
227 | CheckComArgOutPointerValid(aIPV6Supported);
|
---|
228 |
|
---|
229 | *aIPV6Supported = TRUE;
|
---|
230 |
|
---|
231 | return S_OK;
|
---|
232 | }
|
---|
233 |
|
---|
234 | /**
|
---|
235 | * Returns the IP V6 address of the host network interface.
|
---|
236 | *
|
---|
237 | * @returns COM status code
|
---|
238 | * @param aIPV6Address address of result pointer
|
---|
239 | */
|
---|
240 | STDMETHODIMP HostNetworkInterface::COMGETTER(IPV6Address) (BSTR *aIPV6Address)
|
---|
241 | {
|
---|
242 | CheckComArgOutPointerValid(aIPV6Address);
|
---|
243 |
|
---|
244 | AutoCaller autoCaller (this);
|
---|
245 | CheckComRCReturnRC (autoCaller.rc());
|
---|
246 |
|
---|
247 | m.IPV6Address.cloneTo (aIPV6Address);
|
---|
248 |
|
---|
249 | return S_OK;
|
---|
250 | }
|
---|
251 |
|
---|
252 | /**
|
---|
253 | * Returns the IP V6 network mask of the host network interface.
|
---|
254 | *
|
---|
255 | * @returns COM status code
|
---|
256 | * @param aIPV6Mask address of result pointer
|
---|
257 | */
|
---|
258 | STDMETHODIMP HostNetworkInterface::COMGETTER(IPV6NetworkMask) (BSTR *aIPV6Mask)
|
---|
259 | {
|
---|
260 | CheckComArgOutPointerValid(aIPV6Mask);
|
---|
261 |
|
---|
262 | AutoCaller autoCaller (this);
|
---|
263 | CheckComRCReturnRC (autoCaller.rc());
|
---|
264 |
|
---|
265 | m.IPV6NetworkMask.cloneTo (aIPV6Mask);
|
---|
266 |
|
---|
267 | return S_OK;
|
---|
268 | }
|
---|
269 |
|
---|
270 | /**
|
---|
271 | * Returns the IP V6 default gateway of the host network interface.
|
---|
272 | *
|
---|
273 | * @returns COM status code
|
---|
274 | * @param aIPV6DefaultGateway address of result pointer
|
---|
275 | */
|
---|
276 | STDMETHODIMP HostNetworkInterface::COMGETTER(IPV6DefaultGateway) (BSTR *aIPV6DefaultGateway)
|
---|
277 | {
|
---|
278 | CheckComArgOutPointerValid(aIPV6DefaultGateway);
|
---|
279 |
|
---|
280 | AutoCaller autoCaller (this);
|
---|
281 | CheckComRCReturnRC (autoCaller.rc());
|
---|
282 |
|
---|
283 | m.IPV6DefaultGateway.cloneTo (aIPV6DefaultGateway);
|
---|
284 |
|
---|
285 | return S_OK;
|
---|
286 | }
|
---|
287 |
|
---|
288 | /**
|
---|
289 | * Returns the hardware address of the host network interface.
|
---|
290 | *
|
---|
291 | * @returns COM status code
|
---|
292 | * @param aHardwareAddress address of result pointer
|
---|
293 | */
|
---|
294 | STDMETHODIMP HostNetworkInterface::COMGETTER(HardwareAddress) (BSTR *aHardwareAddress)
|
---|
295 | {
|
---|
296 | CheckComArgOutPointerValid(aHardwareAddress);
|
---|
297 |
|
---|
298 | AutoCaller autoCaller (this);
|
---|
299 | CheckComRCReturnRC (autoCaller.rc());
|
---|
300 |
|
---|
301 | m.hardwareAddress.cloneTo (aHardwareAddress);
|
---|
302 |
|
---|
303 | return S_OK;
|
---|
304 | }
|
---|
305 |
|
---|
306 | /**
|
---|
307 | * Returns the encapsulation protocol type of the host network interface.
|
---|
308 | *
|
---|
309 | * @returns COM status code
|
---|
310 | * @param aType address of result pointer
|
---|
311 | */
|
---|
312 | STDMETHODIMP HostNetworkInterface::COMGETTER(MediumType) (HostNetworkInterfaceMediumType_T *aType)
|
---|
313 | {
|
---|
314 | CheckComArgOutPointerValid(aType);
|
---|
315 |
|
---|
316 | AutoCaller autoCaller (this);
|
---|
317 | CheckComRCReturnRC (autoCaller.rc());
|
---|
318 |
|
---|
319 | *aType = m.mediumType;
|
---|
320 |
|
---|
321 | return S_OK;
|
---|
322 | }
|
---|
323 |
|
---|
324 | /**
|
---|
325 | * Returns the current state of the host network interface.
|
---|
326 | *
|
---|
327 | * @returns COM status code
|
---|
328 | * @param aStatus address of result pointer
|
---|
329 | */
|
---|
330 | STDMETHODIMP HostNetworkInterface::COMGETTER(Status) (HostNetworkInterfaceStatus_T *aStatus)
|
---|
331 | {
|
---|
332 | CheckComArgOutPointerValid(aStatus);
|
---|
333 |
|
---|
334 | AutoCaller autoCaller (this);
|
---|
335 | CheckComRCReturnRC (autoCaller.rc());
|
---|
336 |
|
---|
337 | *aStatus = m.status;
|
---|
338 |
|
---|
339 | return S_OK;
|
---|
340 | }
|
---|
341 |
|
---|
342 | /**
|
---|
343 | * Returns network interface type
|
---|
344 | *
|
---|
345 | * @returns COM status code
|
---|
346 | * @param aType address of result pointer
|
---|
347 | */
|
---|
348 | STDMETHODIMP HostNetworkInterface::COMGETTER(InterfaceType) (HostNetworkInterfaceType_T *aType)
|
---|
349 | {
|
---|
350 | CheckComArgOutPointerValid(aType);
|
---|
351 |
|
---|
352 | AutoCaller autoCaller (this);
|
---|
353 | CheckComRCReturnRC (autoCaller.rc());
|
---|
354 |
|
---|
355 | *aType = mIfType;
|
---|
356 |
|
---|
357 | return S_OK;
|
---|
358 |
|
---|
359 | }
|
---|
360 |
|
---|
361 | STDMETHODIMP HostNetworkInterface::EnableStaticIpConfig (ULONG aIPAddress, ULONG aNetworkMask, ULONG aDefaultGateway)
|
---|
362 | {
|
---|
363 | #ifndef VBOX_WITH_HOSTNETIF_API
|
---|
364 | return E_NOTIMPL;
|
---|
365 | #else
|
---|
366 | AutoCaller autoCaller (this);
|
---|
367 | CheckComRCReturnRC (autoCaller.rc());
|
---|
368 |
|
---|
369 | int rc = NetIfEnableStaticIpConfig(this, aIPAddress, aNetworkMask, aDefaultGateway);
|
---|
370 | if (RT_FAILURE(rc))
|
---|
371 | {
|
---|
372 | LogRel(("Failed to EnableStaticIpConfigV6 with rc=%Vrc\n", rc));
|
---|
373 | return rc == VERR_NOT_IMPLEMENTED ? E_NOTIMPL : E_FAIL;
|
---|
374 | }
|
---|
375 | return S_OK;
|
---|
376 | #endif
|
---|
377 | }
|
---|
378 |
|
---|
379 | STDMETHODIMP HostNetworkInterface::EnableStaticIpConfigV6 (IN_BSTR aIPV6Address, ULONG aIPV6MaskPrefixLength, IN_BSTR aIPV6DefaultGateway)
|
---|
380 | {
|
---|
381 | #ifndef VBOX_WITH_HOSTNETIF_API
|
---|
382 | return E_NOTIMPL;
|
---|
383 | #else
|
---|
384 | if (!aIPV6Address)
|
---|
385 | return E_INVALIDARG;
|
---|
386 | if (!aIPV6DefaultGateway)
|
---|
387 | return E_INVALIDARG;
|
---|
388 | if (aIPV6MaskPrefixLength > 128)
|
---|
389 | return E_INVALIDARG;
|
---|
390 |
|
---|
391 | AutoCaller autoCaller (this);
|
---|
392 | CheckComRCReturnRC (autoCaller.rc());
|
---|
393 |
|
---|
394 | int rc = NetIfEnableStaticIpConfigV6(this, aIPV6Address, aIPV6MaskPrefixLength, aIPV6DefaultGateway);
|
---|
395 | if (RT_FAILURE(rc))
|
---|
396 | {
|
---|
397 | LogRel(("Failed to EnableStaticIpConfigV6 with rc=%Vrc\n", rc));
|
---|
398 | return rc == VERR_NOT_IMPLEMENTED ? E_NOTIMPL : E_FAIL;
|
---|
399 | }
|
---|
400 | return S_OK;
|
---|
401 | #endif
|
---|
402 | }
|
---|
403 |
|
---|
404 | STDMETHODIMP HostNetworkInterface::EnableDynamicIpConfig ()
|
---|
405 | {
|
---|
406 | #ifndef VBOX_WITH_HOSTNETIF_API
|
---|
407 | return E_NOTIMPL;
|
---|
408 | #else
|
---|
409 | AutoCaller autoCaller (this);
|
---|
410 | CheckComRCReturnRC (autoCaller.rc());
|
---|
411 |
|
---|
412 | int rc = NetIfEnableDynamicIpConfig(this);
|
---|
413 | if (RT_FAILURE(rc))
|
---|
414 | {
|
---|
415 | LogRel(("Failed to EnableStaticIpConfigV6 with rc=%Vrc\n", rc));
|
---|
416 | return rc == VERR_NOT_IMPLEMENTED ? E_NOTIMPL : E_FAIL;
|
---|
417 | }
|
---|
418 | return S_OK;
|
---|
419 | #endif
|
---|
420 | }
|
---|
421 |
|
---|
422 | /* vi: set tabstop=4 shiftwidth=4 expandtab: */
|
---|