HostNetworkInterfaceImpl.cpp revision 0d49a2fbc9857ad8dd29542de7fb37202f1a283f
/* $Id$ */
/** @file
*
* VirtualBox COM class implementation
*/
/*
* Copyright (C) 2006-2014 Oracle Corporation
*
* This file is part of VirtualBox Open Source Edition (OSE), as
* available from http://www.virtualbox.org. This file is free software;
* General Public License (GPL) as published by the Free Software
* Foundation, in version 2 as it comes in the "COPYING" file of the
* VirtualBox OSE distribution. VirtualBox OSE is distributed in the
* hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
*/
#include "HostNetworkInterfaceImpl.h"
#include "AutoCaller.h"
#include "Logging.h"
#include "netif.h"
#ifdef VBOX_WITH_RESOURCE_USAGE_API
# include "Performance.h"
# include "PerformanceImpl.h"
#endif
#ifdef RT_OS_FREEBSD
#endif /* RT_OS_FREEBSD */
#include "VirtualBoxImpl.h"
// constructor / destructor
/////////////////////////////////////////////////////////////////////////////
: mVirtualBox(NULL)
{
}
{
}
{
return BaseFinalConstruct();
}
void HostNetworkInterface::FinalRelease()
{
uninit();
}
// public initializer/uninitializer for internal purposes only
/////////////////////////////////////////////////////////////////////////////
/**
* Initializes the host object.
*
* @returns COM result indicator
* @param aInterfaceName name of the network interface
* @param aGuid GUID of the host network interface
*/
HRESULT HostNetworkInterface::init(Bstr aInterfaceName, Bstr aShortName, Guid aGuid, HostNetworkInterfaceType_T ifType)
{
LogFlowThisFunc(("aInterfaceName={%ls}, aGuid={%s}\n",
/* Enclose the state transition NotReady->InInit->Ready */
AutoInitSpan autoInitSpan(this);
/* Confirm a successful initialization */
return S_OK;
}
#ifdef VBOX_WITH_RESOURCE_USAGE_API
void HostNetworkInterface::i_registerMetrics(PerformanceCollector *aCollector, ComPtr<IUnknown> objptr)
{
LogFlowThisFunc(("mShortName={%ls}, mInterfaceName={%ls}, mGuid={%s}, mSpeedMbits=%u\n",
/* Create sub metrics */
"Percentage of network interface receive bandwidth used.");
"Percentage of network interface transmit bandwidth used.");
"Physical link speed.");
/* Create and register base metrics */
new pm::AggregateAvg()));
new pm::AggregateMin()));
new pm::AggregateMax()));
new pm::AggregateAvg()));
new pm::AggregateMin()));
new pm::AggregateMax()));
new pm::AggregateAvg()));
new pm::AggregateMin()));
new pm::AggregateMax()));
}
void HostNetworkInterface::i_unregisterMetrics(PerformanceCollector *aCollector, ComPtr<IUnknown> objptr)
{
LogFlowThisFunc(("mShortName={%ls}, mInterfaceName={%ls}, mGuid={%s}\n",
}
#endif /* VBOX_WITH_RESOURCE_USAGE_API */
#ifdef VBOX_WITH_HOSTNETIF_API
{
if (RT_SUCCESS(rc))
{
m.realIPV6PrefixLength = m.IPV6NetworkMaskPrefixLength = composeIPv6PrefixLenghFromAddress(&info.IPv6NetMask);
#ifdef RT_OS_WINDOWS
#else /* !RT_OS_WINDOWS */
#endif /* !RT_OS_WINDOWS */
return S_OK;
}
}
{
}
/**
* Initializes the host object.
*
* @returns COM result indicator
* @param aInterfaceName name of the network interface
* @param aGuid GUID of the host network interface
*/
HRESULT HostNetworkInterface::init(Bstr aInterfaceName, HostNetworkInterfaceType_T ifType, PNETIFINFO pIf)
{
// LogFlowThisFunc(("aInterfaceName={%ls}, aGuid={%s}\n",
// aInterfaceName.raw(), aGuid.toString().raw()));
// ComAssertRet(aInterfaceName, E_INVALIDARG);
// ComAssertRet(aGuid.isValid(), E_INVALIDARG);
/* Enclose the state transition NotReady->InInit->Ready */
AutoInitSpan autoInitSpan(this);
if (pIf->szShortName[0])
{
}
else
{
}
m.realIPV6PrefixLength = m.IPV6NetworkMaskPrefixLength = composeIPv6PrefixLenghFromAddress(&pIf->IPv6NetMask);
#ifdef RT_OS_WINDOWS
#else /* !RT_OS_WINDOWS */
#endif /* !RT_OS_WINDOWS */
/* Confirm a successful initialization */
return S_OK;
}
#endif
// wrapped IHostNetworkInterface properties
/////////////////////////////////////////////////////////////////////////////
/**
* Returns the name of the host network interface.
*
* @returns COM status code
* @param aInterfaceName - Interface Name
*/
{
return S_OK;
}
/**
* Returns the short name of the host network interface.
*
* @returns COM status code
* @param aShortName Short Name
*/
{
return S_OK;
}
/**
* Returns the GUID of the host network interface.
*
* @returns COM status code
* @param aGuid GUI Id
*/
{
return S_OK;
}
{
*aDHCPEnabled = m.dhcpEnabled;
return S_OK;
}
/**
* Returns the IP address of the host network interface.
*
* @returns COM status code
* @param aIPAddress Address name
*/
{
#if defined(RT_OS_WINDOWS)
#else
#endif
if (addr)
{
aIPAddress = addr;
return S_OK;
}
return E_FAIL;
}
/**
* Returns the netwok mask of the host network interface.
*
* @returns COM status code
* @param aNetworkMask name.
*/
{
#if defined(RT_OS_WINDOWS)
#else
#endif
if (addr)
{
return S_OK;
}
return E_FAIL;
}
{
#if defined(RT_OS_WINDOWS)
*aIPV6Supported = FALSE;
#else
*aIPV6Supported = TRUE;
#endif
return S_OK;
}
/**
* Returns the IP V6 address of the host network interface.
*
* @returns COM status code
* @param aIPV6Address
*/
{
aIPV6Address = m.IPV6Address;
return S_OK;
}
/**
* Returns the IP V6 network mask of the host network interface.
*
* @returns COM status code
* @param aIPV6Mask address of result pointer
*/
{
return S_OK;
}
/**
* Returns the hardware address of the host network interface.
*
* @returns COM status code
* @param aHardwareAddress hardware address
*/
{
return S_OK;
}
/**
* Returns the encapsulation protocol type of the host network interface.
*
* @returns COM status code
* @param aType address of result pointer
*/
{
*aType = m.mediumType;
return S_OK;
}
/**
* Returns the current state of the host network interface.
*
* @returns COM status code
* @param aStatus address of result pointer
*/
{
return S_OK;
}
/**
* Returns network interface type
*
* @returns COM status code
* @param aType address of result pointer
*/
{
return S_OK;
}
{
return S_OK;
}
{
#ifndef VBOX_WITH_HOSTNETIF_API
return E_NOTIMPL;
#else
if (aIPAddress.isEmpty())
{
if (m.IPAddress)
{
if (RT_SUCCESS(rc))
{
m.realIPAddress = 0;
return E_FAIL;
return E_FAIL;
return S_OK;
}
}
else
return S_OK;
}
if (ip != INADDR_NONE)
{
if (aNetworkMask.isEmpty())
mask = 0xFFFFFF;
else
if (mask != INADDR_NONE)
{
return S_OK;
if (RT_SUCCESS(rc))
{
m.realIPAddress = ip;
m.realNetworkMask = mask;
return E_FAIL;
return E_FAIL;
return S_OK;
}
else
{
}
}
}
return E_FAIL;
#endif
}
{
#ifndef VBOX_WITH_HOSTNETIF_API
return E_NOTIMPL;
#else
if (aIPV6NetworkMaskPrefixLength > 128)
return E_INVALIDARG;
if ( m.realIPV6Address != aIPV6Address
{
if (aIPV6NetworkMaskPrefixLength == 0)
if (RT_FAILURE(rc))
{
}
else
{
return E_FAIL;
return E_FAIL;
}
}
return S_OK;
#endif
}
{
#ifndef VBOX_WITH_HOSTNETIF_API
return E_NOTIMPL;
#else
if (RT_FAILURE(rc))
{
}
return S_OK;
#endif
}
{
#ifndef VBOX_WITH_HOSTNETIF_API
return E_NOTIMPL;
#else
if (RT_FAILURE(rc))
{
}
return S_OK;
#endif
}
{
AutoCaller autoCaller(this);
#if !defined(RT_OS_WINDOWS)
/* If IPv4 address hasn't been initialized */
{
tmpAddr.asOutParam());
tmpMask.asOutParam());
}
if (m.IPV6Address.isEmpty())
{
m.IPV6Address.asOutParam());
{
else
m.IPV6NetworkMaskPrefixLength = 64;
}
}
#endif
return S_OK;
}
/* vi: set tabstop=4 shiftwidth=4 expandtab: */