[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

[libvirt] [PATCH 11/13] vbox: Rewrite vboxNetworkCreate



---
 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


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]