/* Copyright (c) 2008, 2009 Nicira Networks
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
*
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at:
*
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- *
- * In addition, as a special exception, Nicira Networks gives permission
- * to link the code of its release of vswitchd with the OpenSSL project's
- * "OpenSSL" library (or with modified versions of it that use the same
- * license as the "OpenSSL" library), and distribute the linked
- * executables. You must obey the GNU General Public License in all
- * respects for all of the code used other than "OpenSSL". If you modify
- * this file, you may extend this exception to your version of the file,
- * but you are not obligated to do so. If you do not wish to do so,
- * delete this exception statement from your version.
+ * http://www.apache.org/licenses/LICENSE-2.0
*
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
*/
#include <config.h>
#include <strings.h>
#include <sys/stat.h>
#include <sys/socket.h>
+#include <sys/types.h>
#include <unistd.h>
#include "bitmap.h"
#include "cfg.h"
#include "odp-util.h"
#include "ofp-print.h"
#include "ofpbuf.h"
+#include "packets.h"
#include "poll-loop.h"
#include "port-array.h"
#include "proc-net-compat.h"
#include "svec.h"
#include "timeval.h"
#include "util.h"
+#include "unixctl.h"
#include "vconn.h"
#include "vconn-ssl.h"
#include "xenserver.h"
tag_type active_iface_tag; /* Tag for bcast flows. */
tag_type no_ifaces_tag; /* Tag for flows when all ifaces disabled. */
int updelay, downdelay; /* Delay before iface goes up/down, in ms. */
+ bool bond_compat_is_stale; /* Need to call port_update_bond_compat()? */
/* Port mirroring info. */
mirror_mask_t src_mirrors; /* Mirrors triggered when packet received. */
static struct bridge *bridge_create(const char *name);
static void bridge_destroy(struct bridge *);
static struct bridge *bridge_lookup(const char *name);
+static void bridge_unixctl_dump_flows(struct unixctl_conn *, const char *);
static int bridge_run_one(struct bridge *);
static void bridge_reconfigure_one(struct bridge *);
static void bridge_reconfigure_controller(struct bridge *);
const char *devname);
static uint64_t dpid_from_hash(const void *, size_t nbytes);
+static void bridge_unixctl_fdb_show(struct unixctl_conn *, const char *args);
+
+static void bond_init(void);
static void bond_run(struct bridge *);
static void bond_wait(struct bridge *);
static void bond_rebalance_port(struct port *);
static void port_reconfigure(struct port *);
static void port_destroy(struct port *);
static struct port *port_lookup(const struct bridge *, const char *name);
+static struct iface *port_lookup_iface(const struct port *, const char *name);
static struct port *port_from_dp_ifidx(const struct bridge *,
uint16_t dp_ifidx);
static void port_update_bond_compat(struct port *);
int retval;
int i;
+ bond_init();
+
+ unixctl_command_register("fdb/show", bridge_unixctl_fdb_show);
+
for (i = 0; i < DP_MAX; i++) {
struct dpif dpif;
char devname[16];
}
}
+ unixctl_command_register("bridge/dump-flows", bridge_unixctl_dump_flows);
+
bridge_reconfigure();
}
static char *private_key_file;
static char *certificate_file;
static char *cacert_file;
+ struct stat s;
if (config_string_change("ssl.private-key", &private_key_file)) {
vconn_ssl_set_private_key_file(private_key_file);
vconn_ssl_set_certificate_file(certificate_file);
}
- if (config_string_change("ssl.ca-cert", &cacert_file)) {
+ /* We assume that even if the filename hasn't changed, if the CA cert
+ * file has been removed, that we want to move back into
+ * boot-strapping mode. This opens a small security hole, because
+ * the old certificate will still be trusted until vSwitch is
+ * restarted. We may want to address this in vconn's SSL library. */
+ if (config_string_change("ssl.ca-cert", &cacert_file)
+ || (stat(cacert_file, &s) && errno == ENOENT)) {
vconn_ssl_set_ca_cert_file(cacert_file,
cfg_get_bool(0, "ssl.bootstrap-ca-cert"));
}
for (i = 0; i < add_ifaces.n; i++) {
const char *if_name = add_ifaces.names[i];
for (;;) {
- int internal = cfg_get_bool(0, "iface.%s.internal", if_name);
- int error = dpif_port_add(&br->dpif, if_name, next_port_no++,
- internal ? ODP_PORT_INTERNAL : 0);
+ bool internal;
+ int error;
+
+ /* It's an internal interface if it's marked that way, or if
+ * it's a bonded interface for which we're faking up a network
+ * device. */
+ internal = cfg_get_bool(0, "iface.%s.internal", if_name);
+ if (cfg_get_bool(0, "bonding.%s.fake-iface", if_name)) {
+ struct port *port = port_lookup(br, if_name);
+ if (port && port->n_ifaces > 1) {
+ internal = true;
+ }
+ }
+
+ /* Add to datapath. */
+ error = dpif_port_add(&br->dpif, if_name, next_port_no++,
+ internal ? ODP_PORT_INTERNAL : 0);
if (error != EEXIST) {
if (next_port_no >= 256) {
VLOG_ERR("ran out of valid port numbers on dp%u",
memset(ea, 0xff, sizeof ea);
for (i = 0; i < br->n_ports; i++) {
struct port *port = br->ports[i];
+ uint8_t iface_ea[ETH_ADDR_LEN];
+ uint64_t iface_ea_u64;
+ struct iface *iface;
+
+ /* Mirror output ports don't participate. */
if (port->is_mirror_output_port) {
continue;
}
- for (j = 0; j < port->n_ifaces; j++) {
- struct iface *iface = port->ifaces[j];
- uint8_t iface_ea[ETH_ADDR_LEN];
+
+ /* Choose the MAC address to represent the port. */
+ iface_ea_u64 = cfg_get_mac(0, "port.%s.mac", port->name);
+ if (iface_ea_u64) {
+ /* User specified explicitly. */
+ eth_addr_from_uint64(iface_ea_u64, iface_ea);
+
+ /* Find the interface with this Ethernet address (if any) so that
+ * we can provide the correct devname to the caller. */
+ iface = NULL;
+ for (j = 0; j < port->n_ifaces; j++) {
+ struct iface *candidate = port->ifaces[j];
+ uint8_t candidate_ea[ETH_ADDR_LEN];
+ if (!netdev_nodev_get_etheraddr(candidate->name, candidate_ea)
+ && eth_addr_equals(iface_ea, candidate_ea)) {
+ iface = candidate;
+ }
+ }
+ } else {
+ /* Choose the interface whose MAC address will represent the port.
+ * The Linux kernel bonding code always chooses the MAC address of
+ * the first slave added to a bond, and the Fedora networking
+ * scripts always add slaves to a bond in alphabetical order, so
+ * for compatibility we choose the interface with the name that is
+ * first in alphabetical order. */
+ iface = port->ifaces[0];
+ for (j = 1; j < port->n_ifaces; j++) {
+ struct iface *candidate = port->ifaces[j];
+ if (strcmp(candidate->name, iface->name) < 0) {
+ iface = candidate;
+ }
+ }
+
+ /* The local port doesn't count (since we're trying to choose its
+ * MAC address anyway). Other internal ports don't count because
+ * we really want a physical MAC if we can get it, and internal
+ * ports typically have randomly generated MACs. */
if (iface->dp_ifidx == ODPP_LOCAL
|| cfg_get_bool(0, "iface.%s.internal", iface->name)) {
continue;
}
+
+ /* Grab MAC. */
error = netdev_nodev_get_etheraddr(iface->name, iface_ea);
- if (!error) {
- if (!eth_addr_is_multicast(iface_ea) &&
- !eth_addr_is_reserved(iface_ea) &&
- !eth_addr_is_zero(iface_ea) &&
- memcmp(iface_ea, ea, ETH_ADDR_LEN) < 0) {
- memcpy(ea, iface_ea, ETH_ADDR_LEN);
- *devname = iface->name;
- }
- } else {
+ if (error) {
static struct vlog_rate_limit rl = VLOG_RATE_LIMIT_INIT(1, 5);
VLOG_ERR_RL(&rl, "failed to obtain Ethernet address of %s: %s",
iface->name, strerror(error));
+ continue;
}
}
+
+ /* Compare against our current choice. */
+ if (!eth_addr_is_multicast(iface_ea) &&
+ !eth_addr_is_reserved(iface_ea) &&
+ !eth_addr_is_zero(iface_ea) &&
+ memcmp(iface_ea, ea, ETH_ADDR_LEN) < 0)
+ {
+ memcpy(ea, iface_ea, ETH_ADDR_LEN);
+ *devname = iface ? iface->name : NULL;
+ }
}
if (eth_addr_is_multicast(ea) || eth_addr_is_vif(ea)) {
memcpy(ea, br->default_ea, ETH_ADDR_LEN);
static uint64_t
dpid_from_hash(const void *data, size_t n)
{
- uint8_t hash[SHA1HashSize];
+ uint8_t hash[SHA1_DIGEST_SIZE];
BUILD_ASSERT_DECL(sizeof hash >= ETH_ADDR_LEN);
- SHA1Bytes(data, n, hash);
+ sha1_bytes(data, n, hash);
eth_addr_mark_random(hash);
return eth_addr_to_uint64(hash);
}
}
}
\f
+/* Bridge unixctl user interface functions. */
+static void
+bridge_unixctl_fdb_show(struct unixctl_conn *conn, const char *args)
+{
+ struct ds ds = DS_EMPTY_INITIALIZER;
+ const struct bridge *br;
+
+ br = bridge_lookup(args);
+ if (!br) {
+ unixctl_command_reply(conn, 501, "no such bridge");
+ return;
+ }
+
+ ds_put_cstr(&ds, " port VLAN MAC Age\n");
+ if (br->ml) {
+ const struct mac_entry *e;
+ LIST_FOR_EACH (e, struct mac_entry, lru_node, &br->ml->lrus) {
+ if (e->port < 0 || e->port >= br->n_ports) {
+ continue;
+ }
+ ds_put_format(&ds, "%5d %4d "ETH_ADDR_FMT" %3d\n",
+ br->ports[e->port]->ifaces[0]->dp_ifidx,
+ e->vlan, ETH_ADDR_ARGS(e->mac), mac_entry_age(e));
+ }
+ }
+ unixctl_command_reply(conn, 200, ds_cstr(&ds));
+ ds_destroy(&ds);
+}
+\f
/* Bridge reconfiguration functions. */
static struct bridge *
return br ? ofproto_get_datapath_id(br->ofproto) : 0;
}
+/* Handle requests for a listing of all flows known by the OpenFlow
+ * stack, including those normally hidden. */
+static void
+bridge_unixctl_dump_flows(struct unixctl_conn *conn, const char *args)
+{
+ struct bridge *br;
+ struct ds results;
+
+ br = bridge_lookup(args);
+ if (!br) {
+ unixctl_command_reply(conn, 501, "Unknown bridge");
+ return;
+ }
+
+ ds_init(&results);
+ ofproto_get_all_flows(br->ofproto, &results);
+
+ unixctl_command_reply(conn, 200, ds_cstr(&results));
+ ds_destroy(&results);
+}
+
static int
bridge_run_one(struct bridge *br)
{
int rate_limit, burst_limit;
if (!strcmp(controller, "discover")) {
+ bool update_resolv_conf = true;
+
+ if (cfg_has("%s.update-resolv.conf", pfx)) {
+ update_resolv_conf = cfg_get_bool(0, "%s.update-resolv.conf",
+ pfx);
+ }
ofproto_set_discovery(br->ofproto, true,
cfg_get_string(0, "%s.accept-regex", pfx),
- cfg_get_bool(0, "%s.update-resolv.conf",
- pfx));
+ update_resolv_conf);
} else {
struct netdev *netdev;
bool in_band;
|| !strcmp(fail_mode, "open")));
probe = cfg_get_int(0, "%s.inactivity-probe", pfx);
- ofproto_set_probe_interval(br->ofproto,
- probe ? probe : cfg_get_int(0, "mgmt.inactivity-probe"));
+ if (probe < 5) {
+ probe = cfg_get_int(0, "mgmt.inactivity-probe");
+ if (probe < 5) {
+ probe = 5;
+ }
+ }
+ ofproto_set_probe_interval(br->ofproto, probe);
max_backoff = cfg_get_int(0, "%s.max-backoff", pfx);
if (!max_backoff) {
max_backoff = cfg_get_int(0, "mgmt.max-backoff");
if (!max_backoff) {
- max_backoff = 15;
+ max_backoff = 8;
}
}
ofproto_set_max_backoff(br->ofproto, max_backoff);
struct iface *iface = port->ifaces[j];
svec_add(ifaces, iface->name);
}
+ if (port->n_ifaces > 1
+ && cfg_get_bool(0, "bonding.%s.fake-iface", port->name)) {
+ svec_add(ifaces, port->name);
+ }
}
- svec_sort(ifaces);
- assert(svec_is_unique(ifaces));
+ svec_sort_unique(ifaces);
}
/* For robustness, in case the administrator moves around datapath ports behind
\f
/* Bridge packet processing functions. */
+static int
+bond_hash(const uint8_t mac[ETH_ADDR_LEN])
+{
+ return hash_bytes(mac, ETH_ADDR_LEN, 0) & BOND_MASK;
+}
+
static struct bond_entry *
lookup_bond_entry(const struct port *port, const uint8_t mac[ETH_ADDR_LEN])
{
- size_t h = hash_bytes(mac, ETH_ADDR_LEN, 0);
- return &port->bond_hash[h & BOND_MASK];
+ return &port->bond_hash[bond_hash(mac)];
}
static int
return false;
}
e->iface_tag = tag_create_random();
+ ((struct port *) port)->bond_compat_is_stale = true;
}
*tags |= e->iface_tag;
iface = port->ifaces[e->iface_idx];
iface->delay_expires = LLONG_MAX;
VLOG_INFO_RL(&rl, "interface %s: will not be %s",
iface->name, carrier ? "disabled" : "enabled");
+ } else if (carrier && port->updelay && port->active_iface < 0) {
+ iface->delay_expires = time_msec();
+ VLOG_INFO_RL(&rl, "interface %s: skipping %d ms updelay since no "
+ "other interface is up", iface->name, port->updelay);
} else {
int delay = carrier ? port->updelay : port->downdelay;
iface->delay_expires = time_msec() + delay;
}
}
+static void
+bond_enable_slave(struct iface *iface, bool enable)
+{
+ struct port *port = iface->port;
+ struct bridge *br = port->bridge;
+
+ iface->delay_expires = LLONG_MAX;
+ if (enable == iface->enabled) {
+ return;
+ }
+
+ iface->enabled = enable;
+ if (!iface->enabled) {
+ VLOG_WARN("interface %s: disabled", iface->name);
+ ofproto_revalidate(br->ofproto, iface->tag);
+ if (iface->port_ifidx == port->active_iface) {
+ ofproto_revalidate(br->ofproto,
+ port->active_iface_tag);
+ bond_choose_active_iface(port);
+ }
+ bond_send_learning_packets(port);
+ } else {
+ VLOG_WARN("interface %s: enabled", iface->name);
+ if (port->active_iface < 0) {
+ ofproto_revalidate(br->ofproto, port->no_ifaces_tag);
+ bond_choose_active_iface(port);
+ bond_send_learning_packets(port);
+ }
+ iface->tag = tag_create_random();
+ }
+}
+
static void
bond_run(struct bridge *br)
{
for (i = 0; i < br->n_ports; i++) {
struct port *port = br->ports[i];
+
+ if (port->bond_compat_is_stale) {
+ port->bond_compat_is_stale = false;
+ port_update_bond_compat(port);
+ }
+
if (port->n_ifaces < 2) {
continue;
}
for (j = 0; j < port->n_ifaces; j++) {
struct iface *iface = port->ifaces[j];
if (time_msec() >= iface->delay_expires) {
- iface->delay_expires = LLONG_MAX;
- iface->enabled = !iface->enabled;
- VLOG_WARN("interface %s: %s",
- iface->name,
- iface->enabled ? "enabled" : "disabled");
- if (!iface->enabled) {
- ofproto_revalidate(br->ofproto, iface->tag);
- if (iface->port_ifidx == port->active_iface) {
- ofproto_revalidate(br->ofproto,
- port->active_iface_tag);
- bond_choose_active_iface(port);
- }
- bond_send_learning_packets(port);
- } else {
- if (port->active_iface < 0) {
- ofproto_revalidate(br->ofproto, port->no_ifaces_tag);
- bond_choose_active_iface(port);
- bond_send_learning_packets(port);
- }
- iface->tag = tag_create_random();
- }
+ bond_enable_slave(iface, !iface->enabled);
}
}
}
goto done;
}
- /* Drop multicast and broadcast packets on inactive bonded interfaces, to
+ /* Multicast (and broadcast) packets on bonds need special attention, to
* avoid receiving duplicates. */
if (in_port->n_ifaces > 1 && eth_addr_is_multicast(flow->dl_dst)) {
*tags |= in_port->active_iface_tag;
if (in_port->active_iface != in_iface->port_ifidx) {
+ /* Drop all multicast packets on inactive slaves. */
goto done;
+ } else {
+ /* Drop all multicast packets for which we have learned a different
+ * input port, because we probably sent the packet on one slaves
+ * and got it back on the active slave. Broadcast ARP replies are
+ * an exception to this rule: the host has moved to another
+ * switch. */
+ int src_idx = mac_learning_lookup(br->ml, flow->dl_src, vlan);
+ if (src_idx != -1 && src_idx != in_port->port_idx) {
+ if (packet) {
+ if (!is_bcast_arp_reply(flow, packet)) {
+ goto done;
+ }
+ } else {
+ /* No way to know whether it's an ARP reply, because the
+ * flow entry doesn't include enough information and we
+ * don't have a packet. Punt. */
+ return false;
+ }
+ }
}
}
out_port = FLOOD_PORT;
if (br->ml) {
int out_port_idx;
- bool may_learn;
-
- if (!packet) {
- /* Don't try to learn from revalidation. */
- may_learn = false;
- } else if (in_port->n_ifaces > 1) {
- /* If the packet arrived on a bonded port, don't learn from it
- * unless we haven't learned any port at all for that address
- * (because we probably sent the packet on one bonded interface and
- * got it back on the other). Broadcast ARP replies are an
- * exception to this rule: the host has moved to another switch. */
- int src_idx = mac_learning_lookup(br->ml, flow->dl_src, vlan);
- may_learn = (src_idx < 0
- || src_idx == in_port->port_idx
- || is_bcast_arp_reply(flow, packet));
- } else {
- may_learn = true;
- }
- /* Learn source MAC. */
- if (may_learn) {
+ /* Learn source MAC (but don't try to learn from revalidation). */
+ if (packet) {
tag_type rev_tag = mac_learning_learn(br->ml, flow->dl_src,
vlan, in_port->port_idx);
if (rev_tag) {
ofproto_revalidate(port->bridge->ofproto, hash->iface_tag);
hash->iface_idx = to->iface->port_ifidx;
hash->iface_tag = tag_create_random();
-
}
static void
} else {
from++;
}
+ port->bond_compat_is_stale = true;
}
}
}
}
\f
+/* Bonding unixctl user interface functions. */
+
+static void
+bond_unixctl_list(struct unixctl_conn *conn, const char *args UNUSED)
+{
+ struct ds ds = DS_EMPTY_INITIALIZER;
+ const struct bridge *br;
+
+ ds_put_cstr(&ds, "bridge\tbond\tslaves\n");
+
+ LIST_FOR_EACH (br, struct bridge, node, &all_bridges) {
+ size_t i;
+
+ for (i = 0; i < br->n_ports; i++) {
+ const struct port *port = br->ports[i];
+ if (port->n_ifaces > 1) {
+ size_t j;
+
+ ds_put_format(&ds, "%s\t%s\t", br->name, port->name);
+ for (j = 0; j < port->n_ifaces; j++) {
+ const struct iface *iface = port->ifaces[j];
+ if (j) {
+ ds_put_cstr(&ds, ", ");
+ }
+ ds_put_cstr(&ds, iface->name);
+ }
+ ds_put_char(&ds, '\n');
+ }
+ }
+ }
+ unixctl_command_reply(conn, 200, ds_cstr(&ds));
+ ds_destroy(&ds);
+}
+
+static struct port *
+bond_find(const char *name)
+{
+ const struct bridge *br;
+
+ LIST_FOR_EACH (br, struct bridge, node, &all_bridges) {
+ size_t i;
+
+ for (i = 0; i < br->n_ports; i++) {
+ struct port *port = br->ports[i];
+ if (!strcmp(port->name, name) && port->n_ifaces > 1) {
+ return port;
+ }
+ }
+ }
+ return NULL;
+}
+
+static void
+bond_unixctl_show(struct unixctl_conn *conn, const char *args)
+{
+ struct ds ds = DS_EMPTY_INITIALIZER;
+ const struct port *port;
+ size_t j;
+
+ port = bond_find(args);
+ if (!port) {
+ unixctl_command_reply(conn, 501, "no such bond");
+ return;
+ }
+
+ ds_put_format(&ds, "updelay: %d ms\n", port->updelay);
+ ds_put_format(&ds, "downdelay: %d ms\n", port->downdelay);
+ ds_put_format(&ds, "next rebalance: %lld ms\n",
+ port->bridge->bond_next_rebalance - time_msec());
+ for (j = 0; j < port->n_ifaces; j++) {
+ const struct iface *iface = port->ifaces[j];
+ struct bond_entry *be;
+
+ /* Basic info. */
+ ds_put_format(&ds, "slave %s: %s\n",
+ iface->name, iface->enabled ? "enabled" : "disabled");
+ if (j == port->active_iface) {
+ ds_put_cstr(&ds, "\tactive slave\n");
+ }
+ if (iface->delay_expires != LLONG_MAX) {
+ ds_put_format(&ds, "\t%s expires in %lld ms\n",
+ iface->enabled ? "downdelay" : "updelay",
+ iface->delay_expires - time_msec());
+ }
+
+ /* Hashes. */
+ for (be = port->bond_hash; be <= &port->bond_hash[BOND_MASK]; be++) {
+ int hash = be - port->bond_hash;
+ struct mac_entry *me;
+
+ if (be->iface_idx != j) {
+ continue;
+ }
+
+ ds_put_format(&ds, "\thash %d: %lld kB load\n",
+ hash, be->tx_bytes / 1024);
+
+ /* MACs. */
+ if (!port->bridge->ml) {
+ break;
+ }
+
+ LIST_FOR_EACH (me, struct mac_entry, lru_node,
+ &port->bridge->ml->lrus) {
+ uint16_t dp_ifidx;
+ tag_type tags = 0;
+ if (bond_hash(me->mac) == hash
+ && me->port != port->port_idx
+ && choose_output_iface(port, me->mac, &dp_ifidx, &tags)
+ && dp_ifidx == iface->dp_ifidx)
+ {
+ ds_put_format(&ds, "\t\t"ETH_ADDR_FMT"\n",
+ ETH_ADDR_ARGS(me->mac));
+ }
+ }
+ }
+ }
+ unixctl_command_reply(conn, 200, ds_cstr(&ds));
+ ds_destroy(&ds);
+}
+
+static void
+bond_unixctl_migrate(struct unixctl_conn *conn, const char *args_)
+{
+ char *args = (char *) args_;
+ char *save_ptr = NULL;
+ char *bond_s, *hash_s, *slave_s;
+ uint8_t mac[ETH_ADDR_LEN];
+ struct port *port;
+ struct iface *iface;
+ struct bond_entry *entry;
+ int hash;
+
+ bond_s = strtok_r(args, " ", &save_ptr);
+ hash_s = strtok_r(NULL, " ", &save_ptr);
+ slave_s = strtok_r(NULL, " ", &save_ptr);
+ if (!slave_s) {
+ unixctl_command_reply(conn, 501,
+ "usage: bond/migrate BOND HASH SLAVE");
+ return;
+ }
+
+ port = bond_find(bond_s);
+ if (!port) {
+ unixctl_command_reply(conn, 501, "no such bond");
+ return;
+ }
+
+ if (sscanf(hash_s, ETH_ADDR_SCAN_FMT, ETH_ADDR_SCAN_ARGS(mac))
+ == ETH_ADDR_SCAN_COUNT) {
+ hash = bond_hash(mac);
+ } else if (strspn(hash_s, "0123456789") == strlen(hash_s)) {
+ hash = atoi(hash_s) & BOND_MASK;
+ } else {
+ unixctl_command_reply(conn, 501, "bad hash");
+ return;
+ }
+
+ iface = port_lookup_iface(port, slave_s);
+ if (!iface) {
+ unixctl_command_reply(conn, 501, "no such slave");
+ return;
+ }
+
+ if (!iface->enabled) {
+ unixctl_command_reply(conn, 501, "cannot migrate to disabled slave");
+ return;
+ }
+
+ entry = &port->bond_hash[hash];
+ ofproto_revalidate(port->bridge->ofproto, entry->iface_tag);
+ entry->iface_idx = iface->port_ifidx;
+ entry->iface_tag = tag_create_random();
+ port->bond_compat_is_stale = true;
+ unixctl_command_reply(conn, 200, "migrated");
+}
+
+static void
+bond_unixctl_set_active_slave(struct unixctl_conn *conn, const char *args_)
+{
+ char *args = (char *) args_;
+ char *save_ptr = NULL;
+ char *bond_s, *slave_s;
+ struct port *port;
+ struct iface *iface;
+
+ bond_s = strtok_r(args, " ", &save_ptr);
+ slave_s = strtok_r(NULL, " ", &save_ptr);
+ if (!slave_s) {
+ unixctl_command_reply(conn, 501,
+ "usage: bond/set-active-slave BOND SLAVE");
+ return;
+ }
+
+ port = bond_find(bond_s);
+ if (!port) {
+ unixctl_command_reply(conn, 501, "no such bond");
+ return;
+ }
+
+ iface = port_lookup_iface(port, slave_s);
+ if (!iface) {
+ unixctl_command_reply(conn, 501, "no such slave");
+ return;
+ }
+
+ if (!iface->enabled) {
+ unixctl_command_reply(conn, 501, "cannot make disabled slave active");
+ return;
+ }
+
+ if (port->active_iface != iface->port_ifidx) {
+ ofproto_revalidate(port->bridge->ofproto, port->active_iface_tag);
+ port->active_iface = iface->port_ifidx;
+ port->active_iface_tag = tag_create_random();
+ VLOG_INFO("port %s: active interface is now %s",
+ port->name, iface->name);
+ bond_send_learning_packets(port);
+ unixctl_command_reply(conn, 200, "done");
+ } else {
+ unixctl_command_reply(conn, 200, "no change");
+ }
+}
+
+static void
+enable_slave(struct unixctl_conn *conn, const char *args_, bool enable)
+{
+ char *args = (char *) args_;
+ char *save_ptr = NULL;
+ char *bond_s, *slave_s;
+ struct port *port;
+ struct iface *iface;
+
+ bond_s = strtok_r(args, " ", &save_ptr);
+ slave_s = strtok_r(NULL, " ", &save_ptr);
+ if (!slave_s) {
+ unixctl_command_reply(conn, 501,
+ "usage: bond/enable/disable-slave BOND SLAVE");
+ return;
+ }
+
+ port = bond_find(bond_s);
+ if (!port) {
+ unixctl_command_reply(conn, 501, "no such bond");
+ return;
+ }
+
+ iface = port_lookup_iface(port, slave_s);
+ if (!iface) {
+ unixctl_command_reply(conn, 501, "no such slave");
+ return;
+ }
+
+ bond_enable_slave(iface, enable);
+ unixctl_command_reply(conn, 501, enable ? "enabled" : "disabled");
+}
+
+static void
+bond_unixctl_enable_slave(struct unixctl_conn *conn, const char *args)
+{
+ enable_slave(conn, args, true);
+}
+
+static void
+bond_unixctl_disable_slave(struct unixctl_conn *conn, const char *args)
+{
+ enable_slave(conn, args, false);
+}
+
+static void
+bond_init(void)
+{
+ unixctl_command_register("bond/list", bond_unixctl_list);
+ unixctl_command_register("bond/show", bond_unixctl_show);
+ unixctl_command_register("bond/migrate", bond_unixctl_migrate);
+ unixctl_command_register("bond/set-active-slave",
+ bond_unixctl_set_active_slave);
+ unixctl_command_register("bond/enable-slave", bond_unixctl_enable_slave);
+ unixctl_command_register("bond/disable-slave", bond_unixctl_disable_slave);
+}
+\f
/* Port functions. */
static void
size_t i;
proc_net_compat_update_vlan(port->name, NULL, 0);
+ proc_net_compat_update_bond(port->name, NULL);
for (i = 0; i < MAX_MIRRORS; i++) {
struct mirror *m = br->mirrors[i];
return NULL;
}
+static struct iface *
+port_lookup_iface(const struct port *port, const char *name)
+{
+ size_t j;
+
+ for (j = 0; j < port->n_ifaces; j++) {
+ struct iface *iface = port->ifaces[j];
+ if (!strcmp(iface->name, name)) {
+ return iface;
+ }
+ }
+ return NULL;
+}
+
static void
port_update_bonding(struct port *port)
{
if (port->bond_hash) {
free(port->bond_hash);
port->bond_hash = NULL;
- proc_net_compat_update_bond(port->name, NULL);
+ port->bond_compat_is_stale = true;
}
} else {
if (!port->bond_hash) {
port->no_ifaces_tag = tag_create_random();
bond_choose_active_iface(port);
}
- port_update_bond_compat(port);
+ port->bond_compat_is_stale = true;
}
}
static void
port_update_bond_compat(struct port *port)
{
+ struct compat_bond_hash compat_hashes[BOND_MASK + 1];
struct compat_bond bond;
size_t i;
if (port->n_ifaces < 2) {
+ proc_net_compat_update_bond(port->name, NULL);
return;
}
bond.up = false;
bond.updelay = port->updelay;
bond.downdelay = port->downdelay;
+
+ bond.n_hashes = 0;
+ bond.hashes = compat_hashes;
+ if (port->bond_hash) {
+ const struct bond_entry *e;
+ for (e = port->bond_hash; e <= &port->bond_hash[BOND_MASK]; e++) {
+ if (e->iface_idx >= 0 && e->iface_idx < port->n_ifaces) {
+ struct compat_bond_hash *cbh = &bond.hashes[bond.n_hashes++];
+ cbh->hash = e - port->bond_hash;
+ cbh->netdev_name = port->ifaces[e->iface_idx]->name;
+ }
+ }
+ }
+
bond.n_slaves = port->n_ifaces;
bond.slaves = xmalloc(port->n_ifaces * sizeof *bond.slaves);
for (i = 0; i < port->n_ifaces; i++) {
}
memcpy(slave->mac, iface->mac, ETH_ADDR_LEN);
}
+
proc_net_compat_update_bond(port->name, &bond);
free(bond.slaves);
}
iface->tag = tag_create_random();
iface->delay_expires = LLONG_MAX;
- netdev_nodev_get_etheraddr(name, iface->mac);
- netdev_nodev_get_carrier(name, &iface->enabled);
+ if (!cfg_get_bool(0, "iface.%s.internal", iface->name)) {
+ netdev_nodev_get_etheraddr(name, iface->mac);
+ netdev_nodev_get_carrier(name, &iface->enabled);
+ } else {
+ /* Internal interfaces are created later by the call to dpif_port_add()
+ * in bridge_reconfigure(). Until then, we can't obtain any
+ * information about them. (There's no real value in doing so, anyway,
+ * because the 'mac' and 'enabled' values are only used for interfaces
+ * that are bond slaves, and it doesn't normally make sense to bond an
+ * internal interface.) */
+ }
if (port->n_ifaces >= port->allocated_ifaces) {
port->ifaces = x2nrealloc(port->ifaces, &port->allocated_ifaces,