[libvirt] [PATCH 00/13] vbox: Rewrite networkDriver

This series of patches rewrite the networkDriver in vbox. As a result, all version specified network driver in vbox_driver.c is removed and using a common driver instead. Taowei (13): vbox: Rewrite vboxNetworkOpen vbox: Rewrite vboxNetworkClose vbox: Rewrite vboxConnectNumOfNetworks vbox: Rewrite vboxConnectListNetworks vbox: Rewrite vboxConnectNumOfDefinedNetworks vbox: Rewrite vboxConnectListDefinedNetworks vbox: Rewrite vboxNetworkLookupByUUID vbox: Rewrite vboxNetworkLookupByName vbox: Rewrite vboxNetworkDefineCreateXML vbox: Rewrite vboxNetworkUndefineDestroy vbox: Rewrite vboxNetworkCreate vbox: Rewrite vboxNetworkGetXMLDesc vbox: Introducing vboxCommonNetworkDriver src/vbox/vbox_common.c | 844 +++++++++++++++++++++++++++ src/vbox/vbox_common.h | 16 + src/vbox/vbox_driver.c | 23 +- src/vbox/vbox_tmpl.c | 1264 +++++++++++------------------------------ src/vbox/vbox_uniformed_api.h | 52 ++ 5 files changed, 1244 insertions(+), 955 deletions(-) -- 1.7.9.5

