bridge: Fix uninitialized bond_stable_ids in port_configure_bond().
authorBen Pfaff <blp@nicira.com>
Fri, 13 May 2011 23:47:01 +0000 (16:47 -0700)
committerBen Pfaff <blp@nicira.com>
Fri, 13 May 2011 23:47:01 +0000 (16:47 -0700)
The recent merge of "master" added a new bond_stable_ids member to
struct ofproto_bundle_settings, but neglected to initialize it.  This fixes
the problem.

Found and verified using valgrind.

vswitchd/bridge.c

index 127e0b7..f0ff91d 100644 (file)
@@ -175,7 +175,8 @@ static struct port *port_lookup(const struct bridge *, const char *name);
 static void port_configure(struct port *);
 static struct lacp_settings *port_configure_lacp(struct port *,
                                                  struct lacp_settings *);
-static void port_configure_bond(struct port *, struct bond_settings *);
+static void port_configure_bond(struct port *, struct bond_settings *,
+                                uint32_t *bond_stable_ids);
 
 static void bridge_configure_mirrors(struct bridge *);
 static struct mirror *mirror_create(struct bridge *,
@@ -521,10 +522,12 @@ port_configure(struct port *port)
 
     /* Get bond settings. */
     if (s.n_slaves > 1) {
-        port_configure_bond(port, &bond_settings);
         s.bond = &bond_settings;
+        s.bond_stable_ids = xmalloc(s.n_slaves * sizeof *s.bond_stable_ids);
+        port_configure_bond(port, &bond_settings, s.bond_stable_ids);
     } else {
         s.bond = NULL;
+        s.bond_stable_ids = NULL;
     }
 
     /* Register. */
@@ -533,6 +536,7 @@ port_configure(struct port *port)
     /* Clean up. */
     free(s.trunks);
     free(s.lacp_slaves);
+    free(s.bond_stable_ids);
 }
 
 /* Pick local port hardware address and datapath ID for 'br'. */
@@ -2214,9 +2218,12 @@ iface_configure_lacp(struct iface *iface, struct lacp_slave_settings *s)
 }
 
 static void
-port_configure_bond(struct port *port, struct bond_settings *s)
+port_configure_bond(struct port *port, struct bond_settings *s,
+                    uint32_t *bond_stable_ids)
 {
     const char *detect_s;
+    struct iface *iface;
+    size_t i;
 
     s->name = port->name;
     s->balance = BM_SLB;
@@ -2251,6 +2258,18 @@ port_configure_bond(struct port *port, struct bond_settings *s)
     }
 
     s->fake_iface = port->cfg->bond_fake_iface;
+
+    i = 0;
+    LIST_FOR_EACH (iface, port_elem, &port->ifaces) {
+        long long stable_id;
+
+        stable_id = atoll(get_interface_other_config(iface->cfg,
+                                                     "bond-stable-id", "0"));
+        if (stable_id <= 0 || stable_id >= UINT32_MAX) {
+            stable_id = iface->ofp_port;
+        }
+        bond_stable_ids[i++] = stable_id;
+    }
 }
 \f
 /* Interface functions. */