vswitchd: Prevent a single interface from being added to two different ports.
authorBen Pfaff <blp@nicira.com>
Thu, 1 Jan 2009 00:13:33 +0000 (16:13 -0800)
committerBen Pfaff <blp@nicira.com>
Thu, 1 Jan 2009 00:13:33 +0000 (16:13 -0800)
vswitchd/bridge.c

index 21c4a51d5366d979c91cce07ebe83e1746898e73..81806d97ecb4d3c5153cd8aa1f8e56fe51f48172 100644 (file)
@@ -775,10 +775,10 @@ bridge_run_one(struct bridge *br)
 static void
 bridge_reconfigure_one(struct bridge *br)
 {
-    struct svec old_ports, new_ports;
+    struct svec old_ports, new_ports, ifaces;
     const char *controller;
+    size_t i, j;
     char *ctl;
-    size_t i;
 
     /* Collect old and new ports. */
     svec_init(&old_ports);
@@ -813,6 +813,31 @@ bridge_reconfigure_one(struct bridge *br)
         port_reconfigure(br->ports[i]);
     }
 
+    /* Check and delete duplicate interfaces. */
+    svec_init(&ifaces);
+    for (i = 0; i < br->n_ports; ) {
+        struct port *port = br->ports[i];
+        for (j = 0; j < port->n_ifaces; ) {
+            struct iface *iface = port->ifaces[j];
+            if (svec_contains(&ifaces, iface->name)) {
+                VLOG_ERR("bridge %s: %s interface is on multiple ports, "
+                         "removing from %s",
+                         br->name, iface->name, port->name);
+                iface_destroy(iface);
+            } else {
+                svec_add(&ifaces, iface->name);
+                svec_sort(&ifaces);
+                j++;
+            }
+        }
+        if (!port->n_ifaces) {
+            VLOG_ERR("%s port has no interfaces, dropping", port->name);
+            port_destroy(port);
+        } else {
+            i++;
+        }
+    }
+
     /* Configure remote controller. */
     controller = cfg_get_string(0, "bridge.%s.controller", br->name);
     ctl = controller ? xstrdup(controller) : NULL;