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