struct port **ports;
size_t n_ports, allocated_ports;
struct shash iface_by_name; /* "struct iface"s indexed by name. */
+ struct shash port_by_name; /* "struct port"s indexed by name. */
/* Bonding. */
bool has_bonded_ports;
port_array_init(&br->ifaces);
+ shash_init(&br->port_by_name);
shash_init(&br->iface_by_name);
br->flush = false;
ofproto_destroy(br->ofproto);
mac_learning_destroy(br->ml);
port_array_destroy(&br->ifaces);
+ shash_destroy(&br->port_by_name);
shash_destroy(&br->iface_by_name);
free(br->ports);
free(br->name);
sizeof *br->ports);
}
br->ports[br->n_ports++] = port;
+ shash_add_assert(&br->port_by_name, port->name, port);
VLOG_INFO("created port %s on bridge %s", port->name, br->name);
bridge_flush(br);
iface_destroy(port->ifaces[port->n_ifaces - 1]);
}
+ shash_find_and_delete_assert(&br->port_by_name, port->name);
+
del = br->ports[port->port_idx] = br->ports[--br->n_ports];
del->port_idx = port->port_idx;
static struct port *
port_lookup(const struct bridge *br, const char *name)
{
- size_t i;
-
- for (i = 0; i < br->n_ports; i++) {
- struct port *port = br->ports[i];
- if (!strcmp(port->name, name)) {
- return port;
- }
- }
- return NULL;
+ return shash_find_data(&br->port_by_name, name);
}
static struct iface *