--- src/vbox/vbox_common.c | 28 ++++++++++++++++++++++++++++ src/vbox/vbox_tmpl.c | 24 ------------------------ src/vbox/vbox_uniformed_api.h | 3 +++ 3 files changed, 31 insertions(+), 24 deletions(-) diff --git a/src/vbox/vbox_common.c b/src/vbox/vbox_common.c index b186ea8..b7251e5 100644 --- a/src/vbox/vbox_common.c +++ b/src/vbox/vbox_common.c @@ -7453,6 +7453,34 @@ vboxNodeGetFreePages(virConnectPtr conn ATTRIBUTE_UNUSED, } /** + * The Network Functions here on + */ + +virDrvOpenStatus vboxNetworkOpen(virConnectPtr conn, + virConnectAuthPtr auth ATTRIBUTE_UNUSED, + unsigned int flags) +{ + vboxGlobalData *data = conn->privateData; + + virCheckFlags(VIR_CONNECT_RO, VIR_DRV_OPEN_ERROR); + + if (STRNEQ(conn->driver->name, "VBOX")) + goto cleanup; + + if ((data->pFuncs == NULL) || + (data->vboxObj == NULL) || + (data->vboxSession == NULL)) + goto cleanup; + + VIR_DEBUG("network initialized"); + /* conn->networkPrivateData = some network specific data */ + return VIR_DRV_OPEN_SUCCESS; + + cleanup: + return VIR_DRV_OPEN_DECLINED; +} + +/** * Function Tables */ diff --git a/src/vbox/vbox_tmpl.c b/src/vbox/vbox_tmpl.c index f622ac4..23bbdcb 100644 --- a/src/vbox/vbox_tmpl.c +++ b/src/vbox/vbox_tmpl.c @@ -2059,30 +2059,6 @@ _registerDomainEvent(virDriverPtr driver) /** * The Network Functions here on */ -static virDrvOpenStatus vboxNetworkOpen(virConnectPtr conn, - virConnectAuthPtr auth ATTRIBUTE_UNUSED, - unsigned int flags) -{ - vboxGlobalData *data = conn->privateData; - - virCheckFlags(VIR_CONNECT_RO, VIR_DRV_OPEN_ERROR); - - if (STRNEQ(conn->driver->name, "VBOX")) - goto cleanup; - - if ((data->pFuncs == NULL) || - (data->vboxObj == NULL) || - (data->vboxSession == NULL)) - goto cleanup; - - VIR_DEBUG("network initialized"); - /* conn->networkPrivateData = some network specific data */ - return VIR_DRV_OPEN_SUCCESS; - - cleanup: - return VIR_DRV_OPEN_DECLINED; -} - static int vboxNetworkClose(virConnectPtr conn) { VIR_DEBUG("network uninitialized"); diff --git a/src/vbox/vbox_uniformed_api.h b/src/vbox/vbox_uniformed_api.h index 41ce40f..0237160 100644 --- a/src/vbox/vbox_uniformed_api.h +++ b/src/vbox/vbox_uniformed_api.h @@ -534,6 +534,9 @@ typedef struct { virDomainPtr vboxDomainLookupByUUID(virConnectPtr conn, const unsigned char *uuid); +virDrvOpenStatus vboxNetworkOpen(virConnectPtr conn, + virConnectAuthPtr auth, + unsigned int flags); /* Version specified functions for installing uniformed API */ void vbox22InstallUniformedAPI(vboxUniformedAPI *pVBoxAPI); -- 1.7.9.5

On 20.08.2014 02:17, Taowei wrote:
--- src/vbox/vbox_common.c | 28 ++++++++++++++++++++++++++++ src/vbox/vbox_tmpl.c | 24 ------------------------ src/vbox/vbox_uniformed_api.h | 3 +++ 3 files changed, 31 insertions(+), 24 deletions(-)
diff --git a/src/vbox/vbox_common.c b/src/vbox/vbox_common.c index b186ea8..b7251e5 100644 --- a/src/vbox/vbox_common.c +++ b/src/vbox/vbox_common.c @@ -7453,6 +7453,34 @@ vboxNodeGetFreePages(virConnectPtr conn ATTRIBUTE_UNUSED, }
/** + * The Network Functions here on + */ + +virDrvOpenStatus vboxNetworkOpen(virConnectPtr conn, + virConnectAuthPtr auth ATTRIBUTE_UNUSED, + unsigned int flags) +{ + vboxGlobalData *data = conn->privateData; + + virCheckFlags(VIR_CONNECT_RO, VIR_DRV_OPEN_ERROR); + + if (STRNEQ(conn->driver->name, "VBOX")) + goto cleanup; + + if ((data->pFuncs == NULL) || + (data->vboxObj == NULL) || + (data->vboxSession == NULL)) + goto cleanup;
While you're at this you can reformat these, s/ +==/ ==/. Here and in the rest of the patches. Michal

On 08/20/2014 10:20 AM, Michal Privoznik wrote:
On 20.08.2014 02:17, Taowei wrote:
--- src/vbox/vbox_common.c | 28 ++++++++++++++++++++++++++++ src/vbox/vbox_tmpl.c | 24 ------------------------ src/vbox/vbox_uniformed_api.h | 3 +++ 3 files changed, 31 insertions(+), 24 deletions(-)
+ if ((data->pFuncs == NULL) || + (data->vboxObj == NULL) || + (data->vboxSession == NULL)) + goto cleanup;
While you're at this you can reformat these, s/ +==/ ==/. Here and in the rest of the patches.
Or even shorter (dropping redundant (), and using ! instead of comparison against NULL): if (!data->pFuncs || !data->vboxObj || !data->vboxSession) goto cleanup; -- Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org

--- src/vbox/vbox_common.c | 7 +++++++ src/vbox/vbox_tmpl.c | 6 ------ src/vbox/vbox_uniformed_api.h | 1 + 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/src/vbox/vbox_common.c b/src/vbox/vbox_common.c index b7251e5..4f11b7d 100644 --- a/src/vbox/vbox_common.c +++ b/src/vbox/vbox_common.c @@ -7480,6 +7480,13 @@ virDrvOpenStatus vboxNetworkOpen(virConnectPtr conn, return VIR_DRV_OPEN_DECLINED; } +int vboxNetworkClose(virConnectPtr conn) +{ + VIR_DEBUG("network uninitialized"); + conn->networkPrivateData = NULL; + return 0; +} + /** * Function Tables */ diff --git a/src/vbox/vbox_tmpl.c b/src/vbox/vbox_tmpl.c index 23bbdcb..7b4be00 100644 --- a/src/vbox/vbox_tmpl.c +++ b/src/vbox/vbox_tmpl.c @@ -2059,12 +2059,6 @@ _registerDomainEvent(virDriverPtr driver) /** * The Network Functions here on */ -static int vboxNetworkClose(virConnectPtr conn) -{ - VIR_DEBUG("network uninitialized"); - conn->networkPrivateData = NULL; - return 0; -} static int vboxConnectNumOfNetworks(virConnectPtr conn) { diff --git a/src/vbox/vbox_uniformed_api.h b/src/vbox/vbox_uniformed_api.h index 0237160..8552efb 100644 --- a/src/vbox/vbox_uniformed_api.h +++ b/src/vbox/vbox_uniformed_api.h @@ -537,6 +537,7 @@ virDomainPtr vboxDomainLookupByUUID(virConnectPtr conn, virDrvOpenStatus vboxNetworkOpen(virConnectPtr conn, virConnectAuthPtr auth, unsigned int flags); +int vboxNetworkClose(virConnectPtr conn); /* Version specified functions for installing uniformed API */ void vbox22InstallUniformedAPI(vboxUniformedAPI *pVBoxAPI); -- 1.7.9.5

--- src/vbox/vbox_common.c | 46 +++++++++++++++++++++++++++++ src/vbox/vbox_common.h | 15 ++++++++++ src/vbox/vbox_tmpl.c | 65 ++++++++++++++++++++--------------------- src/vbox/vbox_uniformed_api.h | 10 +++++++ 4 files changed, 102 insertions(+), 34 deletions(-) diff --git a/src/vbox/vbox_common.c b/src/vbox/vbox_common.c index 4f11b7d..7aeb3b9 100644 --- a/src/vbox/vbox_common.c +++ b/src/vbox/vbox_common.c @@ -104,6 +104,17 @@ type ret = value;\ if (!data->vboxObj) {\ return ret;\ } +#define VBOX_OBJECT_HOST_CHECK(conn, type, value) \ +vboxGlobalData *data = conn->privateData;\ +type ret = value;\ +IHost *host = NULL;\ +if (!data->vboxObj) {\ + return ret;\ +}\ +gVBoxAPI.UIVirtualBox.GetHost(data->vboxObj, &host);\ +if (!host) {\ + return ret;\ +} #define vboxIIDUnalloc(iid) gVBoxAPI.UIID.vboxIIDUnalloc(data, iid) #define vboxIIDToUUID(iid, uuid) gVBoxAPI.UIID.vboxIIDToUUID(data, iid, uuid) @@ -7487,6 +7498,41 @@ int vboxNetworkClose(virConnectPtr conn) return 0; } +int vboxConnectNumOfNetworks(virConnectPtr conn) +{ + VBOX_OBJECT_HOST_CHECK(conn, int, 0); + vboxArray networkInterfaces = VBOX_ARRAY_INITIALIZER; + size_t i = 0; + + gVBoxAPI.UArray.vboxArrayGet(&networkInterfaces, host, + gVBoxAPI.UArray.handleHostGetNetworkInterfaces(host)); + + for (i = 0; i < networkInterfaces.count; i++) { + IHostNetworkInterface *networkInterface = networkInterfaces.items[i]; + PRUint32 status = HostNetworkInterfaceStatus_Unknown; + PRUint32 interfaceType = 0; + + if (!networkInterface) + continue; + + gVBoxAPI.UIHNInterface.GetInterfaceType(networkInterface, &interfaceType); + if (interfaceType != HostNetworkInterfaceType_HostOnly) + continue; + + gVBoxAPI.UIHNInterface.GetStatus(networkInterface, &status); + + if (status == HostNetworkInterfaceStatus_Up) + ret++; + } + + gVBoxAPI.UArray.vboxArrayRelease(&networkInterfaces); + + VBOX_RELEASE(host); + + VIR_DEBUG("numActive: %d", ret); + return ret; +} + /** * Function Tables */ diff --git a/src/vbox/vbox_common.h b/src/vbox/vbox_common.h index b5a0353..9f5385b 100644 --- a/src/vbox/vbox_common.h +++ b/src/vbox/vbox_common.h @@ -265,6 +265,19 @@ enum MediumVariant MediumVariant_Diff = 0x20000 }; +enum HostNetworkInterfaceStatus +{ + HostNetworkInterfaceStatus_Unknown = 0, + HostNetworkInterfaceStatus_Up = 1, + HostNetworkInterfaceStatus_Down = 2 +}; + +enum HostNetworkInterfaceType +{ + HostNetworkInterfaceType_Bridged = 1, + HostNetworkInterfaceType_HostOnly = 2 +}; + # define VBOX_E_OBJECT_NOT_FOUND 0x80BB0001 # define VBOX_E_INVALID_VM_STATE 0x80BB0002 # define VBOX_E_VM_ERROR 0x80BB0003 @@ -302,5 +315,7 @@ typedef nsISupports IStorageController; typedef nsISupports ISharedFolder; typedef nsISupports ISnapshot; typedef nsISupports IDisplay; +typedef nsISupports IHost; +typedef nsISupports IHostNetworkInterface; #endif /* VBOX_COMMON_H */ diff --git a/src/vbox/vbox_tmpl.c b/src/vbox/vbox_tmpl.c index 7b4be00..f24be07 100644 --- a/src/vbox/vbox_tmpl.c +++ b/src/vbox/vbox_tmpl.c @@ -2060,40 +2060,6 @@ _registerDomainEvent(virDriverPtr driver) * The Network Functions here on */ -static int vboxConnectNumOfNetworks(virConnectPtr conn) -{ - VBOX_OBJECT_HOST_CHECK(conn, int, 0); - vboxArray networkInterfaces = VBOX_ARRAY_INITIALIZER; - size_t i = 0; - - vboxArrayGet(&networkInterfaces, host, host->vtbl->GetNetworkInterfaces); - - for (i = 0; i < networkInterfaces.count; i++) { - IHostNetworkInterface *networkInterface = networkInterfaces.items[i]; - - if (networkInterface) { - PRUint32 interfaceType = 0; - - networkInterface->vtbl->GetInterfaceType(networkInterface, &interfaceType); - if (interfaceType == HostNetworkInterfaceType_HostOnly) { - PRUint32 status = HostNetworkInterfaceStatus_Unknown; - - networkInterface->vtbl->GetStatus(networkInterface, &status); - - if (status == HostNetworkInterfaceStatus_Up) - ret++; - } - } - } - - vboxArrayRelease(&networkInterfaces); - - VBOX_RELEASE(host); - - VIR_DEBUG("numActive: %d", ret); - return ret; -} - static int vboxConnectListNetworks(virConnectPtr conn, char **const names, int nnames) { VBOX_OBJECT_HOST_CHECK(conn, int, 0); vboxArray networkInterfaces = VBOX_ARRAY_INITIALIZER; @@ -4500,6 +4466,11 @@ static void* _handleMediumGetSnapshotIds(IMedium *medium) return medium->vtbl->GetSnapshotIds; } +static void* _handleHostGetNetworkInterfaces(IHost *host) +{ + return host->vtbl->GetNetworkInterfaces; +} + static nsresult _nsisupportsRelease(nsISupports *nsi) { return nsi->vtbl->Release(nsi); @@ -4547,6 +4518,12 @@ _virtualboxGetSystemProperties(IVirtualBox *vboxObj, ISystemProperties **systemP } static nsresult +_virtualboxGetHost(IVirtualBox *vboxObj, IHost **host) +{ + return vboxObj->vtbl->GetHost(vboxObj, host); +} + +static nsresult _virtualboxCreateMachine(vboxGlobalData *data, virDomainDefPtr def, IMachine **machine, char *uuidstr ATTRIBUTE_UNUSED) { vboxIID iid = VBOX_IID_INITIALIZER; @@ -6042,6 +6019,18 @@ _displayTakeScreenShotPNGToArray(IDisplay *display ATTRIBUTE_UNUSED, #endif /* VBOX_API_VERSION >= 4000000 */ } +static nsresult +_hnInterfaceGetInterfaceType(IHostNetworkInterface *hni, PRUint32 *interfaceType) +{ + return hni->vtbl->GetInterfaceType(hni, interfaceType); +} + +static nsresult +_hnInterfaceGetStatus(IHostNetworkInterface *hni, PRUint32 *status) +{ + return hni->vtbl->GetStatus(hni, status); +} + static bool _machineStateOnline(PRUint32 state) { return ((state >= MachineState_FirstOnline) && @@ -6108,6 +6097,7 @@ static vboxUniformedArray _UArray = { .handleSnapshotGetChildren = _handleSnapshotGetChildren, .handleMediumGetChildren = _handleMediumGetChildren, .handleMediumGetSnapshotIds = _handleMediumGetSnapshotIds, + .handleHostGetNetworkInterfaces = _handleHostGetNetworkInterfaces, }; static vboxUniformednsISupports _nsUISupports = { @@ -6120,6 +6110,7 @@ static vboxUniformedIVirtualBox _UIVirtualBox = { .GetMachine = _virtualboxGetMachine, .OpenMachine = _virtualboxOpenMachine, .GetSystemProperties = _virtualboxGetSystemProperties, + .GetHost = _virtualboxGetHost, .CreateMachine = _virtualboxCreateMachine, .CreateHardDiskMedium = _virtualboxCreateHardDiskMedium, .RegisterMachine = _virtualboxRegisterMachine, @@ -6343,6 +6334,11 @@ static vboxUniformedIDisplay _UIDisplay = { .TakeScreenShotPNGToArray = _displayTakeScreenShotPNGToArray, }; +static vboxUniformedIHNInterface _UIHNInterface = { + .GetInterfaceType = _hnInterfaceGetInterfaceType, + .GetStatus = _hnInterfaceGetStatus, +}; + static uniformedMachineStateChecker _machineStateChecker = { .Online = _machineStateOnline, .Inactive = _machineStateInactive, @@ -6396,6 +6392,7 @@ void NAME(InstallUniformedAPI)(vboxUniformedAPI *pVBoxAPI) pVBoxAPI->UISharedFolder = _UISharedFolder; pVBoxAPI->UISnapshot = _UISnapshot; pVBoxAPI->UIDisplay = _UIDisplay; + pVBoxAPI->UIHNInterface = _UIHNInterface; pVBoxAPI->machineStateChecker = _machineStateChecker; #if VBOX_API_VERSION <= 2002000 || VBOX_API_VERSION >= 4000000 diff --git a/src/vbox/vbox_uniformed_api.h b/src/vbox/vbox_uniformed_api.h index 8552efb..9644f61 100644 --- a/src/vbox/vbox_uniformed_api.h +++ b/src/vbox/vbox_uniformed_api.h @@ -176,6 +176,7 @@ typedef struct { void* (*handleSnapshotGetChildren)(ISnapshot *snapshot); void* (*handleMediumGetChildren)(IMedium *medium); void* (*handleMediumGetSnapshotIds)(IMedium *medium); + void* (*handleHostGetNetworkInterfaces)(IHost *host); } vboxUniformedArray; /* Functions for nsISupports */ @@ -190,6 +191,7 @@ typedef struct { nsresult (*GetMachine)(IVirtualBox *vboxObj, vboxIIDUnion *iidu, IMachine **machine); nsresult (*OpenMachine)(IVirtualBox *vboxObj, PRUnichar *settingsFile, IMachine **machine); nsresult (*GetSystemProperties)(IVirtualBox *vboxObj, ISystemProperties **systemProperties); + nsresult (*GetHost)(IVirtualBox *vboxObj, IHost **host); nsresult (*CreateMachine)(vboxGlobalData *data, virDomainDefPtr def, IMachine **machine, char *uuidstr); nsresult (*CreateHardDiskMedium)(IVirtualBox *vboxObj, PRUnichar *format, PRUnichar *location, IMedium **medium); nsresult (*RegisterMachine)(IVirtualBox *vboxObj, IMachine *machine); @@ -464,6 +466,12 @@ typedef struct { PRUint8** screenData); } vboxUniformedIDisplay; +/* Functions for IHostNetworkInterface */ +typedef struct { + nsresult (*GetInterfaceType)(IHostNetworkInterface *hni, PRUint32 *interfaceType); + nsresult (*GetStatus)(IHostNetworkInterface *hni, PRUint32 *status); +} vboxUniformedIHNInterface; + typedef struct { bool (*Online)(PRUint32 state); bool (*Inactive)(PRUint32 state); @@ -518,6 +526,7 @@ typedef struct { vboxUniformedISharedFolder UISharedFolder; vboxUniformedISnapshot UISnapshot; vboxUniformedIDisplay UIDisplay; + vboxUniformedIHNInterface UIHNInterface; uniformedMachineStateChecker machineStateChecker; /* vbox API features */ bool domainEventCallbacks; @@ -538,6 +547,7 @@ virDrvOpenStatus vboxNetworkOpen(virConnectPtr conn, virConnectAuthPtr auth, unsigned int flags); int vboxNetworkClose(virConnectPtr conn); +int vboxConnectNumOfNetworks(virConnectPtr conn); /* Version specified functions for installing uniformed API */ void vbox22InstallUniformedAPI(vboxUniformedAPI *pVBoxAPI); -- 1.7.9.5

On 20.08.2014 02:17, Taowei wrote:
--- src/vbox/vbox_common.c | 46 +++++++++++++++++++++++++++++ src/vbox/vbox_common.h | 15 ++++++++++ src/vbox/vbox_tmpl.c | 65 ++++++++++++++++++++--------------------- src/vbox/vbox_uniformed_api.h | 10 +++++++ 4 files changed, 102 insertions(+), 34 deletions(-)
diff --git a/src/vbox/vbox_common.c b/src/vbox/vbox_common.c index 4f11b7d..7aeb3b9 100644 --- a/src/vbox/vbox_common.c +++ b/src/vbox/vbox_common.c @@ -104,6 +104,17 @@ type ret = value;\ if (!data->vboxObj) {\ return ret;\ } +#define VBOX_OBJECT_HOST_CHECK(conn, type, value) \ +vboxGlobalData *data = conn->privateData;\ +type ret = value;\ +IHost *host = NULL;\ +if (!data->vboxObj) {\ + return ret;\ +}\
This is rather unusual macro. I'd expect any CHECK macro just to check if given condition is true. Of course for that purpose it can declare local variables, but they had to be disclosed in do { } while(0) block to prevent namespace pollution. I know you're just copying preexisting code. But the code we currently have is wrong in many ways. So I guess we can fix this now. I'd just drop the macros for good. I don't find them useful anyway. Michal

--- src/vbox/vbox_common.c | 47 +++++++++++++++++++++++++++++++++++++ src/vbox/vbox_tmpl.c | 52 ++++++----------------------------------- src/vbox/vbox_uniformed_api.h | 2 ++ 3 files changed, 56 insertions(+), 45 deletions(-) diff --git a/src/vbox/vbox_common.c b/src/vbox/vbox_common.c index 7aeb3b9..e532393 100644 --- a/src/vbox/vbox_common.c +++ b/src/vbox/vbox_common.c @@ -7533,6 +7533,53 @@ int vboxConnectNumOfNetworks(virConnectPtr conn) return ret; } +int vboxConnectListNetworks(virConnectPtr conn, char **const names, int nnames) +{ + VBOX_OBJECT_HOST_CHECK(conn, int, 0); + vboxArray networkInterfaces = VBOX_ARRAY_INITIALIZER; + size_t i = 0; + + gVBoxAPI.UArray.vboxArrayGet(&networkInterfaces, host, + gVBoxAPI.UArray.handleHostGetNetworkInterfaces(host)); + + for (i = 0; (ret < nnames) && (i < networkInterfaces.count); i++) { + IHostNetworkInterface *networkInterface = networkInterfaces.items[i]; + char *nameUtf8 = NULL; + PRUnichar *nameUtf16 = NULL; + PRUint32 interfaceType = 0; + PRUint32 status = HostNetworkInterfaceStatus_Unknown; + + if (!networkInterface) + continue; + + gVBoxAPI.UIHNInterface.GetInterfaceType(networkInterface, &interfaceType); + + if (interfaceType != HostNetworkInterfaceType_HostOnly) + continue; + + gVBoxAPI.UIHNInterface.GetStatus(networkInterface, &status); + + if (status != HostNetworkInterfaceStatus_Up) + continue; + + gVBoxAPI.UIHNInterface.GetName(networkInterface, &nameUtf16); + VBOX_UTF16_TO_UTF8(nameUtf16, &nameUtf8); + + VIR_DEBUG("nnames[%d]: %s", ret, nameUtf8); + if (VIR_STRDUP(names[ret], nameUtf8) >= 0) + ret++; + + VBOX_UTF8_FREE(nameUtf8); + VBOX_UTF16_FREE(nameUtf16); + } + + gVBoxAPI.UArray.vboxArrayRelease(&networkInterfaces); + + VBOX_RELEASE(host); + + return ret; +} + /** * Function Tables */ diff --git a/src/vbox/vbox_tmpl.c b/src/vbox/vbox_tmpl.c index f24be07..738547f 100644 --- a/src/vbox/vbox_tmpl.c +++ b/src/vbox/vbox_tmpl.c @@ -2060,51 +2060,6 @@ _registerDomainEvent(virDriverPtr driver) * The Network Functions here on */ -static int vboxConnectListNetworks(virConnectPtr conn, char **const names, int nnames) { - VBOX_OBJECT_HOST_CHECK(conn, int, 0); - vboxArray networkInterfaces = VBOX_ARRAY_INITIALIZER; - size_t i = 0; - - vboxArrayGet(&networkInterfaces, host, host->vtbl->GetNetworkInterfaces); - - for (i = 0; (ret < nnames) && (i < networkInterfaces.count); i++) { - IHostNetworkInterface *networkInterface = networkInterfaces.items[i]; - - if (networkInterface) { - PRUint32 interfaceType = 0; - - networkInterface->vtbl->GetInterfaceType(networkInterface, &interfaceType); - - if (interfaceType == HostNetworkInterfaceType_HostOnly) { - PRUint32 status = HostNetworkInterfaceStatus_Unknown; - - networkInterface->vtbl->GetStatus(networkInterface, &status); - - if (status == HostNetworkInterfaceStatus_Up) { - char *nameUtf8 = NULL; - PRUnichar *nameUtf16 = NULL; - - networkInterface->vtbl->GetName(networkInterface, &nameUtf16); - VBOX_UTF16_TO_UTF8(nameUtf16, &nameUtf8); - - VIR_DEBUG("nnames[%d]: %s", ret, nameUtf8); - if (VIR_STRDUP(names[ret], nameUtf8) >= 0) - ret++; - - VBOX_UTF8_FREE(nameUtf8); - VBOX_UTF16_FREE(nameUtf16); - } - } - } - } - - vboxArrayRelease(&networkInterfaces); - - VBOX_RELEASE(host); - - return ret; -} - static int vboxConnectNumOfDefinedNetworks(virConnectPtr conn) { VBOX_OBJECT_HOST_CHECK(conn, int, 0); @@ -6031,6 +5986,12 @@ _hnInterfaceGetStatus(IHostNetworkInterface *hni, PRUint32 *status) return hni->vtbl->GetStatus(hni, status); } +static nsresult +_hnInterfaceGetName(IHostNetworkInterface *hni, PRUnichar **name) +{ + return hni->vtbl->GetName(hni, name); +} + static bool _machineStateOnline(PRUint32 state) { return ((state >= MachineState_FirstOnline) && @@ -6337,6 +6298,7 @@ static vboxUniformedIDisplay _UIDisplay = { static vboxUniformedIHNInterface _UIHNInterface = { .GetInterfaceType = _hnInterfaceGetInterfaceType, .GetStatus = _hnInterfaceGetStatus, + .GetName = _hnInterfaceGetName, }; static uniformedMachineStateChecker _machineStateChecker = { diff --git a/src/vbox/vbox_uniformed_api.h b/src/vbox/vbox_uniformed_api.h index 9644f61..ec8e334 100644 --- a/src/vbox/vbox_uniformed_api.h +++ b/src/vbox/vbox_uniformed_api.h @@ -470,6 +470,7 @@ typedef struct { typedef struct { nsresult (*GetInterfaceType)(IHostNetworkInterface *hni, PRUint32 *interfaceType); nsresult (*GetStatus)(IHostNetworkInterface *hni, PRUint32 *status); + nsresult (*GetName)(IHostNetworkInterface *hni, PRUnichar **name); } vboxUniformedIHNInterface; typedef struct { @@ -548,6 +549,7 @@ virDrvOpenStatus vboxNetworkOpen(virConnectPtr conn, unsigned int flags); int vboxNetworkClose(virConnectPtr conn); int vboxConnectNumOfNetworks(virConnectPtr conn); +int vboxConnectListNetworks(virConnectPtr conn, char **const names, int nnames); /* Version specified functions for installing uniformed API */ void vbox22InstallUniformedAPI(vboxUniformedAPI *pVBoxAPI); -- 1.7.9.5

--- src/vbox/vbox_common.c | 35 +++++++++++++++++++++++++++++++++++ src/vbox/vbox_tmpl.c | 34 ---------------------------------- src/vbox/vbox_uniformed_api.h | 1 + 3 files changed, 36 insertions(+), 34 deletions(-) diff --git a/src/vbox/vbox_common.c b/src/vbox/vbox_common.c index e532393..fc5faca 100644 --- a/src/vbox/vbox_common.c +++ b/src/vbox/vbox_common.c @@ -7580,6 +7580,41 @@ int vboxConnectListNetworks(virConnectPtr conn, char **const names, int nnames) return ret; } +int vboxConnectNumOfDefinedNetworks(virConnectPtr conn) +{ + VBOX_OBJECT_HOST_CHECK(conn, int, 0); + vboxArray networkInterfaces = VBOX_ARRAY_INITIALIZER; + size_t i = 0; + + gVBoxAPI.UArray.vboxArrayGet(&networkInterfaces, host, + gVBoxAPI.UArray.handleHostGetNetworkInterfaces(host)); + + for (i = 0; i < networkInterfaces.count; i++) { + IHostNetworkInterface *networkInterface = networkInterfaces.items[i]; + PRUint32 status = HostNetworkInterfaceStatus_Unknown; + PRUint32 interfaceType = 0; + + if (!networkInterface) + continue; + + gVBoxAPI.UIHNInterface.GetInterfaceType(networkInterface, &interfaceType); + if (interfaceType != HostNetworkInterfaceType_HostOnly) + continue; + + gVBoxAPI.UIHNInterface.GetStatus(networkInterface, &status); + + if (status == HostNetworkInterfaceStatus_Down) + ret++; + } + + gVBoxAPI.UArray.vboxArrayRelease(&networkInterfaces); + + VBOX_RELEASE(host); + + VIR_DEBUG("numActive: %d", ret); + return ret; +} + /** * Function Tables */ diff --git a/src/vbox/vbox_tmpl.c b/src/vbox/vbox_tmpl.c index 738547f..52d0b1f 100644 --- a/src/vbox/vbox_tmpl.c +++ b/src/vbox/vbox_tmpl.c @@ -2060,40 +2060,6 @@ _registerDomainEvent(virDriverPtr driver) * The Network Functions here on */ -static int vboxConnectNumOfDefinedNetworks(virConnectPtr conn) -{ - VBOX_OBJECT_HOST_CHECK(conn, int, 0); - vboxArray networkInterfaces = VBOX_ARRAY_INITIALIZER; - size_t i = 0; - - vboxArrayGet(&networkInterfaces, host, host->vtbl->GetNetworkInterfaces); - - for (i = 0; i < networkInterfaces.count; i++) { - IHostNetworkInterface *networkInterface = networkInterfaces.items[i]; - - if (networkInterface) { - PRUint32 interfaceType = 0; - - networkInterface->vtbl->GetInterfaceType(networkInterface, &interfaceType); - if (interfaceType == HostNetworkInterfaceType_HostOnly) { - PRUint32 status = HostNetworkInterfaceStatus_Unknown; - - networkInterface->vtbl->GetStatus(networkInterface, &status); - - if (status == HostNetworkInterfaceStatus_Down) - ret++; - } - } - } - - vboxArrayRelease(&networkInterfaces); - - VBOX_RELEASE(host); - - VIR_DEBUG("numActive: %d", ret); - return ret; -} - static int vboxConnectListDefinedNetworks(virConnectPtr conn, char **const names, int nnames) { VBOX_OBJECT_HOST_CHECK(conn, int, 0); vboxArray networkInterfaces = VBOX_ARRAY_INITIALIZER; diff --git a/src/vbox/vbox_uniformed_api.h b/src/vbox/vbox_uniformed_api.h index ec8e334..2ca90ff 100644 --- a/src/vbox/vbox_uniformed_api.h +++ b/src/vbox/vbox_uniformed_api.h @@ -550,6 +550,7 @@ virDrvOpenStatus vboxNetworkOpen(virConnectPtr conn, int vboxNetworkClose(virConnectPtr conn); int vboxConnectNumOfNetworks(virConnectPtr conn); int vboxConnectListNetworks(virConnectPtr conn, char **const names, int nnames); +int vboxConnectNumOfDefinedNetworks(virConnectPtr conn); /* Version specified functions for installing uniformed API */ void vbox22InstallUniformedAPI(vboxUniformedAPI *pVBoxAPI); -- 1.7.9.5

--- src/vbox/vbox_common.c | 47 +++++++++++++++++++++++++++++++++++++++++ src/vbox/vbox_tmpl.c | 45 --------------------------------------- src/vbox/vbox_uniformed_api.h | 1 + 3 files changed, 48 insertions(+), 45 deletions(-) diff --git a/src/vbox/vbox_common.c b/src/vbox/vbox_common.c index fc5faca..b8a633d 100644 --- a/src/vbox/vbox_common.c +++ b/src/vbox/vbox_common.c @@ -7615,6 +7615,53 @@ int vboxConnectNumOfDefinedNetworks(virConnectPtr conn) return ret; } +int vboxConnectListDefinedNetworks(virConnectPtr conn, char **const names, int nnames) +{ + VBOX_OBJECT_HOST_CHECK(conn, int, 0); + vboxArray networkInterfaces = VBOX_ARRAY_INITIALIZER; + size_t i = 0; + + gVBoxAPI.UArray.vboxArrayGet(&networkInterfaces, host, + gVBoxAPI.UArray.handleHostGetNetworkInterfaces(host)); + + for (i = 0; (ret < nnames) && (i < networkInterfaces.count); i++) { + IHostNetworkInterface *networkInterface = networkInterfaces.items[i]; + PRUint32 interfaceType = 0; + char *nameUtf8 = NULL; + PRUnichar *nameUtf16 = NULL; + PRUint32 status = HostNetworkInterfaceStatus_Unknown; + + if (!networkInterface) + continue; + + gVBoxAPI.UIHNInterface.GetInterfaceType(networkInterface, &interfaceType); + + if (interfaceType != HostNetworkInterfaceType_HostOnly) + continue; + + gVBoxAPI.UIHNInterface.GetStatus(networkInterface, &status); + + if (status != HostNetworkInterfaceStatus_Down) + continue; + + gVBoxAPI.UIHNInterface.GetName(networkInterface, &nameUtf16); + VBOX_UTF16_TO_UTF8(nameUtf16, &nameUtf8); + + VIR_DEBUG("nnames[%d]: %s", ret, nameUtf8); + if (VIR_STRDUP(names[ret], nameUtf8) >= 0) + ret++; + + VBOX_UTF8_FREE(nameUtf8); + VBOX_UTF16_FREE(nameUtf16); + } + + gVBoxAPI.UArray.vboxArrayRelease(&networkInterfaces); + + VBOX_RELEASE(host); + + return ret; +} + /** * Function Tables */ diff --git a/src/vbox/vbox_tmpl.c b/src/vbox/vbox_tmpl.c index 52d0b1f..f52690a 100644 --- a/src/vbox/vbox_tmpl.c +++ b/src/vbox/vbox_tmpl.c @@ -2060,51 +2060,6 @@ _registerDomainEvent(virDriverPtr driver) * The Network Functions here on */ -static int vboxConnectListDefinedNetworks(virConnectPtr conn, char **const names, int nnames) { - VBOX_OBJECT_HOST_CHECK(conn, int, 0); - vboxArray networkInterfaces = VBOX_ARRAY_INITIALIZER; - size_t i = 0; - - vboxArrayGet(&networkInterfaces, host, host->vtbl->GetNetworkInterfaces); - - for (i = 0; (ret < nnames) && (i < networkInterfaces.count); i++) { - IHostNetworkInterface *networkInterface = networkInterfaces.items[i]; - - if (networkInterface) { - PRUint32 interfaceType = 0; - - networkInterface->vtbl->GetInterfaceType(networkInterface, &interfaceType); - - if (interfaceType == HostNetworkInterfaceType_HostOnly) { - PRUint32 status = HostNetworkInterfaceStatus_Unknown; - - networkInterface->vtbl->GetStatus(networkInterface, &status); - - if (status == HostNetworkInterfaceStatus_Down) { - char *nameUtf8 = NULL; - PRUnichar *nameUtf16 = NULL; - - networkInterface->vtbl->GetName(networkInterface, &nameUtf16); - VBOX_UTF16_TO_UTF8(nameUtf16, &nameUtf8); - - VIR_DEBUG("nnames[%d]: %s", ret, nameUtf8); - if (VIR_STRDUP(names[ret], nameUtf8) >= 0) - ret++; - - VBOX_UTF8_FREE(nameUtf8); - VBOX_UTF16_FREE(nameUtf16); - } - } - } - } - - vboxArrayRelease(&networkInterfaces); - - VBOX_RELEASE(host); - - return ret; -} - static virNetworkPtr vboxNetworkLookupByUUID(virConnectPtr conn, const unsigned char *uuid) { diff --git a/src/vbox/vbox_uniformed_api.h b/src/vbox/vbox_uniformed_api.h index 2ca90ff..e6729f2 100644 --- a/src/vbox/vbox_uniformed_api.h +++ b/src/vbox/vbox_uniformed_api.h @@ -551,6 +551,7 @@ int vboxNetworkClose(virConnectPtr conn); int vboxConnectNumOfNetworks(virConnectPtr conn); int vboxConnectListNetworks(virConnectPtr conn, char **const names, int nnames); int vboxConnectNumOfDefinedNetworks(virConnectPtr conn); +int vboxConnectListDefinedNetworks(virConnectPtr conn, char **const names, int nnames); /* Version specified functions for installing uniformed API */ void vbox22InstallUniformedAPI(vboxUniformedAPI *pVBoxAPI); -- 1.7.9.5

--- src/vbox/vbox_common.c | 43 +++++++++++++++++++++++++++++++ src/vbox/vbox_tmpl.c | 57 ++++++++++------------------------------- src/vbox/vbox_uniformed_api.h | 8 ++++++ 3 files changed, 64 insertions(+), 44 deletions(-) diff --git a/src/vbox/vbox_common.c b/src/vbox/vbox_common.c index b8a633d..03ab8d0 100644 --- a/src/vbox/vbox_common.c +++ b/src/vbox/vbox_common.c @@ -7662,6 +7662,49 @@ int vboxConnectListDefinedNetworks(virConnectPtr conn, char **const names, int n return ret; } +virNetworkPtr vboxNetworkLookupByUUID(virConnectPtr conn, const unsigned char *uuid) +{ + VBOX_OBJECT_HOST_CHECK(conn, virNetworkPtr, NULL); + PRUint32 interfaceType = 0; + char *nameUtf8 = NULL; + PRUnichar *nameUtf16 = NULL; + IHostNetworkInterface *networkInterface = NULL; + vboxIIDUnion iid; + + VBOX_IID_INITIALIZE(&iid); + vboxIIDFromUUID(&iid, uuid); + + /* TODO: "internal" networks are just strings and + * thus can't do much with them + */ + + gVBoxAPI.UIHost.FindHostNetworkInterfaceById(host, &iid, + &networkInterface); + if (!networkInterface) + goto cleanup; + + gVBoxAPI.UIHNInterface.GetInterfaceType(networkInterface, &interfaceType); + + if (interfaceType != HostNetworkInterfaceType_HostOnly) + goto cleanup; + + gVBoxAPI.UIHNInterface.GetName(networkInterface, &nameUtf16); + VBOX_UTF16_TO_UTF8(nameUtf16, &nameUtf8); + + ret = virGetNetwork(conn, nameUtf8, uuid); + + VIR_DEBUG("Network Name: %s", nameUtf8); + DEBUGIID("Network UUID", &iid); + VBOX_UTF8_FREE(nameUtf8); + VBOX_UTF16_FREE(nameUtf16); + + cleanup: + VBOX_RELEASE(networkInterface); + VBOX_RELEASE(host); + vboxIIDUnalloc(&iid); + return ret; +} + /** * Function Tables */ diff --git a/src/vbox/vbox_tmpl.c b/src/vbox/vbox_tmpl.c index f52690a..282ab6a 100644 --- a/src/vbox/vbox_tmpl.c +++ b/src/vbox/vbox_tmpl.c @@ -2061,50 +2061,6 @@ _registerDomainEvent(virDriverPtr driver) */ static virNetworkPtr -vboxNetworkLookupByUUID(virConnectPtr conn, const unsigned char *uuid) -{ - VBOX_OBJECT_HOST_CHECK(conn, virNetworkPtr, NULL); - vboxIID iid = VBOX_IID_INITIALIZER; - - vboxIIDFromUUID(&iid, uuid); - - /* TODO: "internal" networks are just strings and - * thus can't do much with them - */ - IHostNetworkInterface *networkInterface = NULL; - - host->vtbl->FindHostNetworkInterfaceById(host, iid.value, &networkInterface); - if (networkInterface) { - PRUint32 interfaceType = 0; - - networkInterface->vtbl->GetInterfaceType(networkInterface, &interfaceType); - - if (interfaceType == HostNetworkInterfaceType_HostOnly) { - char *nameUtf8 = NULL; - PRUnichar *nameUtf16 = NULL; - - networkInterface->vtbl->GetName(networkInterface, &nameUtf16); - VBOX_UTF16_TO_UTF8(nameUtf16, &nameUtf8); - - ret = virGetNetwork(conn, nameUtf8, uuid); - - VIR_DEBUG("Network Name: %s", nameUtf8); - DEBUGIID("Network UUID", iid.value); - - VBOX_UTF8_FREE(nameUtf8); - VBOX_UTF16_FREE(nameUtf16); - } - - VBOX_RELEASE(networkInterface); - } - - VBOX_RELEASE(host); - - vboxIIDUnalloc(&iid); - return ret; -} - -static virNetworkPtr vboxNetworkLookupByName(virConnectPtr conn, const char *name) { VBOX_OBJECT_HOST_CHECK(conn, virNetworkPtr, NULL); @@ -5896,6 +5852,14 @@ _displayTakeScreenShotPNGToArray(IDisplay *display ATTRIBUTE_UNUSED, } static nsresult +_hostFindHostNetworkInterfaceById(IHost *host, vboxIIDUnion *iidu, + IHostNetworkInterface **networkInterface) +{ + return host->vtbl->FindHostNetworkInterfaceById(host, IID_MEMBER(value), + networkInterface); +} + +static nsresult _hnInterfaceGetInterfaceType(IHostNetworkInterface *hni, PRUint32 *interfaceType) { return hni->vtbl->GetInterfaceType(hni, interfaceType); @@ -6216,6 +6180,10 @@ static vboxUniformedIDisplay _UIDisplay = { .TakeScreenShotPNGToArray = _displayTakeScreenShotPNGToArray, }; +static vboxUniformedIHost _UIHost = { + .FindHostNetworkInterfaceById = _hostFindHostNetworkInterfaceById, +}; + static vboxUniformedIHNInterface _UIHNInterface = { .GetInterfaceType = _hnInterfaceGetInterfaceType, .GetStatus = _hnInterfaceGetStatus, @@ -6275,6 +6243,7 @@ void NAME(InstallUniformedAPI)(vboxUniformedAPI *pVBoxAPI) pVBoxAPI->UISharedFolder = _UISharedFolder; pVBoxAPI->UISnapshot = _UISnapshot; pVBoxAPI->UIDisplay = _UIDisplay; + pVBoxAPI->UIHost = _UIHost; pVBoxAPI->UIHNInterface = _UIHNInterface; pVBoxAPI->machineStateChecker = _machineStateChecker; diff --git a/src/vbox/vbox_uniformed_api.h b/src/vbox/vbox_uniformed_api.h index e6729f2..2e0eb10 100644 --- a/src/vbox/vbox_uniformed_api.h +++ b/src/vbox/vbox_uniformed_api.h @@ -466,6 +466,12 @@ typedef struct { PRUint8** screenData); } vboxUniformedIDisplay; +/* Functions for IHost */ +typedef struct { + nsresult (*FindHostNetworkInterfaceById)(IHost *host, vboxIIDUnion *iidu, + IHostNetworkInterface **networkInterface); +} vboxUniformedIHost; + /* Functions for IHostNetworkInterface */ typedef struct { nsresult (*GetInterfaceType)(IHostNetworkInterface *hni, PRUint32 *interfaceType); @@ -527,6 +533,7 @@ typedef struct { vboxUniformedISharedFolder UISharedFolder; vboxUniformedISnapshot UISnapshot; vboxUniformedIDisplay UIDisplay; + vboxUniformedIHost UIHost; vboxUniformedIHNInterface UIHNInterface; uniformedMachineStateChecker machineStateChecker; /* vbox API features */ @@ -552,6 +559,7 @@ int vboxConnectNumOfNetworks(virConnectPtr conn); int vboxConnectListNetworks(virConnectPtr conn, char **const names, int nnames); int vboxConnectNumOfDefinedNetworks(virConnectPtr conn); int vboxConnectListDefinedNetworks(virConnectPtr conn, char **const names, int nnames); +virNetworkPtr vboxNetworkLookupByUUID(virConnectPtr conn, const unsigned char *uuid); /* Version specified functions for installing uniformed API */ void vbox22InstallUniformedAPI(vboxUniformedAPI *pVBoxAPI); -- 1.7.9.5

--- src/vbox/vbox_common.c | 37 ++++++++++++++++++++++++++++ src/vbox/vbox_tmpl.c | 54 ++++++++++++----------------------------- src/vbox/vbox_uniformed_api.h | 4 +++ 3 files changed, 57 insertions(+), 38 deletions(-) diff --git a/src/vbox/vbox_common.c b/src/vbox/vbox_common.c index 03ab8d0..2a949c5 100644 --- a/src/vbox/vbox_common.c +++ b/src/vbox/vbox_common.c @@ -7705,6 +7705,43 @@ virNetworkPtr vboxNetworkLookupByUUID(virConnectPtr conn, const unsigned char *u return ret; } +virNetworkPtr vboxNetworkLookupByName(virConnectPtr conn, const char *name) +{ + VBOX_OBJECT_HOST_CHECK(conn, virNetworkPtr, NULL); + PRUnichar *nameUtf16 = NULL; + IHostNetworkInterface *networkInterface = NULL; + PRUint32 interfaceType = 0; + unsigned char uuid[VIR_UUID_BUFLEN]; + vboxIIDUnion iid; + + VBOX_IID_INITIALIZE(&iid); + VBOX_UTF8_TO_UTF16(name, &nameUtf16); + + gVBoxAPI.UIHost.FindHostNetworkInterfaceByName(host, nameUtf16, &networkInterface); + + if (!networkInterface) + goto cleanup; + + gVBoxAPI.UIHNInterface.GetInterfaceType(networkInterface, &interfaceType); + + if (interfaceType != HostNetworkInterfaceType_HostOnly) + goto cleanup; + + gVBoxAPI.UIHNInterface.GetId(networkInterface, &iid); + vboxIIDToUUID(&iid, uuid); + ret = virGetNetwork(conn, name, uuid); + + VIR_DEBUG("Network Name: %s", name); + DEBUGIID("Network UUID", &iid); + vboxIIDUnalloc(&iid); + + cleanup: + VBOX_RELEASE(networkInterface); + VBOX_UTF16_FREE(nameUtf16); + VBOX_RELEASE(host); + return ret; +} + /** * Function Tables */ diff --git a/src/vbox/vbox_tmpl.c b/src/vbox/vbox_tmpl.c index 282ab6a..5f81367 100644 --- a/src/vbox/vbox_tmpl.c +++ b/src/vbox/vbox_tmpl.c @@ -2061,44 +2061,6 @@ _registerDomainEvent(virDriverPtr driver) */ static virNetworkPtr -vboxNetworkLookupByName(virConnectPtr conn, const char *name) -{ - VBOX_OBJECT_HOST_CHECK(conn, virNetworkPtr, NULL); - PRUnichar *nameUtf16 = NULL; - IHostNetworkInterface *networkInterface = NULL; - - VBOX_UTF8_TO_UTF16(name, &nameUtf16); - - host->vtbl->FindHostNetworkInterfaceByName(host, nameUtf16, &networkInterface); - - if (networkInterface) { - PRUint32 interfaceType = 0; - - networkInterface->vtbl->GetInterfaceType(networkInterface, &interfaceType); - - if (interfaceType == HostNetworkInterfaceType_HostOnly) { - unsigned char uuid[VIR_UUID_BUFLEN]; - vboxIID iid = VBOX_IID_INITIALIZER; - - networkInterface->vtbl->GetId(networkInterface, &iid.value); - vboxIIDToUUID(&iid, uuid); - ret = virGetNetwork(conn, name, uuid); - VIR_DEBUG("Network Name: %s", name); - - DEBUGIID("Network UUID", iid.value); - vboxIIDUnalloc(&iid); - } - - VBOX_RELEASE(networkInterface); - } - - VBOX_UTF16_FREE(nameUtf16); - VBOX_RELEASE(host); - - return ret; -} - -static virNetworkPtr vboxNetworkDefineCreateXML(virConnectPtr conn, const char *xml, bool start) { VBOX_OBJECT_HOST_CHECK(conn, virNetworkPtr, NULL); @@ -5860,6 +5822,14 @@ _hostFindHostNetworkInterfaceById(IHost *host, vboxIIDUnion *iidu, } static nsresult +_hostFindHostNetworkInterfaceByName(IHost *host, PRUnichar *name, + IHostNetworkInterface **networkInterface) +{ + return host->vtbl->FindHostNetworkInterfaceByName(host, name, + networkInterface); +} + +static nsresult _hnInterfaceGetInterfaceType(IHostNetworkInterface *hni, PRUint32 *interfaceType) { return hni->vtbl->GetInterfaceType(hni, interfaceType); @@ -5877,6 +5847,12 @@ _hnInterfaceGetName(IHostNetworkInterface *hni, PRUnichar **name) return hni->vtbl->GetName(hni, name); } +static nsresult +_hnInterfaceGetId(IHostNetworkInterface *hni, vboxIIDUnion *iidu) +{ + return hni->vtbl->GetId(hni, &IID_MEMBER(value)); +} + static bool _machineStateOnline(PRUint32 state) { return ((state >= MachineState_FirstOnline) && @@ -6182,12 +6158,14 @@ static vboxUniformedIDisplay _UIDisplay = { static vboxUniformedIHost _UIHost = { .FindHostNetworkInterfaceById = _hostFindHostNetworkInterfaceById, + .FindHostNetworkInterfaceByName = _hostFindHostNetworkInterfaceByName, }; static vboxUniformedIHNInterface _UIHNInterface = { .GetInterfaceType = _hnInterfaceGetInterfaceType, .GetStatus = _hnInterfaceGetStatus, .GetName = _hnInterfaceGetName, + .GetId = _hnInterfaceGetId, }; static uniformedMachineStateChecker _machineStateChecker = { diff --git a/src/vbox/vbox_uniformed_api.h b/src/vbox/vbox_uniformed_api.h index 2e0eb10..a14ee1c 100644 --- a/src/vbox/vbox_uniformed_api.h +++ b/src/vbox/vbox_uniformed_api.h @@ -470,6 +470,8 @@ typedef struct { typedef struct { nsresult (*FindHostNetworkInterfaceById)(IHost *host, vboxIIDUnion *iidu, IHostNetworkInterface **networkInterface); + nsresult (*FindHostNetworkInterfaceByName)(IHost *host, PRUnichar *name, + IHostNetworkInterface **networkInterface); } vboxUniformedIHost; /* Functions for IHostNetworkInterface */ @@ -477,6 +479,7 @@ typedef struct { nsresult (*GetInterfaceType)(IHostNetworkInterface *hni, PRUint32 *interfaceType); nsresult (*GetStatus)(IHostNetworkInterface *hni, PRUint32 *status); nsresult (*GetName)(IHostNetworkInterface *hni, PRUnichar **name); + nsresult (*GetId)(IHostNetworkInterface *hni, vboxIIDUnion *iidu); } vboxUniformedIHNInterface; typedef struct { @@ -560,6 +563,7 @@ int vboxConnectListNetworks(virConnectPtr conn, char **const names, int nnames); int vboxConnectNumOfDefinedNetworks(virConnectPtr conn); int vboxConnectListDefinedNetworks(virConnectPtr conn, char **const names, int nnames); virNetworkPtr vboxNetworkLookupByUUID(virConnectPtr conn, const unsigned char *uuid); +virNetworkPtr vboxNetworkLookupByName(virConnectPtr conn, const char *name); /* Version specified functions for installing uniformed API */ void vbox22InstallUniformedAPI(vboxUniformedAPI *pVBoxAPI); -- 1.7.9.5

This patch actually contains two public API, virNetworkDefineXML and virNetworkCreateXML. They use the same core function vboxNetworkDefineCreateXML. So I merged it together. --- src/vbox/vbox_common.c | 203 ++++++++++++++++++++++++ src/vbox/vbox_common.h | 1 + src/vbox/vbox_tmpl.c | 350 ++++++++++++++--------------------------- src/vbox/vbox_uniformed_api.h | 22 +++ 4 files changed, 340 insertions(+), 236 deletions(-) diff --git a/src/vbox/vbox_common.c b/src/vbox/vbox_common.c index 2a949c5..8821cbc 100644 --- a/src/vbox/vbox_common.c +++ b/src/vbox/vbox_common.c @@ -35,6 +35,7 @@ #include "vbox_snapshot_conf.h" #include "fdstream.h" #include "configmake.h" +#include "network_conf.h" #include "vbox_common.h" #include "vbox_uniformed_api.h" @@ -7742,6 +7743,208 @@ virNetworkPtr vboxNetworkLookupByName(virConnectPtr conn, const char *name) return ret; } +static PRUnichar * +vboxSocketFormatAddrUtf16(vboxGlobalData *data, virSocketAddrPtr addr) +{ + char *utf8 = NULL; + PRUnichar *utf16 = NULL; + + utf8 = virSocketAddrFormat(addr); + + if (utf8 == NULL) { + return NULL; + } + + VBOX_UTF8_TO_UTF16(utf8, &utf16); + VIR_FREE(utf8); + + return utf16; +} + +static virNetworkPtr +vboxNetworkDefineCreateXML(virConnectPtr conn, const char *xml, bool start) +{ + VBOX_OBJECT_HOST_CHECK(conn, virNetworkPtr, NULL); + PRUnichar *networkInterfaceNameUtf16 = NULL; + char *networkInterfaceNameUtf8 = NULL; + IHostNetworkInterface *networkInterface = NULL; + virNetworkDefPtr def = virNetworkDefParseString(xml); + virNetworkIpDefPtr ipdef = NULL; + unsigned char uuid[VIR_UUID_BUFLEN]; + char *networkNameUtf8 = NULL; + PRUnichar *networkNameUtf16 = NULL; + nsresult rc; + vboxIIDUnion vboxnetiid; + virSocketAddr netmask; + + VBOX_IID_INITIALIZE(&vboxnetiid); + + if ((!def) || + (def->forward.type != VIR_NETWORK_FORWARD_NONE) || + (def->nips == 0 || !def->ips)) + goto cleanup; + + /* Look for the first IPv4 IP address definition and use that. + * If there weren't any IPv4 addresses, ignore the network (since it's + * required below to have an IPv4 address) + */ + ipdef = virNetworkDefGetIpByIndex(def, AF_INET, 0); + if (!ipdef) + goto cleanup; + + if (virNetworkIpDefNetmask(ipdef, &netmask) < 0) + goto cleanup; + + /* the current limitation of hostonly network is that you can't + * assign a name to it and it defaults to vboxnet*, for e.g: + * vboxnet0, vboxnet1, etc. Also the UUID is assigned to it + * automatically depending on the mac address and thus both + * these paramters are ignored here for now. + * + * If the vbox is in 2.x and the def->name not equal to vboxnet0, + * the function call will fail and the networkInterface set to + * NULL. (We can't assign a new name to hostonly network, only + * take the given name, say vboxnet0) + */ + gVBoxAPI.UIHost.CreateHostOnlyNetworkInterface(data, host, def->name, + &networkInterface); + + if (!networkInterface) + goto cleanup; + + gVBoxAPI.UIHNInterface.GetName(networkInterface, &networkInterfaceNameUtf16); + if (networkInterfaceNameUtf16) { + VBOX_UTF16_TO_UTF8(networkInterfaceNameUtf16, &networkInterfaceNameUtf8); + + if (virAsprintf(&networkNameUtf8, "HostInterfaceNetworking-%s", networkInterfaceNameUtf8) < 0) + goto cleanup; + } + + VBOX_UTF8_TO_UTF16(networkNameUtf8, &networkNameUtf16); + + /* Currently support only one dhcp server per network + * with contigious address space from start to end + */ + if ((ipdef->nranges >= 1) && + VIR_SOCKET_ADDR_VALID(&ipdef->ranges[0].start) && + VIR_SOCKET_ADDR_VALID(&ipdef->ranges[0].end)) { + IDHCPServer *dhcpServer = NULL; + + gVBoxAPI.UIVirtualBox.FindDHCPServerByNetworkName(data->vboxObj, + networkNameUtf16, + &dhcpServer); + if (!dhcpServer) { + /* create a dhcp server */ + gVBoxAPI.UIVirtualBox.CreateDHCPServer(data->vboxObj, + networkNameUtf16, + &dhcpServer); + VIR_DEBUG("couldn't find dhcp server so creating one"); + } + if (dhcpServer) { + PRUnichar *ipAddressUtf16 = NULL; + PRUnichar *networkMaskUtf16 = NULL; + PRUnichar *fromIPAddressUtf16 = NULL; + PRUnichar *toIPAddressUtf16 = NULL; + PRUnichar *trunkTypeUtf16 = NULL; + + ipAddressUtf16 = vboxSocketFormatAddrUtf16(data, &ipdef->address); + networkMaskUtf16 = vboxSocketFormatAddrUtf16(data, &netmask); + fromIPAddressUtf16 = vboxSocketFormatAddrUtf16(data, &ipdef->ranges[0].start); + toIPAddressUtf16 = vboxSocketFormatAddrUtf16(data, &ipdef->ranges[0].end); + + if (ipAddressUtf16 == NULL || networkMaskUtf16 == NULL || + fromIPAddressUtf16 == NULL || toIPAddressUtf16 == NULL) { + VBOX_UTF16_FREE(ipAddressUtf16); + VBOX_UTF16_FREE(networkMaskUtf16); + VBOX_UTF16_FREE(fromIPAddressUtf16); + VBOX_UTF16_FREE(toIPAddressUtf16); + VBOX_RELEASE(dhcpServer); + goto cleanup; + } + + VBOX_UTF8_TO_UTF16("netflt", &trunkTypeUtf16); + + gVBoxAPI.UIDHCPServer.SetEnabled(dhcpServer, PR_TRUE); + + gVBoxAPI.UIDHCPServer.SetConfiguration(dhcpServer, + ipAddressUtf16, + networkMaskUtf16, + fromIPAddressUtf16, + toIPAddressUtf16); + + if (start) + gVBoxAPI.UIDHCPServer.Start(dhcpServer, + networkNameUtf16, + networkInterfaceNameUtf16, + trunkTypeUtf16); + + VBOX_UTF16_FREE(ipAddressUtf16); + VBOX_UTF16_FREE(networkMaskUtf16); + VBOX_UTF16_FREE(fromIPAddressUtf16); + VBOX_UTF16_FREE(toIPAddressUtf16); + VBOX_UTF16_FREE(trunkTypeUtf16); + VBOX_RELEASE(dhcpServer); + } + } + + if ((ipdef->nhosts >= 1) && + VIR_SOCKET_ADDR_VALID(&ipdef->hosts[0].ip)) { + PRUnichar *ipAddressUtf16 = NULL; + PRUnichar *networkMaskUtf16 = NULL; + + ipAddressUtf16 = vboxSocketFormatAddrUtf16(data, &ipdef->hosts[0].ip); + networkMaskUtf16 = vboxSocketFormatAddrUtf16(data, &netmask); + + if (ipAddressUtf16 == NULL || networkMaskUtf16 == NULL) { + VBOX_UTF16_FREE(ipAddressUtf16); + VBOX_UTF16_FREE(networkMaskUtf16); + goto cleanup; + } + + /* Current drawback is that since EnableStaticIpConfig() sets + * IP and enables the interface so even if the dhcpserver is not + * started the interface is still up and running + */ + gVBoxAPI.UIHNInterface.EnableStaticIPConfig(networkInterface, + ipAddressUtf16, + networkMaskUtf16); + + VBOX_UTF16_FREE(ipAddressUtf16); + VBOX_UTF16_FREE(networkMaskUtf16); + } else { + gVBoxAPI.UIHNInterface.EnableDynamicIPConfig(networkInterface); + gVBoxAPI.UIHNInterface.DHCPRediscover(networkInterface); + } + + rc = gVBoxAPI.UIHNInterface.GetId(networkInterface, &vboxnetiid); + if (NS_SUCCEEDED(rc)) { + vboxIIDToUUID(&vboxnetiid, uuid); + DEBUGIID("Real Network UUID", &vboxnetiid); + vboxIIDUnalloc(&vboxnetiid); + ret = virGetNetwork(conn, networkInterfaceNameUtf8, uuid); + } + + cleanup: + VIR_FREE(networkNameUtf8); + VBOX_UTF16_FREE(networkNameUtf16); + VBOX_RELEASE(networkInterface); + VBOX_UTF8_FREE(networkInterfaceNameUtf8); + VBOX_UTF16_FREE(networkInterfaceNameUtf16); + VBOX_RELEASE(host); + virNetworkDefFree(def); + return ret; +} + +virNetworkPtr vboxNetworkCreateXML(virConnectPtr conn, const char *xml) +{ + return vboxNetworkDefineCreateXML(conn, xml, true); +} + +virNetworkPtr vboxNetworkDefineXML(virConnectPtr conn, const char *xml) +{ + return vboxNetworkDefineCreateXML(conn, xml, false); +} + /** * Function Tables */ diff --git a/src/vbox/vbox_common.h b/src/vbox/vbox_common.h index 9f5385b..76288d4 100644 --- a/src/vbox/vbox_common.h +++ b/src/vbox/vbox_common.h @@ -317,5 +317,6 @@ typedef nsISupports ISnapshot; typedef nsISupports IDisplay; typedef nsISupports IHost; typedef nsISupports IHostNetworkInterface; +typedef nsISupports IDHCPServer; #endif /* VBOX_COMMON_H */ diff --git a/src/vbox/vbox_tmpl.c b/src/vbox/vbox_tmpl.c index 5f81367..12acda5 100644 --- a/src/vbox/vbox_tmpl.c +++ b/src/vbox/vbox_tmpl.c @@ -838,24 +838,6 @@ static PRUnichar *PRUnicharFromInt(int n) { #endif /* VBOX_API_VERSION >= 3001000 */ -static PRUnichar * -vboxSocketFormatAddrUtf16(vboxGlobalData *data, virSocketAddrPtr addr) -{ - char *utf8 = NULL; - PRUnichar *utf16 = NULL; - - utf8 = virSocketAddrFormat(addr); - - if (utf8 == NULL) { - return NULL; - } - - VBOX_UTF8_TO_UTF16(utf8, &utf16); - VIR_FREE(utf8); - - return utf16; -} - static int vboxSocketParseAddrUtf16(vboxGlobalData *data, const PRUnichar *utf16, virSocketAddrPtr addr) @@ -2060,224 +2042,6 @@ _registerDomainEvent(virDriverPtr driver) * The Network Functions here on */ -static virNetworkPtr -vboxNetworkDefineCreateXML(virConnectPtr conn, const char *xml, bool start) -{ - VBOX_OBJECT_HOST_CHECK(conn, virNetworkPtr, NULL); - PRUnichar *networkInterfaceNameUtf16 = NULL; - char *networkInterfaceNameUtf8 = NULL; - IHostNetworkInterface *networkInterface = NULL; - nsresult rc; - - virNetworkDefPtr def = virNetworkDefParseString(xml); - virNetworkIpDefPtr ipdef; - virSocketAddr netmask; - - if ((!def) || - (def->forward.type != VIR_NETWORK_FORWARD_NONE) || - (def->nips == 0 || !def->ips)) - goto cleanup; - - /* Look for the first IPv4 IP address definition and use that. - * If there weren't any IPv4 addresses, ignore the network (since it's - * required below to have an IPv4 address) - */ - ipdef = virNetworkDefGetIpByIndex(def, AF_INET, 0); - if (!ipdef) - goto cleanup; - - if (virNetworkIpDefNetmask(ipdef, &netmask) < 0) - goto cleanup; - - /* the current limitation of hostonly network is that you can't - * assign a name to it and it defaults to vboxnet*, for e.g: - * vboxnet0, vboxnet1, etc. Also the UUID is assigned to it - * automatically depending on the mac address and thus both - * these paramters are ignored here for now. - */ - -#if VBOX_API_VERSION == 2002000 - if (STREQ(def->name, "vboxnet0")) { - PRUint32 interfaceType = 0; - - VBOX_UTF8_TO_UTF16(def->name, &networkInterfaceNameUtf16); - host->vtbl->FindHostNetworkInterfaceByName(host, networkInterfaceNameUtf16, &networkInterface); - - networkInterface->vtbl->GetInterfaceType(networkInterface, &interfaceType); - if (interfaceType != HostNetworkInterfaceType_HostOnly) { - VBOX_RELEASE(networkInterface); - networkInterface = NULL; - } - } -#else /* VBOX_API_VERSION != 2002000 */ - { - IProgress *progress = NULL; - host->vtbl->CreateHostOnlyNetworkInterface(host, &networkInterface, - &progress); - - if (progress) { - progress->vtbl->WaitForCompletion(progress, -1); - VBOX_RELEASE(progress); - } - } -#endif /* VBOX_API_VERSION != 2002000 */ - - if (networkInterface) { - unsigned char uuid[VIR_UUID_BUFLEN]; - char *networkNameUtf8 = NULL; - PRUnichar *networkNameUtf16 = NULL; - vboxIID vboxnetiid = VBOX_IID_INITIALIZER; - - networkInterface->vtbl->GetName(networkInterface, &networkInterfaceNameUtf16); - if (networkInterfaceNameUtf16) { - VBOX_UTF16_TO_UTF8(networkInterfaceNameUtf16, &networkInterfaceNameUtf8); - - if (virAsprintf(&networkNameUtf8, "HostInterfaceNetworking-%s", networkInterfaceNameUtf8) < 0) { - VBOX_RELEASE(host); - VBOX_RELEASE(networkInterface); - goto cleanup; - } - } - - VBOX_UTF8_TO_UTF16(networkNameUtf8, &networkNameUtf16); - - /* Currently support only one dhcp server per network - * with contigious address space from start to end - */ - if ((ipdef->nranges >= 1) && - VIR_SOCKET_ADDR_VALID(&ipdef->ranges[0].start) && - VIR_SOCKET_ADDR_VALID(&ipdef->ranges[0].end)) { - IDHCPServer *dhcpServer = NULL; - - data->vboxObj->vtbl->FindDHCPServerByNetworkName(data->vboxObj, - networkNameUtf16, - &dhcpServer); - if (!dhcpServer) { - /* create a dhcp server */ - data->vboxObj->vtbl->CreateDHCPServer(data->vboxObj, - networkNameUtf16, - &dhcpServer); - VIR_DEBUG("couldn't find dhcp server so creating one"); - } - if (dhcpServer) { - PRUnichar *ipAddressUtf16 = NULL; - PRUnichar *networkMaskUtf16 = NULL; - PRUnichar *fromIPAddressUtf16 = NULL; - PRUnichar *toIPAddressUtf16 = NULL; - PRUnichar *trunkTypeUtf16 = NULL; - - ipAddressUtf16 = vboxSocketFormatAddrUtf16(data, &ipdef->address); - networkMaskUtf16 = vboxSocketFormatAddrUtf16(data, &netmask); - fromIPAddressUtf16 = vboxSocketFormatAddrUtf16(data, &ipdef->ranges[0].start); - toIPAddressUtf16 = vboxSocketFormatAddrUtf16(data, &ipdef->ranges[0].end); - - if (ipAddressUtf16 == NULL || networkMaskUtf16 == NULL || - fromIPAddressUtf16 == NULL || toIPAddressUtf16 == NULL) { - VBOX_UTF16_FREE(ipAddressUtf16); - VBOX_UTF16_FREE(networkMaskUtf16); - VBOX_UTF16_FREE(fromIPAddressUtf16); - VBOX_UTF16_FREE(toIPAddressUtf16); - VBOX_RELEASE(dhcpServer); - goto cleanup; - } - - VBOX_UTF8_TO_UTF16("netflt", &trunkTypeUtf16); - - dhcpServer->vtbl->SetEnabled(dhcpServer, PR_TRUE); - - dhcpServer->vtbl->SetConfiguration(dhcpServer, - ipAddressUtf16, - networkMaskUtf16, - fromIPAddressUtf16, - toIPAddressUtf16); - - if (start) - dhcpServer->vtbl->Start(dhcpServer, - networkNameUtf16, - networkInterfaceNameUtf16, - trunkTypeUtf16); - - VBOX_UTF16_FREE(ipAddressUtf16); - VBOX_UTF16_FREE(networkMaskUtf16); - VBOX_UTF16_FREE(fromIPAddressUtf16); - VBOX_UTF16_FREE(toIPAddressUtf16); - VBOX_UTF16_FREE(trunkTypeUtf16); - VBOX_RELEASE(dhcpServer); - } - } - - if ((ipdef->nhosts >= 1) && - VIR_SOCKET_ADDR_VALID(&ipdef->hosts[0].ip)) { - PRUnichar *ipAddressUtf16 = NULL; - PRUnichar *networkMaskUtf16 = NULL; - - ipAddressUtf16 = vboxSocketFormatAddrUtf16(data, &ipdef->hosts[0].ip); - networkMaskUtf16 = vboxSocketFormatAddrUtf16(data, &netmask); - - if (ipAddressUtf16 == NULL || networkMaskUtf16 == NULL) { - VBOX_UTF16_FREE(ipAddressUtf16); - VBOX_UTF16_FREE(networkMaskUtf16); - goto cleanup; - } - - /* Current drawback is that since EnableStaticIpConfig() sets - * IP and enables the interface so even if the dhcpserver is not - * started the interface is still up and running - */ -#if VBOX_API_VERSION < 4002000 - networkInterface->vtbl->EnableStaticIpConfig(networkInterface, - ipAddressUtf16, - networkMaskUtf16); -#else - networkInterface->vtbl->EnableStaticIPConfig(networkInterface, - ipAddressUtf16, - networkMaskUtf16); -#endif - - VBOX_UTF16_FREE(ipAddressUtf16); - VBOX_UTF16_FREE(networkMaskUtf16); - } else { -#if VBOX_API_VERSION < 4002000 - networkInterface->vtbl->EnableDynamicIpConfig(networkInterface); - networkInterface->vtbl->DhcpRediscover(networkInterface); -#else - networkInterface->vtbl->EnableDynamicIPConfig(networkInterface); - networkInterface->vtbl->DHCPRediscover(networkInterface); -#endif - } - - rc = networkInterface->vtbl->GetId(networkInterface, &vboxnetiid.value); - if (NS_SUCCEEDED(rc)) { - vboxIIDToUUID(&vboxnetiid, uuid); - DEBUGIID("Real Network UUID", vboxnetiid.value); - vboxIIDUnalloc(&vboxnetiid); - ret = virGetNetwork(conn, networkInterfaceNameUtf8, uuid); - } - - VIR_FREE(networkNameUtf8); - VBOX_UTF16_FREE(networkNameUtf16); - VBOX_RELEASE(networkInterface); - } - - VBOX_UTF8_FREE(networkInterfaceNameUtf8); - VBOX_UTF16_FREE(networkInterfaceNameUtf16); - VBOX_RELEASE(host); - - cleanup: - virNetworkDefFree(def); - return ret; -} - -static virNetworkPtr vboxNetworkCreateXML(virConnectPtr conn, const char *xml) -{ - return vboxNetworkDefineCreateXML(conn, xml, true); -} - -static virNetworkPtr vboxNetworkDefineXML(virConnectPtr conn, const char *xml) -{ - return vboxNetworkDefineCreateXML(conn, xml, false); -} - static int vboxNetworkUndefineDestroy(virNetworkPtr network, bool removeinterface) { @@ -4445,6 +4209,18 @@ _virtualboxOpenMedium(IVirtualBox *vboxObj ATTRIBUTE_UNUSED, } static nsresult +_virtualboxFindDHCPServerByNetworkName(IVirtualBox *vboxObj, PRUnichar *name, IDHCPServer **server) +{ + return vboxObj->vtbl->FindDHCPServerByNetworkName(vboxObj, name, server); +} + +static nsresult +_virtualboxCreateDHCPServer(IVirtualBox *vboxObj, PRUnichar *name, IDHCPServer **server) +{ + return vboxObj->vtbl->CreateDHCPServer(vboxObj, name, server); +} + +static nsresult _machineAddStorageController(IMachine *machine, PRUnichar *name, PRUint32 connectionType, IStorageController **controller) @@ -5830,6 +5606,40 @@ _hostFindHostNetworkInterfaceByName(IHost *host, PRUnichar *name, } static nsresult +_hostCreateHostOnlyNetworkInterface(vboxGlobalData *data ATTRIBUTE_UNUSED, + IHost *host, char *name ATTRIBUTE_UNUSED, + IHostNetworkInterface **networkInterface) +{ + nsresult rc = -1; +#if VBOX_API_VERSION == 2002000 + if (STREQ(name, "vboxnet0")) { + PRUint32 interfaceType = 0; + PRUnichar *networkInterfaceNameUtf16 = NULL; + + VBOX_UTF8_TO_UTF16(name, &networkInterfaceNameUtf16); + host->vtbl->FindHostNetworkInterfaceByName(host, networkInterfaceNameUtf16, networkInterface); + + (*networkInterface)->vtbl->GetInterfaceType(*networkInterface, &interfaceType); + if (interfaceType != HostNetworkInterfaceType_HostOnly) { + VBOX_RELEASE(*networkInterface); + *networkInterface = NULL; + } else + rc = 0; + } +#else /* VBOX_API_VERSION != 2002000 */ + IProgress *progress = NULL; + host->vtbl->CreateHostOnlyNetworkInterface(host, networkInterface, + &progress); + + if (progress) { + rc = progress->vtbl->WaitForCompletion(progress, -1); + VBOX_RELEASE(progress); + } +#endif /* VBOX_API_VERSION != 2002000 */ + return rc; +} + +static nsresult _hnInterfaceGetInterfaceType(IHostNetworkInterface *hni, PRUint32 *interfaceType) { return hni->vtbl->GetInterfaceType(hni, interfaceType); @@ -5853,6 +5663,61 @@ _hnInterfaceGetId(IHostNetworkInterface *hni, vboxIIDUnion *iidu) return hni->vtbl->GetId(hni, &IID_MEMBER(value)); } +static nsresult +_hnInterfaceEnableStaticIPConfig(IHostNetworkInterface *hni, PRUnichar *IPAddress, + PRUnichar *networkMask) +{ +#if VBOX_API_VERSION < 4002000 + return hni->vtbl->EnableStaticIpConfig(hni, IPAddress, networkMask); +#else + return hni->vtbl->EnableStaticIPConfig(hni, IPAddress, networkMask); +#endif +} + +static nsresult +_hnInterfaceEnableDynamicIPConfig(IHostNetworkInterface *hni) +{ +#if VBOX_API_VERSION < 4002000 + return hni->vtbl->EnableDynamicIpConfig(hni); +#else + return hni->vtbl->EnableDynamicIPConfig(hni); +#endif +} + +static nsresult +_hnInterfaceDHCPRediscover(IHostNetworkInterface *hni) +{ +#if VBOX_API_VERSION < 4002000 + return hni->vtbl->DhcpRediscover(hni); +#else + return hni->vtbl->DHCPRediscover(hni); +#endif +} + +static nsresult +_dhcpServerSetEnabled(IDHCPServer *dhcpServer, PRBool enabled) +{ + return dhcpServer->vtbl->SetEnabled(dhcpServer, enabled); +} + +static nsresult +_dhcpServerSetConfiguration(IDHCPServer *dhcpServer, PRUnichar *IPAddress, + PRUnichar *networkMask, PRUnichar *FromIPAddress, + PRUnichar *ToIPAddress) +{ + return dhcpServer->vtbl->SetConfiguration(dhcpServer, IPAddress, + networkMask, FromIPAddress, + ToIPAddress); +} + +static nsresult +_dhcpServerStart(IDHCPServer *dhcpServer, PRUnichar *networkName, + PRUnichar *trunkName, PRUnichar *trunkType) +{ + return dhcpServer->vtbl->Start(dhcpServer, networkName, + trunkName, trunkType); +} + static bool _machineStateOnline(PRUint32 state) { return ((state >= MachineState_FirstOnline) && @@ -5938,6 +5803,8 @@ static vboxUniformedIVirtualBox _UIVirtualBox = { .RegisterMachine = _virtualboxRegisterMachine, .FindMedium = _virtualboxFindMedium, .OpenMedium = _virtualboxOpenMedium, + .FindDHCPServerByNetworkName = _virtualboxFindDHCPServerByNetworkName, + .CreateDHCPServer = _virtualboxCreateDHCPServer, }; static vboxUniformedIMachine _UIMachine = { @@ -6159,6 +6026,7 @@ static vboxUniformedIDisplay _UIDisplay = { static vboxUniformedIHost _UIHost = { .FindHostNetworkInterfaceById = _hostFindHostNetworkInterfaceById, .FindHostNetworkInterfaceByName = _hostFindHostNetworkInterfaceByName, + .CreateHostOnlyNetworkInterface = _hostCreateHostOnlyNetworkInterface, }; static vboxUniformedIHNInterface _UIHNInterface = { @@ -6166,6 +6034,15 @@ static vboxUniformedIHNInterface _UIHNInterface = { .GetStatus = _hnInterfaceGetStatus, .GetName = _hnInterfaceGetName, .GetId = _hnInterfaceGetId, + .EnableStaticIPConfig = _hnInterfaceEnableStaticIPConfig, + .EnableDynamicIPConfig = _hnInterfaceEnableDynamicIPConfig, + .DHCPRediscover = _hnInterfaceDHCPRediscover, +}; + +static vboxUniformedIDHCPServer _UIDHCPServer = { + .SetEnabled = _dhcpServerSetEnabled, + .SetConfiguration = _dhcpServerSetConfiguration, + .Start = _dhcpServerStart, }; static uniformedMachineStateChecker _machineStateChecker = { @@ -6223,6 +6100,7 @@ void NAME(InstallUniformedAPI)(vboxUniformedAPI *pVBoxAPI) pVBoxAPI->UIDisplay = _UIDisplay; pVBoxAPI->UIHost = _UIHost; pVBoxAPI->UIHNInterface = _UIHNInterface; + pVBoxAPI->UIDHCPServer = _UIDHCPServer; pVBoxAPI->machineStateChecker = _machineStateChecker; #if VBOX_API_VERSION <= 2002000 || VBOX_API_VERSION >= 4000000 diff --git a/src/vbox/vbox_uniformed_api.h b/src/vbox/vbox_uniformed_api.h index a14ee1c..83c3834 100644 --- a/src/vbox/vbox_uniformed_api.h +++ b/src/vbox/vbox_uniformed_api.h @@ -197,6 +197,8 @@ typedef struct { nsresult (*RegisterMachine)(IVirtualBox *vboxObj, IMachine *machine); nsresult (*FindMedium)(IVirtualBox *vboxObj, PRUnichar *location, PRUint32 deviceType, PRUint32 accessMode, IMedium **medium); nsresult (*OpenMedium)(IVirtualBox *vboxObj, PRUnichar *location, PRUint32 deviceType, PRUint32 accessMode, IMedium **medium); + nsresult (*FindDHCPServerByNetworkName)(IVirtualBox *vboxObj, PRUnichar *name, IDHCPServer **server); + nsresult (*CreateDHCPServer)(IVirtualBox *vboxObj, PRUnichar *name, IDHCPServer **server); } vboxUniformedIVirtualBox; /* Functions for IMachine */ @@ -472,6 +474,9 @@ typedef struct { IHostNetworkInterface **networkInterface); nsresult (*FindHostNetworkInterfaceByName)(IHost *host, PRUnichar *name, IHostNetworkInterface **networkInterface); + nsresult (*CreateHostOnlyNetworkInterface)(vboxGlobalData *data, + IHost *host, char *name, + IHostNetworkInterface **networkInterface); } vboxUniformedIHost; /* Functions for IHostNetworkInterface */ @@ -480,8 +485,22 @@ typedef struct { nsresult (*GetStatus)(IHostNetworkInterface *hni, PRUint32 *status); nsresult (*GetName)(IHostNetworkInterface *hni, PRUnichar **name); nsresult (*GetId)(IHostNetworkInterface *hni, vboxIIDUnion *iidu); + nsresult (*EnableStaticIPConfig)(IHostNetworkInterface *hni, PRUnichar *IPAddress, + PRUnichar *networkMask); + nsresult (*EnableDynamicIPConfig)(IHostNetworkInterface *hni); + nsresult (*DHCPRediscover)(IHostNetworkInterface *hni); } vboxUniformedIHNInterface; +/* Functions for IDHCPServer */ +typedef struct { + nsresult (*SetEnabled)(IDHCPServer *dhcpServer, PRBool enabled); + nsresult (*SetConfiguration)(IDHCPServer *dhcpServer, PRUnichar *IPAddress, + PRUnichar *networkMask, PRUnichar *FromIPAddress, + PRUnichar *ToIPAddress); + nsresult (*Start)(IDHCPServer *dhcpServer, PRUnichar *networkName, + PRUnichar *trunkName, PRUnichar *trunkType); +} vboxUniformedIDHCPServer; + typedef struct { bool (*Online)(PRUint32 state); bool (*Inactive)(PRUint32 state); @@ -538,6 +557,7 @@ typedef struct { vboxUniformedIDisplay UIDisplay; vboxUniformedIHost UIHost; vboxUniformedIHNInterface UIHNInterface; + vboxUniformedIDHCPServer UIDHCPServer; uniformedMachineStateChecker machineStateChecker; /* vbox API features */ bool domainEventCallbacks; @@ -564,6 +584,8 @@ int vboxConnectNumOfDefinedNetworks(virConnectPtr conn); int vboxConnectListDefinedNetworks(virConnectPtr conn, char **const names, int nnames); virNetworkPtr vboxNetworkLookupByUUID(virConnectPtr conn, const unsigned char *uuid); virNetworkPtr vboxNetworkLookupByName(virConnectPtr conn, const char *name); +virNetworkPtr vboxNetworkCreateXML(virConnectPtr conn, const char *xml); +virNetworkPtr vboxNetworkDefineXML(virConnectPtr conn, const char *xml); /* Version specified functions for installing uniformed API */ void vbox22InstallUniformedAPI(vboxUniformedAPI *pVBoxAPI); -- 1.7.9.5

This patch rewrites two public APIs. They are vboxNetworkUndefine and vboxNetworkDestroy. They use the same core function vboxNetworkUndefineDestroy. I merged it in one patch. --- src/vbox/vbox_common.c | 96 +++++++++++++++++++++++++++++ src/vbox/vbox_tmpl.c | 136 ++++++++++++----------------------------- src/vbox/vbox_uniformed_api.h | 7 +++ 3 files changed, 143 insertions(+), 96 deletions(-) diff --git a/src/vbox/vbox_common.c b/src/vbox/vbox_common.c index 8821cbc..8e204e7 100644 --- a/src/vbox/vbox_common.c +++ b/src/vbox/vbox_common.c @@ -7945,6 +7945,102 @@ virNetworkPtr vboxNetworkDefineXML(virConnectPtr conn, const char *xml) return vboxNetworkDefineCreateXML(conn, xml, false); } +static int +vboxNetworkUndefineDestroy(virNetworkPtr network, bool removeinterface) +{ + VBOX_OBJECT_HOST_CHECK(network->conn, int, -1); + char *networkNameUtf8 = NULL; + PRUnichar *networkInterfaceNameUtf16 = NULL; + IHostNetworkInterface *networkInterface = NULL; + PRUnichar *networkNameUtf16 = NULL; + IDHCPServer *dhcpServer = NULL; + PRUint32 interfaceType = 0; + + /* Current limitation of the function for VirtualBox 2.2.* is + * that you can't delete the default hostonly adaptor namely: + * vboxnet0 and thus all this functions does is remove the + * dhcp server configuration, but the network can still be used + * by giving the machine static IP and also it will still + * show up in the net-list in virsh + */ + + if (virAsprintf(&networkNameUtf8, "HostInterfaceNetworking-%s", network->name) < 0) + goto cleanup; + + VBOX_UTF8_TO_UTF16(network->name, &networkInterfaceNameUtf16); + + gVBoxAPI.UIHost.FindHostNetworkInterfaceByName(host, networkInterfaceNameUtf16, &networkInterface); + + if (!networkInterface) + goto cleanup; + + gVBoxAPI.UIHNInterface.GetInterfaceType(networkInterface, &interfaceType); + + if (interfaceType != HostNetworkInterfaceType_HostOnly) + goto cleanup; + + if (gVBoxAPI.networkRemoveInterface && removeinterface) { + vboxIIDUnion iid; + IProgress *progress = NULL; + nsresult rc; + resultCodeUnion resultCode; + + rc = gVBoxAPI.UIHNInterface.GetId(networkInterface, &iid); + + if (NS_FAILED(rc)) + goto cleanup; + + gVBoxAPI.UIHost.RemoveHostOnlyNetworkInterface(host, &iid, &progress); + vboxIIDUnalloc(&iid); + + if (!progress) + goto cleanup; + + gVBoxAPI.UIProgress.WaitForCompletion(progress, -1); + gVBoxAPI.UIProgress.GetResultCode(progress, &resultCode); + if (RC_FAILED(resultCode)) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("Error while removing hostonly network interface, rc=%08x"), + resultCode.uResultCode); + goto cleanup; + } + VBOX_RELEASE(progress); + } + + VBOX_UTF8_TO_UTF16(networkNameUtf8, &networkNameUtf16); + + gVBoxAPI.UIVirtualBox.FindDHCPServerByNetworkName(data->vboxObj, + networkNameUtf16, + &dhcpServer); + if (!dhcpServer) + goto cleanup; + + gVBoxAPI.UIDHCPServer.SetEnabled(dhcpServer, PR_FALSE); + gVBoxAPI.UIDHCPServer.Stop(dhcpServer); + if (removeinterface) + gVBoxAPI.UIVirtualBox.RemoveDHCPServer(data->vboxObj, dhcpServer); + ret = 0; + VBOX_RELEASE(dhcpServer); + + cleanup: + VBOX_UTF16_FREE(networkNameUtf16); + VBOX_RELEASE(networkInterface); + VBOX_UTF16_FREE(networkInterfaceNameUtf16); + VBOX_RELEASE(host); + VIR_FREE(networkNameUtf8); + return ret; +} + +int vboxNetworkUndefine(virNetworkPtr network) +{ + return vboxNetworkUndefineDestroy(network, true); +} + +int vboxNetworkDestroy(virNetworkPtr network) +{ + return vboxNetworkUndefineDestroy(network, false); +} + /** * Function Tables */ diff --git a/src/vbox/vbox_tmpl.c b/src/vbox/vbox_tmpl.c index 12acda5..e21dce4 100644 --- a/src/vbox/vbox_tmpl.c +++ b/src/vbox/vbox_tmpl.c @@ -2042,97 +2042,6 @@ _registerDomainEvent(virDriverPtr driver) * The Network Functions here on */ -static int -vboxNetworkUndefineDestroy(virNetworkPtr network, bool removeinterface) -{ - VBOX_OBJECT_HOST_CHECK(network->conn, int, -1); - char *networkNameUtf8 = NULL; - PRUnichar *networkInterfaceNameUtf16 = NULL; - IHostNetworkInterface *networkInterface = NULL; - - /* Current limitation of the function for VirtualBox 2.2.* is - * that you can't delete the default hostonly adaptor namely: - * vboxnet0 and thus all this functions does is remove the - * dhcp server configuration, but the network can still be used - * by giving the machine static IP and also it will still - * show up in the net-list in virsh - */ - - if (virAsprintf(&networkNameUtf8, "HostInterfaceNetworking-%s", network->name) < 0) - goto cleanup; - - VBOX_UTF8_TO_UTF16(network->name, &networkInterfaceNameUtf16); - - host->vtbl->FindHostNetworkInterfaceByName(host, networkInterfaceNameUtf16, &networkInterface); - - if (networkInterface) { - PRUint32 interfaceType = 0; - - networkInterface->vtbl->GetInterfaceType(networkInterface, &interfaceType); - - if (interfaceType == HostNetworkInterfaceType_HostOnly) { - PRUnichar *networkNameUtf16 = NULL; - IDHCPServer *dhcpServer = NULL; - -#if VBOX_API_VERSION != 2002000 - if (removeinterface) { - PRUnichar *iidUtf16 = NULL; - IProgress *progress = NULL; - - networkInterface->vtbl->GetId(networkInterface, &iidUtf16); - - if (iidUtf16) { -# if VBOX_API_VERSION == 3000000 - IHostNetworkInterface *netInt = NULL; - host->vtbl->RemoveHostOnlyNetworkInterface(host, iidUtf16, &netInt, &progress); - VBOX_RELEASE(netInt); -# else /* VBOX_API_VERSION > 3000000 */ - host->vtbl->RemoveHostOnlyNetworkInterface(host, iidUtf16, &progress); -# endif /* VBOX_API_VERSION > 3000000 */ - VBOX_UTF16_FREE(iidUtf16); - } - - if (progress) { - progress->vtbl->WaitForCompletion(progress, -1); - VBOX_RELEASE(progress); - } - } -#endif /* VBOX_API_VERSION != 2002000 */ - - VBOX_UTF8_TO_UTF16(networkNameUtf8, &networkNameUtf16); - - data->vboxObj->vtbl->FindDHCPServerByNetworkName(data->vboxObj, - networkNameUtf16, - &dhcpServer); - if (dhcpServer) { - dhcpServer->vtbl->SetEnabled(dhcpServer, PR_FALSE); - dhcpServer->vtbl->Stop(dhcpServer); - if (removeinterface) - data->vboxObj->vtbl->RemoveDHCPServer(data->vboxObj, dhcpServer); - VBOX_RELEASE(dhcpServer); - } - - VBOX_UTF16_FREE(networkNameUtf16); - - } - VBOX_RELEASE(networkInterface); - } - - VBOX_UTF16_FREE(networkInterfaceNameUtf16); - VBOX_RELEASE(host); - - ret = 0; - - cleanup: - VIR_FREE(networkNameUtf8); - return ret; -} - -static int vboxNetworkUndefine(virNetworkPtr network) -{ - return vboxNetworkUndefineDestroy(network, true); -} - static int vboxNetworkCreate(virNetworkPtr network) { VBOX_OBJECT_HOST_CHECK(network->conn, int, -1); @@ -2201,11 +2110,6 @@ static int vboxNetworkCreate(virNetworkPtr network) return ret; } -static int vboxNetworkDestroy(virNetworkPtr network) -{ - return vboxNetworkUndefineDestroy(network, false); -} - static char *vboxNetworkGetXMLDesc(virNetworkPtr network, unsigned int flags) { @@ -4221,6 +4125,12 @@ _virtualboxCreateDHCPServer(IVirtualBox *vboxObj, PRUnichar *name, IDHCPServer * } static nsresult +_virtualboxRemoveDHCPServer(IVirtualBox *vboxObj, IDHCPServer *server) +{ + return vboxObj->vtbl->RemoveDHCPServer(vboxObj, server); +} + +static nsresult _machineAddStorageController(IMachine *machine, PRUnichar *name, PRUint32 connectionType, IStorageController **controller) @@ -5640,6 +5550,25 @@ _hostCreateHostOnlyNetworkInterface(vboxGlobalData *data ATTRIBUTE_UNUSED, } static nsresult +_hostRemoveHostOnlyNetworkInterface(IHost *host ATTRIBUTE_UNUSED, + vboxIIDUnion *iidu ATTRIBUTE_UNUSED, + IProgress **progress ATTRIBUTE_UNUSED) +{ +#if VBOX_API_VERSION == 2002000 + vboxUnsupported(); + return 0; +#elif VBOX_API_VERSION == 3000000 + nsresult rc; + IHostNetworkInterface *netInt = NULL; + rc = host->vtbl->RemoveHostOnlyNetworkInterface(host, IID_MEMBER(value), &netInt, progress); + VBOX_RELEASE(netInt); + return rc; +#else /* VBOX_API_VERSION > 3000000 */ + return host->vtbl->RemoveHostOnlyNetworkInterface(host, IID_MEMBER(value), progress); +#endif /* VBOX_API_VERSION > 3000000 */ +} + +static nsresult _hnInterfaceGetInterfaceType(IHostNetworkInterface *hni, PRUint32 *interfaceType) { return hni->vtbl->GetInterfaceType(hni, interfaceType); @@ -5718,6 +5647,12 @@ _dhcpServerStart(IDHCPServer *dhcpServer, PRUnichar *networkName, trunkName, trunkType); } +static nsresult +_dhcpServerStop(IDHCPServer *dhcpServer) +{ + return dhcpServer->vtbl->Stop(dhcpServer); +} + static bool _machineStateOnline(PRUint32 state) { return ((state >= MachineState_FirstOnline) && @@ -5805,6 +5740,7 @@ static vboxUniformedIVirtualBox _UIVirtualBox = { .OpenMedium = _virtualboxOpenMedium, .FindDHCPServerByNetworkName = _virtualboxFindDHCPServerByNetworkName, .CreateDHCPServer = _virtualboxCreateDHCPServer, + .RemoveDHCPServer = _virtualboxRemoveDHCPServer, }; static vboxUniformedIMachine _UIMachine = { @@ -6027,6 +5963,7 @@ static vboxUniformedIHost _UIHost = { .FindHostNetworkInterfaceById = _hostFindHostNetworkInterfaceById, .FindHostNetworkInterfaceByName = _hostFindHostNetworkInterfaceByName, .CreateHostOnlyNetworkInterface = _hostCreateHostOnlyNetworkInterface, + .RemoveHostOnlyNetworkInterface = _hostRemoveHostOnlyNetworkInterface, }; static vboxUniformedIHNInterface _UIHNInterface = { @@ -6043,6 +5980,7 @@ static vboxUniformedIDHCPServer _UIDHCPServer = { .SetEnabled = _dhcpServerSetEnabled, .SetConfiguration = _dhcpServerSetConfiguration, .Start = _dhcpServerStart, + .Stop = _dhcpServerStop, }; static uniformedMachineStateChecker _machineStateChecker = { @@ -6147,6 +6085,12 @@ void NAME(InstallUniformedAPI)(vboxUniformedAPI *pVBoxAPI) #else /* VBOX_API_VERSION < 4002000 */ pVBoxAPI->vboxSnapshotRedefine = 0; #endif /* VBOX_API_VERSION < 4002000 */ + +#if VBOX_API_VERSION == 2002000 + pVBoxAPI->networkRemoveInterface = 0; +#else /* VBOX_API_VERSION > 2002000 */ + pVBoxAPI->networkRemoveInterface = 1; +#endif /* VBOX_API_VERSION > 2002000 */ } /** diff --git a/src/vbox/vbox_uniformed_api.h b/src/vbox/vbox_uniformed_api.h index 83c3834..8f713af 100644 --- a/src/vbox/vbox_uniformed_api.h +++ b/src/vbox/vbox_uniformed_api.h @@ -199,6 +199,7 @@ typedef struct { nsresult (*OpenMedium)(IVirtualBox *vboxObj, PRUnichar *location, PRUint32 deviceType, PRUint32 accessMode, IMedium **medium); nsresult (*FindDHCPServerByNetworkName)(IVirtualBox *vboxObj, PRUnichar *name, IDHCPServer **server); nsresult (*CreateDHCPServer)(IVirtualBox *vboxObj, PRUnichar *name, IDHCPServer **server); + nsresult (*RemoveDHCPServer)(IVirtualBox *vboxObj, IDHCPServer *server); } vboxUniformedIVirtualBox; /* Functions for IMachine */ @@ -477,6 +478,8 @@ typedef struct { nsresult (*CreateHostOnlyNetworkInterface)(vboxGlobalData *data, IHost *host, char *name, IHostNetworkInterface **networkInterface); + nsresult (*RemoveHostOnlyNetworkInterface)(IHost *host, vboxIIDUnion *iidu, + IProgress **progress); } vboxUniformedIHost; /* Functions for IHostNetworkInterface */ @@ -499,6 +502,7 @@ typedef struct { PRUnichar *ToIPAddress); nsresult (*Start)(IDHCPServer *dhcpServer, PRUnichar *networkName, PRUnichar *trunkName, PRUnichar *trunkType); + nsresult (*Stop)(IDHCPServer *dhcpServer); } vboxUniformedIDHCPServer; typedef struct { @@ -570,6 +574,7 @@ typedef struct { bool oldMediumInterface; bool vboxSnapshotRedefine; bool supportScreenshot; + bool networkRemoveInterface; } vboxUniformedAPI; virDomainPtr vboxDomainLookupByUUID(virConnectPtr conn, @@ -586,6 +591,8 @@ virNetworkPtr vboxNetworkLookupByUUID(virConnectPtr conn, const unsigned char *u virNetworkPtr vboxNetworkLookupByName(virConnectPtr conn, const char *name); virNetworkPtr vboxNetworkCreateXML(virConnectPtr conn, const char *xml); virNetworkPtr vboxNetworkDefineXML(virConnectPtr conn, const char *xml); +int vboxNetworkUndefine(virNetworkPtr network); +int vboxNetworkDestroy(virNetworkPtr network); /* Version specified functions for installing uniformed API */ void vbox22InstallUniformedAPI(vboxUniformedAPI *pVBoxAPI); -- 1.7.9.5

--- src/vbox/vbox_common.c | 63 ++++++++++++++++++++++++++++++++++++++ src/vbox/vbox_tmpl.c | 68 ----------------------------------------- src/vbox/vbox_uniformed_api.h | 1 + 3 files changed, 64 insertions(+), 68 deletions(-) diff --git a/src/vbox/vbox_common.c b/src/vbox/vbox_common.c index 8e204e7..cf0d4e9 100644 --- a/src/vbox/vbox_common.c +++ b/src/vbox/vbox_common.c @@ -8041,6 +8041,69 @@ int vboxNetworkDestroy(virNetworkPtr network) return vboxNetworkUndefineDestroy(network, false); } +int vboxNetworkCreate(virNetworkPtr network) +{ + VBOX_OBJECT_HOST_CHECK(network->conn, int, -1); + char *networkNameUtf8 = NULL; + PRUnichar *networkInterfaceNameUtf16 = NULL; + IHostNetworkInterface *networkInterface = NULL; + PRUnichar *networkNameUtf16 = NULL; + IDHCPServer *dhcpServer = NULL; + PRUnichar *trunkTypeUtf16 = NULL; + PRUint32 interfaceType = 0; + + /* Current limitation of the function for VirtualBox 2.2.* is + * that the default hostonly network "vboxnet0" is always active + * and thus all this functions does is start the dhcp server, + * but the network can still be used without starting the dhcp + * server by giving the machine static IP + */ + + if (virAsprintf(&networkNameUtf8, "HostInterfaceNetworking-%s", network->name) < 0) + goto cleanup; + + VBOX_UTF8_TO_UTF16(network->name, &networkInterfaceNameUtf16); + + gVBoxAPI.UIHost.FindHostNetworkInterfaceByName(host, networkInterfaceNameUtf16, &networkInterface); + + if (!networkInterface) + goto cleanup; + + gVBoxAPI.UIHNInterface.GetInterfaceType(networkInterface, &interfaceType); + + if (interfaceType != HostNetworkInterfaceType_HostOnly) + goto cleanup; + + VBOX_UTF8_TO_UTF16(networkNameUtf8, &networkNameUtf16); + + gVBoxAPI.UIVirtualBox.FindDHCPServerByNetworkName(data->vboxObj, + networkNameUtf16, + &dhcpServer); + if (!dhcpServer) + goto cleanup; + + gVBoxAPI.UIDHCPServer.SetEnabled(dhcpServer, PR_TRUE); + + VBOX_UTF8_TO_UTF16("netflt", &trunkTypeUtf16); + + gVBoxAPI.UIDHCPServer.Start(dhcpServer, + networkNameUtf16, + networkInterfaceNameUtf16, + trunkTypeUtf16); + + VBOX_UTF16_FREE(trunkTypeUtf16); + ret = 0; + + cleanup: + VBOX_RELEASE(dhcpServer); + VBOX_UTF16_FREE(networkNameUtf16); + VBOX_RELEASE(networkInterface); + VBOX_UTF16_FREE(networkInterfaceNameUtf16); + VBOX_RELEASE(host); + VIR_FREE(networkNameUtf8); + return ret; +} + /** * Function Tables */ diff --git a/src/vbox/vbox_tmpl.c b/src/vbox/vbox_tmpl.c index e21dce4..517e3ba 100644 --- a/src/vbox/vbox_tmpl.c +++ b/src/vbox/vbox_tmpl.c @@ -2042,74 +2042,6 @@ _registerDomainEvent(virDriverPtr driver) * The Network Functions here on */ -static int vboxNetworkCreate(virNetworkPtr network) -{ - VBOX_OBJECT_HOST_CHECK(network->conn, int, -1); - char *networkNameUtf8 = NULL; - PRUnichar *networkInterfaceNameUtf16 = NULL; - IHostNetworkInterface *networkInterface = NULL; - - /* Current limitation of the function for VirtualBox 2.2.* is - * that the default hostonly network "vboxnet0" is always active - * and thus all this functions does is start the dhcp server, - * but the network can still be used without starting the dhcp - * server by giving the machine static IP - */ - - if (virAsprintf(&networkNameUtf8, "HostInterfaceNetworking-%s", network->name) < 0) - goto cleanup; - - VBOX_UTF8_TO_UTF16(network->name, &networkInterfaceNameUtf16); - - host->vtbl->FindHostNetworkInterfaceByName(host, networkInterfaceNameUtf16, &networkInterface); - - if (networkInterface) { - PRUint32 interfaceType = 0; - - networkInterface->vtbl->GetInterfaceType(networkInterface, &interfaceType); - - if (interfaceType == HostNetworkInterfaceType_HostOnly) { - PRUnichar *networkNameUtf16 = NULL; - IDHCPServer *dhcpServer = NULL; - - - VBOX_UTF8_TO_UTF16(networkNameUtf8, &networkNameUtf16); - - data->vboxObj->vtbl->FindDHCPServerByNetworkName(data->vboxObj, - networkNameUtf16, - &dhcpServer); - if (dhcpServer) { - PRUnichar *trunkTypeUtf16 = NULL; - - dhcpServer->vtbl->SetEnabled(dhcpServer, PR_TRUE); - - VBOX_UTF8_TO_UTF16("netflt", &trunkTypeUtf16); - - dhcpServer->vtbl->Start(dhcpServer, - networkNameUtf16, - networkInterfaceNameUtf16, - trunkTypeUtf16); - - VBOX_UTF16_FREE(trunkTypeUtf16); - VBOX_RELEASE(dhcpServer); - } - - VBOX_UTF16_FREE(networkNameUtf16); - } - - VBOX_RELEASE(networkInterface); - } - - VBOX_UTF16_FREE(networkInterfaceNameUtf16); - VBOX_RELEASE(host); - - ret = 0; - - cleanup: - VIR_FREE(networkNameUtf8); - return ret; -} - static char *vboxNetworkGetXMLDesc(virNetworkPtr network, unsigned int flags) { diff --git a/src/vbox/vbox_uniformed_api.h b/src/vbox/vbox_uniformed_api.h index 8f713af..f0b98c0 100644 --- a/src/vbox/vbox_uniformed_api.h +++ b/src/vbox/vbox_uniformed_api.h @@ -593,6 +593,7 @@ virNetworkPtr vboxNetworkCreateXML(virConnectPtr conn, const char *xml); virNetworkPtr vboxNetworkDefineXML(virConnectPtr conn, const char *xml); int vboxNetworkUndefine(virNetworkPtr network); int vboxNetworkDestroy(virNetworkPtr network); +int vboxNetworkCreate(virNetworkPtr network); /* Version specified functions for installing uniformed API */ void vbox22InstallUniformedAPI(vboxUniformedAPI *pVBoxAPI); -- 1.7.9.5

--- src/vbox/vbox_common.c | 180 +++++++++++++++++++++++++++++++ src/vbox/vbox_tmpl.c | 235 +++++++++-------------------------------- src/vbox/vbox_uniformed_api.h | 8 ++ 3 files changed, 237 insertions(+), 186 deletions(-) diff --git a/src/vbox/vbox_common.c b/src/vbox/vbox_common.c index cf0d4e9..6e6ce67 100644 --- a/src/vbox/vbox_common.c +++ b/src/vbox/vbox_common.c @@ -8104,6 +8104,186 @@ int vboxNetworkCreate(virNetworkPtr network) return ret; } +static int +vboxSocketParseAddrUtf16(vboxGlobalData *data, const PRUnichar *utf16, + virSocketAddrPtr addr) +{ + int result = -1; + char *utf8 = NULL; + + VBOX_UTF16_TO_UTF8(utf16, &utf8); + + if (virSocketAddrParse(addr, utf8, AF_UNSPEC) < 0) { + goto cleanup; + } + + result = 0; + + cleanup: + VBOX_UTF8_FREE(utf8); + + return result; +} + +char *vboxNetworkGetXMLDesc(virNetworkPtr network, unsigned int flags) +{ + VBOX_OBJECT_HOST_CHECK(network->conn, char *, NULL); + virNetworkDefPtr def = NULL; + virNetworkIpDefPtr ipdef = NULL; + char *networkNameUtf8 = NULL; + PRUnichar *networkInterfaceNameUtf16 = NULL; + IHostNetworkInterface *networkInterface = NULL; + PRUint32 interfaceType = 0; + PRUnichar *networkNameUtf16 = NULL; + IDHCPServer *dhcpServer = NULL; + vboxIIDUnion vboxnet0IID; + + VBOX_IID_INITIALIZE(&vboxnet0IID); + virCheckFlags(0, NULL); + + if (VIR_ALLOC(def) < 0) + goto cleanup; + if (VIR_ALLOC(ipdef) < 0) + goto cleanup; + def->ips = ipdef; + def->nips = 1; + + if (virAsprintf(&networkNameUtf8, "HostInterfaceNetworking-%s", network->name) < 0) + goto cleanup; + + VBOX_UTF8_TO_UTF16(network->name, &networkInterfaceNameUtf16); + + gVBoxAPI.UIHost.FindHostNetworkInterfaceByName(host, networkInterfaceNameUtf16, &networkInterface); + + if (!networkInterface) + goto cleanup; + + gVBoxAPI.UIHNInterface.GetInterfaceType(networkInterface, &interfaceType); + + if (interfaceType != HostNetworkInterfaceType_HostOnly) + goto cleanup; + + if (VIR_STRDUP(def->name, network->name) < 0) + goto cleanup; + + gVBoxAPI.UIHNInterface.GetId(networkInterface, &vboxnet0IID); + vboxIIDToUUID(&vboxnet0IID, def->uuid); + + VBOX_UTF8_TO_UTF16(networkNameUtf8, &networkNameUtf16); + + def->forward.type = VIR_NETWORK_FORWARD_NONE; + + gVBoxAPI.UIVirtualBox.FindDHCPServerByNetworkName(data->vboxObj, + networkNameUtf16, + &dhcpServer); + if (dhcpServer) { + ipdef->nranges = 1; + if (VIR_ALLOC_N(ipdef->ranges, ipdef->nranges) >= 0) { + PRUnichar *ipAddressUtf16 = NULL; + PRUnichar *networkMaskUtf16 = NULL; + PRUnichar *fromIPAddressUtf16 = NULL; + PRUnichar *toIPAddressUtf16 = NULL; + bool errorOccurred = false; + + gVBoxAPI.UIDHCPServer.GetIPAddress(dhcpServer, &ipAddressUtf16); + gVBoxAPI.UIDHCPServer.GetNetworkMask(dhcpServer, &networkMaskUtf16); + gVBoxAPI.UIDHCPServer.GetLowerIP(dhcpServer, &fromIPAddressUtf16); + gVBoxAPI.UIDHCPServer.GetUpperIP(dhcpServer, &toIPAddressUtf16); + /* Currently virtualbox supports only one dhcp server per network + * with contigious address space from start to end + */ + if (vboxSocketParseAddrUtf16(data, ipAddressUtf16, + &ipdef->address) < 0 || + vboxSocketParseAddrUtf16(data, networkMaskUtf16, + &ipdef->netmask) < 0 || + vboxSocketParseAddrUtf16(data, fromIPAddressUtf16, + &ipdef->ranges[0].start) < 0 || + vboxSocketParseAddrUtf16(data, toIPAddressUtf16, + &ipdef->ranges[0].end) < 0) { + errorOccurred = true; + } + + VBOX_UTF16_FREE(ipAddressUtf16); + VBOX_UTF16_FREE(networkMaskUtf16); + VBOX_UTF16_FREE(fromIPAddressUtf16); + VBOX_UTF16_FREE(toIPAddressUtf16); + + if (errorOccurred) { + goto cleanup; + } + } else { + ipdef->nranges = 0; + } + + ipdef->nhosts = 1; + if (VIR_ALLOC_N(ipdef->hosts, ipdef->nhosts) >= 0) { + if (VIR_STRDUP(ipdef->hosts[0].name, network->name) < 0) { + VIR_FREE(ipdef->hosts); + ipdef->nhosts = 0; + } else { + PRUnichar *macAddressUtf16 = NULL; + PRUnichar *ipAddressUtf16 = NULL; + bool errorOccurred = false; + + gVBoxAPI.UIHNInterface.GetHardwareAddress(networkInterface, &macAddressUtf16); + gVBoxAPI.UIHNInterface.GetIPAddress(networkInterface, &ipAddressUtf16); + + VBOX_UTF16_TO_UTF8(macAddressUtf16, &ipdef->hosts[0].mac); + + if (vboxSocketParseAddrUtf16(data, ipAddressUtf16, + &ipdef->hosts[0].ip) < 0) { + errorOccurred = true; + } + + VBOX_UTF16_FREE(macAddressUtf16); + VBOX_UTF16_FREE(ipAddressUtf16); + + if (errorOccurred) { + goto cleanup; + } + } + } else { + ipdef->nhosts = 0; + } + + VBOX_RELEASE(dhcpServer); + } else { + PRUnichar *networkMaskUtf16 = NULL; + PRUnichar *ipAddressUtf16 = NULL; + bool errorOccurred = false; + + gVBoxAPI.UIHNInterface.GetNetworkMask(networkInterface, &networkMaskUtf16); + gVBoxAPI.UIHNInterface.GetIPAddress(networkInterface, &ipAddressUtf16); + + if (vboxSocketParseAddrUtf16(data, networkMaskUtf16, + &ipdef->netmask) < 0 || + vboxSocketParseAddrUtf16(data, ipAddressUtf16, + &ipdef->address) < 0) { + errorOccurred = true; + } + + VBOX_UTF16_FREE(networkMaskUtf16); + VBOX_UTF16_FREE(ipAddressUtf16); + + if (errorOccurred) { + goto cleanup; + } + } + + DEBUGIID("Network UUID", &vboxnet0IID); + ret = virNetworkDefFormat(def, 0); + + cleanup: + vboxIIDUnalloc(&vboxnet0IID); + VBOX_UTF16_FREE(networkNameUtf16); + VBOX_RELEASE(networkInterface); + VBOX_UTF16_FREE(networkInterfaceNameUtf16); + VBOX_RELEASE(host); + virNetworkDefFree(def); + VIR_FREE(networkNameUtf8); + return ret; +} + /** * Function Tables */ diff --git a/src/vbox/vbox_tmpl.c b/src/vbox/vbox_tmpl.c index 517e3ba..d0bed1a 100644 --- a/src/vbox/vbox_tmpl.c +++ b/src/vbox/vbox_tmpl.c @@ -838,27 +838,6 @@ static PRUnichar *PRUnicharFromInt(int n) { #endif /* VBOX_API_VERSION >= 3001000 */ -static int -vboxSocketParseAddrUtf16(vboxGlobalData *data, const PRUnichar *utf16, - virSocketAddrPtr addr) -{ - int result = -1; - char *utf8 = NULL; - - VBOX_UTF16_TO_UTF8(utf16, &utf8); - - if (virSocketAddrParse(addr, utf8, AF_UNSPEC) < 0) { - goto cleanup; - } - - result = 0; - - cleanup: - VBOX_UTF8_FREE(utf8); - - return result; -} - static virDomainState _vboxConvertState(PRUint32 state) { switch (state) { @@ -2039,171 +2018,6 @@ _registerDomainEvent(virDriverPtr driver) #endif /* !(VBOX_API_VERSION == 2002000 || VBOX_API_VERSION >= 4000000) */ /** - * The Network Functions here on - */ - -static char *vboxNetworkGetXMLDesc(virNetworkPtr network, - unsigned int flags) -{ - VBOX_OBJECT_HOST_CHECK(network->conn, char *, NULL); - virNetworkDefPtr def = NULL; - virNetworkIpDefPtr ipdef = NULL; - char *networkNameUtf8 = NULL; - PRUnichar *networkInterfaceNameUtf16 = NULL; - IHostNetworkInterface *networkInterface = NULL; - - virCheckFlags(0, NULL); - - if (VIR_ALLOC(def) < 0) - goto cleanup; - if (VIR_ALLOC(ipdef) < 0) - goto cleanup; - def->ips = ipdef; - def->nips = 1; - - if (virAsprintf(&networkNameUtf8, "HostInterfaceNetworking-%s", network->name) < 0) - goto cleanup; - - VBOX_UTF8_TO_UTF16(network->name, &networkInterfaceNameUtf16); - - host->vtbl->FindHostNetworkInterfaceByName(host, networkInterfaceNameUtf16, &networkInterface); - - if (networkInterface) { - PRUint32 interfaceType = 0; - - networkInterface->vtbl->GetInterfaceType(networkInterface, &interfaceType); - - if (interfaceType == HostNetworkInterfaceType_HostOnly) { - if (VIR_STRDUP(def->name, network->name) >= 0) { - PRUnichar *networkNameUtf16 = NULL; - IDHCPServer *dhcpServer = NULL; - vboxIID vboxnet0IID = VBOX_IID_INITIALIZER; - - networkInterface->vtbl->GetId(networkInterface, &vboxnet0IID.value); - vboxIIDToUUID(&vboxnet0IID, def->uuid); - - VBOX_UTF8_TO_UTF16(networkNameUtf8, &networkNameUtf16); - - def->forward.type = VIR_NETWORK_FORWARD_NONE; - - data->vboxObj->vtbl->FindDHCPServerByNetworkName(data->vboxObj, - networkNameUtf16, - &dhcpServer); - if (dhcpServer) { - ipdef->nranges = 1; - if (VIR_ALLOC_N(ipdef->ranges, ipdef->nranges) >= 0) { - PRUnichar *ipAddressUtf16 = NULL; - PRUnichar *networkMaskUtf16 = NULL; - PRUnichar *fromIPAddressUtf16 = NULL; - PRUnichar *toIPAddressUtf16 = NULL; - bool errorOccurred = false; - - dhcpServer->vtbl->GetIPAddress(dhcpServer, &ipAddressUtf16); - dhcpServer->vtbl->GetNetworkMask(dhcpServer, &networkMaskUtf16); - dhcpServer->vtbl->GetLowerIP(dhcpServer, &fromIPAddressUtf16); - dhcpServer->vtbl->GetUpperIP(dhcpServer, &toIPAddressUtf16); - /* Currently virtualbox supports only one dhcp server per network - * with contigious address space from start to end - */ - if (vboxSocketParseAddrUtf16(data, ipAddressUtf16, - &ipdef->address) < 0 || - vboxSocketParseAddrUtf16(data, networkMaskUtf16, - &ipdef->netmask) < 0 || - vboxSocketParseAddrUtf16(data, fromIPAddressUtf16, - &ipdef->ranges[0].start) < 0 || - vboxSocketParseAddrUtf16(data, toIPAddressUtf16, - &ipdef->ranges[0].end) < 0) { - errorOccurred = true; - } - - VBOX_UTF16_FREE(ipAddressUtf16); - VBOX_UTF16_FREE(networkMaskUtf16); - VBOX_UTF16_FREE(fromIPAddressUtf16); - VBOX_UTF16_FREE(toIPAddressUtf16); - - if (errorOccurred) { - goto cleanup; - } - } else { - ipdef->nranges = 0; - } - - ipdef->nhosts = 1; - if (VIR_ALLOC_N(ipdef->hosts, ipdef->nhosts) >= 0) { - if (VIR_STRDUP(ipdef->hosts[0].name, network->name) < 0) { - VIR_FREE(ipdef->hosts); - ipdef->nhosts = 0; - } else { - PRUnichar *macAddressUtf16 = NULL; - PRUnichar *ipAddressUtf16 = NULL; - bool errorOccurred = false; - - networkInterface->vtbl->GetHardwareAddress(networkInterface, &macAddressUtf16); - networkInterface->vtbl->GetIPAddress(networkInterface, &ipAddressUtf16); - - VBOX_UTF16_TO_UTF8(macAddressUtf16, &ipdef->hosts[0].mac); - - if (vboxSocketParseAddrUtf16(data, ipAddressUtf16, - &ipdef->hosts[0].ip) < 0) { - errorOccurred = true; - } - - VBOX_UTF16_FREE(macAddressUtf16); - VBOX_UTF16_FREE(ipAddressUtf16); - - if (errorOccurred) { - goto cleanup; - } - } - } else { - ipdef->nhosts = 0; - } - - VBOX_RELEASE(dhcpServer); - } else { - PRUnichar *networkMaskUtf16 = NULL; - PRUnichar *ipAddressUtf16 = NULL; - bool errorOccurred = false; - - networkInterface->vtbl->GetNetworkMask(networkInterface, &networkMaskUtf16); - networkInterface->vtbl->GetIPAddress(networkInterface, &ipAddressUtf16); - - if (vboxSocketParseAddrUtf16(data, networkMaskUtf16, - &ipdef->netmask) < 0 || - vboxSocketParseAddrUtf16(data, ipAddressUtf16, - &ipdef->address) < 0) { - errorOccurred = true; - } - - VBOX_UTF16_FREE(networkMaskUtf16); - VBOX_UTF16_FREE(ipAddressUtf16); - - if (errorOccurred) { - goto cleanup; - } - } - - DEBUGIID("Network UUID", vboxnet0IID.value); - vboxIIDUnalloc(&vboxnet0IID); - VBOX_UTF16_FREE(networkNameUtf16); - } - } - - VBOX_RELEASE(networkInterface); - } - - VBOX_UTF16_FREE(networkInterfaceNameUtf16); - VBOX_RELEASE(host); - - ret = virNetworkDefFormat(def, 0); - - cleanup: - virNetworkDefFree(def); - VIR_FREE(networkNameUtf8); - return ret; -} - -/** * The Storage Functions here on */ @@ -5525,6 +5339,24 @@ _hnInterfaceGetId(IHostNetworkInterface *hni, vboxIIDUnion *iidu) } static nsresult +_hnInterfaceGetHardwareAddress(IHostNetworkInterface *hni, PRUnichar **hardwareAddress) +{ + return hni->vtbl->GetHardwareAddress(hni, hardwareAddress); +} + +static nsresult +_hnInterfaceGetIPAddress(IHostNetworkInterface *hni, PRUnichar **IPAddress) +{ + return hni->vtbl->GetIPAddress(hni, IPAddress); +} + +static nsresult +_hnInterfaceGetNetworkMask(IHostNetworkInterface *hni, PRUnichar **networkMask) +{ + return hni->vtbl->GetNetworkMask(hni, networkMask); +} + +static nsresult _hnInterfaceEnableStaticIPConfig(IHostNetworkInterface *hni, PRUnichar *IPAddress, PRUnichar *networkMask) { @@ -5556,6 +5388,30 @@ _hnInterfaceDHCPRediscover(IHostNetworkInterface *hni) } static nsresult +_dhcpServerGetIPAddress(IDHCPServer *dhcpServer, PRUnichar **IPAddress) +{ + return dhcpServer->vtbl->GetIPAddress(dhcpServer, IPAddress); +} + +static nsresult +_dhcpServerGetNetworkMask(IDHCPServer *dhcpServer, PRUnichar **networkMask) +{ + return dhcpServer->vtbl->GetNetworkMask(dhcpServer, networkMask); +} + +static nsresult +_dhcpServerGetLowerIP(IDHCPServer *dhcpServer, PRUnichar **lowerIP) +{ + return dhcpServer->vtbl->GetLowerIP(dhcpServer, lowerIP); +} + +static nsresult +_dhcpServerGetUpperIP(IDHCPServer *dhcpServer, PRUnichar **upperIP) +{ + return dhcpServer->vtbl->GetUpperIP(dhcpServer, upperIP); +} + +static nsresult _dhcpServerSetEnabled(IDHCPServer *dhcpServer, PRBool enabled) { return dhcpServer->vtbl->SetEnabled(dhcpServer, enabled); @@ -5903,12 +5759,19 @@ static vboxUniformedIHNInterface _UIHNInterface = { .GetStatus = _hnInterfaceGetStatus, .GetName = _hnInterfaceGetName, .GetId = _hnInterfaceGetId, + .GetHardwareAddress = _hnInterfaceGetHardwareAddress, + .GetIPAddress = _hnInterfaceGetIPAddress, + .GetNetworkMask = _hnInterfaceGetNetworkMask, .EnableStaticIPConfig = _hnInterfaceEnableStaticIPConfig, .EnableDynamicIPConfig = _hnInterfaceEnableDynamicIPConfig, .DHCPRediscover = _hnInterfaceDHCPRediscover, }; static vboxUniformedIDHCPServer _UIDHCPServer = { + .GetIPAddress = _dhcpServerGetIPAddress, + .GetNetworkMask = _dhcpServerGetNetworkMask, + .GetLowerIP = _dhcpServerGetLowerIP, + .GetUpperIP = _dhcpServerGetUpperIP, .SetEnabled = _dhcpServerSetEnabled, .SetConfiguration = _dhcpServerSetConfiguration, .Start = _dhcpServerStart, diff --git a/src/vbox/vbox_uniformed_api.h b/src/vbox/vbox_uniformed_api.h index f0b98c0..da754e8 100644 --- a/src/vbox/vbox_uniformed_api.h +++ b/src/vbox/vbox_uniformed_api.h @@ -488,6 +488,9 @@ typedef struct { nsresult (*GetStatus)(IHostNetworkInterface *hni, PRUint32 *status); nsresult (*GetName)(IHostNetworkInterface *hni, PRUnichar **name); nsresult (*GetId)(IHostNetworkInterface *hni, vboxIIDUnion *iidu); + nsresult (*GetHardwareAddress)(IHostNetworkInterface *hni, PRUnichar **hardwareAddress); + nsresult (*GetIPAddress)(IHostNetworkInterface *hni, PRUnichar **IPAddress); + nsresult (*GetNetworkMask)(IHostNetworkInterface *hni, PRUnichar **networkMask); nsresult (*EnableStaticIPConfig)(IHostNetworkInterface *hni, PRUnichar *IPAddress, PRUnichar *networkMask); nsresult (*EnableDynamicIPConfig)(IHostNetworkInterface *hni); @@ -496,6 +499,10 @@ typedef struct { /* Functions for IDHCPServer */ typedef struct { + nsresult (*GetIPAddress)(IDHCPServer *dhcpServer, PRUnichar **IPAddress); + nsresult (*GetNetworkMask)(IDHCPServer *dhcpServer, PRUnichar **networkMask); + nsresult (*GetLowerIP)(IDHCPServer *dhcpServer, PRUnichar **lowerIP); + nsresult (*GetUpperIP)(IDHCPServer *dhcpServer, PRUnichar **upperIP); nsresult (*SetEnabled)(IDHCPServer *dhcpServer, PRBool enabled); nsresult (*SetConfiguration)(IDHCPServer *dhcpServer, PRUnichar *IPAddress, PRUnichar *networkMask, PRUnichar *FromIPAddress, @@ -594,6 +601,7 @@ virNetworkPtr vboxNetworkDefineXML(virConnectPtr conn, const char *xml); int vboxNetworkUndefine(virNetworkPtr network); int vboxNetworkDestroy(virNetworkPtr network); int vboxNetworkCreate(virNetworkPtr network); +char *vboxNetworkGetXMLDesc(virNetworkPtr network, unsigned int flags); /* Version specified functions for installing uniformed API */ void vbox22InstallUniformedAPI(vboxUniformedAPI *pVBoxAPI); -- 1.7.9.5

--- src/vbox/vbox_common.c | 54 +++++++++++++++++++++++++++++------------ src/vbox/vbox_driver.c | 23 ++---------------- src/vbox/vbox_tmpl.c | 18 -------------- src/vbox/vbox_uniformed_api.h | 16 ------------ 4 files changed, 40 insertions(+), 71 deletions(-) diff --git a/src/vbox/vbox_common.c b/src/vbox/vbox_common.c index 6e6ce67..4bb01b0 100644 --- a/src/vbox/vbox_common.c +++ b/src/vbox/vbox_common.c @@ -7468,9 +7468,10 @@ vboxNodeGetFreePages(virConnectPtr conn ATTRIBUTE_UNUSED, * The Network Functions here on */ -virDrvOpenStatus vboxNetworkOpen(virConnectPtr conn, - virConnectAuthPtr auth ATTRIBUTE_UNUSED, - unsigned int flags) +static virDrvOpenStatus +vboxNetworkOpen(virConnectPtr conn, + virConnectAuthPtr auth ATTRIBUTE_UNUSED, + unsigned int flags) { vboxGlobalData *data = conn->privateData; @@ -7492,14 +7493,14 @@ virDrvOpenStatus vboxNetworkOpen(virConnectPtr conn, return VIR_DRV_OPEN_DECLINED; } -int vboxNetworkClose(virConnectPtr conn) +static int vboxNetworkClose(virConnectPtr conn) { VIR_DEBUG("network uninitialized"); conn->networkPrivateData = NULL; return 0; } -int vboxConnectNumOfNetworks(virConnectPtr conn) +static int vboxConnectNumOfNetworks(virConnectPtr conn) { VBOX_OBJECT_HOST_CHECK(conn, int, 0); vboxArray networkInterfaces = VBOX_ARRAY_INITIALIZER; @@ -7534,7 +7535,8 @@ int vboxConnectNumOfNetworks(virConnectPtr conn) return ret; } -int vboxConnectListNetworks(virConnectPtr conn, char **const names, int nnames) +static int +vboxConnectListNetworks(virConnectPtr conn, char **const names, int nnames) { VBOX_OBJECT_HOST_CHECK(conn, int, 0); vboxArray networkInterfaces = VBOX_ARRAY_INITIALIZER; @@ -7581,7 +7583,7 @@ int vboxConnectListNetworks(virConnectPtr conn, char **const names, int nnames) return ret; } -int vboxConnectNumOfDefinedNetworks(virConnectPtr conn) +static int vboxConnectNumOfDefinedNetworks(virConnectPtr conn) { VBOX_OBJECT_HOST_CHECK(conn, int, 0); vboxArray networkInterfaces = VBOX_ARRAY_INITIALIZER; @@ -7616,7 +7618,8 @@ int vboxConnectNumOfDefinedNetworks(virConnectPtr conn) return ret; } -int vboxConnectListDefinedNetworks(virConnectPtr conn, char **const names, int nnames) +static int +vboxConnectListDefinedNetworks(virConnectPtr conn, char **const names, int nnames) { VBOX_OBJECT_HOST_CHECK(conn, int, 0); vboxArray networkInterfaces = VBOX_ARRAY_INITIALIZER; @@ -7663,7 +7666,8 @@ int vboxConnectListDefinedNetworks(virConnectPtr conn, char **const names, int n return ret; } -virNetworkPtr vboxNetworkLookupByUUID(virConnectPtr conn, const unsigned char *uuid) +static virNetworkPtr +vboxNetworkLookupByUUID(virConnectPtr conn, const unsigned char *uuid) { VBOX_OBJECT_HOST_CHECK(conn, virNetworkPtr, NULL); PRUint32 interfaceType = 0; @@ -7706,7 +7710,7 @@ virNetworkPtr vboxNetworkLookupByUUID(virConnectPtr conn, const unsigned char *u return ret; } -virNetworkPtr vboxNetworkLookupByName(virConnectPtr conn, const char *name) +static virNetworkPtr vboxNetworkLookupByName(virConnectPtr conn, const char *name) { VBOX_OBJECT_HOST_CHECK(conn, virNetworkPtr, NULL); PRUnichar *nameUtf16 = NULL; @@ -7935,12 +7939,12 @@ vboxNetworkDefineCreateXML(virConnectPtr conn, const char *xml, bool start) return ret; } -virNetworkPtr vboxNetworkCreateXML(virConnectPtr conn, const char *xml) +static virNetworkPtr vboxNetworkCreateXML(virConnectPtr conn, const char *xml) { return vboxNetworkDefineCreateXML(conn, xml, true); } -virNetworkPtr vboxNetworkDefineXML(virConnectPtr conn, const char *xml) +static virNetworkPtr vboxNetworkDefineXML(virConnectPtr conn, const char *xml) { return vboxNetworkDefineCreateXML(conn, xml, false); } @@ -8031,17 +8035,17 @@ vboxNetworkUndefineDestroy(virNetworkPtr network, bool removeinterface) return ret; } -int vboxNetworkUndefine(virNetworkPtr network) +static int vboxNetworkUndefine(virNetworkPtr network) { return vboxNetworkUndefineDestroy(network, true); } -int vboxNetworkDestroy(virNetworkPtr network) +static int vboxNetworkDestroy(virNetworkPtr network) { return vboxNetworkUndefineDestroy(network, false); } -int vboxNetworkCreate(virNetworkPtr network) +static int vboxNetworkCreate(virNetworkPtr network) { VBOX_OBJECT_HOST_CHECK(network->conn, int, -1); char *networkNameUtf8 = NULL; @@ -8125,7 +8129,7 @@ vboxSocketParseAddrUtf16(vboxGlobalData *data, const PRUnichar *utf16, return result; } -char *vboxNetworkGetXMLDesc(virNetworkPtr network, unsigned int flags) +static char *vboxNetworkGetXMLDesc(virNetworkPtr network, unsigned int flags) { VBOX_OBJECT_HOST_CHECK(network->conn, char *, NULL); virNetworkDefPtr def = NULL; @@ -8357,6 +8361,24 @@ virDriver vboxCommonDriver = { .nodeGetFreePages = vboxNodeGetFreePages, /* 1.2.6 */ }; +virNetworkDriver vboxCommonNetworkDriver = { + "VBOX", + .networkOpen = vboxNetworkOpen, /* 0.6.4 */ + .networkClose = vboxNetworkClose, /* 0.6.4 */ + .connectNumOfNetworks = vboxConnectNumOfNetworks, /* 0.6.4 */ + .connectListNetworks = vboxConnectListNetworks, /* 0.6.4 */ + .connectNumOfDefinedNetworks = vboxConnectNumOfDefinedNetworks, /* 0.6.4 */ + .connectListDefinedNetworks = vboxConnectListDefinedNetworks, /* 0.6.4 */ + .networkLookupByUUID = vboxNetworkLookupByUUID, /* 0.6.4 */ + .networkLookupByName = vboxNetworkLookupByName, /* 0.6.4 */ + .networkCreateXML = vboxNetworkCreateXML, /* 0.6.4 */ + .networkDefineXML = vboxNetworkDefineXML, /* 0.6.4 */ + .networkUndefine = vboxNetworkUndefine, /* 0.6.4 */ + .networkCreate = vboxNetworkCreate, /* 0.6.4 */ + .networkDestroy = vboxNetworkDestroy, /* 0.6.4 */ + .networkGetXMLDesc = vboxNetworkGetXMLDesc, /* 0.6.4 */ +}; + static void updateDriver(void) { /* Update the vboxDriver according to the vboxUniformedAPI. diff --git a/src/vbox/vbox_driver.c b/src/vbox/vbox_driver.c index f0c05fe..6c86973 100644 --- a/src/vbox/vbox_driver.c +++ b/src/vbox/vbox_driver.c @@ -48,28 +48,19 @@ VIR_LOG_INIT("vbox.vbox_driver"); -extern virNetworkDriver vbox22NetworkDriver; extern virStorageDriver vbox22StorageDriver; -extern virNetworkDriver vbox30NetworkDriver; extern virStorageDriver vbox30StorageDriver; -extern virNetworkDriver vbox31NetworkDriver; extern virStorageDriver vbox31StorageDriver; -extern virNetworkDriver vbox32NetworkDriver; extern virStorageDriver vbox32StorageDriver; -extern virNetworkDriver vbox40NetworkDriver; extern virStorageDriver vbox40StorageDriver; -extern virNetworkDriver vbox41NetworkDriver; extern virStorageDriver vbox41StorageDriver; -extern virNetworkDriver vbox42NetworkDriver; extern virStorageDriver vbox42StorageDriver; -extern virNetworkDriver vbox42_20NetworkDriver; extern virStorageDriver vbox42_20StorageDriver; -extern virNetworkDriver vbox43NetworkDriver; extern virStorageDriver vbox43StorageDriver; -extern virNetworkDriver vbox43_4NetworkDriver; extern virStorageDriver vbox43_4StorageDriver; extern virDriver vboxCommonDriver; +extern virNetworkDriver vboxCommonNetworkDriver; static virDriver vboxDriverDummy; @@ -89,7 +80,7 @@ int vboxRegister(void) * never work */ driver = &vboxDriverDummy; - networkDriver = &vbox22NetworkDriver; + networkDriver = &vboxCommonNetworkDriver; storageDriver = &vbox22StorageDriver; /* Init the glue and get the API version. */ @@ -106,43 +97,33 @@ int vboxRegister(void) */ if (uVersion >= 2001052 && uVersion < 2002051) { VIR_DEBUG("VirtualBox API version: 2.2"); - networkDriver = &vbox22NetworkDriver; storageDriver = &vbox22StorageDriver; } else if (uVersion >= 2002051 && uVersion < 3000051) { VIR_DEBUG("VirtualBox API version: 3.0"); - networkDriver = &vbox30NetworkDriver; storageDriver = &vbox30StorageDriver; } else if (uVersion >= 3000051 && uVersion < 3001051) { VIR_DEBUG("VirtualBox API version: 3.1"); - networkDriver = &vbox31NetworkDriver; storageDriver = &vbox31StorageDriver; } else if (uVersion >= 3001051 && uVersion < 3002051) { VIR_DEBUG("VirtualBox API version: 3.2"); - networkDriver = &vbox32NetworkDriver; storageDriver = &vbox32StorageDriver; } else if (uVersion >= 3002051 && uVersion < 4000051) { VIR_DEBUG("VirtualBox API version: 4.0"); - networkDriver = &vbox40NetworkDriver; storageDriver = &vbox40StorageDriver; } else if (uVersion >= 4000051 && uVersion < 4001051) { VIR_DEBUG("VirtualBox API version: 4.1"); - networkDriver = &vbox41NetworkDriver; storageDriver = &vbox41StorageDriver; } else if (uVersion >= 4001051 && uVersion < 4002020) { VIR_DEBUG("VirtualBox API version: 4.2"); - networkDriver = &vbox42NetworkDriver; storageDriver = &vbox42StorageDriver; } else if (uVersion >= 4002020 && uVersion < 4002051) { VIR_DEBUG("VirtualBox API version: 4.2.20 or higher"); - networkDriver = &vbox42_20NetworkDriver; storageDriver = &vbox42_20StorageDriver; } else if (uVersion >= 4002051 && uVersion < 4003004) { VIR_DEBUG("VirtualBox API version: 4.3"); - networkDriver = &vbox43NetworkDriver; storageDriver = &vbox43StorageDriver; } else if (uVersion >= 4003004 && uVersion < 4003051) { VIR_DEBUG("VirtualBox API version: 4.3.4 or higher"); - networkDriver = &vbox43_4NetworkDriver; storageDriver = &vbox43_4StorageDriver; } else { VIR_DEBUG("Unsupported VirtualBox API version: %u", uVersion); diff --git a/src/vbox/vbox_tmpl.c b/src/vbox/vbox_tmpl.c index d0bed1a..67bd408 100644 --- a/src/vbox/vbox_tmpl.c +++ b/src/vbox/vbox_tmpl.c @@ -5892,24 +5892,6 @@ void NAME(InstallUniformedAPI)(vboxUniformedAPI *pVBoxAPI) * Function Tables */ -virNetworkDriver NAME(NetworkDriver) = { - "VBOX", - .networkOpen = vboxNetworkOpen, /* 0.6.4 */ - .networkClose = vboxNetworkClose, /* 0.6.4 */ - .connectNumOfNetworks = vboxConnectNumOfNetworks, /* 0.6.4 */ - .connectListNetworks = vboxConnectListNetworks, /* 0.6.4 */ - .connectNumOfDefinedNetworks = vboxConnectNumOfDefinedNetworks, /* 0.6.4 */ - .connectListDefinedNetworks = vboxConnectListDefinedNetworks, /* 0.6.4 */ - .networkLookupByUUID = vboxNetworkLookupByUUID, /* 0.6.4 */ - .networkLookupByName = vboxNetworkLookupByName, /* 0.6.4 */ - .networkCreateXML = vboxNetworkCreateXML, /* 0.6.4 */ - .networkDefineXML = vboxNetworkDefineXML, /* 0.6.4 */ - .networkUndefine = vboxNetworkUndefine, /* 0.6.4 */ - .networkCreate = vboxNetworkCreate, /* 0.6.4 */ - .networkDestroy = vboxNetworkDestroy, /* 0.6.4 */ - .networkGetXMLDesc = vboxNetworkGetXMLDesc, /* 0.6.4 */ -}; - virStorageDriver NAME(StorageDriver) = { .name = "VBOX", .storageOpen = vboxStorageOpen, /* 0.7.1 */ diff --git a/src/vbox/vbox_uniformed_api.h b/src/vbox/vbox_uniformed_api.h index da754e8..b92c932 100644 --- a/src/vbox/vbox_uniformed_api.h +++ b/src/vbox/vbox_uniformed_api.h @@ -586,22 +586,6 @@ typedef struct { virDomainPtr vboxDomainLookupByUUID(virConnectPtr conn, const unsigned char *uuid); -virDrvOpenStatus vboxNetworkOpen(virConnectPtr conn, - virConnectAuthPtr auth, - unsigned int flags); -int vboxNetworkClose(virConnectPtr conn); -int vboxConnectNumOfNetworks(virConnectPtr conn); -int vboxConnectListNetworks(virConnectPtr conn, char **const names, int nnames); -int vboxConnectNumOfDefinedNetworks(virConnectPtr conn); -int vboxConnectListDefinedNetworks(virConnectPtr conn, char **const names, int nnames); -virNetworkPtr vboxNetworkLookupByUUID(virConnectPtr conn, const unsigned char *uuid); -virNetworkPtr vboxNetworkLookupByName(virConnectPtr conn, const char *name); -virNetworkPtr vboxNetworkCreateXML(virConnectPtr conn, const char *xml); -virNetworkPtr vboxNetworkDefineXML(virConnectPtr conn, const char *xml); -int vboxNetworkUndefine(virNetworkPtr network); -int vboxNetworkDestroy(virNetworkPtr network); -int vboxNetworkCreate(virNetworkPtr network); -char *vboxNetworkGetXMLDesc(virNetworkPtr network, unsigned int flags); /* Version specified functions for installing uniformed API */ void vbox22InstallUniformedAPI(vboxUniformedAPI *pVBoxAPI); -- 1.7.9.5
participants (3)
-
Eric Blake
-
Michal Privoznik
-
Taowei