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

[libvirt] [PATCH] Detect bridge name collisions when defining a virtual network



The attached patch is a partial fix for rhbz 479622. If a virtual
network is defined with an explicit bridge name, make sure it doesn't
collide with other virtual network bridge names.

Thanks,
Cole
    Detect bridge name collisions when defining a virtual network.

diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
index 9e9b3e5..fd4ea61 100644
--- a/src/libvirt_private.syms
+++ b/src/libvirt_private.syms
@@ -192,6 +192,7 @@ virFree;
 
 # network_conf.h
 virNetworkAssignDef;
+virNetworkBridgeInUse;
 virNetworkConfigFile;
 virNetworkDefFormat;
 virNetworkDefFree;
diff --git a/src/network_conf.c b/src/network_conf.c
index e19f0fe..0d0545f 100644
--- a/src/network_conf.c
+++ b/src/network_conf.c
@@ -85,6 +85,19 @@ virNetworkObjPtr virNetworkFindByName(const virNetworkObjListPtr nets,
     return NULL;
 }
 
+int virNetworkBridgeInUse(const virNetworkObjListPtr nets,
+                          const char *bridge)
+{
+    unsigned int i;
+
+    for (i = 0 ; i < nets->count ; i++) {
+        if (nets->objs[i]->def->bridge &&
+            STREQ(nets->objs[i]->def->bridge, bridge))
+            return 1;
+    }
+
+    return 0;
+}
 
 void virNetworkDefFree(virNetworkDefPtr def)
 {
diff --git a/src/network_conf.h b/src/network_conf.h
index 94a1748..5ed549e 100644
--- a/src/network_conf.h
+++ b/src/network_conf.h
@@ -112,7 +112,8 @@ virNetworkObjPtr virNetworkFindByUUID(const virNetworkObjListPtr nets,
                                       const unsigned char *uuid);
 virNetworkObjPtr virNetworkFindByName(const virNetworkObjListPtr nets,
                                       const char *name);
-
+int virNetworkBridgeInUse(const virNetworkObjListPtr nets,
+                          const char *bridge);
 
 void virNetworkDefFree(virNetworkDefPtr def);
 void virNetworkObjFree(virNetworkObjPtr net);
diff --git a/src/network_driver.c b/src/network_driver.c
index b256e3d..d750565 100644
--- a/src/network_driver.c
+++ b/src/network_driver.c
@@ -1147,6 +1147,13 @@ static virNetworkPtr networkDefine(virConnectPtr conn, const char *xml) {
     if (!(def = virNetworkDefParseString(conn, xml)))
         goto cleanup;
 
+    if (def->bridge &&
+        virNetworkBridgeInUse(&driver->networks, def->bridge)) {
+        networkReportError(conn, NULL, NULL, VIR_ERR_INTERNAL_ERROR,
+                           _("bridge name '%s' already in use."), def->bridge);
+        goto cleanup;
+    }
+
     if (!(network = virNetworkAssignDef(conn,
                                         &driver->networks,
                                         def)))

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